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 * http://www.linaro.org
15 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
21 #include <linux/bitops.h>
22 #include <linux/gpio/driver.h>
23 #include <linux/of_address.h>
24 #include <linux/of_irq.h>
25 #include <linux/pinctrl/machine.h>
26 #include <linux/pinctrl/pinconf.h>
27 #include <linux/pinctrl/pinctrl.h>
28 #include <linux/pinctrl/pinmux.h>
29 #include <linux/pinctrl/pinconf-generic.h>
30 #include <linux/irqchip/chained_irq.h>
31 #include <linux/clk.h>
32 #include <linux/regmap.h>
33 #include <linux/mfd/syscon.h>
34 #include <dt-bindings/pinctrl/rockchip.h>
39 /* GPIO control registers */
40 #define GPIO_SWPORT_DR 0x00
41 #define GPIO_SWPORT_DDR 0x04
42 #define GPIO_INTEN 0x30
43 #define GPIO_INTMASK 0x34
44 #define GPIO_INTTYPE_LEVEL 0x38
45 #define GPIO_INT_POLARITY 0x3c
46 #define GPIO_INT_STATUS 0x40
47 #define GPIO_INT_RAWSTATUS 0x44
48 #define GPIO_DEBOUNCE 0x48
49 #define GPIO_PORTS_EOI 0x4c
50 #define GPIO_EXT_PORT 0x50
51 #define GPIO_LS_SYNC 0x60
53 enum rockchip_pinctrl_type
{
67 * Encode variants of iomux registers into a type variable
69 #define IOMUX_GPIO_ONLY BIT(0)
70 #define IOMUX_WIDTH_4BIT BIT(1)
71 #define IOMUX_SOURCE_PMU BIT(2)
72 #define IOMUX_UNROUTED BIT(3)
73 #define IOMUX_WIDTH_3BIT BIT(4)
74 #define IOMUX_WIDTH_2BIT BIT(5)
77 * @type: iomux variant using IOMUX_* constants
78 * @offset: if initialized to -1 it will be autocalculated, by specifying
79 * an initial offset value the relevant source offset can be reset
80 * to a new value for autocalculating the following iomux registers.
82 struct rockchip_iomux
{
88 * enum type index corresponding to rockchip_perpin_drv_list arrays index.
90 enum rockchip_pin_drv_type
{
91 DRV_TYPE_IO_DEFAULT
= 0,
92 DRV_TYPE_IO_1V8_OR_3V0
,
94 DRV_TYPE_IO_1V8_3V0_AUTO
,
100 * enum type index corresponding to rockchip_pull_list arrays index.
102 enum rockchip_pin_pull_type
{
103 PULL_TYPE_IO_DEFAULT
= 0,
104 PULL_TYPE_IO_1V8_ONLY
,
109 * @drv_type: drive strength variant using rockchip_perpin_drv_type
110 * @offset: if initialized to -1 it will be autocalculated, by specifying
111 * an initial offset value the relevant source offset can be reset
112 * to a new value for autocalculating the following drive strength
113 * registers. if used chips own cal_drv func instead to calculate
114 * registers offset, the variant could be ignored.
116 struct rockchip_drv
{
117 enum rockchip_pin_drv_type drv_type
;
122 * @reg_base: register base of the gpio bank
123 * @reg_pull: optional separate register for additional pull settings
124 * @clk: clock of the gpio bank
125 * @irq: interrupt of the gpio bank
126 * @saved_masks: Saved content of GPIO_INTEN at suspend time.
127 * @pin_base: first pin number
128 * @nr_pins: number of pins in this bank
129 * @name: name of the bank
130 * @bank_num: number of the bank, to account for holes
131 * @iomux: array describing the 4 iomux sources of the bank
132 * @drv: array describing the 4 drive strength sources of the bank
133 * @pull_type: array describing the 4 pull type sources of the bank
134 * @valid: is all necessary information present
135 * @of_node: dt node of this bank
136 * @drvdata: common pinctrl basedata
137 * @domain: irqdomain of the gpio bank
138 * @gpio_chip: gpiolib chip
139 * @grange: gpio range
140 * @slock: spinlock for the gpio bank
141 * @route_mask: bits describing the routing pins of per bank
143 struct rockchip_pin_bank
{
144 void __iomem
*reg_base
;
145 struct regmap
*regmap_pull
;
153 struct rockchip_iomux iomux
[4];
154 struct rockchip_drv drv
[4];
155 enum rockchip_pin_pull_type pull_type
[4];
157 struct device_node
*of_node
;
158 struct rockchip_pinctrl
*drvdata
;
159 struct irq_domain
*domain
;
160 struct gpio_chip gpio_chip
;
161 struct pinctrl_gpio_range grange
;
162 raw_spinlock_t slock
;
163 u32 toggle_edge_mode
;
168 #define PIN_BANK(id, pins, label) \
181 #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
187 { .type = iom0, .offset = -1 }, \
188 { .type = iom1, .offset = -1 }, \
189 { .type = iom2, .offset = -1 }, \
190 { .type = iom3, .offset = -1 }, \
194 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
206 { .drv_type = type0, .offset = -1 }, \
207 { .drv_type = type1, .offset = -1 }, \
208 { .drv_type = type2, .offset = -1 }, \
209 { .drv_type = type3, .offset = -1 }, \
213 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
214 drv2, drv3, pull0, pull1, \
227 { .drv_type = drv0, .offset = -1 }, \
228 { .drv_type = drv1, .offset = -1 }, \
229 { .drv_type = drv2, .offset = -1 }, \
230 { .drv_type = drv3, .offset = -1 }, \
232 .pull_type[0] = pull0, \
233 .pull_type[1] = pull1, \
234 .pull_type[2] = pull2, \
235 .pull_type[3] = pull3, \
238 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
239 iom2, iom3, drv0, drv1, drv2, \
240 drv3, offset0, offset1, \
247 { .type = iom0, .offset = -1 }, \
248 { .type = iom1, .offset = -1 }, \
249 { .type = iom2, .offset = -1 }, \
250 { .type = iom3, .offset = -1 }, \
253 { .drv_type = drv0, .offset = offset0 }, \
254 { .drv_type = drv1, .offset = offset1 }, \
255 { .drv_type = drv2, .offset = offset2 }, \
256 { .drv_type = drv3, .offset = offset3 }, \
260 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
261 label, iom0, iom1, iom2, \
262 iom3, drv0, drv1, drv2, \
263 drv3, offset0, offset1, \
264 offset2, offset3, pull0, \
265 pull1, pull2, pull3) \
271 { .type = iom0, .offset = -1 }, \
272 { .type = iom1, .offset = -1 }, \
273 { .type = iom2, .offset = -1 }, \
274 { .type = iom3, .offset = -1 }, \
277 { .drv_type = drv0, .offset = offset0 }, \
278 { .drv_type = drv1, .offset = offset1 }, \
279 { .drv_type = drv2, .offset = offset2 }, \
280 { .drv_type = drv3, .offset = offset3 }, \
282 .pull_type[0] = pull0, \
283 .pull_type[1] = pull1, \
284 .pull_type[2] = pull2, \
285 .pull_type[3] = pull3, \
289 * struct rockchip_mux_recalced_data: represent a pin iomux data.
292 * @bit: index at register.
293 * @reg: register offset.
296 struct rockchip_mux_recalced_data
{
304 enum rockchip_mux_route_location
{
305 ROCKCHIP_ROUTE_SAME
= 0,
311 * struct rockchip_mux_recalced_data: represent a pin iomux data.
312 * @bank_num: bank number.
313 * @pin: index at register or used to calc index.
314 * @func: the min pin.
315 * @route_offset: the max pin.
316 * @route_val: the register offset.
318 struct rockchip_mux_route_data
{
322 enum rockchip_mux_route_location route_location
;
329 struct rockchip_pin_ctrl
{
330 struct rockchip_pin_bank
*pin_banks
;
334 enum rockchip_pinctrl_type type
;
339 struct rockchip_mux_recalced_data
*iomux_recalced
;
341 struct rockchip_mux_route_data
*iomux_routes
;
344 void (*pull_calc_reg
)(struct rockchip_pin_bank
*bank
,
345 int pin_num
, struct regmap
**regmap
,
347 void (*drv_calc_reg
)(struct rockchip_pin_bank
*bank
,
348 int pin_num
, struct regmap
**regmap
,
350 int (*schmitt_calc_reg
)(struct rockchip_pin_bank
*bank
,
351 int pin_num
, struct regmap
**regmap
,
355 struct rockchip_pin_config
{
357 unsigned long *configs
;
358 unsigned int nconfigs
;
362 * struct rockchip_pin_group: represent group of pins of a pinmux function.
363 * @name: name of the pin group, used to lookup the group.
364 * @pins: the pins included in this group.
365 * @npins: number of pins included in this group.
366 * @func: the mux function number to be programmed when selected.
367 * @configs: the config values to be set for each pin
368 * @nconfigs: number of configs for each pin
370 struct rockchip_pin_group
{
374 struct rockchip_pin_config
*data
;
378 * struct rockchip_pmx_func: represent a pin function.
379 * @name: name of the pin function, used to lookup the function.
380 * @groups: one or more names of pin groups that provide this function.
381 * @num_groups: number of groups included in @groups.
383 struct rockchip_pmx_func
{
389 struct rockchip_pinctrl
{
390 struct regmap
*regmap_base
;
392 struct regmap
*regmap_pull
;
393 struct regmap
*regmap_pmu
;
395 struct rockchip_pin_ctrl
*ctrl
;
396 struct pinctrl_desc pctl
;
397 struct pinctrl_dev
*pctl_dev
;
398 struct rockchip_pin_group
*groups
;
399 unsigned int ngroups
;
400 struct rockchip_pmx_func
*functions
;
401 unsigned int nfunctions
;
404 static struct regmap_config rockchip_regmap_config
= {
410 static inline const struct rockchip_pin_group
*pinctrl_name_to_group(
411 const struct rockchip_pinctrl
*info
,
416 for (i
= 0; i
< info
->ngroups
; i
++) {
417 if (!strcmp(info
->groups
[i
].name
, name
))
418 return &info
->groups
[i
];
425 * given a pin number that is local to a pin controller, find out the pin bank
426 * and the register base of the pin bank.
428 static struct rockchip_pin_bank
*pin_to_bank(struct rockchip_pinctrl
*info
,
431 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
433 while (pin
>= (b
->pin_base
+ b
->nr_pins
))
439 static struct rockchip_pin_bank
*bank_num_to_bank(
440 struct rockchip_pinctrl
*info
,
443 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
446 for (i
= 0; i
< info
->ctrl
->nr_banks
; i
++, b
++) {
447 if (b
->bank_num
== num
)
451 return ERR_PTR(-EINVAL
);
455 * Pinctrl_ops handling
458 static int rockchip_get_groups_count(struct pinctrl_dev
*pctldev
)
460 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
462 return info
->ngroups
;
465 static const char *rockchip_get_group_name(struct pinctrl_dev
*pctldev
,
468 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
470 return info
->groups
[selector
].name
;
473 static int rockchip_get_group_pins(struct pinctrl_dev
*pctldev
,
474 unsigned selector
, const unsigned **pins
,
477 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
479 if (selector
>= info
->ngroups
)
482 *pins
= info
->groups
[selector
].pins
;
483 *npins
= info
->groups
[selector
].npins
;
488 static int rockchip_dt_node_to_map(struct pinctrl_dev
*pctldev
,
489 struct device_node
*np
,
490 struct pinctrl_map
**map
, unsigned *num_maps
)
492 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
493 const struct rockchip_pin_group
*grp
;
494 struct pinctrl_map
*new_map
;
495 struct device_node
*parent
;
500 * first find the group of this node and check if we need to create
501 * config maps for pins
503 grp
= pinctrl_name_to_group(info
, np
->name
);
505 dev_err(info
->dev
, "unable to find group for node %pOFn\n",
510 map_num
+= grp
->npins
;
511 new_map
= devm_kcalloc(pctldev
->dev
, map_num
, sizeof(*new_map
),
520 parent
= of_get_parent(np
);
522 devm_kfree(pctldev
->dev
, new_map
);
525 new_map
[0].type
= PIN_MAP_TYPE_MUX_GROUP
;
526 new_map
[0].data
.mux
.function
= parent
->name
;
527 new_map
[0].data
.mux
.group
= np
->name
;
530 /* create config map */
532 for (i
= 0; i
< grp
->npins
; i
++) {
533 new_map
[i
].type
= PIN_MAP_TYPE_CONFIGS_PIN
;
534 new_map
[i
].data
.configs
.group_or_pin
=
535 pin_get_name(pctldev
, grp
->pins
[i
]);
536 new_map
[i
].data
.configs
.configs
= grp
->data
[i
].configs
;
537 new_map
[i
].data
.configs
.num_configs
= grp
->data
[i
].nconfigs
;
540 dev_dbg(pctldev
->dev
, "maps: function %s group %s num %d\n",
541 (*map
)->data
.mux
.function
, (*map
)->data
.mux
.group
, map_num
);
546 static void rockchip_dt_free_map(struct pinctrl_dev
*pctldev
,
547 struct pinctrl_map
*map
, unsigned num_maps
)
551 static const struct pinctrl_ops rockchip_pctrl_ops
= {
552 .get_groups_count
= rockchip_get_groups_count
,
553 .get_group_name
= rockchip_get_group_name
,
554 .get_group_pins
= rockchip_get_group_pins
,
555 .dt_node_to_map
= rockchip_dt_node_to_map
,
556 .dt_free_map
= rockchip_dt_free_map
,
563 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data
[] = {
627 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data
[] = {
661 static struct rockchip_mux_recalced_data rk3308_mux_recalced_data
[] = {
755 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data
[] = {
777 static void rockchip_get_recalced_mux(struct rockchip_pin_bank
*bank
, int pin
,
778 int *reg
, u8
*bit
, int *mask
)
780 struct rockchip_pinctrl
*info
= bank
->drvdata
;
781 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
782 struct rockchip_mux_recalced_data
*data
;
785 for (i
= 0; i
< ctrl
->niomux_recalced
; i
++) {
786 data
= &ctrl
->iomux_recalced
[i
];
787 if (data
->num
== bank
->bank_num
&&
792 if (i
>= ctrl
->niomux_recalced
)
800 static struct rockchip_mux_route_data px30_mux_route_data
[] = {
806 .route_offset
= 0x184,
807 .route_val
= BIT(16 + 7),
813 .route_offset
= 0x184,
814 .route_val
= BIT(16 + 7) | BIT(7),
820 .route_offset
= 0x184,
821 .route_val
= BIT(16 + 8),
827 .route_offset
= 0x184,
828 .route_val
= BIT(16 + 8) | BIT(8),
834 .route_offset
= 0x184,
835 .route_val
= BIT(16 + 10),
841 .route_offset
= 0x184,
842 .route_val
= BIT(16 + 10) | BIT(10),
848 .route_offset
= 0x184,
849 .route_val
= BIT(16 + 9),
855 .route_offset
= 0x184,
856 .route_val
= BIT(16 + 9) | BIT(9),
860 static struct rockchip_mux_route_data rk3128_mux_route_data
[] = {
866 .route_offset
= 0x144,
867 .route_val
= BIT(16 + 3) | BIT(16 + 4),
873 .route_offset
= 0x144,
874 .route_val
= BIT(16 + 3) | BIT(16 + 4) | BIT(3),
880 .route_offset
= 0x144,
881 .route_val
= BIT(16 + 3) | BIT(16 + 4) | BIT(4),
887 .route_offset
= 0x144,
888 .route_val
= BIT(16 + 5),
894 .route_offset
= 0x144,
895 .route_val
= BIT(16 + 5) | BIT(5),
901 .route_offset
= 0x144,
902 .route_val
= BIT(16 + 6),
908 .route_offset
= 0x144,
909 .route_val
= BIT(16 + 6) | BIT(6),
913 static struct rockchip_mux_route_data rk3188_mux_route_data
[] = {
915 /* non-iomuxed emmc/flash pins on flash-dqs */
919 .route_location
= ROCKCHIP_ROUTE_GRF
,
920 .route_offset
= 0xa0,
921 .route_val
= BIT(16 + 11),
923 /* non-iomuxed emmc/flash pins on emmc-clk */
927 .route_location
= ROCKCHIP_ROUTE_GRF
,
928 .route_offset
= 0xa0,
929 .route_val
= BIT(16 + 11) | BIT(11),
933 static struct rockchip_mux_route_data rk3228_mux_route_data
[] = {
939 .route_offset
= 0x50,
940 .route_val
= BIT(16),
946 .route_offset
= 0x50,
947 .route_val
= BIT(16) | BIT(0),
953 .route_offset
= 0x50,
954 .route_val
= BIT(16 + 1),
960 .route_offset
= 0x50,
961 .route_val
= BIT(16 + 1) | BIT(1),
967 .route_offset
= 0x50,
968 .route_val
= BIT(16 + 2),
974 .route_offset
= 0x50,
975 .route_val
= BIT(16 + 2) | BIT(2),
981 .route_offset
= 0x50,
982 .route_val
= BIT(16 + 3),
988 .route_offset
= 0x50,
989 .route_val
= BIT(16 + 3) | BIT(3),
995 .route_offset
= 0x50,
996 .route_val
= BIT(16 + 4),
1002 .route_offset
= 0x50,
1003 .route_val
= BIT(16 + 4) | BIT(4),
1009 .route_offset
= 0x50,
1010 .route_val
= BIT(16 + 5),
1016 .route_offset
= 0x50,
1017 .route_val
= BIT(16 + 5) | BIT(5),
1023 .route_offset
= 0x50,
1024 .route_val
= BIT(16 + 7),
1030 .route_offset
= 0x50,
1031 .route_val
= BIT(16 + 7) | BIT(7),
1037 .route_offset
= 0x50,
1038 .route_val
= BIT(16 + 8),
1044 .route_offset
= 0x50,
1045 .route_val
= BIT(16 + 8) | BIT(8),
1051 .route_offset
= 0x50,
1052 .route_val
= BIT(16 + 11),
1058 .route_offset
= 0x50,
1059 .route_val
= BIT(16 + 11) | BIT(11),
1063 static struct rockchip_mux_route_data rk3288_mux_route_data
[] = {
1065 /* edphdmi_cecinoutt1 */
1069 .route_offset
= 0x264,
1070 .route_val
= BIT(16 + 12) | BIT(12),
1072 /* edphdmi_cecinout */
1076 .route_offset
= 0x264,
1077 .route_val
= BIT(16 + 12),
1081 static struct rockchip_mux_route_data rk3308_mux_route_data
[] = {
1087 .route_offset
= 0x314,
1088 .route_val
= BIT(16 + 0) | BIT(0),
1094 .route_offset
= 0x314,
1095 .route_val
= BIT(16 + 2) | BIT(16 + 3),
1101 .route_offset
= 0x314,
1102 .route_val
= BIT(16 + 2) | BIT(16 + 3) | BIT(2),
1108 .route_offset
= 0x608,
1109 .route_val
= BIT(16 + 8) | BIT(16 + 9),
1115 .route_offset
= 0x608,
1116 .route_val
= BIT(16 + 8) | BIT(16 + 9) | BIT(8),
1122 .route_offset
= 0x608,
1123 .route_val
= BIT(16 + 8) | BIT(16 + 9) | BIT(9),
1125 /* i2s-8ch-1-sclktxm0 */
1129 .route_offset
= 0x308,
1130 .route_val
= BIT(16 + 3),
1132 /* i2s-8ch-1-sclkrxm0 */
1136 .route_offset
= 0x308,
1137 .route_val
= BIT(16 + 3),
1139 /* i2s-8ch-1-sclktxm1 */
1143 .route_offset
= 0x308,
1144 .route_val
= BIT(16 + 3) | BIT(3),
1146 /* i2s-8ch-1-sclkrxm1 */
1150 .route_offset
= 0x308,
1151 .route_val
= BIT(16 + 3) | BIT(3),
1157 .route_offset
= 0x308,
1158 .route_val
= BIT(16 + 12) | BIT(16 + 13),
1164 .route_offset
= 0x308,
1165 .route_val
= BIT(16 + 12) | BIT(16 + 13) | BIT(12),
1171 .route_offset
= 0x308,
1172 .route_val
= BIT(16 + 12) | BIT(16 + 13) | BIT(13),
1178 .route_offset
= 0x600,
1179 .route_val
= BIT(16 + 2) | BIT(2),
1185 .route_offset
= 0x314,
1186 .route_val
= BIT(16 + 9),
1192 .route_offset
= 0x314,
1193 .route_val
= BIT(16 + 9) | BIT(9),
1199 .route_offset
= 0x314,
1200 .route_val
= BIT(16 + 10) | BIT(16 + 11),
1206 .route_offset
= 0x314,
1207 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(10),
1213 .route_offset
= 0x314,
1214 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(11),
1220 .route_offset
= 0x314,
1221 .route_val
= BIT(16 + 12) | BIT(16 + 13),
1227 .route_offset
= 0x314,
1228 .route_val
= BIT(16 + 12) | BIT(16 + 13) | BIT(12),
1234 .route_offset
= 0x314,
1235 .route_val
= BIT(16 + 12) | BIT(16 + 13) | BIT(13),
1241 .route_offset
= 0x314,
1242 .route_val
= BIT(16 + 14),
1248 .route_offset
= 0x314,
1249 .route_val
= BIT(16 + 14) | BIT(14),
1255 .route_offset
= 0x314,
1256 .route_val
= BIT(16 + 15),
1262 .route_offset
= 0x314,
1263 .route_val
= BIT(16 + 15) | BIT(15),
1267 static struct rockchip_mux_route_data rk3328_mux_route_data
[] = {
1273 .route_offset
= 0x50,
1274 .route_val
= BIT(16) | BIT(16 + 1),
1280 .route_offset
= 0x50,
1281 .route_val
= BIT(16) | BIT(16 + 1) | BIT(0),
1287 .route_offset
= 0x50,
1288 .route_val
= BIT(16 + 2) | BIT(2),
1290 /* gmac-m1-optimized_rxd3 */
1294 .route_offset
= 0x50,
1295 .route_val
= BIT(16 + 10) | BIT(10),
1301 .route_offset
= 0x50,
1302 .route_val
= BIT(16 + 3),
1308 .route_offset
= 0x50,
1309 .route_val
= BIT(16 + 3) | BIT(3),
1315 .route_offset
= 0x50,
1316 .route_val
= BIT(16 + 4) | BIT(16 + 5) | BIT(5),
1322 .route_offset
= 0x50,
1323 .route_val
= BIT(16 + 6),
1329 .route_offset
= 0x50,
1330 .route_val
= BIT(16 + 6) | BIT(6),
1336 .route_offset
= 0x50,
1337 .route_val
= BIT(16 + 7) | BIT(7),
1343 .route_offset
= 0x50,
1344 .route_val
= BIT(16 + 8) | BIT(8),
1350 .route_offset
= 0x50,
1351 .route_val
= BIT(16 + 9) | BIT(9),
1355 static struct rockchip_mux_route_data rk3399_mux_route_data
[] = {
1361 .route_offset
= 0xe21c,
1362 .route_val
= BIT(16 + 10) | BIT(16 + 11),
1368 .route_offset
= 0xe21c,
1369 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(10),
1375 .route_offset
= 0xe21c,
1376 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(11),
1382 .route_offset
= 0xe21c,
1383 .route_val
= BIT(16 + 14),
1389 .route_offset
= 0xe21c,
1390 .route_val
= BIT(16 + 14) | BIT(14),
1394 static bool rockchip_get_mux_route(struct rockchip_pin_bank
*bank
, int pin
,
1395 int mux
, u32
*loc
, u32
*reg
, u32
*value
)
1397 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1398 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1399 struct rockchip_mux_route_data
*data
;
1402 for (i
= 0; i
< ctrl
->niomux_routes
; i
++) {
1403 data
= &ctrl
->iomux_routes
[i
];
1404 if ((data
->bank_num
== bank
->bank_num
) &&
1405 (data
->pin
== pin
) && (data
->func
== mux
))
1409 if (i
>= ctrl
->niomux_routes
)
1412 *loc
= data
->route_location
;
1413 *reg
= data
->route_offset
;
1414 *value
= data
->route_val
;
1419 static int rockchip_get_mux(struct rockchip_pin_bank
*bank
, int pin
)
1421 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1422 int iomux_num
= (pin
/ 8);
1423 struct regmap
*regmap
;
1425 int reg
, ret
, mask
, mux_type
;
1431 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1432 dev_err(info
->dev
, "pin %d is unrouted\n", pin
);
1436 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1437 return RK_FUNC_GPIO
;
1439 regmap
= (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1440 ? info
->regmap_pmu
: info
->regmap_base
;
1442 /* get basic quadrupel of mux registers and the correct reg inside */
1443 mux_type
= bank
->iomux
[iomux_num
].type
;
1444 reg
= bank
->iomux
[iomux_num
].offset
;
1445 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1448 bit
= (pin
% 4) * 4;
1450 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1453 bit
= (pin
% 8 % 5) * 3;
1456 bit
= (pin
% 8) * 2;
1460 if (bank
->recalced_mask
& BIT(pin
))
1461 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1463 ret
= regmap_read(regmap
, reg
, &val
);
1467 return ((val
>> bit
) & mask
);
1470 static int rockchip_verify_mux(struct rockchip_pin_bank
*bank
,
1473 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1474 int iomux_num
= (pin
/ 8);
1479 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1480 dev_err(info
->dev
, "pin %d is unrouted\n", pin
);
1484 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
) {
1485 if (mux
!= RK_FUNC_GPIO
) {
1487 "pin %d only supports a gpio mux\n", pin
);
1496 * Set a new mux function for a pin.
1498 * The register is divided into the upper and lower 16 bit. When changing
1499 * a value, the previous register value is not read and changed. Instead
1500 * it seems the changed bits are marked in the upper 16 bit, while the
1501 * changed value gets set in the same offset in the lower 16 bit.
1502 * All pin settings seem to be 2 bit wide in both the upper and lower
1504 * @bank: pin bank to change
1505 * @pin: pin to change
1506 * @mux: new mux function to set
1508 static int rockchip_set_mux(struct rockchip_pin_bank
*bank
, int pin
, int mux
)
1510 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1511 int iomux_num
= (pin
/ 8);
1512 struct regmap
*regmap
;
1513 int reg
, ret
, mask
, mux_type
;
1515 u32 data
, rmask
, route_location
, route_reg
, route_val
;
1517 ret
= rockchip_verify_mux(bank
, pin
, mux
);
1521 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1524 dev_dbg(info
->dev
, "setting mux of GPIO%d-%d to %d\n",
1525 bank
->bank_num
, pin
, mux
);
1527 regmap
= (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1528 ? info
->regmap_pmu
: info
->regmap_base
;
1530 /* get basic quadrupel of mux registers and the correct reg inside */
1531 mux_type
= bank
->iomux
[iomux_num
].type
;
1532 reg
= bank
->iomux
[iomux_num
].offset
;
1533 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1536 bit
= (pin
% 4) * 4;
1538 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1541 bit
= (pin
% 8 % 5) * 3;
1544 bit
= (pin
% 8) * 2;
1548 if (bank
->recalced_mask
& BIT(pin
))
1549 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1551 if (bank
->route_mask
& BIT(pin
)) {
1552 if (rockchip_get_mux_route(bank
, pin
, mux
, &route_location
,
1553 &route_reg
, &route_val
)) {
1554 struct regmap
*route_regmap
= regmap
;
1556 /* handle special locations */
1557 switch (route_location
) {
1558 case ROCKCHIP_ROUTE_PMU
:
1559 route_regmap
= info
->regmap_pmu
;
1561 case ROCKCHIP_ROUTE_GRF
:
1562 route_regmap
= info
->regmap_base
;
1566 ret
= regmap_write(route_regmap
, route_reg
, route_val
);
1572 data
= (mask
<< (bit
+ 16));
1573 rmask
= data
| (data
>> 16);
1574 data
|= (mux
& mask
) << bit
;
1575 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1580 #define PX30_PULL_PMU_OFFSET 0x10
1581 #define PX30_PULL_GRF_OFFSET 0x60
1582 #define PX30_PULL_BITS_PER_PIN 2
1583 #define PX30_PULL_PINS_PER_REG 8
1584 #define PX30_PULL_BANK_STRIDE 16
1586 static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1587 int pin_num
, struct regmap
**regmap
,
1590 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1592 /* The first 32 pins of the first bank are located in PMU */
1593 if (bank
->bank_num
== 0) {
1594 *regmap
= info
->regmap_pmu
;
1595 *reg
= PX30_PULL_PMU_OFFSET
;
1597 *regmap
= info
->regmap_base
;
1598 *reg
= PX30_PULL_GRF_OFFSET
;
1600 /* correct the offset, as we're starting with the 2nd bank */
1602 *reg
+= bank
->bank_num
* PX30_PULL_BANK_STRIDE
;
1605 *reg
+= ((pin_num
/ PX30_PULL_PINS_PER_REG
) * 4);
1606 *bit
= (pin_num
% PX30_PULL_PINS_PER_REG
);
1607 *bit
*= PX30_PULL_BITS_PER_PIN
;
1610 #define PX30_DRV_PMU_OFFSET 0x20
1611 #define PX30_DRV_GRF_OFFSET 0xf0
1612 #define PX30_DRV_BITS_PER_PIN 2
1613 #define PX30_DRV_PINS_PER_REG 8
1614 #define PX30_DRV_BANK_STRIDE 16
1616 static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1617 int pin_num
, struct regmap
**regmap
,
1620 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1622 /* The first 32 pins of the first bank are located in PMU */
1623 if (bank
->bank_num
== 0) {
1624 *regmap
= info
->regmap_pmu
;
1625 *reg
= PX30_DRV_PMU_OFFSET
;
1627 *regmap
= info
->regmap_base
;
1628 *reg
= PX30_DRV_GRF_OFFSET
;
1630 /* correct the offset, as we're starting with the 2nd bank */
1632 *reg
+= bank
->bank_num
* PX30_DRV_BANK_STRIDE
;
1635 *reg
+= ((pin_num
/ PX30_DRV_PINS_PER_REG
) * 4);
1636 *bit
= (pin_num
% PX30_DRV_PINS_PER_REG
);
1637 *bit
*= PX30_DRV_BITS_PER_PIN
;
1640 #define PX30_SCHMITT_PMU_OFFSET 0x38
1641 #define PX30_SCHMITT_GRF_OFFSET 0xc0
1642 #define PX30_SCHMITT_PINS_PER_PMU_REG 16
1643 #define PX30_SCHMITT_BANK_STRIDE 16
1644 #define PX30_SCHMITT_PINS_PER_GRF_REG 8
1646 static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1648 struct regmap
**regmap
,
1651 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1654 if (bank
->bank_num
== 0) {
1655 *regmap
= info
->regmap_pmu
;
1656 *reg
= PX30_SCHMITT_PMU_OFFSET
;
1657 pins_per_reg
= PX30_SCHMITT_PINS_PER_PMU_REG
;
1659 *regmap
= info
->regmap_base
;
1660 *reg
= PX30_SCHMITT_GRF_OFFSET
;
1661 pins_per_reg
= PX30_SCHMITT_PINS_PER_GRF_REG
;
1662 *reg
+= (bank
->bank_num
- 1) * PX30_SCHMITT_BANK_STRIDE
;
1665 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1666 *bit
= pin_num
% pins_per_reg
;
1671 #define RV1108_PULL_PMU_OFFSET 0x10
1672 #define RV1108_PULL_OFFSET 0x110
1673 #define RV1108_PULL_PINS_PER_REG 8
1674 #define RV1108_PULL_BITS_PER_PIN 2
1675 #define RV1108_PULL_BANK_STRIDE 16
1677 static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1678 int pin_num
, struct regmap
**regmap
,
1681 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1683 /* The first 24 pins of the first bank are located in PMU */
1684 if (bank
->bank_num
== 0) {
1685 *regmap
= info
->regmap_pmu
;
1686 *reg
= RV1108_PULL_PMU_OFFSET
;
1688 *reg
= RV1108_PULL_OFFSET
;
1689 *regmap
= info
->regmap_base
;
1690 /* correct the offset, as we're starting with the 2nd bank */
1692 *reg
+= bank
->bank_num
* RV1108_PULL_BANK_STRIDE
;
1695 *reg
+= ((pin_num
/ RV1108_PULL_PINS_PER_REG
) * 4);
1696 *bit
= (pin_num
% RV1108_PULL_PINS_PER_REG
);
1697 *bit
*= RV1108_PULL_BITS_PER_PIN
;
1700 #define RV1108_DRV_PMU_OFFSET 0x20
1701 #define RV1108_DRV_GRF_OFFSET 0x210
1702 #define RV1108_DRV_BITS_PER_PIN 2
1703 #define RV1108_DRV_PINS_PER_REG 8
1704 #define RV1108_DRV_BANK_STRIDE 16
1706 static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1707 int pin_num
, struct regmap
**regmap
,
1710 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1712 /* The first 24 pins of the first bank are located in PMU */
1713 if (bank
->bank_num
== 0) {
1714 *regmap
= info
->regmap_pmu
;
1715 *reg
= RV1108_DRV_PMU_OFFSET
;
1717 *regmap
= info
->regmap_base
;
1718 *reg
= RV1108_DRV_GRF_OFFSET
;
1720 /* correct the offset, as we're starting with the 2nd bank */
1722 *reg
+= bank
->bank_num
* RV1108_DRV_BANK_STRIDE
;
1725 *reg
+= ((pin_num
/ RV1108_DRV_PINS_PER_REG
) * 4);
1726 *bit
= pin_num
% RV1108_DRV_PINS_PER_REG
;
1727 *bit
*= RV1108_DRV_BITS_PER_PIN
;
1730 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1731 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1732 #define RV1108_SCHMITT_BANK_STRIDE 8
1733 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1734 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1736 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1738 struct regmap
**regmap
,
1741 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1744 if (bank
->bank_num
== 0) {
1745 *regmap
= info
->regmap_pmu
;
1746 *reg
= RV1108_SCHMITT_PMU_OFFSET
;
1747 pins_per_reg
= RV1108_SCHMITT_PINS_PER_PMU_REG
;
1749 *regmap
= info
->regmap_base
;
1750 *reg
= RV1108_SCHMITT_GRF_OFFSET
;
1751 pins_per_reg
= RV1108_SCHMITT_PINS_PER_GRF_REG
;
1752 *reg
+= (bank
->bank_num
- 1) * RV1108_SCHMITT_BANK_STRIDE
;
1754 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1755 *bit
= pin_num
% pins_per_reg
;
1760 #define RK3308_SCHMITT_PINS_PER_REG 8
1761 #define RK3308_SCHMITT_BANK_STRIDE 16
1762 #define RK3308_SCHMITT_GRF_OFFSET 0x1a0
1764 static int rk3308_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1765 int pin_num
, struct regmap
**regmap
,
1768 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1770 *regmap
= info
->regmap_base
;
1771 *reg
= RK3308_SCHMITT_GRF_OFFSET
;
1773 *reg
+= bank
->bank_num
* RK3308_SCHMITT_BANK_STRIDE
;
1774 *reg
+= ((pin_num
/ RK3308_SCHMITT_PINS_PER_REG
) * 4);
1775 *bit
= pin_num
% RK3308_SCHMITT_PINS_PER_REG
;
1780 #define RK2928_PULL_OFFSET 0x118
1781 #define RK2928_PULL_PINS_PER_REG 16
1782 #define RK2928_PULL_BANK_STRIDE 8
1784 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1785 int pin_num
, struct regmap
**regmap
,
1788 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1790 *regmap
= info
->regmap_base
;
1791 *reg
= RK2928_PULL_OFFSET
;
1792 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1793 *reg
+= (pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4;
1795 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1798 #define RK3128_PULL_OFFSET 0x118
1800 static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1801 int pin_num
, struct regmap
**regmap
,
1804 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1806 *regmap
= info
->regmap_base
;
1807 *reg
= RK3128_PULL_OFFSET
;
1808 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1809 *reg
+= ((pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4);
1811 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1814 #define RK3188_PULL_OFFSET 0x164
1815 #define RK3188_PULL_BITS_PER_PIN 2
1816 #define RK3188_PULL_PINS_PER_REG 8
1817 #define RK3188_PULL_BANK_STRIDE 16
1818 #define RK3188_PULL_PMU_OFFSET 0x64
1820 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1821 int pin_num
, struct regmap
**regmap
,
1824 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1826 /* The first 12 pins of the first bank are located elsewhere */
1827 if (bank
->bank_num
== 0 && pin_num
< 12) {
1828 *regmap
= info
->regmap_pmu
? info
->regmap_pmu
1829 : bank
->regmap_pull
;
1830 *reg
= info
->regmap_pmu
? RK3188_PULL_PMU_OFFSET
: 0;
1831 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1832 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1833 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1835 *regmap
= info
->regmap_pull
? info
->regmap_pull
1836 : info
->regmap_base
;
1837 *reg
= info
->regmap_pull
? 0 : RK3188_PULL_OFFSET
;
1839 /* correct the offset, as it is the 2nd pull register */
1841 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1842 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1845 * The bits in these registers have an inverse ordering
1846 * with the lowest pin being in bits 15:14 and the highest
1849 *bit
= 7 - (pin_num
% RK3188_PULL_PINS_PER_REG
);
1850 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1854 #define RK3288_PULL_OFFSET 0x140
1855 static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1856 int pin_num
, struct regmap
**regmap
,
1859 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1861 /* The first 24 pins of the first bank are located in PMU */
1862 if (bank
->bank_num
== 0) {
1863 *regmap
= info
->regmap_pmu
;
1864 *reg
= RK3188_PULL_PMU_OFFSET
;
1866 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1867 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1868 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1870 *regmap
= info
->regmap_base
;
1871 *reg
= RK3288_PULL_OFFSET
;
1873 /* correct the offset, as we're starting with the 2nd bank */
1875 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1876 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1878 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1879 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1883 #define RK3288_DRV_PMU_OFFSET 0x70
1884 #define RK3288_DRV_GRF_OFFSET 0x1c0
1885 #define RK3288_DRV_BITS_PER_PIN 2
1886 #define RK3288_DRV_PINS_PER_REG 8
1887 #define RK3288_DRV_BANK_STRIDE 16
1889 static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1890 int pin_num
, struct regmap
**regmap
,
1893 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1895 /* The first 24 pins of the first bank are located in PMU */
1896 if (bank
->bank_num
== 0) {
1897 *regmap
= info
->regmap_pmu
;
1898 *reg
= RK3288_DRV_PMU_OFFSET
;
1900 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1901 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
1902 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1904 *regmap
= info
->regmap_base
;
1905 *reg
= RK3288_DRV_GRF_OFFSET
;
1907 /* correct the offset, as we're starting with the 2nd bank */
1909 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1910 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1912 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1913 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1917 #define RK3228_PULL_OFFSET 0x100
1919 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1920 int pin_num
, struct regmap
**regmap
,
1923 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1925 *regmap
= info
->regmap_base
;
1926 *reg
= RK3228_PULL_OFFSET
;
1927 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1928 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1930 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1931 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1934 #define RK3228_DRV_GRF_OFFSET 0x200
1936 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1937 int pin_num
, struct regmap
**regmap
,
1940 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1942 *regmap
= info
->regmap_base
;
1943 *reg
= RK3228_DRV_GRF_OFFSET
;
1944 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1945 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1947 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1948 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1951 #define RK3308_PULL_OFFSET 0xa0
1953 static void rk3308_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1954 int pin_num
, struct regmap
**regmap
,
1957 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1959 *regmap
= info
->regmap_base
;
1960 *reg
= RK3308_PULL_OFFSET
;
1961 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1962 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1964 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1965 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1968 #define RK3308_DRV_GRF_OFFSET 0x100
1970 static void rk3308_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1971 int pin_num
, struct regmap
**regmap
,
1974 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1976 *regmap
= info
->regmap_base
;
1977 *reg
= RK3308_DRV_GRF_OFFSET
;
1978 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1979 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1981 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1982 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1985 #define RK3368_PULL_GRF_OFFSET 0x100
1986 #define RK3368_PULL_PMU_OFFSET 0x10
1988 static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1989 int pin_num
, struct regmap
**regmap
,
1992 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1994 /* The first 32 pins of the first bank are located in PMU */
1995 if (bank
->bank_num
== 0) {
1996 *regmap
= info
->regmap_pmu
;
1997 *reg
= RK3368_PULL_PMU_OFFSET
;
1999 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
2000 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
2001 *bit
*= RK3188_PULL_BITS_PER_PIN
;
2003 *regmap
= info
->regmap_base
;
2004 *reg
= RK3368_PULL_GRF_OFFSET
;
2006 /* correct the offset, as we're starting with the 2nd bank */
2008 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
2009 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
2011 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
2012 *bit
*= RK3188_PULL_BITS_PER_PIN
;
2016 #define RK3368_DRV_PMU_OFFSET 0x20
2017 #define RK3368_DRV_GRF_OFFSET 0x200
2019 static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
2020 int pin_num
, struct regmap
**regmap
,
2023 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2025 /* The first 32 pins of the first bank are located in PMU */
2026 if (bank
->bank_num
== 0) {
2027 *regmap
= info
->regmap_pmu
;
2028 *reg
= RK3368_DRV_PMU_OFFSET
;
2030 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
2031 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
2032 *bit
*= RK3288_DRV_BITS_PER_PIN
;
2034 *regmap
= info
->regmap_base
;
2035 *reg
= RK3368_DRV_GRF_OFFSET
;
2037 /* correct the offset, as we're starting with the 2nd bank */
2039 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
2040 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
2042 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
2043 *bit
*= RK3288_DRV_BITS_PER_PIN
;
2047 #define RK3399_PULL_GRF_OFFSET 0xe040
2048 #define RK3399_PULL_PMU_OFFSET 0x40
2049 #define RK3399_DRV_3BITS_PER_PIN 3
2051 static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
2052 int pin_num
, struct regmap
**regmap
,
2055 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2057 /* The bank0:16 and bank1:32 pins are located in PMU */
2058 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1)) {
2059 *regmap
= info
->regmap_pmu
;
2060 *reg
= RK3399_PULL_PMU_OFFSET
;
2062 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
2064 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
2065 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
2066 *bit
*= RK3188_PULL_BITS_PER_PIN
;
2068 *regmap
= info
->regmap_base
;
2069 *reg
= RK3399_PULL_GRF_OFFSET
;
2071 /* correct the offset, as we're starting with the 3rd bank */
2073 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
2074 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
2076 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
2077 *bit
*= RK3188_PULL_BITS_PER_PIN
;
2081 static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
2082 int pin_num
, struct regmap
**regmap
,
2085 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2086 int drv_num
= (pin_num
/ 8);
2088 /* The bank0:16 and bank1:32 pins are located in PMU */
2089 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1))
2090 *regmap
= info
->regmap_pmu
;
2092 *regmap
= info
->regmap_base
;
2094 *reg
= bank
->drv
[drv_num
].offset
;
2095 if ((bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
2096 (bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_3V3_ONLY
))
2097 *bit
= (pin_num
% 8) * 3;
2099 *bit
= (pin_num
% 8) * 2;
2102 static int rockchip_perpin_drv_list
[DRV_TYPE_MAX
][8] = {
2103 { 2, 4, 8, 12, -1, -1, -1, -1 },
2104 { 3, 6, 9, 12, -1, -1, -1, -1 },
2105 { 5, 10, 15, 20, -1, -1, -1, -1 },
2106 { 4, 6, 8, 10, 12, 14, 16, 18 },
2107 { 4, 7, 10, 13, 16, 19, 22, 26 }
2110 static int rockchip_get_drive_perpin(struct rockchip_pin_bank
*bank
,
2113 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2114 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2115 struct regmap
*regmap
;
2117 u32 data
, temp
, rmask_bits
;
2119 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
2121 ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2124 case DRV_TYPE_IO_1V8_3V0_AUTO
:
2125 case DRV_TYPE_IO_3V3_ONLY
:
2126 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
2129 /* regular case, nothing to do */
2133 * drive-strength offset is special, as it is
2134 * spread over 2 registers
2136 ret
= regmap_read(regmap
, reg
, &data
);
2140 ret
= regmap_read(regmap
, reg
+ 0x4, &temp
);
2145 * the bit data[15] contains bit 0 of the value
2146 * while temp[1:0] contains bits 2 and 1
2153 return rockchip_perpin_drv_list
[drv_type
][data
];
2155 /* setting fully enclosed in the second register */
2160 dev_err(info
->dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
2166 case DRV_TYPE_IO_DEFAULT
:
2167 case DRV_TYPE_IO_1V8_OR_3V0
:
2168 case DRV_TYPE_IO_1V8_ONLY
:
2169 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
2172 dev_err(info
->dev
, "unsupported pinctrl drive type: %d\n",
2177 ret
= regmap_read(regmap
, reg
, &data
);
2182 data
&= (1 << rmask_bits
) - 1;
2184 return rockchip_perpin_drv_list
[drv_type
][data
];
2187 static int rockchip_set_drive_perpin(struct rockchip_pin_bank
*bank
,
2188 int pin_num
, int strength
)
2190 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2191 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2192 struct regmap
*regmap
;
2194 u32 data
, rmask
, rmask_bits
, temp
;
2196 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
2198 dev_dbg(info
->dev
, "setting drive of GPIO%d-%d to %d\n",
2199 bank
->bank_num
, pin_num
, strength
);
2201 ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2204 for (i
= 0; i
< ARRAY_SIZE(rockchip_perpin_drv_list
[drv_type
]); i
++) {
2205 if (rockchip_perpin_drv_list
[drv_type
][i
] == strength
) {
2208 } else if (rockchip_perpin_drv_list
[drv_type
][i
] < 0) {
2209 ret
= rockchip_perpin_drv_list
[drv_type
][i
];
2215 dev_err(info
->dev
, "unsupported driver strength %d\n",
2221 case DRV_TYPE_IO_1V8_3V0_AUTO
:
2222 case DRV_TYPE_IO_3V3_ONLY
:
2223 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
2226 /* regular case, nothing to do */
2230 * drive-strength offset is special, as it is spread
2231 * over 2 registers, the bit data[15] contains bit 0
2232 * of the value while temp[1:0] contains bits 2 and 1
2234 data
= (ret
& 0x1) << 15;
2235 temp
= (ret
>> 0x1) & 0x3;
2237 rmask
= BIT(15) | BIT(31);
2239 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2243 rmask
= 0x3 | (0x3 << 16);
2244 temp
|= (0x3 << 16);
2246 ret
= regmap_update_bits(regmap
, reg
, rmask
, temp
);
2250 /* setting fully enclosed in the second register */
2255 dev_err(info
->dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
2260 case DRV_TYPE_IO_DEFAULT
:
2261 case DRV_TYPE_IO_1V8_OR_3V0
:
2262 case DRV_TYPE_IO_1V8_ONLY
:
2263 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
2266 dev_err(info
->dev
, "unsupported pinctrl drive type: %d\n",
2271 /* enable the write to the equivalent lower bits */
2272 data
= ((1 << rmask_bits
) - 1) << (bit
+ 16);
2273 rmask
= data
| (data
>> 16);
2274 data
|= (ret
<< bit
);
2276 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2281 static int rockchip_pull_list
[PULL_TYPE_MAX
][4] = {
2283 PIN_CONFIG_BIAS_DISABLE
,
2284 PIN_CONFIG_BIAS_PULL_UP
,
2285 PIN_CONFIG_BIAS_PULL_DOWN
,
2286 PIN_CONFIG_BIAS_BUS_HOLD
2289 PIN_CONFIG_BIAS_DISABLE
,
2290 PIN_CONFIG_BIAS_PULL_DOWN
,
2291 PIN_CONFIG_BIAS_DISABLE
,
2292 PIN_CONFIG_BIAS_PULL_UP
2296 static int rockchip_get_pull(struct rockchip_pin_bank
*bank
, int pin_num
)
2298 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2299 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2300 struct regmap
*regmap
;
2301 int reg
, ret
, pull_type
;
2305 /* rk3066b does support any pulls */
2306 if (ctrl
->type
== RK3066B
)
2307 return PIN_CONFIG_BIAS_DISABLE
;
2309 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2311 ret
= regmap_read(regmap
, reg
, &data
);
2315 switch (ctrl
->type
) {
2318 return !(data
& BIT(bit
))
2319 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
2320 : PIN_CONFIG_BIAS_DISABLE
;
2328 pull_type
= bank
->pull_type
[pin_num
/ 8];
2330 data
&= (1 << RK3188_PULL_BITS_PER_PIN
) - 1;
2332 return rockchip_pull_list
[pull_type
][data
];
2334 dev_err(info
->dev
, "unsupported pinctrl type\n");
2339 static int rockchip_set_pull(struct rockchip_pin_bank
*bank
,
2340 int pin_num
, int pull
)
2342 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2343 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2344 struct regmap
*regmap
;
2345 int reg
, ret
, i
, pull_type
;
2349 dev_dbg(info
->dev
, "setting pull of GPIO%d-%d to %d\n",
2350 bank
->bank_num
, pin_num
, pull
);
2352 /* rk3066b does support any pulls */
2353 if (ctrl
->type
== RK3066B
)
2354 return pull
? -EINVAL
: 0;
2356 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2358 switch (ctrl
->type
) {
2361 data
= BIT(bit
+ 16);
2362 if (pull
== PIN_CONFIG_BIAS_DISABLE
)
2364 ret
= regmap_write(regmap
, reg
, data
);
2373 pull_type
= bank
->pull_type
[pin_num
/ 8];
2375 for (i
= 0; i
< ARRAY_SIZE(rockchip_pull_list
[pull_type
]);
2377 if (rockchip_pull_list
[pull_type
][i
] == pull
) {
2384 dev_err(info
->dev
, "unsupported pull setting %d\n",
2389 /* enable the write to the equivalent lower bits */
2390 data
= ((1 << RK3188_PULL_BITS_PER_PIN
) - 1) << (bit
+ 16);
2391 rmask
= data
| (data
>> 16);
2392 data
|= (ret
<< bit
);
2394 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
2397 dev_err(info
->dev
, "unsupported pinctrl type\n");
2404 #define RK3328_SCHMITT_BITS_PER_PIN 1
2405 #define RK3328_SCHMITT_PINS_PER_REG 16
2406 #define RK3328_SCHMITT_BANK_STRIDE 8
2407 #define RK3328_SCHMITT_GRF_OFFSET 0x380
2409 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
2411 struct regmap
**regmap
,
2414 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2416 *regmap
= info
->regmap_base
;
2417 *reg
= RK3328_SCHMITT_GRF_OFFSET
;
2419 *reg
+= bank
->bank_num
* RK3328_SCHMITT_BANK_STRIDE
;
2420 *reg
+= ((pin_num
/ RK3328_SCHMITT_PINS_PER_REG
) * 4);
2421 *bit
= pin_num
% RK3328_SCHMITT_PINS_PER_REG
;
2426 static int rockchip_get_schmitt(struct rockchip_pin_bank
*bank
, int pin_num
)
2428 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2429 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2430 struct regmap
*regmap
;
2435 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2439 ret
= regmap_read(regmap
, reg
, &data
);
2447 static int rockchip_set_schmitt(struct rockchip_pin_bank
*bank
,
2448 int pin_num
, int enable
)
2450 struct rockchip_pinctrl
*info
= bank
->drvdata
;
2451 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2452 struct regmap
*regmap
;
2457 dev_dbg(info
->dev
, "setting input schmitt of GPIO%d-%d to %d\n",
2458 bank
->bank_num
, pin_num
, enable
);
2460 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
2464 /* enable the write to the equivalent lower bits */
2465 data
= BIT(bit
+ 16) | (enable
<< bit
);
2466 rmask
= BIT(bit
+ 16) | BIT(bit
);
2468 return regmap_update_bits(regmap
, reg
, rmask
, data
);
2472 * Pinmux_ops handling
2475 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev
*pctldev
)
2477 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2479 return info
->nfunctions
;
2482 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
2485 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2487 return info
->functions
[selector
].name
;
2490 static int rockchip_pmx_get_groups(struct pinctrl_dev
*pctldev
,
2491 unsigned selector
, const char * const **groups
,
2492 unsigned * const num_groups
)
2494 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2496 *groups
= info
->functions
[selector
].groups
;
2497 *num_groups
= info
->functions
[selector
].ngroups
;
2502 static int rockchip_pmx_set(struct pinctrl_dev
*pctldev
, unsigned selector
,
2505 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2506 const unsigned int *pins
= info
->groups
[group
].pins
;
2507 const struct rockchip_pin_config
*data
= info
->groups
[group
].data
;
2508 struct rockchip_pin_bank
*bank
;
2511 dev_dbg(info
->dev
, "enable function %s group %s\n",
2512 info
->functions
[selector
].name
, info
->groups
[group
].name
);
2515 * for each pin in the pin group selected, program the corresponding
2516 * pin function number in the config register.
2518 for (cnt
= 0; cnt
< info
->groups
[group
].npins
; cnt
++) {
2519 bank
= pin_to_bank(info
, pins
[cnt
]);
2520 ret
= rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
,
2527 /* revert the already done pin settings */
2528 for (cnt
--; cnt
>= 0; cnt
--)
2529 rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
, 0);
2537 static int rockchip_gpio_get_direction(struct gpio_chip
*chip
, unsigned offset
)
2539 struct rockchip_pin_bank
*bank
= gpiochip_get_data(chip
);
2543 ret
= clk_enable(bank
->clk
);
2545 dev_err(bank
->drvdata
->dev
,
2546 "failed to enable clock for bank %s\n", bank
->name
);
2549 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
2550 clk_disable(bank
->clk
);
2552 if (data
& BIT(offset
))
2553 return GPIO_LINE_DIRECTION_OUT
;
2555 return GPIO_LINE_DIRECTION_IN
;
2559 * The calls to gpio_direction_output() and gpio_direction_input()
2560 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
2561 * function called from the gpiolib interface).
2563 static int _rockchip_pmx_gpio_set_direction(struct gpio_chip
*chip
,
2564 int pin
, bool input
)
2566 struct rockchip_pin_bank
*bank
;
2568 unsigned long flags
;
2571 bank
= gpiochip_get_data(chip
);
2573 ret
= rockchip_set_mux(bank
, pin
, RK_FUNC_GPIO
);
2577 clk_enable(bank
->clk
);
2578 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2580 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
2581 /* set bit to 1 for output, 0 for input */
2586 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
2588 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2589 clk_disable(bank
->clk
);
2594 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev
*pctldev
,
2595 struct pinctrl_gpio_range
*range
,
2596 unsigned offset
, bool input
)
2598 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2599 struct gpio_chip
*chip
;
2603 pin
= offset
- chip
->base
;
2604 dev_dbg(info
->dev
, "gpio_direction for pin %u as %s-%d to %s\n",
2605 offset
, range
->name
, pin
, input
? "input" : "output");
2607 return _rockchip_pmx_gpio_set_direction(chip
, offset
- chip
->base
,
2611 static const struct pinmux_ops rockchip_pmx_ops
= {
2612 .get_functions_count
= rockchip_pmx_get_funcs_count
,
2613 .get_function_name
= rockchip_pmx_get_func_name
,
2614 .get_function_groups
= rockchip_pmx_get_groups
,
2615 .set_mux
= rockchip_pmx_set
,
2616 .gpio_set_direction
= rockchip_pmx_gpio_set_direction
,
2620 * Pinconf_ops handling
2623 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl
*ctrl
,
2624 enum pin_config_param pull
)
2626 switch (ctrl
->type
) {
2629 return (pull
== PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
||
2630 pull
== PIN_CONFIG_BIAS_DISABLE
);
2632 return pull
? false : true;
2640 return (pull
!= PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
);
2646 static void rockchip_gpio_set(struct gpio_chip
*gc
, unsigned offset
, int value
);
2647 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
);
2649 /* set the pin config settings for a specified pin */
2650 static int rockchip_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
2651 unsigned long *configs
, unsigned num_configs
)
2653 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2654 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
2655 enum pin_config_param param
;
2660 for (i
= 0; i
< num_configs
; i
++) {
2661 param
= pinconf_to_config_param(configs
[i
]);
2662 arg
= pinconf_to_config_argument(configs
[i
]);
2665 case PIN_CONFIG_BIAS_DISABLE
:
2666 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
2671 case PIN_CONFIG_BIAS_PULL_UP
:
2672 case PIN_CONFIG_BIAS_PULL_DOWN
:
2673 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
2674 case PIN_CONFIG_BIAS_BUS_HOLD
:
2675 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
2681 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
2686 case PIN_CONFIG_OUTPUT
:
2687 rockchip_gpio_set(&bank
->gpio_chip
,
2688 pin
- bank
->pin_base
, arg
);
2689 rc
= _rockchip_pmx_gpio_set_direction(&bank
->gpio_chip
,
2690 pin
- bank
->pin_base
, false);
2694 case PIN_CONFIG_DRIVE_STRENGTH
:
2695 /* rk3288 is the first with per-pin drive-strength */
2696 if (!info
->ctrl
->drv_calc_reg
)
2699 rc
= rockchip_set_drive_perpin(bank
,
2700 pin
- bank
->pin_base
, arg
);
2704 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
2705 if (!info
->ctrl
->schmitt_calc_reg
)
2708 rc
= rockchip_set_schmitt(bank
,
2709 pin
- bank
->pin_base
, arg
);
2717 } /* for each config */
2722 /* get the pin config settings for a specified pin */
2723 static int rockchip_pinconf_get(struct pinctrl_dev
*pctldev
, unsigned int pin
,
2724 unsigned long *config
)
2726 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2727 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
2728 enum pin_config_param param
= pinconf_to_config_param(*config
);
2733 case PIN_CONFIG_BIAS_DISABLE
:
2734 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
2739 case PIN_CONFIG_BIAS_PULL_UP
:
2740 case PIN_CONFIG_BIAS_PULL_DOWN
:
2741 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
2742 case PIN_CONFIG_BIAS_BUS_HOLD
:
2743 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
2746 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
2751 case PIN_CONFIG_OUTPUT
:
2752 rc
= rockchip_get_mux(bank
, pin
- bank
->pin_base
);
2753 if (rc
!= RK_FUNC_GPIO
)
2756 rc
= rockchip_gpio_get(&bank
->gpio_chip
, pin
- bank
->pin_base
);
2762 case PIN_CONFIG_DRIVE_STRENGTH
:
2763 /* rk3288 is the first with per-pin drive-strength */
2764 if (!info
->ctrl
->drv_calc_reg
)
2767 rc
= rockchip_get_drive_perpin(bank
, pin
- bank
->pin_base
);
2773 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
2774 if (!info
->ctrl
->schmitt_calc_reg
)
2777 rc
= rockchip_get_schmitt(bank
, pin
- bank
->pin_base
);
2788 *config
= pinconf_to_config_packed(param
, arg
);
2793 static const struct pinconf_ops rockchip_pinconf_ops
= {
2794 .pin_config_get
= rockchip_pinconf_get
,
2795 .pin_config_set
= rockchip_pinconf_set
,
2799 static const struct of_device_id rockchip_bank_match
[] = {
2800 { .compatible
= "rockchip,gpio-bank" },
2801 { .compatible
= "rockchip,rk3188-gpio-bank0" },
2805 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl
*info
,
2806 struct device_node
*np
)
2808 struct device_node
*child
;
2810 for_each_child_of_node(np
, child
) {
2811 if (of_match_node(rockchip_bank_match
, child
))
2815 info
->ngroups
+= of_get_child_count(child
);
2819 static int rockchip_pinctrl_parse_groups(struct device_node
*np
,
2820 struct rockchip_pin_group
*grp
,
2821 struct rockchip_pinctrl
*info
,
2824 struct rockchip_pin_bank
*bank
;
2831 dev_dbg(info
->dev
, "group(%d): %pOFn\n", index
, np
);
2833 /* Initialise group */
2834 grp
->name
= np
->name
;
2837 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2838 * do sanity check and calculate pins number
2840 list
= of_get_property(np
, "rockchip,pins", &size
);
2841 /* we do not check return since it's safe node passed down */
2842 size
/= sizeof(*list
);
2843 if (!size
|| size
% 4) {
2844 dev_err(info
->dev
, "wrong pins number or pins and configs should be by 4\n");
2848 grp
->npins
= size
/ 4;
2850 grp
->pins
= devm_kcalloc(info
->dev
, grp
->npins
, sizeof(unsigned int),
2852 grp
->data
= devm_kcalloc(info
->dev
,
2854 sizeof(struct rockchip_pin_config
),
2856 if (!grp
->pins
|| !grp
->data
)
2859 for (i
= 0, j
= 0; i
< size
; i
+= 4, j
++) {
2860 const __be32
*phandle
;
2861 struct device_node
*np_config
;
2863 num
= be32_to_cpu(*list
++);
2864 bank
= bank_num_to_bank(info
, num
);
2866 return PTR_ERR(bank
);
2868 grp
->pins
[j
] = bank
->pin_base
+ be32_to_cpu(*list
++);
2869 grp
->data
[j
].func
= be32_to_cpu(*list
++);
2875 np_config
= of_find_node_by_phandle(be32_to_cpup(phandle
));
2876 ret
= pinconf_generic_parse_dt_config(np_config
, NULL
,
2877 &grp
->data
[j
].configs
, &grp
->data
[j
].nconfigs
);
2885 static int rockchip_pinctrl_parse_functions(struct device_node
*np
,
2886 struct rockchip_pinctrl
*info
,
2889 struct device_node
*child
;
2890 struct rockchip_pmx_func
*func
;
2891 struct rockchip_pin_group
*grp
;
2893 static u32 grp_index
;
2896 dev_dbg(info
->dev
, "parse function(%d): %pOFn\n", index
, np
);
2898 func
= &info
->functions
[index
];
2900 /* Initialise function */
2901 func
->name
= np
->name
;
2902 func
->ngroups
= of_get_child_count(np
);
2903 if (func
->ngroups
<= 0)
2906 func
->groups
= devm_kcalloc(info
->dev
,
2907 func
->ngroups
, sizeof(char *), GFP_KERNEL
);
2911 for_each_child_of_node(np
, child
) {
2912 func
->groups
[i
] = child
->name
;
2913 grp
= &info
->groups
[grp_index
++];
2914 ret
= rockchip_pinctrl_parse_groups(child
, grp
, info
, i
++);
2924 static int rockchip_pinctrl_parse_dt(struct platform_device
*pdev
,
2925 struct rockchip_pinctrl
*info
)
2927 struct device
*dev
= &pdev
->dev
;
2928 struct device_node
*np
= dev
->of_node
;
2929 struct device_node
*child
;
2933 rockchip_pinctrl_child_count(info
, np
);
2935 dev_dbg(&pdev
->dev
, "nfunctions = %d\n", info
->nfunctions
);
2936 dev_dbg(&pdev
->dev
, "ngroups = %d\n", info
->ngroups
);
2938 info
->functions
= devm_kcalloc(dev
,
2940 sizeof(struct rockchip_pmx_func
),
2942 if (!info
->functions
)
2945 info
->groups
= devm_kcalloc(dev
,
2947 sizeof(struct rockchip_pin_group
),
2954 for_each_child_of_node(np
, child
) {
2955 if (of_match_node(rockchip_bank_match
, child
))
2958 ret
= rockchip_pinctrl_parse_functions(child
, info
, i
++);
2960 dev_err(&pdev
->dev
, "failed to parse function\n");
2969 static int rockchip_pinctrl_register(struct platform_device
*pdev
,
2970 struct rockchip_pinctrl
*info
)
2972 struct pinctrl_desc
*ctrldesc
= &info
->pctl
;
2973 struct pinctrl_pin_desc
*pindesc
, *pdesc
;
2974 struct rockchip_pin_bank
*pin_bank
;
2978 ctrldesc
->name
= "rockchip-pinctrl";
2979 ctrldesc
->owner
= THIS_MODULE
;
2980 ctrldesc
->pctlops
= &rockchip_pctrl_ops
;
2981 ctrldesc
->pmxops
= &rockchip_pmx_ops
;
2982 ctrldesc
->confops
= &rockchip_pinconf_ops
;
2984 pindesc
= devm_kcalloc(&pdev
->dev
,
2985 info
->ctrl
->nr_pins
, sizeof(*pindesc
),
2990 ctrldesc
->pins
= pindesc
;
2991 ctrldesc
->npins
= info
->ctrl
->nr_pins
;
2994 for (bank
= 0 , k
= 0; bank
< info
->ctrl
->nr_banks
; bank
++) {
2995 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
2996 for (pin
= 0; pin
< pin_bank
->nr_pins
; pin
++, k
++) {
2998 pdesc
->name
= kasprintf(GFP_KERNEL
, "%s-%d",
2999 pin_bank
->name
, pin
);
3004 ret
= rockchip_pinctrl_parse_dt(pdev
, info
);
3008 info
->pctl_dev
= devm_pinctrl_register(&pdev
->dev
, ctrldesc
, info
);
3009 if (IS_ERR(info
->pctl_dev
)) {
3010 dev_err(&pdev
->dev
, "could not register pinctrl driver\n");
3011 return PTR_ERR(info
->pctl_dev
);
3014 for (bank
= 0; bank
< info
->ctrl
->nr_banks
; ++bank
) {
3015 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
3016 pin_bank
->grange
.name
= pin_bank
->name
;
3017 pin_bank
->grange
.id
= bank
;
3018 pin_bank
->grange
.pin_base
= pin_bank
->pin_base
;
3019 pin_bank
->grange
.base
= pin_bank
->gpio_chip
.base
;
3020 pin_bank
->grange
.npins
= pin_bank
->gpio_chip
.ngpio
;
3021 pin_bank
->grange
.gc
= &pin_bank
->gpio_chip
;
3022 pinctrl_add_gpio_range(info
->pctl_dev
, &pin_bank
->grange
);
3032 static void rockchip_gpio_set(struct gpio_chip
*gc
, unsigned offset
, int value
)
3034 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
3035 void __iomem
*reg
= bank
->reg_base
+ GPIO_SWPORT_DR
;
3036 unsigned long flags
;
3039 clk_enable(bank
->clk
);
3040 raw_spin_lock_irqsave(&bank
->slock
, flags
);
3043 data
&= ~BIT(offset
);
3045 data
|= BIT(offset
);
3048 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3049 clk_disable(bank
->clk
);
3053 * Returns the level of the pin for input direction and setting of the DR
3054 * register for output gpios.
3056 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
)
3058 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
3061 clk_enable(bank
->clk
);
3062 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
3063 clk_disable(bank
->clk
);
3070 * gpiolib gpio_direction_input callback function. The setting of the pin
3071 * mux function as 'gpio input' will be handled by the pinctrl subsystem
3074 static int rockchip_gpio_direction_input(struct gpio_chip
*gc
, unsigned offset
)
3076 return pinctrl_gpio_direction_input(gc
->base
+ offset
);
3080 * gpiolib gpio_direction_output callback function. The setting of the pin
3081 * mux function as 'gpio output' will be handled by the pinctrl subsystem
3084 static int rockchip_gpio_direction_output(struct gpio_chip
*gc
,
3085 unsigned offset
, int value
)
3087 rockchip_gpio_set(gc
, offset
, value
);
3088 return pinctrl_gpio_direction_output(gc
->base
+ offset
);
3091 static void rockchip_gpio_set_debounce(struct gpio_chip
*gc
,
3092 unsigned int offset
, bool enable
)
3094 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
3095 void __iomem
*reg
= bank
->reg_base
+ GPIO_DEBOUNCE
;
3096 unsigned long flags
;
3099 clk_enable(bank
->clk
);
3100 raw_spin_lock_irqsave(&bank
->slock
, flags
);
3104 data
|= BIT(offset
);
3106 data
&= ~BIT(offset
);
3109 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3110 clk_disable(bank
->clk
);
3114 * gpiolib set_config callback function. The setting of the pin
3115 * mux function as 'gpio output' will be handled by the pinctrl subsystem
3118 static int rockchip_gpio_set_config(struct gpio_chip
*gc
, unsigned int offset
,
3119 unsigned long config
)
3121 enum pin_config_param param
= pinconf_to_config_param(config
);
3124 case PIN_CONFIG_INPUT_DEBOUNCE
:
3125 rockchip_gpio_set_debounce(gc
, offset
, true);
3127 * Rockchip's gpio could only support up to one period
3128 * of the debounce clock(pclk), which is far away from
3129 * satisftying the requirement, as pclk is usually near
3130 * 100MHz shared by all peripherals. So the fact is it
3131 * has crippled debounce capability could only be useful
3132 * to prevent any spurious glitches from waking up the system
3133 * if the gpio is conguired as wakeup interrupt source. Let's
3134 * still return -ENOTSUPP as before, to make sure the caller
3135 * of gpiod_set_debounce won't change its behaviour.
3144 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
3145 * and a virtual IRQ, if not already present.
3147 static int rockchip_gpio_to_irq(struct gpio_chip
*gc
, unsigned offset
)
3149 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
3155 virq
= irq_create_mapping(bank
->domain
, offset
);
3157 return (virq
) ? : -ENXIO
;
3160 static const struct gpio_chip rockchip_gpiolib_chip
= {
3161 .request
= gpiochip_generic_request
,
3162 .free
= gpiochip_generic_free
,
3163 .set
= rockchip_gpio_set
,
3164 .get
= rockchip_gpio_get
,
3165 .get_direction
= rockchip_gpio_get_direction
,
3166 .direction_input
= rockchip_gpio_direction_input
,
3167 .direction_output
= rockchip_gpio_direction_output
,
3168 .set_config
= rockchip_gpio_set_config
,
3169 .to_irq
= rockchip_gpio_to_irq
,
3170 .owner
= THIS_MODULE
,
3174 * Interrupt handling
3177 static void rockchip_irq_demux(struct irq_desc
*desc
)
3179 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
3180 struct rockchip_pin_bank
*bank
= irq_desc_get_handler_data(desc
);
3183 dev_dbg(bank
->drvdata
->dev
, "got irq for bank %s\n", bank
->name
);
3185 chained_irq_enter(chip
, desc
);
3187 pend
= readl_relaxed(bank
->reg_base
+ GPIO_INT_STATUS
);
3190 unsigned int irq
, virq
;
3194 virq
= irq_linear_revmap(bank
->domain
, irq
);
3197 dev_err(bank
->drvdata
->dev
, "unmapped irq %d\n", irq
);
3201 dev_dbg(bank
->drvdata
->dev
, "handling irq %d\n", irq
);
3204 * Triggering IRQ on both rising and falling edge
3205 * needs manual intervention.
3207 if (bank
->toggle_edge_mode
& BIT(irq
)) {
3208 u32 data
, data_old
, polarity
;
3209 unsigned long flags
;
3211 data
= readl_relaxed(bank
->reg_base
+ GPIO_EXT_PORT
);
3213 raw_spin_lock_irqsave(&bank
->slock
, flags
);
3215 polarity
= readl_relaxed(bank
->reg_base
+
3217 if (data
& BIT(irq
))
3218 polarity
&= ~BIT(irq
);
3220 polarity
|= BIT(irq
);
3222 bank
->reg_base
+ GPIO_INT_POLARITY
);
3224 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3227 data
= readl_relaxed(bank
->reg_base
+
3229 } while ((data
& BIT(irq
)) != (data_old
& BIT(irq
)));
3232 generic_handle_irq(virq
);
3235 chained_irq_exit(chip
, desc
);
3238 static int rockchip_irq_set_type(struct irq_data
*d
, unsigned int type
)
3240 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
3241 struct rockchip_pin_bank
*bank
= gc
->private;
3242 u32 mask
= BIT(d
->hwirq
);
3246 unsigned long flags
;
3249 /* make sure the pin is configured as gpio input */
3250 ret
= rockchip_set_mux(bank
, d
->hwirq
, RK_FUNC_GPIO
);
3254 clk_enable(bank
->clk
);
3255 raw_spin_lock_irqsave(&bank
->slock
, flags
);
3257 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
3259 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
3261 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3263 if (type
& IRQ_TYPE_EDGE_BOTH
)
3264 irq_set_handler_locked(d
, handle_edge_irq
);
3266 irq_set_handler_locked(d
, handle_level_irq
);
3268 raw_spin_lock_irqsave(&bank
->slock
, flags
);
3271 level
= readl_relaxed(gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
3272 polarity
= readl_relaxed(gc
->reg_base
+ GPIO_INT_POLARITY
);
3275 case IRQ_TYPE_EDGE_BOTH
:
3276 bank
->toggle_edge_mode
|= mask
;
3280 * Determine gpio state. If 1 next interrupt should be falling
3283 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
3289 case IRQ_TYPE_EDGE_RISING
:
3290 bank
->toggle_edge_mode
&= ~mask
;
3294 case IRQ_TYPE_EDGE_FALLING
:
3295 bank
->toggle_edge_mode
&= ~mask
;
3299 case IRQ_TYPE_LEVEL_HIGH
:
3300 bank
->toggle_edge_mode
&= ~mask
;
3304 case IRQ_TYPE_LEVEL_LOW
:
3305 bank
->toggle_edge_mode
&= ~mask
;
3311 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3312 clk_disable(bank
->clk
);
3316 writel_relaxed(level
, gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
3317 writel_relaxed(polarity
, gc
->reg_base
+ GPIO_INT_POLARITY
);
3320 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
3321 clk_disable(bank
->clk
);
3326 static void rockchip_irq_suspend(struct irq_data
*d
)
3328 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
3329 struct rockchip_pin_bank
*bank
= gc
->private;
3331 clk_enable(bank
->clk
);
3332 bank
->saved_masks
= irq_reg_readl(gc
, GPIO_INTMASK
);
3333 irq_reg_writel(gc
, ~gc
->wake_active
, GPIO_INTMASK
);
3334 clk_disable(bank
->clk
);
3337 static void rockchip_irq_resume(struct irq_data
*d
)
3339 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
3340 struct rockchip_pin_bank
*bank
= gc
->private;
3342 clk_enable(bank
->clk
);
3343 irq_reg_writel(gc
, bank
->saved_masks
, GPIO_INTMASK
);
3344 clk_disable(bank
->clk
);
3347 static void rockchip_irq_enable(struct irq_data
*d
)
3349 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
3350 struct rockchip_pin_bank
*bank
= gc
->private;
3352 clk_enable(bank
->clk
);
3353 irq_gc_mask_clr_bit(d
);
3356 static void rockchip_irq_disable(struct irq_data
*d
)
3358 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
3359 struct rockchip_pin_bank
*bank
= gc
->private;
3361 irq_gc_mask_set_bit(d
);
3362 clk_disable(bank
->clk
);
3365 static int rockchip_interrupts_register(struct platform_device
*pdev
,
3366 struct rockchip_pinctrl
*info
)
3368 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
3369 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
3370 unsigned int clr
= IRQ_NOREQUEST
| IRQ_NOPROBE
| IRQ_NOAUTOEN
;
3371 struct irq_chip_generic
*gc
;
3375 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3377 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
3382 ret
= clk_enable(bank
->clk
);
3384 dev_err(&pdev
->dev
, "failed to enable clock for bank %s\n",
3389 bank
->domain
= irq_domain_add_linear(bank
->of_node
, 32,
3390 &irq_generic_chip_ops
, NULL
);
3391 if (!bank
->domain
) {
3392 dev_warn(&pdev
->dev
, "could not initialize irq domain for bank %s\n",
3394 clk_disable(bank
->clk
);
3398 ret
= irq_alloc_domain_generic_chips(bank
->domain
, 32, 1,
3399 "rockchip_gpio_irq", handle_level_irq
,
3400 clr
, 0, IRQ_GC_INIT_MASK_CACHE
);
3402 dev_err(&pdev
->dev
, "could not alloc generic chips for bank %s\n",
3404 irq_domain_remove(bank
->domain
);
3405 clk_disable(bank
->clk
);
3410 * Linux assumes that all interrupts start out disabled/masked.
3411 * Our driver only uses the concept of masked and always keeps
3412 * things enabled, so for us that's all masked and all enabled.
3414 writel_relaxed(0xffffffff, bank
->reg_base
+ GPIO_INTMASK
);
3415 writel_relaxed(0xffffffff, bank
->reg_base
+ GPIO_INTEN
);
3417 gc
= irq_get_domain_generic_chip(bank
->domain
, 0);
3418 gc
->reg_base
= bank
->reg_base
;
3420 gc
->chip_types
[0].regs
.mask
= GPIO_INTMASK
;
3421 gc
->chip_types
[0].regs
.ack
= GPIO_PORTS_EOI
;
3422 gc
->chip_types
[0].chip
.irq_ack
= irq_gc_ack_set_bit
;
3423 gc
->chip_types
[0].chip
.irq_mask
= irq_gc_mask_set_bit
;
3424 gc
->chip_types
[0].chip
.irq_unmask
= irq_gc_mask_clr_bit
;
3425 gc
->chip_types
[0].chip
.irq_enable
= rockchip_irq_enable
;
3426 gc
->chip_types
[0].chip
.irq_disable
= rockchip_irq_disable
;
3427 gc
->chip_types
[0].chip
.irq_set_wake
= irq_gc_set_wake
;
3428 gc
->chip_types
[0].chip
.irq_suspend
= rockchip_irq_suspend
;
3429 gc
->chip_types
[0].chip
.irq_resume
= rockchip_irq_resume
;
3430 gc
->chip_types
[0].chip
.irq_set_type
= rockchip_irq_set_type
;
3431 gc
->wake_enabled
= IRQ_MSK(bank
->nr_pins
);
3433 irq_set_chained_handler_and_data(bank
->irq
,
3434 rockchip_irq_demux
, bank
);
3436 /* map the gpio irqs here, when the clock is still running */
3437 for (j
= 0 ; j
< 32 ; j
++)
3438 irq_create_mapping(bank
->domain
, j
);
3440 clk_disable(bank
->clk
);
3446 static int rockchip_gpiolib_register(struct platform_device
*pdev
,
3447 struct rockchip_pinctrl
*info
)
3449 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
3450 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
3451 struct gpio_chip
*gc
;
3455 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3457 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
3462 bank
->gpio_chip
= rockchip_gpiolib_chip
;
3464 gc
= &bank
->gpio_chip
;
3465 gc
->base
= bank
->pin_base
;
3466 gc
->ngpio
= bank
->nr_pins
;
3467 gc
->parent
= &pdev
->dev
;
3468 gc
->of_node
= bank
->of_node
;
3469 gc
->label
= bank
->name
;
3471 ret
= gpiochip_add_data(gc
, bank
);
3473 dev_err(&pdev
->dev
, "failed to register gpio_chip %s, error code: %d\n",
3479 rockchip_interrupts_register(pdev
, info
);
3484 for (--i
, --bank
; i
>= 0; --i
, --bank
) {
3487 gpiochip_remove(&bank
->gpio_chip
);
3492 static int rockchip_gpiolib_unregister(struct platform_device
*pdev
,
3493 struct rockchip_pinctrl
*info
)
3495 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
3496 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
3499 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3502 gpiochip_remove(&bank
->gpio_chip
);
3508 static int rockchip_get_bank_data(struct rockchip_pin_bank
*bank
,
3509 struct rockchip_pinctrl
*info
)
3511 struct resource res
;
3514 if (of_address_to_resource(bank
->of_node
, 0, &res
)) {
3515 dev_err(info
->dev
, "cannot find IO resource for bank\n");
3519 bank
->reg_base
= devm_ioremap_resource(info
->dev
, &res
);
3520 if (IS_ERR(bank
->reg_base
))
3521 return PTR_ERR(bank
->reg_base
);
3524 * special case, where parts of the pull setting-registers are
3525 * part of the PMU register space
3527 if (of_device_is_compatible(bank
->of_node
,
3528 "rockchip,rk3188-gpio-bank0")) {
3529 struct device_node
*node
;
3531 node
= of_parse_phandle(bank
->of_node
->parent
,
3534 if (of_address_to_resource(bank
->of_node
, 1, &res
)) {
3535 dev_err(info
->dev
, "cannot find IO resource for bank\n");
3539 base
= devm_ioremap_resource(info
->dev
, &res
);
3541 return PTR_ERR(base
);
3542 rockchip_regmap_config
.max_register
=
3543 resource_size(&res
) - 4;
3544 rockchip_regmap_config
.name
=
3545 "rockchip,rk3188-gpio-bank0-pull";
3546 bank
->regmap_pull
= devm_regmap_init_mmio(info
->dev
,
3548 &rockchip_regmap_config
);
3553 bank
->irq
= irq_of_parse_and_map(bank
->of_node
, 0);
3555 bank
->clk
= of_clk_get(bank
->of_node
, 0);
3556 if (IS_ERR(bank
->clk
))
3557 return PTR_ERR(bank
->clk
);
3559 return clk_prepare(bank
->clk
);
3562 static const struct of_device_id rockchip_pinctrl_dt_match
[];
3564 /* retrieve the soc specific data */
3565 static struct rockchip_pin_ctrl
*rockchip_pinctrl_get_soc_data(
3566 struct rockchip_pinctrl
*d
,
3567 struct platform_device
*pdev
)
3569 const struct of_device_id
*match
;
3570 struct device_node
*node
= pdev
->dev
.of_node
;
3571 struct device_node
*np
;
3572 struct rockchip_pin_ctrl
*ctrl
;
3573 struct rockchip_pin_bank
*bank
;
3574 int grf_offs
, pmu_offs
, drv_grf_offs
, drv_pmu_offs
, i
, j
;
3576 match
= of_match_node(rockchip_pinctrl_dt_match
, node
);
3577 ctrl
= (struct rockchip_pin_ctrl
*)match
->data
;
3579 for_each_child_of_node(node
, np
) {
3580 if (!of_find_property(np
, "gpio-controller", NULL
))
3583 bank
= ctrl
->pin_banks
;
3584 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3585 if (!strcmp(bank
->name
, np
->name
)) {
3588 if (!rockchip_get_bank_data(bank
, d
))
3596 grf_offs
= ctrl
->grf_mux_offset
;
3597 pmu_offs
= ctrl
->pmu_mux_offset
;
3598 drv_pmu_offs
= ctrl
->pmu_drv_offset
;
3599 drv_grf_offs
= ctrl
->grf_drv_offset
;
3600 bank
= ctrl
->pin_banks
;
3601 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3604 raw_spin_lock_init(&bank
->slock
);
3606 bank
->pin_base
= ctrl
->nr_pins
;
3607 ctrl
->nr_pins
+= bank
->nr_pins
;
3609 /* calculate iomux and drv offsets */
3610 for (j
= 0; j
< 4; j
++) {
3611 struct rockchip_iomux
*iom
= &bank
->iomux
[j
];
3612 struct rockchip_drv
*drv
= &bank
->drv
[j
];
3615 if (bank_pins
>= bank
->nr_pins
)
3618 /* preset iomux offset value, set new start value */
3619 if (iom
->offset
>= 0) {
3620 if (iom
->type
& IOMUX_SOURCE_PMU
)
3621 pmu_offs
= iom
->offset
;
3623 grf_offs
= iom
->offset
;
3624 } else { /* set current iomux offset */
3625 iom
->offset
= (iom
->type
& IOMUX_SOURCE_PMU
) ?
3626 pmu_offs
: grf_offs
;
3629 /* preset drv offset value, set new start value */
3630 if (drv
->offset
>= 0) {
3631 if (iom
->type
& IOMUX_SOURCE_PMU
)
3632 drv_pmu_offs
= drv
->offset
;
3634 drv_grf_offs
= drv
->offset
;
3635 } else { /* set current drv offset */
3636 drv
->offset
= (iom
->type
& IOMUX_SOURCE_PMU
) ?
3637 drv_pmu_offs
: drv_grf_offs
;
3640 dev_dbg(d
->dev
, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3641 i
, j
, iom
->offset
, drv
->offset
);
3644 * Increase offset according to iomux width.
3645 * 4bit iomux'es are spread over two registers.
3647 inc
= (iom
->type
& (IOMUX_WIDTH_4BIT
|
3649 IOMUX_WIDTH_2BIT
)) ? 8 : 4;
3650 if (iom
->type
& IOMUX_SOURCE_PMU
)
3656 * Increase offset according to drv width.
3657 * 3bit drive-strenth'es are spread over two registers.
3659 if ((drv
->drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
3660 (drv
->drv_type
== DRV_TYPE_IO_3V3_ONLY
))
3665 if (iom
->type
& IOMUX_SOURCE_PMU
)
3666 drv_pmu_offs
+= inc
;
3668 drv_grf_offs
+= inc
;
3673 /* calculate the per-bank recalced_mask */
3674 for (j
= 0; j
< ctrl
->niomux_recalced
; j
++) {
3677 if (ctrl
->iomux_recalced
[j
].num
== bank
->bank_num
) {
3678 pin
= ctrl
->iomux_recalced
[j
].pin
;
3679 bank
->recalced_mask
|= BIT(pin
);
3683 /* calculate the per-bank route_mask */
3684 for (j
= 0; j
< ctrl
->niomux_routes
; j
++) {
3687 if (ctrl
->iomux_routes
[j
].bank_num
== bank
->bank_num
) {
3688 pin
= ctrl
->iomux_routes
[j
].pin
;
3689 bank
->route_mask
|= BIT(pin
);
3697 #define RK3288_GRF_GPIO6C_IOMUX 0x64
3698 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3700 static u32 rk3288_grf_gpio6c_iomux
;
3702 static int __maybe_unused
rockchip_pinctrl_suspend(struct device
*dev
)
3704 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3705 int ret
= pinctrl_force_sleep(info
->pctl_dev
);
3711 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3712 * the setting here, and restore it at resume.
3714 if (info
->ctrl
->type
== RK3288
) {
3715 ret
= regmap_read(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3716 &rk3288_grf_gpio6c_iomux
);
3718 pinctrl_force_default(info
->pctl_dev
);
3726 static int __maybe_unused
rockchip_pinctrl_resume(struct device
*dev
)
3728 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3729 int ret
= regmap_write(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3730 rk3288_grf_gpio6c_iomux
|
3731 GPIO6C6_SEL_WRITE_ENABLE
);
3736 return pinctrl_force_default(info
->pctl_dev
);
3739 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops
, rockchip_pinctrl_suspend
,
3740 rockchip_pinctrl_resume
);
3742 static int rockchip_pinctrl_probe(struct platform_device
*pdev
)
3744 struct rockchip_pinctrl
*info
;
3745 struct device
*dev
= &pdev
->dev
;
3746 struct rockchip_pin_ctrl
*ctrl
;
3747 struct device_node
*np
= pdev
->dev
.of_node
, *node
;
3748 struct resource
*res
;
3752 if (!dev
->of_node
) {
3753 dev_err(dev
, "device tree node not found\n");
3757 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
3763 ctrl
= rockchip_pinctrl_get_soc_data(info
, pdev
);
3765 dev_err(dev
, "driver data not available\n");
3770 node
= of_parse_phandle(np
, "rockchip,grf", 0);
3772 info
->regmap_base
= syscon_node_to_regmap(node
);
3773 if (IS_ERR(info
->regmap_base
))
3774 return PTR_ERR(info
->regmap_base
);
3776 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
3777 base
= devm_ioremap_resource(&pdev
->dev
, res
);
3779 return PTR_ERR(base
);
3781 rockchip_regmap_config
.max_register
= resource_size(res
) - 4;
3782 rockchip_regmap_config
.name
= "rockchip,pinctrl";
3783 info
->regmap_base
= devm_regmap_init_mmio(&pdev
->dev
, base
,
3784 &rockchip_regmap_config
);
3786 /* to check for the old dt-bindings */
3787 info
->reg_size
= resource_size(res
);
3789 /* Honor the old binding, with pull registers as 2nd resource */
3790 if (ctrl
->type
== RK3188
&& info
->reg_size
< 0x200) {
3791 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
3792 base
= devm_ioremap_resource(&pdev
->dev
, res
);
3794 return PTR_ERR(base
);
3796 rockchip_regmap_config
.max_register
=
3797 resource_size(res
) - 4;
3798 rockchip_regmap_config
.name
= "rockchip,pinctrl-pull";
3799 info
->regmap_pull
= devm_regmap_init_mmio(&pdev
->dev
,
3801 &rockchip_regmap_config
);
3805 /* try to find the optional reference to the pmu syscon */
3806 node
= of_parse_phandle(np
, "rockchip,pmu", 0);
3808 info
->regmap_pmu
= syscon_node_to_regmap(node
);
3809 if (IS_ERR(info
->regmap_pmu
))
3810 return PTR_ERR(info
->regmap_pmu
);
3813 ret
= rockchip_gpiolib_register(pdev
, info
);
3817 ret
= rockchip_pinctrl_register(pdev
, info
);
3819 rockchip_gpiolib_unregister(pdev
, info
);
3823 platform_set_drvdata(pdev
, info
);
3828 static struct rockchip_pin_bank px30_pin_banks
[] = {
3829 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3834 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT
,
3839 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT
,
3844 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT
,
3851 static struct rockchip_pin_ctrl px30_pin_ctrl
= {
3852 .pin_banks
= px30_pin_banks
,
3853 .nr_banks
= ARRAY_SIZE(px30_pin_banks
),
3854 .label
= "PX30-GPIO",
3856 .grf_mux_offset
= 0x0,
3857 .pmu_mux_offset
= 0x0,
3858 .iomux_routes
= px30_mux_route_data
,
3859 .niomux_routes
= ARRAY_SIZE(px30_mux_route_data
),
3860 .pull_calc_reg
= px30_calc_pull_reg_and_bit
,
3861 .drv_calc_reg
= px30_calc_drv_reg_and_bit
,
3862 .schmitt_calc_reg
= px30_calc_schmitt_reg_and_bit
,
3865 static struct rockchip_pin_bank rv1108_pin_banks
[] = {
3866 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3870 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3871 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3872 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3875 static struct rockchip_pin_ctrl rv1108_pin_ctrl
= {
3876 .pin_banks
= rv1108_pin_banks
,
3877 .nr_banks
= ARRAY_SIZE(rv1108_pin_banks
),
3878 .label
= "RV1108-GPIO",
3880 .grf_mux_offset
= 0x10,
3881 .pmu_mux_offset
= 0x0,
3882 .iomux_recalced
= rv1108_mux_recalced_data
,
3883 .niomux_recalced
= ARRAY_SIZE(rv1108_mux_recalced_data
),
3884 .pull_calc_reg
= rv1108_calc_pull_reg_and_bit
,
3885 .drv_calc_reg
= rv1108_calc_drv_reg_and_bit
,
3886 .schmitt_calc_reg
= rv1108_calc_schmitt_reg_and_bit
,
3889 static struct rockchip_pin_bank rk2928_pin_banks
[] = {
3890 PIN_BANK(0, 32, "gpio0"),
3891 PIN_BANK(1, 32, "gpio1"),
3892 PIN_BANK(2, 32, "gpio2"),
3893 PIN_BANK(3, 32, "gpio3"),
3896 static struct rockchip_pin_ctrl rk2928_pin_ctrl
= {
3897 .pin_banks
= rk2928_pin_banks
,
3898 .nr_banks
= ARRAY_SIZE(rk2928_pin_banks
),
3899 .label
= "RK2928-GPIO",
3901 .grf_mux_offset
= 0xa8,
3902 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3905 static struct rockchip_pin_bank rk3036_pin_banks
[] = {
3906 PIN_BANK(0, 32, "gpio0"),
3907 PIN_BANK(1, 32, "gpio1"),
3908 PIN_BANK(2, 32, "gpio2"),
3911 static struct rockchip_pin_ctrl rk3036_pin_ctrl
= {
3912 .pin_banks
= rk3036_pin_banks
,
3913 .nr_banks
= ARRAY_SIZE(rk3036_pin_banks
),
3914 .label
= "RK3036-GPIO",
3916 .grf_mux_offset
= 0xa8,
3917 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3920 static struct rockchip_pin_bank rk3066a_pin_banks
[] = {
3921 PIN_BANK(0, 32, "gpio0"),
3922 PIN_BANK(1, 32, "gpio1"),
3923 PIN_BANK(2, 32, "gpio2"),
3924 PIN_BANK(3, 32, "gpio3"),
3925 PIN_BANK(4, 32, "gpio4"),
3926 PIN_BANK(6, 16, "gpio6"),
3929 static struct rockchip_pin_ctrl rk3066a_pin_ctrl
= {
3930 .pin_banks
= rk3066a_pin_banks
,
3931 .nr_banks
= ARRAY_SIZE(rk3066a_pin_banks
),
3932 .label
= "RK3066a-GPIO",
3934 .grf_mux_offset
= 0xa8,
3935 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3938 static struct rockchip_pin_bank rk3066b_pin_banks
[] = {
3939 PIN_BANK(0, 32, "gpio0"),
3940 PIN_BANK(1, 32, "gpio1"),
3941 PIN_BANK(2, 32, "gpio2"),
3942 PIN_BANK(3, 32, "gpio3"),
3945 static struct rockchip_pin_ctrl rk3066b_pin_ctrl
= {
3946 .pin_banks
= rk3066b_pin_banks
,
3947 .nr_banks
= ARRAY_SIZE(rk3066b_pin_banks
),
3948 .label
= "RK3066b-GPIO",
3950 .grf_mux_offset
= 0x60,
3953 static struct rockchip_pin_bank rk3128_pin_banks
[] = {
3954 PIN_BANK(0, 32, "gpio0"),
3955 PIN_BANK(1, 32, "gpio1"),
3956 PIN_BANK(2, 32, "gpio2"),
3957 PIN_BANK(3, 32, "gpio3"),
3960 static struct rockchip_pin_ctrl rk3128_pin_ctrl
= {
3961 .pin_banks
= rk3128_pin_banks
,
3962 .nr_banks
= ARRAY_SIZE(rk3128_pin_banks
),
3963 .label
= "RK3128-GPIO",
3965 .grf_mux_offset
= 0xa8,
3966 .iomux_recalced
= rk3128_mux_recalced_data
,
3967 .niomux_recalced
= ARRAY_SIZE(rk3128_mux_recalced_data
),
3968 .iomux_routes
= rk3128_mux_route_data
,
3969 .niomux_routes
= ARRAY_SIZE(rk3128_mux_route_data
),
3970 .pull_calc_reg
= rk3128_calc_pull_reg_and_bit
,
3973 static struct rockchip_pin_bank rk3188_pin_banks
[] = {
3974 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY
, 0, 0, 0),
3975 PIN_BANK(1, 32, "gpio1"),
3976 PIN_BANK(2, 32, "gpio2"),
3977 PIN_BANK(3, 32, "gpio3"),
3980 static struct rockchip_pin_ctrl rk3188_pin_ctrl
= {
3981 .pin_banks
= rk3188_pin_banks
,
3982 .nr_banks
= ARRAY_SIZE(rk3188_pin_banks
),
3983 .label
= "RK3188-GPIO",
3985 .grf_mux_offset
= 0x60,
3986 .iomux_routes
= rk3188_mux_route_data
,
3987 .niomux_routes
= ARRAY_SIZE(rk3188_mux_route_data
),
3988 .pull_calc_reg
= rk3188_calc_pull_reg_and_bit
,
3991 static struct rockchip_pin_bank rk3228_pin_banks
[] = {
3992 PIN_BANK(0, 32, "gpio0"),
3993 PIN_BANK(1, 32, "gpio1"),
3994 PIN_BANK(2, 32, "gpio2"),
3995 PIN_BANK(3, 32, "gpio3"),
3998 static struct rockchip_pin_ctrl rk3228_pin_ctrl
= {
3999 .pin_banks
= rk3228_pin_banks
,
4000 .nr_banks
= ARRAY_SIZE(rk3228_pin_banks
),
4001 .label
= "RK3228-GPIO",
4003 .grf_mux_offset
= 0x0,
4004 .iomux_routes
= rk3228_mux_route_data
,
4005 .niomux_routes
= ARRAY_SIZE(rk3228_mux_route_data
),
4006 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
4007 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
4010 static struct rockchip_pin_bank rk3288_pin_banks
[] = {
4011 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU
,
4016 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED
,
4021 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED
),
4022 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT
),
4023 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT
,
4028 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED
,
4033 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED
),
4034 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
4039 PIN_BANK(8, 16, "gpio8"),
4042 static struct rockchip_pin_ctrl rk3288_pin_ctrl
= {
4043 .pin_banks
= rk3288_pin_banks
,
4044 .nr_banks
= ARRAY_SIZE(rk3288_pin_banks
),
4045 .label
= "RK3288-GPIO",
4047 .grf_mux_offset
= 0x0,
4048 .pmu_mux_offset
= 0x84,
4049 .iomux_routes
= rk3288_mux_route_data
,
4050 .niomux_routes
= ARRAY_SIZE(rk3288_mux_route_data
),
4051 .pull_calc_reg
= rk3288_calc_pull_reg_and_bit
,
4052 .drv_calc_reg
= rk3288_calc_drv_reg_and_bit
,
4055 static struct rockchip_pin_bank rk3308_pin_banks
[] = {
4056 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_WIDTH_2BIT
,
4060 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_2BIT
,
4064 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_2BIT
,
4068 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_2BIT
,
4072 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_2BIT
,
4078 static struct rockchip_pin_ctrl rk3308_pin_ctrl
= {
4079 .pin_banks
= rk3308_pin_banks
,
4080 .nr_banks
= ARRAY_SIZE(rk3308_pin_banks
),
4081 .label
= "RK3308-GPIO",
4083 .grf_mux_offset
= 0x0,
4084 .iomux_recalced
= rk3308_mux_recalced_data
,
4085 .niomux_recalced
= ARRAY_SIZE(rk3308_mux_recalced_data
),
4086 .iomux_routes
= rk3308_mux_route_data
,
4087 .niomux_routes
= ARRAY_SIZE(rk3308_mux_route_data
),
4088 .pull_calc_reg
= rk3308_calc_pull_reg_and_bit
,
4089 .drv_calc_reg
= rk3308_calc_drv_reg_and_bit
,
4090 .schmitt_calc_reg
= rk3308_calc_schmitt_reg_and_bit
,
4093 static struct rockchip_pin_bank rk3328_pin_banks
[] = {
4094 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
4095 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
4096 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
4100 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
4107 static struct rockchip_pin_ctrl rk3328_pin_ctrl
= {
4108 .pin_banks
= rk3328_pin_banks
,
4109 .nr_banks
= ARRAY_SIZE(rk3328_pin_banks
),
4110 .label
= "RK3328-GPIO",
4112 .grf_mux_offset
= 0x0,
4113 .iomux_recalced
= rk3328_mux_recalced_data
,
4114 .niomux_recalced
= ARRAY_SIZE(rk3328_mux_recalced_data
),
4115 .iomux_routes
= rk3328_mux_route_data
,
4116 .niomux_routes
= ARRAY_SIZE(rk3328_mux_route_data
),
4117 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
4118 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
4119 .schmitt_calc_reg
= rk3328_calc_schmitt_reg_and_bit
,
4122 static struct rockchip_pin_bank rk3368_pin_banks
[] = {
4123 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
4128 PIN_BANK(1, 32, "gpio1"),
4129 PIN_BANK(2, 32, "gpio2"),
4130 PIN_BANK(3, 32, "gpio3"),
4133 static struct rockchip_pin_ctrl rk3368_pin_ctrl
= {
4134 .pin_banks
= rk3368_pin_banks
,
4135 .nr_banks
= ARRAY_SIZE(rk3368_pin_banks
),
4136 .label
= "RK3368-GPIO",
4138 .grf_mux_offset
= 0x0,
4139 .pmu_mux_offset
= 0x0,
4140 .pull_calc_reg
= rk3368_calc_pull_reg_and_bit
,
4141 .drv_calc_reg
= rk3368_calc_drv_reg_and_bit
,
4144 static struct rockchip_pin_bank rk3399_pin_banks
[] = {
4145 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
4150 DRV_TYPE_IO_1V8_ONLY
,
4151 DRV_TYPE_IO_1V8_ONLY
,
4152 DRV_TYPE_IO_DEFAULT
,
4153 DRV_TYPE_IO_DEFAULT
,
4158 PULL_TYPE_IO_1V8_ONLY
,
4159 PULL_TYPE_IO_1V8_ONLY
,
4160 PULL_TYPE_IO_DEFAULT
,
4161 PULL_TYPE_IO_DEFAULT
4163 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU
,
4167 DRV_TYPE_IO_1V8_OR_3V0
,
4168 DRV_TYPE_IO_1V8_OR_3V0
,
4169 DRV_TYPE_IO_1V8_OR_3V0
,
4170 DRV_TYPE_IO_1V8_OR_3V0
,
4176 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0
,
4177 DRV_TYPE_IO_1V8_OR_3V0
,
4178 DRV_TYPE_IO_1V8_ONLY
,
4179 DRV_TYPE_IO_1V8_ONLY
,
4180 PULL_TYPE_IO_DEFAULT
,
4181 PULL_TYPE_IO_DEFAULT
,
4182 PULL_TYPE_IO_1V8_ONLY
,
4183 PULL_TYPE_IO_1V8_ONLY
4185 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY
,
4186 DRV_TYPE_IO_3V3_ONLY
,
4187 DRV_TYPE_IO_3V3_ONLY
,
4188 DRV_TYPE_IO_1V8_OR_3V0
4190 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0
,
4191 DRV_TYPE_IO_1V8_3V0_AUTO
,
4192 DRV_TYPE_IO_1V8_OR_3V0
,
4193 DRV_TYPE_IO_1V8_OR_3V0
4197 static struct rockchip_pin_ctrl rk3399_pin_ctrl
= {
4198 .pin_banks
= rk3399_pin_banks
,
4199 .nr_banks
= ARRAY_SIZE(rk3399_pin_banks
),
4200 .label
= "RK3399-GPIO",
4202 .grf_mux_offset
= 0xe000,
4203 .pmu_mux_offset
= 0x0,
4204 .grf_drv_offset
= 0xe100,
4205 .pmu_drv_offset
= 0x80,
4206 .iomux_routes
= rk3399_mux_route_data
,
4207 .niomux_routes
= ARRAY_SIZE(rk3399_mux_route_data
),
4208 .pull_calc_reg
= rk3399_calc_pull_reg_and_bit
,
4209 .drv_calc_reg
= rk3399_calc_drv_reg_and_bit
,
4212 static const struct of_device_id rockchip_pinctrl_dt_match
[] = {
4213 { .compatible
= "rockchip,px30-pinctrl",
4214 .data
= &px30_pin_ctrl
},
4215 { .compatible
= "rockchip,rv1108-pinctrl",
4216 .data
= &rv1108_pin_ctrl
},
4217 { .compatible
= "rockchip,rk2928-pinctrl",
4218 .data
= &rk2928_pin_ctrl
},
4219 { .compatible
= "rockchip,rk3036-pinctrl",
4220 .data
= &rk3036_pin_ctrl
},
4221 { .compatible
= "rockchip,rk3066a-pinctrl",
4222 .data
= &rk3066a_pin_ctrl
},
4223 { .compatible
= "rockchip,rk3066b-pinctrl",
4224 .data
= &rk3066b_pin_ctrl
},
4225 { .compatible
= "rockchip,rk3128-pinctrl",
4226 .data
= (void *)&rk3128_pin_ctrl
},
4227 { .compatible
= "rockchip,rk3188-pinctrl",
4228 .data
= &rk3188_pin_ctrl
},
4229 { .compatible
= "rockchip,rk3228-pinctrl",
4230 .data
= &rk3228_pin_ctrl
},
4231 { .compatible
= "rockchip,rk3288-pinctrl",
4232 .data
= &rk3288_pin_ctrl
},
4233 { .compatible
= "rockchip,rk3308-pinctrl",
4234 .data
= &rk3308_pin_ctrl
},
4235 { .compatible
= "rockchip,rk3328-pinctrl",
4236 .data
= &rk3328_pin_ctrl
},
4237 { .compatible
= "rockchip,rk3368-pinctrl",
4238 .data
= &rk3368_pin_ctrl
},
4239 { .compatible
= "rockchip,rk3399-pinctrl",
4240 .data
= &rk3399_pin_ctrl
},
4244 static struct platform_driver rockchip_pinctrl_driver
= {
4245 .probe
= rockchip_pinctrl_probe
,
4247 .name
= "rockchip-pinctrl",
4248 .pm
= &rockchip_pinctrl_dev_pm_ops
,
4249 .of_match_table
= rockchip_pinctrl_dt_match
,
4253 static int __init
rockchip_pinctrl_drv_register(void)
4255 return platform_driver_register(&rockchip_pinctrl_driver
);
4257 postcore_initcall(rockchip_pinctrl_drv_register
);