Lines Matching +full:pctl +full:- +full:regmap

1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <linux/pinctrl/pinconf-generic.h>
23 #include <linux/regmap.h>
28 #include <dt-bindings/pinctrl/mt65xx.h>
32 #include "../pinctrl-utils.h"
33 #include "mtk-eint.h"
34 #include "pinctrl-mtk-common.h"
52 static struct regmap *mtk_get_regmap(struct mtk_pinctrl *pctl, in mtk_get_regmap() argument
55 if (pin >= pctl->devdata->type1_start && pin < pctl->devdata->type1_end) in mtk_get_regmap()
56 return pctl->regmap2; in mtk_get_regmap()
57 return pctl->regmap1; in mtk_get_regmap()
60 static unsigned int mtk_get_port(struct mtk_pinctrl *pctl, unsigned long pin) in mtk_get_port() argument
63 return ((pin >> pctl->devdata->mode_shf) & pctl->devdata->port_mask) in mtk_get_port()
64 << pctl->devdata->port_shf; in mtk_get_port()
73 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_gpio_set_direction() local
75 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; in mtk_pmx_gpio_set_direction()
76 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_pmx_gpio_set_direction()
78 if (pctl->devdata->spec_dir_set) in mtk_pmx_gpio_set_direction()
79 pctl->devdata->spec_dir_set(&reg_addr, offset); in mtk_pmx_gpio_set_direction()
83 reg_addr = CLR_ADDR(reg_addr, pctl); in mtk_pmx_gpio_set_direction()
85 reg_addr = SET_ADDR(reg_addr, pctl); in mtk_pmx_gpio_set_direction()
87 regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit); in mtk_pmx_gpio_set_direction()
95 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_set() local
97 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dout_offset; in mtk_gpio_set()
98 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_set()
101 reg_addr = SET_ADDR(reg_addr, pctl); in mtk_gpio_set()
103 reg_addr = CLR_ADDR(reg_addr, pctl); in mtk_gpio_set()
105 regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit); in mtk_gpio_set()
108 static int mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin, in mtk_pconf_set_ies_smt() argument
118 if (!pctl->devdata->spec_ies_smt_set && in mtk_pconf_set_ies_smt()
119 pctl->devdata->ies_offset == MTK_PINCTRL_NOT_SUPPORT && in mtk_pconf_set_ies_smt()
121 return -EINVAL; in mtk_pconf_set_ies_smt()
123 if (!pctl->devdata->spec_ies_smt_set && in mtk_pconf_set_ies_smt()
124 pctl->devdata->smt_offset == MTK_PINCTRL_NOT_SUPPORT && in mtk_pconf_set_ies_smt()
126 return -EINVAL; in mtk_pconf_set_ies_smt()
132 if (pctl->devdata->spec_ies_smt_set) { in mtk_pconf_set_ies_smt()
133 return pctl->devdata->spec_ies_smt_set(mtk_get_regmap(pctl, pin), in mtk_pconf_set_ies_smt()
134 pctl->devdata, pin, value, arg); in mtk_pconf_set_ies_smt()
138 offset = pctl->devdata->ies_offset; in mtk_pconf_set_ies_smt()
140 offset = pctl->devdata->smt_offset; in mtk_pconf_set_ies_smt()
142 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_pconf_set_ies_smt()
145 reg_addr = SET_ADDR(mtk_get_port(pctl, pin) + offset, pctl); in mtk_pconf_set_ies_smt()
147 reg_addr = CLR_ADDR(mtk_get_port(pctl, pin) + offset, pctl); in mtk_pconf_set_ies_smt()
149 regmap_write(mtk_get_regmap(pctl, pin), reg_addr, bit); in mtk_pconf_set_ies_smt()
153 int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap, in mtk_pconf_spec_set_ies_smt_range() argument
162 ies_smt_infos = devdata->spec_ies; in mtk_pconf_spec_set_ies_smt_range()
163 info_num = devdata->n_spec_ies; in mtk_pconf_spec_set_ies_smt_range()
166 ies_smt_infos = devdata->spec_smt; in mtk_pconf_spec_set_ies_smt_range()
167 info_num = devdata->n_spec_smt; in mtk_pconf_spec_set_ies_smt_range()
174 return -EINVAL; in mtk_pconf_spec_set_ies_smt_range()
184 return -EINVAL; in mtk_pconf_spec_set_ies_smt_range()
187 reg_addr = ies_smt_infos[i].offset + devdata->port_align; in mtk_pconf_spec_set_ies_smt_range()
189 reg_addr = ies_smt_infos[i].offset + (devdata->port_align << 1); in mtk_pconf_spec_set_ies_smt_range()
192 regmap_write(regmap, reg_addr, bit); in mtk_pconf_spec_set_ies_smt_range()
197 struct mtk_pinctrl *pctl, unsigned long pin) { in mtk_find_pin_drv_grp_by_pin() argument
200 for (i = 0; i < pctl->devdata->n_pin_drv_grps; i++) { in mtk_find_pin_drv_grp_by_pin()
202 pctl->devdata->pin_drv_grp + i; in mtk_find_pin_drv_grp_by_pin()
203 if (pin == pin_drv->pin) in mtk_find_pin_drv_grp_by_pin()
210 static int mtk_pconf_set_driving(struct mtk_pinctrl *pctl, in mtk_pconf_set_driving() argument
218 if (pin >= pctl->devdata->npins) in mtk_pconf_set_driving()
219 return -EINVAL; in mtk_pconf_set_driving()
221 pin_drv = mtk_find_pin_drv_grp_by_pin(pctl, pin); in mtk_pconf_set_driving()
222 if (!pin_drv || pin_drv->grp > pctl->devdata->n_grp_cls) in mtk_pconf_set_driving()
223 return -EINVAL; in mtk_pconf_set_driving()
225 drv_grp = pctl->devdata->grp_desc + pin_drv->grp; in mtk_pconf_set_driving()
226 if (driving >= drv_grp->min_drv && driving <= drv_grp->max_drv in mtk_pconf_set_driving()
227 && !(driving % drv_grp->step)) { in mtk_pconf_set_driving()
228 val = driving / drv_grp->step - 1; in mtk_pconf_set_driving()
229 bits = drv_grp->high_bit - drv_grp->low_bit + 1; in mtk_pconf_set_driving()
230 mask = BIT(bits) - 1; in mtk_pconf_set_driving()
231 shift = pin_drv->bit + drv_grp->low_bit; in mtk_pconf_set_driving()
234 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pconf_set_driving()
235 pin_drv->offset, mask, val); in mtk_pconf_set_driving()
238 return -EINVAL; in mtk_pconf_set_driving()
241 int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap, in mtk_pctrl_spec_pull_set_samereg() argument
251 if (!devdata->spec_pupd) in mtk_pctrl_spec_pull_set_samereg()
252 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
254 for (i = 0; i < devdata->n_spec_pupd; i++) { in mtk_pctrl_spec_pull_set_samereg()
255 if (pin == devdata->spec_pupd[i].pin) { in mtk_pctrl_spec_pull_set_samereg()
262 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
264 spec_pupd_pin = devdata->spec_pupd + i; in mtk_pctrl_spec_pull_set_samereg()
265 reg_set = spec_pupd_pin->offset + devdata->port_align; in mtk_pctrl_spec_pull_set_samereg()
266 reg_rst = spec_pupd_pin->offset + (devdata->port_align << 1); in mtk_pctrl_spec_pull_set_samereg()
273 bit_pupd = BIT(spec_pupd_pin->pupd_bit); in mtk_pctrl_spec_pull_set_samereg()
274 regmap_write(regmap, reg_pupd, bit_pupd); in mtk_pctrl_spec_pull_set_samereg()
276 bit_r0 = BIT(spec_pupd_pin->r0_bit); in mtk_pctrl_spec_pull_set_samereg()
277 bit_r1 = BIT(spec_pupd_pin->r1_bit); in mtk_pctrl_spec_pull_set_samereg()
281 regmap_write(regmap, reg_rst, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
282 regmap_write(regmap, reg_rst, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
285 regmap_write(regmap, reg_set, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
286 regmap_write(regmap, reg_rst, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
289 regmap_write(regmap, reg_rst, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
290 regmap_write(regmap, reg_set, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
293 regmap_write(regmap, reg_set, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
294 regmap_write(regmap, reg_set, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
297 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
303 static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl, in mtk_pconf_set_pull_select() argument
314 if (pctl->devdata->spec_pull_set) { in mtk_pconf_set_pull_select()
315 /* For special pins, bias-disable is set by R1R0, in mtk_pconf_set_pull_select()
319 ret = pctl->devdata->spec_pull_set(mtk_get_regmap(pctl, pin), in mtk_pconf_set_pull_select()
320 pctl->devdata, pin, isup, in mtk_pconf_set_pull_select()
328 dev_err(pctl->dev, "invalid pull-up argument %d on pin %d .\n", in mtk_pconf_set_pull_select()
330 return -EINVAL; in mtk_pconf_set_pull_select()
333 bit = BIT(pin & pctl->devdata->mode_mask); in mtk_pconf_set_pull_select()
335 reg_pullen = SET_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
336 pctl->devdata->pullen_offset, pctl); in mtk_pconf_set_pull_select()
338 reg_pullen = CLR_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
339 pctl->devdata->pullen_offset, pctl); in mtk_pconf_set_pull_select()
342 reg_pullsel = SET_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
343 pctl->devdata->pullsel_offset, pctl); in mtk_pconf_set_pull_select()
345 reg_pullsel = CLR_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
346 pctl->devdata->pullsel_offset, pctl); in mtk_pconf_set_pull_select()
348 regmap_write(mtk_get_regmap(pctl, pin), reg_pullen, bit); in mtk_pconf_set_pull_select()
349 regmap_write(mtk_get_regmap(pctl, pin), reg_pullsel, bit); in mtk_pconf_set_pull_select()
358 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_parse_conf() local
362 ret = mtk_pconf_set_pull_select(pctl, pin, false, false, arg); in mtk_pconf_parse_conf()
365 ret = mtk_pconf_set_pull_select(pctl, pin, true, true, arg); in mtk_pconf_parse_conf()
368 ret = mtk_pconf_set_pull_select(pctl, pin, true, false, arg); in mtk_pconf_parse_conf()
372 ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); in mtk_pconf_parse_conf()
375 mtk_gpio_set(pctl->chip, pin, arg); in mtk_pconf_parse_conf()
380 ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); in mtk_pconf_parse_conf()
383 ret = mtk_pconf_set_driving(pctl, pin, arg); in mtk_pconf_parse_conf()
386 ret = -EINVAL; in mtk_pconf_parse_conf()
396 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_group_get() local
398 *config = pctl->groups[group].config; in mtk_pconf_group_get()
406 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_group_set() local
407 struct mtk_pinctrl_group *g = &pctl->groups[group]; in mtk_pconf_group_set()
411 ret = mtk_pconf_parse_conf(pctldev, g->pin, in mtk_pconf_group_set()
417 g->config = configs[i]; in mtk_pconf_group_set()
429 mtk_pctrl_find_group_by_pin(struct mtk_pinctrl *pctl, u32 pin) in mtk_pctrl_find_group_by_pin() argument
433 for (i = 0; i < pctl->ngroups; i++) { in mtk_pctrl_find_group_by_pin()
434 struct mtk_pinctrl_group *grp = pctl->groups + i; in mtk_pctrl_find_group_by_pin()
436 if (grp->pin == pin) in mtk_pctrl_find_group_by_pin()
444 struct mtk_pinctrl *pctl, u32 pin_num, u32 fnum) in mtk_pctrl_find_function_by_pin() argument
446 const struct mtk_desc_pin *pin = pctl->devdata->pins + pin_num; in mtk_pctrl_find_function_by_pin()
447 const struct mtk_desc_function *func = pin->functions; in mtk_pctrl_find_function_by_pin()
449 while (func && func->name) { in mtk_pctrl_find_function_by_pin()
450 if (func->muxval == fnum) in mtk_pctrl_find_function_by_pin()
458 static bool mtk_pctrl_is_function_valid(struct mtk_pinctrl *pctl, in mtk_pctrl_is_function_valid() argument
463 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_pctrl_is_function_valid()
464 const struct mtk_desc_pin *pin = pctl->devdata->pins + i; in mtk_pctrl_is_function_valid()
466 if (pin->pin.number == pin_num) { in mtk_pctrl_is_function_valid()
468 pin->functions; in mtk_pctrl_is_function_valid()
470 while (func && func->name) { in mtk_pctrl_is_function_valid()
471 if (func->muxval == fnum) in mtk_pctrl_is_function_valid()
483 static int mtk_pctrl_dt_node_to_map_func(struct mtk_pinctrl *pctl, in mtk_pctrl_dt_node_to_map_func() argument
491 return -ENOSPC; in mtk_pctrl_dt_node_to_map_func()
494 (*map)[*num_maps].data.mux.group = grp->name; in mtk_pctrl_dt_node_to_map_func()
496 ret = mtk_pctrl_is_function_valid(pctl, pin, fnum); in mtk_pctrl_dt_node_to_map_func()
498 dev_err(pctl->dev, "invalid function %d on pin %d .\n", in mtk_pctrl_dt_node_to_map_func()
500 return -EINVAL; in mtk_pctrl_dt_node_to_map_func()
524 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_dt_subnode_to_map() local
528 dev_err(pctl->dev, "missing pins property in node %pOFn .\n", in mtk_pctrl_dt_subnode_to_map()
530 return -EINVAL; in mtk_pctrl_dt_subnode_to_map()
541 num_pins = pins->length / sizeof(u32); in mtk_pctrl_dt_subnode_to_map()
550 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
570 if (pin >= pctl->devdata->npins || in mtk_pctrl_dt_subnode_to_map()
572 dev_err(pctl->dev, "invalid pins value.\n"); in mtk_pctrl_dt_subnode_to_map()
573 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
577 grp = mtk_pctrl_find_group_by_pin(pctl, pin); in mtk_pctrl_dt_subnode_to_map()
579 dev_err(pctl->dev, "unable to match pin %d to group\n", in mtk_pctrl_dt_subnode_to_map()
581 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
585 err = mtk_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map, in mtk_pctrl_dt_subnode_to_map()
592 reserved_maps, num_maps, grp->name, in mtk_pctrl_dt_subnode_to_map()
634 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_groups_count() local
636 return pctl->ngroups; in mtk_pctrl_get_groups_count()
642 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_name() local
644 return pctl->groups[group].name; in mtk_pctrl_get_group_name()
652 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_pins() local
654 *pins = (unsigned *)&pctl->groups[group].pin; in mtk_pctrl_get_group_pins()
684 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_get_func_groups() local
686 *groups = pctl->grp_names; in mtk_pmx_get_func_groups()
687 *num_groups = pctl->ngroups; in mtk_pmx_get_func_groups()
698 unsigned int mask = (1L << GPIO_MODE_BITS) - 1; in mtk_pmx_set_mode()
699 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mode() local
701 if (pctl->devdata->spec_pinmux_set) in mtk_pmx_set_mode()
702 pctl->devdata->spec_pinmux_set(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
705 reg_addr = ((pin / pctl->devdata->mode_per_reg) << pctl->devdata->port_shf) in mtk_pmx_set_mode()
706 + pctl->devdata->pinmux_offset; in mtk_pmx_set_mode()
709 bit = pin % pctl->devdata->mode_per_reg; in mtk_pmx_set_mode()
712 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
717 mtk_find_pin_by_eint_num(struct mtk_pinctrl *pctl, unsigned int eint_num) in mtk_find_pin_by_eint_num() argument
722 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_find_pin_by_eint_num()
723 pin = pctl->devdata->pins + i; in mtk_find_pin_by_eint_num()
724 if (pin->eint.eintnum == eint_num) in mtk_find_pin_by_eint_num()
737 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mux() local
738 struct mtk_pinctrl_group *g = pctl->groups + group; in mtk_pmx_set_mux()
740 ret = mtk_pctrl_is_function_valid(pctl, g->pin, function); in mtk_pmx_set_mux()
742 dev_err(pctl->dev, "invalid function %d on group %d .\n", in mtk_pmx_set_mux()
744 return -EINVAL; in mtk_pmx_set_mux()
747 desc = mtk_pctrl_find_function_by_pin(pctl, g->pin, function); in mtk_pmx_set_mux()
749 return -EINVAL; in mtk_pmx_set_mux()
750 mtk_pmx_set_mode(pctldev, g->pin, desc->muxval); in mtk_pmx_set_mux()
754 static int mtk_pmx_find_gpio_mode(struct mtk_pinctrl *pctl, in mtk_pmx_find_gpio_mode() argument
757 const struct mtk_desc_pin *pin = pctl->devdata->pins + offset; in mtk_pmx_find_gpio_mode()
758 const struct mtk_desc_function *func = pin->functions; in mtk_pmx_find_gpio_mode()
760 while (func && func->name) { in mtk_pmx_find_gpio_mode()
761 if (!strncmp(func->name, GPIO_MODE_PREFIX, in mtk_pmx_find_gpio_mode()
762 sizeof(GPIO_MODE_PREFIX)-1)) in mtk_pmx_find_gpio_mode()
763 return func->muxval; in mtk_pmx_find_gpio_mode()
766 return -EINVAL; in mtk_pmx_find_gpio_mode()
774 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_gpio_request_enable() local
776 muxval = mtk_pmx_find_gpio_mode(pctl, offset); in mtk_pmx_gpio_request_enable()
779 dev_err(pctl->dev, "invalid gpio pin %d.\n", offset); in mtk_pmx_gpio_request_enable()
780 return -EINVAL; in mtk_pmx_gpio_request_enable()
784 mtk_pconf_set_ies_smt(pctl, offset, 1, PIN_CONFIG_INPUT_ENABLE); in mtk_pmx_gpio_request_enable()
801 return pinctrl_gpio_direction_input(chip->base + offset); in mtk_gpio_direction_input()
808 return pinctrl_gpio_direction_output(chip->base + offset); in mtk_gpio_direction_output()
817 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get_direction() local
819 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; in mtk_gpio_get_direction()
820 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get_direction()
822 if (pctl->devdata->spec_dir_set) in mtk_gpio_get_direction()
823 pctl->devdata->spec_dir_set(&reg_addr, offset); in mtk_gpio_get_direction()
825 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get_direction()
837 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get() local
839 reg_addr = mtk_get_port(pctl, offset) + in mtk_gpio_get()
840 pctl->devdata->din_offset; in mtk_gpio_get()
842 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get()
843 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get()
849 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_to_irq() local
853 pin = pctl->devdata->pins + offset; in mtk_gpio_to_irq()
854 if (pin->eint.eintnum == NO_EINT_SUPPORT) in mtk_gpio_to_irq()
855 return -EINVAL; in mtk_gpio_to_irq()
857 eint_n = pin->eint.eintnum; in mtk_gpio_to_irq()
859 return mtk_eint_find_irq(pctl->eint, eint_n); in mtk_gpio_to_irq()
865 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_set_config() local
871 return -ENOTSUPP; in mtk_gpio_set_config()
873 pin = pctl->devdata->pins + offset; in mtk_gpio_set_config()
874 if (pin->eint.eintnum == NO_EINT_SUPPORT) in mtk_gpio_set_config()
875 return -EINVAL; in mtk_gpio_set_config()
878 eint_n = pin->eint.eintnum; in mtk_gpio_set_config()
880 return mtk_eint_set_debounce(pctl->eint, eint_n, debounce); in mtk_gpio_set_config()
899 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_suspend() local
901 return mtk_eint_do_suspend(pctl->eint); in mtk_eint_suspend()
906 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_resume() local
908 return mtk_eint_do_resume(pctl->eint); in mtk_eint_resume()
918 struct mtk_pinctrl *pctl = platform_get_drvdata(pdev); in mtk_pctrl_build_state() local
921 pctl->ngroups = pctl->devdata->npins; in mtk_pctrl_build_state()
924 pctl->groups = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
925 sizeof(*pctl->groups), GFP_KERNEL); in mtk_pctrl_build_state()
926 if (!pctl->groups) in mtk_pctrl_build_state()
927 return -ENOMEM; in mtk_pctrl_build_state()
930 pctl->grp_names = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
931 sizeof(*pctl->grp_names), GFP_KERNEL); in mtk_pctrl_build_state()
932 if (!pctl->grp_names) in mtk_pctrl_build_state()
933 return -ENOMEM; in mtk_pctrl_build_state()
935 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_pctrl_build_state()
936 const struct mtk_desc_pin *pin = pctl->devdata->pins + i; in mtk_pctrl_build_state()
937 struct mtk_pinctrl_group *group = pctl->groups + i; in mtk_pctrl_build_state()
939 group->name = pin->pin.name; in mtk_pctrl_build_state()
940 group->pin = pin->pin.number; in mtk_pctrl_build_state()
942 pctl->grp_names[i] = pin->pin.name; in mtk_pctrl_build_state()
952 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_n() local
955 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_n()
957 return -EINVAL; in mtk_xt_get_gpio_n()
959 *gpio_chip = pctl->chip; in mtk_xt_get_gpio_n()
960 *gpio_n = pin->pin.number; in mtk_xt_get_gpio_n()
967 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_state() local
970 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_state()
972 return -EINVAL; in mtk_xt_get_gpio_state()
974 return mtk_gpio_get(pctl->chip, pin->pin.number); in mtk_xt_get_gpio_state()
979 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_set_gpio_as_eint() local
982 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_set_gpio_as_eint()
984 return -EINVAL; in mtk_xt_set_gpio_as_eint()
987 mtk_pmx_set_mode(pctl->pctl_dev, pin->pin.number, pin->eint.eintmux); in mtk_xt_set_gpio_as_eint()
989 mtk_pmx_gpio_set_direction(pctl->pctl_dev, NULL, pin->pin.number, in mtk_xt_set_gpio_as_eint()
991 /* set input-enable */ in mtk_xt_set_gpio_as_eint()
992 mtk_pconf_set_ies_smt(pctl, pin->pin.number, 1, in mtk_xt_set_gpio_as_eint()
1004 static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev) in mtk_eint_init() argument
1006 struct device_node *np = pdev->dev.of_node; in mtk_eint_init()
1008 if (!of_property_read_bool(np, "interrupt-controller")) in mtk_eint_init()
1009 return -ENODEV; in mtk_eint_init()
1011 pctl->eint = devm_kzalloc(pctl->dev, sizeof(*pctl->eint), GFP_KERNEL); in mtk_eint_init()
1012 if (!pctl->eint) in mtk_eint_init()
1013 return -ENOMEM; in mtk_eint_init()
1015 pctl->eint->base = devm_platform_ioremap_resource(pdev, 0); in mtk_eint_init()
1016 if (IS_ERR(pctl->eint->base)) in mtk_eint_init()
1017 return PTR_ERR(pctl->eint->base); in mtk_eint_init()
1019 pctl->eint->irq = irq_of_parse_and_map(np, 0); in mtk_eint_init()
1020 if (!pctl->eint->irq) in mtk_eint_init()
1021 return -EINVAL; in mtk_eint_init()
1023 pctl->eint->dev = &pdev->dev; in mtk_eint_init()
1025 * If pctl->eint->regs == NULL, it would fall back into using a generic in mtk_eint_init()
1028 pctl->eint->regs = pctl->devdata->eint_regs; in mtk_eint_init()
1029 pctl->eint->hw = &pctl->devdata->eint_hw; in mtk_eint_init()
1030 pctl->eint->pctl = pctl; in mtk_eint_init()
1031 pctl->eint->gpio_xlate = &mtk_eint_xt; in mtk_eint_init()
1033 return mtk_eint_do_init(pctl->eint); in mtk_eint_init()
1039 struct regmap *regmap) in mtk_pctrl_init() argument
1041 struct device *dev = &pdev->dev; in mtk_pctrl_init()
1043 struct mtk_pinctrl *pctl; in mtk_pctrl_init() local
1044 struct device_node *np = pdev->dev.of_node, *node; in mtk_pctrl_init()
1048 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in mtk_pctrl_init()
1049 if (!pctl) in mtk_pctrl_init()
1050 return -ENOMEM; in mtk_pctrl_init()
1052 platform_set_drvdata(pdev, pctl); in mtk_pctrl_init()
1054 prop = of_find_property(np, "pins-are-numbered", NULL); in mtk_pctrl_init()
1056 return dev_err_probe(dev, -EINVAL, in mtk_pctrl_init()
1057 "only support pins-are-numbered format\n"); in mtk_pctrl_init()
1059 node = of_parse_phandle(np, "mediatek,pctl-regmap", 0); in mtk_pctrl_init()
1061 pctl->regmap1 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1063 if (IS_ERR(pctl->regmap1)) in mtk_pctrl_init()
1064 return PTR_ERR(pctl->regmap1); in mtk_pctrl_init()
1065 } else if (regmap) { in mtk_pctrl_init()
1066 pctl->regmap1 = regmap; in mtk_pctrl_init()
1068 return dev_err_probe(dev, -EINVAL, "Cannot find pinctrl regmap.\n"); in mtk_pctrl_init()
1072 node = of_parse_phandle(np, "mediatek,pctl-regmap", 1); in mtk_pctrl_init()
1074 pctl->regmap2 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1076 if (IS_ERR(pctl->regmap2)) in mtk_pctrl_init()
1077 return PTR_ERR(pctl->regmap2); in mtk_pctrl_init()
1080 pctl->devdata = data; in mtk_pctrl_init()
1085 pins = devm_kcalloc(&pdev->dev, pctl->devdata->npins, sizeof(*pins), in mtk_pctrl_init()
1088 return -ENOMEM; in mtk_pctrl_init()
1090 for (i = 0; i < pctl->devdata->npins; i++) in mtk_pctrl_init()
1091 pins[i] = pctl->devdata->pins[i].pin; in mtk_pctrl_init()
1093 pctl->pctl_desc.name = dev_name(&pdev->dev); in mtk_pctrl_init()
1094 pctl->pctl_desc.owner = THIS_MODULE; in mtk_pctrl_init()
1095 pctl->pctl_desc.pins = pins; in mtk_pctrl_init()
1096 pctl->pctl_desc.npins = pctl->devdata->npins; in mtk_pctrl_init()
1097 pctl->pctl_desc.confops = &mtk_pconf_ops; in mtk_pctrl_init()
1098 pctl->pctl_desc.pctlops = &mtk_pctrl_ops; in mtk_pctrl_init()
1099 pctl->pctl_desc.pmxops = &mtk_pmx_ops; in mtk_pctrl_init()
1100 pctl->dev = &pdev->dev; in mtk_pctrl_init()
1102 pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, &pctl->pctl_desc, in mtk_pctrl_init()
1103 pctl); in mtk_pctrl_init()
1104 if (IS_ERR(pctl->pctl_dev)) in mtk_pctrl_init()
1105 return dev_err_probe(dev, PTR_ERR(pctl->pctl_dev), in mtk_pctrl_init()
1108 pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); in mtk_pctrl_init()
1109 if (!pctl->chip) in mtk_pctrl_init()
1110 return -ENOMEM; in mtk_pctrl_init()
1112 *pctl->chip = mtk_gpio_chip; in mtk_pctrl_init()
1113 pctl->chip->ngpio = pctl->devdata->npins; in mtk_pctrl_init()
1114 pctl->chip->label = dev_name(&pdev->dev); in mtk_pctrl_init()
1115 pctl->chip->parent = &pdev->dev; in mtk_pctrl_init()
1116 pctl->chip->base = -1; in mtk_pctrl_init()
1118 ret = gpiochip_add_data(pctl->chip, pctl); in mtk_pctrl_init()
1120 return -EINVAL; in mtk_pctrl_init()
1123 ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), in mtk_pctrl_init()
1124 0, 0, pctl->devdata->npins); in mtk_pctrl_init()
1126 ret = -EINVAL; in mtk_pctrl_init()
1130 ret = mtk_eint_init(pctl, pdev); in mtk_pctrl_init()
1137 gpiochip_remove(pctl->chip); in mtk_pctrl_init()
1143 struct device *dev = &pdev->dev; in mtk_pctrl_common_probe()
1147 return -ENODEV; in mtk_pctrl_common_probe()