1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Marvell MVEBU pinctrl core driver
5 * Authors: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
6 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10 #include <linux/gpio/driver.h>
12 #include <linux/mfd/syscon.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
16 #include <linux/seq_file.h>
17 #include <linux/slab.h>
19 #include <linux/pinctrl/machine.h>
20 #include <linux/pinctrl/pinconf.h>
21 #include <linux/pinctrl/pinctrl.h>
22 #include <linux/pinctrl/pinmux.h>
24 #include "pinctrl-mvebu.h"
26 #define MPPS_PER_REG 8
30 struct mvebu_pinctrl_function
{
36 struct mvebu_pinctrl_group
{
38 const struct mvebu_mpp_ctrl
*ctrl
;
39 struct mvebu_mpp_ctrl_data
*data
;
40 struct mvebu_mpp_ctrl_setting
*settings
;
41 unsigned num_settings
;
47 struct mvebu_pinctrl
{
49 struct pinctrl_dev
*pctldev
;
50 struct pinctrl_desc desc
;
51 struct mvebu_pinctrl_group
*groups
;
53 struct mvebu_pinctrl_function
*functions
;
54 unsigned num_functions
;
58 int mvebu_mmio_mpp_ctrl_get(struct mvebu_mpp_ctrl_data
*data
,
59 unsigned int pid
, unsigned long *config
)
61 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
62 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
64 *config
= (readl(data
->base
+ off
) >> shift
) & MVEBU_MPP_MASK
;
69 int mvebu_mmio_mpp_ctrl_set(struct mvebu_mpp_ctrl_data
*data
,
70 unsigned int pid
, unsigned long config
)
72 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
73 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
76 reg
= readl(data
->base
+ off
) & ~(MVEBU_MPP_MASK
<< shift
);
77 writel(reg
| (config
<< shift
), data
->base
+ off
);
82 static struct mvebu_pinctrl_group
*mvebu_pinctrl_find_group_by_pid(
83 struct mvebu_pinctrl
*pctl
, unsigned pid
)
86 for (n
= 0; n
< pctl
->num_groups
; n
++) {
87 if (pid
>= pctl
->groups
[n
].pins
[0] &&
88 pid
< pctl
->groups
[n
].pins
[0] +
89 pctl
->groups
[n
].npins
)
90 return &pctl
->groups
[n
];
95 static struct mvebu_pinctrl_group
*mvebu_pinctrl_find_group_by_name(
96 struct mvebu_pinctrl
*pctl
, const char *name
)
100 for (n
= 0; n
< pctl
->num_groups
; n
++) {
101 if (strcmp(name
, pctl
->groups
[n
].name
) == 0)
102 return &pctl
->groups
[n
];
108 static struct mvebu_mpp_ctrl_setting
*mvebu_pinctrl_find_setting_by_val(
109 struct mvebu_pinctrl
*pctl
, struct mvebu_pinctrl_group
*grp
,
110 unsigned long config
)
114 for (n
= 0; n
< grp
->num_settings
; n
++) {
115 if (config
== grp
->settings
[n
].val
) {
116 if (!pctl
->variant
|| (pctl
->variant
&
117 grp
->settings
[n
].variant
))
118 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
,
131 for (n
= 0; n
< grp
->num_settings
; n
++) {
132 if (strcmp(name
, grp
->settings
[n
].name
) == 0) {
133 if (!pctl
->variant
|| (pctl
->variant
&
134 grp
->settings
[n
].variant
))
135 return &grp
->settings
[n
];
142 static struct mvebu_mpp_ctrl_setting
*mvebu_pinctrl_find_gpio_setting(
143 struct mvebu_pinctrl
*pctl
, struct mvebu_pinctrl_group
*grp
)
147 for (n
= 0; n
< grp
->num_settings
; n
++) {
148 if (grp
->settings
[n
].flags
&
149 (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
150 if (!pctl
->variant
|| (pctl
->variant
&
151 grp
->settings
[n
].variant
))
152 return &grp
->settings
[n
];
159 static struct mvebu_pinctrl_function
*mvebu_pinctrl_find_function_by_name(
160 struct mvebu_pinctrl
*pctl
, const char *name
)
164 for (n
= 0; n
< pctl
->num_functions
; n
++) {
165 if (strcmp(name
, pctl
->functions
[n
].name
) == 0)
166 return &pctl
->functions
[n
];
172 static int mvebu_pinconf_group_get(struct pinctrl_dev
*pctldev
,
173 unsigned gid
, unsigned long *config
)
175 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
176 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
181 return grp
->ctrl
->mpp_get(grp
->data
, grp
->pins
[0], config
);
184 static int mvebu_pinconf_group_set(struct pinctrl_dev
*pctldev
,
185 unsigned gid
, unsigned long *configs
,
186 unsigned num_configs
)
188 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
189 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
195 for (i
= 0; i
< num_configs
; i
++) {
196 ret
= grp
->ctrl
->mpp_set(grp
->data
, grp
->pins
[0], configs
[i
]);
199 } /* for each config */
204 static void mvebu_pinconf_group_dbg_show(struct pinctrl_dev
*pctldev
,
205 struct seq_file
*s
, unsigned gid
)
207 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
208 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
209 struct mvebu_mpp_ctrl_setting
*curr
;
210 unsigned long config
;
213 if (mvebu_pinconf_group_get(pctldev
, gid
, &config
))
216 curr
= mvebu_pinctrl_find_setting_by_val(pctl
, grp
, config
);
219 seq_printf(s
, "current: %s", curr
->name
);
221 seq_printf(s
, "(%s)", curr
->subname
);
222 if (curr
->flags
& (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
224 if (curr
->flags
& MVEBU_SETTING_GPI
)
226 if (curr
->flags
& MVEBU_SETTING_GPO
)
231 seq_puts(s
, "current: UNKNOWN");
234 if (grp
->num_settings
> 1) {
235 seq_puts(s
, ", available = [");
236 for (n
= 0; n
< grp
->num_settings
; n
++) {
237 if (curr
== &grp
->settings
[n
])
240 /* skip unsupported settings for this variant */
242 !(pctl
->variant
& grp
->settings
[n
].variant
))
245 seq_printf(s
, " %s", grp
->settings
[n
].name
);
246 if (grp
->settings
[n
].subname
)
247 seq_printf(s
, "(%s)", grp
->settings
[n
].subname
);
248 if (grp
->settings
[n
].flags
&
249 (MVEBU_SETTING_GPO
| MVEBU_SETTING_GPI
)) {
251 if (grp
->settings
[n
].flags
& MVEBU_SETTING_GPI
)
253 if (grp
->settings
[n
].flags
& MVEBU_SETTING_GPO
)
262 static const struct pinconf_ops mvebu_pinconf_ops
= {
263 .pin_config_group_get
= mvebu_pinconf_group_get
,
264 .pin_config_group_set
= mvebu_pinconf_group_set
,
265 .pin_config_group_dbg_show
= mvebu_pinconf_group_dbg_show
,
268 static int mvebu_pinmux_get_funcs_count(struct pinctrl_dev
*pctldev
)
270 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
272 return pctl
->num_functions
;
275 static const char *mvebu_pinmux_get_func_name(struct pinctrl_dev
*pctldev
,
278 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
280 return pctl
->functions
[fid
].name
;
283 static int mvebu_pinmux_get_groups(struct pinctrl_dev
*pctldev
, unsigned fid
,
284 const char * const **groups
,
285 unsigned * const num_groups
)
287 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
289 *groups
= pctl
->functions
[fid
].groups
;
290 *num_groups
= pctl
->functions
[fid
].num_groups
;
294 static int mvebu_pinmux_set(struct pinctrl_dev
*pctldev
, unsigned fid
,
297 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
298 struct mvebu_pinctrl_function
*func
= &pctl
->functions
[fid
];
299 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[gid
];
300 struct mvebu_mpp_ctrl_setting
*setting
;
302 unsigned long config
;
304 setting
= mvebu_pinctrl_find_setting_by_name(pctl
, grp
,
308 "unable to find setting %s in group %s\n",
309 func
->name
, func
->groups
[gid
]);
313 config
= setting
->val
;
314 ret
= mvebu_pinconf_group_set(pctldev
, grp
->gid
, &config
, 1);
316 dev_err(pctl
->dev
, "cannot set group %s to %s\n",
317 func
->groups
[gid
], func
->name
);
324 static int mvebu_pinmux_gpio_request_enable(struct pinctrl_dev
*pctldev
,
325 struct pinctrl_gpio_range
*range
, unsigned offset
)
327 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
328 struct mvebu_pinctrl_group
*grp
;
329 struct mvebu_mpp_ctrl_setting
*setting
;
330 unsigned long config
;
332 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, offset
);
336 if (grp
->ctrl
->mpp_gpio_req
)
337 return grp
->ctrl
->mpp_gpio_req(grp
->data
, offset
);
339 setting
= mvebu_pinctrl_find_gpio_setting(pctl
, grp
);
343 config
= setting
->val
;
345 return mvebu_pinconf_group_set(pctldev
, grp
->gid
, &config
, 1);
348 static int mvebu_pinmux_gpio_set_direction(struct pinctrl_dev
*pctldev
,
349 struct pinctrl_gpio_range
*range
, unsigned offset
, bool input
)
351 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
352 struct mvebu_pinctrl_group
*grp
;
353 struct mvebu_mpp_ctrl_setting
*setting
;
355 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, offset
);
359 if (grp
->ctrl
->mpp_gpio_dir
)
360 return grp
->ctrl
->mpp_gpio_dir(grp
->data
, offset
, input
);
362 setting
= mvebu_pinctrl_find_gpio_setting(pctl
, grp
);
366 if ((input
&& (setting
->flags
& MVEBU_SETTING_GPI
)) ||
367 (!input
&& (setting
->flags
& MVEBU_SETTING_GPO
)))
373 static const struct pinmux_ops mvebu_pinmux_ops
= {
374 .get_functions_count
= mvebu_pinmux_get_funcs_count
,
375 .get_function_name
= mvebu_pinmux_get_func_name
,
376 .get_function_groups
= mvebu_pinmux_get_groups
,
377 .gpio_request_enable
= mvebu_pinmux_gpio_request_enable
,
378 .gpio_set_direction
= mvebu_pinmux_gpio_set_direction
,
379 .set_mux
= mvebu_pinmux_set
,
382 static int mvebu_pinctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
384 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
385 return pctl
->num_groups
;
388 static const char *mvebu_pinctrl_get_group_name(struct pinctrl_dev
*pctldev
,
391 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
392 return pctl
->groups
[gid
].name
;
395 static int mvebu_pinctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
396 unsigned gid
, const unsigned **pins
,
399 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
400 *pins
= pctl
->groups
[gid
].pins
;
401 *num_pins
= pctl
->groups
[gid
].npins
;
405 static int mvebu_pinctrl_dt_node_to_map(struct pinctrl_dev
*pctldev
,
406 struct device_node
*np
,
407 struct pinctrl_map
**map
,
410 struct mvebu_pinctrl
*pctl
= pinctrl_dev_get_drvdata(pctldev
);
411 struct property
*prop
;
412 const char *function
;
419 ret
= of_property_read_string(np
, "marvell,function", &function
);
422 "missing marvell,function in node %pOFn\n", np
);
426 nmaps
= of_property_count_strings(np
, "marvell,pins");
429 "missing marvell,pins in node %pOFn\n", np
);
433 *map
= kmalloc_array(nmaps
, sizeof(**map
), GFP_KERNEL
);
438 of_property_for_each_string(np
, "marvell,pins", prop
, group
) {
439 struct mvebu_pinctrl_group
*grp
=
440 mvebu_pinctrl_find_group_by_name(pctl
, group
);
443 dev_err(pctl
->dev
, "unknown pin %s", group
);
447 if (!mvebu_pinctrl_find_setting_by_name(pctl
, grp
, function
)) {
448 dev_err(pctl
->dev
, "unsupported function %s on pin %s",
453 (*map
)[n
].type
= PIN_MAP_TYPE_MUX_GROUP
;
454 (*map
)[n
].data
.mux
.group
= group
;
455 (*map
)[n
].data
.mux
.function
= function
;
464 static void mvebu_pinctrl_dt_free_map(struct pinctrl_dev
*pctldev
,
465 struct pinctrl_map
*map
, unsigned num_maps
)
470 static const struct pinctrl_ops mvebu_pinctrl_ops
= {
471 .get_groups_count
= mvebu_pinctrl_get_groups_count
,
472 .get_group_name
= mvebu_pinctrl_get_group_name
,
473 .get_group_pins
= mvebu_pinctrl_get_group_pins
,
474 .dt_node_to_map
= mvebu_pinctrl_dt_node_to_map
,
475 .dt_free_map
= mvebu_pinctrl_dt_free_map
,
478 static int _add_function(struct mvebu_pinctrl_function
*funcs
, int *funcsize
,
484 while (funcs
->num_groups
) {
485 /* function already there */
486 if (strcmp(funcs
->name
, name
) == 0) {
493 /* append new unique function */
495 funcs
->num_groups
= 1;
501 static int mvebu_pinctrl_build_functions(struct platform_device
*pdev
,
502 struct mvebu_pinctrl
*pctl
)
504 struct mvebu_pinctrl_function
*funcs
;
505 int num
= 0, funcsize
= pctl
->desc
.npins
;
508 /* we allocate functions for number of pins and hope
509 * there are fewer unique functions than pins available */
510 funcs
= devm_kcalloc(&pdev
->dev
,
511 funcsize
, sizeof(struct mvebu_pinctrl_function
),
516 for (n
= 0; n
< pctl
->num_groups
; n
++) {
517 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[n
];
518 for (s
= 0; s
< grp
->num_settings
; s
++) {
521 /* skip unsupported settings on this variant */
523 !(pctl
->variant
& grp
->settings
[s
].variant
))
526 /* check for unique functions and count groups */
527 ret
= _add_function(funcs
, &funcsize
,
528 grp
->settings
[s
].name
);
529 if (ret
== -EOVERFLOW
)
531 "More functions than pins(%d)\n",
540 pctl
->num_functions
= num
;
541 pctl
->functions
= funcs
;
543 for (n
= 0; n
< pctl
->num_groups
; n
++) {
544 struct mvebu_pinctrl_group
*grp
= &pctl
->groups
[n
];
545 for (s
= 0; s
< grp
->num_settings
; s
++) {
546 struct mvebu_pinctrl_function
*f
;
549 /* skip unsupported settings on this variant */
551 !(pctl
->variant
& grp
->settings
[s
].variant
))
554 f
= mvebu_pinctrl_find_function_by_name(pctl
,
555 grp
->settings
[s
].name
);
557 /* allocate group name array if not done already */
559 f
->groups
= devm_kcalloc(&pdev
->dev
,
567 /* find next free group name and assign current name */
578 int mvebu_pinctrl_probe(struct platform_device
*pdev
)
580 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
581 struct mvebu_pinctrl
*pctl
;
582 struct pinctrl_pin_desc
*pdesc
;
584 unsigned size
, noname
= 0;
589 if (!soc
|| !soc
->controls
|| !soc
->modes
) {
590 dev_err(&pdev
->dev
, "wrong pinctrl soc info\n");
594 pctl
= devm_kzalloc(&pdev
->dev
, sizeof(struct mvebu_pinctrl
),
599 pctl
->desc
.name
= dev_name(&pdev
->dev
);
600 pctl
->desc
.owner
= THIS_MODULE
;
601 pctl
->desc
.pctlops
= &mvebu_pinctrl_ops
;
602 pctl
->desc
.pmxops
= &mvebu_pinmux_ops
;
603 pctl
->desc
.confops
= &mvebu_pinconf_ops
;
604 pctl
->variant
= soc
->variant
;
605 pctl
->dev
= &pdev
->dev
;
606 platform_set_drvdata(pdev
, pctl
);
608 /* count controls and create names for mvebu generic
609 register controls; also does sanity checks */
610 pctl
->num_groups
= 0;
611 pctl
->desc
.npins
= 0;
612 for (n
= 0; n
< soc
->ncontrols
; n
++) {
613 const struct mvebu_mpp_ctrl
*ctrl
= &soc
->controls
[n
];
615 pctl
->desc
.npins
+= ctrl
->npins
;
616 /* initialize control's pins[] array */
617 for (k
= 0; k
< ctrl
->npins
; k
++)
618 ctrl
->pins
[k
] = ctrl
->pid
+ k
;
621 * We allow to pass controls with NULL name that we treat
622 * as a range of one-pin groups with generic mvebu register
626 pctl
->num_groups
+= ctrl
->npins
;
627 noname
+= ctrl
->npins
;
629 pctl
->num_groups
+= 1;
633 pdesc
= devm_kcalloc(&pdev
->dev
,
635 sizeof(struct pinctrl_pin_desc
),
640 for (n
= 0; n
< pctl
->desc
.npins
; n
++)
642 pctl
->desc
.pins
= pdesc
;
645 * allocate groups and name buffers for unnamed groups.
647 size
= pctl
->num_groups
* sizeof(*pctl
->groups
) + noname
* 8;
648 p
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
653 noname_buf
= p
+ pctl
->num_groups
* sizeof(*pctl
->groups
);
655 /* assign mpp controls to groups */
657 for (n
= 0; n
< soc
->ncontrols
; n
++) {
658 const struct mvebu_mpp_ctrl
*ctrl
= &soc
->controls
[n
];
659 struct mvebu_mpp_ctrl_data
*data
= soc
->control_data
?
660 &soc
->control_data
[n
] : NULL
;
662 pctl
->groups
[gid
].gid
= gid
;
663 pctl
->groups
[gid
].ctrl
= ctrl
;
664 pctl
->groups
[gid
].data
= data
;
665 pctl
->groups
[gid
].name
= ctrl
->name
;
666 pctl
->groups
[gid
].pins
= ctrl
->pins
;
667 pctl
->groups
[gid
].npins
= ctrl
->npins
;
670 * We treat unnamed controls as a range of one-pin groups
671 * with generic mvebu register controls. Use one group for
672 * each in this range and assign a default group name.
675 pctl
->groups
[gid
].name
= noname_buf
;
676 pctl
->groups
[gid
].npins
= 1;
677 sprintf(noname_buf
, "mpp%d", ctrl
->pid
+0);
680 for (k
= 1; k
< ctrl
->npins
; k
++) {
682 pctl
->groups
[gid
].gid
= gid
;
683 pctl
->groups
[gid
].ctrl
= ctrl
;
684 pctl
->groups
[gid
].data
= data
;
685 pctl
->groups
[gid
].name
= noname_buf
;
686 pctl
->groups
[gid
].pins
= &ctrl
->pins
[k
];
687 pctl
->groups
[gid
].npins
= 1;
688 sprintf(noname_buf
, "mpp%d", ctrl
->pid
+k
);
695 /* assign mpp modes to groups */
696 for (n
= 0; n
< soc
->nmodes
; n
++) {
697 struct mvebu_mpp_mode
*mode
= &soc
->modes
[n
];
698 struct mvebu_mpp_ctrl_setting
*set
= &mode
->settings
[0];
699 struct mvebu_pinctrl_group
*grp
;
700 unsigned num_settings
;
701 unsigned supp_settings
;
703 for (num_settings
= 0, supp_settings
= 0; ; set
++) {
709 /* skip unsupported settings for this variant */
710 if (pctl
->variant
&& !(pctl
->variant
& set
->variant
))
715 /* find gpio/gpo/gpi settings */
716 if (strcmp(set
->name
, "gpio") == 0)
717 set
->flags
= MVEBU_SETTING_GPI
|
719 else if (strcmp(set
->name
, "gpo") == 0)
720 set
->flags
= MVEBU_SETTING_GPO
;
721 else if (strcmp(set
->name
, "gpi") == 0)
722 set
->flags
= MVEBU_SETTING_GPI
;
725 /* skip modes with no settings for this variant */
729 grp
= mvebu_pinctrl_find_group_by_pid(pctl
, mode
->pid
);
731 dev_warn(&pdev
->dev
, "unknown pinctrl group %d\n",
736 grp
->settings
= mode
->settings
;
737 grp
->num_settings
= num_settings
;
740 ret
= mvebu_pinctrl_build_functions(pdev
, pctl
);
742 dev_err(&pdev
->dev
, "unable to build functions\n");
746 pctl
->pctldev
= devm_pinctrl_register(&pdev
->dev
, &pctl
->desc
, pctl
);
747 if (IS_ERR(pctl
->pctldev
)) {
748 dev_err(&pdev
->dev
, "unable to register pinctrl driver\n");
749 return PTR_ERR(pctl
->pctldev
);
752 dev_info(&pdev
->dev
, "registered pinctrl driver\n");
754 /* register gpio ranges */
755 for (n
= 0; n
< soc
->ngpioranges
; n
++)
756 pinctrl_add_gpio_range(pctl
->pctldev
, &soc
->gpioranges
[n
]);
762 * mvebu_pinctrl_simple_mmio_probe - probe a simple mmio pinctrl
763 * @pdev: platform device (with platform data already attached)
765 * Initialise a simple (single base address) mmio pinctrl driver,
766 * assigning the MMIO base address to all mvebu mpp ctrl instances.
768 int mvebu_pinctrl_simple_mmio_probe(struct platform_device
*pdev
)
770 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
771 struct mvebu_mpp_ctrl_data
*mpp_data
;
775 base
= devm_platform_ioremap_resource(pdev
, 0);
777 return PTR_ERR(base
);
779 mpp_data
= devm_kcalloc(&pdev
->dev
, soc
->ncontrols
, sizeof(*mpp_data
),
784 for (i
= 0; i
< soc
->ncontrols
; i
++)
785 mpp_data
[i
].base
= base
;
787 soc
->control_data
= mpp_data
;
789 return mvebu_pinctrl_probe(pdev
);
792 int mvebu_regmap_mpp_ctrl_get(struct mvebu_mpp_ctrl_data
*data
,
793 unsigned int pid
, unsigned long *config
)
795 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
796 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
800 err
= regmap_read(data
->regmap
.map
, data
->regmap
.offset
+ off
, &val
);
804 *config
= (val
>> shift
) & MVEBU_MPP_MASK
;
809 int mvebu_regmap_mpp_ctrl_set(struct mvebu_mpp_ctrl_data
*data
,
810 unsigned int pid
, unsigned long config
)
812 unsigned off
= (pid
/ MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
813 unsigned shift
= (pid
% MVEBU_MPPS_PER_REG
) * MVEBU_MPP_BITS
;
815 return regmap_update_bits(data
->regmap
.map
, data
->regmap
.offset
+ off
,
816 MVEBU_MPP_MASK
<< shift
, config
<< shift
);
819 int mvebu_pinctrl_simple_regmap_probe(struct platform_device
*pdev
,
820 struct device
*syscon_dev
, u32 offset
)
822 struct mvebu_pinctrl_soc_info
*soc
= dev_get_platdata(&pdev
->dev
);
823 struct mvebu_mpp_ctrl_data
*mpp_data
;
824 struct regmap
*regmap
;
827 regmap
= syscon_node_to_regmap(syscon_dev
->of_node
);
829 return PTR_ERR(regmap
);
831 mpp_data
= devm_kcalloc(&pdev
->dev
, soc
->ncontrols
, sizeof(*mpp_data
),
836 for (i
= 0; i
< soc
->ncontrols
; i
++) {
837 mpp_data
[i
].regmap
.map
= regmap
;
838 mpp_data
[i
].regmap
.offset
= offset
;
841 soc
->control_data
= mpp_data
;
843 return mvebu_pinctrl_probe(pdev
);