aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinctrl-rockchip.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pinctrl/pinctrl-rockchip.c')
-rw-r--r--drivers/pinctrl/pinctrl-rockchip.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 46dddc159286..96c60d230c13 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -342,7 +342,7 @@ static const struct pinctrl_ops rockchip_pctrl_ops = {
342 * @pin: pin to change 342 * @pin: pin to change
343 * @mux: new mux function to set 343 * @mux: new mux function to set
344 */ 344 */
345static void rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) 345static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
346{ 346{
347 struct rockchip_pinctrl *info = bank->drvdata; 347 struct rockchip_pinctrl *info = bank->drvdata;
348 void __iomem *reg = info->reg_base + info->ctrl->mux_offset; 348 void __iomem *reg = info->reg_base + info->ctrl->mux_offset;
@@ -350,6 +350,20 @@ static void rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
350 u8 bit; 350 u8 bit;
351 u32 data; 351 u32 data;
352 352
353 /*
354 * The first 16 pins of rk3188_bank0 are always gpios and do not have
355 * a mux register at all.
356 */
357 if (bank->bank_type == RK3188_BANK0 && pin < 16) {
358 if (mux != RK_FUNC_GPIO) {
359 dev_err(info->dev,
360 "pin %d only supports a gpio mux\n", pin);
361 return -ENOTSUPP;
362 } else {
363 return 0;
364 }
365 }
366
353 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n", 367 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
354 bank->bank_num, pin, mux); 368 bank->bank_num, pin, mux);
355 369
@@ -365,6 +379,8 @@ static void rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
365 writel(data, reg); 379 writel(data, reg);
366 380
367 spin_unlock_irqrestore(&bank->slock, flags); 381 spin_unlock_irqrestore(&bank->slock, flags);
382
383 return 0;
368} 384}
369 385
370#define RK2928_PULL_OFFSET 0x118 386#define RK2928_PULL_OFFSET 0x118
@@ -560,7 +576,7 @@ static int rockchip_pmx_enable(struct pinctrl_dev *pctldev, unsigned selector,
560 const unsigned int *pins = info->groups[group].pins; 576 const unsigned int *pins = info->groups[group].pins;
561 const struct rockchip_pin_config *data = info->groups[group].data; 577 const struct rockchip_pin_config *data = info->groups[group].data;
562 struct rockchip_pin_bank *bank; 578 struct rockchip_pin_bank *bank;
563 int cnt; 579 int cnt, ret = 0;
564 580
565 dev_dbg(info->dev, "enable function %s group %s\n", 581 dev_dbg(info->dev, "enable function %s group %s\n",
566 info->functions[selector].name, info->groups[group].name); 582 info->functions[selector].name, info->groups[group].name);
@@ -571,8 +587,18 @@ static int rockchip_pmx_enable(struct pinctrl_dev *pctldev, unsigned selector,
571 */ 587 */
572 for (cnt = 0; cnt < info->groups[group].npins; cnt++) { 588 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
573 bank = pin_to_bank(info, pins[cnt]); 589 bank = pin_to_bank(info, pins[cnt]);
574 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 590 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
575 data[cnt].func); 591 data[cnt].func);
592 if (ret)
593 break;
594 }
595
596 if (ret) {
597 /* revert the already done pin settings */
598 for (cnt--; cnt >= 0; cnt--)
599 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
600
601 return ret;
576 } 602 }
577 603
578 return 0; 604 return 0;
@@ -607,7 +633,7 @@ static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
607 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev); 633 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
608 struct rockchip_pin_bank *bank; 634 struct rockchip_pin_bank *bank;
609 struct gpio_chip *chip; 635 struct gpio_chip *chip;
610 int pin; 636 int pin, ret;
611 u32 data; 637 u32 data;
612 638
613 chip = range->gc; 639 chip = range->gc;
@@ -617,7 +643,9 @@ static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
617 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n", 643 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
618 offset, range->name, pin, input ? "input" : "output"); 644 offset, range->name, pin, input ? "input" : "output");
619 645
620 rockchip_set_mux(bank, pin, RK_FUNC_GPIO); 646 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
647 if (ret < 0)
648 return ret;
621 649
622 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); 650 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
623 /* set bit to 1 for output, 0 for input */ 651 /* set bit to 1 for output, 0 for input */
@@ -1144,9 +1172,13 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
1144 u32 polarity; 1172 u32 polarity;
1145 u32 level; 1173 u32 level;
1146 u32 data; 1174 u32 data;
1175 int ret;
1147 1176
1148 /* make sure the pin is configured as gpio input */ 1177 /* make sure the pin is configured as gpio input */
1149 rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO); 1178 ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
1179 if (ret < 0)
1180 return ret;
1181
1150 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); 1182 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
1151 data &= ~mask; 1183 data &= ~mask;
1152 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR); 1184 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
@@ -1534,7 +1566,7 @@ static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
1534 .nr_banks = ARRAY_SIZE(rk3188_pin_banks), 1566 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
1535 .label = "RK3188-GPIO", 1567 .label = "RK3188-GPIO",
1536 .type = RK3188, 1568 .type = RK3188,
1537 .mux_offset = 0x68, 1569 .mux_offset = 0x60,
1538 .pull_calc_reg = rk3188_calc_pull_reg_and_bit, 1570 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
1539}; 1571};
1540 1572