Lines Matching full:pctl
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(®_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()
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()
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()
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()
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()
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()
223 drv_grp = pctl->devdata->grp_desc + pin_drv->grp; in mtk_pconf_set_driving()
232 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pconf_set_driving()
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()
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()
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()
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()
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()
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()
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()
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()
496 static int mtk_pctrl_dt_node_to_map_func(struct mtk_pinctrl *pctl, in mtk_pctrl_dt_node_to_map_func() argument
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()
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()
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()
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()
598 err = mtk_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map, in mtk_pctrl_dt_subnode_to_map()
645 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_groups_count() local
647 return pctl->ngroups; in mtk_pctrl_get_groups_count()
653 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_name() local
655 return pctl->groups[group].name; in mtk_pctrl_get_group_name()
663 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pctrl_get_group_pins() local
665 *pins = (unsigned *)&pctl->groups[group].pin; in mtk_pctrl_get_group_pins()
695 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_get_func_groups() local
697 *groups = pctl->grp_names; in mtk_pmx_get_func_groups()
698 *num_groups = pctl->ngroups; in mtk_pmx_get_func_groups()
710 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mode() local
712 if (pctl->devdata->spec_pinmux_set) in mtk_pmx_set_mode()
713 pctl->devdata->spec_pinmux_set(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
716 reg_addr = ((pin / pctl->devdata->mode_per_reg) << pctl->devdata->port_shf) in mtk_pmx_set_mode()
717 + pctl->devdata->pinmux_offset; in mtk_pmx_set_mode()
720 bit = pin % pctl->devdata->mode_per_reg; in mtk_pmx_set_mode()
723 return regmap_update_bits(mtk_get_regmap(pctl, pin), in mtk_pmx_set_mode()
728 mtk_find_pin_by_eint_num(struct mtk_pinctrl *pctl, unsigned int eint_num) in mtk_find_pin_by_eint_num() argument
733 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_find_pin_by_eint_num()
734 pin = pctl->devdata->pins + i; in mtk_find_pin_by_eint_num()
748 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_set_mux() local
749 struct mtk_pinctrl_group *g = pctl->groups + group; in mtk_pmx_set_mux()
751 ret = mtk_pctrl_is_function_valid(pctl, g->pin, function); in mtk_pmx_set_mux()
753 dev_err(pctl->dev, "invalid function %d on group %d .\n", in mtk_pmx_set_mux()
758 desc = mtk_pctrl_find_function_by_pin(pctl, g->pin, function); in mtk_pmx_set_mux()
765 static int mtk_pmx_find_gpio_mode(struct mtk_pinctrl *pctl, in mtk_pmx_find_gpio_mode() argument
768 const struct mtk_desc_pin *pin = pctl->devdata->pins + offset; in mtk_pmx_find_gpio_mode()
785 struct mtk_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in mtk_pmx_gpio_request_enable() local
787 muxval = mtk_pmx_find_gpio_mode(pctl, offset); in mtk_pmx_gpio_request_enable()
790 dev_err(pctl->dev, "invalid gpio pin %d.\n", offset); in mtk_pmx_gpio_request_enable()
795 mtk_pconf_set_ies_smt(pctl, offset, 1, PIN_CONFIG_INPUT_ENABLE); in mtk_pmx_gpio_request_enable()
822 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get_direction() local
824 reg_addr = mtk_get_port(pctl, offset) + pctl->devdata->dir_offset; in mtk_gpio_get_direction()
825 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get_direction()
827 if (pctl->devdata->spec_dir_set) in mtk_gpio_get_direction()
828 pctl->devdata->spec_dir_set(®_addr, offset); in mtk_gpio_get_direction()
830 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get_direction()
842 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_get() local
844 reg_addr = mtk_get_port(pctl, offset) + in mtk_gpio_get()
845 pctl->devdata->din_offset; in mtk_gpio_get()
847 bit = BIT(offset & pctl->devdata->mode_mask); in mtk_gpio_get()
848 regmap_read(pctl->regmap1, reg_addr, &read_val); in mtk_gpio_get()
854 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_to_irq() local
858 pin = pctl->devdata->pins + offset; in mtk_gpio_to_irq()
864 return mtk_eint_find_irq(pctl->eint, eint_n); in mtk_gpio_to_irq()
870 struct mtk_pinctrl *pctl = gpiochip_get_data(chip); in mtk_gpio_set_config() local
878 pin = pctl->devdata->pins + offset; in mtk_gpio_set_config()
885 return mtk_eint_set_debounce(pctl->eint, eint_n, debounce); in mtk_gpio_set_config()
903 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_suspend() local
905 return mtk_eint_do_suspend(pctl->eint); in mtk_eint_suspend()
910 struct mtk_pinctrl *pctl = dev_get_drvdata(device); in mtk_eint_resume() local
912 return mtk_eint_do_resume(pctl->eint); in mtk_eint_resume()
921 struct mtk_pinctrl *pctl = platform_get_drvdata(pdev); in mtk_pctrl_build_state() local
924 pctl->ngroups = pctl->devdata->npins; in mtk_pctrl_build_state()
927 pctl->groups = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
928 sizeof(*pctl->groups), GFP_KERNEL); in mtk_pctrl_build_state()
929 if (!pctl->groups) in mtk_pctrl_build_state()
933 pctl->grp_names = devm_kcalloc(&pdev->dev, pctl->ngroups, in mtk_pctrl_build_state()
934 sizeof(*pctl->grp_names), GFP_KERNEL); in mtk_pctrl_build_state()
935 if (!pctl->grp_names) in mtk_pctrl_build_state()
938 for (i = 0; i < pctl->devdata->npins; i++) { in mtk_pctrl_build_state()
939 const struct mtk_desc_pin *pin = pctl->devdata->pins + i; in mtk_pctrl_build_state()
940 struct mtk_pinctrl_group *group = pctl->groups + i; in mtk_pctrl_build_state()
945 pctl->grp_names[i] = pin->pin.name; in mtk_pctrl_build_state()
955 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_n() local
958 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_n()
962 *gpio_chip = pctl->chip; in mtk_xt_get_gpio_n()
970 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_get_gpio_state() local
973 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_get_gpio_state()
977 return mtk_gpio_get(pctl->chip, pin->pin.number); in mtk_xt_get_gpio_state()
982 struct mtk_pinctrl *pctl = (struct mtk_pinctrl *)data; in mtk_xt_set_gpio_as_eint() local
985 pin = mtk_find_pin_by_eint_num(pctl, eint_n); in mtk_xt_set_gpio_as_eint()
990 mtk_pmx_set_mode(pctl->pctl_dev, pin->pin.number, pin->eint.eintmux); in mtk_xt_set_gpio_as_eint()
992 mtk_pmx_gpio_set_direction(pctl->pctl_dev, NULL, pin->pin.number, in mtk_xt_set_gpio_as_eint()
995 mtk_pconf_set_ies_smt(pctl, pin->pin.number, 1, in mtk_xt_set_gpio_as_eint()
1007 static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev) in mtk_eint_init() argument
1014 pctl->eint = devm_kzalloc(pctl->dev, sizeof(*pctl->eint), GFP_KERNEL); in mtk_eint_init()
1015 if (!pctl->eint) in mtk_eint_init()
1018 pctl->eint->base = devm_platform_ioremap_resource(pdev, 0); in mtk_eint_init()
1019 if (IS_ERR(pctl->eint->base)) in mtk_eint_init()
1020 return PTR_ERR(pctl->eint->base); in mtk_eint_init()
1022 pctl->eint->irq = irq_of_parse_and_map(np, 0); in mtk_eint_init()
1023 if (!pctl->eint->irq) in mtk_eint_init()
1026 pctl->eint->dev = &pdev->dev; in mtk_eint_init()
1028 * If pctl->eint->regs == NULL, it would fall back into using a generic in mtk_eint_init()
1031 pctl->eint->regs = pctl->devdata->eint_regs; in mtk_eint_init()
1032 pctl->eint->hw = &pctl->devdata->eint_hw; in mtk_eint_init()
1033 pctl->eint->pctl = pctl; in mtk_eint_init()
1034 pctl->eint->gpio_xlate = &mtk_eint_xt; in mtk_eint_init()
1036 return mtk_eint_do_init(pctl->eint); in mtk_eint_init()
1046 struct mtk_pinctrl *pctl; in mtk_pctrl_init() local
1050 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); in mtk_pctrl_init()
1051 if (!pctl) in mtk_pctrl_init()
1054 platform_set_drvdata(pdev, pctl); in mtk_pctrl_init()
1056 node = of_parse_phandle(np, "mediatek,pctl-regmap", 0); in mtk_pctrl_init()
1058 pctl->regmap1 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1060 if (IS_ERR(pctl->regmap1)) in mtk_pctrl_init()
1061 return PTR_ERR(pctl->regmap1); in mtk_pctrl_init()
1063 pctl->regmap1 = regmap; in mtk_pctrl_init()
1069 node = of_parse_phandle(np, "mediatek,pctl-regmap", 1); in mtk_pctrl_init()
1071 pctl->regmap2 = syscon_node_to_regmap(node); in mtk_pctrl_init()
1073 if (IS_ERR(pctl->regmap2)) in mtk_pctrl_init()
1074 return PTR_ERR(pctl->regmap2); in mtk_pctrl_init()
1077 pctl->devdata = data; in mtk_pctrl_init()
1082 pins = devm_kcalloc(&pdev->dev, pctl->devdata->npins, sizeof(*pins), in mtk_pctrl_init()
1087 for (i = 0; i < pctl->devdata->npins; i++) in mtk_pctrl_init()
1088 pins[i] = pctl->devdata->pins[i].pin; in mtk_pctrl_init()
1090 pctl->pctl_desc.name = dev_name(&pdev->dev); in mtk_pctrl_init()
1091 pctl->pctl_desc.owner = THIS_MODULE; in mtk_pctrl_init()
1092 pctl->pctl_desc.pins = pins; in mtk_pctrl_init()
1093 pctl->pctl_desc.npins = pctl->devdata->npins; in mtk_pctrl_init()
1094 pctl->pctl_desc.confops = &mtk_pconf_ops; in mtk_pctrl_init()
1095 pctl->pctl_desc.pctlops = &mtk_pctrl_ops; in mtk_pctrl_init()
1096 pctl->pctl_desc.pmxops = &mtk_pmx_ops; in mtk_pctrl_init()
1097 pctl->dev = &pdev->dev; in mtk_pctrl_init()
1099 pctl->pctl_dev = devm_pinctrl_register(&pdev->dev, &pctl->pctl_desc, in mtk_pctrl_init()
1100 pctl); in mtk_pctrl_init()
1101 if (IS_ERR(pctl->pctl_dev)) in mtk_pctrl_init()
1102 return dev_err_probe(dev, PTR_ERR(pctl->pctl_dev), in mtk_pctrl_init()
1105 pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); in mtk_pctrl_init()
1106 if (!pctl->chip) in mtk_pctrl_init()
1109 *pctl->chip = mtk_gpio_chip; in mtk_pctrl_init()
1110 pctl->chip->ngpio = pctl->devdata->npins; in mtk_pctrl_init()
1111 pctl->chip->label = dev_name(&pdev->dev); in mtk_pctrl_init()
1112 pctl->chip->parent = &pdev->dev; in mtk_pctrl_init()
1113 pctl->chip->base = -1; in mtk_pctrl_init()
1115 ret = gpiochip_add_data(pctl->chip, pctl); in mtk_pctrl_init()
1120 ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), in mtk_pctrl_init()
1121 0, 0, pctl->devdata->npins); in mtk_pctrl_init()
1127 ret = mtk_eint_init(pctl, pdev); in mtk_pctrl_init()
1134 gpiochip_remove(pctl->chip); in mtk_pctrl_init()