Lines Matching +full:drv +full:- +full:pinconf

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2014-2018 Renesas Electronics Europe Limited
9 #include <dt-bindings/pinctrl/rzn1-pinctrl.h>
19 #include <linux/pinctrl/pinconf-generic.h>
20 #include <linux/pinctrl/pinconf.h>
25 #include "../pinconf.h"
26 #include "../pinctrl-utils.h"
83 * struct rzn1_pmx_func - describes rzn1 pinmux functions
95 * struct rzn1_pin_group - describes an rzn1 pin group
187 u32 val = ipctl->lev1_protect_phys | !(value & LOCK_LEVEL1); in rzn1_hw_set_lock()
189 writel(val, &ipctl->lev1->status_protect); in rzn1_hw_set_lock()
193 u32 val = ipctl->lev2_protect_phys | !(value & LOCK_LEVEL2); in rzn1_hw_set_lock()
195 writel(val, &ipctl->lev2->status_protect); in rzn1_hw_set_lock()
202 if (ipctl->mdio_func[mdio] >= 0 && ipctl->mdio_func[mdio] != func) in rzn1_pinctrl_mdio_select()
203 dev_warn(ipctl->dev, "conflicting setting for mdio%d!\n", mdio); in rzn1_pinctrl_mdio_select()
204 ipctl->mdio_func[mdio] = func; in rzn1_pinctrl_mdio_select()
206 dev_dbg(ipctl->dev, "setting mdio%d to %u\n", mdio, func); in rzn1_pinctrl_mdio_select()
208 writel(func, &ipctl->lev2->l2_mdio[mdio]); in rzn1_pinctrl_mdio_select()
240 mdio_func = pin_config - RZN1_FUNC_MDIO0_HIGHZ; in rzn1_set_hw_pin_func()
243 mdio_func = pin_config - RZN1_FUNC_MDIO0_E1_HIGHZ; in rzn1_set_hw_pin_func()
246 mdio_func = pin_config - RZN1_FUNC_MDIO1_HIGHZ; in rzn1_set_hw_pin_func()
249 mdio_func = pin_config - RZN1_FUNC_MDIO1_E1_HIGHZ; in rzn1_set_hw_pin_func()
256 if (pin >= ARRAY_SIZE(ipctl->lev1->conf) || in rzn1_set_hw_pin_func()
258 return -EINVAL; in rzn1_set_hw_pin_func()
260 l1 = readl(&ipctl->lev1->conf[pin]); in rzn1_set_hw_pin_func()
262 l2 = readl(&ipctl->lev2->conf[pin]); in rzn1_set_hw_pin_func()
265 dev_dbg(ipctl->dev, "setting func for pin %u to %u\n", pin, pin_config); in rzn1_set_hw_pin_func()
274 l2 = pin_config - RZN1_FUNC_L2_OFFSET; in rzn1_set_hw_pin_func()
279 writel(l1, &ipctl->lev1->conf[pin]); in rzn1_set_hw_pin_func()
280 writel(l2, &ipctl->lev2->conf[pin]); in rzn1_set_hw_pin_func()
291 for (i = 0; i < ipctl->ngroups; i++) { in rzn1_pinctrl_find_group_by_name()
292 if (!strcmp(ipctl->groups[i].name, name)) in rzn1_pinctrl_find_group_by_name()
293 return &ipctl->groups[i]; in rzn1_pinctrl_find_group_by_name()
303 return ipctl->ngroups; in rzn1_get_groups_count()
311 return ipctl->groups[selector].name; in rzn1_get_group_name()
320 if (selector >= ipctl->ngroups) in rzn1_get_group_pins()
321 return -EINVAL; in rzn1_get_group_pins()
323 *pins = ipctl->groups[selector].pins; in rzn1_get_group_pins()
324 *npins = ipctl->groups[selector].npins; in rzn1_get_group_pins()
331 * Sub-nodes can be used to describe multiple 'Groups' for the 'Function'
332 * If there aren't any sub-nodes, the 'Group' is essentially the 'Function'.
350 dev_dbg(ipctl->dev, "processing node %pOF\n", np); in rzn1_dt_node_to_map_one()
352 grp = rzn1_pinctrl_find_group_by_name(ipctl, np->name); in rzn1_dt_node_to_map_one()
354 dev_err(ipctl->dev, "unable to find group for node %pOF\n", np); in rzn1_dt_node_to_map_one()
356 return -EINVAL; in rzn1_dt_node_to_map_one()
363 dev_err(ipctl->dev, "%pOF: could not parse property\n", np); in rzn1_dt_node_to_map_one()
379 grp->name, grp->func); in rzn1_dt_node_to_map_one()
386 &reserved_maps, num_maps, grp->name, in rzn1_dt_node_to_map_one()
393 dev_dbg(pctldev->dev, "maps: function %s group %s (%d pins)\n", in rzn1_dt_node_to_map_one()
394 grp->func, grp->name, grp->npins); in rzn1_dt_node_to_map_one()
440 return ipctl->nfunctions; in rzn1_pmx_get_funcs_count()
448 return ipctl->functions[selector].name; in rzn1_pmx_get_func_name()
458 *groups = ipctl->functions[selector].groups; in rzn1_pmx_get_groups()
459 *num_groups = ipctl->functions[selector].num_groups; in rzn1_pmx_get_groups()
468 struct rzn1_pin_group *grp = &ipctl->groups[group]; in rzn1_set_mux()
469 unsigned int i, grp_pins = grp->npins; in rzn1_set_mux()
471 dev_dbg(ipctl->dev, "set mux %s(%d) group %s(%d)\n", in rzn1_set_mux()
472 ipctl->functions[selector].name, selector, grp->name, group); in rzn1_set_mux()
476 rzn1_set_hw_pin_func(ipctl, grp->pins[i], grp->pin_ids[i], 0); in rzn1_set_mux()
498 if (pin >= ARRAY_SIZE(ipctl->lev1->conf)) in rzn1_pinconf_get()
499 return -EINVAL; in rzn1_pinconf_get()
501 l1 = readl(&ipctl->lev1->conf[pin]); in rzn1_pinconf_get()
510 return -EINVAL; in rzn1_pinconf_get()
514 return -EINVAL; in rzn1_pinconf_get()
518 return -EINVAL; in rzn1_pinconf_get()
524 l2 = readl(&ipctl->lev2->conf[pin]); in rzn1_pinconf_get()
527 return -EINVAL; in rzn1_pinconf_get()
529 return -EINVAL; in rzn1_pinconf_get()
533 return -ENOTSUPP; in rzn1_pinconf_get()
548 u32 drv; in rzn1_pinconf_set() local
551 if (pin >= ARRAY_SIZE(ipctl->lev1->conf)) in rzn1_pinconf_set()
552 return -EINVAL; in rzn1_pinconf_set()
554 l1 = readl(&ipctl->lev1->conf[pin]); in rzn1_pinconf_set()
563 dev_dbg(ipctl->dev, "set pin %d pull up\n", pin); in rzn1_pinconf_set()
568 dev_dbg(ipctl->dev, "set pin %d pull down\n", pin); in rzn1_pinconf_set()
573 dev_dbg(ipctl->dev, "set pin %d bias off\n", pin); in rzn1_pinconf_set()
578 dev_dbg(ipctl->dev, "set pin %d drv %umA\n", pin, arg); in rzn1_pinconf_set()
581 drv = RZN1_L1_PIN_DRIVE_STRENGTH_4MA; in rzn1_pinconf_set()
584 drv = RZN1_L1_PIN_DRIVE_STRENGTH_6MA; in rzn1_pinconf_set()
587 drv = RZN1_L1_PIN_DRIVE_STRENGTH_8MA; in rzn1_pinconf_set()
590 drv = RZN1_L1_PIN_DRIVE_STRENGTH_12MA; in rzn1_pinconf_set()
593 dev_err(ipctl->dev, in rzn1_pinconf_set()
597 return -EINVAL; in rzn1_pinconf_set()
601 l1 |= (drv << RZN1_L1_PIN_DRIVE_STRENGTH); in rzn1_pinconf_set()
605 dev_dbg(ipctl->dev, "set pin %d High-Z\n", pin); in rzn1_pinconf_set()
610 return -ENOTSUPP; in rzn1_pinconf_set()
616 writel(l1, &ipctl->lev1->conf[pin]); in rzn1_pinconf_set()
628 struct rzn1_pin_group *grp = &ipctl->groups[selector]; in rzn1_pinconf_group_get()
632 dev_dbg(ipctl->dev, "group get %s selector:%u\n", grp->name, selector); in rzn1_pinconf_group_get()
634 for (i = 0; i < grp->npins; i++) { in rzn1_pinconf_group_get()
635 if (rzn1_pinconf_get(pctldev, grp->pins[i], config)) in rzn1_pinconf_group_get()
636 return -ENOTSUPP; in rzn1_pinconf_group_get()
640 return -ENOTSUPP; in rzn1_pinconf_group_get()
654 struct rzn1_pin_group *grp = &ipctl->groups[selector]; in rzn1_pinconf_group_set()
658 dev_dbg(ipctl->dev, "group set %s selector:%u configs:%p/%d\n", in rzn1_pinconf_group_set()
659 grp->name, selector, configs, num_configs); in rzn1_pinconf_group_set()
661 for (i = 0; i < grp->npins; i++) { in rzn1_pinconf_group_set()
662 unsigned int pin = grp->pins[i]; in rzn1_pinconf_group_set()
696 dev_dbg(ipctl->dev, "%s: %s\n", __func__, np->name); in rzn1_pinctrl_parse_groups()
699 grp->name = np->name; in rzn1_pinctrl_parse_groups()
708 dev_err(ipctl->dev, in rzn1_pinctrl_parse_groups()
711 return -EINVAL; in rzn1_pinctrl_parse_groups()
715 dev_err(ipctl->dev, "Invalid " RZN1_PINS_PROP " in node %pOF\n", in rzn1_pinctrl_parse_groups()
718 return -EINVAL; in rzn1_pinctrl_parse_groups()
721 grp->npins = size / sizeof(list[0]); in rzn1_pinctrl_parse_groups()
722 grp->pin_ids = devm_kmalloc_array(ipctl->dev, in rzn1_pinctrl_parse_groups()
723 grp->npins, sizeof(grp->pin_ids[0]), in rzn1_pinctrl_parse_groups()
725 grp->pins = devm_kmalloc_array(ipctl->dev, in rzn1_pinctrl_parse_groups()
726 grp->npins, sizeof(grp->pins[0]), in rzn1_pinctrl_parse_groups()
728 if (!grp->pin_ids || !grp->pins) in rzn1_pinctrl_parse_groups()
729 return -ENOMEM; in rzn1_pinctrl_parse_groups()
731 for (i = 0; i < grp->npins; i++) { in rzn1_pinctrl_parse_groups()
734 grp->pins[i] = pin_id & 0xff; in rzn1_pinctrl_parse_groups()
735 grp->pin_ids[i] = (pin_id >> 8) & 0x7f; in rzn1_pinctrl_parse_groups()
738 return grp->npins; in rzn1_pinctrl_parse_groups()
767 func = &ipctl->functions[index]; in rzn1_pinctrl_parse_functions()
770 func->name = np->name; in rzn1_pinctrl_parse_functions()
771 func->num_groups = rzn1_pinctrl_count_function_groups(np); in rzn1_pinctrl_parse_functions()
772 if (func->num_groups == 0) { in rzn1_pinctrl_parse_functions()
773 dev_err(ipctl->dev, "no groups defined in %pOF\n", np); in rzn1_pinctrl_parse_functions()
774 return -EINVAL; in rzn1_pinctrl_parse_functions()
776 dev_dbg(ipctl->dev, "function %s has %d groups\n", in rzn1_pinctrl_parse_functions()
777 np->name, func->num_groups); in rzn1_pinctrl_parse_functions()
779 func->groups = devm_kmalloc_array(ipctl->dev, in rzn1_pinctrl_parse_functions()
780 func->num_groups, sizeof(char *), in rzn1_pinctrl_parse_functions()
782 if (!func->groups) in rzn1_pinctrl_parse_functions()
783 return -ENOMEM; in rzn1_pinctrl_parse_functions()
786 func->groups[i] = np->name; in rzn1_pinctrl_parse_functions()
787 grp = &ipctl->groups[ipctl->ngroups]; in rzn1_pinctrl_parse_functions()
788 grp->func = func->name; in rzn1_pinctrl_parse_functions()
793 ipctl->ngroups++; in rzn1_pinctrl_parse_functions()
797 func->groups[i] = child->name; in rzn1_pinctrl_parse_functions()
798 grp = &ipctl->groups[ipctl->ngroups]; in rzn1_pinctrl_parse_functions()
799 grp->func = func->name; in rzn1_pinctrl_parse_functions()
806 ipctl->ngroups++; in rzn1_pinctrl_parse_functions()
809 dev_dbg(ipctl->dev, "function %s parsed %u/%u groups\n", in rzn1_pinctrl_parse_functions()
810 np->name, i, func->num_groups); in rzn1_pinctrl_parse_functions()
818 struct device_node *np = pdev->dev.of_node; in rzn1_pinctrl_probe_dt()
829 ipctl->nfunctions = nfuncs; in rzn1_pinctrl_probe_dt()
830 ipctl->functions = devm_kmalloc_array(&pdev->dev, nfuncs, in rzn1_pinctrl_probe_dt()
831 sizeof(*ipctl->functions), in rzn1_pinctrl_probe_dt()
833 if (!ipctl->functions) in rzn1_pinctrl_probe_dt()
834 return -ENOMEM; in rzn1_pinctrl_probe_dt()
836 ipctl->ngroups = 0; in rzn1_pinctrl_probe_dt()
840 ipctl->groups = devm_kmalloc_array(&pdev->dev, in rzn1_pinctrl_probe_dt()
842 sizeof(*ipctl->groups), in rzn1_pinctrl_probe_dt()
844 if (!ipctl->groups) in rzn1_pinctrl_probe_dt()
845 return -ENOMEM; in rzn1_pinctrl_probe_dt()
865 ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL); in rzn1_pinctrl_probe()
867 return -ENOMEM; in rzn1_pinctrl_probe()
869 ipctl->mdio_func[0] = -1; in rzn1_pinctrl_probe()
870 ipctl->mdio_func[1] = -1; in rzn1_pinctrl_probe()
872 ipctl->lev1 = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in rzn1_pinctrl_probe()
873 if (IS_ERR(ipctl->lev1)) in rzn1_pinctrl_probe()
874 return PTR_ERR(ipctl->lev1); in rzn1_pinctrl_probe()
875 ipctl->lev1_protect_phys = (u32)res->start + 0x400; in rzn1_pinctrl_probe()
877 ipctl->lev2 = devm_platform_get_and_ioremap_resource(pdev, 1, &res); in rzn1_pinctrl_probe()
878 if (IS_ERR(ipctl->lev2)) in rzn1_pinctrl_probe()
879 return PTR_ERR(ipctl->lev2); in rzn1_pinctrl_probe()
880 ipctl->lev2_protect_phys = (u32)res->start + 0x400; in rzn1_pinctrl_probe()
882 ipctl->clk = devm_clk_get(&pdev->dev, NULL); in rzn1_pinctrl_probe()
883 if (IS_ERR(ipctl->clk)) in rzn1_pinctrl_probe()
884 return PTR_ERR(ipctl->clk); in rzn1_pinctrl_probe()
885 ret = clk_prepare_enable(ipctl->clk); in rzn1_pinctrl_probe()
889 ipctl->dev = &pdev->dev; in rzn1_pinctrl_probe()
890 rzn1_pinctrl_desc.name = dev_name(&pdev->dev); in rzn1_pinctrl_probe()
896 dev_err(&pdev->dev, "fail to probe dt properties\n"); in rzn1_pinctrl_probe()
902 ret = devm_pinctrl_register_and_init(&pdev->dev, &rzn1_pinctrl_desc, in rzn1_pinctrl_probe()
903 ipctl, &ipctl->pctl); in rzn1_pinctrl_probe()
905 dev_err(&pdev->dev, "could not register rzn1 pinctrl driver\n"); in rzn1_pinctrl_probe()
909 ret = pinctrl_enable(ipctl->pctl); in rzn1_pinctrl_probe()
913 dev_info(&pdev->dev, "probed\n"); in rzn1_pinctrl_probe()
918 clk_disable_unprepare(ipctl->clk); in rzn1_pinctrl_probe()
927 clk_disable_unprepare(ipctl->clk); in rzn1_pinctrl_remove()
933 { .compatible = "renesas,rzn1-pinctrl", },
942 .name = "rzn1-pinctrl",