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[] = {
565 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
587 static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
588 int *reg, u8 *bit, int *mask)
590 struct rockchip_pinctrl *info = bank->drvdata;
591 struct rockchip_pin_ctrl *ctrl = info->ctrl;
592 struct rockchip_mux_recalced_data *data;
595 for (i = 0; i < ctrl->niomux_recalced; i++) {
596 data = &ctrl->iomux_recalced[i];
597 if (data->num == bank->bank_num &&
602 if (i >= ctrl->niomux_recalced)
610 static struct rockchip_mux_route_data px30_mux_route_data[] = {
611 RK_MUXROUTE_SAME(2, RK_PA0, 1, 0x184, BIT(16 + 7)), /* cif-d2m0 */
612 RK_MUXROUTE_SAME(3, RK_PA3, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d2m1 */
613 RK_MUXROUTE_SAME(3, RK_PC6, 2, 0x184, BIT(16 + 8)), /* pdm-m0 */
614 RK_MUXROUTE_SAME(2, RK_PC6, 1, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-m1 */
615 RK_MUXROUTE_SAME(1, RK_PD3, 2, 0x184, BIT(16 + 10)), /* uart2-rxm0 */
616 RK_MUXROUTE_SAME(2, RK_PB6, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-rxm1 */
617 RK_MUXROUTE_SAME(0, RK_PC1, 2, 0x184, BIT(16 + 9)), /* uart3-rxm0 */
618 RK_MUXROUTE_SAME(1, RK_PB7, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rxm1 */
621 static struct rockchip_mux_route_data rk3128_mux_route_data[] = {
622 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x144, BIT(16 + 3) | BIT(16 + 4)), /* spi-0 */
623 RK_MUXROUTE_SAME(1, RK_PD3, 3, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(3)), /* spi-1 */
624 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(4)), /* spi-2 */
625 RK_MUXROUTE_SAME(1, RK_PA5, 1, 0x144, BIT(16 + 5)), /* i2s-0 */
626 RK_MUXROUTE_SAME(0, RK_PB6, 1, 0x144, BIT(16 + 5) | BIT(5)), /* i2s-1 */
627 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x144, BIT(16 + 6)), /* emmc-0 */
628 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x144, BIT(16 + 6) | BIT(6)), /* emmc-1 */
631 static struct rockchip_mux_route_data rk3188_mux_route_data[] = {
632 RK_MUXROUTE_SAME(0, RK_PD0, 1, 0xa0, BIT(16 + 11)), /* non-iomuxed emmc/flash pins on flash-dqs */
633 RK_MUXROUTE_SAME(0, RK_PD0, 2, 0xa0, BIT(16 + 11) | BIT(11)), /* non-iomuxed emmc/flash pins on emmc-clk */
636 static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
637 RK_MUXROUTE_SAME(0, RK_PD2, 1, 0x50, BIT(16)), /* pwm0-0 */
638 RK_MUXROUTE_SAME(3, RK_PC5, 1, 0x50, BIT(16) | BIT(0)), /* pwm0-1 */
639 RK_MUXROUTE_SAME(0, RK_PD3, 1, 0x50, BIT(16 + 1)), /* pwm1-0 */
640 RK_MUXROUTE_SAME(0, RK_PD6, 2, 0x50, BIT(16 + 1) | BIT(1)), /* pwm1-1 */
641 RK_MUXROUTE_SAME(0, RK_PD4, 1, 0x50, BIT(16 + 2)), /* pwm2-0 */
642 RK_MUXROUTE_SAME(1, RK_PB4, 2, 0x50, BIT(16 + 2) | BIT(2)), /* pwm2-1 */
643 RK_MUXROUTE_SAME(3, RK_PD2, 1, 0x50, BIT(16 + 3)), /* pwm3-0 */
644 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 3) | BIT(3)), /* pwm3-1 */
645 RK_MUXROUTE_SAME(1, RK_PA1, 1, 0x50, BIT(16 + 4)), /* sdio-0_d0 */
646 RK_MUXROUTE_SAME(3, RK_PA2, 1, 0x50, BIT(16 + 4) | BIT(4)), /* sdio-1_d0 */
647 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x50, BIT(16 + 5)), /* spi-0_rx */
648 RK_MUXROUTE_SAME(2, RK_PA0, 2, 0x50, BIT(16 + 5) | BIT(5)), /* spi-1_rx */
649 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x50, BIT(16 + 7)), /* emmc-0_cmd */
650 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x50, BIT(16 + 7) | BIT(7)), /* emmc-1_cmd */
651 RK_MUXROUTE_SAME(1, RK_PC3, 2, 0x50, BIT(16 + 8)), /* uart2-0_rx */
652 RK_MUXROUTE_SAME(1, RK_PB2, 2, 0x50, BIT(16 + 8) | BIT(8)), /* uart2-1_rx */
653 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x50, BIT(16 + 11)), /* uart1-0_rx */
654 RK_MUXROUTE_SAME(3, RK_PB5, 1, 0x50, BIT(16 + 11) | BIT(11)), /* uart1-1_rx */
657 static struct rockchip_mux_route_data rk3288_mux_route_data[] = {
658 RK_MUXROUTE_SAME(7, RK_PC0, 2, 0x264, BIT(16 + 12) | BIT(12)), /* edphdmi_cecinoutt1 */
659 RK_MUXROUTE_SAME(7, RK_PC7, 4, 0x264, BIT(16 + 12)), /* edphdmi_cecinout */
662 static struct rockchip_mux_route_data rk3308_mux_route_data[] = {
663 RK_MUXROUTE_SAME(0, RK_PC3, 1, 0x314, BIT(16 + 0) | BIT(0)), /* rtc_clk */
664 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x314, BIT(16 + 2) | BIT(16 + 3)), /* uart2_rxm0 */
665 RK_MUXROUTE_SAME(4, RK_PD2, 2, 0x314, BIT(16 + 2) | BIT(16 + 3) | BIT(2)), /* uart2_rxm1 */
666 RK_MUXROUTE_SAME(0, RK_PB7, 2, 0x608, BIT(16 + 8) | BIT(16 + 9)), /* i2c3_sdam0 */
667 RK_MUXROUTE_SAME(3, RK_PB4, 2, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(8)), /* i2c3_sdam1 */
668 RK_MUXROUTE_SAME(2, RK_PA0, 3, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(9)), /* i2c3_sdam2 */
669 RK_MUXROUTE_SAME(1, RK_PA3, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclktxm0 */
670 RK_MUXROUTE_SAME(1, RK_PA4, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclkrxm0 */
671 RK_MUXROUTE_SAME(1, RK_PB5, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclktxm1 */
672 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclkrxm1 */
673 RK_MUXROUTE_SAME(1, RK_PA4, 3, 0x308, BIT(16 + 12) | BIT(16 + 13)), /* pdm-clkm0 */
674 RK_MUXROUTE_SAME(1, RK_PB6, 4, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* pdm-clkm1 */
675 RK_MUXROUTE_SAME(2, RK_PA6, 2, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* pdm-clkm2 */
676 RK_MUXROUTE_SAME(2, RK_PA4, 3, 0x600, BIT(16 + 2) | BIT(2)), /* pdm-clkm-m2 */
677 RK_MUXROUTE_SAME(3, RK_PB2, 3, 0x314, BIT(16 + 9)), /* spi1_miso */
678 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x314, BIT(16 + 9) | BIT(9)), /* spi1_miso_m1 */
679 RK_MUXROUTE_SAME(0, RK_PB3, 3, 0x314, BIT(16 + 10) | BIT(16 + 11)), /* owire_m0 */
680 RK_MUXROUTE_SAME(1, RK_PC6, 7, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* owire_m1 */
681 RK_MUXROUTE_SAME(2, RK_PA2, 5, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* owire_m2 */
682 RK_MUXROUTE_SAME(0, RK_PB3, 2, 0x314, BIT(16 + 12) | BIT(16 + 13)), /* can_rxd_m0 */
683 RK_MUXROUTE_SAME(1, RK_PC6, 5, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* can_rxd_m1 */
684 RK_MUXROUTE_SAME(2, RK_PA2, 4, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* can_rxd_m2 */
685 RK_MUXROUTE_SAME(1, RK_PC4, 3, 0x314, BIT(16 + 14)), /* mac_rxd0_m0 */
686 RK_MUXROUTE_SAME(4, RK_PA2, 2, 0x314, BIT(16 + 14) | BIT(14)), /* mac_rxd0_m1 */
687 RK_MUXROUTE_SAME(3, RK_PB4, 4, 0x314, BIT(16 + 15)), /* uart3_rx */
688 RK_MUXROUTE_SAME(0, RK_PC1, 3, 0x314, BIT(16 + 15) | BIT(15)), /* uart3_rx_m1 */
691 static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
692 RK_MUXROUTE_SAME(1, RK_PA1, 2, 0x50, BIT(16) | BIT(16 + 1)), /* uart2dbg_rxm0 */
693 RK_MUXROUTE_SAME(2, RK_PA1, 1, 0x50, BIT(16) | BIT(16 + 1) | BIT(0)), /* uart2dbg_rxm1 */
694 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 2) | BIT(2)), /* gmac-m1_rxd0 */
695 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x50, BIT(16 + 10) | BIT(10)), /* gmac-m1-optimized_rxd3 */
696 RK_MUXROUTE_SAME(2, RK_PC3, 2, 0x50, BIT(16 + 3)), /* pdm_sdi0m0 */
697 RK_MUXROUTE_SAME(1, RK_PC7, 3, 0x50, BIT(16 + 3) | BIT(3)), /* pdm_sdi0m1 */
698 RK_MUXROUTE_SAME(3, RK_PA2, 4, 0x50, BIT(16 + 4) | BIT(16 + 5) | BIT(5)), /* spi_rxdm2 */
699 RK_MUXROUTE_SAME(1, RK_PD0, 1, 0x50, BIT(16 + 6)), /* i2s2_sdim0 */
700 RK_MUXROUTE_SAME(3, RK_PA2, 6, 0x50, BIT(16 + 6) | BIT(6)), /* i2s2_sdim1 */
701 RK_MUXROUTE_SAME(2, RK_PC6, 3, 0x50, BIT(16 + 7) | BIT(7)), /* card_iom1 */
702 RK_MUXROUTE_SAME(2, RK_PC0, 3, 0x50, BIT(16 + 8) | BIT(8)), /* tsp_d5m1 */
703 RK_MUXROUTE_SAME(2, RK_PC0, 4, 0x50, BIT(16 + 9) | BIT(9)), /* cif_data5m1 */
706 static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
707 RK_MUXROUTE_SAME(4, RK_PB0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11)), /* uart2dbga_rx */
708 RK_MUXROUTE_SAME(4, RK_PC0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* uart2dbgb_rx */
709 RK_MUXROUTE_SAME(4, RK_PC3, 1, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* uart2dbgc_rx */
710 RK_MUXROUTE_SAME(2, RK_PD2, 2, 0xe21c, BIT(16 + 14)), /* pcie_clkreqn */
711 RK_MUXROUTE_SAME(4, RK_PD0, 1, 0xe21c, BIT(16 + 14) | BIT(14)), /* pcie_clkreqnb */
714 static struct rockchip_mux_route_data rk3568_mux_route_data[] = {
715 RK_MUXROUTE_PMU(0, RK_PB7, 1, 0x0110, WRITE_MASK_VAL(1, 0, 0)), /* PWM0 IO mux M0 */
716 RK_MUXROUTE_PMU(0, RK_PC7, 2, 0x0110, WRITE_MASK_VAL(1, 0, 1)), /* PWM0 IO mux M1 */
717 RK_MUXROUTE_PMU(0, RK_PC0, 1, 0x0110, WRITE_MASK_VAL(3, 2, 0)), /* PWM1 IO mux M0 */
718 RK_MUXROUTE_PMU(0, RK_PB5, 4, 0x0110, WRITE_MASK_VAL(3, 2, 1)), /* PWM1 IO mux M1 */
719 RK_MUXROUTE_PMU(0, RK_PC1, 1, 0x0110, WRITE_MASK_VAL(5, 4, 0)), /* PWM2 IO mux M0 */
720 RK_MUXROUTE_PMU(0, RK_PB6, 4, 0x0110, WRITE_MASK_VAL(5, 4, 1)), /* PWM2 IO mux M1 */
721 RK_MUXROUTE_PMU(0, RK_PB3, 2, 0x0300, WRITE_MASK_VAL(0, 0, 0)), /* CAN0 IO mux M0 */
722 RK_MUXROUTE_GRF(2, RK_PA1, 4, 0x0300, WRITE_MASK_VAL(0, 0, 1)), /* CAN0 IO mux M1 */
723 RK_MUXROUTE_GRF(1, RK_PA1, 3, 0x0300, WRITE_MASK_VAL(2, 2, 0)), /* CAN1 IO mux M0 */
724 RK_MUXROUTE_GRF(4, RK_PC3, 3, 0x0300, WRITE_MASK_VAL(2, 2, 1)), /* CAN1 IO mux M1 */
725 RK_MUXROUTE_GRF(4, RK_PB5, 3, 0x0300, WRITE_MASK_VAL(4, 4, 0)), /* CAN2 IO mux M0 */
726 RK_MUXROUTE_GRF(2, RK_PB2, 4, 0x0300, WRITE_MASK_VAL(4, 4, 1)), /* CAN2 IO mux M1 */
727 RK_MUXROUTE_GRF(4, RK_PC4, 1, 0x0300, WRITE_MASK_VAL(6, 6, 0)), /* HPDIN IO mux M0 */
728 RK_MUXROUTE_PMU(0, RK_PC2, 2, 0x0300, WRITE_MASK_VAL(6, 6, 1)), /* HPDIN IO mux M1 */
729 RK_MUXROUTE_GRF(3, RK_PB1, 3, 0x0300, WRITE_MASK_VAL(8, 8, 0)), /* GMAC1 IO mux M0 */
730 RK_MUXROUTE_GRF(4, RK_PA7, 3, 0x0300, WRITE_MASK_VAL(8, 8, 1)), /* GMAC1 IO mux M1 */
731 RK_MUXROUTE_GRF(4, RK_PD1, 1, 0x0300, WRITE_MASK_VAL(10, 10, 0)), /* HDMITX IO mux M0 */
732 RK_MUXROUTE_PMU(0, RK_PC7, 1, 0x0300, WRITE_MASK_VAL(10, 10, 1)), /* HDMITX IO mux M1 */
733 RK_MUXROUTE_PMU(0, RK_PB6, 1, 0x0300, WRITE_MASK_VAL(14, 14, 0)), /* I2C2 IO mux M0 */
734 RK_MUXROUTE_GRF(4, RK_PB4, 1, 0x0300, WRITE_MASK_VAL(14, 14, 1)), /* I2C2 IO mux M1 */
735 RK_MUXROUTE_GRF(1, RK_PA0, 1, 0x0304, WRITE_MASK_VAL(0, 0, 0)), /* I2C3 IO mux M0 */
736 RK_MUXROUTE_GRF(3, RK_PB6, 4, 0x0304, WRITE_MASK_VAL(0, 0, 1)), /* I2C3 IO mux M1 */
737 RK_MUXROUTE_GRF(4, RK_PB2, 1, 0x0304, WRITE_MASK_VAL(2, 2, 0)), /* I2C4 IO mux M0 */
738 RK_MUXROUTE_GRF(2, RK_PB1, 2, 0x0304, WRITE_MASK_VAL(2, 2, 1)), /* I2C4 IO mux M1 */
739 RK_MUXROUTE_GRF(3, RK_PB4, 4, 0x0304, WRITE_MASK_VAL(4, 4, 0)), /* I2C5 IO mux M0 */
740 RK_MUXROUTE_GRF(4, RK_PD0, 2, 0x0304, WRITE_MASK_VAL(4, 4, 1)), /* I2C5 IO mux M1 */
741 RK_MUXROUTE_GRF(3, RK_PB1, 5, 0x0304, WRITE_MASK_VAL(14, 14, 0)), /* PWM8 IO mux M0 */
742 RK_MUXROUTE_GRF(1, RK_PD5, 4, 0x0304, WRITE_MASK_VAL(14, 14, 1)), /* PWM8 IO mux M1 */
743 RK_MUXROUTE_GRF(3, RK_PB2, 5, 0x0308, WRITE_MASK_VAL(0, 0, 0)), /* PWM9 IO mux M0 */
744 RK_MUXROUTE_GRF(1, RK_PD6, 4, 0x0308, WRITE_MASK_VAL(0, 0, 1)), /* PWM9 IO mux M1 */
745 RK_MUXROUTE_GRF(3, RK_PB5, 5, 0x0308, WRITE_MASK_VAL(2, 2, 0)), /* PWM10 IO mux M0 */
746 RK_MUXROUTE_GRF(2, RK_PA1, 2, 0x0308, WRITE_MASK_VAL(2, 2, 1)), /* PWM10 IO mux M1 */
747 RK_MUXROUTE_GRF(3, RK_PB6, 5, 0x0308, WRITE_MASK_VAL(4, 4, 0)), /* PWM11 IO mux M0 */
748 RK_MUXROUTE_GRF(4, RK_PC0, 3, 0x0308, WRITE_MASK_VAL(4, 4, 1)), /* PWM11 IO mux M1 */
749 RK_MUXROUTE_GRF(3, RK_PB7, 2, 0x0308, WRITE_MASK_VAL(6, 6, 0)), /* PWM12 IO mux M0 */
750 RK_MUXROUTE_GRF(4, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(6, 6, 1)), /* PWM12 IO mux M1 */
751 RK_MUXROUTE_GRF(3, RK_PC0, 2, 0x0308, WRITE_MASK_VAL(8, 8, 0)), /* PWM13 IO mux M0 */
752 RK_MUXROUTE_GRF(4, RK_PC6, 1, 0x0308, WRITE_MASK_VAL(8, 8, 1)), /* PWM13 IO mux M1 */
753 RK_MUXROUTE_GRF(3, RK_PC4, 1, 0x0308, WRITE_MASK_VAL(10, 10, 0)), /* PWM14 IO mux M0 */
754 RK_MUXROUTE_GRF(4, RK_PC2, 1, 0x0308, WRITE_MASK_VAL(10, 10, 1)), /* PWM14 IO mux M1 */
755 RK_MUXROUTE_GRF(3, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(12, 12, 0)), /* PWM15 IO mux M0 */
756 RK_MUXROUTE_GRF(4, RK_PC3, 1, 0x0308, WRITE_MASK_VAL(12, 12, 1)), /* PWM15 IO mux M1 */
757 RK_MUXROUTE_GRF(3, RK_PD2, 3, 0x0308, WRITE_MASK_VAL(14, 14, 0)), /* SDMMC2 IO mux M0 */
758 RK_MUXROUTE_GRF(3, RK_PA5, 5, 0x0308, WRITE_MASK_VAL(14, 14, 1)), /* SDMMC2 IO mux M1 */
759 RK_MUXROUTE_PMU(0, RK_PB5, 2, 0x030c, WRITE_MASK_VAL(0, 0, 0)), /* SPI0 IO mux M0 */
760 RK_MUXROUTE_GRF(2, RK_PD3, 3, 0x030c, WRITE_MASK_VAL(0, 0, 1)), /* SPI0 IO mux M1 */
761 RK_MUXROUTE_GRF(2, RK_PB5, 3, 0x030c, WRITE_MASK_VAL(2, 2, 0)), /* SPI1 IO mux M0 */
762 RK_MUXROUTE_GRF(3, RK_PC3, 3, 0x030c, WRITE_MASK_VAL(2, 2, 1)), /* SPI1 IO mux M1 */
763 RK_MUXROUTE_GRF(2, RK_PC1, 4, 0x030c, WRITE_MASK_VAL(4, 4, 0)), /* SPI2 IO mux M0 */
764 RK_MUXROUTE_GRF(3, RK_PA0, 3, 0x030c, WRITE_MASK_VAL(4, 4, 1)), /* SPI2 IO mux M1 */
765 RK_MUXROUTE_GRF(4, RK_PB3, 4, 0x030c, WRITE_MASK_VAL(6, 6, 0)), /* SPI3 IO mux M0 */
766 RK_MUXROUTE_GRF(4, RK_PC2, 2, 0x030c, WRITE_MASK_VAL(6, 6, 1)), /* SPI3 IO mux M1 */
767 RK_MUXROUTE_GRF(2, RK_PB4, 2, 0x030c, WRITE_MASK_VAL(8, 8, 0)), /* UART1 IO mux M0 */
768 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(8, 8, 1)), /* UART1 IO mux M1 */
769 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(10, 10, 0)), /* UART2 IO mux M0 */
770 RK_MUXROUTE_GRF(1, RK_PD5, 2, 0x030c, WRITE_MASK_VAL(10, 10, 1)), /* UART2 IO mux M1 */
771 RK_MUXROUTE_GRF(1, RK_PA1, 2, 0x030c, WRITE_MASK_VAL(12, 12, 0)), /* UART3 IO mux M0 */
772 RK_MUXROUTE_GRF(3, RK_PB7, 4, 0x030c, WRITE_MASK_VAL(12, 12, 1)), /* UART3 IO mux M1 */
773 RK_MUXROUTE_GRF(1, RK_PA6, 2, 0x030c, WRITE_MASK_VAL(14, 14, 0)), /* UART4 IO mux M0 */
774 RK_MUXROUTE_GRF(3, RK_PB2, 4, 0x030c, WRITE_MASK_VAL(14, 14, 1)), /* UART4 IO mux M1 */
775 RK_MUXROUTE_GRF(2, RK_PA2, 3, 0x0310, WRITE_MASK_VAL(0, 0, 0)), /* UART5 IO mux M0 */
776 RK_MUXROUTE_GRF(3, RK_PC2, 4, 0x0310, WRITE_MASK_VAL(0, 0, 1)), /* UART5 IO mux M1 */
777 RK_MUXROUTE_GRF(2, RK_PA4, 3, 0x0310, WRITE_MASK_VAL(2, 2, 0)), /* UART6 IO mux M0 */
778 RK_MUXROUTE_GRF(1, RK_PD5, 3, 0x0310, WRITE_MASK_VAL(2, 2, 1)), /* UART6 IO mux M1 */
779 RK_MUXROUTE_GRF(2, RK_PA6, 3, 0x0310, WRITE_MASK_VAL(5, 4, 0)), /* UART7 IO mux M0 */
780 RK_MUXROUTE_GRF(3, RK_PC4, 4, 0x0310, WRITE_MASK_VAL(5, 4, 1)), /* UART7 IO mux M1 */
781 RK_MUXROUTE_GRF(4, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(5, 4, 2)), /* UART7 IO mux M2 */
782 RK_MUXROUTE_GRF(2, RK_PC5, 3, 0x0310, WRITE_MASK_VAL(6, 6, 0)), /* UART8 IO mux M0 */
783 RK_MUXROUTE_GRF(2, RK_PD7, 4, 0x0310, WRITE_MASK_VAL(6, 6, 1)), /* UART8 IO mux M1 */
784 RK_MUXROUTE_GRF(2, RK_PB0, 3, 0x0310, WRITE_MASK_VAL(9, 8, 0)), /* UART9 IO mux M0 */
785 RK_MUXROUTE_GRF(4, RK_PC5, 4, 0x0310, WRITE_MASK_VAL(9, 8, 1)), /* UART9 IO mux M1 */
786 RK_MUXROUTE_GRF(4, RK_PA4, 4, 0x0310, WRITE_MASK_VAL(9, 8, 2)), /* UART9 IO mux M2 */
787 RK_MUXROUTE_GRF(1, RK_PA2, 1, 0x0310, WRITE_MASK_VAL(11, 10, 0)), /* I2S1 IO mux M0 */
788 RK_MUXROUTE_GRF(3, RK_PC6, 4, 0x0310, WRITE_MASK_VAL(11, 10, 1)), /* I2S1 IO mux M1 */
789 RK_MUXROUTE_GRF(2, RK_PD0, 5, 0x0310, WRITE_MASK_VAL(11, 10, 2)), /* I2S1 IO mux M2 */
790 RK_MUXROUTE_GRF(2, RK_PC1, 1, 0x0310, WRITE_MASK_VAL(12, 12, 0)), /* I2S2 IO mux M0 */
791 RK_MUXROUTE_GRF(4, RK_PB6, 5, 0x0310, WRITE_MASK_VAL(12, 12, 1)), /* I2S2 IO mux M1 */
792 RK_MUXROUTE_GRF(3, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(14, 14, 0)), /* I2S3 IO mux M0 */
793 RK_MUXROUTE_GRF(4, RK_PC2, 5, 0x0310, WRITE_MASK_VAL(14, 14, 1)), /* I2S3 IO mux M1 */
794 RK_MUXROUTE_GRF(1, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
795 RK_MUXROUTE_GRF(1, RK_PA6, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
796 RK_MUXROUTE_GRF(3, RK_PD6, 5, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
797 RK_MUXROUTE_GRF(4, RK_PA0, 4, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
798 RK_MUXROUTE_GRF(3, RK_PC4, 5, 0x0314, WRITE_MASK_VAL(1, 0, 2)), /* PDM IO mux M2 */
799 RK_MUXROUTE_PMU(0, RK_PA5, 3, 0x0314, WRITE_MASK_VAL(3, 2, 0)), /* PCIE20 IO mux M0 */
800 RK_MUXROUTE_GRF(2, RK_PD0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 1)), /* PCIE20 IO mux M1 */
801 RK_MUXROUTE_GRF(1, RK_PB0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 2)), /* PCIE20 IO mux M2 */
802 RK_MUXROUTE_PMU(0, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux M0 */
803 RK_MUXROUTE_GRF(2, RK_PD2, 4, 0x0314, WRITE_MASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux M1 */
804 RK_MUXROUTE_GRF(1, RK_PA5, 4, 0x0314, WRITE_MASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux M2 */
805 RK_MUXROUTE_PMU(0, RK_PA6, 2, 0x0314, WRITE_MASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux M0 */
806 RK_MUXROUTE_GRF(2, RK_PD4, 4, 0x0314, WRITE_MASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux M1 */
807 RK_MUXROUTE_GRF(4, RK_PC2, 4, 0x0314, WRITE_MASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux M2 */
810 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
811 int mux, u32 *loc, u32 *reg, u32 *value)
813 struct rockchip_pinctrl *info = bank->drvdata;
814 struct rockchip_pin_ctrl *ctrl = info->ctrl;
815 struct rockchip_mux_route_data *data;
818 for (i = 0; i < ctrl->niomux_routes; i++) {
819 data = &ctrl->iomux_routes[i];
820 if ((data->bank_num == bank->bank_num) &&
821 (data->pin == pin) && (data->func == mux))
825 if (i >= ctrl->niomux_routes)
828 *loc = data->route_location;
829 *reg = data->route_offset;
830 *value = data->route_val;
835 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
837 struct rockchip_pinctrl *info = bank->drvdata;
838 int iomux_num = (pin / 8);
839 struct regmap *regmap;
841 int reg, ret, mask, mux_type;
847 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
848 dev_err(info->dev, "pin %d is unrouted\n", pin);
852 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
855 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
856 ? info->regmap_pmu : info->regmap_base;
858 /* get basic quadrupel of mux registers and the correct reg inside */
859 mux_type = bank->iomux[iomux_num].type;
860 reg = bank->iomux[iomux_num].offset;
861 if (mux_type & IOMUX_WIDTH_4BIT) {
866 } else if (mux_type & IOMUX_WIDTH_3BIT) {
869 bit = (pin % 8 % 5) * 3;
876 if (bank->recalced_mask & BIT(pin))
877 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
879 ret = regmap_read(regmap, reg, &val);
883 return ((val >> bit) & mask);
886 static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
889 struct rockchip_pinctrl *info = bank->drvdata;
890 int iomux_num = (pin / 8);
895 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
896 dev_err(info->dev, "pin %d is unrouted\n", pin);
900 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
901 if (mux != RK_FUNC_GPIO) {
903 "pin %d only supports a gpio mux\n", pin);
912 * Set a new mux function for a pin.
914 * The register is divided into the upper and lower 16 bit. When changing
915 * a value, the previous register value is not read and changed. Instead
916 * it seems the changed bits are marked in the upper 16 bit, while the
917 * changed value gets set in the same offset in the lower 16 bit.
918 * All pin settings seem to be 2 bit wide in both the upper and lower
920 * @bank: pin bank to change
921 * @pin: pin to change
922 * @mux: new mux function to set
924 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
926 struct rockchip_pinctrl *info = bank->drvdata;
927 int iomux_num = (pin / 8);
928 struct regmap *regmap;
929 int reg, ret, mask, mux_type;
931 u32 data, rmask, route_location, route_reg, route_val;
933 ret = rockchip_verify_mux(bank, pin, mux);
937 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
940 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
941 bank->bank_num, pin, mux);
943 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
944 ? info->regmap_pmu : info->regmap_base;
946 /* get basic quadrupel of mux registers and the correct reg inside */
947 mux_type = bank->iomux[iomux_num].type;
948 reg = bank->iomux[iomux_num].offset;
949 if (mux_type & IOMUX_WIDTH_4BIT) {
954 } else if (mux_type & IOMUX_WIDTH_3BIT) {
957 bit = (pin % 8 % 5) * 3;
964 if (bank->recalced_mask & BIT(pin))
965 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
967 if (bank->route_mask & BIT(pin)) {
968 if (rockchip_get_mux_route(bank, pin, mux, &route_location,
969 &route_reg, &route_val)) {
970 struct regmap *route_regmap = regmap;
972 /* handle special locations */
973 switch (route_location) {
974 case ROCKCHIP_ROUTE_PMU:
975 route_regmap = info->regmap_pmu;
977 case ROCKCHIP_ROUTE_GRF:
978 route_regmap = info->regmap_base;
982 ret = regmap_write(route_regmap, route_reg, route_val);
988 data = (mask << (bit + 16));
989 rmask = data | (data >> 16);
990 data |= (mux & mask) << bit;
991 ret = regmap_update_bits(regmap, reg, rmask, data);
996 #define PX30_PULL_PMU_OFFSET 0x10
997 #define PX30_PULL_GRF_OFFSET 0x60
998 #define PX30_PULL_BITS_PER_PIN 2
999 #define PX30_PULL_PINS_PER_REG 8
1000 #define PX30_PULL_BANK_STRIDE 16
1002 static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1003 int pin_num, struct regmap **regmap,
1006 struct rockchip_pinctrl *info = bank->drvdata;
1008 /* The first 32 pins of the first bank are located in PMU */
1009 if (bank->bank_num == 0) {
1010 *regmap = info->regmap_pmu;
1011 *reg = PX30_PULL_PMU_OFFSET;
1013 *regmap = info->regmap_base;
1014 *reg = PX30_PULL_GRF_OFFSET;
1016 /* correct the offset, as we're starting with the 2nd bank */
1018 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE;
1021 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4);
1022 *bit = (pin_num % PX30_PULL_PINS_PER_REG);
1023 *bit *= PX30_PULL_BITS_PER_PIN;
1026 #define PX30_DRV_PMU_OFFSET 0x20
1027 #define PX30_DRV_GRF_OFFSET 0xf0
1028 #define PX30_DRV_BITS_PER_PIN 2
1029 #define PX30_DRV_PINS_PER_REG 8
1030 #define PX30_DRV_BANK_STRIDE 16
1032 static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1033 int pin_num, struct regmap **regmap,
1036 struct rockchip_pinctrl *info = bank->drvdata;
1038 /* The first 32 pins of the first bank are located in PMU */
1039 if (bank->bank_num == 0) {
1040 *regmap = info->regmap_pmu;
1041 *reg = PX30_DRV_PMU_OFFSET;
1043 *regmap = info->regmap_base;
1044 *reg = PX30_DRV_GRF_OFFSET;
1046 /* correct the offset, as we're starting with the 2nd bank */
1048 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE;
1051 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4);
1052 *bit = (pin_num % PX30_DRV_PINS_PER_REG);
1053 *bit *= PX30_DRV_BITS_PER_PIN;
1056 #define PX30_SCHMITT_PMU_OFFSET 0x38
1057 #define PX30_SCHMITT_GRF_OFFSET 0xc0
1058 #define PX30_SCHMITT_PINS_PER_PMU_REG 16
1059 #define PX30_SCHMITT_BANK_STRIDE 16
1060 #define PX30_SCHMITT_PINS_PER_GRF_REG 8
1062 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1064 struct regmap **regmap,
1067 struct rockchip_pinctrl *info = bank->drvdata;
1070 if (bank->bank_num == 0) {
1071 *regmap = info->regmap_pmu;
1072 *reg = PX30_SCHMITT_PMU_OFFSET;
1073 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG;
1075 *regmap = info->regmap_base;
1076 *reg = PX30_SCHMITT_GRF_OFFSET;
1077 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG;
1078 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE;
1081 *reg += ((pin_num / pins_per_reg) * 4);
1082 *bit = pin_num % pins_per_reg;
1087 #define RV1108_PULL_PMU_OFFSET 0x10
1088 #define RV1108_PULL_OFFSET 0x110
1089 #define RV1108_PULL_PINS_PER_REG 8
1090 #define RV1108_PULL_BITS_PER_PIN 2
1091 #define RV1108_PULL_BANK_STRIDE 16
1093 static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1094 int pin_num, struct regmap **regmap,
1097 struct rockchip_pinctrl *info = bank->drvdata;
1099 /* The first 24 pins of the first bank are located in PMU */
1100 if (bank->bank_num == 0) {
1101 *regmap = info->regmap_pmu;
1102 *reg = RV1108_PULL_PMU_OFFSET;
1104 *reg = RV1108_PULL_OFFSET;
1105 *regmap = info->regmap_base;
1106 /* correct the offset, as we're starting with the 2nd bank */
1108 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
1111 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1112 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1113 *bit *= RV1108_PULL_BITS_PER_PIN;
1116 #define RV1108_DRV_PMU_OFFSET 0x20
1117 #define RV1108_DRV_GRF_OFFSET 0x210
1118 #define RV1108_DRV_BITS_PER_PIN 2
1119 #define RV1108_DRV_PINS_PER_REG 8
1120 #define RV1108_DRV_BANK_STRIDE 16
1122 static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1123 int pin_num, struct regmap **regmap,
1126 struct rockchip_pinctrl *info = bank->drvdata;
1128 /* The first 24 pins of the first bank are located in PMU */
1129 if (bank->bank_num == 0) {
1130 *regmap = info->regmap_pmu;
1131 *reg = RV1108_DRV_PMU_OFFSET;
1133 *regmap = info->regmap_base;
1134 *reg = RV1108_DRV_GRF_OFFSET;
1136 /* correct the offset, as we're starting with the 2nd bank */
1138 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
1141 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1142 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1143 *bit *= RV1108_DRV_BITS_PER_PIN;
1146 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1147 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1148 #define RV1108_SCHMITT_BANK_STRIDE 8
1149 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1150 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1152 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1154 struct regmap **regmap,
1157 struct rockchip_pinctrl *info = bank->drvdata;
1160 if (bank->bank_num == 0) {
1161 *regmap = info->regmap_pmu;
1162 *reg = RV1108_SCHMITT_PMU_OFFSET;
1163 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1165 *regmap = info->regmap_base;
1166 *reg = RV1108_SCHMITT_GRF_OFFSET;
1167 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1168 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1170 *reg += ((pin_num / pins_per_reg) * 4);
1171 *bit = pin_num % pins_per_reg;
1176 #define RK3308_SCHMITT_PINS_PER_REG 8
1177 #define RK3308_SCHMITT_BANK_STRIDE 16
1178 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0
1180 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1181 int pin_num, struct regmap **regmap,
1184 struct rockchip_pinctrl *info = bank->drvdata;
1186 *regmap = info->regmap_base;
1187 *reg = RK3308_SCHMITT_GRF_OFFSET;
1189 *reg += bank->bank_num * RK3308_SCHMITT_BANK_STRIDE;
1190 *reg += ((pin_num / RK3308_SCHMITT_PINS_PER_REG) * 4);
1191 *bit = pin_num % RK3308_SCHMITT_PINS_PER_REG;
1196 #define RK2928_PULL_OFFSET 0x118
1197 #define RK2928_PULL_PINS_PER_REG 16
1198 #define RK2928_PULL_BANK_STRIDE 8
1200 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1201 int pin_num, struct regmap **regmap,
1204 struct rockchip_pinctrl *info = bank->drvdata;
1206 *regmap = info->regmap_base;
1207 *reg = RK2928_PULL_OFFSET;
1208 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1209 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1211 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1214 #define RK3128_PULL_OFFSET 0x118
1216 static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1217 int pin_num, struct regmap **regmap,
1220 struct rockchip_pinctrl *info = bank->drvdata;
1222 *regmap = info->regmap_base;
1223 *reg = RK3128_PULL_OFFSET;
1224 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1225 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1227 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1230 #define RK3188_PULL_OFFSET 0x164
1231 #define RK3188_PULL_BITS_PER_PIN 2
1232 #define RK3188_PULL_PINS_PER_REG 8
1233 #define RK3188_PULL_BANK_STRIDE 16
1234 #define RK3188_PULL_PMU_OFFSET 0x64
1236 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1237 int pin_num, struct regmap **regmap,
1240 struct rockchip_pinctrl *info = bank->drvdata;
1242 /* The first 12 pins of the first bank are located elsewhere */
1243 if (bank->bank_num == 0 && pin_num < 12) {
1244 *regmap = info->regmap_pmu ? info->regmap_pmu
1245 : bank->regmap_pull;
1246 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
1247 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1248 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1249 *bit *= RK3188_PULL_BITS_PER_PIN;
1251 *regmap = info->regmap_pull ? info->regmap_pull
1252 : info->regmap_base;
1253 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1255 /* correct the offset, as it is the 2nd pull register */
1257 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1258 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1261 * The bits in these registers have an inverse ordering
1262 * with the lowest pin being in bits 15:14 and the highest
1265 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1266 *bit *= RK3188_PULL_BITS_PER_PIN;
1270 #define RK3288_PULL_OFFSET 0x140
1271 static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1272 int pin_num, struct regmap **regmap,
1275 struct rockchip_pinctrl *info = bank->drvdata;
1277 /* The first 24 pins of the first bank are located in PMU */
1278 if (bank->bank_num == 0) {
1279 *regmap = info->regmap_pmu;
1280 *reg = RK3188_PULL_PMU_OFFSET;
1282 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1283 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1284 *bit *= RK3188_PULL_BITS_PER_PIN;
1286 *regmap = info->regmap_base;
1287 *reg = RK3288_PULL_OFFSET;
1289 /* correct the offset, as we're starting with the 2nd bank */
1291 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1292 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1294 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1295 *bit *= RK3188_PULL_BITS_PER_PIN;
1299 #define RK3288_DRV_PMU_OFFSET 0x70
1300 #define RK3288_DRV_GRF_OFFSET 0x1c0
1301 #define RK3288_DRV_BITS_PER_PIN 2
1302 #define RK3288_DRV_PINS_PER_REG 8
1303 #define RK3288_DRV_BANK_STRIDE 16
1305 static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1306 int pin_num, struct regmap **regmap,
1309 struct rockchip_pinctrl *info = bank->drvdata;
1311 /* The first 24 pins of the first bank are located in PMU */
1312 if (bank->bank_num == 0) {
1313 *regmap = info->regmap_pmu;
1314 *reg = RK3288_DRV_PMU_OFFSET;
1316 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1317 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1318 *bit *= RK3288_DRV_BITS_PER_PIN;
1320 *regmap = info->regmap_base;
1321 *reg = RK3288_DRV_GRF_OFFSET;
1323 /* correct the offset, as we're starting with the 2nd bank */
1325 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1326 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1328 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1329 *bit *= RK3288_DRV_BITS_PER_PIN;
1333 #define RK3228_PULL_OFFSET 0x100
1335 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1336 int pin_num, struct regmap **regmap,
1339 struct rockchip_pinctrl *info = bank->drvdata;
1341 *regmap = info->regmap_base;
1342 *reg = RK3228_PULL_OFFSET;
1343 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1344 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1346 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1347 *bit *= RK3188_PULL_BITS_PER_PIN;
1350 #define RK3228_DRV_GRF_OFFSET 0x200
1352 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1353 int pin_num, struct regmap **regmap,
1356 struct rockchip_pinctrl *info = bank->drvdata;
1358 *regmap = info->regmap_base;
1359 *reg = RK3228_DRV_GRF_OFFSET;
1360 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1361 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1363 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1364 *bit *= RK3288_DRV_BITS_PER_PIN;
1367 #define RK3308_PULL_OFFSET 0xa0
1369 static void rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1370 int pin_num, struct regmap **regmap,
1373 struct rockchip_pinctrl *info = bank->drvdata;
1375 *regmap = info->regmap_base;
1376 *reg = RK3308_PULL_OFFSET;
1377 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1378 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1380 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1381 *bit *= RK3188_PULL_BITS_PER_PIN;
1384 #define RK3308_DRV_GRF_OFFSET 0x100
1386 static void rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1387 int pin_num, struct regmap **regmap,
1390 struct rockchip_pinctrl *info = bank->drvdata;
1392 *regmap = info->regmap_base;
1393 *reg = RK3308_DRV_GRF_OFFSET;
1394 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1395 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1397 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1398 *bit *= RK3288_DRV_BITS_PER_PIN;
1401 #define RK3368_PULL_GRF_OFFSET 0x100
1402 #define RK3368_PULL_PMU_OFFSET 0x10
1404 static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1405 int pin_num, struct regmap **regmap,
1408 struct rockchip_pinctrl *info = bank->drvdata;
1410 /* The first 32 pins of the first bank are located in PMU */
1411 if (bank->bank_num == 0) {
1412 *regmap = info->regmap_pmu;
1413 *reg = RK3368_PULL_PMU_OFFSET;
1415 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1416 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1417 *bit *= RK3188_PULL_BITS_PER_PIN;
1419 *regmap = info->regmap_base;
1420 *reg = RK3368_PULL_GRF_OFFSET;
1422 /* correct the offset, as we're starting with the 2nd bank */
1424 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1425 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1427 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1428 *bit *= RK3188_PULL_BITS_PER_PIN;
1432 #define RK3368_DRV_PMU_OFFSET 0x20
1433 #define RK3368_DRV_GRF_OFFSET 0x200
1435 static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1436 int pin_num, struct regmap **regmap,
1439 struct rockchip_pinctrl *info = bank->drvdata;
1441 /* The first 32 pins of the first bank are located in PMU */
1442 if (bank->bank_num == 0) {
1443 *regmap = info->regmap_pmu;
1444 *reg = RK3368_DRV_PMU_OFFSET;
1446 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1447 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1448 *bit *= RK3288_DRV_BITS_PER_PIN;
1450 *regmap = info->regmap_base;
1451 *reg = RK3368_DRV_GRF_OFFSET;
1453 /* correct the offset, as we're starting with the 2nd bank */
1455 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1456 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1458 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1459 *bit *= RK3288_DRV_BITS_PER_PIN;
1463 #define RK3399_PULL_GRF_OFFSET 0xe040
1464 #define RK3399_PULL_PMU_OFFSET 0x40
1465 #define RK3399_DRV_3BITS_PER_PIN 3
1467 static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1468 int pin_num, struct regmap **regmap,
1471 struct rockchip_pinctrl *info = bank->drvdata;
1473 /* The bank0:16 and bank1:32 pins are located in PMU */
1474 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1475 *regmap = info->regmap_pmu;
1476 *reg = RK3399_PULL_PMU_OFFSET;
1478 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1480 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1481 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1482 *bit *= RK3188_PULL_BITS_PER_PIN;
1484 *regmap = info->regmap_base;
1485 *reg = RK3399_PULL_GRF_OFFSET;
1487 /* correct the offset, as we're starting with the 3rd bank */
1489 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1490 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1492 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1493 *bit *= RK3188_PULL_BITS_PER_PIN;
1497 static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1498 int pin_num, struct regmap **regmap,
1501 struct rockchip_pinctrl *info = bank->drvdata;
1502 int drv_num = (pin_num / 8);
1504 /* The bank0:16 and bank1:32 pins are located in PMU */
1505 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1506 *regmap = info->regmap_pmu;
1508 *regmap = info->regmap_base;
1510 *reg = bank->drv[drv_num].offset;
1511 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1512 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1513 *bit = (pin_num % 8) * 3;
1515 *bit = (pin_num % 8) * 2;
1518 #define RK3568_PULL_PMU_OFFSET 0x20
1519 #define RK3568_PULL_GRF_OFFSET 0x80
1520 #define RK3568_PULL_BITS_PER_PIN 2
1521 #define RK3568_PULL_PINS_PER_REG 8
1522 #define RK3568_PULL_BANK_STRIDE 0x10
1524 static void rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1525 int pin_num, struct regmap **regmap,
1528 struct rockchip_pinctrl *info = bank->drvdata;
1530 if (bank->bank_num == 0) {
1531 *regmap = info->regmap_pmu;
1532 *reg = RK3568_PULL_PMU_OFFSET;
1533 *reg += bank->bank_num * RK3568_PULL_BANK_STRIDE;
1534 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1536 *bit = pin_num % RK3568_PULL_PINS_PER_REG;
1537 *bit *= RK3568_PULL_BITS_PER_PIN;
1539 *regmap = info->regmap_base;
1540 *reg = RK3568_PULL_GRF_OFFSET;
1541 *reg += (bank->bank_num - 1) * RK3568_PULL_BANK_STRIDE;
1542 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1544 *bit = (pin_num % RK3568_PULL_PINS_PER_REG);
1545 *bit *= RK3568_PULL_BITS_PER_PIN;
1549 #define RK3568_DRV_PMU_OFFSET 0x70
1550 #define RK3568_DRV_GRF_OFFSET 0x200
1551 #define RK3568_DRV_BITS_PER_PIN 8
1552 #define RK3568_DRV_PINS_PER_REG 2
1553 #define RK3568_DRV_BANK_STRIDE 0x40
1555 static void rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1556 int pin_num, struct regmap **regmap,
1559 struct rockchip_pinctrl *info = bank->drvdata;
1561 /* The first 32 pins of the first bank are located in PMU */
1562 if (bank->bank_num == 0) {
1563 *regmap = info->regmap_pmu;
1564 *reg = RK3568_DRV_PMU_OFFSET;
1565 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1567 *bit = pin_num % RK3568_DRV_PINS_PER_REG;
1568 *bit *= RK3568_DRV_BITS_PER_PIN;
1570 *regmap = info->regmap_base;
1571 *reg = RK3568_DRV_GRF_OFFSET;
1572 *reg += (bank->bank_num - 1) * RK3568_DRV_BANK_STRIDE;
1573 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1575 *bit = (pin_num % RK3568_DRV_PINS_PER_REG);
1576 *bit *= RK3568_DRV_BITS_PER_PIN;
1580 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1581 { 2, 4, 8, 12, -1, -1, -1, -1 },
1582 { 3, 6, 9, 12, -1, -1, -1, -1 },
1583 { 5, 10, 15, 20, -1, -1, -1, -1 },
1584 { 4, 6, 8, 10, 12, 14, 16, 18 },
1585 { 4, 7, 10, 13, 16, 19, 22, 26 }
1588 static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1591 struct rockchip_pinctrl *info = bank->drvdata;
1592 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1593 struct regmap *regmap;
1595 u32 data, temp, rmask_bits;
1597 int drv_type = bank->drv[pin_num / 8].drv_type;
1599 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1602 case DRV_TYPE_IO_1V8_3V0_AUTO:
1603 case DRV_TYPE_IO_3V3_ONLY:
1604 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1607 /* regular case, nothing to do */
1611 * drive-strength offset is special, as it is
1612 * spread over 2 registers
1614 ret = regmap_read(regmap, reg, &data);
1618 ret = regmap_read(regmap, reg + 0x4, &temp);
1623 * the bit data[15] contains bit 0 of the value
1624 * while temp[1:0] contains bits 2 and 1
1631 return rockchip_perpin_drv_list[drv_type][data];
1633 /* setting fully enclosed in the second register */
1638 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1644 case DRV_TYPE_IO_DEFAULT:
1645 case DRV_TYPE_IO_1V8_OR_3V0:
1646 case DRV_TYPE_IO_1V8_ONLY:
1647 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1650 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1655 ret = regmap_read(regmap, reg, &data);
1660 data &= (1 << rmask_bits) - 1;
1662 return rockchip_perpin_drv_list[drv_type][data];
1665 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1666 int pin_num, int strength)
1668 struct rockchip_pinctrl *info = bank->drvdata;
1669 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1670 struct regmap *regmap;
1672 u32 data, rmask, rmask_bits, temp;
1674 int drv_type = bank->drv[pin_num / 8].drv_type;
1676 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1677 bank->bank_num, pin_num, strength);
1679 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1680 if (ctrl->type == RK3568) {
1681 rmask_bits = RK3568_DRV_BITS_PER_PIN;
1682 ret = (1 << (strength + 1)) - 1;
1687 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1688 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
1691 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1692 ret = rockchip_perpin_drv_list[drv_type][i];
1698 dev_err(info->dev, "unsupported driver strength %d\n",
1704 case DRV_TYPE_IO_1V8_3V0_AUTO:
1705 case DRV_TYPE_IO_3V3_ONLY:
1706 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1709 /* regular case, nothing to do */
1713 * drive-strength offset is special, as it is spread
1714 * over 2 registers, the bit data[15] contains bit 0
1715 * of the value while temp[1:0] contains bits 2 and 1
1717 data = (ret & 0x1) << 15;
1718 temp = (ret >> 0x1) & 0x3;
1720 rmask = BIT(15) | BIT(31);
1722 ret = regmap_update_bits(regmap, reg, rmask, data);
1726 rmask = 0x3 | (0x3 << 16);
1727 temp |= (0x3 << 16);
1729 ret = regmap_update_bits(regmap, reg, rmask, temp);
1733 /* setting fully enclosed in the second register */
1738 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1743 case DRV_TYPE_IO_DEFAULT:
1744 case DRV_TYPE_IO_1V8_OR_3V0:
1745 case DRV_TYPE_IO_1V8_ONLY:
1746 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1749 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1755 /* enable the write to the equivalent lower bits */
1756 data = ((1 << rmask_bits) - 1) << (bit + 16);
1757 rmask = data | (data >> 16);
1758 data |= (ret << bit);
1760 ret = regmap_update_bits(regmap, reg, rmask, data);
1765 static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1767 PIN_CONFIG_BIAS_DISABLE,
1768 PIN_CONFIG_BIAS_PULL_UP,
1769 PIN_CONFIG_BIAS_PULL_DOWN,
1770 PIN_CONFIG_BIAS_BUS_HOLD
1773 PIN_CONFIG_BIAS_DISABLE,
1774 PIN_CONFIG_BIAS_PULL_DOWN,
1775 PIN_CONFIG_BIAS_DISABLE,
1776 PIN_CONFIG_BIAS_PULL_UP
1780 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1782 struct rockchip_pinctrl *info = bank->drvdata;
1783 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1784 struct regmap *regmap;
1785 int reg, ret, pull_type;
1789 /* rk3066b does support any pulls */
1790 if (ctrl->type == RK3066B)
1791 return PIN_CONFIG_BIAS_DISABLE;
1793 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1795 ret = regmap_read(regmap, reg, &data);
1799 switch (ctrl->type) {
1802 return !(data & BIT(bit))
1803 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1804 : PIN_CONFIG_BIAS_DISABLE;
1812 pull_type = bank->pull_type[pin_num / 8];
1814 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1816 return rockchip_pull_list[pull_type][data];
1818 dev_err(info->dev, "unsupported pinctrl type\n");
1823 static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1824 int pin_num, int pull)
1826 struct rockchip_pinctrl *info = bank->drvdata;
1827 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1828 struct regmap *regmap;
1829 int reg, ret, i, pull_type;
1833 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
1834 bank->bank_num, pin_num, pull);
1836 /* rk3066b does support any pulls */
1837 if (ctrl->type == RK3066B)
1838 return pull ? -EINVAL : 0;
1840 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1842 switch (ctrl->type) {
1845 data = BIT(bit + 16);
1846 if (pull == PIN_CONFIG_BIAS_DISABLE)
1848 ret = regmap_write(regmap, reg, data);
1858 pull_type = bank->pull_type[pin_num / 8];
1860 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
1862 if (rockchip_pull_list[pull_type][i] == pull) {
1868 * In the TRM, pull-up being 1 for everything except the GPIO0_D0-D6,
1869 * where that pull up value becomes 3.
1871 if (ctrl->type == RK3568 && bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) {
1877 dev_err(info->dev, "unsupported pull setting %d\n",
1882 /* enable the write to the equivalent lower bits */
1883 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
1884 rmask = data | (data >> 16);
1885 data |= (ret << bit);
1887 ret = regmap_update_bits(regmap, reg, rmask, data);
1890 dev_err(info->dev, "unsupported pinctrl type\n");
1897 #define RK3328_SCHMITT_BITS_PER_PIN 1
1898 #define RK3328_SCHMITT_PINS_PER_REG 16
1899 #define RK3328_SCHMITT_BANK_STRIDE 8
1900 #define RK3328_SCHMITT_GRF_OFFSET 0x380
1902 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1904 struct regmap **regmap,
1907 struct rockchip_pinctrl *info = bank->drvdata;
1909 *regmap = info->regmap_base;
1910 *reg = RK3328_SCHMITT_GRF_OFFSET;
1912 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
1913 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
1914 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
1919 #define RK3568_SCHMITT_BITS_PER_PIN 2
1920 #define RK3568_SCHMITT_PINS_PER_REG 8
1921 #define RK3568_SCHMITT_BANK_STRIDE 0x10
1922 #define RK3568_SCHMITT_GRF_OFFSET 0xc0
1923 #define RK3568_SCHMITT_PMUGRF_OFFSET 0x30
1925 static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1927 struct regmap **regmap,
1930 struct rockchip_pinctrl *info = bank->drvdata;
1932 if (bank->bank_num == 0) {
1933 *regmap = info->regmap_pmu;
1934 *reg = RK3568_SCHMITT_PMUGRF_OFFSET;
1936 *regmap = info->regmap_base;
1937 *reg = RK3568_SCHMITT_GRF_OFFSET;
1938 *reg += (bank->bank_num - 1) * RK3568_SCHMITT_BANK_STRIDE;
1941 *reg += ((pin_num / RK3568_SCHMITT_PINS_PER_REG) * 4);
1942 *bit = pin_num % RK3568_SCHMITT_PINS_PER_REG;
1943 *bit *= RK3568_SCHMITT_BITS_PER_PIN;
1948 static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
1950 struct rockchip_pinctrl *info = bank->drvdata;
1951 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1952 struct regmap *regmap;
1957 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1961 ret = regmap_read(regmap, reg, &data);
1966 switch (ctrl->type) {
1968 return data & ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1);
1976 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
1977 int pin_num, int enable)
1979 struct rockchip_pinctrl *info = bank->drvdata;
1980 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1981 struct regmap *regmap;
1986 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
1987 bank->bank_num, pin_num, enable);
1989 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1993 /* enable the write to the equivalent lower bits */
1994 switch (ctrl->type) {
1996 data = ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1) << (bit + 16);
1997 rmask = data | (data >> 16);
1998 data |= ((enable ? 0x2 : 0x1) << bit);
2001 data = BIT(bit + 16) | (enable << bit);
2002 rmask = BIT(bit + 16) | BIT(bit);
2006 return regmap_update_bits(regmap, reg, rmask, data);
2010 * Pinmux_ops handling
2013 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
2015 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2017 return info->nfunctions;
2020 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
2023 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2025 return info->functions[selector].name;
2028 static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
2029 unsigned selector, const char * const **groups,
2030 unsigned * const num_groups)
2032 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2034 *groups = info->functions[selector].groups;
2035 *num_groups = info->functions[selector].ngroups;
2040 static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
2043 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2044 const unsigned int *pins = info->groups[group].pins;
2045 const struct rockchip_pin_config *data = info->groups[group].data;
2046 struct rockchip_pin_bank *bank;
2049 dev_dbg(info->dev, "enable function %s group %s\n",
2050 info->functions[selector].name, info->groups[group].name);
2053 * for each pin in the pin group selected, program the corresponding
2054 * pin function number in the config register.
2056 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
2057 bank = pin_to_bank(info, pins[cnt]);
2058 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
2065 /* revert the already done pin settings */
2066 for (cnt--; cnt >= 0; cnt--)
2067 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
2075 static const struct pinmux_ops rockchip_pmx_ops = {
2076 .get_functions_count = rockchip_pmx_get_funcs_count,
2077 .get_function_name = rockchip_pmx_get_func_name,
2078 .get_function_groups = rockchip_pmx_get_groups,
2079 .set_mux = rockchip_pmx_set,
2083 * Pinconf_ops handling
2086 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2087 enum pin_config_param pull)
2089 switch (ctrl->type) {
2092 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2093 pull == PIN_CONFIG_BIAS_DISABLE);
2095 return pull ? false : true;
2104 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
2110 static int rockchip_pinconf_defer_pin(struct rockchip_pin_bank *bank,
2111 unsigned int pin, u32 param, u32 arg)
2113 struct rockchip_pin_deferred *cfg;
2115 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2123 list_add_tail(&cfg->head, &bank->deferred_pins);
2128 /* set the pin config settings for a specified pin */
2129 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2130 unsigned long *configs, unsigned num_configs)
2132 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2133 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2134 struct gpio_chip *gpio = &bank->gpio_chip;
2135 enum pin_config_param param;
2140 for (i = 0; i < num_configs; i++) {
2141 param = pinconf_to_config_param(configs[i]);
2142 arg = pinconf_to_config_argument(configs[i]);
2144 if (param == (PIN_CONFIG_OUTPUT | PIN_CONFIG_INPUT_ENABLE)) {
2146 * Check for gpio driver not being probed yet.
2147 * The lock makes sure that either gpio-probe has completed
2148 * or the gpio driver hasn't probed yet.
2150 mutex_lock(&bank->deferred_lock);
2151 if (!gpio || !gpio->direction_output) {
2152 rc = rockchip_pinconf_defer_pin(bank, pin - bank->pin_base, param,
2154 mutex_unlock(&bank->deferred_lock);
2160 mutex_unlock(&bank->deferred_lock);
2164 case PIN_CONFIG_BIAS_DISABLE:
2165 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2170 case PIN_CONFIG_BIAS_PULL_UP:
2171 case PIN_CONFIG_BIAS_PULL_DOWN:
2172 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2173 case PIN_CONFIG_BIAS_BUS_HOLD:
2174 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2180 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2185 case PIN_CONFIG_OUTPUT:
2186 rc = rockchip_set_mux(bank, pin - bank->pin_base,
2188 if (rc != RK_FUNC_GPIO)
2191 rc = gpio->direction_output(gpio, pin - bank->pin_base,
2196 case PIN_CONFIG_DRIVE_STRENGTH:
2197 /* rk3288 is the first with per-pin drive-strength */
2198 if (!info->ctrl->drv_calc_reg)
2201 rc = rockchip_set_drive_perpin(bank,
2202 pin - bank->pin_base, arg);
2206 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2207 if (!info->ctrl->schmitt_calc_reg)
2210 rc = rockchip_set_schmitt(bank,
2211 pin - bank->pin_base, arg);
2219 } /* for each config */
2224 /* get the pin config settings for a specified pin */
2225 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2226 unsigned long *config)
2228 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2229 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2230 struct gpio_chip *gpio = &bank->gpio_chip;
2231 enum pin_config_param param = pinconf_to_config_param(*config);
2236 case PIN_CONFIG_BIAS_DISABLE:
2237 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2242 case PIN_CONFIG_BIAS_PULL_UP:
2243 case PIN_CONFIG_BIAS_PULL_DOWN:
2244 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2245 case PIN_CONFIG_BIAS_BUS_HOLD:
2246 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2249 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2254 case PIN_CONFIG_OUTPUT:
2255 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2256 if (rc != RK_FUNC_GPIO)
2259 if (!gpio || !gpio->get) {
2264 rc = gpio->get(gpio, pin - bank->pin_base);
2270 case PIN_CONFIG_DRIVE_STRENGTH:
2271 /* rk3288 is the first with per-pin drive-strength */
2272 if (!info->ctrl->drv_calc_reg)
2275 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
2281 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2282 if (!info->ctrl->schmitt_calc_reg)
2285 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2296 *config = pinconf_to_config_packed(param, arg);
2301 static const struct pinconf_ops rockchip_pinconf_ops = {
2302 .pin_config_get = rockchip_pinconf_get,
2303 .pin_config_set = rockchip_pinconf_set,
2307 static const struct of_device_id rockchip_bank_match[] = {
2308 { .compatible = "rockchip,gpio-bank" },
2309 { .compatible = "rockchip,rk3188-gpio-bank0" },
2313 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2314 struct device_node *np)
2316 struct device_node *child;
2318 for_each_child_of_node(np, child) {
2319 if (of_match_node(rockchip_bank_match, child))
2323 info->ngroups += of_get_child_count(child);
2327 static int rockchip_pinctrl_parse_groups(struct device_node *np,
2328 struct rockchip_pin_group *grp,
2329 struct rockchip_pinctrl *info,
2332 struct rockchip_pin_bank *bank;
2339 dev_dbg(info->dev, "group(%d): %pOFn\n", index, np);
2341 /* Initialise group */
2342 grp->name = np->name;
2345 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2346 * do sanity check and calculate pins number
2348 list = of_get_property(np, "rockchip,pins", &size);
2349 /* we do not check return since it's safe node passed down */
2350 size /= sizeof(*list);
2351 if (!size || size % 4) {
2352 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2356 grp->npins = size / 4;
2358 grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int),
2360 grp->data = devm_kcalloc(info->dev,
2362 sizeof(struct rockchip_pin_config),
2364 if (!grp->pins || !grp->data)
2367 for (i = 0, j = 0; i < size; i += 4, j++) {
2368 const __be32 *phandle;
2369 struct device_node *np_config;
2371 num = be32_to_cpu(*list++);
2372 bank = bank_num_to_bank(info, num);
2374 return PTR_ERR(bank);
2376 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2377 grp->data[j].func = be32_to_cpu(*list++);
2383 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
2384 ret = pinconf_generic_parse_dt_config(np_config, NULL,
2385 &grp->data[j].configs, &grp->data[j].nconfigs);
2393 static int rockchip_pinctrl_parse_functions(struct device_node *np,
2394 struct rockchip_pinctrl *info,
2397 struct device_node *child;
2398 struct rockchip_pmx_func *func;
2399 struct rockchip_pin_group *grp;
2401 static u32 grp_index;
2404 dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np);
2406 func = &info->functions[index];
2408 /* Initialise function */
2409 func->name = np->name;
2410 func->ngroups = of_get_child_count(np);
2411 if (func->ngroups <= 0)
2414 func->groups = devm_kcalloc(info->dev,
2415 func->ngroups, sizeof(char *), GFP_KERNEL);
2419 for_each_child_of_node(np, child) {
2420 func->groups[i] = child->name;
2421 grp = &info->groups[grp_index++];
2422 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
2432 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2433 struct rockchip_pinctrl *info)
2435 struct device *dev = &pdev->dev;
2436 struct device_node *np = dev->of_node;
2437 struct device_node *child;
2441 rockchip_pinctrl_child_count(info, np);
2443 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2444 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2446 info->functions = devm_kcalloc(dev,
2448 sizeof(struct rockchip_pmx_func),
2450 if (!info->functions)
2453 info->groups = devm_kcalloc(dev,
2455 sizeof(struct rockchip_pin_group),
2462 for_each_child_of_node(np, child) {
2463 if (of_match_node(rockchip_bank_match, child))
2466 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2468 dev_err(&pdev->dev, "failed to parse function\n");
2477 static int rockchip_pinctrl_register(struct platform_device *pdev,
2478 struct rockchip_pinctrl *info)
2480 struct pinctrl_desc *ctrldesc = &info->pctl;
2481 struct pinctrl_pin_desc *pindesc, *pdesc;
2482 struct rockchip_pin_bank *pin_bank;
2486 ctrldesc->name = "rockchip-pinctrl";
2487 ctrldesc->owner = THIS_MODULE;
2488 ctrldesc->pctlops = &rockchip_pctrl_ops;
2489 ctrldesc->pmxops = &rockchip_pmx_ops;
2490 ctrldesc->confops = &rockchip_pinconf_ops;
2492 pindesc = devm_kcalloc(&pdev->dev,
2493 info->ctrl->nr_pins, sizeof(*pindesc),
2498 ctrldesc->pins = pindesc;
2499 ctrldesc->npins = info->ctrl->nr_pins;
2502 for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) {
2503 pin_bank = &info->ctrl->pin_banks[bank];
2504 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2506 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2507 pin_bank->name, pin);
2511 INIT_LIST_HEAD(&pin_bank->deferred_pins);
2512 mutex_init(&pin_bank->deferred_lock);
2515 ret = rockchip_pinctrl_parse_dt(pdev, info);
2519 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
2520 if (IS_ERR(info->pctl_dev)) {
2521 dev_err(&pdev->dev, "could not register pinctrl driver\n");
2522 return PTR_ERR(info->pctl_dev);
2528 static const struct of_device_id rockchip_pinctrl_dt_match[];
2530 /* retrieve the soc specific data */
2531 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2532 struct rockchip_pinctrl *d,
2533 struct platform_device *pdev)
2535 const struct of_device_id *match;
2536 struct device_node *node = pdev->dev.of_node;
2537 struct rockchip_pin_ctrl *ctrl;
2538 struct rockchip_pin_bank *bank;
2539 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
2541 match = of_match_node(rockchip_pinctrl_dt_match, node);
2542 ctrl = (struct rockchip_pin_ctrl *)match->data;
2544 grf_offs = ctrl->grf_mux_offset;
2545 pmu_offs = ctrl->pmu_mux_offset;
2546 drv_pmu_offs = ctrl->pmu_drv_offset;
2547 drv_grf_offs = ctrl->grf_drv_offset;
2548 bank = ctrl->pin_banks;
2549 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2552 raw_spin_lock_init(&bank->slock);
2554 bank->pin_base = ctrl->nr_pins;
2555 ctrl->nr_pins += bank->nr_pins;
2557 /* calculate iomux and drv offsets */
2558 for (j = 0; j < 4; j++) {
2559 struct rockchip_iomux *iom = &bank->iomux[j];
2560 struct rockchip_drv *drv = &bank->drv[j];
2563 if (bank_pins >= bank->nr_pins)
2566 /* preset iomux offset value, set new start value */
2567 if (iom->offset >= 0) {
2568 if (iom->type & IOMUX_SOURCE_PMU)
2569 pmu_offs = iom->offset;
2571 grf_offs = iom->offset;
2572 } else { /* set current iomux offset */
2573 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2574 pmu_offs : grf_offs;
2577 /* preset drv offset value, set new start value */
2578 if (drv->offset >= 0) {
2579 if (iom->type & IOMUX_SOURCE_PMU)
2580 drv_pmu_offs = drv->offset;
2582 drv_grf_offs = drv->offset;
2583 } else { /* set current drv offset */
2584 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2585 drv_pmu_offs : drv_grf_offs;
2588 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
2589 i, j, iom->offset, drv->offset);
2592 * Increase offset according to iomux width.
2593 * 4bit iomux'es are spread over two registers.
2595 inc = (iom->type & (IOMUX_WIDTH_4BIT |
2597 IOMUX_WIDTH_2BIT)) ? 8 : 4;
2598 if (iom->type & IOMUX_SOURCE_PMU)
2604 * Increase offset according to drv width.
2605 * 3bit drive-strenth'es are spread over two registers.
2607 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
2608 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
2613 if (iom->type & IOMUX_SOURCE_PMU)
2614 drv_pmu_offs += inc;
2616 drv_grf_offs += inc;
2621 /* calculate the per-bank recalced_mask */
2622 for (j = 0; j < ctrl->niomux_recalced; j++) {
2625 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
2626 pin = ctrl->iomux_recalced[j].pin;
2627 bank->recalced_mask |= BIT(pin);
2631 /* calculate the per-bank route_mask */
2632 for (j = 0; j < ctrl->niomux_routes; j++) {
2635 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
2636 pin = ctrl->iomux_routes[j].pin;
2637 bank->route_mask |= BIT(pin);
2645 #define RK3288_GRF_GPIO6C_IOMUX 0x64
2646 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
2648 static u32 rk3288_grf_gpio6c_iomux;
2650 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
2652 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2653 int ret = pinctrl_force_sleep(info->pctl_dev);
2659 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
2660 * the setting here, and restore it at resume.
2662 if (info->ctrl->type == RK3288) {
2663 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2664 &rk3288_grf_gpio6c_iomux);
2666 pinctrl_force_default(info->pctl_dev);
2674 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
2676 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2679 if (info->ctrl->type == RK3288) {
2680 ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2681 rk3288_grf_gpio6c_iomux |
2682 GPIO6C6_SEL_WRITE_ENABLE);
2687 return pinctrl_force_default(info->pctl_dev);
2690 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
2691 rockchip_pinctrl_resume);
2693 static int rockchip_pinctrl_probe(struct platform_device *pdev)
2695 struct rockchip_pinctrl *info;
2696 struct device *dev = &pdev->dev;
2697 struct rockchip_pin_ctrl *ctrl;
2698 struct device_node *np = pdev->dev.of_node, *node;
2699 struct resource *res;
2703 if (!dev->of_node) {
2704 dev_err(dev, "device tree node not found\n");
2708 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
2714 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
2716 dev_err(dev, "driver data not available\n");
2721 node = of_parse_phandle(np, "rockchip,grf", 0);
2723 info->regmap_base = syscon_node_to_regmap(node);
2725 if (IS_ERR(info->regmap_base))
2726 return PTR_ERR(info->regmap_base);
2728 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2729 base = devm_ioremap_resource(&pdev->dev, res);
2731 return PTR_ERR(base);
2733 rockchip_regmap_config.max_register = resource_size(res) - 4;
2734 rockchip_regmap_config.name = "rockchip,pinctrl";
2735 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
2736 &rockchip_regmap_config);
2738 /* to check for the old dt-bindings */
2739 info->reg_size = resource_size(res);
2741 /* Honor the old binding, with pull registers as 2nd resource */
2742 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
2743 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2744 base = devm_ioremap_resource(&pdev->dev, res);
2746 return PTR_ERR(base);
2748 rockchip_regmap_config.max_register =
2749 resource_size(res) - 4;
2750 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
2751 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
2753 &rockchip_regmap_config);
2757 /* try to find the optional reference to the pmu syscon */
2758 node = of_parse_phandle(np, "rockchip,pmu", 0);
2760 info->regmap_pmu = syscon_node_to_regmap(node);
2762 if (IS_ERR(info->regmap_pmu))
2763 return PTR_ERR(info->regmap_pmu);
2766 ret = rockchip_pinctrl_register(pdev, info);
2770 platform_set_drvdata(pdev, info);
2772 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
2774 dev_err(&pdev->dev, "failed to register gpio device\n");
2781 static int rockchip_pinctrl_remove(struct platform_device *pdev)
2783 struct rockchip_pinctrl *info = platform_get_drvdata(pdev);
2784 struct rockchip_pin_bank *bank;
2785 struct rockchip_pin_deferred *cfg;
2788 of_platform_depopulate(&pdev->dev);
2790 for (i = 0; i < info->ctrl->nr_banks; i++) {
2791 bank = &info->ctrl->pin_banks[i];
2793 mutex_lock(&bank->deferred_lock);
2794 while (!list_empty(&bank->deferred_pins)) {
2795 cfg = list_first_entry(&bank->deferred_pins,
2796 struct rockchip_pin_deferred, head);
2797 list_del(&cfg->head);
2800 mutex_unlock(&bank->deferred_lock);
2806 static struct rockchip_pin_bank px30_pin_banks[] = {
2807 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2812 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
2817 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
2822 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
2829 static struct rockchip_pin_ctrl px30_pin_ctrl = {
2830 .pin_banks = px30_pin_banks,
2831 .nr_banks = ARRAY_SIZE(px30_pin_banks),
2832 .label = "PX30-GPIO",
2834 .grf_mux_offset = 0x0,
2835 .pmu_mux_offset = 0x0,
2836 .iomux_routes = px30_mux_route_data,
2837 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
2838 .pull_calc_reg = px30_calc_pull_reg_and_bit,
2839 .drv_calc_reg = px30_calc_drv_reg_and_bit,
2840 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
2843 static struct rockchip_pin_bank rv1108_pin_banks[] = {
2844 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2848 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
2849 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
2850 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
2853 static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
2854 .pin_banks = rv1108_pin_banks,
2855 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
2856 .label = "RV1108-GPIO",
2858 .grf_mux_offset = 0x10,
2859 .pmu_mux_offset = 0x0,
2860 .iomux_recalced = rv1108_mux_recalced_data,
2861 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
2862 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
2863 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
2864 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
2867 static struct rockchip_pin_bank rk2928_pin_banks[] = {
2868 PIN_BANK(0, 32, "gpio0"),
2869 PIN_BANK(1, 32, "gpio1"),
2870 PIN_BANK(2, 32, "gpio2"),
2871 PIN_BANK(3, 32, "gpio3"),
2874 static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
2875 .pin_banks = rk2928_pin_banks,
2876 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
2877 .label = "RK2928-GPIO",
2879 .grf_mux_offset = 0xa8,
2880 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2883 static struct rockchip_pin_bank rk3036_pin_banks[] = {
2884 PIN_BANK(0, 32, "gpio0"),
2885 PIN_BANK(1, 32, "gpio1"),
2886 PIN_BANK(2, 32, "gpio2"),
2889 static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
2890 .pin_banks = rk3036_pin_banks,
2891 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
2892 .label = "RK3036-GPIO",
2894 .grf_mux_offset = 0xa8,
2895 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2898 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
2899 PIN_BANK(0, 32, "gpio0"),
2900 PIN_BANK(1, 32, "gpio1"),
2901 PIN_BANK(2, 32, "gpio2"),
2902 PIN_BANK(3, 32, "gpio3"),
2903 PIN_BANK(4, 32, "gpio4"),
2904 PIN_BANK(6, 16, "gpio6"),
2907 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
2908 .pin_banks = rk3066a_pin_banks,
2909 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
2910 .label = "RK3066a-GPIO",
2912 .grf_mux_offset = 0xa8,
2913 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2916 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
2917 PIN_BANK(0, 32, "gpio0"),
2918 PIN_BANK(1, 32, "gpio1"),
2919 PIN_BANK(2, 32, "gpio2"),
2920 PIN_BANK(3, 32, "gpio3"),
2923 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
2924 .pin_banks = rk3066b_pin_banks,
2925 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
2926 .label = "RK3066b-GPIO",
2928 .grf_mux_offset = 0x60,
2931 static struct rockchip_pin_bank rk3128_pin_banks[] = {
2932 PIN_BANK(0, 32, "gpio0"),
2933 PIN_BANK(1, 32, "gpio1"),
2934 PIN_BANK(2, 32, "gpio2"),
2935 PIN_BANK(3, 32, "gpio3"),
2938 static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
2939 .pin_banks = rk3128_pin_banks,
2940 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
2941 .label = "RK3128-GPIO",
2943 .grf_mux_offset = 0xa8,
2944 .iomux_recalced = rk3128_mux_recalced_data,
2945 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
2946 .iomux_routes = rk3128_mux_route_data,
2947 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
2948 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
2951 static struct rockchip_pin_bank rk3188_pin_banks[] = {
2952 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
2953 PIN_BANK(1, 32, "gpio1"),
2954 PIN_BANK(2, 32, "gpio2"),
2955 PIN_BANK(3, 32, "gpio3"),
2958 static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
2959 .pin_banks = rk3188_pin_banks,
2960 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
2961 .label = "RK3188-GPIO",
2963 .grf_mux_offset = 0x60,
2964 .iomux_routes = rk3188_mux_route_data,
2965 .niomux_routes = ARRAY_SIZE(rk3188_mux_route_data),
2966 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
2969 static struct rockchip_pin_bank rk3228_pin_banks[] = {
2970 PIN_BANK(0, 32, "gpio0"),
2971 PIN_BANK(1, 32, "gpio1"),
2972 PIN_BANK(2, 32, "gpio2"),
2973 PIN_BANK(3, 32, "gpio3"),
2976 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
2977 .pin_banks = rk3228_pin_banks,
2978 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
2979 .label = "RK3228-GPIO",
2981 .grf_mux_offset = 0x0,
2982 .iomux_routes = rk3228_mux_route_data,
2983 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
2984 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
2985 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
2988 static struct rockchip_pin_bank rk3288_pin_banks[] = {
2989 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
2994 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
2999 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3000 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3001 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3006 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3011 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3012 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3017 PIN_BANK(8, 16, "gpio8"),
3020 static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3021 .pin_banks = rk3288_pin_banks,
3022 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3023 .label = "RK3288-GPIO",
3025 .grf_mux_offset = 0x0,
3026 .pmu_mux_offset = 0x84,
3027 .iomux_routes = rk3288_mux_route_data,
3028 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
3029 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
3030 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
3033 static struct rockchip_pin_bank rk3308_pin_banks[] = {
3034 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT,
3038 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT,
3042 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT,
3046 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT,
3050 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT,
3056 static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
3057 .pin_banks = rk3308_pin_banks,
3058 .nr_banks = ARRAY_SIZE(rk3308_pin_banks),
3059 .label = "RK3308-GPIO",
3061 .grf_mux_offset = 0x0,
3062 .iomux_recalced = rk3308_mux_recalced_data,
3063 .niomux_recalced = ARRAY_SIZE(rk3308_mux_recalced_data),
3064 .iomux_routes = rk3308_mux_route_data,
3065 .niomux_routes = ARRAY_SIZE(rk3308_mux_route_data),
3066 .pull_calc_reg = rk3308_calc_pull_reg_and_bit,
3067 .drv_calc_reg = rk3308_calc_drv_reg_and_bit,
3068 .schmitt_calc_reg = rk3308_calc_schmitt_reg_and_bit,
3071 static struct rockchip_pin_bank rk3328_pin_banks[] = {
3072 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3073 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3074 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3078 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3085 static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3086 .pin_banks = rk3328_pin_banks,
3087 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3088 .label = "RK3328-GPIO",
3090 .grf_mux_offset = 0x0,
3091 .iomux_recalced = rk3328_mux_recalced_data,
3092 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
3093 .iomux_routes = rk3328_mux_route_data,
3094 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
3095 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3096 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3097 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
3100 static struct rockchip_pin_bank rk3368_pin_banks[] = {
3101 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3106 PIN_BANK(1, 32, "gpio1"),
3107 PIN_BANK(2, 32, "gpio2"),
3108 PIN_BANK(3, 32, "gpio3"),
3111 static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3112 .pin_banks = rk3368_pin_banks,
3113 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3114 .label = "RK3368-GPIO",
3116 .grf_mux_offset = 0x0,
3117 .pmu_mux_offset = 0x0,
3118 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3119 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3122 static struct rockchip_pin_bank rk3399_pin_banks[] = {
3123 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3128 DRV_TYPE_IO_1V8_ONLY,
3129 DRV_TYPE_IO_1V8_ONLY,
3130 DRV_TYPE_IO_DEFAULT,
3131 DRV_TYPE_IO_DEFAULT,
3136 PULL_TYPE_IO_1V8_ONLY,
3137 PULL_TYPE_IO_1V8_ONLY,
3138 PULL_TYPE_IO_DEFAULT,
3139 PULL_TYPE_IO_DEFAULT
3141 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3145 DRV_TYPE_IO_1V8_OR_3V0,
3146 DRV_TYPE_IO_1V8_OR_3V0,
3147 DRV_TYPE_IO_1V8_OR_3V0,
3148 DRV_TYPE_IO_1V8_OR_3V0,
3154 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3155 DRV_TYPE_IO_1V8_OR_3V0,
3156 DRV_TYPE_IO_1V8_ONLY,
3157 DRV_TYPE_IO_1V8_ONLY,
3158 PULL_TYPE_IO_DEFAULT,
3159 PULL_TYPE_IO_DEFAULT,
3160 PULL_TYPE_IO_1V8_ONLY,
3161 PULL_TYPE_IO_1V8_ONLY
3163 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3164 DRV_TYPE_IO_3V3_ONLY,
3165 DRV_TYPE_IO_3V3_ONLY,
3166 DRV_TYPE_IO_1V8_OR_3V0
3168 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3169 DRV_TYPE_IO_1V8_3V0_AUTO,
3170 DRV_TYPE_IO_1V8_OR_3V0,
3171 DRV_TYPE_IO_1V8_OR_3V0
3175 static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3176 .pin_banks = rk3399_pin_banks,
3177 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3178 .label = "RK3399-GPIO",
3180 .grf_mux_offset = 0xe000,
3181 .pmu_mux_offset = 0x0,
3182 .grf_drv_offset = 0xe100,
3183 .pmu_drv_offset = 0x80,
3184 .iomux_routes = rk3399_mux_route_data,
3185 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
3186 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3187 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3190 static struct rockchip_pin_bank rk3568_pin_banks[] = {
3191 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3192 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3193 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3194 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT),
3195 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3199 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3203 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3207 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3213 static struct rockchip_pin_ctrl rk3568_pin_ctrl = {
3214 .pin_banks = rk3568_pin_banks,
3215 .nr_banks = ARRAY_SIZE(rk3568_pin_banks),
3216 .label = "RK3568-GPIO",
3218 .grf_mux_offset = 0x0,
3219 .pmu_mux_offset = 0x0,
3220 .grf_drv_offset = 0x0200,
3221 .pmu_drv_offset = 0x0070,
3222 .iomux_routes = rk3568_mux_route_data,
3223 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data),
3224 .pull_calc_reg = rk3568_calc_pull_reg_and_bit,
3225 .drv_calc_reg = rk3568_calc_drv_reg_and_bit,
3226 .schmitt_calc_reg = rk3568_calc_schmitt_reg_and_bit,
3229 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
3230 { .compatible = "rockchip,px30-pinctrl",
3231 .data = &px30_pin_ctrl },
3232 { .compatible = "rockchip,rv1108-pinctrl",
3233 .data = &rv1108_pin_ctrl },
3234 { .compatible = "rockchip,rk2928-pinctrl",
3235 .data = &rk2928_pin_ctrl },
3236 { .compatible = "rockchip,rk3036-pinctrl",
3237 .data = &rk3036_pin_ctrl },
3238 { .compatible = "rockchip,rk3066a-pinctrl",
3239 .data = &rk3066a_pin_ctrl },
3240 { .compatible = "rockchip,rk3066b-pinctrl",
3241 .data = &rk3066b_pin_ctrl },
3242 { .compatible = "rockchip,rk3128-pinctrl",
3243 .data = (void *)&rk3128_pin_ctrl },
3244 { .compatible = "rockchip,rk3188-pinctrl",
3245 .data = &rk3188_pin_ctrl },
3246 { .compatible = "rockchip,rk3228-pinctrl",
3247 .data = &rk3228_pin_ctrl },
3248 { .compatible = "rockchip,rk3288-pinctrl",
3249 .data = &rk3288_pin_ctrl },
3250 { .compatible = "rockchip,rk3308-pinctrl",
3251 .data = &rk3308_pin_ctrl },
3252 { .compatible = "rockchip,rk3328-pinctrl",
3253 .data = &rk3328_pin_ctrl },
3254 { .compatible = "rockchip,rk3368-pinctrl",
3255 .data = &rk3368_pin_ctrl },
3256 { .compatible = "rockchip,rk3399-pinctrl",
3257 .data = &rk3399_pin_ctrl },
3258 { .compatible = "rockchip,rk3568-pinctrl",
3259 .data = &rk3568_pin_ctrl },
3263 static struct platform_driver rockchip_pinctrl_driver = {
3264 .probe = rockchip_pinctrl_probe,
3265 .remove = rockchip_pinctrl_remove,
3267 .name = "rockchip-pinctrl",
3268 .pm = &rockchip_pinctrl_dev_pm_ops,
3269 .of_match_table = rockchip_pinctrl_dt_match,
3273 static int __init rockchip_pinctrl_drv_register(void)
3275 return platform_driver_register(&rockchip_pinctrl_driver);
3277 postcore_initcall(rockchip_pinctrl_drv_register);
3279 static void __exit rockchip_pinctrl_drv_unregister(void)
3281 platform_driver_unregister(&rockchip_pinctrl_driver);
3283 module_exit(rockchip_pinctrl_drv_unregister);
3285 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver");
3286 MODULE_LICENSE("GPL");
3287 MODULE_ALIAS("platform:pinctrl-rockchip");
3288 MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match);