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

1 // SPDX-License-Identifier: GPL-2.0-only
15 #include <linux/pinctrl/pinconf-generic.h>
21 #include <linux/regmap.h>
26 #include <dt-bindings/pinctrl/mt65xx.h>
30 #include "../pinctrl-utils.h"
31 #include "mtk-eint.h"
32 #include "pinctrl-mtk-common.h"
50 static struct regmap *mtk_get_regmap(struct mtk_pinctrl *pctl, in mtk_get_regmap() argument
53 if (pin >= pctl->devdata->type1_start && pin < pctl->devdata->type1_end) in mtk_get_regmap()
54 return pctl->regmap2; in mtk_get_regmap()
55 return pctl->regmap1; in mtk_get_regmap()
58 static unsigned int mtk_get_port(struct mtk_pinctrl *pctl, unsigned long pin) in mtk_get_port() argument
61 return ((pin >> pctl->devdata->mode_shf) & pctl->devdata->port_mask) in mtk_get_port()
62 << pctl->devdata->port_shf; in mtk_get_port()
71 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_gpio_set_direction() local
73 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; in mtk_pmx_gpio_set_direction()
74 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_pmx_gpio_set_direction()
76 if (pctl->devdata->spec_dir_set) in mtk_pmx_gpio_set_direction()
77 pctl->devdata->spec_dir_set(&reg_addr, offset); in mtk_pmx_gpio_set_direction()
81 reg_addr = CLR_ADDR(reg_addr, pctl); in mtk_pmx_gpio_set_direction()
83 reg_addr = SET_ADDR(reg_addr, pctl); in mtk_pmx_gpio_set_direction()
85 regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit); in mtk_pmx_gpio_set_direction()
93 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_set() local
95 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dout_offset; in mtk_gpio_set()
96 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_set()
99 reg_addr = SET_ADDR(reg_addr, pctl); in mtk_gpio_set()
101 reg_addr = CLR_ADDR(reg_addr, pctl); in mtk_gpio_set()
103 regmap_write(mtk_get_regmap(pctl, offset), reg_addr, bit); in mtk_gpio_set()
106 static int mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin, in mtk_pconf_set_ies_smt() argument
116 if (!pctl->devdata->spec_ies_smt_set && in mtk_pconf_set_ies_smt()
117 pctl->devdata->ies_offset == MTK_PINCTRL_NOT_SUPPORT && in mtk_pconf_set_ies_smt()
119 return -EINVAL; in mtk_pconf_set_ies_smt()
121 if (!pctl->devdata->spec_ies_smt_set && in mtk_pconf_set_ies_smt()
122 pctl->devdata->smt_offset == MTK_PINCTRL_NOT_SUPPORT && in mtk_pconf_set_ies_smt()
124 return -EINVAL; in mtk_pconf_set_ies_smt()
130 if (pctl->devdata->spec_ies_smt_set) { in mtk_pconf_set_ies_smt()
131 return pctl->devdata->spec_ies_smt_set(mtk_get_regmap(pctl, pin), in mtk_pconf_set_ies_smt()
132 pctl->devdata, pin, value, arg); in mtk_pconf_set_ies_smt()
136 offset = pctl->devdata->ies_offset; in mtk_pconf_set_ies_smt()
138 offset = pctl->devdata->smt_offset; in mtk_pconf_set_ies_smt()
140 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_pconf_set_ies_smt()
143 reg_addr = SET_ADDR(mtk_get_port(pctl, pin) + offset, pctl); in mtk_pconf_set_ies_smt()
145 reg_addr = CLR_ADDR(mtk_get_port(pctl, pin) + offset, pctl); in mtk_pconf_set_ies_smt()
147 regmap_write(mtk_get_regmap(pctl, pin), reg_addr, bit); in mtk_pconf_set_ies_smt()
151 int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap, in mtk_pconf_spec_set_ies_smt_range() argument
160 ies_smt_infos = devdata->spec_ies; in mtk_pconf_spec_set_ies_smt_range()
161 info_num = devdata->n_spec_ies; in mtk_pconf_spec_set_ies_smt_range()
164 ies_smt_infos = devdata->spec_smt; in mtk_pconf_spec_set_ies_smt_range()
165 info_num = devdata->n_spec_smt; in mtk_pconf_spec_set_ies_smt_range()
172 return -EINVAL; in mtk_pconf_spec_set_ies_smt_range()
182 return -EINVAL; in mtk_pconf_spec_set_ies_smt_range()
185 reg_addr = ies_smt_infos[i].offset + devdata->port_align; in mtk_pconf_spec_set_ies_smt_range()
187 reg_addr = ies_smt_infos[i].offset + (devdata->port_align << 1); in mtk_pconf_spec_set_ies_smt_range()
190 regmap_write(regmap, reg_addr, bit); in mtk_pconf_spec_set_ies_smt_range()
195 struct mtk_pinctrl *pctl, unsigned long pin) { in mtk_find_pin_drv_grp_by_pin() argument
198 for (i = 0; i < pctl->devdata->n_pin_drv_grps; i++) { in mtk_find_pin_drv_grp_by_pin()
200 pctl->devdata->pin_drv_grp + i; in mtk_find_pin_drv_grp_by_pin()
201 if (pin == pin_drv->pin) in mtk_find_pin_drv_grp_by_pin()
208 static int mtk_pconf_set_driving(struct mtk_pinctrl *pctl, in mtk_pconf_set_driving() argument
216 if (pin >= pctl->devdata->npins) in mtk_pconf_set_driving()
217 return -EINVAL; in mtk_pconf_set_driving()
219 pin_drv = mtk_find_pin_drv_grp_by_pin(pctl, pin); in mtk_pconf_set_driving()
220 if (!pin_drv || pin_drv->grp > pctl->devdata->n_grp_cls) in mtk_pconf_set_driving()
221 return -EINVAL; in mtk_pconf_set_driving()
223 drv_grp = pctl->devdata->grp_desc + pin_drv->grp; in mtk_pconf_set_driving()
224 if (driving >= drv_grp->min_drv && driving <= drv_grp->max_drv in mtk_pconf_set_driving()
225 && !(driving % drv_grp->step)) { in mtk_pconf_set_driving()
226 val = driving / drv_grp->step - 1; in mtk_pconf_set_driving()
227 bits = drv_grp->high_bit - drv_grp->low_bit + 1; in mtk_pconf_set_driving()
228 mask = BIT(bits) - 1; in mtk_pconf_set_driving()
229 shift = pin_drv->bit + drv_grp->low_bit; in mtk_pconf_set_driving()
232 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pconf_set_driving()
233 pin_drv->offset, mask, val); in mtk_pconf_set_driving()
236 return -EINVAL; in mtk_pconf_set_driving()
239 int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap, in mtk_pctrl_spec_pull_set_samereg() argument
249 if (!devdata->spec_pupd) in mtk_pctrl_spec_pull_set_samereg()
250 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
252 for (i = 0; i < devdata->n_spec_pupd; i++) { in mtk_pctrl_spec_pull_set_samereg()
253 if (pin == devdata->spec_pupd[i].pin) { in mtk_pctrl_spec_pull_set_samereg()
260 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
262 spec_pupd_pin = devdata->spec_pupd + i; in mtk_pctrl_spec_pull_set_samereg()
263 reg_set = spec_pupd_pin->offset + devdata->port_align; in mtk_pctrl_spec_pull_set_samereg()
264 reg_rst = spec_pupd_pin->offset + (devdata->port_align << 1); in mtk_pctrl_spec_pull_set_samereg()
271 bit_pupd = BIT(spec_pupd_pin->pupd_bit); in mtk_pctrl_spec_pull_set_samereg()
272 regmap_write(regmap, reg_pupd, bit_pupd); in mtk_pctrl_spec_pull_set_samereg()
274 bit_r0 = BIT(spec_pupd_pin->r0_bit); in mtk_pctrl_spec_pull_set_samereg()
275 bit_r1 = BIT(spec_pupd_pin->r1_bit); in mtk_pctrl_spec_pull_set_samereg()
279 regmap_write(regmap, reg_rst, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
280 regmap_write(regmap, reg_rst, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
283 regmap_write(regmap, reg_set, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
284 regmap_write(regmap, reg_rst, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
287 regmap_write(regmap, reg_rst, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
288 regmap_write(regmap, reg_set, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
291 regmap_write(regmap, reg_set, bit_r0); in mtk_pctrl_spec_pull_set_samereg()
292 regmap_write(regmap, reg_set, bit_r1); in mtk_pctrl_spec_pull_set_samereg()
295 return -EINVAL; in mtk_pctrl_spec_pull_set_samereg()
301 static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl, in mtk_pconf_set_pull_select() argument
312 if (pctl->devdata->spec_pull_set) { in mtk_pconf_set_pull_select()
313 /* For special pins, bias-disable is set by R1R0, in mtk_pconf_set_pull_select()
317 ret = pctl->devdata->spec_pull_set(mtk_get_regmap(pctl, pin), in mtk_pconf_set_pull_select()
318 pctl->devdata, pin, isup, in mtk_pconf_set_pull_select()
326 dev_err(pctl->dev, "invalid pull-up argument %d on pin %d .\n", in mtk_pconf_set_pull_select()
328 return -EINVAL; in mtk_pconf_set_pull_select()
331 if (pctl->devdata->mt8365_set_clr_mode) { in mtk_pconf_set_pull_select()
332 bit = pin & pctl->devdata->mode_mask; in mtk_pconf_set_pull_select()
333 reg_pullen = mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
334 pctl->devdata->pullen_offset; in mtk_pconf_set_pull_select()
335 reg_pullsel = mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
336 pctl->devdata->pullsel_offset; in mtk_pconf_set_pull_select()
337 ret = pctl->devdata->mt8365_set_clr_mode(mtk_get_regmap(pctl, pin), in mtk_pconf_set_pull_select()
341 return -EINVAL; in mtk_pconf_set_pull_select()
346 bit = BIT(pin & pctl->devdata->mode_mask); in mtk_pconf_set_pull_select()
348 reg_pullen = SET_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
349 pctl->devdata->pullen_offset, pctl); in mtk_pconf_set_pull_select()
351 reg_pullen = CLR_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
352 pctl->devdata->pullen_offset, pctl); in mtk_pconf_set_pull_select()
355 reg_pullsel = SET_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
356 pctl->devdata->pullsel_offset, pctl); in mtk_pconf_set_pull_select()
358 reg_pullsel = CLR_ADDR(mtk_get_port(pctl, pin) + in mtk_pconf_set_pull_select()
359 pctl->devdata->pullsel_offset, pctl); in mtk_pconf_set_pull_select()
361 regmap_write(mtk_get_regmap(pctl, pin), reg_pullen, bit); in mtk_pconf_set_pull_select()
362 regmap_write(mtk_get_regmap(pctl, pin), reg_pullsel, bit); in mtk_pconf_set_pull_select()
371 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_parse_conf() local
375 ret = mtk_pconf_set_pull_select(pctl, pin, false, false, arg); in mtk_pconf_parse_conf()
378 ret = mtk_pconf_set_pull_select(pctl, pin, true, true, arg); in mtk_pconf_parse_conf()
381 ret = mtk_pconf_set_pull_select(pctl, pin, true, false, arg); in mtk_pconf_parse_conf()
385 ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); in mtk_pconf_parse_conf()
388 mtk_gpio_set(pctl->chip, pin, arg); in mtk_pconf_parse_conf()
393 ret = mtk_pconf_set_ies_smt(pctl, pin, arg, param); in mtk_pconf_parse_conf()
396 ret = mtk_pconf_set_driving(pctl, pin, arg); in mtk_pconf_parse_conf()
399 ret = -EINVAL; in mtk_pconf_parse_conf()
409 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_group_get() local
411 *config = pctl->groups[group].config; in mtk_pconf_group_get()
419 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pconf_group_set() local
420 struct mtk_pinctrl_group *g = &pctl->groups[group]; in mtk_pconf_group_set()
424 ret = mtk_pconf_parse_conf(pctldev, g->pin, in mtk_pconf_group_set()
430 g->config = configs[i]; in mtk_pconf_group_set()
442 mtk_pctrl_find_group_by_pin(struct mtk_pinctrl *pctl, u32 pin) in mtk_pctrl_find_group_by_pin() argument
446 for (i = 0; i < pctl->ngroups; i++) { in mtk_pctrl_find_group_by_pin()
447 struct mtk_pinctrl_group *grp = pctl->groups + i; in mtk_pctrl_find_group_by_pin()
449 if (grp->pin == pin) in mtk_pctrl_find_group_by_pin()
457 struct mtk_pinctrl *pctl, u32 pin_num, u32 fnum) in mtk_pctrl_find_function_by_pin() argument
459 const struct mtk_desc_pin *pin = pctl->devdata->pins + pin_num; in mtk_pctrl_find_function_by_pin()
460 const struct mtk_desc_function *func = pin->functions; in mtk_pctrl_find_function_by_pin()
462 while (func && func->name) { in mtk_pctrl_find_function_by_pin()
463 if (func->muxval == fnum) in mtk_pctrl_find_function_by_pin()
471 static bool mtk_pctrl_is_function_valid(struct mtk_pinctrl *pctl, in mtk_pctrl_is_function_valid() argument
476 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_pctrl_is_function_valid()
477 const struct mtk_desc_pin *pin = pctl->devdata->pins + i; in mtk_pctrl_is_function_valid()
479 if (pin->pin.number == pin_num) { in mtk_pctrl_is_function_valid()
481 pin->functions; in mtk_pctrl_is_function_valid()
483 while (func && func->name) { in mtk_pctrl_is_function_valid()
484 if (func->muxval == fnum) in mtk_pctrl_is_function_valid()
496 static int mtk_pctrl_dt_node_to_map_func(struct mtk_pinctrl *pctl, in mtk_pctrl_dt_node_to_map_func() argument
504 return -ENOSPC; in mtk_pctrl_dt_node_to_map_func()
507 (*map)[*num_maps].data.mux.group = grp->name; in mtk_pctrl_dt_node_to_map_func()
509 ret = mtk_pctrl_is_function_valid(pctl, pin, fnum); in mtk_pctrl_dt_node_to_map_func()
511 dev_err(pctl->dev, "invalid function %d on pin %d .\n", in mtk_pctrl_dt_node_to_map_func()
513 return -EINVAL; in mtk_pctrl_dt_node_to_map_func()
537 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_dt_subnode_to_map() local
541 dev_err(pctl->dev, "missing pins property in node %pOFn .\n", in mtk_pctrl_dt_subnode_to_map()
543 return -EINVAL; in mtk_pctrl_dt_subnode_to_map()
554 num_pins = pins->length / sizeof(u32); in mtk_pctrl_dt_subnode_to_map()
563 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
583 if (pin >= pctl->devdata->npins || in mtk_pctrl_dt_subnode_to_map()
585 dev_err(pctl->dev, "invalid pins value.\n"); in mtk_pctrl_dt_subnode_to_map()
586 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
590 grp = mtk_pctrl_find_group_by_pin(pctl, pin); in mtk_pctrl_dt_subnode_to_map()
592 dev_err(pctl->dev, "unable to match pin %d to group\n", in mtk_pctrl_dt_subnode_to_map()
594 err = -EINVAL; in mtk_pctrl_dt_subnode_to_map()
598 err = mtk_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map, in mtk_pctrl_dt_subnode_to_map()
605 reserved_maps, num_maps, grp->name, in mtk_pctrl_dt_subnode_to_map()
647 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_groups_count() local
649 return pctl->ngroups; in mtk_pctrl_get_groups_count()
655 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_name() local
657 return pctl->groups[group].name; in mtk_pctrl_get_group_name()
665 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_pins() local
667 *pins = (unsigned *)&pctl->groups[group].pin; in mtk_pctrl_get_group_pins()
697 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_get_func_groups() local
699 *groups = pctl->grp_names; in mtk_pmx_get_func_groups()
700 *num_groups = pctl->ngroups; in mtk_pmx_get_func_groups()
711 unsigned int mask = (1L << GPIO_MODE_BITS) - 1; in mtk_pmx_set_mode()
712 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mode() local
714 if (pctl->devdata->spec_pinmux_set) in mtk_pmx_set_mode()
715 pctl->devdata->spec_pinmux_set(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
718 reg_addr = ((pin / pctl->devdata->mode_per_reg) << pctl->devdata->port_shf) in mtk_pmx_set_mode()
719 + pctl->devdata->pinmux_offset; in mtk_pmx_set_mode()
722 bit = pin % pctl->devdata->mode_per_reg; in mtk_pmx_set_mode()
725 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
730 mtk_find_pin_by_eint_num(struct mtk_pinctrl *pctl, unsigned int eint_num) in mtk_find_pin_by_eint_num() argument
735 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_find_pin_by_eint_num()
736 pin = pctl->devdata->pins + i; in mtk_find_pin_by_eint_num()
737 if (pin->eint.eintnum == eint_num) in mtk_find_pin_by_eint_num()
750 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mux() local
751 struct mtk_pinctrl_group *g = pctl->groups + group; in mtk_pmx_set_mux()
753 ret = mtk_pctrl_is_function_valid(pctl, g->pin, function); in mtk_pmx_set_mux()
755 dev_err(pctl->dev, "invalid function %d on group %d .\n", in mtk_pmx_set_mux()
757 return -EINVAL; in mtk_pmx_set_mux()
760 desc = mtk_pctrl_find_function_by_pin(pctl, g->pin, function); in mtk_pmx_set_mux()
762 return -EINVAL; in mtk_pmx_set_mux()
763 mtk_pmx_set_mode(pctldev, g->pin, desc->muxval); in mtk_pmx_set_mux()
767 static int mtk_pmx_find_gpio_mode(struct mtk_pinctrl *pctl, in mtk_pmx_find_gpio_mode() argument
770 const struct mtk_desc_pin *pin = pctl->devdata->pins + offset; in mtk_pmx_find_gpio_mode()
771 const struct mtk_desc_function *func = pin->functions; in mtk_pmx_find_gpio_mode()
773 while (func && func->name) { in mtk_pmx_find_gpio_mode()
774 if (!strncmp(func->name, GPIO_MODE_PREFIX, in mtk_pmx_find_gpio_mode()
775 sizeof(GPIO_MODE_PREFIX)-1)) in mtk_pmx_find_gpio_mode()
776 return func->muxval; in mtk_pmx_find_gpio_mode()
779 return -EINVAL; in mtk_pmx_find_gpio_mode()
787 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_gpio_request_enable() local
789 muxval = mtk_pmx_find_gpio_mode(pctl, offset); in mtk_pmx_gpio_request_enable()
792 dev_err(pctl->dev, "invalid gpio pin %d.\n", offset); in mtk_pmx_gpio_request_enable()
793 return -EINVAL; in mtk_pmx_gpio_request_enable()
797 mtk_pconf_set_ies_smt(pctl, offset, 1, PIN_CONFIG_INPUT_ENABLE); in mtk_pmx_gpio_request_enable()
814 return pinctrl_gpio_direction_input(chip->base + offset); in mtk_gpio_direction_input()
821 return pinctrl_gpio_direction_output(chip->base + offset); in mtk_gpio_direction_output()
830 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get_direction() local
832 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; in mtk_gpio_get_direction()
833 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get_direction()
835 if (pctl->devdata->spec_dir_set) in mtk_gpio_get_direction()
836 pctl->devdata->spec_dir_set(&reg_addr, offset); in mtk_gpio_get_direction()
838 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get_direction()
850 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get() local
852 reg_addr = mtk_get_port(pctl, offset) + in mtk_gpio_get()
853 pctl->devdata->din_offset; in mtk_gpio_get()
855 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get()
856 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get()
862 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_to_irq() local
866 pin = pctl->devdata->pins + offset; in mtk_gpio_to_irq()
867 if (pin->eint.eintnum == NO_EINT_SUPPORT) in mtk_gpio_to_irq()
868 return -EINVAL; in mtk_gpio_to_irq()
870 eint_n = pin->eint.eintnum; in mtk_gpio_to_irq()
872 return mtk_eint_find_irq(pctl->eint, eint_n); in mtk_gpio_to_irq()
878 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_set_config() local
884 return -ENOTSUPP; in mtk_gpio_set_config()
886 pin = pctl->devdata->pins + offset; in mtk_gpio_set_config()
887 if (pin->eint.eintnum == NO_EINT_SUPPORT) in mtk_gpio_set_config()
888 return -EINVAL; in mtk_gpio_set_config()
891 eint_n = pin->eint.eintnum; in mtk_gpio_set_config()
893 return mtk_eint_set_debounce(pctl->eint, eint_n, debounce); in mtk_gpio_set_config()
911 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_suspend() local
913 return mtk_eint_do_suspend(pctl->eint); in mtk_eint_suspend()
918 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_resume() local
920 return mtk_eint_do_resume(pctl->eint); in mtk_eint_resume()
930 struct mtk_pinctrl *pctl = platform_get_drvdata(pdev); in mtk_pctrl_build_state() local
933 pctl->ngroups = pctl->devdata->npins; in mtk_pctrl_build_state()
936 pctl->groups = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
937 sizeof(*pctl->groups), GFP_KERNEL); in mtk_pctrl_build_state()
938 if (!pctl->groups) in mtk_pctrl_build_state()
939 return -ENOMEM; in mtk_pctrl_build_state()
942 pctl->grp_names = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
943 sizeof(*pctl->grp_names), GFP_KERNEL); in mtk_pctrl_build_state()
944 if (!pctl->grp_names) in mtk_pctrl_build_state()
945 return -ENOMEM; in mtk_pctrl_build_state()
947 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_pctrl_build_state()
948 const struct mtk_desc_pin *pin = pctl->devdata->pins + i; in mtk_pctrl_build_state()
949 struct mtk_pinctrl_group *group = pctl->groups + i; in mtk_pctrl_build_state()
951 group->name = pin->pin.name; in mtk_pctrl_build_state()
952 group->pin = pin->pin.number; in mtk_pctrl_build_state()
954 pctl->grp_names[i] = pin->pin.name; in mtk_pctrl_build_state()
964 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_n() local
967 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_n()
969 return -EINVAL; in mtk_xt_get_gpio_n()
971 *gpio_chip = pctl->chip; in mtk_xt_get_gpio_n()
972 *gpio_n = pin->pin.number; in mtk_xt_get_gpio_n()
979 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_state() local
982 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_state()
984 return -EINVAL; in mtk_xt_get_gpio_state()
986 return mtk_gpio_get(pctl->chip, pin->pin.number); in mtk_xt_get_gpio_state()
991 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_set_gpio_as_eint() local
994 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_set_gpio_as_eint()
996 return -EINVAL; in mtk_xt_set_gpio_as_eint()
999 mtk_pmx_set_mode(pctl->pctl_dev, pin->pin.number, pin->eint.eintmux); in mtk_xt_set_gpio_as_eint()
1001 mtk_pmx_gpio_set_direction(pctl->pctl_dev, NULL, pin->pin.number, in mtk_xt_set_gpio_as_eint()
1003 /* set input-enable */ in mtk_xt_set_gpio_as_eint()
1004 mtk_pconf_set_ies_smt(pctl, pin->pin.number, 1, in mtk_xt_set_gpio_as_eint()
1016 static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev) in mtk_eint_init() argument
1018 struct device_node *np = pdev->dev.of_node; in mtk_eint_init()
1020 if (!of_property_read_bool(np, "interrupt-controller")) in mtk_eint_init()
1021 return -ENODEV; in mtk_eint_init()
1023 pctl->eint = devm_kzalloc(pctl->dev, sizeof(*pctl->eint), GFP_KERNEL); in mtk_eint_init()
1024 if (!pctl->eint) in mtk_eint_init()
1025 return -ENOMEM; in mtk_eint_init()
1027 pctl->eint->base = devm_platform_ioremap_resource(pdev, 0); in mtk_eint_init()
1028 if (IS_ERR(pctl->eint->base)) in mtk_eint_init()
1029 return PTR_ERR(pctl->eint->base); in mtk_eint_init()
1031 pctl->eint->irq = irq_of_parse_and_map(np, 0); in mtk_eint_init()
1032 if (!pctl->eint->irq) in mtk_eint_init()
1033 return -EINVAL; in mtk_eint_init()
1035 pctl->eint->dev = &pdev->dev; in mtk_eint_init()
1037 * If pctl->eint->regs == NULL, it would fall back into using a generic in mtk_eint_init()
1040 pctl->eint->regs = pctl->devdata->eint_regs; in mtk_eint_init()
1041 pctl->eint->hw = &pctl->devdata->eint_hw; in mtk_eint_init()
1042 pctl->eint->pctl = pctl; in mtk_eint_init()
1043 pctl->eint->gpio_xlate = &mtk_eint_xt; in mtk_eint_init()
1045 return mtk_eint_do_init(pctl->eint); in mtk_eint_init()
1051 struct regmap *regmap) in mtk_pctrl_init() argument
1053 struct device *dev = &pdev->dev; in mtk_pctrl_init()
1055 struct mtk_pinctrl *pctl; in mtk_pctrl_init() local
1056 struct device_node *np = pdev->dev.of_node, *node; in mtk_pctrl_init()
1059 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in mtk_pctrl_init()
1060 if (!pctl) in mtk_pctrl_init()
1061 return -ENOMEM; in mtk_pctrl_init()
1063 platform_set_drvdata(pdev, pctl); in mtk_pctrl_init()
1065 node = of_parse_phandle(np, "mediatek,pctl-regmap", 0); in mtk_pctrl_init()
1067 pctl->regmap1 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1069 if (IS_ERR(pctl->regmap1)) in mtk_pctrl_init()
1070 return PTR_ERR(pctl->regmap1); in mtk_pctrl_init()
1071 } else if (regmap) { in mtk_pctrl_init()
1072 pctl->regmap1 = regmap; in mtk_pctrl_init()
1074 return dev_err_probe(dev, -EINVAL, "Cannot find pinctrl regmap.\n"); in mtk_pctrl_init()
1078 node = of_parse_phandle(np, "mediatek,pctl-regmap", 1); in mtk_pctrl_init()
1080 pctl->regmap2 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1082 if (IS_ERR(pctl->regmap2)) in mtk_pctrl_init()
1083 return PTR_ERR(pctl->regmap2); in mtk_pctrl_init()
1086 pctl->devdata = data; in mtk_pctrl_init()
1091 pins = devm_kcalloc(&pdev->dev, pctl->devdata->npins, sizeof(*pins), in mtk_pctrl_init()
1094 return -ENOMEM; in mtk_pctrl_init()
1096 for (i = 0; i < pctl->devdata->npins; i++) in mtk_pctrl_init()
1097 pins[i] = pctl->devdata->pins[i].pin; in mtk_pctrl_init()
1099 pctl->pctl_desc.name = dev_name(&pdev->dev); in mtk_pctrl_init()
1100 pctl->pctl_desc.owner = THIS_MODULE; in mtk_pctrl_init()
1101 pctl->pctl_desc.pins = pins; in mtk_pctrl_init()
1102 pctl->pctl_desc.npins = pctl->devdata->npins; in mtk_pctrl_init()
1103 pctl->pctl_desc.confops = &mtk_pconf_ops; in mtk_pctrl_init()
1104 pctl->pctl_desc.pctlops = &mtk_pctrl_ops; in mtk_pctrl_init()
1105 pctl->pctl_desc.pmxops = &mtk_pmx_ops; in mtk_pctrl_init()
1106 pctl->dev = &pdev->dev; in mtk_pctrl_init()
1108 pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, &pctl->pctl_desc, in mtk_pctrl_init()
1109 pctl); in mtk_pctrl_init()
1110 if (IS_ERR(pctl->pctl_dev)) in mtk_pctrl_init()
1111 return dev_err_probe(dev, PTR_ERR(pctl->pctl_dev), in mtk_pctrl_init()
1114 pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); in mtk_pctrl_init()
1115 if (!pctl->chip) in mtk_pctrl_init()
1116 return -ENOMEM; in mtk_pctrl_init()
1118 *pctl->chip = mtk_gpio_chip; in mtk_pctrl_init()
1119 pctl->chip->ngpio = pctl->devdata->npins; in mtk_pctrl_init()
1120 pctl->chip->label = dev_name(&pdev->dev); in mtk_pctrl_init()
1121 pctl->chip->parent = &pdev->dev; in mtk_pctrl_init()
1122 pctl->chip->base = -1; in mtk_pctrl_init()
1124 ret = gpiochip_add_data(pctl->chip, pctl); in mtk_pctrl_init()
1126 return -EINVAL; in mtk_pctrl_init()
1129 ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), in mtk_pctrl_init()
1130 0, 0, pctl->devdata->npins); in mtk_pctrl_init()
1132 ret = -EINVAL; in mtk_pctrl_init()
1136 ret = mtk_eint_init(pctl, pdev); in mtk_pctrl_init()
1143 gpiochip_remove(pctl->chip); in mtk_pctrl_init()
1149 struct device *dev = &pdev->dev; in mtk_pctrl_common_probe()
1153 return -ENODEV; in mtk_pctrl_common_probe()