Lines Matching +full:pullup +full:- +full:ohm
1 // SPDX-License-Identifier: GPL-2.0
9 #include <dt-bindings/pinctrl/mt65xx.h>
18 #include "mtk-eint.h"
19 #include "pinctrl-mtk-common-v2.h"
22 * struct mtk_drive_desc - the structure that holds the information
29 * formula: output = ((input) / step - 1) * scal
49 writel_relaxed(val, pctl->base[i] + reg); in mtk_w32()
54 return readl_relaxed(pctl->base[i] + reg); in mtk_r32()
62 spin_lock_irqsave(&pctl->lock, flags); in mtk_rmw()
69 spin_unlock_irqrestore(&pctl->lock, flags); in mtk_rmw()
82 if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) { in mtk_hw_pin_field_lookup()
83 rc = &hw->soc->reg_cal[field]; in mtk_hw_pin_field_lookup()
85 dev_dbg(hw->dev, in mtk_hw_pin_field_lookup()
87 return -ENOTSUPP; in mtk_hw_pin_field_lookup()
90 end = rc->nranges - 1; in mtk_hw_pin_field_lookup()
94 if (desc->number >= rc->range[check].s_pin in mtk_hw_pin_field_lookup()
95 && desc->number <= rc->range[check].e_pin) { in mtk_hw_pin_field_lookup()
100 else if (desc->number < rc->range[check].s_pin) in mtk_hw_pin_field_lookup()
101 end = check - 1; in mtk_hw_pin_field_lookup()
107 dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n", in mtk_hw_pin_field_lookup()
108 field, desc->number, desc->name); in mtk_hw_pin_field_lookup()
109 return -ENOTSUPP; in mtk_hw_pin_field_lookup()
112 c = rc->range + check; in mtk_hw_pin_field_lookup()
114 if (c->i_base > hw->nbase - 1) { in mtk_hw_pin_field_lookup()
115 dev_err(hw->dev, in mtk_hw_pin_field_lookup()
117 field, desc->number, desc->name); in mtk_hw_pin_field_lookup()
118 return -EINVAL; in mtk_hw_pin_field_lookup()
122 * if c->fixed is held, that determines the all the pins in the in mtk_hw_pin_field_lookup()
125 bits = c->fixed ? c->s_bit : c->s_bit + in mtk_hw_pin_field_lookup()
126 (desc->number - c->s_pin) * (c->x_bits); in mtk_hw_pin_field_lookup()
128 /* Fill pfd from bits. For example 32-bit register applied is assumed in mtk_hw_pin_field_lookup()
129 * when c->sz_reg is equal to 32. in mtk_hw_pin_field_lookup()
131 pfd->index = c->i_base; in mtk_hw_pin_field_lookup()
132 pfd->offset = c->s_addr + c->x_addrs * (bits / c->sz_reg); in mtk_hw_pin_field_lookup()
133 pfd->bitpos = bits % c->sz_reg; in mtk_hw_pin_field_lookup()
134 pfd->mask = (1 << c->x_bits) - 1; in mtk_hw_pin_field_lookup()
136 /* pfd->next is used for indicating that bit wrapping-around happens in mtk_hw_pin_field_lookup()
140 pfd->next = pfd->bitpos + c->x_bits > c->sz_reg ? c->x_addrs : 0; in mtk_hw_pin_field_lookup()
150 dev_err(hw->dev, "Invalid Field %d\n", field); in mtk_hw_pin_field_get()
151 return -EINVAL; in mtk_hw_pin_field_get()
159 *l = 32 - pf->bitpos; in mtk_hw_bits_part()
160 *h = get_count_order(pf->mask) - *l; in mtk_hw_bits_part()
170 mtk_rmw(hw, pf->index, pf->offset, pf->mask << pf->bitpos, in mtk_hw_write_cross_field()
171 (value & pf->mask) << pf->bitpos); in mtk_hw_write_cross_field()
173 mtk_rmw(hw, pf->index, pf->offset + pf->next, BIT(nbits_h) - 1, in mtk_hw_write_cross_field()
174 (value & pf->mask) >> nbits_l); in mtk_hw_write_cross_field()
184 l = (mtk_r32(hw, pf->index, pf->offset) in mtk_hw_read_cross_field()
185 >> pf->bitpos) & (BIT(nbits_l) - 1); in mtk_hw_read_cross_field()
186 h = (mtk_r32(hw, pf->index, pf->offset + pf->next)) in mtk_hw_read_cross_field()
187 & (BIT(nbits_h) - 1); in mtk_hw_read_cross_field()
203 return -EINVAL; in mtk_hw_set_value()
240 desc = (const struct mtk_pin_desc *)hw->soc->pins; in mtk_xt_find_eint_num()
242 while (i < hw->soc->npins) { in mtk_xt_find_eint_num()
254 * In MTK platform, external interrupt (EINT) and GPIO is 1-1 mapping
265 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_is_virt_gpio()
268 if (desc->eint.eint_m == NO_EINT_SUPPORT) in mtk_is_virt_gpio()
271 if (desc->funcs && !desc->funcs[desc->eint.eint_m].name) in mtk_is_virt_gpio()
285 desc = (const struct mtk_pin_desc *)hw->soc->pins; in mtk_xt_get_gpio_n()
286 *gpio_chip = &hw->chip; in mtk_xt_get_gpio_n()
292 if (hw->soc->npins > eint_n && in mtk_xt_get_gpio_n()
298 return *gpio_n == EINT_NA ? -EINVAL : 0; in mtk_xt_get_gpio_n()
313 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_xt_get_gpio_state()
337 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; in mtk_xt_set_gpio_as_eint()
340 desc->eint.eint_m); in mtk_xt_set_gpio_as_eint()
350 * support virtual GPIOs, so the extra condition err != -ENOTSUPP in mtk_xt_set_gpio_as_eint()
355 if (err && err != -ENOTSUPP) in mtk_xt_set_gpio_as_eint()
369 struct device_node *np = pdev->dev.of_node; in mtk_build_eint()
375 if (!of_property_read_bool(np, "interrupt-controller")) in mtk_build_eint()
376 return -ENODEV; in mtk_build_eint()
378 hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL); in mtk_build_eint()
379 if (!hw->eint) in mtk_build_eint()
380 return -ENOMEM; in mtk_build_eint()
382 hw->eint->base = devm_platform_ioremap_resource_byname(pdev, "eint"); in mtk_build_eint()
383 if (IS_ERR(hw->eint->base)) { in mtk_build_eint()
384 ret = PTR_ERR(hw->eint->base); in mtk_build_eint()
388 hw->eint->irq = irq_of_parse_and_map(np, 0); in mtk_build_eint()
389 if (!hw->eint->irq) { in mtk_build_eint()
390 ret = -EINVAL; in mtk_build_eint()
394 if (!hw->soc->eint_hw) { in mtk_build_eint()
395 ret = -ENODEV; in mtk_build_eint()
399 hw->eint->dev = &pdev->dev; in mtk_build_eint()
400 hw->eint->hw = hw->soc->eint_hw; in mtk_build_eint()
401 hw->eint->pctl = hw; in mtk_build_eint()
402 hw->eint->gpio_xlate = &mtk_eint_xt; in mtk_build_eint()
404 return mtk_eint_do_init(hw->eint); in mtk_build_eint()
407 devm_kfree(hw->dev, hw->eint); in mtk_build_eint()
408 hw->eint = NULL; in mtk_build_eint()
448 return -EINVAL; in mtk_pinconf_bias_disable_get()
457 const struct mtk_pin_desc *desc, bool pullup) in mtk_pinconf_bias_set() argument
461 arg = pullup ? 1 : 2; in mtk_pinconf_bias_set()
477 const struct mtk_pin_desc *desc, bool pullup, int *res) in mtk_pinconf_bias_get() argument
481 reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD; in mtk_pinconf_bias_get()
488 return -EINVAL; in mtk_pinconf_bias_get()
515 return -EINVAL; in mtk_pinconf_bias_disable_get_rev1()
524 const struct mtk_pin_desc *desc, bool pullup) in mtk_pinconf_bias_set_rev1() argument
528 arg = pullup ? MTK_PULLUP : MTK_PULLDOWN; in mtk_pinconf_bias_set_rev1()
544 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_bias_get_rev1() argument
554 return -EINVAL; in mtk_pinconf_bias_get_rev1()
560 if (pullup ^ (v == MTK_PULLUP)) in mtk_pinconf_bias_get_rev1()
561 return -EINVAL; in mtk_pinconf_bias_get_rev1()
576 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pu_pd() argument
583 } else if ((arg == MTK_ENABLE) && pullup) { in mtk_pinconf_bias_set_pu_pd()
586 } else if ((arg == MTK_ENABLE) && !pullup) { in mtk_pinconf_bias_set_pu_pd()
590 err = -EINVAL; in mtk_pinconf_bias_set_pu_pd()
606 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pullsel_pullen() argument
615 err = -EINVAL; in mtk_pinconf_bias_set_pullsel_pullen()
623 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_set_pullsel_pullen()
631 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pupd_r1_r0() argument
636 pullup = 0; in mtk_pinconf_bias_set_pupd_r1_r0()
649 err = -EINVAL; in mtk_pinconf_bias_set_pupd_r1_r0()
653 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_set_pupd_r1_r0()
654 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup); in mtk_pinconf_bias_set_pupd_r1_r0()
670 u32 pullup, u32 arg, u32 *rsel_val) in mtk_hw_pin_rsel_lookup() argument
676 rsel = hw->soc->pin_rsel; in mtk_hw_pin_rsel_lookup()
678 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_hw_pin_rsel_lookup()
679 if (desc->number >= rsel[check].s_pin && in mtk_hw_pin_rsel_lookup()
680 desc->number <= rsel[check].e_pin) { in mtk_hw_pin_rsel_lookup()
681 if (pullup) { in mtk_hw_pin_rsel_lookup()
698 dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n", in mtk_hw_pin_rsel_lookup()
699 arg, desc->number, desc->name); in mtk_hw_pin_rsel_lookup()
700 return -ENOTSUPP; in mtk_hw_pin_rsel_lookup()
708 u32 pullup, u32 arg) in mtk_pinconf_bias_set_rsel() argument
712 if (!pullup && arg == MTK_DISABLE) in mtk_pinconf_bias_set_rsel()
715 if (hw->rsel_si_unit) { in mtk_pinconf_bias_set_rsel()
717 err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val); in mtk_pinconf_bias_set_rsel()
723 err = -EINVAL; in mtk_pinconf_bias_set_rsel()
727 rsel_val = arg - MTK_PULL_SET_RSEL_000; in mtk_pinconf_bias_set_rsel()
734 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, MTK_ENABLE); in mtk_pinconf_bias_set_rsel()
742 u32 pullup, u32 arg) in mtk_pinconf_bias_set_combo() argument
744 int err = -ENOTSUPP; in mtk_pinconf_bias_set_combo()
747 if (hw->soc->pull_type) in mtk_pinconf_bias_set_combo()
748 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_set_combo()
753 err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
759 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
766 pullup, arg); in mtk_pinconf_bias_set_combo()
772 err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
775 dev_err(hw->dev, "Invalid pull argument\n"); in mtk_pinconf_bias_set_combo()
783 u32 pullup, u32 rsel_val, u32 *si_unit) in mtk_rsel_get_si_unit() argument
788 rsel = hw->soc->pin_rsel; in mtk_rsel_get_si_unit()
790 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_rsel_get_si_unit()
791 if (desc->number >= rsel[check].s_pin && in mtk_rsel_get_si_unit()
792 desc->number <= rsel[check].e_pin) { in mtk_rsel_get_si_unit()
794 if (pullup) in mtk_rsel_get_si_unit()
808 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_rsel() argument
825 *pullup = 0; in mtk_pinconf_bias_get_rsel()
828 *pullup = 1; in mtk_pinconf_bias_get_rsel()
829 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_rsel()
830 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_rsel()
834 *pullup = 0; in mtk_pinconf_bias_get_rsel()
835 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_rsel()
836 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_rsel()
840 err = -EINVAL; in mtk_pinconf_bias_get_rsel()
850 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd() argument
863 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
866 *pullup = 1; in mtk_pinconf_bias_get_pu_pd()
869 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
872 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd()
880 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pullsel_pullen() argument
884 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_get_pullsel_pullen()
896 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pupd_r1_r0() argument
900 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
903 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_get_pupd_r1_r0()
904 *pullup = !(*pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
923 err = -EINVAL; in mtk_pinconf_bias_get_pupd_r1_r0()
931 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_combo() argument
933 int err = -ENOTSUPP; in mtk_pinconf_bias_get_combo()
936 if (hw->soc->pull_type) in mtk_pinconf_bias_get_combo()
937 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_get_combo()
942 err = mtk_pinconf_bias_get_rsel(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
948 err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
955 pullup, enable); in mtk_pinconf_bias_get_combo()
961 err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
972 int err = -ENOTSUPP; in mtk_pinconf_drive_set()
974 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set()
980 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set()
981 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set()
1003 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get()
1016 *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get()
1027 int err = -ENOTSUPP; in mtk_pinconf_drive_set_rev1()
1029 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set_rev1()
1031 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set_rev1()
1032 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set_rev1()
1050 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get_rev1()
1056 *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get_rev1()
1077 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_set() argument
1096 arg = pullup ? 0 : 1; in mtk_pinconf_adv_pull_set()
1103 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_set()
1104 if (hw->soc->bias_set) { in mtk_pinconf_adv_pull_set()
1105 err = hw->soc->bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1109 err = mtk_pinconf_bias_set_rev1(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1111 err = mtk_pinconf_bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1120 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_get() argument
1131 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_get()
1132 if (hw->soc->bias_get) { in mtk_pinconf_adv_pull_get()
1133 err = hw->soc->bias_get(hw, desc, pullup, val); in mtk_pinconf_adv_pull_get()
1137 return -ENOTSUPP; in mtk_pinconf_adv_pull_get()
1140 /* t == 0 supposes PULLUP for the customized PULL setup */ in mtk_pinconf_adv_pull_get()
1144 if (pullup ^ !t) in mtk_pinconf_adv_pull_get()
1145 return -EINVAL; in mtk_pinconf_adv_pull_get()