1 // SPDX-License-Identifier: GPL-2.0
3 * MediaTek Pinctrl Paris Driver, which implement the vendor per-pin
4 * bindings for MediaTek SoC.
6 * Copyright (C) 2018 MediaTek Inc.
7 * Author: Sean Wang <sean.wang@mediatek.com>
8 * Zhiyong Tao <zhiyong.tao@mediatek.com>
9 * Hongzhou.Yang <hongzhou.yang@mediatek.com>
12 #include <linux/gpio/driver.h>
13 #include <dt-bindings/pinctrl/mt65xx.h>
14 #include "pinctrl-paris.h"
16 #define PINCTRL_PINCTRL_DEV KBUILD_MODNAME
18 /* Custom pinconf parameters */
19 #define MTK_PIN_CONFIG_TDSEL (PIN_CONFIG_END + 1)
20 #define MTK_PIN_CONFIG_RDSEL (PIN_CONFIG_END + 2)
21 #define MTK_PIN_CONFIG_PU_ADV (PIN_CONFIG_END + 3)
22 #define MTK_PIN_CONFIG_PD_ADV (PIN_CONFIG_END + 4)
23 #define MTK_PIN_CONFIG_DRV_ADV (PIN_CONFIG_END + 5)
25 static const struct pinconf_generic_params mtk_custom_bindings
[] = {
26 {"mediatek,tdsel", MTK_PIN_CONFIG_TDSEL
, 0},
27 {"mediatek,rdsel", MTK_PIN_CONFIG_RDSEL
, 0},
28 {"mediatek,pull-up-adv", MTK_PIN_CONFIG_PU_ADV
, 1},
29 {"mediatek,pull-down-adv", MTK_PIN_CONFIG_PD_ADV
, 1},
30 {"mediatek,drive-strength-adv", MTK_PIN_CONFIG_DRV_ADV
, 2},
33 #ifdef CONFIG_DEBUG_FS
34 static const struct pin_config_item mtk_conf_items
[] = {
35 PCONFDUMP(MTK_PIN_CONFIG_TDSEL
, "tdsel", NULL
, true),
36 PCONFDUMP(MTK_PIN_CONFIG_RDSEL
, "rdsel", NULL
, true),
37 PCONFDUMP(MTK_PIN_CONFIG_PU_ADV
, "pu-adv", NULL
, true),
38 PCONFDUMP(MTK_PIN_CONFIG_PD_ADV
, "pd-adv", NULL
, true),
39 PCONFDUMP(MTK_PIN_CONFIG_DRV_ADV
, "drive-strength-adv", NULL
, true),
43 static const char * const mtk_gpio_functions
[] = {
44 "func0", "func1", "func2", "func3",
45 "func4", "func5", "func6", "func7",
46 "func8", "func9", "func10", "func11",
47 "func12", "func13", "func14", "func15",
50 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev
*pctldev
,
51 struct pinctrl_gpio_range
*range
,
54 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
55 const struct mtk_pin_desc
*desc
;
57 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
59 return mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_MODE
,
63 static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev
*pctldev
,
64 struct pinctrl_gpio_range
*range
,
65 unsigned int pin
, bool input
)
67 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
68 const struct mtk_pin_desc
*desc
;
70 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
72 /* hardware would take 0 as input direction */
73 return mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, !input
);
76 static int mtk_pinconf_get(struct pinctrl_dev
*pctldev
,
77 unsigned int pin
, unsigned long *config
)
79 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
80 u32 param
= pinconf_to_config_param(*config
);
81 int val
, val2
, err
, reg
, ret
= 1;
82 const struct mtk_pin_desc
*desc
;
84 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
87 case PIN_CONFIG_BIAS_DISABLE
:
88 if (hw
->soc
->bias_disable_get
) {
89 err
= hw
->soc
->bias_disable_get(hw
, desc
, &ret
);
96 case PIN_CONFIG_BIAS_PULL_UP
:
97 if (hw
->soc
->bias_get
) {
98 err
= hw
->soc
->bias_get(hw
, desc
, 1, &ret
);
105 case PIN_CONFIG_BIAS_PULL_DOWN
:
106 if (hw
->soc
->bias_get
) {
107 err
= hw
->soc
->bias_get(hw
, desc
, 0, &ret
);
114 case PIN_CONFIG_SLEW_RATE
:
115 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_SR
, &val
);
123 case PIN_CONFIG_INPUT_ENABLE
:
124 case PIN_CONFIG_OUTPUT_ENABLE
:
125 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &val
);
129 /* HW takes input mode as zero; output mode as non-zero */
130 if ((val
&& param
== PIN_CONFIG_INPUT_ENABLE
) ||
131 (!val
&& param
== PIN_CONFIG_OUTPUT_ENABLE
))
135 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
136 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &val
);
140 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_SMT
, &val2
);
148 case PIN_CONFIG_DRIVE_STRENGTH
:
149 if (hw
->soc
->drive_get
) {
150 err
= hw
->soc
->drive_get(hw
, desc
, &ret
);
157 case MTK_PIN_CONFIG_TDSEL
:
158 case MTK_PIN_CONFIG_RDSEL
:
159 reg
= (param
== MTK_PIN_CONFIG_TDSEL
) ?
160 PINCTRL_PIN_REG_TDSEL
: PINCTRL_PIN_REG_RDSEL
;
162 err
= mtk_hw_get_value(hw
, desc
, reg
, &val
);
169 case MTK_PIN_CONFIG_PU_ADV
:
170 case MTK_PIN_CONFIG_PD_ADV
:
171 if (hw
->soc
->adv_pull_get
) {
174 pullup
= param
== MTK_PIN_CONFIG_PU_ADV
;
175 err
= hw
->soc
->adv_pull_get(hw
, desc
, pullup
, &ret
);
182 case MTK_PIN_CONFIG_DRV_ADV
:
183 if (hw
->soc
->adv_drive_get
) {
184 err
= hw
->soc
->adv_drive_get(hw
, desc
, &ret
);
195 *config
= pinconf_to_config_packed(param
, ret
);
200 static int mtk_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
201 enum pin_config_param param
,
202 enum pin_config_param arg
)
204 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
205 const struct mtk_pin_desc
*desc
;
209 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
211 switch ((u32
)param
) {
212 case PIN_CONFIG_BIAS_DISABLE
:
213 if (hw
->soc
->bias_disable_set
) {
214 err
= hw
->soc
->bias_disable_set(hw
, desc
);
221 case PIN_CONFIG_BIAS_PULL_UP
:
222 if (hw
->soc
->bias_set
) {
223 err
= hw
->soc
->bias_set(hw
, desc
, 1);
230 case PIN_CONFIG_BIAS_PULL_DOWN
:
231 if (hw
->soc
->bias_set
) {
232 err
= hw
->soc
->bias_set(hw
, desc
, 0);
239 case PIN_CONFIG_OUTPUT_ENABLE
:
240 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SMT
,
245 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
250 case PIN_CONFIG_INPUT_ENABLE
:
251 if (hw
->soc
->ies_present
) {
252 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_IES
,
256 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
261 case PIN_CONFIG_SLEW_RATE
:
262 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SR
,
268 case PIN_CONFIG_OUTPUT
:
269 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
274 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DO
,
279 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
280 /* arg = 1: Input mode & SMT enable ;
281 * arg = 0: Output mode & SMT disable
284 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
289 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SMT
,
294 case PIN_CONFIG_DRIVE_STRENGTH
:
295 if (hw
->soc
->drive_set
) {
296 err
= hw
->soc
->drive_set(hw
, desc
, arg
);
303 case MTK_PIN_CONFIG_TDSEL
:
304 case MTK_PIN_CONFIG_RDSEL
:
305 reg
= (param
== MTK_PIN_CONFIG_TDSEL
) ?
306 PINCTRL_PIN_REG_TDSEL
: PINCTRL_PIN_REG_RDSEL
;
308 err
= mtk_hw_set_value(hw
, desc
, reg
, arg
);
312 case MTK_PIN_CONFIG_PU_ADV
:
313 case MTK_PIN_CONFIG_PD_ADV
:
314 if (hw
->soc
->adv_pull_set
) {
317 pullup
= param
== MTK_PIN_CONFIG_PU_ADV
;
318 err
= hw
->soc
->adv_pull_set(hw
, desc
, pullup
,
326 case MTK_PIN_CONFIG_DRV_ADV
:
327 if (hw
->soc
->adv_drive_set
) {
328 err
= hw
->soc
->adv_drive_set(hw
, desc
, arg
);
343 static struct mtk_pinctrl_group
*
344 mtk_pctrl_find_group_by_pin(struct mtk_pinctrl
*hw
, u32 pin
)
348 for (i
= 0; i
< hw
->soc
->ngrps
; i
++) {
349 struct mtk_pinctrl_group
*grp
= hw
->groups
+ i
;
358 static const struct mtk_func_desc
*
359 mtk_pctrl_find_function_by_pin(struct mtk_pinctrl
*hw
, u32 pin_num
, u32 fnum
)
361 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ pin_num
;
362 const struct mtk_func_desc
*func
= pin
->funcs
;
364 while (func
&& func
->name
) {
365 if (func
->muxval
== fnum
)
373 static bool mtk_pctrl_is_function_valid(struct mtk_pinctrl
*hw
, u32 pin_num
,
378 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
379 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ i
;
381 if (pin
->number
== pin_num
) {
382 const struct mtk_func_desc
*func
= pin
->funcs
;
384 while (func
&& func
->name
) {
385 if (func
->muxval
== fnum
)
397 static int mtk_pctrl_dt_node_to_map_func(struct mtk_pinctrl
*pctl
,
399 struct mtk_pinctrl_group
*grp
,
400 struct pinctrl_map
**map
,
401 unsigned *reserved_maps
,
406 if (*num_maps
== *reserved_maps
)
409 (*map
)[*num_maps
].type
= PIN_MAP_TYPE_MUX_GROUP
;
410 (*map
)[*num_maps
].data
.mux
.group
= grp
->name
;
412 ret
= mtk_pctrl_is_function_valid(pctl
, pin
, fnum
);
414 dev_err(pctl
->dev
, "invalid function %d on pin %d .\n",
419 (*map
)[*num_maps
].data
.mux
.function
= mtk_gpio_functions
[fnum
];
425 static int mtk_pctrl_dt_subnode_to_map(struct pinctrl_dev
*pctldev
,
426 struct device_node
*node
,
427 struct pinctrl_map
**map
,
428 unsigned *reserved_maps
,
431 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
432 int num_pins
, num_funcs
, maps_per_pin
, i
, err
;
433 struct mtk_pinctrl_group
*grp
;
434 unsigned int num_configs
;
435 bool has_config
= false;
436 unsigned long *configs
;
437 u32 pinfunc
, pin
, func
;
438 struct property
*pins
;
439 unsigned reserve
= 0;
441 pins
= of_find_property(node
, "pinmux", NULL
);
443 dev_err(hw
->dev
, "missing pins property in node %pOFn .\n",
448 err
= pinconf_generic_parse_dt_config(node
, pctldev
, &configs
,
456 num_pins
= pins
->length
/ sizeof(u32
);
457 num_funcs
= num_pins
;
461 if (has_config
&& num_pins
>= 1)
464 if (!num_pins
|| !maps_per_pin
) {
469 reserve
= num_pins
* maps_per_pin
;
471 err
= pinctrl_utils_reserve_map(pctldev
, map
, reserved_maps
, num_maps
,
476 for (i
= 0; i
< num_pins
; i
++) {
477 err
= of_property_read_u32_index(node
, "pinmux", i
, &pinfunc
);
481 pin
= MTK_GET_PIN_NO(pinfunc
);
482 func
= MTK_GET_PIN_FUNC(pinfunc
);
484 if (pin
>= hw
->soc
->npins
||
485 func
>= ARRAY_SIZE(mtk_gpio_functions
)) {
486 dev_err(hw
->dev
, "invalid pins value.\n");
491 grp
= mtk_pctrl_find_group_by_pin(hw
, pin
);
493 dev_err(hw
->dev
, "unable to match pin %d to group\n",
499 err
= mtk_pctrl_dt_node_to_map_func(hw
, pin
, func
, grp
, map
,
500 reserved_maps
, num_maps
);
505 err
= pinctrl_utils_add_map_configs(pctldev
, map
,
511 PIN_MAP_TYPE_CONFIGS_GROUP
);
524 static int mtk_pctrl_dt_node_to_map(struct pinctrl_dev
*pctldev
,
525 struct device_node
*np_config
,
526 struct pinctrl_map
**map
,
529 struct device_node
*np
;
530 unsigned reserved_maps
;
537 for_each_child_of_node(np_config
, np
) {
538 ret
= mtk_pctrl_dt_subnode_to_map(pctldev
, np
, map
,
542 pinctrl_utils_free_map(pctldev
, *map
, *num_maps
);
551 static int mtk_pctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
553 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
555 return hw
->soc
->ngrps
;
558 static const char *mtk_pctrl_get_group_name(struct pinctrl_dev
*pctldev
,
561 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
563 return hw
->groups
[group
].name
;
566 static int mtk_pctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
567 unsigned group
, const unsigned **pins
,
570 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
572 *pins
= (unsigned *)&hw
->groups
[group
].pin
;
578 static const struct pinctrl_ops mtk_pctlops
= {
579 .dt_node_to_map
= mtk_pctrl_dt_node_to_map
,
580 .dt_free_map
= pinctrl_utils_free_map
,
581 .get_groups_count
= mtk_pctrl_get_groups_count
,
582 .get_group_name
= mtk_pctrl_get_group_name
,
583 .get_group_pins
= mtk_pctrl_get_group_pins
,
586 static int mtk_pmx_get_funcs_cnt(struct pinctrl_dev
*pctldev
)
588 return ARRAY_SIZE(mtk_gpio_functions
);
591 static const char *mtk_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
594 return mtk_gpio_functions
[selector
];
597 static int mtk_pmx_get_func_groups(struct pinctrl_dev
*pctldev
,
599 const char * const **groups
,
600 unsigned * const num_groups
)
602 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
604 *groups
= hw
->grp_names
;
605 *num_groups
= hw
->soc
->ngrps
;
610 static int mtk_pmx_set_mux(struct pinctrl_dev
*pctldev
,
614 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
615 struct mtk_pinctrl_group
*grp
= hw
->groups
+ group
;
616 const struct mtk_func_desc
*desc_func
;
617 const struct mtk_pin_desc
*desc
;
620 ret
= mtk_pctrl_is_function_valid(hw
, grp
->pin
, function
);
622 dev_err(hw
->dev
, "invalid function %d on group %d .\n",
627 desc_func
= mtk_pctrl_find_function_by_pin(hw
, grp
->pin
, function
);
631 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[grp
->pin
];
632 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_MODE
, desc_func
->muxval
);
637 static const struct pinmux_ops mtk_pmxops
= {
638 .get_functions_count
= mtk_pmx_get_funcs_cnt
,
639 .get_function_name
= mtk_pmx_get_func_name
,
640 .get_function_groups
= mtk_pmx_get_func_groups
,
641 .set_mux
= mtk_pmx_set_mux
,
642 .gpio_set_direction
= mtk_pinmux_gpio_set_direction
,
643 .gpio_request_enable
= mtk_pinmux_gpio_request_enable
,
646 static int mtk_pconf_group_get(struct pinctrl_dev
*pctldev
, unsigned group
,
647 unsigned long *config
)
649 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
651 *config
= hw
->groups
[group
].config
;
656 static int mtk_pconf_group_set(struct pinctrl_dev
*pctldev
, unsigned group
,
657 unsigned long *configs
, unsigned num_configs
)
659 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
660 struct mtk_pinctrl_group
*grp
= &hw
->groups
[group
];
663 for (i
= 0; i
< num_configs
; i
++) {
664 ret
= mtk_pinconf_set(pctldev
, grp
->pin
,
665 pinconf_to_config_param(configs
[i
]),
666 pinconf_to_config_argument(configs
[i
]));
670 grp
->config
= configs
[i
];
676 static const struct pinconf_ops mtk_confops
= {
677 .pin_config_get
= mtk_pinconf_get
,
678 .pin_config_group_get
= mtk_pconf_group_get
,
679 .pin_config_group_set
= mtk_pconf_group_set
,
682 static struct pinctrl_desc mtk_desc
= {
683 .name
= PINCTRL_PINCTRL_DEV
,
684 .pctlops
= &mtk_pctlops
,
685 .pmxops
= &mtk_pmxops
,
686 .confops
= &mtk_confops
,
687 .owner
= THIS_MODULE
,
690 static int mtk_gpio_get_direction(struct gpio_chip
*chip
, unsigned int gpio
)
692 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
693 const struct mtk_pin_desc
*desc
;
696 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
698 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &value
);
705 static int mtk_gpio_get(struct gpio_chip
*chip
, unsigned int gpio
)
707 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
708 const struct mtk_pin_desc
*desc
;
711 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
713 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DI
, &value
);
720 static void mtk_gpio_set(struct gpio_chip
*chip
, unsigned int gpio
, int value
)
722 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
723 const struct mtk_pin_desc
*desc
;
725 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
727 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DO
, !!value
);
730 static int mtk_gpio_direction_input(struct gpio_chip
*chip
, unsigned int gpio
)
732 return pinctrl_gpio_direction_input(chip
->base
+ gpio
);
735 static int mtk_gpio_direction_output(struct gpio_chip
*chip
, unsigned int gpio
,
738 mtk_gpio_set(chip
, gpio
, value
);
740 return pinctrl_gpio_direction_output(chip
->base
+ gpio
);
743 static int mtk_gpio_to_irq(struct gpio_chip
*chip
, unsigned int offset
)
745 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
746 const struct mtk_pin_desc
*desc
;
751 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[offset
];
753 if (desc
->eint
.eint_n
== EINT_NA
)
756 return mtk_eint_find_irq(hw
->eint
, desc
->eint
.eint_n
);
759 static int mtk_gpio_set_config(struct gpio_chip
*chip
, unsigned int offset
,
760 unsigned long config
)
762 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
763 const struct mtk_pin_desc
*desc
;
766 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[offset
];
769 pinconf_to_config_param(config
) != PIN_CONFIG_INPUT_DEBOUNCE
||
770 desc
->eint
.eint_n
== EINT_NA
)
773 debounce
= pinconf_to_config_argument(config
);
775 return mtk_eint_set_debounce(hw
->eint
, desc
->eint
.eint_n
, debounce
);
778 static int mtk_build_gpiochip(struct mtk_pinctrl
*hw
, struct device_node
*np
)
780 struct gpio_chip
*chip
= &hw
->chip
;
783 chip
->label
= PINCTRL_PINCTRL_DEV
;
784 chip
->parent
= hw
->dev
;
785 chip
->request
= gpiochip_generic_request
;
786 chip
->free
= gpiochip_generic_free
;
787 chip
->get_direction
= mtk_gpio_get_direction
;
788 chip
->direction_input
= mtk_gpio_direction_input
;
789 chip
->direction_output
= mtk_gpio_direction_output
;
790 chip
->get
= mtk_gpio_get
;
791 chip
->set
= mtk_gpio_set
;
792 chip
->to_irq
= mtk_gpio_to_irq
,
793 chip
->set_config
= mtk_gpio_set_config
,
795 chip
->ngpio
= hw
->soc
->npins
;
797 chip
->of_gpio_n_cells
= 2;
799 ret
= gpiochip_add_data(chip
, hw
);
806 static int mtk_pctrl_build_state(struct platform_device
*pdev
)
808 struct mtk_pinctrl
*hw
= platform_get_drvdata(pdev
);
811 /* Allocate groups */
812 hw
->groups
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->ngrps
,
813 sizeof(*hw
->groups
), GFP_KERNEL
);
817 /* We assume that one pin is one group, use pin name as group name. */
818 hw
->grp_names
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->ngrps
,
819 sizeof(*hw
->grp_names
), GFP_KERNEL
);
823 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
824 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ i
;
825 struct mtk_pinctrl_group
*group
= hw
->groups
+ i
;
827 group
->name
= pin
->name
;
828 group
->pin
= pin
->number
;
830 hw
->grp_names
[i
] = pin
->name
;
836 int mtk_paris_pinctrl_probe(struct platform_device
*pdev
,
837 const struct mtk_pin_soc
*soc
)
839 struct pinctrl_pin_desc
*pins
;
840 struct mtk_pinctrl
*hw
;
841 struct resource
*res
;
844 hw
= devm_kzalloc(&pdev
->dev
, sizeof(*hw
), GFP_KERNEL
);
848 platform_set_drvdata(pdev
, hw
);
850 hw
->dev
= &pdev
->dev
;
852 if (!hw
->soc
->nbase_names
) {
854 "SoC should be assigned at least one register base\n");
858 hw
->base
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->nbase_names
,
859 sizeof(*hw
->base
), GFP_KERNEL
);
863 for (i
= 0; i
< hw
->soc
->nbase_names
; i
++) {
864 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
865 hw
->soc
->base_names
[i
]);
867 dev_err(&pdev
->dev
, "missing IO resource\n");
871 hw
->base
[i
] = devm_ioremap_resource(&pdev
->dev
, res
);
872 if (IS_ERR(hw
->base
[i
]))
873 return PTR_ERR(hw
->base
[i
]);
876 hw
->nbase
= hw
->soc
->nbase_names
;
878 err
= mtk_pctrl_build_state(pdev
);
880 dev_err(&pdev
->dev
, "build state failed: %d\n", err
);
884 /* Copy from internal struct mtk_pin_desc to register to the core */
885 pins
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->npins
, sizeof(*pins
),
890 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
891 pins
[i
].number
= hw
->soc
->pins
[i
].number
;
892 pins
[i
].name
= hw
->soc
->pins
[i
].name
;
895 /* Setup pins descriptions per SoC types */
896 mtk_desc
.pins
= (const struct pinctrl_pin_desc
*)pins
;
897 mtk_desc
.npins
= hw
->soc
->npins
;
898 mtk_desc
.num_custom_params
= ARRAY_SIZE(mtk_custom_bindings
);
899 mtk_desc
.custom_params
= mtk_custom_bindings
;
900 #ifdef CONFIG_DEBUG_FS
901 mtk_desc
.custom_conf_items
= mtk_conf_items
;
904 err
= devm_pinctrl_register_and_init(&pdev
->dev
, &mtk_desc
, hw
,
909 err
= pinctrl_enable(hw
->pctrl
);
913 err
= mtk_build_eint(hw
, pdev
);
916 "Failed to add EINT, but pinctrl still can work\n");
918 /* Build gpiochip should be after pinctrl_enable is done */
919 err
= mtk_build_gpiochip(hw
, pdev
->dev
.of_node
);
921 dev_err(&pdev
->dev
, "Failed to add gpio_chip\n");
925 platform_set_drvdata(pdev
, hw
);
930 static int mtk_paris_pinctrl_suspend(struct device
*device
)
932 struct mtk_pinctrl
*pctl
= dev_get_drvdata(device
);
934 return mtk_eint_do_suspend(pctl
->eint
);
937 static int mtk_paris_pinctrl_resume(struct device
*device
)
939 struct mtk_pinctrl
*pctl
= dev_get_drvdata(device
);
941 return mtk_eint_do_resume(pctl
->eint
);
944 const struct dev_pm_ops mtk_paris_pinctrl_pm_ops
= {
945 .suspend_noirq
= mtk_paris_pinctrl_suspend
,
946 .resume_noirq
= mtk_paris_pinctrl_resume
,