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>
25 #include <linux/of_platform.h>
26 #include <linux/pinctrl/machine.h>
27 #include <linux/pinctrl/pinconf.h>
28 #include <linux/pinctrl/pinctrl.h>
29 #include <linux/pinctrl/pinmux.h>
30 #include <linux/pinctrl/pinconf-generic.h>
31 #include <linux/irqchip/chained_irq.h>
32 #include <linux/clk.h>
33 #include <linux/regmap.h>
34 #include <linux/mfd/syscon.h>
35 #include <linux/string_helpers.h>
37 #include <dt-bindings/pinctrl/rockchip.h>
41 #include "pinctrl-rockchip.h"
44 * Generate a bitmask for setting a value (v) with a write mask bit in hiword
45 * register 31:16 area.
47 #define WRITE_MASK_VAL(h, l, v) \
48 (GENMASK(((h) + 16), ((l) + 16)) | (((v) << (l)) & GENMASK((h), (l))))
51 * Encode variants of iomux registers into a type variable
53 #define IOMUX_GPIO_ONLY BIT(0)
54 #define IOMUX_WIDTH_4BIT BIT(1)
55 #define IOMUX_SOURCE_PMU BIT(2)
56 #define IOMUX_UNROUTED BIT(3)
57 #define IOMUX_WIDTH_3BIT BIT(4)
58 #define IOMUX_WIDTH_2BIT BIT(5)
59 #define IOMUX_L_SOURCE_PMU BIT(6)
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_IOMUX_FLAGS_OFFSET_PULL_FLAGS(id, pins, label, iom0, \
90 offset2, offset3, pull0, \
91 pull1, pull2, pull3) \
97 { .type = iom0, .offset = offset0 }, \
98 { .type = iom1, .offset = offset1 }, \
99 { .type = iom2, .offset = offset2 }, \
100 { .type = iom3, .offset = offset3 }, \
102 .pull_type[0] = pull0, \
103 .pull_type[1] = pull1, \
104 .pull_type[2] = pull2, \
105 .pull_type[3] = pull3, \
108 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
120 { .drv_type = type0, .offset = -1 }, \
121 { .drv_type = type1, .offset = -1 }, \
122 { .drv_type = type2, .offset = -1 }, \
123 { .drv_type = type3, .offset = -1 }, \
127 #define PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(id, pins, label, iom0, iom1, \
128 iom2, iom3, pull0, pull1, \
135 { .type = iom0, .offset = -1 }, \
136 { .type = iom1, .offset = -1 }, \
137 { .type = iom2, .offset = -1 }, \
138 { .type = iom3, .offset = -1 }, \
140 .pull_type[0] = pull0, \
141 .pull_type[1] = pull1, \
142 .pull_type[2] = pull2, \
143 .pull_type[3] = pull3, \
146 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
147 drv2, drv3, pull0, pull1, \
160 { .drv_type = drv0, .offset = -1 }, \
161 { .drv_type = drv1, .offset = -1 }, \
162 { .drv_type = drv2, .offset = -1 }, \
163 { .drv_type = drv3, .offset = -1 }, \
165 .pull_type[0] = pull0, \
166 .pull_type[1] = pull1, \
167 .pull_type[2] = pull2, \
168 .pull_type[3] = pull3, \
171 #define PIN_BANK_IOMUX_FLAGS_OFFSET(id, pins, label, iom0, iom1, iom2, \
172 iom3, offset0, offset1, offset2, \
179 { .type = iom0, .offset = offset0 }, \
180 { .type = iom1, .offset = offset1 }, \
181 { .type = iom2, .offset = offset2 }, \
182 { .type = iom3, .offset = offset3 }, \
186 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
187 iom2, iom3, drv0, drv1, drv2, \
188 drv3, offset0, offset1, \
195 { .type = iom0, .offset = -1 }, \
196 { .type = iom1, .offset = -1 }, \
197 { .type = iom2, .offset = -1 }, \
198 { .type = iom3, .offset = -1 }, \
201 { .drv_type = drv0, .offset = offset0 }, \
202 { .drv_type = drv1, .offset = offset1 }, \
203 { .drv_type = drv2, .offset = offset2 }, \
204 { .drv_type = drv3, .offset = offset3 }, \
208 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
209 label, iom0, iom1, iom2, \
210 iom3, drv0, drv1, drv2, \
211 drv3, offset0, offset1, \
212 offset2, offset3, pull0, \
213 pull1, pull2, pull3) \
219 { .type = iom0, .offset = -1 }, \
220 { .type = iom1, .offset = -1 }, \
221 { .type = iom2, .offset = -1 }, \
222 { .type = iom3, .offset = -1 }, \
225 { .drv_type = drv0, .offset = offset0 }, \
226 { .drv_type = drv1, .offset = offset1 }, \
227 { .drv_type = drv2, .offset = offset2 }, \
228 { .drv_type = drv3, .offset = offset3 }, \
230 .pull_type[0] = pull0, \
231 .pull_type[1] = pull1, \
232 .pull_type[2] = pull2, \
233 .pull_type[3] = pull3, \
236 #define PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, FLAG) \
241 .route_offset = REG, \
243 .route_location = FLAG, \
246 #define RK_MUXROUTE_SAME(ID, PIN, FUNC, REG, VAL) \
247 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_SAME)
249 #define RK_MUXROUTE_GRF(ID, PIN, FUNC, REG, VAL) \
250 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_GRF)
252 #define RK_MUXROUTE_PMU(ID, PIN, FUNC, REG, VAL) \
253 PIN_BANK_MUX_ROUTE_FLAGS(ID, PIN, FUNC, REG, VAL, ROCKCHIP_ROUTE_PMU)
255 #define RK3588_PIN_BANK_FLAGS(ID, PIN, LABEL, M, P) \
256 PIN_BANK_IOMUX_FLAGS_PULL_FLAGS(ID, PIN, LABEL, M, M, M, M, P, P, P, P)
258 static struct regmap_config rockchip_regmap_config
= {
264 static inline const struct rockchip_pin_group
*pinctrl_name_to_group(
265 const struct rockchip_pinctrl
*info
,
270 for (i
= 0; i
< info
->ngroups
; i
++) {
271 if (!strcmp(info
->groups
[i
].name
, name
))
272 return &info
->groups
[i
];
279 * given a pin number that is local to a pin controller, find out the pin bank
280 * and the register base of the pin bank.
282 static struct rockchip_pin_bank
*pin_to_bank(struct rockchip_pinctrl
*info
,
285 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
287 while (pin
>= (b
->pin_base
+ b
->nr_pins
))
293 static struct rockchip_pin_bank
*bank_num_to_bank(
294 struct rockchip_pinctrl
*info
,
297 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
300 for (i
= 0; i
< info
->ctrl
->nr_banks
; i
++, b
++) {
301 if (b
->bank_num
== num
)
305 return ERR_PTR(-EINVAL
);
309 * Pinctrl_ops handling
312 static int rockchip_get_groups_count(struct pinctrl_dev
*pctldev
)
314 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
316 return info
->ngroups
;
319 static const char *rockchip_get_group_name(struct pinctrl_dev
*pctldev
,
322 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
324 return info
->groups
[selector
].name
;
327 static int rockchip_get_group_pins(struct pinctrl_dev
*pctldev
,
328 unsigned selector
, const unsigned **pins
,
331 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
333 if (selector
>= info
->ngroups
)
336 *pins
= info
->groups
[selector
].pins
;
337 *npins
= info
->groups
[selector
].npins
;
342 static int rockchip_dt_node_to_map(struct pinctrl_dev
*pctldev
,
343 struct device_node
*np
,
344 struct pinctrl_map
**map
, unsigned *num_maps
)
346 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
347 const struct rockchip_pin_group
*grp
;
348 struct device
*dev
= info
->dev
;
349 struct pinctrl_map
*new_map
;
350 struct device_node
*parent
;
355 * first find the group of this node and check if we need to create
356 * config maps for pins
358 grp
= pinctrl_name_to_group(info
, np
->name
);
360 dev_err(dev
, "unable to find group for node %pOFn\n", np
);
364 map_num
+= grp
->npins
;
366 new_map
= kcalloc(map_num
, sizeof(*new_map
), GFP_KERNEL
);
374 parent
= of_get_parent(np
);
379 new_map
[0].type
= PIN_MAP_TYPE_MUX_GROUP
;
380 new_map
[0].data
.mux
.function
= parent
->name
;
381 new_map
[0].data
.mux
.group
= np
->name
;
384 /* create config map */
386 for (i
= 0; i
< grp
->npins
; i
++) {
387 new_map
[i
].type
= PIN_MAP_TYPE_CONFIGS_PIN
;
388 new_map
[i
].data
.configs
.group_or_pin
=
389 pin_get_name(pctldev
, grp
->pins
[i
]);
390 new_map
[i
].data
.configs
.configs
= grp
->data
[i
].configs
;
391 new_map
[i
].data
.configs
.num_configs
= grp
->data
[i
].nconfigs
;
394 dev_dbg(dev
, "maps: function %s group %s num %d\n",
395 (*map
)->data
.mux
.function
, (*map
)->data
.mux
.group
, map_num
);
400 static void rockchip_dt_free_map(struct pinctrl_dev
*pctldev
,
401 struct pinctrl_map
*map
, unsigned num_maps
)
406 static const struct pinctrl_ops rockchip_pctrl_ops
= {
407 .get_groups_count
= rockchip_get_groups_count
,
408 .get_group_name
= rockchip_get_group_name
,
409 .get_group_pins
= rockchip_get_group_pins
,
410 .dt_node_to_map
= rockchip_dt_node_to_map
,
411 .dt_free_map
= rockchip_dt_free_map
,
418 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data
[] = {
482 static struct rockchip_mux_recalced_data rv1126_mux_recalced_data
[] = {
513 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data
[] = {
547 static struct rockchip_mux_recalced_data rk3308_mux_recalced_data
[] = {
656 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data
[] = {
723 static void rockchip_get_recalced_mux(struct rockchip_pin_bank
*bank
, int pin
,
724 int *reg
, u8
*bit
, int *mask
)
726 struct rockchip_pinctrl
*info
= bank
->drvdata
;
727 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
728 struct rockchip_mux_recalced_data
*data
;
731 for (i
= 0; i
< ctrl
->niomux_recalced
; i
++) {
732 data
= &ctrl
->iomux_recalced
[i
];
733 if (data
->num
== bank
->bank_num
&&
738 if (i
>= ctrl
->niomux_recalced
)
746 static struct rockchip_mux_route_data px30_mux_route_data
[] = {
747 RK_MUXROUTE_SAME(2, RK_PB4
, 1, 0x184, BIT(16 + 7)), /* cif-d0m0 */
748 RK_MUXROUTE_SAME(3, RK_PA1
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d0m1 */
749 RK_MUXROUTE_SAME(2, RK_PB6
, 1, 0x184, BIT(16 + 7)), /* cif-d1m0 */
750 RK_MUXROUTE_SAME(3, RK_PA2
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d1m1 */
751 RK_MUXROUTE_SAME(2, RK_PA0
, 1, 0x184, BIT(16 + 7)), /* cif-d2m0 */
752 RK_MUXROUTE_SAME(3, RK_PA3
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d2m1 */
753 RK_MUXROUTE_SAME(2, RK_PA1
, 1, 0x184, BIT(16 + 7)), /* cif-d3m0 */
754 RK_MUXROUTE_SAME(3, RK_PA5
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d3m1 */
755 RK_MUXROUTE_SAME(2, RK_PA2
, 1, 0x184, BIT(16 + 7)), /* cif-d4m0 */
756 RK_MUXROUTE_SAME(3, RK_PA7
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d4m1 */
757 RK_MUXROUTE_SAME(2, RK_PA3
, 1, 0x184, BIT(16 + 7)), /* cif-d5m0 */
758 RK_MUXROUTE_SAME(3, RK_PB0
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d5m1 */
759 RK_MUXROUTE_SAME(2, RK_PA4
, 1, 0x184, BIT(16 + 7)), /* cif-d6m0 */
760 RK_MUXROUTE_SAME(3, RK_PB1
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d6m1 */
761 RK_MUXROUTE_SAME(2, RK_PA5
, 1, 0x184, BIT(16 + 7)), /* cif-d7m0 */
762 RK_MUXROUTE_SAME(3, RK_PB4
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d7m1 */
763 RK_MUXROUTE_SAME(2, RK_PA6
, 1, 0x184, BIT(16 + 7)), /* cif-d8m0 */
764 RK_MUXROUTE_SAME(3, RK_PB6
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d8m1 */
765 RK_MUXROUTE_SAME(2, RK_PA7
, 1, 0x184, BIT(16 + 7)), /* cif-d9m0 */
766 RK_MUXROUTE_SAME(3, RK_PB7
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d9m1 */
767 RK_MUXROUTE_SAME(2, RK_PB7
, 1, 0x184, BIT(16 + 7)), /* cif-d10m0 */
768 RK_MUXROUTE_SAME(3, RK_PC6
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d10m1 */
769 RK_MUXROUTE_SAME(2, RK_PC0
, 1, 0x184, BIT(16 + 7)), /* cif-d11m0 */
770 RK_MUXROUTE_SAME(3, RK_PC7
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-d11m1 */
771 RK_MUXROUTE_SAME(2, RK_PB0
, 1, 0x184, BIT(16 + 7)), /* cif-vsyncm0 */
772 RK_MUXROUTE_SAME(3, RK_PD1
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-vsyncm1 */
773 RK_MUXROUTE_SAME(2, RK_PB1
, 1, 0x184, BIT(16 + 7)), /* cif-hrefm0 */
774 RK_MUXROUTE_SAME(3, RK_PD2
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-hrefm1 */
775 RK_MUXROUTE_SAME(2, RK_PB2
, 1, 0x184, BIT(16 + 7)), /* cif-clkinm0 */
776 RK_MUXROUTE_SAME(3, RK_PD3
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-clkinm1 */
777 RK_MUXROUTE_SAME(2, RK_PB3
, 1, 0x184, BIT(16 + 7)), /* cif-clkoutm0 */
778 RK_MUXROUTE_SAME(3, RK_PD0
, 3, 0x184, BIT(16 + 7) | BIT(7)), /* cif-clkoutm1 */
779 RK_MUXROUTE_SAME(3, RK_PC6
, 2, 0x184, BIT(16 + 8)), /* pdm-m0 */
780 RK_MUXROUTE_SAME(2, RK_PC6
, 1, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-m1 */
781 RK_MUXROUTE_SAME(3, RK_PD3
, 2, 0x184, BIT(16 + 8)), /* pdm-sdi0m0 */
782 RK_MUXROUTE_SAME(2, RK_PC5
, 2, 0x184, BIT(16 + 8) | BIT(8)), /* pdm-sdi0m1 */
783 RK_MUXROUTE_SAME(1, RK_PD3
, 2, 0x184, BIT(16 + 10)), /* uart2-rxm0 */
784 RK_MUXROUTE_SAME(2, RK_PB6
, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-rxm1 */
785 RK_MUXROUTE_SAME(1, RK_PD2
, 2, 0x184, BIT(16 + 10)), /* uart2-txm0 */
786 RK_MUXROUTE_SAME(2, RK_PB4
, 2, 0x184, BIT(16 + 10) | BIT(10)), /* uart2-txm1 */
787 RK_MUXROUTE_SAME(0, RK_PC1
, 2, 0x184, BIT(16 + 9)), /* uart3-rxm0 */
788 RK_MUXROUTE_SAME(1, RK_PB7
, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rxm1 */
789 RK_MUXROUTE_SAME(0, RK_PC0
, 2, 0x184, BIT(16 + 9)), /* uart3-txm0 */
790 RK_MUXROUTE_SAME(1, RK_PB6
, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-txm1 */
791 RK_MUXROUTE_SAME(0, RK_PC2
, 2, 0x184, BIT(16 + 9)), /* uart3-ctsm0 */
792 RK_MUXROUTE_SAME(1, RK_PB4
, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-ctsm1 */
793 RK_MUXROUTE_SAME(0, RK_PC3
, 2, 0x184, BIT(16 + 9)), /* uart3-rtsm0 */
794 RK_MUXROUTE_SAME(1, RK_PB5
, 2, 0x184, BIT(16 + 9) | BIT(9)), /* uart3-rtsm1 */
797 static struct rockchip_mux_route_data rv1126_mux_route_data
[] = {
798 RK_MUXROUTE_GRF(3, RK_PD2
, 1, 0x10260, WRITE_MASK_VAL(0, 0, 0)), /* I2S0_MCLK_M0 */
799 RK_MUXROUTE_GRF(3, RK_PB0
, 3, 0x10260, WRITE_MASK_VAL(0, 0, 1)), /* I2S0_MCLK_M1 */
801 RK_MUXROUTE_GRF(0, RK_PD4
, 4, 0x10260, WRITE_MASK_VAL(3, 2, 0)), /* I2S1_MCLK_M0 */
802 RK_MUXROUTE_GRF(1, RK_PD5
, 2, 0x10260, WRITE_MASK_VAL(3, 2, 1)), /* I2S1_MCLK_M1 */
803 RK_MUXROUTE_GRF(2, RK_PC7
, 6, 0x10260, WRITE_MASK_VAL(3, 2, 2)), /* I2S1_MCLK_M2 */
805 RK_MUXROUTE_GRF(1, RK_PD0
, 1, 0x10260, WRITE_MASK_VAL(4, 4, 0)), /* I2S2_MCLK_M0 */
806 RK_MUXROUTE_GRF(2, RK_PB3
, 2, 0x10260, WRITE_MASK_VAL(4, 4, 1)), /* I2S2_MCLK_M1 */
808 RK_MUXROUTE_GRF(3, RK_PD4
, 2, 0x10260, WRITE_MASK_VAL(12, 12, 0)), /* PDM_CLK0_M0 */
809 RK_MUXROUTE_GRF(3, RK_PC0
, 3, 0x10260, WRITE_MASK_VAL(12, 12, 1)), /* PDM_CLK0_M1 */
811 RK_MUXROUTE_GRF(3, RK_PC6
, 1, 0x10264, WRITE_MASK_VAL(0, 0, 0)), /* CIF_CLKOUT_M0 */
812 RK_MUXROUTE_GRF(2, RK_PD1
, 3, 0x10264, WRITE_MASK_VAL(0, 0, 1)), /* CIF_CLKOUT_M1 */
814 RK_MUXROUTE_GRF(3, RK_PA4
, 5, 0x10264, WRITE_MASK_VAL(5, 4, 0)), /* I2C3_SCL_M0 */
815 RK_MUXROUTE_GRF(2, RK_PD4
, 7, 0x10264, WRITE_MASK_VAL(5, 4, 1)), /* I2C3_SCL_M1 */
816 RK_MUXROUTE_GRF(1, RK_PD6
, 3, 0x10264, WRITE_MASK_VAL(5, 4, 2)), /* I2C3_SCL_M2 */
818 RK_MUXROUTE_GRF(3, RK_PA0
, 7, 0x10264, WRITE_MASK_VAL(6, 6, 0)), /* I2C4_SCL_M0 */
819 RK_MUXROUTE_GRF(4, RK_PA0
, 4, 0x10264, WRITE_MASK_VAL(6, 6, 1)), /* I2C4_SCL_M1 */
821 RK_MUXROUTE_GRF(2, RK_PA5
, 7, 0x10264, WRITE_MASK_VAL(9, 8, 0)), /* I2C5_SCL_M0 */
822 RK_MUXROUTE_GRF(3, RK_PB0
, 5, 0x10264, WRITE_MASK_VAL(9, 8, 1)), /* I2C5_SCL_M1 */
823 RK_MUXROUTE_GRF(1, RK_PD0
, 4, 0x10264, WRITE_MASK_VAL(9, 8, 2)), /* I2C5_SCL_M2 */
825 RK_MUXROUTE_GRF(3, RK_PC0
, 5, 0x10264, WRITE_MASK_VAL(11, 10, 0)), /* SPI1_CLK_M0 */
826 RK_MUXROUTE_GRF(1, RK_PC6
, 3, 0x10264, WRITE_MASK_VAL(11, 10, 1)), /* SPI1_CLK_M1 */
827 RK_MUXROUTE_GRF(2, RK_PD5
, 6, 0x10264, WRITE_MASK_VAL(11, 10, 2)), /* SPI1_CLK_M2 */
829 RK_MUXROUTE_GRF(3, RK_PC0
, 2, 0x10264, WRITE_MASK_VAL(12, 12, 0)), /* RGMII_CLK_M0 */
830 RK_MUXROUTE_GRF(2, RK_PB7
, 2, 0x10264, WRITE_MASK_VAL(12, 12, 1)), /* RGMII_CLK_M1 */
832 RK_MUXROUTE_GRF(3, RK_PA1
, 3, 0x10264, WRITE_MASK_VAL(13, 13, 0)), /* CAN_TXD_M0 */
833 RK_MUXROUTE_GRF(3, RK_PA7
, 5, 0x10264, WRITE_MASK_VAL(13, 13, 1)), /* CAN_TXD_M1 */
835 RK_MUXROUTE_GRF(3, RK_PA4
, 6, 0x10268, WRITE_MASK_VAL(0, 0, 0)), /* PWM8_M0 */
836 RK_MUXROUTE_GRF(2, RK_PD7
, 5, 0x10268, WRITE_MASK_VAL(0, 0, 1)), /* PWM8_M1 */
838 RK_MUXROUTE_GRF(3, RK_PA5
, 6, 0x10268, WRITE_MASK_VAL(2, 2, 0)), /* PWM9_M0 */
839 RK_MUXROUTE_GRF(2, RK_PD6
, 5, 0x10268, WRITE_MASK_VAL(2, 2, 1)), /* PWM9_M1 */
841 RK_MUXROUTE_GRF(3, RK_PA6
, 6, 0x10268, WRITE_MASK_VAL(4, 4, 0)), /* PWM10_M0 */
842 RK_MUXROUTE_GRF(2, RK_PD5
, 5, 0x10268, WRITE_MASK_VAL(4, 4, 1)), /* PWM10_M1 */
844 RK_MUXROUTE_GRF(3, RK_PA7
, 6, 0x10268, WRITE_MASK_VAL(6, 6, 0)), /* PWM11_IR_M0 */
845 RK_MUXROUTE_GRF(3, RK_PA1
, 5, 0x10268, WRITE_MASK_VAL(6, 6, 1)), /* PWM11_IR_M1 */
847 RK_MUXROUTE_GRF(1, RK_PA5
, 3, 0x10268, WRITE_MASK_VAL(8, 8, 0)), /* UART2_TX_M0 */
848 RK_MUXROUTE_GRF(3, RK_PA2
, 1, 0x10268, WRITE_MASK_VAL(8, 8, 1)), /* UART2_TX_M1 */
850 RK_MUXROUTE_GRF(3, RK_PC6
, 3, 0x10268, WRITE_MASK_VAL(11, 10, 0)), /* UART3_TX_M0 */
851 RK_MUXROUTE_GRF(1, RK_PA7
, 2, 0x10268, WRITE_MASK_VAL(11, 10, 1)), /* UART3_TX_M1 */
852 RK_MUXROUTE_GRF(3, RK_PA0
, 4, 0x10268, WRITE_MASK_VAL(11, 10, 2)), /* UART3_TX_M2 */
854 RK_MUXROUTE_GRF(3, RK_PA4
, 4, 0x10268, WRITE_MASK_VAL(13, 12, 0)), /* UART4_TX_M0 */
855 RK_MUXROUTE_GRF(2, RK_PA6
, 4, 0x10268, WRITE_MASK_VAL(13, 12, 1)), /* UART4_TX_M1 */
856 RK_MUXROUTE_GRF(1, RK_PD5
, 3, 0x10268, WRITE_MASK_VAL(13, 12, 2)), /* UART4_TX_M2 */
858 RK_MUXROUTE_GRF(3, RK_PA6
, 4, 0x10268, WRITE_MASK_VAL(15, 14, 0)), /* UART5_TX_M0 */
859 RK_MUXROUTE_GRF(2, RK_PB0
, 4, 0x10268, WRITE_MASK_VAL(15, 14, 1)), /* UART5_TX_M1 */
860 RK_MUXROUTE_GRF(2, RK_PA0
, 3, 0x10268, WRITE_MASK_VAL(15, 14, 2)), /* UART5_TX_M2 */
862 RK_MUXROUTE_PMU(0, RK_PB6
, 3, 0x0114, WRITE_MASK_VAL(0, 0, 0)), /* PWM0_M0 */
863 RK_MUXROUTE_PMU(2, RK_PB3
, 5, 0x0114, WRITE_MASK_VAL(0, 0, 1)), /* PWM0_M1 */
865 RK_MUXROUTE_PMU(0, RK_PB7
, 3, 0x0114, WRITE_MASK_VAL(2, 2, 0)), /* PWM1_M0 */
866 RK_MUXROUTE_PMU(2, RK_PB2
, 5, 0x0114, WRITE_MASK_VAL(2, 2, 1)), /* PWM1_M1 */
868 RK_MUXROUTE_PMU(0, RK_PC0
, 3, 0x0114, WRITE_MASK_VAL(4, 4, 0)), /* PWM2_M0 */
869 RK_MUXROUTE_PMU(2, RK_PB1
, 5, 0x0114, WRITE_MASK_VAL(4, 4, 1)), /* PWM2_M1 */
871 RK_MUXROUTE_PMU(0, RK_PC1
, 3, 0x0114, WRITE_MASK_VAL(6, 6, 0)), /* PWM3_IR_M0 */
872 RK_MUXROUTE_PMU(2, RK_PB0
, 5, 0x0114, WRITE_MASK_VAL(6, 6, 1)), /* PWM3_IR_M1 */
874 RK_MUXROUTE_PMU(0, RK_PC2
, 3, 0x0114, WRITE_MASK_VAL(8, 8, 0)), /* PWM4_M0 */
875 RK_MUXROUTE_PMU(2, RK_PA7
, 5, 0x0114, WRITE_MASK_VAL(8, 8, 1)), /* PWM4_M1 */
877 RK_MUXROUTE_PMU(0, RK_PC3
, 3, 0x0114, WRITE_MASK_VAL(10, 10, 0)), /* PWM5_M0 */
878 RK_MUXROUTE_PMU(2, RK_PA6
, 5, 0x0114, WRITE_MASK_VAL(10, 10, 1)), /* PWM5_M1 */
880 RK_MUXROUTE_PMU(0, RK_PB2
, 3, 0x0114, WRITE_MASK_VAL(12, 12, 0)), /* PWM6_M0 */
881 RK_MUXROUTE_PMU(2, RK_PD4
, 5, 0x0114, WRITE_MASK_VAL(12, 12, 1)), /* PWM6_M1 */
883 RK_MUXROUTE_PMU(0, RK_PB1
, 3, 0x0114, WRITE_MASK_VAL(14, 14, 0)), /* PWM7_IR_M0 */
884 RK_MUXROUTE_PMU(3, RK_PA0
, 5, 0x0114, WRITE_MASK_VAL(14, 14, 1)), /* PWM7_IR_M1 */
886 RK_MUXROUTE_PMU(0, RK_PB0
, 1, 0x0118, WRITE_MASK_VAL(1, 0, 0)), /* SPI0_CLK_M0 */
887 RK_MUXROUTE_PMU(2, RK_PA1
, 1, 0x0118, WRITE_MASK_VAL(1, 0, 1)), /* SPI0_CLK_M1 */
888 RK_MUXROUTE_PMU(2, RK_PB2
, 6, 0x0118, WRITE_MASK_VAL(1, 0, 2)), /* SPI0_CLK_M2 */
890 RK_MUXROUTE_PMU(0, RK_PB6
, 2, 0x0118, WRITE_MASK_VAL(2, 2, 0)), /* UART1_TX_M0 */
891 RK_MUXROUTE_PMU(1, RK_PD0
, 5, 0x0118, WRITE_MASK_VAL(2, 2, 1)), /* UART1_TX_M1 */
894 static struct rockchip_mux_route_data rk3128_mux_route_data
[] = {
895 RK_MUXROUTE_SAME(1, RK_PB2
, 1, 0x144, BIT(16 + 3) | BIT(16 + 4)), /* spi-0 */
896 RK_MUXROUTE_SAME(1, RK_PD3
, 3, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(3)), /* spi-1 */
897 RK_MUXROUTE_SAME(0, RK_PB5
, 2, 0x144, BIT(16 + 3) | BIT(16 + 4) | BIT(4)), /* spi-2 */
898 RK_MUXROUTE_SAME(1, RK_PA5
, 1, 0x144, BIT(16 + 5)), /* i2s-0 */
899 RK_MUXROUTE_SAME(0, RK_PB6
, 1, 0x144, BIT(16 + 5) | BIT(5)), /* i2s-1 */
900 RK_MUXROUTE_SAME(1, RK_PC6
, 2, 0x144, BIT(16 + 6)), /* emmc-0 */
901 RK_MUXROUTE_SAME(2, RK_PA4
, 2, 0x144, BIT(16 + 6) | BIT(6)), /* emmc-1 */
904 static struct rockchip_mux_route_data rk3188_mux_route_data
[] = {
905 RK_MUXROUTE_SAME(0, RK_PD0
, 1, 0xa0, BIT(16 + 11)), /* non-iomuxed emmc/flash pins on flash-dqs */
906 RK_MUXROUTE_SAME(0, RK_PD0
, 2, 0xa0, BIT(16 + 11) | BIT(11)), /* non-iomuxed emmc/flash pins on emmc-clk */
909 static struct rockchip_mux_route_data rk3228_mux_route_data
[] = {
910 RK_MUXROUTE_SAME(0, RK_PD2
, 1, 0x50, BIT(16)), /* pwm0-0 */
911 RK_MUXROUTE_SAME(3, RK_PC5
, 1, 0x50, BIT(16) | BIT(0)), /* pwm0-1 */
912 RK_MUXROUTE_SAME(0, RK_PD3
, 1, 0x50, BIT(16 + 1)), /* pwm1-0 */
913 RK_MUXROUTE_SAME(0, RK_PD6
, 2, 0x50, BIT(16 + 1) | BIT(1)), /* pwm1-1 */
914 RK_MUXROUTE_SAME(0, RK_PD4
, 1, 0x50, BIT(16 + 2)), /* pwm2-0 */
915 RK_MUXROUTE_SAME(1, RK_PB4
, 2, 0x50, BIT(16 + 2) | BIT(2)), /* pwm2-1 */
916 RK_MUXROUTE_SAME(3, RK_PD2
, 1, 0x50, BIT(16 + 3)), /* pwm3-0 */
917 RK_MUXROUTE_SAME(1, RK_PB3
, 2, 0x50, BIT(16 + 3) | BIT(3)), /* pwm3-1 */
918 RK_MUXROUTE_SAME(1, RK_PA1
, 1, 0x50, BIT(16 + 4)), /* sdio-0_d0 */
919 RK_MUXROUTE_SAME(3, RK_PA2
, 1, 0x50, BIT(16 + 4) | BIT(4)), /* sdio-1_d0 */
920 RK_MUXROUTE_SAME(0, RK_PB5
, 2, 0x50, BIT(16 + 5)), /* spi-0_rx */
921 RK_MUXROUTE_SAME(2, RK_PA0
, 2, 0x50, BIT(16 + 5) | BIT(5)), /* spi-1_rx */
922 RK_MUXROUTE_SAME(1, RK_PC6
, 2, 0x50, BIT(16 + 7)), /* emmc-0_cmd */
923 RK_MUXROUTE_SAME(2, RK_PA4
, 2, 0x50, BIT(16 + 7) | BIT(7)), /* emmc-1_cmd */
924 RK_MUXROUTE_SAME(1, RK_PC3
, 2, 0x50, BIT(16 + 8)), /* uart2-0_rx */
925 RK_MUXROUTE_SAME(1, RK_PB2
, 2, 0x50, BIT(16 + 8) | BIT(8)), /* uart2-1_rx */
926 RK_MUXROUTE_SAME(1, RK_PB2
, 1, 0x50, BIT(16 + 11)), /* uart1-0_rx */
927 RK_MUXROUTE_SAME(3, RK_PB5
, 1, 0x50, BIT(16 + 11) | BIT(11)), /* uart1-1_rx */
930 static struct rockchip_mux_route_data rk3288_mux_route_data
[] = {
931 RK_MUXROUTE_SAME(7, RK_PC0
, 2, 0x264, BIT(16 + 12) | BIT(12)), /* edphdmi_cecinoutt1 */
932 RK_MUXROUTE_SAME(7, RK_PC7
, 4, 0x264, BIT(16 + 12)), /* edphdmi_cecinout */
935 static struct rockchip_mux_route_data rk3308_mux_route_data
[] = {
936 RK_MUXROUTE_SAME(0, RK_PC3
, 1, 0x314, BIT(16 + 0) | BIT(0)), /* rtc_clk */
937 RK_MUXROUTE_SAME(1, RK_PC6
, 2, 0x314, BIT(16 + 2) | BIT(16 + 3)), /* uart2_rxm0 */
938 RK_MUXROUTE_SAME(4, RK_PD2
, 2, 0x314, BIT(16 + 2) | BIT(16 + 3) | BIT(2)), /* uart2_rxm1 */
939 RK_MUXROUTE_SAME(0, RK_PB7
, 2, 0x314, BIT(16 + 4)), /* i2c3_sdam0 */
940 RK_MUXROUTE_SAME(3, RK_PB4
, 2, 0x314, BIT(16 + 4) | BIT(4)), /* i2c3_sdam1 */
941 RK_MUXROUTE_SAME(1, RK_PA3
, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclktxm0 */
942 RK_MUXROUTE_SAME(1, RK_PA4
, 2, 0x308, BIT(16 + 3)), /* i2s-8ch-1-sclkrxm0 */
943 RK_MUXROUTE_SAME(1, RK_PB5
, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclktxm1 */
944 RK_MUXROUTE_SAME(1, RK_PB6
, 2, 0x308, BIT(16 + 3) | BIT(3)), /* i2s-8ch-1-sclkrxm1 */
945 RK_MUXROUTE_SAME(1, RK_PA4
, 3, 0x308, BIT(16 + 12) | BIT(16 + 13)), /* pdm-clkm0 */
946 RK_MUXROUTE_SAME(1, RK_PB6
, 4, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(12)), /* pdm-clkm1 */
947 RK_MUXROUTE_SAME(2, RK_PA6
, 2, 0x308, BIT(16 + 12) | BIT(16 + 13) | BIT(13)), /* pdm-clkm2 */
948 RK_MUXROUTE_SAME(2, RK_PA4
, 3, 0x600, BIT(16 + 2) | BIT(2)), /* pdm-clkm-m2 */
951 static struct rockchip_mux_route_data rk3328_mux_route_data
[] = {
952 RK_MUXROUTE_SAME(1, RK_PA1
, 2, 0x50, BIT(16) | BIT(16 + 1)), /* uart2dbg_rxm0 */
953 RK_MUXROUTE_SAME(2, RK_PA1
, 1, 0x50, BIT(16) | BIT(16 + 1) | BIT(0)), /* uart2dbg_rxm1 */
954 RK_MUXROUTE_SAME(1, RK_PB3
, 2, 0x50, BIT(16 + 2) | BIT(2)), /* gmac-m1_rxd0 */
955 RK_MUXROUTE_SAME(1, RK_PB6
, 2, 0x50, BIT(16 + 10) | BIT(10)), /* gmac-m1-optimized_rxd3 */
956 RK_MUXROUTE_SAME(2, RK_PC3
, 2, 0x50, BIT(16 + 3)), /* pdm_sdi0m0 */
957 RK_MUXROUTE_SAME(1, RK_PC7
, 3, 0x50, BIT(16 + 3) | BIT(3)), /* pdm_sdi0m1 */
958 RK_MUXROUTE_SAME(3, RK_PA2
, 4, 0x50, BIT(16 + 4) | BIT(16 + 5) | BIT(5)), /* spi_rxdm2 */
959 RK_MUXROUTE_SAME(1, RK_PD0
, 1, 0x50, BIT(16 + 6)), /* i2s2_sdim0 */
960 RK_MUXROUTE_SAME(3, RK_PA2
, 6, 0x50, BIT(16 + 6) | BIT(6)), /* i2s2_sdim1 */
961 RK_MUXROUTE_SAME(2, RK_PC6
, 3, 0x50, BIT(16 + 7) | BIT(7)), /* card_iom1 */
962 RK_MUXROUTE_SAME(2, RK_PC0
, 3, 0x50, BIT(16 + 8) | BIT(8)), /* tsp_d5m1 */
963 RK_MUXROUTE_SAME(2, RK_PC0
, 4, 0x50, BIT(16 + 9) | BIT(9)), /* cif_data5m1 */
966 static struct rockchip_mux_route_data rk3399_mux_route_data
[] = {
967 RK_MUXROUTE_SAME(4, RK_PB0
, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11)), /* uart2dbga_rx */
968 RK_MUXROUTE_SAME(4, RK_PC0
, 2, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(10)), /* uart2dbgb_rx */
969 RK_MUXROUTE_SAME(4, RK_PC3
, 1, 0xe21c, BIT(16 + 10) | BIT(16 + 11) | BIT(11)), /* uart2dbgc_rx */
970 RK_MUXROUTE_SAME(2, RK_PD2
, 2, 0xe21c, BIT(16 + 14)), /* pcie_clkreqn */
971 RK_MUXROUTE_SAME(4, RK_PD0
, 1, 0xe21c, BIT(16 + 14) | BIT(14)), /* pcie_clkreqnb */
974 static struct rockchip_mux_route_data rk3568_mux_route_data
[] = {
975 RK_MUXROUTE_PMU(0, RK_PB7
, 1, 0x0110, WRITE_MASK_VAL(1, 0, 0)), /* PWM0 IO mux M0 */
976 RK_MUXROUTE_PMU(0, RK_PC7
, 2, 0x0110, WRITE_MASK_VAL(1, 0, 1)), /* PWM0 IO mux M1 */
977 RK_MUXROUTE_PMU(0, RK_PC0
, 1, 0x0110, WRITE_MASK_VAL(3, 2, 0)), /* PWM1 IO mux M0 */
978 RK_MUXROUTE_PMU(0, RK_PB5
, 4, 0x0110, WRITE_MASK_VAL(3, 2, 1)), /* PWM1 IO mux M1 */
979 RK_MUXROUTE_PMU(0, RK_PC1
, 1, 0x0110, WRITE_MASK_VAL(5, 4, 0)), /* PWM2 IO mux M0 */
980 RK_MUXROUTE_PMU(0, RK_PB6
, 4, 0x0110, WRITE_MASK_VAL(5, 4, 1)), /* PWM2 IO mux M1 */
981 RK_MUXROUTE_GRF(0, RK_PB3
, 2, 0x0300, WRITE_MASK_VAL(0, 0, 0)), /* CAN0 IO mux M0 */
982 RK_MUXROUTE_GRF(2, RK_PA1
, 4, 0x0300, WRITE_MASK_VAL(0, 0, 1)), /* CAN0 IO mux M1 */
983 RK_MUXROUTE_GRF(1, RK_PA1
, 3, 0x0300, WRITE_MASK_VAL(2, 2, 0)), /* CAN1 IO mux M0 */
984 RK_MUXROUTE_GRF(4, RK_PC3
, 3, 0x0300, WRITE_MASK_VAL(2, 2, 1)), /* CAN1 IO mux M1 */
985 RK_MUXROUTE_GRF(4, RK_PB5
, 3, 0x0300, WRITE_MASK_VAL(4, 4, 0)), /* CAN2 IO mux M0 */
986 RK_MUXROUTE_GRF(2, RK_PB2
, 4, 0x0300, WRITE_MASK_VAL(4, 4, 1)), /* CAN2 IO mux M1 */
987 RK_MUXROUTE_GRF(4, RK_PC4
, 1, 0x0300, WRITE_MASK_VAL(6, 6, 0)), /* HPDIN IO mux M0 */
988 RK_MUXROUTE_GRF(0, RK_PC2
, 2, 0x0300, WRITE_MASK_VAL(6, 6, 1)), /* HPDIN IO mux M1 */
989 RK_MUXROUTE_GRF(3, RK_PB1
, 3, 0x0300, WRITE_MASK_VAL(8, 8, 0)), /* GMAC1 IO mux M0 */
990 RK_MUXROUTE_GRF(4, RK_PA7
, 3, 0x0300, WRITE_MASK_VAL(8, 8, 1)), /* GMAC1 IO mux M1 */
991 RK_MUXROUTE_GRF(4, RK_PD1
, 1, 0x0300, WRITE_MASK_VAL(10, 10, 0)), /* HDMITX IO mux M0 */
992 RK_MUXROUTE_GRF(0, RK_PC7
, 1, 0x0300, WRITE_MASK_VAL(10, 10, 1)), /* HDMITX IO mux M1 */
993 RK_MUXROUTE_GRF(0, RK_PB6
, 1, 0x0300, WRITE_MASK_VAL(14, 14, 0)), /* I2C2 IO mux M0 */
994 RK_MUXROUTE_GRF(4, RK_PB4
, 1, 0x0300, WRITE_MASK_VAL(14, 14, 1)), /* I2C2 IO mux M1 */
995 RK_MUXROUTE_GRF(1, RK_PA0
, 1, 0x0304, WRITE_MASK_VAL(0, 0, 0)), /* I2C3 IO mux M0 */
996 RK_MUXROUTE_GRF(3, RK_PB6
, 4, 0x0304, WRITE_MASK_VAL(0, 0, 1)), /* I2C3 IO mux M1 */
997 RK_MUXROUTE_GRF(4, RK_PB2
, 1, 0x0304, WRITE_MASK_VAL(2, 2, 0)), /* I2C4 IO mux M0 */
998 RK_MUXROUTE_GRF(2, RK_PB1
, 2, 0x0304, WRITE_MASK_VAL(2, 2, 1)), /* I2C4 IO mux M1 */
999 RK_MUXROUTE_GRF(3, RK_PB4
, 4, 0x0304, WRITE_MASK_VAL(4, 4, 0)), /* I2C5 IO mux M0 */
1000 RK_MUXROUTE_GRF(4, RK_PD0
, 2, 0x0304, WRITE_MASK_VAL(4, 4, 1)), /* I2C5 IO mux M1 */
1001 RK_MUXROUTE_GRF(3, RK_PB1
, 5, 0x0304, WRITE_MASK_VAL(14, 14, 0)), /* PWM8 IO mux M0 */
1002 RK_MUXROUTE_GRF(1, RK_PD5
, 4, 0x0304, WRITE_MASK_VAL(14, 14, 1)), /* PWM8 IO mux M1 */
1003 RK_MUXROUTE_GRF(3, RK_PB2
, 5, 0x0308, WRITE_MASK_VAL(0, 0, 0)), /* PWM9 IO mux M0 */
1004 RK_MUXROUTE_GRF(1, RK_PD6
, 4, 0x0308, WRITE_MASK_VAL(0, 0, 1)), /* PWM9 IO mux M1 */
1005 RK_MUXROUTE_GRF(3, RK_PB5
, 5, 0x0308, WRITE_MASK_VAL(2, 2, 0)), /* PWM10 IO mux M0 */
1006 RK_MUXROUTE_GRF(2, RK_PA1
, 2, 0x0308, WRITE_MASK_VAL(2, 2, 1)), /* PWM10 IO mux M1 */
1007 RK_MUXROUTE_GRF(3, RK_PB6
, 5, 0x0308, WRITE_MASK_VAL(4, 4, 0)), /* PWM11 IO mux M0 */
1008 RK_MUXROUTE_GRF(4, RK_PC0
, 3, 0x0308, WRITE_MASK_VAL(4, 4, 1)), /* PWM11 IO mux M1 */
1009 RK_MUXROUTE_GRF(3, RK_PB7
, 2, 0x0308, WRITE_MASK_VAL(6, 6, 0)), /* PWM12 IO mux M0 */
1010 RK_MUXROUTE_GRF(4, RK_PC5
, 1, 0x0308, WRITE_MASK_VAL(6, 6, 1)), /* PWM12 IO mux M1 */
1011 RK_MUXROUTE_GRF(3, RK_PC0
, 2, 0x0308, WRITE_MASK_VAL(8, 8, 0)), /* PWM13 IO mux M0 */
1012 RK_MUXROUTE_GRF(4, RK_PC6
, 1, 0x0308, WRITE_MASK_VAL(8, 8, 1)), /* PWM13 IO mux M1 */
1013 RK_MUXROUTE_GRF(3, RK_PC4
, 1, 0x0308, WRITE_MASK_VAL(10, 10, 0)), /* PWM14 IO mux M0 */
1014 RK_MUXROUTE_GRF(4, RK_PC2
, 1, 0x0308, WRITE_MASK_VAL(10, 10, 1)), /* PWM14 IO mux M1 */
1015 RK_MUXROUTE_GRF(3, RK_PC5
, 1, 0x0308, WRITE_MASK_VAL(12, 12, 0)), /* PWM15 IO mux M0 */
1016 RK_MUXROUTE_GRF(4, RK_PC3
, 1, 0x0308, WRITE_MASK_VAL(12, 12, 1)), /* PWM15 IO mux M1 */
1017 RK_MUXROUTE_GRF(3, RK_PD2
, 3, 0x0308, WRITE_MASK_VAL(14, 14, 0)), /* SDMMC2 IO mux M0 */
1018 RK_MUXROUTE_GRF(3, RK_PA5
, 5, 0x0308, WRITE_MASK_VAL(14, 14, 1)), /* SDMMC2 IO mux M1 */
1019 RK_MUXROUTE_GRF(0, RK_PB5
, 2, 0x030c, WRITE_MASK_VAL(0, 0, 0)), /* SPI0 IO mux M0 */
1020 RK_MUXROUTE_GRF(2, RK_PD3
, 3, 0x030c, WRITE_MASK_VAL(0, 0, 1)), /* SPI0 IO mux M1 */
1021 RK_MUXROUTE_GRF(2, RK_PB5
, 3, 0x030c, WRITE_MASK_VAL(2, 2, 0)), /* SPI1 IO mux M0 */
1022 RK_MUXROUTE_GRF(3, RK_PC3
, 3, 0x030c, WRITE_MASK_VAL(2, 2, 1)), /* SPI1 IO mux M1 */
1023 RK_MUXROUTE_GRF(2, RK_PC1
, 4, 0x030c, WRITE_MASK_VAL(4, 4, 0)), /* SPI2 IO mux M0 */
1024 RK_MUXROUTE_GRF(3, RK_PA0
, 3, 0x030c, WRITE_MASK_VAL(4, 4, 1)), /* SPI2 IO mux M1 */
1025 RK_MUXROUTE_GRF(4, RK_PB3
, 4, 0x030c, WRITE_MASK_VAL(6, 6, 0)), /* SPI3 IO mux M0 */
1026 RK_MUXROUTE_GRF(4, RK_PC2
, 2, 0x030c, WRITE_MASK_VAL(6, 6, 1)), /* SPI3 IO mux M1 */
1027 RK_MUXROUTE_GRF(2, RK_PB4
, 2, 0x030c, WRITE_MASK_VAL(8, 8, 0)), /* UART1 IO mux M0 */
1028 RK_MUXROUTE_GRF(3, RK_PD6
, 4, 0x030c, WRITE_MASK_VAL(8, 8, 1)), /* UART1 IO mux M1 */
1029 RK_MUXROUTE_GRF(0, RK_PD1
, 1, 0x030c, WRITE_MASK_VAL(10, 10, 0)), /* UART2 IO mux M0 */
1030 RK_MUXROUTE_GRF(1, RK_PD5
, 2, 0x030c, WRITE_MASK_VAL(10, 10, 1)), /* UART2 IO mux M1 */
1031 RK_MUXROUTE_GRF(1, RK_PA1
, 2, 0x030c, WRITE_MASK_VAL(12, 12, 0)), /* UART3 IO mux M0 */
1032 RK_MUXROUTE_GRF(3, RK_PB7
, 4, 0x030c, WRITE_MASK_VAL(12, 12, 1)), /* UART3 IO mux M1 */
1033 RK_MUXROUTE_GRF(1, RK_PA6
, 2, 0x030c, WRITE_MASK_VAL(14, 14, 0)), /* UART4 IO mux M0 */
1034 RK_MUXROUTE_GRF(3, RK_PB2
, 4, 0x030c, WRITE_MASK_VAL(14, 14, 1)), /* UART4 IO mux M1 */
1035 RK_MUXROUTE_GRF(2, RK_PA2
, 3, 0x0310, WRITE_MASK_VAL(0, 0, 0)), /* UART5 IO mux M0 */
1036 RK_MUXROUTE_GRF(3, RK_PC2
, 4, 0x0310, WRITE_MASK_VAL(0, 0, 1)), /* UART5 IO mux M1 */
1037 RK_MUXROUTE_GRF(2, RK_PA4
, 3, 0x0310, WRITE_MASK_VAL(2, 2, 0)), /* UART6 IO mux M0 */
1038 RK_MUXROUTE_GRF(1, RK_PD5
, 3, 0x0310, WRITE_MASK_VAL(2, 2, 1)), /* UART6 IO mux M1 */
1039 RK_MUXROUTE_GRF(2, RK_PA6
, 3, 0x0310, WRITE_MASK_VAL(5, 4, 0)), /* UART7 IO mux M0 */
1040 RK_MUXROUTE_GRF(3, RK_PC4
, 4, 0x0310, WRITE_MASK_VAL(5, 4, 1)), /* UART7 IO mux M1 */
1041 RK_MUXROUTE_GRF(4, RK_PA2
, 4, 0x0310, WRITE_MASK_VAL(5, 4, 2)), /* UART7 IO mux M2 */
1042 RK_MUXROUTE_GRF(2, RK_PC5
, 3, 0x0310, WRITE_MASK_VAL(6, 6, 0)), /* UART8 IO mux M0 */
1043 RK_MUXROUTE_GRF(2, RK_PD7
, 4, 0x0310, WRITE_MASK_VAL(6, 6, 1)), /* UART8 IO mux M1 */
1044 RK_MUXROUTE_GRF(2, RK_PB0
, 3, 0x0310, WRITE_MASK_VAL(9, 8, 0)), /* UART9 IO mux M0 */
1045 RK_MUXROUTE_GRF(4, RK_PC5
, 4, 0x0310, WRITE_MASK_VAL(9, 8, 1)), /* UART9 IO mux M1 */
1046 RK_MUXROUTE_GRF(4, RK_PA4
, 4, 0x0310, WRITE_MASK_VAL(9, 8, 2)), /* UART9 IO mux M2 */
1047 RK_MUXROUTE_GRF(1, RK_PA2
, 1, 0x0310, WRITE_MASK_VAL(11, 10, 0)), /* I2S1 IO mux M0 */
1048 RK_MUXROUTE_GRF(3, RK_PC6
, 4, 0x0310, WRITE_MASK_VAL(11, 10, 1)), /* I2S1 IO mux M1 */
1049 RK_MUXROUTE_GRF(2, RK_PD0
, 5, 0x0310, WRITE_MASK_VAL(11, 10, 2)), /* I2S1 IO mux M2 */
1050 RK_MUXROUTE_GRF(2, RK_PC1
, 1, 0x0310, WRITE_MASK_VAL(12, 12, 0)), /* I2S2 IO mux M0 */
1051 RK_MUXROUTE_GRF(4, RK_PB6
, 5, 0x0310, WRITE_MASK_VAL(12, 12, 1)), /* I2S2 IO mux M1 */
1052 RK_MUXROUTE_GRF(3, RK_PA2
, 4, 0x0310, WRITE_MASK_VAL(14, 14, 0)), /* I2S3 IO mux M0 */
1053 RK_MUXROUTE_GRF(4, RK_PC2
, 5, 0x0310, WRITE_MASK_VAL(14, 14, 1)), /* I2S3 IO mux M1 */
1054 RK_MUXROUTE_GRF(1, RK_PA4
, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
1055 RK_MUXROUTE_GRF(1, RK_PA6
, 3, 0x0314, WRITE_MASK_VAL(1, 0, 0)), /* PDM IO mux M0 */
1056 RK_MUXROUTE_GRF(3, RK_PD6
, 5, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
1057 RK_MUXROUTE_GRF(4, RK_PA0
, 4, 0x0314, WRITE_MASK_VAL(1, 0, 1)), /* PDM IO mux M1 */
1058 RK_MUXROUTE_GRF(3, RK_PC4
, 5, 0x0314, WRITE_MASK_VAL(1, 0, 2)), /* PDM IO mux M2 */
1059 RK_MUXROUTE_GRF(0, RK_PA5
, 3, 0x0314, WRITE_MASK_VAL(3, 2, 0)), /* PCIE20 IO mux M0 */
1060 RK_MUXROUTE_GRF(2, RK_PD0
, 4, 0x0314, WRITE_MASK_VAL(3, 2, 1)), /* PCIE20 IO mux M1 */
1061 RK_MUXROUTE_GRF(1, RK_PB0
, 4, 0x0314, WRITE_MASK_VAL(3, 2, 2)), /* PCIE20 IO mux M2 */
1062 RK_MUXROUTE_GRF(0, RK_PA4
, 3, 0x0314, WRITE_MASK_VAL(5, 4, 0)), /* PCIE30X1 IO mux M0 */
1063 RK_MUXROUTE_GRF(2, RK_PD2
, 4, 0x0314, WRITE_MASK_VAL(5, 4, 1)), /* PCIE30X1 IO mux M1 */
1064 RK_MUXROUTE_GRF(1, RK_PA5
, 4, 0x0314, WRITE_MASK_VAL(5, 4, 2)), /* PCIE30X1 IO mux M2 */
1065 RK_MUXROUTE_GRF(0, RK_PA6
, 2, 0x0314, WRITE_MASK_VAL(7, 6, 0)), /* PCIE30X2 IO mux M0 */
1066 RK_MUXROUTE_GRF(2, RK_PD4
, 4, 0x0314, WRITE_MASK_VAL(7, 6, 1)), /* PCIE30X2 IO mux M1 */
1067 RK_MUXROUTE_GRF(4, RK_PC2
, 4, 0x0314, WRITE_MASK_VAL(7, 6, 2)), /* PCIE30X2 IO mux M2 */
1070 static bool rockchip_get_mux_route(struct rockchip_pin_bank
*bank
, int pin
,
1071 int mux
, u32
*loc
, u32
*reg
, u32
*value
)
1073 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1074 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1075 struct rockchip_mux_route_data
*data
;
1078 for (i
= 0; i
< ctrl
->niomux_routes
; i
++) {
1079 data
= &ctrl
->iomux_routes
[i
];
1080 if ((data
->bank_num
== bank
->bank_num
) &&
1081 (data
->pin
== pin
) && (data
->func
== mux
))
1085 if (i
>= ctrl
->niomux_routes
)
1088 *loc
= data
->route_location
;
1089 *reg
= data
->route_offset
;
1090 *value
= data
->route_val
;
1095 static int rockchip_get_mux(struct rockchip_pin_bank
*bank
, int pin
)
1097 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1098 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1099 int iomux_num
= (pin
/ 8);
1100 struct regmap
*regmap
;
1102 int reg
, ret
, mask
, mux_type
;
1108 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1109 dev_err(info
->dev
, "pin %d is unrouted\n", pin
);
1113 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1114 return RK_FUNC_GPIO
;
1116 if (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1117 regmap
= info
->regmap_pmu
;
1118 else if (bank
->iomux
[iomux_num
].type
& IOMUX_L_SOURCE_PMU
)
1119 regmap
= (pin
% 8 < 4) ? info
->regmap_pmu
: info
->regmap_base
;
1121 regmap
= info
->regmap_base
;
1123 /* get basic quadrupel of mux registers and the correct reg inside */
1124 mux_type
= bank
->iomux
[iomux_num
].type
;
1125 reg
= bank
->iomux
[iomux_num
].offset
;
1126 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1129 bit
= (pin
% 4) * 4;
1131 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1134 bit
= (pin
% 8 % 5) * 3;
1137 bit
= (pin
% 8) * 2;
1141 if (bank
->recalced_mask
& BIT(pin
))
1142 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1144 if (ctrl
->type
== RK3576
) {
1145 if ((bank
->bank_num
== 0) && (pin
>= RK_PB4
) && (pin
<= RK_PB7
))
1146 reg
+= 0x1ff4; /* GPIO0_IOC_GPIO0B_IOMUX_SEL_H */
1149 if (ctrl
->type
== RK3588
) {
1150 if (bank
->bank_num
== 0) {
1151 if ((pin
>= RK_PB4
) && (pin
<= RK_PD7
)) {
1154 reg0
= reg
+ 0x4000 - 0xC; /* PMU2_IOC_BASE */
1155 ret
= regmap_read(regmap
, reg0
, &val
);
1159 if (!(val
& BIT(8)))
1160 return ((val
>> bit
) & mask
);
1162 reg
= reg
+ 0x8000; /* BUS_IOC_BASE */
1163 regmap
= info
->regmap_base
;
1165 } else if (bank
->bank_num
> 0) {
1166 reg
+= 0x8000; /* BUS_IOC_BASE */
1170 ret
= regmap_read(regmap
, reg
, &val
);
1174 return ((val
>> bit
) & mask
);
1177 static int rockchip_verify_mux(struct rockchip_pin_bank
*bank
,
1180 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1181 struct device
*dev
= info
->dev
;
1182 int iomux_num
= (pin
/ 8);
1187 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1188 dev_err(dev
, "pin %d is unrouted\n", pin
);
1192 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
) {
1193 if (mux
!= RK_FUNC_GPIO
) {
1194 dev_err(dev
, "pin %d only supports a gpio mux\n", pin
);
1203 * Set a new mux function for a pin.
1205 * The register is divided into the upper and lower 16 bit. When changing
1206 * a value, the previous register value is not read and changed. Instead
1207 * it seems the changed bits are marked in the upper 16 bit, while the
1208 * changed value gets set in the same offset in the lower 16 bit.
1209 * All pin settings seem to be 2 bit wide in both the upper and lower
1211 * @bank: pin bank to change
1212 * @pin: pin to change
1213 * @mux: new mux function to set
1215 static int rockchip_set_mux(struct rockchip_pin_bank
*bank
, int pin
, int mux
)
1217 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1218 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1219 struct device
*dev
= info
->dev
;
1220 int iomux_num
= (pin
/ 8);
1221 struct regmap
*regmap
;
1222 int reg
, ret
, mask
, mux_type
;
1224 u32 data
, rmask
, route_location
, route_reg
, route_val
;
1226 ret
= rockchip_verify_mux(bank
, pin
, mux
);
1230 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1233 dev_dbg(dev
, "setting mux of GPIO%d-%d to %d\n", bank
->bank_num
, pin
, mux
);
1235 if (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1236 regmap
= info
->regmap_pmu
;
1237 else if (bank
->iomux
[iomux_num
].type
& IOMUX_L_SOURCE_PMU
)
1238 regmap
= (pin
% 8 < 4) ? info
->regmap_pmu
: info
->regmap_base
;
1240 regmap
= info
->regmap_base
;
1242 /* get basic quadrupel of mux registers and the correct reg inside */
1243 mux_type
= bank
->iomux
[iomux_num
].type
;
1244 reg
= bank
->iomux
[iomux_num
].offset
;
1245 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1248 bit
= (pin
% 4) * 4;
1250 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1253 bit
= (pin
% 8 % 5) * 3;
1256 bit
= (pin
% 8) * 2;
1260 if (bank
->recalced_mask
& BIT(pin
))
1261 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1263 if (ctrl
->type
== RK3576
) {
1264 if ((bank
->bank_num
== 0) && (pin
>= RK_PB4
) && (pin
<= RK_PB7
))
1265 reg
+= 0x1ff4; /* GPIO0_IOC_GPIO0B_IOMUX_SEL_H */
1268 if (ctrl
->type
== RK3588
) {
1269 if (bank
->bank_num
== 0) {
1270 if ((pin
>= RK_PB4
) && (pin
<= RK_PD7
)) {
1272 reg
+= 0x4000 - 0xC; /* PMU2_IOC_BASE */
1273 data
= (mask
<< (bit
+ 16));
1274 rmask
= data
| (data
>> 16);
1275 data
|= (mux
& mask
) << bit
;
1276 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1280 reg0
= reg
+ 0x4000 - 0xC; /* PMU2_IOC_BASE */
1281 data
= (mask
<< (bit
+ 16));
1282 rmask
= data
| (data
>> 16);
1284 ret
= regmap_update_bits(regmap
, reg0
, rmask
, data
);
1286 reg0
= reg
+ 0x8000; /* BUS_IOC_BASE */
1287 data
= (mask
<< (bit
+ 16));
1288 rmask
= data
| (data
>> 16);
1290 regmap
= info
->regmap_base
;
1291 ret
|= regmap_update_bits(regmap
, reg0
, rmask
, data
);
1294 data
= (mask
<< (bit
+ 16));
1295 rmask
= data
| (data
>> 16);
1296 data
|= (mux
& mask
) << bit
;
1297 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1300 } else if (bank
->bank_num
> 0) {
1301 reg
+= 0x8000; /* BUS_IOC_BASE */
1308 if (bank
->route_mask
& BIT(pin
)) {
1309 if (rockchip_get_mux_route(bank
, pin
, mux
, &route_location
,
1310 &route_reg
, &route_val
)) {
1311 struct regmap
*route_regmap
= regmap
;
1313 /* handle special locations */
1314 switch (route_location
) {
1315 case ROCKCHIP_ROUTE_PMU
:
1316 route_regmap
= info
->regmap_pmu
;
1318 case ROCKCHIP_ROUTE_GRF
:
1319 route_regmap
= info
->regmap_base
;
1323 ret
= regmap_write(route_regmap
, route_reg
, route_val
);
1329 data
= (mask
<< (bit
+ 16));
1330 rmask
= data
| (data
>> 16);
1331 data
|= (mux
& mask
) << bit
;
1332 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1337 #define PX30_PULL_PMU_OFFSET 0x10
1338 #define PX30_PULL_GRF_OFFSET 0x60
1339 #define PX30_PULL_BITS_PER_PIN 2
1340 #define PX30_PULL_PINS_PER_REG 8
1341 #define PX30_PULL_BANK_STRIDE 16
1343 static int px30_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1344 int pin_num
, struct regmap
**regmap
,
1347 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1349 /* The first 32 pins of the first bank are located in PMU */
1350 if (bank
->bank_num
== 0) {
1351 *regmap
= info
->regmap_pmu
;
1352 *reg
= PX30_PULL_PMU_OFFSET
;
1354 *regmap
= info
->regmap_base
;
1355 *reg
= PX30_PULL_GRF_OFFSET
;
1357 /* correct the offset, as we're starting with the 2nd bank */
1359 *reg
+= bank
->bank_num
* PX30_PULL_BANK_STRIDE
;
1362 *reg
+= ((pin_num
/ PX30_PULL_PINS_PER_REG
) * 4);
1363 *bit
= (pin_num
% PX30_PULL_PINS_PER_REG
);
1364 *bit
*= PX30_PULL_BITS_PER_PIN
;
1369 #define PX30_DRV_PMU_OFFSET 0x20
1370 #define PX30_DRV_GRF_OFFSET 0xf0
1371 #define PX30_DRV_BITS_PER_PIN 2
1372 #define PX30_DRV_PINS_PER_REG 8
1373 #define PX30_DRV_BANK_STRIDE 16
1375 static int px30_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1376 int pin_num
, struct regmap
**regmap
,
1379 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1381 /* The first 32 pins of the first bank are located in PMU */
1382 if (bank
->bank_num
== 0) {
1383 *regmap
= info
->regmap_pmu
;
1384 *reg
= PX30_DRV_PMU_OFFSET
;
1386 *regmap
= info
->regmap_base
;
1387 *reg
= PX30_DRV_GRF_OFFSET
;
1389 /* correct the offset, as we're starting with the 2nd bank */
1391 *reg
+= bank
->bank_num
* PX30_DRV_BANK_STRIDE
;
1394 *reg
+= ((pin_num
/ PX30_DRV_PINS_PER_REG
) * 4);
1395 *bit
= (pin_num
% PX30_DRV_PINS_PER_REG
);
1396 *bit
*= PX30_DRV_BITS_PER_PIN
;
1401 #define PX30_SCHMITT_PMU_OFFSET 0x38
1402 #define PX30_SCHMITT_GRF_OFFSET 0xc0
1403 #define PX30_SCHMITT_PINS_PER_PMU_REG 16
1404 #define PX30_SCHMITT_BANK_STRIDE 16
1405 #define PX30_SCHMITT_PINS_PER_GRF_REG 8
1407 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1409 struct regmap
**regmap
,
1412 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1415 if (bank
->bank_num
== 0) {
1416 *regmap
= info
->regmap_pmu
;
1417 *reg
= PX30_SCHMITT_PMU_OFFSET
;
1418 pins_per_reg
= PX30_SCHMITT_PINS_PER_PMU_REG
;
1420 *regmap
= info
->regmap_base
;
1421 *reg
= PX30_SCHMITT_GRF_OFFSET
;
1422 pins_per_reg
= PX30_SCHMITT_PINS_PER_GRF_REG
;
1423 *reg
+= (bank
->bank_num
- 1) * PX30_SCHMITT_BANK_STRIDE
;
1426 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1427 *bit
= pin_num
% pins_per_reg
;
1432 #define RV1108_PULL_PMU_OFFSET 0x10
1433 #define RV1108_PULL_OFFSET 0x110
1434 #define RV1108_PULL_PINS_PER_REG 8
1435 #define RV1108_PULL_BITS_PER_PIN 2
1436 #define RV1108_PULL_BANK_STRIDE 16
1438 static int rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1439 int pin_num
, struct regmap
**regmap
,
1442 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1444 /* The first 24 pins of the first bank are located in PMU */
1445 if (bank
->bank_num
== 0) {
1446 *regmap
= info
->regmap_pmu
;
1447 *reg
= RV1108_PULL_PMU_OFFSET
;
1449 *reg
= RV1108_PULL_OFFSET
;
1450 *regmap
= info
->regmap_base
;
1451 /* correct the offset, as we're starting with the 2nd bank */
1453 *reg
+= bank
->bank_num
* RV1108_PULL_BANK_STRIDE
;
1456 *reg
+= ((pin_num
/ RV1108_PULL_PINS_PER_REG
) * 4);
1457 *bit
= (pin_num
% RV1108_PULL_PINS_PER_REG
);
1458 *bit
*= RV1108_PULL_BITS_PER_PIN
;
1463 #define RV1108_DRV_PMU_OFFSET 0x20
1464 #define RV1108_DRV_GRF_OFFSET 0x210
1465 #define RV1108_DRV_BITS_PER_PIN 2
1466 #define RV1108_DRV_PINS_PER_REG 8
1467 #define RV1108_DRV_BANK_STRIDE 16
1469 static int rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1470 int pin_num
, struct regmap
**regmap
,
1473 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1475 /* The first 24 pins of the first bank are located in PMU */
1476 if (bank
->bank_num
== 0) {
1477 *regmap
= info
->regmap_pmu
;
1478 *reg
= RV1108_DRV_PMU_OFFSET
;
1480 *regmap
= info
->regmap_base
;
1481 *reg
= RV1108_DRV_GRF_OFFSET
;
1483 /* correct the offset, as we're starting with the 2nd bank */
1485 *reg
+= bank
->bank_num
* RV1108_DRV_BANK_STRIDE
;
1488 *reg
+= ((pin_num
/ RV1108_DRV_PINS_PER_REG
) * 4);
1489 *bit
= pin_num
% RV1108_DRV_PINS_PER_REG
;
1490 *bit
*= RV1108_DRV_BITS_PER_PIN
;
1495 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1496 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1497 #define RV1108_SCHMITT_BANK_STRIDE 8
1498 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1499 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1501 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1503 struct regmap
**regmap
,
1506 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1509 if (bank
->bank_num
== 0) {
1510 *regmap
= info
->regmap_pmu
;
1511 *reg
= RV1108_SCHMITT_PMU_OFFSET
;
1512 pins_per_reg
= RV1108_SCHMITT_PINS_PER_PMU_REG
;
1514 *regmap
= info
->regmap_base
;
1515 *reg
= RV1108_SCHMITT_GRF_OFFSET
;
1516 pins_per_reg
= RV1108_SCHMITT_PINS_PER_GRF_REG
;
1517 *reg
+= (bank
->bank_num
- 1) * RV1108_SCHMITT_BANK_STRIDE
;
1519 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1520 *bit
= pin_num
% pins_per_reg
;
1525 #define RV1126_PULL_PMU_OFFSET 0x40
1526 #define RV1126_PULL_GRF_GPIO1A0_OFFSET 0x10108
1527 #define RV1126_PULL_PINS_PER_REG 8
1528 #define RV1126_PULL_BITS_PER_PIN 2
1529 #define RV1126_PULL_BANK_STRIDE 16
1530 #define RV1126_GPIO_C4_D7(p) (p >= 20 && p <= 31) /* GPIO0_C4 ~ GPIO0_D7 */
1532 static int rv1126_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1533 int pin_num
, struct regmap
**regmap
,
1536 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1538 /* The first 24 pins of the first bank are located in PMU */
1539 if (bank
->bank_num
== 0) {
1540 if (RV1126_GPIO_C4_D7(pin_num
)) {
1541 *regmap
= info
->regmap_base
;
1542 *reg
= RV1126_PULL_GRF_GPIO1A0_OFFSET
;
1543 *reg
-= (((31 - pin_num
) / RV1126_PULL_PINS_PER_REG
+ 1) * 4);
1544 *bit
= pin_num
% RV1126_PULL_PINS_PER_REG
;
1545 *bit
*= RV1126_PULL_BITS_PER_PIN
;
1548 *regmap
= info
->regmap_pmu
;
1549 *reg
= RV1126_PULL_PMU_OFFSET
;
1551 *reg
= RV1126_PULL_GRF_GPIO1A0_OFFSET
;
1552 *regmap
= info
->regmap_base
;
1553 *reg
+= (bank
->bank_num
- 1) * RV1126_PULL_BANK_STRIDE
;
1556 *reg
+= ((pin_num
/ RV1126_PULL_PINS_PER_REG
) * 4);
1557 *bit
= (pin_num
% RV1126_PULL_PINS_PER_REG
);
1558 *bit
*= RV1126_PULL_BITS_PER_PIN
;
1563 #define RV1126_DRV_PMU_OFFSET 0x20
1564 #define RV1126_DRV_GRF_GPIO1A0_OFFSET 0x10090
1565 #define RV1126_DRV_BITS_PER_PIN 4
1566 #define RV1126_DRV_PINS_PER_REG 4
1567 #define RV1126_DRV_BANK_STRIDE 32
1569 static int rv1126_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1570 int pin_num
, struct regmap
**regmap
,
1573 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1575 /* The first 24 pins of the first bank are located in PMU */
1576 if (bank
->bank_num
== 0) {
1577 if (RV1126_GPIO_C4_D7(pin_num
)) {
1578 *regmap
= info
->regmap_base
;
1579 *reg
= RV1126_DRV_GRF_GPIO1A0_OFFSET
;
1580 *reg
-= (((31 - pin_num
) / RV1126_DRV_PINS_PER_REG
+ 1) * 4);
1582 *bit
= pin_num
% RV1126_DRV_PINS_PER_REG
;
1583 *bit
*= RV1126_DRV_BITS_PER_PIN
;
1586 *regmap
= info
->regmap_pmu
;
1587 *reg
= RV1126_DRV_PMU_OFFSET
;
1589 *regmap
= info
->regmap_base
;
1590 *reg
= RV1126_DRV_GRF_GPIO1A0_OFFSET
;
1591 *reg
+= (bank
->bank_num
- 1) * RV1126_DRV_BANK_STRIDE
;
1594 *reg
+= ((pin_num
/ RV1126_DRV_PINS_PER_REG
) * 4);
1595 *bit
= pin_num
% RV1126_DRV_PINS_PER_REG
;
1596 *bit
*= RV1126_DRV_BITS_PER_PIN
;
1601 #define RV1126_SCHMITT_PMU_OFFSET 0x60
1602 #define RV1126_SCHMITT_GRF_GPIO1A0_OFFSET 0x10188
1603 #define RV1126_SCHMITT_BANK_STRIDE 16
1604 #define RV1126_SCHMITT_PINS_PER_GRF_REG 8
1605 #define RV1126_SCHMITT_PINS_PER_PMU_REG 8
1607 static int rv1126_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1609 struct regmap
**regmap
,
1612 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1615 if (bank
->bank_num
== 0) {
1616 if (RV1126_GPIO_C4_D7(pin_num
)) {
1617 *regmap
= info
->regmap_base
;
1618 *reg
= RV1126_SCHMITT_GRF_GPIO1A0_OFFSET
;
1619 *reg
-= (((31 - pin_num
) / RV1126_SCHMITT_PINS_PER_GRF_REG
+ 1) * 4);
1620 *bit
= pin_num
% RV1126_SCHMITT_PINS_PER_GRF_REG
;
1623 *regmap
= info
->regmap_pmu
;
1624 *reg
= RV1126_SCHMITT_PMU_OFFSET
;
1625 pins_per_reg
= RV1126_SCHMITT_PINS_PER_PMU_REG
;
1627 *regmap
= info
->regmap_base
;
1628 *reg
= RV1126_SCHMITT_GRF_GPIO1A0_OFFSET
;
1629 pins_per_reg
= RV1126_SCHMITT_PINS_PER_GRF_REG
;
1630 *reg
+= (bank
->bank_num
- 1) * RV1126_SCHMITT_BANK_STRIDE
;
1632 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1633 *bit
= pin_num
% pins_per_reg
;
1638 #define RK3308_SCHMITT_PINS_PER_REG 8
1639 #define RK3308_SCHMITT_BANK_STRIDE 16
1640 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0
1642 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1643 int pin_num
, struct regmap
**regmap
,
1646 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1648 *regmap
= info
->regmap_base
;
1649 *reg
= RK3308_SCHMITT_GRF_OFFSET
;
1651 *reg
+= bank
->bank_num
* RK3308_SCHMITT_BANK_STRIDE
;
1652 *reg
+= ((pin_num
/ RK3308_SCHMITT_PINS_PER_REG
) * 4);
1653 *bit
= pin_num
% RK3308_SCHMITT_PINS_PER_REG
;
1658 #define RK2928_PULL_OFFSET 0x118
1659 #define RK2928_PULL_PINS_PER_REG 16
1660 #define RK2928_PULL_BANK_STRIDE 8
1662 static int rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1663 int pin_num
, struct regmap
**regmap
,
1666 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1668 *regmap
= info
->regmap_base
;
1669 *reg
= RK2928_PULL_OFFSET
;
1670 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1671 *reg
+= (pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4;
1673 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1678 #define RK3128_PULL_OFFSET 0x118
1680 static int rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1681 int pin_num
, struct regmap
**regmap
,
1684 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1686 *regmap
= info
->regmap_base
;
1687 *reg
= RK3128_PULL_OFFSET
;
1688 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1689 *reg
+= ((pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4);
1691 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1696 #define RK3188_PULL_OFFSET 0x164
1697 #define RK3188_PULL_BITS_PER_PIN 2
1698 #define RK3188_PULL_PINS_PER_REG 8
1699 #define RK3188_PULL_BANK_STRIDE 16
1700 #define RK3188_PULL_PMU_OFFSET 0x64
1702 static int rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1703 int pin_num
, struct regmap
**regmap
,
1706 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1708 /* The first 12 pins of the first bank are located elsewhere */
1709 if (bank
->bank_num
== 0 && pin_num
< 12) {
1710 *regmap
= info
->regmap_pmu
? info
->regmap_pmu
1711 : bank
->regmap_pull
;
1712 *reg
= info
->regmap_pmu
? RK3188_PULL_PMU_OFFSET
: 0;
1713 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1714 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1715 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1717 *regmap
= info
->regmap_pull
? info
->regmap_pull
1718 : info
->regmap_base
;
1719 *reg
= info
->regmap_pull
? 0 : RK3188_PULL_OFFSET
;
1721 /* correct the offset, as it is the 2nd pull register */
1723 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1724 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1727 * The bits in these registers have an inverse ordering
1728 * with the lowest pin being in bits 15:14 and the highest
1731 *bit
= 7 - (pin_num
% RK3188_PULL_PINS_PER_REG
);
1732 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1738 #define RK3288_PULL_OFFSET 0x140
1739 static int rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1740 int pin_num
, struct regmap
**regmap
,
1743 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1745 /* The first 24 pins of the first bank are located in PMU */
1746 if (bank
->bank_num
== 0) {
1747 *regmap
= info
->regmap_pmu
;
1748 *reg
= RK3188_PULL_PMU_OFFSET
;
1750 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1751 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1752 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1754 *regmap
= info
->regmap_base
;
1755 *reg
= RK3288_PULL_OFFSET
;
1757 /* correct the offset, as we're starting with the 2nd bank */
1759 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1760 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1762 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1763 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1769 #define RK3288_DRV_PMU_OFFSET 0x70
1770 #define RK3288_DRV_GRF_OFFSET 0x1c0
1771 #define RK3288_DRV_BITS_PER_PIN 2
1772 #define RK3288_DRV_PINS_PER_REG 8
1773 #define RK3288_DRV_BANK_STRIDE 16
1775 static int rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1776 int pin_num
, struct regmap
**regmap
,
1779 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1781 /* The first 24 pins of the first bank are located in PMU */
1782 if (bank
->bank_num
== 0) {
1783 *regmap
= info
->regmap_pmu
;
1784 *reg
= RK3288_DRV_PMU_OFFSET
;
1786 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1787 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
1788 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1790 *regmap
= info
->regmap_base
;
1791 *reg
= RK3288_DRV_GRF_OFFSET
;
1793 /* correct the offset, as we're starting with the 2nd bank */
1795 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1796 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1798 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1799 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1805 #define RK3228_PULL_OFFSET 0x100
1807 static int rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1808 int pin_num
, struct regmap
**regmap
,
1811 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1813 *regmap
= info
->regmap_base
;
1814 *reg
= RK3228_PULL_OFFSET
;
1815 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1816 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1818 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1819 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1824 #define RK3228_DRV_GRF_OFFSET 0x200
1826 static int rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1827 int pin_num
, struct regmap
**regmap
,
1830 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1832 *regmap
= info
->regmap_base
;
1833 *reg
= RK3228_DRV_GRF_OFFSET
;
1834 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1835 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1837 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1838 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1843 #define RK3308_PULL_OFFSET 0xa0
1845 static int rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1846 int pin_num
, struct regmap
**regmap
,
1849 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1851 *regmap
= info
->regmap_base
;
1852 *reg
= RK3308_PULL_OFFSET
;
1853 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1854 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1856 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1857 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1862 #define RK3308_DRV_GRF_OFFSET 0x100
1864 static int rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1865 int pin_num
, struct regmap
**regmap
,
1868 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1870 *regmap
= info
->regmap_base
;
1871 *reg
= RK3308_DRV_GRF_OFFSET
;
1872 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1873 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1875 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1876 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1881 #define RK3368_PULL_GRF_OFFSET 0x100
1882 #define RK3368_PULL_PMU_OFFSET 0x10
1884 static int rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1885 int pin_num
, struct regmap
**regmap
,
1888 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1890 /* The first 32 pins of the first bank are located in PMU */
1891 if (bank
->bank_num
== 0) {
1892 *regmap
= info
->regmap_pmu
;
1893 *reg
= RK3368_PULL_PMU_OFFSET
;
1895 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1896 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1897 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1899 *regmap
= info
->regmap_base
;
1900 *reg
= RK3368_PULL_GRF_OFFSET
;
1902 /* correct the offset, as we're starting with the 2nd bank */
1904 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1905 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1907 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1908 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1914 #define RK3368_DRV_PMU_OFFSET 0x20
1915 #define RK3368_DRV_GRF_OFFSET 0x200
1917 static int rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1918 int pin_num
, struct regmap
**regmap
,
1921 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1923 /* The first 32 pins of the first bank are located in PMU */
1924 if (bank
->bank_num
== 0) {
1925 *regmap
= info
->regmap_pmu
;
1926 *reg
= RK3368_DRV_PMU_OFFSET
;
1928 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1929 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
1930 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1932 *regmap
= info
->regmap_base
;
1933 *reg
= RK3368_DRV_GRF_OFFSET
;
1935 /* correct the offset, as we're starting with the 2nd bank */
1937 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1938 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1940 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1941 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1947 #define RK3399_PULL_GRF_OFFSET 0xe040
1948 #define RK3399_PULL_PMU_OFFSET 0x40
1949 #define RK3399_DRV_3BITS_PER_PIN 3
1951 static int rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1952 int pin_num
, struct regmap
**regmap
,
1955 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1957 /* The bank0:16 and bank1:32 pins are located in PMU */
1958 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1)) {
1959 *regmap
= info
->regmap_pmu
;
1960 *reg
= RK3399_PULL_PMU_OFFSET
;
1962 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1964 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1965 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1966 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1968 *regmap
= info
->regmap_base
;
1969 *reg
= RK3399_PULL_GRF_OFFSET
;
1971 /* correct the offset, as we're starting with the 3rd bank */
1973 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1974 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1976 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1977 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1983 static int rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1984 int pin_num
, struct regmap
**regmap
,
1987 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1988 int drv_num
= (pin_num
/ 8);
1990 /* The bank0:16 and bank1:32 pins are located in PMU */
1991 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1))
1992 *regmap
= info
->regmap_pmu
;
1994 *regmap
= info
->regmap_base
;
1996 *reg
= bank
->drv
[drv_num
].offset
;
1997 if ((bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
1998 (bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_3V3_ONLY
))
1999 *bit
= (pin_num
% 8) * 3;
2001 *bit
= (pin_num
% 8) * 2;
2006 #define RK3568_PULL_PMU_OFFSET 0x20
2007 #define RK3568_PULL_GRF_OFFSET 0x80
2008 #define RK3568_PULL_BITS_PER_PIN 2
2009 #define RK3568_PULL_PINS_PER_REG 8
2010 #define RK3568_PULL_BANK_STRIDE 0x10
2012 static int rk3568_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
2013 int pin_num
, struct regmap
**regmap
,
2016 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2018 if (bank
->bank_num
== 0) {
2019 *regmap
= info
->regmap_pmu
;
2020 *reg
= RK3568_PULL_PMU_OFFSET
;
2021 *reg
+= bank
->bank_num
* RK3568_PULL_BANK_STRIDE
;
2022 *reg
+= ((pin_num
/ RK3568_PULL_PINS_PER_REG
) * 4);
2024 *bit
= pin_num
% RK3568_PULL_PINS_PER_REG
;
2025 *bit
*= RK3568_PULL_BITS_PER_PIN
;
2027 *regmap
= info
->regmap_base
;
2028 *reg
= RK3568_PULL_GRF_OFFSET
;
2029 *reg
+= (bank
->bank_num
- 1) * RK3568_PULL_BANK_STRIDE
;
2030 *reg
+= ((pin_num
/ RK3568_PULL_PINS_PER_REG
) * 4);
2032 *bit
= (pin_num
% RK3568_PULL_PINS_PER_REG
);
2033 *bit
*= RK3568_PULL_BITS_PER_PIN
;
2039 #define RK3568_DRV_PMU_OFFSET 0x70
2040 #define RK3568_DRV_GRF_OFFSET 0x200
2041 #define RK3568_DRV_BITS_PER_PIN 8
2042 #define RK3568_DRV_PINS_PER_REG 2
2043 #define RK3568_DRV_BANK_STRIDE 0x40
2045 static int rk3568_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
2046 int pin_num
, struct regmap
**regmap
,
2049 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2051 /* The first 32 pins of the first bank are located in PMU */
2052 if (bank
->bank_num
== 0) {
2053 *regmap
= info
->regmap_pmu
;
2054 *reg
= RK3568_DRV_PMU_OFFSET
;
2055 *reg
+= ((pin_num
/ RK3568_DRV_PINS_PER_REG
) * 4);
2057 *bit
= pin_num
% RK3568_DRV_PINS_PER_REG
;
2058 *bit
*= RK3568_DRV_BITS_PER_PIN
;
2060 *regmap
= info
->regmap_base
;
2061 *reg
= RK3568_DRV_GRF_OFFSET
;
2062 *reg
+= (bank
->bank_num
- 1) * RK3568_DRV_BANK_STRIDE
;
2063 *reg
+= ((pin_num
/ RK3568_DRV_PINS_PER_REG
) * 4);
2065 *bit
= (pin_num
% RK3568_DRV_PINS_PER_REG
);
2066 *bit
*= RK3568_DRV_BITS_PER_PIN
;
2072 #define RK3576_DRV_BITS_PER_PIN 4
2073 #define RK3576_DRV_PINS_PER_REG 4
2074 #define RK3576_DRV_GPIO0_AL_OFFSET 0x10
2075 #define RK3576_DRV_GPIO0_BH_OFFSET 0x2014
2076 #define RK3576_DRV_GPIO1_OFFSET 0x6020
2077 #define RK3576_DRV_GPIO2_OFFSET 0x6040
2078 #define RK3576_DRV_GPIO3_OFFSET 0x6060
2079 #define RK3576_DRV_GPIO4_AL_OFFSET 0x6080
2080 #define RK3576_DRV_GPIO4_CL_OFFSET 0xA090
2081 #define RK3576_DRV_GPIO4_DL_OFFSET 0xB098
2083 static int rk3576_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
2084 int pin_num
, struct regmap
**regmap
,
2087 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2089 *regmap
= info
->regmap_base
;
2091 if (bank
->bank_num
== 0 && pin_num
< 12)
2092 *reg
= RK3576_DRV_GPIO0_AL_OFFSET
;
2093 else if (bank
->bank_num
== 0)
2094 *reg
= RK3576_DRV_GPIO0_BH_OFFSET
- 0xc;
2095 else if (bank
->bank_num
== 1)
2096 *reg
= RK3576_DRV_GPIO1_OFFSET
;
2097 else if (bank
->bank_num
== 2)
2098 *reg
= RK3576_DRV_GPIO2_OFFSET
;
2099 else if (bank
->bank_num
== 3)
2100 *reg
= RK3576_DRV_GPIO3_OFFSET
;
2101 else if (bank
->bank_num
== 4 && pin_num
< 16)
2102 *reg
= RK3576_DRV_GPIO4_AL_OFFSET
;
2103 else if (bank
->bank_num
== 4 && pin_num
< 24)
2104 *reg
= RK3576_DRV_GPIO4_CL_OFFSET
- 0x10;
2105 else if (bank
->bank_num
== 4)
2106 *reg
= RK3576_DRV_GPIO4_DL_OFFSET
- 0x18;
2108 dev_err(info
->dev
, "unsupported bank_num %d\n", bank
->bank_num
);
2110 *reg
+= ((pin_num
/ RK3576_DRV_PINS_PER_REG
) * 4);
2111 *bit
= pin_num
% RK3576_DRV_PINS_PER_REG
;
2112 *bit
*= RK3576_DRV_BITS_PER_PIN
;
2117 #define RK3576_PULL_BITS_PER_PIN 2
2118 #define RK3576_PULL_PINS_PER_REG 8
2119 #define RK3576_PULL_GPIO0_AL_OFFSET 0x20
2120 #define RK3576_PULL_GPIO0_BH_OFFSET 0x2028
2121 #define RK3576_PULL_GPIO1_OFFSET 0x6110
2122 #define RK3576_PULL_GPIO2_OFFSET 0x6120
2123 #define RK3576_PULL_GPIO3_OFFSET 0x6130
2124 #define RK3576_PULL_GPIO4_AL_OFFSET 0x6140
2125 #define RK3576_PULL_GPIO4_CL_OFFSET 0xA148
2126 #define RK3576_PULL_GPIO4_DL_OFFSET 0xB14C
2128 static int rk3576_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
2129 int pin_num
, struct regmap
**regmap
,
2132 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2134 *regmap
= info
->regmap_base
;
2136 if (bank
->bank_num
== 0 && pin_num
< 12)
2137 *reg
= RK3576_PULL_GPIO0_AL_OFFSET
;
2138 else if (bank
->bank_num
== 0)
2139 *reg
= RK3576_PULL_GPIO0_BH_OFFSET
- 0x4;
2140 else if (bank
->bank_num
== 1)
2141 *reg
= RK3576_PULL_GPIO1_OFFSET
;
2142 else if (bank
->bank_num
== 2)
2143 *reg
= RK3576_PULL_GPIO2_OFFSET
;
2144 else if (bank
->bank_num
== 3)
2145 *reg
= RK3576_PULL_GPIO3_OFFSET
;
2146 else if (bank
->bank_num
== 4 && pin_num
< 16)
2147 *reg
= RK3576_PULL_GPIO4_AL_OFFSET
;
2148 else if (bank
->bank_num
== 4 && pin_num
< 24)
2149 *reg
= RK3576_PULL_GPIO4_CL_OFFSET
- 0x8;
2150 else if (bank
->bank_num
== 4)
2151 *reg
= RK3576_PULL_GPIO4_DL_OFFSET
- 0xc;
2153 dev_err(info
->dev
, "unsupported bank_num %d\n", bank
->bank_num
);
2155 *reg
+= ((pin_num
/ RK3576_PULL_PINS_PER_REG
) * 4);
2156 *bit
= pin_num
% RK3576_PULL_PINS_PER_REG
;
2157 *bit
*= RK3576_PULL_BITS_PER_PIN
;
2162 #define RK3576_SMT_BITS_PER_PIN 1
2163 #define RK3576_SMT_PINS_PER_REG 8
2164 #define RK3576_SMT_GPIO0_AL_OFFSET 0x30
2165 #define RK3576_SMT_GPIO0_BH_OFFSET 0x2040
2166 #define RK3576_SMT_GPIO1_OFFSET 0x6210
2167 #define RK3576_SMT_GPIO2_OFFSET 0x6220
2168 #define RK3576_SMT_GPIO3_OFFSET 0x6230
2169 #define RK3576_SMT_GPIO4_AL_OFFSET 0x6240
2170 #define RK3576_SMT_GPIO4_CL_OFFSET 0xA248
2171 #define RK3576_SMT_GPIO4_DL_OFFSET 0xB24C
2173 static int rk3576_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
2175 struct regmap
**regmap
,
2178 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2180 *regmap
= info
->regmap_base
;
2182 if (bank
->bank_num
== 0 && pin_num
< 12)
2183 *reg
= RK3576_SMT_GPIO0_AL_OFFSET
;
2184 else if (bank
->bank_num
== 0)
2185 *reg
= RK3576_SMT_GPIO0_BH_OFFSET
- 0x4;
2186 else if (bank
->bank_num
== 1)
2187 *reg
= RK3576_SMT_GPIO1_OFFSET
;
2188 else if (bank
->bank_num
== 2)
2189 *reg
= RK3576_SMT_GPIO2_OFFSET
;
2190 else if (bank
->bank_num
== 3)
2191 *reg
= RK3576_SMT_GPIO3_OFFSET
;
2192 else if (bank
->bank_num
== 4 && pin_num
< 16)
2193 *reg
= RK3576_SMT_GPIO4_AL_OFFSET
;
2194 else if (bank
->bank_num
== 4 && pin_num
< 24)
2195 *reg
= RK3576_SMT_GPIO4_CL_OFFSET
- 0x8;
2196 else if (bank
->bank_num
== 4)
2197 *reg
= RK3576_SMT_GPIO4_DL_OFFSET
- 0xc;
2199 dev_err(info
->dev
, "unsupported bank_num %d\n", bank
->bank_num
);
2201 *reg
+= ((pin_num
/ RK3576_SMT_PINS_PER_REG
) * 4);
2202 *bit
= pin_num
% RK3576_SMT_PINS_PER_REG
;
2203 *bit
*= RK3576_SMT_BITS_PER_PIN
;
2208 #define RK3588_PMU1_IOC_REG (0x0000)
2209 #define RK3588_PMU2_IOC_REG (0x4000)
2210 #define RK3588_BUS_IOC_REG (0x8000)
2211 #define RK3588_VCCIO1_4_IOC_REG (0x9000)
2212 #define RK3588_VCCIO3_5_IOC_REG (0xA000)
2213 #define RK3588_VCCIO2_IOC_REG (0xB000)
2214 #define RK3588_VCCIO6_IOC_REG (0xC000)
2215 #define RK3588_EMMC_IOC_REG (0xD000)
2217 static const u32 rk3588_ds_regs
[][2] = {
2218 {RK_GPIO0_A0
, RK3588_PMU1_IOC_REG
+ 0x0010},
2219 {RK_GPIO0_A4
, RK3588_PMU1_IOC_REG
+ 0x0014},
2220 {RK_GPIO0_B0
, RK3588_PMU1_IOC_REG
+ 0x0018},
2221 {RK_GPIO0_B4
, RK3588_PMU2_IOC_REG
+ 0x0014},
2222 {RK_GPIO0_C0
, RK3588_PMU2_IOC_REG
+ 0x0018},
2223 {RK_GPIO0_C4
, RK3588_PMU2_IOC_REG
+ 0x001C},
2224 {RK_GPIO0_D0
, RK3588_PMU2_IOC_REG
+ 0x0020},
2225 {RK_GPIO0_D4
, RK3588_PMU2_IOC_REG
+ 0x0024},
2226 {RK_GPIO1_A0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0020},
2227 {RK_GPIO1_A4
, RK3588_VCCIO1_4_IOC_REG
+ 0x0024},
2228 {RK_GPIO1_B0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0028},
2229 {RK_GPIO1_B4
, RK3588_VCCIO1_4_IOC_REG
+ 0x002C},
2230 {RK_GPIO1_C0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0030},
2231 {RK_GPIO1_C4
, RK3588_VCCIO1_4_IOC_REG
+ 0x0034},
2232 {RK_GPIO1_D0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0038},
2233 {RK_GPIO1_D4
, RK3588_VCCIO1_4_IOC_REG
+ 0x003C},
2234 {RK_GPIO2_A0
, RK3588_EMMC_IOC_REG
+ 0x0040},
2235 {RK_GPIO2_A4
, RK3588_VCCIO3_5_IOC_REG
+ 0x0044},
2236 {RK_GPIO2_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0048},
2237 {RK_GPIO2_B4
, RK3588_VCCIO3_5_IOC_REG
+ 0x004C},
2238 {RK_GPIO2_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0050},
2239 {RK_GPIO2_C4
, RK3588_VCCIO3_5_IOC_REG
+ 0x0054},
2240 {RK_GPIO2_D0
, RK3588_EMMC_IOC_REG
+ 0x0058},
2241 {RK_GPIO2_D4
, RK3588_EMMC_IOC_REG
+ 0x005C},
2242 {RK_GPIO3_A0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0060},
2243 {RK_GPIO3_A4
, RK3588_VCCIO3_5_IOC_REG
+ 0x0064},
2244 {RK_GPIO3_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0068},
2245 {RK_GPIO3_B4
, RK3588_VCCIO3_5_IOC_REG
+ 0x006C},
2246 {RK_GPIO3_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0070},
2247 {RK_GPIO3_C4
, RK3588_VCCIO3_5_IOC_REG
+ 0x0074},
2248 {RK_GPIO3_D0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0078},
2249 {RK_GPIO3_D4
, RK3588_VCCIO3_5_IOC_REG
+ 0x007C},
2250 {RK_GPIO4_A0
, RK3588_VCCIO6_IOC_REG
+ 0x0080},
2251 {RK_GPIO4_A4
, RK3588_VCCIO6_IOC_REG
+ 0x0084},
2252 {RK_GPIO4_B0
, RK3588_VCCIO6_IOC_REG
+ 0x0088},
2253 {RK_GPIO4_B4
, RK3588_VCCIO6_IOC_REG
+ 0x008C},
2254 {RK_GPIO4_C0
, RK3588_VCCIO6_IOC_REG
+ 0x0090},
2255 {RK_GPIO4_C2
, RK3588_VCCIO3_5_IOC_REG
+ 0x0090},
2256 {RK_GPIO4_C4
, RK3588_VCCIO3_5_IOC_REG
+ 0x0094},
2257 {RK_GPIO4_D0
, RK3588_VCCIO2_IOC_REG
+ 0x0098},
2258 {RK_GPIO4_D4
, RK3588_VCCIO2_IOC_REG
+ 0x009C},
2261 static const u32 rk3588_p_regs
[][2] = {
2262 {RK_GPIO0_A0
, RK3588_PMU1_IOC_REG
+ 0x0020},
2263 {RK_GPIO0_B0
, RK3588_PMU1_IOC_REG
+ 0x0024},
2264 {RK_GPIO0_B5
, RK3588_PMU2_IOC_REG
+ 0x0028},
2265 {RK_GPIO0_C0
, RK3588_PMU2_IOC_REG
+ 0x002C},
2266 {RK_GPIO0_D0
, RK3588_PMU2_IOC_REG
+ 0x0030},
2267 {RK_GPIO1_A0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0110},
2268 {RK_GPIO1_B0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0114},
2269 {RK_GPIO1_C0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0118},
2270 {RK_GPIO1_D0
, RK3588_VCCIO1_4_IOC_REG
+ 0x011C},
2271 {RK_GPIO2_A0
, RK3588_EMMC_IOC_REG
+ 0x0120},
2272 {RK_GPIO2_A6
, RK3588_VCCIO3_5_IOC_REG
+ 0x0120},
2273 {RK_GPIO2_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0124},
2274 {RK_GPIO2_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0128},
2275 {RK_GPIO2_D0
, RK3588_EMMC_IOC_REG
+ 0x012C},
2276 {RK_GPIO3_A0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0130},
2277 {RK_GPIO3_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0134},
2278 {RK_GPIO3_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0138},
2279 {RK_GPIO3_D0
, RK3588_VCCIO3_5_IOC_REG
+ 0x013C},
2280 {RK_GPIO4_A0
, RK3588_VCCIO6_IOC_REG
+ 0x0140},
2281 {RK_GPIO4_B0
, RK3588_VCCIO6_IOC_REG
+ 0x0144},
2282 {RK_GPIO4_C0
, RK3588_VCCIO6_IOC_REG
+ 0x0148},
2283 {RK_GPIO4_C2
, RK3588_VCCIO3_5_IOC_REG
+ 0x0148},
2284 {RK_GPIO4_D0
, RK3588_VCCIO2_IOC_REG
+ 0x014C},
2287 static const u32 rk3588_smt_regs
[][2] = {
2288 {RK_GPIO0_A0
, RK3588_PMU1_IOC_REG
+ 0x0030},
2289 {RK_GPIO0_B0
, RK3588_PMU1_IOC_REG
+ 0x0034},
2290 {RK_GPIO0_B5
, RK3588_PMU2_IOC_REG
+ 0x0040},
2291 {RK_GPIO0_C0
, RK3588_PMU2_IOC_REG
+ 0x0044},
2292 {RK_GPIO0_D0
, RK3588_PMU2_IOC_REG
+ 0x0048},
2293 {RK_GPIO1_A0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0210},
2294 {RK_GPIO1_B0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0214},
2295 {RK_GPIO1_C0
, RK3588_VCCIO1_4_IOC_REG
+ 0x0218},
2296 {RK_GPIO1_D0
, RK3588_VCCIO1_4_IOC_REG
+ 0x021C},
2297 {RK_GPIO2_A0
, RK3588_EMMC_IOC_REG
+ 0x0220},
2298 {RK_GPIO2_A6
, RK3588_VCCIO3_5_IOC_REG
+ 0x0220},
2299 {RK_GPIO2_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0224},
2300 {RK_GPIO2_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0228},
2301 {RK_GPIO2_D0
, RK3588_EMMC_IOC_REG
+ 0x022C},
2302 {RK_GPIO3_A0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0230},
2303 {RK_GPIO3_B0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0234},
2304 {RK_GPIO3_C0
, RK3588_VCCIO3_5_IOC_REG
+ 0x0238},
2305 {RK_GPIO3_D0
, RK3588_VCCIO3_5_IOC_REG
+ 0x023C},
2306 {RK_GPIO4_A0
, RK3588_VCCIO6_IOC_REG
+ 0x0240},
2307 {RK_GPIO4_B0
, RK3588_VCCIO6_IOC_REG
+ 0x0244},
2308 {RK_GPIO4_C0
, RK3588_VCCIO6_IOC_REG
+ 0x0248},
2309 {RK_GPIO4_C2
, RK3588_VCCIO3_5_IOC_REG
+ 0x0248},
2310 {RK_GPIO4_D0
, RK3588_VCCIO2_IOC_REG
+ 0x024C},
2313 #define RK3588_PULL_BITS_PER_PIN 2
2314 #define RK3588_PULL_PINS_PER_REG 8
2316 static int rk3588_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
2317 int pin_num
, struct regmap
**regmap
,
2320 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2321 u8 bank_num
= bank
->bank_num
;
2322 u32 pin
= bank_num
* 32 + pin_num
;
2325 for (i
= ARRAY_SIZE(rk3588_p_regs
) - 1; i
>= 0; i
--) {
2326 if (pin
>= rk3588_p_regs
[i
][0]) {
2327 *reg
= rk3588_p_regs
[i
][1];
2328 *regmap
= info
->regmap_base
;
2329 *bit
= pin_num
% RK3588_PULL_PINS_PER_REG
;
2330 *bit
*= RK3588_PULL_BITS_PER_PIN
;
2338 #define RK3588_DRV_BITS_PER_PIN 4
2339 #define RK3588_DRV_PINS_PER_REG 4
2341 static int rk3588_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
2342 int pin_num
, struct regmap
**regmap
,
2345 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2346 u8 bank_num
= bank
->bank_num
;
2347 u32 pin
= bank_num
* 32 + pin_num
;
2350 for (i
= ARRAY_SIZE(rk3588_ds_regs
) - 1; i
>= 0; i
--) {
2351 if (pin
>= rk3588_ds_regs
[i
][0]) {
2352 *reg
= rk3588_ds_regs
[i
][1];
2353 *regmap
= info
->regmap_base
;
2354 *bit
= pin_num
% RK3588_DRV_PINS_PER_REG
;
2355 *bit
*= RK3588_DRV_BITS_PER_PIN
;
2363 #define RK3588_SMT_BITS_PER_PIN 1
2364 #define RK3588_SMT_PINS_PER_REG 8
2366 static int rk3588_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
2368 struct regmap
**regmap
,
2371 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2372 u8 bank_num
= bank
->bank_num
;
2373 u32 pin
= bank_num
* 32 + pin_num
;
2376 for (i
= ARRAY_SIZE(rk3588_smt_regs
) - 1; i
>= 0; i
--) {
2377 if (pin
>= rk3588_smt_regs
[i
][0]) {
2378 *reg
= rk3588_smt_regs
[i
][1];
2379 *regmap
= info
->regmap_base
;
2380 *bit
= pin_num
% RK3588_SMT_PINS_PER_REG
;
2381 *bit
*= RK3588_SMT_BITS_PER_PIN
;
2389 static int rockchip_perpin_drv_list
[DRV_TYPE_MAX
][8] = {
2390 { 2, 4, 8, 12, -1, -1, -1, -1 },
2391 { 3, 6, 9, 12, -1, -1, -1, -1 },
2392 { 5, 10, 15, 20, -1, -1, -1, -1 },
2393 { 4, 6, 8, 10, 12, 14, 16, 18 },
2394 { 4, 7, 10, 13, 16, 19, 22, 26 }
2397 static int rockchip_get_drive_perpin(struct rockchip_pin_bank
*bank
,
2400 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2401 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2402 struct device
*dev
= info
->dev
;
2403 struct regmap
*regmap
;
2405 u32 data
, temp
, rmask_bits
;
2407 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
2409 ret
= ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2414 case DRV_TYPE_IO_1V8_3V0_AUTO
:
2415 case DRV_TYPE_IO_3V3_ONLY
:
2416 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
2419 /* regular case, nothing to do */
2423 * drive-strength offset is special, as it is
2424 * spread over 2 registers
2426 ret
= regmap_read(regmap
, reg
, &data
);
2430 ret
= regmap_read(regmap
, reg
+ 0x4, &temp
);
2435 * the bit data[15] contains bit 0 of the value
2436 * while temp[1:0] contains bits 2 and 1
2443 return rockchip_perpin_drv_list
[drv_type
][data
];
2445 /* setting fully enclosed in the second register */
2450 dev_err(dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
2456 case DRV_TYPE_IO_DEFAULT
:
2457 case DRV_TYPE_IO_1V8_OR_3V0
:
2458 case DRV_TYPE_IO_1V8_ONLY
:
2459 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
2462 dev_err(dev
, "unsupported pinctrl drive type: %d\n", drv_type
);
2466 ret
= regmap_read(regmap
, reg
, &data
);
2471 data
&= (1 << rmask_bits
) - 1;
2473 return rockchip_perpin_drv_list
[drv_type
][data
];
2476 static int rockchip_set_drive_perpin(struct rockchip_pin_bank
*bank
,
2477 int pin_num
, int strength
)
2479 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2480 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2481 struct device
*dev
= info
->dev
;
2482 struct regmap
*regmap
;
2484 u32 data
, rmask
, rmask_bits
, temp
;
2486 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
2488 dev_dbg(dev
, "setting drive of GPIO%d-%d to %d\n",
2489 bank
->bank_num
, pin_num
, strength
);
2491 ret
= ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2494 if (ctrl
->type
== RK3588
) {
2495 rmask_bits
= RK3588_DRV_BITS_PER_PIN
;
2498 } else if (ctrl
->type
== RK3568
) {
2499 rmask_bits
= RK3568_DRV_BITS_PER_PIN
;
2500 ret
= (1 << (strength
+ 1)) - 1;
2502 } else if (ctrl
->type
== RK3576
) {
2503 rmask_bits
= RK3576_DRV_BITS_PER_PIN
;
2504 ret
= ((strength
& BIT(2)) >> 2) | ((strength
& BIT(0)) << 2) | (strength
& BIT(1));
2508 if (ctrl
->type
== RV1126
) {
2509 rmask_bits
= RV1126_DRV_BITS_PER_PIN
;
2515 for (i
= 0; i
< ARRAY_SIZE(rockchip_perpin_drv_list
[drv_type
]); i
++) {
2516 if (rockchip_perpin_drv_list
[drv_type
][i
] == strength
) {
2519 } else if (rockchip_perpin_drv_list
[drv_type
][i
] < 0) {
2520 ret
= rockchip_perpin_drv_list
[drv_type
][i
];
2526 dev_err(dev
, "unsupported driver strength %d\n", strength
);
2531 case DRV_TYPE_IO_1V8_3V0_AUTO
:
2532 case DRV_TYPE_IO_3V3_ONLY
:
2533 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
2536 /* regular case, nothing to do */
2540 * drive-strength offset is special, as it is spread
2541 * over 2 registers, the bit data[15] contains bit 0
2542 * of the value while temp[1:0] contains bits 2 and 1
2544 data
= (ret
& 0x1) << 15;
2545 temp
= (ret
>> 0x1) & 0x3;
2547 rmask
= BIT(15) | BIT(31);
2549 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2553 rmask
= 0x3 | (0x3 << 16);
2554 temp
|= (0x3 << 16);
2556 ret
= regmap_update_bits(regmap
, reg
, rmask
, temp
);
2560 /* setting fully enclosed in the second register */
2565 dev_err(dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
2570 case DRV_TYPE_IO_DEFAULT
:
2571 case DRV_TYPE_IO_1V8_OR_3V0
:
2572 case DRV_TYPE_IO_1V8_ONLY
:
2573 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
2576 dev_err(dev
, "unsupported pinctrl drive type: %d\n", drv_type
);
2581 /* enable the write to the equivalent lower bits */
2582 data
= ((1 << rmask_bits
) - 1) << (bit
+ 16);
2583 rmask
= data
| (data
>> 16);
2584 data
|= (ret
<< bit
);
2586 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2591 static int rockchip_pull_list
[PULL_TYPE_MAX
][4] = {
2593 PIN_CONFIG_BIAS_DISABLE
,
2594 PIN_CONFIG_BIAS_PULL_UP
,
2595 PIN_CONFIG_BIAS_PULL_DOWN
,
2596 PIN_CONFIG_BIAS_BUS_HOLD
2599 PIN_CONFIG_BIAS_DISABLE
,
2600 PIN_CONFIG_BIAS_PULL_DOWN
,
2601 PIN_CONFIG_BIAS_DISABLE
,
2602 PIN_CONFIG_BIAS_PULL_UP
2606 static int rockchip_get_pull(struct rockchip_pin_bank
*bank
, int pin_num
)
2608 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2609 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2610 struct device
*dev
= info
->dev
;
2611 struct regmap
*regmap
;
2612 int reg
, ret
, pull_type
;
2616 /* rk3066b does support any pulls */
2617 if (ctrl
->type
== RK3066B
)
2618 return PIN_CONFIG_BIAS_DISABLE
;
2620 ret
= ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2624 ret
= regmap_read(regmap
, reg
, &data
);
2628 switch (ctrl
->type
) {
2631 return !(data
& BIT(bit
))
2632 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
2633 : PIN_CONFIG_BIAS_DISABLE
;
2645 pull_type
= bank
->pull_type
[pin_num
/ 8];
2647 data
&= (1 << RK3188_PULL_BITS_PER_PIN
) - 1;
2649 * In the TRM, pull-up being 1 for everything except the GPIO0_D3-D6,
2650 * where that pull up value becomes 3.
2652 if (ctrl
->type
== RK3568
&& bank
->bank_num
== 0 && pin_num
>= 27 && pin_num
<= 30) {
2657 return rockchip_pull_list
[pull_type
][data
];
2659 dev_err(dev
, "unsupported pinctrl type\n");
2664 static int rockchip_set_pull(struct rockchip_pin_bank
*bank
,
2665 int pin_num
, int pull
)
2667 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2668 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2669 struct device
*dev
= info
->dev
;
2670 struct regmap
*regmap
;
2671 int reg
, ret
, i
, pull_type
;
2675 dev_dbg(dev
, "setting pull of GPIO%d-%d to %d\n", bank
->bank_num
, pin_num
, pull
);
2677 /* rk3066b does support any pulls */
2678 if (ctrl
->type
== RK3066B
)
2679 return pull
? -EINVAL
: 0;
2681 ret
= ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2685 switch (ctrl
->type
) {
2688 data
= BIT(bit
+ 16);
2689 if (pull
== PIN_CONFIG_BIAS_DISABLE
)
2691 ret
= regmap_write(regmap
, reg
, data
);
2705 pull_type
= bank
->pull_type
[pin_num
/ 8];
2707 for (i
= 0; i
< ARRAY_SIZE(rockchip_pull_list
[pull_type
]);
2709 if (rockchip_pull_list
[pull_type
][i
] == pull
) {
2715 * In the TRM, pull-up being 1 for everything except the GPIO0_D3-D6,
2716 * where that pull up value becomes 3.
2718 if (ctrl
->type
== RK3568
&& bank
->bank_num
== 0 && pin_num
>= 27 && pin_num
<= 30) {
2724 dev_err(dev
, "unsupported pull setting %d\n", pull
);
2728 /* enable the write to the equivalent lower bits */
2729 data
= ((1 << RK3188_PULL_BITS_PER_PIN
) - 1) << (bit
+ 16);
2730 rmask
= data
| (data
>> 16);
2731 data
|= (ret
<< bit
);
2733 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2736 dev_err(dev
, "unsupported pinctrl type\n");
2743 #define RK3328_SCHMITT_BITS_PER_PIN 1
2744 #define RK3328_SCHMITT_PINS_PER_REG 16
2745 #define RK3328_SCHMITT_BANK_STRIDE 8
2746 #define RK3328_SCHMITT_GRF_OFFSET 0x380
2748 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
2750 struct regmap
**regmap
,
2753 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2755 *regmap
= info
->regmap_base
;
2756 *reg
= RK3328_SCHMITT_GRF_OFFSET
;
2758 *reg
+= bank
->bank_num
* RK3328_SCHMITT_BANK_STRIDE
;
2759 *reg
+= ((pin_num
/ RK3328_SCHMITT_PINS_PER_REG
) * 4);
2760 *bit
= pin_num
% RK3328_SCHMITT_PINS_PER_REG
;
2765 #define RK3568_SCHMITT_BITS_PER_PIN 2
2766 #define RK3568_SCHMITT_PINS_PER_REG 8
2767 #define RK3568_SCHMITT_BANK_STRIDE 0x10
2768 #define RK3568_SCHMITT_GRF_OFFSET 0xc0
2769 #define RK3568_SCHMITT_PMUGRF_OFFSET 0x30
2771 static int rk3568_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
2773 struct regmap
**regmap
,
2776 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2778 if (bank
->bank_num
== 0) {
2779 *regmap
= info
->regmap_pmu
;
2780 *reg
= RK3568_SCHMITT_PMUGRF_OFFSET
;
2782 *regmap
= info
->regmap_base
;
2783 *reg
= RK3568_SCHMITT_GRF_OFFSET
;
2784 *reg
+= (bank
->bank_num
- 1) * RK3568_SCHMITT_BANK_STRIDE
;
2787 *reg
+= ((pin_num
/ RK3568_SCHMITT_PINS_PER_REG
) * 4);
2788 *bit
= pin_num
% RK3568_SCHMITT_PINS_PER_REG
;
2789 *bit
*= RK3568_SCHMITT_BITS_PER_PIN
;
2794 static int rockchip_get_schmitt(struct rockchip_pin_bank
*bank
, int pin_num
)
2796 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2797 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2798 struct regmap
*regmap
;
2803 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2807 ret
= regmap_read(regmap
, reg
, &data
);
2812 switch (ctrl
->type
) {
2814 return data
& ((1 << RK3568_SCHMITT_BITS_PER_PIN
) - 1);
2822 static int rockchip_set_schmitt(struct rockchip_pin_bank
*bank
,
2823 int pin_num
, int enable
)
2825 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2826 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2827 struct device
*dev
= info
->dev
;
2828 struct regmap
*regmap
;
2833 dev_dbg(dev
, "setting input schmitt of GPIO%d-%d to %d\n",
2834 bank
->bank_num
, pin_num
, enable
);
2836 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2840 /* enable the write to the equivalent lower bits */
2841 switch (ctrl
->type
) {
2843 data
= ((1 << RK3568_SCHMITT_BITS_PER_PIN
) - 1) << (bit
+ 16);
2844 rmask
= data
| (data
>> 16);
2845 data
|= ((enable
? 0x2 : 0x1) << bit
);
2848 data
= BIT(bit
+ 16) | (enable
<< bit
);
2849 rmask
= BIT(bit
+ 16) | BIT(bit
);
2853 return regmap_update_bits(regmap
, reg
, rmask
, data
);
2857 * Pinmux_ops handling
2860 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev
*pctldev
)
2862 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2864 return info
->nfunctions
;
2867 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
2870 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2872 return info
->functions
[selector
].name
;
2875 static int rockchip_pmx_get_groups(struct pinctrl_dev
*pctldev
,
2876 unsigned selector
, const char * const **groups
,
2877 unsigned * const num_groups
)
2879 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2881 *groups
= info
->functions
[selector
].groups
;
2882 *num_groups
= info
->functions
[selector
].ngroups
;
2887 static int rockchip_pmx_set(struct pinctrl_dev
*pctldev
, unsigned selector
,
2890 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2891 const unsigned int *pins
= info
->groups
[group
].pins
;
2892 const struct rockchip_pin_config
*data
= info
->groups
[group
].data
;
2893 struct device
*dev
= info
->dev
;
2894 struct rockchip_pin_bank
*bank
;
2897 dev_dbg(dev
, "enable function %s group %s\n",
2898 info
->functions
[selector
].name
, info
->groups
[group
].name
);
2901 * for each pin in the pin group selected, program the corresponding
2902 * pin function number in the config register.
2904 for (cnt
= 0; cnt
< info
->groups
[group
].npins
; cnt
++) {
2905 bank
= pin_to_bank(info
, pins
[cnt
]);
2906 ret
= rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
,
2913 /* revert the already done pin settings */
2914 for (cnt
--; cnt
>= 0; cnt
--) {
2915 bank
= pin_to_bank(info
, pins
[cnt
]);
2916 rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
, 0);
2925 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev
*pctldev
,
2926 struct pinctrl_gpio_range
*range
,
2930 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2931 struct rockchip_pin_bank
*bank
;
2933 bank
= pin_to_bank(info
, offset
);
2934 return rockchip_set_mux(bank
, offset
- bank
->pin_base
, RK_FUNC_GPIO
);
2937 static const struct pinmux_ops rockchip_pmx_ops
= {
2938 .get_functions_count
= rockchip_pmx_get_funcs_count
,
2939 .get_function_name
= rockchip_pmx_get_func_name
,
2940 .get_function_groups
= rockchip_pmx_get_groups
,
2941 .set_mux
= rockchip_pmx_set
,
2942 .gpio_set_direction
= rockchip_pmx_gpio_set_direction
,
2946 * Pinconf_ops handling
2949 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl
*ctrl
,
2950 enum pin_config_param pull
)
2952 switch (ctrl
->type
) {
2955 return (pull
== PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
||
2956 pull
== PIN_CONFIG_BIAS_DISABLE
);
2958 return pull
? false : true;
2971 return (pull
!= PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
);
2977 static int rockchip_pinconf_defer_pin(struct rockchip_pin_bank
*bank
,
2978 unsigned int pin
, u32 param
, u32 arg
)
2980 struct rockchip_pin_deferred
*cfg
;
2982 cfg
= kzalloc(sizeof(*cfg
), GFP_KERNEL
);
2990 list_add_tail(&cfg
->head
, &bank
->deferred_pins
);
2995 /* set the pin config settings for a specified pin */
2996 static int rockchip_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
2997 unsigned long *configs
, unsigned num_configs
)
2999 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
3000 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
3001 struct gpio_chip
*gpio
= &bank
->gpio_chip
;
3002 enum pin_config_param param
;
3007 for (i
= 0; i
< num_configs
; i
++) {
3008 param
= pinconf_to_config_param(configs
[i
]);
3009 arg
= pinconf_to_config_argument(configs
[i
]);
3011 if (param
== PIN_CONFIG_OUTPUT
|| param
== PIN_CONFIG_INPUT_ENABLE
) {
3013 * Check for gpio driver not being probed yet.
3014 * The lock makes sure that either gpio-probe has completed
3015 * or the gpio driver hasn't probed yet.
3017 mutex_lock(&bank
->deferred_lock
);
3018 if (!gpio
|| !gpio
->direction_output
) {
3019 rc
= rockchip_pinconf_defer_pin(bank
, pin
- bank
->pin_base
, param
,
3021 mutex_unlock(&bank
->deferred_lock
);
3027 mutex_unlock(&bank
->deferred_lock
);
3031 case PIN_CONFIG_BIAS_DISABLE
:
3032 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
3037 case PIN_CONFIG_BIAS_PULL_UP
:
3038 case PIN_CONFIG_BIAS_PULL_DOWN
:
3039 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
3040 case PIN_CONFIG_BIAS_BUS_HOLD
:
3041 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
3047 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
3052 case PIN_CONFIG_OUTPUT
:
3053 rc
= rockchip_set_mux(bank
, pin
- bank
->pin_base
,
3055 if (rc
!= RK_FUNC_GPIO
)
3058 rc
= gpio
->direction_output(gpio
, pin
- bank
->pin_base
,
3063 case PIN_CONFIG_INPUT_ENABLE
:
3064 rc
= rockchip_set_mux(bank
, pin
- bank
->pin_base
,
3066 if (rc
!= RK_FUNC_GPIO
)
3069 rc
= gpio
->direction_input(gpio
, pin
- bank
->pin_base
);
3073 case PIN_CONFIG_DRIVE_STRENGTH
:
3074 /* rk3288 is the first with per-pin drive-strength */
3075 if (!info
->ctrl
->drv_calc_reg
)
3078 rc
= rockchip_set_drive_perpin(bank
,
3079 pin
- bank
->pin_base
, arg
);
3083 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
3084 if (!info
->ctrl
->schmitt_calc_reg
)
3087 rc
= rockchip_set_schmitt(bank
,
3088 pin
- bank
->pin_base
, arg
);
3096 } /* for each config */
3101 /* get the pin config settings for a specified pin */
3102 static int rockchip_pinconf_get(struct pinctrl_dev
*pctldev
, unsigned int pin
,
3103 unsigned long *config
)
3105 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
3106 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
3107 struct gpio_chip
*gpio
= &bank
->gpio_chip
;
3108 enum pin_config_param param
= pinconf_to_config_param(*config
);
3113 case PIN_CONFIG_BIAS_DISABLE
:
3114 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
3119 case PIN_CONFIG_BIAS_PULL_UP
:
3120 case PIN_CONFIG_BIAS_PULL_DOWN
:
3121 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
3122 case PIN_CONFIG_BIAS_BUS_HOLD
:
3123 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
3126 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
3131 case PIN_CONFIG_OUTPUT
:
3132 rc
= rockchip_get_mux(bank
, pin
- bank
->pin_base
);
3133 if (rc
!= RK_FUNC_GPIO
)
3136 if (!gpio
|| !gpio
->get
) {
3141 rc
= gpio
->get(gpio
, pin
- bank
->pin_base
);
3147 case PIN_CONFIG_DRIVE_STRENGTH
:
3148 /* rk3288 is the first with per-pin drive-strength */
3149 if (!info
->ctrl
->drv_calc_reg
)
3152 rc
= rockchip_get_drive_perpin(bank
, pin
- bank
->pin_base
);
3158 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
3159 if (!info
->ctrl
->schmitt_calc_reg
)
3162 rc
= rockchip_get_schmitt(bank
, pin
- bank
->pin_base
);
3173 *config
= pinconf_to_config_packed(param
, arg
);
3178 static const struct pinconf_ops rockchip_pinconf_ops
= {
3179 .pin_config_get
= rockchip_pinconf_get
,
3180 .pin_config_set
= rockchip_pinconf_set
,
3184 static const struct of_device_id rockchip_bank_match
[] = {
3185 { .compatible
= "rockchip,gpio-bank" },
3186 { .compatible
= "rockchip,rk3188-gpio-bank0" },
3190 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl
*info
,
3191 struct device_node
*np
)
3193 struct device_node
*child
;
3195 for_each_child_of_node(np
, child
) {
3196 if (of_match_node(rockchip_bank_match
, child
))
3200 info
->ngroups
+= of_get_child_count(child
);
3204 static int rockchip_pinctrl_parse_groups(struct device_node
*np
,
3205 struct rockchip_pin_group
*grp
,
3206 struct rockchip_pinctrl
*info
,
3209 struct device
*dev
= info
->dev
;
3210 struct rockchip_pin_bank
*bank
;
3217 dev_dbg(dev
, "group(%d): %pOFn\n", index
, np
);
3219 /* Initialise group */
3220 grp
->name
= np
->name
;
3223 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
3224 * do sanity check and calculate pins number
3226 list
= of_get_property(np
, "rockchip,pins", &size
);
3227 /* we do not check return since it's safe node passed down */
3228 size
/= sizeof(*list
);
3229 if (!size
|| size
% 4)
3230 return dev_err_probe(dev
, -EINVAL
,
3231 "%pOF: rockchip,pins: expected one or more of <bank pin mux CONFIG>, got %d args instead\n",
3234 grp
->npins
= size
/ 4;
3236 grp
->pins
= devm_kcalloc(dev
, grp
->npins
, sizeof(*grp
->pins
), GFP_KERNEL
);
3237 grp
->data
= devm_kcalloc(dev
, grp
->npins
, sizeof(*grp
->data
), GFP_KERNEL
);
3238 if (!grp
->pins
|| !grp
->data
)
3241 for (i
= 0, j
= 0; i
< size
; i
+= 4, j
++) {
3242 const __be32
*phandle
;
3243 struct device_node
*np_config
;
3245 num
= be32_to_cpu(*list
++);
3246 bank
= bank_num_to_bank(info
, num
);
3248 return PTR_ERR(bank
);
3250 grp
->pins
[j
] = bank
->pin_base
+ be32_to_cpu(*list
++);
3251 grp
->data
[j
].func
= be32_to_cpu(*list
++);
3257 np_config
= of_find_node_by_phandle(be32_to_cpup(phandle
));
3258 ret
= pinconf_generic_parse_dt_config(np_config
, NULL
,
3259 &grp
->data
[j
].configs
, &grp
->data
[j
].nconfigs
);
3260 of_node_put(np_config
);
3268 static int rockchip_pinctrl_parse_functions(struct device_node
*np
,
3269 struct rockchip_pinctrl
*info
,
3272 struct device
*dev
= info
->dev
;
3273 struct rockchip_pmx_func
*func
;
3274 struct rockchip_pin_group
*grp
;
3276 static u32 grp_index
;
3279 dev_dbg(dev
, "parse function(%d): %pOFn\n", index
, np
);
3281 func
= &info
->functions
[index
];
3283 /* Initialise function */
3284 func
->name
= np
->name
;
3285 func
->ngroups
= of_get_child_count(np
);
3286 if (func
->ngroups
<= 0)
3289 func
->groups
= devm_kcalloc(dev
, func
->ngroups
, sizeof(*func
->groups
), GFP_KERNEL
);
3293 for_each_child_of_node_scoped(np
, child
) {
3294 func
->groups
[i
] = child
->name
;
3295 grp
= &info
->groups
[grp_index
++];
3296 ret
= rockchip_pinctrl_parse_groups(child
, grp
, info
, i
++);
3304 static int rockchip_pinctrl_parse_dt(struct platform_device
*pdev
,
3305 struct rockchip_pinctrl
*info
)
3307 struct device
*dev
= &pdev
->dev
;
3308 struct device_node
*np
= dev
->of_node
;
3312 rockchip_pinctrl_child_count(info
, np
);
3314 dev_dbg(dev
, "nfunctions = %d\n", info
->nfunctions
);
3315 dev_dbg(dev
, "ngroups = %d\n", info
->ngroups
);
3317 info
->functions
= devm_kcalloc(dev
, info
->nfunctions
, sizeof(*info
->functions
), GFP_KERNEL
);
3318 if (!info
->functions
)
3321 info
->groups
= devm_kcalloc(dev
, info
->ngroups
, sizeof(*info
->groups
), GFP_KERNEL
);
3327 for_each_child_of_node_scoped(np
, child
) {
3328 if (of_match_node(rockchip_bank_match
, child
))
3331 ret
= rockchip_pinctrl_parse_functions(child
, info
, i
++);
3333 dev_err(dev
, "failed to parse function\n");
3341 static int rockchip_pinctrl_register(struct platform_device
*pdev
,
3342 struct rockchip_pinctrl
*info
)
3344 struct pinctrl_desc
*ctrldesc
= &info
->pctl
;
3345 struct pinctrl_pin_desc
*pindesc
, *pdesc
;
3346 struct rockchip_pin_bank
*pin_bank
;
3347 struct device
*dev
= &pdev
->dev
;
3352 ctrldesc
->name
= "rockchip-pinctrl";
3353 ctrldesc
->owner
= THIS_MODULE
;
3354 ctrldesc
->pctlops
= &rockchip_pctrl_ops
;
3355 ctrldesc
->pmxops
= &rockchip_pmx_ops
;
3356 ctrldesc
->confops
= &rockchip_pinconf_ops
;
3358 pindesc
= devm_kcalloc(dev
, info
->ctrl
->nr_pins
, sizeof(*pindesc
), GFP_KERNEL
);
3362 ctrldesc
->pins
= pindesc
;
3363 ctrldesc
->npins
= info
->ctrl
->nr_pins
;
3366 for (bank
= 0, k
= 0; bank
< info
->ctrl
->nr_banks
; bank
++) {
3367 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
3369 pin_names
= devm_kasprintf_strarray(dev
, pin_bank
->name
, pin_bank
->nr_pins
);
3370 if (IS_ERR(pin_names
))
3371 return PTR_ERR(pin_names
);
3373 for (pin
= 0; pin
< pin_bank
->nr_pins
; pin
++, k
++) {
3375 pdesc
->name
= pin_names
[pin
];
3379 INIT_LIST_HEAD(&pin_bank
->deferred_pins
);
3380 mutex_init(&pin_bank
->deferred_lock
);
3383 ret
= rockchip_pinctrl_parse_dt(pdev
, info
);
3387 info
->pctl_dev
= devm_pinctrl_register(dev
, ctrldesc
, info
);
3388 if (IS_ERR(info
->pctl_dev
))
3389 return dev_err_probe(dev
, PTR_ERR(info
->pctl_dev
), "could not register pinctrl driver\n");
3394 static const struct of_device_id rockchip_pinctrl_dt_match
[];
3396 /* retrieve the soc specific data */
3397 static struct rockchip_pin_ctrl
*rockchip_pinctrl_get_soc_data(
3398 struct rockchip_pinctrl
*d
,
3399 struct platform_device
*pdev
)
3401 struct device
*dev
= &pdev
->dev
;
3402 struct device_node
*node
= dev
->of_node
;
3403 const struct of_device_id
*match
;
3404 struct rockchip_pin_ctrl
*ctrl
;
3405 struct rockchip_pin_bank
*bank
;
3406 int grf_offs
, pmu_offs
, drv_grf_offs
, drv_pmu_offs
, i
, j
;
3408 match
= of_match_node(rockchip_pinctrl_dt_match
, node
);
3409 ctrl
= (struct rockchip_pin_ctrl
*)match
->data
;
3411 grf_offs
= ctrl
->grf_mux_offset
;
3412 pmu_offs
= ctrl
->pmu_mux_offset
;
3413 drv_pmu_offs
= ctrl
->pmu_drv_offset
;
3414 drv_grf_offs
= ctrl
->grf_drv_offset
;
3415 bank
= ctrl
->pin_banks
;
3416 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3419 raw_spin_lock_init(&bank
->slock
);
3421 bank
->pin_base
= ctrl
->nr_pins
;
3422 ctrl
->nr_pins
+= bank
->nr_pins
;
3424 /* calculate iomux and drv offsets */
3425 for (j
= 0; j
< 4; j
++) {
3426 struct rockchip_iomux
*iom
= &bank
->iomux
[j
];
3427 struct rockchip_drv
*drv
= &bank
->drv
[j
];
3430 if (bank_pins
>= bank
->nr_pins
)
3433 /* preset iomux offset value, set new start value */
3434 if (iom
->offset
>= 0) {
3435 if ((iom
->type
& IOMUX_SOURCE_PMU
) ||
3436 (iom
->type
& IOMUX_L_SOURCE_PMU
))
3437 pmu_offs
= iom
->offset
;
3439 grf_offs
= iom
->offset
;
3440 } else { /* set current iomux offset */
3441 iom
->offset
= ((iom
->type
& IOMUX_SOURCE_PMU
) ||
3442 (iom
->type
& IOMUX_L_SOURCE_PMU
)) ?
3443 pmu_offs
: grf_offs
;
3446 /* preset drv offset value, set new start value */
3447 if (drv
->offset
>= 0) {
3448 if (iom
->type
& IOMUX_SOURCE_PMU
)
3449 drv_pmu_offs
= drv
->offset
;
3451 drv_grf_offs
= drv
->offset
;
3452 } else { /* set current drv offset */
3453 drv
->offset
= (iom
->type
& IOMUX_SOURCE_PMU
) ?
3454 drv_pmu_offs
: drv_grf_offs
;
3457 dev_dbg(dev
, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3458 i
, j
, iom
->offset
, drv
->offset
);
3461 * Increase offset according to iomux width.
3462 * 4bit iomux'es are spread over two registers.
3464 inc
= (iom
->type
& (IOMUX_WIDTH_4BIT
|
3466 IOMUX_WIDTH_2BIT
)) ? 8 : 4;
3467 if ((iom
->type
& IOMUX_SOURCE_PMU
) || (iom
->type
& IOMUX_L_SOURCE_PMU
))
3473 * Increase offset according to drv width.
3474 * 3bit drive-strenth'es are spread over two registers.
3476 if ((drv
->drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
3477 (drv
->drv_type
== DRV_TYPE_IO_3V3_ONLY
))
3482 if (iom
->type
& IOMUX_SOURCE_PMU
)
3483 drv_pmu_offs
+= inc
;
3485 drv_grf_offs
+= inc
;
3490 /* calculate the per-bank recalced_mask */
3491 for (j
= 0; j
< ctrl
->niomux_recalced
; j
++) {
3494 if (ctrl
->iomux_recalced
[j
].num
== bank
->bank_num
) {
3495 pin
= ctrl
->iomux_recalced
[j
].pin
;
3496 bank
->recalced_mask
|= BIT(pin
);
3500 /* calculate the per-bank route_mask */
3501 for (j
= 0; j
< ctrl
->niomux_routes
; j
++) {
3504 if (ctrl
->iomux_routes
[j
].bank_num
== bank
->bank_num
) {
3505 pin
= ctrl
->iomux_routes
[j
].pin
;
3506 bank
->route_mask
|= BIT(pin
);
3514 #define RK3288_GRF_GPIO6C_IOMUX 0x64
3515 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3517 static u32 rk3288_grf_gpio6c_iomux
;
3519 static int __maybe_unused
rockchip_pinctrl_suspend(struct device
*dev
)
3521 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3522 int ret
= pinctrl_force_sleep(info
->pctl_dev
);
3528 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3529 * the setting here, and restore it at resume.
3531 if (info
->ctrl
->type
== RK3288
) {
3532 ret
= regmap_read(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3533 &rk3288_grf_gpio6c_iomux
);
3535 pinctrl_force_default(info
->pctl_dev
);
3543 static int __maybe_unused
rockchip_pinctrl_resume(struct device
*dev
)
3545 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3548 if (info
->ctrl
->type
== RK3288
) {
3549 ret
= regmap_write(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3550 rk3288_grf_gpio6c_iomux
|
3551 GPIO6C6_SEL_WRITE_ENABLE
);
3556 return pinctrl_force_default(info
->pctl_dev
);
3559 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops
, rockchip_pinctrl_suspend
,
3560 rockchip_pinctrl_resume
);
3562 static int rockchip_pinctrl_probe(struct platform_device
*pdev
)
3564 struct rockchip_pinctrl
*info
;
3565 struct device
*dev
= &pdev
->dev
;
3566 struct device_node
*np
= dev
->of_node
, *node
;
3567 struct rockchip_pin_ctrl
*ctrl
;
3568 struct resource
*res
;
3573 return dev_err_probe(dev
, -ENODEV
, "device tree node not found\n");
3575 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
3581 ctrl
= rockchip_pinctrl_get_soc_data(info
, pdev
);
3583 return dev_err_probe(dev
, -EINVAL
, "driver data not available\n");
3586 node
= of_parse_phandle(np
, "rockchip,grf", 0);
3588 info
->regmap_base
= syscon_node_to_regmap(node
);
3590 if (IS_ERR(info
->regmap_base
))
3591 return PTR_ERR(info
->regmap_base
);
3593 base
= devm_platform_get_and_ioremap_resource(pdev
, 0, &res
);
3595 return PTR_ERR(base
);
3597 rockchip_regmap_config
.max_register
= resource_size(res
) - 4;
3598 rockchip_regmap_config
.name
= "rockchip,pinctrl";
3600 devm_regmap_init_mmio(dev
, base
, &rockchip_regmap_config
);
3602 /* to check for the old dt-bindings */
3603 info
->reg_size
= resource_size(res
);
3605 /* Honor the old binding, with pull registers as 2nd resource */
3606 if (ctrl
->type
== RK3188
&& info
->reg_size
< 0x200) {
3607 base
= devm_platform_get_and_ioremap_resource(pdev
, 1, &res
);
3609 return PTR_ERR(base
);
3611 rockchip_regmap_config
.max_register
= resource_size(res
) - 4;
3612 rockchip_regmap_config
.name
= "rockchip,pinctrl-pull";
3614 devm_regmap_init_mmio(dev
, base
, &rockchip_regmap_config
);
3618 /* try to find the optional reference to the pmu syscon */
3619 node
= of_parse_phandle(np
, "rockchip,pmu", 0);
3621 info
->regmap_pmu
= syscon_node_to_regmap(node
);
3623 if (IS_ERR(info
->regmap_pmu
))
3624 return PTR_ERR(info
->regmap_pmu
);
3627 ret
= rockchip_pinctrl_register(pdev
, info
);
3631 platform_set_drvdata(pdev
, info
);
3633 ret
= of_platform_populate(np
, NULL
, NULL
, &pdev
->dev
);
3635 return dev_err_probe(dev
, ret
, "failed to register gpio device\n");
3640 static void rockchip_pinctrl_remove(struct platform_device
*pdev
)
3642 struct rockchip_pinctrl
*info
= platform_get_drvdata(pdev
);
3643 struct rockchip_pin_bank
*bank
;
3644 struct rockchip_pin_deferred
*cfg
;
3647 of_platform_depopulate(&pdev
->dev
);
3649 for (i
= 0; i
< info
->ctrl
->nr_banks
; i
++) {
3650 bank
= &info
->ctrl
->pin_banks
[i
];
3652 mutex_lock(&bank
->deferred_lock
);
3653 while (!list_empty(&bank
->deferred_pins
)) {
3654 cfg
= list_first_entry(&bank
->deferred_pins
,
3655 struct rockchip_pin_deferred
, head
);
3656 list_del(&cfg
->head
);
3659 mutex_unlock(&bank
->deferred_lock
);
3663 static struct rockchip_pin_bank px30_pin_banks
[] = {
3664 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3669 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT
,
3674 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT
,
3679 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT
,
3686 static struct rockchip_pin_ctrl px30_pin_ctrl
= {
3687 .pin_banks
= px30_pin_banks
,
3688 .nr_banks
= ARRAY_SIZE(px30_pin_banks
),
3689 .label
= "PX30-GPIO",
3691 .grf_mux_offset
= 0x0,
3692 .pmu_mux_offset
= 0x0,
3693 .iomux_routes
= px30_mux_route_data
,
3694 .niomux_routes
= ARRAY_SIZE(px30_mux_route_data
),
3695 .pull_calc_reg
= px30_calc_pull_reg_and_bit
,
3696 .drv_calc_reg
= px30_calc_drv_reg_and_bit
,
3697 .schmitt_calc_reg
= px30_calc_schmitt_reg_and_bit
,
3700 static struct rockchip_pin_bank rv1108_pin_banks
[] = {
3701 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3705 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3706 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3707 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3710 static struct rockchip_pin_ctrl rv1108_pin_ctrl
= {
3711 .pin_banks
= rv1108_pin_banks
,
3712 .nr_banks
= ARRAY_SIZE(rv1108_pin_banks
),
3713 .label
= "RV1108-GPIO",
3715 .grf_mux_offset
= 0x10,
3716 .pmu_mux_offset
= 0x0,
3717 .iomux_recalced
= rv1108_mux_recalced_data
,
3718 .niomux_recalced
= ARRAY_SIZE(rv1108_mux_recalced_data
),
3719 .pull_calc_reg
= rv1108_calc_pull_reg_and_bit
,
3720 .drv_calc_reg
= rv1108_calc_drv_reg_and_bit
,
3721 .schmitt_calc_reg
= rv1108_calc_schmitt_reg_and_bit
,
3724 static struct rockchip_pin_bank rv1126_pin_banks
[] = {
3725 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0",
3726 IOMUX_WIDTH_4BIT
| IOMUX_SOURCE_PMU
,
3727 IOMUX_WIDTH_4BIT
| IOMUX_SOURCE_PMU
,
3728 IOMUX_WIDTH_4BIT
| IOMUX_L_SOURCE_PMU
,
3730 PIN_BANK_IOMUX_FLAGS_OFFSET(1, 32, "gpio1",
3735 0x10010, 0x10018, 0x10020, 0x10028),
3736 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2",
3741 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3746 PIN_BANK_IOMUX_FLAGS(4, 2, "gpio4",
3747 IOMUX_WIDTH_4BIT
, 0, 0, 0),
3750 static struct rockchip_pin_ctrl rv1126_pin_ctrl
= {
3751 .pin_banks
= rv1126_pin_banks
,
3752 .nr_banks
= ARRAY_SIZE(rv1126_pin_banks
),
3753 .label
= "RV1126-GPIO",
3755 .grf_mux_offset
= 0x10004, /* mux offset from GPIO0_D0 */
3756 .pmu_mux_offset
= 0x0,
3757 .iomux_routes
= rv1126_mux_route_data
,
3758 .niomux_routes
= ARRAY_SIZE(rv1126_mux_route_data
),
3759 .iomux_recalced
= rv1126_mux_recalced_data
,
3760 .niomux_recalced
= ARRAY_SIZE(rv1126_mux_recalced_data
),
3761 .pull_calc_reg
= rv1126_calc_pull_reg_and_bit
,
3762 .drv_calc_reg
= rv1126_calc_drv_reg_and_bit
,
3763 .schmitt_calc_reg
= rv1126_calc_schmitt_reg_and_bit
,
3766 static struct rockchip_pin_bank rk2928_pin_banks
[] = {
3767 PIN_BANK(0, 32, "gpio0"),
3768 PIN_BANK(1, 32, "gpio1"),
3769 PIN_BANK(2, 32, "gpio2"),
3770 PIN_BANK(3, 32, "gpio3"),
3773 static struct rockchip_pin_ctrl rk2928_pin_ctrl
= {
3774 .pin_banks
= rk2928_pin_banks
,
3775 .nr_banks
= ARRAY_SIZE(rk2928_pin_banks
),
3776 .label
= "RK2928-GPIO",
3778 .grf_mux_offset
= 0xa8,
3779 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3782 static struct rockchip_pin_bank rk3036_pin_banks
[] = {
3783 PIN_BANK(0, 32, "gpio0"),
3784 PIN_BANK(1, 32, "gpio1"),
3785 PIN_BANK(2, 32, "gpio2"),
3788 static struct rockchip_pin_ctrl rk3036_pin_ctrl
= {
3789 .pin_banks
= rk3036_pin_banks
,
3790 .nr_banks
= ARRAY_SIZE(rk3036_pin_banks
),
3791 .label
= "RK3036-GPIO",
3793 .grf_mux_offset
= 0xa8,
3794 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3797 static struct rockchip_pin_bank rk3066a_pin_banks
[] = {
3798 PIN_BANK(0, 32, "gpio0"),
3799 PIN_BANK(1, 32, "gpio1"),
3800 PIN_BANK(2, 32, "gpio2"),
3801 PIN_BANK(3, 32, "gpio3"),
3802 PIN_BANK(4, 32, "gpio4"),
3803 PIN_BANK(6, 16, "gpio6"),
3806 static struct rockchip_pin_ctrl rk3066a_pin_ctrl
= {
3807 .pin_banks
= rk3066a_pin_banks
,
3808 .nr_banks
= ARRAY_SIZE(rk3066a_pin_banks
),
3809 .label
= "RK3066a-GPIO",
3811 .grf_mux_offset
= 0xa8,
3812 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3815 static struct rockchip_pin_bank rk3066b_pin_banks
[] = {
3816 PIN_BANK(0, 32, "gpio0"),
3817 PIN_BANK(1, 32, "gpio1"),
3818 PIN_BANK(2, 32, "gpio2"),
3819 PIN_BANK(3, 32, "gpio3"),
3822 static struct rockchip_pin_ctrl rk3066b_pin_ctrl
= {
3823 .pin_banks
= rk3066b_pin_banks
,
3824 .nr_banks
= ARRAY_SIZE(rk3066b_pin_banks
),
3825 .label
= "RK3066b-GPIO",
3827 .grf_mux_offset
= 0x60,
3830 static struct rockchip_pin_bank rk3128_pin_banks
[] = {
3831 PIN_BANK(0, 32, "gpio0"),
3832 PIN_BANK(1, 32, "gpio1"),
3833 PIN_BANK(2, 32, "gpio2"),
3834 PIN_BANK(3, 32, "gpio3"),
3837 static struct rockchip_pin_ctrl rk3128_pin_ctrl
= {
3838 .pin_banks
= rk3128_pin_banks
,
3839 .nr_banks
= ARRAY_SIZE(rk3128_pin_banks
),
3840 .label
= "RK3128-GPIO",
3842 .grf_mux_offset
= 0xa8,
3843 .iomux_recalced
= rk3128_mux_recalced_data
,
3844 .niomux_recalced
= ARRAY_SIZE(rk3128_mux_recalced_data
),
3845 .iomux_routes
= rk3128_mux_route_data
,
3846 .niomux_routes
= ARRAY_SIZE(rk3128_mux_route_data
),
3847 .pull_calc_reg
= rk3128_calc_pull_reg_and_bit
,
3850 static struct rockchip_pin_bank rk3188_pin_banks
[] = {
3851 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY
, 0, 0, 0),
3852 PIN_BANK(1, 32, "gpio1"),
3853 PIN_BANK(2, 32, "gpio2"),
3854 PIN_BANK(3, 32, "gpio3"),
3857 static struct rockchip_pin_ctrl rk3188_pin_ctrl
= {
3858 .pin_banks
= rk3188_pin_banks
,
3859 .nr_banks
= ARRAY_SIZE(rk3188_pin_banks
),
3860 .label
= "RK3188-GPIO",
3862 .grf_mux_offset
= 0x60,
3863 .iomux_routes
= rk3188_mux_route_data
,
3864 .niomux_routes
= ARRAY_SIZE(rk3188_mux_route_data
),
3865 .pull_calc_reg
= rk3188_calc_pull_reg_and_bit
,
3868 static struct rockchip_pin_bank rk3228_pin_banks
[] = {
3869 PIN_BANK(0, 32, "gpio0"),
3870 PIN_BANK(1, 32, "gpio1"),
3871 PIN_BANK(2, 32, "gpio2"),
3872 PIN_BANK(3, 32, "gpio3"),
3875 static struct rockchip_pin_ctrl rk3228_pin_ctrl
= {
3876 .pin_banks
= rk3228_pin_banks
,
3877 .nr_banks
= ARRAY_SIZE(rk3228_pin_banks
),
3878 .label
= "RK3228-GPIO",
3880 .grf_mux_offset
= 0x0,
3881 .iomux_routes
= rk3228_mux_route_data
,
3882 .niomux_routes
= ARRAY_SIZE(rk3228_mux_route_data
),
3883 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
3884 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
3887 static struct rockchip_pin_bank rk3288_pin_banks
[] = {
3888 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU
,
3893 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED
,
3898 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED
),
3899 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT
),
3900 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT
,
3905 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED
,
3910 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED
),
3911 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3916 PIN_BANK(8, 16, "gpio8"),
3919 static struct rockchip_pin_ctrl rk3288_pin_ctrl
= {
3920 .pin_banks
= rk3288_pin_banks
,
3921 .nr_banks
= ARRAY_SIZE(rk3288_pin_banks
),
3922 .label
= "RK3288-GPIO",
3924 .grf_mux_offset
= 0x0,
3925 .pmu_mux_offset
= 0x84,
3926 .iomux_routes
= rk3288_mux_route_data
,
3927 .niomux_routes
= ARRAY_SIZE(rk3288_mux_route_data
),
3928 .pull_calc_reg
= rk3288_calc_pull_reg_and_bit
,
3929 .drv_calc_reg
= rk3288_calc_drv_reg_and_bit
,
3932 static struct rockchip_pin_bank rk3308_pin_banks
[] = {
3933 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT
,
3937 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT
,
3941 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT
,
3945 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT
,
3949 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT
,
3955 static struct rockchip_pin_ctrl rk3308_pin_ctrl
= {
3956 .pin_banks
= rk3308_pin_banks
,
3957 .nr_banks
= ARRAY_SIZE(rk3308_pin_banks
),
3958 .label
= "RK3308-GPIO",
3960 .grf_mux_offset
= 0x0,
3961 .iomux_recalced
= rk3308_mux_recalced_data
,
3962 .niomux_recalced
= ARRAY_SIZE(rk3308_mux_recalced_data
),
3963 .iomux_routes
= rk3308_mux_route_data
,
3964 .niomux_routes
= ARRAY_SIZE(rk3308_mux_route_data
),
3965 .pull_calc_reg
= rk3308_calc_pull_reg_and_bit
,
3966 .drv_calc_reg
= rk3308_calc_drv_reg_and_bit
,
3967 .schmitt_calc_reg
= rk3308_calc_schmitt_reg_and_bit
,
3970 static struct rockchip_pin_bank rk3328_pin_banks
[] = {
3971 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3972 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3973 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3977 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3984 static struct rockchip_pin_ctrl rk3328_pin_ctrl
= {
3985 .pin_banks
= rk3328_pin_banks
,
3986 .nr_banks
= ARRAY_SIZE(rk3328_pin_banks
),
3987 .label
= "RK3328-GPIO",
3989 .grf_mux_offset
= 0x0,
3990 .iomux_recalced
= rk3328_mux_recalced_data
,
3991 .niomux_recalced
= ARRAY_SIZE(rk3328_mux_recalced_data
),
3992 .iomux_routes
= rk3328_mux_route_data
,
3993 .niomux_routes
= ARRAY_SIZE(rk3328_mux_route_data
),
3994 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
3995 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
3996 .schmitt_calc_reg
= rk3328_calc_schmitt_reg_and_bit
,
3999 static struct rockchip_pin_bank rk3368_pin_banks
[] = {
4000 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
4005 PIN_BANK(1, 32, "gpio1"),
4006 PIN_BANK(2, 32, "gpio2"),
4007 PIN_BANK(3, 32, "gpio3"),
4010 static struct rockchip_pin_ctrl rk3368_pin_ctrl
= {
4011 .pin_banks
= rk3368_pin_banks
,
4012 .nr_banks
= ARRAY_SIZE(rk3368_pin_banks
),
4013 .label
= "RK3368-GPIO",
4015 .grf_mux_offset
= 0x0,
4016 .pmu_mux_offset
= 0x0,
4017 .pull_calc_reg
= rk3368_calc_pull_reg_and_bit
,
4018 .drv_calc_reg
= rk3368_calc_drv_reg_and_bit
,
4021 static struct rockchip_pin_bank rk3399_pin_banks
[] = {
4022 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
4027 DRV_TYPE_IO_1V8_ONLY
,
4028 DRV_TYPE_IO_1V8_ONLY
,
4029 DRV_TYPE_IO_DEFAULT
,
4030 DRV_TYPE_IO_DEFAULT
,
4035 PULL_TYPE_IO_1V8_ONLY
,
4036 PULL_TYPE_IO_1V8_ONLY
,
4037 PULL_TYPE_IO_DEFAULT
,
4038 PULL_TYPE_IO_DEFAULT
4040 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU
,
4044 DRV_TYPE_IO_1V8_OR_3V0
,
4045 DRV_TYPE_IO_1V8_OR_3V0
,
4046 DRV_TYPE_IO_1V8_OR_3V0
,
4047 DRV_TYPE_IO_1V8_OR_3V0
,
4053 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0
,
4054 DRV_TYPE_IO_1V8_OR_3V0
,
4055 DRV_TYPE_IO_1V8_ONLY
,
4056 DRV_TYPE_IO_1V8_ONLY
,
4057 PULL_TYPE_IO_DEFAULT
,
4058 PULL_TYPE_IO_DEFAULT
,
4059 PULL_TYPE_IO_1V8_ONLY
,
4060 PULL_TYPE_IO_1V8_ONLY
4062 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY
,
4063 DRV_TYPE_IO_3V3_ONLY
,
4064 DRV_TYPE_IO_3V3_ONLY
,
4065 DRV_TYPE_IO_1V8_OR_3V0
4067 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0
,
4068 DRV_TYPE_IO_1V8_3V0_AUTO
,
4069 DRV_TYPE_IO_1V8_OR_3V0
,
4070 DRV_TYPE_IO_1V8_OR_3V0
4074 static struct rockchip_pin_ctrl rk3399_pin_ctrl
= {
4075 .pin_banks
= rk3399_pin_banks
,
4076 .nr_banks
= ARRAY_SIZE(rk3399_pin_banks
),
4077 .label
= "RK3399-GPIO",
4079 .grf_mux_offset
= 0xe000,
4080 .pmu_mux_offset
= 0x0,
4081 .grf_drv_offset
= 0xe100,
4082 .pmu_drv_offset
= 0x80,
4083 .iomux_routes
= rk3399_mux_route_data
,
4084 .niomux_routes
= ARRAY_SIZE(rk3399_mux_route_data
),
4085 .pull_calc_reg
= rk3399_calc_pull_reg_and_bit
,
4086 .drv_calc_reg
= rk3399_calc_drv_reg_and_bit
,
4089 static struct rockchip_pin_bank rk3568_pin_banks
[] = {
4090 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
| IOMUX_WIDTH_4BIT
,
4091 IOMUX_SOURCE_PMU
| IOMUX_WIDTH_4BIT
,
4092 IOMUX_SOURCE_PMU
| IOMUX_WIDTH_4BIT
,
4093 IOMUX_SOURCE_PMU
| IOMUX_WIDTH_4BIT
),
4094 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT
,
4098 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT
,
4102 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT
,
4106 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT
,
4112 static struct rockchip_pin_ctrl rk3568_pin_ctrl
= {
4113 .pin_banks
= rk3568_pin_banks
,
4114 .nr_banks
= ARRAY_SIZE(rk3568_pin_banks
),
4115 .label
= "RK3568-GPIO",
4117 .grf_mux_offset
= 0x0,
4118 .pmu_mux_offset
= 0x0,
4119 .grf_drv_offset
= 0x0200,
4120 .pmu_drv_offset
= 0x0070,
4121 .iomux_routes
= rk3568_mux_route_data
,
4122 .niomux_routes
= ARRAY_SIZE(rk3568_mux_route_data
),
4123 .pull_calc_reg
= rk3568_calc_pull_reg_and_bit
,
4124 .drv_calc_reg
= rk3568_calc_drv_reg_and_bit
,
4125 .schmitt_calc_reg
= rk3568_calc_schmitt_reg_and_bit
,
4128 #define RK3576_PIN_BANK(ID, LABEL, OFFSET0, OFFSET1, OFFSET2, OFFSET3) \
4129 PIN_BANK_IOMUX_FLAGS_OFFSET_PULL_FLAGS(ID, 32, LABEL, \
4136 PULL_TYPE_IO_1V8_ONLY, \
4137 PULL_TYPE_IO_1V8_ONLY, \
4138 PULL_TYPE_IO_1V8_ONLY, \
4139 PULL_TYPE_IO_1V8_ONLY)
4141 static struct rockchip_pin_bank rk3576_pin_banks
[] = {
4142 RK3576_PIN_BANK(0, "gpio0", 0, 0x8, 0x2004, 0x200C),
4143 RK3576_PIN_BANK(1, "gpio1", 0x4020, 0x4028, 0x4030, 0x4038),
4144 RK3576_PIN_BANK(2, "gpio2", 0x4040, 0x4048, 0x4050, 0x4058),
4145 RK3576_PIN_BANK(3, "gpio3", 0x4060, 0x4068, 0x4070, 0x4078),
4146 RK3576_PIN_BANK(4, "gpio4", 0x4080, 0x4088, 0xA390, 0xB398),
4149 static struct rockchip_pin_ctrl rk3576_pin_ctrl __maybe_unused
= {
4150 .pin_banks
= rk3576_pin_banks
,
4151 .nr_banks
= ARRAY_SIZE(rk3576_pin_banks
),
4152 .label
= "RK3576-GPIO",
4154 .pull_calc_reg
= rk3576_calc_pull_reg_and_bit
,
4155 .drv_calc_reg
= rk3576_calc_drv_reg_and_bit
,
4156 .schmitt_calc_reg
= rk3576_calc_schmitt_reg_and_bit
,
4159 static struct rockchip_pin_bank rk3588_pin_banks
[] = {
4160 RK3588_PIN_BANK_FLAGS(0, 32, "gpio0",
4161 IOMUX_WIDTH_4BIT
, PULL_TYPE_IO_1V8_ONLY
),
4162 RK3588_PIN_BANK_FLAGS(1, 32, "gpio1",
4163 IOMUX_WIDTH_4BIT
, PULL_TYPE_IO_1V8_ONLY
),
4164 RK3588_PIN_BANK_FLAGS(2, 32, "gpio2",
4165 IOMUX_WIDTH_4BIT
, PULL_TYPE_IO_1V8_ONLY
),
4166 RK3588_PIN_BANK_FLAGS(3, 32, "gpio3",
4167 IOMUX_WIDTH_4BIT
, PULL_TYPE_IO_1V8_ONLY
),
4168 RK3588_PIN_BANK_FLAGS(4, 32, "gpio4",
4169 IOMUX_WIDTH_4BIT
, PULL_TYPE_IO_1V8_ONLY
),
4172 static struct rockchip_pin_ctrl rk3588_pin_ctrl
= {
4173 .pin_banks
= rk3588_pin_banks
,
4174 .nr_banks
= ARRAY_SIZE(rk3588_pin_banks
),
4175 .label
= "RK3588-GPIO",
4177 .pull_calc_reg
= rk3588_calc_pull_reg_and_bit
,
4178 .drv_calc_reg
= rk3588_calc_drv_reg_and_bit
,
4179 .schmitt_calc_reg
= rk3588_calc_schmitt_reg_and_bit
,
4182 static const struct of_device_id rockchip_pinctrl_dt_match
[] = {
4183 { .compatible
= "rockchip,px30-pinctrl",
4184 .data
= &px30_pin_ctrl
},
4185 { .compatible
= "rockchip,rv1108-pinctrl",
4186 .data
= &rv1108_pin_ctrl
},
4187 { .compatible
= "rockchip,rv1126-pinctrl",
4188 .data
= &rv1126_pin_ctrl
},
4189 { .compatible
= "rockchip,rk2928-pinctrl",
4190 .data
= &rk2928_pin_ctrl
},
4191 { .compatible
= "rockchip,rk3036-pinctrl",
4192 .data
= &rk3036_pin_ctrl
},
4193 { .compatible
= "rockchip,rk3066a-pinctrl",
4194 .data
= &rk3066a_pin_ctrl
},
4195 { .compatible
= "rockchip,rk3066b-pinctrl",
4196 .data
= &rk3066b_pin_ctrl
},
4197 { .compatible
= "rockchip,rk3128-pinctrl",
4198 .data
= (void *)&rk3128_pin_ctrl
},
4199 { .compatible
= "rockchip,rk3188-pinctrl",
4200 .data
= &rk3188_pin_ctrl
},
4201 { .compatible
= "rockchip,rk3228-pinctrl",
4202 .data
= &rk3228_pin_ctrl
},
4203 { .compatible
= "rockchip,rk3288-pinctrl",
4204 .data
= &rk3288_pin_ctrl
},
4205 { .compatible
= "rockchip,rk3308-pinctrl",
4206 .data
= &rk3308_pin_ctrl
},
4207 { .compatible
= "rockchip,rk3328-pinctrl",
4208 .data
= &rk3328_pin_ctrl
},
4209 { .compatible
= "rockchip,rk3368-pinctrl",
4210 .data
= &rk3368_pin_ctrl
},
4211 { .compatible
= "rockchip,rk3399-pinctrl",
4212 .data
= &rk3399_pin_ctrl
},
4213 { .compatible
= "rockchip,rk3568-pinctrl",
4214 .data
= &rk3568_pin_ctrl
},
4215 { .compatible
= "rockchip,rk3576-pinctrl",
4216 .data
= &rk3576_pin_ctrl
},
4217 { .compatible
= "rockchip,rk3588-pinctrl",
4218 .data
= &rk3588_pin_ctrl
},
4222 static struct platform_driver rockchip_pinctrl_driver
= {
4223 .probe
= rockchip_pinctrl_probe
,
4224 .remove
= rockchip_pinctrl_remove
,
4226 .name
= "rockchip-pinctrl",
4227 .pm
= &rockchip_pinctrl_dev_pm_ops
,
4228 .of_match_table
= rockchip_pinctrl_dt_match
,
4232 static int __init
rockchip_pinctrl_drv_register(void)
4234 return platform_driver_register(&rockchip_pinctrl_driver
);
4236 postcore_initcall(rockchip_pinctrl_drv_register
);
4238 static void __exit
rockchip_pinctrl_drv_unregister(void)
4240 platform_driver_unregister(&rockchip_pinctrl_driver
);
4242 module_exit(rockchip_pinctrl_drv_unregister
);
4244 MODULE_DESCRIPTION("ROCKCHIP Pin Controller Driver");
4245 MODULE_LICENSE("GPL");
4246 MODULE_ALIAS("platform:pinctrl-rockchip");
4247 MODULE_DEVICE_TABLE(of
, rockchip_pinctrl_dt_match
);