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)
24 static const struct pinconf_generic_params mtk_custom_bindings
[] = {
25 {"mediatek,tdsel", MTK_PIN_CONFIG_TDSEL
, 0},
26 {"mediatek,rdsel", MTK_PIN_CONFIG_RDSEL
, 0},
27 {"mediatek,pull-up-adv", MTK_PIN_CONFIG_PU_ADV
, 1},
28 {"mediatek,pull-down-adv", MTK_PIN_CONFIG_PD_ADV
, 1},
31 #ifdef CONFIG_DEBUG_FS
32 static const struct pin_config_item mtk_conf_items
[] = {
33 PCONFDUMP(MTK_PIN_CONFIG_TDSEL
, "tdsel", NULL
, true),
34 PCONFDUMP(MTK_PIN_CONFIG_RDSEL
, "rdsel", NULL
, true),
35 PCONFDUMP(MTK_PIN_CONFIG_PU_ADV
, "pu-adv", NULL
, true),
36 PCONFDUMP(MTK_PIN_CONFIG_PD_ADV
, "pd-adv", NULL
, true),
40 static const char * const mtk_gpio_functions
[] = {
41 "func0", "func1", "func2", "func3",
42 "func4", "func5", "func6", "func7",
43 "func8", "func9", "func10", "func11",
44 "func12", "func13", "func14", "func15",
47 static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev
*pctldev
,
48 struct pinctrl_gpio_range
*range
,
51 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
52 const struct mtk_pin_desc
*desc
;
54 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
56 return mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_MODE
,
60 static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev
*pctldev
,
61 struct pinctrl_gpio_range
*range
,
62 unsigned int pin
, bool input
)
64 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
65 const struct mtk_pin_desc
*desc
;
67 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
69 /* hardware would take 0 as input direction */
70 return mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, !input
);
73 static int mtk_pinconf_get(struct pinctrl_dev
*pctldev
,
74 unsigned int pin
, unsigned long *config
)
76 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
77 u32 param
= pinconf_to_config_param(*config
);
78 int val
, val2
, err
, reg
, ret
= 1;
79 const struct mtk_pin_desc
*desc
;
81 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
84 case PIN_CONFIG_BIAS_DISABLE
:
85 if (hw
->soc
->bias_disable_get
) {
86 err
= hw
->soc
->bias_disable_get(hw
, desc
, &ret
);
93 case PIN_CONFIG_BIAS_PULL_UP
:
94 if (hw
->soc
->bias_get
) {
95 err
= hw
->soc
->bias_get(hw
, desc
, 1, &ret
);
102 case PIN_CONFIG_BIAS_PULL_DOWN
:
103 if (hw
->soc
->bias_get
) {
104 err
= hw
->soc
->bias_get(hw
, desc
, 0, &ret
);
111 case PIN_CONFIG_SLEW_RATE
:
112 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_SR
, &val
);
120 case PIN_CONFIG_INPUT_ENABLE
:
121 case PIN_CONFIG_OUTPUT_ENABLE
:
122 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &val
);
126 /* HW takes input mode as zero; output mode as non-zero */
127 if ((val
&& param
== PIN_CONFIG_INPUT_ENABLE
) ||
128 (!val
&& param
== PIN_CONFIG_OUTPUT_ENABLE
))
132 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
133 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &val
);
137 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_SMT
, &val2
);
145 case PIN_CONFIG_DRIVE_STRENGTH
:
146 if (hw
->soc
->drive_get
) {
147 err
= hw
->soc
->drive_get(hw
, desc
, &ret
);
154 case MTK_PIN_CONFIG_TDSEL
:
155 case MTK_PIN_CONFIG_RDSEL
:
156 reg
= (param
== MTK_PIN_CONFIG_TDSEL
) ?
157 PINCTRL_PIN_REG_TDSEL
: PINCTRL_PIN_REG_RDSEL
;
159 err
= mtk_hw_get_value(hw
, desc
, reg
, &val
);
166 case MTK_PIN_CONFIG_PU_ADV
:
167 case MTK_PIN_CONFIG_PD_ADV
:
168 if (hw
->soc
->adv_pull_get
) {
171 pullup
= param
== MTK_PIN_CONFIG_PU_ADV
;
172 err
= hw
->soc
->adv_pull_get(hw
, desc
, pullup
, &ret
);
183 *config
= pinconf_to_config_packed(param
, ret
);
188 static int mtk_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
189 enum pin_config_param param
,
190 enum pin_config_param arg
)
192 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
193 const struct mtk_pin_desc
*desc
;
197 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[pin
];
199 switch ((u32
)param
) {
200 case PIN_CONFIG_BIAS_DISABLE
:
201 if (hw
->soc
->bias_disable_set
) {
202 err
= hw
->soc
->bias_disable_set(hw
, desc
);
209 case PIN_CONFIG_BIAS_PULL_UP
:
210 if (hw
->soc
->bias_set
) {
211 err
= hw
->soc
->bias_set(hw
, desc
, 1);
218 case PIN_CONFIG_BIAS_PULL_DOWN
:
219 if (hw
->soc
->bias_set
) {
220 err
= hw
->soc
->bias_set(hw
, desc
, 0);
227 case PIN_CONFIG_OUTPUT_ENABLE
:
228 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SMT
,
233 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
238 case PIN_CONFIG_INPUT_ENABLE
:
239 if (hw
->soc
->ies_present
) {
240 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_IES
,
244 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
249 case PIN_CONFIG_SLEW_RATE
:
250 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SR
,
256 case PIN_CONFIG_OUTPUT
:
257 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
262 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DO
,
267 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
268 /* arg = 1: Input mode & SMT enable ;
269 * arg = 0: Output mode & SMT disable
272 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DIR
,
277 err
= mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_SMT
,
282 case PIN_CONFIG_DRIVE_STRENGTH
:
283 if (hw
->soc
->drive_set
) {
284 err
= hw
->soc
->drive_set(hw
, desc
, arg
);
291 case MTK_PIN_CONFIG_TDSEL
:
292 case MTK_PIN_CONFIG_RDSEL
:
293 reg
= (param
== MTK_PIN_CONFIG_TDSEL
) ?
294 PINCTRL_PIN_REG_TDSEL
: PINCTRL_PIN_REG_RDSEL
;
296 err
= mtk_hw_set_value(hw
, desc
, reg
, arg
);
300 case MTK_PIN_CONFIG_PU_ADV
:
301 case MTK_PIN_CONFIG_PD_ADV
:
302 if (hw
->soc
->adv_pull_set
) {
305 pullup
= param
== MTK_PIN_CONFIG_PU_ADV
;
306 err
= hw
->soc
->adv_pull_set(hw
, desc
, pullup
,
322 static struct mtk_pinctrl_group
*
323 mtk_pctrl_find_group_by_pin(struct mtk_pinctrl
*hw
, u32 pin
)
327 for (i
= 0; i
< hw
->soc
->ngrps
; i
++) {
328 struct mtk_pinctrl_group
*grp
= hw
->groups
+ i
;
337 static const struct mtk_func_desc
*
338 mtk_pctrl_find_function_by_pin(struct mtk_pinctrl
*hw
, u32 pin_num
, u32 fnum
)
340 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ pin_num
;
341 const struct mtk_func_desc
*func
= pin
->funcs
;
343 while (func
&& func
->name
) {
344 if (func
->muxval
== fnum
)
352 static bool mtk_pctrl_is_function_valid(struct mtk_pinctrl
*hw
, u32 pin_num
,
357 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
358 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ i
;
360 if (pin
->number
== pin_num
) {
361 const struct mtk_func_desc
*func
= pin
->funcs
;
363 while (func
&& func
->name
) {
364 if (func
->muxval
== fnum
)
376 static int mtk_pctrl_dt_node_to_map_func(struct mtk_pinctrl
*pctl
,
378 struct mtk_pinctrl_group
*grp
,
379 struct pinctrl_map
**map
,
380 unsigned *reserved_maps
,
385 if (*num_maps
== *reserved_maps
)
388 (*map
)[*num_maps
].type
= PIN_MAP_TYPE_MUX_GROUP
;
389 (*map
)[*num_maps
].data
.mux
.group
= grp
->name
;
391 ret
= mtk_pctrl_is_function_valid(pctl
, pin
, fnum
);
393 dev_err(pctl
->dev
, "invalid function %d on pin %d .\n",
398 (*map
)[*num_maps
].data
.mux
.function
= mtk_gpio_functions
[fnum
];
404 static int mtk_pctrl_dt_subnode_to_map(struct pinctrl_dev
*pctldev
,
405 struct device_node
*node
,
406 struct pinctrl_map
**map
,
407 unsigned *reserved_maps
,
410 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
411 int num_pins
, num_funcs
, maps_per_pin
, i
, err
;
412 struct mtk_pinctrl_group
*grp
;
413 unsigned int num_configs
;
414 bool has_config
= false;
415 unsigned long *configs
;
416 u32 pinfunc
, pin
, func
;
417 struct property
*pins
;
418 unsigned reserve
= 0;
420 pins
= of_find_property(node
, "pinmux", NULL
);
422 dev_err(hw
->dev
, "missing pins property in node %pOFn .\n",
427 err
= pinconf_generic_parse_dt_config(node
, pctldev
, &configs
,
435 num_pins
= pins
->length
/ sizeof(u32
);
436 num_funcs
= num_pins
;
440 if (has_config
&& num_pins
>= 1)
443 if (!num_pins
|| !maps_per_pin
) {
448 reserve
= num_pins
* maps_per_pin
;
450 err
= pinctrl_utils_reserve_map(pctldev
, map
, reserved_maps
, num_maps
,
455 for (i
= 0; i
< num_pins
; i
++) {
456 err
= of_property_read_u32_index(node
, "pinmux", i
, &pinfunc
);
460 pin
= MTK_GET_PIN_NO(pinfunc
);
461 func
= MTK_GET_PIN_FUNC(pinfunc
);
463 if (pin
>= hw
->soc
->npins
||
464 func
>= ARRAY_SIZE(mtk_gpio_functions
)) {
465 dev_err(hw
->dev
, "invalid pins value.\n");
470 grp
= mtk_pctrl_find_group_by_pin(hw
, pin
);
472 dev_err(hw
->dev
, "unable to match pin %d to group\n",
478 err
= mtk_pctrl_dt_node_to_map_func(hw
, pin
, func
, grp
, map
,
479 reserved_maps
, num_maps
);
484 err
= pinctrl_utils_add_map_configs(pctldev
, map
,
490 PIN_MAP_TYPE_CONFIGS_GROUP
);
503 static int mtk_pctrl_dt_node_to_map(struct pinctrl_dev
*pctldev
,
504 struct device_node
*np_config
,
505 struct pinctrl_map
**map
,
508 struct device_node
*np
;
509 unsigned reserved_maps
;
516 for_each_child_of_node(np_config
, np
) {
517 ret
= mtk_pctrl_dt_subnode_to_map(pctldev
, np
, map
,
521 pinctrl_utils_free_map(pctldev
, *map
, *num_maps
);
530 static int mtk_pctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
532 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
534 return hw
->soc
->ngrps
;
537 static const char *mtk_pctrl_get_group_name(struct pinctrl_dev
*pctldev
,
540 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
542 return hw
->groups
[group
].name
;
545 static int mtk_pctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
546 unsigned group
, const unsigned **pins
,
549 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
551 *pins
= (unsigned *)&hw
->groups
[group
].pin
;
557 static const struct pinctrl_ops mtk_pctlops
= {
558 .dt_node_to_map
= mtk_pctrl_dt_node_to_map
,
559 .dt_free_map
= pinctrl_utils_free_map
,
560 .get_groups_count
= mtk_pctrl_get_groups_count
,
561 .get_group_name
= mtk_pctrl_get_group_name
,
562 .get_group_pins
= mtk_pctrl_get_group_pins
,
565 static int mtk_pmx_get_funcs_cnt(struct pinctrl_dev
*pctldev
)
567 return ARRAY_SIZE(mtk_gpio_functions
);
570 static const char *mtk_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
573 return mtk_gpio_functions
[selector
];
576 static int mtk_pmx_get_func_groups(struct pinctrl_dev
*pctldev
,
578 const char * const **groups
,
579 unsigned * const num_groups
)
581 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
583 *groups
= hw
->grp_names
;
584 *num_groups
= hw
->soc
->ngrps
;
589 static int mtk_pmx_set_mux(struct pinctrl_dev
*pctldev
,
593 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
594 struct mtk_pinctrl_group
*grp
= hw
->groups
+ group
;
595 const struct mtk_func_desc
*desc_func
;
596 const struct mtk_pin_desc
*desc
;
599 ret
= mtk_pctrl_is_function_valid(hw
, grp
->pin
, function
);
601 dev_err(hw
->dev
, "invalid function %d on group %d .\n",
606 desc_func
= mtk_pctrl_find_function_by_pin(hw
, grp
->pin
, function
);
610 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[grp
->pin
];
611 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_MODE
, desc_func
->muxval
);
616 static const struct pinmux_ops mtk_pmxops
= {
617 .get_functions_count
= mtk_pmx_get_funcs_cnt
,
618 .get_function_name
= mtk_pmx_get_func_name
,
619 .get_function_groups
= mtk_pmx_get_func_groups
,
620 .set_mux
= mtk_pmx_set_mux
,
621 .gpio_set_direction
= mtk_pinmux_gpio_set_direction
,
622 .gpio_request_enable
= mtk_pinmux_gpio_request_enable
,
625 static int mtk_pconf_group_get(struct pinctrl_dev
*pctldev
, unsigned group
,
626 unsigned long *config
)
628 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
630 *config
= hw
->groups
[group
].config
;
635 static int mtk_pconf_group_set(struct pinctrl_dev
*pctldev
, unsigned group
,
636 unsigned long *configs
, unsigned num_configs
)
638 struct mtk_pinctrl
*hw
= pinctrl_dev_get_drvdata(pctldev
);
639 struct mtk_pinctrl_group
*grp
= &hw
->groups
[group
];
642 for (i
= 0; i
< num_configs
; i
++) {
643 ret
= mtk_pinconf_set(pctldev
, grp
->pin
,
644 pinconf_to_config_param(configs
[i
]),
645 pinconf_to_config_argument(configs
[i
]));
649 grp
->config
= configs
[i
];
655 static const struct pinconf_ops mtk_confops
= {
656 .pin_config_get
= mtk_pinconf_get
,
657 .pin_config_group_get
= mtk_pconf_group_get
,
658 .pin_config_group_set
= mtk_pconf_group_set
,
661 static struct pinctrl_desc mtk_desc
= {
662 .name
= PINCTRL_PINCTRL_DEV
,
663 .pctlops
= &mtk_pctlops
,
664 .pmxops
= &mtk_pmxops
,
665 .confops
= &mtk_confops
,
666 .owner
= THIS_MODULE
,
669 static int mtk_gpio_get_direction(struct gpio_chip
*chip
, unsigned int gpio
)
671 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
672 const struct mtk_pin_desc
*desc
;
675 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
677 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DIR
, &value
);
684 static int mtk_gpio_get(struct gpio_chip
*chip
, unsigned int gpio
)
686 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
687 const struct mtk_pin_desc
*desc
;
690 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
692 err
= mtk_hw_get_value(hw
, desc
, PINCTRL_PIN_REG_DI
, &value
);
699 static void mtk_gpio_set(struct gpio_chip
*chip
, unsigned int gpio
, int value
)
701 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
702 const struct mtk_pin_desc
*desc
;
704 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[gpio
];
706 mtk_hw_set_value(hw
, desc
, PINCTRL_PIN_REG_DO
, !!value
);
709 static int mtk_gpio_direction_input(struct gpio_chip
*chip
, unsigned int gpio
)
711 return pinctrl_gpio_direction_input(chip
->base
+ gpio
);
714 static int mtk_gpio_direction_output(struct gpio_chip
*chip
, unsigned int gpio
,
717 mtk_gpio_set(chip
, gpio
, value
);
719 return pinctrl_gpio_direction_output(chip
->base
+ gpio
);
722 static int mtk_gpio_to_irq(struct gpio_chip
*chip
, unsigned int offset
)
724 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
725 const struct mtk_pin_desc
*desc
;
730 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[offset
];
732 if (desc
->eint
.eint_n
== EINT_NA
)
735 return mtk_eint_find_irq(hw
->eint
, desc
->eint
.eint_n
);
738 static int mtk_gpio_set_config(struct gpio_chip
*chip
, unsigned int offset
,
739 unsigned long config
)
741 struct mtk_pinctrl
*hw
= gpiochip_get_data(chip
);
742 const struct mtk_pin_desc
*desc
;
745 desc
= (const struct mtk_pin_desc
*)&hw
->soc
->pins
[offset
];
748 pinconf_to_config_param(config
) != PIN_CONFIG_INPUT_DEBOUNCE
||
749 desc
->eint
.eint_n
== EINT_NA
)
752 debounce
= pinconf_to_config_argument(config
);
754 return mtk_eint_set_debounce(hw
->eint
, desc
->eint
.eint_n
, debounce
);
757 static int mtk_build_gpiochip(struct mtk_pinctrl
*hw
, struct device_node
*np
)
759 struct gpio_chip
*chip
= &hw
->chip
;
762 chip
->label
= PINCTRL_PINCTRL_DEV
;
763 chip
->parent
= hw
->dev
;
764 chip
->request
= gpiochip_generic_request
;
765 chip
->free
= gpiochip_generic_free
;
766 chip
->get_direction
= mtk_gpio_get_direction
;
767 chip
->direction_input
= mtk_gpio_direction_input
;
768 chip
->direction_output
= mtk_gpio_direction_output
;
769 chip
->get
= mtk_gpio_get
;
770 chip
->set
= mtk_gpio_set
;
771 chip
->to_irq
= mtk_gpio_to_irq
,
772 chip
->set_config
= mtk_gpio_set_config
,
774 chip
->ngpio
= hw
->soc
->npins
;
776 chip
->of_gpio_n_cells
= 2;
778 ret
= gpiochip_add_data(chip
, hw
);
785 static int mtk_pctrl_build_state(struct platform_device
*pdev
)
787 struct mtk_pinctrl
*hw
= platform_get_drvdata(pdev
);
790 /* Allocate groups */
791 hw
->groups
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->ngrps
,
792 sizeof(*hw
->groups
), GFP_KERNEL
);
796 /* We assume that one pin is one group, use pin name as group name. */
797 hw
->grp_names
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->ngrps
,
798 sizeof(*hw
->grp_names
), GFP_KERNEL
);
802 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
803 const struct mtk_pin_desc
*pin
= hw
->soc
->pins
+ i
;
804 struct mtk_pinctrl_group
*group
= hw
->groups
+ i
;
806 group
->name
= pin
->name
;
807 group
->pin
= pin
->number
;
809 hw
->grp_names
[i
] = pin
->name
;
815 int mtk_paris_pinctrl_probe(struct platform_device
*pdev
,
816 const struct mtk_pin_soc
*soc
)
818 struct pinctrl_pin_desc
*pins
;
819 struct mtk_pinctrl
*hw
;
820 struct resource
*res
;
823 hw
= devm_kzalloc(&pdev
->dev
, sizeof(*hw
), GFP_KERNEL
);
827 platform_set_drvdata(pdev
, hw
);
829 hw
->dev
= &pdev
->dev
;
831 if (!hw
->soc
->nbase_names
) {
833 "SoC should be assigned at least one register base\n");
837 hw
->base
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->nbase_names
,
838 sizeof(*hw
->base
), GFP_KERNEL
);
842 for (i
= 0; i
< hw
->soc
->nbase_names
; i
++) {
843 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
844 hw
->soc
->base_names
[i
]);
846 dev_err(&pdev
->dev
, "missing IO resource\n");
850 hw
->base
[i
] = devm_ioremap_resource(&pdev
->dev
, res
);
851 if (IS_ERR(hw
->base
[i
]))
852 return PTR_ERR(hw
->base
[i
]);
855 hw
->nbase
= hw
->soc
->nbase_names
;
857 err
= mtk_pctrl_build_state(pdev
);
859 dev_err(&pdev
->dev
, "build state failed: %d\n", err
);
863 /* Copy from internal struct mtk_pin_desc to register to the core */
864 pins
= devm_kmalloc_array(&pdev
->dev
, hw
->soc
->npins
, sizeof(*pins
),
869 for (i
= 0; i
< hw
->soc
->npins
; i
++) {
870 pins
[i
].number
= hw
->soc
->pins
[i
].number
;
871 pins
[i
].name
= hw
->soc
->pins
[i
].name
;
874 /* Setup pins descriptions per SoC types */
875 mtk_desc
.pins
= (const struct pinctrl_pin_desc
*)pins
;
876 mtk_desc
.npins
= hw
->soc
->npins
;
877 mtk_desc
.num_custom_params
= ARRAY_SIZE(mtk_custom_bindings
);
878 mtk_desc
.custom_params
= mtk_custom_bindings
;
879 #ifdef CONFIG_DEBUG_FS
880 mtk_desc
.custom_conf_items
= mtk_conf_items
;
883 err
= devm_pinctrl_register_and_init(&pdev
->dev
, &mtk_desc
, hw
,
888 err
= pinctrl_enable(hw
->pctrl
);
892 err
= mtk_build_eint(hw
, pdev
);
895 "Failed to add EINT, but pinctrl still can work\n");
897 /* Build gpiochip should be after pinctrl_enable is done */
898 err
= mtk_build_gpiochip(hw
, pdev
->dev
.of_node
);
900 dev_err(&pdev
->dev
, "Failed to add gpio_chip\n");
904 platform_set_drvdata(pdev
, hw
);