Lines Matching +full:pullup +full:- +full:ohm
1 // SPDX-License-Identifier: GPL-2.0
9 #include <dt-bindings/pinctrl/mt65xx.h>
19 #include "mtk-eint.h"
20 #include "pinctrl-mtk-common-v2.h"
23 * struct mtk_drive_desc - the structure that holds the information
30 * formula: output = ((input) / step - 1) * scal
50 writel_relaxed(val, pctl->base[i] + reg); in mtk_w32()
55 return readl_relaxed(pctl->base[i] + reg); in mtk_r32()
63 spin_lock_irqsave(&pctl->lock, flags); in mtk_rmw()
70 spin_unlock_irqrestore(&pctl->lock, flags); in mtk_rmw()
83 if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) { in mtk_hw_pin_field_lookup()
84 rc = &hw->soc->reg_cal[field]; in mtk_hw_pin_field_lookup()
86 dev_dbg(hw->dev, in mtk_hw_pin_field_lookup()
88 return -ENOTSUPP; in mtk_hw_pin_field_lookup()
91 end = rc->nranges - 1; in mtk_hw_pin_field_lookup()
95 if (desc->number >= rc->range[check].s_pin in mtk_hw_pin_field_lookup()
96 && desc->number <= rc->range[check].e_pin) { in mtk_hw_pin_field_lookup()
101 else if (desc->number < rc->range[check].s_pin) in mtk_hw_pin_field_lookup()
102 end = check - 1; in mtk_hw_pin_field_lookup()
108 dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n", in mtk_hw_pin_field_lookup()
109 field, desc->number, desc->name); in mtk_hw_pin_field_lookup()
110 return -ENOTSUPP; in mtk_hw_pin_field_lookup()
113 c = rc->range + check; in mtk_hw_pin_field_lookup()
115 if (c->i_base > hw->nbase - 1) { in mtk_hw_pin_field_lookup()
116 dev_err(hw->dev, in mtk_hw_pin_field_lookup()
118 field, desc->number, desc->name); in mtk_hw_pin_field_lookup()
119 return -EINVAL; in mtk_hw_pin_field_lookup()
123 * if c->fixed is held, that determines the all the pins in the in mtk_hw_pin_field_lookup()
126 bits = c->fixed ? c->s_bit : c->s_bit + in mtk_hw_pin_field_lookup()
127 (desc->number - c->s_pin) * (c->x_bits); in mtk_hw_pin_field_lookup()
129 /* Fill pfd from bits. For example 32-bit register applied is assumed in mtk_hw_pin_field_lookup()
130 * when c->sz_reg is equal to 32. in mtk_hw_pin_field_lookup()
132 pfd->index = c->i_base; in mtk_hw_pin_field_lookup()
133 pfd->offset = c->s_addr + c->x_addrs * (bits / c->sz_reg); in mtk_hw_pin_field_lookup()
134 pfd->bitpos = bits % c->sz_reg; in mtk_hw_pin_field_lookup()
135 pfd->mask = (1 << c->x_bits) - 1; in mtk_hw_pin_field_lookup()
137 /* pfd->next is used for indicating that bit wrapping-around happens in mtk_hw_pin_field_lookup()
141 pfd->next = pfd->bitpos + c->x_bits > c->sz_reg ? c->x_addrs : 0; in mtk_hw_pin_field_lookup()
151 dev_err(hw->dev, "Invalid Field %d\n", field); in mtk_hw_pin_field_get()
152 return -EINVAL; in mtk_hw_pin_field_get()
160 *l = 32 - pf->bitpos; in mtk_hw_bits_part()
161 *h = get_count_order(pf->mask) - *l; in mtk_hw_bits_part()
171 mtk_rmw(hw, pf->index, pf->offset, pf->mask << pf->bitpos, in mtk_hw_write_cross_field()
172 (value & pf->mask) << pf->bitpos); in mtk_hw_write_cross_field()
174 mtk_rmw(hw, pf->index, pf->offset + pf->next, BIT(nbits_h) - 1, in mtk_hw_write_cross_field()
175 (value & pf->mask) >> nbits_l); in mtk_hw_write_cross_field()
185 l = (mtk_r32(hw, pf->index, pf->offset) in mtk_hw_read_cross_field()
186 >> pf->bitpos) & (BIT(nbits_l) - 1); in mtk_hw_read_cross_field()
187 h = (mtk_r32(hw, pf->index, pf->offset + pf->next)) in mtk_hw_read_cross_field()
188 & (BIT(nbits_h) - 1); in mtk_hw_read_cross_field()
204 return -EINVAL; in mtk_hw_set_value()
241 desc = (const struct mtk_pin_desc *)hw->soc->pins; in mtk_xt_find_eint_num()
243 while (i < hw->soc->npins) { in mtk_xt_find_eint_num()
255 * In MTK platform, external interrupt (EINT) and GPIO is 1-1 mapping
266 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_is_virt_gpio()
269 if (desc->eint.eint_m == NO_EINT_SUPPORT) in mtk_is_virt_gpio()
272 if (desc->funcs && !desc->funcs[desc->eint.eint_m].name) in mtk_is_virt_gpio()
286 desc = (const struct mtk_pin_desc *)hw->soc->pins; in mtk_xt_get_gpio_n()
287 *gpio_chip = &hw->chip; in mtk_xt_get_gpio_n()
293 if (hw->soc->npins > eint_n && in mtk_xt_get_gpio_n()
299 return *gpio_n == EINT_NA ? -EINVAL : 0; in mtk_xt_get_gpio_n()
314 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_xt_get_gpio_state()
338 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_xt_set_gpio_as_eint()
341 desc->eint.eint_m); in mtk_xt_set_gpio_as_eint()
351 * support virtual GPIOs, so the extra condition err != -ENOTSUPP in mtk_xt_set_gpio_as_eint()
356 if (err && err != -ENOTSUPP) in mtk_xt_set_gpio_as_eint()
370 struct device_node *np = pdev->dev.of_node; in mtk_build_eint()
376 if (!of_property_read_bool(np, "interrupt-controller")) in mtk_build_eint()
377 return -ENODEV; in mtk_build_eint()
379 hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL); in mtk_build_eint()
380 if (!hw->eint) in mtk_build_eint()
381 return -ENOMEM; in mtk_build_eint()
383 count_reg_names = of_property_count_strings(np, "reg-names"); in mtk_build_eint()
385 return -EINVAL; in mtk_build_eint()
387 hw->eint->nbase = count_reg_names - (int)hw->soc->nbase_names; in mtk_build_eint()
388 if (hw->eint->nbase <= 0) in mtk_build_eint()
389 return -EINVAL; in mtk_build_eint()
391 hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase, in mtk_build_eint()
392 sizeof(*hw->eint->base), GFP_KERNEL | __GFP_ZERO); in mtk_build_eint()
393 if (!hw->eint->base) { in mtk_build_eint()
394 ret = -ENOMEM; in mtk_build_eint()
398 for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) { in mtk_build_eint()
399 hw->eint->base[j] = of_iomap(np, i); in mtk_build_eint()
400 if (IS_ERR(hw->eint->base[j])) { in mtk_build_eint()
401 ret = PTR_ERR(hw->eint->base[j]); in mtk_build_eint()
406 hw->eint->irq = irq_of_parse_and_map(np, 0); in mtk_build_eint()
407 if (!hw->eint->irq) { in mtk_build_eint()
408 ret = -EINVAL; in mtk_build_eint()
412 if (!hw->soc->eint_hw) { in mtk_build_eint()
413 ret = -ENODEV; in mtk_build_eint()
417 hw->eint->dev = &pdev->dev; in mtk_build_eint()
418 hw->eint->hw = hw->soc->eint_hw; in mtk_build_eint()
419 hw->eint->pctl = hw; in mtk_build_eint()
420 hw->eint->gpio_xlate = &mtk_eint_xt; in mtk_build_eint()
422 ret = mtk_eint_do_init(hw->eint, hw->soc->eint_pin); in mtk_build_eint()
429 for (j = 0; j < hw->eint->nbase; j++) { in mtk_build_eint()
430 if (hw->eint->base[j]) in mtk_build_eint()
431 iounmap(hw->eint->base[j]); in mtk_build_eint()
433 devm_kfree(hw->dev, hw->eint->base); in mtk_build_eint()
435 devm_kfree(hw->dev, hw->eint); in mtk_build_eint()
436 hw->eint = NULL; in mtk_build_eint()
476 return -EINVAL; in mtk_pinconf_bias_disable_get()
485 const struct mtk_pin_desc *desc, bool pullup) in mtk_pinconf_bias_set() argument
489 arg = pullup ? 1 : 2; in mtk_pinconf_bias_set()
505 const struct mtk_pin_desc *desc, bool pullup, int *res) in mtk_pinconf_bias_get() argument
509 reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD; in mtk_pinconf_bias_get()
516 return -EINVAL; in mtk_pinconf_bias_get()
543 return -EINVAL; in mtk_pinconf_bias_disable_get_rev1()
552 const struct mtk_pin_desc *desc, bool pullup) in mtk_pinconf_bias_set_rev1() argument
556 arg = pullup ? MTK_PULLUP : MTK_PULLDOWN; in mtk_pinconf_bias_set_rev1()
572 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_bias_get_rev1() argument
582 return -EINVAL; in mtk_pinconf_bias_get_rev1()
588 if (pullup ^ (v == MTK_PULLUP)) in mtk_pinconf_bias_get_rev1()
589 return -EINVAL; in mtk_pinconf_bias_get_rev1()
604 u32 pullup, u32 arg, bool pd_only) in mtk_pinconf_bias_set_pu_pd() argument
611 } else if ((arg == MTK_ENABLE) && pullup) { in mtk_pinconf_bias_set_pu_pd()
614 } else if ((arg == MTK_ENABLE) && !pullup) { in mtk_pinconf_bias_set_pu_pd()
618 return -EINVAL; in mtk_pinconf_bias_set_pu_pd()
632 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pullsel_pullen() argument
641 err = -EINVAL; in mtk_pinconf_bias_set_pullsel_pullen()
649 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_set_pullsel_pullen()
657 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pupd_r1_r0() argument
662 pullup = 0; in mtk_pinconf_bias_set_pupd_r1_r0()
675 err = -EINVAL; in mtk_pinconf_bias_set_pupd_r1_r0()
679 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_set_pupd_r1_r0()
680 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup); in mtk_pinconf_bias_set_pupd_r1_r0()
696 u32 pullup, u32 arg, u32 *rsel_val) in mtk_hw_pin_rsel_lookup() argument
702 rsel = hw->soc->pin_rsel; in mtk_hw_pin_rsel_lookup()
704 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_hw_pin_rsel_lookup()
705 if (desc->number >= rsel[check].s_pin && in mtk_hw_pin_rsel_lookup()
706 desc->number <= rsel[check].e_pin) { in mtk_hw_pin_rsel_lookup()
707 if (pullup) { in mtk_hw_pin_rsel_lookup()
724 dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n", in mtk_hw_pin_rsel_lookup()
725 arg, desc->number, desc->name); in mtk_hw_pin_rsel_lookup()
726 return -ENOTSUPP; in mtk_hw_pin_rsel_lookup()
734 u32 pullup, u32 arg) in mtk_pinconf_bias_set_rsel() argument
738 if (hw->rsel_si_unit) { in mtk_pinconf_bias_set_rsel()
740 err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val); in mtk_pinconf_bias_set_rsel()
745 return -EINVAL; in mtk_pinconf_bias_set_rsel()
747 rsel_val = arg - MTK_PULL_SET_RSEL_000; in mtk_pinconf_bias_set_rsel()
755 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pu_pd_rsel() argument
761 err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_pu_pd_rsel()
766 return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable, false); in mtk_pinconf_bias_set_pu_pd_rsel()
771 u32 pullup, u32 arg) in mtk_pinconf_bias_set_combo() argument
773 int err = -ENOTSUPP; in mtk_pinconf_bias_set_combo()
776 if (hw->soc->pull_type) in mtk_pinconf_bias_set_combo()
777 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_set_combo()
782 err = mtk_pinconf_bias_set_pu_pd_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
788 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, true); in mtk_pinconf_bias_set_combo()
794 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, false); in mtk_pinconf_bias_set_combo()
801 pullup, arg); in mtk_pinconf_bias_set_combo()
807 err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
810 dev_err(hw->dev, "Invalid pull argument\n"); in mtk_pinconf_bias_set_combo()
818 u32 pullup, u32 rsel_val, u32 *si_unit) in mtk_rsel_get_si_unit() argument
823 rsel = hw->soc->pin_rsel; in mtk_rsel_get_si_unit()
825 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_rsel_get_si_unit()
826 if (desc->number >= rsel[check].s_pin && in mtk_rsel_get_si_unit()
827 desc->number <= rsel[check].e_pin) { in mtk_rsel_get_si_unit()
829 if (pullup) in mtk_rsel_get_si_unit()
843 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd_rsel() argument
860 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
863 *pullup = 1; in mtk_pinconf_bias_get_pu_pd_rsel()
864 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
865 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
869 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
870 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
871 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
875 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd_rsel()
885 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd() argument
898 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
901 *pullup = 1; in mtk_pinconf_bias_get_pu_pd()
904 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
907 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd()
915 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pd() argument
924 *pullup = 0; in mtk_pinconf_bias_get_pd()
927 *pullup = 0; in mtk_pinconf_bias_get_pd()
930 err = -EINVAL; in mtk_pinconf_bias_get_pd()
938 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pullsel_pullen() argument
942 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_get_pullsel_pullen()
954 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pupd_r1_r0() argument
958 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
961 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_get_pupd_r1_r0()
962 *pullup = !(*pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
981 err = -EINVAL; in mtk_pinconf_bias_get_pupd_r1_r0()
989 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_combo() argument
991 int err = -ENOTSUPP; in mtk_pinconf_bias_get_combo()
994 if (hw->soc->pull_type) in mtk_pinconf_bias_get_combo()
995 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_get_combo()
1000 err = mtk_pinconf_bias_get_pu_pd_rsel(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
1006 err = mtk_pinconf_bias_get_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
1012 err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
1019 pullup, enable); in mtk_pinconf_bias_get_combo()
1025 err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
1036 int err = -ENOTSUPP; in mtk_pinconf_drive_set()
1038 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set()
1044 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set()
1045 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set()
1067 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get()
1080 *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get()
1091 int err = -ENOTSUPP; in mtk_pinconf_drive_set_rev1()
1093 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set_rev1()
1095 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set_rev1()
1096 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set_rev1()
1114 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get_rev1()
1120 *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get_rev1()
1141 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_set() argument
1160 arg = pullup ? 0 : 1; in mtk_pinconf_adv_pull_set()
1167 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_set()
1168 if (hw->soc->bias_set) { in mtk_pinconf_adv_pull_set()
1169 err = hw->soc->bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1173 err = mtk_pinconf_bias_set_rev1(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1175 err = mtk_pinconf_bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1184 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_get() argument
1195 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_get()
1196 if (hw->soc->bias_get) { in mtk_pinconf_adv_pull_get()
1197 err = hw->soc->bias_get(hw, desc, pullup, val); in mtk_pinconf_adv_pull_get()
1201 return -ENOTSUPP; in mtk_pinconf_adv_pull_get()
1204 /* t == 0 supposes PULLUP for the customized PULL setup */ in mtk_pinconf_adv_pull_get()
1208 if (pullup ^ !t) in mtk_pinconf_adv_pull_get()
1209 return -EINVAL; in mtk_pinconf_adv_pull_get()