blob: 246bf14c7f727cf93e002ed0f1be91858fb36cd1 [file] [log] [blame]
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001/*
2 * Pinctrl driver for Rockchip SoCs
3 *
4 * Copyright (c) 2013 MundoReader S.L.
5 * Author: Heiko Stuebner <heiko@sntech.de>
6 *
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
12 *
13 * and pinctrl-at91:
14 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
15 *
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.
19 *
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.
24 */
25
Paul Gortmaker2f436202016-08-23 17:19:42 -040026#include <linux/init.h>
Heiko Stübnerd3e51162013-06-10 22:16:22 +020027#include <linux/platform_device.h>
28#include <linux/io.h>
29#include <linux/bitops.h>
Linus Walleij1c5fb662018-09-13 13:58:21 +020030#include <linux/gpio/driver.h>
Heiko Stübnerd3e51162013-06-10 22:16:22 +020031#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>
Heiko Stübner7e865ab2013-07-23 13:34:20 +020039#include <linux/clk.h>
Heiko Stübner751a99a2014-05-05 13:58:20 +020040#include <linux/regmap.h>
Heiko Stübner14dee862014-05-05 13:59:09 +020041#include <linux/mfd/syscon.h>
Heiko Stübnerd3e51162013-06-10 22:16:22 +020042#include <dt-bindings/pinctrl/rockchip.h>
43
44#include "core.h"
45#include "pinconf.h"
46
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
60
Heiko Stübnera2829262013-10-16 01:07:20 +020061enum rockchip_pinctrl_type {
David Wu87065ca2018-05-14 19:59:51 +080062 PX30,
Andy Yanb9c6dca2017-03-17 18:18:36 +010063 RV1108,
Heiko Stübnera2829262013-10-16 01:07:20 +020064 RK2928,
65 RK3066B,
David Wud23c66d2017-07-21 14:27:15 +080066 RK3128,
Heiko Stübnera2829262013-10-16 01:07:20 +020067 RK3188,
Heiko Stübner66d750e2014-07-20 01:49:17 +020068 RK3288,
Heiko Stübnerdaecdc62015-06-12 23:51:01 +020069 RK3368,
David Wub6c23272016-02-01 10:58:21 +080070 RK3399,
Heiko Stübnera2829262013-10-16 01:07:20 +020071};
72
Heiko Stübnerfc72c922014-06-16 01:36:05 +020073/**
74 * Encode variants of iomux registers into a type variable
75 */
76#define IOMUX_GPIO_ONLY BIT(0)
Heiko Stübner03716e12014-06-16 01:36:57 +020077#define IOMUX_WIDTH_4BIT BIT(1)
Heiko Stübner95ec8ae2014-06-16 01:37:23 +020078#define IOMUX_SOURCE_PMU BIT(2)
Heiko Stübner62f49222014-06-16 01:37:49 +020079#define IOMUX_UNROUTED BIT(3)
david.wu8b6c6f92017-02-10 18:23:47 +080080#define IOMUX_WIDTH_3BIT BIT(4)
Heiko Stübnerfc72c922014-06-16 01:36:05 +020081
82/**
83 * @type: iomux variant using IOMUX_* constants
Heiko Stübner6bc0d122014-06-16 01:36:33 +020084 * @offset: if initialized to -1 it will be autocalculated, by specifying
85 * an initial offset value the relevant source offset can be reset
86 * to a new value for autocalculating the following iomux registers.
Heiko Stübnerfc72c922014-06-16 01:36:05 +020087 */
88struct rockchip_iomux {
89 int type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +020090 int offset;
Heiko Stübner65fca612013-10-16 01:07:49 +020091};
92
Heiko Stübnerd3e51162013-06-10 22:16:22 +020093/**
David Wub6c23272016-02-01 10:58:21 +080094 * enum type index corresponding to rockchip_perpin_drv_list arrays index.
95 */
96enum rockchip_pin_drv_type {
97 DRV_TYPE_IO_DEFAULT = 0,
98 DRV_TYPE_IO_1V8_OR_3V0,
99 DRV_TYPE_IO_1V8_ONLY,
100 DRV_TYPE_IO_1V8_3V0_AUTO,
101 DRV_TYPE_IO_3V3_ONLY,
102 DRV_TYPE_MAX
103};
104
105/**
David Wu3ba67672016-05-11 11:39:28 +0800106 * enum type index corresponding to rockchip_pull_list arrays index.
107 */
108enum rockchip_pin_pull_type {
109 PULL_TYPE_IO_DEFAULT = 0,
110 PULL_TYPE_IO_1V8_ONLY,
111 PULL_TYPE_MAX
112};
113
114/**
David Wub6c23272016-02-01 10:58:21 +0800115 * @drv_type: drive strength variant using rockchip_perpin_drv_type
116 * @offset: if initialized to -1 it will be autocalculated, by specifying
117 * an initial offset value the relevant source offset can be reset
118 * to a new value for autocalculating the following drive strength
119 * registers. if used chips own cal_drv func instead to calculate
120 * registers offset, the variant could be ignored.
121 */
122struct rockchip_drv {
123 enum rockchip_pin_drv_type drv_type;
124 int offset;
125};
126
127/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200128 * @reg_base: register base of the gpio bank
Heiko Stübner6ca52742013-10-16 01:08:42 +0200129 * @reg_pull: optional separate register for additional pull settings
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200130 * @clk: clock of the gpio bank
131 * @irq: interrupt of the gpio bank
Doug Anderson5ae0c7a2015-01-26 08:24:03 -0800132 * @saved_masks: Saved content of GPIO_INTEN at suspend time.
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200133 * @pin_base: first pin number
134 * @nr_pins: number of pins in this bank
135 * @name: name of the bank
136 * @bank_num: number of the bank, to account for holes
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200137 * @iomux: array describing the 4 iomux sources of the bank
David Wub6c23272016-02-01 10:58:21 +0800138 * @drv: array describing the 4 drive strength sources of the bank
David Wu3ba67672016-05-11 11:39:28 +0800139 * @pull_type: array describing the 4 pull type sources of the bank
Markus Elfring85dc3972017-12-23 22:22:54 +0100140 * @valid: is all necessary information present
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200141 * @of_node: dt node of this bank
142 * @drvdata: common pinctrl basedata
143 * @domain: irqdomain of the gpio bank
144 * @gpio_chip: gpiolib chip
145 * @grange: gpio range
146 * @slock: spinlock for the gpio bank
David Wubd35b9b2017-05-26 15:20:20 +0800147 * @route_mask: bits describing the routing pins of per bank
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200148 */
149struct rockchip_pin_bank {
150 void __iomem *reg_base;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200151 struct regmap *regmap_pull;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200152 struct clk *clk;
153 int irq;
Doug Anderson5ae0c7a2015-01-26 08:24:03 -0800154 u32 saved_masks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200155 u32 pin_base;
156 u8 nr_pins;
157 char *name;
158 u8 bank_num;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200159 struct rockchip_iomux iomux[4];
David Wub6c23272016-02-01 10:58:21 +0800160 struct rockchip_drv drv[4];
David Wu3ba67672016-05-11 11:39:28 +0800161 enum rockchip_pin_pull_type pull_type[4];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200162 bool valid;
163 struct device_node *of_node;
164 struct rockchip_pinctrl *drvdata;
165 struct irq_domain *domain;
166 struct gpio_chip gpio_chip;
167 struct pinctrl_gpio_range grange;
John Keeping70b7aa72017-03-23 10:59:29 +0000168 raw_spinlock_t slock;
Heiko Stübner5a927502013-10-16 01:09:08 +0200169 u32 toggle_edge_mode;
David Wuc04c3fa2017-07-21 14:27:14 +0800170 u32 recalced_mask;
David Wubd35b9b2017-05-26 15:20:20 +0800171 u32 route_mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200172};
173
174#define PIN_BANK(id, pins, label) \
175 { \
176 .bank_num = id, \
177 .nr_pins = pins, \
178 .name = label, \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200179 .iomux = { \
180 { .offset = -1 }, \
181 { .offset = -1 }, \
182 { .offset = -1 }, \
183 { .offset = -1 }, \
184 }, \
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200185 }
186
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200187#define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
188 { \
189 .bank_num = id, \
190 .nr_pins = pins, \
191 .name = label, \
192 .iomux = { \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200193 { .type = iom0, .offset = -1 }, \
194 { .type = iom1, .offset = -1 }, \
195 { .type = iom2, .offset = -1 }, \
196 { .type = iom3, .offset = -1 }, \
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200197 }, \
198 }
199
David Wub6c23272016-02-01 10:58:21 +0800200#define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
201 { \
202 .bank_num = id, \
203 .nr_pins = pins, \
204 .name = label, \
205 .iomux = { \
206 { .offset = -1 }, \
207 { .offset = -1 }, \
208 { .offset = -1 }, \
209 { .offset = -1 }, \
210 }, \
211 .drv = { \
212 { .drv_type = type0, .offset = -1 }, \
213 { .drv_type = type1, .offset = -1 }, \
214 { .drv_type = type2, .offset = -1 }, \
215 { .drv_type = type3, .offset = -1 }, \
216 }, \
217 }
218
David Wu3ba67672016-05-11 11:39:28 +0800219#define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
220 drv2, drv3, pull0, pull1, \
221 pull2, pull3) \
222 { \
223 .bank_num = id, \
224 .nr_pins = pins, \
225 .name = label, \
226 .iomux = { \
227 { .offset = -1 }, \
228 { .offset = -1 }, \
229 { .offset = -1 }, \
230 { .offset = -1 }, \
231 }, \
232 .drv = { \
233 { .drv_type = drv0, .offset = -1 }, \
234 { .drv_type = drv1, .offset = -1 }, \
235 { .drv_type = drv2, .offset = -1 }, \
236 { .drv_type = drv3, .offset = -1 }, \
237 }, \
238 .pull_type[0] = pull0, \
239 .pull_type[1] = pull1, \
240 .pull_type[2] = pull2, \
241 .pull_type[3] = pull3, \
242 }
243
David Wub6c23272016-02-01 10:58:21 +0800244#define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
245 iom2, iom3, drv0, drv1, drv2, \
246 drv3, offset0, offset1, \
247 offset2, offset3) \
248 { \
249 .bank_num = id, \
250 .nr_pins = pins, \
251 .name = label, \
252 .iomux = { \
253 { .type = iom0, .offset = -1 }, \
254 { .type = iom1, .offset = -1 }, \
255 { .type = iom2, .offset = -1 }, \
256 { .type = iom3, .offset = -1 }, \
257 }, \
258 .drv = { \
259 { .drv_type = drv0, .offset = offset0 }, \
260 { .drv_type = drv1, .offset = offset1 }, \
261 { .drv_type = drv2, .offset = offset2 }, \
262 { .drv_type = drv3, .offset = offset3 }, \
263 }, \
264 }
265
David Wu3ba67672016-05-11 11:39:28 +0800266#define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
267 label, iom0, iom1, iom2, \
268 iom3, drv0, drv1, drv2, \
269 drv3, offset0, offset1, \
270 offset2, offset3, pull0, \
271 pull1, pull2, pull3) \
272 { \
273 .bank_num = id, \
274 .nr_pins = pins, \
275 .name = label, \
276 .iomux = { \
277 { .type = iom0, .offset = -1 }, \
278 { .type = iom1, .offset = -1 }, \
279 { .type = iom2, .offset = -1 }, \
280 { .type = iom3, .offset = -1 }, \
281 }, \
282 .drv = { \
283 { .drv_type = drv0, .offset = offset0 }, \
284 { .drv_type = drv1, .offset = offset1 }, \
285 { .drv_type = drv2, .offset = offset2 }, \
286 { .drv_type = drv3, .offset = offset3 }, \
287 }, \
288 .pull_type[0] = pull0, \
289 .pull_type[1] = pull1, \
290 .pull_type[2] = pull2, \
291 .pull_type[3] = pull3, \
292 }
293
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200294/**
David Wubd35b9b2017-05-26 15:20:20 +0800295 * struct rockchip_mux_recalced_data: represent a pin iomux data.
David Wuc04c3fa2017-07-21 14:27:14 +0800296 * @num: bank number.
297 * @pin: pin number.
298 * @bit: index at register.
299 * @reg: register offset.
300 * @mask: mask bit
301 */
302struct rockchip_mux_recalced_data {
303 u8 num;
304 u8 pin;
David Wu12b8f012017-08-23 16:00:07 +0800305 u32 reg;
David Wuc04c3fa2017-07-21 14:27:14 +0800306 u8 bit;
307 u8 mask;
308};
309
Heiko Stuebner51ff47a2018-11-11 22:00:46 +0100310enum rockchip_mux_route_location {
311 ROCKCHIP_ROUTE_SAME = 0,
312 ROCKCHIP_ROUTE_PMU,
313 ROCKCHIP_ROUTE_GRF,
314};
315
David Wuc04c3fa2017-07-21 14:27:14 +0800316/**
317 * struct rockchip_mux_recalced_data: represent a pin iomux data.
David Wubd35b9b2017-05-26 15:20:20 +0800318 * @bank_num: bank number.
319 * @pin: index at register or used to calc index.
320 * @func: the min pin.
321 * @route_offset: the max pin.
322 * @route_val: the register offset.
323 */
324struct rockchip_mux_route_data {
325 u8 bank_num;
326 u8 pin;
327 u8 func;
Heiko Stuebner51ff47a2018-11-11 22:00:46 +0100328 enum rockchip_mux_route_location route_location;
David Wubd35b9b2017-05-26 15:20:20 +0800329 u32 route_offset;
330 u32 route_val;
331};
332
333/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200334 */
335struct rockchip_pin_ctrl {
336 struct rockchip_pin_bank *pin_banks;
337 u32 nr_banks;
338 u32 nr_pins;
339 char *label;
Heiko Stübnera2829262013-10-16 01:07:20 +0200340 enum rockchip_pinctrl_type type;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200341 int grf_mux_offset;
342 int pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +0800343 int grf_drv_offset;
344 int pmu_drv_offset;
David Wuc04c3fa2017-07-21 14:27:14 +0800345 struct rockchip_mux_recalced_data *iomux_recalced;
346 u32 niomux_recalced;
David Wubd35b9b2017-05-26 15:20:20 +0800347 struct rockchip_mux_route_data *iomux_routes;
348 u32 niomux_routes;
David Wub6c23272016-02-01 10:58:21 +0800349
Heiko Stübner751a99a2014-05-05 13:58:20 +0200350 void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
351 int pin_num, struct regmap **regmap,
352 int *reg, u8 *bit);
Heiko Stübneref17f692015-06-12 23:50:11 +0200353 void (*drv_calc_reg)(struct rockchip_pin_bank *bank,
354 int pin_num, struct regmap **regmap,
355 int *reg, u8 *bit);
david.wue3b357d2017-03-02 15:11:23 +0800356 int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
357 int pin_num, struct regmap **regmap,
358 int *reg, u8 *bit);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200359};
360
361struct rockchip_pin_config {
362 unsigned int func;
363 unsigned long *configs;
364 unsigned int nconfigs;
365};
366
367/**
368 * struct rockchip_pin_group: represent group of pins of a pinmux function.
369 * @name: name of the pin group, used to lookup the group.
370 * @pins: the pins included in this group.
371 * @npins: number of pins included in this group.
372 * @func: the mux function number to be programmed when selected.
373 * @configs: the config values to be set for each pin
374 * @nconfigs: number of configs for each pin
375 */
376struct rockchip_pin_group {
377 const char *name;
378 unsigned int npins;
379 unsigned int *pins;
380 struct rockchip_pin_config *data;
381};
382
383/**
384 * struct rockchip_pmx_func: represent a pin function.
385 * @name: name of the pin function, used to lookup the function.
386 * @groups: one or more names of pin groups that provide this function.
387 * @num_groups: number of groups included in @groups.
388 */
389struct rockchip_pmx_func {
390 const char *name;
391 const char **groups;
392 u8 ngroups;
393};
394
395struct rockchip_pinctrl {
Heiko Stübner751a99a2014-05-05 13:58:20 +0200396 struct regmap *regmap_base;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200397 int reg_size;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200398 struct regmap *regmap_pull;
Heiko Stübner14dee862014-05-05 13:59:09 +0200399 struct regmap *regmap_pmu;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200400 struct device *dev;
401 struct rockchip_pin_ctrl *ctrl;
402 struct pinctrl_desc pctl;
403 struct pinctrl_dev *pctl_dev;
404 struct rockchip_pin_group *groups;
405 unsigned int ngroups;
406 struct rockchip_pmx_func *functions;
407 unsigned int nfunctions;
408};
409
Heiko Stübner751a99a2014-05-05 13:58:20 +0200410static struct regmap_config rockchip_regmap_config = {
411 .reg_bits = 32,
412 .val_bits = 32,
413 .reg_stride = 4,
414};
415
Arnd Bergmann56411f32016-06-13 17:18:34 +0200416static inline const struct rockchip_pin_group *pinctrl_name_to_group(
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200417 const struct rockchip_pinctrl *info,
418 const char *name)
419{
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200420 int i;
421
422 for (i = 0; i < info->ngroups; i++) {
Axel Lin1cb95392013-08-21 10:28:50 +0800423 if (!strcmp(info->groups[i].name, name))
424 return &info->groups[i];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200425 }
426
Axel Lin1cb95392013-08-21 10:28:50 +0800427 return NULL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200428}
429
430/*
431 * given a pin number that is local to a pin controller, find out the pin bank
432 * and the register base of the pin bank.
433 */
434static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
435 unsigned pin)
436{
437 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
438
Axel Lin51578b92013-08-23 15:49:00 +0800439 while (pin >= (b->pin_base + b->nr_pins))
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200440 b++;
441
442 return b;
443}
444
445static struct rockchip_pin_bank *bank_num_to_bank(
446 struct rockchip_pinctrl *info,
447 unsigned num)
448{
449 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
450 int i;
451
Axel Lin1cb95392013-08-21 10:28:50 +0800452 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200453 if (b->bank_num == num)
Axel Lin1cb95392013-08-21 10:28:50 +0800454 return b;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200455 }
456
Axel Lin1cb95392013-08-21 10:28:50 +0800457 return ERR_PTR(-EINVAL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200458}
459
460/*
461 * Pinctrl_ops handling
462 */
463
464static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
465{
466 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
467
468 return info->ngroups;
469}
470
471static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
472 unsigned selector)
473{
474 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
475
476 return info->groups[selector].name;
477}
478
479static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
480 unsigned selector, const unsigned **pins,
481 unsigned *npins)
482{
483 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
484
485 if (selector >= info->ngroups)
486 return -EINVAL;
487
488 *pins = info->groups[selector].pins;
489 *npins = info->groups[selector].npins;
490
491 return 0;
492}
493
494static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
495 struct device_node *np,
496 struct pinctrl_map **map, unsigned *num_maps)
497{
498 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
499 const struct rockchip_pin_group *grp;
500 struct pinctrl_map *new_map;
501 struct device_node *parent;
502 int map_num = 1;
503 int i;
504
505 /*
506 * first find the group of this node and check if we need to create
507 * config maps for pins
508 */
509 grp = pinctrl_name_to_group(info, np->name);
510 if (!grp) {
Rob Herring94f4e542018-08-27 20:52:41 -0500511 dev_err(info->dev, "unable to find group for node %pOFn\n",
512 np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200513 return -EINVAL;
514 }
515
516 map_num += grp->npins;
Kees Cooka86854d2018-06-12 14:07:58 -0700517 new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200518 GFP_KERNEL);
519 if (!new_map)
520 return -ENOMEM;
521
522 *map = new_map;
523 *num_maps = map_num;
524
525 /* create mux map */
526 parent = of_get_parent(np);
527 if (!parent) {
528 devm_kfree(pctldev->dev, new_map);
529 return -EINVAL;
530 }
531 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
532 new_map[0].data.mux.function = parent->name;
533 new_map[0].data.mux.group = np->name;
534 of_node_put(parent);
535
536 /* create config map */
537 new_map++;
538 for (i = 0; i < grp->npins; i++) {
539 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
540 new_map[i].data.configs.group_or_pin =
541 pin_get_name(pctldev, grp->pins[i]);
542 new_map[i].data.configs.configs = grp->data[i].configs;
543 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
544 }
545
546 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
547 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
548
549 return 0;
550}
551
552static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
553 struct pinctrl_map *map, unsigned num_maps)
554{
555}
556
557static const struct pinctrl_ops rockchip_pctrl_ops = {
558 .get_groups_count = rockchip_get_groups_count,
559 .get_group_name = rockchip_get_group_name,
560 .get_group_pins = rockchip_get_group_pins,
561 .dt_node_to_map = rockchip_dt_node_to_map,
562 .dt_free_map = rockchip_dt_free_map,
563};
564
565/*
566 * Hardware access
567 */
568
David Wu12b8f012017-08-23 16:00:07 +0800569static struct rockchip_mux_recalced_data rv1108_mux_recalced_data[] = {
570 {
571 .num = 1,
572 .pin = 0,
573 .reg = 0x418,
574 .bit = 0,
575 .mask = 0x3
576 }, {
577 .num = 1,
578 .pin = 1,
579 .reg = 0x418,
580 .bit = 2,
581 .mask = 0x3
582 }, {
583 .num = 1,
584 .pin = 2,
585 .reg = 0x418,
586 .bit = 4,
587 .mask = 0x3
588 }, {
589 .num = 1,
590 .pin = 3,
591 .reg = 0x418,
592 .bit = 6,
593 .mask = 0x3
594 }, {
595 .num = 1,
596 .pin = 4,
597 .reg = 0x418,
598 .bit = 8,
599 .mask = 0x3
600 }, {
601 .num = 1,
602 .pin = 5,
603 .reg = 0x418,
604 .bit = 10,
605 .mask = 0x3
606 }, {
607 .num = 1,
608 .pin = 6,
609 .reg = 0x418,
610 .bit = 12,
611 .mask = 0x3
612 }, {
613 .num = 1,
614 .pin = 7,
615 .reg = 0x418,
616 .bit = 14,
617 .mask = 0x3
618 }, {
619 .num = 1,
620 .pin = 8,
621 .reg = 0x41c,
622 .bit = 0,
623 .mask = 0x3
624 }, {
625 .num = 1,
626 .pin = 9,
627 .reg = 0x41c,
628 .bit = 2,
629 .mask = 0x3
630 },
631};
632
David Wud23c66d2017-07-21 14:27:15 +0800633static struct rockchip_mux_recalced_data rk3128_mux_recalced_data[] = {
634 {
635 .num = 2,
636 .pin = 20,
637 .reg = 0xe8,
638 .bit = 0,
639 .mask = 0x7
640 }, {
641 .num = 2,
642 .pin = 21,
643 .reg = 0xe8,
644 .bit = 4,
645 .mask = 0x7
646 }, {
647 .num = 2,
648 .pin = 22,
649 .reg = 0xe8,
650 .bit = 8,
651 .mask = 0x7
652 }, {
653 .num = 2,
654 .pin = 23,
655 .reg = 0xe8,
656 .bit = 12,
657 .mask = 0x7
658 }, {
659 .num = 2,
660 .pin = 24,
661 .reg = 0xd4,
662 .bit = 12,
663 .mask = 0x7
664 },
665};
666
David Wuc04c3fa2017-07-21 14:27:14 +0800667static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
david.wu3818e4a2017-02-10 18:23:49 +0800668 {
669 .num = 2,
670 .pin = 12,
671 .reg = 0x24,
672 .bit = 8,
673 .mask = 0x3
674 }, {
675 .num = 2,
676 .pin = 15,
677 .reg = 0x28,
678 .bit = 0,
679 .mask = 0x7
680 }, {
681 .num = 2,
682 .pin = 23,
683 .reg = 0x30,
684 .bit = 14,
685 .mask = 0x3
686 },
687};
688
David Wuc04c3fa2017-07-21 14:27:14 +0800689static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
690 int *reg, u8 *bit, int *mask)
david.wu3818e4a2017-02-10 18:23:49 +0800691{
David Wuc04c3fa2017-07-21 14:27:14 +0800692 struct rockchip_pinctrl *info = bank->drvdata;
693 struct rockchip_pin_ctrl *ctrl = info->ctrl;
694 struct rockchip_mux_recalced_data *data;
david.wu3818e4a2017-02-10 18:23:49 +0800695 int i;
696
David Wuc04c3fa2017-07-21 14:27:14 +0800697 for (i = 0; i < ctrl->niomux_recalced; i++) {
698 data = &ctrl->iomux_recalced[i];
699 if (data->num == bank->bank_num &&
700 data->pin == pin)
david.wu3818e4a2017-02-10 18:23:49 +0800701 break;
David Wuc04c3fa2017-07-21 14:27:14 +0800702 }
david.wu3818e4a2017-02-10 18:23:49 +0800703
David Wuc04c3fa2017-07-21 14:27:14 +0800704 if (i >= ctrl->niomux_recalced)
david.wu3818e4a2017-02-10 18:23:49 +0800705 return;
706
707 *reg = data->reg;
708 *mask = data->mask;
709 *bit = data->bit;
710}
711
David Wu87065ca2018-05-14 19:59:51 +0800712static struct rockchip_mux_route_data px30_mux_route_data[] = {
713 {
714 /* cif-d2m0 */
715 .bank_num = 2,
716 .pin = 0,
717 .func = 1,
718 .route_offset = 0x184,
719 .route_val = BIT(16 + 7),
720 }, {
721 /* cif-d2m1 */
722 .bank_num = 3,
723 .pin = 3,
724 .func = 3,
725 .route_offset = 0x184,
726 .route_val = BIT(16 + 7) | BIT(7),
727 }, {
728 /* pdm-m0 */
729 .bank_num = 3,
730 .pin = 22,
731 .func = 2,
732 .route_offset = 0x184,
733 .route_val = BIT(16 + 8),
734 }, {
735 /* pdm-m1 */
736 .bank_num = 2,
737 .pin = 22,
738 .func = 1,
739 .route_offset = 0x184,
740 .route_val = BIT(16 + 8) | BIT(8),
741 }, {
742 /* uart2-rxm0 */
743 .bank_num = 1,
744 .pin = 27,
745 .func = 2,
746 .route_offset = 0x184,
747 .route_val = BIT(16 + 10),
748 }, {
749 /* uart2-rxm1 */
750 .bank_num = 2,
751 .pin = 14,
752 .func = 2,
753 .route_offset = 0x184,
754 .route_val = BIT(16 + 10) | BIT(10),
755 }, {
756 /* uart3-rxm0 */
757 .bank_num = 0,
758 .pin = 17,
759 .func = 2,
760 .route_offset = 0x184,
761 .route_val = BIT(16 + 9),
762 }, {
763 /* uart3-rxm1 */
764 .bank_num = 1,
765 .pin = 15,
766 .func = 2,
767 .route_offset = 0x184,
768 .route_val = BIT(16 + 9) | BIT(9),
769 },
770};
771
David Wud23c66d2017-07-21 14:27:15 +0800772static struct rockchip_mux_route_data rk3128_mux_route_data[] = {
773 {
774 /* spi-0 */
775 .bank_num = 1,
776 .pin = 10,
777 .func = 1,
778 .route_offset = 0x144,
779 .route_val = BIT(16 + 3) | BIT(16 + 4),
780 }, {
781 /* spi-1 */
782 .bank_num = 1,
783 .pin = 27,
784 .func = 3,
785 .route_offset = 0x144,
786 .route_val = BIT(16 + 3) | BIT(16 + 4) | BIT(3),
787 }, {
788 /* spi-2 */
789 .bank_num = 0,
790 .pin = 13,
791 .func = 2,
792 .route_offset = 0x144,
793 .route_val = BIT(16 + 3) | BIT(16 + 4) | BIT(4),
794 }, {
795 /* i2s-0 */
796 .bank_num = 1,
797 .pin = 5,
798 .func = 1,
799 .route_offset = 0x144,
800 .route_val = BIT(16 + 5),
801 }, {
802 /* i2s-1 */
803 .bank_num = 0,
804 .pin = 14,
805 .func = 1,
806 .route_offset = 0x144,
807 .route_val = BIT(16 + 5) | BIT(5),
808 }, {
809 /* emmc-0 */
810 .bank_num = 1,
811 .pin = 22,
812 .func = 2,
813 .route_offset = 0x144,
814 .route_val = BIT(16 + 6),
815 }, {
816 /* emmc-1 */
817 .bank_num = 2,
818 .pin = 4,
819 .func = 2,
820 .route_offset = 0x144,
821 .route_val = BIT(16 + 6) | BIT(6),
822 },
823};
824
David Wud4970ee2017-05-26 15:20:21 +0800825static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
826 {
827 /* pwm0-0 */
828 .bank_num = 0,
829 .pin = 26,
830 .func = 1,
831 .route_offset = 0x50,
832 .route_val = BIT(16),
833 }, {
834 /* pwm0-1 */
835 .bank_num = 3,
836 .pin = 21,
837 .func = 1,
838 .route_offset = 0x50,
839 .route_val = BIT(16) | BIT(0),
840 }, {
841 /* pwm1-0 */
842 .bank_num = 0,
843 .pin = 27,
844 .func = 1,
845 .route_offset = 0x50,
846 .route_val = BIT(16 + 1),
847 }, {
848 /* pwm1-1 */
849 .bank_num = 0,
850 .pin = 30,
851 .func = 2,
852 .route_offset = 0x50,
853 .route_val = BIT(16 + 1) | BIT(1),
854 }, {
855 /* pwm2-0 */
856 .bank_num = 0,
857 .pin = 28,
858 .func = 1,
859 .route_offset = 0x50,
860 .route_val = BIT(16 + 2),
861 }, {
862 /* pwm2-1 */
863 .bank_num = 1,
864 .pin = 12,
865 .func = 2,
866 .route_offset = 0x50,
867 .route_val = BIT(16 + 2) | BIT(2),
868 }, {
869 /* pwm3-0 */
870 .bank_num = 3,
871 .pin = 26,
872 .func = 1,
873 .route_offset = 0x50,
874 .route_val = BIT(16 + 3),
875 }, {
876 /* pwm3-1 */
877 .bank_num = 1,
878 .pin = 11,
879 .func = 2,
880 .route_offset = 0x50,
881 .route_val = BIT(16 + 3) | BIT(3),
882 }, {
883 /* sdio-0_d0 */
884 .bank_num = 1,
885 .pin = 1,
886 .func = 1,
887 .route_offset = 0x50,
888 .route_val = BIT(16 + 4),
889 }, {
890 /* sdio-1_d0 */
891 .bank_num = 3,
892 .pin = 2,
893 .func = 1,
894 .route_offset = 0x50,
895 .route_val = BIT(16 + 4) | BIT(4),
896 }, {
897 /* spi-0_rx */
898 .bank_num = 0,
899 .pin = 13,
900 .func = 2,
901 .route_offset = 0x50,
902 .route_val = BIT(16 + 5),
903 }, {
904 /* spi-1_rx */
905 .bank_num = 2,
906 .pin = 0,
907 .func = 2,
908 .route_offset = 0x50,
909 .route_val = BIT(16 + 5) | BIT(5),
910 }, {
911 /* emmc-0_cmd */
912 .bank_num = 1,
913 .pin = 22,
914 .func = 2,
915 .route_offset = 0x50,
916 .route_val = BIT(16 + 7),
917 }, {
918 /* emmc-1_cmd */
919 .bank_num = 2,
920 .pin = 4,
921 .func = 2,
922 .route_offset = 0x50,
923 .route_val = BIT(16 + 7) | BIT(7),
924 }, {
925 /* uart2-0_rx */
926 .bank_num = 1,
927 .pin = 19,
928 .func = 2,
929 .route_offset = 0x50,
930 .route_val = BIT(16 + 8),
931 }, {
932 /* uart2-1_rx */
933 .bank_num = 1,
934 .pin = 10,
935 .func = 2,
936 .route_offset = 0x50,
937 .route_val = BIT(16 + 8) | BIT(8),
938 }, {
939 /* uart1-0_rx */
940 .bank_num = 1,
941 .pin = 10,
942 .func = 1,
943 .route_offset = 0x50,
944 .route_val = BIT(16 + 11),
945 }, {
946 /* uart1-1_rx */
947 .bank_num = 3,
948 .pin = 13,
949 .func = 1,
950 .route_offset = 0x50,
951 .route_val = BIT(16 + 11) | BIT(11),
952 },
953};
954
Heiko Stuebner4e96fd32017-10-21 10:53:10 +0200955static struct rockchip_mux_route_data rk3288_mux_route_data[] = {
956 {
957 /* edphdmi_cecinoutt1 */
958 .bank_num = 7,
959 .pin = 16,
960 .func = 2,
961 .route_offset = 0x264,
962 .route_val = BIT(16 + 12) | BIT(12),
963 }, {
964 /* edphdmi_cecinout */
965 .bank_num = 7,
966 .pin = 23,
967 .func = 4,
968 .route_offset = 0x264,
969 .route_val = BIT(16 + 12),
970 },
971};
972
David Wucedc9642017-05-26 15:20:22 +0800973static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
974 {
975 /* uart2dbg_rxm0 */
976 .bank_num = 1,
977 .pin = 1,
978 .func = 2,
979 .route_offset = 0x50,
980 .route_val = BIT(16) | BIT(16 + 1),
981 }, {
982 /* uart2dbg_rxm1 */
983 .bank_num = 2,
984 .pin = 1,
985 .func = 1,
986 .route_offset = 0x50,
987 .route_val = BIT(16) | BIT(16 + 1) | BIT(0),
988 }, {
David Wua976d7b2017-09-30 20:13:21 +0800989 /* gmac-m1_rxd0 */
David Wucedc9642017-05-26 15:20:22 +0800990 .bank_num = 1,
991 .pin = 11,
992 .func = 2,
993 .route_offset = 0x50,
David Wua976d7b2017-09-30 20:13:21 +0800994 .route_val = BIT(16 + 2) | BIT(2),
995 }, {
996 /* gmac-m1-optimized_rxd3 */
997 .bank_num = 1,
998 .pin = 14,
999 .func = 2,
1000 .route_offset = 0x50,
1001 .route_val = BIT(16 + 10) | BIT(10),
David Wucedc9642017-05-26 15:20:22 +08001002 }, {
1003 /* pdm_sdi0m0 */
1004 .bank_num = 2,
1005 .pin = 19,
1006 .func = 2,
1007 .route_offset = 0x50,
1008 .route_val = BIT(16 + 3),
1009 }, {
1010 /* pdm_sdi0m1 */
1011 .bank_num = 1,
1012 .pin = 23,
1013 .func = 3,
1014 .route_offset = 0x50,
1015 .route_val = BIT(16 + 3) | BIT(3),
1016 }, {
1017 /* spi_rxdm2 */
1018 .bank_num = 3,
1019 .pin = 2,
1020 .func = 4,
1021 .route_offset = 0x50,
1022 .route_val = BIT(16 + 4) | BIT(16 + 5) | BIT(5),
1023 }, {
1024 /* i2s2_sdim0 */
1025 .bank_num = 1,
1026 .pin = 24,
1027 .func = 1,
1028 .route_offset = 0x50,
1029 .route_val = BIT(16 + 6),
1030 }, {
1031 /* i2s2_sdim1 */
1032 .bank_num = 3,
1033 .pin = 2,
1034 .func = 6,
1035 .route_offset = 0x50,
1036 .route_val = BIT(16 + 6) | BIT(6),
1037 }, {
1038 /* card_iom1 */
1039 .bank_num = 2,
1040 .pin = 22,
1041 .func = 3,
1042 .route_offset = 0x50,
1043 .route_val = BIT(16 + 7) | BIT(7),
1044 }, {
1045 /* tsp_d5m1 */
1046 .bank_num = 2,
1047 .pin = 16,
1048 .func = 3,
1049 .route_offset = 0x50,
1050 .route_val = BIT(16 + 8) | BIT(8),
1051 }, {
1052 /* cif_data5m1 */
1053 .bank_num = 2,
1054 .pin = 16,
1055 .func = 4,
1056 .route_offset = 0x50,
1057 .route_val = BIT(16 + 9) | BIT(9),
1058 },
1059};
1060
David Wuaccc1ce2017-05-26 15:20:23 +08001061static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
1062 {
1063 /* uart2dbga_rx */
1064 .bank_num = 4,
1065 .pin = 8,
1066 .func = 2,
1067 .route_offset = 0xe21c,
1068 .route_val = BIT(16 + 10) | BIT(16 + 11),
1069 }, {
1070 /* uart2dbgb_rx */
1071 .bank_num = 4,
1072 .pin = 16,
1073 .func = 2,
1074 .route_offset = 0xe21c,
1075 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(10),
1076 }, {
1077 /* uart2dbgc_rx */
1078 .bank_num = 4,
1079 .pin = 19,
1080 .func = 1,
1081 .route_offset = 0xe21c,
1082 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(11),
1083 }, {
1084 /* pcie_clkreqn */
1085 .bank_num = 2,
1086 .pin = 26,
1087 .func = 2,
1088 .route_offset = 0xe21c,
1089 .route_val = BIT(16 + 14),
1090 }, {
1091 /* pcie_clkreqnb */
1092 .bank_num = 4,
1093 .pin = 24,
1094 .func = 1,
1095 .route_offset = 0xe21c,
1096 .route_val = BIT(16 + 14) | BIT(14),
1097 },
1098};
1099
David Wubd35b9b2017-05-26 15:20:20 +08001100static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
Heiko Stuebner51ff47a2018-11-11 22:00:46 +01001101 int mux, u32 *loc, u32 *reg, u32 *value)
David Wubd35b9b2017-05-26 15:20:20 +08001102{
1103 struct rockchip_pinctrl *info = bank->drvdata;
1104 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1105 struct rockchip_mux_route_data *data;
1106 int i;
1107
1108 for (i = 0; i < ctrl->niomux_routes; i++) {
1109 data = &ctrl->iomux_routes[i];
1110 if ((data->bank_num == bank->bank_num) &&
1111 (data->pin == pin) && (data->func == mux))
1112 break;
1113 }
1114
1115 if (i >= ctrl->niomux_routes)
1116 return false;
1117
Heiko Stuebner51ff47a2018-11-11 22:00:46 +01001118 *loc = data->route_location;
David Wubd35b9b2017-05-26 15:20:20 +08001119 *reg = data->route_offset;
1120 *value = data->route_val;
1121
1122 return true;
1123}
1124
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001125static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
1126{
1127 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001128 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001129 struct regmap *regmap;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001130 unsigned int val;
david.wuea262ad2017-02-10 18:23:48 +08001131 int reg, ret, mask, mux_type;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001132 u8 bit;
1133
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001134 if (iomux_num > 3)
1135 return -EINVAL;
1136
Heiko Stübner62f49222014-06-16 01:37:49 +02001137 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1138 dev_err(info->dev, "pin %d is unrouted\n", pin);
1139 return -EINVAL;
1140 }
1141
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001142 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001143 return RK_FUNC_GPIO;
1144
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001145 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1146 ? info->regmap_pmu : info->regmap_base;
1147
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001148 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +08001149 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001150 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +08001151 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +02001152 if ((pin % 8) >= 4)
1153 reg += 0x4;
1154 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +08001155 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +08001156 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +08001157 if ((pin % 8) >= 5)
1158 reg += 0x4;
1159 bit = (pin % 8 % 5) * 3;
1160 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +02001161 } else {
1162 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +08001163 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +02001164 }
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001165
David Wuc04c3fa2017-07-21 14:27:14 +08001166 if (bank->recalced_mask & BIT(pin))
1167 rockchip_get_recalced_mux(bank, pin, &reg, &bit, &mask);
david.wuea262ad2017-02-10 18:23:48 +08001168
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001169 ret = regmap_read(regmap, reg, &val);
Heiko Stübner751a99a2014-05-05 13:58:20 +02001170 if (ret)
1171 return ret;
1172
Heiko Stübner03716e12014-06-16 01:36:57 +02001173 return ((val >> bit) & mask);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001174}
1175
John Keeping05709c32017-03-23 10:59:30 +00001176static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
1177 int pin, int mux)
1178{
1179 struct rockchip_pinctrl *info = bank->drvdata;
1180 int iomux_num = (pin / 8);
1181
1182 if (iomux_num > 3)
1183 return -EINVAL;
1184
1185 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1186 dev_err(info->dev, "pin %d is unrouted\n", pin);
1187 return -EINVAL;
1188 }
1189
1190 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
1191 if (mux != RK_FUNC_GPIO) {
1192 dev_err(info->dev,
1193 "pin %d only supports a gpio mux\n", pin);
1194 return -ENOTSUPP;
1195 }
1196 }
1197
1198 return 0;
1199}
1200
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001201/*
1202 * Set a new mux function for a pin.
1203 *
1204 * The register is divided into the upper and lower 16 bit. When changing
1205 * a value, the previous register value is not read and changed. Instead
1206 * it seems the changed bits are marked in the upper 16 bit, while the
1207 * changed value gets set in the same offset in the lower 16 bit.
1208 * All pin settings seem to be 2 bit wide in both the upper and lower
1209 * parts.
1210 * @bank: pin bank to change
1211 * @pin: pin to change
1212 * @mux: new mux function to set
1213 */
Heiko Stübner14797182014-03-26 00:57:00 +01001214static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001215{
1216 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001217 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001218 struct regmap *regmap;
david.wuea262ad2017-02-10 18:23:48 +08001219 int reg, ret, mask, mux_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001220 u8 bit;
Heiko Stuebner51ff47a2018-11-11 22:00:46 +01001221 u32 data, rmask, route_location, route_reg, route_val;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001222
John Keeping05709c32017-03-23 10:59:30 +00001223 ret = rockchip_verify_mux(bank, pin, mux);
1224 if (ret < 0)
1225 return ret;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001226
John Keeping05709c32017-03-23 10:59:30 +00001227 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
1228 return 0;
Heiko Stübnerc4a532de2014-03-26 00:57:52 +01001229
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001230 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
1231 bank->bank_num, pin, mux);
1232
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001233 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1234 ? info->regmap_pmu : info->regmap_base;
1235
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001236 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +08001237 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001238 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +08001239 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +02001240 if ((pin % 8) >= 4)
1241 reg += 0x4;
1242 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +08001243 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +08001244 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +08001245 if ((pin % 8) >= 5)
1246 reg += 0x4;
1247 bit = (pin % 8 % 5) * 3;
1248 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +02001249 } else {
1250 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +08001251 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +02001252 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001253
David Wuc04c3fa2017-07-21 14:27:14 +08001254 if (bank->recalced_mask & BIT(pin))
1255 rockchip_get_recalced_mux(bank, pin, &reg, &bit, &mask);
david.wuea262ad2017-02-10 18:23:48 +08001256
David Wubd35b9b2017-05-26 15:20:20 +08001257 if (bank->route_mask & BIT(pin)) {
Heiko Stuebner51ff47a2018-11-11 22:00:46 +01001258 if (rockchip_get_mux_route(bank, pin, mux, &route_location,
1259 &route_reg, &route_val)) {
1260 struct regmap *route_regmap = regmap;
1261
1262 /* handle special locations */
1263 switch (route_location) {
1264 case ROCKCHIP_ROUTE_PMU:
1265 route_regmap = info->regmap_pmu;
1266 break;
1267 case ROCKCHIP_ROUTE_GRF:
1268 route_regmap = info->regmap_base;
1269 break;
1270 }
1271
1272 ret = regmap_write(route_regmap, route_reg, route_val);
David Wubd35b9b2017-05-26 15:20:20 +08001273 if (ret)
1274 return ret;
1275 }
1276 }
1277
Heiko Stübner03716e12014-06-16 01:36:57 +02001278 data = (mask << (bit + 16));
Sonny Rao99e872d2014-07-31 22:58:00 -07001279 rmask = data | (data >> 16);
Heiko Stübner03716e12014-06-16 01:36:57 +02001280 data |= (mux & mask) << bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001281 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001282
Heiko Stübner751a99a2014-05-05 13:58:20 +02001283 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001284}
1285
David Wu87065ca2018-05-14 19:59:51 +08001286#define PX30_PULL_PMU_OFFSET 0x10
1287#define PX30_PULL_GRF_OFFSET 0x60
1288#define PX30_PULL_BITS_PER_PIN 2
1289#define PX30_PULL_PINS_PER_REG 8
1290#define PX30_PULL_BANK_STRIDE 16
1291
1292static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1293 int pin_num, struct regmap **regmap,
1294 int *reg, u8 *bit)
1295{
1296 struct rockchip_pinctrl *info = bank->drvdata;
1297
1298 /* The first 32 pins of the first bank are located in PMU */
1299 if (bank->bank_num == 0) {
1300 *regmap = info->regmap_pmu;
1301 *reg = PX30_PULL_PMU_OFFSET;
1302 } else {
1303 *regmap = info->regmap_base;
1304 *reg = PX30_PULL_GRF_OFFSET;
1305
1306 /* correct the offset, as we're starting with the 2nd bank */
1307 *reg -= 0x10;
1308 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE;
1309 }
1310
1311 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4);
1312 *bit = (pin_num % PX30_PULL_PINS_PER_REG);
1313 *bit *= PX30_PULL_BITS_PER_PIN;
1314}
1315
1316#define PX30_DRV_PMU_OFFSET 0x20
1317#define PX30_DRV_GRF_OFFSET 0xf0
1318#define PX30_DRV_BITS_PER_PIN 2
1319#define PX30_DRV_PINS_PER_REG 8
1320#define PX30_DRV_BANK_STRIDE 16
1321
1322static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1323 int pin_num, struct regmap **regmap,
1324 int *reg, u8 *bit)
1325{
1326 struct rockchip_pinctrl *info = bank->drvdata;
1327
1328 /* The first 32 pins of the first bank are located in PMU */
1329 if (bank->bank_num == 0) {
1330 *regmap = info->regmap_pmu;
1331 *reg = PX30_DRV_PMU_OFFSET;
1332 } else {
1333 *regmap = info->regmap_base;
1334 *reg = PX30_DRV_GRF_OFFSET;
1335
1336 /* correct the offset, as we're starting with the 2nd bank */
1337 *reg -= 0x10;
1338 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE;
1339 }
1340
1341 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4);
1342 *bit = (pin_num % PX30_DRV_PINS_PER_REG);
1343 *bit *= PX30_DRV_BITS_PER_PIN;
1344}
1345
1346#define PX30_SCHMITT_PMU_OFFSET 0x38
1347#define PX30_SCHMITT_GRF_OFFSET 0xc0
1348#define PX30_SCHMITT_PINS_PER_PMU_REG 16
1349#define PX30_SCHMITT_BANK_STRIDE 16
1350#define PX30_SCHMITT_PINS_PER_GRF_REG 8
1351
1352static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1353 int pin_num,
1354 struct regmap **regmap,
1355 int *reg, u8 *bit)
1356{
1357 struct rockchip_pinctrl *info = bank->drvdata;
1358 int pins_per_reg;
1359
1360 if (bank->bank_num == 0) {
1361 *regmap = info->regmap_pmu;
1362 *reg = PX30_SCHMITT_PMU_OFFSET;
1363 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG;
1364 } else {
1365 *regmap = info->regmap_base;
1366 *reg = PX30_SCHMITT_GRF_OFFSET;
1367 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG;
1368 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE;
1369 }
1370
1371 *reg += ((pin_num / pins_per_reg) * 4);
1372 *bit = pin_num % pins_per_reg;
1373
1374 return 0;
1375}
1376
Andy Yanb9c6dca2017-03-17 18:18:36 +01001377#define RV1108_PULL_PMU_OFFSET 0x10
1378#define RV1108_PULL_OFFSET 0x110
1379#define RV1108_PULL_PINS_PER_REG 8
1380#define RV1108_PULL_BITS_PER_PIN 2
1381#define RV1108_PULL_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001382
Andy Yanb9c6dca2017-03-17 18:18:36 +01001383static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001384 int pin_num, struct regmap **regmap,
1385 int *reg, u8 *bit)
1386{
1387 struct rockchip_pinctrl *info = bank->drvdata;
1388
1389 /* The first 24 pins of the first bank are located in PMU */
1390 if (bank->bank_num == 0) {
1391 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001392 *reg = RV1108_PULL_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001393 } else {
Andy Yanb9c6dca2017-03-17 18:18:36 +01001394 *reg = RV1108_PULL_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001395 *regmap = info->regmap_base;
1396 /* correct the offset, as we're starting with the 2nd bank */
1397 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001398 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001399 }
1400
Andy Yanb9c6dca2017-03-17 18:18:36 +01001401 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1402 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1403 *bit *= RV1108_PULL_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001404}
1405
Andy Yanb9c6dca2017-03-17 18:18:36 +01001406#define RV1108_DRV_PMU_OFFSET 0x20
1407#define RV1108_DRV_GRF_OFFSET 0x210
1408#define RV1108_DRV_BITS_PER_PIN 2
1409#define RV1108_DRV_PINS_PER_REG 8
1410#define RV1108_DRV_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001411
Andy Yanb9c6dca2017-03-17 18:18:36 +01001412static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001413 int pin_num, struct regmap **regmap,
1414 int *reg, u8 *bit)
1415{
1416 struct rockchip_pinctrl *info = bank->drvdata;
1417
1418 /* The first 24 pins of the first bank are located in PMU */
1419 if (bank->bank_num == 0) {
1420 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001421 *reg = RV1108_DRV_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001422 } else {
1423 *regmap = info->regmap_base;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001424 *reg = RV1108_DRV_GRF_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001425
1426 /* correct the offset, as we're starting with the 2nd bank */
1427 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001428 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001429 }
1430
Andy Yanb9c6dca2017-03-17 18:18:36 +01001431 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1432 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1433 *bit *= RV1108_DRV_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001434}
1435
Andy Yan5caff7e2017-07-31 18:10:22 +08001436#define RV1108_SCHMITT_PMU_OFFSET 0x30
1437#define RV1108_SCHMITT_GRF_OFFSET 0x388
1438#define RV1108_SCHMITT_BANK_STRIDE 8
1439#define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1440#define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1441
1442static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1443 int pin_num,
1444 struct regmap **regmap,
1445 int *reg, u8 *bit)
1446{
1447 struct rockchip_pinctrl *info = bank->drvdata;
1448 int pins_per_reg;
1449
1450 if (bank->bank_num == 0) {
1451 *regmap = info->regmap_pmu;
1452 *reg = RV1108_SCHMITT_PMU_OFFSET;
1453 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1454 } else {
1455 *regmap = info->regmap_base;
1456 *reg = RV1108_SCHMITT_GRF_OFFSET;
1457 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1458 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1459 }
1460 *reg += ((pin_num / pins_per_reg) * 4);
1461 *bit = pin_num % pins_per_reg;
1462
1463 return 0;
1464}
1465
Heiko Stübnera2829262013-10-16 01:07:20 +02001466#define RK2928_PULL_OFFSET 0x118
1467#define RK2928_PULL_PINS_PER_REG 16
1468#define RK2928_PULL_BANK_STRIDE 8
1469
1470static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001471 int pin_num, struct regmap **regmap,
1472 int *reg, u8 *bit)
Heiko Stübnera2829262013-10-16 01:07:20 +02001473{
1474 struct rockchip_pinctrl *info = bank->drvdata;
1475
Heiko Stübner751a99a2014-05-05 13:58:20 +02001476 *regmap = info->regmap_base;
1477 *reg = RK2928_PULL_OFFSET;
Heiko Stübnera2829262013-10-16 01:07:20 +02001478 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1479 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1480
1481 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1482};
1483
David Wud23c66d2017-07-21 14:27:15 +08001484#define RK3128_PULL_OFFSET 0x118
1485
1486static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1487 int pin_num, struct regmap **regmap,
1488 int *reg, u8 *bit)
1489{
1490 struct rockchip_pinctrl *info = bank->drvdata;
1491
1492 *regmap = info->regmap_base;
1493 *reg = RK3128_PULL_OFFSET;
1494 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1495 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1496
1497 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1498}
1499
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001500#define RK3188_PULL_OFFSET 0x164
Heiko Stübner6ca52742013-10-16 01:08:42 +02001501#define RK3188_PULL_BITS_PER_PIN 2
1502#define RK3188_PULL_PINS_PER_REG 8
1503#define RK3188_PULL_BANK_STRIDE 16
Heiko Stübner14dee862014-05-05 13:59:09 +02001504#define RK3188_PULL_PMU_OFFSET 0x64
Heiko Stübner6ca52742013-10-16 01:08:42 +02001505
1506static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001507 int pin_num, struct regmap **regmap,
1508 int *reg, u8 *bit)
Heiko Stübner6ca52742013-10-16 01:08:42 +02001509{
1510 struct rockchip_pinctrl *info = bank->drvdata;
1511
1512 /* The first 12 pins of the first bank are located elsewhere */
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001513 if (bank->bank_num == 0 && pin_num < 12) {
Heiko Stübner14dee862014-05-05 13:59:09 +02001514 *regmap = info->regmap_pmu ? info->regmap_pmu
1515 : bank->regmap_pull;
1516 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001517 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001518 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1519 *bit *= RK3188_PULL_BITS_PER_PIN;
1520 } else {
Heiko Stübner751a99a2014-05-05 13:58:20 +02001521 *regmap = info->regmap_pull ? info->regmap_pull
1522 : info->regmap_base;
1523 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1524
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001525 /* correct the offset, as it is the 2nd pull register */
1526 *reg -= 4;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001527 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1528 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1529
1530 /*
1531 * The bits in these registers have an inverse ordering
1532 * with the lowest pin being in bits 15:14 and the highest
1533 * pin in bits 1:0
1534 */
1535 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1536 *bit *= RK3188_PULL_BITS_PER_PIN;
1537 }
1538}
1539
Heiko Stübner304f0772014-06-16 01:38:14 +02001540#define RK3288_PULL_OFFSET 0x140
1541static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1542 int pin_num, struct regmap **regmap,
1543 int *reg, u8 *bit)
1544{
1545 struct rockchip_pinctrl *info = bank->drvdata;
1546
1547 /* The first 24 pins of the first bank are located in PMU */
1548 if (bank->bank_num == 0) {
1549 *regmap = info->regmap_pmu;
1550 *reg = RK3188_PULL_PMU_OFFSET;
1551
1552 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1553 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1554 *bit *= RK3188_PULL_BITS_PER_PIN;
1555 } else {
1556 *regmap = info->regmap_base;
1557 *reg = RK3288_PULL_OFFSET;
1558
1559 /* correct the offset, as we're starting with the 2nd bank */
1560 *reg -= 0x10;
1561 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1562 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1563
1564 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1565 *bit *= RK3188_PULL_BITS_PER_PIN;
1566 }
1567}
1568
Heiko Stübnerb547c802014-07-20 01:50:11 +02001569#define RK3288_DRV_PMU_OFFSET 0x70
1570#define RK3288_DRV_GRF_OFFSET 0x1c0
1571#define RK3288_DRV_BITS_PER_PIN 2
1572#define RK3288_DRV_PINS_PER_REG 8
1573#define RK3288_DRV_BANK_STRIDE 16
Heiko Stübnerb547c802014-07-20 01:50:11 +02001574
1575static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1576 int pin_num, struct regmap **regmap,
1577 int *reg, u8 *bit)
1578{
1579 struct rockchip_pinctrl *info = bank->drvdata;
1580
1581 /* The first 24 pins of the first bank are located in PMU */
1582 if (bank->bank_num == 0) {
1583 *regmap = info->regmap_pmu;
1584 *reg = RK3288_DRV_PMU_OFFSET;
1585
1586 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1587 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1588 *bit *= RK3288_DRV_BITS_PER_PIN;
1589 } else {
1590 *regmap = info->regmap_base;
1591 *reg = RK3288_DRV_GRF_OFFSET;
1592
1593 /* correct the offset, as we're starting with the 2nd bank */
1594 *reg -= 0x10;
1595 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1596 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1597
1598 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1599 *bit *= RK3288_DRV_BITS_PER_PIN;
1600 }
1601}
1602
Jeffy Chenfea0fe62015-12-09 17:04:06 +08001603#define RK3228_PULL_OFFSET 0x100
1604
1605static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1606 int pin_num, struct regmap **regmap,
1607 int *reg, u8 *bit)
1608{
1609 struct rockchip_pinctrl *info = bank->drvdata;
1610
1611 *regmap = info->regmap_base;
1612 *reg = RK3228_PULL_OFFSET;
1613 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1614 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1615
1616 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1617 *bit *= RK3188_PULL_BITS_PER_PIN;
1618}
1619
1620#define RK3228_DRV_GRF_OFFSET 0x200
1621
1622static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1623 int pin_num, struct regmap **regmap,
1624 int *reg, u8 *bit)
1625{
1626 struct rockchip_pinctrl *info = bank->drvdata;
1627
1628 *regmap = info->regmap_base;
1629 *reg = RK3228_DRV_GRF_OFFSET;
1630 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1631 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1632
1633 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1634 *bit *= RK3288_DRV_BITS_PER_PIN;
1635}
1636
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001637#define RK3368_PULL_GRF_OFFSET 0x100
1638#define RK3368_PULL_PMU_OFFSET 0x10
1639
1640static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1641 int pin_num, struct regmap **regmap,
1642 int *reg, u8 *bit)
1643{
1644 struct rockchip_pinctrl *info = bank->drvdata;
1645
1646 /* The first 32 pins of the first bank are located in PMU */
1647 if (bank->bank_num == 0) {
1648 *regmap = info->regmap_pmu;
1649 *reg = RK3368_PULL_PMU_OFFSET;
1650
1651 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1652 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1653 *bit *= RK3188_PULL_BITS_PER_PIN;
1654 } else {
1655 *regmap = info->regmap_base;
1656 *reg = RK3368_PULL_GRF_OFFSET;
1657
1658 /* correct the offset, as we're starting with the 2nd bank */
1659 *reg -= 0x10;
1660 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1661 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1662
1663 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1664 *bit *= RK3188_PULL_BITS_PER_PIN;
1665 }
1666}
1667
1668#define RK3368_DRV_PMU_OFFSET 0x20
1669#define RK3368_DRV_GRF_OFFSET 0x200
1670
1671static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1672 int pin_num, struct regmap **regmap,
1673 int *reg, u8 *bit)
1674{
1675 struct rockchip_pinctrl *info = bank->drvdata;
1676
1677 /* The first 32 pins of the first bank are located in PMU */
1678 if (bank->bank_num == 0) {
1679 *regmap = info->regmap_pmu;
1680 *reg = RK3368_DRV_PMU_OFFSET;
1681
1682 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1683 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1684 *bit *= RK3288_DRV_BITS_PER_PIN;
1685 } else {
1686 *regmap = info->regmap_base;
1687 *reg = RK3368_DRV_GRF_OFFSET;
1688
1689 /* correct the offset, as we're starting with the 2nd bank */
1690 *reg -= 0x10;
1691 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1692 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1693
1694 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1695 *bit *= RK3288_DRV_BITS_PER_PIN;
1696 }
1697}
1698
David Wub6c23272016-02-01 10:58:21 +08001699#define RK3399_PULL_GRF_OFFSET 0xe040
1700#define RK3399_PULL_PMU_OFFSET 0x40
1701#define RK3399_DRV_3BITS_PER_PIN 3
1702
1703static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1704 int pin_num, struct regmap **regmap,
1705 int *reg, u8 *bit)
1706{
1707 struct rockchip_pinctrl *info = bank->drvdata;
1708
1709 /* The bank0:16 and bank1:32 pins are located in PMU */
1710 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1711 *regmap = info->regmap_pmu;
1712 *reg = RK3399_PULL_PMU_OFFSET;
1713
1714 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1715
1716 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1717 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1718 *bit *= RK3188_PULL_BITS_PER_PIN;
1719 } else {
1720 *regmap = info->regmap_base;
1721 *reg = RK3399_PULL_GRF_OFFSET;
1722
1723 /* correct the offset, as we're starting with the 3rd bank */
1724 *reg -= 0x20;
1725 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1726 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1727
1728 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1729 *bit *= RK3188_PULL_BITS_PER_PIN;
1730 }
1731}
1732
1733static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1734 int pin_num, struct regmap **regmap,
1735 int *reg, u8 *bit)
1736{
1737 struct rockchip_pinctrl *info = bank->drvdata;
1738 int drv_num = (pin_num / 8);
1739
1740 /* The bank0:16 and bank1:32 pins are located in PMU */
1741 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1742 *regmap = info->regmap_pmu;
1743 else
1744 *regmap = info->regmap_base;
1745
1746 *reg = bank->drv[drv_num].offset;
1747 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1748 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1749 *bit = (pin_num % 8) * 3;
1750 else
1751 *bit = (pin_num % 8) * 2;
1752}
1753
1754static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1755 { 2, 4, 8, 12, -1, -1, -1, -1 },
1756 { 3, 6, 9, 12, -1, -1, -1, -1 },
1757 { 5, 10, 15, 20, -1, -1, -1, -1 },
1758 { 4, 6, 8, 10, 12, 14, 16, 18 },
1759 { 4, 7, 10, 13, 16, 19, 22, 26 }
1760};
Heiko Stübneref17f692015-06-12 23:50:11 +02001761
1762static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1763 int pin_num)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001764{
Heiko Stübneref17f692015-06-12 23:50:11 +02001765 struct rockchip_pinctrl *info = bank->drvdata;
1766 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001767 struct regmap *regmap;
1768 int reg, ret;
David Wub6c23272016-02-01 10:58:21 +08001769 u32 data, temp, rmask_bits;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001770 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001771 int drv_type = bank->drv[pin_num / 8].drv_type;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001772
Heiko Stübneref17f692015-06-12 23:50:11 +02001773 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001774
David Wub6c23272016-02-01 10:58:21 +08001775 switch (drv_type) {
1776 case DRV_TYPE_IO_1V8_3V0_AUTO:
1777 case DRV_TYPE_IO_3V3_ONLY:
1778 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1779 switch (bit) {
1780 case 0 ... 12:
1781 /* regular case, nothing to do */
1782 break;
1783 case 15:
1784 /*
1785 * drive-strength offset is special, as it is
1786 * spread over 2 registers
1787 */
1788 ret = regmap_read(regmap, reg, &data);
1789 if (ret)
1790 return ret;
1791
1792 ret = regmap_read(regmap, reg + 0x4, &temp);
1793 if (ret)
1794 return ret;
1795
1796 /*
1797 * the bit data[15] contains bit 0 of the value
1798 * while temp[1:0] contains bits 2 and 1
1799 */
1800 data >>= 15;
1801 temp &= 0x3;
1802 temp <<= 1;
1803 data |= temp;
1804
1805 return rockchip_perpin_drv_list[drv_type][data];
1806 case 18 ... 21:
1807 /* setting fully enclosed in the second register */
1808 reg += 4;
1809 bit -= 16;
1810 break;
1811 default:
1812 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1813 bit, drv_type);
1814 return -EINVAL;
1815 }
1816
1817 break;
1818 case DRV_TYPE_IO_DEFAULT:
1819 case DRV_TYPE_IO_1V8_OR_3V0:
1820 case DRV_TYPE_IO_1V8_ONLY:
1821 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1822 break;
1823 default:
1824 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1825 drv_type);
1826 return -EINVAL;
1827 }
1828
Heiko Stübnerb547c802014-07-20 01:50:11 +02001829 ret = regmap_read(regmap, reg, &data);
1830 if (ret)
1831 return ret;
1832
1833 data >>= bit;
David Wub6c23272016-02-01 10:58:21 +08001834 data &= (1 << rmask_bits) - 1;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001835
David Wub6c23272016-02-01 10:58:21 +08001836 return rockchip_perpin_drv_list[drv_type][data];
Heiko Stübnerb547c802014-07-20 01:50:11 +02001837}
1838
Heiko Stübneref17f692015-06-12 23:50:11 +02001839static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1840 int pin_num, int strength)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001841{
1842 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübneref17f692015-06-12 23:50:11 +02001843 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001844 struct regmap *regmap;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001845 int reg, ret, i;
David Wub6c23272016-02-01 10:58:21 +08001846 u32 data, rmask, rmask_bits, temp;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001847 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001848 int drv_type = bank->drv[pin_num / 8].drv_type;
1849
1850 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1851 bank->bank_num, pin_num, strength);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001852
Heiko Stübneref17f692015-06-12 23:50:11 +02001853 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001854
1855 ret = -EINVAL;
David Wub6c23272016-02-01 10:58:21 +08001856 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1857 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
Heiko Stübnerb547c802014-07-20 01:50:11 +02001858 ret = i;
1859 break;
David Wub6c23272016-02-01 10:58:21 +08001860 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1861 ret = rockchip_perpin_drv_list[drv_type][i];
1862 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001863 }
1864 }
1865
1866 if (ret < 0) {
1867 dev_err(info->dev, "unsupported driver strength %d\n",
1868 strength);
1869 return ret;
1870 }
1871
David Wub6c23272016-02-01 10:58:21 +08001872 switch (drv_type) {
1873 case DRV_TYPE_IO_1V8_3V0_AUTO:
1874 case DRV_TYPE_IO_3V3_ONLY:
1875 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1876 switch (bit) {
1877 case 0 ... 12:
1878 /* regular case, nothing to do */
1879 break;
1880 case 15:
1881 /*
1882 * drive-strength offset is special, as it is spread
1883 * over 2 registers, the bit data[15] contains bit 0
1884 * of the value while temp[1:0] contains bits 2 and 1
1885 */
1886 data = (ret & 0x1) << 15;
1887 temp = (ret >> 0x1) & 0x3;
1888
1889 rmask = BIT(15) | BIT(31);
1890 data |= BIT(31);
1891 ret = regmap_update_bits(regmap, reg, rmask, data);
John Keepingf07bedc2017-03-23 10:59:28 +00001892 if (ret)
David Wub6c23272016-02-01 10:58:21 +08001893 return ret;
David Wub6c23272016-02-01 10:58:21 +08001894
1895 rmask = 0x3 | (0x3 << 16);
1896 temp |= (0x3 << 16);
1897 reg += 0x4;
1898 ret = regmap_update_bits(regmap, reg, rmask, temp);
1899
David Wub6c23272016-02-01 10:58:21 +08001900 return ret;
1901 case 18 ... 21:
1902 /* setting fully enclosed in the second register */
1903 reg += 4;
1904 bit -= 16;
1905 break;
1906 default:
David Wub6c23272016-02-01 10:58:21 +08001907 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1908 bit, drv_type);
1909 return -EINVAL;
1910 }
1911 break;
1912 case DRV_TYPE_IO_DEFAULT:
1913 case DRV_TYPE_IO_1V8_OR_3V0:
1914 case DRV_TYPE_IO_1V8_ONLY:
1915 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1916 break;
1917 default:
David Wub6c23272016-02-01 10:58:21 +08001918 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1919 drv_type);
1920 return -EINVAL;
1921 }
1922
Heiko Stübnerb547c802014-07-20 01:50:11 +02001923 /* enable the write to the equivalent lower bits */
David Wub6c23272016-02-01 10:58:21 +08001924 data = ((1 << rmask_bits) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07001925 rmask = data | (data >> 16);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001926 data |= (ret << bit);
1927
Sonny Rao99e872d2014-07-31 22:58:00 -07001928 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001929
1930 return ret;
1931}
1932
David Wu3ba67672016-05-11 11:39:28 +08001933static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1934 {
1935 PIN_CONFIG_BIAS_DISABLE,
1936 PIN_CONFIG_BIAS_PULL_UP,
1937 PIN_CONFIG_BIAS_PULL_DOWN,
1938 PIN_CONFIG_BIAS_BUS_HOLD
1939 },
1940 {
1941 PIN_CONFIG_BIAS_DISABLE,
1942 PIN_CONFIG_BIAS_PULL_DOWN,
1943 PIN_CONFIG_BIAS_DISABLE,
1944 PIN_CONFIG_BIAS_PULL_UP
1945 },
1946};
1947
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001948static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1949{
1950 struct rockchip_pinctrl *info = bank->drvdata;
1951 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001952 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001953 int reg, ret, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001954 u8 bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001955 u32 data;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001956
1957 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02001958 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001959 return PIN_CONFIG_BIAS_DISABLE;
1960
Heiko Stübner751a99a2014-05-05 13:58:20 +02001961 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
1962
1963 ret = regmap_read(regmap, reg, &data);
1964 if (ret)
1965 return ret;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001966
Heiko Stübnera2829262013-10-16 01:07:20 +02001967 switch (ctrl->type) {
1968 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08001969 case RK3128:
Heiko Stübner751a99a2014-05-05 13:58:20 +02001970 return !(data & BIT(bit))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001971 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1972 : PIN_CONFIG_BIAS_DISABLE;
David Wu87065ca2018-05-14 19:59:51 +08001973 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01001974 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001975 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02001976 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001977 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08001978 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08001979 pull_type = bank->pull_type[pin_num / 8];
Heiko Stübner751a99a2014-05-05 13:58:20 +02001980 data >>= bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001981 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1982
David Wu3ba67672016-05-11 11:39:28 +08001983 return rockchip_pull_list[pull_type][data];
Heiko Stübnera2829262013-10-16 01:07:20 +02001984 default:
1985 dev_err(info->dev, "unsupported pinctrl type\n");
1986 return -EINVAL;
1987 };
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001988}
1989
1990static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1991 int pin_num, int pull)
1992{
1993 struct rockchip_pinctrl *info = bank->drvdata;
1994 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001995 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001996 int reg, ret, i, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001997 u8 bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001998 u32 data, rmask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001999
2000 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
2001 bank->bank_num, pin_num, pull);
2002
2003 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02002004 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002005 return pull ? -EINVAL : 0;
2006
Heiko Stübner751a99a2014-05-05 13:58:20 +02002007 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02002008
Heiko Stübnera2829262013-10-16 01:07:20 +02002009 switch (ctrl->type) {
2010 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08002011 case RK3128:
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002012 data = BIT(bit + 16);
2013 if (pull == PIN_CONFIG_BIAS_DISABLE)
2014 data |= BIT(bit);
Heiko Stübner751a99a2014-05-05 13:58:20 +02002015 ret = regmap_write(regmap, reg, data);
Heiko Stübnera2829262013-10-16 01:07:20 +02002016 break;
David Wu87065ca2018-05-14 19:59:51 +08002017 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01002018 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02002019 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02002020 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02002021 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08002022 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08002023 pull_type = bank->pull_type[pin_num / 8];
2024 ret = -EINVAL;
2025 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
2026 i++) {
2027 if (rockchip_pull_list[pull_type][i] == pull) {
2028 ret = i;
2029 break;
2030 }
2031 }
2032
2033 if (ret < 0) {
2034 dev_err(info->dev, "unsupported pull setting %d\n",
2035 pull);
2036 return ret;
2037 }
2038
Heiko Stübner6ca52742013-10-16 01:08:42 +02002039 /* enable the write to the equivalent lower bits */
2040 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07002041 rmask = data | (data >> 16);
David Wu3ba67672016-05-11 11:39:28 +08002042 data |= (ret << bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02002043
Sonny Rao99e872d2014-07-31 22:58:00 -07002044 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübner6ca52742013-10-16 01:08:42 +02002045 break;
Heiko Stübnera2829262013-10-16 01:07:20 +02002046 default:
2047 dev_err(info->dev, "unsupported pinctrl type\n");
2048 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002049 }
2050
Heiko Stübner751a99a2014-05-05 13:58:20 +02002051 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002052}
2053
david.wu728d3f52017-03-02 15:11:24 +08002054#define RK3328_SCHMITT_BITS_PER_PIN 1
2055#define RK3328_SCHMITT_PINS_PER_REG 16
2056#define RK3328_SCHMITT_BANK_STRIDE 8
2057#define RK3328_SCHMITT_GRF_OFFSET 0x380
2058
2059static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
2060 int pin_num,
2061 struct regmap **regmap,
2062 int *reg, u8 *bit)
2063{
2064 struct rockchip_pinctrl *info = bank->drvdata;
2065
2066 *regmap = info->regmap_base;
2067 *reg = RK3328_SCHMITT_GRF_OFFSET;
2068
2069 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
2070 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
2071 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
2072
2073 return 0;
2074}
2075
david.wue3b357d2017-03-02 15:11:23 +08002076static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
2077{
2078 struct rockchip_pinctrl *info = bank->drvdata;
2079 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2080 struct regmap *regmap;
2081 int reg, ret;
2082 u8 bit;
2083 u32 data;
2084
2085 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
2086 if (ret)
2087 return ret;
2088
2089 ret = regmap_read(regmap, reg, &data);
2090 if (ret)
2091 return ret;
2092
2093 data >>= bit;
2094 return data & 0x1;
2095}
2096
2097static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
2098 int pin_num, int enable)
2099{
2100 struct rockchip_pinctrl *info = bank->drvdata;
2101 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2102 struct regmap *regmap;
2103 int reg, ret;
david.wue3b357d2017-03-02 15:11:23 +08002104 u8 bit;
2105 u32 data, rmask;
2106
2107 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
2108 bank->bank_num, pin_num, enable);
2109
2110 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
2111 if (ret)
2112 return ret;
2113
david.wue3b357d2017-03-02 15:11:23 +08002114 /* enable the write to the equivalent lower bits */
2115 data = BIT(bit + 16) | (enable << bit);
2116 rmask = BIT(bit + 16) | BIT(bit);
2117
John Keepingf07bedc2017-03-23 10:59:28 +00002118 return regmap_update_bits(regmap, reg, rmask, data);
david.wue3b357d2017-03-02 15:11:23 +08002119}
2120
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002121/*
2122 * Pinmux_ops handling
2123 */
2124
2125static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
2126{
2127 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2128
2129 return info->nfunctions;
2130}
2131
2132static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
2133 unsigned selector)
2134{
2135 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2136
2137 return info->functions[selector].name;
2138}
2139
2140static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
2141 unsigned selector, const char * const **groups,
2142 unsigned * const num_groups)
2143{
2144 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2145
2146 *groups = info->functions[selector].groups;
2147 *num_groups = info->functions[selector].ngroups;
2148
2149 return 0;
2150}
2151
Linus Walleij03e9f0c2014-09-03 13:02:56 +02002152static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
2153 unsigned group)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002154{
2155 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2156 const unsigned int *pins = info->groups[group].pins;
2157 const struct rockchip_pin_config *data = info->groups[group].data;
2158 struct rockchip_pin_bank *bank;
Heiko Stübner14797182014-03-26 00:57:00 +01002159 int cnt, ret = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002160
2161 dev_dbg(info->dev, "enable function %s group %s\n",
2162 info->functions[selector].name, info->groups[group].name);
2163
2164 /*
Markus Elfring85dc3972017-12-23 22:22:54 +01002165 * for each pin in the pin group selected, program the corresponding
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002166 * pin function number in the config register.
2167 */
2168 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
2169 bank = pin_to_bank(info, pins[cnt]);
Heiko Stübner14797182014-03-26 00:57:00 +01002170 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
2171 data[cnt].func);
2172 if (ret)
2173 break;
2174 }
2175
2176 if (ret) {
2177 /* revert the already done pin settings */
2178 for (cnt--; cnt >= 0; cnt--)
2179 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
2180
2181 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002182 }
2183
2184 return 0;
2185}
2186
Caesar Wang6ba20a02016-03-15 15:55:45 +08002187static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
2188{
2189 struct rockchip_pin_bank *bank = gpiochip_get_data(chip);
2190 u32 data;
Brian Norris5c9d8c42017-12-12 09:43:43 -08002191 int ret;
Caesar Wang6ba20a02016-03-15 15:55:45 +08002192
Brian Norris5c9d8c42017-12-12 09:43:43 -08002193 ret = clk_enable(bank->clk);
2194 if (ret < 0) {
2195 dev_err(bank->drvdata->dev,
2196 "failed to enable clock for bank %s\n", bank->name);
2197 return ret;
2198 }
Caesar Wang6ba20a02016-03-15 15:55:45 +08002199 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
Brian Norris5c9d8c42017-12-12 09:43:43 -08002200 clk_disable(bank->clk);
Caesar Wang6ba20a02016-03-15 15:55:45 +08002201
2202 return !(data & BIT(offset));
2203}
2204
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002205/*
2206 * The calls to gpio_direction_output() and gpio_direction_input()
2207 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
2208 * function called from the gpiolib interface).
2209 */
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002210static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip,
2211 int pin, bool input)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002212{
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002213 struct rockchip_pin_bank *bank;
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002214 int ret;
Doug Andersonfab262f2014-10-21 10:47:35 -07002215 unsigned long flags;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002216 u32 data;
2217
Linus Walleij03bf81f2015-12-08 09:39:13 +01002218 bank = gpiochip_get_data(chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002219
Heiko Stübner14797182014-03-26 00:57:00 +01002220 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
2221 if (ret < 0)
2222 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002223
Lin Huang07a06ae2015-08-11 18:12:04 +08002224 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002225 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002226
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002227 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2228 /* set bit to 1 for output, 0 for input */
2229 if (!input)
2230 data |= BIT(pin);
2231 else
2232 data &= ~BIT(pin);
2233 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2234
John Keeping70b7aa72017-03-23 10:59:29 +00002235 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08002236 clk_disable(bank->clk);
Doug Andersonfab262f2014-10-21 10:47:35 -07002237
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002238 return 0;
2239}
2240
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002241static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
2242 struct pinctrl_gpio_range *range,
2243 unsigned offset, bool input)
2244{
2245 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2246 struct gpio_chip *chip;
2247 int pin;
2248
2249 chip = range->gc;
2250 pin = offset - chip->base;
2251 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
2252 offset, range->name, pin, input ? "input" : "output");
2253
2254 return _rockchip_pmx_gpio_set_direction(chip, offset - chip->base,
2255 input);
2256}
2257
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002258static const struct pinmux_ops rockchip_pmx_ops = {
2259 .get_functions_count = rockchip_pmx_get_funcs_count,
2260 .get_function_name = rockchip_pmx_get_func_name,
2261 .get_function_groups = rockchip_pmx_get_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +02002262 .set_mux = rockchip_pmx_set,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002263 .gpio_set_direction = rockchip_pmx_gpio_set_direction,
2264};
2265
2266/*
2267 * Pinconf_ops handling
2268 */
2269
Heiko Stübner44b6d932013-06-16 17:41:16 +02002270static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2271 enum pin_config_param pull)
2272{
Heiko Stübnera2829262013-10-16 01:07:20 +02002273 switch (ctrl->type) {
2274 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08002275 case RK3128:
Heiko Stübnera2829262013-10-16 01:07:20 +02002276 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2277 pull == PIN_CONFIG_BIAS_DISABLE);
2278 case RK3066B:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002279 return pull ? false : true;
David Wu87065ca2018-05-14 19:59:51 +08002280 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01002281 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02002282 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02002283 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02002284 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08002285 case RK3399:
Heiko Stübnera2829262013-10-16 01:07:20 +02002286 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
Heiko Stübner44b6d932013-06-16 17:41:16 +02002287 }
2288
Heiko Stübnera2829262013-10-16 01:07:20 +02002289 return false;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002290}
2291
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002292static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002293static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset);
2294
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002295/* set the pin config settings for a specified pin */
2296static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Sherman Yin03b054e2013-08-27 11:32:12 -07002297 unsigned long *configs, unsigned num_configs)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002298{
2299 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2300 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
Sherman Yin03b054e2013-08-27 11:32:12 -07002301 enum pin_config_param param;
Mika Westerberg58957d22017-01-23 15:34:32 +03002302 u32 arg;
Sherman Yin03b054e2013-08-27 11:32:12 -07002303 int i;
2304 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002305
Sherman Yin03b054e2013-08-27 11:32:12 -07002306 for (i = 0; i < num_configs; i++) {
2307 param = pinconf_to_config_param(configs[i]);
2308 arg = pinconf_to_config_argument(configs[i]);
2309
2310 switch (param) {
2311 case PIN_CONFIG_BIAS_DISABLE:
2312 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2313 param);
2314 if (rc)
2315 return rc;
2316 break;
2317 case PIN_CONFIG_BIAS_PULL_UP:
2318 case PIN_CONFIG_BIAS_PULL_DOWN:
2319 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02002320 case PIN_CONFIG_BIAS_BUS_HOLD:
Sherman Yin03b054e2013-08-27 11:32:12 -07002321 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2322 return -ENOTSUPP;
2323
2324 if (!arg)
2325 return -EINVAL;
2326
2327 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2328 param);
2329 if (rc)
2330 return rc;
2331 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002332 case PIN_CONFIG_OUTPUT:
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002333 rockchip_gpio_set(&bank->gpio_chip,
2334 pin - bank->pin_base, arg);
2335 rc = _rockchip_pmx_gpio_set_direction(&bank->gpio_chip,
2336 pin - bank->pin_base, false);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002337 if (rc)
2338 return rc;
2339 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02002340 case PIN_CONFIG_DRIVE_STRENGTH:
2341 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02002342 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02002343 return -ENOTSUPP;
2344
Heiko Stübneref17f692015-06-12 23:50:11 +02002345 rc = rockchip_set_drive_perpin(bank,
2346 pin - bank->pin_base, arg);
Heiko Stübnerb547c802014-07-20 01:50:11 +02002347 if (rc < 0)
2348 return rc;
2349 break;
david.wue3b357d2017-03-02 15:11:23 +08002350 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2351 if (!info->ctrl->schmitt_calc_reg)
2352 return -ENOTSUPP;
2353
2354 rc = rockchip_set_schmitt(bank,
2355 pin - bank->pin_base, arg);
2356 if (rc < 0)
2357 return rc;
2358 break;
Sherman Yin03b054e2013-08-27 11:32:12 -07002359 default:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002360 return -ENOTSUPP;
Sherman Yin03b054e2013-08-27 11:32:12 -07002361 break;
2362 }
2363 } /* for each config */
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002364
2365 return 0;
2366}
2367
2368/* get the pin config settings for a specified pin */
2369static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2370 unsigned long *config)
2371{
2372 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2373 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2374 enum pin_config_param param = pinconf_to_config_param(*config);
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002375 u16 arg;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002376 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002377
2378 switch (param) {
2379 case PIN_CONFIG_BIAS_DISABLE:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002380 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002381 return -EINVAL;
2382
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002383 arg = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002384 break;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002385 case PIN_CONFIG_BIAS_PULL_UP:
2386 case PIN_CONFIG_BIAS_PULL_DOWN:
2387 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02002388 case PIN_CONFIG_BIAS_BUS_HOLD:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002389 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2390 return -ENOTSUPP;
2391
2392 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2393 return -EINVAL;
2394
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002395 arg = 1;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002396 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002397 case PIN_CONFIG_OUTPUT:
2398 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2399 if (rc != RK_FUNC_GPIO)
2400 return -EINVAL;
2401
2402 rc = rockchip_gpio_get(&bank->gpio_chip, pin - bank->pin_base);
2403 if (rc < 0)
2404 return rc;
2405
2406 arg = rc ? 1 : 0;
2407 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02002408 case PIN_CONFIG_DRIVE_STRENGTH:
2409 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02002410 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02002411 return -ENOTSUPP;
2412
Heiko Stübneref17f692015-06-12 23:50:11 +02002413 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
Heiko Stübnerb547c802014-07-20 01:50:11 +02002414 if (rc < 0)
2415 return rc;
2416
2417 arg = rc;
2418 break;
david.wue3b357d2017-03-02 15:11:23 +08002419 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2420 if (!info->ctrl->schmitt_calc_reg)
2421 return -ENOTSUPP;
2422
2423 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2424 if (rc < 0)
2425 return rc;
2426
2427 arg = rc;
2428 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002429 default:
2430 return -ENOTSUPP;
2431 break;
2432 }
2433
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002434 *config = pinconf_to_config_packed(param, arg);
2435
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002436 return 0;
2437}
2438
2439static const struct pinconf_ops rockchip_pinconf_ops = {
2440 .pin_config_get = rockchip_pinconf_get,
2441 .pin_config_set = rockchip_pinconf_set,
Heiko Stübnered62f2f2014-07-20 01:48:45 +02002442 .is_generic = true,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002443};
2444
Heiko Stübner65fca612013-10-16 01:07:49 +02002445static const struct of_device_id rockchip_bank_match[] = {
2446 { .compatible = "rockchip,gpio-bank" },
Heiko Stübner6ca52742013-10-16 01:08:42 +02002447 { .compatible = "rockchip,rk3188-gpio-bank0" },
Heiko Stübner65fca612013-10-16 01:07:49 +02002448 {},
2449};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002450
2451static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2452 struct device_node *np)
2453{
2454 struct device_node *child;
2455
2456 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002457 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002458 continue;
2459
2460 info->nfunctions++;
2461 info->ngroups += of_get_child_count(child);
2462 }
2463}
2464
2465static int rockchip_pinctrl_parse_groups(struct device_node *np,
2466 struct rockchip_pin_group *grp,
2467 struct rockchip_pinctrl *info,
2468 u32 index)
2469{
2470 struct rockchip_pin_bank *bank;
2471 int size;
2472 const __be32 *list;
2473 int num;
2474 int i, j;
2475 int ret;
2476
Rob Herring94f4e542018-08-27 20:52:41 -05002477 dev_dbg(info->dev, "group(%d): %pOFn\n", index, np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002478
2479 /* Initialise group */
2480 grp->name = np->name;
2481
2482 /*
2483 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2484 * do sanity check and calculate pins number
2485 */
2486 list = of_get_property(np, "rockchip,pins", &size);
2487 /* we do not check return since it's safe node passed down */
2488 size /= sizeof(*list);
2489 if (!size || size % 4) {
2490 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2491 return -EINVAL;
2492 }
2493
2494 grp->npins = size / 4;
2495
Kees Cooka86854d2018-06-12 14:07:58 -07002496 grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002497 GFP_KERNEL);
Kees Cooka86854d2018-06-12 14:07:58 -07002498 grp->data = devm_kcalloc(info->dev,
2499 grp->npins,
2500 sizeof(struct rockchip_pin_config),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002501 GFP_KERNEL);
2502 if (!grp->pins || !grp->data)
2503 return -ENOMEM;
2504
2505 for (i = 0, j = 0; i < size; i += 4, j++) {
2506 const __be32 *phandle;
2507 struct device_node *np_config;
2508
2509 num = be32_to_cpu(*list++);
2510 bank = bank_num_to_bank(info, num);
2511 if (IS_ERR(bank))
2512 return PTR_ERR(bank);
2513
2514 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2515 grp->data[j].func = be32_to_cpu(*list++);
2516
2517 phandle = list++;
2518 if (!phandle)
2519 return -EINVAL;
2520
2521 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
Soren Brinkmanndd4d01f2015-01-09 07:43:46 -08002522 ret = pinconf_generic_parse_dt_config(np_config, NULL,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002523 &grp->data[j].configs, &grp->data[j].nconfigs);
2524 if (ret)
2525 return ret;
2526 }
2527
2528 return 0;
2529}
2530
2531static int rockchip_pinctrl_parse_functions(struct device_node *np,
2532 struct rockchip_pinctrl *info,
2533 u32 index)
2534{
2535 struct device_node *child;
2536 struct rockchip_pmx_func *func;
2537 struct rockchip_pin_group *grp;
2538 int ret;
2539 static u32 grp_index;
2540 u32 i = 0;
2541
Rob Herring94f4e542018-08-27 20:52:41 -05002542 dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002543
2544 func = &info->functions[index];
2545
2546 /* Initialise function */
2547 func->name = np->name;
2548 func->ngroups = of_get_child_count(np);
2549 if (func->ngroups <= 0)
2550 return 0;
2551
Kees Cooka86854d2018-06-12 14:07:58 -07002552 func->groups = devm_kcalloc(info->dev,
2553 func->ngroups, sizeof(char *), GFP_KERNEL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002554 if (!func->groups)
2555 return -ENOMEM;
2556
2557 for_each_child_of_node(np, child) {
2558 func->groups[i] = child->name;
2559 grp = &info->groups[grp_index++];
2560 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
Julia Lawallf7a81b72015-12-21 17:39:47 +01002561 if (ret) {
2562 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002563 return ret;
Julia Lawallf7a81b72015-12-21 17:39:47 +01002564 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002565 }
2566
2567 return 0;
2568}
2569
2570static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2571 struct rockchip_pinctrl *info)
2572{
2573 struct device *dev = &pdev->dev;
2574 struct device_node *np = dev->of_node;
2575 struct device_node *child;
2576 int ret;
2577 int i;
2578
2579 rockchip_pinctrl_child_count(info, np);
2580
2581 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2582 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2583
Kees Cooka86854d2018-06-12 14:07:58 -07002584 info->functions = devm_kcalloc(dev,
2585 info->nfunctions,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002586 sizeof(struct rockchip_pmx_func),
2587 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002588 if (!info->functions)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002589 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002590
Kees Cooka86854d2018-06-12 14:07:58 -07002591 info->groups = devm_kcalloc(dev,
2592 info->ngroups,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002593 sizeof(struct rockchip_pin_group),
2594 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002595 if (!info->groups)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002596 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002597
2598 i = 0;
2599
2600 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002601 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002602 continue;
Heiko Stübner65fca612013-10-16 01:07:49 +02002603
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002604 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2605 if (ret) {
2606 dev_err(&pdev->dev, "failed to parse function\n");
Julia Lawallf7a81b72015-12-21 17:39:47 +01002607 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002608 return ret;
2609 }
2610 }
2611
2612 return 0;
2613}
2614
2615static int rockchip_pinctrl_register(struct platform_device *pdev,
2616 struct rockchip_pinctrl *info)
2617{
2618 struct pinctrl_desc *ctrldesc = &info->pctl;
2619 struct pinctrl_pin_desc *pindesc, *pdesc;
2620 struct rockchip_pin_bank *pin_bank;
2621 int pin, bank, ret;
2622 int k;
2623
2624 ctrldesc->name = "rockchip-pinctrl";
2625 ctrldesc->owner = THIS_MODULE;
2626 ctrldesc->pctlops = &rockchip_pctrl_ops;
2627 ctrldesc->pmxops = &rockchip_pmx_ops;
2628 ctrldesc->confops = &rockchip_pinconf_ops;
2629
Kees Cooka86854d2018-06-12 14:07:58 -07002630 pindesc = devm_kcalloc(&pdev->dev,
2631 info->ctrl->nr_pins, sizeof(*pindesc),
2632 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002633 if (!pindesc)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002634 return -ENOMEM;
Markus Elfring98c8ee72017-12-23 22:02:47 +01002635
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002636 ctrldesc->pins = pindesc;
2637 ctrldesc->npins = info->ctrl->nr_pins;
2638
2639 pdesc = pindesc;
2640 for (bank = 0 , k = 0; bank < info->ctrl->nr_banks; bank++) {
2641 pin_bank = &info->ctrl->pin_banks[bank];
2642 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2643 pdesc->number = k;
2644 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2645 pin_bank->name, pin);
2646 pdesc++;
2647 }
2648 }
2649
Doug Anderson0fb7dcb2014-10-21 10:47:34 -07002650 ret = rockchip_pinctrl_parse_dt(pdev, info);
2651 if (ret)
2652 return ret;
2653
Laxman Dewangan0085a2b2016-02-24 14:44:07 +05302654 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002655 if (IS_ERR(info->pctl_dev)) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002656 dev_err(&pdev->dev, "could not register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002657 return PTR_ERR(info->pctl_dev);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002658 }
2659
2660 for (bank = 0; bank < info->ctrl->nr_banks; ++bank) {
2661 pin_bank = &info->ctrl->pin_banks[bank];
2662 pin_bank->grange.name = pin_bank->name;
2663 pin_bank->grange.id = bank;
2664 pin_bank->grange.pin_base = pin_bank->pin_base;
2665 pin_bank->grange.base = pin_bank->gpio_chip.base;
2666 pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
2667 pin_bank->grange.gc = &pin_bank->gpio_chip;
2668 pinctrl_add_gpio_range(info->pctl_dev, &pin_bank->grange);
2669 }
2670
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002671 return 0;
2672}
2673
2674/*
2675 * GPIO handling
2676 */
2677
2678static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
2679{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002680 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002681 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR;
2682 unsigned long flags;
2683 u32 data;
2684
Lin Huang07a06ae2015-08-11 18:12:04 +08002685 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002686 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002687
2688 data = readl(reg);
2689 data &= ~BIT(offset);
2690 if (value)
2691 data |= BIT(offset);
2692 writel(data, reg);
2693
John Keeping70b7aa72017-03-23 10:59:29 +00002694 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08002695 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002696}
2697
2698/*
2699 * Returns the level of the pin for input direction and setting of the DR
2700 * register for output gpios.
2701 */
2702static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset)
2703{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002704 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002705 u32 data;
2706
Lin Huang07a06ae2015-08-11 18:12:04 +08002707 clk_enable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002708 data = readl(bank->reg_base + GPIO_EXT_PORT);
Lin Huang07a06ae2015-08-11 18:12:04 +08002709 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002710 data >>= offset;
2711 data &= 1;
2712 return data;
2713}
2714
2715/*
2716 * gpiolib gpio_direction_input callback function. The setting of the pin
Markus Elfring85dc3972017-12-23 22:22:54 +01002717 * mux function as 'gpio input' will be handled by the pinctrl subsystem
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002718 * interface.
2719 */
2720static int rockchip_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
2721{
2722 return pinctrl_gpio_direction_input(gc->base + offset);
2723}
2724
2725/*
2726 * gpiolib gpio_direction_output callback function. The setting of the pin
Markus Elfring85dc3972017-12-23 22:22:54 +01002727 * mux function as 'gpio output' will be handled by the pinctrl subsystem
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002728 * interface.
2729 */
2730static int rockchip_gpio_direction_output(struct gpio_chip *gc,
2731 unsigned offset, int value)
2732{
2733 rockchip_gpio_set(gc, offset, value);
2734 return pinctrl_gpio_direction_output(gc->base + offset);
2735}
2736
Shawn Linb97038a2018-05-03 16:04:42 +08002737static void rockchip_gpio_set_debounce(struct gpio_chip *gc,
2738 unsigned int offset, bool enable)
2739{
2740 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
2741 void __iomem *reg = bank->reg_base + GPIO_DEBOUNCE;
2742 unsigned long flags;
2743 u32 data;
2744
2745 clk_enable(bank->clk);
2746 raw_spin_lock_irqsave(&bank->slock, flags);
2747
2748 data = readl(reg);
2749 if (enable)
2750 data |= BIT(offset);
2751 else
2752 data &= ~BIT(offset);
2753 writel(data, reg);
2754
2755 raw_spin_unlock_irqrestore(&bank->slock, flags);
2756 clk_disable(bank->clk);
2757}
2758
2759/*
2760 * gpiolib set_config callback function. The setting of the pin
2761 * mux function as 'gpio output' will be handled by the pinctrl subsystem
2762 * interface.
2763 */
2764static int rockchip_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
2765 unsigned long config)
2766{
2767 enum pin_config_param param = pinconf_to_config_param(config);
2768
2769 switch (param) {
2770 case PIN_CONFIG_INPUT_DEBOUNCE:
2771 rockchip_gpio_set_debounce(gc, offset, true);
2772 /*
2773 * Rockchip's gpio could only support up to one period
2774 * of the debounce clock(pclk), which is far away from
2775 * satisftying the requirement, as pclk is usually near
2776 * 100MHz shared by all peripherals. So the fact is it
2777 * has crippled debounce capability could only be useful
2778 * to prevent any spurious glitches from waking up the system
2779 * if the gpio is conguired as wakeup interrupt source. Let's
2780 * still return -ENOTSUPP as before, to make sure the caller
2781 * of gpiod_set_debounce won't change its behaviour.
2782 */
2783 default:
2784 return -ENOTSUPP;
2785 }
2786}
2787
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002788/*
2789 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
2790 * and a virtual IRQ, if not already present.
2791 */
2792static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
2793{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002794 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002795 unsigned int virq;
2796
2797 if (!bank->domain)
2798 return -ENXIO;
2799
2800 virq = irq_create_mapping(bank->domain, offset);
2801
2802 return (virq) ? : -ENXIO;
2803}
2804
2805static const struct gpio_chip rockchip_gpiolib_chip = {
Jonas Gorski98c85d52015-10-11 17:34:19 +02002806 .request = gpiochip_generic_request,
2807 .free = gpiochip_generic_free,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002808 .set = rockchip_gpio_set,
2809 .get = rockchip_gpio_get,
Caesar Wang6ba20a02016-03-15 15:55:45 +08002810 .get_direction = rockchip_gpio_get_direction,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002811 .direction_input = rockchip_gpio_direction_input,
2812 .direction_output = rockchip_gpio_direction_output,
Shawn Linb97038a2018-05-03 16:04:42 +08002813 .set_config = rockchip_gpio_set_config,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002814 .to_irq = rockchip_gpio_to_irq,
2815 .owner = THIS_MODULE,
2816};
2817
2818/*
2819 * Interrupt handling
2820 */
2821
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +02002822static void rockchip_irq_demux(struct irq_desc *desc)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002823{
Jiang Liu5663bb22015-06-04 12:13:16 +08002824 struct irq_chip *chip = irq_desc_get_chip(desc);
2825 struct rockchip_pin_bank *bank = irq_desc_get_handler_data(desc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002826 u32 pend;
2827
2828 dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
2829
2830 chained_irq_enter(chip, desc);
2831
2832 pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
2833
2834 while (pend) {
Thomas Gleixner415f7482015-07-13 01:52:00 +02002835 unsigned int irq, virq;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002836
2837 irq = __ffs(pend);
2838 pend &= ~BIT(irq);
2839 virq = irq_linear_revmap(bank->domain, irq);
2840
2841 if (!virq) {
2842 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
2843 continue;
2844 }
2845
2846 dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
2847
Heiko Stübner5a927502013-10-16 01:09:08 +02002848 /*
2849 * Triggering IRQ on both rising and falling edge
2850 * needs manual intervention.
2851 */
2852 if (bank->toggle_edge_mode & BIT(irq)) {
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002853 u32 data, data_old, polarity;
2854 unsigned long flags;
Heiko Stübner5a927502013-10-16 01:09:08 +02002855
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002856 data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
2857 do {
John Keeping70b7aa72017-03-23 10:59:29 +00002858 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002859
2860 polarity = readl_relaxed(bank->reg_base +
2861 GPIO_INT_POLARITY);
2862 if (data & BIT(irq))
2863 polarity &= ~BIT(irq);
2864 else
2865 polarity |= BIT(irq);
2866 writel(polarity,
2867 bank->reg_base + GPIO_INT_POLARITY);
2868
John Keeping70b7aa72017-03-23 10:59:29 +00002869 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002870
2871 data_old = data;
2872 data = readl_relaxed(bank->reg_base +
2873 GPIO_EXT_PORT);
2874 } while ((data & BIT(irq)) != (data_old & BIT(irq)));
Heiko Stübner5a927502013-10-16 01:09:08 +02002875 }
2876
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002877 generic_handle_irq(virq);
2878 }
2879
2880 chained_irq_exit(chip, desc);
2881}
2882
2883static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
2884{
2885 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2886 struct rockchip_pin_bank *bank = gc->private;
2887 u32 mask = BIT(d->hwirq);
2888 u32 polarity;
2889 u32 level;
2890 u32 data;
Doug Andersonfab262f2014-10-21 10:47:35 -07002891 unsigned long flags;
Heiko Stübner14797182014-03-26 00:57:00 +01002892 int ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002893
Heiko Stübner5a927502013-10-16 01:09:08 +02002894 /* make sure the pin is configured as gpio input */
Brian Norris1d80df92017-06-23 13:59:11 -07002895 ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
Heiko Stübner14797182014-03-26 00:57:00 +01002896 if (ret < 0)
2897 return ret;
2898
Brian Norris1d80df92017-06-23 13:59:11 -07002899 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002900 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002901
Heiko Stübner5a927502013-10-16 01:09:08 +02002902 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2903 data &= ~mask;
2904 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2905
John Keeping70b7aa72017-03-23 10:59:29 +00002906 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002907
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002908 if (type & IRQ_TYPE_EDGE_BOTH)
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002909 irq_set_handler_locked(d, handle_edge_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002910 else
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002911 irq_set_handler_locked(d, handle_level_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002912
John Keeping70b7aa72017-03-23 10:59:29 +00002913 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002914 irq_gc_lock(gc);
2915
2916 level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL);
2917 polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
2918
2919 switch (type) {
Heiko Stübner5a927502013-10-16 01:09:08 +02002920 case IRQ_TYPE_EDGE_BOTH:
2921 bank->toggle_edge_mode |= mask;
2922 level |= mask;
2923
2924 /*
2925 * Determine gpio state. If 1 next interrupt should be falling
2926 * otherwise rising.
2927 */
2928 data = readl(bank->reg_base + GPIO_EXT_PORT);
2929 if (data & mask)
2930 polarity &= ~mask;
2931 else
2932 polarity |= mask;
2933 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002934 case IRQ_TYPE_EDGE_RISING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002935 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002936 level |= mask;
2937 polarity |= mask;
2938 break;
2939 case IRQ_TYPE_EDGE_FALLING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002940 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002941 level |= mask;
2942 polarity &= ~mask;
2943 break;
2944 case IRQ_TYPE_LEVEL_HIGH:
Heiko Stübner5a927502013-10-16 01:09:08 +02002945 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002946 level &= ~mask;
2947 polarity |= mask;
2948 break;
2949 case IRQ_TYPE_LEVEL_LOW:
Heiko Stübner5a927502013-10-16 01:09:08 +02002950 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002951 level &= ~mask;
2952 polarity &= ~mask;
2953 break;
2954 default:
Axel Lin7cc5f972013-06-23 08:48:34 +08002955 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002956 raw_spin_unlock_irqrestore(&bank->slock, flags);
Brian Norris1d80df92017-06-23 13:59:11 -07002957 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002958 return -EINVAL;
2959 }
2960
2961 writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL);
2962 writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY);
2963
2964 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002965 raw_spin_unlock_irqrestore(&bank->slock, flags);
Brian Norris1d80df92017-06-23 13:59:11 -07002966 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002967
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002968 return 0;
2969}
2970
Doug Anderson68bda472014-11-19 14:51:32 -08002971static void rockchip_irq_suspend(struct irq_data *d)
2972{
2973 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2974 struct rockchip_pin_bank *bank = gc->private;
2975
Lin Huang07a06ae2015-08-11 18:12:04 +08002976 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002977 bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK);
2978 irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002979 clk_disable(bank->clk);
Doug Anderson68bda472014-11-19 14:51:32 -08002980}
2981
2982static void rockchip_irq_resume(struct irq_data *d)
2983{
2984 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2985 struct rockchip_pin_bank *bank = gc->private;
2986
Lin Huang07a06ae2015-08-11 18:12:04 +08002987 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002988 irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002989 clk_disable(bank->clk);
2990}
2991
Jeffy Chend4682892017-03-02 13:56:52 +08002992static void rockchip_irq_enable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08002993{
2994 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2995 struct rockchip_pin_bank *bank = gc->private;
2996
2997 clk_enable(bank->clk);
2998 irq_gc_mask_clr_bit(d);
2999}
3000
Jeffy Chend4682892017-03-02 13:56:52 +08003001static void rockchip_irq_disable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08003002{
3003 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
3004 struct rockchip_pin_bank *bank = gc->private;
3005
3006 irq_gc_mask_set_bit(d);
3007 clk_disable(bank->clk);
Doug Andersonf2dd0282014-11-19 14:51:33 -08003008}
3009
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003010static int rockchip_interrupts_register(struct platform_device *pdev,
3011 struct rockchip_pinctrl *info)
3012{
3013 struct rockchip_pin_ctrl *ctrl = info->ctrl;
3014 struct rockchip_pin_bank *bank = ctrl->pin_banks;
3015 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
3016 struct irq_chip_generic *gc;
3017 int ret;
Lin Huang07a06ae2015-08-11 18:12:04 +08003018 int i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003019
3020 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3021 if (!bank->valid) {
3022 dev_warn(&pdev->dev, "bank %s is not valid\n",
3023 bank->name);
3024 continue;
3025 }
3026
Lin Huang07a06ae2015-08-11 18:12:04 +08003027 ret = clk_enable(bank->clk);
3028 if (ret) {
3029 dev_err(&pdev->dev, "failed to enable clock for bank %s\n",
3030 bank->name);
3031 continue;
3032 }
3033
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003034 bank->domain = irq_domain_add_linear(bank->of_node, 32,
3035 &irq_generic_chip_ops, NULL);
3036 if (!bank->domain) {
3037 dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n",
3038 bank->name);
Lin Huang07a06ae2015-08-11 18:12:04 +08003039 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003040 continue;
3041 }
3042
3043 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
3044 "rockchip_gpio_irq", handle_level_irq,
3045 clr, 0, IRQ_GC_INIT_MASK_CACHE);
3046 if (ret) {
3047 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
3048 bank->name);
3049 irq_domain_remove(bank->domain);
Lin Huang07a06ae2015-08-11 18:12:04 +08003050 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003051 continue;
3052 }
3053
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08003054 /*
3055 * Linux assumes that all interrupts start out disabled/masked.
3056 * Our driver only uses the concept of masked and always keeps
3057 * things enabled, so for us that's all masked and all enabled.
3058 */
3059 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
3060 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
3061
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003062 gc = irq_get_domain_generic_chip(bank->domain, 0);
3063 gc->reg_base = bank->reg_base;
3064 gc->private = bank;
Doug Andersonf2dd0282014-11-19 14:51:33 -08003065 gc->chip_types[0].regs.mask = GPIO_INTMASK;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003066 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
3067 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
Jeffy Chend4682892017-03-02 13:56:52 +08003068 gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
3069 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit;
3070 gc->chip_types[0].chip.irq_enable = rockchip_irq_enable;
3071 gc->chip_types[0].chip.irq_disable = rockchip_irq_disable;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003072 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
Doug Anderson68bda472014-11-19 14:51:32 -08003073 gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend;
3074 gc->chip_types[0].chip.irq_resume = rockchip_irq_resume;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003075 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
Doug Anderson876d7162014-10-21 10:47:32 -07003076 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003077
Thomas Gleixner03051bc2015-06-21 21:11:06 +02003078 irq_set_chained_handler_and_data(bank->irq,
3079 rockchip_irq_demux, bank);
Lin Huang07a06ae2015-08-11 18:12:04 +08003080
3081 /* map the gpio irqs here, when the clock is still running */
3082 for (j = 0 ; j < 32 ; j++)
3083 irq_create_mapping(bank->domain, j);
3084
3085 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003086 }
3087
3088 return 0;
3089}
3090
3091static int rockchip_gpiolib_register(struct platform_device *pdev,
3092 struct rockchip_pinctrl *info)
3093{
3094 struct rockchip_pin_ctrl *ctrl = info->ctrl;
3095 struct rockchip_pin_bank *bank = ctrl->pin_banks;
3096 struct gpio_chip *gc;
3097 int ret;
3098 int i;
3099
3100 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3101 if (!bank->valid) {
3102 dev_warn(&pdev->dev, "bank %s is not valid\n",
3103 bank->name);
3104 continue;
3105 }
3106
3107 bank->gpio_chip = rockchip_gpiolib_chip;
3108
3109 gc = &bank->gpio_chip;
3110 gc->base = bank->pin_base;
3111 gc->ngpio = bank->nr_pins;
Linus Walleij58383c782015-11-04 09:56:26 +01003112 gc->parent = &pdev->dev;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003113 gc->of_node = bank->of_node;
3114 gc->label = bank->name;
3115
Linus Walleij03bf81f2015-12-08 09:39:13 +01003116 ret = gpiochip_add_data(gc, bank);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003117 if (ret) {
3118 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
3119 gc->label, ret);
3120 goto fail;
3121 }
3122 }
3123
3124 rockchip_interrupts_register(pdev, info);
3125
3126 return 0;
3127
3128fail:
3129 for (--i, --bank; i >= 0; --i, --bank) {
3130 if (!bank->valid)
3131 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003132 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003133 }
3134 return ret;
3135}
3136
3137static int rockchip_gpiolib_unregister(struct platform_device *pdev,
3138 struct rockchip_pinctrl *info)
3139{
3140 struct rockchip_pin_ctrl *ctrl = info->ctrl;
3141 struct rockchip_pin_bank *bank = ctrl->pin_banks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003142 int i;
3143
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003144 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003145 if (!bank->valid)
3146 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003147 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003148 }
3149
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003150 return 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003151}
3152
3153static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
Heiko Stübner622f3232014-05-05 13:58:46 +02003154 struct rockchip_pinctrl *info)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003155{
3156 struct resource res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02003157 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003158
3159 if (of_address_to_resource(bank->of_node, 0, &res)) {
Heiko Stübner622f3232014-05-05 13:58:46 +02003160 dev_err(info->dev, "cannot find IO resource for bank\n");
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003161 return -ENOENT;
3162 }
3163
Heiko Stübner622f3232014-05-05 13:58:46 +02003164 bank->reg_base = devm_ioremap_resource(info->dev, &res);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003165 if (IS_ERR(bank->reg_base))
3166 return PTR_ERR(bank->reg_base);
3167
Heiko Stübner6ca52742013-10-16 01:08:42 +02003168 /*
3169 * special case, where parts of the pull setting-registers are
3170 * part of the PMU register space
3171 */
3172 if (of_device_is_compatible(bank->of_node,
3173 "rockchip,rk3188-gpio-bank0")) {
Heiko Stübnera658efa2014-05-05 13:59:30 +02003174 struct device_node *node;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02003175
Heiko Stübnera658efa2014-05-05 13:59:30 +02003176 node = of_parse_phandle(bank->of_node->parent,
3177 "rockchip,pmu", 0);
3178 if (!node) {
3179 if (of_address_to_resource(bank->of_node, 1, &res)) {
3180 dev_err(info->dev, "cannot find IO resource for bank\n");
3181 return -ENOENT;
3182 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003183
Heiko Stübnera658efa2014-05-05 13:59:30 +02003184 base = devm_ioremap_resource(info->dev, &res);
3185 if (IS_ERR(base))
3186 return PTR_ERR(base);
3187 rockchip_regmap_config.max_register =
3188 resource_size(&res) - 4;
3189 rockchip_regmap_config.name =
3190 "rockchip,rk3188-gpio-bank0-pull";
3191 bank->regmap_pull = devm_regmap_init_mmio(info->dev,
3192 base,
3193 &rockchip_regmap_config);
3194 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003195 }
Heiko Stübner65fca612013-10-16 01:07:49 +02003196
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003197 bank->irq = irq_of_parse_and_map(bank->of_node, 0);
3198
3199 bank->clk = of_clk_get(bank->of_node, 0);
3200 if (IS_ERR(bank->clk))
3201 return PTR_ERR(bank->clk);
3202
Lin Huang07a06ae2015-08-11 18:12:04 +08003203 return clk_prepare(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003204}
3205
3206static const struct of_device_id rockchip_pinctrl_dt_match[];
3207
3208/* retrieve the soc specific data */
3209static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
3210 struct rockchip_pinctrl *d,
3211 struct platform_device *pdev)
3212{
3213 const struct of_device_id *match;
3214 struct device_node *node = pdev->dev.of_node;
3215 struct device_node *np;
3216 struct rockchip_pin_ctrl *ctrl;
3217 struct rockchip_pin_bank *bank;
David Wub6c23272016-02-01 10:58:21 +08003218 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003219
3220 match = of_match_node(rockchip_pinctrl_dt_match, node);
3221 ctrl = (struct rockchip_pin_ctrl *)match->data;
3222
3223 for_each_child_of_node(node, np) {
3224 if (!of_find_property(np, "gpio-controller", NULL))
3225 continue;
3226
3227 bank = ctrl->pin_banks;
3228 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3229 if (!strcmp(bank->name, np->name)) {
3230 bank->of_node = np;
3231
Heiko Stübner622f3232014-05-05 13:58:46 +02003232 if (!rockchip_get_bank_data(bank, d))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003233 bank->valid = true;
3234
3235 break;
3236 }
3237 }
3238 }
3239
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003240 grf_offs = ctrl->grf_mux_offset;
3241 pmu_offs = ctrl->pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +08003242 drv_pmu_offs = ctrl->pmu_drv_offset;
3243 drv_grf_offs = ctrl->grf_drv_offset;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003244 bank = ctrl->pin_banks;
3245 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003246 int bank_pins = 0;
3247
John Keeping70b7aa72017-03-23 10:59:29 +00003248 raw_spin_lock_init(&bank->slock);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003249 bank->drvdata = d;
3250 bank->pin_base = ctrl->nr_pins;
3251 ctrl->nr_pins += bank->nr_pins;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003252
David Wub6c23272016-02-01 10:58:21 +08003253 /* calculate iomux and drv offsets */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003254 for (j = 0; j < 4; j++) {
3255 struct rockchip_iomux *iom = &bank->iomux[j];
David Wub6c23272016-02-01 10:58:21 +08003256 struct rockchip_drv *drv = &bank->drv[j];
Heiko Stübner03716e12014-06-16 01:36:57 +02003257 int inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003258
3259 if (bank_pins >= bank->nr_pins)
3260 break;
3261
David Wub6c23272016-02-01 10:58:21 +08003262 /* preset iomux offset value, set new start value */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003263 if (iom->offset >= 0) {
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003264 if (iom->type & IOMUX_SOURCE_PMU)
3265 pmu_offs = iom->offset;
3266 else
3267 grf_offs = iom->offset;
David Wub6c23272016-02-01 10:58:21 +08003268 } else { /* set current iomux offset */
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003269 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3270 pmu_offs : grf_offs;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003271 }
3272
David Wub6c23272016-02-01 10:58:21 +08003273 /* preset drv offset value, set new start value */
3274 if (drv->offset >= 0) {
3275 if (iom->type & IOMUX_SOURCE_PMU)
3276 drv_pmu_offs = drv->offset;
3277 else
3278 drv_grf_offs = drv->offset;
3279 } else { /* set current drv offset */
3280 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3281 drv_pmu_offs : drv_grf_offs;
3282 }
3283
3284 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3285 i, j, iom->offset, drv->offset);
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003286
3287 /*
3288 * Increase offset according to iomux width.
Heiko Stübner03716e12014-06-16 01:36:57 +02003289 * 4bit iomux'es are spread over two registers.
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003290 */
david.wu8b6c6f92017-02-10 18:23:47 +08003291 inc = (iom->type & (IOMUX_WIDTH_4BIT |
3292 IOMUX_WIDTH_3BIT)) ? 8 : 4;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003293 if (iom->type & IOMUX_SOURCE_PMU)
3294 pmu_offs += inc;
3295 else
3296 grf_offs += inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003297
David Wub6c23272016-02-01 10:58:21 +08003298 /*
3299 * Increase offset according to drv width.
3300 * 3bit drive-strenth'es are spread over two registers.
3301 */
3302 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
3303 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
3304 inc = 8;
3305 else
3306 inc = 4;
3307
3308 if (iom->type & IOMUX_SOURCE_PMU)
3309 drv_pmu_offs += inc;
3310 else
3311 drv_grf_offs += inc;
3312
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003313 bank_pins += 8;
3314 }
David Wubd35b9b2017-05-26 15:20:20 +08003315
David Wuc04c3fa2017-07-21 14:27:14 +08003316 /* calculate the per-bank recalced_mask */
3317 for (j = 0; j < ctrl->niomux_recalced; j++) {
3318 int pin = 0;
3319
3320 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
3321 pin = ctrl->iomux_recalced[j].pin;
3322 bank->recalced_mask |= BIT(pin);
3323 }
3324 }
3325
David Wubd35b9b2017-05-26 15:20:20 +08003326 /* calculate the per-bank route_mask */
3327 for (j = 0; j < ctrl->niomux_routes; j++) {
3328 int pin = 0;
3329
3330 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
3331 pin = ctrl->iomux_routes[j].pin;
3332 bank->route_mask |= BIT(pin);
3333 }
3334 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003335 }
3336
3337 return ctrl;
3338}
3339
Chris Zhong8dca9332014-10-29 19:52:00 +08003340#define RK3288_GRF_GPIO6C_IOMUX 0x64
3341#define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3342
3343static u32 rk3288_grf_gpio6c_iomux;
3344
Chris Zhong9198f502014-10-29 19:51:59 +08003345static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
3346{
3347 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08003348 int ret = pinctrl_force_sleep(info->pctl_dev);
Chris Zhong9198f502014-10-29 19:51:59 +08003349
Chris Zhong8dca9332014-10-29 19:52:00 +08003350 if (ret)
3351 return ret;
3352
3353 /*
3354 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3355 * the setting here, and restore it at resume.
3356 */
3357 if (info->ctrl->type == RK3288) {
3358 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3359 &rk3288_grf_gpio6c_iomux);
3360 if (ret) {
3361 pinctrl_force_default(info->pctl_dev);
3362 return ret;
3363 }
3364 }
3365
3366 return 0;
Chris Zhong9198f502014-10-29 19:51:59 +08003367}
3368
3369static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
3370{
3371 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08003372 int ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3373 rk3288_grf_gpio6c_iomux |
3374 GPIO6C6_SEL_WRITE_ENABLE);
3375
3376 if (ret)
3377 return ret;
Chris Zhong9198f502014-10-29 19:51:59 +08003378
3379 return pinctrl_force_default(info->pctl_dev);
3380}
3381
3382static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
3383 rockchip_pinctrl_resume);
3384
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003385static int rockchip_pinctrl_probe(struct platform_device *pdev)
3386{
3387 struct rockchip_pinctrl *info;
3388 struct device *dev = &pdev->dev;
3389 struct rockchip_pin_ctrl *ctrl;
Heiko Stübner14dee862014-05-05 13:59:09 +02003390 struct device_node *np = pdev->dev.of_node, *node;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003391 struct resource *res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02003392 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003393 int ret;
3394
3395 if (!dev->of_node) {
3396 dev_err(dev, "device tree node not found\n");
3397 return -ENODEV;
3398 }
3399
Markus Elfring283b7ac2017-12-23 22:07:30 +01003400 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003401 if (!info)
3402 return -ENOMEM;
3403
Heiko Stübner622f3232014-05-05 13:58:46 +02003404 info->dev = dev;
3405
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003406 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
3407 if (!ctrl) {
3408 dev_err(dev, "driver data not available\n");
3409 return -EINVAL;
3410 }
3411 info->ctrl = ctrl;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003412
Heiko Stübner1e747e52014-05-05 13:59:51 +02003413 node = of_parse_phandle(np, "rockchip,grf", 0);
3414 if (node) {
3415 info->regmap_base = syscon_node_to_regmap(node);
3416 if (IS_ERR(info->regmap_base))
3417 return PTR_ERR(info->regmap_base);
3418 } else {
3419 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Heiko Stübner751a99a2014-05-05 13:58:20 +02003420 base = devm_ioremap_resource(&pdev->dev, res);
3421 if (IS_ERR(base))
3422 return PTR_ERR(base);
3423
3424 rockchip_regmap_config.max_register = resource_size(res) - 4;
Heiko Stübner1e747e52014-05-05 13:59:51 +02003425 rockchip_regmap_config.name = "rockchip,pinctrl";
3426 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
3427 &rockchip_regmap_config);
3428
3429 /* to check for the old dt-bindings */
3430 info->reg_size = resource_size(res);
3431
3432 /* Honor the old binding, with pull registers as 2nd resource */
3433 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
3434 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3435 base = devm_ioremap_resource(&pdev->dev, res);
3436 if (IS_ERR(base))
3437 return PTR_ERR(base);
3438
3439 rockchip_regmap_config.max_register =
3440 resource_size(res) - 4;
3441 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
3442 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
3443 base,
3444 &rockchip_regmap_config);
3445 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003446 }
3447
Heiko Stübner14dee862014-05-05 13:59:09 +02003448 /* try to find the optional reference to the pmu syscon */
3449 node = of_parse_phandle(np, "rockchip,pmu", 0);
3450 if (node) {
3451 info->regmap_pmu = syscon_node_to_regmap(node);
3452 if (IS_ERR(info->regmap_pmu))
3453 return PTR_ERR(info->regmap_pmu);
3454 }
3455
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003456 ret = rockchip_gpiolib_register(pdev, info);
3457 if (ret)
3458 return ret;
3459
3460 ret = rockchip_pinctrl_register(pdev, info);
3461 if (ret) {
3462 rockchip_gpiolib_unregister(pdev, info);
3463 return ret;
3464 }
3465
3466 platform_set_drvdata(pdev, info);
3467
3468 return 0;
3469}
3470
David Wu87065ca2018-05-14 19:59:51 +08003471static struct rockchip_pin_bank px30_pin_banks[] = {
3472 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3473 IOMUX_SOURCE_PMU,
3474 IOMUX_SOURCE_PMU,
3475 IOMUX_SOURCE_PMU
3476 ),
3477 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3478 IOMUX_WIDTH_4BIT,
3479 IOMUX_WIDTH_4BIT,
3480 IOMUX_WIDTH_4BIT
3481 ),
3482 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3483 IOMUX_WIDTH_4BIT,
3484 IOMUX_WIDTH_4BIT,
3485 IOMUX_WIDTH_4BIT
3486 ),
3487 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3488 IOMUX_WIDTH_4BIT,
3489 IOMUX_WIDTH_4BIT,
3490 IOMUX_WIDTH_4BIT
3491 ),
3492};
3493
3494static struct rockchip_pin_ctrl px30_pin_ctrl = {
3495 .pin_banks = px30_pin_banks,
3496 .nr_banks = ARRAY_SIZE(px30_pin_banks),
3497 .label = "PX30-GPIO",
3498 .type = PX30,
3499 .grf_mux_offset = 0x0,
3500 .pmu_mux_offset = 0x0,
3501 .iomux_routes = px30_mux_route_data,
3502 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
3503 .pull_calc_reg = px30_calc_pull_reg_and_bit,
3504 .drv_calc_reg = px30_calc_drv_reg_and_bit,
3505 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
3506};
3507
Andy Yanb9c6dca2017-03-17 18:18:36 +01003508static struct rockchip_pin_bank rv1108_pin_banks[] = {
Andy Yan688daf22016-11-15 18:02:43 +08003509 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3510 IOMUX_SOURCE_PMU,
3511 IOMUX_SOURCE_PMU,
3512 IOMUX_SOURCE_PMU),
3513 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3514 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3515 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3516};
3517
Andy Yanb9c6dca2017-03-17 18:18:36 +01003518static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
3519 .pin_banks = rv1108_pin_banks,
3520 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
3521 .label = "RV1108-GPIO",
3522 .type = RV1108,
Andy Yan688daf22016-11-15 18:02:43 +08003523 .grf_mux_offset = 0x10,
3524 .pmu_mux_offset = 0x0,
David Wu12b8f012017-08-23 16:00:07 +08003525 .iomux_recalced = rv1108_mux_recalced_data,
3526 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
Andy Yanb9c6dca2017-03-17 18:18:36 +01003527 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
3528 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
Andy Yan5caff7e2017-07-31 18:10:22 +08003529 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
Andy Yan688daf22016-11-15 18:02:43 +08003530};
3531
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003532static struct rockchip_pin_bank rk2928_pin_banks[] = {
3533 PIN_BANK(0, 32, "gpio0"),
3534 PIN_BANK(1, 32, "gpio1"),
3535 PIN_BANK(2, 32, "gpio2"),
3536 PIN_BANK(3, 32, "gpio3"),
3537};
3538
3539static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
3540 .pin_banks = rk2928_pin_banks,
3541 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
3542 .label = "RK2928-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003543 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003544 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003545 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003546};
3547
Xing Zhengc5ce7672015-08-28 13:46:47 +08003548static struct rockchip_pin_bank rk3036_pin_banks[] = {
3549 PIN_BANK(0, 32, "gpio0"),
3550 PIN_BANK(1, 32, "gpio1"),
3551 PIN_BANK(2, 32, "gpio2"),
3552};
3553
3554static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
3555 .pin_banks = rk3036_pin_banks,
3556 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
3557 .label = "RK3036-GPIO",
3558 .type = RK2928,
3559 .grf_mux_offset = 0xa8,
3560 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3561};
3562
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003563static struct rockchip_pin_bank rk3066a_pin_banks[] = {
3564 PIN_BANK(0, 32, "gpio0"),
3565 PIN_BANK(1, 32, "gpio1"),
3566 PIN_BANK(2, 32, "gpio2"),
3567 PIN_BANK(3, 32, "gpio3"),
3568 PIN_BANK(4, 32, "gpio4"),
3569 PIN_BANK(6, 16, "gpio6"),
3570};
3571
3572static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
3573 .pin_banks = rk3066a_pin_banks,
3574 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
3575 .label = "RK3066a-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003576 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003577 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003578 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003579};
3580
3581static struct rockchip_pin_bank rk3066b_pin_banks[] = {
3582 PIN_BANK(0, 32, "gpio0"),
3583 PIN_BANK(1, 32, "gpio1"),
3584 PIN_BANK(2, 32, "gpio2"),
3585 PIN_BANK(3, 32, "gpio3"),
3586};
3587
3588static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
3589 .pin_banks = rk3066b_pin_banks,
3590 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
3591 .label = "RK3066b-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003592 .type = RK3066B,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003593 .grf_mux_offset = 0x60,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003594};
3595
David Wud23c66d2017-07-21 14:27:15 +08003596static struct rockchip_pin_bank rk3128_pin_banks[] = {
3597 PIN_BANK(0, 32, "gpio0"),
3598 PIN_BANK(1, 32, "gpio1"),
3599 PIN_BANK(2, 32, "gpio2"),
3600 PIN_BANK(3, 32, "gpio3"),
3601};
3602
3603static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
3604 .pin_banks = rk3128_pin_banks,
3605 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
3606 .label = "RK3128-GPIO",
3607 .type = RK3128,
3608 .grf_mux_offset = 0xa8,
3609 .iomux_recalced = rk3128_mux_recalced_data,
3610 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
3611 .iomux_routes = rk3128_mux_route_data,
3612 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
3613 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
3614};
3615
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003616static struct rockchip_pin_bank rk3188_pin_banks[] = {
Heiko Stübnerfc72c922014-06-16 01:36:05 +02003617 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003618 PIN_BANK(1, 32, "gpio1"),
3619 PIN_BANK(2, 32, "gpio2"),
3620 PIN_BANK(3, 32, "gpio3"),
3621};
3622
3623static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
3624 .pin_banks = rk3188_pin_banks,
3625 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
3626 .label = "RK3188-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003627 .type = RK3188,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003628 .grf_mux_offset = 0x60,
Heiko Stübner6ca52742013-10-16 01:08:42 +02003629 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003630};
3631
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003632static struct rockchip_pin_bank rk3228_pin_banks[] = {
3633 PIN_BANK(0, 32, "gpio0"),
3634 PIN_BANK(1, 32, "gpio1"),
3635 PIN_BANK(2, 32, "gpio2"),
3636 PIN_BANK(3, 32, "gpio3"),
3637};
3638
3639static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
3640 .pin_banks = rk3228_pin_banks,
3641 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
3642 .label = "RK3228-GPIO",
3643 .type = RK3288,
3644 .grf_mux_offset = 0x0,
David Wud4970ee2017-05-26 15:20:21 +08003645 .iomux_routes = rk3228_mux_route_data,
3646 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003647 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3648 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3649};
3650
Heiko Stübner304f0772014-06-16 01:38:14 +02003651static struct rockchip_pin_bank rk3288_pin_banks[] = {
3652 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
3653 IOMUX_SOURCE_PMU,
3654 IOMUX_SOURCE_PMU,
3655 IOMUX_UNROUTED
3656 ),
3657 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
3658 IOMUX_UNROUTED,
3659 IOMUX_UNROUTED,
3660 0
3661 ),
3662 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3663 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3664 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3665 IOMUX_WIDTH_4BIT,
3666 0,
3667 0
3668 ),
3669 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3670 0,
3671 0,
3672 IOMUX_UNROUTED
3673 ),
3674 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3675 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3676 0,
3677 IOMUX_WIDTH_4BIT,
3678 IOMUX_UNROUTED
3679 ),
3680 PIN_BANK(8, 16, "gpio8"),
3681};
3682
3683static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3684 .pin_banks = rk3288_pin_banks,
3685 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3686 .label = "RK3288-GPIO",
Heiko Stübner66d750e2014-07-20 01:49:17 +02003687 .type = RK3288,
Heiko Stübner304f0772014-06-16 01:38:14 +02003688 .grf_mux_offset = 0x0,
3689 .pmu_mux_offset = 0x84,
Heiko Stuebner4e96fd32017-10-21 10:53:10 +02003690 .iomux_routes = rk3288_mux_route_data,
3691 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
Heiko Stübner304f0772014-06-16 01:38:14 +02003692 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
Heiko Stübneref17f692015-06-12 23:50:11 +02003693 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
Heiko Stübner304f0772014-06-16 01:38:14 +02003694};
3695
david.wu3818e4a2017-02-10 18:23:49 +08003696static struct rockchip_pin_bank rk3328_pin_banks[] = {
3697 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3698 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3699 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
David Wuc04c3fa2017-07-21 14:27:14 +08003700 IOMUX_WIDTH_3BIT,
3701 IOMUX_WIDTH_3BIT,
david.wu3818e4a2017-02-10 18:23:49 +08003702 0),
3703 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3704 IOMUX_WIDTH_3BIT,
David Wuc04c3fa2017-07-21 14:27:14 +08003705 IOMUX_WIDTH_3BIT,
david.wu3818e4a2017-02-10 18:23:49 +08003706 0,
3707 0),
3708};
3709
3710static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3711 .pin_banks = rk3328_pin_banks,
3712 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3713 .label = "RK3328-GPIO",
3714 .type = RK3288,
3715 .grf_mux_offset = 0x0,
David Wuc04c3fa2017-07-21 14:27:14 +08003716 .iomux_recalced = rk3328_mux_recalced_data,
3717 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
David Wucedc9642017-05-26 15:20:22 +08003718 .iomux_routes = rk3328_mux_route_data,
3719 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
david.wu3818e4a2017-02-10 18:23:49 +08003720 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3721 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
david.wu728d3f52017-03-02 15:11:24 +08003722 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
david.wu3818e4a2017-02-10 18:23:49 +08003723};
3724
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003725static struct rockchip_pin_bank rk3368_pin_banks[] = {
3726 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3727 IOMUX_SOURCE_PMU,
3728 IOMUX_SOURCE_PMU,
3729 IOMUX_SOURCE_PMU
3730 ),
3731 PIN_BANK(1, 32, "gpio1"),
3732 PIN_BANK(2, 32, "gpio2"),
3733 PIN_BANK(3, 32, "gpio3"),
3734};
3735
3736static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3737 .pin_banks = rk3368_pin_banks,
3738 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3739 .label = "RK3368-GPIO",
3740 .type = RK3368,
3741 .grf_mux_offset = 0x0,
3742 .pmu_mux_offset = 0x0,
3743 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3744 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3745};
3746
David Wub6c23272016-02-01 10:58:21 +08003747static struct rockchip_pin_bank rk3399_pin_banks[] = {
David Wu3ba67672016-05-11 11:39:28 +08003748 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3749 IOMUX_SOURCE_PMU,
3750 IOMUX_SOURCE_PMU,
3751 IOMUX_SOURCE_PMU,
3752 IOMUX_SOURCE_PMU,
3753 DRV_TYPE_IO_1V8_ONLY,
3754 DRV_TYPE_IO_1V8_ONLY,
3755 DRV_TYPE_IO_DEFAULT,
3756 DRV_TYPE_IO_DEFAULT,
David Wuc437f652017-09-30 20:13:20 +08003757 0x80,
3758 0x88,
David Wu3ba67672016-05-11 11:39:28 +08003759 -1,
3760 -1,
3761 PULL_TYPE_IO_1V8_ONLY,
3762 PULL_TYPE_IO_1V8_ONLY,
3763 PULL_TYPE_IO_DEFAULT,
3764 PULL_TYPE_IO_DEFAULT
3765 ),
David Wub6c23272016-02-01 10:58:21 +08003766 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3767 IOMUX_SOURCE_PMU,
3768 IOMUX_SOURCE_PMU,
3769 IOMUX_SOURCE_PMU,
3770 DRV_TYPE_IO_1V8_OR_3V0,
3771 DRV_TYPE_IO_1V8_OR_3V0,
3772 DRV_TYPE_IO_1V8_OR_3V0,
3773 DRV_TYPE_IO_1V8_OR_3V0,
David Wuc437f652017-09-30 20:13:20 +08003774 0xa0,
3775 0xa8,
3776 0xb0,
3777 0xb8
David Wub6c23272016-02-01 10:58:21 +08003778 ),
David Wu3ba67672016-05-11 11:39:28 +08003779 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3780 DRV_TYPE_IO_1V8_OR_3V0,
3781 DRV_TYPE_IO_1V8_ONLY,
3782 DRV_TYPE_IO_1V8_ONLY,
3783 PULL_TYPE_IO_DEFAULT,
3784 PULL_TYPE_IO_DEFAULT,
3785 PULL_TYPE_IO_1V8_ONLY,
3786 PULL_TYPE_IO_1V8_ONLY
3787 ),
David Wub6c23272016-02-01 10:58:21 +08003788 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3789 DRV_TYPE_IO_3V3_ONLY,
3790 DRV_TYPE_IO_3V3_ONLY,
3791 DRV_TYPE_IO_1V8_OR_3V0
3792 ),
3793 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3794 DRV_TYPE_IO_1V8_3V0_AUTO,
3795 DRV_TYPE_IO_1V8_OR_3V0,
3796 DRV_TYPE_IO_1V8_OR_3V0
3797 ),
3798};
3799
3800static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3801 .pin_banks = rk3399_pin_banks,
3802 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3803 .label = "RK3399-GPIO",
3804 .type = RK3399,
3805 .grf_mux_offset = 0xe000,
3806 .pmu_mux_offset = 0x0,
3807 .grf_drv_offset = 0xe100,
3808 .pmu_drv_offset = 0x80,
David Wuaccc1ce2017-05-26 15:20:23 +08003809 .iomux_routes = rk3399_mux_route_data,
3810 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
David Wub6c23272016-02-01 10:58:21 +08003811 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3812 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3813};
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003814
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003815static const struct of_device_id rockchip_pinctrl_dt_match[] = {
David Wu87065ca2018-05-14 19:59:51 +08003816 { .compatible = "rockchip,px30-pinctrl",
3817 .data = &px30_pin_ctrl },
Andy Yanb9c6dca2017-03-17 18:18:36 +01003818 { .compatible = "rockchip,rv1108-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003819 .data = &rv1108_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003820 { .compatible = "rockchip,rk2928-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003821 .data = &rk2928_pin_ctrl },
Xing Zhengc5ce7672015-08-28 13:46:47 +08003822 { .compatible = "rockchip,rk3036-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003823 .data = &rk3036_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003824 { .compatible = "rockchip,rk3066a-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003825 .data = &rk3066a_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003826 { .compatible = "rockchip,rk3066b-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003827 .data = &rk3066b_pin_ctrl },
David Wud23c66d2017-07-21 14:27:15 +08003828 { .compatible = "rockchip,rk3128-pinctrl",
3829 .data = (void *)&rk3128_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003830 { .compatible = "rockchip,rk3188-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003831 .data = &rk3188_pin_ctrl },
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003832 { .compatible = "rockchip,rk3228-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003833 .data = &rk3228_pin_ctrl },
Heiko Stübner304f0772014-06-16 01:38:14 +02003834 { .compatible = "rockchip,rk3288-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003835 .data = &rk3288_pin_ctrl },
david.wu3818e4a2017-02-10 18:23:49 +08003836 { .compatible = "rockchip,rk3328-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003837 .data = &rk3328_pin_ctrl },
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003838 { .compatible = "rockchip,rk3368-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003839 .data = &rk3368_pin_ctrl },
David Wub6c23272016-02-01 10:58:21 +08003840 { .compatible = "rockchip,rk3399-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003841 .data = &rk3399_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003842 {},
3843};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003844
3845static struct platform_driver rockchip_pinctrl_driver = {
3846 .probe = rockchip_pinctrl_probe,
3847 .driver = {
3848 .name = "rockchip-pinctrl",
Chris Zhong9198f502014-10-29 19:51:59 +08003849 .pm = &rockchip_pinctrl_dev_pm_ops,
Axel Lin0be9e702013-08-23 14:27:53 +08003850 .of_match_table = rockchip_pinctrl_dt_match,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003851 },
3852};
3853
3854static int __init rockchip_pinctrl_drv_register(void)
3855{
3856 return platform_driver_register(&rockchip_pinctrl_driver);
3857}
3858postcore_initcall(rockchip_pinctrl_drv_register);