Lines Matching +full:bias +full:- +full:pullup

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 (hw->rsel_si_unit) { in mtk_pinconf_bias_set_rsel()
714 err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val); in mtk_pinconf_bias_set_rsel()
719 return -EINVAL; in mtk_pinconf_bias_set_rsel()
721 rsel_val = arg - MTK_PULL_SET_RSEL_000; in mtk_pinconf_bias_set_rsel()
729 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pu_pd_rsel() argument
735 err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_pu_pd_rsel()
740 return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_set_pu_pd_rsel()
745 u32 pullup, u32 arg) in mtk_pinconf_bias_set_combo() argument
747 int err = -ENOTSUPP; in mtk_pinconf_bias_set_combo()
750 if (hw->soc->pull_type) in mtk_pinconf_bias_set_combo()
751 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_set_combo()
756 err = mtk_pinconf_bias_set_pu_pd_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
762 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
769 pullup, arg); in mtk_pinconf_bias_set_combo()
775 err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
778 dev_err(hw->dev, "Invalid pull argument\n"); in mtk_pinconf_bias_set_combo()
786 u32 pullup, u32 rsel_val, u32 *si_unit) in mtk_rsel_get_si_unit() argument
791 rsel = hw->soc->pin_rsel; in mtk_rsel_get_si_unit()
793 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_rsel_get_si_unit()
794 if (desc->number >= rsel[check].s_pin && in mtk_rsel_get_si_unit()
795 desc->number <= rsel[check].e_pin) { in mtk_rsel_get_si_unit()
797 if (pullup) in mtk_rsel_get_si_unit()
811 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd_rsel() argument
828 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
831 *pullup = 1; in mtk_pinconf_bias_get_pu_pd_rsel()
832 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
833 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
837 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
838 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
839 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
843 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd_rsel()
853 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd() argument
866 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
869 *pullup = 1; in mtk_pinconf_bias_get_pu_pd()
872 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
875 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd()
883 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pullsel_pullen() argument
887 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_get_pullsel_pullen()
899 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pupd_r1_r0() argument
903 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
906 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_get_pupd_r1_r0()
907 *pullup = !(*pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
926 err = -EINVAL; in mtk_pinconf_bias_get_pupd_r1_r0()
934 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_combo() argument
936 int err = -ENOTSUPP; in mtk_pinconf_bias_get_combo()
939 if (hw->soc->pull_type) in mtk_pinconf_bias_get_combo()
940 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_get_combo()
945 err = mtk_pinconf_bias_get_pu_pd_rsel(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
951 err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
958 pullup, enable); in mtk_pinconf_bias_get_combo()
964 err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
975 int err = -ENOTSUPP; in mtk_pinconf_drive_set()
977 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set()
983 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set()
984 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set()
1006 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get()
1019 *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get()
1030 int err = -ENOTSUPP; in mtk_pinconf_drive_set_rev1()
1032 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set_rev1()
1034 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set_rev1()
1035 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set_rev1()
1053 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get_rev1()
1059 *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get_rev1()
1080 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_set() argument
1099 arg = pullup ? 0 : 1; in mtk_pinconf_adv_pull_set()
1104 * general bias control. in mtk_pinconf_adv_pull_set()
1106 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_set()
1107 if (hw->soc->bias_set) { in mtk_pinconf_adv_pull_set()
1108 err = hw->soc->bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1112 err = mtk_pinconf_bias_set_rev1(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1114 err = mtk_pinconf_bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1123 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_get() argument
1132 * general bias control. in mtk_pinconf_adv_pull_get()
1134 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_get()
1135 if (hw->soc->bias_get) { in mtk_pinconf_adv_pull_get()
1136 err = hw->soc->bias_get(hw, desc, pullup, val); in mtk_pinconf_adv_pull_get()
1140 return -ENOTSUPP; in mtk_pinconf_adv_pull_get()
1143 /* t == 0 supposes PULLUP for the customized PULL setup */ in mtk_pinconf_adv_pull_get()
1147 if (pullup ^ !t) in mtk_pinconf_adv_pull_get()
1148 return -EINVAL; in mtk_pinconf_adv_pull_get()