1 // SPDX-License-Identifier: GPL-2.0-only
3 * Pinctrl driver for Rockchip SoCs
5 * Copyright (c) 2013 MundoReader S.L.
6 * Author: Heiko Stuebner <heiko@sntech.de>
8 * With some ideas taken from pinctrl-samsung:
9 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
10 * http://www.samsung.com
11 * Copyright (c) 2012 Linaro Ltd
12 * https://www.linaro.org
15 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
22 #include <linux/bitops.h>
23 #include <linux/gpio/driver.h>
24 #include <linux/of_address.h>
25 #include <linux/of_device.h>
26 #include <linux/of_irq.h>
27 #include <linux/pinctrl/machine.h>
28 #include <linux/pinctrl/pinconf.h>
29 #include <linux/pinctrl/pinctrl.h>
30 #include <linux/pinctrl/pinmux.h>
31 #include <linux/pinctrl/pinconf-generic.h>
32 #include <linux/irqchip/chained_irq.h>
33 #include <linux/clk.h>
34 #include <linux/regmap.h>
35 #include <linux/mfd/syscon.h>
36 #include <dt-bindings/pinctrl/rockchip.h>
40 #include "pinctrl-rockchip.h"
43 * Generate a bitmask for setting a value (v) with a write mask bit in hiword
44 * register 31:16 area.
46 #define WRITE_MASK_VAL(h, l, v) \
47 (GENMASK(((h) + 16), ((l) + 16)) | (((v) << (l)) & GENMASK((h), (l))))
50 * Encode variants of iomux registers into a type variable
52 #define IOMUX_GPIO_ONLY BIT(0)
53 #define IOMUX_WIDTH_4BIT BIT(1)
54 #define IOMUX_SOURCE_PMU BIT(2)
55 #define IOMUX_UNROUTED BIT(3)
56 #define IOMUX_WIDTH_3BIT BIT(4)
57 #define IOMUX_WIDTH_2BIT BIT(5)
59 #define PIN_BANK(id, pins, label) \
72 #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
78 { .type = iom0, .offset = -1 }, \
79 { .type = iom1, .offset = -1 }, \
80 { .type = iom2, .offset = -1 }, \
81 { .type = iom3, .offset = -1 }, \
85 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
97 { .drv_type = type0, .offset = -1 }, \
98 { .drv_type = type1, .offset = -1 }, \
99 { .drv_type = type2, .offset = -1 }, \
100 { .drv_type = type3, .offset = -1 }, \
104 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
105 drv2, drv3, pull0, pull1, \
118 { .drv_type = drv0, .offset = -1 }, \
119 { .drv_type = drv1, .offset = -1 }, \
120 { .drv_type = drv2, .offset = -1 }, \
121 { .drv_type = drv3, .offset = -1 }, \
123 .pull_type[0] = pull0, \
124 .pull_type[1] = pull1, \
125 .pull_type[2] = pull2, \
126 .pull_type[3] = pull3, \
129 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
130 iom2, iom3, drv0, drv1, drv2, \
131 drv3, offset0, offset1, \
138 { .type = iom0, .offset = -1 }, \
139 { .type = iom1, .offset = -1 }, \
140 { .type = iom2, .offset = -1 }, \
141 { .type = iom3, .offset = -1 }, \
144 { .drv_type = drv0, .offset = offset0 }, \
145 { .drv_type = drv1, .offset = offset1 }, \
146 { .drv_type = drv2, .offset = offset2 }, \
147 { .drv_type = drv3, .offset = offset3 }, \
151 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
152 label, iom0, iom1, iom2, \
153 iom3, drv0, drv1, drv2, \
154 drv3, offset0, offset1, \
155 offset2, offset3, pull0, \
156 pull1, pull2, pull3) \
162 { .type = iom0, .offset = -1 }, \
163 { .type = iom1, .offset = -1 }, \
164 { .type = iom2, .offset = -1 }, \
165 { .type = iom3, .offset = -1 }, \
168 { .drv_type = drv0, .offset = offset0 }, \
169 { .drv_type = drv1, .offset = offset1 }, \
170 { .drv_type = drv2, .offset = offset2 }, \
171 { .drv_type = drv3, .offset = offset3 }, \
173 .pull_type[0] = pull0, \
174 .pull_type[1] = pull1, \
175 .pull_type[2] = pull2, \
176 .pull_type[3] = pull3, \
179 #define PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, FLAG) \
184 .route_offset = REG, \
186 .route_location = FLAG, \
189 #define RK_MUXROUTE_SAME(ID, PIN, FUNC, REG, VAL) \
190 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_SAME)
192 #define RK_MUXROUTE_GRF(ID, PIN, FUNC, REG, VAL) \
193 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_GRF)
195 #define RK_MUXROUTE_PMU(ID, PIN, FUNC, REG, VAL) \
196 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_PMU)
198 static struct regmap_config rockchip_regmap_config = {
204 static inline const struct rockchip_pin_group *pinctrl_name_to_group(
205 const struct rockchip_pinctrl *info,
210 for (i = 0; i < info->ngroups; i++) {
211 if (!strcmp(info->groups[i].name, name))
212 return &info->groups[i];
219 * given a pin number that is local to a pin controller, find out the pin bank
220 * and the register base of the pin bank.
222 static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
225 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
227 while (pin >= (b->pin_base + b->nr_pins))
233 static struct rockchip_pin_bank *bank_num_to_bank(
234 struct rockchip_pinctrl *info,
237 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
240 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
241 if (b->bank_num == num)
245 return ERR_PTR(-EINVAL);
249 * Pinctrl_ops handling
252 static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
254 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
256 return info->ngroups;
259 static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
262 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
264 return info->groups[selector].name;
267 static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
268 unsigned selector, const unsigned **pins,
271 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
273 if (selector >= info->ngroups)
276 *pins = info->groups[selector].pins;
277 *npins = info->groups[selector].npins;
282 static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
283 struct device_node *np,
284 struct pinctrl_map **map, unsigned *num_maps)
286 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
287 const struct rockchip_pin_group *grp;
288 struct pinctrl_map *new_map;
289 struct device_node *parent;
294 * first find the group of this node and check if we need to create
295 * config maps for pins
297 grp = pinctrl_name_to_group(info, np->name);
299 dev_err(info->dev, "unable to find group for node %pOFn\n",
304 map_num += grp->npins;
306 new_map = kcalloc(map_num, sizeof(*new_map), GFP_KERNEL);
314 parent = of_get_parent(np);
319 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
320 new_map[0].data.mux.function = parent->name;
321 new_map[0].data.mux.group = np->name;
324 /* create config map */
326 for (i = 0; i < grp->npins; i++) {
327 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
328 new_map[i].data.configs.group_or_pin =
329 pin_get_name(pctldev, grp->pins[i]);
330 new_map[i].data.configs.configs = grp->data[i].configs;
331 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
334 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
335 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
340 static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
341 struct pinctrl_map *map, unsigned num_maps)
346 static const struct pinctrl_ops rockchip_pctrl_ops = {
347 .get_groups_count = rockchip_get_groups_count,
348 .get_group_name = rockchip_get_group_name,
349 .get_group_pins = rockchip_get_group_pins,
350 .dt_node_to_map = rockchip_dt_node_to_map,
351 .dt_free_map = rockchip_dt_free_map,
358 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data[] = {
422 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data[] = {
456 static struct rockchip_mux_recalced_data rk3308_mux_recalced_data[] = {
550 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
572 static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
573 int *reg, u8 *bit, int *mask)
575 struct rockchip_pinctrl *info = bank->drvdata;
576 struct rockchip_pin_ctrl *ctrl = info->ctrl;
577 struct rockchip_mux_recalced_data *data;
580 for (i = 0; i < ctrl->niomux_recalced; i++) {
581 data = &ctrl->iomux_recalced[i];
582 if (data->num == bank->bank_num &&
587 if (i >= ctrl->niomux_recalced)
595 static struct rockchip_mux_route_data px30_mux_route_data[] = {
596 RK_MUXROUTE_SAME(2, RK_PA0, 1, 0x184, BIT(16 + 7)), /* cif-d2m0 */
597 RK_MUXROUTE_SAME(3, RK_PA3, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d2m1 */
598 RK_MUXROUTE_SAME(3, RK_PC6, 2, 0x184, BIT(16 + 8)), /* pdm-m0 */
599 RK_MUXROUTE_SAME(2, RK_PC6, 1, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-m1 */
600 RK_MUXROUTE_SAME(1, RK_PD3, 2, 0x184, BIT(16 + 10)), /* uart2-rxm0 */
601 RK_MUXROUTE_SAME(2, RK_PB6, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-rxm1 */
602 RK_MUXROUTE_SAME(0, RK_PC1, 2, 0x184, BIT(16 + 9)), /* uart3-rxm0 */
603 RK_MUXROUTE_SAME(1, RK_PB7, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rxm1 */
606 static struct rockchip_mux_route_data rk3128_mux_route_data[] = {
607 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x144, BIT(16 + 3) | BIT(16 + 4)), /* spi-0 */
608 RK_MUXROUTE_SAME(1, RK_PD3, 3, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(3)), /* spi-1 */
609 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(4)), /* spi-2 */
610 RK_MUXROUTE_SAME(1, RK_PA5, 1, 0x144, BIT(16 + 5)), /* i2s-0 */
611 RK_MUXROUTE_SAME(0, RK_PB6, 1, 0x144, BIT(16 + 5) | BIT(5)), /* i2s-1 */
612 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x144, BIT(16 + 6)), /* emmc-0 */
613 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x144, BIT(16 + 6) | BIT(6)), /* emmc-1 */
616 static struct rockchip_mux_route_data rk3188_mux_route_data[] = {
617 RK_MUXROUTE_SAME(0, RK_PD0, 1, 0xa0, BIT(16 + 11)), /* non-iomuxed emmc/flash pins on flash-dqs */
618 RK_MUXROUTE_SAME(0, RK_PD0, 2, 0xa0, BIT(16 + 11) | BIT(11)), /* non-iomuxed emmc/flash pins on emmc-clk */
621 static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
622 RK_MUXROUTE_SAME(0, RK_PD2, 1, 0x50, BIT(16)), /* pwm0-0 */
623 RK_MUXROUTE_SAME(3, RK_PC5, 1, 0x50, BIT(16) | BIT(0)), /* pwm0-1 */
624 RK_MUXROUTE_SAME(0, RK_PD3, 1, 0x50, BIT(16 + 1)), /* pwm1-0 */
625 RK_MUXROUTE_SAME(0, RK_PD6, 2, 0x50, BIT(16 + 1) | BIT(1)), /* pwm1-1 */
626 RK_MUXROUTE_SAME(0, RK_PD4, 1, 0x50, BIT(16 + 2)), /* pwm2-0 */
627 RK_MUXROUTE_SAME(1, RK_PB4, 2, 0x50, BIT(16 + 2) | BIT(2)), /* pwm2-1 */
628 RK_MUXROUTE_SAME(3, RK_PD2, 1, 0x50, BIT(16 + 3)), /* pwm3-0 */
629 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 3) | BIT(3)), /* pwm3-1 */
630 RK_MUXROUTE_SAME(1, RK_PA1, 1, 0x50, BIT(16 + 4)), /* sdio-0_d0 */
631 RK_MUXROUTE_SAME(3, RK_PA2, 1, 0x50, BIT(16 + 4) | BIT(4)), /* sdio-1_d0 */
632 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x50, BIT(16 + 5)), /* spi-0_rx */
633 RK_MUXROUTE_SAME(2, RK_PA0, 2, 0x50, BIT(16 + 5) | BIT(5)), /* spi-1_rx */
634 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x50, BIT(16 + 7)), /* emmc-0_cmd */
635 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x50, BIT(16 + 7) | BIT(7)), /* emmc-1_cmd */
636 RK_MUXROUTE_SAME(1, RK_PC3, 2, 0x50, BIT(16 + 8)), /* uart2-0_rx */
637 RK_MUXROUTE_SAME(1, RK_PB2, 2, 0x50, BIT(16 + 8) | BIT(8)), /* uart2-1_rx */
638 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x50, BIT(16 + 11)), /* uart1-0_rx */
639 RK_MUXROUTE_SAME(3, RK_PB5, 1, 0x50, BIT(16 + 11) | BIT(11)), /* uart1-1_rx */
642 static struct rockchip_mux_route_data rk3288_mux_route_data[] = {
643 RK_MUXROUTE_SAME(7, RK_PC0, 2, 0x264, BIT(16 + 12) | BIT(12)), /* edphdmi_cecinoutt1 */
644 RK_MUXROUTE_SAME(7, RK_PC7, 4, 0x264, BIT(16 + 12)), /* edphdmi_cecinout */
647 static struct rockchip_mux_route_data rk3308_mux_route_data[] = {
648 RK_MUXROUTE_SAME(0, RK_PC3, 1, 0x314, BIT(16 + 0) | BIT(0)), /* rtc_clk */
649 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x314, BIT(16 + 2) | BIT(16 + 3)), /* uart2_rxm0 */
650 RK_MUXROUTE_SAME(4, RK_PD2, 2, 0x314, BIT(16 + 2) | BIT(16 + 3) | BIT(2)), /* uart2_rxm1 */
651 RK_MUXROUTE_SAME(0, RK_PB7, 2, 0x608, BIT(16 + 8) | BIT(16 + 9)), /* i2c3_sdam0 */
652 RK_MUXROUTE_SAME(3, RK_PB4, 2, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(8)), /* i2c3_sdam1 */
653 RK_MUXROUTE_SAME(2, RK_PA0, 3, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(9)), /* i2c3_sdam2 */
654 RK_MUXROUTE_SAME(1, RK_PA3, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclktxm0 */
655 RK_MUXROUTE_SAME(1, RK_PA4, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclkrxm0 */
656 RK_MUXROUTE_SAME(1, RK_PB5, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclktxm1 */
657 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclkrxm1 */
658 RK_MUXROUTE_SAME(1, RK_PA4, 3, 0x308, BIT(16 + 12) | BIT(16 + 13)), /* pdm-clkm0 */
659 RK_MUXROUTE_SAME(1, RK_PB6, 4, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* pdm-clkm1 */
660 RK_MUXROUTE_SAME(2, RK_PA6, 2, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* pdm-clkm2 */
661 RK_MUXROUTE_SAME(2, RK_PA4, 3, 0x600, BIT(16 + 2) | BIT(2)), /* pdm-clkm-m2 */
662 RK_MUXROUTE_SAME(3, RK_PB2, 3, 0x314, BIT(16 + 9)), /* spi1_miso */
663 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x314, BIT(16 + 9) | BIT(9)), /* spi1_miso_m1 */
664 RK_MUXROUTE_SAME(0, RK_PB3, 3, 0x314, BIT(16 + 10) | BIT(16 + 11)), /* owire_m0 */
665 RK_MUXROUTE_SAME(1, RK_PC6, 7, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* owire_m1 */
666 RK_MUXROUTE_SAME(2, RK_PA2, 5, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* owire_m2 */
667 RK_MUXROUTE_SAME(0, RK_PB3, 2, 0x314, BIT(16 + 12) | BIT(16 + 13)), /* can_rxd_m0 */
668 RK_MUXROUTE_SAME(1, RK_PC6, 5, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* can_rxd_m1 */
669 RK_MUXROUTE_SAME(2, RK_PA2, 4, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* can_rxd_m2 */
670 RK_MUXROUTE_SAME(1, RK_PC4, 3, 0x314, BIT(16 + 14)), /* mac_rxd0_m0 */
671 RK_MUXROUTE_SAME(4, RK_PA2, 2, 0x314, BIT(16 + 14) | BIT(14)), /* mac_rxd0_m1 */
672 RK_MUXROUTE_SAME(3, RK_PB4, 4, 0x314, BIT(16 + 15)), /* uart3_rx */
673 RK_MUXROUTE_SAME(0, RK_PC1, 3, 0x314, BIT(16 + 15) | BIT(15)), /* uart3_rx_m1 */
676 static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
677 RK_MUXROUTE_SAME(1, RK_PA1, 2, 0x50, BIT(16) | BIT(16 + 1)), /* uart2dbg_rxm0 */
678 RK_MUXROUTE_SAME(2, RK_PA1, 1, 0x50, BIT(16) | BIT(16 + 1) | BIT(0)), /* uart2dbg_rxm1 */
679 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 2) | BIT(2)), /* gmac-m1_rxd0 */
680 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x50, BIT(16 + 10) | BIT(10)), /* gmac-m1-optimized_rxd3 */
681 RK_MUXROUTE_SAME(2, RK_PC3, 2, 0x50, BIT(16 + 3)), /* pdm_sdi0m0 */
682 RK_MUXROUTE_SAME(1, RK_PC7, 3, 0x50, BIT(16 + 3) | BIT(3)), /* pdm_sdi0m1 */
683 RK_MUXROUTE_SAME(3, RK_PA2, 4, 0x50, BIT(16 + 4) | BIT(16 + 5) | BIT(5)), /* spi_rxdm2 */
684 RK_MUXROUTE_SAME(1, RK_PD0, 1, 0x50, BIT(16 + 6)), /* i2s2_sdim0 */
685 RK_MUXROUTE_SAME(3, RK_PA2, 6, 0x50, BIT(16 + 6) | BIT(6)), /* i2s2_sdim1 */
686 RK_MUXROUTE_SAME(2, RK_PC6, 3, 0x50, BIT(16 + 7) | BIT(7)), /* card_iom1 */
687 RK_MUXROUTE_SAME(2, RK_PC0, 3, 0x50, BIT(16 + 8) | BIT(8)), /* tsp_d5m1 */
688 RK_MUXROUTE_SAME(2, RK_PC0, 4, 0x50, BIT(16 + 9) | BIT(9)), /* cif_data5m1 */
691 static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
692 RK_MUXROUTE_SAME(4, RK_PB0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11)), /* uart2dbga_rx */
693 RK_MUXROUTE_SAME(4, RK_PC0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* uart2dbgb_rx */
694 RK_MUXROUTE_SAME(4, RK_PC3, 1, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* uart2dbgc_rx */
695 RK_MUXROUTE_SAME(2, RK_PD2, 2, 0xe21c, BIT(16 + 14)), /* pcie_clkreqn */
696 RK_MUXROUTE_SAME(4, RK_PD0, 1, 0xe21c, BIT(16 + 14) | BIT(14)), /* pcie_clkreqnb */
699 static struct rockchip_mux_route_data rk3568_mux_route_data[] = {
700 RK_MUXROUTE_PMU(0, RK_PB7, 1, 0x0110, WRITE_MASK_VAL(1, 0, 0)), /* PWM0 IO mux M0 */
701 RK_MUXROUTE_PMU(0, RK_PC7, 2, 0x0110, WRITE_MASK_VAL(1, 0, 1)), /* PWM0 IO mux M1 */
702 RK_MUXROUTE_PMU(0, RK_PC0, 1, 0x0110, WRITE_MASK_VAL(3, 2, 0)), /* PWM1 IO mux M0 */
703 RK_MUXROUTE_PMU(0, RK_PB5, 4, 0x0110, WRITE_MASK_VAL(3, 2, 1)), /* PWM1 IO mux M1 */
704 RK_MUXROUTE_PMU(0, RK_PC1, 1, 0x0110, WRITE_MASK_VAL(5, 4, 0)), /* PWM2 IO mux M0 */
705 RK_MUXROUTE_PMU(0, RK_PB6, 4, 0x0110, WRITE_MASK_VAL(5, 4, 1)), /* PWM2 IO mux M1 */
706 RK_MUXROUTE_PMU(0, RK_PB3, 2, 0x0300, WRITE_MASK_VAL(0, 0, 0)), /* CAN0 IO mux M0 */
707 RK_MUXROUTE_GRF(2, RK_PA1, 4, 0x0300, WRITE_MASK_VAL(0, 0, 1)), /* CAN0 IO mux M1 */
708 RK_MUXROUTE_GRF(1, RK_PA1, 3, 0x0300, WRITE_MASK_VAL(2, 2, 0)), /* CAN1 IO mux M0 */
709 RK_MUXROUTE_GRF(4, RK_PC3, 3, 0x0300, WRITE_MASK_VAL(2, 2, 1)), /* CAN1 IO mux M1 */
710 RK_MUXROUTE_GRF(4, RK_PB5, 3, 0x0300, WRITE_MASK_VAL(4, 4, 0)), /* CAN2 IO mux M0 */
711 RK_MUXROUTE_GRF(2, RK_PB2, 4, 0x0300, WRITE_MASK_VAL(4, 4, 1)), /* CAN2 IO mux M1 */
712 RK_MUXROUTE_GRF(4, RK_PC4, 1, 0x0300, WRITE_MASK_VAL(6, 6, 0)), /* HPDIN IO mux M0 */
713 RK_MUXROUTE_PMU(0, RK_PC2, 2, 0x0300, WRITE_MASK_VAL(6, 6, 1)), /* HPDIN IO mux M1 */
714 RK_MUXROUTE_GRF(3, RK_PB1, 3, 0x0300, WRITE_MASK_VAL(8, 8, 0)), /* GMAC1 IO mux M0 */
715 RK_MUXROUTE_GRF(4, RK_PA7, 3, 0x0300, WRITE_MASK_VAL(8, 8, 1)), /* GMAC1 IO mux M1 */
716 RK_MUXROUTE_GRF(4, RK_PD1, 1, 0x0300, WRITE_MASK_VAL(10, 10, 0)), /* HDMITX IO mux M0 */
717 RK_MUXROUTE_PMU(0, RK_PC7, 1, 0x0300, WRITE_MASK_VAL(10, 10, 1)), /* HDMITX IO mux M1 */
718 RK_MUXROUTE_PMU(0, RK_PB6, 1, 0x0300, WRITE_MASK_VAL(14, 14, 0)), /* I2C2 IO mux M0 */
719 RK_MUXROUTE_GRF(4, RK_PB4, 1, 0x0300, WRITE_MASK_VAL(14, 14, 1)), /* I2C2 IO mux M1 */
720 RK_MUXROUTE_GRF(1, RK_PA0, 1, 0x0304, WRITE_MASK_VAL(0, 0, 0)), /* I2C3 IO mux M0 */
721 RK_MUXROUTE_GRF(3, RK_PB6, 4, 0x0304, WRITE_MASK_VAL(0, 0, 1)), /* I2C3 IO mux M1 */
722 RK_MUXROUTE_GRF(4, RK_PB2, 1, 0x0304, WRITE_MASK_VAL(2, 2, 0)), /* I2C4 IO mux M0 */
723 RK_MUXROUTE_GRF(2, RK_PB1, 2, 0x0304, WRITE_MASK_VAL(2, 2, 1)), /* I2C4 IO mux M1 */
724 RK_MUXROUTE_GRF(3, RK_PB4, 4, 0x0304, WRITE_MASK_VAL(4, 4, 0)), /* I2C5 IO mux M0 */
725 RK_MUXROUTE_GRF(4, RK_PD0, 2, 0x0304, WRITE_MASK_VAL(4, 4, 1)), /* I2C5 IO mux M1 */
726 RK_MUXROUTE_GRF(3, RK_PB1, 5, 0x0304, WRITE_MASK_VAL(14, 14, 0)), /* PWM8 IO mux M0 */
727 RK_MUXROUTE_GRF(1, RK_PD5, 4, 0x0304, WRITE_MASK_VAL(14, 14, 1)), /* PWM8 IO mux M1 */
728 RK_MUXROUTE_GRF(3, RK_PB2, 5, 0x0308, WRITE_MASK_VAL(0, 0, 0)), /* PWM9 IO mux M0 */
729 RK_MUXROUTE_GRF(1, RK_PD6, 4, 0x0308, WRITE_MASK_VAL(0, 0, 1)), /* PWM9 IO mux M1 */
730 RK_MUXROUTE_GRF(3, RK_PB5, 5, 0x0308, WRITE_MASK_VAL(2, 2, 0)), /* PWM10 IO mux M0 */
731 RK_MUXROUTE_GRF(2, RK_PA1, 2, 0x0308, WRITE_MASK_VAL(2, 2, 1)), /* PWM10 IO mux M1 */
732 RK_MUXROUTE_GRF(3, RK_PB6, 5, 0x0308, WRITE_MASK_VAL(4, 4, 0)), /* PWM11 IO mux M0 */
733 RK_MUXROUTE_GRF(4, RK_PC0, 3, 0x0308, WRITE_MASK_VAL(4, 4, 1)), /* PWM11 IO mux M1 */
734 RK_MUXROUTE_GRF(3, RK_PB7, 2, 0x0308, WRITE_MASK_VAL(6, 6, 0)), /* PWM12 IO mux M0 */
735 RK_MUXROUTE_GRF(4, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(6, 6, 1)), /* PWM12 IO mux M1 */
736 RK_MUXROUTE_GRF(3, RK_PC0, 2, 0x0308, WRITE_MASK_VAL(8, 8, 0)), /* PWM13 IO mux M0 */
737 RK_MUXROUTE_GRF(4, RK_PC6, 1, 0x0308, WRITE_MASK_VAL(8, 8, 1)), /* PWM13 IO mux M1 */
738 RK_MUXROUTE_GRF(3, RK_PC4, 1, 0x0308, WRITE_MASK_VAL(10, 10, 0)), /* PWM14 IO mux M0 */
739 RK_MUXROUTE_GRF(4, RK_PC2, 1, 0x0308, WRITE_MASK_VAL(10, 10, 1)), /* PWM14 IO mux M1 */
740 RK_MUXROUTE_GRF(3, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(12, 12, 0)), /* PWM15 IO mux M0 */
741 RK_MUXROUTE_GRF(4, RK_PC3, 1, 0x0308, WRITE_MASK_VAL(12, 12, 1)), /* PWM15 IO mux M1 */
742 RK_MUXROUTE_GRF(3, RK_PD2, 3, 0x0308, WRITE_MASK_VAL(14, 14, 0)), /* SDMMC2 IO mux M0 */
743 RK_MUXROUTE_GRF(3, RK_PA5, 5, 0x0308, WRITE_MASK_VAL(14, 14, 1)), /* SDMMC2 IO mux M1 */
744 RK_MUXROUTE_PMU(0, RK_PB5, 2, 0x030c, WRITE_MASK_VAL(0, 0, 0)), /* SPI0 IO mux M0 */
745 RK_MUXROUTE_GRF(2, RK_PD3, 3, 0x030c, WRITE_MASK_VAL(0, 0, 1)), /* SPI0 IO mux M1 */
746 RK_MUXROUTE_GRF(2, RK_PB5, 3, 0x030c, WRITE_MASK_VAL(2, 2, 0)), /* SPI1 IO mux M0 */
747 RK_MUXROUTE_GRF(3, RK_PC3, 3, 0x030c, WRITE_MASK_VAL(2, 2, 1)), /* SPI1 IO mux M1 */
748 RK_MUXROUTE_GRF(2, RK_PC1, 4, 0x030c, WRITE_MASK_VAL(4, 4, 0)), /* SPI2 IO mux M0 */
749 RK_MUXROUTE_GRF(3, RK_PA0, 3, 0x030c, WRITE_MASK_VAL(4, 4, 1)), /* SPI2 IO mux M1 */
750 RK_MUXROUTE_GRF(4, RK_PB3, 4, 0x030c, WRITE_MASK_VAL(6, 6, 0)), /* SPI3 IO mux M0 */
751 RK_MUXROUTE_GRF(4, RK_PC2, 2, 0x030c, WRITE_MASK_VAL(6, 6, 1)), /* SPI3 IO mux M1 */
752 RK_MUXROUTE_GRF(2, RK_PB4, 2, 0x030c, WRITE_MASK_VAL(8, 8, 0)), /* UART1 IO mux M0 */
753 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(8, 8, 1)), /* UART1 IO mux M1 */
754 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(10, 10, 0)), /* UART2 IO mux M0 */
755 RK_MUXROUTE_GRF(1, RK_PD5, 2, 0x030c, WRITE_MASK_VAL(10, 10, 1)), /* UART2 IO mux M1 */
756 RK_MUXROUTE_GRF(1, RK_PA1, 2, 0x030c, WRITE_MASK_VAL(12, 12, 0)), /* UART3 IO mux M0 */
757 RK_MUXROUTE_GRF(3, RK_PB7, 4, 0x030c, WRITE_MASK_VAL(12, 12, 1)), /* UART3 IO mux M1 */
758 RK_MUXROUTE_GRF(1, RK_PA6, 2, 0x030c, WRITE_MASK_VAL(14, 14, 0)), /* UART4 IO mux M0 */
759 RK_MUXROUTE_GRF(3, RK_PB2, 4, 0x030c, WRITE_MASK_VAL(14, 14, 1)), /* UART4 IO mux M1 */
760 RK_MUXROUTE_GRF(2, RK_PA2, 3, 0x0310, WRITE_MASK_VAL(0, 0, 0)), /* UART5 IO mux M0 */
761 RK_MUXROUTE_GRF(3, RK_PC2, 4, 0x0310, WRITE_MASK_VAL(0, 0, 1)), /* UART5 IO mux M1 */
762 RK_MUXROUTE_GRF(2, RK_PA4, 3, 0x0310, WRITE_MASK_VAL(2, 2, 0)), /* UART6 IO mux M0 */
763 RK_MUXROUTE_GRF(1, RK_PD5, 3, 0x0310, WRITE_MASK_VAL(2, 2, 1)), /* UART6 IO mux M1 */
764 RK_MUXROUTE_GRF(2, RK_PA6, 3, 0x0310, WRITE_MASK_VAL(5, 4, 0)), /* UART7 IO mux M0 */
765 RK_MUXROUTE_GRF(3, RK_PC4, 4, 0x0310, WRITE_MASK_VAL(5, 4, 1)), /* UART7 IO mux M1 */
766 RK_MUXROUTE_GRF(4, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(5, 4, 2)), /* UART7 IO mux M2 */
767 RK_MUXROUTE_GRF(2, RK_PC5, 3, 0x0310, WRITE_MASK_VAL(6, 6, 0)), /* UART8 IO mux M0 */
768 RK_MUXROUTE_GRF(2, RK_PD7, 4, 0x0310, WRITE_MASK_VAL(6, 6, 1)), /* UART8 IO mux M1 */
769 RK_MUXROUTE_GRF(2, RK_PB0, 3, 0x0310, WRITE_MASK_VAL(9, 8, 0)), /* UART9 IO mux M0 */
770 RK_MUXROUTE_GRF(4, RK_PC5, 4, 0x0310, WRITE_MASK_VAL(9, 8, 1)), /* UART9 IO mux M1 */
771 RK_MUXROUTE_GRF(4, RK_PA4, 4, 0x0310, WRITE_MASK_VAL(9, 8, 2)), /* UART9 IO mux M2 */
772 RK_MUXROUTE_GRF(1, RK_PA2, 1, 0x0310, WRITE_MASK_VAL(11, 10, 0)), /* I2S1 IO mux M0 */
773 RK_MUXROUTE_GRF(3, RK_PC6, 4, 0x0310, WRITE_MASK_VAL(11, 10, 1)), /* I2S1 IO mux M1 */
774 RK_MUXROUTE_GRF(2, RK_PD0, 5, 0x0310, WRITE_MASK_VAL(11, 10, 2)), /* I2S1 IO mux M2 */
775 RK_MUXROUTE_GRF(2, RK_PC1, 1, 0x0310, WRITE_MASK_VAL(12, 12, 0)), /* I2S2 IO mux M0 */
776 RK_MUXROUTE_GRF(4, RK_PB6, 5, 0x0310, WRITE_MASK_VAL(12, 12, 1)), /* I2S2 IO mux M1 */
777 RK_MUXROUTE_GRF(3, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(14, 14, 0)), /* I2S3 IO mux M0 */
778 RK_MUXROUTE_GRF(4, RK_PC2, 5, 0x0310, WRITE_MASK_VAL(14, 14, 1)), /* I2S3 IO mux M1 */
779 RK_MUXROUTE_GRF(1, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
780 RK_MUXROUTE_GRF(1, RK_PA6, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
781 RK_MUXROUTE_GRF(3, RK_PD6, 5, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
782 RK_MUXROUTE_GRF(4, RK_PA0, 4, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
783 RK_MUXROUTE_GRF(3, RK_PC4, 5, 0x0314, WRITE_MASK_VAL(1, 0, 2)), /* PDM IO mux M2 */
784 RK_MUXROUTE_PMU(0, RK_PA5, 3, 0x0314, WRITE_MASK_VAL(3, 2, 0)), /* PCIE20 IO mux M0 */
785 RK_MUXROUTE_GRF(2, RK_PD0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 1)), /* PCIE20 IO mux M1 */
786 RK_MUXROUTE_GRF(1, RK_PB0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 2)), /* PCIE20 IO mux M2 */
787 RK_MUXROUTE_PMU(0, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux M0 */
788 RK_MUXROUTE_GRF(2, RK_PD2, 4, 0x0314, WRITE_MASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux M1 */
789 RK_MUXROUTE_GRF(1, RK_PA5, 4, 0x0314, WRITE_MASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux M2 */
790 RK_MUXROUTE_PMU(0, RK_PA6, 2, 0x0314, WRITE_MASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux M0 */
791 RK_MUXROUTE_GRF(2, RK_PD4, 4, 0x0314, WRITE_MASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux M1 */
792 RK_MUXROUTE_GRF(4, RK_PC2, 4, 0x0314, WRITE_MASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux M2 */
795 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
796 int mux, u32 *loc, u32 *reg, u32 *value)
798 struct rockchip_pinctrl *info = bank->drvdata;
799 struct rockchip_pin_ctrl *ctrl = info->ctrl;
800 struct rockchip_mux_route_data *data;
803 for (i = 0; i < ctrl->niomux_routes; i++) {
804 data = &ctrl->iomux_routes[i];
805 if ((data->bank_num == bank->bank_num) &&
806 (data->pin == pin) && (data->func == mux))
810 if (i >= ctrl->niomux_routes)
813 *loc = data->route_location;
814 *reg = data->route_offset;
815 *value = data->route_val;
820 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
822 struct rockchip_pinctrl *info = bank->drvdata;
823 int iomux_num = (pin / 8);
824 struct regmap *regmap;
826 int reg, ret, mask, mux_type;
832 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
833 dev_err(info->dev, "pin %d is unrouted\n", pin);
837 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
840 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
841 ? info->regmap_pmu : info->regmap_base;
843 /* get basic quadrupel of mux registers and the correct reg inside */
844 mux_type = bank->iomux[iomux_num].type;
845 reg = bank->iomux[iomux_num].offset;
846 if (mux_type & IOMUX_WIDTH_4BIT) {
851 } else if (mux_type & IOMUX_WIDTH_3BIT) {
854 bit = (pin % 8 % 5) * 3;
861 if (bank->recalced_mask & BIT(pin))
862 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
864 ret = regmap_read(regmap, reg, &val);
868 return ((val >> bit) & mask);
871 static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
874 struct rockchip_pinctrl *info = bank->drvdata;
875 int iomux_num = (pin / 8);
880 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
881 dev_err(info->dev, "pin %d is unrouted\n", pin);
885 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
886 if (mux != RK_FUNC_GPIO) {
888 "pin %d only supports a gpio mux\n", pin);
897 * Set a new mux function for a pin.
899 * The register is divided into the upper and lower 16 bit. When changing
900 * a value, the previous register value is not read and changed. Instead
901 * it seems the changed bits are marked in the upper 16 bit, while the
902 * changed value gets set in the same offset in the lower 16 bit.
903 * All pin settings seem to be 2 bit wide in both the upper and lower
905 * @bank: pin bank to change
906 * @pin: pin to change
907 * @mux: new mux function to set
909 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
911 struct rockchip_pinctrl *info = bank->drvdata;
912 int iomux_num = (pin / 8);
913 struct regmap *regmap;
914 int reg, ret, mask, mux_type;
916 u32 data, rmask, route_location, route_reg, route_val;
918 ret = rockchip_verify_mux(bank, pin, mux);
922 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
925 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
926 bank->bank_num, pin, mux);
928 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
929 ? info->regmap_pmu : info->regmap_base;
931 /* get basic quadrupel of mux registers and the correct reg inside */
932 mux_type = bank->iomux[iomux_num].type;
933 reg = bank->iomux[iomux_num].offset;
934 if (mux_type & IOMUX_WIDTH_4BIT) {
939 } else if (mux_type & IOMUX_WIDTH_3BIT) {
942 bit = (pin % 8 % 5) * 3;
949 if (bank->recalced_mask & BIT(pin))
950 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
952 if (bank->route_mask & BIT(pin)) {
953 if (rockchip_get_mux_route(bank, pin, mux, &route_location,
954 &route_reg, &route_val)) {
955 struct regmap *route_regmap = regmap;
957 /* handle special locations */
958 switch (route_location) {
959 case ROCKCHIP_ROUTE_PMU:
960 route_regmap = info->regmap_pmu;
962 case ROCKCHIP_ROUTE_GRF:
963 route_regmap = info->regmap_base;
967 ret = regmap_write(route_regmap, route_reg, route_val);
973 data = (mask << (bit + 16));
974 rmask = data | (data >> 16);
975 data |= (mux & mask) << bit;
976 ret = regmap_update_bits(regmap, reg, rmask, data);
981 #define PX30_PULL_PMU_OFFSET 0x10
982 #define PX30_PULL_GRF_OFFSET 0x60
983 #define PX30_PULL_BITS_PER_PIN 2
984 #define PX30_PULL_PINS_PER_REG 8
985 #define PX30_PULL_BANK_STRIDE 16
987 static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
988 int pin_num, struct regmap **regmap,
991 struct rockchip_pinctrl *info = bank->drvdata;
993 /* The first 32 pins of the first bank are located in PMU */
994 if (bank->bank_num == 0) {
995 *regmap = info->regmap_pmu;
996 *reg = PX30_PULL_PMU_OFFSET;
998 *regmap = info->regmap_base;
999 *reg = PX30_PULL_GRF_OFFSET;
1001 /* correct the offset, as we're starting with the 2nd bank */
1003 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE;
1006 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4);
1007 *bit = (pin_num % PX30_PULL_PINS_PER_REG);
1008 *bit *= PX30_PULL_BITS_PER_PIN;
1011 #define PX30_DRV_PMU_OFFSET 0x20
1012 #define PX30_DRV_GRF_OFFSET 0xf0
1013 #define PX30_DRV_BITS_PER_PIN 2
1014 #define PX30_DRV_PINS_PER_REG 8
1015 #define PX30_DRV_BANK_STRIDE 16
1017 static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1018 int pin_num, struct regmap **regmap,
1021 struct rockchip_pinctrl *info = bank->drvdata;
1023 /* The first 32 pins of the first bank are located in PMU */
1024 if (bank->bank_num == 0) {
1025 *regmap = info->regmap_pmu;
1026 *reg = PX30_DRV_PMU_OFFSET;
1028 *regmap = info->regmap_base;
1029 *reg = PX30_DRV_GRF_OFFSET;
1031 /* correct the offset, as we're starting with the 2nd bank */
1033 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE;
1036 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4);
1037 *bit = (pin_num % PX30_DRV_PINS_PER_REG);
1038 *bit *= PX30_DRV_BITS_PER_PIN;
1041 #define PX30_SCHMITT_PMU_OFFSET 0x38
1042 #define PX30_SCHMITT_GRF_OFFSET 0xc0
1043 #define PX30_SCHMITT_PINS_PER_PMU_REG 16
1044 #define PX30_SCHMITT_BANK_STRIDE 16
1045 #define PX30_SCHMITT_PINS_PER_GRF_REG 8
1047 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1049 struct regmap **regmap,
1052 struct rockchip_pinctrl *info = bank->drvdata;
1055 if (bank->bank_num == 0) {
1056 *regmap = info->regmap_pmu;
1057 *reg = PX30_SCHMITT_PMU_OFFSET;
1058 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG;
1060 *regmap = info->regmap_base;
1061 *reg = PX30_SCHMITT_GRF_OFFSET;
1062 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG;
1063 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE;
1066 *reg += ((pin_num / pins_per_reg) * 4);
1067 *bit = pin_num % pins_per_reg;
1072 #define RV1108_PULL_PMU_OFFSET 0x10
1073 #define RV1108_PULL_OFFSET 0x110
1074 #define RV1108_PULL_PINS_PER_REG 8
1075 #define RV1108_PULL_BITS_PER_PIN 2
1076 #define RV1108_PULL_BANK_STRIDE 16
1078 static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1079 int pin_num, struct regmap **regmap,
1082 struct rockchip_pinctrl *info = bank->drvdata;
1084 /* The first 24 pins of the first bank are located in PMU */
1085 if (bank->bank_num == 0) {
1086 *regmap = info->regmap_pmu;
1087 *reg = RV1108_PULL_PMU_OFFSET;
1089 *reg = RV1108_PULL_OFFSET;
1090 *regmap = info->regmap_base;
1091 /* correct the offset, as we're starting with the 2nd bank */
1093 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
1096 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1097 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1098 *bit *= RV1108_PULL_BITS_PER_PIN;
1101 #define RV1108_DRV_PMU_OFFSET 0x20
1102 #define RV1108_DRV_GRF_OFFSET 0x210
1103 #define RV1108_DRV_BITS_PER_PIN 2
1104 #define RV1108_DRV_PINS_PER_REG 8
1105 #define RV1108_DRV_BANK_STRIDE 16
1107 static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1108 int pin_num, struct regmap **regmap,
1111 struct rockchip_pinctrl *info = bank->drvdata;
1113 /* The first 24 pins of the first bank are located in PMU */
1114 if (bank->bank_num == 0) {
1115 *regmap = info->regmap_pmu;
1116 *reg = RV1108_DRV_PMU_OFFSET;
1118 *regmap = info->regmap_base;
1119 *reg = RV1108_DRV_GRF_OFFSET;
1121 /* correct the offset, as we're starting with the 2nd bank */
1123 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
1126 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1127 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1128 *bit *= RV1108_DRV_BITS_PER_PIN;
1131 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1132 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1133 #define RV1108_SCHMITT_BANK_STRIDE 8
1134 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1135 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1137 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1139 struct regmap **regmap,
1142 struct rockchip_pinctrl *info = bank->drvdata;
1145 if (bank->bank_num == 0) {
1146 *regmap = info->regmap_pmu;
1147 *reg = RV1108_SCHMITT_PMU_OFFSET;
1148 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1150 *regmap = info->regmap_base;
1151 *reg = RV1108_SCHMITT_GRF_OFFSET;
1152 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1153 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1155 *reg += ((pin_num / pins_per_reg) * 4);
1156 *bit = pin_num % pins_per_reg;
1161 #define RK3308_SCHMITT_PINS_PER_REG 8
1162 #define RK3308_SCHMITT_BANK_STRIDE 16
1163 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0
1165 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1166 int pin_num, struct regmap **regmap,
1169 struct rockchip_pinctrl *info = bank->drvdata;
1171 *regmap = info->regmap_base;
1172 *reg = RK3308_SCHMITT_GRF_OFFSET;
1174 *reg += bank->bank_num * RK3308_SCHMITT_BANK_STRIDE;
1175 *reg += ((pin_num / RK3308_SCHMITT_PINS_PER_REG) * 4);
1176 *bit = pin_num % RK3308_SCHMITT_PINS_PER_REG;
1181 #define RK2928_PULL_OFFSET 0x118
1182 #define RK2928_PULL_PINS_PER_REG 16
1183 #define RK2928_PULL_BANK_STRIDE 8
1185 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1186 int pin_num, struct regmap **regmap,
1189 struct rockchip_pinctrl *info = bank->drvdata;
1191 *regmap = info->regmap_base;
1192 *reg = RK2928_PULL_OFFSET;
1193 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1194 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1196 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1199 #define RK3128_PULL_OFFSET 0x118
1201 static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1202 int pin_num, struct regmap **regmap,
1205 struct rockchip_pinctrl *info = bank->drvdata;
1207 *regmap = info->regmap_base;
1208 *reg = RK3128_PULL_OFFSET;
1209 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1210 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1212 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1215 #define RK3188_PULL_OFFSET 0x164
1216 #define RK3188_PULL_BITS_PER_PIN 2
1217 #define RK3188_PULL_PINS_PER_REG 8
1218 #define RK3188_PULL_BANK_STRIDE 16
1219 #define RK3188_PULL_PMU_OFFSET 0x64
1221 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1222 int pin_num, struct regmap **regmap,
1225 struct rockchip_pinctrl *info = bank->drvdata;
1227 /* The first 12 pins of the first bank are located elsewhere */
1228 if (bank->bank_num == 0 && pin_num < 12) {
1229 *regmap = info->regmap_pmu ? info->regmap_pmu
1230 : bank->regmap_pull;
1231 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
1232 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1233 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1234 *bit *= RK3188_PULL_BITS_PER_PIN;
1236 *regmap = info->regmap_pull ? info->regmap_pull
1237 : info->regmap_base;
1238 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1240 /* correct the offset, as it is the 2nd pull register */
1242 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1243 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1246 * The bits in these registers have an inverse ordering
1247 * with the lowest pin being in bits 15:14 and the highest
1250 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1251 *bit *= RK3188_PULL_BITS_PER_PIN;
1255 #define RK3288_PULL_OFFSET 0x140
1256 static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1257 int pin_num, struct regmap **regmap,
1260 struct rockchip_pinctrl *info = bank->drvdata;
1262 /* The first 24 pins of the first bank are located in PMU */
1263 if (bank->bank_num == 0) {
1264 *regmap = info->regmap_pmu;
1265 *reg = RK3188_PULL_PMU_OFFSET;
1267 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1268 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1269 *bit *= RK3188_PULL_BITS_PER_PIN;
1271 *regmap = info->regmap_base;
1272 *reg = RK3288_PULL_OFFSET;
1274 /* correct the offset, as we're starting with the 2nd bank */
1276 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1277 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1279 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1280 *bit *= RK3188_PULL_BITS_PER_PIN;
1284 #define RK3288_DRV_PMU_OFFSET 0x70
1285 #define RK3288_DRV_GRF_OFFSET 0x1c0
1286 #define RK3288_DRV_BITS_PER_PIN 2
1287 #define RK3288_DRV_PINS_PER_REG 8
1288 #define RK3288_DRV_BANK_STRIDE 16
1290 static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1291 int pin_num, struct regmap **regmap,
1294 struct rockchip_pinctrl *info = bank->drvdata;
1296 /* The first 24 pins of the first bank are located in PMU */
1297 if (bank->bank_num == 0) {
1298 *regmap = info->regmap_pmu;
1299 *reg = RK3288_DRV_PMU_OFFSET;
1301 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1302 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1303 *bit *= RK3288_DRV_BITS_PER_PIN;
1305 *regmap = info->regmap_base;
1306 *reg = RK3288_DRV_GRF_OFFSET;
1308 /* correct the offset, as we're starting with the 2nd bank */
1310 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1311 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1313 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1314 *bit *= RK3288_DRV_BITS_PER_PIN;
1318 #define RK3228_PULL_OFFSET 0x100
1320 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1321 int pin_num, struct regmap **regmap,
1324 struct rockchip_pinctrl *info = bank->drvdata;
1326 *regmap = info->regmap_base;
1327 *reg = RK3228_PULL_OFFSET;
1328 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1329 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1331 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1332 *bit *= RK3188_PULL_BITS_PER_PIN;
1335 #define RK3228_DRV_GRF_OFFSET 0x200
1337 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1338 int pin_num, struct regmap **regmap,
1341 struct rockchip_pinctrl *info = bank->drvdata;
1343 *regmap = info->regmap_base;
1344 *reg = RK3228_DRV_GRF_OFFSET;
1345 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1346 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1348 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1349 *bit *= RK3288_DRV_BITS_PER_PIN;
1352 #define RK3308_PULL_OFFSET 0xa0
1354 static void rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1355 int pin_num, struct regmap **regmap,
1358 struct rockchip_pinctrl *info = bank->drvdata;
1360 *regmap = info->regmap_base;
1361 *reg = RK3308_PULL_OFFSET;
1362 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1363 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1365 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1366 *bit *= RK3188_PULL_BITS_PER_PIN;
1369 #define RK3308_DRV_GRF_OFFSET 0x100
1371 static void rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1372 int pin_num, struct regmap **regmap,
1375 struct rockchip_pinctrl *info = bank->drvdata;
1377 *regmap = info->regmap_base;
1378 *reg = RK3308_DRV_GRF_OFFSET;
1379 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1380 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1382 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1383 *bit *= RK3288_DRV_BITS_PER_PIN;
1386 #define RK3368_PULL_GRF_OFFSET 0x100
1387 #define RK3368_PULL_PMU_OFFSET 0x10
1389 static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1390 int pin_num, struct regmap **regmap,
1393 struct rockchip_pinctrl *info = bank->drvdata;
1395 /* The first 32 pins of the first bank are located in PMU */
1396 if (bank->bank_num == 0) {
1397 *regmap = info->regmap_pmu;
1398 *reg = RK3368_PULL_PMU_OFFSET;
1400 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1401 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1402 *bit *= RK3188_PULL_BITS_PER_PIN;
1404 *regmap = info->regmap_base;
1405 *reg = RK3368_PULL_GRF_OFFSET;
1407 /* correct the offset, as we're starting with the 2nd bank */
1409 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1410 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1412 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1413 *bit *= RK3188_PULL_BITS_PER_PIN;
1417 #define RK3368_DRV_PMU_OFFSET 0x20
1418 #define RK3368_DRV_GRF_OFFSET 0x200
1420 static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1421 int pin_num, struct regmap **regmap,
1424 struct rockchip_pinctrl *info = bank->drvdata;
1426 /* The first 32 pins of the first bank are located in PMU */
1427 if (bank->bank_num == 0) {
1428 *regmap = info->regmap_pmu;
1429 *reg = RK3368_DRV_PMU_OFFSET;
1431 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1432 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1433 *bit *= RK3288_DRV_BITS_PER_PIN;
1435 *regmap = info->regmap_base;
1436 *reg = RK3368_DRV_GRF_OFFSET;
1438 /* correct the offset, as we're starting with the 2nd bank */
1440 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1441 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1443 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1444 *bit *= RK3288_DRV_BITS_PER_PIN;
1448 #define RK3399_PULL_GRF_OFFSET 0xe040
1449 #define RK3399_PULL_PMU_OFFSET 0x40
1450 #define RK3399_DRV_3BITS_PER_PIN 3
1452 static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1453 int pin_num, struct regmap **regmap,
1456 struct rockchip_pinctrl *info = bank->drvdata;
1458 /* The bank0:16 and bank1:32 pins are located in PMU */
1459 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1460 *regmap = info->regmap_pmu;
1461 *reg = RK3399_PULL_PMU_OFFSET;
1463 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1465 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1466 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1467 *bit *= RK3188_PULL_BITS_PER_PIN;
1469 *regmap = info->regmap_base;
1470 *reg = RK3399_PULL_GRF_OFFSET;
1472 /* correct the offset, as we're starting with the 3rd bank */
1474 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1475 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1477 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1478 *bit *= RK3188_PULL_BITS_PER_PIN;
1482 static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1483 int pin_num, struct regmap **regmap,
1486 struct rockchip_pinctrl *info = bank->drvdata;
1487 int drv_num = (pin_num / 8);
1489 /* The bank0:16 and bank1:32 pins are located in PMU */
1490 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1491 *regmap = info->regmap_pmu;
1493 *regmap = info->regmap_base;
1495 *reg = bank->drv[drv_num].offset;
1496 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1497 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1498 *bit = (pin_num % 8) * 3;
1500 *bit = (pin_num % 8) * 2;
1503 #define RK3568_PULL_PMU_OFFSET 0x20
1504 #define RK3568_PULL_GRF_OFFSET 0x80
1505 #define RK3568_PULL_BITS_PER_PIN 2
1506 #define RK3568_PULL_PINS_PER_REG 8
1507 #define RK3568_PULL_BANK_STRIDE 0x10
1509 static void rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1510 int pin_num, struct regmap **regmap,
1513 struct rockchip_pinctrl *info = bank->drvdata;
1515 if (bank->bank_num == 0) {
1516 *regmap = info->regmap_pmu;
1517 *reg = RK3568_PULL_PMU_OFFSET;
1518 *reg += bank->bank_num * RK3568_PULL_BANK_STRIDE;
1519 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1521 *bit = pin_num % RK3568_PULL_PINS_PER_REG;
1522 *bit *= RK3568_PULL_BITS_PER_PIN;
1524 *regmap = info->regmap_base;
1525 *reg = RK3568_PULL_GRF_OFFSET;
1526 *reg += (bank->bank_num - 1) * RK3568_PULL_BANK_STRIDE;
1527 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1529 *bit = (pin_num % RK3568_PULL_PINS_PER_REG);
1530 *bit *= RK3568_PULL_BITS_PER_PIN;
1534 #define RK3568_DRV_PMU_OFFSET 0x70
1535 #define RK3568_DRV_GRF_OFFSET 0x200
1536 #define RK3568_DRV_BITS_PER_PIN 8
1537 #define RK3568_DRV_PINS_PER_REG 2
1538 #define RK3568_DRV_BANK_STRIDE 0x40
1540 static void rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1541 int pin_num, struct regmap **regmap,
1544 struct rockchip_pinctrl *info = bank->drvdata;
1546 /* The first 32 pins of the first bank are located in PMU */
1547 if (bank->bank_num == 0) {
1548 *regmap = info->regmap_pmu;
1549 *reg = RK3568_DRV_PMU_OFFSET;
1550 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1552 *bit = pin_num % RK3568_DRV_PINS_PER_REG;
1553 *bit *= RK3568_DRV_BITS_PER_PIN;
1555 *regmap = info->regmap_base;
1556 *reg = RK3568_DRV_GRF_OFFSET;
1557 *reg += (bank->bank_num - 1) * RK3568_DRV_BANK_STRIDE;
1558 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1560 *bit = (pin_num % RK3568_DRV_PINS_PER_REG);
1561 *bit *= RK3568_DRV_BITS_PER_PIN;
1565 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1566 { 2, 4, 8, 12, -1, -1, -1, -1 },
1567 { 3, 6, 9, 12, -1, -1, -1, -1 },
1568 { 5, 10, 15, 20, -1, -1, -1, -1 },
1569 { 4, 6, 8, 10, 12, 14, 16, 18 },
1570 { 4, 7, 10, 13, 16, 19, 22, 26 }
1573 static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1576 struct rockchip_pinctrl *info = bank->drvdata;
1577 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1578 struct regmap *regmap;
1580 u32 data, temp, rmask_bits;
1582 int drv_type = bank->drv[pin_num / 8].drv_type;
1584 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1587 case DRV_TYPE_IO_1V8_3V0_AUTO:
1588 case DRV_TYPE_IO_3V3_ONLY:
1589 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1592 /* regular case, nothing to do */
1596 * drive-strength offset is special, as it is
1597 * spread over 2 registers
1599 ret = regmap_read(regmap, reg, &data);
1603 ret = regmap_read(regmap, reg + 0x4, &temp);
1608 * the bit data[15] contains bit 0 of the value
1609 * while temp[1:0] contains bits 2 and 1
1616 return rockchip_perpin_drv_list[drv_type][data];
1618 /* setting fully enclosed in the second register */
1623 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1629 case DRV_TYPE_IO_DEFAULT:
1630 case DRV_TYPE_IO_1V8_OR_3V0:
1631 case DRV_TYPE_IO_1V8_ONLY:
1632 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1635 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1640 ret = regmap_read(regmap, reg, &data);
1645 data &= (1 << rmask_bits) - 1;
1647 return rockchip_perpin_drv_list[drv_type][data];
1650 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1651 int pin_num, int strength)
1653 struct rockchip_pinctrl *info = bank->drvdata;
1654 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1655 struct regmap *regmap;
1657 u32 data, rmask, rmask_bits, temp;
1659 int drv_type = bank->drv[pin_num / 8].drv_type;
1661 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1662 bank->bank_num, pin_num, strength);
1664 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1665 if (ctrl->type == RK3568) {
1666 rmask_bits = RK3568_DRV_BITS_PER_PIN;
1667 ret = (1 << (strength + 1)) - 1;
1672 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1673 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
1676 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1677 ret = rockchip_perpin_drv_list[drv_type][i];
1683 dev_err(info->dev, "unsupported driver strength %d\n",
1689 case DRV_TYPE_IO_1V8_3V0_AUTO:
1690 case DRV_TYPE_IO_3V3_ONLY:
1691 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1694 /* regular case, nothing to do */
1698 * drive-strength offset is special, as it is spread
1699 * over 2 registers, the bit data[15] contains bit 0
1700 * of the value while temp[1:0] contains bits 2 and 1
1702 data = (ret & 0x1) << 15;
1703 temp = (ret >> 0x1) & 0x3;
1705 rmask = BIT(15) | BIT(31);
1707 ret = regmap_update_bits(regmap, reg, rmask, data);
1711 rmask = 0x3 | (0x3 << 16);
1712 temp |= (0x3 << 16);
1714 ret = regmap_update_bits(regmap, reg, rmask, temp);
1718 /* setting fully enclosed in the second register */
1723 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1728 case DRV_TYPE_IO_DEFAULT:
1729 case DRV_TYPE_IO_1V8_OR_3V0:
1730 case DRV_TYPE_IO_1V8_ONLY:
1731 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1734 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1740 /* enable the write to the equivalent lower bits */
1741 data = ((1 << rmask_bits) - 1) << (bit + 16);
1742 rmask = data | (data >> 16);
1743 data |= (ret << bit);
1745 ret = regmap_update_bits(regmap, reg, rmask, data);
1750 static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1752 PIN_CONFIG_BIAS_DISABLE,
1753 PIN_CONFIG_BIAS_PULL_UP,
1754 PIN_CONFIG_BIAS_PULL_DOWN,
1755 PIN_CONFIG_BIAS_BUS_HOLD
1758 PIN_CONFIG_BIAS_DISABLE,
1759 PIN_CONFIG_BIAS_PULL_DOWN,
1760 PIN_CONFIG_BIAS_DISABLE,
1761 PIN_CONFIG_BIAS_PULL_UP
1765 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1767 struct rockchip_pinctrl *info = bank->drvdata;
1768 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1769 struct regmap *regmap;
1770 int reg, ret, pull_type;
1774 /* rk3066b does support any pulls */
1775 if (ctrl->type == RK3066B)
1776 return PIN_CONFIG_BIAS_DISABLE;
1778 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1780 ret = regmap_read(regmap, reg, &data);
1784 switch (ctrl->type) {
1787 return !(data & BIT(bit))
1788 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1789 : PIN_CONFIG_BIAS_DISABLE;
1797 pull_type = bank->pull_type[pin_num / 8];
1799 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1801 return rockchip_pull_list[pull_type][data];
1803 dev_err(info->dev, "unsupported pinctrl type\n");
1808 static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1809 int pin_num, int pull)
1811 struct rockchip_pinctrl *info = bank->drvdata;
1812 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1813 struct regmap *regmap;
1814 int reg, ret, i, pull_type;
1818 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
1819 bank->bank_num, pin_num, pull);
1821 /* rk3066b does support any pulls */
1822 if (ctrl->type == RK3066B)
1823 return pull ? -EINVAL : 0;
1825 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1827 switch (ctrl->type) {
1830 data = BIT(bit + 16);
1831 if (pull == PIN_CONFIG_BIAS_DISABLE)
1833 ret = regmap_write(regmap, reg, data);
1843 pull_type = bank->pull_type[pin_num / 8];
1845 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
1847 if (rockchip_pull_list[pull_type][i] == pull) {
1853 * In the TRM, pull-up being 1 for everything except the GPIO0_D0-D6,
1854 * where that pull up value becomes 3.
1856 if (ctrl->type == RK3568 && bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) {
1862 dev_err(info->dev, "unsupported pull setting %d\n",
1867 /* enable the write to the equivalent lower bits */
1868 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
1869 rmask = data | (data >> 16);
1870 data |= (ret << bit);
1872 ret = regmap_update_bits(regmap, reg, rmask, data);
1875 dev_err(info->dev, "unsupported pinctrl type\n");
1882 #define RK3328_SCHMITT_BITS_PER_PIN 1
1883 #define RK3328_SCHMITT_PINS_PER_REG 16
1884 #define RK3328_SCHMITT_BANK_STRIDE 8
1885 #define RK3328_SCHMITT_GRF_OFFSET 0x380
1887 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1889 struct regmap **regmap,
1892 struct rockchip_pinctrl *info = bank->drvdata;
1894 *regmap = info->regmap_base;
1895 *reg = RK3328_SCHMITT_GRF_OFFSET;
1897 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
1898 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
1899 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
1904 #define RK3568_SCHMITT_BITS_PER_PIN 2
1905 #define RK3568_SCHMITT_PINS_PER_REG 8
1906 #define RK3568_SCHMITT_BANK_STRIDE 0x10
1907 #define RK3568_SCHMITT_GRF_OFFSET 0xc0
1908 #define RK3568_SCHMITT_PMUGRF_OFFSET 0x30
1910 static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1912 struct regmap **regmap,
1915 struct rockchip_pinctrl *info = bank->drvdata;
1917 if (bank->bank_num == 0) {
1918 *regmap = info->regmap_pmu;
1919 *reg = RK3568_SCHMITT_PMUGRF_OFFSET;
1921 *regmap = info->regmap_base;
1922 *reg = RK3568_SCHMITT_GRF_OFFSET;
1923 *reg += (bank->bank_num - 1) * RK3568_SCHMITT_BANK_STRIDE;
1926 *reg += ((pin_num / RK3568_SCHMITT_PINS_PER_REG) * 4);
1927 *bit = pin_num % RK3568_SCHMITT_PINS_PER_REG;
1928 *bit *= RK3568_SCHMITT_BITS_PER_PIN;
1933 static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
1935 struct rockchip_pinctrl *info = bank->drvdata;
1936 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1937 struct regmap *regmap;
1942 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1946 ret = regmap_read(regmap, reg, &data);
1951 switch (ctrl->type) {
1953 return data & ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1);
1961 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
1962 int pin_num, int enable)
1964 struct rockchip_pinctrl *info = bank->drvdata;
1965 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1966 struct regmap *regmap;
1971 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
1972 bank->bank_num, pin_num, enable);
1974 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1978 /* enable the write to the equivalent lower bits */
1979 switch (ctrl->type) {
1981 data = ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1) << (bit + 16);
1982 rmask = data | (data >> 16);
1983 data |= ((enable ? 0x2 : 0x1) << bit);
1986 data = BIT(bit + 16) | (enable << bit);
1987 rmask = BIT(bit + 16) | BIT(bit);
1991 return regmap_update_bits(regmap, reg, rmask, data);
1995 * Pinmux_ops handling
1998 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
2000 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2002 return info->nfunctions;
2005 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
2008 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2010 return info->functions[selector].name;
2013 static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
2014 unsigned selector, const char * const **groups,
2015 unsigned * const num_groups)
2017 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2019 *groups = info->functions[selector].groups;
2020 *num_groups = info->functions[selector].ngroups;
2025 static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
2028 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2029 const unsigned int *pins = info->groups[group].pins;
2030 const struct rockchip_pin_config *data = info->groups[group].data;
2031 struct rockchip_pin_bank *bank;
2034 dev_dbg(info->dev, "enable function %s group %s\n",
2035 info->functions[selector].name, info->groups[group].name);
2038 * for each pin in the pin group selected, program the corresponding
2039 * pin function number in the config register.
2041 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
2042 bank = pin_to_bank(info, pins[cnt]);
2043 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
2050 /* revert the already done pin settings */
2051 for (cnt--; cnt >= 0; cnt--)
2052 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
2060 static const struct pinmux_ops rockchip_pmx_ops = {
2061 .get_functions_count = rockchip_pmx_get_funcs_count,
2062 .get_function_name = rockchip_pmx_get_func_name,
2063 .get_function_groups = rockchip_pmx_get_groups,
2064 .set_mux = rockchip_pmx_set,
2068 * Pinconf_ops handling
2071 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2072 enum pin_config_param pull)
2074 switch (ctrl->type) {
2077 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2078 pull == PIN_CONFIG_BIAS_DISABLE);
2080 return pull ? false : true;
2089 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
2095 /* set the pin config settings for a specified pin */
2096 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2097 unsigned long *configs, unsigned num_configs)
2099 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2100 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2101 struct gpio_chip *gpio = &bank->gpio_chip;
2102 enum pin_config_param param;
2107 for (i = 0; i < num_configs; i++) {
2108 param = pinconf_to_config_param(configs[i]);
2109 arg = pinconf_to_config_argument(configs[i]);
2112 case PIN_CONFIG_BIAS_DISABLE:
2113 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2118 case PIN_CONFIG_BIAS_PULL_UP:
2119 case PIN_CONFIG_BIAS_PULL_DOWN:
2120 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2121 case PIN_CONFIG_BIAS_BUS_HOLD:
2122 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2128 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2133 case PIN_CONFIG_OUTPUT:
2134 rc = rockchip_set_mux(bank, pin - bank->pin_base,
2136 if (rc != RK_FUNC_GPIO)
2139 rc = gpio->direction_output(gpio, pin - bank->pin_base,
2144 case PIN_CONFIG_DRIVE_STRENGTH:
2145 /* rk3288 is the first with per-pin drive-strength */
2146 if (!info->ctrl->drv_calc_reg)
2149 rc = rockchip_set_drive_perpin(bank,
2150 pin - bank->pin_base, arg);
2154 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2155 if (!info->ctrl->schmitt_calc_reg)
2158 rc = rockchip_set_schmitt(bank,
2159 pin - bank->pin_base, arg);
2167 } /* for each config */
2172 /* get the pin config settings for a specified pin */
2173 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2174 unsigned long *config)
2176 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2177 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2178 struct gpio_chip *gpio = &bank->gpio_chip;
2179 enum pin_config_param param = pinconf_to_config_param(*config);
2184 case PIN_CONFIG_BIAS_DISABLE:
2185 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2190 case PIN_CONFIG_BIAS_PULL_UP:
2191 case PIN_CONFIG_BIAS_PULL_DOWN:
2192 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2193 case PIN_CONFIG_BIAS_BUS_HOLD:
2194 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2197 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2202 case PIN_CONFIG_OUTPUT:
2203 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2204 if (rc != RK_FUNC_GPIO)
2207 rc = gpio->get(gpio, pin - bank->pin_base);
2213 case PIN_CONFIG_DRIVE_STRENGTH:
2214 /* rk3288 is the first with per-pin drive-strength */
2215 if (!info->ctrl->drv_calc_reg)
2218 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
2224 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2225 if (!info->ctrl->schmitt_calc_reg)
2228 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2239 *config = pinconf_to_config_packed(param, arg);
2244 static const struct pinconf_ops rockchip_pinconf_ops = {
2245 .pin_config_get = rockchip_pinconf_get,
2246 .pin_config_set = rockchip_pinconf_set,
2250 static const struct of_device_id rockchip_bank_match[] = {
2251 { .compatible = "rockchip,gpio-bank" },
2252 { .compatible = "rockchip,rk3188-gpio-bank0" },
2256 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2257 struct device_node *np)
2259 struct device_node *child;
2261 for_each_child_of_node(np, child) {
2262 if (of_match_node(rockchip_bank_match, child))
2266 info->ngroups += of_get_child_count(child);
2270 static int rockchip_pinctrl_parse_groups(struct device_node *np,
2271 struct rockchip_pin_group *grp,
2272 struct rockchip_pinctrl *info,
2275 struct rockchip_pin_bank *bank;
2282 dev_dbg(info->dev, "group(%d): %pOFn\n", index, np);
2284 /* Initialise group */
2285 grp->name = np->name;
2288 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2289 * do sanity check and calculate pins number
2291 list = of_get_property(np, "rockchip,pins", &size);
2292 /* we do not check return since it's safe node passed down */
2293 size /= sizeof(*list);
2294 if (!size || size % 4) {
2295 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2299 grp->npins = size / 4;
2301 grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int),
2303 grp->data = devm_kcalloc(info->dev,
2305 sizeof(struct rockchip_pin_config),
2307 if (!grp->pins || !grp->data)
2310 for (i = 0, j = 0; i < size; i += 4, j++) {
2311 const __be32 *phandle;
2312 struct device_node *np_config;
2314 num = be32_to_cpu(*list++);
2315 bank = bank_num_to_bank(info, num);
2317 return PTR_ERR(bank);
2319 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2320 grp->data[j].func = be32_to_cpu(*list++);
2326 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
2327 ret = pinconf_generic_parse_dt_config(np_config, NULL,
2328 &grp->data[j].configs, &grp->data[j].nconfigs);
2336 static int rockchip_pinctrl_parse_functions(struct device_node *np,
2337 struct rockchip_pinctrl *info,
2340 struct device_node *child;
2341 struct rockchip_pmx_func *func;
2342 struct rockchip_pin_group *grp;
2344 static u32 grp_index;
2347 dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np);
2349 func = &info->functions[index];
2351 /* Initialise function */
2352 func->name = np->name;
2353 func->ngroups = of_get_child_count(np);
2354 if (func->ngroups <= 0)
2357 func->groups = devm_kcalloc(info->dev,
2358 func->ngroups, sizeof(char *), GFP_KERNEL);
2362 for_each_child_of_node(np, child) {
2363 func->groups[i] = child->name;
2364 grp = &info->groups[grp_index++];
2365 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
2375 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2376 struct rockchip_pinctrl *info)
2378 struct device *dev = &pdev->dev;
2379 struct device_node *np = dev->of_node;
2380 struct device_node *child;
2384 rockchip_pinctrl_child_count(info, np);
2386 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2387 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2389 info->functions = devm_kcalloc(dev,
2391 sizeof(struct rockchip_pmx_func),
2393 if (!info->functions)
2396 info->groups = devm_kcalloc(dev,
2398 sizeof(struct rockchip_pin_group),
2405 for_each_child_of_node(np, child) {
2406 if (of_match_node(rockchip_bank_match, child))
2409 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2411 dev_err(&pdev->dev, "failed to parse function\n");
2420 static int rockchip_pinctrl_register(struct platform_device *pdev,
2421 struct rockchip_pinctrl *info)
2423 struct pinctrl_desc *ctrldesc = &info->pctl;
2424 struct pinctrl_pin_desc *pindesc, *pdesc;
2425 struct rockchip_pin_bank *pin_bank;
2429 ctrldesc->name = "rockchip-pinctrl";
2430 ctrldesc->owner = THIS_MODULE;
2431 ctrldesc->pctlops = &rockchip_pctrl_ops;
2432 ctrldesc->pmxops = &rockchip_pmx_ops;
2433 ctrldesc->confops = &rockchip_pinconf_ops;
2435 pindesc = devm_kcalloc(&pdev->dev,
2436 info->ctrl->nr_pins, sizeof(*pindesc),
2441 ctrldesc->pins = pindesc;
2442 ctrldesc->npins = info->ctrl->nr_pins;
2445 for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) {
2446 pin_bank = &info->ctrl->pin_banks[bank];
2447 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2449 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2450 pin_bank->name, pin);
2455 ret = rockchip_pinctrl_parse_dt(pdev, info);
2459 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
2460 if (IS_ERR(info->pctl_dev)) {
2461 dev_err(&pdev->dev, "could not register pinctrl driver\n");
2462 return PTR_ERR(info->pctl_dev);
2468 static const struct of_device_id rockchip_pinctrl_dt_match[];
2470 /* retrieve the soc specific data */
2471 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2472 struct rockchip_pinctrl *d,
2473 struct platform_device *pdev)
2475 const struct of_device_id *match;
2476 struct device_node *node = pdev->dev.of_node;
2477 struct rockchip_pin_ctrl *ctrl;
2478 struct rockchip_pin_bank *bank;
2479 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
2481 match = of_match_node(rockchip_pinctrl_dt_match, node);
2482 ctrl = (struct rockchip_pin_ctrl *)match->data;
2484 grf_offs = ctrl->grf_mux_offset;
2485 pmu_offs = ctrl->pmu_mux_offset;
2486 drv_pmu_offs = ctrl->pmu_drv_offset;
2487 drv_grf_offs = ctrl->grf_drv_offset;
2488 bank = ctrl->pin_banks;
2489 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2492 raw_spin_lock_init(&bank->slock);
2494 bank->pin_base = ctrl->nr_pins;
2495 ctrl->nr_pins += bank->nr_pins;
2497 /* calculate iomux and drv offsets */
2498 for (j = 0; j < 4; j++) {
2499 struct rockchip_iomux *iom = &bank->iomux[j];
2500 struct rockchip_drv *drv = &bank->drv[j];
2503 if (bank_pins >= bank->nr_pins)
2506 /* preset iomux offset value, set new start value */
2507 if (iom->offset >= 0) {
2508 if (iom->type & IOMUX_SOURCE_PMU)
2509 pmu_offs = iom->offset;
2511 grf_offs = iom->offset;
2512 } else { /* set current iomux offset */
2513 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2514 pmu_offs : grf_offs;
2517 /* preset drv offset value, set new start value */
2518 if (drv->offset >= 0) {
2519 if (iom->type & IOMUX_SOURCE_PMU)
2520 drv_pmu_offs = drv->offset;
2522 drv_grf_offs = drv->offset;
2523 } else { /* set current drv offset */
2524 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2525 drv_pmu_offs : drv_grf_offs;
2528 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
2529 i, j, iom->offset, drv->offset);
2532 * Increase offset according to iomux width.
2533 * 4bit iomux'es are spread over two registers.
2535 inc = (iom->type & (IOMUX_WIDTH_4BIT |
2537 IOMUX_WIDTH_2BIT)) ? 8 : 4;
2538 if (iom->type & IOMUX_SOURCE_PMU)
2544 * Increase offset according to drv width.
2545 * 3bit drive-strenth'es are spread over two registers.
2547 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
2548 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
2553 if (iom->type & IOMUX_SOURCE_PMU)
2554 drv_pmu_offs += inc;
2556 drv_grf_offs += inc;
2561 /* calculate the per-bank recalced_mask */
2562 for (j = 0; j < ctrl->niomux_recalced; j++) {
2565 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
2566 pin = ctrl->iomux_recalced[j].pin;
2567 bank->recalced_mask |= BIT(pin);
2571 /* calculate the per-bank route_mask */
2572 for (j = 0; j < ctrl->niomux_routes; j++) {
2575 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
2576 pin = ctrl->iomux_routes[j].pin;
2577 bank->route_mask |= BIT(pin);
2585 #define RK3288_GRF_GPIO6C_IOMUX 0x64
2586 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
2588 static u32 rk3288_grf_gpio6c_iomux;
2590 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
2592 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2593 int ret = pinctrl_force_sleep(info->pctl_dev);
2599 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
2600 * the setting here, and restore it at resume.
2602 if (info->ctrl->type == RK3288) {
2603 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2604 &rk3288_grf_gpio6c_iomux);
2606 pinctrl_force_default(info->pctl_dev);
2614 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
2616 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2619 if (info->ctrl->type == RK3288) {
2620 ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2621 rk3288_grf_gpio6c_iomux |
2622 GPIO6C6_SEL_WRITE_ENABLE);
2627 return pinctrl_force_default(info->pctl_dev);
2630 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
2631 rockchip_pinctrl_resume);
2633 static int rockchip_pinctrl_probe(struct platform_device *pdev)
2635 struct rockchip_pinctrl *info;
2636 struct device *dev = &pdev->dev;
2637 struct rockchip_pin_ctrl *ctrl;
2638 struct device_node *np = pdev->dev.of_node, *node;
2639 struct resource *res;
2643 if (!dev->of_node) {
2644 dev_err(dev, "device tree node not found\n");
2648 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
2654 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
2656 dev_err(dev, "driver data not available\n");
2661 node = of_parse_phandle(np, "rockchip,grf", 0);
2663 info->regmap_base = syscon_node_to_regmap(node);
2664 if (IS_ERR(info->regmap_base))
2665 return PTR_ERR(info->regmap_base);
2667 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2668 base = devm_ioremap_resource(&pdev->dev, res);
2670 return PTR_ERR(base);
2672 rockchip_regmap_config.max_register = resource_size(res) - 4;
2673 rockchip_regmap_config.name = "rockchip,pinctrl";
2674 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
2675 &rockchip_regmap_config);
2677 /* to check for the old dt-bindings */
2678 info->reg_size = resource_size(res);
2680 /* Honor the old binding, with pull registers as 2nd resource */
2681 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
2682 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2683 base = devm_ioremap_resource(&pdev->dev, res);
2685 return PTR_ERR(base);
2687 rockchip_regmap_config.max_register =
2688 resource_size(res) - 4;
2689 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
2690 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
2692 &rockchip_regmap_config);
2696 /* try to find the optional reference to the pmu syscon */
2697 node = of_parse_phandle(np, "rockchip,pmu", 0);
2699 info->regmap_pmu = syscon_node_to_regmap(node);
2700 if (IS_ERR(info->regmap_pmu))
2701 return PTR_ERR(info->regmap_pmu);
2704 ret = rockchip_pinctrl_register(pdev, info);
2708 platform_set_drvdata(pdev, info);
2710 ret = of_platform_populate(np, rockchip_bank_match, NULL, NULL);
2712 dev_err(&pdev->dev, "failed to register gpio device\n");
2719 static struct rockchip_pin_bank px30_pin_banks[] = {
2720 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2725 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
2730 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
2735 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
2742 static struct rockchip_pin_ctrl px30_pin_ctrl = {
2743 .pin_banks = px30_pin_banks,
2744 .nr_banks = ARRAY_SIZE(px30_pin_banks),
2745 .label = "PX30-GPIO",
2747 .grf_mux_offset = 0x0,
2748 .pmu_mux_offset = 0x0,
2749 .iomux_routes = px30_mux_route_data,
2750 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
2751 .pull_calc_reg = px30_calc_pull_reg_and_bit,
2752 .drv_calc_reg = px30_calc_drv_reg_and_bit,
2753 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
2756 static struct rockchip_pin_bank rv1108_pin_banks[] = {
2757 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2761 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
2762 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
2763 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
2766 static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
2767 .pin_banks = rv1108_pin_banks,
2768 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
2769 .label = "RV1108-GPIO",
2771 .grf_mux_offset = 0x10,
2772 .pmu_mux_offset = 0x0,
2773 .iomux_recalced = rv1108_mux_recalced_data,
2774 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
2775 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
2776 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
2777 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
2780 static struct rockchip_pin_bank rk2928_pin_banks[] = {
2781 PIN_BANK(0, 32, "gpio0"),
2782 PIN_BANK(1, 32, "gpio1"),
2783 PIN_BANK(2, 32, "gpio2"),
2784 PIN_BANK(3, 32, "gpio3"),
2787 static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
2788 .pin_banks = rk2928_pin_banks,
2789 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
2790 .label = "RK2928-GPIO",
2792 .grf_mux_offset = 0xa8,
2793 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2796 static struct rockchip_pin_bank rk3036_pin_banks[] = {
2797 PIN_BANK(0, 32, "gpio0"),
2798 PIN_BANK(1, 32, "gpio1"),
2799 PIN_BANK(2, 32, "gpio2"),
2802 static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
2803 .pin_banks = rk3036_pin_banks,
2804 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
2805 .label = "RK3036-GPIO",
2807 .grf_mux_offset = 0xa8,
2808 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2811 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
2812 PIN_BANK(0, 32, "gpio0"),
2813 PIN_BANK(1, 32, "gpio1"),
2814 PIN_BANK(2, 32, "gpio2"),
2815 PIN_BANK(3, 32, "gpio3"),
2816 PIN_BANK(4, 32, "gpio4"),
2817 PIN_BANK(6, 16, "gpio6"),
2820 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
2821 .pin_banks = rk3066a_pin_banks,
2822 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
2823 .label = "RK3066a-GPIO",
2825 .grf_mux_offset = 0xa8,
2826 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2829 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
2830 PIN_BANK(0, 32, "gpio0"),
2831 PIN_BANK(1, 32, "gpio1"),
2832 PIN_BANK(2, 32, "gpio2"),
2833 PIN_BANK(3, 32, "gpio3"),
2836 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
2837 .pin_banks = rk3066b_pin_banks,
2838 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
2839 .label = "RK3066b-GPIO",
2841 .grf_mux_offset = 0x60,
2844 static struct rockchip_pin_bank rk3128_pin_banks[] = {
2845 PIN_BANK(0, 32, "gpio0"),
2846 PIN_BANK(1, 32, "gpio1"),
2847 PIN_BANK(2, 32, "gpio2"),
2848 PIN_BANK(3, 32, "gpio3"),
2851 static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
2852 .pin_banks = rk3128_pin_banks,
2853 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
2854 .label = "RK3128-GPIO",
2856 .grf_mux_offset = 0xa8,
2857 .iomux_recalced = rk3128_mux_recalced_data,
2858 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
2859 .iomux_routes = rk3128_mux_route_data,
2860 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
2861 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
2864 static struct rockchip_pin_bank rk3188_pin_banks[] = {
2865 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
2866 PIN_BANK(1, 32, "gpio1"),
2867 PIN_BANK(2, 32, "gpio2"),
2868 PIN_BANK(3, 32, "gpio3"),
2871 static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
2872 .pin_banks = rk3188_pin_banks,
2873 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
2874 .label = "RK3188-GPIO",
2876 .grf_mux_offset = 0x60,
2877 .iomux_routes = rk3188_mux_route_data,
2878 .niomux_routes = ARRAY_SIZE(rk3188_mux_route_data),
2879 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
2882 static struct rockchip_pin_bank rk3228_pin_banks[] = {
2883 PIN_BANK(0, 32, "gpio0"),
2884 PIN_BANK(1, 32, "gpio1"),
2885 PIN_BANK(2, 32, "gpio2"),
2886 PIN_BANK(3, 32, "gpio3"),
2889 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
2890 .pin_banks = rk3228_pin_banks,
2891 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
2892 .label = "RK3228-GPIO",
2894 .grf_mux_offset = 0x0,
2895 .iomux_routes = rk3228_mux_route_data,
2896 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
2897 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
2898 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
2901 static struct rockchip_pin_bank rk3288_pin_banks[] = {
2902 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
2907 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
2912 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
2913 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
2914 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
2919 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
2924 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
2925 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
2930 PIN_BANK(8, 16, "gpio8"),
2933 static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
2934 .pin_banks = rk3288_pin_banks,
2935 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
2936 .label = "RK3288-GPIO",
2938 .grf_mux_offset = 0x0,
2939 .pmu_mux_offset = 0x84,
2940 .iomux_routes = rk3288_mux_route_data,
2941 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
2942 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
2943 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
2946 static struct rockchip_pin_bank rk3308_pin_banks[] = {
2947 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT,
2951 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT,
2955 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT,
2959 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT,
2963 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT,
2969 static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
2970 .pin_banks = rk3308_pin_banks,
2971 .nr_banks = ARRAY_SIZE(rk3308_pin_banks),
2972 .label = "RK3308-GPIO",
2974 .grf_mux_offset = 0x0,
2975 .iomux_recalced = rk3308_mux_recalced_data,
2976 .niomux_recalced = ARRAY_SIZE(rk3308_mux_recalced_data),
2977 .iomux_routes = rk3308_mux_route_data,
2978 .niomux_routes = ARRAY_SIZE(rk3308_mux_route_data),
2979 .pull_calc_reg = rk3308_calc_pull_reg_and_bit,
2980 .drv_calc_reg = rk3308_calc_drv_reg_and_bit,
2981 .schmitt_calc_reg = rk3308_calc_schmitt_reg_and_bit,
2984 static struct rockchip_pin_bank rk3328_pin_banks[] = {
2985 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
2986 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
2987 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
2991 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
2998 static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
2999 .pin_banks = rk3328_pin_banks,
3000 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3001 .label = "RK3328-GPIO",
3003 .grf_mux_offset = 0x0,
3004 .iomux_recalced = rk3328_mux_recalced_data,
3005 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
3006 .iomux_routes = rk3328_mux_route_data,
3007 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
3008 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3009 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3010 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
3013 static struct rockchip_pin_bank rk3368_pin_banks[] = {
3014 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3019 PIN_BANK(1, 32, "gpio1"),
3020 PIN_BANK(2, 32, "gpio2"),
3021 PIN_BANK(3, 32, "gpio3"),
3024 static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3025 .pin_banks = rk3368_pin_banks,
3026 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3027 .label = "RK3368-GPIO",
3029 .grf_mux_offset = 0x0,
3030 .pmu_mux_offset = 0x0,
3031 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3032 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3035 static struct rockchip_pin_bank rk3399_pin_banks[] = {
3036 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3041 DRV_TYPE_IO_1V8_ONLY,
3042 DRV_TYPE_IO_1V8_ONLY,
3043 DRV_TYPE_IO_DEFAULT,
3044 DRV_TYPE_IO_DEFAULT,
3049 PULL_TYPE_IO_1V8_ONLY,
3050 PULL_TYPE_IO_1V8_ONLY,
3051 PULL_TYPE_IO_DEFAULT,
3052 PULL_TYPE_IO_DEFAULT
3054 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3058 DRV_TYPE_IO_1V8_OR_3V0,
3059 DRV_TYPE_IO_1V8_OR_3V0,
3060 DRV_TYPE_IO_1V8_OR_3V0,
3061 DRV_TYPE_IO_1V8_OR_3V0,
3067 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3068 DRV_TYPE_IO_1V8_OR_3V0,
3069 DRV_TYPE_IO_1V8_ONLY,
3070 DRV_TYPE_IO_1V8_ONLY,
3071 PULL_TYPE_IO_DEFAULT,
3072 PULL_TYPE_IO_DEFAULT,
3073 PULL_TYPE_IO_1V8_ONLY,
3074 PULL_TYPE_IO_1V8_ONLY
3076 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3077 DRV_TYPE_IO_3V3_ONLY,
3078 DRV_TYPE_IO_3V3_ONLY,
3079 DRV_TYPE_IO_1V8_OR_3V0
3081 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3082 DRV_TYPE_IO_1V8_3V0_AUTO,
3083 DRV_TYPE_IO_1V8_OR_3V0,
3084 DRV_TYPE_IO_1V8_OR_3V0
3088 static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3089 .pin_banks = rk3399_pin_banks,
3090 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3091 .label = "RK3399-GPIO",
3093 .grf_mux_offset = 0xe000,
3094 .pmu_mux_offset = 0x0,
3095 .grf_drv_offset = 0xe100,
3096 .pmu_drv_offset = 0x80,
3097 .iomux_routes = rk3399_mux_route_data,
3098 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
3099 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3100 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3103 static struct rockchip_pin_bank rk3568_pin_banks[] = {
3104 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3105 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3106 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3107 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT),
3108 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3112 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3116 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3120 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3126 static struct rockchip_pin_ctrl rk3568_pin_ctrl = {
3127 .pin_banks = rk3568_pin_banks,
3128 .nr_banks = ARRAY_SIZE(rk3568_pin_banks),
3129 .label = "RK3568-GPIO",
3131 .grf_mux_offset = 0x0,
3132 .pmu_mux_offset = 0x0,
3133 .grf_drv_offset = 0x0200,
3134 .pmu_drv_offset = 0x0070,
3135 .iomux_routes = rk3568_mux_route_data,
3136 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data),
3137 .pull_calc_reg = rk3568_calc_pull_reg_and_bit,
3138 .drv_calc_reg = rk3568_calc_drv_reg_and_bit,
3139 .schmitt_calc_reg = rk3568_calc_schmitt_reg_and_bit,
3142 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
3143 { .compatible = "rockchip,px30-pinctrl",
3144 .data = &px30_pin_ctrl },
3145 { .compatible = "rockchip,rv1108-pinctrl",
3146 .data = &rv1108_pin_ctrl },
3147 { .compatible = "rockchip,rk2928-pinctrl",
3148 .data = &rk2928_pin_ctrl },
3149 { .compatible = "rockchip,rk3036-pinctrl",
3150 .data = &rk3036_pin_ctrl },
3151 { .compatible = "rockchip,rk3066a-pinctrl",
3152 .data = &rk3066a_pin_ctrl },
3153 { .compatible = "rockchip,rk3066b-pinctrl",
3154 .data = &rk3066b_pin_ctrl },
3155 { .compatible = "rockchip,rk3128-pinctrl",
3156 .data = (void *)&rk3128_pin_ctrl },
3157 { .compatible = "rockchip,rk3188-pinctrl",
3158 .data = &rk3188_pin_ctrl },
3159 { .compatible = "rockchip,rk3228-pinctrl",
3160 .data = &rk3228_pin_ctrl },
3161 { .compatible = "rockchip,rk3288-pinctrl",
3162 .data = &rk3288_pin_ctrl },
3163 { .compatible = "rockchip,rk3308-pinctrl",
3164 .data = &rk3308_pin_ctrl },
3165 { .compatible = "rockchip,rk3328-pinctrl",
3166 .data = &rk3328_pin_ctrl },
3167 { .compatible = "rockchip,rk3368-pinctrl",
3168 .data = &rk3368_pin_ctrl },
3169 { .compatible = "rockchip,rk3399-pinctrl",
3170 .data = &rk3399_pin_ctrl },
3171 { .compatible = "rockchip,rk3568-pinctrl",
3172 .data = &rk3568_pin_ctrl },
3176 static struct platform_driver rockchip_pinctrl_driver = {
3177 .probe = rockchip_pinctrl_probe,
3179 .name = "rockchip-pinctrl",
3180 .pm = &rockchip_pinctrl_dev_pm_ops,
3181 .of_match_table = rockchip_pinctrl_dt_match,
3185 static int __init rockchip_pinctrl_drv_register(void)
3187 return platform_driver_register(&rockchip_pinctrl_driver);
3189 postcore_initcall(rockchip_pinctrl_drv_register);
3191 static void __exit rockchip_pinctrl_drv_unregister(void)
3193 platform_driver_unregister(&rockchip_pinctrl_driver);
3195 module_exit(rockchip_pinctrl_drv_unregister);
3197 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver");
3198 MODULE_LICENSE("GPL");
3199 MODULE_ALIAS("platform:pinctrl-rockchip");
3200 MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match);