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 static int rockchip_pinconf_defer_output(struct rockchip_pin_bank *bank,
2096 unsigned int pin, u32 arg)
2098 struct rockchip_pin_output_deferred *cfg;
2100 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2107 list_add_tail(&cfg->head, &bank->deferred_output);
2112 /* set the pin config settings for a specified pin */
2113 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2114 unsigned long *configs, unsigned num_configs)
2116 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2117 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2118 struct gpio_chip *gpio = &bank->gpio_chip;
2119 enum pin_config_param param;
2124 for (i = 0; i < num_configs; i++) {
2125 param = pinconf_to_config_param(configs[i]);
2126 arg = pinconf_to_config_argument(configs[i]);
2129 case PIN_CONFIG_BIAS_DISABLE:
2130 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2135 case PIN_CONFIG_BIAS_PULL_UP:
2136 case PIN_CONFIG_BIAS_PULL_DOWN:
2137 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2138 case PIN_CONFIG_BIAS_BUS_HOLD:
2139 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2145 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2150 case PIN_CONFIG_OUTPUT:
2151 rc = rockchip_set_mux(bank, pin - bank->pin_base,
2153 if (rc != RK_FUNC_GPIO)
2157 * Check for gpio driver not being probed yet.
2158 * The lock makes sure that either gpio-probe has completed
2159 * or the gpio driver hasn't probed yet.
2161 mutex_lock(&bank->deferred_lock);
2162 if (!gpio || !gpio->direction_output) {
2163 rc = rockchip_pinconf_defer_output(bank, pin - bank->pin_base, arg);
2164 mutex_unlock(&bank->deferred_lock);
2170 mutex_unlock(&bank->deferred_lock);
2172 rc = gpio->direction_output(gpio, pin - bank->pin_base,
2177 case PIN_CONFIG_DRIVE_STRENGTH:
2178 /* rk3288 is the first with per-pin drive-strength */
2179 if (!info->ctrl->drv_calc_reg)
2182 rc = rockchip_set_drive_perpin(bank,
2183 pin - bank->pin_base, arg);
2187 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2188 if (!info->ctrl->schmitt_calc_reg)
2191 rc = rockchip_set_schmitt(bank,
2192 pin - bank->pin_base, arg);
2200 } /* for each config */
2205 /* get the pin config settings for a specified pin */
2206 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2207 unsigned long *config)
2209 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2210 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2211 struct gpio_chip *gpio = &bank->gpio_chip;
2212 enum pin_config_param param = pinconf_to_config_param(*config);
2217 case PIN_CONFIG_BIAS_DISABLE:
2218 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2223 case PIN_CONFIG_BIAS_PULL_UP:
2224 case PIN_CONFIG_BIAS_PULL_DOWN:
2225 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2226 case PIN_CONFIG_BIAS_BUS_HOLD:
2227 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2230 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2235 case PIN_CONFIG_OUTPUT:
2236 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2237 if (rc != RK_FUNC_GPIO)
2240 if (!gpio || !gpio->get) {
2245 rc = gpio->get(gpio, pin - bank->pin_base);
2251 case PIN_CONFIG_DRIVE_STRENGTH:
2252 /* rk3288 is the first with per-pin drive-strength */
2253 if (!info->ctrl->drv_calc_reg)
2256 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
2262 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2263 if (!info->ctrl->schmitt_calc_reg)
2266 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2277 *config = pinconf_to_config_packed(param, arg);
2282 static const struct pinconf_ops rockchip_pinconf_ops = {
2283 .pin_config_get = rockchip_pinconf_get,
2284 .pin_config_set = rockchip_pinconf_set,
2288 static const struct of_device_id rockchip_bank_match[] = {
2289 { .compatible = "rockchip,gpio-bank" },
2290 { .compatible = "rockchip,rk3188-gpio-bank0" },
2294 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2295 struct device_node *np)
2297 struct device_node *child;
2299 for_each_child_of_node(np, child) {
2300 if (of_match_node(rockchip_bank_match, child))
2304 info->ngroups += of_get_child_count(child);
2308 static int rockchip_pinctrl_parse_groups(struct device_node *np,
2309 struct rockchip_pin_group *grp,
2310 struct rockchip_pinctrl *info,
2313 struct rockchip_pin_bank *bank;
2320 dev_dbg(info->dev, "group(%d): %pOFn\n", index, np);
2322 /* Initialise group */
2323 grp->name = np->name;
2326 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2327 * do sanity check and calculate pins number
2329 list = of_get_property(np, "rockchip,pins", &size);
2330 /* we do not check return since it's safe node passed down */
2331 size /= sizeof(*list);
2332 if (!size || size % 4) {
2333 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2337 grp->npins = size / 4;
2339 grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int),
2341 grp->data = devm_kcalloc(info->dev,
2343 sizeof(struct rockchip_pin_config),
2345 if (!grp->pins || !grp->data)
2348 for (i = 0, j = 0; i < size; i += 4, j++) {
2349 const __be32 *phandle;
2350 struct device_node *np_config;
2352 num = be32_to_cpu(*list++);
2353 bank = bank_num_to_bank(info, num);
2355 return PTR_ERR(bank);
2357 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2358 grp->data[j].func = be32_to_cpu(*list++);
2364 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
2365 ret = pinconf_generic_parse_dt_config(np_config, NULL,
2366 &grp->data[j].configs, &grp->data[j].nconfigs);
2374 static int rockchip_pinctrl_parse_functions(struct device_node *np,
2375 struct rockchip_pinctrl *info,
2378 struct device_node *child;
2379 struct rockchip_pmx_func *func;
2380 struct rockchip_pin_group *grp;
2382 static u32 grp_index;
2385 dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np);
2387 func = &info->functions[index];
2389 /* Initialise function */
2390 func->name = np->name;
2391 func->ngroups = of_get_child_count(np);
2392 if (func->ngroups <= 0)
2395 func->groups = devm_kcalloc(info->dev,
2396 func->ngroups, sizeof(char *), GFP_KERNEL);
2400 for_each_child_of_node(np, child) {
2401 func->groups[i] = child->name;
2402 grp = &info->groups[grp_index++];
2403 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
2413 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2414 struct rockchip_pinctrl *info)
2416 struct device *dev = &pdev->dev;
2417 struct device_node *np = dev->of_node;
2418 struct device_node *child;
2422 rockchip_pinctrl_child_count(info, np);
2424 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2425 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2427 info->functions = devm_kcalloc(dev,
2429 sizeof(struct rockchip_pmx_func),
2431 if (!info->functions)
2434 info->groups = devm_kcalloc(dev,
2436 sizeof(struct rockchip_pin_group),
2443 for_each_child_of_node(np, child) {
2444 if (of_match_node(rockchip_bank_match, child))
2447 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2449 dev_err(&pdev->dev, "failed to parse function\n");
2458 static int rockchip_pinctrl_register(struct platform_device *pdev,
2459 struct rockchip_pinctrl *info)
2461 struct pinctrl_desc *ctrldesc = &info->pctl;
2462 struct pinctrl_pin_desc *pindesc, *pdesc;
2463 struct rockchip_pin_bank *pin_bank;
2467 ctrldesc->name = "rockchip-pinctrl";
2468 ctrldesc->owner = THIS_MODULE;
2469 ctrldesc->pctlops = &rockchip_pctrl_ops;
2470 ctrldesc->pmxops = &rockchip_pmx_ops;
2471 ctrldesc->confops = &rockchip_pinconf_ops;
2473 pindesc = devm_kcalloc(&pdev->dev,
2474 info->ctrl->nr_pins, sizeof(*pindesc),
2479 ctrldesc->pins = pindesc;
2480 ctrldesc->npins = info->ctrl->nr_pins;
2483 for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) {
2484 pin_bank = &info->ctrl->pin_banks[bank];
2485 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2487 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2488 pin_bank->name, pin);
2492 INIT_LIST_HEAD(&pin_bank->deferred_output);
2493 mutex_init(&pin_bank->deferred_lock);
2496 ret = rockchip_pinctrl_parse_dt(pdev, info);
2500 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
2501 if (IS_ERR(info->pctl_dev)) {
2502 dev_err(&pdev->dev, "could not register pinctrl driver\n");
2503 return PTR_ERR(info->pctl_dev);
2509 static const struct of_device_id rockchip_pinctrl_dt_match[];
2511 /* retrieve the soc specific data */
2512 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2513 struct rockchip_pinctrl *d,
2514 struct platform_device *pdev)
2516 const struct of_device_id *match;
2517 struct device_node *node = pdev->dev.of_node;
2518 struct rockchip_pin_ctrl *ctrl;
2519 struct rockchip_pin_bank *bank;
2520 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
2522 match = of_match_node(rockchip_pinctrl_dt_match, node);
2523 ctrl = (struct rockchip_pin_ctrl *)match->data;
2525 grf_offs = ctrl->grf_mux_offset;
2526 pmu_offs = ctrl->pmu_mux_offset;
2527 drv_pmu_offs = ctrl->pmu_drv_offset;
2528 drv_grf_offs = ctrl->grf_drv_offset;
2529 bank = ctrl->pin_banks;
2530 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2533 raw_spin_lock_init(&bank->slock);
2535 bank->pin_base = ctrl->nr_pins;
2536 ctrl->nr_pins += bank->nr_pins;
2538 /* calculate iomux and drv offsets */
2539 for (j = 0; j < 4; j++) {
2540 struct rockchip_iomux *iom = &bank->iomux[j];
2541 struct rockchip_drv *drv = &bank->drv[j];
2544 if (bank_pins >= bank->nr_pins)
2547 /* preset iomux offset value, set new start value */
2548 if (iom->offset >= 0) {
2549 if (iom->type & IOMUX_SOURCE_PMU)
2550 pmu_offs = iom->offset;
2552 grf_offs = iom->offset;
2553 } else { /* set current iomux offset */
2554 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2555 pmu_offs : grf_offs;
2558 /* preset drv offset value, set new start value */
2559 if (drv->offset >= 0) {
2560 if (iom->type & IOMUX_SOURCE_PMU)
2561 drv_pmu_offs = drv->offset;
2563 drv_grf_offs = drv->offset;
2564 } else { /* set current drv offset */
2565 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2566 drv_pmu_offs : drv_grf_offs;
2569 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
2570 i, j, iom->offset, drv->offset);
2573 * Increase offset according to iomux width.
2574 * 4bit iomux'es are spread over two registers.
2576 inc = (iom->type & (IOMUX_WIDTH_4BIT |
2578 IOMUX_WIDTH_2BIT)) ? 8 : 4;
2579 if (iom->type & IOMUX_SOURCE_PMU)
2585 * Increase offset according to drv width.
2586 * 3bit drive-strenth'es are spread over two registers.
2588 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
2589 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
2594 if (iom->type & IOMUX_SOURCE_PMU)
2595 drv_pmu_offs += inc;
2597 drv_grf_offs += inc;
2602 /* calculate the per-bank recalced_mask */
2603 for (j = 0; j < ctrl->niomux_recalced; j++) {
2606 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
2607 pin = ctrl->iomux_recalced[j].pin;
2608 bank->recalced_mask |= BIT(pin);
2612 /* calculate the per-bank route_mask */
2613 for (j = 0; j < ctrl->niomux_routes; j++) {
2616 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
2617 pin = ctrl->iomux_routes[j].pin;
2618 bank->route_mask |= BIT(pin);
2626 #define RK3288_GRF_GPIO6C_IOMUX 0x64
2627 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
2629 static u32 rk3288_grf_gpio6c_iomux;
2631 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
2633 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2634 int ret = pinctrl_force_sleep(info->pctl_dev);
2640 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
2641 * the setting here, and restore it at resume.
2643 if (info->ctrl->type == RK3288) {
2644 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2645 &rk3288_grf_gpio6c_iomux);
2647 pinctrl_force_default(info->pctl_dev);
2655 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
2657 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2660 if (info->ctrl->type == RK3288) {
2661 ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2662 rk3288_grf_gpio6c_iomux |
2663 GPIO6C6_SEL_WRITE_ENABLE);
2668 return pinctrl_force_default(info->pctl_dev);
2671 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
2672 rockchip_pinctrl_resume);
2674 static int rockchip_pinctrl_probe(struct platform_device *pdev)
2676 struct rockchip_pinctrl *info;
2677 struct device *dev = &pdev->dev;
2678 struct rockchip_pin_ctrl *ctrl;
2679 struct device_node *np = pdev->dev.of_node, *node;
2680 struct resource *res;
2684 if (!dev->of_node) {
2685 dev_err(dev, "device tree node not found\n");
2689 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
2695 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
2697 dev_err(dev, "driver data not available\n");
2702 node = of_parse_phandle(np, "rockchip,grf", 0);
2704 info->regmap_base = syscon_node_to_regmap(node);
2705 if (IS_ERR(info->regmap_base))
2706 return PTR_ERR(info->regmap_base);
2708 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2709 base = devm_ioremap_resource(&pdev->dev, res);
2711 return PTR_ERR(base);
2713 rockchip_regmap_config.max_register = resource_size(res) - 4;
2714 rockchip_regmap_config.name = "rockchip,pinctrl";
2715 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
2716 &rockchip_regmap_config);
2718 /* to check for the old dt-bindings */
2719 info->reg_size = resource_size(res);
2721 /* Honor the old binding, with pull registers as 2nd resource */
2722 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
2723 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2724 base = devm_ioremap_resource(&pdev->dev, res);
2726 return PTR_ERR(base);
2728 rockchip_regmap_config.max_register =
2729 resource_size(res) - 4;
2730 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
2731 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
2733 &rockchip_regmap_config);
2737 /* try to find the optional reference to the pmu syscon */
2738 node = of_parse_phandle(np, "rockchip,pmu", 0);
2740 info->regmap_pmu = syscon_node_to_regmap(node);
2741 if (IS_ERR(info->regmap_pmu))
2742 return PTR_ERR(info->regmap_pmu);
2745 ret = rockchip_pinctrl_register(pdev, info);
2749 platform_set_drvdata(pdev, info);
2751 ret = of_platform_populate(np, rockchip_bank_match, NULL, NULL);
2753 dev_err(&pdev->dev, "failed to register gpio device\n");
2760 static int rockchip_pinctrl_remove(struct platform_device *pdev)
2762 struct rockchip_pinctrl *info = platform_get_drvdata(pdev);
2763 struct rockchip_pin_bank *bank;
2764 struct rockchip_pin_output_deferred *cfg;
2767 of_platform_depopulate(&pdev->dev);
2769 for (i = 0; i < info->ctrl->nr_banks; i++) {
2770 bank = &info->ctrl->pin_banks[i];
2772 mutex_lock(&bank->deferred_lock);
2773 while (!list_empty(&bank->deferred_output)) {
2774 cfg = list_first_entry(&bank->deferred_output,
2775 struct rockchip_pin_output_deferred, head);
2776 list_del(&cfg->head);
2779 mutex_unlock(&bank->deferred_lock);
2785 static struct rockchip_pin_bank px30_pin_banks[] = {
2786 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2791 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
2796 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
2801 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
2808 static struct rockchip_pin_ctrl px30_pin_ctrl = {
2809 .pin_banks = px30_pin_banks,
2810 .nr_banks = ARRAY_SIZE(px30_pin_banks),
2811 .label = "PX30-GPIO",
2813 .grf_mux_offset = 0x0,
2814 .pmu_mux_offset = 0x0,
2815 .iomux_routes = px30_mux_route_data,
2816 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
2817 .pull_calc_reg = px30_calc_pull_reg_and_bit,
2818 .drv_calc_reg = px30_calc_drv_reg_and_bit,
2819 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
2822 static struct rockchip_pin_bank rv1108_pin_banks[] = {
2823 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
2827 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
2828 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
2829 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
2832 static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
2833 .pin_banks = rv1108_pin_banks,
2834 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
2835 .label = "RV1108-GPIO",
2837 .grf_mux_offset = 0x10,
2838 .pmu_mux_offset = 0x0,
2839 .iomux_recalced = rv1108_mux_recalced_data,
2840 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
2841 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
2842 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
2843 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
2846 static struct rockchip_pin_bank rk2928_pin_banks[] = {
2847 PIN_BANK(0, 32, "gpio0"),
2848 PIN_BANK(1, 32, "gpio1"),
2849 PIN_BANK(2, 32, "gpio2"),
2850 PIN_BANK(3, 32, "gpio3"),
2853 static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
2854 .pin_banks = rk2928_pin_banks,
2855 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
2856 .label = "RK2928-GPIO",
2858 .grf_mux_offset = 0xa8,
2859 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2862 static struct rockchip_pin_bank rk3036_pin_banks[] = {
2863 PIN_BANK(0, 32, "gpio0"),
2864 PIN_BANK(1, 32, "gpio1"),
2865 PIN_BANK(2, 32, "gpio2"),
2868 static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
2869 .pin_banks = rk3036_pin_banks,
2870 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
2871 .label = "RK3036-GPIO",
2873 .grf_mux_offset = 0xa8,
2874 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2877 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
2878 PIN_BANK(0, 32, "gpio0"),
2879 PIN_BANK(1, 32, "gpio1"),
2880 PIN_BANK(2, 32, "gpio2"),
2881 PIN_BANK(3, 32, "gpio3"),
2882 PIN_BANK(4, 32, "gpio4"),
2883 PIN_BANK(6, 16, "gpio6"),
2886 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
2887 .pin_banks = rk3066a_pin_banks,
2888 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
2889 .label = "RK3066a-GPIO",
2891 .grf_mux_offset = 0xa8,
2892 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
2895 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
2896 PIN_BANK(0, 32, "gpio0"),
2897 PIN_BANK(1, 32, "gpio1"),
2898 PIN_BANK(2, 32, "gpio2"),
2899 PIN_BANK(3, 32, "gpio3"),
2902 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
2903 .pin_banks = rk3066b_pin_banks,
2904 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
2905 .label = "RK3066b-GPIO",
2907 .grf_mux_offset = 0x60,
2910 static struct rockchip_pin_bank rk3128_pin_banks[] = {
2911 PIN_BANK(0, 32, "gpio0"),
2912 PIN_BANK(1, 32, "gpio1"),
2913 PIN_BANK(2, 32, "gpio2"),
2914 PIN_BANK(3, 32, "gpio3"),
2917 static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
2918 .pin_banks = rk3128_pin_banks,
2919 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
2920 .label = "RK3128-GPIO",
2922 .grf_mux_offset = 0xa8,
2923 .iomux_recalced = rk3128_mux_recalced_data,
2924 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
2925 .iomux_routes = rk3128_mux_route_data,
2926 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
2927 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
2930 static struct rockchip_pin_bank rk3188_pin_banks[] = {
2931 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
2932 PIN_BANK(1, 32, "gpio1"),
2933 PIN_BANK(2, 32, "gpio2"),
2934 PIN_BANK(3, 32, "gpio3"),
2937 static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
2938 .pin_banks = rk3188_pin_banks,
2939 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
2940 .label = "RK3188-GPIO",
2942 .grf_mux_offset = 0x60,
2943 .iomux_routes = rk3188_mux_route_data,
2944 .niomux_routes = ARRAY_SIZE(rk3188_mux_route_data),
2945 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
2948 static struct rockchip_pin_bank rk3228_pin_banks[] = {
2949 PIN_BANK(0, 32, "gpio0"),
2950 PIN_BANK(1, 32, "gpio1"),
2951 PIN_BANK(2, 32, "gpio2"),
2952 PIN_BANK(3, 32, "gpio3"),
2955 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
2956 .pin_banks = rk3228_pin_banks,
2957 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
2958 .label = "RK3228-GPIO",
2960 .grf_mux_offset = 0x0,
2961 .iomux_routes = rk3228_mux_route_data,
2962 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
2963 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
2964 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
2967 static struct rockchip_pin_bank rk3288_pin_banks[] = {
2968 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
2973 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
2978 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
2979 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
2980 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
2985 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
2990 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
2991 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
2996 PIN_BANK(8, 16, "gpio8"),
2999 static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3000 .pin_banks = rk3288_pin_banks,
3001 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3002 .label = "RK3288-GPIO",
3004 .grf_mux_offset = 0x0,
3005 .pmu_mux_offset = 0x84,
3006 .iomux_routes = rk3288_mux_route_data,
3007 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
3008 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
3009 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
3012 static struct rockchip_pin_bank rk3308_pin_banks[] = {
3013 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT,
3017 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT,
3021 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT,
3025 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT,
3029 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT,
3035 static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
3036 .pin_banks = rk3308_pin_banks,
3037 .nr_banks = ARRAY_SIZE(rk3308_pin_banks),
3038 .label = "RK3308-GPIO",
3040 .grf_mux_offset = 0x0,
3041 .iomux_recalced = rk3308_mux_recalced_data,
3042 .niomux_recalced = ARRAY_SIZE(rk3308_mux_recalced_data),
3043 .iomux_routes = rk3308_mux_route_data,
3044 .niomux_routes = ARRAY_SIZE(rk3308_mux_route_data),
3045 .pull_calc_reg = rk3308_calc_pull_reg_and_bit,
3046 .drv_calc_reg = rk3308_calc_drv_reg_and_bit,
3047 .schmitt_calc_reg = rk3308_calc_schmitt_reg_and_bit,
3050 static struct rockchip_pin_bank rk3328_pin_banks[] = {
3051 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3052 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3053 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3057 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3064 static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3065 .pin_banks = rk3328_pin_banks,
3066 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3067 .label = "RK3328-GPIO",
3069 .grf_mux_offset = 0x0,
3070 .iomux_recalced = rk3328_mux_recalced_data,
3071 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
3072 .iomux_routes = rk3328_mux_route_data,
3073 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
3074 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3075 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3076 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
3079 static struct rockchip_pin_bank rk3368_pin_banks[] = {
3080 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3085 PIN_BANK(1, 32, "gpio1"),
3086 PIN_BANK(2, 32, "gpio2"),
3087 PIN_BANK(3, 32, "gpio3"),
3090 static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3091 .pin_banks = rk3368_pin_banks,
3092 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3093 .label = "RK3368-GPIO",
3095 .grf_mux_offset = 0x0,
3096 .pmu_mux_offset = 0x0,
3097 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3098 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3101 static struct rockchip_pin_bank rk3399_pin_banks[] = {
3102 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3107 DRV_TYPE_IO_1V8_ONLY,
3108 DRV_TYPE_IO_1V8_ONLY,
3109 DRV_TYPE_IO_DEFAULT,
3110 DRV_TYPE_IO_DEFAULT,
3115 PULL_TYPE_IO_1V8_ONLY,
3116 PULL_TYPE_IO_1V8_ONLY,
3117 PULL_TYPE_IO_DEFAULT,
3118 PULL_TYPE_IO_DEFAULT
3120 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3124 DRV_TYPE_IO_1V8_OR_3V0,
3125 DRV_TYPE_IO_1V8_OR_3V0,
3126 DRV_TYPE_IO_1V8_OR_3V0,
3127 DRV_TYPE_IO_1V8_OR_3V0,
3133 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3134 DRV_TYPE_IO_1V8_OR_3V0,
3135 DRV_TYPE_IO_1V8_ONLY,
3136 DRV_TYPE_IO_1V8_ONLY,
3137 PULL_TYPE_IO_DEFAULT,
3138 PULL_TYPE_IO_DEFAULT,
3139 PULL_TYPE_IO_1V8_ONLY,
3140 PULL_TYPE_IO_1V8_ONLY
3142 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3143 DRV_TYPE_IO_3V3_ONLY,
3144 DRV_TYPE_IO_3V3_ONLY,
3145 DRV_TYPE_IO_1V8_OR_3V0
3147 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3148 DRV_TYPE_IO_1V8_3V0_AUTO,
3149 DRV_TYPE_IO_1V8_OR_3V0,
3150 DRV_TYPE_IO_1V8_OR_3V0
3154 static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3155 .pin_banks = rk3399_pin_banks,
3156 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3157 .label = "RK3399-GPIO",
3159 .grf_mux_offset = 0xe000,
3160 .pmu_mux_offset = 0x0,
3161 .grf_drv_offset = 0xe100,
3162 .pmu_drv_offset = 0x80,
3163 .iomux_routes = rk3399_mux_route_data,
3164 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
3165 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3166 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3169 static struct rockchip_pin_bank rk3568_pin_banks[] = {
3170 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3171 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3172 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3173 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT),
3174 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3178 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3182 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3186 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3192 static struct rockchip_pin_ctrl rk3568_pin_ctrl = {
3193 .pin_banks = rk3568_pin_banks,
3194 .nr_banks = ARRAY_SIZE(rk3568_pin_banks),
3195 .label = "RK3568-GPIO",
3197 .grf_mux_offset = 0x0,
3198 .pmu_mux_offset = 0x0,
3199 .grf_drv_offset = 0x0200,
3200 .pmu_drv_offset = 0x0070,
3201 .iomux_routes = rk3568_mux_route_data,
3202 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data),
3203 .pull_calc_reg = rk3568_calc_pull_reg_and_bit,
3204 .drv_calc_reg = rk3568_calc_drv_reg_and_bit,
3205 .schmitt_calc_reg = rk3568_calc_schmitt_reg_and_bit,
3208 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
3209 { .compatible = "rockchip,px30-pinctrl",
3210 .data = &px30_pin_ctrl },
3211 { .compatible = "rockchip,rv1108-pinctrl",
3212 .data = &rv1108_pin_ctrl },
3213 { .compatible = "rockchip,rk2928-pinctrl",
3214 .data = &rk2928_pin_ctrl },
3215 { .compatible = "rockchip,rk3036-pinctrl",
3216 .data = &rk3036_pin_ctrl },
3217 { .compatible = "rockchip,rk3066a-pinctrl",
3218 .data = &rk3066a_pin_ctrl },
3219 { .compatible = "rockchip,rk3066b-pinctrl",
3220 .data = &rk3066b_pin_ctrl },
3221 { .compatible = "rockchip,rk3128-pinctrl",
3222 .data = (void *)&rk3128_pin_ctrl },
3223 { .compatible = "rockchip,rk3188-pinctrl",
3224 .data = &rk3188_pin_ctrl },
3225 { .compatible = "rockchip,rk3228-pinctrl",
3226 .data = &rk3228_pin_ctrl },
3227 { .compatible = "rockchip,rk3288-pinctrl",
3228 .data = &rk3288_pin_ctrl },
3229 { .compatible = "rockchip,rk3308-pinctrl",
3230 .data = &rk3308_pin_ctrl },
3231 { .compatible = "rockchip,rk3328-pinctrl",
3232 .data = &rk3328_pin_ctrl },
3233 { .compatible = "rockchip,rk3368-pinctrl",
3234 .data = &rk3368_pin_ctrl },
3235 { .compatible = "rockchip,rk3399-pinctrl",
3236 .data = &rk3399_pin_ctrl },
3237 { .compatible = "rockchip,rk3568-pinctrl",
3238 .data = &rk3568_pin_ctrl },
3242 static struct platform_driver rockchip_pinctrl_driver = {
3243 .probe = rockchip_pinctrl_probe,
3244 .remove = rockchip_pinctrl_remove,
3246 .name = "rockchip-pinctrl",
3247 .pm = &rockchip_pinctrl_dev_pm_ops,
3248 .of_match_table = rockchip_pinctrl_dt_match,
3252 static int __init rockchip_pinctrl_drv_register(void)
3254 return platform_driver_register(&rockchip_pinctrl_driver);
3256 postcore_initcall(rockchip_pinctrl_drv_register);
3258 static void __exit rockchip_pinctrl_drv_unregister(void)
3260 platform_driver_unregister(&rockchip_pinctrl_driver);
3262 module_exit(rockchip_pinctrl_drv_unregister);
3264 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver");
3265 MODULE_LICENSE("GPL");
3266 MODULE_ALIAS("platform:pinctrl-rockchip");
3267 MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match);