Lines Matching +full:gpi +full:- +full:config

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
24 #include "pinctrl-mvebu.h"
59 unsigned int pid, unsigned long *config) in mvebu_mmio_mpp_ctrl_get() argument
64 *config = (readl(data->base + off) >> shift) & MVEBU_MPP_MASK; in mvebu_mmio_mpp_ctrl_get()
70 unsigned int pid, unsigned long config) in mvebu_mmio_mpp_ctrl_set() argument
76 reg = readl(data->base + off) & ~(MVEBU_MPP_MASK << shift); in mvebu_mmio_mpp_ctrl_set()
77 writel(reg | (config << shift), data->base + off); in mvebu_mmio_mpp_ctrl_set()
86 for (n = 0; n < pctl->num_groups; n++) { in mvebu_pinctrl_find_group_by_pid()
87 if (pid >= pctl->groups[n].pins[0] && in mvebu_pinctrl_find_group_by_pid()
88 pid < pctl->groups[n].pins[0] + in mvebu_pinctrl_find_group_by_pid()
89 pctl->groups[n].npins) in mvebu_pinctrl_find_group_by_pid()
90 return &pctl->groups[n]; in mvebu_pinctrl_find_group_by_pid()
100 for (n = 0; n < pctl->num_groups; n++) { in mvebu_pinctrl_find_group_by_name()
101 if (strcmp(name, pctl->groups[n].name) == 0) in mvebu_pinctrl_find_group_by_name()
102 return &pctl->groups[n]; in mvebu_pinctrl_find_group_by_name()
110 unsigned long config) in mvebu_pinctrl_find_setting_by_val() argument
114 for (n = 0; n < grp->num_settings; n++) { in mvebu_pinctrl_find_setting_by_val()
115 if (config == grp->settings[n].val) { in mvebu_pinctrl_find_setting_by_val()
116 if (!pctl->variant || (pctl->variant & in mvebu_pinctrl_find_setting_by_val()
117 grp->settings[n].variant)) in mvebu_pinctrl_find_setting_by_val()
118 return &grp->settings[n]; in mvebu_pinctrl_find_setting_by_val()
131 for (n = 0; n < grp->num_settings; n++) { in mvebu_pinctrl_find_setting_by_name()
132 if (strcmp(name, grp->settings[n].name) == 0) { in mvebu_pinctrl_find_setting_by_name()
133 if (!pctl->variant || (pctl->variant & in mvebu_pinctrl_find_setting_by_name()
134 grp->settings[n].variant)) in mvebu_pinctrl_find_setting_by_name()
135 return &grp->settings[n]; in mvebu_pinctrl_find_setting_by_name()
147 for (n = 0; n < grp->num_settings; n++) { in mvebu_pinctrl_find_gpio_setting()
148 if (grp->settings[n].flags & in mvebu_pinctrl_find_gpio_setting()
150 if (!pctl->variant || (pctl->variant & in mvebu_pinctrl_find_gpio_setting()
151 grp->settings[n].variant)) in mvebu_pinctrl_find_gpio_setting()
152 return &grp->settings[n]; in mvebu_pinctrl_find_gpio_setting()
164 for (n = 0; n < pctl->num_functions; n++) { in mvebu_pinctrl_find_function_by_name()
165 if (strcmp(name, pctl->functions[n].name) == 0) in mvebu_pinctrl_find_function_by_name()
166 return &pctl->functions[n]; in mvebu_pinctrl_find_function_by_name()
173 unsigned gid, unsigned long *config) in mvebu_pinconf_group_get() argument
176 struct mvebu_pinctrl_group *grp = &pctl->groups[gid]; in mvebu_pinconf_group_get()
178 if (!grp->ctrl) in mvebu_pinconf_group_get()
179 return -EINVAL; in mvebu_pinconf_group_get()
181 return grp->ctrl->mpp_get(grp->data, grp->pins[0], config); in mvebu_pinconf_group_get()
189 struct mvebu_pinctrl_group *grp = &pctl->groups[gid]; in mvebu_pinconf_group_set()
192 if (!grp->ctrl) in mvebu_pinconf_group_set()
193 return -EINVAL; in mvebu_pinconf_group_set()
196 ret = grp->ctrl->mpp_set(grp->data, grp->pins[0], configs[i]); in mvebu_pinconf_group_set()
199 } /* for each config */ in mvebu_pinconf_group_set()
208 struct mvebu_pinctrl_group *grp = &pctl->groups[gid]; in mvebu_pinconf_group_dbg_show()
210 unsigned long config; in mvebu_pinconf_group_dbg_show() local
213 if (mvebu_pinconf_group_get(pctldev, gid, &config)) in mvebu_pinconf_group_dbg_show()
216 curr = mvebu_pinctrl_find_setting_by_val(pctl, grp, config); in mvebu_pinconf_group_dbg_show()
219 seq_printf(s, "current: %s", curr->name); in mvebu_pinconf_group_dbg_show()
220 if (curr->subname) in mvebu_pinconf_group_dbg_show()
221 seq_printf(s, "(%s)", curr->subname); in mvebu_pinconf_group_dbg_show()
222 if (curr->flags & (MVEBU_SETTING_GPO | MVEBU_SETTING_GPI)) { in mvebu_pinconf_group_dbg_show()
224 if (curr->flags & MVEBU_SETTING_GPI) in mvebu_pinconf_group_dbg_show()
226 if (curr->flags & MVEBU_SETTING_GPO) in mvebu_pinconf_group_dbg_show()
234 if (grp->num_settings > 1) { in mvebu_pinconf_group_dbg_show()
236 for (n = 0; n < grp->num_settings; n++) { in mvebu_pinconf_group_dbg_show()
237 if (curr == &grp->settings[n]) in mvebu_pinconf_group_dbg_show()
241 if (pctl->variant && in mvebu_pinconf_group_dbg_show()
242 !(pctl->variant & grp->settings[n].variant)) in mvebu_pinconf_group_dbg_show()
245 seq_printf(s, " %s", grp->settings[n].name); in mvebu_pinconf_group_dbg_show()
246 if (grp->settings[n].subname) in mvebu_pinconf_group_dbg_show()
247 seq_printf(s, "(%s)", grp->settings[n].subname); in mvebu_pinconf_group_dbg_show()
248 if (grp->settings[n].flags & in mvebu_pinconf_group_dbg_show()
251 if (grp->settings[n].flags & MVEBU_SETTING_GPI) in mvebu_pinconf_group_dbg_show()
253 if (grp->settings[n].flags & MVEBU_SETTING_GPO) in mvebu_pinconf_group_dbg_show()
272 return pctl->num_functions; in mvebu_pinmux_get_funcs_count()
280 return pctl->functions[fid].name; in mvebu_pinmux_get_func_name()
289 *groups = pctl->functions[fid].groups; in mvebu_pinmux_get_groups()
290 *num_groups = pctl->functions[fid].num_groups; in mvebu_pinmux_get_groups()
298 struct mvebu_pinctrl_function *func = &pctl->functions[fid]; in mvebu_pinmux_set()
299 struct mvebu_pinctrl_group *grp = &pctl->groups[gid]; in mvebu_pinmux_set()
302 unsigned long config; in mvebu_pinmux_set() local
305 func->name); in mvebu_pinmux_set()
307 dev_err(pctl->dev, in mvebu_pinmux_set()
309 func->name, func->groups[gid]); in mvebu_pinmux_set()
310 return -EINVAL; in mvebu_pinmux_set()
313 config = setting->val; in mvebu_pinmux_set()
314 ret = mvebu_pinconf_group_set(pctldev, grp->gid, &config, 1); in mvebu_pinmux_set()
316 dev_err(pctl->dev, "cannot set group %s to %s\n", in mvebu_pinmux_set()
317 func->groups[gid], func->name); in mvebu_pinmux_set()
330 unsigned long config; in mvebu_pinmux_gpio_request_enable() local
334 return -EINVAL; in mvebu_pinmux_gpio_request_enable()
336 if (grp->ctrl->mpp_gpio_req) in mvebu_pinmux_gpio_request_enable()
337 return grp->ctrl->mpp_gpio_req(grp->data, offset); in mvebu_pinmux_gpio_request_enable()
341 return -ENOTSUPP; in mvebu_pinmux_gpio_request_enable()
343 config = setting->val; in mvebu_pinmux_gpio_request_enable()
345 return mvebu_pinconf_group_set(pctldev, grp->gid, &config, 1); in mvebu_pinmux_gpio_request_enable()
357 return -EINVAL; in mvebu_pinmux_gpio_set_direction()
359 if (grp->ctrl->mpp_gpio_dir) in mvebu_pinmux_gpio_set_direction()
360 return grp->ctrl->mpp_gpio_dir(grp->data, offset, input); in mvebu_pinmux_gpio_set_direction()
364 return -ENOTSUPP; in mvebu_pinmux_gpio_set_direction()
366 if ((input && (setting->flags & MVEBU_SETTING_GPI)) || in mvebu_pinmux_gpio_set_direction()
367 (!input && (setting->flags & MVEBU_SETTING_GPO))) in mvebu_pinmux_gpio_set_direction()
370 return -ENOTSUPP; in mvebu_pinmux_gpio_set_direction()
385 return pctl->num_groups; in mvebu_pinctrl_get_groups_count()
392 return pctl->groups[gid].name; in mvebu_pinctrl_get_group_name()
400 *pins = pctl->groups[gid].pins; in mvebu_pinctrl_get_group_pins()
401 *num_pins = pctl->groups[gid].npins; in mvebu_pinctrl_get_group_pins()
421 dev_err(pctl->dev, in mvebu_pinctrl_dt_node_to_map()
428 dev_err(pctl->dev, in mvebu_pinctrl_dt_node_to_map()
435 return -ENOMEM; in mvebu_pinctrl_dt_node_to_map()
443 dev_err(pctl->dev, "unknown pin %s", group); in mvebu_pinctrl_dt_node_to_map()
448 dev_err(pctl->dev, "unsupported function %s on pin %s", in mvebu_pinctrl_dt_node_to_map()
482 return -EOVERFLOW; in _add_function()
484 while (funcs->num_groups) { in _add_function()
486 if (strcmp(funcs->name, name) == 0) { in _add_function()
487 funcs->num_groups++; in _add_function()
488 return -EEXIST; in _add_function()
494 funcs->name = name; in _add_function()
495 funcs->num_groups = 1; in _add_function()
496 (*funcsize)--; in _add_function()
505 int num = 0, funcsize = pctl->desc.npins; in mvebu_pinctrl_build_functions()
510 funcs = devm_kcalloc(&pdev->dev, in mvebu_pinctrl_build_functions()
514 return -ENOMEM; in mvebu_pinctrl_build_functions()
516 for (n = 0; n < pctl->num_groups; n++) { in mvebu_pinctrl_build_functions()
517 struct mvebu_pinctrl_group *grp = &pctl->groups[n]; in mvebu_pinctrl_build_functions()
518 for (s = 0; s < grp->num_settings; s++) { in mvebu_pinctrl_build_functions()
522 if (pctl->variant && in mvebu_pinctrl_build_functions()
523 !(pctl->variant & grp->settings[s].variant)) in mvebu_pinctrl_build_functions()
528 grp->settings[s].name); in mvebu_pinctrl_build_functions()
529 if (ret == -EOVERFLOW) in mvebu_pinctrl_build_functions()
530 dev_err(&pdev->dev, in mvebu_pinctrl_build_functions()
532 pctl->desc.npins); in mvebu_pinctrl_build_functions()
540 pctl->num_functions = num; in mvebu_pinctrl_build_functions()
541 pctl->functions = funcs; in mvebu_pinctrl_build_functions()
543 for (n = 0; n < pctl->num_groups; n++) { in mvebu_pinctrl_build_functions()
544 struct mvebu_pinctrl_group *grp = &pctl->groups[n]; in mvebu_pinctrl_build_functions()
545 for (s = 0; s < grp->num_settings; s++) { in mvebu_pinctrl_build_functions()
550 if (pctl->variant && in mvebu_pinctrl_build_functions()
551 !(pctl->variant & grp->settings[s].variant)) in mvebu_pinctrl_build_functions()
555 grp->settings[s].name); in mvebu_pinctrl_build_functions()
558 if (!f->groups) { in mvebu_pinctrl_build_functions()
559 f->groups = devm_kcalloc(&pdev->dev, in mvebu_pinctrl_build_functions()
560 f->num_groups, in mvebu_pinctrl_build_functions()
563 if (!f->groups) in mvebu_pinctrl_build_functions()
564 return -ENOMEM; in mvebu_pinctrl_build_functions()
568 groups = f->groups; in mvebu_pinctrl_build_functions()
571 *groups = grp->name; in mvebu_pinctrl_build_functions()
580 struct mvebu_pinctrl_soc_info *soc = dev_get_platdata(&pdev->dev); in mvebu_pinctrl_probe()
589 if (!soc || !soc->controls || !soc->modes) { in mvebu_pinctrl_probe()
590 dev_err(&pdev->dev, "wrong pinctrl soc info\n"); in mvebu_pinctrl_probe()
591 return -EINVAL; in mvebu_pinctrl_probe()
594 pctl = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pinctrl), in mvebu_pinctrl_probe()
597 return -ENOMEM; in mvebu_pinctrl_probe()
599 pctl->desc.name = dev_name(&pdev->dev); in mvebu_pinctrl_probe()
600 pctl->desc.owner = THIS_MODULE; in mvebu_pinctrl_probe()
601 pctl->desc.pctlops = &mvebu_pinctrl_ops; in mvebu_pinctrl_probe()
602 pctl->desc.pmxops = &mvebu_pinmux_ops; in mvebu_pinctrl_probe()
603 pctl->desc.confops = &mvebu_pinconf_ops; in mvebu_pinctrl_probe()
604 pctl->variant = soc->variant; in mvebu_pinctrl_probe()
605 pctl->dev = &pdev->dev; in mvebu_pinctrl_probe()
610 pctl->num_groups = 0; in mvebu_pinctrl_probe()
611 pctl->desc.npins = 0; in mvebu_pinctrl_probe()
612 for (n = 0; n < soc->ncontrols; n++) { in mvebu_pinctrl_probe()
613 const struct mvebu_mpp_ctrl *ctrl = &soc->controls[n]; in mvebu_pinctrl_probe()
615 pctl->desc.npins += ctrl->npins; in mvebu_pinctrl_probe()
617 for (k = 0; k < ctrl->npins; k++) in mvebu_pinctrl_probe()
618 ctrl->pins[k] = ctrl->pid + k; in mvebu_pinctrl_probe()
622 * as a range of one-pin groups with generic mvebu register in mvebu_pinctrl_probe()
625 if (!ctrl->name) { in mvebu_pinctrl_probe()
626 pctl->num_groups += ctrl->npins; in mvebu_pinctrl_probe()
627 noname += ctrl->npins; in mvebu_pinctrl_probe()
629 pctl->num_groups += 1; in mvebu_pinctrl_probe()
633 pdesc = devm_kcalloc(&pdev->dev, in mvebu_pinctrl_probe()
634 pctl->desc.npins, in mvebu_pinctrl_probe()
638 return -ENOMEM; in mvebu_pinctrl_probe()
640 for (n = 0; n < pctl->desc.npins; n++) in mvebu_pinctrl_probe()
642 pctl->desc.pins = pdesc; in mvebu_pinctrl_probe()
647 size = pctl->num_groups * sizeof(*pctl->groups) + noname * 8; in mvebu_pinctrl_probe()
648 p = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); in mvebu_pinctrl_probe()
650 return -ENOMEM; in mvebu_pinctrl_probe()
652 pctl->groups = p; in mvebu_pinctrl_probe()
653 noname_buf = p + pctl->num_groups * sizeof(*pctl->groups); in mvebu_pinctrl_probe()
657 for (n = 0; n < soc->ncontrols; n++) { in mvebu_pinctrl_probe()
658 const struct mvebu_mpp_ctrl *ctrl = &soc->controls[n]; in mvebu_pinctrl_probe()
659 struct mvebu_mpp_ctrl_data *data = soc->control_data ? in mvebu_pinctrl_probe()
660 &soc->control_data[n] : NULL; in mvebu_pinctrl_probe()
662 pctl->groups[gid].gid = gid; in mvebu_pinctrl_probe()
663 pctl->groups[gid].ctrl = ctrl; in mvebu_pinctrl_probe()
664 pctl->groups[gid].data = data; in mvebu_pinctrl_probe()
665 pctl->groups[gid].name = ctrl->name; in mvebu_pinctrl_probe()
666 pctl->groups[gid].pins = ctrl->pins; in mvebu_pinctrl_probe()
667 pctl->groups[gid].npins = ctrl->npins; in mvebu_pinctrl_probe()
670 * We treat unnamed controls as a range of one-pin groups in mvebu_pinctrl_probe()
674 if (!ctrl->name) { in mvebu_pinctrl_probe()
675 pctl->groups[gid].name = noname_buf; in mvebu_pinctrl_probe()
676 pctl->groups[gid].npins = 1; in mvebu_pinctrl_probe()
677 sprintf(noname_buf, "mpp%d", ctrl->pid+0); in mvebu_pinctrl_probe()
680 for (k = 1; k < ctrl->npins; k++) { in mvebu_pinctrl_probe()
682 pctl->groups[gid].gid = gid; in mvebu_pinctrl_probe()
683 pctl->groups[gid].ctrl = ctrl; in mvebu_pinctrl_probe()
684 pctl->groups[gid].data = data; in mvebu_pinctrl_probe()
685 pctl->groups[gid].name = noname_buf; in mvebu_pinctrl_probe()
686 pctl->groups[gid].pins = &ctrl->pins[k]; in mvebu_pinctrl_probe()
687 pctl->groups[gid].npins = 1; in mvebu_pinctrl_probe()
688 sprintf(noname_buf, "mpp%d", ctrl->pid+k); in mvebu_pinctrl_probe()
696 for (n = 0; n < soc->nmodes; n++) { in mvebu_pinctrl_probe()
697 struct mvebu_mpp_mode *mode = &soc->modes[n]; in mvebu_pinctrl_probe()
698 struct mvebu_mpp_ctrl_setting *set = &mode->settings[0]; in mvebu_pinctrl_probe()
704 if (!set->name) in mvebu_pinctrl_probe()
710 if (pctl->variant && !(pctl->variant & set->variant)) in mvebu_pinctrl_probe()
715 /* find gpio/gpo/gpi settings */ in mvebu_pinctrl_probe()
716 if (strcmp(set->name, "gpio") == 0) in mvebu_pinctrl_probe()
717 set->flags = MVEBU_SETTING_GPI | in mvebu_pinctrl_probe()
719 else if (strcmp(set->name, "gpo") == 0) in mvebu_pinctrl_probe()
720 set->flags = MVEBU_SETTING_GPO; in mvebu_pinctrl_probe()
721 else if (strcmp(set->name, "gpi") == 0) in mvebu_pinctrl_probe()
722 set->flags = MVEBU_SETTING_GPI; in mvebu_pinctrl_probe()
729 grp = mvebu_pinctrl_find_group_by_pid(pctl, mode->pid); in mvebu_pinctrl_probe()
731 dev_warn(&pdev->dev, "unknown pinctrl group %d\n", in mvebu_pinctrl_probe()
732 mode->pid); in mvebu_pinctrl_probe()
736 grp->settings = mode->settings; in mvebu_pinctrl_probe()
737 grp->num_settings = num_settings; in mvebu_pinctrl_probe()
742 dev_err(&pdev->dev, "unable to build functions\n"); in mvebu_pinctrl_probe()
746 pctl->pctldev = devm_pinctrl_register(&pdev->dev, &pctl->desc, pctl); in mvebu_pinctrl_probe()
747 if (IS_ERR(pctl->pctldev)) { in mvebu_pinctrl_probe()
748 dev_err(&pdev->dev, "unable to register pinctrl driver\n"); in mvebu_pinctrl_probe()
749 return PTR_ERR(pctl->pctldev); in mvebu_pinctrl_probe()
752 dev_info(&pdev->dev, "registered pinctrl driver\n"); in mvebu_pinctrl_probe()
755 for (n = 0; n < soc->ngpioranges; n++) in mvebu_pinctrl_probe()
756 pinctrl_add_gpio_range(pctl->pctldev, &soc->gpioranges[n]); in mvebu_pinctrl_probe()
762 * mvebu_pinctrl_simple_mmio_probe - probe a simple mmio pinctrl
770 struct mvebu_pinctrl_soc_info *soc = dev_get_platdata(&pdev->dev); in mvebu_pinctrl_simple_mmio_probe()
779 mpp_data = devm_kcalloc(&pdev->dev, soc->ncontrols, sizeof(*mpp_data), in mvebu_pinctrl_simple_mmio_probe()
782 return -ENOMEM; in mvebu_pinctrl_simple_mmio_probe()
784 for (i = 0; i < soc->ncontrols; i++) in mvebu_pinctrl_simple_mmio_probe()
787 soc->control_data = mpp_data; in mvebu_pinctrl_simple_mmio_probe()
793 unsigned int pid, unsigned long *config) in mvebu_regmap_mpp_ctrl_get() argument
800 err = regmap_read(data->regmap.map, data->regmap.offset + off, &val); in mvebu_regmap_mpp_ctrl_get()
804 *config = (val >> shift) & MVEBU_MPP_MASK; in mvebu_regmap_mpp_ctrl_get()
810 unsigned int pid, unsigned long config) in mvebu_regmap_mpp_ctrl_set() argument
815 return regmap_update_bits(data->regmap.map, data->regmap.offset + off, in mvebu_regmap_mpp_ctrl_set()
816 MVEBU_MPP_MASK << shift, config << shift); in mvebu_regmap_mpp_ctrl_set()
822 struct mvebu_pinctrl_soc_info *soc = dev_get_platdata(&pdev->dev); in mvebu_pinctrl_simple_regmap_probe()
827 regmap = syscon_node_to_regmap(syscon_dev->of_node); in mvebu_pinctrl_simple_regmap_probe()
831 mpp_data = devm_kcalloc(&pdev->dev, soc->ncontrols, sizeof(*mpp_data), in mvebu_pinctrl_simple_regmap_probe()
834 return -ENOMEM; in mvebu_pinctrl_simple_regmap_probe()
836 for (i = 0; i < soc->ncontrols; i++) { in mvebu_pinctrl_simple_regmap_probe()
841 soc->control_data = mpp_data; in mvebu_pinctrl_simple_regmap_probe()