diff options
author | Heiko Stübner <heiko@sntech.de> | 2014-06-15 19:36:05 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-07-11 08:08:27 -0400 |
commit | fc72c923e50d5c0575faa5f6379bd55b900ed85a (patch) | |
tree | 8856489c05455068eee19666c0899357ad3f2500 /drivers/pinctrl/pinctrl-rockchip.c | |
parent | 2243a87d90b42eb38bc281957df3e57c712b5e56 (diff) |
pinctrl: rockchip: generalize bank-quirks
Upcoming Rockchip SoCs have additional quirks to handle. Currently they would
be handled by giving the bank a special compatible property. But the nature
of the new quirks would require a lot of them. Also as we want to move to the
separate dw_gpio driver in the future, these bank-definitions should be
extended at all.
Describing the bank quirks this way also enables us to deprecate the special
bank compatible string for bank0 on rk3188 and simplify the handling code.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinctrl-rockchip.c')
-rw-r--r-- | drivers/pinctrl/pinctrl-rockchip.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 51f67a6eadcb..2f5ba046232e 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c | |||
@@ -64,9 +64,16 @@ enum rockchip_pinctrl_type { | |||
64 | RK3188, | 64 | RK3188, |
65 | }; | 65 | }; |
66 | 66 | ||
67 | enum rockchip_pin_bank_type { | 67 | /** |
68 | COMMON_BANK, | 68 | * Encode variants of iomux registers into a type variable |
69 | RK3188_BANK0, | 69 | */ |
70 | #define IOMUX_GPIO_ONLY BIT(0) | ||
71 | |||
72 | /** | ||
73 | * @type: iomux variant using IOMUX_* constants | ||
74 | */ | ||
75 | struct rockchip_iomux { | ||
76 | int type; | ||
70 | }; | 77 | }; |
71 | 78 | ||
72 | /** | 79 | /** |
@@ -78,6 +85,7 @@ enum rockchip_pin_bank_type { | |||
78 | * @nr_pins: number of pins in this bank | 85 | * @nr_pins: number of pins in this bank |
79 | * @name: name of the bank | 86 | * @name: name of the bank |
80 | * @bank_num: number of the bank, to account for holes | 87 | * @bank_num: number of the bank, to account for holes |
88 | * @iomux: array describing the 4 iomux sources of the bank | ||
81 | * @valid: are all necessary informations present | 89 | * @valid: are all necessary informations present |
82 | * @of_node: dt node of this bank | 90 | * @of_node: dt node of this bank |
83 | * @drvdata: common pinctrl basedata | 91 | * @drvdata: common pinctrl basedata |
@@ -95,7 +103,7 @@ struct rockchip_pin_bank { | |||
95 | u8 nr_pins; | 103 | u8 nr_pins; |
96 | char *name; | 104 | char *name; |
97 | u8 bank_num; | 105 | u8 bank_num; |
98 | enum rockchip_pin_bank_type bank_type; | 106 | struct rockchip_iomux iomux[4]; |
99 | bool valid; | 107 | bool valid; |
100 | struct device_node *of_node; | 108 | struct device_node *of_node; |
101 | struct rockchip_pinctrl *drvdata; | 109 | struct rockchip_pinctrl *drvdata; |
@@ -113,6 +121,19 @@ struct rockchip_pin_bank { | |||
113 | .name = label, \ | 121 | .name = label, \ |
114 | } | 122 | } |
115 | 123 | ||
124 | #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \ | ||
125 | { \ | ||
126 | .bank_num = id, \ | ||
127 | .nr_pins = pins, \ | ||
128 | .name = label, \ | ||
129 | .iomux = { \ | ||
130 | { .type = iom0, }, \ | ||
131 | { .type = iom1, }, \ | ||
132 | { .type = iom2, }, \ | ||
133 | { .type = iom3, }, \ | ||
134 | }, \ | ||
135 | } | ||
136 | |||
116 | /** | 137 | /** |
117 | */ | 138 | */ |
118 | struct rockchip_pin_ctrl { | 139 | struct rockchip_pin_ctrl { |
@@ -343,17 +364,21 @@ static const struct pinctrl_ops rockchip_pctrl_ops = { | |||
343 | static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin) | 364 | static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin) |
344 | { | 365 | { |
345 | struct rockchip_pinctrl *info = bank->drvdata; | 366 | struct rockchip_pinctrl *info = bank->drvdata; |
367 | int iomux_num = (pin / 8); | ||
346 | unsigned int val; | 368 | unsigned int val; |
347 | int reg, ret; | 369 | int reg, ret; |
348 | u8 bit; | 370 | u8 bit; |
349 | 371 | ||
350 | if (bank->bank_type == RK3188_BANK0 && pin < 16) | 372 | if (iomux_num > 3) |
373 | return -EINVAL; | ||
374 | |||
375 | if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) | ||
351 | return RK_FUNC_GPIO; | 376 | return RK_FUNC_GPIO; |
352 | 377 | ||
353 | /* get basic quadrupel of mux registers and the correct reg inside */ | 378 | /* get basic quadrupel of mux registers and the correct reg inside */ |
354 | reg = info->ctrl->mux_offset; | 379 | reg = info->ctrl->mux_offset; |
355 | reg += bank->bank_num * 0x10; | 380 | reg += bank->bank_num * 0x10; |
356 | reg += (pin / 8) * 4; | 381 | reg += iomux_num * 4; |
357 | bit = (pin % 8) * 2; | 382 | bit = (pin % 8) * 2; |
358 | 383 | ||
359 | ret = regmap_read(info->regmap_base, reg, &val); | 384 | ret = regmap_read(info->regmap_base, reg, &val); |
@@ -379,16 +404,16 @@ static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin) | |||
379 | static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) | 404 | static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) |
380 | { | 405 | { |
381 | struct rockchip_pinctrl *info = bank->drvdata; | 406 | struct rockchip_pinctrl *info = bank->drvdata; |
407 | int iomux_num = (pin / 8); | ||
382 | int reg, ret; | 408 | int reg, ret; |
383 | unsigned long flags; | 409 | unsigned long flags; |
384 | u8 bit; | 410 | u8 bit; |
385 | u32 data; | 411 | u32 data; |
386 | 412 | ||
387 | /* | 413 | if (iomux_num > 3) |
388 | * The first 16 pins of rk3188_bank0 are always gpios and do not have | 414 | return -EINVAL; |
389 | * a mux register at all. | 415 | |
390 | */ | 416 | if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) { |
391 | if (bank->bank_type == RK3188_BANK0 && pin < 16) { | ||
392 | if (mux != RK_FUNC_GPIO) { | 417 | if (mux != RK_FUNC_GPIO) { |
393 | dev_err(info->dev, | 418 | dev_err(info->dev, |
394 | "pin %d only supports a gpio mux\n", pin); | 419 | "pin %d only supports a gpio mux\n", pin); |
@@ -404,7 +429,7 @@ static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux) | |||
404 | /* get basic quadrupel of mux registers and the correct reg inside */ | 429 | /* get basic quadrupel of mux registers and the correct reg inside */ |
405 | reg = info->ctrl->mux_offset; | 430 | reg = info->ctrl->mux_offset; |
406 | reg += bank->bank_num * 0x10; | 431 | reg += bank->bank_num * 0x10; |
407 | reg += (pin / 8) * 4; | 432 | reg += iomux_num * 4; |
408 | bit = (pin % 8) * 2; | 433 | bit = (pin % 8) * 2; |
409 | 434 | ||
410 | spin_lock_irqsave(&bank->slock, flags); | 435 | spin_lock_irqsave(&bank->slock, flags); |
@@ -449,7 +474,7 @@ static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank, | |||
449 | struct rockchip_pinctrl *info = bank->drvdata; | 474 | struct rockchip_pinctrl *info = bank->drvdata; |
450 | 475 | ||
451 | /* The first 12 pins of the first bank are located elsewhere */ | 476 | /* The first 12 pins of the first bank are located elsewhere */ |
452 | if (bank->bank_type == RK3188_BANK0 && pin_num < 12) { | 477 | if (bank->bank_num == 0 && pin_num < 12) { |
453 | *regmap = info->regmap_pmu ? info->regmap_pmu | 478 | *regmap = info->regmap_pmu ? info->regmap_pmu |
454 | : bank->regmap_pull; | 479 | : bank->regmap_pull; |
455 | *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0; | 480 | *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0; |
@@ -1448,8 +1473,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank, | |||
1448 | "rockchip,rk3188-gpio-bank0")) { | 1473 | "rockchip,rk3188-gpio-bank0")) { |
1449 | struct device_node *node; | 1474 | struct device_node *node; |
1450 | 1475 | ||
1451 | bank->bank_type = RK3188_BANK0; | ||
1452 | |||
1453 | node = of_parse_phandle(bank->of_node->parent, | 1476 | node = of_parse_phandle(bank->of_node->parent, |
1454 | "rockchip,pmu", 0); | 1477 | "rockchip,pmu", 0); |
1455 | if (!node) { | 1478 | if (!node) { |
@@ -1469,9 +1492,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank, | |||
1469 | base, | 1492 | base, |
1470 | &rockchip_regmap_config); | 1493 | &rockchip_regmap_config); |
1471 | } | 1494 | } |
1472 | |||
1473 | } else { | ||
1474 | bank->bank_type = COMMON_BANK; | ||
1475 | } | 1495 | } |
1476 | 1496 | ||
1477 | bank->irq = irq_of_parse_and_map(bank->of_node, 0); | 1497 | bank->irq = irq_of_parse_and_map(bank->of_node, 0); |
@@ -1664,7 +1684,7 @@ static struct rockchip_pin_ctrl rk3066b_pin_ctrl = { | |||
1664 | }; | 1684 | }; |
1665 | 1685 | ||
1666 | static struct rockchip_pin_bank rk3188_pin_banks[] = { | 1686 | static struct rockchip_pin_bank rk3188_pin_banks[] = { |
1667 | PIN_BANK(0, 32, "gpio0"), | 1687 | PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0), |
1668 | PIN_BANK(1, 32, "gpio1"), | 1688 | PIN_BANK(1, 32, "gpio1"), |
1669 | PIN_BANK(2, 32, "gpio2"), | 1689 | PIN_BANK(2, 32, "gpio2"), |
1670 | PIN_BANK(3, 32, "gpio3"), | 1690 | PIN_BANK(3, 32, "gpio3"), |