14 #include <linux/module.h>
15 #include <linux/slab.h>
30 #define MPPS_PER_REG 8
67 if (pid >= pctl->
groups[n].pins[0] &&
92 if (config == grp->
settings[n].val) {
149 unsigned long *config)
164 unsigned long config)
173 reg |= (config << shift);
179 static int mvebu_pinconf_group_get(
struct pinctrl_dev *pctldev,
180 unsigned gid,
unsigned long *config)
188 if (grp->
ctrl->mpp_get)
189 return grp->
ctrl->mpp_get(grp->
ctrl, config);
191 return mvebu_common_mpp_get(pctl, grp, config);
194 static int mvebu_pinconf_group_set(
struct pinctrl_dev *pctldev,
195 unsigned gid,
unsigned long config)
203 if (grp->
ctrl->mpp_set)
204 return grp->
ctrl->mpp_set(grp->
ctrl, config);
206 return mvebu_common_mpp_set(pctl, grp, config);
209 static void mvebu_pinconf_group_dbg_show(
struct pinctrl_dev *pctldev,
218 if (mvebu_pinconf_group_get(pctldev, gid, &config))
221 curr = mvebu_pinctrl_find_setting_by_val(pctl, grp, config);
267 static struct pinconf_ops mvebu_pinconf_ops = {
268 .pin_config_group_get = mvebu_pinconf_group_get,
269 .pin_config_group_set = mvebu_pinconf_group_set,
270 .pin_config_group_dbg_show = mvebu_pinconf_group_dbg_show,
273 static int mvebu_pinmux_get_funcs_count(
struct pinctrl_dev *pctldev)
280 static const char *mvebu_pinmux_get_func_name(
struct pinctrl_dev *pctldev,
288 static int mvebu_pinmux_get_groups(
struct pinctrl_dev *pctldev,
unsigned fid,
289 const char *
const **
groups,
299 static int mvebu_pinmux_enable(
struct pinctrl_dev *pctldev,
unsigned fid,
308 setting = mvebu_pinctrl_find_setting_by_name(pctl, grp,
312 "unable to find setting %s in group %s\n",
317 ret = mvebu_pinconf_group_set(pctldev, grp->
gid, setting->
val);
319 dev_err(pctl->
dev,
"cannot set group %s to %s\n",
327 static int mvebu_pinmux_gpio_request_enable(
struct pinctrl_dev *pctldev,
334 grp = mvebu_pinctrl_find_group_by_pid(pctl, offset);
338 if (grp->
ctrl->mpp_gpio_req)
339 return grp->
ctrl->mpp_gpio_req(grp->
ctrl, offset);
341 setting = mvebu_pinctrl_find_gpio_setting(pctl, grp);
345 return mvebu_pinconf_group_set(pctldev, grp->
gid, setting->
val);
348 static int mvebu_pinmux_gpio_set_direction(
struct pinctrl_dev *pctldev,
349 struct pinctrl_gpio_range *range,
unsigned offset,
bool input)
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->
ctrl, offset, input);
362 setting = mvebu_pinctrl_find_gpio_setting(pctl, grp);
373 static 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 .enable = mvebu_pinmux_enable,
382 static int mvebu_pinctrl_get_groups_count(
struct pinctrl_dev *pctldev)
388 static const char *mvebu_pinctrl_get_group_name(
struct pinctrl_dev *pctldev,
395 static int mvebu_pinctrl_get_group_pins(
struct pinctrl_dev *pctldev,
396 unsigned gid,
const unsigned **
pins,
405 static int mvebu_pinctrl_dt_node_to_map(
struct pinctrl_dev *pctldev,
412 const char *
function;
422 "missing marvell,function in node %s\n", np->
name);
429 "missing marvell,pins in node %s\n", np->
name);
436 "cannot allocate pinctrl_map memory for %s\n",
444 mvebu_pinctrl_find_group_by_name(pctl, group);
451 if (!mvebu_pinctrl_find_setting_by_name(pctl, grp,
function)) {
452 dev_err(pctl->
dev,
"unsupported function %s on pin %s",
458 (*map)[
n].data.mux.group =
group;
459 (*map)[
n].data.mux.function =
function;
468 static void mvebu_pinctrl_dt_free_map(
struct pinctrl_dev *pctldev,
474 static struct pinctrl_ops mvebu_pinctrl_ops = {
475 .get_groups_count = mvebu_pinctrl_get_groups_count,
476 .get_group_name = mvebu_pinctrl_get_group_name,
477 .get_group_pins = mvebu_pinctrl_get_group_pins,
478 .dt_node_to_map = mvebu_pinctrl_dt_node_to_map,
479 .dt_free_map = mvebu_pinctrl_dt_free_map,
521 if (_add_function(funcs, grp->
settings[s].name))
549 f = mvebu_pinctrl_find_function_by_name(pctl,
578 struct pinctrl_pin_desc *
pdesc;
583 dev_err(&pdev->
dev,
"wrong pinctrl soc info\n");
589 dev_err(&pdev->
dev,
"unable to get base address\n");
596 dev_err(&pdev->
dev,
"unable to alloc driver\n");
600 pctl->
desc.name = dev_name(&pdev->
dev);
602 pctl->
desc.pctlops = &mvebu_pinctrl_ops;
603 pctl->
desc.pmxops = &mvebu_pinmux_ops;
604 pctl->
desc.confops = &mvebu_pinconf_ops;
608 platform_set_drvdata(pdev, pctl);
613 pctl->
desc.npins = 0;
620 for (k = 0; k < ctrl->
npins; k++)
626 dev_err(&pdev->
dev,
"wrong soc control info\n");
636 dev_err(&pdev->
dev,
"failed to alloc mpp names\n");
639 for (k = 0; k < ctrl->
npins; k++)
648 dev_err(&pdev->
dev,
"failed to alloc pinctrl pins\n");
652 for (n = 0; n < pctl->
desc.npins; n++)
654 pctl->
desc.pins = pdesc;
659 dev_err(&pdev->
dev,
"failed to alloc pinctrl groups\n");
677 for (k = 1; k < ctrl->
npins; k++) {
690 for (n = 0; n < soc->
nmodes; n++) {
693 mvebu_pinctrl_find_group_by_pid(pctl, mode->
pid);
702 for (num_settings = 0; ;) {
728 ret = mvebu_pinctrl_build_functions(pdev, pctl);
730 dev_err(&pdev->
dev,
"unable to build functions\n");
736 dev_err(&pdev->
dev,
"unable to register pinctrl driver\n");
740 dev_info(&pdev->
dev,
"registered pinctrl driver\n");