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 <linux/string_helpers.h>
38 #include <dt-bindings/pinctrl/rockchip.h>
42 #include "pinctrl-rockchip.h"
45 * Generate a bitmask for setting a value (v) with a write mask bit in hiword
46 * register 31:16 area.
48 #define WRITE_MASK_VAL(h, l, v) \
49 (GENMASK(((h) + 16), ((l) + 16)) | (((v) << (l)) & GENMASK((h), (l))))
52 * Encode variants of iomux registers into a type variable
54 #define IOMUX_GPIO_ONLY BIT(0)
55 #define IOMUX_WIDTH_4BIT BIT(1)
56 #define IOMUX_SOURCE_PMU BIT(2)
57 #define IOMUX_UNROUTED BIT(3)
58 #define IOMUX_WIDTH_3BIT BIT(4)
59 #define IOMUX_WIDTH_2BIT BIT(5)
61 #define PIN_BANK(id, pins, label) \
74 #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
80 { .type = iom0, .offset = -1 }, \
81 { .type = iom1, .offset = -1 }, \
82 { .type = iom2, .offset = -1 }, \
83 { .type = iom3, .offset = -1 }, \
87 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
99 { .drv_type = type0, .offset = -1 }, \
100 { .drv_type = type1, .offset = -1 }, \
101 { .drv_type = type2, .offset = -1 }, \
102 { .drv_type = type3, .offset = -1 }, \
106 #define PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(id, pins, label, iom0, iom1, \
107 iom2, iom3, pull0, pull1, \
114 { .type = iom0, .offset = -1 }, \
115 { .type = iom1, .offset = -1 }, \
116 { .type = iom2, .offset = -1 }, \
117 { .type = iom3, .offset = -1 }, \
119 .pull_type[0] = pull0, \
120 .pull_type[1] = pull1, \
121 .pull_type[2] = pull2, \
122 .pull_type[3] = pull3, \
125 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
126 drv2, drv3, pull0, pull1, \
139 { .drv_type = drv0, .offset = -1 }, \
140 { .drv_type = drv1, .offset = -1 }, \
141 { .drv_type = drv2, .offset = -1 }, \
142 { .drv_type = drv3, .offset = -1 }, \
144 .pull_type[0] = pull0, \
145 .pull_type[1] = pull1, \
146 .pull_type[2] = pull2, \
147 .pull_type[3] = pull3, \
150 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
151 iom2, iom3, drv0, drv1, drv2, \
152 drv3, offset0, offset1, \
159 { .type = iom0, .offset = -1 }, \
160 { .type = iom1, .offset = -1 }, \
161 { .type = iom2, .offset = -1 }, \
162 { .type = iom3, .offset = -1 }, \
165 { .drv_type = drv0, .offset = offset0 }, \
166 { .drv_type = drv1, .offset = offset1 }, \
167 { .drv_type = drv2, .offset = offset2 }, \
168 { .drv_type = drv3, .offset = offset3 }, \
172 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
173 label, iom0, iom1, iom2, \
174 iom3, drv0, drv1, drv2, \
175 drv3, offset0, offset1, \
176 offset2, offset3, pull0, \
177 pull1, pull2, pull3) \
183 { .type = iom0, .offset = -1 }, \
184 { .type = iom1, .offset = -1 }, \
185 { .type = iom2, .offset = -1 }, \
186 { .type = iom3, .offset = -1 }, \
189 { .drv_type = drv0, .offset = offset0 }, \
190 { .drv_type = drv1, .offset = offset1 }, \
191 { .drv_type = drv2, .offset = offset2 }, \
192 { .drv_type = drv3, .offset = offset3 }, \
194 .pull_type[0] = pull0, \
195 .pull_type[1] = pull1, \
196 .pull_type[2] = pull2, \
197 .pull_type[3] = pull3, \
200 #define PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, FLAG) \
205 .route_offset = REG, \
207 .route_location = FLAG, \
210 #define RK_MUXROUTE_SAME(ID, PIN, FUNC, REG, VAL) \
211 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_SAME)
213 #define RK_MUXROUTE_GRF(ID, PIN, FUNC, REG, VAL) \
214 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_GRF)
216 #define RK_MUXROUTE_PMU(ID, PIN, FUNC, REG, VAL) \
217 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_PMU)
219 #define RK3588_PIN_BANK_FLAGS(ID, PIN, LABEL, M, P) \
220 PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(ID, PIN, LABEL, M, M, M, M, P, P, P, P)
222 static struct regmap_config rockchip_regmap_config = {
228 static inline const struct rockchip_pin_group *pinctrl_name_to_group(
229 const struct rockchip_pinctrl *info,
234 for (i = 0; i < info->ngroups; i++) {
235 if (!strcmp(info->groups[i].name, name))
236 return &info->groups[i];
243 * given a pin number that is local to a pin controller, find out the pin bank
244 * and the register base of the pin bank.
246 static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
249 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
251 while (pin >= (b->pin_base + b->nr_pins))
257 static struct rockchip_pin_bank *bank_num_to_bank(
258 struct rockchip_pinctrl *info,
261 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
264 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
265 if (b->bank_num == num)
269 return ERR_PTR(-EINVAL);
273 * Pinctrl_ops handling
276 static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
278 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
280 return info->ngroups;
283 static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
286 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
288 return info->groups[selector].name;
291 static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
292 unsigned selector, const unsigned **pins,
295 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
297 if (selector >= info->ngroups)
300 *pins = info->groups[selector].pins;
301 *npins = info->groups[selector].npins;
306 static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
307 struct device_node *np,
308 struct pinctrl_map **map, unsigned *num_maps)
310 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
311 const struct rockchip_pin_group *grp;
312 struct device *dev = info->dev;
313 struct pinctrl_map *new_map;
314 struct device_node *parent;
319 * first find the group of this node and check if we need to create
320 * config maps for pins
322 grp = pinctrl_name_to_group(info, np->name);
324 dev_err(dev, "unable to find group for node %pOFn\n", np);
328 map_num += grp->npins;
330 new_map = kcalloc(map_num, sizeof(*new_map), GFP_KERNEL);
338 parent = of_get_parent(np);
343 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
344 new_map[0].data.mux.function = parent->name;
345 new_map[0].data.mux.group = np->name;
348 /* create config map */
350 for (i = 0; i < grp->npins; i++) {
351 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
352 new_map[i].data.configs.group_or_pin =
353 pin_get_name(pctldev, grp->pins[i]);
354 new_map[i].data.configs.configs = grp->data[i].configs;
355 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
358 dev_dbg(dev, "maps: function %s group %s num %d\n",
359 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
364 static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
365 struct pinctrl_map *map, unsigned num_maps)
370 static const struct pinctrl_ops rockchip_pctrl_ops = {
371 .get_groups_count = rockchip_get_groups_count,
372 .get_group_name = rockchip_get_group_name,
373 .get_group_pins = rockchip_get_group_pins,
374 .dt_node_to_map = rockchip_dt_node_to_map,
375 .dt_free_map = rockchip_dt_free_map,
382 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data[] = {
446 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data[] = {
480 static struct rockchip_mux_recalced_data rk3308_mux_recalced_data[] = {
589 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
611 static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
612 int *reg, u8 *bit, int *mask)
614 struct rockchip_pinctrl *info = bank->drvdata;
615 struct rockchip_pin_ctrl *ctrl = info->ctrl;
616 struct rockchip_mux_recalced_data *data;
619 for (i = 0; i < ctrl->niomux_recalced; i++) {
620 data = &ctrl->iomux_recalced[i];
621 if (data->num == bank->bank_num &&
626 if (i >= ctrl->niomux_recalced)
634 static struct rockchip_mux_route_data px30_mux_route_data[] = {
635 RK_MUXROUTE_SAME(2, RK_PA0, 1, 0x184, BIT(16 + 7)), /* cif-d2m0 */
636 RK_MUXROUTE_SAME(3, RK_PA3, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d2m1 */
637 RK_MUXROUTE_SAME(3, RK_PC6, 2, 0x184, BIT(16 + 8)), /* pdm-m0 */
638 RK_MUXROUTE_SAME(2, RK_PC6, 1, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-m1 */
639 RK_MUXROUTE_SAME(1, RK_PD3, 2, 0x184, BIT(16 + 10)), /* uart2-rxm0 */
640 RK_MUXROUTE_SAME(2, RK_PB6, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-rxm1 */
641 RK_MUXROUTE_SAME(0, RK_PC1, 2, 0x184, BIT(16 + 9)), /* uart3-rxm0 */
642 RK_MUXROUTE_SAME(1, RK_PB7, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rxm1 */
645 static struct rockchip_mux_route_data rk3128_mux_route_data[] = {
646 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x144, BIT(16 + 3) | BIT(16 + 4)), /* spi-0 */
647 RK_MUXROUTE_SAME(1, RK_PD3, 3, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(3)), /* spi-1 */
648 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(4)), /* spi-2 */
649 RK_MUXROUTE_SAME(1, RK_PA5, 1, 0x144, BIT(16 + 5)), /* i2s-0 */
650 RK_MUXROUTE_SAME(0, RK_PB6, 1, 0x144, BIT(16 + 5) | BIT(5)), /* i2s-1 */
651 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x144, BIT(16 + 6)), /* emmc-0 */
652 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x144, BIT(16 + 6) | BIT(6)), /* emmc-1 */
655 static struct rockchip_mux_route_data rk3188_mux_route_data[] = {
656 RK_MUXROUTE_SAME(0, RK_PD0, 1, 0xa0, BIT(16 + 11)), /* non-iomuxed emmc/flash pins on flash-dqs */
657 RK_MUXROUTE_SAME(0, RK_PD0, 2, 0xa0, BIT(16 + 11) | BIT(11)), /* non-iomuxed emmc/flash pins on emmc-clk */
660 static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
661 RK_MUXROUTE_SAME(0, RK_PD2, 1, 0x50, BIT(16)), /* pwm0-0 */
662 RK_MUXROUTE_SAME(3, RK_PC5, 1, 0x50, BIT(16) | BIT(0)), /* pwm0-1 */
663 RK_MUXROUTE_SAME(0, RK_PD3, 1, 0x50, BIT(16 + 1)), /* pwm1-0 */
664 RK_MUXROUTE_SAME(0, RK_PD6, 2, 0x50, BIT(16 + 1) | BIT(1)), /* pwm1-1 */
665 RK_MUXROUTE_SAME(0, RK_PD4, 1, 0x50, BIT(16 + 2)), /* pwm2-0 */
666 RK_MUXROUTE_SAME(1, RK_PB4, 2, 0x50, BIT(16 + 2) | BIT(2)), /* pwm2-1 */
667 RK_MUXROUTE_SAME(3, RK_PD2, 1, 0x50, BIT(16 + 3)), /* pwm3-0 */
668 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 3) | BIT(3)), /* pwm3-1 */
669 RK_MUXROUTE_SAME(1, RK_PA1, 1, 0x50, BIT(16 + 4)), /* sdio-0_d0 */
670 RK_MUXROUTE_SAME(3, RK_PA2, 1, 0x50, BIT(16 + 4) | BIT(4)), /* sdio-1_d0 */
671 RK_MUXROUTE_SAME(0, RK_PB5, 2, 0x50, BIT(16 + 5)), /* spi-0_rx */
672 RK_MUXROUTE_SAME(2, RK_PA0, 2, 0x50, BIT(16 + 5) | BIT(5)), /* spi-1_rx */
673 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x50, BIT(16 + 7)), /* emmc-0_cmd */
674 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x50, BIT(16 + 7) | BIT(7)), /* emmc-1_cmd */
675 RK_MUXROUTE_SAME(1, RK_PC3, 2, 0x50, BIT(16 + 8)), /* uart2-0_rx */
676 RK_MUXROUTE_SAME(1, RK_PB2, 2, 0x50, BIT(16 + 8) | BIT(8)), /* uart2-1_rx */
677 RK_MUXROUTE_SAME(1, RK_PB2, 1, 0x50, BIT(16 + 11)), /* uart1-0_rx */
678 RK_MUXROUTE_SAME(3, RK_PB5, 1, 0x50, BIT(16 + 11) | BIT(11)), /* uart1-1_rx */
681 static struct rockchip_mux_route_data rk3288_mux_route_data[] = {
682 RK_MUXROUTE_SAME(7, RK_PC0, 2, 0x264, BIT(16 + 12) | BIT(12)), /* edphdmi_cecinoutt1 */
683 RK_MUXROUTE_SAME(7, RK_PC7, 4, 0x264, BIT(16 + 12)), /* edphdmi_cecinout */
686 static struct rockchip_mux_route_data rk3308_mux_route_data[] = {
687 RK_MUXROUTE_SAME(0, RK_PC3, 1, 0x314, BIT(16 + 0) | BIT(0)), /* rtc_clk */
688 RK_MUXROUTE_SAME(1, RK_PC6, 2, 0x314, BIT(16 + 2) | BIT(16 + 3)), /* uart2_rxm0 */
689 RK_MUXROUTE_SAME(4, RK_PD2, 2, 0x314, BIT(16 + 2) | BIT(16 + 3) | BIT(2)), /* uart2_rxm1 */
690 RK_MUXROUTE_SAME(0, RK_PB7, 2, 0x608, BIT(16 + 8) | BIT(16 + 9)), /* i2c3_sdam0 */
691 RK_MUXROUTE_SAME(3, RK_PB4, 2, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(8)), /* i2c3_sdam1 */
692 RK_MUXROUTE_SAME(2, RK_PA0, 3, 0x608, BIT(16 + 8) | BIT(16 + 9) | BIT(9)), /* i2c3_sdam2 */
693 RK_MUXROUTE_SAME(1, RK_PA3, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclktxm0 */
694 RK_MUXROUTE_SAME(1, RK_PA4, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclkrxm0 */
695 RK_MUXROUTE_SAME(1, RK_PB5, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclktxm1 */
696 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclkrxm1 */
697 RK_MUXROUTE_SAME(1, RK_PA4, 3, 0x308, BIT(16 + 12) | BIT(16 + 13)), /* pdm-clkm0 */
698 RK_MUXROUTE_SAME(1, RK_PB6, 4, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* pdm-clkm1 */
699 RK_MUXROUTE_SAME(2, RK_PA6, 2, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* pdm-clkm2 */
700 RK_MUXROUTE_SAME(2, RK_PA4, 3, 0x600, BIT(16 + 2) | BIT(2)), /* pdm-clkm-m2 */
701 RK_MUXROUTE_SAME(3, RK_PB2, 3, 0x314, BIT(16 + 9)), /* spi1_miso */
702 RK_MUXROUTE_SAME(2, RK_PA4, 2, 0x314, BIT(16 + 9) | BIT(9)), /* spi1_miso_m1 */
703 RK_MUXROUTE_SAME(0, RK_PB3, 3, 0x314, BIT(16 + 10) | BIT(16 + 11)), /* owire_m0 */
704 RK_MUXROUTE_SAME(1, RK_PC6, 7, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* owire_m1 */
705 RK_MUXROUTE_SAME(2, RK_PA2, 5, 0x314, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* owire_m2 */
706 RK_MUXROUTE_SAME(0, RK_PB3, 2, 0x314, BIT(16 + 12) | BIT(16 + 13)), /* can_rxd_m0 */
707 RK_MUXROUTE_SAME(1, RK_PC6, 5, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* can_rxd_m1 */
708 RK_MUXROUTE_SAME(2, RK_PA2, 4, 0x314, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* can_rxd_m2 */
709 RK_MUXROUTE_SAME(1, RK_PC4, 3, 0x314, BIT(16 + 14)), /* mac_rxd0_m0 */
710 RK_MUXROUTE_SAME(4, RK_PA2, 2, 0x314, BIT(16 + 14) | BIT(14)), /* mac_rxd0_m1 */
711 RK_MUXROUTE_SAME(3, RK_PB4, 4, 0x314, BIT(16 + 15)), /* uart3_rx */
712 RK_MUXROUTE_SAME(0, RK_PC1, 3, 0x314, BIT(16 + 15) | BIT(15)), /* uart3_rx_m1 */
715 static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
716 RK_MUXROUTE_SAME(1, RK_PA1, 2, 0x50, BIT(16) | BIT(16 + 1)), /* uart2dbg_rxm0 */
717 RK_MUXROUTE_SAME(2, RK_PA1, 1, 0x50, BIT(16) | BIT(16 + 1) | BIT(0)), /* uart2dbg_rxm1 */
718 RK_MUXROUTE_SAME(1, RK_PB3, 2, 0x50, BIT(16 + 2) | BIT(2)), /* gmac-m1_rxd0 */
719 RK_MUXROUTE_SAME(1, RK_PB6, 2, 0x50, BIT(16 + 10) | BIT(10)), /* gmac-m1-optimized_rxd3 */
720 RK_MUXROUTE_SAME(2, RK_PC3, 2, 0x50, BIT(16 + 3)), /* pdm_sdi0m0 */
721 RK_MUXROUTE_SAME(1, RK_PC7, 3, 0x50, BIT(16 + 3) | BIT(3)), /* pdm_sdi0m1 */
722 RK_MUXROUTE_SAME(3, RK_PA2, 4, 0x50, BIT(16 + 4) | BIT(16 + 5) | BIT(5)), /* spi_rxdm2 */
723 RK_MUXROUTE_SAME(1, RK_PD0, 1, 0x50, BIT(16 + 6)), /* i2s2_sdim0 */
724 RK_MUXROUTE_SAME(3, RK_PA2, 6, 0x50, BIT(16 + 6) | BIT(6)), /* i2s2_sdim1 */
725 RK_MUXROUTE_SAME(2, RK_PC6, 3, 0x50, BIT(16 + 7) | BIT(7)), /* card_iom1 */
726 RK_MUXROUTE_SAME(2, RK_PC0, 3, 0x50, BIT(16 + 8) | BIT(8)), /* tsp_d5m1 */
727 RK_MUXROUTE_SAME(2, RK_PC0, 4, 0x50, BIT(16 + 9) | BIT(9)), /* cif_data5m1 */
730 static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
731 RK_MUXROUTE_SAME(4, RK_PB0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11)), /* uart2dbga_rx */
732 RK_MUXROUTE_SAME(4, RK_PC0, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* uart2dbgb_rx */
733 RK_MUXROUTE_SAME(4, RK_PC3, 1, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* uart2dbgc_rx */
734 RK_MUXROUTE_SAME(2, RK_PD2, 2, 0xe21c, BIT(16 + 14)), /* pcie_clkreqn */
735 RK_MUXROUTE_SAME(4, RK_PD0, 1, 0xe21c, BIT(16 + 14) | BIT(14)), /* pcie_clkreqnb */
738 static struct rockchip_mux_route_data rk3568_mux_route_data[] = {
739 RK_MUXROUTE_PMU(0, RK_PB7, 1, 0x0110, WRITE_MASK_VAL(1, 0, 0)), /* PWM0 IO mux M0 */
740 RK_MUXROUTE_PMU(0, RK_PC7, 2, 0x0110, WRITE_MASK_VAL(1, 0, 1)), /* PWM0 IO mux M1 */
741 RK_MUXROUTE_PMU(0, RK_PC0, 1, 0x0110, WRITE_MASK_VAL(3, 2, 0)), /* PWM1 IO mux M0 */
742 RK_MUXROUTE_PMU(0, RK_PB5, 4, 0x0110, WRITE_MASK_VAL(3, 2, 1)), /* PWM1 IO mux M1 */
743 RK_MUXROUTE_PMU(0, RK_PC1, 1, 0x0110, WRITE_MASK_VAL(5, 4, 0)), /* PWM2 IO mux M0 */
744 RK_MUXROUTE_PMU(0, RK_PB6, 4, 0x0110, WRITE_MASK_VAL(5, 4, 1)), /* PWM2 IO mux M1 */
745 RK_MUXROUTE_PMU(0, RK_PB3, 2, 0x0300, WRITE_MASK_VAL(0, 0, 0)), /* CAN0 IO mux M0 */
746 RK_MUXROUTE_GRF(2, RK_PA1, 4, 0x0300, WRITE_MASK_VAL(0, 0, 1)), /* CAN0 IO mux M1 */
747 RK_MUXROUTE_GRF(1, RK_PA1, 3, 0x0300, WRITE_MASK_VAL(2, 2, 0)), /* CAN1 IO mux M0 */
748 RK_MUXROUTE_GRF(4, RK_PC3, 3, 0x0300, WRITE_MASK_VAL(2, 2, 1)), /* CAN1 IO mux M1 */
749 RK_MUXROUTE_GRF(4, RK_PB5, 3, 0x0300, WRITE_MASK_VAL(4, 4, 0)), /* CAN2 IO mux M0 */
750 RK_MUXROUTE_GRF(2, RK_PB2, 4, 0x0300, WRITE_MASK_VAL(4, 4, 1)), /* CAN2 IO mux M1 */
751 RK_MUXROUTE_GRF(4, RK_PC4, 1, 0x0300, WRITE_MASK_VAL(6, 6, 0)), /* HPDIN IO mux M0 */
752 RK_MUXROUTE_PMU(0, RK_PC2, 2, 0x0300, WRITE_MASK_VAL(6, 6, 1)), /* HPDIN IO mux M1 */
753 RK_MUXROUTE_GRF(3, RK_PB1, 3, 0x0300, WRITE_MASK_VAL(8, 8, 0)), /* GMAC1 IO mux M0 */
754 RK_MUXROUTE_GRF(4, RK_PA7, 3, 0x0300, WRITE_MASK_VAL(8, 8, 1)), /* GMAC1 IO mux M1 */
755 RK_MUXROUTE_GRF(4, RK_PD1, 1, 0x0300, WRITE_MASK_VAL(10, 10, 0)), /* HDMITX IO mux M0 */
756 RK_MUXROUTE_PMU(0, RK_PC7, 1, 0x0300, WRITE_MASK_VAL(10, 10, 1)), /* HDMITX IO mux M1 */
757 RK_MUXROUTE_PMU(0, RK_PB6, 1, 0x0300, WRITE_MASK_VAL(14, 14, 0)), /* I2C2 IO mux M0 */
758 RK_MUXROUTE_GRF(4, RK_PB4, 1, 0x0300, WRITE_MASK_VAL(14, 14, 1)), /* I2C2 IO mux M1 */
759 RK_MUXROUTE_GRF(1, RK_PA0, 1, 0x0304, WRITE_MASK_VAL(0, 0, 0)), /* I2C3 IO mux M0 */
760 RK_MUXROUTE_GRF(3, RK_PB6, 4, 0x0304, WRITE_MASK_VAL(0, 0, 1)), /* I2C3 IO mux M1 */
761 RK_MUXROUTE_GRF(4, RK_PB2, 1, 0x0304, WRITE_MASK_VAL(2, 2, 0)), /* I2C4 IO mux M0 */
762 RK_MUXROUTE_GRF(2, RK_PB1, 2, 0x0304, WRITE_MASK_VAL(2, 2, 1)), /* I2C4 IO mux M1 */
763 RK_MUXROUTE_GRF(3, RK_PB4, 4, 0x0304, WRITE_MASK_VAL(4, 4, 0)), /* I2C5 IO mux M0 */
764 RK_MUXROUTE_GRF(4, RK_PD0, 2, 0x0304, WRITE_MASK_VAL(4, 4, 1)), /* I2C5 IO mux M1 */
765 RK_MUXROUTE_GRF(3, RK_PB1, 5, 0x0304, WRITE_MASK_VAL(14, 14, 0)), /* PWM8 IO mux M0 */
766 RK_MUXROUTE_GRF(1, RK_PD5, 4, 0x0304, WRITE_MASK_VAL(14, 14, 1)), /* PWM8 IO mux M1 */
767 RK_MUXROUTE_GRF(3, RK_PB2, 5, 0x0308, WRITE_MASK_VAL(0, 0, 0)), /* PWM9 IO mux M0 */
768 RK_MUXROUTE_GRF(1, RK_PD6, 4, 0x0308, WRITE_MASK_VAL(0, 0, 1)), /* PWM9 IO mux M1 */
769 RK_MUXROUTE_GRF(3, RK_PB5, 5, 0x0308, WRITE_MASK_VAL(2, 2, 0)), /* PWM10 IO mux M0 */
770 RK_MUXROUTE_GRF(2, RK_PA1, 2, 0x0308, WRITE_MASK_VAL(2, 2, 1)), /* PWM10 IO mux M1 */
771 RK_MUXROUTE_GRF(3, RK_PB6, 5, 0x0308, WRITE_MASK_VAL(4, 4, 0)), /* PWM11 IO mux M0 */
772 RK_MUXROUTE_GRF(4, RK_PC0, 3, 0x0308, WRITE_MASK_VAL(4, 4, 1)), /* PWM11 IO mux M1 */
773 RK_MUXROUTE_GRF(3, RK_PB7, 2, 0x0308, WRITE_MASK_VAL(6, 6, 0)), /* PWM12 IO mux M0 */
774 RK_MUXROUTE_GRF(4, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(6, 6, 1)), /* PWM12 IO mux M1 */
775 RK_MUXROUTE_GRF(3, RK_PC0, 2, 0x0308, WRITE_MASK_VAL(8, 8, 0)), /* PWM13 IO mux M0 */
776 RK_MUXROUTE_GRF(4, RK_PC6, 1, 0x0308, WRITE_MASK_VAL(8, 8, 1)), /* PWM13 IO mux M1 */
777 RK_MUXROUTE_GRF(3, RK_PC4, 1, 0x0308, WRITE_MASK_VAL(10, 10, 0)), /* PWM14 IO mux M0 */
778 RK_MUXROUTE_GRF(4, RK_PC2, 1, 0x0308, WRITE_MASK_VAL(10, 10, 1)), /* PWM14 IO mux M1 */
779 RK_MUXROUTE_GRF(3, RK_PC5, 1, 0x0308, WRITE_MASK_VAL(12, 12, 0)), /* PWM15 IO mux M0 */
780 RK_MUXROUTE_GRF(4, RK_PC3, 1, 0x0308, WRITE_MASK_VAL(12, 12, 1)), /* PWM15 IO mux M1 */
781 RK_MUXROUTE_GRF(3, RK_PD2, 3, 0x0308, WRITE_MASK_VAL(14, 14, 0)), /* SDMMC2 IO mux M0 */
782 RK_MUXROUTE_GRF(3, RK_PA5, 5, 0x0308, WRITE_MASK_VAL(14, 14, 1)), /* SDMMC2 IO mux M1 */
783 RK_MUXROUTE_PMU(0, RK_PB5, 2, 0x030c, WRITE_MASK_VAL(0, 0, 0)), /* SPI0 IO mux M0 */
784 RK_MUXROUTE_GRF(2, RK_PD3, 3, 0x030c, WRITE_MASK_VAL(0, 0, 1)), /* SPI0 IO mux M1 */
785 RK_MUXROUTE_GRF(2, RK_PB5, 3, 0x030c, WRITE_MASK_VAL(2, 2, 0)), /* SPI1 IO mux M0 */
786 RK_MUXROUTE_GRF(3, RK_PC3, 3, 0x030c, WRITE_MASK_VAL(2, 2, 1)), /* SPI1 IO mux M1 */
787 RK_MUXROUTE_GRF(2, RK_PC1, 4, 0x030c, WRITE_MASK_VAL(4, 4, 0)), /* SPI2 IO mux M0 */
788 RK_MUXROUTE_GRF(3, RK_PA0, 3, 0x030c, WRITE_MASK_VAL(4, 4, 1)), /* SPI2 IO mux M1 */
789 RK_MUXROUTE_GRF(4, RK_PB3, 4, 0x030c, WRITE_MASK_VAL(6, 6, 0)), /* SPI3 IO mux M0 */
790 RK_MUXROUTE_GRF(4, RK_PC2, 2, 0x030c, WRITE_MASK_VAL(6, 6, 1)), /* SPI3 IO mux M1 */
791 RK_MUXROUTE_GRF(2, RK_PB4, 2, 0x030c, WRITE_MASK_VAL(8, 8, 0)), /* UART1 IO mux M0 */
792 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(8, 8, 1)), /* UART1 IO mux M1 */
793 RK_MUXROUTE_PMU(0, RK_PD1, 1, 0x030c, WRITE_MASK_VAL(10, 10, 0)), /* UART2 IO mux M0 */
794 RK_MUXROUTE_GRF(1, RK_PD5, 2, 0x030c, WRITE_MASK_VAL(10, 10, 1)), /* UART2 IO mux M1 */
795 RK_MUXROUTE_GRF(1, RK_PA1, 2, 0x030c, WRITE_MASK_VAL(12, 12, 0)), /* UART3 IO mux M0 */
796 RK_MUXROUTE_GRF(3, RK_PB7, 4, 0x030c, WRITE_MASK_VAL(12, 12, 1)), /* UART3 IO mux M1 */
797 RK_MUXROUTE_GRF(1, RK_PA6, 2, 0x030c, WRITE_MASK_VAL(14, 14, 0)), /* UART4 IO mux M0 */
798 RK_MUXROUTE_GRF(3, RK_PB2, 4, 0x030c, WRITE_MASK_VAL(14, 14, 1)), /* UART4 IO mux M1 */
799 RK_MUXROUTE_GRF(2, RK_PA2, 3, 0x0310, WRITE_MASK_VAL(0, 0, 0)), /* UART5 IO mux M0 */
800 RK_MUXROUTE_GRF(3, RK_PC2, 4, 0x0310, WRITE_MASK_VAL(0, 0, 1)), /* UART5 IO mux M1 */
801 RK_MUXROUTE_GRF(2, RK_PA4, 3, 0x0310, WRITE_MASK_VAL(2, 2, 0)), /* UART6 IO mux M0 */
802 RK_MUXROUTE_GRF(1, RK_PD5, 3, 0x0310, WRITE_MASK_VAL(2, 2, 1)), /* UART6 IO mux M1 */
803 RK_MUXROUTE_GRF(2, RK_PA6, 3, 0x0310, WRITE_MASK_VAL(5, 4, 0)), /* UART7 IO mux M0 */
804 RK_MUXROUTE_GRF(3, RK_PC4, 4, 0x0310, WRITE_MASK_VAL(5, 4, 1)), /* UART7 IO mux M1 */
805 RK_MUXROUTE_GRF(4, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(5, 4, 2)), /* UART7 IO mux M2 */
806 RK_MUXROUTE_GRF(2, RK_PC5, 3, 0x0310, WRITE_MASK_VAL(6, 6, 0)), /* UART8 IO mux M0 */
807 RK_MUXROUTE_GRF(2, RK_PD7, 4, 0x0310, WRITE_MASK_VAL(6, 6, 1)), /* UART8 IO mux M1 */
808 RK_MUXROUTE_GRF(2, RK_PB0, 3, 0x0310, WRITE_MASK_VAL(9, 8, 0)), /* UART9 IO mux M0 */
809 RK_MUXROUTE_GRF(4, RK_PC5, 4, 0x0310, WRITE_MASK_VAL(9, 8, 1)), /* UART9 IO mux M1 */
810 RK_MUXROUTE_GRF(4, RK_PA4, 4, 0x0310, WRITE_MASK_VAL(9, 8, 2)), /* UART9 IO mux M2 */
811 RK_MUXROUTE_GRF(1, RK_PA2, 1, 0x0310, WRITE_MASK_VAL(11, 10, 0)), /* I2S1 IO mux M0 */
812 RK_MUXROUTE_GRF(3, RK_PC6, 4, 0x0310, WRITE_MASK_VAL(11, 10, 1)), /* I2S1 IO mux M1 */
813 RK_MUXROUTE_GRF(2, RK_PD0, 5, 0x0310, WRITE_MASK_VAL(11, 10, 2)), /* I2S1 IO mux M2 */
814 RK_MUXROUTE_GRF(2, RK_PC1, 1, 0x0310, WRITE_MASK_VAL(12, 12, 0)), /* I2S2 IO mux M0 */
815 RK_MUXROUTE_GRF(4, RK_PB6, 5, 0x0310, WRITE_MASK_VAL(12, 12, 1)), /* I2S2 IO mux M1 */
816 RK_MUXROUTE_GRF(3, RK_PA2, 4, 0x0310, WRITE_MASK_VAL(14, 14, 0)), /* I2S3 IO mux M0 */
817 RK_MUXROUTE_GRF(4, RK_PC2, 5, 0x0310, WRITE_MASK_VAL(14, 14, 1)), /* I2S3 IO mux M1 */
818 RK_MUXROUTE_GRF(1, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
819 RK_MUXROUTE_GRF(1, RK_PA6, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
820 RK_MUXROUTE_GRF(3, RK_PD6, 5, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
821 RK_MUXROUTE_GRF(4, RK_PA0, 4, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
822 RK_MUXROUTE_GRF(3, RK_PC4, 5, 0x0314, WRITE_MASK_VAL(1, 0, 2)), /* PDM IO mux M2 */
823 RK_MUXROUTE_PMU(0, RK_PA5, 3, 0x0314, WRITE_MASK_VAL(3, 2, 0)), /* PCIE20 IO mux M0 */
824 RK_MUXROUTE_GRF(2, RK_PD0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 1)), /* PCIE20 IO mux M1 */
825 RK_MUXROUTE_GRF(1, RK_PB0, 4, 0x0314, WRITE_MASK_VAL(3, 2, 2)), /* PCIE20 IO mux M2 */
826 RK_MUXROUTE_PMU(0, RK_PA4, 3, 0x0314, WRITE_MASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux M0 */
827 RK_MUXROUTE_GRF(2, RK_PD2, 4, 0x0314, WRITE_MASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux M1 */
828 RK_MUXROUTE_GRF(1, RK_PA5, 4, 0x0314, WRITE_MASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux M2 */
829 RK_MUXROUTE_PMU(0, RK_PA6, 2, 0x0314, WRITE_MASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux M0 */
830 RK_MUXROUTE_GRF(2, RK_PD4, 4, 0x0314, WRITE_MASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux M1 */
831 RK_MUXROUTE_GRF(4, RK_PC2, 4, 0x0314, WRITE_MASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux M2 */
834 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
835 int mux, u32 *loc, u32 *reg, u32 *value)
837 struct rockchip_pinctrl *info = bank->drvdata;
838 struct rockchip_pin_ctrl *ctrl = info->ctrl;
839 struct rockchip_mux_route_data *data;
842 for (i = 0; i < ctrl->niomux_routes; i++) {
843 data = &ctrl->iomux_routes[i];
844 if ((data->bank_num == bank->bank_num) &&
845 (data->pin == pin) && (data->func == mux))
849 if (i >= ctrl->niomux_routes)
852 *loc = data->route_location;
853 *reg = data->route_offset;
854 *value = data->route_val;
859 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
861 struct rockchip_pinctrl *info = bank->drvdata;
862 struct rockchip_pin_ctrl *ctrl = info->ctrl;
863 int iomux_num = (pin / 8);
864 struct regmap *regmap;
866 int reg, ret, mask, mux_type;
872 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
873 dev_err(info->dev, "pin %d is unrouted\n", pin);
877 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
880 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
881 ? info->regmap_pmu : info->regmap_base;
883 /* get basic quadrupel of mux registers and the correct reg inside */
884 mux_type = bank->iomux[iomux_num].type;
885 reg = bank->iomux[iomux_num].offset;
886 if (mux_type & IOMUX_WIDTH_4BIT) {
891 } else if (mux_type & IOMUX_WIDTH_3BIT) {
894 bit = (pin % 8 % 5) * 3;
901 if (bank->recalced_mask & BIT(pin))
902 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
904 if (ctrl->type == RK3588) {
905 if (bank->bank_num == 0) {
906 if ((pin >= RK_PB4) && (pin <= RK_PD7)) {
909 reg0 = reg + 0x4000 - 0xC; /* PMU2_IOC_BASE */
910 ret = regmap_read(regmap, reg0, &val);
915 return ((val >> bit) & mask);
917 reg = reg + 0x8000; /* BUS_IOC_BASE */
918 regmap = info->regmap_base;
920 } else if (bank->bank_num > 0) {
921 reg += 0x8000; /* BUS_IOC_BASE */
925 ret = regmap_read(regmap, reg, &val);
929 return ((val >> bit) & mask);
932 static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
935 struct rockchip_pinctrl *info = bank->drvdata;
936 struct device *dev = info->dev;
937 int iomux_num = (pin / 8);
942 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
943 dev_err(dev, "pin %d is unrouted\n", pin);
947 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
948 if (mux != RK_FUNC_GPIO) {
949 dev_err(dev, "pin %d only supports a gpio mux\n", pin);
958 * Set a new mux function for a pin.
960 * The register is divided into the upper and lower 16 bit. When changing
961 * a value, the previous register value is not read and changed. Instead
962 * it seems the changed bits are marked in the upper 16 bit, while the
963 * changed value gets set in the same offset in the lower 16 bit.
964 * All pin settings seem to be 2 bit wide in both the upper and lower
966 * @bank: pin bank to change
967 * @pin: pin to change
968 * @mux: new mux function to set
970 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
972 struct rockchip_pinctrl *info = bank->drvdata;
973 struct rockchip_pin_ctrl *ctrl = info->ctrl;
974 struct device *dev = info->dev;
975 int iomux_num = (pin / 8);
976 struct regmap *regmap;
977 int reg, ret, mask, mux_type;
979 u32 data, rmask, route_location, route_reg, route_val;
981 ret = rockchip_verify_mux(bank, pin, mux);
985 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
988 dev_dbg(dev, "setting mux of GPIO%d-%d to %d\n", bank->bank_num, pin, mux);
990 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
991 ? info->regmap_pmu : info->regmap_base;
993 /* get basic quadrupel of mux registers and the correct reg inside */
994 mux_type = bank->iomux[iomux_num].type;
995 reg = bank->iomux[iomux_num].offset;
996 if (mux_type & IOMUX_WIDTH_4BIT) {
1001 } else if (mux_type & IOMUX_WIDTH_3BIT) {
1004 bit = (pin % 8 % 5) * 3;
1007 bit = (pin % 8) * 2;
1011 if (bank->recalced_mask & BIT(pin))
1012 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
1014 if (ctrl->type == RK3588) {
1015 if (bank->bank_num == 0) {
1016 if ((pin >= RK_PB4) && (pin <= RK_PD7)) {
1018 reg += 0x4000 - 0xC; /* PMU2_IOC_BASE */
1019 data = (mask << (bit + 16));
1020 rmask = data | (data >> 16);
1021 data |= (mux & mask) << bit;
1022 ret = regmap_update_bits(regmap, reg, rmask, data);
1026 reg0 = reg + 0x4000 - 0xC; /* PMU2_IOC_BASE */
1027 data = (mask << (bit + 16));
1028 rmask = data | (data >> 16);
1030 ret = regmap_update_bits(regmap, reg0, rmask, data);
1032 reg0 = reg + 0x8000; /* BUS_IOC_BASE */
1033 data = (mask << (bit + 16));
1034 rmask = data | (data >> 16);
1036 regmap = info->regmap_base;
1037 ret |= regmap_update_bits(regmap, reg0, rmask, data);
1040 data = (mask << (bit + 16));
1041 rmask = data | (data >> 16);
1042 data |= (mux & mask) << bit;
1043 ret = regmap_update_bits(regmap, reg, rmask, data);
1046 } else if (bank->bank_num > 0) {
1047 reg += 0x8000; /* BUS_IOC_BASE */
1054 if (bank->route_mask & BIT(pin)) {
1055 if (rockchip_get_mux_route(bank, pin, mux, &route_location,
1056 &route_reg, &route_val)) {
1057 struct regmap *route_regmap = regmap;
1059 /* handle special locations */
1060 switch (route_location) {
1061 case ROCKCHIP_ROUTE_PMU:
1062 route_regmap = info->regmap_pmu;
1064 case ROCKCHIP_ROUTE_GRF:
1065 route_regmap = info->regmap_base;
1069 ret = regmap_write(route_regmap, route_reg, route_val);
1075 data = (mask << (bit + 16));
1076 rmask = data | (data >> 16);
1077 data |= (mux & mask) << bit;
1078 ret = regmap_update_bits(regmap, reg, rmask, data);
1083 #define PX30_PULL_PMU_OFFSET 0x10
1084 #define PX30_PULL_GRF_OFFSET 0x60
1085 #define PX30_PULL_BITS_PER_PIN 2
1086 #define PX30_PULL_PINS_PER_REG 8
1087 #define PX30_PULL_BANK_STRIDE 16
1089 static int px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1090 int pin_num, struct regmap **regmap,
1093 struct rockchip_pinctrl *info = bank->drvdata;
1095 /* The first 32 pins of the first bank are located in PMU */
1096 if (bank->bank_num == 0) {
1097 *regmap = info->regmap_pmu;
1098 *reg = PX30_PULL_PMU_OFFSET;
1100 *regmap = info->regmap_base;
1101 *reg = PX30_PULL_GRF_OFFSET;
1103 /* correct the offset, as we're starting with the 2nd bank */
1105 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE;
1108 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4);
1109 *bit = (pin_num % PX30_PULL_PINS_PER_REG);
1110 *bit *= PX30_PULL_BITS_PER_PIN;
1115 #define PX30_DRV_PMU_OFFSET 0x20
1116 #define PX30_DRV_GRF_OFFSET 0xf0
1117 #define PX30_DRV_BITS_PER_PIN 2
1118 #define PX30_DRV_PINS_PER_REG 8
1119 #define PX30_DRV_BANK_STRIDE 16
1121 static int px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1122 int pin_num, struct regmap **regmap,
1125 struct rockchip_pinctrl *info = bank->drvdata;
1127 /* The first 32 pins of the first bank are located in PMU */
1128 if (bank->bank_num == 0) {
1129 *regmap = info->regmap_pmu;
1130 *reg = PX30_DRV_PMU_OFFSET;
1132 *regmap = info->regmap_base;
1133 *reg = PX30_DRV_GRF_OFFSET;
1135 /* correct the offset, as we're starting with the 2nd bank */
1137 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE;
1140 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4);
1141 *bit = (pin_num % PX30_DRV_PINS_PER_REG);
1142 *bit *= PX30_DRV_BITS_PER_PIN;
1147 #define PX30_SCHMITT_PMU_OFFSET 0x38
1148 #define PX30_SCHMITT_GRF_OFFSET 0xc0
1149 #define PX30_SCHMITT_PINS_PER_PMU_REG 16
1150 #define PX30_SCHMITT_BANK_STRIDE 16
1151 #define PX30_SCHMITT_PINS_PER_GRF_REG 8
1153 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1155 struct regmap **regmap,
1158 struct rockchip_pinctrl *info = bank->drvdata;
1161 if (bank->bank_num == 0) {
1162 *regmap = info->regmap_pmu;
1163 *reg = PX30_SCHMITT_PMU_OFFSET;
1164 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG;
1166 *regmap = info->regmap_base;
1167 *reg = PX30_SCHMITT_GRF_OFFSET;
1168 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG;
1169 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE;
1172 *reg += ((pin_num / pins_per_reg) * 4);
1173 *bit = pin_num % pins_per_reg;
1178 #define RV1108_PULL_PMU_OFFSET 0x10
1179 #define RV1108_PULL_OFFSET 0x110
1180 #define RV1108_PULL_PINS_PER_REG 8
1181 #define RV1108_PULL_BITS_PER_PIN 2
1182 #define RV1108_PULL_BANK_STRIDE 16
1184 static int rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1185 int pin_num, struct regmap **regmap,
1188 struct rockchip_pinctrl *info = bank->drvdata;
1190 /* The first 24 pins of the first bank are located in PMU */
1191 if (bank->bank_num == 0) {
1192 *regmap = info->regmap_pmu;
1193 *reg = RV1108_PULL_PMU_OFFSET;
1195 *reg = RV1108_PULL_OFFSET;
1196 *regmap = info->regmap_base;
1197 /* correct the offset, as we're starting with the 2nd bank */
1199 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
1202 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1203 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1204 *bit *= RV1108_PULL_BITS_PER_PIN;
1209 #define RV1108_DRV_PMU_OFFSET 0x20
1210 #define RV1108_DRV_GRF_OFFSET 0x210
1211 #define RV1108_DRV_BITS_PER_PIN 2
1212 #define RV1108_DRV_PINS_PER_REG 8
1213 #define RV1108_DRV_BANK_STRIDE 16
1215 static int rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1216 int pin_num, struct regmap **regmap,
1219 struct rockchip_pinctrl *info = bank->drvdata;
1221 /* The first 24 pins of the first bank are located in PMU */
1222 if (bank->bank_num == 0) {
1223 *regmap = info->regmap_pmu;
1224 *reg = RV1108_DRV_PMU_OFFSET;
1226 *regmap = info->regmap_base;
1227 *reg = RV1108_DRV_GRF_OFFSET;
1229 /* correct the offset, as we're starting with the 2nd bank */
1231 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
1234 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1235 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1236 *bit *= RV1108_DRV_BITS_PER_PIN;
1241 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1242 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1243 #define RV1108_SCHMITT_BANK_STRIDE 8
1244 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1245 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1247 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1249 struct regmap **regmap,
1252 struct rockchip_pinctrl *info = bank->drvdata;
1255 if (bank->bank_num == 0) {
1256 *regmap = info->regmap_pmu;
1257 *reg = RV1108_SCHMITT_PMU_OFFSET;
1258 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1260 *regmap = info->regmap_base;
1261 *reg = RV1108_SCHMITT_GRF_OFFSET;
1262 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1263 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1265 *reg += ((pin_num / pins_per_reg) * 4);
1266 *bit = pin_num % pins_per_reg;
1271 #define RK3308_SCHMITT_PINS_PER_REG 8
1272 #define RK3308_SCHMITT_BANK_STRIDE 16
1273 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0
1275 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1276 int pin_num, struct regmap **regmap,
1279 struct rockchip_pinctrl *info = bank->drvdata;
1281 *regmap = info->regmap_base;
1282 *reg = RK3308_SCHMITT_GRF_OFFSET;
1284 *reg += bank->bank_num * RK3308_SCHMITT_BANK_STRIDE;
1285 *reg += ((pin_num / RK3308_SCHMITT_PINS_PER_REG) * 4);
1286 *bit = pin_num % RK3308_SCHMITT_PINS_PER_REG;
1291 #define RK2928_PULL_OFFSET 0x118
1292 #define RK2928_PULL_PINS_PER_REG 16
1293 #define RK2928_PULL_BANK_STRIDE 8
1295 static int rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1296 int pin_num, struct regmap **regmap,
1299 struct rockchip_pinctrl *info = bank->drvdata;
1301 *regmap = info->regmap_base;
1302 *reg = RK2928_PULL_OFFSET;
1303 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1304 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1306 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1311 #define RK3128_PULL_OFFSET 0x118
1313 static int rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1314 int pin_num, struct regmap **regmap,
1317 struct rockchip_pinctrl *info = bank->drvdata;
1319 *regmap = info->regmap_base;
1320 *reg = RK3128_PULL_OFFSET;
1321 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1322 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1324 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1329 #define RK3188_PULL_OFFSET 0x164
1330 #define RK3188_PULL_BITS_PER_PIN 2
1331 #define RK3188_PULL_PINS_PER_REG 8
1332 #define RK3188_PULL_BANK_STRIDE 16
1333 #define RK3188_PULL_PMU_OFFSET 0x64
1335 static int rk3188_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 /* The first 12 pins of the first bank are located elsewhere */
1342 if (bank->bank_num == 0 && pin_num < 12) {
1343 *regmap = info->regmap_pmu ? info->regmap_pmu
1344 : bank->regmap_pull;
1345 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
1346 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1347 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1348 *bit *= RK3188_PULL_BITS_PER_PIN;
1350 *regmap = info->regmap_pull ? info->regmap_pull
1351 : info->regmap_base;
1352 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1354 /* correct the offset, as it is the 2nd pull register */
1356 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1357 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1360 * The bits in these registers have an inverse ordering
1361 * with the lowest pin being in bits 15:14 and the highest
1364 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1365 *bit *= RK3188_PULL_BITS_PER_PIN;
1371 #define RK3288_PULL_OFFSET 0x140
1372 static int rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1373 int pin_num, struct regmap **regmap,
1376 struct rockchip_pinctrl *info = bank->drvdata;
1378 /* The first 24 pins of the first bank are located in PMU */
1379 if (bank->bank_num == 0) {
1380 *regmap = info->regmap_pmu;
1381 *reg = RK3188_PULL_PMU_OFFSET;
1383 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1384 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1385 *bit *= RK3188_PULL_BITS_PER_PIN;
1387 *regmap = info->regmap_base;
1388 *reg = RK3288_PULL_OFFSET;
1390 /* correct the offset, as we're starting with the 2nd bank */
1392 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1393 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1395 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1396 *bit *= RK3188_PULL_BITS_PER_PIN;
1402 #define RK3288_DRV_PMU_OFFSET 0x70
1403 #define RK3288_DRV_GRF_OFFSET 0x1c0
1404 #define RK3288_DRV_BITS_PER_PIN 2
1405 #define RK3288_DRV_PINS_PER_REG 8
1406 #define RK3288_DRV_BANK_STRIDE 16
1408 static int rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1409 int pin_num, struct regmap **regmap,
1412 struct rockchip_pinctrl *info = bank->drvdata;
1414 /* The first 24 pins of the first bank are located in PMU */
1415 if (bank->bank_num == 0) {
1416 *regmap = info->regmap_pmu;
1417 *reg = RK3288_DRV_PMU_OFFSET;
1419 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1420 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1421 *bit *= RK3288_DRV_BITS_PER_PIN;
1423 *regmap = info->regmap_base;
1424 *reg = RK3288_DRV_GRF_OFFSET;
1426 /* correct the offset, as we're starting with the 2nd bank */
1428 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1429 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1431 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1432 *bit *= RK3288_DRV_BITS_PER_PIN;
1438 #define RK3228_PULL_OFFSET 0x100
1440 static int rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1441 int pin_num, struct regmap **regmap,
1444 struct rockchip_pinctrl *info = bank->drvdata;
1446 *regmap = info->regmap_base;
1447 *reg = RK3228_PULL_OFFSET;
1448 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1449 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1451 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1452 *bit *= RK3188_PULL_BITS_PER_PIN;
1457 #define RK3228_DRV_GRF_OFFSET 0x200
1459 static int rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1460 int pin_num, struct regmap **regmap,
1463 struct rockchip_pinctrl *info = bank->drvdata;
1465 *regmap = info->regmap_base;
1466 *reg = RK3228_DRV_GRF_OFFSET;
1467 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1468 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1470 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1471 *bit *= RK3288_DRV_BITS_PER_PIN;
1476 #define RK3308_PULL_OFFSET 0xa0
1478 static int rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1479 int pin_num, struct regmap **regmap,
1482 struct rockchip_pinctrl *info = bank->drvdata;
1484 *regmap = info->regmap_base;
1485 *reg = RK3308_PULL_OFFSET;
1486 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1487 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1489 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1490 *bit *= RK3188_PULL_BITS_PER_PIN;
1495 #define RK3308_DRV_GRF_OFFSET 0x100
1497 static int rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1498 int pin_num, struct regmap **regmap,
1501 struct rockchip_pinctrl *info = bank->drvdata;
1503 *regmap = info->regmap_base;
1504 *reg = RK3308_DRV_GRF_OFFSET;
1505 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1506 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1508 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1509 *bit *= RK3288_DRV_BITS_PER_PIN;
1514 #define RK3368_PULL_GRF_OFFSET 0x100
1515 #define RK3368_PULL_PMU_OFFSET 0x10
1517 static int rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1518 int pin_num, struct regmap **regmap,
1521 struct rockchip_pinctrl *info = bank->drvdata;
1523 /* The first 32 pins of the first bank are located in PMU */
1524 if (bank->bank_num == 0) {
1525 *regmap = info->regmap_pmu;
1526 *reg = RK3368_PULL_PMU_OFFSET;
1528 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1529 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1530 *bit *= RK3188_PULL_BITS_PER_PIN;
1532 *regmap = info->regmap_base;
1533 *reg = RK3368_PULL_GRF_OFFSET;
1535 /* correct the offset, as we're starting with the 2nd bank */
1537 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1538 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1540 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1541 *bit *= RK3188_PULL_BITS_PER_PIN;
1547 #define RK3368_DRV_PMU_OFFSET 0x20
1548 #define RK3368_DRV_GRF_OFFSET 0x200
1550 static int rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1551 int pin_num, struct regmap **regmap,
1554 struct rockchip_pinctrl *info = bank->drvdata;
1556 /* The first 32 pins of the first bank are located in PMU */
1557 if (bank->bank_num == 0) {
1558 *regmap = info->regmap_pmu;
1559 *reg = RK3368_DRV_PMU_OFFSET;
1561 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1562 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1563 *bit *= RK3288_DRV_BITS_PER_PIN;
1565 *regmap = info->regmap_base;
1566 *reg = RK3368_DRV_GRF_OFFSET;
1568 /* correct the offset, as we're starting with the 2nd bank */
1570 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1571 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1573 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1574 *bit *= RK3288_DRV_BITS_PER_PIN;
1580 #define RK3399_PULL_GRF_OFFSET 0xe040
1581 #define RK3399_PULL_PMU_OFFSET 0x40
1582 #define RK3399_DRV_3BITS_PER_PIN 3
1584 static int rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1585 int pin_num, struct regmap **regmap,
1588 struct rockchip_pinctrl *info = bank->drvdata;
1590 /* The bank0:16 and bank1:32 pins are located in PMU */
1591 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1592 *regmap = info->regmap_pmu;
1593 *reg = RK3399_PULL_PMU_OFFSET;
1595 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1597 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1598 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1599 *bit *= RK3188_PULL_BITS_PER_PIN;
1601 *regmap = info->regmap_base;
1602 *reg = RK3399_PULL_GRF_OFFSET;
1604 /* correct the offset, as we're starting with the 3rd bank */
1606 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1607 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1609 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1610 *bit *= RK3188_PULL_BITS_PER_PIN;
1616 static int rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1617 int pin_num, struct regmap **regmap,
1620 struct rockchip_pinctrl *info = bank->drvdata;
1621 int drv_num = (pin_num / 8);
1623 /* The bank0:16 and bank1:32 pins are located in PMU */
1624 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1625 *regmap = info->regmap_pmu;
1627 *regmap = info->regmap_base;
1629 *reg = bank->drv[drv_num].offset;
1630 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1631 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1632 *bit = (pin_num % 8) * 3;
1634 *bit = (pin_num % 8) * 2;
1639 #define RK3568_PULL_PMU_OFFSET 0x20
1640 #define RK3568_PULL_GRF_OFFSET 0x80
1641 #define RK3568_PULL_BITS_PER_PIN 2
1642 #define RK3568_PULL_PINS_PER_REG 8
1643 #define RK3568_PULL_BANK_STRIDE 0x10
1645 static int rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1646 int pin_num, struct regmap **regmap,
1649 struct rockchip_pinctrl *info = bank->drvdata;
1651 if (bank->bank_num == 0) {
1652 *regmap = info->regmap_pmu;
1653 *reg = RK3568_PULL_PMU_OFFSET;
1654 *reg += bank->bank_num * RK3568_PULL_BANK_STRIDE;
1655 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1657 *bit = pin_num % RK3568_PULL_PINS_PER_REG;
1658 *bit *= RK3568_PULL_BITS_PER_PIN;
1660 *regmap = info->regmap_base;
1661 *reg = RK3568_PULL_GRF_OFFSET;
1662 *reg += (bank->bank_num - 1) * RK3568_PULL_BANK_STRIDE;
1663 *reg += ((pin_num / RK3568_PULL_PINS_PER_REG) * 4);
1665 *bit = (pin_num % RK3568_PULL_PINS_PER_REG);
1666 *bit *= RK3568_PULL_BITS_PER_PIN;
1672 #define RK3568_DRV_PMU_OFFSET 0x70
1673 #define RK3568_DRV_GRF_OFFSET 0x200
1674 #define RK3568_DRV_BITS_PER_PIN 8
1675 #define RK3568_DRV_PINS_PER_REG 2
1676 #define RK3568_DRV_BANK_STRIDE 0x40
1678 static int rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1679 int pin_num, struct regmap **regmap,
1682 struct rockchip_pinctrl *info = bank->drvdata;
1684 /* The first 32 pins of the first bank are located in PMU */
1685 if (bank->bank_num == 0) {
1686 *regmap = info->regmap_pmu;
1687 *reg = RK3568_DRV_PMU_OFFSET;
1688 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1690 *bit = pin_num % RK3568_DRV_PINS_PER_REG;
1691 *bit *= RK3568_DRV_BITS_PER_PIN;
1693 *regmap = info->regmap_base;
1694 *reg = RK3568_DRV_GRF_OFFSET;
1695 *reg += (bank->bank_num - 1) * RK3568_DRV_BANK_STRIDE;
1696 *reg += ((pin_num / RK3568_DRV_PINS_PER_REG) * 4);
1698 *bit = (pin_num % RK3568_DRV_PINS_PER_REG);
1699 *bit *= RK3568_DRV_BITS_PER_PIN;
1705 #define RK3588_PMU1_IOC_REG (0x0000)
1706 #define RK3588_PMU2_IOC_REG (0x4000)
1707 #define RK3588_BUS_IOC_REG (0x8000)
1708 #define RK3588_VCCIO1_4_IOC_REG (0x9000)
1709 #define RK3588_VCCIO3_5_IOC_REG (0xA000)
1710 #define RK3588_VCCIO2_IOC_REG (0xB000)
1711 #define RK3588_VCCIO6_IOC_REG (0xC000)
1712 #define RK3588_EMMC_IOC_REG (0xD000)
1714 static const u32 rk3588_ds_regs[][2] = {
1715 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0010},
1716 {RK_GPIO0_A4, RK3588_PMU1_IOC_REG + 0x0014},
1717 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0018},
1718 {RK_GPIO0_B4, RK3588_PMU2_IOC_REG + 0x0014},
1719 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x0018},
1720 {RK_GPIO0_C4, RK3588_PMU2_IOC_REG + 0x001C},
1721 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0020},
1722 {RK_GPIO0_D4, RK3588_PMU2_IOC_REG + 0x0024},
1723 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0020},
1724 {RK_GPIO1_A4, RK3588_VCCIO1_4_IOC_REG + 0x0024},
1725 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0028},
1726 {RK_GPIO1_B4, RK3588_VCCIO1_4_IOC_REG + 0x002C},
1727 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0030},
1728 {RK_GPIO1_C4, RK3588_VCCIO1_4_IOC_REG + 0x0034},
1729 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x0038},
1730 {RK_GPIO1_D4, RK3588_VCCIO1_4_IOC_REG + 0x003C},
1731 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0040},
1732 {RK_GPIO2_A4, RK3588_VCCIO3_5_IOC_REG + 0x0044},
1733 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0048},
1734 {RK_GPIO2_B4, RK3588_VCCIO3_5_IOC_REG + 0x004C},
1735 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0050},
1736 {RK_GPIO2_C4, RK3588_VCCIO3_5_IOC_REG + 0x0054},
1737 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x0058},
1738 {RK_GPIO2_D4, RK3588_EMMC_IOC_REG + 0x005C},
1739 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0060},
1740 {RK_GPIO3_A4, RK3588_VCCIO3_5_IOC_REG + 0x0064},
1741 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0068},
1742 {RK_GPIO3_B4, RK3588_VCCIO3_5_IOC_REG + 0x006C},
1743 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0070},
1744 {RK_GPIO3_C4, RK3588_VCCIO3_5_IOC_REG + 0x0074},
1745 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x0078},
1746 {RK_GPIO3_D4, RK3588_VCCIO3_5_IOC_REG + 0x007C},
1747 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0080},
1748 {RK_GPIO4_A4, RK3588_VCCIO6_IOC_REG + 0x0084},
1749 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0088},
1750 {RK_GPIO4_B4, RK3588_VCCIO6_IOC_REG + 0x008C},
1751 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0090},
1752 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0090},
1753 {RK_GPIO4_C4, RK3588_VCCIO3_5_IOC_REG + 0x0094},
1754 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x0098},
1755 {RK_GPIO4_D4, RK3588_VCCIO2_IOC_REG + 0x009C},
1758 static const u32 rk3588_p_regs[][2] = {
1759 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0020},
1760 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0024},
1761 {RK_GPIO0_B5, RK3588_PMU2_IOC_REG + 0x0028},
1762 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x002C},
1763 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0030},
1764 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0110},
1765 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0114},
1766 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0118},
1767 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x011C},
1768 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0120},
1769 {RK_GPIO2_A6, RK3588_VCCIO3_5_IOC_REG + 0x0120},
1770 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0124},
1771 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0128},
1772 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x012C},
1773 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0130},
1774 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0134},
1775 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0138},
1776 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x013C},
1777 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0140},
1778 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0144},
1779 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0148},
1780 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0148},
1781 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x014C},
1784 static const u32 rk3588_smt_regs[][2] = {
1785 {RK_GPIO0_A0, RK3588_PMU1_IOC_REG + 0x0030},
1786 {RK_GPIO0_B0, RK3588_PMU1_IOC_REG + 0x0034},
1787 {RK_GPIO0_B5, RK3588_PMU2_IOC_REG + 0x0040},
1788 {RK_GPIO0_C0, RK3588_PMU2_IOC_REG + 0x0044},
1789 {RK_GPIO0_D0, RK3588_PMU2_IOC_REG + 0x0048},
1790 {RK_GPIO1_A0, RK3588_VCCIO1_4_IOC_REG + 0x0210},
1791 {RK_GPIO1_B0, RK3588_VCCIO1_4_IOC_REG + 0x0214},
1792 {RK_GPIO1_C0, RK3588_VCCIO1_4_IOC_REG + 0x0218},
1793 {RK_GPIO1_D0, RK3588_VCCIO1_4_IOC_REG + 0x021C},
1794 {RK_GPIO2_A0, RK3588_EMMC_IOC_REG + 0x0220},
1795 {RK_GPIO2_A6, RK3588_VCCIO3_5_IOC_REG + 0x0220},
1796 {RK_GPIO2_B0, RK3588_VCCIO3_5_IOC_REG + 0x0224},
1797 {RK_GPIO2_C0, RK3588_VCCIO3_5_IOC_REG + 0x0228},
1798 {RK_GPIO2_D0, RK3588_EMMC_IOC_REG + 0x022C},
1799 {RK_GPIO3_A0, RK3588_VCCIO3_5_IOC_REG + 0x0230},
1800 {RK_GPIO3_B0, RK3588_VCCIO3_5_IOC_REG + 0x0234},
1801 {RK_GPIO3_C0, RK3588_VCCIO3_5_IOC_REG + 0x0238},
1802 {RK_GPIO3_D0, RK3588_VCCIO3_5_IOC_REG + 0x023C},
1803 {RK_GPIO4_A0, RK3588_VCCIO6_IOC_REG + 0x0240},
1804 {RK_GPIO4_B0, RK3588_VCCIO6_IOC_REG + 0x0244},
1805 {RK_GPIO4_C0, RK3588_VCCIO6_IOC_REG + 0x0248},
1806 {RK_GPIO4_C2, RK3588_VCCIO3_5_IOC_REG + 0x0248},
1807 {RK_GPIO4_D0, RK3588_VCCIO2_IOC_REG + 0x024C},
1810 #define RK3588_PULL_BITS_PER_PIN 2
1811 #define RK3588_PULL_PINS_PER_REG 8
1813 static int rk3588_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1814 int pin_num, struct regmap **regmap,
1817 struct rockchip_pinctrl *info = bank->drvdata;
1818 u8 bank_num = bank->bank_num;
1819 u32 pin = bank_num * 32 + pin_num;
1822 for (i = ARRAY_SIZE(rk3588_p_regs) - 1; i >= 0; i--) {
1823 if (pin >= rk3588_p_regs[i][0]) {
1824 *reg = rk3588_p_regs[i][1];
1825 *regmap = info->regmap_base;
1826 *bit = pin_num % RK3588_PULL_PINS_PER_REG;
1827 *bit *= RK3588_PULL_BITS_PER_PIN;
1835 #define RK3588_DRV_BITS_PER_PIN 4
1836 #define RK3588_DRV_PINS_PER_REG 4
1838 static int rk3588_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1839 int pin_num, struct regmap **regmap,
1842 struct rockchip_pinctrl *info = bank->drvdata;
1843 u8 bank_num = bank->bank_num;
1844 u32 pin = bank_num * 32 + pin_num;
1847 for (i = ARRAY_SIZE(rk3588_ds_regs) - 1; i >= 0; i--) {
1848 if (pin >= rk3588_ds_regs[i][0]) {
1849 *reg = rk3588_ds_regs[i][1];
1850 *regmap = info->regmap_base;
1851 *bit = pin_num % RK3588_DRV_PINS_PER_REG;
1852 *bit *= RK3588_DRV_BITS_PER_PIN;
1860 #define RK3588_SMT_BITS_PER_PIN 1
1861 #define RK3588_SMT_PINS_PER_REG 8
1863 static int rk3588_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1865 struct regmap **regmap,
1868 struct rockchip_pinctrl *info = bank->drvdata;
1869 u8 bank_num = bank->bank_num;
1870 u32 pin = bank_num * 32 + pin_num;
1873 for (i = ARRAY_SIZE(rk3588_smt_regs) - 1; i >= 0; i--) {
1874 if (pin >= rk3588_smt_regs[i][0]) {
1875 *reg = rk3588_smt_regs[i][1];
1876 *regmap = info->regmap_base;
1877 *bit = pin_num % RK3588_SMT_PINS_PER_REG;
1878 *bit *= RK3588_SMT_BITS_PER_PIN;
1886 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1887 { 2, 4, 8, 12, -1, -1, -1, -1 },
1888 { 3, 6, 9, 12, -1, -1, -1, -1 },
1889 { 5, 10, 15, 20, -1, -1, -1, -1 },
1890 { 4, 6, 8, 10, 12, 14, 16, 18 },
1891 { 4, 7, 10, 13, 16, 19, 22, 26 }
1894 static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1897 struct rockchip_pinctrl *info = bank->drvdata;
1898 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1899 struct device *dev = info->dev;
1900 struct regmap *regmap;
1902 u32 data, temp, rmask_bits;
1904 int drv_type = bank->drv[pin_num / 8].drv_type;
1906 ret = ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1911 case DRV_TYPE_IO_1V8_3V0_AUTO:
1912 case DRV_TYPE_IO_3V3_ONLY:
1913 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1916 /* regular case, nothing to do */
1920 * drive-strength offset is special, as it is
1921 * spread over 2 registers
1923 ret = regmap_read(regmap, reg, &data);
1927 ret = regmap_read(regmap, reg + 0x4, &temp);
1932 * the bit data[15] contains bit 0 of the value
1933 * while temp[1:0] contains bits 2 and 1
1940 return rockchip_perpin_drv_list[drv_type][data];
1942 /* setting fully enclosed in the second register */
1947 dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1953 case DRV_TYPE_IO_DEFAULT:
1954 case DRV_TYPE_IO_1V8_OR_3V0:
1955 case DRV_TYPE_IO_1V8_ONLY:
1956 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1959 dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type);
1963 ret = regmap_read(regmap, reg, &data);
1968 data &= (1 << rmask_bits) - 1;
1970 return rockchip_perpin_drv_list[drv_type][data];
1973 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1974 int pin_num, int strength)
1976 struct rockchip_pinctrl *info = bank->drvdata;
1977 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1978 struct device *dev = info->dev;
1979 struct regmap *regmap;
1981 u32 data, rmask, rmask_bits, temp;
1983 int drv_type = bank->drv[pin_num / 8].drv_type;
1985 dev_dbg(dev, "setting drive of GPIO%d-%d to %d\n",
1986 bank->bank_num, pin_num, strength);
1988 ret = ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1991 if (ctrl->type == RK3588) {
1992 rmask_bits = RK3588_DRV_BITS_PER_PIN;
1995 } else if (ctrl->type == RK3568) {
1996 rmask_bits = RK3568_DRV_BITS_PER_PIN;
1997 ret = (1 << (strength + 1)) - 1;
2002 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
2003 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
2006 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
2007 ret = rockchip_perpin_drv_list[drv_type][i];
2013 dev_err(dev, "unsupported driver strength %d\n", strength);
2018 case DRV_TYPE_IO_1V8_3V0_AUTO:
2019 case DRV_TYPE_IO_3V3_ONLY:
2020 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
2023 /* regular case, nothing to do */
2027 * drive-strength offset is special, as it is spread
2028 * over 2 registers, the bit data[15] contains bit 0
2029 * of the value while temp[1:0] contains bits 2 and 1
2031 data = (ret & 0x1) << 15;
2032 temp = (ret >> 0x1) & 0x3;
2034 rmask = BIT(15) | BIT(31);
2036 ret = regmap_update_bits(regmap, reg, rmask, data);
2040 rmask = 0x3 | (0x3 << 16);
2041 temp |= (0x3 << 16);
2043 ret = regmap_update_bits(regmap, reg, rmask, temp);
2047 /* setting fully enclosed in the second register */
2052 dev_err(dev, "unsupported bit: %d for pinctrl drive type: %d\n",
2057 case DRV_TYPE_IO_DEFAULT:
2058 case DRV_TYPE_IO_1V8_OR_3V0:
2059 case DRV_TYPE_IO_1V8_ONLY:
2060 rmask_bits = RK3288_DRV_BITS_PER_PIN;
2063 dev_err(dev, "unsupported pinctrl drive type: %d\n", drv_type);
2068 /* enable the write to the equivalent lower bits */
2069 data = ((1 << rmask_bits) - 1) << (bit + 16);
2070 rmask = data | (data >> 16);
2071 data |= (ret << bit);
2073 ret = regmap_update_bits(regmap, reg, rmask, data);
2078 static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
2080 PIN_CONFIG_BIAS_DISABLE,
2081 PIN_CONFIG_BIAS_PULL_UP,
2082 PIN_CONFIG_BIAS_PULL_DOWN,
2083 PIN_CONFIG_BIAS_BUS_HOLD
2086 PIN_CONFIG_BIAS_DISABLE,
2087 PIN_CONFIG_BIAS_PULL_DOWN,
2088 PIN_CONFIG_BIAS_DISABLE,
2089 PIN_CONFIG_BIAS_PULL_UP
2093 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
2095 struct rockchip_pinctrl *info = bank->drvdata;
2096 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2097 struct device *dev = info->dev;
2098 struct regmap *regmap;
2099 int reg, ret, pull_type;
2103 /* rk3066b does support any pulls */
2104 if (ctrl->type == RK3066B)
2105 return PIN_CONFIG_BIAS_DISABLE;
2107 ret = ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
2111 ret = regmap_read(regmap, reg, &data);
2115 switch (ctrl->type) {
2118 return !(data & BIT(bit))
2119 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
2120 : PIN_CONFIG_BIAS_DISABLE;
2129 pull_type = bank->pull_type[pin_num / 8];
2131 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
2133 return rockchip_pull_list[pull_type][data];
2135 dev_err(dev, "unsupported pinctrl type\n");
2140 static int rockchip_set_pull(struct rockchip_pin_bank *bank,
2141 int pin_num, int pull)
2143 struct rockchip_pinctrl *info = bank->drvdata;
2144 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2145 struct device *dev = info->dev;
2146 struct regmap *regmap;
2147 int reg, ret, i, pull_type;
2151 dev_dbg(dev, "setting pull of GPIO%d-%d to %d\n", bank->bank_num, pin_num, pull);
2153 /* rk3066b does support any pulls */
2154 if (ctrl->type == RK3066B)
2155 return pull ? -EINVAL : 0;
2157 ret = ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
2161 switch (ctrl->type) {
2164 data = BIT(bit + 16);
2165 if (pull == PIN_CONFIG_BIAS_DISABLE)
2167 ret = regmap_write(regmap, reg, data);
2178 pull_type = bank->pull_type[pin_num / 8];
2180 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
2182 if (rockchip_pull_list[pull_type][i] == pull) {
2188 * In the TRM, pull-up being 1 for everything except the GPIO0_D0-D6,
2189 * where that pull up value becomes 3.
2191 if (ctrl->type == RK3568 && bank->bank_num == 0 && pin_num >= 27 && pin_num <= 30) {
2197 dev_err(dev, "unsupported pull setting %d\n", pull);
2201 /* enable the write to the equivalent lower bits */
2202 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
2203 rmask = data | (data >> 16);
2204 data |= (ret << bit);
2206 ret = regmap_update_bits(regmap, reg, rmask, data);
2209 dev_err(dev, "unsupported pinctrl type\n");
2216 #define RK3328_SCHMITT_BITS_PER_PIN 1
2217 #define RK3328_SCHMITT_PINS_PER_REG 16
2218 #define RK3328_SCHMITT_BANK_STRIDE 8
2219 #define RK3328_SCHMITT_GRF_OFFSET 0x380
2221 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
2223 struct regmap **regmap,
2226 struct rockchip_pinctrl *info = bank->drvdata;
2228 *regmap = info->regmap_base;
2229 *reg = RK3328_SCHMITT_GRF_OFFSET;
2231 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
2232 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
2233 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
2238 #define RK3568_SCHMITT_BITS_PER_PIN 2
2239 #define RK3568_SCHMITT_PINS_PER_REG 8
2240 #define RK3568_SCHMITT_BANK_STRIDE 0x10
2241 #define RK3568_SCHMITT_GRF_OFFSET 0xc0
2242 #define RK3568_SCHMITT_PMUGRF_OFFSET 0x30
2244 static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
2246 struct regmap **regmap,
2249 struct rockchip_pinctrl *info = bank->drvdata;
2251 if (bank->bank_num == 0) {
2252 *regmap = info->regmap_pmu;
2253 *reg = RK3568_SCHMITT_PMUGRF_OFFSET;
2255 *regmap = info->regmap_base;
2256 *reg = RK3568_SCHMITT_GRF_OFFSET;
2257 *reg += (bank->bank_num - 1) * RK3568_SCHMITT_BANK_STRIDE;
2260 *reg += ((pin_num / RK3568_SCHMITT_PINS_PER_REG) * 4);
2261 *bit = pin_num % RK3568_SCHMITT_PINS_PER_REG;
2262 *bit *= RK3568_SCHMITT_BITS_PER_PIN;
2267 static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
2269 struct rockchip_pinctrl *info = bank->drvdata;
2270 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2271 struct regmap *regmap;
2276 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
2280 ret = regmap_read(regmap, reg, &data);
2285 switch (ctrl->type) {
2287 return data & ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1);
2295 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
2296 int pin_num, int enable)
2298 struct rockchip_pinctrl *info = bank->drvdata;
2299 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2300 struct device *dev = info->dev;
2301 struct regmap *regmap;
2306 dev_dbg(dev, "setting input schmitt of GPIO%d-%d to %d\n",
2307 bank->bank_num, pin_num, enable);
2309 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
2313 /* enable the write to the equivalent lower bits */
2314 switch (ctrl->type) {
2316 data = ((1 << RK3568_SCHMITT_BITS_PER_PIN) - 1) << (bit + 16);
2317 rmask = data | (data >> 16);
2318 data |= ((enable ? 0x2 : 0x1) << bit);
2321 data = BIT(bit + 16) | (enable << bit);
2322 rmask = BIT(bit + 16) | BIT(bit);
2326 return regmap_update_bits(regmap, reg, rmask, data);
2330 * Pinmux_ops handling
2333 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
2335 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2337 return info->nfunctions;
2340 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
2343 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2345 return info->functions[selector].name;
2348 static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
2349 unsigned selector, const char * const **groups,
2350 unsigned * const num_groups)
2352 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2354 *groups = info->functions[selector].groups;
2355 *num_groups = info->functions[selector].ngroups;
2360 static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
2363 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2364 const unsigned int *pins = info->groups[group].pins;
2365 const struct rockchip_pin_config *data = info->groups[group].data;
2366 struct device *dev = info->dev;
2367 struct rockchip_pin_bank *bank;
2370 dev_dbg(dev, "enable function %s group %s\n",
2371 info->functions[selector].name, info->groups[group].name);
2374 * for each pin in the pin group selected, program the corresponding
2375 * pin function number in the config register.
2377 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
2378 bank = pin_to_bank(info, pins[cnt]);
2379 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
2386 /* revert the already done pin settings */
2387 for (cnt--; cnt >= 0; cnt--)
2388 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
2396 static const struct pinmux_ops rockchip_pmx_ops = {
2397 .get_functions_count = rockchip_pmx_get_funcs_count,
2398 .get_function_name = rockchip_pmx_get_func_name,
2399 .get_function_groups = rockchip_pmx_get_groups,
2400 .set_mux = rockchip_pmx_set,
2404 * Pinconf_ops handling
2407 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2408 enum pin_config_param pull)
2410 switch (ctrl->type) {
2413 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2414 pull == PIN_CONFIG_BIAS_DISABLE);
2416 return pull ? false : true;
2426 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
2432 static int rockchip_pinconf_defer_pin(struct rockchip_pin_bank *bank,
2433 unsigned int pin, u32 param, u32 arg)
2435 struct rockchip_pin_deferred *cfg;
2437 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2445 list_add_tail(&cfg->head, &bank->deferred_pins);
2450 /* set the pin config settings for a specified pin */
2451 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2452 unsigned long *configs, unsigned num_configs)
2454 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2455 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2456 struct gpio_chip *gpio = &bank->gpio_chip;
2457 enum pin_config_param param;
2462 for (i = 0; i < num_configs; i++) {
2463 param = pinconf_to_config_param(configs[i]);
2464 arg = pinconf_to_config_argument(configs[i]);
2466 if (param == PIN_CONFIG_OUTPUT || param == PIN_CONFIG_INPUT_ENABLE) {
2468 * Check for gpio driver not being probed yet.
2469 * The lock makes sure that either gpio-probe has completed
2470 * or the gpio driver hasn't probed yet.
2472 mutex_lock(&bank->deferred_lock);
2473 if (!gpio || !gpio->direction_output) {
2474 rc = rockchip_pinconf_defer_pin(bank, pin - bank->pin_base, param,
2476 mutex_unlock(&bank->deferred_lock);
2482 mutex_unlock(&bank->deferred_lock);
2486 case PIN_CONFIG_BIAS_DISABLE:
2487 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2492 case PIN_CONFIG_BIAS_PULL_UP:
2493 case PIN_CONFIG_BIAS_PULL_DOWN:
2494 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2495 case PIN_CONFIG_BIAS_BUS_HOLD:
2496 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2502 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2507 case PIN_CONFIG_OUTPUT:
2508 rc = rockchip_set_mux(bank, pin - bank->pin_base,
2510 if (rc != RK_FUNC_GPIO)
2513 rc = gpio->direction_output(gpio, pin - bank->pin_base,
2518 case PIN_CONFIG_INPUT_ENABLE:
2519 rc = rockchip_set_mux(bank, pin - bank->pin_base,
2521 if (rc != RK_FUNC_GPIO)
2524 rc = gpio->direction_input(gpio, pin - bank->pin_base);
2528 case PIN_CONFIG_DRIVE_STRENGTH:
2529 /* rk3288 is the first with per-pin drive-strength */
2530 if (!info->ctrl->drv_calc_reg)
2533 rc = rockchip_set_drive_perpin(bank,
2534 pin - bank->pin_base, arg);
2538 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2539 if (!info->ctrl->schmitt_calc_reg)
2542 rc = rockchip_set_schmitt(bank,
2543 pin - bank->pin_base, arg);
2551 } /* for each config */
2556 /* get the pin config settings for a specified pin */
2557 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2558 unsigned long *config)
2560 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2561 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2562 struct gpio_chip *gpio = &bank->gpio_chip;
2563 enum pin_config_param param = pinconf_to_config_param(*config);
2568 case PIN_CONFIG_BIAS_DISABLE:
2569 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2574 case PIN_CONFIG_BIAS_PULL_UP:
2575 case PIN_CONFIG_BIAS_PULL_DOWN:
2576 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2577 case PIN_CONFIG_BIAS_BUS_HOLD:
2578 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2581 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2586 case PIN_CONFIG_OUTPUT:
2587 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2588 if (rc != RK_FUNC_GPIO)
2591 if (!gpio || !gpio->get) {
2596 rc = gpio->get(gpio, pin - bank->pin_base);
2602 case PIN_CONFIG_DRIVE_STRENGTH:
2603 /* rk3288 is the first with per-pin drive-strength */
2604 if (!info->ctrl->drv_calc_reg)
2607 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
2613 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2614 if (!info->ctrl->schmitt_calc_reg)
2617 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2628 *config = pinconf_to_config_packed(param, arg);
2633 static const struct pinconf_ops rockchip_pinconf_ops = {
2634 .pin_config_get = rockchip_pinconf_get,
2635 .pin_config_set = rockchip_pinconf_set,
2639 static const struct of_device_id rockchip_bank_match[] = {
2640 { .compatible = "rockchip,gpio-bank" },
2641 { .compatible = "rockchip,rk3188-gpio-bank0" },
2645 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2646 struct device_node *np)
2648 struct device_node *child;
2650 for_each_child_of_node(np, child) {
2651 if (of_match_node(rockchip_bank_match, child))
2655 info->ngroups += of_get_child_count(child);
2659 static int rockchip_pinctrl_parse_groups(struct device_node *np,
2660 struct rockchip_pin_group *grp,
2661 struct rockchip_pinctrl *info,
2664 struct device *dev = info->dev;
2665 struct rockchip_pin_bank *bank;
2672 dev_dbg(dev, "group(%d): %pOFn\n", index, np);
2674 /* Initialise group */
2675 grp->name = np->name;
2678 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2679 * do sanity check and calculate pins number
2681 list = of_get_property(np, "rockchip,pins", &size);
2682 /* we do not check return since it's safe node passed down */
2683 size /= sizeof(*list);
2684 if (!size || size % 4)
2685 return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n");
2687 grp->npins = size / 4;
2689 grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL);
2690 grp->data = devm_kcalloc(dev, grp->npins, sizeof(*grp->data), GFP_KERNEL);
2691 if (!grp->pins || !grp->data)
2694 for (i = 0, j = 0; i < size; i += 4, j++) {
2695 const __be32 *phandle;
2696 struct device_node *np_config;
2698 num = be32_to_cpu(*list++);
2699 bank = bank_num_to_bank(info, num);
2701 return PTR_ERR(bank);
2703 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2704 grp->data[j].func = be32_to_cpu(*list++);
2710 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
2711 ret = pinconf_generic_parse_dt_config(np_config, NULL,
2712 &grp->data[j].configs, &grp->data[j].nconfigs);
2720 static int rockchip_pinctrl_parse_functions(struct device_node *np,
2721 struct rockchip_pinctrl *info,
2724 struct device *dev = info->dev;
2725 struct device_node *child;
2726 struct rockchip_pmx_func *func;
2727 struct rockchip_pin_group *grp;
2729 static u32 grp_index;
2732 dev_dbg(dev, "parse function(%d): %pOFn\n", index, np);
2734 func = &info->functions[index];
2736 /* Initialise function */
2737 func->name = np->name;
2738 func->ngroups = of_get_child_count(np);
2739 if (func->ngroups <= 0)
2742 func->groups = devm_kcalloc(dev, func->ngroups, sizeof(*func->groups), GFP_KERNEL);
2746 for_each_child_of_node(np, child) {
2747 func->groups[i] = child->name;
2748 grp = &info->groups[grp_index++];
2749 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
2759 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2760 struct rockchip_pinctrl *info)
2762 struct device *dev = &pdev->dev;
2763 struct device_node *np = dev->of_node;
2764 struct device_node *child;
2768 rockchip_pinctrl_child_count(info, np);
2770 dev_dbg(dev, "nfunctions = %d\n", info->nfunctions);
2771 dev_dbg(dev, "ngroups = %d\n", info->ngroups);
2773 info->functions = devm_kcalloc(dev, info->nfunctions, sizeof(*info->functions), GFP_KERNEL);
2774 if (!info->functions)
2777 info->groups = devm_kcalloc(dev, info->ngroups, sizeof(*info->groups), GFP_KERNEL);
2783 for_each_child_of_node(np, child) {
2784 if (of_match_node(rockchip_bank_match, child))
2787 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2789 dev_err(dev, "failed to parse function\n");
2798 static int rockchip_pinctrl_register(struct platform_device *pdev,
2799 struct rockchip_pinctrl *info)
2801 struct pinctrl_desc *ctrldesc = &info->pctl;
2802 struct pinctrl_pin_desc *pindesc, *pdesc;
2803 struct rockchip_pin_bank *pin_bank;
2804 struct device *dev = &pdev->dev;
2809 ctrldesc->name = "rockchip-pinctrl";
2810 ctrldesc->owner = THIS_MODULE;
2811 ctrldesc->pctlops = &rockchip_pctrl_ops;
2812 ctrldesc->pmxops = &rockchip_pmx_ops;
2813 ctrldesc->confops = &rockchip_pinconf_ops;
2815 pindesc = devm_kcalloc(dev, info->ctrl->nr_pins, sizeof(*pindesc), GFP_KERNEL);
2819 ctrldesc->pins = pindesc;
2820 ctrldesc->npins = info->ctrl->nr_pins;
2823 for (bank = 0, k = 0; bank < info->ctrl->nr_banks; bank++) {
2824 pin_bank = &info->ctrl->pin_banks[bank];
2826 pin_names = devm_kasprintf_strarray(dev, pin_bank->name, pin_bank->nr_pins);
2827 if (IS_ERR(pin_names))
2828 return PTR_ERR(pin_names);
2830 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2832 pdesc->name = pin_names[pin];
2836 INIT_LIST_HEAD(&pin_bank->deferred_pins);
2837 mutex_init(&pin_bank->deferred_lock);
2840 ret = rockchip_pinctrl_parse_dt(pdev, info);
2844 info->pctl_dev = devm_pinctrl_register(dev, ctrldesc, info);
2845 if (IS_ERR(info->pctl_dev))
2846 return dev_err_probe(dev, PTR_ERR(info->pctl_dev), "could not register pinctrl driver\n");
2851 static const struct of_device_id rockchip_pinctrl_dt_match[];
2853 /* retrieve the soc specific data */
2854 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2855 struct rockchip_pinctrl *d,
2856 struct platform_device *pdev)
2858 struct device *dev = &pdev->dev;
2859 struct device_node *node = dev->of_node;
2860 const struct of_device_id *match;
2861 struct rockchip_pin_ctrl *ctrl;
2862 struct rockchip_pin_bank *bank;
2863 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
2865 match = of_match_node(rockchip_pinctrl_dt_match, node);
2866 ctrl = (struct rockchip_pin_ctrl *)match->data;
2868 grf_offs = ctrl->grf_mux_offset;
2869 pmu_offs = ctrl->pmu_mux_offset;
2870 drv_pmu_offs = ctrl->pmu_drv_offset;
2871 drv_grf_offs = ctrl->grf_drv_offset;
2872 bank = ctrl->pin_banks;
2873 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2876 raw_spin_lock_init(&bank->slock);
2878 bank->pin_base = ctrl->nr_pins;
2879 ctrl->nr_pins += bank->nr_pins;
2881 /* calculate iomux and drv offsets */
2882 for (j = 0; j < 4; j++) {
2883 struct rockchip_iomux *iom = &bank->iomux[j];
2884 struct rockchip_drv *drv = &bank->drv[j];
2887 if (bank_pins >= bank->nr_pins)
2890 /* preset iomux offset value, set new start value */
2891 if (iom->offset >= 0) {
2892 if (iom->type & IOMUX_SOURCE_PMU)
2893 pmu_offs = iom->offset;
2895 grf_offs = iom->offset;
2896 } else { /* set current iomux offset */
2897 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2898 pmu_offs : grf_offs;
2901 /* preset drv offset value, set new start value */
2902 if (drv->offset >= 0) {
2903 if (iom->type & IOMUX_SOURCE_PMU)
2904 drv_pmu_offs = drv->offset;
2906 drv_grf_offs = drv->offset;
2907 } else { /* set current drv offset */
2908 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2909 drv_pmu_offs : drv_grf_offs;
2912 dev_dbg(dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
2913 i, j, iom->offset, drv->offset);
2916 * Increase offset according to iomux width.
2917 * 4bit iomux'es are spread over two registers.
2919 inc = (iom->type & (IOMUX_WIDTH_4BIT |
2921 IOMUX_WIDTH_2BIT)) ? 8 : 4;
2922 if (iom->type & IOMUX_SOURCE_PMU)
2928 * Increase offset according to drv width.
2929 * 3bit drive-strenth'es are spread over two registers.
2931 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
2932 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
2937 if (iom->type & IOMUX_SOURCE_PMU)
2938 drv_pmu_offs += inc;
2940 drv_grf_offs += inc;
2945 /* calculate the per-bank recalced_mask */
2946 for (j = 0; j < ctrl->niomux_recalced; j++) {
2949 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
2950 pin = ctrl->iomux_recalced[j].pin;
2951 bank->recalced_mask |= BIT(pin);
2955 /* calculate the per-bank route_mask */
2956 for (j = 0; j < ctrl->niomux_routes; j++) {
2959 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
2960 pin = ctrl->iomux_routes[j].pin;
2961 bank->route_mask |= BIT(pin);
2969 #define RK3288_GRF_GPIO6C_IOMUX 0x64
2970 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
2972 static u32 rk3288_grf_gpio6c_iomux;
2974 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
2976 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
2977 int ret = pinctrl_force_sleep(info->pctl_dev);
2983 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
2984 * the setting here, and restore it at resume.
2986 if (info->ctrl->type == RK3288) {
2987 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2988 &rk3288_grf_gpio6c_iomux);
2990 pinctrl_force_default(info->pctl_dev);
2998 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
3000 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
3003 if (info->ctrl->type == RK3288) {
3004 ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3005 rk3288_grf_gpio6c_iomux |
3006 GPIO6C6_SEL_WRITE_ENABLE);
3011 return pinctrl_force_default(info->pctl_dev);
3014 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
3015 rockchip_pinctrl_resume);
3017 static int rockchip_pinctrl_probe(struct platform_device *pdev)
3019 struct rockchip_pinctrl *info;
3020 struct device *dev = &pdev->dev;
3021 struct device_node *np = dev->of_node, *node;
3022 struct rockchip_pin_ctrl *ctrl;
3023 struct resource *res;
3028 return dev_err_probe(dev, -ENODEV, "device tree node not found\n");
3030 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
3036 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
3038 return dev_err_probe(dev, -EINVAL, "driver data not available\n");
3041 node = of_parse_phandle(np, "rockchip,grf", 0);
3043 info->regmap_base = syscon_node_to_regmap(node);
3045 if (IS_ERR(info->regmap_base))
3046 return PTR_ERR(info->regmap_base);
3048 base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
3050 return PTR_ERR(base);
3052 rockchip_regmap_config.max_register = resource_size(res) - 4;
3053 rockchip_regmap_config.name = "rockchip,pinctrl";
3055 devm_regmap_init_mmio(dev, base, &rockchip_regmap_config);
3057 /* to check for the old dt-bindings */
3058 info->reg_size = resource_size(res);
3060 /* Honor the old binding, with pull registers as 2nd resource */
3061 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
3062 base = devm_platform_get_and_ioremap_resource(pdev, 1, &res);
3064 return PTR_ERR(base);
3066 rockchip_regmap_config.max_register = resource_size(res) - 4;
3067 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
3069 devm_regmap_init_mmio(dev, base, &rockchip_regmap_config);
3073 /* try to find the optional reference to the pmu syscon */
3074 node = of_parse_phandle(np, "rockchip,pmu", 0);
3076 info->regmap_pmu = syscon_node_to_regmap(node);
3078 if (IS_ERR(info->regmap_pmu))
3079 return PTR_ERR(info->regmap_pmu);
3082 ret = rockchip_pinctrl_register(pdev, info);
3086 platform_set_drvdata(pdev, info);
3088 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
3090 return dev_err_probe(dev, ret, "failed to register gpio device\n");
3095 static int rockchip_pinctrl_remove(struct platform_device *pdev)
3097 struct rockchip_pinctrl *info = platform_get_drvdata(pdev);
3098 struct rockchip_pin_bank *bank;
3099 struct rockchip_pin_deferred *cfg;
3102 of_platform_depopulate(&pdev->dev);
3104 for (i = 0; i < info->ctrl->nr_banks; i++) {
3105 bank = &info->ctrl->pin_banks[i];
3107 mutex_lock(&bank->deferred_lock);
3108 while (!list_empty(&bank->deferred_pins)) {
3109 cfg = list_first_entry(&bank->deferred_pins,
3110 struct rockchip_pin_deferred, head);
3111 list_del(&cfg->head);
3114 mutex_unlock(&bank->deferred_lock);
3120 static struct rockchip_pin_bank px30_pin_banks[] = {
3121 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3126 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3131 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3136 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3143 static struct rockchip_pin_ctrl px30_pin_ctrl = {
3144 .pin_banks = px30_pin_banks,
3145 .nr_banks = ARRAY_SIZE(px30_pin_banks),
3146 .label = "PX30-GPIO",
3148 .grf_mux_offset = 0x0,
3149 .pmu_mux_offset = 0x0,
3150 .iomux_routes = px30_mux_route_data,
3151 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
3152 .pull_calc_reg = px30_calc_pull_reg_and_bit,
3153 .drv_calc_reg = px30_calc_drv_reg_and_bit,
3154 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
3157 static struct rockchip_pin_bank rv1108_pin_banks[] = {
3158 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3162 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3163 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3164 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3167 static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
3168 .pin_banks = rv1108_pin_banks,
3169 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
3170 .label = "RV1108-GPIO",
3172 .grf_mux_offset = 0x10,
3173 .pmu_mux_offset = 0x0,
3174 .iomux_recalced = rv1108_mux_recalced_data,
3175 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
3176 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
3177 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
3178 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
3181 static struct rockchip_pin_bank rk2928_pin_banks[] = {
3182 PIN_BANK(0, 32, "gpio0"),
3183 PIN_BANK(1, 32, "gpio1"),
3184 PIN_BANK(2, 32, "gpio2"),
3185 PIN_BANK(3, 32, "gpio3"),
3188 static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
3189 .pin_banks = rk2928_pin_banks,
3190 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
3191 .label = "RK2928-GPIO",
3193 .grf_mux_offset = 0xa8,
3194 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3197 static struct rockchip_pin_bank rk3036_pin_banks[] = {
3198 PIN_BANK(0, 32, "gpio0"),
3199 PIN_BANK(1, 32, "gpio1"),
3200 PIN_BANK(2, 32, "gpio2"),
3203 static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
3204 .pin_banks = rk3036_pin_banks,
3205 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
3206 .label = "RK3036-GPIO",
3208 .grf_mux_offset = 0xa8,
3209 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3212 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
3213 PIN_BANK(0, 32, "gpio0"),
3214 PIN_BANK(1, 32, "gpio1"),
3215 PIN_BANK(2, 32, "gpio2"),
3216 PIN_BANK(3, 32, "gpio3"),
3217 PIN_BANK(4, 32, "gpio4"),
3218 PIN_BANK(6, 16, "gpio6"),
3221 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
3222 .pin_banks = rk3066a_pin_banks,
3223 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
3224 .label = "RK3066a-GPIO",
3226 .grf_mux_offset = 0xa8,
3227 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3230 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
3231 PIN_BANK(0, 32, "gpio0"),
3232 PIN_BANK(1, 32, "gpio1"),
3233 PIN_BANK(2, 32, "gpio2"),
3234 PIN_BANK(3, 32, "gpio3"),
3237 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
3238 .pin_banks = rk3066b_pin_banks,
3239 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
3240 .label = "RK3066b-GPIO",
3242 .grf_mux_offset = 0x60,
3245 static struct rockchip_pin_bank rk3128_pin_banks[] = {
3246 PIN_BANK(0, 32, "gpio0"),
3247 PIN_BANK(1, 32, "gpio1"),
3248 PIN_BANK(2, 32, "gpio2"),
3249 PIN_BANK(3, 32, "gpio3"),
3252 static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
3253 .pin_banks = rk3128_pin_banks,
3254 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
3255 .label = "RK3128-GPIO",
3257 .grf_mux_offset = 0xa8,
3258 .iomux_recalced = rk3128_mux_recalced_data,
3259 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
3260 .iomux_routes = rk3128_mux_route_data,
3261 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
3262 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
3265 static struct rockchip_pin_bank rk3188_pin_banks[] = {
3266 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
3267 PIN_BANK(1, 32, "gpio1"),
3268 PIN_BANK(2, 32, "gpio2"),
3269 PIN_BANK(3, 32, "gpio3"),
3272 static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
3273 .pin_banks = rk3188_pin_banks,
3274 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
3275 .label = "RK3188-GPIO",
3277 .grf_mux_offset = 0x60,
3278 .iomux_routes = rk3188_mux_route_data,
3279 .niomux_routes = ARRAY_SIZE(rk3188_mux_route_data),
3280 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
3283 static struct rockchip_pin_bank rk3228_pin_banks[] = {
3284 PIN_BANK(0, 32, "gpio0"),
3285 PIN_BANK(1, 32, "gpio1"),
3286 PIN_BANK(2, 32, "gpio2"),
3287 PIN_BANK(3, 32, "gpio3"),
3290 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
3291 .pin_banks = rk3228_pin_banks,
3292 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
3293 .label = "RK3228-GPIO",
3295 .grf_mux_offset = 0x0,
3296 .iomux_routes = rk3228_mux_route_data,
3297 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
3298 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3299 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3302 static struct rockchip_pin_bank rk3288_pin_banks[] = {
3303 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
3308 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
3313 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3314 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3315 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3320 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3325 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3326 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3331 PIN_BANK(8, 16, "gpio8"),
3334 static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3335 .pin_banks = rk3288_pin_banks,
3336 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3337 .label = "RK3288-GPIO",
3339 .grf_mux_offset = 0x0,
3340 .pmu_mux_offset = 0x84,
3341 .iomux_routes = rk3288_mux_route_data,
3342 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
3343 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
3344 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
3347 static struct rockchip_pin_bank rk3308_pin_banks[] = {
3348 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT,
3352 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT,
3356 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT,
3360 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT,
3364 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT,
3370 static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
3371 .pin_banks = rk3308_pin_banks,
3372 .nr_banks = ARRAY_SIZE(rk3308_pin_banks),
3373 .label = "RK3308-GPIO",
3375 .grf_mux_offset = 0x0,
3376 .iomux_recalced = rk3308_mux_recalced_data,
3377 .niomux_recalced = ARRAY_SIZE(rk3308_mux_recalced_data),
3378 .iomux_routes = rk3308_mux_route_data,
3379 .niomux_routes = ARRAY_SIZE(rk3308_mux_route_data),
3380 .pull_calc_reg = rk3308_calc_pull_reg_and_bit,
3381 .drv_calc_reg = rk3308_calc_drv_reg_and_bit,
3382 .schmitt_calc_reg = rk3308_calc_schmitt_reg_and_bit,
3385 static struct rockchip_pin_bank rk3328_pin_banks[] = {
3386 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3387 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3388 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3392 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3399 static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3400 .pin_banks = rk3328_pin_banks,
3401 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3402 .label = "RK3328-GPIO",
3404 .grf_mux_offset = 0x0,
3405 .iomux_recalced = rk3328_mux_recalced_data,
3406 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
3407 .iomux_routes = rk3328_mux_route_data,
3408 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
3409 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3410 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3411 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
3414 static struct rockchip_pin_bank rk3368_pin_banks[] = {
3415 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3420 PIN_BANK(1, 32, "gpio1"),
3421 PIN_BANK(2, 32, "gpio2"),
3422 PIN_BANK(3, 32, "gpio3"),
3425 static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3426 .pin_banks = rk3368_pin_banks,
3427 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3428 .label = "RK3368-GPIO",
3430 .grf_mux_offset = 0x0,
3431 .pmu_mux_offset = 0x0,
3432 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3433 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3436 static struct rockchip_pin_bank rk3399_pin_banks[] = {
3437 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3442 DRV_TYPE_IO_1V8_ONLY,
3443 DRV_TYPE_IO_1V8_ONLY,
3444 DRV_TYPE_IO_DEFAULT,
3445 DRV_TYPE_IO_DEFAULT,
3450 PULL_TYPE_IO_1V8_ONLY,
3451 PULL_TYPE_IO_1V8_ONLY,
3452 PULL_TYPE_IO_DEFAULT,
3453 PULL_TYPE_IO_DEFAULT
3455 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3459 DRV_TYPE_IO_1V8_OR_3V0,
3460 DRV_TYPE_IO_1V8_OR_3V0,
3461 DRV_TYPE_IO_1V8_OR_3V0,
3462 DRV_TYPE_IO_1V8_OR_3V0,
3468 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3469 DRV_TYPE_IO_1V8_OR_3V0,
3470 DRV_TYPE_IO_1V8_ONLY,
3471 DRV_TYPE_IO_1V8_ONLY,
3472 PULL_TYPE_IO_DEFAULT,
3473 PULL_TYPE_IO_DEFAULT,
3474 PULL_TYPE_IO_1V8_ONLY,
3475 PULL_TYPE_IO_1V8_ONLY
3477 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3478 DRV_TYPE_IO_3V3_ONLY,
3479 DRV_TYPE_IO_3V3_ONLY,
3480 DRV_TYPE_IO_1V8_OR_3V0
3482 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3483 DRV_TYPE_IO_1V8_3V0_AUTO,
3484 DRV_TYPE_IO_1V8_OR_3V0,
3485 DRV_TYPE_IO_1V8_OR_3V0
3489 static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3490 .pin_banks = rk3399_pin_banks,
3491 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3492 .label = "RK3399-GPIO",
3494 .grf_mux_offset = 0xe000,
3495 .pmu_mux_offset = 0x0,
3496 .grf_drv_offset = 0xe100,
3497 .pmu_drv_offset = 0x80,
3498 .iomux_routes = rk3399_mux_route_data,
3499 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
3500 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3501 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3504 static struct rockchip_pin_bank rk3568_pin_banks[] = {
3505 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3506 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3507 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT,
3508 IOMUX_SOURCE_PMU | IOMUX_WIDTH_4BIT),
3509 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3513 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3517 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3521 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3527 static struct rockchip_pin_ctrl rk3568_pin_ctrl = {
3528 .pin_banks = rk3568_pin_banks,
3529 .nr_banks = ARRAY_SIZE(rk3568_pin_banks),
3530 .label = "RK3568-GPIO",
3532 .grf_mux_offset = 0x0,
3533 .pmu_mux_offset = 0x0,
3534 .grf_drv_offset = 0x0200,
3535 .pmu_drv_offset = 0x0070,
3536 .iomux_routes = rk3568_mux_route_data,
3537 .niomux_routes = ARRAY_SIZE(rk3568_mux_route_data),
3538 .pull_calc_reg = rk3568_calc_pull_reg_and_bit,
3539 .drv_calc_reg = rk3568_calc_drv_reg_and_bit,
3540 .schmitt_calc_reg = rk3568_calc_schmitt_reg_and_bit,
3543 static struct rockchip_pin_bank rk3588_pin_banks[] = {
3544 RK3588_PIN_BANK_FLAGS(0, 32, "gpio0",
3545 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY),
3546 RK3588_PIN_BANK_FLAGS(1, 32, "gpio1",
3547 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY),
3548 RK3588_PIN_BANK_FLAGS(2, 32, "gpio2",
3549 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY),
3550 RK3588_PIN_BANK_FLAGS(3, 32, "gpio3",
3551 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY),
3552 RK3588_PIN_BANK_FLAGS(4, 32, "gpio4",
3553 IOMUX_WIDTH_4BIT, PULL_TYPE_IO_1V8_ONLY),
3556 static struct rockchip_pin_ctrl rk3588_pin_ctrl = {
3557 .pin_banks = rk3588_pin_banks,
3558 .nr_banks = ARRAY_SIZE(rk3588_pin_banks),
3559 .label = "RK3588-GPIO",
3561 .pull_calc_reg = rk3588_calc_pull_reg_and_bit,
3562 .drv_calc_reg = rk3588_calc_drv_reg_and_bit,
3563 .schmitt_calc_reg = rk3588_calc_schmitt_reg_and_bit,
3566 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
3567 { .compatible = "rockchip,px30-pinctrl",
3568 .data = &px30_pin_ctrl },
3569 { .compatible = "rockchip,rv1108-pinctrl",
3570 .data = &rv1108_pin_ctrl },
3571 { .compatible = "rockchip,rk2928-pinctrl",
3572 .data = &rk2928_pin_ctrl },
3573 { .compatible = "rockchip,rk3036-pinctrl",
3574 .data = &rk3036_pin_ctrl },
3575 { .compatible = "rockchip,rk3066a-pinctrl",
3576 .data = &rk3066a_pin_ctrl },
3577 { .compatible = "rockchip,rk3066b-pinctrl",
3578 .data = &rk3066b_pin_ctrl },
3579 { .compatible = "rockchip,rk3128-pinctrl",
3580 .data = (void *)&rk3128_pin_ctrl },
3581 { .compatible = "rockchip,rk3188-pinctrl",
3582 .data = &rk3188_pin_ctrl },
3583 { .compatible = "rockchip,rk3228-pinctrl",
3584 .data = &rk3228_pin_ctrl },
3585 { .compatible = "rockchip,rk3288-pinctrl",
3586 .data = &rk3288_pin_ctrl },
3587 { .compatible = "rockchip,rk3308-pinctrl",
3588 .data = &rk3308_pin_ctrl },
3589 { .compatible = "rockchip,rk3328-pinctrl",
3590 .data = &rk3328_pin_ctrl },
3591 { .compatible = "rockchip,rk3368-pinctrl",
3592 .data = &rk3368_pin_ctrl },
3593 { .compatible = "rockchip,rk3399-pinctrl",
3594 .data = &rk3399_pin_ctrl },
3595 { .compatible = "rockchip,rk3568-pinctrl",
3596 .data = &rk3568_pin_ctrl },
3597 { .compatible = "rockchip,rk3588-pinctrl",
3598 .data = &rk3588_pin_ctrl },
3602 static struct platform_driver rockchip_pinctrl_driver = {
3603 .probe = rockchip_pinctrl_probe,
3604 .remove = rockchip_pinctrl_remove,
3606 .name = "rockchip-pinctrl",
3607 .pm = &rockchip_pinctrl_dev_pm_ops,
3608 .of_match_table = rockchip_pinctrl_dt_match,
3612 static int __init rockchip_pinctrl_drv_register(void)
3614 return platform_driver_register(&rockchip_pinctrl_driver);
3616 postcore_initcall(rockchip_pinctrl_drv_register);
3618 static void __exit rockchip_pinctrl_drv_unregister(void)
3620 platform_driver_unregister(&rockchip_pinctrl_driver);
3622 module_exit(rockchip_pinctrl_drv_unregister);
3624 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver");
3625 MODULE_LICENSE("GPL");
3626 MODULE_ALIAS("platform:pinctrl-rockchip");
3627 MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match);