Lines Matching +full:custom +full:- +full:output +full:- +full:range +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0
3 * MediaTek Pinctrl Moore Driver, which implement the generic dt-binding
4 * pinctrl-bindings.txt for MediaTek SoC.
6 * Copyright (C) 2017-2018 MediaTek Inc.
11 #include <dt-bindings/pinctrl/mt65xx.h>
16 #include "pinctrl-moore.h"
20 /* Custom pinconf parameters */
29 {"mediatek,pull-up-adv", MTK_PIN_CONFIG_PU_ADV, 1},
30 {"mediatek,pull-down-adv", MTK_PIN_CONFIG_PD_ADV, 1},
37 PCONFDUMP(MTK_PIN_CONFIG_PU_ADV, "pu-adv", NULL, true),
38 PCONFDUMP(MTK_PIN_CONFIG_PD_ADV, "pd-adv", NULL, true),
52 return -EINVAL; in mtk_pinmux_set_mux()
56 return -EINVAL; in mtk_pinmux_set_mux()
58 dev_dbg(pctldev->dev, "enable function %s group %s\n", in mtk_pinmux_set_mux()
59 func->func.name, grp->grp.name); in mtk_pinmux_set_mux()
61 for (i = 0; i < grp->grp.npins; i++) { in mtk_pinmux_set_mux()
63 int *pin_modes = grp->data; in mtk_pinmux_set_mux()
64 int pin = grp->grp.pins[i]; in mtk_pinmux_set_mux()
66 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_set_mux()
67 if (!desc->name) in mtk_pinmux_set_mux()
68 return -ENOTSUPP; in mtk_pinmux_set_mux()
81 struct pinctrl_gpio_range *range, in mtk_pinmux_gpio_request_enable() argument
87 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_request_enable()
88 if (!desc->name) in mtk_pinmux_gpio_request_enable()
89 return -ENOTSUPP; in mtk_pinmux_gpio_request_enable()
92 hw->soc->gpio_m); in mtk_pinmux_gpio_request_enable()
96 struct pinctrl_gpio_range *range, in mtk_pinmux_gpio_set_direction() argument
102 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_set_direction()
103 if (!desc->name) in mtk_pinmux_gpio_set_direction()
104 return -ENOTSUPP; in mtk_pinmux_gpio_set_direction()
111 unsigned int pin, unsigned long *config) in mtk_pinconf_get() argument
114 u32 param = pinconf_to_config_param(*config); in mtk_pinconf_get()
118 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_get()
119 if (!desc->name) in mtk_pinconf_get()
120 return -ENOTSUPP; in mtk_pinconf_get()
124 if (hw->soc->bias_get_combo) { in mtk_pinconf_get()
125 err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret); in mtk_pinconf_get()
129 return -EINVAL; in mtk_pinconf_get()
130 } else if (hw->soc->bias_disable_get) { in mtk_pinconf_get()
131 err = hw->soc->bias_disable_get(hw, desc, &ret); in mtk_pinconf_get()
135 return -ENOTSUPP; in mtk_pinconf_get()
139 if (hw->soc->bias_get_combo) { in mtk_pinconf_get()
140 err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret); in mtk_pinconf_get()
144 return -EINVAL; in mtk_pinconf_get()
146 return -EINVAL; in mtk_pinconf_get()
147 } else if (hw->soc->bias_get) { in mtk_pinconf_get()
148 err = hw->soc->bias_get(hw, desc, 1, &ret); in mtk_pinconf_get()
152 return -ENOTSUPP; in mtk_pinconf_get()
156 if (hw->soc->bias_get_combo) { in mtk_pinconf_get()
157 err = hw->soc->bias_get_combo(hw, desc, &pullup, &ret); in mtk_pinconf_get()
161 return -EINVAL; in mtk_pinconf_get()
163 return -EINVAL; in mtk_pinconf_get()
164 } else if (hw->soc->bias_get) { in mtk_pinconf_get()
165 err = hw->soc->bias_get(hw, desc, 0, &ret); in mtk_pinconf_get()
169 return -ENOTSUPP; in mtk_pinconf_get()
178 return -EINVAL; in mtk_pinconf_get()
187 /* HW takes input mode as zero; output mode as non-zero */ in mtk_pinconf_get()
190 return -EINVAL; in mtk_pinconf_get()
203 return -EINVAL; in mtk_pinconf_get()
207 if (hw->soc->drive_get) { in mtk_pinconf_get()
208 err = hw->soc->drive_get(hw, desc, &ret); in mtk_pinconf_get()
212 err = -ENOTSUPP; in mtk_pinconf_get()
229 if (hw->soc->adv_pull_get) { in mtk_pinconf_get()
233 err = hw->soc->adv_pull_get(hw, desc, pullup, &ret); in mtk_pinconf_get()
237 return -ENOTSUPP; in mtk_pinconf_get()
241 return -ENOTSUPP; in mtk_pinconf_get()
244 *config = pinconf_to_config_packed(param, ret); in mtk_pinconf_get()
257 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_set()
258 if (!desc->name) in mtk_pinconf_set()
259 return -ENOTSUPP; in mtk_pinconf_set()
267 if (hw->soc->bias_set_combo) { in mtk_pinconf_set()
268 err = hw->soc->bias_set_combo(hw, desc, 0, MTK_DISABLE); in mtk_pinconf_set()
271 } else if (hw->soc->bias_disable_set) { in mtk_pinconf_set()
272 err = hw->soc->bias_disable_set(hw, desc); in mtk_pinconf_set()
276 return -ENOTSUPP; in mtk_pinconf_set()
280 if (hw->soc->bias_set_combo) { in mtk_pinconf_set()
281 err = hw->soc->bias_set_combo(hw, desc, 1, arg); in mtk_pinconf_set()
284 } else if (hw->soc->bias_set) { in mtk_pinconf_set()
285 err = hw->soc->bias_set(hw, desc, 1); in mtk_pinconf_set()
289 return -ENOTSUPP; in mtk_pinconf_set()
293 if (hw->soc->bias_set_combo) { in mtk_pinconf_set()
294 err = hw->soc->bias_set_combo(hw, desc, 0, arg); in mtk_pinconf_set()
297 } else if (hw->soc->bias_set) { in mtk_pinconf_set()
298 err = hw->soc->bias_set(hw, desc, 0); in mtk_pinconf_set()
302 return -ENOTSUPP; in mtk_pinconf_set()
318 if (hw->soc->ies_present) { in mtk_pinconf_set()
348 * arg = 0: Output mode & SMT disable in mtk_pinconf_set()
362 if (hw->soc->drive_set) { in mtk_pinconf_set()
363 err = hw->soc->drive_set(hw, desc, arg); in mtk_pinconf_set()
367 err = -ENOTSUPP; in mtk_pinconf_set()
381 if (hw->soc->adv_pull_set) { in mtk_pinconf_set()
385 err = hw->soc->adv_pull_set(hw, desc, pullup, in mtk_pinconf_set()
390 return -ENOTSUPP; in mtk_pinconf_set()
394 err = -ENOTSUPP; in mtk_pinconf_set()
402 unsigned int group, unsigned long *config) in mtk_pinconf_group_get() argument
413 if (mtk_pinconf_get(pctldev, pins[i], config)) in mtk_pinconf_group_get()
414 return -ENOTSUPP; in mtk_pinconf_group_get()
417 if (i && old != *config) in mtk_pinconf_group_get()
418 return -ENOTSUPP; in mtk_pinconf_group_get()
420 old = *config; in mtk_pinconf_group_get()
488 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_get()
489 if (!desc->name) in mtk_gpio_get()
490 return -ENOTSUPP; in mtk_gpio_get()
504 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_set()
505 if (!desc->name) { in mtk_gpio_set()
506 dev_err(hw->dev, "Failed to set gpio %d\n", gpio); in mtk_gpio_set()
526 if (!hw->eint) in mtk_gpio_to_irq()
527 return -ENOTSUPP; in mtk_gpio_to_irq()
529 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_to_irq()
531 if (desc->eint.eint_n == (u16)EINT_NA) in mtk_gpio_to_irq()
532 return -ENOTSUPP; in mtk_gpio_to_irq()
534 return mtk_eint_find_irq(hw->eint, desc->eint.eint_n); in mtk_gpio_to_irq()
538 unsigned long config) in mtk_gpio_set_config() argument
544 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_set_config()
545 if (!desc->name) in mtk_gpio_set_config()
546 return -ENOTSUPP; in mtk_gpio_set_config()
548 if (!hw->eint || in mtk_gpio_set_config()
549 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || in mtk_gpio_set_config()
550 desc->eint.eint_n == (u16)EINT_NA) in mtk_gpio_set_config()
551 return -ENOTSUPP; in mtk_gpio_set_config()
553 debounce = pinconf_to_config_argument(config); in mtk_gpio_set_config()
555 return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); in mtk_gpio_set_config()
560 struct gpio_chip *chip = &hw->chip; in mtk_build_gpiochip()
563 chip->label = PINCTRL_PINCTRL_DEV; in mtk_build_gpiochip()
564 chip->parent = hw->dev; in mtk_build_gpiochip()
565 chip->request = gpiochip_generic_request; in mtk_build_gpiochip()
566 chip->free = gpiochip_generic_free; in mtk_build_gpiochip()
567 chip->direction_input = pinctrl_gpio_direction_input; in mtk_build_gpiochip()
568 chip->direction_output = mtk_gpio_direction_output; in mtk_build_gpiochip()
569 chip->get = mtk_gpio_get; in mtk_build_gpiochip()
570 chip->set = mtk_gpio_set; in mtk_build_gpiochip()
571 chip->to_irq = mtk_gpio_to_irq; in mtk_build_gpiochip()
572 chip->set_config = mtk_gpio_set_config; in mtk_build_gpiochip()
573 chip->base = -1; in mtk_build_gpiochip()
574 chip->ngpio = hw->soc->npins; in mtk_build_gpiochip()
581 * "gpio-ranges" property. Otherwise, called directly from a in mtk_build_gpiochip()
582 * DeviceTree-supported pinctrl driver is DEPRECATED. in mtk_build_gpiochip()
585 * bind pinctrl and gpio drivers via the "gpio-ranges" property. in mtk_build_gpiochip()
587 if (!of_property_present(hw->dev->of_node, "gpio-ranges")) { in mtk_build_gpiochip()
588 ret = gpiochip_add_pin_range(chip, dev_name(hw->dev), 0, 0, in mtk_build_gpiochip()
589 chip->ngpio); in mtk_build_gpiochip()
603 for (i = 0; i < hw->soc->ngrps; i++) { in mtk_build_groups()
604 const struct group_desc *group = hw->soc->grps + i; in mtk_build_groups()
605 const struct pingroup *grp = &group->grp; in mtk_build_groups()
607 err = pinctrl_generic_add_group(hw->pctrl, grp->name, grp->pins, grp->npins, in mtk_build_groups()
608 group->data); in mtk_build_groups()
610 dev_err(hw->dev, "Failed to register group %s\n", grp->name); in mtk_build_groups()
622 for (i = 0; i < hw->soc->nfuncs ; i++) { in mtk_build_functions()
623 const struct function_desc *function = hw->soc->funcs + i; in mtk_build_functions()
624 const struct pinfunction *func = &function->func; in mtk_build_functions()
626 err = pinmux_generic_add_function(hw->pctrl, func->name, in mtk_build_functions()
627 func->groups, func->ngroups, in mtk_build_functions()
628 function->data); in mtk_build_functions()
630 dev_err(hw->dev, "Failed to register function %s\n", in mtk_build_functions()
631 func->name); in mtk_build_functions()
642 struct device *dev = &pdev->dev; in mtk_moore_pinctrl_probe()
647 hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); in mtk_moore_pinctrl_probe()
649 return -ENOMEM; in mtk_moore_pinctrl_probe()
651 hw->soc = soc; in mtk_moore_pinctrl_probe()
652 hw->dev = &pdev->dev; in mtk_moore_pinctrl_probe()
654 if (!hw->soc->nbase_names) in mtk_moore_pinctrl_probe()
655 return dev_err_probe(dev, -EINVAL, in mtk_moore_pinctrl_probe()
658 hw->base = devm_kmalloc_array(&pdev->dev, hw->soc->nbase_names, in mtk_moore_pinctrl_probe()
659 sizeof(*hw->base), GFP_KERNEL); in mtk_moore_pinctrl_probe()
660 if (!hw->base) in mtk_moore_pinctrl_probe()
661 return -ENOMEM; in mtk_moore_pinctrl_probe()
663 for (i = 0; i < hw->soc->nbase_names; i++) { in mtk_moore_pinctrl_probe()
664 hw->base[i] = devm_platform_ioremap_resource_byname(pdev, in mtk_moore_pinctrl_probe()
665 hw->soc->base_names[i]); in mtk_moore_pinctrl_probe()
666 if (IS_ERR(hw->base[i])) in mtk_moore_pinctrl_probe()
667 return PTR_ERR(hw->base[i]); in mtk_moore_pinctrl_probe()
670 hw->nbase = hw->soc->nbase_names; in mtk_moore_pinctrl_probe()
672 spin_lock_init(&hw->lock); in mtk_moore_pinctrl_probe()
675 pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), in mtk_moore_pinctrl_probe()
678 return -ENOMEM; in mtk_moore_pinctrl_probe()
680 for (i = 0; i < hw->soc->npins; i++) { in mtk_moore_pinctrl_probe()
681 pins[i].number = hw->soc->pins[i].number; in mtk_moore_pinctrl_probe()
682 pins[i].name = hw->soc->pins[i].name; in mtk_moore_pinctrl_probe()
687 mtk_desc.npins = hw->soc->npins; in mtk_moore_pinctrl_probe()
694 err = devm_pinctrl_register_and_init(&pdev->dev, &mtk_desc, hw, in mtk_moore_pinctrl_probe()
695 &hw->pctrl); in mtk_moore_pinctrl_probe()
712 err = pinctrl_enable(hw->pctrl); in mtk_moore_pinctrl_probe()
718 dev_warn(&pdev->dev, in mtk_moore_pinctrl_probe()