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, bool pd_only) 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 return -EINVAL; in mtk_pinconf_bias_set_pu_pd()
604 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pullsel_pullen() argument
613 err = -EINVAL; in mtk_pinconf_bias_set_pullsel_pullen()
621 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_set_pullsel_pullen()
629 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pupd_r1_r0() argument
634 pullup = 0; in mtk_pinconf_bias_set_pupd_r1_r0()
647 err = -EINVAL; in mtk_pinconf_bias_set_pupd_r1_r0()
651 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_set_pupd_r1_r0()
652 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup); in mtk_pinconf_bias_set_pupd_r1_r0()
668 u32 pullup, u32 arg, u32 *rsel_val) in mtk_hw_pin_rsel_lookup() argument
674 rsel = hw->soc->pin_rsel; in mtk_hw_pin_rsel_lookup()
676 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_hw_pin_rsel_lookup()
677 if (desc->number >= rsel[check].s_pin && in mtk_hw_pin_rsel_lookup()
678 desc->number <= rsel[check].e_pin) { in mtk_hw_pin_rsel_lookup()
679 if (pullup) { in mtk_hw_pin_rsel_lookup()
696 dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n", in mtk_hw_pin_rsel_lookup()
697 arg, desc->number, desc->name); in mtk_hw_pin_rsel_lookup()
698 return -ENOTSUPP; in mtk_hw_pin_rsel_lookup()
706 u32 pullup, u32 arg) in mtk_pinconf_bias_set_rsel() argument
710 if (hw->rsel_si_unit) { in mtk_pinconf_bias_set_rsel()
712 err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val); in mtk_pinconf_bias_set_rsel()
717 return -EINVAL; in mtk_pinconf_bias_set_rsel()
719 rsel_val = arg - MTK_PULL_SET_RSEL_000; in mtk_pinconf_bias_set_rsel()
727 u32 pullup, u32 arg) in mtk_pinconf_bias_set_pu_pd_rsel() argument
733 err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_pu_pd_rsel()
738 return mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, enable, false); in mtk_pinconf_bias_set_pu_pd_rsel()
743 u32 pullup, u32 arg) in mtk_pinconf_bias_set_combo() argument
745 int err = -ENOTSUPP; in mtk_pinconf_bias_set_combo()
748 if (hw->soc->pull_type) in mtk_pinconf_bias_set_combo()
749 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_set_combo()
754 err = mtk_pinconf_bias_set_pu_pd_rsel(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
760 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, true); in mtk_pinconf_bias_set_combo()
766 err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg, false); in mtk_pinconf_bias_set_combo()
773 pullup, arg); in mtk_pinconf_bias_set_combo()
779 err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); in mtk_pinconf_bias_set_combo()
782 dev_err(hw->dev, "Invalid pull argument\n"); in mtk_pinconf_bias_set_combo()
790 u32 pullup, u32 rsel_val, u32 *si_unit) in mtk_rsel_get_si_unit() argument
795 rsel = hw->soc->pin_rsel; in mtk_rsel_get_si_unit()
797 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_rsel_get_si_unit()
798 if (desc->number >= rsel[check].s_pin && in mtk_rsel_get_si_unit()
799 desc->number <= rsel[check].e_pin) { in mtk_rsel_get_si_unit()
801 if (pullup) in mtk_rsel_get_si_unit()
815 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd_rsel() argument
832 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
835 *pullup = 1; in mtk_pinconf_bias_get_pu_pd_rsel()
836 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
837 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
841 *pullup = 0; in mtk_pinconf_bias_get_pu_pd_rsel()
842 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
843 mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); in mtk_pinconf_bias_get_pu_pd_rsel()
847 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd_rsel()
857 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pu_pd() argument
870 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
873 *pullup = 1; in mtk_pinconf_bias_get_pu_pd()
876 *pullup = 0; in mtk_pinconf_bias_get_pu_pd()
879 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd()
887 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pd() argument
896 *pullup = 0; in mtk_pinconf_bias_get_pd()
899 *pullup = 0; in mtk_pinconf_bias_get_pd()
902 err = -EINVAL; in mtk_pinconf_bias_get_pd()
910 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pullsel_pullen() argument
914 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); in mtk_pinconf_bias_get_pullsel_pullen()
926 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_pupd_r1_r0() argument
930 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
933 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_get_pupd_r1_r0()
934 *pullup = !(*pullup); in mtk_pinconf_bias_get_pupd_r1_r0()
953 err = -EINVAL; in mtk_pinconf_bias_get_pupd_r1_r0()
961 u32 *pullup, u32 *enable) in mtk_pinconf_bias_get_combo() argument
963 int err = -ENOTSUPP; in mtk_pinconf_bias_get_combo()
966 if (hw->soc->pull_type) in mtk_pinconf_bias_get_combo()
967 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_get_combo()
972 err = mtk_pinconf_bias_get_pu_pd_rsel(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
978 err = mtk_pinconf_bias_get_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
984 err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
991 pullup, enable); in mtk_pinconf_bias_get_combo()
997 err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); in mtk_pinconf_bias_get_combo()
1008 int err = -ENOTSUPP; in mtk_pinconf_drive_set()
1010 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set()
1016 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set()
1017 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set()
1039 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get()
1052 *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get()
1063 int err = -ENOTSUPP; in mtk_pinconf_drive_set_rev1()
1065 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set_rev1()
1067 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set_rev1()
1068 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set_rev1()
1086 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get_rev1()
1092 *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get_rev1()
1113 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_set() argument
1132 arg = pullup ? 0 : 1; in mtk_pinconf_adv_pull_set()
1137 * general bias control. in mtk_pinconf_adv_pull_set()
1139 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_set()
1140 if (hw->soc->bias_set) { in mtk_pinconf_adv_pull_set()
1141 err = hw->soc->bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1145 err = mtk_pinconf_bias_set_rev1(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1147 err = mtk_pinconf_bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1156 const struct mtk_pin_desc *desc, bool pullup, in mtk_pinconf_adv_pull_get() argument
1165 * general bias control. in mtk_pinconf_adv_pull_get()
1167 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_get()
1168 if (hw->soc->bias_get) { in mtk_pinconf_adv_pull_get()
1169 err = hw->soc->bias_get(hw, desc, pullup, val); in mtk_pinconf_adv_pull_get()
1173 return -ENOTSUPP; in mtk_pinconf_adv_pull_get()
1176 /* t == 0 supposes PULLUP for the customized PULL setup */ in mtk_pinconf_adv_pull_get()
1180 if (pullup ^ !t) in mtk_pinconf_adv_pull_get()
1181 return -EINVAL; in mtk_pinconf_adv_pull_get()