Lines Matching +full:pull +full:- +full:down +full:- +full:adv

1 // SPDX-License-Identifier: GPL-2.0
3 * MediaTek Pinctrl Paris Driver, which implement the vendor per-pin
18 #include <dt-bindings/pinctrl/mt65xx.h>
20 #include "pinctrl-paris.h"
34 {"mediatek,pull-up-adv", MTK_PIN_CONFIG_PU_ADV, 1},
35 {"mediatek,pull-down-adv", MTK_PIN_CONFIG_PD_ADV, 1},
36 {"mediatek,drive-strength-adv", MTK_PIN_CONFIG_DRV_ADV, 2},
43 PCONFDUMP(MTK_PIN_CONFIG_PU_ADV, "pu-adv", NULL, true),
44 PCONFDUMP(MTK_PIN_CONFIG_PD_ADV, "pd-adv", NULL, true),
45 PCONFDUMP(MTK_PIN_CONFIG_DRV_ADV, "drive-strength-adv", NULL, true),
64 * ------------------------------------------------
66 * -------------------------------------
78 return -EINVAL; in mtk_drv_adv_to_uA()
82 return -EINVAL; in mtk_drv_adv_to_uA()
100 return -EINVAL; in mtk_drv_uA_to_adv()
110 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_request_enable()
113 hw->soc->gpio_m); in mtk_pinmux_gpio_request_enable()
123 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_set_direction()
134 int pullup, reg, err = -ENOTSUPP, ret = 1; in mtk_pinconf_get()
137 if (pin >= hw->soc->npins) in mtk_pinconf_get()
138 return -EINVAL; in mtk_pinconf_get()
140 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_get()
146 if (!hw->soc->bias_get_combo) in mtk_pinconf_get()
148 err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret); in mtk_pinconf_get()
155 err = -EINVAL; in mtk_pinconf_get()
158 err = -EINVAL; in mtk_pinconf_get()
161 err = -EINVAL; in mtk_pinconf_get()
173 * ------------- ----------------- ---------------------- in mtk_pinconf_get()
191 err = -EINVAL; in mtk_pinconf_get()
198 if (!hw->soc->drive_get) in mtk_pinconf_get()
201 if (hw->soc->adv_drive_get) { in mtk_pinconf_get()
202 err = hw->soc->adv_drive_get(hw, desc, &ret); in mtk_pinconf_get()
207 err = -EINVAL; in mtk_pinconf_get()
213 err = hw->soc->drive_get(hw, desc, &ret); in mtk_pinconf_get()
216 if (!hw->soc->adv_drive_get) in mtk_pinconf_get()
219 err = hw->soc->adv_drive_get(hw, desc, &ret); in mtk_pinconf_get()
237 if (!hw->soc->adv_pull_get) in mtk_pinconf_get()
240 err = hw->soc->adv_pull_get(hw, desc, pullup, &ret); in mtk_pinconf_get()
243 if (!hw->soc->adv_drive_get) in mtk_pinconf_get()
245 err = hw->soc->adv_drive_get(hw, desc, &ret); in mtk_pinconf_get()
260 int err = -ENOTSUPP; in mtk_pinconf_set()
263 if (pin >= hw->soc->npins) in mtk_pinconf_set()
264 return -EINVAL; in mtk_pinconf_set()
266 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_set()
270 if (!hw->soc->bias_set_combo) in mtk_pinconf_set()
272 err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); in mtk_pinconf_set()
275 if (!hw->soc->bias_set_combo) in mtk_pinconf_set()
277 err = hw->soc->bias_set_combo(hw, desc, 1, arg); in mtk_pinconf_set()
280 if (!hw->soc->bias_set_combo) in mtk_pinconf_set()
282 err = hw->soc->bias_set_combo(hw, desc, 0, arg); in mtk_pinconf_set()
290 if (err != -ENOTSUPP) in mtk_pinconf_set()
297 /* regard all non-zero value as enable */ in mtk_pinconf_set()
306 /* regard all non-zero value as enable */ in mtk_pinconf_set()
330 if (!hw->soc->drive_set) in mtk_pinconf_set()
332 err = hw->soc->drive_set(hw, desc, arg); in mtk_pinconf_set()
335 if (!hw->soc->adv_drive_set) in mtk_pinconf_set()
341 err = hw->soc->adv_drive_set(hw, desc, err); in mtk_pinconf_set()
351 if (!hw->soc->adv_pull_set) in mtk_pinconf_set()
353 err = hw->soc->adv_pull_set(hw, desc, in mtk_pinconf_set()
358 if (!hw->soc->adv_drive_set) in mtk_pinconf_set()
360 err = hw->soc->adv_drive_set(hw, desc, arg); in mtk_pinconf_set()
372 for (i = 0; i < hw->soc->ngrps; i++) { in mtk_pctrl_find_group_by_pin()
373 struct mtk_pinctrl_group *grp = hw->groups + i; in mtk_pctrl_find_group_by_pin()
375 if (grp->pin == pin) in mtk_pctrl_find_group_by_pin()
385 const struct mtk_pin_desc *pin = hw->soc->pins + pin_num; in mtk_pctrl_find_function_by_pin()
386 const struct mtk_func_desc *func = pin->funcs; in mtk_pctrl_find_function_by_pin()
388 while (func && func->name) { in mtk_pctrl_find_function_by_pin()
389 if (func->muxval == fnum) in mtk_pctrl_find_function_by_pin()
402 for (i = 0; i < hw->soc->npins; i++) { in mtk_pctrl_is_function_valid()
403 const struct mtk_pin_desc *pin = hw->soc->pins + i; in mtk_pctrl_is_function_valid()
405 if (pin->number == pin_num) { in mtk_pctrl_is_function_valid()
406 const struct mtk_func_desc *func = pin->funcs; in mtk_pctrl_is_function_valid()
408 while (func && func->name) { in mtk_pctrl_is_function_valid()
409 if (func->muxval == fnum) in mtk_pctrl_is_function_valid()
431 return -ENOSPC; in mtk_pctrl_dt_node_to_map_func()
434 (*map)[*num_maps].data.mux.group = grp->name; in mtk_pctrl_dt_node_to_map_func()
438 dev_err(pctl->dev, "invalid function %d on pin %d .\n", in mtk_pctrl_dt_node_to_map_func()
440 return -EINVAL; in mtk_pctrl_dt_node_to_map_func()
467 dev_err(hw->dev, "missing pins property in node %pOFn .\n", in mtk_pctrl_dt_subnode_to_map()
469 return -EINVAL; in mtk_pctrl_dt_subnode_to_map()
480 num_pins = pins->length / sizeof(u32); in mtk_pctrl_dt_subnode_to_map()
489 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
508 if (pin >= hw->soc->npins || in mtk_pctrl_dt_subnode_to_map()
510 dev_err(hw->dev, "invalid pins value.\n"); in mtk_pctrl_dt_subnode_to_map()
511 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
517 dev_err(hw->dev, "unable to match pin %d to group\n", in mtk_pctrl_dt_subnode_to_map()
519 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
532 grp->name, in mtk_pctrl_dt_subnode_to_map()
579 return hw->soc->ngrps; in mtk_pctrl_get_groups_count()
587 return hw->groups[group].name; in mtk_pctrl_get_group_name()
596 *pins = (unsigned *)&hw->groups[group].pin; in mtk_pctrl_get_group_pins()
607 if (gpio >= hw->soc->npins) in mtk_hw_get_value_wrap()
608 return -EINVAL; in mtk_hw_get_value_wrap()
610 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_hw_get_value_wrap()
643 int pinmux, pullup = 0, pullen = 0, len = 0, r1 = -1, r0 = -1, rsel = -1; in mtk_pctrl_show_one_pin()
647 if (gpio >= hw->soc->npins) in mtk_pctrl_show_one_pin()
648 return -EINVAL; in mtk_pctrl_show_one_pin()
651 return -EINVAL; in mtk_pctrl_show_one_pin()
653 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_pctrl_show_one_pin()
655 if (pinmux >= hw->soc->nfuncs) in mtk_pctrl_show_one_pin()
656 pinmux -= hw->soc->nfuncs; in mtk_pctrl_show_one_pin()
660 if (hw->soc->pull_type) in mtk_pctrl_show_one_pin()
661 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pctrl_show_one_pin()
663 if (hw->rsel_si_unit && (try_all_type & MTK_PULL_RSEL_TYPE)) { in mtk_pctrl_show_one_pin()
689 rsel = pullen - MTK_PULL_SET_RSEL_000; in mtk_pctrl_show_one_pin()
693 len += scnprintf(buf + len, buf_len - len, in mtk_pctrl_show_one_pin()
706 if (r1 != -1) in mtk_pctrl_show_one_pin()
707 len += scnprintf(buf + len, buf_len - len, " (%1d %1d)", r1, r0); in mtk_pctrl_show_one_pin()
708 else if (rsel != -1) in mtk_pctrl_show_one_pin()
709 len += scnprintf(buf + len, buf_len - len, " (%1d)", rsel); in mtk_pctrl_show_one_pin()
754 *groups = hw->grp_names; in mtk_pmx_get_func_groups()
755 *num_groups = hw->soc->ngrps; in mtk_pmx_get_func_groups()
765 struct mtk_pinctrl_group *grp = hw->groups + group; in mtk_pmx_set_mux()
770 ret = mtk_pctrl_is_function_valid(hw, grp->pin, function); in mtk_pmx_set_mux()
772 dev_err(hw->dev, "invalid function %d on group %d .\n", in mtk_pmx_set_mux()
774 return -EINVAL; in mtk_pmx_set_mux()
777 desc_func = mtk_pctrl_find_function_by_pin(hw, grp->pin, function); in mtk_pmx_set_mux()
779 return -EINVAL; in mtk_pmx_set_mux()
781 desc = (const struct mtk_pin_desc *)&hw->soc->pins[grp->pin]; in mtk_pmx_set_mux()
782 mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, desc_func->muxval); in mtk_pmx_set_mux()
800 struct mtk_pinctrl_group *grp = &hw->groups[group]; in mtk_pconf_group_get()
803 return mtk_pinconf_get(pctldev, grp->pin, config); in mtk_pconf_group_get()
810 struct mtk_pinctrl_group *grp = &hw->groups[group]; in mtk_pconf_group_set()
816 ret = mtk_pinconf_set(pctldev, grp->pin, in mtk_pconf_group_set()
829 * Disable advanced drive strength mode if drive-strength-microamp in mtk_pconf_group_set()
830 * is not set. However, mediatek,drive-strength-adv takes precedence in mtk_pconf_group_set()
833 if (hw->soc->adv_drive_set && !drive_strength_uA_found && in mtk_pconf_group_set()
835 hw->soc->adv_drive_set(hw, &hw->soc->pins[grp->pin], 0); in mtk_pconf_group_set()
861 if (gpio >= hw->soc->npins) in mtk_gpio_get_direction()
862 return -EINVAL; in mtk_gpio_get_direction()
871 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_get_direction()
889 if (gpio >= hw->soc->npins) in mtk_gpio_get()
890 return -EINVAL; in mtk_gpio_get()
892 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_get()
906 if (gpio >= hw->soc->npins) in mtk_gpio_set()
909 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_set()
918 if (gpio >= hw->soc->npins) in mtk_gpio_direction_input()
919 return -EINVAL; in mtk_gpio_direction_input()
921 return pinctrl_gpio_direction_input(chip->base + gpio); in mtk_gpio_direction_input()
929 if (gpio >= hw->soc->npins) in mtk_gpio_direction_output()
930 return -EINVAL; in mtk_gpio_direction_output()
934 return pinctrl_gpio_direction_output(chip->base + gpio); in mtk_gpio_direction_output()
942 if (!hw->eint) in mtk_gpio_to_irq()
943 return -ENOTSUPP; in mtk_gpio_to_irq()
945 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_to_irq()
947 if (desc->eint.eint_n == EINT_NA) in mtk_gpio_to_irq()
948 return -ENOTSUPP; in mtk_gpio_to_irq()
950 return mtk_eint_find_irq(hw->eint, desc->eint.eint_n); in mtk_gpio_to_irq()
960 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_set_config()
962 if (!hw->eint || in mtk_gpio_set_config()
964 desc->eint.eint_n == EINT_NA) in mtk_gpio_set_config()
965 return -ENOTSUPP; in mtk_gpio_set_config()
969 return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); in mtk_gpio_set_config()
974 struct gpio_chip *chip = &hw->chip; in mtk_build_gpiochip()
977 chip->label = PINCTRL_PINCTRL_DEV; in mtk_build_gpiochip()
978 chip->parent = hw->dev; in mtk_build_gpiochip()
979 chip->request = gpiochip_generic_request; in mtk_build_gpiochip()
980 chip->free = gpiochip_generic_free; in mtk_build_gpiochip()
981 chip->get_direction = mtk_gpio_get_direction; in mtk_build_gpiochip()
982 chip->direction_input = mtk_gpio_direction_input; in mtk_build_gpiochip()
983 chip->direction_output = mtk_gpio_direction_output; in mtk_build_gpiochip()
984 chip->get = mtk_gpio_get; in mtk_build_gpiochip()
985 chip->set = mtk_gpio_set; in mtk_build_gpiochip()
986 chip->to_irq = mtk_gpio_to_irq; in mtk_build_gpiochip()
987 chip->set_config = mtk_gpio_set_config; in mtk_build_gpiochip()
988 chip->base = -1; in mtk_build_gpiochip()
989 chip->ngpio = hw->soc->npins; in mtk_build_gpiochip()
1004 hw->groups = devm_kmalloc_array(&pdev->dev, hw->soc->ngrps, in mtk_pctrl_build_state()
1005 sizeof(*hw->groups), GFP_KERNEL); in mtk_pctrl_build_state()
1006 if (!hw->groups) in mtk_pctrl_build_state()
1007 return -ENOMEM; in mtk_pctrl_build_state()
1010 hw->grp_names = devm_kmalloc_array(&pdev->dev, hw->soc->ngrps, in mtk_pctrl_build_state()
1011 sizeof(*hw->grp_names), GFP_KERNEL); in mtk_pctrl_build_state()
1012 if (!hw->grp_names) in mtk_pctrl_build_state()
1013 return -ENOMEM; in mtk_pctrl_build_state()
1015 for (i = 0; i < hw->soc->npins; i++) { in mtk_pctrl_build_state()
1016 const struct mtk_pin_desc *pin = hw->soc->pins + i; in mtk_pctrl_build_state()
1017 struct mtk_pinctrl_group *group = hw->groups + i; in mtk_pctrl_build_state()
1019 group->name = pin->name; in mtk_pctrl_build_state()
1020 group->pin = pin->number; in mtk_pctrl_build_state()
1022 hw->grp_names[i] = pin->name; in mtk_pctrl_build_state()
1030 struct device *dev = &pdev->dev; in mtk_paris_pinctrl_probe()
1035 hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); in mtk_paris_pinctrl_probe()
1037 return -ENOMEM; in mtk_paris_pinctrl_probe()
1041 hw->soc = device_get_match_data(dev); in mtk_paris_pinctrl_probe()
1042 if (!hw->soc) in mtk_paris_pinctrl_probe()
1043 return -ENOENT; in mtk_paris_pinctrl_probe()
1045 hw->dev = &pdev->dev; in mtk_paris_pinctrl_probe()
1047 if (!hw->soc->nbase_names) in mtk_paris_pinctrl_probe()
1048 return dev_err_probe(dev, -EINVAL, in mtk_paris_pinctrl_probe()
1051 hw->base = devm_kmalloc_array(&pdev->dev, hw->soc->nbase_names, in mtk_paris_pinctrl_probe()
1052 sizeof(*hw->base), GFP_KERNEL); in mtk_paris_pinctrl_probe()
1053 if (!hw->base) in mtk_paris_pinctrl_probe()
1054 return -ENOMEM; in mtk_paris_pinctrl_probe()
1056 for (i = 0; i < hw->soc->nbase_names; i++) { in mtk_paris_pinctrl_probe()
1057 hw->base[i] = devm_platform_ioremap_resource_byname(pdev, in mtk_paris_pinctrl_probe()
1058 hw->soc->base_names[i]); in mtk_paris_pinctrl_probe()
1059 if (IS_ERR(hw->base[i])) in mtk_paris_pinctrl_probe()
1060 return PTR_ERR(hw->base[i]); in mtk_paris_pinctrl_probe()
1063 hw->nbase = hw->soc->nbase_names; in mtk_paris_pinctrl_probe()
1065 if (of_find_property(hw->dev->of_node, in mtk_paris_pinctrl_probe()
1066 "mediatek,rsel-resistance-in-si-unit", NULL)) in mtk_paris_pinctrl_probe()
1067 hw->rsel_si_unit = true; in mtk_paris_pinctrl_probe()
1069 hw->rsel_si_unit = false; in mtk_paris_pinctrl_probe()
1071 spin_lock_init(&hw->lock); in mtk_paris_pinctrl_probe()
1078 pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), in mtk_paris_pinctrl_probe()
1081 return -ENOMEM; in mtk_paris_pinctrl_probe()
1083 for (i = 0; i < hw->soc->npins; i++) { in mtk_paris_pinctrl_probe()
1084 pins[i].number = hw->soc->pins[i].number; in mtk_paris_pinctrl_probe()
1085 pins[i].name = hw->soc->pins[i].name; in mtk_paris_pinctrl_probe()
1090 mtk_desc.npins = hw->soc->npins; in mtk_paris_pinctrl_probe()
1097 err = devm_pinctrl_register_and_init(&pdev->dev, &mtk_desc, hw, in mtk_paris_pinctrl_probe()
1098 &hw->pctrl); in mtk_paris_pinctrl_probe()
1102 err = pinctrl_enable(hw->pctrl); in mtk_paris_pinctrl_probe()
1108 dev_warn(&pdev->dev, in mtk_paris_pinctrl_probe()
1126 return mtk_eint_do_suspend(pctl->eint); in mtk_paris_pinctrl_suspend()
1133 return mtk_eint_do_resume(pctl->eint); in mtk_paris_pinctrl_resume()