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: are all necessary informations 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 rk3328_mux_route_data[] = {
893 .route_offset = 0x50,
894 .route_val = BIT(16) | BIT(16 + 1),
900 .route_offset = 0x50,
901 .route_val = BIT(16) | BIT(16 + 1) | BIT(0),
903 /* gmac-m1-optimized_rxd0 */
907 .route_offset = 0x50,
908 .route_val = BIT(16 + 2) | BIT(16 + 10) | BIT(2) | BIT(10),
914 .route_offset = 0x50,
915 .route_val = BIT(16 + 3),
921 .route_offset = 0x50,
922 .route_val = BIT(16 + 3) | BIT(3),
928 .route_offset = 0x50,
929 .route_val = BIT(16 + 4) | BIT(16 + 5) | BIT(5),
935 .route_offset = 0x50,
936 .route_val = BIT(16 + 6),
942 .route_offset = 0x50,
943 .route_val = BIT(16 + 6) | BIT(6),
949 .route_offset = 0x50,
950 .route_val = BIT(16 + 7) | BIT(7),
956 .route_offset = 0x50,
957 .route_val = BIT(16 + 8) | BIT(8),
963 .route_offset = 0x50,
964 .route_val = BIT(16 + 9) | BIT(9),
968 static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
974 .route_offset = 0xe21c,
975 .route_val = BIT(16 + 10) | BIT(16 + 11),
981 .route_offset = 0xe21c,
982 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(10),
988 .route_offset = 0xe21c,
989 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(11),
995 .route_offset = 0xe21c,
996 .route_val = BIT(16 + 14),
1002 .route_offset = 0xe21c,
1003 .route_val = BIT(16 + 14) | BIT(14),
1007 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
1008 int mux, u32 *reg, u32 *value)
1010 struct rockchip_pinctrl *info = bank->drvdata;
1011 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1012 struct rockchip_mux_route_data *data;
1015 for (i = 0; i < ctrl->niomux_routes; i++) {
1016 data = &ctrl->iomux_routes[i];
1017 if ((data->bank_num == bank->bank_num) &&
1018 (data->pin == pin) && (data->func == mux))
1022 if (i >= ctrl->niomux_routes)
1025 *reg = data->route_offset;
1026 *value = data->route_val;
1031 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
1033 struct rockchip_pinctrl *info = bank->drvdata;
1034 int iomux_num = (pin / 8);
1035 struct regmap *regmap;
1037 int reg, ret, mask, mux_type;
1043 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1044 dev_err(info->dev, "pin %d is unrouted\n", pin);
1048 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
1049 return RK_FUNC_GPIO;
1051 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1052 ? info->regmap_pmu : info->regmap_base;
1054 /* get basic quadrupel of mux registers and the correct reg inside */
1055 mux_type = bank->iomux[iomux_num].type;
1056 reg = bank->iomux[iomux_num].offset;
1057 if (mux_type & IOMUX_WIDTH_4BIT) {
1060 bit = (pin % 4) * 4;
1062 } else if (mux_type & IOMUX_WIDTH_3BIT) {
1065 bit = (pin % 8 % 5) * 3;
1068 bit = (pin % 8) * 2;
1072 if (bank->recalced_mask & BIT(pin))
1073 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
1075 ret = regmap_read(regmap, reg, &val);
1079 return ((val >> bit) & mask);
1082 static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
1085 struct rockchip_pinctrl *info = bank->drvdata;
1086 int iomux_num = (pin / 8);
1091 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1092 dev_err(info->dev, "pin %d is unrouted\n", pin);
1096 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
1097 if (mux != RK_FUNC_GPIO) {
1099 "pin %d only supports a gpio mux\n", pin);
1108 * Set a new mux function for a pin.
1110 * The register is divided into the upper and lower 16 bit. When changing
1111 * a value, the previous register value is not read and changed. Instead
1112 * it seems the changed bits are marked in the upper 16 bit, while the
1113 * changed value gets set in the same offset in the lower 16 bit.
1114 * All pin settings seem to be 2 bit wide in both the upper and lower
1116 * @bank: pin bank to change
1117 * @pin: pin to change
1118 * @mux: new mux function to set
1120 static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
1122 struct rockchip_pinctrl *info = bank->drvdata;
1123 int iomux_num = (pin / 8);
1124 struct regmap *regmap;
1125 int reg, ret, mask, mux_type;
1127 u32 data, rmask, route_reg, route_val;
1129 ret = rockchip_verify_mux(bank, pin, mux);
1133 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
1136 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
1137 bank->bank_num, pin, mux);
1139 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1140 ? info->regmap_pmu : info->regmap_base;
1142 /* get basic quadrupel of mux registers and the correct reg inside */
1143 mux_type = bank->iomux[iomux_num].type;
1144 reg = bank->iomux[iomux_num].offset;
1145 if (mux_type & IOMUX_WIDTH_4BIT) {
1148 bit = (pin % 4) * 4;
1150 } else if (mux_type & IOMUX_WIDTH_3BIT) {
1153 bit = (pin % 8 % 5) * 3;
1156 bit = (pin % 8) * 2;
1160 if (bank->recalced_mask & BIT(pin))
1161 rockchip_get_recalced_mux(bank, pin, ®, &bit, &mask);
1163 if (bank->route_mask & BIT(pin)) {
1164 if (rockchip_get_mux_route(bank, pin, mux, &route_reg,
1166 ret = regmap_write(regmap, route_reg, route_val);
1172 data = (mask << (bit + 16));
1173 rmask = data | (data >> 16);
1174 data |= (mux & mask) << bit;
1175 ret = regmap_update_bits(regmap, reg, rmask, data);
1180 #define RV1108_PULL_PMU_OFFSET 0x10
1181 #define RV1108_PULL_OFFSET 0x110
1182 #define RV1108_PULL_PINS_PER_REG 8
1183 #define RV1108_PULL_BITS_PER_PIN 2
1184 #define RV1108_PULL_BANK_STRIDE 16
1186 static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1187 int pin_num, struct regmap **regmap,
1190 struct rockchip_pinctrl *info = bank->drvdata;
1192 /* The first 24 pins of the first bank are located in PMU */
1193 if (bank->bank_num == 0) {
1194 *regmap = info->regmap_pmu;
1195 *reg = RV1108_PULL_PMU_OFFSET;
1197 *reg = RV1108_PULL_OFFSET;
1198 *regmap = info->regmap_base;
1199 /* correct the offset, as we're starting with the 2nd bank */
1201 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
1204 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1205 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1206 *bit *= RV1108_PULL_BITS_PER_PIN;
1209 #define RV1108_DRV_PMU_OFFSET 0x20
1210 #define RV1108_DRV_GRF_OFFSET 0x210
1211 #define RV1108_DRV_BITS_PER_PIN 2
1212 #define RV1108_DRV_PINS_PER_REG 8
1213 #define RV1108_DRV_BANK_STRIDE 16
1215 static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1216 int pin_num, struct regmap **regmap,
1219 struct rockchip_pinctrl *info = bank->drvdata;
1221 /* The first 24 pins of the first bank are located in PMU */
1222 if (bank->bank_num == 0) {
1223 *regmap = info->regmap_pmu;
1224 *reg = RV1108_DRV_PMU_OFFSET;
1226 *regmap = info->regmap_base;
1227 *reg = RV1108_DRV_GRF_OFFSET;
1229 /* correct the offset, as we're starting with the 2nd bank */
1231 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
1234 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1235 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1236 *bit *= RV1108_DRV_BITS_PER_PIN;
1239 #define RV1108_SCHMITT_PMU_OFFSET 0x30
1240 #define RV1108_SCHMITT_GRF_OFFSET 0x388
1241 #define RV1108_SCHMITT_BANK_STRIDE 8
1242 #define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1243 #define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1245 static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1247 struct regmap **regmap,
1250 struct rockchip_pinctrl *info = bank->drvdata;
1253 if (bank->bank_num == 0) {
1254 *regmap = info->regmap_pmu;
1255 *reg = RV1108_SCHMITT_PMU_OFFSET;
1256 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1258 *regmap = info->regmap_base;
1259 *reg = RV1108_SCHMITT_GRF_OFFSET;
1260 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1261 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1263 *reg += ((pin_num / pins_per_reg) * 4);
1264 *bit = pin_num % pins_per_reg;
1269 #define RK2928_PULL_OFFSET 0x118
1270 #define RK2928_PULL_PINS_PER_REG 16
1271 #define RK2928_PULL_BANK_STRIDE 8
1273 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1274 int pin_num, struct regmap **regmap,
1277 struct rockchip_pinctrl *info = bank->drvdata;
1279 *regmap = info->regmap_base;
1280 *reg = RK2928_PULL_OFFSET;
1281 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1282 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1284 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1287 #define RK3128_PULL_OFFSET 0x118
1289 static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1290 int pin_num, struct regmap **regmap,
1293 struct rockchip_pinctrl *info = bank->drvdata;
1295 *regmap = info->regmap_base;
1296 *reg = RK3128_PULL_OFFSET;
1297 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1298 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1300 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1303 #define RK3188_PULL_OFFSET 0x164
1304 #define RK3188_PULL_BITS_PER_PIN 2
1305 #define RK3188_PULL_PINS_PER_REG 8
1306 #define RK3188_PULL_BANK_STRIDE 16
1307 #define RK3188_PULL_PMU_OFFSET 0x64
1309 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1310 int pin_num, struct regmap **regmap,
1313 struct rockchip_pinctrl *info = bank->drvdata;
1315 /* The first 12 pins of the first bank are located elsewhere */
1316 if (bank->bank_num == 0 && pin_num < 12) {
1317 *regmap = info->regmap_pmu ? info->regmap_pmu
1318 : bank->regmap_pull;
1319 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
1320 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1321 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1322 *bit *= RK3188_PULL_BITS_PER_PIN;
1324 *regmap = info->regmap_pull ? info->regmap_pull
1325 : info->regmap_base;
1326 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1328 /* correct the offset, as it is the 2nd pull register */
1330 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1331 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1334 * The bits in these registers have an inverse ordering
1335 * with the lowest pin being in bits 15:14 and the highest
1338 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1339 *bit *= RK3188_PULL_BITS_PER_PIN;
1343 #define RK3288_PULL_OFFSET 0x140
1344 static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1345 int pin_num, struct regmap **regmap,
1348 struct rockchip_pinctrl *info = bank->drvdata;
1350 /* The first 24 pins of the first bank are located in PMU */
1351 if (bank->bank_num == 0) {
1352 *regmap = info->regmap_pmu;
1353 *reg = RK3188_PULL_PMU_OFFSET;
1355 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1356 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1357 *bit *= RK3188_PULL_BITS_PER_PIN;
1359 *regmap = info->regmap_base;
1360 *reg = RK3288_PULL_OFFSET;
1362 /* correct the offset, as we're starting with the 2nd bank */
1364 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1365 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1367 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1368 *bit *= RK3188_PULL_BITS_PER_PIN;
1372 #define RK3288_DRV_PMU_OFFSET 0x70
1373 #define RK3288_DRV_GRF_OFFSET 0x1c0
1374 #define RK3288_DRV_BITS_PER_PIN 2
1375 #define RK3288_DRV_PINS_PER_REG 8
1376 #define RK3288_DRV_BANK_STRIDE 16
1378 static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1379 int pin_num, struct regmap **regmap,
1382 struct rockchip_pinctrl *info = bank->drvdata;
1384 /* The first 24 pins of the first bank are located in PMU */
1385 if (bank->bank_num == 0) {
1386 *regmap = info->regmap_pmu;
1387 *reg = RK3288_DRV_PMU_OFFSET;
1389 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1390 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1391 *bit *= RK3288_DRV_BITS_PER_PIN;
1393 *regmap = info->regmap_base;
1394 *reg = RK3288_DRV_GRF_OFFSET;
1396 /* correct the offset, as we're starting with the 2nd bank */
1398 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1399 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1401 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1402 *bit *= RK3288_DRV_BITS_PER_PIN;
1406 #define RK3228_PULL_OFFSET 0x100
1408 static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1409 int pin_num, struct regmap **regmap,
1412 struct rockchip_pinctrl *info = bank->drvdata;
1414 *regmap = info->regmap_base;
1415 *reg = RK3228_PULL_OFFSET;
1416 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1417 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1419 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1420 *bit *= RK3188_PULL_BITS_PER_PIN;
1423 #define RK3228_DRV_GRF_OFFSET 0x200
1425 static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1426 int pin_num, struct regmap **regmap,
1429 struct rockchip_pinctrl *info = bank->drvdata;
1431 *regmap = info->regmap_base;
1432 *reg = RK3228_DRV_GRF_OFFSET;
1433 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1434 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1436 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1437 *bit *= RK3288_DRV_BITS_PER_PIN;
1440 #define RK3368_PULL_GRF_OFFSET 0x100
1441 #define RK3368_PULL_PMU_OFFSET 0x10
1443 static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1444 int pin_num, struct regmap **regmap,
1447 struct rockchip_pinctrl *info = bank->drvdata;
1449 /* The first 32 pins of the first bank are located in PMU */
1450 if (bank->bank_num == 0) {
1451 *regmap = info->regmap_pmu;
1452 *reg = RK3368_PULL_PMU_OFFSET;
1454 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1455 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1456 *bit *= RK3188_PULL_BITS_PER_PIN;
1458 *regmap = info->regmap_base;
1459 *reg = RK3368_PULL_GRF_OFFSET;
1461 /* correct the offset, as we're starting with the 2nd bank */
1463 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1464 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1466 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1467 *bit *= RK3188_PULL_BITS_PER_PIN;
1471 #define RK3368_DRV_PMU_OFFSET 0x20
1472 #define RK3368_DRV_GRF_OFFSET 0x200
1474 static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1475 int pin_num, struct regmap **regmap,
1478 struct rockchip_pinctrl *info = bank->drvdata;
1480 /* The first 32 pins of the first bank are located in PMU */
1481 if (bank->bank_num == 0) {
1482 *regmap = info->regmap_pmu;
1483 *reg = RK3368_DRV_PMU_OFFSET;
1485 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1486 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1487 *bit *= RK3288_DRV_BITS_PER_PIN;
1489 *regmap = info->regmap_base;
1490 *reg = RK3368_DRV_GRF_OFFSET;
1492 /* correct the offset, as we're starting with the 2nd bank */
1494 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1495 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1497 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1498 *bit *= RK3288_DRV_BITS_PER_PIN;
1502 #define RK3399_PULL_GRF_OFFSET 0xe040
1503 #define RK3399_PULL_PMU_OFFSET 0x40
1504 #define RK3399_DRV_3BITS_PER_PIN 3
1506 static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1507 int pin_num, struct regmap **regmap,
1510 struct rockchip_pinctrl *info = bank->drvdata;
1512 /* The bank0:16 and bank1:32 pins are located in PMU */
1513 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1514 *regmap = info->regmap_pmu;
1515 *reg = RK3399_PULL_PMU_OFFSET;
1517 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1519 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1520 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1521 *bit *= RK3188_PULL_BITS_PER_PIN;
1523 *regmap = info->regmap_base;
1524 *reg = RK3399_PULL_GRF_OFFSET;
1526 /* correct the offset, as we're starting with the 3rd bank */
1528 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1529 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1531 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1532 *bit *= RK3188_PULL_BITS_PER_PIN;
1536 static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1537 int pin_num, struct regmap **regmap,
1540 struct rockchip_pinctrl *info = bank->drvdata;
1541 int drv_num = (pin_num / 8);
1543 /* The bank0:16 and bank1:32 pins are located in PMU */
1544 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1545 *regmap = info->regmap_pmu;
1547 *regmap = info->regmap_base;
1549 *reg = bank->drv[drv_num].offset;
1550 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1551 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1552 *bit = (pin_num % 8) * 3;
1554 *bit = (pin_num % 8) * 2;
1557 static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1558 { 2, 4, 8, 12, -1, -1, -1, -1 },
1559 { 3, 6, 9, 12, -1, -1, -1, -1 },
1560 { 5, 10, 15, 20, -1, -1, -1, -1 },
1561 { 4, 6, 8, 10, 12, 14, 16, 18 },
1562 { 4, 7, 10, 13, 16, 19, 22, 26 }
1565 static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1568 struct rockchip_pinctrl *info = bank->drvdata;
1569 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1570 struct regmap *regmap;
1572 u32 data, temp, rmask_bits;
1574 int drv_type = bank->drv[pin_num / 8].drv_type;
1576 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1579 case DRV_TYPE_IO_1V8_3V0_AUTO:
1580 case DRV_TYPE_IO_3V3_ONLY:
1581 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1584 /* regular case, nothing to do */
1588 * drive-strength offset is special, as it is
1589 * spread over 2 registers
1591 ret = regmap_read(regmap, reg, &data);
1595 ret = regmap_read(regmap, reg + 0x4, &temp);
1600 * the bit data[15] contains bit 0 of the value
1601 * while temp[1:0] contains bits 2 and 1
1608 return rockchip_perpin_drv_list[drv_type][data];
1610 /* setting fully enclosed in the second register */
1615 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1621 case DRV_TYPE_IO_DEFAULT:
1622 case DRV_TYPE_IO_1V8_OR_3V0:
1623 case DRV_TYPE_IO_1V8_ONLY:
1624 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1627 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1632 ret = regmap_read(regmap, reg, &data);
1637 data &= (1 << rmask_bits) - 1;
1639 return rockchip_perpin_drv_list[drv_type][data];
1642 static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1643 int pin_num, int strength)
1645 struct rockchip_pinctrl *info = bank->drvdata;
1646 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1647 struct regmap *regmap;
1649 u32 data, rmask, rmask_bits, temp;
1651 int drv_type = bank->drv[pin_num / 8].drv_type;
1653 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1654 bank->bank_num, pin_num, strength);
1656 ctrl->drv_calc_reg(bank, pin_num, ®map, ®, &bit);
1659 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1660 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
1663 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1664 ret = rockchip_perpin_drv_list[drv_type][i];
1670 dev_err(info->dev, "unsupported driver strength %d\n",
1676 case DRV_TYPE_IO_1V8_3V0_AUTO:
1677 case DRV_TYPE_IO_3V3_ONLY:
1678 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1681 /* regular case, nothing to do */
1685 * drive-strength offset is special, as it is spread
1686 * over 2 registers, the bit data[15] contains bit 0
1687 * of the value while temp[1:0] contains bits 2 and 1
1689 data = (ret & 0x1) << 15;
1690 temp = (ret >> 0x1) & 0x3;
1692 rmask = BIT(15) | BIT(31);
1694 ret = regmap_update_bits(regmap, reg, rmask, data);
1698 rmask = 0x3 | (0x3 << 16);
1699 temp |= (0x3 << 16);
1701 ret = regmap_update_bits(regmap, reg, rmask, temp);
1705 /* setting fully enclosed in the second register */
1710 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1715 case DRV_TYPE_IO_DEFAULT:
1716 case DRV_TYPE_IO_1V8_OR_3V0:
1717 case DRV_TYPE_IO_1V8_ONLY:
1718 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1721 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1726 /* enable the write to the equivalent lower bits */
1727 data = ((1 << rmask_bits) - 1) << (bit + 16);
1728 rmask = data | (data >> 16);
1729 data |= (ret << bit);
1731 ret = regmap_update_bits(regmap, reg, rmask, data);
1736 static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1738 PIN_CONFIG_BIAS_DISABLE,
1739 PIN_CONFIG_BIAS_PULL_UP,
1740 PIN_CONFIG_BIAS_PULL_DOWN,
1741 PIN_CONFIG_BIAS_BUS_HOLD
1744 PIN_CONFIG_BIAS_DISABLE,
1745 PIN_CONFIG_BIAS_PULL_DOWN,
1746 PIN_CONFIG_BIAS_DISABLE,
1747 PIN_CONFIG_BIAS_PULL_UP
1751 static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1753 struct rockchip_pinctrl *info = bank->drvdata;
1754 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1755 struct regmap *regmap;
1756 int reg, ret, pull_type;
1760 /* rk3066b does support any pulls */
1761 if (ctrl->type == RK3066B)
1762 return PIN_CONFIG_BIAS_DISABLE;
1764 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1766 ret = regmap_read(regmap, reg, &data);
1770 switch (ctrl->type) {
1773 return !(data & BIT(bit))
1774 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1775 : PIN_CONFIG_BIAS_DISABLE;
1781 pull_type = bank->pull_type[pin_num / 8];
1783 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1785 return rockchip_pull_list[pull_type][data];
1787 dev_err(info->dev, "unsupported pinctrl type\n");
1792 static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1793 int pin_num, int pull)
1795 struct rockchip_pinctrl *info = bank->drvdata;
1796 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1797 struct regmap *regmap;
1798 int reg, ret, i, pull_type;
1802 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
1803 bank->bank_num, pin_num, pull);
1805 /* rk3066b does support any pulls */
1806 if (ctrl->type == RK3066B)
1807 return pull ? -EINVAL : 0;
1809 ctrl->pull_calc_reg(bank, pin_num, ®map, ®, &bit);
1811 switch (ctrl->type) {
1814 data = BIT(bit + 16);
1815 if (pull == PIN_CONFIG_BIAS_DISABLE)
1817 ret = regmap_write(regmap, reg, data);
1824 pull_type = bank->pull_type[pin_num / 8];
1826 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
1828 if (rockchip_pull_list[pull_type][i] == pull) {
1835 dev_err(info->dev, "unsupported pull setting %d\n",
1840 /* enable the write to the equivalent lower bits */
1841 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
1842 rmask = data | (data >> 16);
1843 data |= (ret << bit);
1845 ret = regmap_update_bits(regmap, reg, rmask, data);
1848 dev_err(info->dev, "unsupported pinctrl type\n");
1855 #define RK3328_SCHMITT_BITS_PER_PIN 1
1856 #define RK3328_SCHMITT_PINS_PER_REG 16
1857 #define RK3328_SCHMITT_BANK_STRIDE 8
1858 #define RK3328_SCHMITT_GRF_OFFSET 0x380
1860 static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1862 struct regmap **regmap,
1865 struct rockchip_pinctrl *info = bank->drvdata;
1867 *regmap = info->regmap_base;
1868 *reg = RK3328_SCHMITT_GRF_OFFSET;
1870 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
1871 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
1872 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
1877 static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
1879 struct rockchip_pinctrl *info = bank->drvdata;
1880 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1881 struct regmap *regmap;
1886 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1890 ret = regmap_read(regmap, reg, &data);
1898 static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
1899 int pin_num, int enable)
1901 struct rockchip_pinctrl *info = bank->drvdata;
1902 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1903 struct regmap *regmap;
1908 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
1909 bank->bank_num, pin_num, enable);
1911 ret = ctrl->schmitt_calc_reg(bank, pin_num, ®map, ®, &bit);
1915 /* enable the write to the equivalent lower bits */
1916 data = BIT(bit + 16) | (enable << bit);
1917 rmask = BIT(bit + 16) | BIT(bit);
1919 return regmap_update_bits(regmap, reg, rmask, data);
1923 * Pinmux_ops handling
1926 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
1928 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1930 return info->nfunctions;
1933 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
1936 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1938 return info->functions[selector].name;
1941 static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
1942 unsigned selector, const char * const **groups,
1943 unsigned * const num_groups)
1945 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1947 *groups = info->functions[selector].groups;
1948 *num_groups = info->functions[selector].ngroups;
1953 static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
1956 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1957 const unsigned int *pins = info->groups[group].pins;
1958 const struct rockchip_pin_config *data = info->groups[group].data;
1959 struct rockchip_pin_bank *bank;
1962 dev_dbg(info->dev, "enable function %s group %s\n",
1963 info->functions[selector].name, info->groups[group].name);
1966 * for each pin in the pin group selected, program the correspoding pin
1967 * pin function number in the config register.
1969 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
1970 bank = pin_to_bank(info, pins[cnt]);
1971 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
1978 /* revert the already done pin settings */
1979 for (cnt--; cnt >= 0; cnt--)
1980 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
1988 static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
1990 struct rockchip_pin_bank *bank = gpiochip_get_data(chip);
1993 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
1995 return !(data & BIT(offset));
1999 * The calls to gpio_direction_output() and gpio_direction_input()
2000 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
2001 * function called from the gpiolib interface).
2003 static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip,
2004 int pin, bool input)
2006 struct rockchip_pin_bank *bank;
2008 unsigned long flags;
2011 bank = gpiochip_get_data(chip);
2013 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
2017 clk_enable(bank->clk);
2018 raw_spin_lock_irqsave(&bank->slock, flags);
2020 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2021 /* set bit to 1 for output, 0 for input */
2026 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2028 raw_spin_unlock_irqrestore(&bank->slock, flags);
2029 clk_disable(bank->clk);
2034 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
2035 struct pinctrl_gpio_range *range,
2036 unsigned offset, bool input)
2038 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2039 struct gpio_chip *chip;
2043 pin = offset - chip->base;
2044 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
2045 offset, range->name, pin, input ? "input" : "output");
2047 return _rockchip_pmx_gpio_set_direction(chip, offset - chip->base,
2051 static const struct pinmux_ops rockchip_pmx_ops = {
2052 .get_functions_count = rockchip_pmx_get_funcs_count,
2053 .get_function_name = rockchip_pmx_get_func_name,
2054 .get_function_groups = rockchip_pmx_get_groups,
2055 .set_mux = rockchip_pmx_set,
2056 .gpio_set_direction = rockchip_pmx_gpio_set_direction,
2060 * Pinconf_ops handling
2063 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2064 enum pin_config_param pull)
2066 switch (ctrl->type) {
2069 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2070 pull == PIN_CONFIG_BIAS_DISABLE);
2072 return pull ? false : true;
2078 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
2084 static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
2085 static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset);
2087 /* set the pin config settings for a specified pin */
2088 static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
2089 unsigned long *configs, unsigned num_configs)
2091 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2092 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2093 enum pin_config_param param;
2098 for (i = 0; i < num_configs; i++) {
2099 param = pinconf_to_config_param(configs[i]);
2100 arg = pinconf_to_config_argument(configs[i]);
2103 case PIN_CONFIG_BIAS_DISABLE:
2104 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2109 case PIN_CONFIG_BIAS_PULL_UP:
2110 case PIN_CONFIG_BIAS_PULL_DOWN:
2111 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2112 case PIN_CONFIG_BIAS_BUS_HOLD:
2113 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2119 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2124 case PIN_CONFIG_OUTPUT:
2125 rockchip_gpio_set(&bank->gpio_chip,
2126 pin - bank->pin_base, arg);
2127 rc = _rockchip_pmx_gpio_set_direction(&bank->gpio_chip,
2128 pin - bank->pin_base, false);
2132 case PIN_CONFIG_DRIVE_STRENGTH:
2133 /* rk3288 is the first with per-pin drive-strength */
2134 if (!info->ctrl->drv_calc_reg)
2137 rc = rockchip_set_drive_perpin(bank,
2138 pin - bank->pin_base, arg);
2142 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2143 if (!info->ctrl->schmitt_calc_reg)
2146 rc = rockchip_set_schmitt(bank,
2147 pin - bank->pin_base, arg);
2155 } /* for each config */
2160 /* get the pin config settings for a specified pin */
2161 static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2162 unsigned long *config)
2164 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2165 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2166 enum pin_config_param param = pinconf_to_config_param(*config);
2171 case PIN_CONFIG_BIAS_DISABLE:
2172 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2177 case PIN_CONFIG_BIAS_PULL_UP:
2178 case PIN_CONFIG_BIAS_PULL_DOWN:
2179 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
2180 case PIN_CONFIG_BIAS_BUS_HOLD:
2181 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2184 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2189 case PIN_CONFIG_OUTPUT:
2190 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2191 if (rc != RK_FUNC_GPIO)
2194 rc = rockchip_gpio_get(&bank->gpio_chip, pin - bank->pin_base);
2200 case PIN_CONFIG_DRIVE_STRENGTH:
2201 /* rk3288 is the first with per-pin drive-strength */
2202 if (!info->ctrl->drv_calc_reg)
2205 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
2211 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2212 if (!info->ctrl->schmitt_calc_reg)
2215 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2226 *config = pinconf_to_config_packed(param, arg);
2231 static const struct pinconf_ops rockchip_pinconf_ops = {
2232 .pin_config_get = rockchip_pinconf_get,
2233 .pin_config_set = rockchip_pinconf_set,
2237 static const struct of_device_id rockchip_bank_match[] = {
2238 { .compatible = "rockchip,gpio-bank" },
2239 { .compatible = "rockchip,rk3188-gpio-bank0" },
2243 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2244 struct device_node *np)
2246 struct device_node *child;
2248 for_each_child_of_node(np, child) {
2249 if (of_match_node(rockchip_bank_match, child))
2253 info->ngroups += of_get_child_count(child);
2257 static int rockchip_pinctrl_parse_groups(struct device_node *np,
2258 struct rockchip_pin_group *grp,
2259 struct rockchip_pinctrl *info,
2262 struct rockchip_pin_bank *bank;
2269 dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
2271 /* Initialise group */
2272 grp->name = np->name;
2275 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2276 * do sanity check and calculate pins number
2278 list = of_get_property(np, "rockchip,pins", &size);
2279 /* we do not check return since it's safe node passed down */
2280 size /= sizeof(*list);
2281 if (!size || size % 4) {
2282 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2286 grp->npins = size / 4;
2288 grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),
2290 grp->data = devm_kzalloc(info->dev, grp->npins *
2291 sizeof(struct rockchip_pin_config),
2293 if (!grp->pins || !grp->data)
2296 for (i = 0, j = 0; i < size; i += 4, j++) {
2297 const __be32 *phandle;
2298 struct device_node *np_config;
2300 num = be32_to_cpu(*list++);
2301 bank = bank_num_to_bank(info, num);
2303 return PTR_ERR(bank);
2305 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2306 grp->data[j].func = be32_to_cpu(*list++);
2312 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
2313 ret = pinconf_generic_parse_dt_config(np_config, NULL,
2314 &grp->data[j].configs, &grp->data[j].nconfigs);
2322 static int rockchip_pinctrl_parse_functions(struct device_node *np,
2323 struct rockchip_pinctrl *info,
2326 struct device_node *child;
2327 struct rockchip_pmx_func *func;
2328 struct rockchip_pin_group *grp;
2330 static u32 grp_index;
2333 dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
2335 func = &info->functions[index];
2337 /* Initialise function */
2338 func->name = np->name;
2339 func->ngroups = of_get_child_count(np);
2340 if (func->ngroups <= 0)
2343 func->groups = devm_kzalloc(info->dev,
2344 func->ngroups * sizeof(char *), GFP_KERNEL);
2348 for_each_child_of_node(np, child) {
2349 func->groups[i] = child->name;
2350 grp = &info->groups[grp_index++];
2351 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
2361 static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2362 struct rockchip_pinctrl *info)
2364 struct device *dev = &pdev->dev;
2365 struct device_node *np = dev->of_node;
2366 struct device_node *child;
2370 rockchip_pinctrl_child_count(info, np);
2372 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2373 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2375 info->functions = devm_kzalloc(dev, info->nfunctions *
2376 sizeof(struct rockchip_pmx_func),
2378 if (!info->functions) {
2379 dev_err(dev, "failed to allocate memory for function list\n");
2383 info->groups = devm_kzalloc(dev, info->ngroups *
2384 sizeof(struct rockchip_pin_group),
2386 if (!info->groups) {
2387 dev_err(dev, "failed allocate memory for ping group list\n");
2393 for_each_child_of_node(np, child) {
2394 if (of_match_node(rockchip_bank_match, child))
2397 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2399 dev_err(&pdev->dev, "failed to parse function\n");
2408 static int rockchip_pinctrl_register(struct platform_device *pdev,
2409 struct rockchip_pinctrl *info)
2411 struct pinctrl_desc *ctrldesc = &info->pctl;
2412 struct pinctrl_pin_desc *pindesc, *pdesc;
2413 struct rockchip_pin_bank *pin_bank;
2417 ctrldesc->name = "rockchip-pinctrl";
2418 ctrldesc->owner = THIS_MODULE;
2419 ctrldesc->pctlops = &rockchip_pctrl_ops;
2420 ctrldesc->pmxops = &rockchip_pmx_ops;
2421 ctrldesc->confops = &rockchip_pinconf_ops;
2423 pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
2424 info->ctrl->nr_pins, GFP_KERNEL);
2426 dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
2429 ctrldesc->pins = pindesc;
2430 ctrldesc->npins = info->ctrl->nr_pins;
2433 for (bank = 0 , k = 0; bank < info->ctrl->nr_banks; bank++) {
2434 pin_bank = &info->ctrl->pin_banks[bank];
2435 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2437 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2438 pin_bank->name, pin);
2443 ret = rockchip_pinctrl_parse_dt(pdev, info);
2447 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
2448 if (IS_ERR(info->pctl_dev)) {
2449 dev_err(&pdev->dev, "could not register pinctrl driver\n");
2450 return PTR_ERR(info->pctl_dev);
2453 for (bank = 0; bank < info->ctrl->nr_banks; ++bank) {
2454 pin_bank = &info->ctrl->pin_banks[bank];
2455 pin_bank->grange.name = pin_bank->name;
2456 pin_bank->grange.id = bank;
2457 pin_bank->grange.pin_base = pin_bank->pin_base;
2458 pin_bank->grange.base = pin_bank->gpio_chip.base;
2459 pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
2460 pin_bank->grange.gc = &pin_bank->gpio_chip;
2461 pinctrl_add_gpio_range(info->pctl_dev, &pin_bank->grange);
2471 static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
2473 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
2474 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR;
2475 unsigned long flags;
2478 clk_enable(bank->clk);
2479 raw_spin_lock_irqsave(&bank->slock, flags);
2482 data &= ~BIT(offset);
2484 data |= BIT(offset);
2487 raw_spin_unlock_irqrestore(&bank->slock, flags);
2488 clk_disable(bank->clk);
2492 * Returns the level of the pin for input direction and setting of the DR
2493 * register for output gpios.
2495 static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset)
2497 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
2500 clk_enable(bank->clk);
2501 data = readl(bank->reg_base + GPIO_EXT_PORT);
2502 clk_disable(bank->clk);
2509 * gpiolib gpio_direction_input callback function. The setting of the pin
2510 * mux function as 'gpio input' will be handled by the pinctrl susbsystem
2513 static int rockchip_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
2515 return pinctrl_gpio_direction_input(gc->base + offset);
2519 * gpiolib gpio_direction_output callback function. The setting of the pin
2520 * mux function as 'gpio output' will be handled by the pinctrl susbsystem
2523 static int rockchip_gpio_direction_output(struct gpio_chip *gc,
2524 unsigned offset, int value)
2526 rockchip_gpio_set(gc, offset, value);
2527 return pinctrl_gpio_direction_output(gc->base + offset);
2531 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
2532 * and a virtual IRQ, if not already present.
2534 static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
2536 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
2542 virq = irq_create_mapping(bank->domain, offset);
2544 return (virq) ? : -ENXIO;
2547 static const struct gpio_chip rockchip_gpiolib_chip = {
2548 .request = gpiochip_generic_request,
2549 .free = gpiochip_generic_free,
2550 .set = rockchip_gpio_set,
2551 .get = rockchip_gpio_get,
2552 .get_direction = rockchip_gpio_get_direction,
2553 .direction_input = rockchip_gpio_direction_input,
2554 .direction_output = rockchip_gpio_direction_output,
2555 .to_irq = rockchip_gpio_to_irq,
2556 .owner = THIS_MODULE,
2560 * Interrupt handling
2563 static void rockchip_irq_demux(struct irq_desc *desc)
2565 struct irq_chip *chip = irq_desc_get_chip(desc);
2566 struct rockchip_pin_bank *bank = irq_desc_get_handler_data(desc);
2569 dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
2571 chained_irq_enter(chip, desc);
2573 pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
2576 unsigned int irq, virq;
2580 virq = irq_linear_revmap(bank->domain, irq);
2583 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
2587 dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
2590 * Triggering IRQ on both rising and falling edge
2591 * needs manual intervention.
2593 if (bank->toggle_edge_mode & BIT(irq)) {
2594 u32 data, data_old, polarity;
2595 unsigned long flags;
2597 data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
2599 raw_spin_lock_irqsave(&bank->slock, flags);
2601 polarity = readl_relaxed(bank->reg_base +
2603 if (data & BIT(irq))
2604 polarity &= ~BIT(irq);
2606 polarity |= BIT(irq);
2608 bank->reg_base + GPIO_INT_POLARITY);
2610 raw_spin_unlock_irqrestore(&bank->slock, flags);
2613 data = readl_relaxed(bank->reg_base +
2615 } while ((data & BIT(irq)) != (data_old & BIT(irq)));
2618 generic_handle_irq(virq);
2621 chained_irq_exit(chip, desc);
2624 static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
2626 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2627 struct rockchip_pin_bank *bank = gc->private;
2628 u32 mask = BIT(d->hwirq);
2632 unsigned long flags;
2635 /* make sure the pin is configured as gpio input */
2636 ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
2640 clk_enable(bank->clk);
2641 raw_spin_lock_irqsave(&bank->slock, flags);
2643 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2645 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2647 raw_spin_unlock_irqrestore(&bank->slock, flags);
2649 if (type & IRQ_TYPE_EDGE_BOTH)
2650 irq_set_handler_locked(d, handle_edge_irq);
2652 irq_set_handler_locked(d, handle_level_irq);
2654 raw_spin_lock_irqsave(&bank->slock, flags);
2657 level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL);
2658 polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
2661 case IRQ_TYPE_EDGE_BOTH:
2662 bank->toggle_edge_mode |= mask;
2666 * Determine gpio state. If 1 next interrupt should be falling
2669 data = readl(bank->reg_base + GPIO_EXT_PORT);
2675 case IRQ_TYPE_EDGE_RISING:
2676 bank->toggle_edge_mode &= ~mask;
2680 case IRQ_TYPE_EDGE_FALLING:
2681 bank->toggle_edge_mode &= ~mask;
2685 case IRQ_TYPE_LEVEL_HIGH:
2686 bank->toggle_edge_mode &= ~mask;
2690 case IRQ_TYPE_LEVEL_LOW:
2691 bank->toggle_edge_mode &= ~mask;
2697 raw_spin_unlock_irqrestore(&bank->slock, flags);
2698 clk_disable(bank->clk);
2702 writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL);
2703 writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY);
2706 raw_spin_unlock_irqrestore(&bank->slock, flags);
2707 clk_disable(bank->clk);
2712 static void rockchip_irq_suspend(struct irq_data *d)
2714 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2715 struct rockchip_pin_bank *bank = gc->private;
2717 clk_enable(bank->clk);
2718 bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK);
2719 irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK);
2720 clk_disable(bank->clk);
2723 static void rockchip_irq_resume(struct irq_data *d)
2725 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2726 struct rockchip_pin_bank *bank = gc->private;
2728 clk_enable(bank->clk);
2729 irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK);
2730 clk_disable(bank->clk);
2733 static void rockchip_irq_enable(struct irq_data *d)
2735 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2736 struct rockchip_pin_bank *bank = gc->private;
2738 clk_enable(bank->clk);
2739 irq_gc_mask_clr_bit(d);
2742 static void rockchip_irq_disable(struct irq_data *d)
2744 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2745 struct rockchip_pin_bank *bank = gc->private;
2747 irq_gc_mask_set_bit(d);
2748 clk_disable(bank->clk);
2751 static int rockchip_interrupts_register(struct platform_device *pdev,
2752 struct rockchip_pinctrl *info)
2754 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2755 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2756 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
2757 struct irq_chip_generic *gc;
2761 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2763 dev_warn(&pdev->dev, "bank %s is not valid\n",
2768 ret = clk_enable(bank->clk);
2770 dev_err(&pdev->dev, "failed to enable clock for bank %s\n",
2775 bank->domain = irq_domain_add_linear(bank->of_node, 32,
2776 &irq_generic_chip_ops, NULL);
2777 if (!bank->domain) {
2778 dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n",
2780 clk_disable(bank->clk);
2784 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
2785 "rockchip_gpio_irq", handle_level_irq,
2786 clr, 0, IRQ_GC_INIT_MASK_CACHE);
2788 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
2790 irq_domain_remove(bank->domain);
2791 clk_disable(bank->clk);
2796 * Linux assumes that all interrupts start out disabled/masked.
2797 * Our driver only uses the concept of masked and always keeps
2798 * things enabled, so for us that's all masked and all enabled.
2800 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
2801 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
2803 gc = irq_get_domain_generic_chip(bank->domain, 0);
2804 gc->reg_base = bank->reg_base;
2806 gc->chip_types[0].regs.mask = GPIO_INTMASK;
2807 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
2808 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
2809 gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
2810 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit;
2811 gc->chip_types[0].chip.irq_enable = rockchip_irq_enable;
2812 gc->chip_types[0].chip.irq_disable = rockchip_irq_disable;
2813 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
2814 gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend;
2815 gc->chip_types[0].chip.irq_resume = rockchip_irq_resume;
2816 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
2817 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
2819 irq_set_chained_handler_and_data(bank->irq,
2820 rockchip_irq_demux, bank);
2822 /* map the gpio irqs here, when the clock is still running */
2823 for (j = 0 ; j < 32 ; j++)
2824 irq_create_mapping(bank->domain, j);
2826 clk_disable(bank->clk);
2832 static int rockchip_gpiolib_register(struct platform_device *pdev,
2833 struct rockchip_pinctrl *info)
2835 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2836 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2837 struct gpio_chip *gc;
2841 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2843 dev_warn(&pdev->dev, "bank %s is not valid\n",
2848 bank->gpio_chip = rockchip_gpiolib_chip;
2850 gc = &bank->gpio_chip;
2851 gc->base = bank->pin_base;
2852 gc->ngpio = bank->nr_pins;
2853 gc->parent = &pdev->dev;
2854 gc->of_node = bank->of_node;
2855 gc->label = bank->name;
2857 ret = gpiochip_add_data(gc, bank);
2859 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
2865 rockchip_interrupts_register(pdev, info);
2870 for (--i, --bank; i >= 0; --i, --bank) {
2873 gpiochip_remove(&bank->gpio_chip);
2878 static int rockchip_gpiolib_unregister(struct platform_device *pdev,
2879 struct rockchip_pinctrl *info)
2881 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2882 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2885 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2888 gpiochip_remove(&bank->gpio_chip);
2894 static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
2895 struct rockchip_pinctrl *info)
2897 struct resource res;
2900 if (of_address_to_resource(bank->of_node, 0, &res)) {
2901 dev_err(info->dev, "cannot find IO resource for bank\n");
2905 bank->reg_base = devm_ioremap_resource(info->dev, &res);
2906 if (IS_ERR(bank->reg_base))
2907 return PTR_ERR(bank->reg_base);
2910 * special case, where parts of the pull setting-registers are
2911 * part of the PMU register space
2913 if (of_device_is_compatible(bank->of_node,
2914 "rockchip,rk3188-gpio-bank0")) {
2915 struct device_node *node;
2917 node = of_parse_phandle(bank->of_node->parent,
2920 if (of_address_to_resource(bank->of_node, 1, &res)) {
2921 dev_err(info->dev, "cannot find IO resource for bank\n");
2925 base = devm_ioremap_resource(info->dev, &res);
2927 return PTR_ERR(base);
2928 rockchip_regmap_config.max_register =
2929 resource_size(&res) - 4;
2930 rockchip_regmap_config.name =
2931 "rockchip,rk3188-gpio-bank0-pull";
2932 bank->regmap_pull = devm_regmap_init_mmio(info->dev,
2934 &rockchip_regmap_config);
2938 bank->irq = irq_of_parse_and_map(bank->of_node, 0);
2940 bank->clk = of_clk_get(bank->of_node, 0);
2941 if (IS_ERR(bank->clk))
2942 return PTR_ERR(bank->clk);
2944 return clk_prepare(bank->clk);
2947 static const struct of_device_id rockchip_pinctrl_dt_match[];
2949 /* retrieve the soc specific data */
2950 static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2951 struct rockchip_pinctrl *d,
2952 struct platform_device *pdev)
2954 const struct of_device_id *match;
2955 struct device_node *node = pdev->dev.of_node;
2956 struct device_node *np;
2957 struct rockchip_pin_ctrl *ctrl;
2958 struct rockchip_pin_bank *bank;
2959 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
2961 match = of_match_node(rockchip_pinctrl_dt_match, node);
2962 ctrl = (struct rockchip_pin_ctrl *)match->data;
2964 for_each_child_of_node(node, np) {
2965 if (!of_find_property(np, "gpio-controller", NULL))
2968 bank = ctrl->pin_banks;
2969 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2970 if (!strcmp(bank->name, np->name)) {
2973 if (!rockchip_get_bank_data(bank, d))
2981 grf_offs = ctrl->grf_mux_offset;
2982 pmu_offs = ctrl->pmu_mux_offset;
2983 drv_pmu_offs = ctrl->pmu_drv_offset;
2984 drv_grf_offs = ctrl->grf_drv_offset;
2985 bank = ctrl->pin_banks;
2986 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2989 raw_spin_lock_init(&bank->slock);
2991 bank->pin_base = ctrl->nr_pins;
2992 ctrl->nr_pins += bank->nr_pins;
2994 /* calculate iomux and drv offsets */
2995 for (j = 0; j < 4; j++) {
2996 struct rockchip_iomux *iom = &bank->iomux[j];
2997 struct rockchip_drv *drv = &bank->drv[j];
3000 if (bank_pins >= bank->nr_pins)
3003 /* preset iomux offset value, set new start value */
3004 if (iom->offset >= 0) {
3005 if (iom->type & IOMUX_SOURCE_PMU)
3006 pmu_offs = iom->offset;
3008 grf_offs = iom->offset;
3009 } else { /* set current iomux offset */
3010 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3011 pmu_offs : grf_offs;
3014 /* preset drv offset value, set new start value */
3015 if (drv->offset >= 0) {
3016 if (iom->type & IOMUX_SOURCE_PMU)
3017 drv_pmu_offs = drv->offset;
3019 drv_grf_offs = drv->offset;
3020 } else { /* set current drv offset */
3021 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3022 drv_pmu_offs : drv_grf_offs;
3025 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3026 i, j, iom->offset, drv->offset);
3029 * Increase offset according to iomux width.
3030 * 4bit iomux'es are spread over two registers.
3032 inc = (iom->type & (IOMUX_WIDTH_4BIT |
3033 IOMUX_WIDTH_3BIT)) ? 8 : 4;
3034 if (iom->type & IOMUX_SOURCE_PMU)
3040 * Increase offset according to drv width.
3041 * 3bit drive-strenth'es are spread over two registers.
3043 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
3044 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
3049 if (iom->type & IOMUX_SOURCE_PMU)
3050 drv_pmu_offs += inc;
3052 drv_grf_offs += inc;
3057 /* calculate the per-bank recalced_mask */
3058 for (j = 0; j < ctrl->niomux_recalced; j++) {
3061 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
3062 pin = ctrl->iomux_recalced[j].pin;
3063 bank->recalced_mask |= BIT(pin);
3067 /* calculate the per-bank route_mask */
3068 for (j = 0; j < ctrl->niomux_routes; j++) {
3071 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
3072 pin = ctrl->iomux_routes[j].pin;
3073 bank->route_mask |= BIT(pin);
3081 #define RK3288_GRF_GPIO6C_IOMUX 0x64
3082 #define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3084 static u32 rk3288_grf_gpio6c_iomux;
3086 static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
3088 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
3089 int ret = pinctrl_force_sleep(info->pctl_dev);
3095 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3096 * the setting here, and restore it at resume.
3098 if (info->ctrl->type == RK3288) {
3099 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3100 &rk3288_grf_gpio6c_iomux);
3102 pinctrl_force_default(info->pctl_dev);
3110 static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
3112 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
3113 int ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3114 rk3288_grf_gpio6c_iomux |
3115 GPIO6C6_SEL_WRITE_ENABLE);
3120 return pinctrl_force_default(info->pctl_dev);
3123 static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
3124 rockchip_pinctrl_resume);
3126 static int rockchip_pinctrl_probe(struct platform_device *pdev)
3128 struct rockchip_pinctrl *info;
3129 struct device *dev = &pdev->dev;
3130 struct rockchip_pin_ctrl *ctrl;
3131 struct device_node *np = pdev->dev.of_node, *node;
3132 struct resource *res;
3136 if (!dev->of_node) {
3137 dev_err(dev, "device tree node not found\n");
3141 info = devm_kzalloc(dev, sizeof(struct rockchip_pinctrl), GFP_KERNEL);
3147 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
3149 dev_err(dev, "driver data not available\n");
3154 node = of_parse_phandle(np, "rockchip,grf", 0);
3156 info->regmap_base = syscon_node_to_regmap(node);
3157 if (IS_ERR(info->regmap_base))
3158 return PTR_ERR(info->regmap_base);
3160 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3161 base = devm_ioremap_resource(&pdev->dev, res);
3163 return PTR_ERR(base);
3165 rockchip_regmap_config.max_register = resource_size(res) - 4;
3166 rockchip_regmap_config.name = "rockchip,pinctrl";
3167 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
3168 &rockchip_regmap_config);
3170 /* to check for the old dt-bindings */
3171 info->reg_size = resource_size(res);
3173 /* Honor the old binding, with pull registers as 2nd resource */
3174 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
3175 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3176 base = devm_ioremap_resource(&pdev->dev, res);
3178 return PTR_ERR(base);
3180 rockchip_regmap_config.max_register =
3181 resource_size(res) - 4;
3182 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
3183 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
3185 &rockchip_regmap_config);
3189 /* try to find the optional reference to the pmu syscon */
3190 node = of_parse_phandle(np, "rockchip,pmu", 0);
3192 info->regmap_pmu = syscon_node_to_regmap(node);
3193 if (IS_ERR(info->regmap_pmu))
3194 return PTR_ERR(info->regmap_pmu);
3197 ret = rockchip_gpiolib_register(pdev, info);
3201 ret = rockchip_pinctrl_register(pdev, info);
3203 rockchip_gpiolib_unregister(pdev, info);
3207 platform_set_drvdata(pdev, info);
3212 static struct rockchip_pin_bank rv1108_pin_banks[] = {
3213 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3217 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3218 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3219 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3222 static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
3223 .pin_banks = rv1108_pin_banks,
3224 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
3225 .label = "RV1108-GPIO",
3227 .grf_mux_offset = 0x10,
3228 .pmu_mux_offset = 0x0,
3229 .iomux_recalced = rv1108_mux_recalced_data,
3230 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
3231 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
3232 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
3233 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
3236 static struct rockchip_pin_bank rk2928_pin_banks[] = {
3237 PIN_BANK(0, 32, "gpio0"),
3238 PIN_BANK(1, 32, "gpio1"),
3239 PIN_BANK(2, 32, "gpio2"),
3240 PIN_BANK(3, 32, "gpio3"),
3243 static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
3244 .pin_banks = rk2928_pin_banks,
3245 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
3246 .label = "RK2928-GPIO",
3248 .grf_mux_offset = 0xa8,
3249 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3252 static struct rockchip_pin_bank rk3036_pin_banks[] = {
3253 PIN_BANK(0, 32, "gpio0"),
3254 PIN_BANK(1, 32, "gpio1"),
3255 PIN_BANK(2, 32, "gpio2"),
3258 static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
3259 .pin_banks = rk3036_pin_banks,
3260 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
3261 .label = "RK3036-GPIO",
3263 .grf_mux_offset = 0xa8,
3264 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3267 static struct rockchip_pin_bank rk3066a_pin_banks[] = {
3268 PIN_BANK(0, 32, "gpio0"),
3269 PIN_BANK(1, 32, "gpio1"),
3270 PIN_BANK(2, 32, "gpio2"),
3271 PIN_BANK(3, 32, "gpio3"),
3272 PIN_BANK(4, 32, "gpio4"),
3273 PIN_BANK(6, 16, "gpio6"),
3276 static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
3277 .pin_banks = rk3066a_pin_banks,
3278 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
3279 .label = "RK3066a-GPIO",
3281 .grf_mux_offset = 0xa8,
3282 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3285 static struct rockchip_pin_bank rk3066b_pin_banks[] = {
3286 PIN_BANK(0, 32, "gpio0"),
3287 PIN_BANK(1, 32, "gpio1"),
3288 PIN_BANK(2, 32, "gpio2"),
3289 PIN_BANK(3, 32, "gpio3"),
3292 static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
3293 .pin_banks = rk3066b_pin_banks,
3294 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
3295 .label = "RK3066b-GPIO",
3297 .grf_mux_offset = 0x60,
3300 static struct rockchip_pin_bank rk3128_pin_banks[] = {
3301 PIN_BANK(0, 32, "gpio0"),
3302 PIN_BANK(1, 32, "gpio1"),
3303 PIN_BANK(2, 32, "gpio2"),
3304 PIN_BANK(3, 32, "gpio3"),
3307 static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
3308 .pin_banks = rk3128_pin_banks,
3309 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
3310 .label = "RK3128-GPIO",
3312 .grf_mux_offset = 0xa8,
3313 .iomux_recalced = rk3128_mux_recalced_data,
3314 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
3315 .iomux_routes = rk3128_mux_route_data,
3316 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
3317 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
3320 static struct rockchip_pin_bank rk3188_pin_banks[] = {
3321 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
3322 PIN_BANK(1, 32, "gpio1"),
3323 PIN_BANK(2, 32, "gpio2"),
3324 PIN_BANK(3, 32, "gpio3"),
3327 static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
3328 .pin_banks = rk3188_pin_banks,
3329 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
3330 .label = "RK3188-GPIO",
3332 .grf_mux_offset = 0x60,
3333 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
3336 static struct rockchip_pin_bank rk3228_pin_banks[] = {
3337 PIN_BANK(0, 32, "gpio0"),
3338 PIN_BANK(1, 32, "gpio1"),
3339 PIN_BANK(2, 32, "gpio2"),
3340 PIN_BANK(3, 32, "gpio3"),
3343 static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
3344 .pin_banks = rk3228_pin_banks,
3345 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
3346 .label = "RK3228-GPIO",
3348 .grf_mux_offset = 0x0,
3349 .iomux_routes = rk3228_mux_route_data,
3350 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
3351 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3352 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3355 static struct rockchip_pin_bank rk3288_pin_banks[] = {
3356 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
3361 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
3366 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3367 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3368 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3373 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3378 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3379 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3384 PIN_BANK(8, 16, "gpio8"),
3387 static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3388 .pin_banks = rk3288_pin_banks,
3389 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3390 .label = "RK3288-GPIO",
3392 .grf_mux_offset = 0x0,
3393 .pmu_mux_offset = 0x84,
3394 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
3395 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
3398 static struct rockchip_pin_bank rk3328_pin_banks[] = {
3399 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3400 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3401 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3405 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3412 static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3413 .pin_banks = rk3328_pin_banks,
3414 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3415 .label = "RK3328-GPIO",
3417 .grf_mux_offset = 0x0,
3418 .iomux_recalced = rk3328_mux_recalced_data,
3419 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
3420 .iomux_routes = rk3328_mux_route_data,
3421 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
3422 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3423 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3424 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
3427 static struct rockchip_pin_bank rk3368_pin_banks[] = {
3428 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3433 PIN_BANK(1, 32, "gpio1"),
3434 PIN_BANK(2, 32, "gpio2"),
3435 PIN_BANK(3, 32, "gpio3"),
3438 static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3439 .pin_banks = rk3368_pin_banks,
3440 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3441 .label = "RK3368-GPIO",
3443 .grf_mux_offset = 0x0,
3444 .pmu_mux_offset = 0x0,
3445 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3446 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3449 static struct rockchip_pin_bank rk3399_pin_banks[] = {
3450 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3455 DRV_TYPE_IO_1V8_ONLY,
3456 DRV_TYPE_IO_1V8_ONLY,
3457 DRV_TYPE_IO_DEFAULT,
3458 DRV_TYPE_IO_DEFAULT,
3463 PULL_TYPE_IO_1V8_ONLY,
3464 PULL_TYPE_IO_1V8_ONLY,
3465 PULL_TYPE_IO_DEFAULT,
3466 PULL_TYPE_IO_DEFAULT
3468 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3472 DRV_TYPE_IO_1V8_OR_3V0,
3473 DRV_TYPE_IO_1V8_OR_3V0,
3474 DRV_TYPE_IO_1V8_OR_3V0,
3475 DRV_TYPE_IO_1V8_OR_3V0,
3481 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3482 DRV_TYPE_IO_1V8_OR_3V0,
3483 DRV_TYPE_IO_1V8_ONLY,
3484 DRV_TYPE_IO_1V8_ONLY,
3485 PULL_TYPE_IO_DEFAULT,
3486 PULL_TYPE_IO_DEFAULT,
3487 PULL_TYPE_IO_1V8_ONLY,
3488 PULL_TYPE_IO_1V8_ONLY
3490 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3491 DRV_TYPE_IO_3V3_ONLY,
3492 DRV_TYPE_IO_3V3_ONLY,
3493 DRV_TYPE_IO_1V8_OR_3V0
3495 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3496 DRV_TYPE_IO_1V8_3V0_AUTO,
3497 DRV_TYPE_IO_1V8_OR_3V0,
3498 DRV_TYPE_IO_1V8_OR_3V0
3502 static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3503 .pin_banks = rk3399_pin_banks,
3504 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3505 .label = "RK3399-GPIO",
3507 .grf_mux_offset = 0xe000,
3508 .pmu_mux_offset = 0x0,
3509 .grf_drv_offset = 0xe100,
3510 .pmu_drv_offset = 0x80,
3511 .iomux_routes = rk3399_mux_route_data,
3512 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
3513 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3514 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3517 static const struct of_device_id rockchip_pinctrl_dt_match[] = {
3518 { .compatible = "rockchip,rv1108-pinctrl",
3519 .data = &rv1108_pin_ctrl },
3520 { .compatible = "rockchip,rk2928-pinctrl",
3521 .data = &rk2928_pin_ctrl },
3522 { .compatible = "rockchip,rk3036-pinctrl",
3523 .data = &rk3036_pin_ctrl },
3524 { .compatible = "rockchip,rk3066a-pinctrl",
3525 .data = &rk3066a_pin_ctrl },
3526 { .compatible = "rockchip,rk3066b-pinctrl",
3527 .data = &rk3066b_pin_ctrl },
3528 { .compatible = "rockchip,rk3128-pinctrl",
3529 .data = (void *)&rk3128_pin_ctrl },
3530 { .compatible = "rockchip,rk3188-pinctrl",
3531 .data = &rk3188_pin_ctrl },
3532 { .compatible = "rockchip,rk3228-pinctrl",
3533 .data = &rk3228_pin_ctrl },
3534 { .compatible = "rockchip,rk3288-pinctrl",
3535 .data = &rk3288_pin_ctrl },
3536 { .compatible = "rockchip,rk3328-pinctrl",
3537 .data = &rk3328_pin_ctrl },
3538 { .compatible = "rockchip,rk3368-pinctrl",
3539 .data = &rk3368_pin_ctrl },
3540 { .compatible = "rockchip,rk3399-pinctrl",
3541 .data = &rk3399_pin_ctrl },
3545 static struct platform_driver rockchip_pinctrl_driver = {
3546 .probe = rockchip_pinctrl_probe,
3548 .name = "rockchip-pinctrl",
3549 .pm = &rockchip_pinctrl_dev_pm_ops,
3550 .of_match_table = rockchip_pinctrl_dt_match,
3554 static int __init rockchip_pinctrl_drv_register(void)
3556 return platform_driver_register(&rockchip_pinctrl_driver);
3558 postcore_initcall(rockchip_pinctrl_drv_register);