2 * Pinctrl driver for Rockchip SoCs
4 * Copyright (c) 2013 MundoReader S.L.
5 * Author: Heiko Stuebner <heiko@sntech.de>
7 * With some ideas taken from pinctrl-samsung:
8 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
9 * http://www.samsung.com
10 * Copyright (c) 2012 Linaro Ltd
11 * http://www.linaro.org
14 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/init.h>
27 #include <linux/platform_device.h>
29 #include <linux/bitops.h>
30 #include <linux/gpio.h>
31 #include <linux/of_address.h>
32 #include <linux/of_irq.h>
33 #include <linux/pinctrl/machine.h>
34 #include <linux/pinctrl/pinconf.h>
35 #include <linux/pinctrl/pinctrl.h>
36 #include <linux/pinctrl/pinmux.h>
37 #include <linux/pinctrl/pinconf-generic.h>
38 #include <linux/irqchip/chained_irq.h>
39 #include <linux/clk.h>
40 #include <linux/regmap.h>
41 #include <linux/mfd/syscon.h>
42 #include <dt-bindings/pinctrl/rockchip.h>
47 /* GPIO control registers */
48 #define GPIO_SWPORT_DR 0x00
49 #define GPIO_SWPORT_DDR 0x04
50 #define GPIO_INTEN 0x30
51 #define GPIO_INTMASK 0x34
52 #define GPIO_INTTYPE_LEVEL 0x38
53 #define GPIO_INT_POLARITY 0x3c
54 #define GPIO_INT_STATUS 0x40
55 #define GPIO_INT_RAWSTATUS 0x44
56 #define GPIO_DEBOUNCE 0x48
57 #define GPIO_PORTS_EOI 0x4c
58 #define GPIO_EXT_PORT 0x50
59 #define GPIO_LS_SYNC 0x60
61 enum rockchip_pinctrl_type
{
73 * Encode variants of iomux registers into a type variable
75 #define IOMUX_GPIO_ONLY BIT(0)
76 #define IOMUX_WIDTH_4BIT BIT(1)
77 #define IOMUX_SOURCE_PMU BIT(2)
78 #define IOMUX_UNROUTED BIT(3)
79 #define IOMUX_WIDTH_3BIT BIT(4)
82 * @type: iomux variant using IOMUX_* constants
83 * @offset: if initialized to -1 it will be autocalculated, by specifying
84 * an initial offset value the relevant source offset can be reset
85 * to a new value for autocalculating the following iomux registers.
87 struct rockchip_iomux
{
93 * enum type index corresponding to rockchip_perpin_drv_list arrays index.
95 enum rockchip_pin_drv_type
{
96 DRV_TYPE_IO_DEFAULT
= 0,
97 DRV_TYPE_IO_1V8_OR_3V0
,
99 DRV_TYPE_IO_1V8_3V0_AUTO
,
100 DRV_TYPE_IO_3V3_ONLY
,
105 * enum type index corresponding to rockchip_pull_list arrays index.
107 enum rockchip_pin_pull_type
{
108 PULL_TYPE_IO_DEFAULT
= 0,
109 PULL_TYPE_IO_1V8_ONLY
,
114 * @drv_type: drive strength variant using rockchip_perpin_drv_type
115 * @offset: if initialized to -1 it will be autocalculated, by specifying
116 * an initial offset value the relevant source offset can be reset
117 * to a new value for autocalculating the following drive strength
118 * registers. if used chips own cal_drv func instead to calculate
119 * registers offset, the variant could be ignored.
121 struct rockchip_drv
{
122 enum rockchip_pin_drv_type drv_type
;
127 * @reg_base: register base of the gpio bank
128 * @reg_pull: optional separate register for additional pull settings
129 * @clk: clock of the gpio bank
130 * @irq: interrupt of the gpio bank
131 * @saved_masks: Saved content of GPIO_INTEN at suspend time.
132 * @pin_base: first pin number
133 * @nr_pins: number of pins in this bank
134 * @name: name of the bank
135 * @bank_num: number of the bank, to account for holes
136 * @iomux: array describing the 4 iomux sources of the bank
137 * @drv: array describing the 4 drive strength sources of the bank
138 * @pull_type: array describing the 4 pull type sources of the bank
139 * @valid: is all necessary information present
140 * @of_node: dt node of this bank
141 * @drvdata: common pinctrl basedata
142 * @domain: irqdomain of the gpio bank
143 * @gpio_chip: gpiolib chip
144 * @grange: gpio range
145 * @slock: spinlock for the gpio bank
146 * @route_mask: bits describing the routing pins of per bank
148 struct rockchip_pin_bank
{
149 void __iomem
*reg_base
;
150 struct regmap
*regmap_pull
;
158 struct rockchip_iomux iomux
[4];
159 struct rockchip_drv drv
[4];
160 enum rockchip_pin_pull_type pull_type
[4];
162 struct device_node
*of_node
;
163 struct rockchip_pinctrl
*drvdata
;
164 struct irq_domain
*domain
;
165 struct gpio_chip gpio_chip
;
166 struct pinctrl_gpio_range grange
;
167 raw_spinlock_t slock
;
168 u32 toggle_edge_mode
;
173 #define PIN_BANK(id, pins, label) \
186 #define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
192 { .type = iom0, .offset = -1 }, \
193 { .type = iom1, .offset = -1 }, \
194 { .type = iom2, .offset = -1 }, \
195 { .type = iom3, .offset = -1 }, \
199 #define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
211 { .drv_type = type0, .offset = -1 }, \
212 { .drv_type = type1, .offset = -1 }, \
213 { .drv_type = type2, .offset = -1 }, \
214 { .drv_type = type3, .offset = -1 }, \
218 #define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
219 drv2, drv3, pull0, pull1, \
232 { .drv_type = drv0, .offset = -1 }, \
233 { .drv_type = drv1, .offset = -1 }, \
234 { .drv_type = drv2, .offset = -1 }, \
235 { .drv_type = drv3, .offset = -1 }, \
237 .pull_type[0] = pull0, \
238 .pull_type[1] = pull1, \
239 .pull_type[2] = pull2, \
240 .pull_type[3] = pull3, \
243 #define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
244 iom2, iom3, drv0, drv1, drv2, \
245 drv3, offset0, offset1, \
252 { .type = iom0, .offset = -1 }, \
253 { .type = iom1, .offset = -1 }, \
254 { .type = iom2, .offset = -1 }, \
255 { .type = iom3, .offset = -1 }, \
258 { .drv_type = drv0, .offset = offset0 }, \
259 { .drv_type = drv1, .offset = offset1 }, \
260 { .drv_type = drv2, .offset = offset2 }, \
261 { .drv_type = drv3, .offset = offset3 }, \
265 #define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
266 label, iom0, iom1, iom2, \
267 iom3, drv0, drv1, drv2, \
268 drv3, offset0, offset1, \
269 offset2, offset3, pull0, \
270 pull1, pull2, pull3) \
276 { .type = iom0, .offset = -1 }, \
277 { .type = iom1, .offset = -1 }, \
278 { .type = iom2, .offset = -1 }, \
279 { .type = iom3, .offset = -1 }, \
282 { .drv_type = drv0, .offset = offset0 }, \
283 { .drv_type = drv1, .offset = offset1 }, \
284 { .drv_type = drv2, .offset = offset2 }, \
285 { .drv_type = drv3, .offset = offset3 }, \
287 .pull_type[0] = pull0, \
288 .pull_type[1] = pull1, \
289 .pull_type[2] = pull2, \
290 .pull_type[3] = pull3, \
294 * struct rockchip_mux_recalced_data: represent a pin iomux data.
297 * @bit: index at register.
298 * @reg: register offset.
301 struct rockchip_mux_recalced_data
{
310 * struct rockchip_mux_recalced_data: represent a pin iomux data.
311 * @bank_num: bank number.
312 * @pin: index at register or used to calc index.
313 * @func: the min pin.
314 * @route_offset: the max pin.
315 * @route_val: the register offset.
317 struct rockchip_mux_route_data
{
327 struct rockchip_pin_ctrl
{
328 struct rockchip_pin_bank
*pin_banks
;
332 enum rockchip_pinctrl_type type
;
337 struct rockchip_mux_recalced_data
*iomux_recalced
;
339 struct rockchip_mux_route_data
*iomux_routes
;
342 void (*pull_calc_reg
)(struct rockchip_pin_bank
*bank
,
343 int pin_num
, struct regmap
**regmap
,
345 void (*drv_calc_reg
)(struct rockchip_pin_bank
*bank
,
346 int pin_num
, struct regmap
**regmap
,
348 int (*schmitt_calc_reg
)(struct rockchip_pin_bank
*bank
,
349 int pin_num
, struct regmap
**regmap
,
353 struct rockchip_pin_config
{
355 unsigned long *configs
;
356 unsigned int nconfigs
;
360 * struct rockchip_pin_group: represent group of pins of a pinmux function.
361 * @name: name of the pin group, used to lookup the group.
362 * @pins: the pins included in this group.
363 * @npins: number of pins included in this group.
364 * @func: the mux function number to be programmed when selected.
365 * @configs: the config values to be set for each pin
366 * @nconfigs: number of configs for each pin
368 struct rockchip_pin_group
{
372 struct rockchip_pin_config
*data
;
376 * struct rockchip_pmx_func: represent a pin function.
377 * @name: name of the pin function, used to lookup the function.
378 * @groups: one or more names of pin groups that provide this function.
379 * @num_groups: number of groups included in @groups.
381 struct rockchip_pmx_func
{
387 struct rockchip_pinctrl
{
388 struct regmap
*regmap_base
;
390 struct regmap
*regmap_pull
;
391 struct regmap
*regmap_pmu
;
393 struct rockchip_pin_ctrl
*ctrl
;
394 struct pinctrl_desc pctl
;
395 struct pinctrl_dev
*pctl_dev
;
396 struct rockchip_pin_group
*groups
;
397 unsigned int ngroups
;
398 struct rockchip_pmx_func
*functions
;
399 unsigned int nfunctions
;
402 static struct regmap_config rockchip_regmap_config
= {
408 static inline const struct rockchip_pin_group
*pinctrl_name_to_group(
409 const struct rockchip_pinctrl
*info
,
414 for (i
= 0; i
< info
->ngroups
; i
++) {
415 if (!strcmp(info
->groups
[i
].name
, name
))
416 return &info
->groups
[i
];
423 * given a pin number that is local to a pin controller, find out the pin bank
424 * and the register base of the pin bank.
426 static struct rockchip_pin_bank
*pin_to_bank(struct rockchip_pinctrl
*info
,
429 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
431 while (pin
>= (b
->pin_base
+ b
->nr_pins
))
437 static struct rockchip_pin_bank
*bank_num_to_bank(
438 struct rockchip_pinctrl
*info
,
441 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
444 for (i
= 0; i
< info
->ctrl
->nr_banks
; i
++, b
++) {
445 if (b
->bank_num
== num
)
449 return ERR_PTR(-EINVAL
);
453 * Pinctrl_ops handling
456 static int rockchip_get_groups_count(struct pinctrl_dev
*pctldev
)
458 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
460 return info
->ngroups
;
463 static const char *rockchip_get_group_name(struct pinctrl_dev
*pctldev
,
466 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
468 return info
->groups
[selector
].name
;
471 static int rockchip_get_group_pins(struct pinctrl_dev
*pctldev
,
472 unsigned selector
, const unsigned **pins
,
475 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
477 if (selector
>= info
->ngroups
)
480 *pins
= info
->groups
[selector
].pins
;
481 *npins
= info
->groups
[selector
].npins
;
486 static int rockchip_dt_node_to_map(struct pinctrl_dev
*pctldev
,
487 struct device_node
*np
,
488 struct pinctrl_map
**map
, unsigned *num_maps
)
490 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
491 const struct rockchip_pin_group
*grp
;
492 struct pinctrl_map
*new_map
;
493 struct device_node
*parent
;
498 * first find the group of this node and check if we need to create
499 * config maps for pins
501 grp
= pinctrl_name_to_group(info
, np
->name
);
503 dev_err(info
->dev
, "unable to find group for node %s\n",
508 map_num
+= grp
->npins
;
509 new_map
= devm_kzalloc(pctldev
->dev
, sizeof(*new_map
) * map_num
,
518 parent
= of_get_parent(np
);
520 devm_kfree(pctldev
->dev
, new_map
);
523 new_map
[0].type
= PIN_MAP_TYPE_MUX_GROUP
;
524 new_map
[0].data
.mux
.function
= parent
->name
;
525 new_map
[0].data
.mux
.group
= np
->name
;
528 /* create config map */
530 for (i
= 0; i
< grp
->npins
; i
++) {
531 new_map
[i
].type
= PIN_MAP_TYPE_CONFIGS_PIN
;
532 new_map
[i
].data
.configs
.group_or_pin
=
533 pin_get_name(pctldev
, grp
->pins
[i
]);
534 new_map
[i
].data
.configs
.configs
= grp
->data
[i
].configs
;
535 new_map
[i
].data
.configs
.num_configs
= grp
->data
[i
].nconfigs
;
538 dev_dbg(pctldev
->dev
, "maps: function %s group %s num %d\n",
539 (*map
)->data
.mux
.function
, (*map
)->data
.mux
.group
, map_num
);
544 static void rockchip_dt_free_map(struct pinctrl_dev
*pctldev
,
545 struct pinctrl_map
*map
, unsigned num_maps
)
549 static const struct pinctrl_ops rockchip_pctrl_ops
= {
550 .get_groups_count
= rockchip_get_groups_count
,
551 .get_group_name
= rockchip_get_group_name
,
552 .get_group_pins
= rockchip_get_group_pins
,
553 .dt_node_to_map
= rockchip_dt_node_to_map
,
554 .dt_free_map
= rockchip_dt_free_map
,
561 static struct rockchip_mux_recalced_data rv1108_mux_recalced_data
[] = {
625 static struct rockchip_mux_recalced_data rk3128_mux_recalced_data
[] = {
659 static struct rockchip_mux_recalced_data rk3328_mux_recalced_data
[] = {
681 static void rockchip_get_recalced_mux(struct rockchip_pin_bank
*bank
, int pin
,
682 int *reg
, u8
*bit
, int *mask
)
684 struct rockchip_pinctrl
*info
= bank
->drvdata
;
685 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
686 struct rockchip_mux_recalced_data
*data
;
689 for (i
= 0; i
< ctrl
->niomux_recalced
; i
++) {
690 data
= &ctrl
->iomux_recalced
[i
];
691 if (data
->num
== bank
->bank_num
&&
696 if (i
>= ctrl
->niomux_recalced
)
704 static struct rockchip_mux_route_data rk3128_mux_route_data
[] = {
710 .route_offset
= 0x144,
711 .route_val
= BIT(16 + 3) | BIT(16 + 4),
717 .route_offset
= 0x144,
718 .route_val
= BIT(16 + 3) | BIT(16 + 4) | BIT(3),
724 .route_offset
= 0x144,
725 .route_val
= BIT(16 + 3) | BIT(16 + 4) | BIT(4),
731 .route_offset
= 0x144,
732 .route_val
= BIT(16 + 5),
738 .route_offset
= 0x144,
739 .route_val
= BIT(16 + 5) | BIT(5),
745 .route_offset
= 0x144,
746 .route_val
= BIT(16 + 6),
752 .route_offset
= 0x144,
753 .route_val
= BIT(16 + 6) | BIT(6),
757 static struct rockchip_mux_route_data rk3228_mux_route_data
[] = {
763 .route_offset
= 0x50,
764 .route_val
= BIT(16),
770 .route_offset
= 0x50,
771 .route_val
= BIT(16) | BIT(0),
777 .route_offset
= 0x50,
778 .route_val
= BIT(16 + 1),
784 .route_offset
= 0x50,
785 .route_val
= BIT(16 + 1) | BIT(1),
791 .route_offset
= 0x50,
792 .route_val
= BIT(16 + 2),
798 .route_offset
= 0x50,
799 .route_val
= BIT(16 + 2) | BIT(2),
805 .route_offset
= 0x50,
806 .route_val
= BIT(16 + 3),
812 .route_offset
= 0x50,
813 .route_val
= BIT(16 + 3) | BIT(3),
819 .route_offset
= 0x50,
820 .route_val
= BIT(16 + 4),
826 .route_offset
= 0x50,
827 .route_val
= BIT(16 + 4) | BIT(4),
833 .route_offset
= 0x50,
834 .route_val
= BIT(16 + 5),
840 .route_offset
= 0x50,
841 .route_val
= BIT(16 + 5) | BIT(5),
847 .route_offset
= 0x50,
848 .route_val
= BIT(16 + 7),
854 .route_offset
= 0x50,
855 .route_val
= BIT(16 + 7) | BIT(7),
861 .route_offset
= 0x50,
862 .route_val
= BIT(16 + 8),
868 .route_offset
= 0x50,
869 .route_val
= BIT(16 + 8) | BIT(8),
875 .route_offset
= 0x50,
876 .route_val
= BIT(16 + 11),
882 .route_offset
= 0x50,
883 .route_val
= BIT(16 + 11) | BIT(11),
887 static struct rockchip_mux_route_data rk3288_mux_route_data
[] = {
889 /* edphdmi_cecinoutt1 */
893 .route_offset
= 0x264,
894 .route_val
= BIT(16 + 12) | BIT(12),
896 /* edphdmi_cecinout */
900 .route_offset
= 0x264,
901 .route_val
= BIT(16 + 12),
905 static struct rockchip_mux_route_data rk3328_mux_route_data
[] = {
911 .route_offset
= 0x50,
912 .route_val
= BIT(16) | BIT(16 + 1),
918 .route_offset
= 0x50,
919 .route_val
= BIT(16) | BIT(16 + 1) | BIT(0),
925 .route_offset
= 0x50,
926 .route_val
= BIT(16 + 2) | BIT(2),
928 /* gmac-m1-optimized_rxd3 */
932 .route_offset
= 0x50,
933 .route_val
= BIT(16 + 10) | BIT(10),
939 .route_offset
= 0x50,
940 .route_val
= BIT(16 + 3),
946 .route_offset
= 0x50,
947 .route_val
= BIT(16 + 3) | BIT(3),
953 .route_offset
= 0x50,
954 .route_val
= BIT(16 + 4) | BIT(16 + 5) | BIT(5),
960 .route_offset
= 0x50,
961 .route_val
= BIT(16 + 6),
967 .route_offset
= 0x50,
968 .route_val
= BIT(16 + 6) | BIT(6),
974 .route_offset
= 0x50,
975 .route_val
= BIT(16 + 7) | BIT(7),
981 .route_offset
= 0x50,
982 .route_val
= BIT(16 + 8) | BIT(8),
988 .route_offset
= 0x50,
989 .route_val
= BIT(16 + 9) | BIT(9),
993 static struct rockchip_mux_route_data rk3399_mux_route_data
[] = {
999 .route_offset
= 0xe21c,
1000 .route_val
= BIT(16 + 10) | BIT(16 + 11),
1006 .route_offset
= 0xe21c,
1007 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(10),
1013 .route_offset
= 0xe21c,
1014 .route_val
= BIT(16 + 10) | BIT(16 + 11) | BIT(11),
1020 .route_offset
= 0xe21c,
1021 .route_val
= BIT(16 + 14),
1027 .route_offset
= 0xe21c,
1028 .route_val
= BIT(16 + 14) | BIT(14),
1032 static bool rockchip_get_mux_route(struct rockchip_pin_bank
*bank
, int pin
,
1033 int mux
, u32
*reg
, u32
*value
)
1035 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1036 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1037 struct rockchip_mux_route_data
*data
;
1040 for (i
= 0; i
< ctrl
->niomux_routes
; i
++) {
1041 data
= &ctrl
->iomux_routes
[i
];
1042 if ((data
->bank_num
== bank
->bank_num
) &&
1043 (data
->pin
== pin
) && (data
->func
== mux
))
1047 if (i
>= ctrl
->niomux_routes
)
1050 *reg
= data
->route_offset
;
1051 *value
= data
->route_val
;
1056 static int rockchip_get_mux(struct rockchip_pin_bank
*bank
, int pin
)
1058 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1059 int iomux_num
= (pin
/ 8);
1060 struct regmap
*regmap
;
1062 int reg
, ret
, mask
, mux_type
;
1068 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1069 dev_err(info
->dev
, "pin %d is unrouted\n", pin
);
1073 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1074 return RK_FUNC_GPIO
;
1076 regmap
= (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1077 ? info
->regmap_pmu
: info
->regmap_base
;
1079 /* get basic quadrupel of mux registers and the correct reg inside */
1080 mux_type
= bank
->iomux
[iomux_num
].type
;
1081 reg
= bank
->iomux
[iomux_num
].offset
;
1082 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1085 bit
= (pin
% 4) * 4;
1087 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1090 bit
= (pin
% 8 % 5) * 3;
1093 bit
= (pin
% 8) * 2;
1097 if (bank
->recalced_mask
& BIT(pin
))
1098 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1100 ret
= regmap_read(regmap
, reg
, &val
);
1104 return ((val
>> bit
) & mask
);
1107 static int rockchip_verify_mux(struct rockchip_pin_bank
*bank
,
1110 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1111 int iomux_num
= (pin
/ 8);
1116 if (bank
->iomux
[iomux_num
].type
& IOMUX_UNROUTED
) {
1117 dev_err(info
->dev
, "pin %d is unrouted\n", pin
);
1121 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
) {
1122 if (mux
!= RK_FUNC_GPIO
) {
1124 "pin %d only supports a gpio mux\n", pin
);
1133 * Set a new mux function for a pin.
1135 * The register is divided into the upper and lower 16 bit. When changing
1136 * a value, the previous register value is not read and changed. Instead
1137 * it seems the changed bits are marked in the upper 16 bit, while the
1138 * changed value gets set in the same offset in the lower 16 bit.
1139 * All pin settings seem to be 2 bit wide in both the upper and lower
1141 * @bank: pin bank to change
1142 * @pin: pin to change
1143 * @mux: new mux function to set
1145 static int rockchip_set_mux(struct rockchip_pin_bank
*bank
, int pin
, int mux
)
1147 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1148 int iomux_num
= (pin
/ 8);
1149 struct regmap
*regmap
;
1150 int reg
, ret
, mask
, mux_type
;
1152 u32 data
, rmask
, route_reg
, route_val
;
1154 ret
= rockchip_verify_mux(bank
, pin
, mux
);
1158 if (bank
->iomux
[iomux_num
].type
& IOMUX_GPIO_ONLY
)
1161 dev_dbg(info
->dev
, "setting mux of GPIO%d-%d to %d\n",
1162 bank
->bank_num
, pin
, mux
);
1164 regmap
= (bank
->iomux
[iomux_num
].type
& IOMUX_SOURCE_PMU
)
1165 ? info
->regmap_pmu
: info
->regmap_base
;
1167 /* get basic quadrupel of mux registers and the correct reg inside */
1168 mux_type
= bank
->iomux
[iomux_num
].type
;
1169 reg
= bank
->iomux
[iomux_num
].offset
;
1170 if (mux_type
& IOMUX_WIDTH_4BIT
) {
1173 bit
= (pin
% 4) * 4;
1175 } else if (mux_type
& IOMUX_WIDTH_3BIT
) {
1178 bit
= (pin
% 8 % 5) * 3;
1181 bit
= (pin
% 8) * 2;
1185 if (bank
->recalced_mask
& BIT(pin
))
1186 rockchip_get_recalced_mux(bank
, pin
, ®
, &bit
, &mask
);
1188 if (bank
->route_mask
& BIT(pin
)) {
1189 if (rockchip_get_mux_route(bank
, pin
, mux
, &route_reg
,
1191 ret
= regmap_write(regmap
, route_reg
, route_val
);
1197 data
= (mask
<< (bit
+ 16));
1198 rmask
= data
| (data
>> 16);
1199 data
|= (mux
& mask
) << bit
;
1200 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1205 #define RV1108_PULL_PMU_OFFSET 0x10
1206 #define RV1108_PULL_OFFSET 0x110
1207 #define RV1108_PULL_PINS_PER_REG 8
1208 #define RV1108_PULL_BITS_PER_PIN 2
1209 #define RV1108_PULL_BANK_STRIDE 16
1211 static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1212 int pin_num
, struct regmap
**regmap
,
1215 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1217 /* The first 24 pins of the first bank are located in PMU */
1218 if (bank
->bank_num
== 0) {
1219 *regmap
= info
->regmap_pmu
;
1220 *reg
= RV1108_PULL_PMU_OFFSET
;
1222 *reg
= RV1108_PULL_OFFSET
;
1223 *regmap
= info
->regmap_base
;
1224 /* correct the offset, as we're starting with the 2nd bank */
1226 *reg
+= bank
->bank_num
* RV1108_PULL_BANK_STRIDE
;
1229 *reg
+= ((pin_num
/ RV1108_PULL_PINS_PER_REG
) * 4);
1230 *bit
= (pin_num
% RV1108_PULL_PINS_PER_REG
);
1231 *bit
*= RV1108_PULL_BITS_PER_PIN
;
1234 #define RV1108_DRV_PMU_OFFSET 0x20
1235 #define RV1108_DRV_GRF_OFFSET 0x210
1236 #define RV1108_DRV_BITS_PER_PIN 2
1237 #define RV1108_DRV_PINS_PER_REG 8
1238 #define RV1108_DRV_BANK_STRIDE 16
1240 static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1241 int pin_num
, struct regmap
**regmap
,
1244 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1246 /* The first 24 pins of the first bank are located in PMU */
1247 if (bank
->bank_num
== 0) {
1248 *regmap
= info
->regmap_pmu
;
1249 *reg
= RV1108_DRV_PMU_OFFSET
;
1251 *regmap
= info
->regmap_base
;
1252 *reg
= RV1108_DRV_GRF_OFFSET
;
1254 /* correct the offset, as we're starting with the 2nd bank */
1256 *reg
+= bank
->bank_num
* RV1108_DRV_BANK_STRIDE
;
1259 *reg
+= ((pin_num
/ RV1108_DRV_PINS_PER_REG
) * 4);
1260 *bit
= pin_num
% RV1108_DRV_PINS_PER_REG
;
1261 *bit
*= RV1108_DRV_BITS_PER_PIN
;
1264 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1265 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1266 #define RV1108_SCHMITT_BANK_STRIDE 8
1267 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1268 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1270 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1272 struct regmap
**regmap
,
1275 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1278 if (bank
->bank_num
== 0) {
1279 *regmap
= info
->regmap_pmu
;
1280 *reg
= RV1108_SCHMITT_PMU_OFFSET
;
1281 pins_per_reg
= RV1108_SCHMITT_PINS_PER_PMU_REG
;
1283 *regmap
= info
->regmap_base
;
1284 *reg
= RV1108_SCHMITT_GRF_OFFSET
;
1285 pins_per_reg
= RV1108_SCHMITT_PINS_PER_GRF_REG
;
1286 *reg
+= (bank
->bank_num
- 1) * RV1108_SCHMITT_BANK_STRIDE
;
1288 *reg
+= ((pin_num
/ pins_per_reg
) * 4);
1289 *bit
= pin_num
% pins_per_reg
;
1294 #define RK2928_PULL_OFFSET 0x118
1295 #define RK2928_PULL_PINS_PER_REG 16
1296 #define RK2928_PULL_BANK_STRIDE 8
1298 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1299 int pin_num
, struct regmap
**regmap
,
1302 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1304 *regmap
= info
->regmap_base
;
1305 *reg
= RK2928_PULL_OFFSET
;
1306 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1307 *reg
+= (pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4;
1309 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1312 #define RK3128_PULL_OFFSET 0x118
1314 static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1315 int pin_num
, struct regmap
**regmap
,
1318 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1320 *regmap
= info
->regmap_base
;
1321 *reg
= RK3128_PULL_OFFSET
;
1322 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
1323 *reg
+= ((pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4);
1325 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
1328 #define RK3188_PULL_OFFSET 0x164
1329 #define RK3188_PULL_BITS_PER_PIN 2
1330 #define RK3188_PULL_PINS_PER_REG 8
1331 #define RK3188_PULL_BANK_STRIDE 16
1332 #define RK3188_PULL_PMU_OFFSET 0x64
1334 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1335 int pin_num
, struct regmap
**regmap
,
1338 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1340 /* The first 12 pins of the first bank are located elsewhere */
1341 if (bank
->bank_num
== 0 && pin_num
< 12) {
1342 *regmap
= info
->regmap_pmu
? info
->regmap_pmu
1343 : bank
->regmap_pull
;
1344 *reg
= info
->regmap_pmu
? RK3188_PULL_PMU_OFFSET
: 0;
1345 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1346 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1347 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1349 *regmap
= info
->regmap_pull
? info
->regmap_pull
1350 : info
->regmap_base
;
1351 *reg
= info
->regmap_pull
? 0 : RK3188_PULL_OFFSET
;
1353 /* correct the offset, as it is the 2nd pull register */
1355 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1356 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1359 * The bits in these registers have an inverse ordering
1360 * with the lowest pin being in bits 15:14 and the highest
1363 *bit
= 7 - (pin_num
% RK3188_PULL_PINS_PER_REG
);
1364 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1368 #define RK3288_PULL_OFFSET 0x140
1369 static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1370 int pin_num
, struct regmap
**regmap
,
1373 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1375 /* The first 24 pins of the first bank are located in PMU */
1376 if (bank
->bank_num
== 0) {
1377 *regmap
= info
->regmap_pmu
;
1378 *reg
= RK3188_PULL_PMU_OFFSET
;
1380 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1381 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1382 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1384 *regmap
= info
->regmap_base
;
1385 *reg
= RK3288_PULL_OFFSET
;
1387 /* correct the offset, as we're starting with the 2nd bank */
1389 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1390 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1392 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1393 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1397 #define RK3288_DRV_PMU_OFFSET 0x70
1398 #define RK3288_DRV_GRF_OFFSET 0x1c0
1399 #define RK3288_DRV_BITS_PER_PIN 2
1400 #define RK3288_DRV_PINS_PER_REG 8
1401 #define RK3288_DRV_BANK_STRIDE 16
1403 static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1404 int pin_num
, struct regmap
**regmap
,
1407 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1409 /* The first 24 pins of the first bank are located in PMU */
1410 if (bank
->bank_num
== 0) {
1411 *regmap
= info
->regmap_pmu
;
1412 *reg
= RK3288_DRV_PMU_OFFSET
;
1414 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1415 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
1416 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1418 *regmap
= info
->regmap_base
;
1419 *reg
= RK3288_DRV_GRF_OFFSET
;
1421 /* correct the offset, as we're starting with the 2nd bank */
1423 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1424 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1426 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1427 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1431 #define RK3228_PULL_OFFSET 0x100
1433 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1434 int pin_num
, struct regmap
**regmap
,
1437 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1439 *regmap
= info
->regmap_base
;
1440 *reg
= RK3228_PULL_OFFSET
;
1441 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1442 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1444 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1445 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1448 #define RK3228_DRV_GRF_OFFSET 0x200
1450 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1451 int pin_num
, struct regmap
**regmap
,
1454 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1456 *regmap
= info
->regmap_base
;
1457 *reg
= RK3228_DRV_GRF_OFFSET
;
1458 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1459 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1461 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1462 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1465 #define RK3368_PULL_GRF_OFFSET 0x100
1466 #define RK3368_PULL_PMU_OFFSET 0x10
1468 static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1469 int pin_num
, struct regmap
**regmap
,
1472 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1474 /* The first 32 pins of the first bank are located in PMU */
1475 if (bank
->bank_num
== 0) {
1476 *regmap
= info
->regmap_pmu
;
1477 *reg
= RK3368_PULL_PMU_OFFSET
;
1479 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1480 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1481 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1483 *regmap
= info
->regmap_base
;
1484 *reg
= RK3368_PULL_GRF_OFFSET
;
1486 /* correct the offset, as we're starting with the 2nd bank */
1488 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1489 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1491 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1492 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1496 #define RK3368_DRV_PMU_OFFSET 0x20
1497 #define RK3368_DRV_GRF_OFFSET 0x200
1499 static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1500 int pin_num
, struct regmap
**regmap
,
1503 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1505 /* The first 32 pins of the first bank are located in PMU */
1506 if (bank
->bank_num
== 0) {
1507 *regmap
= info
->regmap_pmu
;
1508 *reg
= RK3368_DRV_PMU_OFFSET
;
1510 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1511 *bit
= pin_num
% RK3288_DRV_PINS_PER_REG
;
1512 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1514 *regmap
= info
->regmap_base
;
1515 *reg
= RK3368_DRV_GRF_OFFSET
;
1517 /* correct the offset, as we're starting with the 2nd bank */
1519 *reg
+= bank
->bank_num
* RK3288_DRV_BANK_STRIDE
;
1520 *reg
+= ((pin_num
/ RK3288_DRV_PINS_PER_REG
) * 4);
1522 *bit
= (pin_num
% RK3288_DRV_PINS_PER_REG
);
1523 *bit
*= RK3288_DRV_BITS_PER_PIN
;
1527 #define RK3399_PULL_GRF_OFFSET 0xe040
1528 #define RK3399_PULL_PMU_OFFSET 0x40
1529 #define RK3399_DRV_3BITS_PER_PIN 3
1531 static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
1532 int pin_num
, struct regmap
**regmap
,
1535 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1537 /* The bank0:16 and bank1:32 pins are located in PMU */
1538 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1)) {
1539 *regmap
= info
->regmap_pmu
;
1540 *reg
= RK3399_PULL_PMU_OFFSET
;
1542 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1544 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1545 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
1546 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1548 *regmap
= info
->regmap_base
;
1549 *reg
= RK3399_PULL_GRF_OFFSET
;
1551 /* correct the offset, as we're starting with the 3rd bank */
1553 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
1554 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
1556 *bit
= (pin_num
% RK3188_PULL_PINS_PER_REG
);
1557 *bit
*= RK3188_PULL_BITS_PER_PIN
;
1561 static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank
*bank
,
1562 int pin_num
, struct regmap
**regmap
,
1565 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1566 int drv_num
= (pin_num
/ 8);
1568 /* The bank0:16 and bank1:32 pins are located in PMU */
1569 if ((bank
->bank_num
== 0) || (bank
->bank_num
== 1))
1570 *regmap
= info
->regmap_pmu
;
1572 *regmap
= info
->regmap_base
;
1574 *reg
= bank
->drv
[drv_num
].offset
;
1575 if ((bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
1576 (bank
->drv
[drv_num
].drv_type
== DRV_TYPE_IO_3V3_ONLY
))
1577 *bit
= (pin_num
% 8) * 3;
1579 *bit
= (pin_num
% 8) * 2;
1582 static int rockchip_perpin_drv_list
[DRV_TYPE_MAX
][8] = {
1583 { 2, 4, 8, 12, -1, -1, -1, -1 },
1584 { 3, 6, 9, 12, -1, -1, -1, -1 },
1585 { 5, 10, 15, 20, -1, -1, -1, -1 },
1586 { 4, 6, 8, 10, 12, 14, 16, 18 },
1587 { 4, 7, 10, 13, 16, 19, 22, 26 }
1590 static int rockchip_get_drive_perpin(struct rockchip_pin_bank
*bank
,
1593 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1594 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1595 struct regmap
*regmap
;
1597 u32 data
, temp
, rmask_bits
;
1599 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
1601 ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1604 case DRV_TYPE_IO_1V8_3V0_AUTO
:
1605 case DRV_TYPE_IO_3V3_ONLY
:
1606 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
1609 /* regular case, nothing to do */
1613 * drive-strength offset is special, as it is
1614 * spread over 2 registers
1616 ret
= regmap_read(regmap
, reg
, &data
);
1620 ret
= regmap_read(regmap
, reg
+ 0x4, &temp
);
1625 * the bit data[15] contains bit 0 of the value
1626 * while temp[1:0] contains bits 2 and 1
1633 return rockchip_perpin_drv_list
[drv_type
][data
];
1635 /* setting fully enclosed in the second register */
1640 dev_err(info
->dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
1646 case DRV_TYPE_IO_DEFAULT
:
1647 case DRV_TYPE_IO_1V8_OR_3V0
:
1648 case DRV_TYPE_IO_1V8_ONLY
:
1649 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
1652 dev_err(info
->dev
, "unsupported pinctrl drive type: %d\n",
1657 ret
= regmap_read(regmap
, reg
, &data
);
1662 data
&= (1 << rmask_bits
) - 1;
1664 return rockchip_perpin_drv_list
[drv_type
][data
];
1667 static int rockchip_set_drive_perpin(struct rockchip_pin_bank
*bank
,
1668 int pin_num
, int strength
)
1670 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1671 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1672 struct regmap
*regmap
;
1674 u32 data
, rmask
, rmask_bits
, temp
;
1676 int drv_type
= bank
->drv
[pin_num
/ 8].drv_type
;
1678 dev_dbg(info
->dev
, "setting drive of GPIO%d-%d to %d\n",
1679 bank
->bank_num
, pin_num
, strength
);
1681 ctrl
->drv_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1684 for (i
= 0; i
< ARRAY_SIZE(rockchip_perpin_drv_list
[drv_type
]); i
++) {
1685 if (rockchip_perpin_drv_list
[drv_type
][i
] == strength
) {
1688 } else if (rockchip_perpin_drv_list
[drv_type
][i
] < 0) {
1689 ret
= rockchip_perpin_drv_list
[drv_type
][i
];
1695 dev_err(info
->dev
, "unsupported driver strength %d\n",
1701 case DRV_TYPE_IO_1V8_3V0_AUTO
:
1702 case DRV_TYPE_IO_3V3_ONLY
:
1703 rmask_bits
= RK3399_DRV_3BITS_PER_PIN
;
1706 /* regular case, nothing to do */
1710 * drive-strength offset is special, as it is spread
1711 * over 2 registers, the bit data[15] contains bit 0
1712 * of the value while temp[1:0] contains bits 2 and 1
1714 data
= (ret
& 0x1) << 15;
1715 temp
= (ret
>> 0x1) & 0x3;
1717 rmask
= BIT(15) | BIT(31);
1719 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1723 rmask
= 0x3 | (0x3 << 16);
1724 temp
|= (0x3 << 16);
1726 ret
= regmap_update_bits(regmap
, reg
, rmask
, temp
);
1730 /* setting fully enclosed in the second register */
1735 dev_err(info
->dev
, "unsupported bit: %d for pinctrl drive type: %d\n",
1740 case DRV_TYPE_IO_DEFAULT
:
1741 case DRV_TYPE_IO_1V8_OR_3V0
:
1742 case DRV_TYPE_IO_1V8_ONLY
:
1743 rmask_bits
= RK3288_DRV_BITS_PER_PIN
;
1746 dev_err(info
->dev
, "unsupported pinctrl drive type: %d\n",
1751 /* enable the write to the equivalent lower bits */
1752 data
= ((1 << rmask_bits
) - 1) << (bit
+ 16);
1753 rmask
= data
| (data
>> 16);
1754 data
|= (ret
<< bit
);
1756 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1761 static int rockchip_pull_list
[PULL_TYPE_MAX
][4] = {
1763 PIN_CONFIG_BIAS_DISABLE
,
1764 PIN_CONFIG_BIAS_PULL_UP
,
1765 PIN_CONFIG_BIAS_PULL_DOWN
,
1766 PIN_CONFIG_BIAS_BUS_HOLD
1769 PIN_CONFIG_BIAS_DISABLE
,
1770 PIN_CONFIG_BIAS_PULL_DOWN
,
1771 PIN_CONFIG_BIAS_DISABLE
,
1772 PIN_CONFIG_BIAS_PULL_UP
1776 static int rockchip_get_pull(struct rockchip_pin_bank
*bank
, int pin_num
)
1778 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1779 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1780 struct regmap
*regmap
;
1781 int reg
, ret
, pull_type
;
1785 /* rk3066b does support any pulls */
1786 if (ctrl
->type
== RK3066B
)
1787 return PIN_CONFIG_BIAS_DISABLE
;
1789 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1791 ret
= regmap_read(regmap
, reg
, &data
);
1795 switch (ctrl
->type
) {
1798 return !(data
& BIT(bit
))
1799 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1800 : PIN_CONFIG_BIAS_DISABLE
;
1806 pull_type
= bank
->pull_type
[pin_num
/ 8];
1808 data
&= (1 << RK3188_PULL_BITS_PER_PIN
) - 1;
1810 return rockchip_pull_list
[pull_type
][data
];
1812 dev_err(info
->dev
, "unsupported pinctrl type\n");
1817 static int rockchip_set_pull(struct rockchip_pin_bank
*bank
,
1818 int pin_num
, int pull
)
1820 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1821 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1822 struct regmap
*regmap
;
1823 int reg
, ret
, i
, pull_type
;
1827 dev_dbg(info
->dev
, "setting pull of GPIO%d-%d to %d\n",
1828 bank
->bank_num
, pin_num
, pull
);
1830 /* rk3066b does support any pulls */
1831 if (ctrl
->type
== RK3066B
)
1832 return pull
? -EINVAL
: 0;
1834 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1836 switch (ctrl
->type
) {
1839 data
= BIT(bit
+ 16);
1840 if (pull
== PIN_CONFIG_BIAS_DISABLE
)
1842 ret
= regmap_write(regmap
, reg
, data
);
1849 pull_type
= bank
->pull_type
[pin_num
/ 8];
1851 for (i
= 0; i
< ARRAY_SIZE(rockchip_pull_list
[pull_type
]);
1853 if (rockchip_pull_list
[pull_type
][i
] == pull
) {
1860 dev_err(info
->dev
, "unsupported pull setting %d\n",
1865 /* enable the write to the equivalent lower bits */
1866 data
= ((1 << RK3188_PULL_BITS_PER_PIN
) - 1) << (bit
+ 16);
1867 rmask
= data
| (data
>> 16);
1868 data
|= (ret
<< bit
);
1870 ret
= regmap_update_bits(regmap
, reg
, rmask
, data
);
1873 dev_err(info
->dev
, "unsupported pinctrl type\n");
1880 #define RK3328_SCHMITT_BITS_PER_PIN 1
1881 #define RK3328_SCHMITT_PINS_PER_REG 16
1882 #define RK3328_SCHMITT_BANK_STRIDE 8
1883 #define RK3328_SCHMITT_GRF_OFFSET 0x380
1885 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank
*bank
,
1887 struct regmap
**regmap
,
1890 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1892 *regmap
= info
->regmap_base
;
1893 *reg
= RK3328_SCHMITT_GRF_OFFSET
;
1895 *reg
+= bank
->bank_num
* RK3328_SCHMITT_BANK_STRIDE
;
1896 *reg
+= ((pin_num
/ RK3328_SCHMITT_PINS_PER_REG
) * 4);
1897 *bit
= pin_num
% RK3328_SCHMITT_PINS_PER_REG
;
1902 static int rockchip_get_schmitt(struct rockchip_pin_bank
*bank
, int pin_num
)
1904 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1905 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1906 struct regmap
*regmap
;
1911 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1915 ret
= regmap_read(regmap
, reg
, &data
);
1923 static int rockchip_set_schmitt(struct rockchip_pin_bank
*bank
,
1924 int pin_num
, int enable
)
1926 struct rockchip_pinctrl
*info
= bank
->drvdata
;
1927 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1928 struct regmap
*regmap
;
1933 dev_dbg(info
->dev
, "setting input schmitt of GPIO%d-%d to %d\n",
1934 bank
->bank_num
, pin_num
, enable
);
1936 ret
= ctrl
->schmitt_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
1940 /* enable the write to the equivalent lower bits */
1941 data
= BIT(bit
+ 16) | (enable
<< bit
);
1942 rmask
= BIT(bit
+ 16) | BIT(bit
);
1944 return regmap_update_bits(regmap
, reg
, rmask
, data
);
1948 * Pinmux_ops handling
1951 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev
*pctldev
)
1953 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
1955 return info
->nfunctions
;
1958 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
1961 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
1963 return info
->functions
[selector
].name
;
1966 static int rockchip_pmx_get_groups(struct pinctrl_dev
*pctldev
,
1967 unsigned selector
, const char * const **groups
,
1968 unsigned * const num_groups
)
1970 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
1972 *groups
= info
->functions
[selector
].groups
;
1973 *num_groups
= info
->functions
[selector
].ngroups
;
1978 static int rockchip_pmx_set(struct pinctrl_dev
*pctldev
, unsigned selector
,
1981 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
1982 const unsigned int *pins
= info
->groups
[group
].pins
;
1983 const struct rockchip_pin_config
*data
= info
->groups
[group
].data
;
1984 struct rockchip_pin_bank
*bank
;
1987 dev_dbg(info
->dev
, "enable function %s group %s\n",
1988 info
->functions
[selector
].name
, info
->groups
[group
].name
);
1991 * for each pin in the pin group selected, program the corresponding
1992 * pin function number in the config register.
1994 for (cnt
= 0; cnt
< info
->groups
[group
].npins
; cnt
++) {
1995 bank
= pin_to_bank(info
, pins
[cnt
]);
1996 ret
= rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
,
2003 /* revert the already done pin settings */
2004 for (cnt
--; cnt
>= 0; cnt
--)
2005 rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
, 0);
2013 static int rockchip_gpio_get_direction(struct gpio_chip
*chip
, unsigned offset
)
2015 struct rockchip_pin_bank
*bank
= gpiochip_get_data(chip
);
2019 ret
= clk_enable(bank
->clk
);
2021 dev_err(bank
->drvdata
->dev
,
2022 "failed to enable clock for bank %s\n", bank
->name
);
2025 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
2026 clk_disable(bank
->clk
);
2028 return !(data
& BIT(offset
));
2032 * The calls to gpio_direction_output() and gpio_direction_input()
2033 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
2034 * function called from the gpiolib interface).
2036 static int _rockchip_pmx_gpio_set_direction(struct gpio_chip
*chip
,
2037 int pin
, bool input
)
2039 struct rockchip_pin_bank
*bank
;
2041 unsigned long flags
;
2044 bank
= gpiochip_get_data(chip
);
2046 ret
= rockchip_set_mux(bank
, pin
, RK_FUNC_GPIO
);
2050 clk_enable(bank
->clk
);
2051 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2053 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
2054 /* set bit to 1 for output, 0 for input */
2059 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
2061 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2062 clk_disable(bank
->clk
);
2067 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev
*pctldev
,
2068 struct pinctrl_gpio_range
*range
,
2069 unsigned offset
, bool input
)
2071 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2072 struct gpio_chip
*chip
;
2076 pin
= offset
- chip
->base
;
2077 dev_dbg(info
->dev
, "gpio_direction for pin %u as %s-%d to %s\n",
2078 offset
, range
->name
, pin
, input
? "input" : "output");
2080 return _rockchip_pmx_gpio_set_direction(chip
, offset
- chip
->base
,
2084 static const struct pinmux_ops rockchip_pmx_ops
= {
2085 .get_functions_count
= rockchip_pmx_get_funcs_count
,
2086 .get_function_name
= rockchip_pmx_get_func_name
,
2087 .get_function_groups
= rockchip_pmx_get_groups
,
2088 .set_mux
= rockchip_pmx_set
,
2089 .gpio_set_direction
= rockchip_pmx_gpio_set_direction
,
2093 * Pinconf_ops handling
2096 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl
*ctrl
,
2097 enum pin_config_param pull
)
2099 switch (ctrl
->type
) {
2102 return (pull
== PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
||
2103 pull
== PIN_CONFIG_BIAS_DISABLE
);
2105 return pull
? false : true;
2111 return (pull
!= PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
);
2117 static void rockchip_gpio_set(struct gpio_chip
*gc
, unsigned offset
, int value
);
2118 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
);
2120 /* set the pin config settings for a specified pin */
2121 static int rockchip_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
2122 unsigned long *configs
, unsigned num_configs
)
2124 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2125 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
2126 enum pin_config_param param
;
2131 for (i
= 0; i
< num_configs
; i
++) {
2132 param
= pinconf_to_config_param(configs
[i
]);
2133 arg
= pinconf_to_config_argument(configs
[i
]);
2136 case PIN_CONFIG_BIAS_DISABLE
:
2137 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
2142 case PIN_CONFIG_BIAS_PULL_UP
:
2143 case PIN_CONFIG_BIAS_PULL_DOWN
:
2144 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
2145 case PIN_CONFIG_BIAS_BUS_HOLD
:
2146 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
2152 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
2157 case PIN_CONFIG_OUTPUT
:
2158 rockchip_gpio_set(&bank
->gpio_chip
,
2159 pin
- bank
->pin_base
, arg
);
2160 rc
= _rockchip_pmx_gpio_set_direction(&bank
->gpio_chip
,
2161 pin
- bank
->pin_base
, false);
2165 case PIN_CONFIG_DRIVE_STRENGTH
:
2166 /* rk3288 is the first with per-pin drive-strength */
2167 if (!info
->ctrl
->drv_calc_reg
)
2170 rc
= rockchip_set_drive_perpin(bank
,
2171 pin
- bank
->pin_base
, arg
);
2175 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
2176 if (!info
->ctrl
->schmitt_calc_reg
)
2179 rc
= rockchip_set_schmitt(bank
,
2180 pin
- bank
->pin_base
, arg
);
2188 } /* for each config */
2193 /* get the pin config settings for a specified pin */
2194 static int rockchip_pinconf_get(struct pinctrl_dev
*pctldev
, unsigned int pin
,
2195 unsigned long *config
)
2197 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
2198 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
2199 enum pin_config_param param
= pinconf_to_config_param(*config
);
2204 case PIN_CONFIG_BIAS_DISABLE
:
2205 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
2210 case PIN_CONFIG_BIAS_PULL_UP
:
2211 case PIN_CONFIG_BIAS_PULL_DOWN
:
2212 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
2213 case PIN_CONFIG_BIAS_BUS_HOLD
:
2214 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
2217 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
2222 case PIN_CONFIG_OUTPUT
:
2223 rc
= rockchip_get_mux(bank
, pin
- bank
->pin_base
);
2224 if (rc
!= RK_FUNC_GPIO
)
2227 rc
= rockchip_gpio_get(&bank
->gpio_chip
, pin
- bank
->pin_base
);
2233 case PIN_CONFIG_DRIVE_STRENGTH
:
2234 /* rk3288 is the first with per-pin drive-strength */
2235 if (!info
->ctrl
->drv_calc_reg
)
2238 rc
= rockchip_get_drive_perpin(bank
, pin
- bank
->pin_base
);
2244 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
2245 if (!info
->ctrl
->schmitt_calc_reg
)
2248 rc
= rockchip_get_schmitt(bank
, pin
- bank
->pin_base
);
2259 *config
= pinconf_to_config_packed(param
, arg
);
2264 static const struct pinconf_ops rockchip_pinconf_ops
= {
2265 .pin_config_get
= rockchip_pinconf_get
,
2266 .pin_config_set
= rockchip_pinconf_set
,
2270 static const struct of_device_id rockchip_bank_match
[] = {
2271 { .compatible
= "rockchip,gpio-bank" },
2272 { .compatible
= "rockchip,rk3188-gpio-bank0" },
2276 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl
*info
,
2277 struct device_node
*np
)
2279 struct device_node
*child
;
2281 for_each_child_of_node(np
, child
) {
2282 if (of_match_node(rockchip_bank_match
, child
))
2286 info
->ngroups
+= of_get_child_count(child
);
2290 static int rockchip_pinctrl_parse_groups(struct device_node
*np
,
2291 struct rockchip_pin_group
*grp
,
2292 struct rockchip_pinctrl
*info
,
2295 struct rockchip_pin_bank
*bank
;
2302 dev_dbg(info
->dev
, "group(%d): %s\n", index
, np
->name
);
2304 /* Initialise group */
2305 grp
->name
= np
->name
;
2308 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2309 * do sanity check and calculate pins number
2311 list
= of_get_property(np
, "rockchip,pins", &size
);
2312 /* we do not check return since it's safe node passed down */
2313 size
/= sizeof(*list
);
2314 if (!size
|| size
% 4) {
2315 dev_err(info
->dev
, "wrong pins number or pins and configs should be by 4\n");
2319 grp
->npins
= size
/ 4;
2321 grp
->pins
= devm_kzalloc(info
->dev
, grp
->npins
* sizeof(unsigned int),
2323 grp
->data
= devm_kzalloc(info
->dev
, grp
->npins
*
2324 sizeof(struct rockchip_pin_config
),
2326 if (!grp
->pins
|| !grp
->data
)
2329 for (i
= 0, j
= 0; i
< size
; i
+= 4, j
++) {
2330 const __be32
*phandle
;
2331 struct device_node
*np_config
;
2333 num
= be32_to_cpu(*list
++);
2334 bank
= bank_num_to_bank(info
, num
);
2336 return PTR_ERR(bank
);
2338 grp
->pins
[j
] = bank
->pin_base
+ be32_to_cpu(*list
++);
2339 grp
->data
[j
].func
= be32_to_cpu(*list
++);
2345 np_config
= of_find_node_by_phandle(be32_to_cpup(phandle
));
2346 ret
= pinconf_generic_parse_dt_config(np_config
, NULL
,
2347 &grp
->data
[j
].configs
, &grp
->data
[j
].nconfigs
);
2355 static int rockchip_pinctrl_parse_functions(struct device_node
*np
,
2356 struct rockchip_pinctrl
*info
,
2359 struct device_node
*child
;
2360 struct rockchip_pmx_func
*func
;
2361 struct rockchip_pin_group
*grp
;
2363 static u32 grp_index
;
2366 dev_dbg(info
->dev
, "parse function(%d): %s\n", index
, np
->name
);
2368 func
= &info
->functions
[index
];
2370 /* Initialise function */
2371 func
->name
= np
->name
;
2372 func
->ngroups
= of_get_child_count(np
);
2373 if (func
->ngroups
<= 0)
2376 func
->groups
= devm_kzalloc(info
->dev
,
2377 func
->ngroups
* sizeof(char *), GFP_KERNEL
);
2381 for_each_child_of_node(np
, child
) {
2382 func
->groups
[i
] = child
->name
;
2383 grp
= &info
->groups
[grp_index
++];
2384 ret
= rockchip_pinctrl_parse_groups(child
, grp
, info
, i
++);
2394 static int rockchip_pinctrl_parse_dt(struct platform_device
*pdev
,
2395 struct rockchip_pinctrl
*info
)
2397 struct device
*dev
= &pdev
->dev
;
2398 struct device_node
*np
= dev
->of_node
;
2399 struct device_node
*child
;
2403 rockchip_pinctrl_child_count(info
, np
);
2405 dev_dbg(&pdev
->dev
, "nfunctions = %d\n", info
->nfunctions
);
2406 dev_dbg(&pdev
->dev
, "ngroups = %d\n", info
->ngroups
);
2408 info
->functions
= devm_kzalloc(dev
, info
->nfunctions
*
2409 sizeof(struct rockchip_pmx_func
),
2411 if (!info
->functions
)
2414 info
->groups
= devm_kzalloc(dev
, info
->ngroups
*
2415 sizeof(struct rockchip_pin_group
),
2422 for_each_child_of_node(np
, child
) {
2423 if (of_match_node(rockchip_bank_match
, child
))
2426 ret
= rockchip_pinctrl_parse_functions(child
, info
, i
++);
2428 dev_err(&pdev
->dev
, "failed to parse function\n");
2437 static int rockchip_pinctrl_register(struct platform_device
*pdev
,
2438 struct rockchip_pinctrl
*info
)
2440 struct pinctrl_desc
*ctrldesc
= &info
->pctl
;
2441 struct pinctrl_pin_desc
*pindesc
, *pdesc
;
2442 struct rockchip_pin_bank
*pin_bank
;
2446 ctrldesc
->name
= "rockchip-pinctrl";
2447 ctrldesc
->owner
= THIS_MODULE
;
2448 ctrldesc
->pctlops
= &rockchip_pctrl_ops
;
2449 ctrldesc
->pmxops
= &rockchip_pmx_ops
;
2450 ctrldesc
->confops
= &rockchip_pinconf_ops
;
2452 pindesc
= devm_kzalloc(&pdev
->dev
, sizeof(*pindesc
) *
2453 info
->ctrl
->nr_pins
, GFP_KERNEL
);
2457 ctrldesc
->pins
= pindesc
;
2458 ctrldesc
->npins
= info
->ctrl
->nr_pins
;
2461 for (bank
= 0 , k
= 0; bank
< info
->ctrl
->nr_banks
; bank
++) {
2462 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
2463 for (pin
= 0; pin
< pin_bank
->nr_pins
; pin
++, k
++) {
2465 pdesc
->name
= kasprintf(GFP_KERNEL
, "%s-%d",
2466 pin_bank
->name
, pin
);
2471 ret
= rockchip_pinctrl_parse_dt(pdev
, info
);
2475 info
->pctl_dev
= devm_pinctrl_register(&pdev
->dev
, ctrldesc
, info
);
2476 if (IS_ERR(info
->pctl_dev
)) {
2477 dev_err(&pdev
->dev
, "could not register pinctrl driver\n");
2478 return PTR_ERR(info
->pctl_dev
);
2481 for (bank
= 0; bank
< info
->ctrl
->nr_banks
; ++bank
) {
2482 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
2483 pin_bank
->grange
.name
= pin_bank
->name
;
2484 pin_bank
->grange
.id
= bank
;
2485 pin_bank
->grange
.pin_base
= pin_bank
->pin_base
;
2486 pin_bank
->grange
.base
= pin_bank
->gpio_chip
.base
;
2487 pin_bank
->grange
.npins
= pin_bank
->gpio_chip
.ngpio
;
2488 pin_bank
->grange
.gc
= &pin_bank
->gpio_chip
;
2489 pinctrl_add_gpio_range(info
->pctl_dev
, &pin_bank
->grange
);
2499 static void rockchip_gpio_set(struct gpio_chip
*gc
, unsigned offset
, int value
)
2501 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
2502 void __iomem
*reg
= bank
->reg_base
+ GPIO_SWPORT_DR
;
2503 unsigned long flags
;
2506 clk_enable(bank
->clk
);
2507 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2510 data
&= ~BIT(offset
);
2512 data
|= BIT(offset
);
2515 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2516 clk_disable(bank
->clk
);
2520 * Returns the level of the pin for input direction and setting of the DR
2521 * register for output gpios.
2523 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
)
2525 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
2528 clk_enable(bank
->clk
);
2529 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
2530 clk_disable(bank
->clk
);
2537 * gpiolib gpio_direction_input callback function. The setting of the pin
2538 * mux function as 'gpio input' will be handled by the pinctrl subsystem
2541 static int rockchip_gpio_direction_input(struct gpio_chip
*gc
, unsigned offset
)
2543 return pinctrl_gpio_direction_input(gc
->base
+ offset
);
2547 * gpiolib gpio_direction_output callback function. The setting of the pin
2548 * mux function as 'gpio output' will be handled by the pinctrl subsystem
2551 static int rockchip_gpio_direction_output(struct gpio_chip
*gc
,
2552 unsigned offset
, int value
)
2554 rockchip_gpio_set(gc
, offset
, value
);
2555 return pinctrl_gpio_direction_output(gc
->base
+ offset
);
2559 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
2560 * and a virtual IRQ, if not already present.
2562 static int rockchip_gpio_to_irq(struct gpio_chip
*gc
, unsigned offset
)
2564 struct rockchip_pin_bank
*bank
= gpiochip_get_data(gc
);
2570 virq
= irq_create_mapping(bank
->domain
, offset
);
2572 return (virq
) ? : -ENXIO
;
2575 static const struct gpio_chip rockchip_gpiolib_chip
= {
2576 .request
= gpiochip_generic_request
,
2577 .free
= gpiochip_generic_free
,
2578 .set
= rockchip_gpio_set
,
2579 .get
= rockchip_gpio_get
,
2580 .get_direction
= rockchip_gpio_get_direction
,
2581 .direction_input
= rockchip_gpio_direction_input
,
2582 .direction_output
= rockchip_gpio_direction_output
,
2583 .to_irq
= rockchip_gpio_to_irq
,
2584 .owner
= THIS_MODULE
,
2588 * Interrupt handling
2591 static void rockchip_irq_demux(struct irq_desc
*desc
)
2593 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
2594 struct rockchip_pin_bank
*bank
= irq_desc_get_handler_data(desc
);
2597 dev_dbg(bank
->drvdata
->dev
, "got irq for bank %s\n", bank
->name
);
2599 chained_irq_enter(chip
, desc
);
2601 pend
= readl_relaxed(bank
->reg_base
+ GPIO_INT_STATUS
);
2604 unsigned int irq
, virq
;
2608 virq
= irq_linear_revmap(bank
->domain
, irq
);
2611 dev_err(bank
->drvdata
->dev
, "unmapped irq %d\n", irq
);
2615 dev_dbg(bank
->drvdata
->dev
, "handling irq %d\n", irq
);
2618 * Triggering IRQ on both rising and falling edge
2619 * needs manual intervention.
2621 if (bank
->toggle_edge_mode
& BIT(irq
)) {
2622 u32 data
, data_old
, polarity
;
2623 unsigned long flags
;
2625 data
= readl_relaxed(bank
->reg_base
+ GPIO_EXT_PORT
);
2627 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2629 polarity
= readl_relaxed(bank
->reg_base
+
2631 if (data
& BIT(irq
))
2632 polarity
&= ~BIT(irq
);
2634 polarity
|= BIT(irq
);
2636 bank
->reg_base
+ GPIO_INT_POLARITY
);
2638 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2641 data
= readl_relaxed(bank
->reg_base
+
2643 } while ((data
& BIT(irq
)) != (data_old
& BIT(irq
)));
2646 generic_handle_irq(virq
);
2649 chained_irq_exit(chip
, desc
);
2652 static int rockchip_irq_set_type(struct irq_data
*d
, unsigned int type
)
2654 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
2655 struct rockchip_pin_bank
*bank
= gc
->private;
2656 u32 mask
= BIT(d
->hwirq
);
2660 unsigned long flags
;
2663 /* make sure the pin is configured as gpio input */
2664 ret
= rockchip_set_mux(bank
, d
->hwirq
, RK_FUNC_GPIO
);
2668 clk_enable(bank
->clk
);
2669 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2671 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
2673 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
2675 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2677 if (type
& IRQ_TYPE_EDGE_BOTH
)
2678 irq_set_handler_locked(d
, handle_edge_irq
);
2680 irq_set_handler_locked(d
, handle_level_irq
);
2682 raw_spin_lock_irqsave(&bank
->slock
, flags
);
2685 level
= readl_relaxed(gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
2686 polarity
= readl_relaxed(gc
->reg_base
+ GPIO_INT_POLARITY
);
2689 case IRQ_TYPE_EDGE_BOTH
:
2690 bank
->toggle_edge_mode
|= mask
;
2694 * Determine gpio state. If 1 next interrupt should be falling
2697 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
2703 case IRQ_TYPE_EDGE_RISING
:
2704 bank
->toggle_edge_mode
&= ~mask
;
2708 case IRQ_TYPE_EDGE_FALLING
:
2709 bank
->toggle_edge_mode
&= ~mask
;
2713 case IRQ_TYPE_LEVEL_HIGH
:
2714 bank
->toggle_edge_mode
&= ~mask
;
2718 case IRQ_TYPE_LEVEL_LOW
:
2719 bank
->toggle_edge_mode
&= ~mask
;
2725 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2726 clk_disable(bank
->clk
);
2730 writel_relaxed(level
, gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
2731 writel_relaxed(polarity
, gc
->reg_base
+ GPIO_INT_POLARITY
);
2734 raw_spin_unlock_irqrestore(&bank
->slock
, flags
);
2735 clk_disable(bank
->clk
);
2740 static void rockchip_irq_suspend(struct irq_data
*d
)
2742 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
2743 struct rockchip_pin_bank
*bank
= gc
->private;
2745 clk_enable(bank
->clk
);
2746 bank
->saved_masks
= irq_reg_readl(gc
, GPIO_INTMASK
);
2747 irq_reg_writel(gc
, ~gc
->wake_active
, GPIO_INTMASK
);
2748 clk_disable(bank
->clk
);
2751 static void rockchip_irq_resume(struct irq_data
*d
)
2753 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
2754 struct rockchip_pin_bank
*bank
= gc
->private;
2756 clk_enable(bank
->clk
);
2757 irq_reg_writel(gc
, bank
->saved_masks
, GPIO_INTMASK
);
2758 clk_disable(bank
->clk
);
2761 static void rockchip_irq_enable(struct irq_data
*d
)
2763 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
2764 struct rockchip_pin_bank
*bank
= gc
->private;
2766 clk_enable(bank
->clk
);
2767 irq_gc_mask_clr_bit(d
);
2770 static void rockchip_irq_disable(struct irq_data
*d
)
2772 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
2773 struct rockchip_pin_bank
*bank
= gc
->private;
2775 irq_gc_mask_set_bit(d
);
2776 clk_disable(bank
->clk
);
2779 static int rockchip_interrupts_register(struct platform_device
*pdev
,
2780 struct rockchip_pinctrl
*info
)
2782 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2783 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
2784 unsigned int clr
= IRQ_NOREQUEST
| IRQ_NOPROBE
| IRQ_NOAUTOEN
;
2785 struct irq_chip_generic
*gc
;
2789 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
2791 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
2796 ret
= clk_enable(bank
->clk
);
2798 dev_err(&pdev
->dev
, "failed to enable clock for bank %s\n",
2803 bank
->domain
= irq_domain_add_linear(bank
->of_node
, 32,
2804 &irq_generic_chip_ops
, NULL
);
2805 if (!bank
->domain
) {
2806 dev_warn(&pdev
->dev
, "could not initialize irq domain for bank %s\n",
2808 clk_disable(bank
->clk
);
2812 ret
= irq_alloc_domain_generic_chips(bank
->domain
, 32, 1,
2813 "rockchip_gpio_irq", handle_level_irq
,
2814 clr
, 0, IRQ_GC_INIT_MASK_CACHE
);
2816 dev_err(&pdev
->dev
, "could not alloc generic chips for bank %s\n",
2818 irq_domain_remove(bank
->domain
);
2819 clk_disable(bank
->clk
);
2824 * Linux assumes that all interrupts start out disabled/masked.
2825 * Our driver only uses the concept of masked and always keeps
2826 * things enabled, so for us that's all masked and all enabled.
2828 writel_relaxed(0xffffffff, bank
->reg_base
+ GPIO_INTMASK
);
2829 writel_relaxed(0xffffffff, bank
->reg_base
+ GPIO_INTEN
);
2831 gc
= irq_get_domain_generic_chip(bank
->domain
, 0);
2832 gc
->reg_base
= bank
->reg_base
;
2834 gc
->chip_types
[0].regs
.mask
= GPIO_INTMASK
;
2835 gc
->chip_types
[0].regs
.ack
= GPIO_PORTS_EOI
;
2836 gc
->chip_types
[0].chip
.irq_ack
= irq_gc_ack_set_bit
;
2837 gc
->chip_types
[0].chip
.irq_mask
= irq_gc_mask_set_bit
;
2838 gc
->chip_types
[0].chip
.irq_unmask
= irq_gc_mask_clr_bit
;
2839 gc
->chip_types
[0].chip
.irq_enable
= rockchip_irq_enable
;
2840 gc
->chip_types
[0].chip
.irq_disable
= rockchip_irq_disable
;
2841 gc
->chip_types
[0].chip
.irq_set_wake
= irq_gc_set_wake
;
2842 gc
->chip_types
[0].chip
.irq_suspend
= rockchip_irq_suspend
;
2843 gc
->chip_types
[0].chip
.irq_resume
= rockchip_irq_resume
;
2844 gc
->chip_types
[0].chip
.irq_set_type
= rockchip_irq_set_type
;
2845 gc
->wake_enabled
= IRQ_MSK(bank
->nr_pins
);
2847 irq_set_chained_handler_and_data(bank
->irq
,
2848 rockchip_irq_demux
, bank
);
2850 /* map the gpio irqs here, when the clock is still running */
2851 for (j
= 0 ; j
< 32 ; j
++)
2852 irq_create_mapping(bank
->domain
, j
);
2854 clk_disable(bank
->clk
);
2860 static int rockchip_gpiolib_register(struct platform_device
*pdev
,
2861 struct rockchip_pinctrl
*info
)
2863 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2864 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
2865 struct gpio_chip
*gc
;
2869 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
2871 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
2876 bank
->gpio_chip
= rockchip_gpiolib_chip
;
2878 gc
= &bank
->gpio_chip
;
2879 gc
->base
= bank
->pin_base
;
2880 gc
->ngpio
= bank
->nr_pins
;
2881 gc
->parent
= &pdev
->dev
;
2882 gc
->of_node
= bank
->of_node
;
2883 gc
->label
= bank
->name
;
2885 ret
= gpiochip_add_data(gc
, bank
);
2887 dev_err(&pdev
->dev
, "failed to register gpio_chip %s, error code: %d\n",
2893 rockchip_interrupts_register(pdev
, info
);
2898 for (--i
, --bank
; i
>= 0; --i
, --bank
) {
2901 gpiochip_remove(&bank
->gpio_chip
);
2906 static int rockchip_gpiolib_unregister(struct platform_device
*pdev
,
2907 struct rockchip_pinctrl
*info
)
2909 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
2910 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
2913 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
2916 gpiochip_remove(&bank
->gpio_chip
);
2922 static int rockchip_get_bank_data(struct rockchip_pin_bank
*bank
,
2923 struct rockchip_pinctrl
*info
)
2925 struct resource res
;
2928 if (of_address_to_resource(bank
->of_node
, 0, &res
)) {
2929 dev_err(info
->dev
, "cannot find IO resource for bank\n");
2933 bank
->reg_base
= devm_ioremap_resource(info
->dev
, &res
);
2934 if (IS_ERR(bank
->reg_base
))
2935 return PTR_ERR(bank
->reg_base
);
2938 * special case, where parts of the pull setting-registers are
2939 * part of the PMU register space
2941 if (of_device_is_compatible(bank
->of_node
,
2942 "rockchip,rk3188-gpio-bank0")) {
2943 struct device_node
*node
;
2945 node
= of_parse_phandle(bank
->of_node
->parent
,
2948 if (of_address_to_resource(bank
->of_node
, 1, &res
)) {
2949 dev_err(info
->dev
, "cannot find IO resource for bank\n");
2953 base
= devm_ioremap_resource(info
->dev
, &res
);
2955 return PTR_ERR(base
);
2956 rockchip_regmap_config
.max_register
=
2957 resource_size(&res
) - 4;
2958 rockchip_regmap_config
.name
=
2959 "rockchip,rk3188-gpio-bank0-pull";
2960 bank
->regmap_pull
= devm_regmap_init_mmio(info
->dev
,
2962 &rockchip_regmap_config
);
2966 bank
->irq
= irq_of_parse_and_map(bank
->of_node
, 0);
2968 bank
->clk
= of_clk_get(bank
->of_node
, 0);
2969 if (IS_ERR(bank
->clk
))
2970 return PTR_ERR(bank
->clk
);
2972 return clk_prepare(bank
->clk
);
2975 static const struct of_device_id rockchip_pinctrl_dt_match
[];
2977 /* retrieve the soc specific data */
2978 static struct rockchip_pin_ctrl
*rockchip_pinctrl_get_soc_data(
2979 struct rockchip_pinctrl
*d
,
2980 struct platform_device
*pdev
)
2982 const struct of_device_id
*match
;
2983 struct device_node
*node
= pdev
->dev
.of_node
;
2984 struct device_node
*np
;
2985 struct rockchip_pin_ctrl
*ctrl
;
2986 struct rockchip_pin_bank
*bank
;
2987 int grf_offs
, pmu_offs
, drv_grf_offs
, drv_pmu_offs
, i
, j
;
2989 match
= of_match_node(rockchip_pinctrl_dt_match
, node
);
2990 ctrl
= (struct rockchip_pin_ctrl
*)match
->data
;
2992 for_each_child_of_node(node
, np
) {
2993 if (!of_find_property(np
, "gpio-controller", NULL
))
2996 bank
= ctrl
->pin_banks
;
2997 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
2998 if (!strcmp(bank
->name
, np
->name
)) {
3001 if (!rockchip_get_bank_data(bank
, d
))
3009 grf_offs
= ctrl
->grf_mux_offset
;
3010 pmu_offs
= ctrl
->pmu_mux_offset
;
3011 drv_pmu_offs
= ctrl
->pmu_drv_offset
;
3012 drv_grf_offs
= ctrl
->grf_drv_offset
;
3013 bank
= ctrl
->pin_banks
;
3014 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
3017 raw_spin_lock_init(&bank
->slock
);
3019 bank
->pin_base
= ctrl
->nr_pins
;
3020 ctrl
->nr_pins
+= bank
->nr_pins
;
3022 /* calculate iomux and drv offsets */
3023 for (j
= 0; j
< 4; j
++) {
3024 struct rockchip_iomux
*iom
= &bank
->iomux
[j
];
3025 struct rockchip_drv
*drv
= &bank
->drv
[j
];
3028 if (bank_pins
>= bank
->nr_pins
)
3031 /* preset iomux offset value, set new start value */
3032 if (iom
->offset
>= 0) {
3033 if (iom
->type
& IOMUX_SOURCE_PMU
)
3034 pmu_offs
= iom
->offset
;
3036 grf_offs
= iom
->offset
;
3037 } else { /* set current iomux offset */
3038 iom
->offset
= (iom
->type
& IOMUX_SOURCE_PMU
) ?
3039 pmu_offs
: grf_offs
;
3042 /* preset drv offset value, set new start value */
3043 if (drv
->offset
>= 0) {
3044 if (iom
->type
& IOMUX_SOURCE_PMU
)
3045 drv_pmu_offs
= drv
->offset
;
3047 drv_grf_offs
= drv
->offset
;
3048 } else { /* set current drv offset */
3049 drv
->offset
= (iom
->type
& IOMUX_SOURCE_PMU
) ?
3050 drv_pmu_offs
: drv_grf_offs
;
3053 dev_dbg(d
->dev
, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3054 i
, j
, iom
->offset
, drv
->offset
);
3057 * Increase offset according to iomux width.
3058 * 4bit iomux'es are spread over two registers.
3060 inc
= (iom
->type
& (IOMUX_WIDTH_4BIT
|
3061 IOMUX_WIDTH_3BIT
)) ? 8 : 4;
3062 if (iom
->type
& IOMUX_SOURCE_PMU
)
3068 * Increase offset according to drv width.
3069 * 3bit drive-strenth'es are spread over two registers.
3071 if ((drv
->drv_type
== DRV_TYPE_IO_1V8_3V0_AUTO
) ||
3072 (drv
->drv_type
== DRV_TYPE_IO_3V3_ONLY
))
3077 if (iom
->type
& IOMUX_SOURCE_PMU
)
3078 drv_pmu_offs
+= inc
;
3080 drv_grf_offs
+= inc
;
3085 /* calculate the per-bank recalced_mask */
3086 for (j
= 0; j
< ctrl
->niomux_recalced
; j
++) {
3089 if (ctrl
->iomux_recalced
[j
].num
== bank
->bank_num
) {
3090 pin
= ctrl
->iomux_recalced
[j
].pin
;
3091 bank
->recalced_mask
|= BIT(pin
);
3095 /* calculate the per-bank route_mask */
3096 for (j
= 0; j
< ctrl
->niomux_routes
; j
++) {
3099 if (ctrl
->iomux_routes
[j
].bank_num
== bank
->bank_num
) {
3100 pin
= ctrl
->iomux_routes
[j
].pin
;
3101 bank
->route_mask
|= BIT(pin
);
3109 #define RK3288_GRF_GPIO6C_IOMUX 0x64
3110 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3112 static u32 rk3288_grf_gpio6c_iomux
;
3114 static int __maybe_unused
rockchip_pinctrl_suspend(struct device
*dev
)
3116 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3117 int ret
= pinctrl_force_sleep(info
->pctl_dev
);
3123 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3124 * the setting here, and restore it at resume.
3126 if (info
->ctrl
->type
== RK3288
) {
3127 ret
= regmap_read(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3128 &rk3288_grf_gpio6c_iomux
);
3130 pinctrl_force_default(info
->pctl_dev
);
3138 static int __maybe_unused
rockchip_pinctrl_resume(struct device
*dev
)
3140 struct rockchip_pinctrl
*info
= dev_get_drvdata(dev
);
3141 int ret
= regmap_write(info
->regmap_base
, RK3288_GRF_GPIO6C_IOMUX
,
3142 rk3288_grf_gpio6c_iomux
|
3143 GPIO6C6_SEL_WRITE_ENABLE
);
3148 return pinctrl_force_default(info
->pctl_dev
);
3151 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops
, rockchip_pinctrl_suspend
,
3152 rockchip_pinctrl_resume
);
3154 static int rockchip_pinctrl_probe(struct platform_device
*pdev
)
3156 struct rockchip_pinctrl
*info
;
3157 struct device
*dev
= &pdev
->dev
;
3158 struct rockchip_pin_ctrl
*ctrl
;
3159 struct device_node
*np
= pdev
->dev
.of_node
, *node
;
3160 struct resource
*res
;
3164 if (!dev
->of_node
) {
3165 dev_err(dev
, "device tree node not found\n");
3169 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
3175 ctrl
= rockchip_pinctrl_get_soc_data(info
, pdev
);
3177 dev_err(dev
, "driver data not available\n");
3182 node
= of_parse_phandle(np
, "rockchip,grf", 0);
3184 info
->regmap_base
= syscon_node_to_regmap(node
);
3185 if (IS_ERR(info
->regmap_base
))
3186 return PTR_ERR(info
->regmap_base
);
3188 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
3189 base
= devm_ioremap_resource(&pdev
->dev
, res
);
3191 return PTR_ERR(base
);
3193 rockchip_regmap_config
.max_register
= resource_size(res
) - 4;
3194 rockchip_regmap_config
.name
= "rockchip,pinctrl";
3195 info
->regmap_base
= devm_regmap_init_mmio(&pdev
->dev
, base
,
3196 &rockchip_regmap_config
);
3198 /* to check for the old dt-bindings */
3199 info
->reg_size
= resource_size(res
);
3201 /* Honor the old binding, with pull registers as 2nd resource */
3202 if (ctrl
->type
== RK3188
&& info
->reg_size
< 0x200) {
3203 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
3204 base
= devm_ioremap_resource(&pdev
->dev
, res
);
3206 return PTR_ERR(base
);
3208 rockchip_regmap_config
.max_register
=
3209 resource_size(res
) - 4;
3210 rockchip_regmap_config
.name
= "rockchip,pinctrl-pull";
3211 info
->regmap_pull
= devm_regmap_init_mmio(&pdev
->dev
,
3213 &rockchip_regmap_config
);
3217 /* try to find the optional reference to the pmu syscon */
3218 node
= of_parse_phandle(np
, "rockchip,pmu", 0);
3220 info
->regmap_pmu
= syscon_node_to_regmap(node
);
3221 if (IS_ERR(info
->regmap_pmu
))
3222 return PTR_ERR(info
->regmap_pmu
);
3225 ret
= rockchip_gpiolib_register(pdev
, info
);
3229 ret
= rockchip_pinctrl_register(pdev
, info
);
3231 rockchip_gpiolib_unregister(pdev
, info
);
3235 platform_set_drvdata(pdev
, info
);
3240 static struct rockchip_pin_bank rv1108_pin_banks
[] = {
3241 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3245 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3246 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3247 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3250 static struct rockchip_pin_ctrl rv1108_pin_ctrl
= {
3251 .pin_banks
= rv1108_pin_banks
,
3252 .nr_banks
= ARRAY_SIZE(rv1108_pin_banks
),
3253 .label
= "RV1108-GPIO",
3255 .grf_mux_offset
= 0x10,
3256 .pmu_mux_offset
= 0x0,
3257 .iomux_recalced
= rv1108_mux_recalced_data
,
3258 .niomux_recalced
= ARRAY_SIZE(rv1108_mux_recalced_data
),
3259 .pull_calc_reg
= rv1108_calc_pull_reg_and_bit
,
3260 .drv_calc_reg
= rv1108_calc_drv_reg_and_bit
,
3261 .schmitt_calc_reg
= rv1108_calc_schmitt_reg_and_bit
,
3264 static struct rockchip_pin_bank rk2928_pin_banks
[] = {
3265 PIN_BANK(0, 32, "gpio0"),
3266 PIN_BANK(1, 32, "gpio1"),
3267 PIN_BANK(2, 32, "gpio2"),
3268 PIN_BANK(3, 32, "gpio3"),
3271 static struct rockchip_pin_ctrl rk2928_pin_ctrl
= {
3272 .pin_banks
= rk2928_pin_banks
,
3273 .nr_banks
= ARRAY_SIZE(rk2928_pin_banks
),
3274 .label
= "RK2928-GPIO",
3276 .grf_mux_offset
= 0xa8,
3277 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3280 static struct rockchip_pin_bank rk3036_pin_banks
[] = {
3281 PIN_BANK(0, 32, "gpio0"),
3282 PIN_BANK(1, 32, "gpio1"),
3283 PIN_BANK(2, 32, "gpio2"),
3286 static struct rockchip_pin_ctrl rk3036_pin_ctrl
= {
3287 .pin_banks
= rk3036_pin_banks
,
3288 .nr_banks
= ARRAY_SIZE(rk3036_pin_banks
),
3289 .label
= "RK3036-GPIO",
3291 .grf_mux_offset
= 0xa8,
3292 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3295 static struct rockchip_pin_bank rk3066a_pin_banks
[] = {
3296 PIN_BANK(0, 32, "gpio0"),
3297 PIN_BANK(1, 32, "gpio1"),
3298 PIN_BANK(2, 32, "gpio2"),
3299 PIN_BANK(3, 32, "gpio3"),
3300 PIN_BANK(4, 32, "gpio4"),
3301 PIN_BANK(6, 16, "gpio6"),
3304 static struct rockchip_pin_ctrl rk3066a_pin_ctrl
= {
3305 .pin_banks
= rk3066a_pin_banks
,
3306 .nr_banks
= ARRAY_SIZE(rk3066a_pin_banks
),
3307 .label
= "RK3066a-GPIO",
3309 .grf_mux_offset
= 0xa8,
3310 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
3313 static struct rockchip_pin_bank rk3066b_pin_banks
[] = {
3314 PIN_BANK(0, 32, "gpio0"),
3315 PIN_BANK(1, 32, "gpio1"),
3316 PIN_BANK(2, 32, "gpio2"),
3317 PIN_BANK(3, 32, "gpio3"),
3320 static struct rockchip_pin_ctrl rk3066b_pin_ctrl
= {
3321 .pin_banks
= rk3066b_pin_banks
,
3322 .nr_banks
= ARRAY_SIZE(rk3066b_pin_banks
),
3323 .label
= "RK3066b-GPIO",
3325 .grf_mux_offset
= 0x60,
3328 static struct rockchip_pin_bank rk3128_pin_banks
[] = {
3329 PIN_BANK(0, 32, "gpio0"),
3330 PIN_BANK(1, 32, "gpio1"),
3331 PIN_BANK(2, 32, "gpio2"),
3332 PIN_BANK(3, 32, "gpio3"),
3335 static struct rockchip_pin_ctrl rk3128_pin_ctrl
= {
3336 .pin_banks
= rk3128_pin_banks
,
3337 .nr_banks
= ARRAY_SIZE(rk3128_pin_banks
),
3338 .label
= "RK3128-GPIO",
3340 .grf_mux_offset
= 0xa8,
3341 .iomux_recalced
= rk3128_mux_recalced_data
,
3342 .niomux_recalced
= ARRAY_SIZE(rk3128_mux_recalced_data
),
3343 .iomux_routes
= rk3128_mux_route_data
,
3344 .niomux_routes
= ARRAY_SIZE(rk3128_mux_route_data
),
3345 .pull_calc_reg
= rk3128_calc_pull_reg_and_bit
,
3348 static struct rockchip_pin_bank rk3188_pin_banks
[] = {
3349 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY
, 0, 0, 0),
3350 PIN_BANK(1, 32, "gpio1"),
3351 PIN_BANK(2, 32, "gpio2"),
3352 PIN_BANK(3, 32, "gpio3"),
3355 static struct rockchip_pin_ctrl rk3188_pin_ctrl
= {
3356 .pin_banks
= rk3188_pin_banks
,
3357 .nr_banks
= ARRAY_SIZE(rk3188_pin_banks
),
3358 .label
= "RK3188-GPIO",
3360 .grf_mux_offset
= 0x60,
3361 .pull_calc_reg
= rk3188_calc_pull_reg_and_bit
,
3364 static struct rockchip_pin_bank rk3228_pin_banks
[] = {
3365 PIN_BANK(0, 32, "gpio0"),
3366 PIN_BANK(1, 32, "gpio1"),
3367 PIN_BANK(2, 32, "gpio2"),
3368 PIN_BANK(3, 32, "gpio3"),
3371 static struct rockchip_pin_ctrl rk3228_pin_ctrl
= {
3372 .pin_banks
= rk3228_pin_banks
,
3373 .nr_banks
= ARRAY_SIZE(rk3228_pin_banks
),
3374 .label
= "RK3228-GPIO",
3376 .grf_mux_offset
= 0x0,
3377 .iomux_routes
= rk3228_mux_route_data
,
3378 .niomux_routes
= ARRAY_SIZE(rk3228_mux_route_data
),
3379 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
3380 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
3383 static struct rockchip_pin_bank rk3288_pin_banks
[] = {
3384 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU
,
3389 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED
,
3394 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED
),
3395 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT
),
3396 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT
,
3401 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED
,
3406 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED
),
3407 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3412 PIN_BANK(8, 16, "gpio8"),
3415 static struct rockchip_pin_ctrl rk3288_pin_ctrl
= {
3416 .pin_banks
= rk3288_pin_banks
,
3417 .nr_banks
= ARRAY_SIZE(rk3288_pin_banks
),
3418 .label
= "RK3288-GPIO",
3420 .grf_mux_offset
= 0x0,
3421 .pmu_mux_offset
= 0x84,
3422 .iomux_routes
= rk3288_mux_route_data
,
3423 .niomux_routes
= ARRAY_SIZE(rk3288_mux_route_data
),
3424 .pull_calc_reg
= rk3288_calc_pull_reg_and_bit
,
3425 .drv_calc_reg
= rk3288_calc_drv_reg_and_bit
,
3428 static struct rockchip_pin_bank rk3328_pin_banks
[] = {
3429 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3430 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3431 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3435 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3442 static struct rockchip_pin_ctrl rk3328_pin_ctrl
= {
3443 .pin_banks
= rk3328_pin_banks
,
3444 .nr_banks
= ARRAY_SIZE(rk3328_pin_banks
),
3445 .label
= "RK3328-GPIO",
3447 .grf_mux_offset
= 0x0,
3448 .iomux_recalced
= rk3328_mux_recalced_data
,
3449 .niomux_recalced
= ARRAY_SIZE(rk3328_mux_recalced_data
),
3450 .iomux_routes
= rk3328_mux_route_data
,
3451 .niomux_routes
= ARRAY_SIZE(rk3328_mux_route_data
),
3452 .pull_calc_reg
= rk3228_calc_pull_reg_and_bit
,
3453 .drv_calc_reg
= rk3228_calc_drv_reg_and_bit
,
3454 .schmitt_calc_reg
= rk3328_calc_schmitt_reg_and_bit
,
3457 static struct rockchip_pin_bank rk3368_pin_banks
[] = {
3458 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU
,
3463 PIN_BANK(1, 32, "gpio1"),
3464 PIN_BANK(2, 32, "gpio2"),
3465 PIN_BANK(3, 32, "gpio3"),
3468 static struct rockchip_pin_ctrl rk3368_pin_ctrl
= {
3469 .pin_banks
= rk3368_pin_banks
,
3470 .nr_banks
= ARRAY_SIZE(rk3368_pin_banks
),
3471 .label
= "RK3368-GPIO",
3473 .grf_mux_offset
= 0x0,
3474 .pmu_mux_offset
= 0x0,
3475 .pull_calc_reg
= rk3368_calc_pull_reg_and_bit
,
3476 .drv_calc_reg
= rk3368_calc_drv_reg_and_bit
,
3479 static struct rockchip_pin_bank rk3399_pin_banks
[] = {
3480 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3485 DRV_TYPE_IO_1V8_ONLY
,
3486 DRV_TYPE_IO_1V8_ONLY
,
3487 DRV_TYPE_IO_DEFAULT
,
3488 DRV_TYPE_IO_DEFAULT
,
3493 PULL_TYPE_IO_1V8_ONLY
,
3494 PULL_TYPE_IO_1V8_ONLY
,
3495 PULL_TYPE_IO_DEFAULT
,
3496 PULL_TYPE_IO_DEFAULT
3498 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU
,
3502 DRV_TYPE_IO_1V8_OR_3V0
,
3503 DRV_TYPE_IO_1V8_OR_3V0
,
3504 DRV_TYPE_IO_1V8_OR_3V0
,
3505 DRV_TYPE_IO_1V8_OR_3V0
,
3511 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0
,
3512 DRV_TYPE_IO_1V8_OR_3V0
,
3513 DRV_TYPE_IO_1V8_ONLY
,
3514 DRV_TYPE_IO_1V8_ONLY
,
3515 PULL_TYPE_IO_DEFAULT
,
3516 PULL_TYPE_IO_DEFAULT
,
3517 PULL_TYPE_IO_1V8_ONLY
,
3518 PULL_TYPE_IO_1V8_ONLY
3520 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY
,
3521 DRV_TYPE_IO_3V3_ONLY
,
3522 DRV_TYPE_IO_3V3_ONLY
,
3523 DRV_TYPE_IO_1V8_OR_3V0
3525 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0
,
3526 DRV_TYPE_IO_1V8_3V0_AUTO
,
3527 DRV_TYPE_IO_1V8_OR_3V0
,
3528 DRV_TYPE_IO_1V8_OR_3V0
3532 static struct rockchip_pin_ctrl rk3399_pin_ctrl
= {
3533 .pin_banks
= rk3399_pin_banks
,
3534 .nr_banks
= ARRAY_SIZE(rk3399_pin_banks
),
3535 .label
= "RK3399-GPIO",
3537 .grf_mux_offset
= 0xe000,
3538 .pmu_mux_offset
= 0x0,
3539 .grf_drv_offset
= 0xe100,
3540 .pmu_drv_offset
= 0x80,
3541 .iomux_routes
= rk3399_mux_route_data
,
3542 .niomux_routes
= ARRAY_SIZE(rk3399_mux_route_data
),
3543 .pull_calc_reg
= rk3399_calc_pull_reg_and_bit
,
3544 .drv_calc_reg
= rk3399_calc_drv_reg_and_bit
,
3547 static const struct of_device_id rockchip_pinctrl_dt_match
[] = {
3548 { .compatible
= "rockchip,rv1108-pinctrl",
3549 .data
= &rv1108_pin_ctrl
},
3550 { .compatible
= "rockchip,rk2928-pinctrl",
3551 .data
= &rk2928_pin_ctrl
},
3552 { .compatible
= "rockchip,rk3036-pinctrl",
3553 .data
= &rk3036_pin_ctrl
},
3554 { .compatible
= "rockchip,rk3066a-pinctrl",
3555 .data
= &rk3066a_pin_ctrl
},
3556 { .compatible
= "rockchip,rk3066b-pinctrl",
3557 .data
= &rk3066b_pin_ctrl
},
3558 { .compatible
= "rockchip,rk3128-pinctrl",
3559 .data
= (void *)&rk3128_pin_ctrl
},
3560 { .compatible
= "rockchip,rk3188-pinctrl",
3561 .data
= &rk3188_pin_ctrl
},
3562 { .compatible
= "rockchip,rk3228-pinctrl",
3563 .data
= &rk3228_pin_ctrl
},
3564 { .compatible
= "rockchip,rk3288-pinctrl",
3565 .data
= &rk3288_pin_ctrl
},
3566 { .compatible
= "rockchip,rk3328-pinctrl",
3567 .data
= &rk3328_pin_ctrl
},
3568 { .compatible
= "rockchip,rk3368-pinctrl",
3569 .data
= &rk3368_pin_ctrl
},
3570 { .compatible
= "rockchip,rk3399-pinctrl",
3571 .data
= &rk3399_pin_ctrl
},
3575 static struct platform_driver rockchip_pinctrl_driver
= {
3576 .probe
= rockchip_pinctrl_probe
,
3578 .name
= "rockchip-pinctrl",
3579 .pm
= &rockchip_pinctrl_dev_pm_ops
,
3580 .of_match_table
= rockchip_pinctrl_dt_match
,
3584 static int __init
rockchip_pinctrl_drv_register(void)
3586 return platform_driver_register(&rockchip_pinctrl_driver
);
3588 postcore_initcall(rockchip_pinctrl_drv_register
);