2 * Marvell MVEBU pinctrl core driver
4 * Authors: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
5 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
17 #include <linux/of_address.h>
18 #include <linux/of_platform.h>
19 #include <linux/err.h>
20 #include <linux/gpio.h>
21 #include <linux/pinctrl/machine.h>
22 #include <linux/pinctrl/pinconf.h>
23 #include <linux/pinctrl/pinctrl.h>
24 #include <linux/pinctrl/pinmux.h>
25 #include <linux/mfd/syscon.h>
26 #include <linux/regmap.h>
28 #include "pinctrl-mvebu.h"
30 #define MPPS_PER_REG 8
34 struct mvebu_pinctrl_function
{
40 struct mvebu_pinctrl_group
{
42 const struct mvebu_mpp_ctrl
*ctrl
;
43 struct mvebu_mpp_ctrl_data
*data
;
44 struct mvebu_mpp_ctrl_setting
*settings
;
45 unsigned num_settings
;
51 struct mvebu_pinctrl
{
53 struct pinctrl_dev
*pctldev
;
54 struct pinctrl_desc desc
;
55 struct mvebu_pinctrl_group
*groups
;
57 struct mvebu_pinctrl_function
*functions
;
58 unsigned num_functions
;
62 int mvebu_mmio_mpp_ctrl_get(struct mvebu_mpp_ctrl_data
*data
,
63 unsigned int pid
, unsigned long *config
)
65 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
66 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
68 *config
= (readl(data
->base
+ off
) >> shift
) & MVEBU_MPP_MASK
;
73 int mvebu_mmio_mpp_ctrl_set(struct mvebu_mpp_ctrl_data
*data
,
74 unsigned int pid
, unsigned long config
)
76 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
77 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
80 reg
= readl(data
->base
+ off
) & ~(MVEBU_MPP_MASK
<< shift
);
81 writel(reg
| (config
<< shift
), data
->base
+ off
);
86 static struct mvebu_pinctrl_group
*mvebu_pinctrl_find_group_by_pid(
87 struct mvebu_pinctrl
*pctl
, unsigned pid
)
90 for (n
= 0; n
< pctl
->num_groups
; n
++) {
91 if (pid
>= pctl
->groups
[n
].pins
[0] &&
92 pid
< pctl
->groups
[n
].pins
[0] +
93 pctl
->groups
[n
].npins
)
94 return &pctl
->groups
[n
];
99 static struct mvebu_pinctrl_group
*mvebu_pinctrl_find_group_by_name(
100 struct mvebu_pinctrl
*pctl
, const char *name
)
103 for (n
= 0; n
< pctl
->num_groups
; n
++) {
104 if (strcmp(name
, pctl
->groups
[n
].name
) == 0)
105 return &pctl
->groups
[n
];
110 static struct mvebu_mpp_ctrl_setting
*mvebu_pinctrl_find_setting_by_val(
111 struct mvebu_pinctrl
*pctl
, struct mvebu_pinctrl_group
*grp
,
112 unsigned long config
)
115 for (n
= 0; n
< grp
->num_settings
; n
++) {
116 if (config
== grp
->settings
[n
].val
) {
117 if (!pctl
->variant
|| (pctl
->variant
&
118 grp
->settings
[n
].variant
))
119 return &grp
->settings
[n
];
125 static struct mvebu_mpp_ctrl_setting
*mvebu_pinctrl_find_setting_by_name(
126 struct mvebu_pinctrl
*pctl
, struct mvebu_pinctrl_group
*grp
,
130 for (n
= 0; n
< grp
->num_settings
; n
++) {
131 if (strcmp(name
, grp
->settings
[n
].name
) == 0) {
132 if (!pctl
->variant
|| (pctl
->variant
&
133 grp
->settings
[n
].variant
))
134 return &grp
->settings
[n
];
140 static struct mvebu_mpp_ctrl_setting
*mvebu_pinctrl_find_gpio_setting(
141 struct mvebu_pinctrl
*pctl
, struct mvebu_pinctrl_group
*grp
)
144 for (n
= 0; n
< grp
->num_settings
; n
++) {
145 if (grp
->settings
[n
].flags
&
146 (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
147 if (!pctl
->variant
|| (pctl
->variant
&
148 grp
->settings
[n
].variant
))
149 return &grp
->settings
[n
];
155 static struct mvebu_pinctrl_function
*mvebu_pinctrl_find_function_by_name(
156 struct mvebu_pinctrl
*pctl
, const char *name
)
159 for (n
= 0; n
< pctl
->num_functions
; n
++) {
160 if (strcmp(name
, pctl
->functions
[n
].name
) == 0)
161 return &pctl
->functions
[n
];
166 static int mvebu_pinconf_group_get(struct pinctrl_dev
*pctldev
,
167 unsigned gid
, unsigned long *config
)
169 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
170 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
175 return grp
->ctrl
->mpp_get(grp
->data
, grp
->pins
[0], config
);
178 static int mvebu_pinconf_group_set(struct pinctrl_dev
*pctldev
,
179 unsigned gid
, unsigned long *configs
,
180 unsigned num_configs
)
182 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
183 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
189 for (i
= 0; i
< num_configs
; i
++) {
190 ret
= grp
->ctrl
->mpp_set(grp
->data
, grp
->pins
[0], configs
[i
]);
193 } /* for each config */
198 static void mvebu_pinconf_group_dbg_show(struct pinctrl_dev
*pctldev
,
199 struct seq_file
*s
, unsigned gid
)
201 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
202 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
203 struct mvebu_mpp_ctrl_setting
*curr
;
204 unsigned long config
;
207 if (mvebu_pinconf_group_get(pctldev
, gid
, &config
))
210 curr
= mvebu_pinctrl_find_setting_by_val(pctl
, grp
, config
);
213 seq_printf(s
, "current: %s", curr
->name
);
215 seq_printf(s
, "(%s)", curr
->subname
);
216 if (curr
->flags
& (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
218 if (curr
->flags
& MVEBU_SETTING_GPI
)
220 if (curr
->flags
& MVEBU_SETTING_GPO
)
225 seq_puts(s
, "current: UNKNOWN");
228 if (grp
->num_settings
> 1) {
229 seq_puts(s
, ", available = [");
230 for (n
= 0; n
< grp
->num_settings
; n
++) {
231 if (curr
== &grp
->settings
[n
])
234 /* skip unsupported settings for this variant */
236 !(pctl
->variant
& grp
->settings
[n
].variant
))
239 seq_printf(s
, " %s", grp
->settings
[n
].name
);
240 if (grp
->settings
[n
].subname
)
241 seq_printf(s
, "(%s)", grp
->settings
[n
].subname
);
242 if (grp
->settings
[n
].flags
&
243 (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
245 if (grp
->settings
[n
].flags
& MVEBU_SETTING_GPI
)
247 if (grp
->settings
[n
].flags
& MVEBU_SETTING_GPO
)
256 static const struct pinconf_ops mvebu_pinconf_ops
= {
257 .pin_config_group_get
= mvebu_pinconf_group_get
,
258 .pin_config_group_set
= mvebu_pinconf_group_set
,
259 .pin_config_group_dbg_show
= mvebu_pinconf_group_dbg_show
,
262 static int mvebu_pinmux_get_funcs_count(struct pinctrl_dev
*pctldev
)
264 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
266 return pctl
->num_functions
;
269 static const char *mvebu_pinmux_get_func_name(struct pinctrl_dev
*pctldev
,
272 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
274 return pctl
->functions
[fid
].name
;
277 static int mvebu_pinmux_get_groups(struct pinctrl_dev
*pctldev
, unsigned fid
,
278 const char * const **groups
,
279 unsigned * const num_groups
)
281 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
283 *groups
= pctl
->functions
[fid
].groups
;
284 *num_groups
= pctl
->functions
[fid
].num_groups
;
288 static int mvebu_pinmux_set(struct pinctrl_dev
*pctldev
, unsigned fid
,
291 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
292 struct mvebu_pinctrl_function
*func
= &pctl
->functions
[fid
];
293 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
294 struct mvebu_mpp_ctrl_setting
*setting
;
296 unsigned long config
;
298 setting
= mvebu_pinctrl_find_setting_by_name(pctl
, grp
,
302 "unable to find setting %s in group %s\n",
303 func
->name
, func
->groups
[gid
]);
307 config
= setting
->val
;
308 ret
= mvebu_pinconf_group_set(pctldev
, grp
->gid
, &config
, 1);
310 dev_err(pctl
->dev
, "cannot set group %s to %s\n",
311 func
->groups
[gid
], func
->name
);
318 static int mvebu_pinmux_gpio_request_enable(struct pinctrl_dev
*pctldev
,
319 struct pinctrl_gpio_range
*range
, unsigned offset
)
321 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
322 struct mvebu_pinctrl_group
*grp
;
323 struct mvebu_mpp_ctrl_setting
*setting
;
324 unsigned long config
;
326 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, offset
);
330 if (grp
->ctrl
->mpp_gpio_req
)
331 return grp
->ctrl
->mpp_gpio_req(grp
->data
, offset
);
333 setting
= mvebu_pinctrl_find_gpio_setting(pctl
, grp
);
337 config
= setting
->val
;
339 return mvebu_pinconf_group_set(pctldev
, grp
->gid
, &config
, 1);
342 static int mvebu_pinmux_gpio_set_direction(struct pinctrl_dev
*pctldev
,
343 struct pinctrl_gpio_range
*range
, unsigned offset
, bool input
)
345 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
346 struct mvebu_pinctrl_group
*grp
;
347 struct mvebu_mpp_ctrl_setting
*setting
;
349 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, offset
);
353 if (grp
->ctrl
->mpp_gpio_dir
)
354 return grp
->ctrl
->mpp_gpio_dir(grp
->data
, offset
, input
);
356 setting
= mvebu_pinctrl_find_gpio_setting(pctl
, grp
);
360 if ((input
&& (setting
->flags
& MVEBU_SETTING_GPI
)) ||
361 (!input
&& (setting
->flags
& MVEBU_SETTING_GPO
)))
367 static const struct pinmux_ops mvebu_pinmux_ops
= {
368 .get_functions_count
= mvebu_pinmux_get_funcs_count
,
369 .get_function_name
= mvebu_pinmux_get_func_name
,
370 .get_function_groups
= mvebu_pinmux_get_groups
,
371 .gpio_request_enable
= mvebu_pinmux_gpio_request_enable
,
372 .gpio_set_direction
= mvebu_pinmux_gpio_set_direction
,
373 .set_mux
= mvebu_pinmux_set
,
376 static int mvebu_pinctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
378 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
379 return pctl
->num_groups
;
382 static const char *mvebu_pinctrl_get_group_name(struct pinctrl_dev
*pctldev
,
385 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
386 return pctl
->groups
[gid
].name
;
389 static int mvebu_pinctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
390 unsigned gid
, const unsigned **pins
,
393 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
394 *pins
= pctl
->groups
[gid
].pins
;
395 *num_pins
= pctl
->groups
[gid
].npins
;
399 static int mvebu_pinctrl_dt_node_to_map(struct pinctrl_dev
*pctldev
,
400 struct device_node
*np
,
401 struct pinctrl_map
**map
,
404 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
405 struct property
*prop
;
406 const char *function
;
413 ret
= of_property_read_string(np
, "marvell,function", &function
);
416 "missing marvell,function in node %s\n", np
->name
);
420 nmaps
= of_property_count_strings(np
, "marvell,pins");
423 "missing marvell,pins in node %s\n", np
->name
);
427 *map
= kmalloc_array(nmaps
, sizeof(**map
), GFP_KERNEL
);
432 of_property_for_each_string(np
, "marvell,pins", prop
, group
) {
433 struct mvebu_pinctrl_group
*grp
=
434 mvebu_pinctrl_find_group_by_name(pctl
, group
);
437 dev_err(pctl
->dev
, "unknown pin %s", group
);
441 if (!mvebu_pinctrl_find_setting_by_name(pctl
, grp
, function
)) {
442 dev_err(pctl
->dev
, "unsupported function %s on pin %s",
447 (*map
)[n
].type
= PIN_MAP_TYPE_MUX_GROUP
;
448 (*map
)[n
].data
.mux
.group
= group
;
449 (*map
)[n
].data
.mux
.function
= function
;
458 static void mvebu_pinctrl_dt_free_map(struct pinctrl_dev
*pctldev
,
459 struct pinctrl_map
*map
, unsigned num_maps
)
464 static const struct pinctrl_ops mvebu_pinctrl_ops
= {
465 .get_groups_count
= mvebu_pinctrl_get_groups_count
,
466 .get_group_name
= mvebu_pinctrl_get_group_name
,
467 .get_group_pins
= mvebu_pinctrl_get_group_pins
,
468 .dt_node_to_map
= mvebu_pinctrl_dt_node_to_map
,
469 .dt_free_map
= mvebu_pinctrl_dt_free_map
,
472 static int _add_function(struct mvebu_pinctrl_function
*funcs
, int *funcsize
,
478 while (funcs
->num_groups
) {
479 /* function already there */
480 if (strcmp(funcs
->name
, name
) == 0) {
487 /* append new unique function */
489 funcs
->num_groups
= 1;
495 static int mvebu_pinctrl_build_functions(struct platform_device
*pdev
,
496 struct mvebu_pinctrl
*pctl
)
498 struct mvebu_pinctrl_function
*funcs
;
499 int num
= 0, funcsize
= pctl
->desc
.npins
;
502 /* we allocate functions for number of pins and hope
503 * there are fewer unique functions than pins available */
504 funcs
= devm_kcalloc(&pdev
->dev
,
505 funcsize
, sizeof(struct mvebu_pinctrl_function
),
510 for (n
= 0; n
< pctl
->num_groups
; n
++) {
511 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[n
];
512 for (s
= 0; s
< grp
->num_settings
; s
++) {
515 /* skip unsupported settings on this variant */
517 !(pctl
->variant
& grp
->settings
[s
].variant
))
520 /* check for unique functions and count groups */
521 ret
= _add_function(funcs
, &funcsize
,
522 grp
->settings
[s
].name
);
523 if (ret
== -EOVERFLOW
)
525 "More functions than pins(%d)\n",
534 pctl
->num_functions
= num
;
535 pctl
->functions
= funcs
;
537 for (n
= 0; n
< pctl
->num_groups
; n
++) {
538 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[n
];
539 for (s
= 0; s
< grp
->num_settings
; s
++) {
540 struct mvebu_pinctrl_function
*f
;
543 /* skip unsupported settings on this variant */
545 !(pctl
->variant
& grp
->settings
[s
].variant
))
548 f
= mvebu_pinctrl_find_function_by_name(pctl
,
549 grp
->settings
[s
].name
);
551 /* allocate group name array if not done already */
553 f
->groups
= devm_kcalloc(&pdev
->dev
,
561 /* find next free group name and assign current name */
572 int mvebu_pinctrl_probe(struct platform_device
*pdev
)
574 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
575 struct mvebu_pinctrl
*pctl
;
576 struct pinctrl_pin_desc
*pdesc
;
578 unsigned size
, noname
= 0;
583 if (!soc
|| !soc
->controls
|| !soc
->modes
) {
584 dev_err(&pdev
->dev
, "wrong pinctrl soc info\n");
588 pctl
= devm_kzalloc(&pdev
->dev
, sizeof(struct mvebu_pinctrl
),
593 pctl
->desc
.name
= dev_name(&pdev
->dev
);
594 pctl
->desc
.owner
= THIS_MODULE
;
595 pctl
->desc
.pctlops
= &mvebu_pinctrl_ops
;
596 pctl
->desc
.pmxops
= &mvebu_pinmux_ops
;
597 pctl
->desc
.confops
= &mvebu_pinconf_ops
;
598 pctl
->variant
= soc
->variant
;
599 pctl
->dev
= &pdev
->dev
;
600 platform_set_drvdata(pdev
, pctl
);
602 /* count controls and create names for mvebu generic
603 register controls; also does sanity checks */
604 pctl
->num_groups
= 0;
605 pctl
->desc
.npins
= 0;
606 for (n
= 0; n
< soc
->ncontrols
; n
++) {
607 const struct mvebu_mpp_ctrl
*ctrl
= &soc
->controls
[n
];
609 pctl
->desc
.npins
+= ctrl
->npins
;
610 /* initialize control's pins[] array */
611 for (k
= 0; k
< ctrl
->npins
; k
++)
612 ctrl
->pins
[k
] = ctrl
->pid
+ k
;
615 * We allow to pass controls with NULL name that we treat
616 * as a range of one-pin groups with generic mvebu register
620 pctl
->num_groups
+= ctrl
->npins
;
621 noname
+= ctrl
->npins
;
623 pctl
->num_groups
+= 1;
627 pdesc
= devm_kcalloc(&pdev
->dev
,
629 sizeof(struct pinctrl_pin_desc
),
634 for (n
= 0; n
< pctl
->desc
.npins
; n
++)
636 pctl
->desc
.pins
= pdesc
;
639 * allocate groups and name buffers for unnamed groups.
641 size
= pctl
->num_groups
* sizeof(*pctl
->groups
) + noname
* 8;
642 p
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
647 noname_buf
= p
+ pctl
->num_groups
* sizeof(*pctl
->groups
);
649 /* assign mpp controls to groups */
651 for (n
= 0; n
< soc
->ncontrols
; n
++) {
652 const struct mvebu_mpp_ctrl
*ctrl
= &soc
->controls
[n
];
653 struct mvebu_mpp_ctrl_data
*data
= soc
->control_data
?
654 &soc
->control_data
[n
] : NULL
;
656 pctl
->groups
[gid
].gid
= gid
;
657 pctl
->groups
[gid
].ctrl
= ctrl
;
658 pctl
->groups
[gid
].data
= data
;
659 pctl
->groups
[gid
].name
= ctrl
->name
;
660 pctl
->groups
[gid
].pins
= ctrl
->pins
;
661 pctl
->groups
[gid
].npins
= ctrl
->npins
;
664 * We treat unnamed controls as a range of one-pin groups
665 * with generic mvebu register controls. Use one group for
666 * each in this range and assign a default group name.
669 pctl
->groups
[gid
].name
= noname_buf
;
670 pctl
->groups
[gid
].npins
= 1;
671 sprintf(noname_buf
, "mpp%d", ctrl
->pid
+0);
674 for (k
= 1; k
< ctrl
->npins
; k
++) {
676 pctl
->groups
[gid
].gid
= gid
;
677 pctl
->groups
[gid
].ctrl
= ctrl
;
678 pctl
->groups
[gid
].data
= data
;
679 pctl
->groups
[gid
].name
= noname_buf
;
680 pctl
->groups
[gid
].pins
= &ctrl
->pins
[k
];
681 pctl
->groups
[gid
].npins
= 1;
682 sprintf(noname_buf
, "mpp%d", ctrl
->pid
+k
);
689 /* assign mpp modes to groups */
690 for (n
= 0; n
< soc
->nmodes
; n
++) {
691 struct mvebu_mpp_mode
*mode
= &soc
->modes
[n
];
692 struct mvebu_mpp_ctrl_setting
*set
= &mode
->settings
[0];
693 struct mvebu_pinctrl_group
*grp
;
694 unsigned num_settings
;
695 unsigned supp_settings
;
697 for (num_settings
= 0, supp_settings
= 0; ; set
++) {
703 /* skip unsupported settings for this variant */
704 if (pctl
->variant
&& !(pctl
->variant
& set
->variant
))
709 /* find gpio/gpo/gpi settings */
710 if (strcmp(set
->name
, "gpio") == 0)
711 set
->flags
= MVEBU_SETTING_GPI
|
713 else if (strcmp(set
->name
, "gpo") == 0)
714 set
->flags
= MVEBU_SETTING_GPO
;
715 else if (strcmp(set
->name
, "gpi") == 0)
716 set
->flags
= MVEBU_SETTING_GPI
;
719 /* skip modes with no settings for this variant */
723 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, mode
->pid
);
725 dev_warn(&pdev
->dev
, "unknown pinctrl group %d\n",
730 grp
->settings
= mode
->settings
;
731 grp
->num_settings
= num_settings
;
734 ret
= mvebu_pinctrl_build_functions(pdev
, pctl
);
736 dev_err(&pdev
->dev
, "unable to build functions\n");
740 pctl
->pctldev
= devm_pinctrl_register(&pdev
->dev
, &pctl
->desc
, pctl
);
741 if (IS_ERR(pctl
->pctldev
)) {
742 dev_err(&pdev
->dev
, "unable to register pinctrl driver\n");
743 return PTR_ERR(pctl
->pctldev
);
746 dev_info(&pdev
->dev
, "registered pinctrl driver\n");
748 /* register gpio ranges */
749 for (n
= 0; n
< soc
->ngpioranges
; n
++)
750 pinctrl_add_gpio_range(pctl
->pctldev
, &soc
->gpioranges
[n
]);
756 * mvebu_pinctrl_simple_mmio_probe - probe a simple mmio pinctrl
757 * @pdev: platform device (with platform data already attached)
759 * Initialise a simple (single base address) mmio pinctrl driver,
760 * assigning the MMIO base address to all mvebu mpp ctrl instances.
762 int mvebu_pinctrl_simple_mmio_probe(struct platform_device
*pdev
)
764 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
765 struct mvebu_mpp_ctrl_data
*mpp_data
;
766 struct resource
*res
;
770 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
771 base
= devm_ioremap_resource(&pdev
->dev
, res
);
773 return PTR_ERR(base
);
775 mpp_data
= devm_kcalloc(&pdev
->dev
, soc
->ncontrols
, sizeof(*mpp_data
),
780 for (i
= 0; i
< soc
->ncontrols
; i
++)
781 mpp_data
[i
].base
= base
;
783 soc
->control_data
= mpp_data
;
785 return mvebu_pinctrl_probe(pdev
);
788 int mvebu_regmap_mpp_ctrl_get(struct mvebu_mpp_ctrl_data
*data
,
789 unsigned int pid
, unsigned long *config
)
791 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
792 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
796 err
= regmap_read(data
->regmap
.map
, data
->regmap
.offset
+ off
, &val
);
800 *config
= (val
>> shift
) & MVEBU_MPP_MASK
;
805 int mvebu_regmap_mpp_ctrl_set(struct mvebu_mpp_ctrl_data
*data
,
806 unsigned int pid
, unsigned long config
)
808 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
809 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
811 return regmap_update_bits(data
->regmap
.map
, data
->regmap
.offset
+ off
,
812 MVEBU_MPP_MASK
<< shift
, config
<< shift
);
815 int mvebu_pinctrl_simple_regmap_probe(struct platform_device
*pdev
,
816 struct device
*syscon_dev
, u32 offset
)
818 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
819 struct mvebu_mpp_ctrl_data
*mpp_data
;
820 struct regmap
*regmap
;
823 regmap
= syscon_node_to_regmap(syscon_dev
->of_node
);
825 return PTR_ERR(regmap
);
827 mpp_data
= devm_kcalloc(&pdev
->dev
, soc
->ncontrols
, sizeof(*mpp_data
),
832 for (i
= 0; i
< soc
->ncontrols
; i
++) {
833 mpp_data
[i
].regmap
.map
= regmap
;
834 mpp_data
[i
].regmap
.offset
= offset
;
837 soc
->control_data
= mpp_data
;
839 return mvebu_pinctrl_probe(pdev
);