1a1a503a8SSean Wang // SPDX-License-Identifier: GPL-2.0 2a1a503a8SSean Wang /* 3a1a503a8SSean Wang * Copyright (C) 2018 MediaTek Inc. 4a1a503a8SSean Wang * 5a1a503a8SSean Wang * Author: Sean Wang <sean.wang@mediatek.com> 6a1a503a8SSean Wang * 7a1a503a8SSean Wang */ 8a1a503a8SSean Wang 9cafe19dbSLight Hsieh #include <dt-bindings/pinctrl/mt65xx.h> 10a1a503a8SSean Wang #include <linux/device.h> 11a1a503a8SSean Wang #include <linux/err.h> 1222d7fe49SLinus Walleij #include <linux/gpio/driver.h> 1389132dd8SSean Wang #include <linux/platform_device.h> 14a1a503a8SSean Wang #include <linux/io.h> 158174a851SLight Hsieh #include <linux/module.h> 1689132dd8SSean Wang #include <linux/of_irq.h> 17a1a503a8SSean Wang 1889132dd8SSean Wang #include "mtk-eint.h" 19a1a503a8SSean Wang #include "pinctrl-mtk-common-v2.h" 20a1a503a8SSean Wang 21c2832197SSean Wang /** 22c2832197SSean Wang * struct mtk_drive_desc - the structure that holds the information 23c2832197SSean Wang * of the driving current 24c2832197SSean Wang * @min: the minimum current of this group 25c2832197SSean Wang * @max: the maximum current of this group 26c2832197SSean Wang * @step: the step current of this group 27c2832197SSean Wang * @scal: the weight factor 28c2832197SSean Wang * 29c2832197SSean Wang * formula: output = ((input) / step - 1) * scal 30c2832197SSean Wang */ 31c2832197SSean Wang struct mtk_drive_desc { 32c2832197SSean Wang u8 min; 33c2832197SSean Wang u8 max; 34c2832197SSean Wang u8 step; 35c2832197SSean Wang u8 scal; 36c2832197SSean Wang }; 37c2832197SSean Wang 38c2832197SSean Wang /* The groups of drive strength */ 3907c6b037SWei Yongjun static const struct mtk_drive_desc mtk_drive[] = { 40c2832197SSean Wang [DRV_GRP0] = { 4, 16, 4, 1 }, 41c2832197SSean Wang [DRV_GRP1] = { 4, 16, 4, 2 }, 42c2832197SSean Wang [DRV_GRP2] = { 2, 8, 2, 1 }, 43c2832197SSean Wang [DRV_GRP3] = { 2, 8, 2, 2 }, 44c2832197SSean Wang [DRV_GRP4] = { 2, 16, 2, 1 }, 45c2832197SSean Wang }; 46c2832197SSean Wang 472bc47dfeSSean Wang static void mtk_w32(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 val) 48a1a503a8SSean Wang { 492bc47dfeSSean Wang writel_relaxed(val, pctl->base[i] + reg); 50a1a503a8SSean Wang } 51a1a503a8SSean Wang 522bc47dfeSSean Wang static u32 mtk_r32(struct mtk_pinctrl *pctl, u8 i, u32 reg) 53a1a503a8SSean Wang { 542bc47dfeSSean Wang return readl_relaxed(pctl->base[i] + reg); 55a1a503a8SSean Wang } 56a1a503a8SSean Wang 572bc47dfeSSean Wang void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set) 58a1a503a8SSean Wang { 59a1a503a8SSean Wang u32 val; 6056ab29ecSTzung-Bi Shih unsigned long flags; 61a1a503a8SSean Wang 6256ab29ecSTzung-Bi Shih spin_lock_irqsave(&pctl->lock, flags); 6342a46434SZhiyong Tao 642bc47dfeSSean Wang val = mtk_r32(pctl, i, reg); 65a1a503a8SSean Wang val &= ~mask; 66a1a503a8SSean Wang val |= set; 672bc47dfeSSean Wang mtk_w32(pctl, i, reg, val); 6842a46434SZhiyong Tao 6956ab29ecSTzung-Bi Shih spin_unlock_irqrestore(&pctl->lock, flags); 70a1a503a8SSean Wang } 71a1a503a8SSean Wang 72ea051eb3SSean Wang static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, 73ea051eb3SSean Wang const struct mtk_pin_desc *desc, 749d9b171cSSean Wang int field, struct mtk_pin_field *pfd) 75a1a503a8SSean Wang { 7686ecb7d6SYueHaibing const struct mtk_pin_field_calc *c; 779d9b171cSSean Wang const struct mtk_pin_reg_calc *rc; 783de7deefSLight Hsieh int start = 0, end, check; 793de7deefSLight Hsieh bool found = false; 80a1a503a8SSean Wang u32 bits; 81a1a503a8SSean Wang 829d9b171cSSean Wang if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) { 839d9b171cSSean Wang rc = &hw->soc->reg_cal[field]; 849d9b171cSSean Wang } else { 859d9b171cSSean Wang dev_dbg(hw->dev, 863de7deefSLight Hsieh "Not support field %d for this soc\n", field); 879d9b171cSSean Wang return -ENOTSUPP; 889d9b171cSSean Wang } 899d9b171cSSean Wang 903de7deefSLight Hsieh end = rc->nranges - 1; 91a1a503a8SSean Wang 923de7deefSLight Hsieh while (start <= end) { 933de7deefSLight Hsieh check = (start + end) >> 1; 943de7deefSLight Hsieh if (desc->number >= rc->range[check].s_pin 953de7deefSLight Hsieh && desc->number <= rc->range[check].e_pin) { 963de7deefSLight Hsieh found = true; 97a1a503a8SSean Wang break; 983de7deefSLight Hsieh } else if (start == end) 993de7deefSLight Hsieh break; 1003de7deefSLight Hsieh else if (desc->number < rc->range[check].s_pin) 1013de7deefSLight Hsieh end = check - 1; 1023de7deefSLight Hsieh else 1033de7deefSLight Hsieh start = check + 1; 104a1a503a8SSean Wang } 105a1a503a8SSean Wang 1063de7deefSLight Hsieh if (!found) { 1079d9b171cSSean Wang dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n", 1089d9b171cSSean Wang field, desc->number, desc->name); 1099d9b171cSSean Wang return -ENOTSUPP; 110a1a503a8SSean Wang } 111a1a503a8SSean Wang 1123de7deefSLight Hsieh c = rc->range + check; 1133de7deefSLight Hsieh 1142bc47dfeSSean Wang if (c->i_base > hw->nbase - 1) { 1159d9b171cSSean Wang dev_err(hw->dev, 1169d9b171cSSean Wang "Invalid base for field %d for pin = %d (%s)\n", 1179d9b171cSSean Wang field, desc->number, desc->name); 1182bc47dfeSSean Wang return -EINVAL; 1192bc47dfeSSean Wang } 1202bc47dfeSSean Wang 121b906faf7SSean Wang /* Calculated bits as the overall offset the pin is located at, 122b906faf7SSean Wang * if c->fixed is held, that determines the all the pins in the 123b906faf7SSean Wang * range use the same field with the s_pin. 124b906faf7SSean Wang */ 125ea051eb3SSean Wang bits = c->fixed ? c->s_bit : c->s_bit + 126ea051eb3SSean Wang (desc->number - c->s_pin) * (c->x_bits); 127a1a503a8SSean Wang 128b906faf7SSean Wang /* Fill pfd from bits. For example 32-bit register applied is assumed 129b906faf7SSean Wang * when c->sz_reg is equal to 32. 130b906faf7SSean Wang */ 1312bc47dfeSSean Wang pfd->index = c->i_base; 132b906faf7SSean Wang pfd->offset = c->s_addr + c->x_addrs * (bits / c->sz_reg); 133b906faf7SSean Wang pfd->bitpos = bits % c->sz_reg; 134a1a503a8SSean Wang pfd->mask = (1 << c->x_bits) - 1; 135a1a503a8SSean Wang 136a1a503a8SSean Wang /* pfd->next is used for indicating that bit wrapping-around happens 137a1a503a8SSean Wang * which requires the manipulation for bit 0 starting in the next 138a1a503a8SSean Wang * register to form the complete field read/write. 139a1a503a8SSean Wang */ 140b906faf7SSean Wang pfd->next = pfd->bitpos + c->x_bits > c->sz_reg ? c->x_addrs : 0; 141a1a503a8SSean Wang 142a1a503a8SSean Wang return 0; 143a1a503a8SSean Wang } 144a1a503a8SSean Wang 145ea051eb3SSean Wang static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, 146ea051eb3SSean Wang const struct mtk_pin_desc *desc, 147a1a503a8SSean Wang int field, struct mtk_pin_field *pfd) 148a1a503a8SSean Wang { 149a1a503a8SSean Wang if (field < 0 || field >= PINCTRL_PIN_REG_MAX) { 150a1a503a8SSean Wang dev_err(hw->dev, "Invalid Field %d\n", field); 151a1a503a8SSean Wang return -EINVAL; 152a1a503a8SSean Wang } 153a1a503a8SSean Wang 1549d9b171cSSean Wang return mtk_hw_pin_field_lookup(hw, desc, field, pfd); 155a1a503a8SSean Wang } 156a1a503a8SSean Wang 157a1a503a8SSean Wang static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l) 158a1a503a8SSean Wang { 159a1a503a8SSean Wang *l = 32 - pf->bitpos; 160a1a503a8SSean Wang *h = get_count_order(pf->mask) - *l; 161a1a503a8SSean Wang } 162a1a503a8SSean Wang 163a1a503a8SSean Wang static void mtk_hw_write_cross_field(struct mtk_pinctrl *hw, 164a1a503a8SSean Wang struct mtk_pin_field *pf, int value) 165a1a503a8SSean Wang { 166a1a503a8SSean Wang int nbits_l, nbits_h; 167a1a503a8SSean Wang 168a1a503a8SSean Wang mtk_hw_bits_part(pf, &nbits_h, &nbits_l); 169a1a503a8SSean Wang 1702bc47dfeSSean Wang mtk_rmw(hw, pf->index, pf->offset, pf->mask << pf->bitpos, 171a1a503a8SSean Wang (value & pf->mask) << pf->bitpos); 172a1a503a8SSean Wang 1732bc47dfeSSean Wang mtk_rmw(hw, pf->index, pf->offset + pf->next, BIT(nbits_h) - 1, 174a1a503a8SSean Wang (value & pf->mask) >> nbits_l); 175a1a503a8SSean Wang } 176a1a503a8SSean Wang 177a1a503a8SSean Wang static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw, 178a1a503a8SSean Wang struct mtk_pin_field *pf, int *value) 179a1a503a8SSean Wang { 180a1a503a8SSean Wang int nbits_l, nbits_h, h, l; 181a1a503a8SSean Wang 182a1a503a8SSean Wang mtk_hw_bits_part(pf, &nbits_h, &nbits_l); 183a1a503a8SSean Wang 1842bc47dfeSSean Wang l = (mtk_r32(hw, pf->index, pf->offset) 1852bc47dfeSSean Wang >> pf->bitpos) & (BIT(nbits_l) - 1); 1862bc47dfeSSean Wang h = (mtk_r32(hw, pf->index, pf->offset + pf->next)) 1872bc47dfeSSean Wang & (BIT(nbits_h) - 1); 188a1a503a8SSean Wang 189a1a503a8SSean Wang *value = (h << nbits_l) | l; 190a1a503a8SSean Wang } 191a1a503a8SSean Wang 192ea051eb3SSean Wang int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc, 193ea051eb3SSean Wang int field, int value) 194a1a503a8SSean Wang { 195a1a503a8SSean Wang struct mtk_pin_field pf; 196a1a503a8SSean Wang int err; 197a1a503a8SSean Wang 198ea051eb3SSean Wang err = mtk_hw_pin_field_get(hw, desc, field, &pf); 199a1a503a8SSean Wang if (err) 200a1a503a8SSean Wang return err; 201a1a503a8SSean Wang 2023de7deefSLight Hsieh if (value < 0 || value > pf.mask) 2033de7deefSLight Hsieh return -EINVAL; 2043de7deefSLight Hsieh 205a1a503a8SSean Wang if (!pf.next) 2062bc47dfeSSean Wang mtk_rmw(hw, pf.index, pf.offset, pf.mask << pf.bitpos, 207a1a503a8SSean Wang (value & pf.mask) << pf.bitpos); 208a1a503a8SSean Wang else 209a1a503a8SSean Wang mtk_hw_write_cross_field(hw, &pf, value); 210a1a503a8SSean Wang 211a1a503a8SSean Wang return 0; 212a1a503a8SSean Wang } 2138174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_hw_set_value); 214a1a503a8SSean Wang 215ea051eb3SSean Wang int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc, 216ea051eb3SSean Wang int field, int *value) 217a1a503a8SSean Wang { 218a1a503a8SSean Wang struct mtk_pin_field pf; 219a1a503a8SSean Wang int err; 220a1a503a8SSean Wang 221ea051eb3SSean Wang err = mtk_hw_pin_field_get(hw, desc, field, &pf); 222a1a503a8SSean Wang if (err) 223a1a503a8SSean Wang return err; 224a1a503a8SSean Wang 225a1a503a8SSean Wang if (!pf.next) 2262bc47dfeSSean Wang *value = (mtk_r32(hw, pf.index, pf.offset) 2272bc47dfeSSean Wang >> pf.bitpos) & pf.mask; 228a1a503a8SSean Wang else 229a1a503a8SSean Wang mtk_hw_read_cross_field(hw, &pf, value); 230a1a503a8SSean Wang 231a1a503a8SSean Wang return 0; 232a1a503a8SSean Wang } 2338174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_hw_get_value); 234c2832197SSean Wang 23589132dd8SSean Wang static int mtk_xt_find_eint_num(struct mtk_pinctrl *hw, unsigned long eint_n) 23689132dd8SSean Wang { 23789132dd8SSean Wang const struct mtk_pin_desc *desc; 23889132dd8SSean Wang int i = 0; 23989132dd8SSean Wang 24089132dd8SSean Wang desc = (const struct mtk_pin_desc *)hw->soc->pins; 24189132dd8SSean Wang 24289132dd8SSean Wang while (i < hw->soc->npins) { 24389132dd8SSean Wang if (desc[i].eint.eint_n == eint_n) 24489132dd8SSean Wang return desc[i].number; 24589132dd8SSean Wang i++; 24689132dd8SSean Wang } 24789132dd8SSean Wang 24889132dd8SSean Wang return EINT_NA; 24989132dd8SSean Wang } 25089132dd8SSean Wang 251edd54646SHanks Chen /* 252edd54646SHanks Chen * Virtual GPIO only used inside SOC and not being exported to outside SOC. 253edd54646SHanks Chen * Some modules use virtual GPIO as eint (e.g. pmif or usb). 254edd54646SHanks Chen * In MTK platform, external interrupt (EINT) and GPIO is 1-1 mapping 255edd54646SHanks Chen * and we can set GPIO as eint. 256edd54646SHanks Chen * But some modules use specific eint which doesn't have real GPIO pin. 257edd54646SHanks Chen * So we use virtual GPIO to map it. 258edd54646SHanks Chen */ 259edd54646SHanks Chen 260edd54646SHanks Chen bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n) 261edd54646SHanks Chen { 262edd54646SHanks Chen const struct mtk_pin_desc *desc; 263edd54646SHanks Chen bool virt_gpio = false; 264edd54646SHanks Chen 265edd54646SHanks Chen desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; 266edd54646SHanks Chen 26739c4dbe4SHanks Chen /* if the GPIO is not supported for eint mode */ 26839c4dbe4SHanks Chen if (desc->eint.eint_m == NO_EINT_SUPPORT) 26939c4dbe4SHanks Chen return virt_gpio; 27039c4dbe4SHanks Chen 271edd54646SHanks Chen if (desc->funcs && !desc->funcs[desc->eint.eint_m].name) 272edd54646SHanks Chen virt_gpio = true; 273edd54646SHanks Chen 274edd54646SHanks Chen return virt_gpio; 275edd54646SHanks Chen } 276047cd9a6SRandy Dunlap EXPORT_SYMBOL_GPL(mtk_is_virt_gpio); 277edd54646SHanks Chen 27889132dd8SSean Wang static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n, 27989132dd8SSean Wang unsigned int *gpio_n, 28089132dd8SSean Wang struct gpio_chip **gpio_chip) 28189132dd8SSean Wang { 28289132dd8SSean Wang struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data; 28389132dd8SSean Wang const struct mtk_pin_desc *desc; 28489132dd8SSean Wang 28589132dd8SSean Wang desc = (const struct mtk_pin_desc *)hw->soc->pins; 28689132dd8SSean Wang *gpio_chip = &hw->chip; 28789132dd8SSean Wang 288*2d5446daSGuodong Liu /* 289*2d5446daSGuodong Liu * Be greedy to guess first gpio_n is equal to eint_n. 290*2d5446daSGuodong Liu * Only eint virtual eint number is greater than gpio number. 291*2d5446daSGuodong Liu */ 292*2d5446daSGuodong Liu if (hw->soc->npins > eint_n && 293*2d5446daSGuodong Liu desc[eint_n].eint.eint_n == eint_n) 29489132dd8SSean Wang *gpio_n = eint_n; 29589132dd8SSean Wang else 29689132dd8SSean Wang *gpio_n = mtk_xt_find_eint_num(hw, eint_n); 29789132dd8SSean Wang 29889132dd8SSean Wang return *gpio_n == EINT_NA ? -EINVAL : 0; 29989132dd8SSean Wang } 30089132dd8SSean Wang 30189132dd8SSean Wang static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n) 30289132dd8SSean Wang { 30389132dd8SSean Wang struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data; 30489132dd8SSean Wang const struct mtk_pin_desc *desc; 30589132dd8SSean Wang struct gpio_chip *gpio_chip; 30689132dd8SSean Wang unsigned int gpio_n; 30789132dd8SSean Wang int value, err; 30889132dd8SSean Wang 30989132dd8SSean Wang err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip); 31089132dd8SSean Wang if (err) 31189132dd8SSean Wang return err; 31289132dd8SSean Wang 31389132dd8SSean Wang desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; 31489132dd8SSean Wang 31589132dd8SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value); 31689132dd8SSean Wang if (err) 31789132dd8SSean Wang return err; 31889132dd8SSean Wang 31989132dd8SSean Wang return !!value; 32089132dd8SSean Wang } 32189132dd8SSean Wang 32289132dd8SSean Wang static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n) 32389132dd8SSean Wang { 32489132dd8SSean Wang struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data; 32589132dd8SSean Wang const struct mtk_pin_desc *desc; 32689132dd8SSean Wang struct gpio_chip *gpio_chip; 32789132dd8SSean Wang unsigned int gpio_n; 32889132dd8SSean Wang int err; 32989132dd8SSean Wang 33089132dd8SSean Wang err = mtk_xt_get_gpio_n(hw, eint_n, &gpio_n, &gpio_chip); 33189132dd8SSean Wang if (err) 33289132dd8SSean Wang return err; 33389132dd8SSean Wang 334edd54646SHanks Chen if (mtk_is_virt_gpio(hw, gpio_n)) 335edd54646SHanks Chen return 0; 336edd54646SHanks Chen 33789132dd8SSean Wang desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; 33889132dd8SSean Wang 33989132dd8SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, 34089132dd8SSean Wang desc->eint.eint_m); 34189132dd8SSean Wang if (err) 34289132dd8SSean Wang return err; 34389132dd8SSean Wang 34489132dd8SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT); 34589132dd8SSean Wang if (err) 34689132dd8SSean Wang return err; 34789132dd8SSean Wang 34889132dd8SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE); 3496e737a4eSchuanjia.liu /* SMT is supposed to be supported by every real GPIO and doesn't 3506e737a4eSchuanjia.liu * support virtual GPIOs, so the extra condition err != -ENOTSUPP 3516e737a4eSchuanjia.liu * is just for adding EINT support to these virtual GPIOs. It should 3526e737a4eSchuanjia.liu * add an extra flag in the pin descriptor when more pins with 3536e737a4eSchuanjia.liu * distinctive characteristic come out. 3546e737a4eSchuanjia.liu */ 3556e737a4eSchuanjia.liu if (err && err != -ENOTSUPP) 35689132dd8SSean Wang return err; 35789132dd8SSean Wang 35889132dd8SSean Wang return 0; 35989132dd8SSean Wang } 36089132dd8SSean Wang 36189132dd8SSean Wang static const struct mtk_eint_xt mtk_eint_xt = { 36289132dd8SSean Wang .get_gpio_n = mtk_xt_get_gpio_n, 36389132dd8SSean Wang .get_gpio_state = mtk_xt_get_gpio_state, 36489132dd8SSean Wang .set_gpio_as_eint = mtk_xt_set_gpio_as_eint, 36589132dd8SSean Wang }; 36689132dd8SSean Wang 36789132dd8SSean Wang int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) 36889132dd8SSean Wang { 36989132dd8SSean Wang struct device_node *np = pdev->dev.of_node; 370db751578SEnric Balletbo i Serra int ret; 37189132dd8SSean Wang 37289132dd8SSean Wang if (!IS_ENABLED(CONFIG_EINT_MTK)) 37389132dd8SSean Wang return 0; 37489132dd8SSean Wang 37589132dd8SSean Wang if (!of_property_read_bool(np, "interrupt-controller")) 37689132dd8SSean Wang return -ENODEV; 37789132dd8SSean Wang 37889132dd8SSean Wang hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL); 37989132dd8SSean Wang if (!hw->eint) 38089132dd8SSean Wang return -ENOMEM; 38189132dd8SSean Wang 38248548c78SWang Xiaojun hw->eint->base = devm_platform_ioremap_resource_byname(pdev, "eint"); 383db751578SEnric Balletbo i Serra if (IS_ERR(hw->eint->base)) { 384db751578SEnric Balletbo i Serra ret = PTR_ERR(hw->eint->base); 385db751578SEnric Balletbo i Serra goto err_free_eint; 38689132dd8SSean Wang } 38789132dd8SSean Wang 38889132dd8SSean Wang hw->eint->irq = irq_of_parse_and_map(np, 0); 389db751578SEnric Balletbo i Serra if (!hw->eint->irq) { 390db751578SEnric Balletbo i Serra ret = -EINVAL; 391db751578SEnric Balletbo i Serra goto err_free_eint; 392db751578SEnric Balletbo i Serra } 39389132dd8SSean Wang 394db751578SEnric Balletbo i Serra if (!hw->soc->eint_hw) { 395db751578SEnric Balletbo i Serra ret = -ENODEV; 396db751578SEnric Balletbo i Serra goto err_free_eint; 397db751578SEnric Balletbo i Serra } 39889132dd8SSean Wang 39989132dd8SSean Wang hw->eint->dev = &pdev->dev; 40089132dd8SSean Wang hw->eint->hw = hw->soc->eint_hw; 40189132dd8SSean Wang hw->eint->pctl = hw; 40289132dd8SSean Wang hw->eint->gpio_xlate = &mtk_eint_xt; 40389132dd8SSean Wang 40489132dd8SSean Wang return mtk_eint_do_init(hw->eint); 405db751578SEnric Balletbo i Serra 406db751578SEnric Balletbo i Serra err_free_eint: 407db751578SEnric Balletbo i Serra devm_kfree(hw->dev, hw->eint); 408db751578SEnric Balletbo i Serra hw->eint = NULL; 409db751578SEnric Balletbo i Serra return ret; 41089132dd8SSean Wang } 4118174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_build_eint); 41289132dd8SSean Wang 4139afc305bSSean Wang /* Revision 0 */ 41485430152SSean Wang int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw, 41585430152SSean Wang const struct mtk_pin_desc *desc) 41685430152SSean Wang { 41785430152SSean Wang int err; 41885430152SSean Wang 419ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, 42085430152SSean Wang MTK_DISABLE); 42185430152SSean Wang if (err) 42285430152SSean Wang return err; 42385430152SSean Wang 424ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, 42585430152SSean Wang MTK_DISABLE); 42685430152SSean Wang if (err) 42785430152SSean Wang return err; 42885430152SSean Wang 42985430152SSean Wang return 0; 43085430152SSean Wang } 4318174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_set); 43285430152SSean Wang 43385430152SSean Wang int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw, 43485430152SSean Wang const struct mtk_pin_desc *desc, int *res) 43585430152SSean Wang { 43685430152SSean Wang int v, v2; 43785430152SSean Wang int err; 43885430152SSean Wang 439ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v); 44085430152SSean Wang if (err) 44185430152SSean Wang return err; 44285430152SSean Wang 443ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2); 44485430152SSean Wang if (err) 44585430152SSean Wang return err; 44685430152SSean Wang 44785430152SSean Wang if (v == MTK_ENABLE || v2 == MTK_ENABLE) 44885430152SSean Wang return -EINVAL; 44985430152SSean Wang 45085430152SSean Wang *res = 1; 45185430152SSean Wang 45285430152SSean Wang return 0; 45385430152SSean Wang } 4548174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_get); 45585430152SSean Wang 45685430152SSean Wang int mtk_pinconf_bias_set(struct mtk_pinctrl *hw, 45785430152SSean Wang const struct mtk_pin_desc *desc, bool pullup) 45885430152SSean Wang { 45985430152SSean Wang int err, arg; 46085430152SSean Wang 46185430152SSean Wang arg = pullup ? 1 : 2; 46285430152SSean Wang 463ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1); 46485430152SSean Wang if (err) 46585430152SSean Wang return err; 46685430152SSean Wang 467ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, 46885430152SSean Wang !!(arg & 2)); 46985430152SSean Wang if (err) 47085430152SSean Wang return err; 47185430152SSean Wang 47285430152SSean Wang return 0; 47385430152SSean Wang } 4748174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set); 47585430152SSean Wang 47685430152SSean Wang int mtk_pinconf_bias_get(struct mtk_pinctrl *hw, 47785430152SSean Wang const struct mtk_pin_desc *desc, bool pullup, int *res) 47885430152SSean Wang { 47985430152SSean Wang int reg, err, v; 48085430152SSean Wang 48185430152SSean Wang reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD; 48285430152SSean Wang 483ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, reg, &v); 48485430152SSean Wang if (err) 48585430152SSean Wang return err; 48685430152SSean Wang 48785430152SSean Wang if (!v) 48885430152SSean Wang return -EINVAL; 48985430152SSean Wang 49085430152SSean Wang *res = 1; 49185430152SSean Wang 49285430152SSean Wang return 0; 49385430152SSean Wang } 4948174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get); 49585430152SSean Wang 4969afc305bSSean Wang /* Revision 1 */ 4979afc305bSSean Wang int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw, 4989afc305bSSean Wang const struct mtk_pin_desc *desc) 4999afc305bSSean Wang { 500a15f8596SZheng Yongjun return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, 5019afc305bSSean Wang MTK_DISABLE); 5029afc305bSSean Wang } 5038174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_set_rev1); 5049afc305bSSean Wang 5059afc305bSSean Wang int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw, 5069afc305bSSean Wang const struct mtk_pin_desc *desc, int *res) 5079afc305bSSean Wang { 5089afc305bSSean Wang int v, err; 5099afc305bSSean Wang 510ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v); 5119afc305bSSean Wang if (err) 5129afc305bSSean Wang return err; 5139afc305bSSean Wang 5149afc305bSSean Wang if (v == MTK_ENABLE) 5159afc305bSSean Wang return -EINVAL; 5169afc305bSSean Wang 5179afc305bSSean Wang *res = 1; 5189afc305bSSean Wang 5199afc305bSSean Wang return 0; 5209afc305bSSean Wang } 5218174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_disable_get_rev1); 5229afc305bSSean Wang 5239afc305bSSean Wang int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw, 5249afc305bSSean Wang const struct mtk_pin_desc *desc, bool pullup) 5259afc305bSSean Wang { 5269afc305bSSean Wang int err, arg; 5279afc305bSSean Wang 5289afc305bSSean Wang arg = pullup ? MTK_PULLUP : MTK_PULLDOWN; 5299afc305bSSean Wang 530ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, 5319afc305bSSean Wang MTK_ENABLE); 5329afc305bSSean Wang if (err) 5339afc305bSSean Wang return err; 5349afc305bSSean Wang 535ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg); 5369afc305bSSean Wang if (err) 5379afc305bSSean Wang return err; 5389afc305bSSean Wang 5399afc305bSSean Wang return 0; 5409afc305bSSean Wang } 5418174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set_rev1); 5429afc305bSSean Wang 5439afc305bSSean Wang int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw, 5449afc305bSSean Wang const struct mtk_pin_desc *desc, bool pullup, 5459afc305bSSean Wang int *res) 5469afc305bSSean Wang { 5479afc305bSSean Wang int err, v; 5489afc305bSSean Wang 549ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v); 5509afc305bSSean Wang if (err) 5519afc305bSSean Wang return err; 5529afc305bSSean Wang 5539afc305bSSean Wang if (v == MTK_DISABLE) 5549afc305bSSean Wang return -EINVAL; 5559afc305bSSean Wang 556ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v); 5579afc305bSSean Wang if (err) 5589afc305bSSean Wang return err; 5599afc305bSSean Wang 5609afc305bSSean Wang if (pullup ^ (v == MTK_PULLUP)) 5619afc305bSSean Wang return -EINVAL; 5629afc305bSSean Wang 5639afc305bSSean Wang *res = 1; 5649afc305bSSean Wang 5659afc305bSSean Wang return 0; 5669afc305bSSean Wang } 5678174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_rev1); 5689afc305bSSean Wang 569cafe19dbSLight Hsieh /* Combo for the following pull register type: 570cafe19dbSLight Hsieh * 1. PU + PD 571cafe19dbSLight Hsieh * 2. PULLSEL + PULLEN 572cafe19dbSLight Hsieh * 3. PUPD + R0 + R1 573cafe19dbSLight Hsieh */ 574cafe19dbSLight Hsieh static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw, 575cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 576cafe19dbSLight Hsieh u32 pullup, u32 arg) 577cafe19dbSLight Hsieh { 578cafe19dbSLight Hsieh int err, pu, pd; 579cafe19dbSLight Hsieh 580cafe19dbSLight Hsieh if (arg == MTK_DISABLE) { 581cafe19dbSLight Hsieh pu = 0; 582cafe19dbSLight Hsieh pd = 0; 583cafe19dbSLight Hsieh } else if ((arg == MTK_ENABLE) && pullup) { 584cafe19dbSLight Hsieh pu = 1; 585cafe19dbSLight Hsieh pd = 0; 586cafe19dbSLight Hsieh } else if ((arg == MTK_ENABLE) && !pullup) { 587cafe19dbSLight Hsieh pu = 0; 588cafe19dbSLight Hsieh pd = 1; 589cafe19dbSLight Hsieh } else { 590cafe19dbSLight Hsieh err = -EINVAL; 591cafe19dbSLight Hsieh goto out; 592cafe19dbSLight Hsieh } 593cafe19dbSLight Hsieh 594cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu); 595cafe19dbSLight Hsieh if (err) 596cafe19dbSLight Hsieh goto out; 597cafe19dbSLight Hsieh 598cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd); 599cafe19dbSLight Hsieh 600cafe19dbSLight Hsieh out: 601cafe19dbSLight Hsieh return err; 602cafe19dbSLight Hsieh } 603cafe19dbSLight Hsieh 604cafe19dbSLight Hsieh static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw, 605cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 606cafe19dbSLight Hsieh u32 pullup, u32 arg) 607cafe19dbSLight Hsieh { 608cafe19dbSLight Hsieh int err, enable; 609cafe19dbSLight Hsieh 610cafe19dbSLight Hsieh if (arg == MTK_DISABLE) 611cafe19dbSLight Hsieh enable = 0; 612cafe19dbSLight Hsieh else if (arg == MTK_ENABLE) 613cafe19dbSLight Hsieh enable = 1; 614cafe19dbSLight Hsieh else { 615cafe19dbSLight Hsieh err = -EINVAL; 616cafe19dbSLight Hsieh goto out; 617cafe19dbSLight Hsieh } 618cafe19dbSLight Hsieh 619cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable); 620cafe19dbSLight Hsieh if (err) 621cafe19dbSLight Hsieh goto out; 622cafe19dbSLight Hsieh 623cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); 624cafe19dbSLight Hsieh 625cafe19dbSLight Hsieh out: 626cafe19dbSLight Hsieh return err; 627cafe19dbSLight Hsieh } 628cafe19dbSLight Hsieh 629cafe19dbSLight Hsieh static int mtk_pinconf_bias_set_pupd_r1_r0(struct mtk_pinctrl *hw, 630cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 631cafe19dbSLight Hsieh u32 pullup, u32 arg) 632cafe19dbSLight Hsieh { 633cafe19dbSLight Hsieh int err, r0, r1; 634cafe19dbSLight Hsieh 635cafe19dbSLight Hsieh if ((arg == MTK_DISABLE) || (arg == MTK_PUPD_SET_R1R0_00)) { 636cafe19dbSLight Hsieh pullup = 0; 637cafe19dbSLight Hsieh r0 = 0; 638cafe19dbSLight Hsieh r1 = 0; 639cafe19dbSLight Hsieh } else if (arg == MTK_PUPD_SET_R1R0_01) { 640cafe19dbSLight Hsieh r0 = 1; 641cafe19dbSLight Hsieh r1 = 0; 642cafe19dbSLight Hsieh } else if (arg == MTK_PUPD_SET_R1R0_10) { 643cafe19dbSLight Hsieh r0 = 0; 644cafe19dbSLight Hsieh r1 = 1; 645cafe19dbSLight Hsieh } else if (arg == MTK_PUPD_SET_R1R0_11) { 646cafe19dbSLight Hsieh r0 = 1; 647cafe19dbSLight Hsieh r1 = 1; 648cafe19dbSLight Hsieh } else { 649cafe19dbSLight Hsieh err = -EINVAL; 650cafe19dbSLight Hsieh goto out; 651cafe19dbSLight Hsieh } 652cafe19dbSLight Hsieh 653cafe19dbSLight Hsieh /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ 654cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup); 655cafe19dbSLight Hsieh if (err) 656cafe19dbSLight Hsieh goto out; 657cafe19dbSLight Hsieh 658cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, r0); 659cafe19dbSLight Hsieh if (err) 660cafe19dbSLight Hsieh goto out; 661cafe19dbSLight Hsieh 662cafe19dbSLight Hsieh err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, r1); 663cafe19dbSLight Hsieh 664cafe19dbSLight Hsieh out: 665cafe19dbSLight Hsieh return err; 666cafe19dbSLight Hsieh } 667cafe19dbSLight Hsieh 668fb34a9aeSZhiyong Tao static int mtk_hw_pin_rsel_lookup(struct mtk_pinctrl *hw, 669fb34a9aeSZhiyong Tao const struct mtk_pin_desc *desc, 670fb34a9aeSZhiyong Tao u32 pullup, u32 arg, u32 *rsel_val) 671fb34a9aeSZhiyong Tao { 672fb34a9aeSZhiyong Tao const struct mtk_pin_rsel *rsel; 673fb34a9aeSZhiyong Tao int check; 674fb34a9aeSZhiyong Tao bool found = false; 675fb34a9aeSZhiyong Tao 676fb34a9aeSZhiyong Tao rsel = hw->soc->pin_rsel; 677fb34a9aeSZhiyong Tao 678fb34a9aeSZhiyong Tao for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { 679fb34a9aeSZhiyong Tao if (desc->number >= rsel[check].s_pin && 680fb34a9aeSZhiyong Tao desc->number <= rsel[check].e_pin) { 681fb34a9aeSZhiyong Tao if (pullup) { 682fb34a9aeSZhiyong Tao if (rsel[check].up_rsel == arg) { 683fb34a9aeSZhiyong Tao found = true; 684fb34a9aeSZhiyong Tao *rsel_val = rsel[check].rsel_index; 685fb34a9aeSZhiyong Tao break; 686fb34a9aeSZhiyong Tao } 687fb34a9aeSZhiyong Tao } else { 688fb34a9aeSZhiyong Tao if (rsel[check].down_rsel == arg) { 689fb34a9aeSZhiyong Tao found = true; 690fb34a9aeSZhiyong Tao *rsel_val = rsel[check].rsel_index; 691fb34a9aeSZhiyong Tao break; 692fb34a9aeSZhiyong Tao } 693fb34a9aeSZhiyong Tao } 694fb34a9aeSZhiyong Tao } 695fb34a9aeSZhiyong Tao } 696fb34a9aeSZhiyong Tao 697fb34a9aeSZhiyong Tao if (!found) { 698fb34a9aeSZhiyong Tao dev_err(hw->dev, "Not support rsel value %d Ohm for pin = %d (%s)\n", 699fb34a9aeSZhiyong Tao arg, desc->number, desc->name); 700fb34a9aeSZhiyong Tao return -ENOTSUPP; 701fb34a9aeSZhiyong Tao } 702fb34a9aeSZhiyong Tao 703fb34a9aeSZhiyong Tao return 0; 704fb34a9aeSZhiyong Tao } 705fb34a9aeSZhiyong Tao 706fb34a9aeSZhiyong Tao static int mtk_pinconf_bias_set_rsel(struct mtk_pinctrl *hw, 707fb34a9aeSZhiyong Tao const struct mtk_pin_desc *desc, 708fb34a9aeSZhiyong Tao u32 pullup, u32 arg) 709fb34a9aeSZhiyong Tao { 710fb34a9aeSZhiyong Tao int err, rsel_val; 711fb34a9aeSZhiyong Tao 712fb34a9aeSZhiyong Tao if (hw->rsel_si_unit) { 713fb34a9aeSZhiyong Tao /* find pin rsel_index from pin_rsel array*/ 714fb34a9aeSZhiyong Tao err = mtk_hw_pin_rsel_lookup(hw, desc, pullup, arg, &rsel_val); 715fb34a9aeSZhiyong Tao if (err) 716fb34a9aeSZhiyong Tao goto out; 717fb34a9aeSZhiyong Tao } else { 718fb34a9aeSZhiyong Tao if (arg < MTK_PULL_SET_RSEL_000 || 719fb34a9aeSZhiyong Tao arg > MTK_PULL_SET_RSEL_111) { 720fb34a9aeSZhiyong Tao err = -EINVAL; 721fb34a9aeSZhiyong Tao goto out; 722fb34a9aeSZhiyong Tao } 723fb34a9aeSZhiyong Tao 724fb34a9aeSZhiyong Tao rsel_val = arg - MTK_PULL_SET_RSEL_000; 725fb34a9aeSZhiyong Tao } 726fb34a9aeSZhiyong Tao 727fb34a9aeSZhiyong Tao err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_RSEL, rsel_val); 728fb34a9aeSZhiyong Tao if (err) 729fb34a9aeSZhiyong Tao goto out; 730fb34a9aeSZhiyong Tao 731fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, MTK_ENABLE); 732fb34a9aeSZhiyong Tao 733fb34a9aeSZhiyong Tao out: 734fb34a9aeSZhiyong Tao return err; 735fb34a9aeSZhiyong Tao } 736fb34a9aeSZhiyong Tao 737fb34a9aeSZhiyong Tao int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw, 738fb34a9aeSZhiyong Tao const struct mtk_pin_desc *desc, 739fb34a9aeSZhiyong Tao u32 pullup, u32 arg) 740fb34a9aeSZhiyong Tao { 741fb34a9aeSZhiyong Tao int err = -ENOTSUPP; 742fb34a9aeSZhiyong Tao u32 try_all_type; 743fb34a9aeSZhiyong Tao 744fb34a9aeSZhiyong Tao if (hw->soc->pull_type) 745fb34a9aeSZhiyong Tao try_all_type = hw->soc->pull_type[desc->number]; 746fb34a9aeSZhiyong Tao else 747fb34a9aeSZhiyong Tao try_all_type = MTK_PULL_TYPE_MASK; 748fb34a9aeSZhiyong Tao 749fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_RSEL_TYPE) { 750fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_set_rsel(hw, desc, pullup, arg); 751fb34a9aeSZhiyong Tao if (!err) 752fb34a9aeSZhiyong Tao return err; 753fb34a9aeSZhiyong Tao } 754fb34a9aeSZhiyong Tao 755fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PU_PD_TYPE) { 756fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg); 757fb34a9aeSZhiyong Tao if (!err) 758fb34a9aeSZhiyong Tao return err; 759fb34a9aeSZhiyong Tao } 760fb34a9aeSZhiyong Tao 761fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PULLSEL_TYPE) { 762fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc, 763fb34a9aeSZhiyong Tao pullup, arg); 764fb34a9aeSZhiyong Tao if (!err) 765fb34a9aeSZhiyong Tao return err; 766fb34a9aeSZhiyong Tao } 767fb34a9aeSZhiyong Tao 768fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE) 769fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg); 770fb34a9aeSZhiyong Tao 771fb34a9aeSZhiyong Tao if (err) 772fb34a9aeSZhiyong Tao dev_err(hw->dev, "Invalid pull argument\n"); 773fb34a9aeSZhiyong Tao 774fb34a9aeSZhiyong Tao return err; 775fb34a9aeSZhiyong Tao } 776fb34a9aeSZhiyong Tao EXPORT_SYMBOL_GPL(mtk_pinconf_bias_set_combo); 777fb34a9aeSZhiyong Tao 778fb34a9aeSZhiyong Tao static int mtk_rsel_get_si_unit(struct mtk_pinctrl *hw, 779fb34a9aeSZhiyong Tao const struct mtk_pin_desc *desc, 780fb34a9aeSZhiyong Tao u32 pullup, u32 rsel_val, u32 *si_unit) 781fb34a9aeSZhiyong Tao { 782fb34a9aeSZhiyong Tao const struct mtk_pin_rsel *rsel; 783fb34a9aeSZhiyong Tao int check; 784fb34a9aeSZhiyong Tao 785fb34a9aeSZhiyong Tao rsel = hw->soc->pin_rsel; 786fb34a9aeSZhiyong Tao 787fb34a9aeSZhiyong Tao for (check = 0; check <= hw->soc->npin_rsel - 1; check++) { 788fb34a9aeSZhiyong Tao if (desc->number >= rsel[check].s_pin && 789fb34a9aeSZhiyong Tao desc->number <= rsel[check].e_pin) { 790fb34a9aeSZhiyong Tao if (rsel_val == rsel[check].rsel_index) { 791fb34a9aeSZhiyong Tao if (pullup) 792fb34a9aeSZhiyong Tao *si_unit = rsel[check].up_rsel; 793fb34a9aeSZhiyong Tao else 794fb34a9aeSZhiyong Tao *si_unit = rsel[check].down_rsel; 795fb34a9aeSZhiyong Tao break; 796fb34a9aeSZhiyong Tao } 797fb34a9aeSZhiyong Tao } 798fb34a9aeSZhiyong Tao } 799fb34a9aeSZhiyong Tao 800fb34a9aeSZhiyong Tao return 0; 801fb34a9aeSZhiyong Tao } 802fb34a9aeSZhiyong Tao 803fb34a9aeSZhiyong Tao static int mtk_pinconf_bias_get_rsel(struct mtk_pinctrl *hw, 804fb34a9aeSZhiyong Tao const struct mtk_pin_desc *desc, 805fb34a9aeSZhiyong Tao u32 *pullup, u32 *enable) 806fb34a9aeSZhiyong Tao { 807fb34a9aeSZhiyong Tao int pu, pd, rsel, err; 808fb34a9aeSZhiyong Tao 809fb34a9aeSZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_RSEL, &rsel); 810fb34a9aeSZhiyong Tao if (err) 811fb34a9aeSZhiyong Tao goto out; 812fb34a9aeSZhiyong Tao 813fb34a9aeSZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu); 814fb34a9aeSZhiyong Tao if (err) 815fb34a9aeSZhiyong Tao goto out; 816fb34a9aeSZhiyong Tao 817fb34a9aeSZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); 818fb34a9aeSZhiyong Tao 819fb34a9aeSZhiyong Tao if (pu == 0 && pd == 0) { 820fb34a9aeSZhiyong Tao *pullup = 0; 821fb34a9aeSZhiyong Tao *enable = MTK_DISABLE; 822fb34a9aeSZhiyong Tao } else if (pu == 1 && pd == 0) { 823fb34a9aeSZhiyong Tao *pullup = 1; 824fb34a9aeSZhiyong Tao if (hw->rsel_si_unit) 825fb34a9aeSZhiyong Tao mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); 826fb34a9aeSZhiyong Tao else 827fb34a9aeSZhiyong Tao *enable = rsel + MTK_PULL_SET_RSEL_000; 828fb34a9aeSZhiyong Tao } else if (pu == 0 && pd == 1) { 829fb34a9aeSZhiyong Tao *pullup = 0; 830fb34a9aeSZhiyong Tao if (hw->rsel_si_unit) 831fb34a9aeSZhiyong Tao mtk_rsel_get_si_unit(hw, desc, *pullup, rsel, enable); 832fb34a9aeSZhiyong Tao else 833fb34a9aeSZhiyong Tao *enable = rsel + MTK_PULL_SET_RSEL_000; 834fb34a9aeSZhiyong Tao } else { 835fb34a9aeSZhiyong Tao err = -EINVAL; 836fb34a9aeSZhiyong Tao goto out; 837fb34a9aeSZhiyong Tao } 838fb34a9aeSZhiyong Tao 839fb34a9aeSZhiyong Tao out: 840fb34a9aeSZhiyong Tao return err; 841fb34a9aeSZhiyong Tao } 842fb34a9aeSZhiyong Tao 843cafe19dbSLight Hsieh static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw, 844cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 845cafe19dbSLight Hsieh u32 *pullup, u32 *enable) 846cafe19dbSLight Hsieh { 847cafe19dbSLight Hsieh int err, pu, pd; 848cafe19dbSLight Hsieh 849cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu); 850cafe19dbSLight Hsieh if (err) 851cafe19dbSLight Hsieh goto out; 852cafe19dbSLight Hsieh 853cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd); 854cafe19dbSLight Hsieh if (err) 855cafe19dbSLight Hsieh goto out; 856cafe19dbSLight Hsieh 857cafe19dbSLight Hsieh if (pu == 0 && pd == 0) { 858cafe19dbSLight Hsieh *pullup = 0; 859cafe19dbSLight Hsieh *enable = MTK_DISABLE; 860cafe19dbSLight Hsieh } else if (pu == 1 && pd == 0) { 861cafe19dbSLight Hsieh *pullup = 1; 862cafe19dbSLight Hsieh *enable = MTK_ENABLE; 863cafe19dbSLight Hsieh } else if (pu == 0 && pd == 1) { 864cafe19dbSLight Hsieh *pullup = 0; 865cafe19dbSLight Hsieh *enable = MTK_ENABLE; 866cafe19dbSLight Hsieh } else 867cafe19dbSLight Hsieh err = -EINVAL; 868cafe19dbSLight Hsieh 869cafe19dbSLight Hsieh out: 870cafe19dbSLight Hsieh return err; 871cafe19dbSLight Hsieh } 872cafe19dbSLight Hsieh 873cafe19dbSLight Hsieh static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw, 874cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 875cafe19dbSLight Hsieh u32 *pullup, u32 *enable) 876cafe19dbSLight Hsieh { 877cafe19dbSLight Hsieh int err; 878cafe19dbSLight Hsieh 879cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup); 880cafe19dbSLight Hsieh if (err) 881cafe19dbSLight Hsieh goto out; 882cafe19dbSLight Hsieh 883cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable); 884cafe19dbSLight Hsieh 885cafe19dbSLight Hsieh out: 886cafe19dbSLight Hsieh return err; 887cafe19dbSLight Hsieh } 888cafe19dbSLight Hsieh 889cafe19dbSLight Hsieh static int mtk_pinconf_bias_get_pupd_r1_r0(struct mtk_pinctrl *hw, 890cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 891cafe19dbSLight Hsieh u32 *pullup, u32 *enable) 892cafe19dbSLight Hsieh { 893cafe19dbSLight Hsieh int err, r0, r1; 894cafe19dbSLight Hsieh 895cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup); 896cafe19dbSLight Hsieh if (err) 897cafe19dbSLight Hsieh goto out; 898cafe19dbSLight Hsieh /* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */ 899cafe19dbSLight Hsieh *pullup = !(*pullup); 900cafe19dbSLight Hsieh 901cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &r0); 902cafe19dbSLight Hsieh if (err) 903cafe19dbSLight Hsieh goto out; 904cafe19dbSLight Hsieh 905cafe19dbSLight Hsieh err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &r1); 906cafe19dbSLight Hsieh if (err) 907cafe19dbSLight Hsieh goto out; 908cafe19dbSLight Hsieh 909cafe19dbSLight Hsieh if ((r1 == 0) && (r0 == 0)) 910cafe19dbSLight Hsieh *enable = MTK_PUPD_SET_R1R0_00; 911cafe19dbSLight Hsieh else if ((r1 == 0) && (r0 == 1)) 912cafe19dbSLight Hsieh *enable = MTK_PUPD_SET_R1R0_01; 913cafe19dbSLight Hsieh else if ((r1 == 1) && (r0 == 0)) 914cafe19dbSLight Hsieh *enable = MTK_PUPD_SET_R1R0_10; 915cafe19dbSLight Hsieh else if ((r1 == 1) && (r0 == 1)) 916cafe19dbSLight Hsieh *enable = MTK_PUPD_SET_R1R0_11; 917cafe19dbSLight Hsieh else 918cafe19dbSLight Hsieh err = -EINVAL; 919cafe19dbSLight Hsieh 920cafe19dbSLight Hsieh out: 921cafe19dbSLight Hsieh return err; 922cafe19dbSLight Hsieh } 923cafe19dbSLight Hsieh 924cafe19dbSLight Hsieh int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw, 925cafe19dbSLight Hsieh const struct mtk_pin_desc *desc, 926cafe19dbSLight Hsieh u32 *pullup, u32 *enable) 927cafe19dbSLight Hsieh { 928fb34a9aeSZhiyong Tao int err = -ENOTSUPP; 929fb34a9aeSZhiyong Tao u32 try_all_type; 930cafe19dbSLight Hsieh 931fb34a9aeSZhiyong Tao if (hw->soc->pull_type) 932fb34a9aeSZhiyong Tao try_all_type = hw->soc->pull_type[desc->number]; 933fb34a9aeSZhiyong Tao else 934fb34a9aeSZhiyong Tao try_all_type = MTK_PULL_TYPE_MASK; 935fb34a9aeSZhiyong Tao 936fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_RSEL_TYPE) { 937fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_get_rsel(hw, desc, pullup, enable); 938fb34a9aeSZhiyong Tao if (!err) 939fb34a9aeSZhiyong Tao return err; 940fb34a9aeSZhiyong Tao } 941fb34a9aeSZhiyong Tao 942fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PU_PD_TYPE) { 943cafe19dbSLight Hsieh err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable); 944cafe19dbSLight Hsieh if (!err) 945fb34a9aeSZhiyong Tao return err; 946fb34a9aeSZhiyong Tao } 947cafe19dbSLight Hsieh 948fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PULLSEL_TYPE) { 949fb34a9aeSZhiyong Tao err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc, 950fb34a9aeSZhiyong Tao pullup, enable); 951cafe19dbSLight Hsieh if (!err) 952fb34a9aeSZhiyong Tao return err; 953fb34a9aeSZhiyong Tao } 954cafe19dbSLight Hsieh 955fb34a9aeSZhiyong Tao if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE) 956cafe19dbSLight Hsieh err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable); 957cafe19dbSLight Hsieh 958cafe19dbSLight Hsieh return err; 959cafe19dbSLight Hsieh } 9608174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_combo); 961cafe19dbSLight Hsieh 962c2832197SSean Wang /* Revision 0 */ 963c2832197SSean Wang int mtk_pinconf_drive_set(struct mtk_pinctrl *hw, 964c2832197SSean Wang const struct mtk_pin_desc *desc, u32 arg) 965c2832197SSean Wang { 966c2832197SSean Wang const struct mtk_drive_desc *tb; 967c2832197SSean Wang int err = -ENOTSUPP; 968c2832197SSean Wang 969c2832197SSean Wang tb = &mtk_drive[desc->drv_n]; 970c2832197SSean Wang /* 4mA when (e8, e4) = (0, 0) 971c2832197SSean Wang * 8mA when (e8, e4) = (0, 1) 972c2832197SSean Wang * 12mA when (e8, e4) = (1, 0) 973c2832197SSean Wang * 16mA when (e8, e4) = (1, 1) 974c2832197SSean Wang */ 975c2832197SSean Wang if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { 976c2832197SSean Wang arg = (arg / tb->step - 1) * tb->scal; 977ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4, 978c2832197SSean Wang arg & 0x1); 979c2832197SSean Wang if (err) 980c2832197SSean Wang return err; 981c2832197SSean Wang 982ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8, 983c2832197SSean Wang (arg & 0x2) >> 1); 984c2832197SSean Wang if (err) 985c2832197SSean Wang return err; 986c2832197SSean Wang } 987c2832197SSean Wang 988c2832197SSean Wang return err; 989c2832197SSean Wang } 9908174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set); 991c2832197SSean Wang 992c2832197SSean Wang int mtk_pinconf_drive_get(struct mtk_pinctrl *hw, 993c2832197SSean Wang const struct mtk_pin_desc *desc, int *val) 994c2832197SSean Wang { 995c2832197SSean Wang const struct mtk_drive_desc *tb; 996c2832197SSean Wang int err, val1, val2; 997c2832197SSean Wang 998c2832197SSean Wang tb = &mtk_drive[desc->drv_n]; 999c2832197SSean Wang 1000ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1); 1001c2832197SSean Wang if (err) 1002c2832197SSean Wang return err; 1003c2832197SSean Wang 1004ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2); 1005c2832197SSean Wang if (err) 1006c2832197SSean Wang return err; 1007c2832197SSean Wang 1008c2832197SSean Wang /* 4mA when (e8, e4) = (0, 0); 8mA when (e8, e4) = (0, 1) 1009c2832197SSean Wang * 12mA when (e8, e4) = (1, 0); 16mA when (e8, e4) = (1, 1) 1010c2832197SSean Wang */ 1011c2832197SSean Wang *val = (((val2 << 1) + val1) / tb->scal + 1) * tb->step; 1012c2832197SSean Wang 1013c2832197SSean Wang return 0; 1014c2832197SSean Wang } 10158174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get); 10163ad38a14SSean Wang 10173ad38a14SSean Wang /* Revision 1 */ 10183ad38a14SSean Wang int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw, 10193ad38a14SSean Wang const struct mtk_pin_desc *desc, u32 arg) 10203ad38a14SSean Wang { 10213ad38a14SSean Wang const struct mtk_drive_desc *tb; 10223ad38a14SSean Wang int err = -ENOTSUPP; 10233ad38a14SSean Wang 10243ad38a14SSean Wang tb = &mtk_drive[desc->drv_n]; 10253ad38a14SSean Wang 10263ad38a14SSean Wang if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) { 10273ad38a14SSean Wang arg = (arg / tb->step - 1) * tb->scal; 10283ad38a14SSean Wang 1029ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV, 10303ad38a14SSean Wang arg); 10313ad38a14SSean Wang if (err) 10323ad38a14SSean Wang return err; 10333ad38a14SSean Wang } 10343ad38a14SSean Wang 10353ad38a14SSean Wang return err; 10363ad38a14SSean Wang } 10378174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set_rev1); 10383ad38a14SSean Wang 10393ad38a14SSean Wang int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw, 10403ad38a14SSean Wang const struct mtk_pin_desc *desc, int *val) 10413ad38a14SSean Wang { 10423ad38a14SSean Wang const struct mtk_drive_desc *tb; 10433ad38a14SSean Wang int err, val1; 10443ad38a14SSean Wang 10453ad38a14SSean Wang tb = &mtk_drive[desc->drv_n]; 10463ad38a14SSean Wang 1047ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1); 10483ad38a14SSean Wang if (err) 10493ad38a14SSean Wang return err; 10503ad38a14SSean Wang 10513ad38a14SSean Wang *val = ((val1 & 0x7) / tb->scal + 1) * tb->step; 10523ad38a14SSean Wang 10533ad38a14SSean Wang return 0; 10543ad38a14SSean Wang } 10558174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get_rev1); 10560d7ca772SSean Wang 10575f755e1fSLight Hsieh int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw, 10585f755e1fSLight Hsieh const struct mtk_pin_desc *desc, u32 arg) 10595f755e1fSLight Hsieh { 10605f755e1fSLight Hsieh return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV, arg); 10615f755e1fSLight Hsieh } 10628174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_set_raw); 10635f755e1fSLight Hsieh 10645f755e1fSLight Hsieh int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw, 10655f755e1fSLight Hsieh const struct mtk_pin_desc *desc, int *val) 10665f755e1fSLight Hsieh { 10675f755e1fSLight Hsieh return mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, val); 10685f755e1fSLight Hsieh } 10698174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_drive_get_raw); 10705f755e1fSLight Hsieh 10710d7ca772SSean Wang int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw, 10720d7ca772SSean Wang const struct mtk_pin_desc *desc, bool pullup, 10730d7ca772SSean Wang u32 arg) 10740d7ca772SSean Wang { 10750d7ca772SSean Wang int err; 10760d7ca772SSean Wang 10770d7ca772SSean Wang /* 10K off & 50K (75K) off, when (R0, R1) = (0, 0); 10780d7ca772SSean Wang * 10K off & 50K (75K) on, when (R0, R1) = (0, 1); 10790d7ca772SSean Wang * 10K on & 50K (75K) off, when (R0, R1) = (1, 0); 10800d7ca772SSean Wang * 10K on & 50K (75K) on, when (R0, R1) = (1, 1) 10810d7ca772SSean Wang */ 1082ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1); 10830d7ca772SSean Wang if (err) 10840d7ca772SSean Wang return 0; 10850d7ca772SSean Wang 1086ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, 10870d7ca772SSean Wang !!(arg & 2)); 10880d7ca772SSean Wang if (err) 10890d7ca772SSean Wang return 0; 10900d7ca772SSean Wang 10910d7ca772SSean Wang arg = pullup ? 0 : 1; 10920d7ca772SSean Wang 1093ea051eb3SSean Wang err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg); 10940d7ca772SSean Wang 109579348f6fSSean Wang /* If PUPD register is not supported for that pin, let's fallback to 109679348f6fSSean Wang * general bias control. 109779348f6fSSean Wang */ 109879348f6fSSean Wang if (err == -ENOTSUPP) { 109979348f6fSSean Wang if (hw->soc->bias_set) { 110079348f6fSSean Wang err = hw->soc->bias_set(hw, desc, pullup); 110179348f6fSSean Wang if (err) 110279348f6fSSean Wang return err; 110379348f6fSSean Wang } else { 1104798a315fSHsin-Yi Wang err = mtk_pinconf_bias_set_rev1(hw, desc, pullup); 1105798a315fSHsin-Yi Wang if (err) 1106798a315fSHsin-Yi Wang err = mtk_pinconf_bias_set(hw, desc, pullup); 110779348f6fSSean Wang } 110879348f6fSSean Wang } 110979348f6fSSean Wang 11100d7ca772SSean Wang return err; 11110d7ca772SSean Wang } 11128174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_adv_pull_set); 11130d7ca772SSean Wang 11140d7ca772SSean Wang int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw, 11150d7ca772SSean Wang const struct mtk_pin_desc *desc, bool pullup, 11160d7ca772SSean Wang u32 *val) 11170d7ca772SSean Wang { 11180d7ca772SSean Wang u32 t, t2; 11190d7ca772SSean Wang int err; 11200d7ca772SSean Wang 1121ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t); 112279348f6fSSean Wang 112379348f6fSSean Wang /* If PUPD register is not supported for that pin, let's fallback to 112479348f6fSSean Wang * general bias control. 112579348f6fSSean Wang */ 112679348f6fSSean Wang if (err == -ENOTSUPP) { 112779348f6fSSean Wang if (hw->soc->bias_get) { 112879348f6fSSean Wang err = hw->soc->bias_get(hw, desc, pullup, val); 112979348f6fSSean Wang if (err) 113079348f6fSSean Wang return err; 113179348f6fSSean Wang } else { 113279348f6fSSean Wang return -ENOTSUPP; 113379348f6fSSean Wang } 113479348f6fSSean Wang } else { 113579348f6fSSean Wang /* t == 0 supposes PULLUP for the customized PULL setup */ 11360d7ca772SSean Wang if (err) 11370d7ca772SSean Wang return err; 11380d7ca772SSean Wang 11390d7ca772SSean Wang if (pullup ^ !t) 11400d7ca772SSean Wang return -EINVAL; 114179348f6fSSean Wang } 11420d7ca772SSean Wang 1143ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t); 11440d7ca772SSean Wang if (err) 11450d7ca772SSean Wang return err; 11460d7ca772SSean Wang 1147ea051eb3SSean Wang err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2); 11480d7ca772SSean Wang if (err) 11490d7ca772SSean Wang return err; 11500d7ca772SSean Wang 11510d7ca772SSean Wang *val = (t | t2 << 1) & 0x7; 11520d7ca772SSean Wang 11530d7ca772SSean Wang return 0; 11540d7ca772SSean Wang } 11558174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_adv_pull_get); 11565e73de34SZhiyong Tao 11575e73de34SZhiyong Tao int mtk_pinconf_adv_drive_set(struct mtk_pinctrl *hw, 11585e73de34SZhiyong Tao const struct mtk_pin_desc *desc, u32 arg) 11595e73de34SZhiyong Tao { 11605e73de34SZhiyong Tao int err; 11615e73de34SZhiyong Tao int en = arg & 1; 11625e73de34SZhiyong Tao int e0 = !!(arg & 2); 11635e73de34SZhiyong Tao int e1 = !!(arg & 4); 11645e73de34SZhiyong Tao 11655e73de34SZhiyong Tao err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_EN, en); 11665e73de34SZhiyong Tao if (err) 11675e73de34SZhiyong Tao return err; 11685e73de34SZhiyong Tao 11695e73de34SZhiyong Tao if (!en) 11705e73de34SZhiyong Tao return err; 11715e73de34SZhiyong Tao 11725e73de34SZhiyong Tao err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_E0, e0); 11735e73de34SZhiyong Tao if (err) 11745e73de34SZhiyong Tao return err; 11755e73de34SZhiyong Tao 11765e73de34SZhiyong Tao err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_E1, e1); 11775e73de34SZhiyong Tao if (err) 11785e73de34SZhiyong Tao return err; 11795e73de34SZhiyong Tao 11805e73de34SZhiyong Tao return err; 11815e73de34SZhiyong Tao } 11828174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_set); 11835e73de34SZhiyong Tao 11845e73de34SZhiyong Tao int mtk_pinconf_adv_drive_get(struct mtk_pinctrl *hw, 11855e73de34SZhiyong Tao const struct mtk_pin_desc *desc, u32 *val) 11865e73de34SZhiyong Tao { 11875e73de34SZhiyong Tao u32 en, e0, e1; 11885e73de34SZhiyong Tao int err; 11895e73de34SZhiyong Tao 11905e73de34SZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_EN, &en); 11915e73de34SZhiyong Tao if (err) 11925e73de34SZhiyong Tao return err; 11935e73de34SZhiyong Tao 11945e73de34SZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_E0, &e0); 11955e73de34SZhiyong Tao if (err) 11965e73de34SZhiyong Tao return err; 11975e73de34SZhiyong Tao 11985e73de34SZhiyong Tao err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_E1, &e1); 11995e73de34SZhiyong Tao if (err) 12005e73de34SZhiyong Tao return err; 12015e73de34SZhiyong Tao 12025e73de34SZhiyong Tao *val = (en | e0 << 1 | e1 << 2) & 0x7; 12035e73de34SZhiyong Tao 12045e73de34SZhiyong Tao return 0; 12055e73de34SZhiyong Tao } 12068174a851SLight Hsieh EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_get); 1207c7acd6feSArnd Bergmann 1208ea9d2ed4SZhiyong Tao int mtk_pinconf_adv_drive_set_raw(struct mtk_pinctrl *hw, 1209ea9d2ed4SZhiyong Tao const struct mtk_pin_desc *desc, u32 arg) 1210ea9d2ed4SZhiyong Tao { 1211ea9d2ed4SZhiyong Tao return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV_ADV, arg); 1212ea9d2ed4SZhiyong Tao } 1213ea9d2ed4SZhiyong Tao EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_set_raw); 1214ea9d2ed4SZhiyong Tao 1215ea9d2ed4SZhiyong Tao int mtk_pinconf_adv_drive_get_raw(struct mtk_pinctrl *hw, 1216ea9d2ed4SZhiyong Tao const struct mtk_pin_desc *desc, u32 *val) 1217ea9d2ed4SZhiyong Tao { 1218ea9d2ed4SZhiyong Tao return mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV_ADV, val); 1219ea9d2ed4SZhiyong Tao } 1220ea9d2ed4SZhiyong Tao EXPORT_SYMBOL_GPL(mtk_pinconf_adv_drive_get_raw); 1221ea9d2ed4SZhiyong Tao 1222c7acd6feSArnd Bergmann MODULE_LICENSE("GPL v2"); 1223c7acd6feSArnd Bergmann MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>"); 1224c7acd6feSArnd Bergmann MODULE_DESCRIPTION("Pin configuration library module for mediatek SoCs"); 1225