Lines Matching +full:per +full:- +full:soc
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.
12 #include "pinctrl-moore.h"
25 {"mediatek,pull-up-adv", MTK_PIN_CONFIG_PU_ADV, 1},
26 {"mediatek,pull-down-adv", MTK_PIN_CONFIG_PD_ADV, 1},
33 PCONFDUMP(MTK_PIN_CONFIG_PU_ADV, "pu-adv", NULL, true),
34 PCONFDUMP(MTK_PIN_CONFIG_PD_ADV, "pd-adv", NULL, true),
48 return -EINVAL; in mtk_pinmux_set_mux()
52 return -EINVAL; in mtk_pinmux_set_mux()
54 dev_dbg(pctldev->dev, "enable function %s group %s\n", in mtk_pinmux_set_mux()
55 func->name, grp->name); in mtk_pinmux_set_mux()
57 for (i = 0; i < grp->num_pins; i++) { in mtk_pinmux_set_mux()
59 int *pin_modes = grp->data; in mtk_pinmux_set_mux()
60 int pin = grp->pins[i]; in mtk_pinmux_set_mux()
62 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_set_mux()
78 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_request_enable()
81 hw->soc->gpio_m); in mtk_pinmux_gpio_request_enable()
91 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinmux_gpio_set_direction()
105 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_get()
109 if (hw->soc->bias_disable_get) { in mtk_pinconf_get()
110 err = hw->soc->bias_disable_get(hw, desc, &ret); in mtk_pinconf_get()
114 return -ENOTSUPP; in mtk_pinconf_get()
118 if (hw->soc->bias_get) { in mtk_pinconf_get()
119 err = hw->soc->bias_get(hw, desc, 1, &ret); in mtk_pinconf_get()
123 return -ENOTSUPP; in mtk_pinconf_get()
127 if (hw->soc->bias_get) { in mtk_pinconf_get()
128 err = hw->soc->bias_get(hw, desc, 0, &ret); in mtk_pinconf_get()
132 return -ENOTSUPP; in mtk_pinconf_get()
141 return -EINVAL; in mtk_pinconf_get()
150 /* HW takes input mode as zero; output mode as non-zero */ in mtk_pinconf_get()
153 return -EINVAL; in mtk_pinconf_get()
166 return -EINVAL; in mtk_pinconf_get()
170 if (hw->soc->drive_get) { in mtk_pinconf_get()
171 err = hw->soc->drive_get(hw, desc, &ret); in mtk_pinconf_get()
175 err = -ENOTSUPP; in mtk_pinconf_get()
192 if (hw->soc->adv_pull_get) { in mtk_pinconf_get()
196 err = hw->soc->adv_pull_get(hw, desc, pullup, &ret); in mtk_pinconf_get()
200 return -ENOTSUPP; in mtk_pinconf_get()
204 return -ENOTSUPP; in mtk_pinconf_get()
220 desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin]; in mtk_pinconf_set()
228 if (hw->soc->bias_disable_set) { in mtk_pinconf_set()
229 err = hw->soc->bias_disable_set(hw, desc); in mtk_pinconf_set()
233 return -ENOTSUPP; in mtk_pinconf_set()
237 if (hw->soc->bias_set) { in mtk_pinconf_set()
238 err = hw->soc->bias_set(hw, desc, 1); in mtk_pinconf_set()
242 return -ENOTSUPP; in mtk_pinconf_set()
246 if (hw->soc->bias_set) { in mtk_pinconf_set()
247 err = hw->soc->bias_set(hw, desc, 0); in mtk_pinconf_set()
251 return -ENOTSUPP; in mtk_pinconf_set()
267 if (hw->soc->ies_present) { in mtk_pinconf_set()
311 if (hw->soc->drive_set) { in mtk_pinconf_set()
312 err = hw->soc->drive_set(hw, desc, arg); in mtk_pinconf_set()
316 err = -ENOTSUPP; in mtk_pinconf_set()
330 if (hw->soc->adv_pull_set) { in mtk_pinconf_set()
334 err = hw->soc->adv_pull_set(hw, desc, pullup, in mtk_pinconf_set()
339 return -ENOTSUPP; in mtk_pinconf_set()
343 err = -ENOTSUPP; in mtk_pinconf_set()
363 return -ENOTSUPP; in mtk_pinconf_group_get()
367 return -ENOTSUPP; in mtk_pinconf_group_get()
437 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_get()
451 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; in mtk_gpio_set()
458 return pinctrl_gpio_direction_input(chip->base + gpio); in mtk_gpio_direction_input()
466 return pinctrl_gpio_direction_output(chip->base + gpio); in mtk_gpio_direction_output()
474 if (!hw->eint) in mtk_gpio_to_irq()
475 return -ENOTSUPP; in mtk_gpio_to_irq()
477 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_to_irq()
479 if (desc->eint.eint_n == (u16)EINT_NA) in mtk_gpio_to_irq()
480 return -ENOTSUPP; in mtk_gpio_to_irq()
482 return mtk_eint_find_irq(hw->eint, desc->eint.eint_n); in mtk_gpio_to_irq()
492 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; in mtk_gpio_set_config()
494 if (!hw->eint || in mtk_gpio_set_config()
496 desc->eint.eint_n == (u16)EINT_NA) in mtk_gpio_set_config()
497 return -ENOTSUPP; in mtk_gpio_set_config()
501 return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); in mtk_gpio_set_config()
506 struct gpio_chip *chip = &hw->chip; in mtk_build_gpiochip()
509 chip->label = PINCTRL_PINCTRL_DEV; in mtk_build_gpiochip()
510 chip->parent = hw->dev; in mtk_build_gpiochip()
511 chip->request = gpiochip_generic_request; in mtk_build_gpiochip()
512 chip->free = gpiochip_generic_free; in mtk_build_gpiochip()
513 chip->direction_input = mtk_gpio_direction_input; in mtk_build_gpiochip()
514 chip->direction_output = mtk_gpio_direction_output; in mtk_build_gpiochip()
515 chip->get = mtk_gpio_get; in mtk_build_gpiochip()
516 chip->set = mtk_gpio_set; in mtk_build_gpiochip()
517 chip->to_irq = mtk_gpio_to_irq, in mtk_build_gpiochip()
518 chip->set_config = mtk_gpio_set_config, in mtk_build_gpiochip()
519 chip->base = -1; in mtk_build_gpiochip()
520 chip->ngpio = hw->soc->npins; in mtk_build_gpiochip()
521 chip->of_node = np; in mtk_build_gpiochip()
522 chip->of_gpio_n_cells = 2; in mtk_build_gpiochip()
529 * "gpio-ranges" property. Otherwise, called directly from a in mtk_build_gpiochip()
530 * DeviceTree-supported pinctrl driver is DEPRECATED. in mtk_build_gpiochip()
533 * bind pinctrl and gpio drivers via the "gpio-ranges" property. in mtk_build_gpiochip()
535 if (!of_find_property(np, "gpio-ranges", NULL)) { in mtk_build_gpiochip()
536 ret = gpiochip_add_pin_range(chip, dev_name(hw->dev), 0, 0, in mtk_build_gpiochip()
537 chip->ngpio); in mtk_build_gpiochip()
551 for (i = 0; i < hw->soc->ngrps; i++) { in mtk_build_groups()
552 const struct group_desc *group = hw->soc->grps + i; in mtk_build_groups()
554 err = pinctrl_generic_add_group(hw->pctrl, group->name, in mtk_build_groups()
555 group->pins, group->num_pins, in mtk_build_groups()
556 group->data); in mtk_build_groups()
558 dev_err(hw->dev, "Failed to register group %s\n", in mtk_build_groups()
559 group->name); in mtk_build_groups()
571 for (i = 0; i < hw->soc->nfuncs ; i++) { in mtk_build_functions()
572 const struct function_desc *func = hw->soc->funcs + i; in mtk_build_functions()
574 err = pinmux_generic_add_function(hw->pctrl, func->name, in mtk_build_functions()
575 func->group_names, in mtk_build_functions()
576 func->num_group_names, in mtk_build_functions()
577 func->data); in mtk_build_functions()
579 dev_err(hw->dev, "Failed to register function %s\n", in mtk_build_functions()
580 func->name); in mtk_build_functions()
589 const struct mtk_pin_soc *soc) in mtk_moore_pinctrl_probe() argument
595 hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); in mtk_moore_pinctrl_probe()
597 return -ENOMEM; in mtk_moore_pinctrl_probe()
599 hw->soc = soc; in mtk_moore_pinctrl_probe()
600 hw->dev = &pdev->dev; in mtk_moore_pinctrl_probe()
602 if (!hw->soc->nbase_names) { in mtk_moore_pinctrl_probe()
603 dev_err(&pdev->dev, in mtk_moore_pinctrl_probe()
604 "SoC should be assigned at least one register base\n"); in mtk_moore_pinctrl_probe()
605 return -EINVAL; in mtk_moore_pinctrl_probe()
608 hw->base = devm_kmalloc_array(&pdev->dev, hw->soc->nbase_names, in mtk_moore_pinctrl_probe()
609 sizeof(*hw->base), GFP_KERNEL); in mtk_moore_pinctrl_probe()
610 if (!hw->base) in mtk_moore_pinctrl_probe()
611 return -ENOMEM; in mtk_moore_pinctrl_probe()
613 for (i = 0; i < hw->soc->nbase_names; i++) { in mtk_moore_pinctrl_probe()
614 hw->base[i] = devm_platform_ioremap_resource_byname(pdev, in mtk_moore_pinctrl_probe()
615 hw->soc->base_names[i]); in mtk_moore_pinctrl_probe()
616 if (IS_ERR(hw->base[i])) in mtk_moore_pinctrl_probe()
617 return PTR_ERR(hw->base[i]); in mtk_moore_pinctrl_probe()
620 hw->nbase = hw->soc->nbase_names; in mtk_moore_pinctrl_probe()
623 pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), in mtk_moore_pinctrl_probe()
626 return -ENOMEM; in mtk_moore_pinctrl_probe()
628 for (i = 0; i < hw->soc->npins; i++) { in mtk_moore_pinctrl_probe()
629 pins[i].number = hw->soc->pins[i].number; in mtk_moore_pinctrl_probe()
630 pins[i].name = hw->soc->pins[i].name; in mtk_moore_pinctrl_probe()
633 /* Setup pins descriptions per SoC types */ in mtk_moore_pinctrl_probe()
635 mtk_desc.npins = hw->soc->npins; in mtk_moore_pinctrl_probe()
642 err = devm_pinctrl_register_and_init(&pdev->dev, &mtk_desc, hw, in mtk_moore_pinctrl_probe()
643 &hw->pctrl); in mtk_moore_pinctrl_probe()
647 /* Setup groups descriptions per SoC types */ in mtk_moore_pinctrl_probe()
650 dev_err(&pdev->dev, "Failed to build groups\n"); in mtk_moore_pinctrl_probe()
654 /* Setup functions descriptions per SoC types */ in mtk_moore_pinctrl_probe()
657 dev_err(&pdev->dev, "Failed to build functions\n"); in mtk_moore_pinctrl_probe()
664 err = pinctrl_enable(hw->pctrl); in mtk_moore_pinctrl_probe()
670 dev_warn(&pdev->dev, in mtk_moore_pinctrl_probe()
674 err = mtk_build_gpiochip(hw, pdev->dev.of_node); in mtk_moore_pinctrl_probe()
676 dev_err(&pdev->dev, "Failed to add gpio_chip\n"); in mtk_moore_pinctrl_probe()