Lines Matching +full:pd +full:- +full:revision
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()
384 if (count_reg_names < hw->soc->nbase_names) in mtk_build_eint()
385 return -EINVAL; in mtk_build_eint()
387 hw->eint->nbase = count_reg_names - hw->soc->nbase_names; in mtk_build_eint()
388 hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase, in mtk_build_eint()
389 sizeof(*hw->eint->base), GFP_KERNEL | __GFP_ZERO); in mtk_build_eint()
390 if (!hw->eint->base) { in mtk_build_eint()
391 ret = -ENOMEM; in mtk_build_eint()
395 for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) { in mtk_build_eint()
396 hw->eint->base[j] = of_iomap(np, i); in mtk_build_eint()
397 if (IS_ERR(hw->eint->base[j])) { in mtk_build_eint()
398 ret = PTR_ERR(hw->eint->base[j]); in mtk_build_eint()
403 hw->eint->irq = irq_of_parse_and_map(np, 0); in mtk_build_eint()
404 if (!hw->eint->irq) { in mtk_build_eint()
405 ret = -EINVAL; in mtk_build_eint()
409 if (!hw->soc->eint_hw) { in mtk_build_eint()
410 ret = -ENODEV; in mtk_build_eint()
414 hw->eint->dev = &pdev->dev; in mtk_build_eint()
415 hw->eint->hw = hw->soc->eint_hw; in mtk_build_eint()
416 hw->eint->pctl = hw; in mtk_build_eint()
417 hw->eint->gpio_xlate = &mtk_eint_xt; in mtk_build_eint()
419 ret = mtk_eint_do_init(hw->eint); in mtk_build_eint()
426 for (j = 0; j < hw->eint->nbase; j++) { in mtk_build_eint()
427 if (hw->eint->base[j]) in mtk_build_eint()
428 iounmap(hw->eint->base[j]); in mtk_build_eint()
430 devm_kfree(hw->dev, hw->eint->base); in mtk_build_eint()
432 devm_kfree(hw->dev, hw->eint); in mtk_build_eint()
433 hw->eint = NULL; in mtk_build_eint()
438 /* Revision 0 */
473 return -EINVAL; in mtk_pinconf_bias_disable_get()
513 return -EINVAL; in mtk_pinconf_bias_get()
521 /* Revision 1 */
540 return -EINVAL; in mtk_pinconf_bias_disable_get_rev1()
579 return -EINVAL; in mtk_pinconf_bias_get_rev1()
586 return -EINVAL; in mtk_pinconf_bias_get_rev1()
595 * 1. PU + PD
603 int err, pu, pd; in mtk_pinconf_bias_set_pu_pd() local
607 pd = 0; in mtk_pinconf_bias_set_pu_pd()
610 pd = 0; in mtk_pinconf_bias_set_pu_pd()
613 pd = 1; in mtk_pinconf_bias_set_pu_pd()
615 return -EINVAL; in mtk_pinconf_bias_set_pu_pd()
624 return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); in mtk_pinconf_bias_set_pu_pd()
638 err = -EINVAL; in mtk_pinconf_bias_set_pullsel_pullen()
672 err = -EINVAL; in mtk_pinconf_bias_set_pupd_r1_r0()
676 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_set_pupd_r1_r0()
699 rsel = hw->soc->pin_rsel; in mtk_hw_pin_rsel_lookup()
701 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_hw_pin_rsel_lookup()
702 if (desc->number >= rsel[check].s_pin && in mtk_hw_pin_rsel_lookup()
703 desc->number <= rsel[check].e_pin) { in mtk_hw_pin_rsel_lookup()
721 dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n", in mtk_hw_pin_rsel_lookup()
722 arg, desc->number, desc->name); in mtk_hw_pin_rsel_lookup()
723 return -ENOTSUPP; in mtk_hw_pin_rsel_lookup()
735 if (hw->rsel_si_unit) { in mtk_pinconf_bias_set_rsel()
742 return -EINVAL; in mtk_pinconf_bias_set_rsel()
744 rsel_val = arg - MTK_PULL_SET_RSEL_000; in mtk_pinconf_bias_set_rsel()
770 int err = -ENOTSUPP; in mtk_pinconf_bias_set_combo()
773 if (hw->soc->pull_type) in mtk_pinconf_bias_set_combo()
774 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_set_combo()
807 dev_err(hw->dev, "Invalid pull argument\n"); in mtk_pinconf_bias_set_combo()
820 rsel = hw->soc->pin_rsel; in mtk_rsel_get_si_unit()
822 for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { in mtk_rsel_get_si_unit()
823 if (desc->number >= rsel[check].s_pin && in mtk_rsel_get_si_unit()
824 desc->number <= rsel[check].e_pin) { in mtk_rsel_get_si_unit()
842 int pu, pd, rsel, err; in mtk_pinconf_bias_get_pu_pd_rsel() local
852 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); in mtk_pinconf_bias_get_pu_pd_rsel()
856 if (pu == 0 && pd == 0) { in mtk_pinconf_bias_get_pu_pd_rsel()
859 } else if (pu == 1 && pd == 0) { in mtk_pinconf_bias_get_pu_pd_rsel()
861 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
865 } else if (pu == 0 && pd == 1) { in mtk_pinconf_bias_get_pu_pd_rsel()
867 if (hw->rsel_si_unit) in mtk_pinconf_bias_get_pu_pd_rsel()
872 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd_rsel()
884 int err, pu, pd; in mtk_pinconf_bias_get_pu_pd() local
890 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); in mtk_pinconf_bias_get_pu_pd()
894 if (pu == 0 && pd == 0) { in mtk_pinconf_bias_get_pu_pd()
897 } else if (pu == 1 && pd == 0) { in mtk_pinconf_bias_get_pu_pd()
900 } else if (pu == 0 && pd == 1) { in mtk_pinconf_bias_get_pu_pd()
904 err = -EINVAL; in mtk_pinconf_bias_get_pu_pd()
914 int err, pd; in mtk_pinconf_bias_get_pd() local
916 err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); in mtk_pinconf_bias_get_pd()
920 if (pd == 0) { in mtk_pinconf_bias_get_pd()
923 } else if (pd == 1) { in mtk_pinconf_bias_get_pd()
927 err = -EINVAL; in mtk_pinconf_bias_get_pd()
958 /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ in mtk_pinconf_bias_get_pupd_r1_r0()
978 err = -EINVAL; in mtk_pinconf_bias_get_pupd_r1_r0()
988 int err = -ENOTSUPP; in mtk_pinconf_bias_get_combo()
991 if (hw->soc->pull_type) in mtk_pinconf_bias_get_combo()
992 try_all_type = hw->soc->pull_type[desc->number]; in mtk_pinconf_bias_get_combo()
1028 /* Revision 0 */
1033 int err = -ENOTSUPP; in mtk_pinconf_drive_set()
1035 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set()
1041 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set()
1042 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set()
1064 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get()
1077 *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get()
1083 /* Revision 1 */
1088 int err = -ENOTSUPP; in mtk_pinconf_drive_set_rev1()
1090 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_set_rev1()
1092 if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { in mtk_pinconf_drive_set_rev1()
1093 arg = (arg / tb->step - 1) * tb->scal; in mtk_pinconf_drive_set_rev1()
1111 tb = &mtk_drive[desc->drv_n]; in mtk_pinconf_drive_get_rev1()
1117 *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; in mtk_pinconf_drive_get_rev1()
1164 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_set()
1165 if (hw->soc->bias_set) { in mtk_pinconf_adv_pull_set()
1166 err = hw->soc->bias_set(hw, desc, pullup); in mtk_pinconf_adv_pull_set()
1192 if (err == -ENOTSUPP) { in mtk_pinconf_adv_pull_get()
1193 if (hw->soc->bias_get) { in mtk_pinconf_adv_pull_get()
1194 err = hw->soc->bias_get(hw, desc, pullup, val); in mtk_pinconf_adv_pull_get()
1198 return -ENOTSUPP; in mtk_pinconf_adv_pull_get()
1206 return -EINVAL; in mtk_pinconf_adv_pull_get()