blob: 95e4a06de01918159253610afa9532fec27453e8 [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
310/**
311 * struct rockchip_mux_recalced_data: represent a pin iomux data.
David Wubd35b9b2017-05-26 15:20:20 +0800312 * @bank_num: bank number.
313 * @pin: index at register or used to calc index.
314 * @func: the min pin.
315 * @route_offset: the max pin.
316 * @route_val: the register offset.
317 */
318struct rockchip_mux_route_data {
319 u8 bank_num;
320 u8 pin;
321 u8 func;
322 u32 route_offset;
323 u32 route_val;
324};
325
326/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200327 */
328struct rockchip_pin_ctrl {
329 struct rockchip_pin_bank *pin_banks;
330 u32 nr_banks;
331 u32 nr_pins;
332 char *label;
Heiko Stübnera2829262013-10-16 01:07:20 +0200333 enum rockchip_pinctrl_type type;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200334 int grf_mux_offset;
335 int pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +0800336 int grf_drv_offset;
337 int pmu_drv_offset;
David Wuc04c3fa2017-07-21 14:27:14 +0800338 struct rockchip_mux_recalced_data *iomux_recalced;
339 u32 niomux_recalced;
David Wubd35b9b2017-05-26 15:20:20 +0800340 struct rockchip_mux_route_data *iomux_routes;
341 u32 niomux_routes;
David Wub6c23272016-02-01 10:58:21 +0800342
Heiko Stübner751a99a2014-05-05 13:58:20 +0200343 void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
344 int pin_num, struct regmap **regmap,
345 int *reg, u8 *bit);
Heiko Stübneref17f692015-06-12 23:50:11 +0200346 void (*drv_calc_reg)(struct rockchip_pin_bank *bank,
347 int pin_num, struct regmap **regmap,
348 int *reg, u8 *bit);
david.wue3b357d2017-03-02 15:11:23 +0800349 int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
350 int pin_num, struct regmap **regmap,
351 int *reg, u8 *bit);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200352};
353
354struct rockchip_pin_config {
355 unsigned int func;
356 unsigned long *configs;
357 unsigned int nconfigs;
358};
359
360/**
361 * struct rockchip_pin_group: represent group of pins of a pinmux function.
362 * @name: name of the pin group, used to lookup the group.
363 * @pins: the pins included in this group.
364 * @npins: number of pins included in this group.
365 * @func: the mux function number to be programmed when selected.
366 * @configs: the config values to be set for each pin
367 * @nconfigs: number of configs for each pin
368 */
369struct rockchip_pin_group {
370 const char *name;
371 unsigned int npins;
372 unsigned int *pins;
373 struct rockchip_pin_config *data;
374};
375
376/**
377 * struct rockchip_pmx_func: represent a pin function.
378 * @name: name of the pin function, used to lookup the function.
379 * @groups: one or more names of pin groups that provide this function.
380 * @num_groups: number of groups included in @groups.
381 */
382struct rockchip_pmx_func {
383 const char *name;
384 const char **groups;
385 u8 ngroups;
386};
387
388struct rockchip_pinctrl {
Heiko Stübner751a99a2014-05-05 13:58:20 +0200389 struct regmap *regmap_base;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200390 int reg_size;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200391 struct regmap *regmap_pull;
Heiko Stübner14dee862014-05-05 13:59:09 +0200392 struct regmap *regmap_pmu;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200393 struct device *dev;
394 struct rockchip_pin_ctrl *ctrl;
395 struct pinctrl_desc pctl;
396 struct pinctrl_dev *pctl_dev;
397 struct rockchip_pin_group *groups;
398 unsigned int ngroups;
399 struct rockchip_pmx_func *functions;
400 unsigned int nfunctions;
401};
402
Heiko Stübner751a99a2014-05-05 13:58:20 +0200403static struct regmap_config rockchip_regmap_config = {
404 .reg_bits = 32,
405 .val_bits = 32,
406 .reg_stride = 4,
407};
408
Arnd Bergmann56411f32016-06-13 17:18:34 +0200409static inline const struct rockchip_pin_group *pinctrl_name_to_group(
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200410 const struct rockchip_pinctrl *info,
411 const char *name)
412{
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200413 int i;
414
415 for (i = 0; i < info->ngroups; i++) {
Axel Lin1cb95392013-08-21 10:28:50 +0800416 if (!strcmp(info->groups[i].name, name))
417 return &info->groups[i];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200418 }
419
Axel Lin1cb95392013-08-21 10:28:50 +0800420 return NULL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200421}
422
423/*
424 * given a pin number that is local to a pin controller, find out the pin bank
425 * and the register base of the pin bank.
426 */
427static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
428 unsigned pin)
429{
430 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
431
Axel Lin51578b92013-08-23 15:49:00 +0800432 while (pin >= (b->pin_base + b->nr_pins))
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200433 b++;
434
435 return b;
436}
437
438static struct rockchip_pin_bank *bank_num_to_bank(
439 struct rockchip_pinctrl *info,
440 unsigned num)
441{
442 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
443 int i;
444
Axel Lin1cb95392013-08-21 10:28:50 +0800445 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200446 if (b->bank_num == num)
Axel Lin1cb95392013-08-21 10:28:50 +0800447 return b;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200448 }
449
Axel Lin1cb95392013-08-21 10:28:50 +0800450 return ERR_PTR(-EINVAL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200451}
452
453/*
454 * Pinctrl_ops handling
455 */
456
457static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
458{
459 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
460
461 return info->ngroups;
462}
463
464static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
465 unsigned selector)
466{
467 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
468
469 return info->groups[selector].name;
470}
471
472static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
473 unsigned selector, const unsigned **pins,
474 unsigned *npins)
475{
476 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
477
478 if (selector >= info->ngroups)
479 return -EINVAL;
480
481 *pins = info->groups[selector].pins;
482 *npins = info->groups[selector].npins;
483
484 return 0;
485}
486
487static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
488 struct device_node *np,
489 struct pinctrl_map **map, unsigned *num_maps)
490{
491 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
492 const struct rockchip_pin_group *grp;
493 struct pinctrl_map *new_map;
494 struct device_node *parent;
495 int map_num = 1;
496 int i;
497
498 /*
499 * first find the group of this node and check if we need to create
500 * config maps for pins
501 */
502 grp = pinctrl_name_to_group(info, np->name);
503 if (!grp) {
Rob Herring94f4e542018-08-27 20:52:41 -0500504 dev_err(info->dev, "unable to find group for node %pOFn\n",
505 np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200506 return -EINVAL;
507 }
508
509 map_num += grp->npins;
Kees Cooka86854d2018-06-12 14:07:58 -0700510 new_map = devm_kcalloc(pctldev->dev, map_num, sizeof(*new_map),
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200511 GFP_KERNEL);
512 if (!new_map)
513 return -ENOMEM;
514
515 *map = new_map;
516 *num_maps = map_num;
517
518 /* create mux map */
519 parent = of_get_parent(np);
520 if (!parent) {
521 devm_kfree(pctldev->dev, new_map);
522 return -EINVAL;
523 }
524 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
525 new_map[0].data.mux.function = parent->name;
526 new_map[0].data.mux.group = np->name;
527 of_node_put(parent);
528
529 /* create config map */
530 new_map++;
531 for (i = 0; i < grp->npins; i++) {
532 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
533 new_map[i].data.configs.group_or_pin =
534 pin_get_name(pctldev, grp->pins[i]);
535 new_map[i].data.configs.configs = grp->data[i].configs;
536 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
537 }
538
539 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
540 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
541
542 return 0;
543}
544
545static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
546 struct pinctrl_map *map, unsigned num_maps)
547{
548}
549
550static const struct pinctrl_ops rockchip_pctrl_ops = {
551 .get_groups_count = rockchip_get_groups_count,
552 .get_group_name = rockchip_get_group_name,
553 .get_group_pins = rockchip_get_group_pins,
554 .dt_node_to_map = rockchip_dt_node_to_map,
555 .dt_free_map = rockchip_dt_free_map,
556};
557
558/*
559 * Hardware access
560 */
561
David Wu12b8f012017-08-23 16:00:07 +0800562static struct rockchip_mux_recalced_data rv1108_mux_recalced_data[] = {
563 {
564 .num = 1,
565 .pin = 0,
566 .reg = 0x418,
567 .bit = 0,
568 .mask = 0x3
569 }, {
570 .num = 1,
571 .pin = 1,
572 .reg = 0x418,
573 .bit = 2,
574 .mask = 0x3
575 }, {
576 .num = 1,
577 .pin = 2,
578 .reg = 0x418,
579 .bit = 4,
580 .mask = 0x3
581 }, {
582 .num = 1,
583 .pin = 3,
584 .reg = 0x418,
585 .bit = 6,
586 .mask = 0x3
587 }, {
588 .num = 1,
589 .pin = 4,
590 .reg = 0x418,
591 .bit = 8,
592 .mask = 0x3
593 }, {
594 .num = 1,
595 .pin = 5,
596 .reg = 0x418,
597 .bit = 10,
598 .mask = 0x3
599 }, {
600 .num = 1,
601 .pin = 6,
602 .reg = 0x418,
603 .bit = 12,
604 .mask = 0x3
605 }, {
606 .num = 1,
607 .pin = 7,
608 .reg = 0x418,
609 .bit = 14,
610 .mask = 0x3
611 }, {
612 .num = 1,
613 .pin = 8,
614 .reg = 0x41c,
615 .bit = 0,
616 .mask = 0x3
617 }, {
618 .num = 1,
619 .pin = 9,
620 .reg = 0x41c,
621 .bit = 2,
622 .mask = 0x3
623 },
624};
625
David Wud23c66d2017-07-21 14:27:15 +0800626static struct rockchip_mux_recalced_data rk3128_mux_recalced_data[] = {
627 {
628 .num = 2,
629 .pin = 20,
630 .reg = 0xe8,
631 .bit = 0,
632 .mask = 0x7
633 }, {
634 .num = 2,
635 .pin = 21,
636 .reg = 0xe8,
637 .bit = 4,
638 .mask = 0x7
639 }, {
640 .num = 2,
641 .pin = 22,
642 .reg = 0xe8,
643 .bit = 8,
644 .mask = 0x7
645 }, {
646 .num = 2,
647 .pin = 23,
648 .reg = 0xe8,
649 .bit = 12,
650 .mask = 0x7
651 }, {
652 .num = 2,
653 .pin = 24,
654 .reg = 0xd4,
655 .bit = 12,
656 .mask = 0x7
657 },
658};
659
David Wuc04c3fa2017-07-21 14:27:14 +0800660static struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
david.wu3818e4a2017-02-10 18:23:49 +0800661 {
662 .num = 2,
663 .pin = 12,
664 .reg = 0x24,
665 .bit = 8,
666 .mask = 0x3
667 }, {
668 .num = 2,
669 .pin = 15,
670 .reg = 0x28,
671 .bit = 0,
672 .mask = 0x7
673 }, {
674 .num = 2,
675 .pin = 23,
676 .reg = 0x30,
677 .bit = 14,
678 .mask = 0x3
679 },
680};
681
David Wuc04c3fa2017-07-21 14:27:14 +0800682static void rockchip_get_recalced_mux(struct rockchip_pin_bank *bank, int pin,
683 int *reg, u8 *bit, int *mask)
david.wu3818e4a2017-02-10 18:23:49 +0800684{
David Wuc04c3fa2017-07-21 14:27:14 +0800685 struct rockchip_pinctrl *info = bank->drvdata;
686 struct rockchip_pin_ctrl *ctrl = info->ctrl;
687 struct rockchip_mux_recalced_data *data;
david.wu3818e4a2017-02-10 18:23:49 +0800688 int i;
689
David Wuc04c3fa2017-07-21 14:27:14 +0800690 for (i = 0; i < ctrl->niomux_recalced; i++) {
691 data = &ctrl->iomux_recalced[i];
692 if (data->num == bank->bank_num &&
693 data->pin == pin)
david.wu3818e4a2017-02-10 18:23:49 +0800694 break;
David Wuc04c3fa2017-07-21 14:27:14 +0800695 }
david.wu3818e4a2017-02-10 18:23:49 +0800696
David Wuc04c3fa2017-07-21 14:27:14 +0800697 if (i >= ctrl->niomux_recalced)
david.wu3818e4a2017-02-10 18:23:49 +0800698 return;
699
700 *reg = data->reg;
701 *mask = data->mask;
702 *bit = data->bit;
703}
704
David Wu87065ca2018-05-14 19:59:51 +0800705static struct rockchip_mux_route_data px30_mux_route_data[] = {
706 {
707 /* cif-d2m0 */
708 .bank_num = 2,
709 .pin = 0,
710 .func = 1,
711 .route_offset = 0x184,
712 .route_val = BIT(16 + 7),
713 }, {
714 /* cif-d2m1 */
715 .bank_num = 3,
716 .pin = 3,
717 .func = 3,
718 .route_offset = 0x184,
719 .route_val = BIT(16 + 7) | BIT(7),
720 }, {
721 /* pdm-m0 */
722 .bank_num = 3,
723 .pin = 22,
724 .func = 2,
725 .route_offset = 0x184,
726 .route_val = BIT(16 + 8),
727 }, {
728 /* pdm-m1 */
729 .bank_num = 2,
730 .pin = 22,
731 .func = 1,
732 .route_offset = 0x184,
733 .route_val = BIT(16 + 8) | BIT(8),
734 }, {
735 /* uart2-rxm0 */
736 .bank_num = 1,
737 .pin = 27,
738 .func = 2,
739 .route_offset = 0x184,
740 .route_val = BIT(16 + 10),
741 }, {
742 /* uart2-rxm1 */
743 .bank_num = 2,
744 .pin = 14,
745 .func = 2,
746 .route_offset = 0x184,
747 .route_val = BIT(16 + 10) | BIT(10),
748 }, {
749 /* uart3-rxm0 */
750 .bank_num = 0,
751 .pin = 17,
752 .func = 2,
753 .route_offset = 0x184,
754 .route_val = BIT(16 + 9),
755 }, {
756 /* uart3-rxm1 */
757 .bank_num = 1,
758 .pin = 15,
759 .func = 2,
760 .route_offset = 0x184,
761 .route_val = BIT(16 + 9) | BIT(9),
762 },
763};
764
David Wud23c66d2017-07-21 14:27:15 +0800765static struct rockchip_mux_route_data rk3128_mux_route_data[] = {
766 {
767 /* spi-0 */
768 .bank_num = 1,
769 .pin = 10,
770 .func = 1,
771 .route_offset = 0x144,
772 .route_val = BIT(16 + 3) | BIT(16 + 4),
773 }, {
774 /* spi-1 */
775 .bank_num = 1,
776 .pin = 27,
777 .func = 3,
778 .route_offset = 0x144,
779 .route_val = BIT(16 + 3) | BIT(16 + 4) | BIT(3),
780 }, {
781 /* spi-2 */
782 .bank_num = 0,
783 .pin = 13,
784 .func = 2,
785 .route_offset = 0x144,
786 .route_val = BIT(16 + 3) | BIT(16 + 4) | BIT(4),
787 }, {
788 /* i2s-0 */
789 .bank_num = 1,
790 .pin = 5,
791 .func = 1,
792 .route_offset = 0x144,
793 .route_val = BIT(16 + 5),
794 }, {
795 /* i2s-1 */
796 .bank_num = 0,
797 .pin = 14,
798 .func = 1,
799 .route_offset = 0x144,
800 .route_val = BIT(16 + 5) | BIT(5),
801 }, {
802 /* emmc-0 */
803 .bank_num = 1,
804 .pin = 22,
805 .func = 2,
806 .route_offset = 0x144,
807 .route_val = BIT(16 + 6),
808 }, {
809 /* emmc-1 */
810 .bank_num = 2,
811 .pin = 4,
812 .func = 2,
813 .route_offset = 0x144,
814 .route_val = BIT(16 + 6) | BIT(6),
815 },
816};
817
David Wud4970ee2017-05-26 15:20:21 +0800818static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
819 {
820 /* pwm0-0 */
821 .bank_num = 0,
822 .pin = 26,
823 .func = 1,
824 .route_offset = 0x50,
825 .route_val = BIT(16),
826 }, {
827 /* pwm0-1 */
828 .bank_num = 3,
829 .pin = 21,
830 .func = 1,
831 .route_offset = 0x50,
832 .route_val = BIT(16) | BIT(0),
833 }, {
834 /* pwm1-0 */
835 .bank_num = 0,
836 .pin = 27,
837 .func = 1,
838 .route_offset = 0x50,
839 .route_val = BIT(16 + 1),
840 }, {
841 /* pwm1-1 */
842 .bank_num = 0,
843 .pin = 30,
844 .func = 2,
845 .route_offset = 0x50,
846 .route_val = BIT(16 + 1) | BIT(1),
847 }, {
848 /* pwm2-0 */
849 .bank_num = 0,
850 .pin = 28,
851 .func = 1,
852 .route_offset = 0x50,
853 .route_val = BIT(16 + 2),
854 }, {
855 /* pwm2-1 */
856 .bank_num = 1,
857 .pin = 12,
858 .func = 2,
859 .route_offset = 0x50,
860 .route_val = BIT(16 + 2) | BIT(2),
861 }, {
862 /* pwm3-0 */
863 .bank_num = 3,
864 .pin = 26,
865 .func = 1,
866 .route_offset = 0x50,
867 .route_val = BIT(16 + 3),
868 }, {
869 /* pwm3-1 */
870 .bank_num = 1,
871 .pin = 11,
872 .func = 2,
873 .route_offset = 0x50,
874 .route_val = BIT(16 + 3) | BIT(3),
875 }, {
876 /* sdio-0_d0 */
877 .bank_num = 1,
878 .pin = 1,
879 .func = 1,
880 .route_offset = 0x50,
881 .route_val = BIT(16 + 4),
882 }, {
883 /* sdio-1_d0 */
884 .bank_num = 3,
885 .pin = 2,
886 .func = 1,
887 .route_offset = 0x50,
888 .route_val = BIT(16 + 4) | BIT(4),
889 }, {
890 /* spi-0_rx */
891 .bank_num = 0,
892 .pin = 13,
893 .func = 2,
894 .route_offset = 0x50,
895 .route_val = BIT(16 + 5),
896 }, {
897 /* spi-1_rx */
898 .bank_num = 2,
899 .pin = 0,
900 .func = 2,
901 .route_offset = 0x50,
902 .route_val = BIT(16 + 5) | BIT(5),
903 }, {
904 /* emmc-0_cmd */
905 .bank_num = 1,
906 .pin = 22,
907 .func = 2,
908 .route_offset = 0x50,
909 .route_val = BIT(16 + 7),
910 }, {
911 /* emmc-1_cmd */
912 .bank_num = 2,
913 .pin = 4,
914 .func = 2,
915 .route_offset = 0x50,
916 .route_val = BIT(16 + 7) | BIT(7),
917 }, {
918 /* uart2-0_rx */
919 .bank_num = 1,
920 .pin = 19,
921 .func = 2,
922 .route_offset = 0x50,
923 .route_val = BIT(16 + 8),
924 }, {
925 /* uart2-1_rx */
926 .bank_num = 1,
927 .pin = 10,
928 .func = 2,
929 .route_offset = 0x50,
930 .route_val = BIT(16 + 8) | BIT(8),
931 }, {
932 /* uart1-0_rx */
933 .bank_num = 1,
934 .pin = 10,
935 .func = 1,
936 .route_offset = 0x50,
937 .route_val = BIT(16 + 11),
938 }, {
939 /* uart1-1_rx */
940 .bank_num = 3,
941 .pin = 13,
942 .func = 1,
943 .route_offset = 0x50,
944 .route_val = BIT(16 + 11) | BIT(11),
945 },
946};
947
Heiko Stuebner4e96fd32017-10-21 10:53:10 +0200948static struct rockchip_mux_route_data rk3288_mux_route_data[] = {
949 {
950 /* edphdmi_cecinoutt1 */
951 .bank_num = 7,
952 .pin = 16,
953 .func = 2,
954 .route_offset = 0x264,
955 .route_val = BIT(16 + 12) | BIT(12),
956 }, {
957 /* edphdmi_cecinout */
958 .bank_num = 7,
959 .pin = 23,
960 .func = 4,
961 .route_offset = 0x264,
962 .route_val = BIT(16 + 12),
963 },
964};
965
David Wucedc9642017-05-26 15:20:22 +0800966static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
967 {
968 /* uart2dbg_rxm0 */
969 .bank_num = 1,
970 .pin = 1,
971 .func = 2,
972 .route_offset = 0x50,
973 .route_val = BIT(16) | BIT(16 + 1),
974 }, {
975 /* uart2dbg_rxm1 */
976 .bank_num = 2,
977 .pin = 1,
978 .func = 1,
979 .route_offset = 0x50,
980 .route_val = BIT(16) | BIT(16 + 1) | BIT(0),
981 }, {
David Wua976d7b2017-09-30 20:13:21 +0800982 /* gmac-m1_rxd0 */
David Wucedc9642017-05-26 15:20:22 +0800983 .bank_num = 1,
984 .pin = 11,
985 .func = 2,
986 .route_offset = 0x50,
David Wua976d7b2017-09-30 20:13:21 +0800987 .route_val = BIT(16 + 2) | BIT(2),
988 }, {
989 /* gmac-m1-optimized_rxd3 */
990 .bank_num = 1,
991 .pin = 14,
992 .func = 2,
993 .route_offset = 0x50,
994 .route_val = BIT(16 + 10) | BIT(10),
David Wucedc9642017-05-26 15:20:22 +0800995 }, {
996 /* pdm_sdi0m0 */
997 .bank_num = 2,
998 .pin = 19,
999 .func = 2,
1000 .route_offset = 0x50,
1001 .route_val = BIT(16 + 3),
1002 }, {
1003 /* pdm_sdi0m1 */
1004 .bank_num = 1,
1005 .pin = 23,
1006 .func = 3,
1007 .route_offset = 0x50,
1008 .route_val = BIT(16 + 3) | BIT(3),
1009 }, {
1010 /* spi_rxdm2 */
1011 .bank_num = 3,
1012 .pin = 2,
1013 .func = 4,
1014 .route_offset = 0x50,
1015 .route_val = BIT(16 + 4) | BIT(16 + 5) | BIT(5),
1016 }, {
1017 /* i2s2_sdim0 */
1018 .bank_num = 1,
1019 .pin = 24,
1020 .func = 1,
1021 .route_offset = 0x50,
1022 .route_val = BIT(16 + 6),
1023 }, {
1024 /* i2s2_sdim1 */
1025 .bank_num = 3,
1026 .pin = 2,
1027 .func = 6,
1028 .route_offset = 0x50,
1029 .route_val = BIT(16 + 6) | BIT(6),
1030 }, {
1031 /* card_iom1 */
1032 .bank_num = 2,
1033 .pin = 22,
1034 .func = 3,
1035 .route_offset = 0x50,
1036 .route_val = BIT(16 + 7) | BIT(7),
1037 }, {
1038 /* tsp_d5m1 */
1039 .bank_num = 2,
1040 .pin = 16,
1041 .func = 3,
1042 .route_offset = 0x50,
1043 .route_val = BIT(16 + 8) | BIT(8),
1044 }, {
1045 /* cif_data5m1 */
1046 .bank_num = 2,
1047 .pin = 16,
1048 .func = 4,
1049 .route_offset = 0x50,
1050 .route_val = BIT(16 + 9) | BIT(9),
1051 },
1052};
1053
David Wuaccc1ce2017-05-26 15:20:23 +08001054static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
1055 {
1056 /* uart2dbga_rx */
1057 .bank_num = 4,
1058 .pin = 8,
1059 .func = 2,
1060 .route_offset = 0xe21c,
1061 .route_val = BIT(16 + 10) | BIT(16 + 11),
1062 }, {
1063 /* uart2dbgb_rx */
1064 .bank_num = 4,
1065 .pin = 16,
1066 .func = 2,
1067 .route_offset = 0xe21c,
1068 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(10),
1069 }, {
1070 /* uart2dbgc_rx */
1071 .bank_num = 4,
1072 .pin = 19,
1073 .func = 1,
1074 .route_offset = 0xe21c,
1075 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(11),
1076 }, {
1077 /* pcie_clkreqn */
1078 .bank_num = 2,
1079 .pin = 26,
1080 .func = 2,
1081 .route_offset = 0xe21c,
1082 .route_val = BIT(16 + 14),
1083 }, {
1084 /* pcie_clkreqnb */
1085 .bank_num = 4,
1086 .pin = 24,
1087 .func = 1,
1088 .route_offset = 0xe21c,
1089 .route_val = BIT(16 + 14) | BIT(14),
1090 },
1091};
1092
David Wubd35b9b2017-05-26 15:20:20 +08001093static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
1094 int mux, u32 *reg, u32 *value)
1095{
1096 struct rockchip_pinctrl *info = bank->drvdata;
1097 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1098 struct rockchip_mux_route_data *data;
1099 int i;
1100
1101 for (i = 0; i < ctrl->niomux_routes; i++) {
1102 data = &ctrl->iomux_routes[i];
1103 if ((data->bank_num == bank->bank_num) &&
1104 (data->pin == pin) && (data->func == mux))
1105 break;
1106 }
1107
1108 if (i >= ctrl->niomux_routes)
1109 return false;
1110
1111 *reg = data->route_offset;
1112 *value = data->route_val;
1113
1114 return true;
1115}
1116
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001117static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
1118{
1119 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001120 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001121 struct regmap *regmap;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001122 unsigned int val;
david.wuea262ad2017-02-10 18:23:48 +08001123 int reg, ret, mask, mux_type;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001124 u8 bit;
1125
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001126 if (iomux_num > 3)
1127 return -EINVAL;
1128
Heiko Stübner62f49222014-06-16 01:37:49 +02001129 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1130 dev_err(info->dev, "pin %d is unrouted\n", pin);
1131 return -EINVAL;
1132 }
1133
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001134 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001135 return RK_FUNC_GPIO;
1136
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001137 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1138 ? info->regmap_pmu : info->regmap_base;
1139
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001140 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +08001141 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001142 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +08001143 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +02001144 if ((pin % 8) >= 4)
1145 reg += 0x4;
1146 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +08001147 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +08001148 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +08001149 if ((pin % 8) >= 5)
1150 reg += 0x4;
1151 bit = (pin % 8 % 5) * 3;
1152 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +02001153 } else {
1154 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +08001155 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +02001156 }
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001157
David Wuc04c3fa2017-07-21 14:27:14 +08001158 if (bank->recalced_mask & BIT(pin))
1159 rockchip_get_recalced_mux(bank, pin, &reg, &bit, &mask);
david.wuea262ad2017-02-10 18:23:48 +08001160
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001161 ret = regmap_read(regmap, reg, &val);
Heiko Stübner751a99a2014-05-05 13:58:20 +02001162 if (ret)
1163 return ret;
1164
Heiko Stübner03716e12014-06-16 01:36:57 +02001165 return ((val >> bit) & mask);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001166}
1167
John Keeping05709c32017-03-23 10:59:30 +00001168static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
1169 int pin, int mux)
1170{
1171 struct rockchip_pinctrl *info = bank->drvdata;
1172 int iomux_num = (pin / 8);
1173
1174 if (iomux_num > 3)
1175 return -EINVAL;
1176
1177 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
1178 dev_err(info->dev, "pin %d is unrouted\n", pin);
1179 return -EINVAL;
1180 }
1181
1182 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
1183 if (mux != RK_FUNC_GPIO) {
1184 dev_err(info->dev,
1185 "pin %d only supports a gpio mux\n", pin);
1186 return -ENOTSUPP;
1187 }
1188 }
1189
1190 return 0;
1191}
1192
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001193/*
1194 * Set a new mux function for a pin.
1195 *
1196 * The register is divided into the upper and lower 16 bit. When changing
1197 * a value, the previous register value is not read and changed. Instead
1198 * it seems the changed bits are marked in the upper 16 bit, while the
1199 * changed value gets set in the same offset in the lower 16 bit.
1200 * All pin settings seem to be 2 bit wide in both the upper and lower
1201 * parts.
1202 * @bank: pin bank to change
1203 * @pin: pin to change
1204 * @mux: new mux function to set
1205 */
Heiko Stübner14797182014-03-26 00:57:00 +01001206static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001207{
1208 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001209 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001210 struct regmap *regmap;
david.wuea262ad2017-02-10 18:23:48 +08001211 int reg, ret, mask, mux_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001212 u8 bit;
David Wubd35b9b2017-05-26 15:20:20 +08001213 u32 data, rmask, route_reg, route_val;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001214
John Keeping05709c32017-03-23 10:59:30 +00001215 ret = rockchip_verify_mux(bank, pin, mux);
1216 if (ret < 0)
1217 return ret;
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001218
John Keeping05709c32017-03-23 10:59:30 +00001219 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
1220 return 0;
Heiko Stübnerc4a532de2014-03-26 00:57:52 +01001221
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001222 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
1223 bank->bank_num, pin, mux);
1224
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001225 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
1226 ? info->regmap_pmu : info->regmap_base;
1227
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001228 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +08001229 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001230 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +08001231 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +02001232 if ((pin % 8) >= 4)
1233 reg += 0x4;
1234 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +08001235 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +08001236 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +08001237 if ((pin % 8) >= 5)
1238 reg += 0x4;
1239 bit = (pin % 8 % 5) * 3;
1240 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +02001241 } else {
1242 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +08001243 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +02001244 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001245
David Wuc04c3fa2017-07-21 14:27:14 +08001246 if (bank->recalced_mask & BIT(pin))
1247 rockchip_get_recalced_mux(bank, pin, &reg, &bit, &mask);
david.wuea262ad2017-02-10 18:23:48 +08001248
David Wubd35b9b2017-05-26 15:20:20 +08001249 if (bank->route_mask & BIT(pin)) {
1250 if (rockchip_get_mux_route(bank, pin, mux, &route_reg,
1251 &route_val)) {
1252 ret = regmap_write(regmap, route_reg, route_val);
1253 if (ret)
1254 return ret;
1255 }
1256 }
1257
Heiko Stübner03716e12014-06-16 01:36:57 +02001258 data = (mask << (bit + 16));
Sonny Rao99e872d2014-07-31 22:58:00 -07001259 rmask = data | (data >> 16);
Heiko Stübner03716e12014-06-16 01:36:57 +02001260 data |= (mux & mask) << bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001261 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001262
Heiko Stübner751a99a2014-05-05 13:58:20 +02001263 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001264}
1265
David Wu87065ca2018-05-14 19:59:51 +08001266#define PX30_PULL_PMU_OFFSET 0x10
1267#define PX30_PULL_GRF_OFFSET 0x60
1268#define PX30_PULL_BITS_PER_PIN 2
1269#define PX30_PULL_PINS_PER_REG 8
1270#define PX30_PULL_BANK_STRIDE 16
1271
1272static void px30_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1273 int pin_num, struct regmap **regmap,
1274 int *reg, u8 *bit)
1275{
1276 struct rockchip_pinctrl *info = bank->drvdata;
1277
1278 /* The first 32 pins of the first bank are located in PMU */
1279 if (bank->bank_num == 0) {
1280 *regmap = info->regmap_pmu;
1281 *reg = PX30_PULL_PMU_OFFSET;
1282 } else {
1283 *regmap = info->regmap_base;
1284 *reg = PX30_PULL_GRF_OFFSET;
1285
1286 /* correct the offset, as we're starting with the 2nd bank */
1287 *reg -= 0x10;
1288 *reg += bank->bank_num * PX30_PULL_BANK_STRIDE;
1289 }
1290
1291 *reg += ((pin_num / PX30_PULL_PINS_PER_REG) * 4);
1292 *bit = (pin_num % PX30_PULL_PINS_PER_REG);
1293 *bit *= PX30_PULL_BITS_PER_PIN;
1294}
1295
1296#define PX30_DRV_PMU_OFFSET 0x20
1297#define PX30_DRV_GRF_OFFSET 0xf0
1298#define PX30_DRV_BITS_PER_PIN 2
1299#define PX30_DRV_PINS_PER_REG 8
1300#define PX30_DRV_BANK_STRIDE 16
1301
1302static void px30_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1303 int pin_num, struct regmap **regmap,
1304 int *reg, u8 *bit)
1305{
1306 struct rockchip_pinctrl *info = bank->drvdata;
1307
1308 /* The first 32 pins of the first bank are located in PMU */
1309 if (bank->bank_num == 0) {
1310 *regmap = info->regmap_pmu;
1311 *reg = PX30_DRV_PMU_OFFSET;
1312 } else {
1313 *regmap = info->regmap_base;
1314 *reg = PX30_DRV_GRF_OFFSET;
1315
1316 /* correct the offset, as we're starting with the 2nd bank */
1317 *reg -= 0x10;
1318 *reg += bank->bank_num * PX30_DRV_BANK_STRIDE;
1319 }
1320
1321 *reg += ((pin_num / PX30_DRV_PINS_PER_REG) * 4);
1322 *bit = (pin_num % PX30_DRV_PINS_PER_REG);
1323 *bit *= PX30_DRV_BITS_PER_PIN;
1324}
1325
1326#define PX30_SCHMITT_PMU_OFFSET 0x38
1327#define PX30_SCHMITT_GRF_OFFSET 0xc0
1328#define PX30_SCHMITT_PINS_PER_PMU_REG 16
1329#define PX30_SCHMITT_BANK_STRIDE 16
1330#define PX30_SCHMITT_PINS_PER_GRF_REG 8
1331
1332static int px30_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1333 int pin_num,
1334 struct regmap **regmap,
1335 int *reg, u8 *bit)
1336{
1337 struct rockchip_pinctrl *info = bank->drvdata;
1338 int pins_per_reg;
1339
1340 if (bank->bank_num == 0) {
1341 *regmap = info->regmap_pmu;
1342 *reg = PX30_SCHMITT_PMU_OFFSET;
1343 pins_per_reg = PX30_SCHMITT_PINS_PER_PMU_REG;
1344 } else {
1345 *regmap = info->regmap_base;
1346 *reg = PX30_SCHMITT_GRF_OFFSET;
1347 pins_per_reg = PX30_SCHMITT_PINS_PER_GRF_REG;
1348 *reg += (bank->bank_num - 1) * PX30_SCHMITT_BANK_STRIDE;
1349 }
1350
1351 *reg += ((pin_num / pins_per_reg) * 4);
1352 *bit = pin_num % pins_per_reg;
1353
1354 return 0;
1355}
1356
Andy Yanb9c6dca2017-03-17 18:18:36 +01001357#define RV1108_PULL_PMU_OFFSET 0x10
1358#define RV1108_PULL_OFFSET 0x110
1359#define RV1108_PULL_PINS_PER_REG 8
1360#define RV1108_PULL_BITS_PER_PIN 2
1361#define RV1108_PULL_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001362
Andy Yanb9c6dca2017-03-17 18:18:36 +01001363static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001364 int pin_num, struct regmap **regmap,
1365 int *reg, u8 *bit)
1366{
1367 struct rockchip_pinctrl *info = bank->drvdata;
1368
1369 /* The first 24 pins of the first bank are located in PMU */
1370 if (bank->bank_num == 0) {
1371 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001372 *reg = RV1108_PULL_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001373 } else {
Andy Yanb9c6dca2017-03-17 18:18:36 +01001374 *reg = RV1108_PULL_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001375 *regmap = info->regmap_base;
1376 /* correct the offset, as we're starting with the 2nd bank */
1377 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001378 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001379 }
1380
Andy Yanb9c6dca2017-03-17 18:18:36 +01001381 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1382 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1383 *bit *= RV1108_PULL_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001384}
1385
Andy Yanb9c6dca2017-03-17 18:18:36 +01001386#define RV1108_DRV_PMU_OFFSET 0x20
1387#define RV1108_DRV_GRF_OFFSET 0x210
1388#define RV1108_DRV_BITS_PER_PIN 2
1389#define RV1108_DRV_PINS_PER_REG 8
1390#define RV1108_DRV_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001391
Andy Yanb9c6dca2017-03-17 18:18:36 +01001392static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001393 int pin_num, struct regmap **regmap,
1394 int *reg, u8 *bit)
1395{
1396 struct rockchip_pinctrl *info = bank->drvdata;
1397
1398 /* The first 24 pins of the first bank are located in PMU */
1399 if (bank->bank_num == 0) {
1400 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001401 *reg = RV1108_DRV_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001402 } else {
1403 *regmap = info->regmap_base;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001404 *reg = RV1108_DRV_GRF_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001405
1406 /* correct the offset, as we're starting with the 2nd bank */
1407 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001408 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001409 }
1410
Andy Yanb9c6dca2017-03-17 18:18:36 +01001411 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1412 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1413 *bit *= RV1108_DRV_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001414}
1415
Andy Yan5caff7e2017-07-31 18:10:22 +08001416#define RV1108_SCHMITT_PMU_OFFSET 0x30
1417#define RV1108_SCHMITT_GRF_OFFSET 0x388
1418#define RV1108_SCHMITT_BANK_STRIDE 8
1419#define RV1108_SCHMITT_PINS_PER_GRF_REG 16
1420#define RV1108_SCHMITT_PINS_PER_PMU_REG 8
1421
1422static int rv1108_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1423 int pin_num,
1424 struct regmap **regmap,
1425 int *reg, u8 *bit)
1426{
1427 struct rockchip_pinctrl *info = bank->drvdata;
1428 int pins_per_reg;
1429
1430 if (bank->bank_num == 0) {
1431 *regmap = info->regmap_pmu;
1432 *reg = RV1108_SCHMITT_PMU_OFFSET;
1433 pins_per_reg = RV1108_SCHMITT_PINS_PER_PMU_REG;
1434 } else {
1435 *regmap = info->regmap_base;
1436 *reg = RV1108_SCHMITT_GRF_OFFSET;
1437 pins_per_reg = RV1108_SCHMITT_PINS_PER_GRF_REG;
1438 *reg += (bank->bank_num - 1) * RV1108_SCHMITT_BANK_STRIDE;
1439 }
1440 *reg += ((pin_num / pins_per_reg) * 4);
1441 *bit = pin_num % pins_per_reg;
1442
1443 return 0;
1444}
1445
Heiko Stübnera2829262013-10-16 01:07:20 +02001446#define RK2928_PULL_OFFSET 0x118
1447#define RK2928_PULL_PINS_PER_REG 16
1448#define RK2928_PULL_BANK_STRIDE 8
1449
1450static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001451 int pin_num, struct regmap **regmap,
1452 int *reg, u8 *bit)
Heiko Stübnera2829262013-10-16 01:07:20 +02001453{
1454 struct rockchip_pinctrl *info = bank->drvdata;
1455
Heiko Stübner751a99a2014-05-05 13:58:20 +02001456 *regmap = info->regmap_base;
1457 *reg = RK2928_PULL_OFFSET;
Heiko Stübnera2829262013-10-16 01:07:20 +02001458 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1459 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1460
1461 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1462};
1463
David Wud23c66d2017-07-21 14:27:15 +08001464#define RK3128_PULL_OFFSET 0x118
1465
1466static void rk3128_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1467 int pin_num, struct regmap **regmap,
1468 int *reg, u8 *bit)
1469{
1470 struct rockchip_pinctrl *info = bank->drvdata;
1471
1472 *regmap = info->regmap_base;
1473 *reg = RK3128_PULL_OFFSET;
1474 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1475 *reg += ((pin_num / RK2928_PULL_PINS_PER_REG) * 4);
1476
1477 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1478}
1479
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001480#define RK3188_PULL_OFFSET 0x164
Heiko Stübner6ca52742013-10-16 01:08:42 +02001481#define RK3188_PULL_BITS_PER_PIN 2
1482#define RK3188_PULL_PINS_PER_REG 8
1483#define RK3188_PULL_BANK_STRIDE 16
Heiko Stübner14dee862014-05-05 13:59:09 +02001484#define RK3188_PULL_PMU_OFFSET 0x64
Heiko Stübner6ca52742013-10-16 01:08:42 +02001485
1486static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001487 int pin_num, struct regmap **regmap,
1488 int *reg, u8 *bit)
Heiko Stübner6ca52742013-10-16 01:08:42 +02001489{
1490 struct rockchip_pinctrl *info = bank->drvdata;
1491
1492 /* The first 12 pins of the first bank are located elsewhere */
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001493 if (bank->bank_num == 0 && pin_num < 12) {
Heiko Stübner14dee862014-05-05 13:59:09 +02001494 *regmap = info->regmap_pmu ? info->regmap_pmu
1495 : bank->regmap_pull;
1496 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001497 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001498 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1499 *bit *= RK3188_PULL_BITS_PER_PIN;
1500 } else {
Heiko Stübner751a99a2014-05-05 13:58:20 +02001501 *regmap = info->regmap_pull ? info->regmap_pull
1502 : info->regmap_base;
1503 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1504
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001505 /* correct the offset, as it is the 2nd pull register */
1506 *reg -= 4;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001507 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1508 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1509
1510 /*
1511 * The bits in these registers have an inverse ordering
1512 * with the lowest pin being in bits 15:14 and the highest
1513 * pin in bits 1:0
1514 */
1515 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1516 *bit *= RK3188_PULL_BITS_PER_PIN;
1517 }
1518}
1519
Heiko Stübner304f0772014-06-16 01:38:14 +02001520#define RK3288_PULL_OFFSET 0x140
1521static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1522 int pin_num, struct regmap **regmap,
1523 int *reg, u8 *bit)
1524{
1525 struct rockchip_pinctrl *info = bank->drvdata;
1526
1527 /* The first 24 pins of the first bank are located in PMU */
1528 if (bank->bank_num == 0) {
1529 *regmap = info->regmap_pmu;
1530 *reg = RK3188_PULL_PMU_OFFSET;
1531
1532 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1533 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1534 *bit *= RK3188_PULL_BITS_PER_PIN;
1535 } else {
1536 *regmap = info->regmap_base;
1537 *reg = RK3288_PULL_OFFSET;
1538
1539 /* correct the offset, as we're starting with the 2nd bank */
1540 *reg -= 0x10;
1541 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1542 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1543
1544 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1545 *bit *= RK3188_PULL_BITS_PER_PIN;
1546 }
1547}
1548
Heiko Stübnerb547c802014-07-20 01:50:11 +02001549#define RK3288_DRV_PMU_OFFSET 0x70
1550#define RK3288_DRV_GRF_OFFSET 0x1c0
1551#define RK3288_DRV_BITS_PER_PIN 2
1552#define RK3288_DRV_PINS_PER_REG 8
1553#define RK3288_DRV_BANK_STRIDE 16
Heiko Stübnerb547c802014-07-20 01:50:11 +02001554
1555static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1556 int pin_num, struct regmap **regmap,
1557 int *reg, u8 *bit)
1558{
1559 struct rockchip_pinctrl *info = bank->drvdata;
1560
1561 /* The first 24 pins of the first bank are located in PMU */
1562 if (bank->bank_num == 0) {
1563 *regmap = info->regmap_pmu;
1564 *reg = RK3288_DRV_PMU_OFFSET;
1565
1566 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1567 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1568 *bit *= RK3288_DRV_BITS_PER_PIN;
1569 } else {
1570 *regmap = info->regmap_base;
1571 *reg = RK3288_DRV_GRF_OFFSET;
1572
1573 /* correct the offset, as we're starting with the 2nd bank */
1574 *reg -= 0x10;
1575 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1576 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1577
1578 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1579 *bit *= RK3288_DRV_BITS_PER_PIN;
1580 }
1581}
1582
Jeffy Chenfea0fe62015-12-09 17:04:06 +08001583#define RK3228_PULL_OFFSET 0x100
1584
1585static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1586 int pin_num, struct regmap **regmap,
1587 int *reg, u8 *bit)
1588{
1589 struct rockchip_pinctrl *info = bank->drvdata;
1590
1591 *regmap = info->regmap_base;
1592 *reg = RK3228_PULL_OFFSET;
1593 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1594 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1595
1596 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1597 *bit *= RK3188_PULL_BITS_PER_PIN;
1598}
1599
1600#define RK3228_DRV_GRF_OFFSET 0x200
1601
1602static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1603 int pin_num, struct regmap **regmap,
1604 int *reg, u8 *bit)
1605{
1606 struct rockchip_pinctrl *info = bank->drvdata;
1607
1608 *regmap = info->regmap_base;
1609 *reg = RK3228_DRV_GRF_OFFSET;
1610 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1611 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1612
1613 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1614 *bit *= RK3288_DRV_BITS_PER_PIN;
1615}
1616
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001617#define RK3368_PULL_GRF_OFFSET 0x100
1618#define RK3368_PULL_PMU_OFFSET 0x10
1619
1620static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1621 int pin_num, struct regmap **regmap,
1622 int *reg, u8 *bit)
1623{
1624 struct rockchip_pinctrl *info = bank->drvdata;
1625
1626 /* The first 32 pins of the first bank are located in PMU */
1627 if (bank->bank_num == 0) {
1628 *regmap = info->regmap_pmu;
1629 *reg = RK3368_PULL_PMU_OFFSET;
1630
1631 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1632 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1633 *bit *= RK3188_PULL_BITS_PER_PIN;
1634 } else {
1635 *regmap = info->regmap_base;
1636 *reg = RK3368_PULL_GRF_OFFSET;
1637
1638 /* correct the offset, as we're starting with the 2nd bank */
1639 *reg -= 0x10;
1640 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1641 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1642
1643 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1644 *bit *= RK3188_PULL_BITS_PER_PIN;
1645 }
1646}
1647
1648#define RK3368_DRV_PMU_OFFSET 0x20
1649#define RK3368_DRV_GRF_OFFSET 0x200
1650
1651static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1652 int pin_num, struct regmap **regmap,
1653 int *reg, u8 *bit)
1654{
1655 struct rockchip_pinctrl *info = bank->drvdata;
1656
1657 /* The first 32 pins of the first bank are located in PMU */
1658 if (bank->bank_num == 0) {
1659 *regmap = info->regmap_pmu;
1660 *reg = RK3368_DRV_PMU_OFFSET;
1661
1662 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1663 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1664 *bit *= RK3288_DRV_BITS_PER_PIN;
1665 } else {
1666 *regmap = info->regmap_base;
1667 *reg = RK3368_DRV_GRF_OFFSET;
1668
1669 /* correct the offset, as we're starting with the 2nd bank */
1670 *reg -= 0x10;
1671 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1672 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1673
1674 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1675 *bit *= RK3288_DRV_BITS_PER_PIN;
1676 }
1677}
1678
David Wub6c23272016-02-01 10:58:21 +08001679#define RK3399_PULL_GRF_OFFSET 0xe040
1680#define RK3399_PULL_PMU_OFFSET 0x40
1681#define RK3399_DRV_3BITS_PER_PIN 3
1682
1683static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1684 int pin_num, struct regmap **regmap,
1685 int *reg, u8 *bit)
1686{
1687 struct rockchip_pinctrl *info = bank->drvdata;
1688
1689 /* The bank0:16 and bank1:32 pins are located in PMU */
1690 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1691 *regmap = info->regmap_pmu;
1692 *reg = RK3399_PULL_PMU_OFFSET;
1693
1694 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1695
1696 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1697 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1698 *bit *= RK3188_PULL_BITS_PER_PIN;
1699 } else {
1700 *regmap = info->regmap_base;
1701 *reg = RK3399_PULL_GRF_OFFSET;
1702
1703 /* correct the offset, as we're starting with the 3rd bank */
1704 *reg -= 0x20;
1705 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1706 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1707
1708 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1709 *bit *= RK3188_PULL_BITS_PER_PIN;
1710 }
1711}
1712
1713static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1714 int pin_num, struct regmap **regmap,
1715 int *reg, u8 *bit)
1716{
1717 struct rockchip_pinctrl *info = bank->drvdata;
1718 int drv_num = (pin_num / 8);
1719
1720 /* The bank0:16 and bank1:32 pins are located in PMU */
1721 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1722 *regmap = info->regmap_pmu;
1723 else
1724 *regmap = info->regmap_base;
1725
1726 *reg = bank->drv[drv_num].offset;
1727 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1728 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1729 *bit = (pin_num % 8) * 3;
1730 else
1731 *bit = (pin_num % 8) * 2;
1732}
1733
1734static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1735 { 2, 4, 8, 12, -1, -1, -1, -1 },
1736 { 3, 6, 9, 12, -1, -1, -1, -1 },
1737 { 5, 10, 15, 20, -1, -1, -1, -1 },
1738 { 4, 6, 8, 10, 12, 14, 16, 18 },
1739 { 4, 7, 10, 13, 16, 19, 22, 26 }
1740};
Heiko Stübneref17f692015-06-12 23:50:11 +02001741
1742static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1743 int pin_num)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001744{
Heiko Stübneref17f692015-06-12 23:50:11 +02001745 struct rockchip_pinctrl *info = bank->drvdata;
1746 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001747 struct regmap *regmap;
1748 int reg, ret;
David Wub6c23272016-02-01 10:58:21 +08001749 u32 data, temp, rmask_bits;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001750 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001751 int drv_type = bank->drv[pin_num / 8].drv_type;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001752
Heiko Stübneref17f692015-06-12 23:50:11 +02001753 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001754
David Wub6c23272016-02-01 10:58:21 +08001755 switch (drv_type) {
1756 case DRV_TYPE_IO_1V8_3V0_AUTO:
1757 case DRV_TYPE_IO_3V3_ONLY:
1758 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1759 switch (bit) {
1760 case 0 ... 12:
1761 /* regular case, nothing to do */
1762 break;
1763 case 15:
1764 /*
1765 * drive-strength offset is special, as it is
1766 * spread over 2 registers
1767 */
1768 ret = regmap_read(regmap, reg, &data);
1769 if (ret)
1770 return ret;
1771
1772 ret = regmap_read(regmap, reg + 0x4, &temp);
1773 if (ret)
1774 return ret;
1775
1776 /*
1777 * the bit data[15] contains bit 0 of the value
1778 * while temp[1:0] contains bits 2 and 1
1779 */
1780 data >>= 15;
1781 temp &= 0x3;
1782 temp <<= 1;
1783 data |= temp;
1784
1785 return rockchip_perpin_drv_list[drv_type][data];
1786 case 18 ... 21:
1787 /* setting fully enclosed in the second register */
1788 reg += 4;
1789 bit -= 16;
1790 break;
1791 default:
1792 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1793 bit, drv_type);
1794 return -EINVAL;
1795 }
1796
1797 break;
1798 case DRV_TYPE_IO_DEFAULT:
1799 case DRV_TYPE_IO_1V8_OR_3V0:
1800 case DRV_TYPE_IO_1V8_ONLY:
1801 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1802 break;
1803 default:
1804 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1805 drv_type);
1806 return -EINVAL;
1807 }
1808
Heiko Stübnerb547c802014-07-20 01:50:11 +02001809 ret = regmap_read(regmap, reg, &data);
1810 if (ret)
1811 return ret;
1812
1813 data >>= bit;
David Wub6c23272016-02-01 10:58:21 +08001814 data &= (1 << rmask_bits) - 1;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001815
David Wub6c23272016-02-01 10:58:21 +08001816 return rockchip_perpin_drv_list[drv_type][data];
Heiko Stübnerb547c802014-07-20 01:50:11 +02001817}
1818
Heiko Stübneref17f692015-06-12 23:50:11 +02001819static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1820 int pin_num, int strength)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001821{
1822 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübneref17f692015-06-12 23:50:11 +02001823 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001824 struct regmap *regmap;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001825 int reg, ret, i;
David Wub6c23272016-02-01 10:58:21 +08001826 u32 data, rmask, rmask_bits, temp;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001827 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001828 int drv_type = bank->drv[pin_num / 8].drv_type;
1829
1830 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1831 bank->bank_num, pin_num, strength);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001832
Heiko Stübneref17f692015-06-12 23:50:11 +02001833 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001834
1835 ret = -EINVAL;
David Wub6c23272016-02-01 10:58:21 +08001836 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1837 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
Heiko Stübnerb547c802014-07-20 01:50:11 +02001838 ret = i;
1839 break;
David Wub6c23272016-02-01 10:58:21 +08001840 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1841 ret = rockchip_perpin_drv_list[drv_type][i];
1842 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001843 }
1844 }
1845
1846 if (ret < 0) {
1847 dev_err(info->dev, "unsupported driver strength %d\n",
1848 strength);
1849 return ret;
1850 }
1851
David Wub6c23272016-02-01 10:58:21 +08001852 switch (drv_type) {
1853 case DRV_TYPE_IO_1V8_3V0_AUTO:
1854 case DRV_TYPE_IO_3V3_ONLY:
1855 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1856 switch (bit) {
1857 case 0 ... 12:
1858 /* regular case, nothing to do */
1859 break;
1860 case 15:
1861 /*
1862 * drive-strength offset is special, as it is spread
1863 * over 2 registers, the bit data[15] contains bit 0
1864 * of the value while temp[1:0] contains bits 2 and 1
1865 */
1866 data = (ret & 0x1) << 15;
1867 temp = (ret >> 0x1) & 0x3;
1868
1869 rmask = BIT(15) | BIT(31);
1870 data |= BIT(31);
1871 ret = regmap_update_bits(regmap, reg, rmask, data);
John Keepingf07bedc2017-03-23 10:59:28 +00001872 if (ret)
David Wub6c23272016-02-01 10:58:21 +08001873 return ret;
David Wub6c23272016-02-01 10:58:21 +08001874
1875 rmask = 0x3 | (0x3 << 16);
1876 temp |= (0x3 << 16);
1877 reg += 0x4;
1878 ret = regmap_update_bits(regmap, reg, rmask, temp);
1879
David Wub6c23272016-02-01 10:58:21 +08001880 return ret;
1881 case 18 ... 21:
1882 /* setting fully enclosed in the second register */
1883 reg += 4;
1884 bit -= 16;
1885 break;
1886 default:
David Wub6c23272016-02-01 10:58:21 +08001887 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1888 bit, drv_type);
1889 return -EINVAL;
1890 }
1891 break;
1892 case DRV_TYPE_IO_DEFAULT:
1893 case DRV_TYPE_IO_1V8_OR_3V0:
1894 case DRV_TYPE_IO_1V8_ONLY:
1895 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1896 break;
1897 default:
David Wub6c23272016-02-01 10:58:21 +08001898 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1899 drv_type);
1900 return -EINVAL;
1901 }
1902
Heiko Stübnerb547c802014-07-20 01:50:11 +02001903 /* enable the write to the equivalent lower bits */
David Wub6c23272016-02-01 10:58:21 +08001904 data = ((1 << rmask_bits) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07001905 rmask = data | (data >> 16);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001906 data |= (ret << bit);
1907
Sonny Rao99e872d2014-07-31 22:58:00 -07001908 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001909
1910 return ret;
1911}
1912
David Wu3ba67672016-05-11 11:39:28 +08001913static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1914 {
1915 PIN_CONFIG_BIAS_DISABLE,
1916 PIN_CONFIG_BIAS_PULL_UP,
1917 PIN_CONFIG_BIAS_PULL_DOWN,
1918 PIN_CONFIG_BIAS_BUS_HOLD
1919 },
1920 {
1921 PIN_CONFIG_BIAS_DISABLE,
1922 PIN_CONFIG_BIAS_PULL_DOWN,
1923 PIN_CONFIG_BIAS_DISABLE,
1924 PIN_CONFIG_BIAS_PULL_UP
1925 },
1926};
1927
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001928static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1929{
1930 struct rockchip_pinctrl *info = bank->drvdata;
1931 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001932 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001933 int reg, ret, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001934 u8 bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001935 u32 data;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001936
1937 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02001938 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001939 return PIN_CONFIG_BIAS_DISABLE;
1940
Heiko Stübner751a99a2014-05-05 13:58:20 +02001941 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
1942
1943 ret = regmap_read(regmap, reg, &data);
1944 if (ret)
1945 return ret;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001946
Heiko Stübnera2829262013-10-16 01:07:20 +02001947 switch (ctrl->type) {
1948 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08001949 case RK3128:
Heiko Stübner751a99a2014-05-05 13:58:20 +02001950 return !(data & BIT(bit))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001951 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1952 : PIN_CONFIG_BIAS_DISABLE;
David Wu87065ca2018-05-14 19:59:51 +08001953 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01001954 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001955 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02001956 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001957 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08001958 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08001959 pull_type = bank->pull_type[pin_num / 8];
Heiko Stübner751a99a2014-05-05 13:58:20 +02001960 data >>= bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001961 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1962
David Wu3ba67672016-05-11 11:39:28 +08001963 return rockchip_pull_list[pull_type][data];
Heiko Stübnera2829262013-10-16 01:07:20 +02001964 default:
1965 dev_err(info->dev, "unsupported pinctrl type\n");
1966 return -EINVAL;
1967 };
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001968}
1969
1970static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1971 int pin_num, int pull)
1972{
1973 struct rockchip_pinctrl *info = bank->drvdata;
1974 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001975 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001976 int reg, ret, i, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001977 u8 bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001978 u32 data, rmask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001979
1980 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
1981 bank->bank_num, pin_num, pull);
1982
1983 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02001984 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001985 return pull ? -EINVAL : 0;
1986
Heiko Stübner751a99a2014-05-05 13:58:20 +02001987 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001988
Heiko Stübnera2829262013-10-16 01:07:20 +02001989 switch (ctrl->type) {
1990 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08001991 case RK3128:
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001992 data = BIT(bit + 16);
1993 if (pull == PIN_CONFIG_BIAS_DISABLE)
1994 data |= BIT(bit);
Heiko Stübner751a99a2014-05-05 13:58:20 +02001995 ret = regmap_write(regmap, reg, data);
Heiko Stübnera2829262013-10-16 01:07:20 +02001996 break;
David Wu87065ca2018-05-14 19:59:51 +08001997 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01001998 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001999 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02002000 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02002001 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08002002 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08002003 pull_type = bank->pull_type[pin_num / 8];
2004 ret = -EINVAL;
2005 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
2006 i++) {
2007 if (rockchip_pull_list[pull_type][i] == pull) {
2008 ret = i;
2009 break;
2010 }
2011 }
2012
2013 if (ret < 0) {
2014 dev_err(info->dev, "unsupported pull setting %d\n",
2015 pull);
2016 return ret;
2017 }
2018
Heiko Stübner6ca52742013-10-16 01:08:42 +02002019 /* enable the write to the equivalent lower bits */
2020 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07002021 rmask = data | (data >> 16);
David Wu3ba67672016-05-11 11:39:28 +08002022 data |= (ret << bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02002023
Sonny Rao99e872d2014-07-31 22:58:00 -07002024 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübner6ca52742013-10-16 01:08:42 +02002025 break;
Heiko Stübnera2829262013-10-16 01:07:20 +02002026 default:
2027 dev_err(info->dev, "unsupported pinctrl type\n");
2028 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002029 }
2030
Heiko Stübner751a99a2014-05-05 13:58:20 +02002031 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002032}
2033
david.wu728d3f52017-03-02 15:11:24 +08002034#define RK3328_SCHMITT_BITS_PER_PIN 1
2035#define RK3328_SCHMITT_PINS_PER_REG 16
2036#define RK3328_SCHMITT_BANK_STRIDE 8
2037#define RK3328_SCHMITT_GRF_OFFSET 0x380
2038
2039static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
2040 int pin_num,
2041 struct regmap **regmap,
2042 int *reg, u8 *bit)
2043{
2044 struct rockchip_pinctrl *info = bank->drvdata;
2045
2046 *regmap = info->regmap_base;
2047 *reg = RK3328_SCHMITT_GRF_OFFSET;
2048
2049 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
2050 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
2051 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
2052
2053 return 0;
2054}
2055
david.wue3b357d2017-03-02 15:11:23 +08002056static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
2057{
2058 struct rockchip_pinctrl *info = bank->drvdata;
2059 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2060 struct regmap *regmap;
2061 int reg, ret;
2062 u8 bit;
2063 u32 data;
2064
2065 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
2066 if (ret)
2067 return ret;
2068
2069 ret = regmap_read(regmap, reg, &data);
2070 if (ret)
2071 return ret;
2072
2073 data >>= bit;
2074 return data & 0x1;
2075}
2076
2077static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
2078 int pin_num, int enable)
2079{
2080 struct rockchip_pinctrl *info = bank->drvdata;
2081 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2082 struct regmap *regmap;
2083 int reg, ret;
david.wue3b357d2017-03-02 15:11:23 +08002084 u8 bit;
2085 u32 data, rmask;
2086
2087 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
2088 bank->bank_num, pin_num, enable);
2089
2090 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
2091 if (ret)
2092 return ret;
2093
david.wue3b357d2017-03-02 15:11:23 +08002094 /* enable the write to the equivalent lower bits */
2095 data = BIT(bit + 16) | (enable << bit);
2096 rmask = BIT(bit + 16) | BIT(bit);
2097
John Keepingf07bedc2017-03-23 10:59:28 +00002098 return regmap_update_bits(regmap, reg, rmask, data);
david.wue3b357d2017-03-02 15:11:23 +08002099}
2100
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002101/*
2102 * Pinmux_ops handling
2103 */
2104
2105static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
2106{
2107 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2108
2109 return info->nfunctions;
2110}
2111
2112static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
2113 unsigned selector)
2114{
2115 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2116
2117 return info->functions[selector].name;
2118}
2119
2120static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
2121 unsigned selector, const char * const **groups,
2122 unsigned * const num_groups)
2123{
2124 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2125
2126 *groups = info->functions[selector].groups;
2127 *num_groups = info->functions[selector].ngroups;
2128
2129 return 0;
2130}
2131
Linus Walleij03e9f0c2014-09-03 13:02:56 +02002132static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
2133 unsigned group)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002134{
2135 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2136 const unsigned int *pins = info->groups[group].pins;
2137 const struct rockchip_pin_config *data = info->groups[group].data;
2138 struct rockchip_pin_bank *bank;
Heiko Stübner14797182014-03-26 00:57:00 +01002139 int cnt, ret = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002140
2141 dev_dbg(info->dev, "enable function %s group %s\n",
2142 info->functions[selector].name, info->groups[group].name);
2143
2144 /*
Markus Elfring85dc3972017-12-23 22:22:54 +01002145 * for each pin in the pin group selected, program the corresponding
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002146 * pin function number in the config register.
2147 */
2148 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
2149 bank = pin_to_bank(info, pins[cnt]);
Heiko Stübner14797182014-03-26 00:57:00 +01002150 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
2151 data[cnt].func);
2152 if (ret)
2153 break;
2154 }
2155
2156 if (ret) {
2157 /* revert the already done pin settings */
2158 for (cnt--; cnt >= 0; cnt--)
2159 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
2160
2161 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002162 }
2163
2164 return 0;
2165}
2166
Caesar Wang6ba20a02016-03-15 15:55:45 +08002167static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
2168{
2169 struct rockchip_pin_bank *bank = gpiochip_get_data(chip);
2170 u32 data;
Brian Norris5c9d8c42017-12-12 09:43:43 -08002171 int ret;
Caesar Wang6ba20a02016-03-15 15:55:45 +08002172
Brian Norris5c9d8c42017-12-12 09:43:43 -08002173 ret = clk_enable(bank->clk);
2174 if (ret < 0) {
2175 dev_err(bank->drvdata->dev,
2176 "failed to enable clock for bank %s\n", bank->name);
2177 return ret;
2178 }
Caesar Wang6ba20a02016-03-15 15:55:45 +08002179 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
Brian Norris5c9d8c42017-12-12 09:43:43 -08002180 clk_disable(bank->clk);
Caesar Wang6ba20a02016-03-15 15:55:45 +08002181
2182 return !(data & BIT(offset));
2183}
2184
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002185/*
2186 * The calls to gpio_direction_output() and gpio_direction_input()
2187 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
2188 * function called from the gpiolib interface).
2189 */
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002190static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip,
2191 int pin, bool input)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002192{
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002193 struct rockchip_pin_bank *bank;
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002194 int ret;
Doug Andersonfab262f2014-10-21 10:47:35 -07002195 unsigned long flags;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002196 u32 data;
2197
Linus Walleij03bf81f2015-12-08 09:39:13 +01002198 bank = gpiochip_get_data(chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002199
Heiko Stübner14797182014-03-26 00:57:00 +01002200 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
2201 if (ret < 0)
2202 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002203
Lin Huang07a06ae2015-08-11 18:12:04 +08002204 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002205 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002206
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002207 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2208 /* set bit to 1 for output, 0 for input */
2209 if (!input)
2210 data |= BIT(pin);
2211 else
2212 data &= ~BIT(pin);
2213 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2214
John Keeping70b7aa72017-03-23 10:59:29 +00002215 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08002216 clk_disable(bank->clk);
Doug Andersonfab262f2014-10-21 10:47:35 -07002217
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002218 return 0;
2219}
2220
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002221static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
2222 struct pinctrl_gpio_range *range,
2223 unsigned offset, bool input)
2224{
2225 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2226 struct gpio_chip *chip;
2227 int pin;
2228
2229 chip = range->gc;
2230 pin = offset - chip->base;
2231 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
2232 offset, range->name, pin, input ? "input" : "output");
2233
2234 return _rockchip_pmx_gpio_set_direction(chip, offset - chip->base,
2235 input);
2236}
2237
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002238static const struct pinmux_ops rockchip_pmx_ops = {
2239 .get_functions_count = rockchip_pmx_get_funcs_count,
2240 .get_function_name = rockchip_pmx_get_func_name,
2241 .get_function_groups = rockchip_pmx_get_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +02002242 .set_mux = rockchip_pmx_set,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002243 .gpio_set_direction = rockchip_pmx_gpio_set_direction,
2244};
2245
2246/*
2247 * Pinconf_ops handling
2248 */
2249
Heiko Stübner44b6d932013-06-16 17:41:16 +02002250static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
2251 enum pin_config_param pull)
2252{
Heiko Stübnera2829262013-10-16 01:07:20 +02002253 switch (ctrl->type) {
2254 case RK2928:
David Wud23c66d2017-07-21 14:27:15 +08002255 case RK3128:
Heiko Stübnera2829262013-10-16 01:07:20 +02002256 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
2257 pull == PIN_CONFIG_BIAS_DISABLE);
2258 case RK3066B:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002259 return pull ? false : true;
David Wu87065ca2018-05-14 19:59:51 +08002260 case PX30:
Andy Yanb9c6dca2017-03-17 18:18:36 +01002261 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02002262 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02002263 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02002264 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08002265 case RK3399:
Heiko Stübnera2829262013-10-16 01:07:20 +02002266 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
Heiko Stübner44b6d932013-06-16 17:41:16 +02002267 }
2268
Heiko Stübnera2829262013-10-16 01:07:20 +02002269 return false;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002270}
2271
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002272static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002273static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset);
2274
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002275/* set the pin config settings for a specified pin */
2276static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Sherman Yin03b054e2013-08-27 11:32:12 -07002277 unsigned long *configs, unsigned num_configs)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002278{
2279 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2280 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
Sherman Yin03b054e2013-08-27 11:32:12 -07002281 enum pin_config_param param;
Mika Westerberg58957d22017-01-23 15:34:32 +03002282 u32 arg;
Sherman Yin03b054e2013-08-27 11:32:12 -07002283 int i;
2284 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002285
Sherman Yin03b054e2013-08-27 11:32:12 -07002286 for (i = 0; i < num_configs; i++) {
2287 param = pinconf_to_config_param(configs[i]);
2288 arg = pinconf_to_config_argument(configs[i]);
2289
2290 switch (param) {
2291 case PIN_CONFIG_BIAS_DISABLE:
2292 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2293 param);
2294 if (rc)
2295 return rc;
2296 break;
2297 case PIN_CONFIG_BIAS_PULL_UP:
2298 case PIN_CONFIG_BIAS_PULL_DOWN:
2299 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02002300 case PIN_CONFIG_BIAS_BUS_HOLD:
Sherman Yin03b054e2013-08-27 11:32:12 -07002301 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2302 return -ENOTSUPP;
2303
2304 if (!arg)
2305 return -EINVAL;
2306
2307 rc = rockchip_set_pull(bank, pin - bank->pin_base,
2308 param);
2309 if (rc)
2310 return rc;
2311 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002312 case PIN_CONFIG_OUTPUT:
Doug Andersone5c2c9d2014-10-21 10:47:33 -07002313 rockchip_gpio_set(&bank->gpio_chip,
2314 pin - bank->pin_base, arg);
2315 rc = _rockchip_pmx_gpio_set_direction(&bank->gpio_chip,
2316 pin - bank->pin_base, false);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002317 if (rc)
2318 return rc;
2319 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02002320 case PIN_CONFIG_DRIVE_STRENGTH:
2321 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02002322 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02002323 return -ENOTSUPP;
2324
Heiko Stübneref17f692015-06-12 23:50:11 +02002325 rc = rockchip_set_drive_perpin(bank,
2326 pin - bank->pin_base, arg);
Heiko Stübnerb547c802014-07-20 01:50:11 +02002327 if (rc < 0)
2328 return rc;
2329 break;
david.wue3b357d2017-03-02 15:11:23 +08002330 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2331 if (!info->ctrl->schmitt_calc_reg)
2332 return -ENOTSUPP;
2333
2334 rc = rockchip_set_schmitt(bank,
2335 pin - bank->pin_base, arg);
2336 if (rc < 0)
2337 return rc;
2338 break;
Sherman Yin03b054e2013-08-27 11:32:12 -07002339 default:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002340 return -ENOTSUPP;
Sherman Yin03b054e2013-08-27 11:32:12 -07002341 break;
2342 }
2343 } /* for each config */
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002344
2345 return 0;
2346}
2347
2348/* get the pin config settings for a specified pin */
2349static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
2350 unsigned long *config)
2351{
2352 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
2353 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
2354 enum pin_config_param param = pinconf_to_config_param(*config);
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002355 u16 arg;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002356 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002357
2358 switch (param) {
2359 case PIN_CONFIG_BIAS_DISABLE:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002360 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002361 return -EINVAL;
2362
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002363 arg = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002364 break;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002365 case PIN_CONFIG_BIAS_PULL_UP:
2366 case PIN_CONFIG_BIAS_PULL_DOWN:
2367 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02002368 case PIN_CONFIG_BIAS_BUS_HOLD:
Heiko Stübner44b6d932013-06-16 17:41:16 +02002369 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
2370 return -ENOTSUPP;
2371
2372 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
2373 return -EINVAL;
2374
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002375 arg = 1;
Heiko Stübner44b6d932013-06-16 17:41:16 +02002376 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02002377 case PIN_CONFIG_OUTPUT:
2378 rc = rockchip_get_mux(bank, pin - bank->pin_base);
2379 if (rc != RK_FUNC_GPIO)
2380 return -EINVAL;
2381
2382 rc = rockchip_gpio_get(&bank->gpio_chip, pin - bank->pin_base);
2383 if (rc < 0)
2384 return rc;
2385
2386 arg = rc ? 1 : 0;
2387 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02002388 case PIN_CONFIG_DRIVE_STRENGTH:
2389 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02002390 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02002391 return -ENOTSUPP;
2392
Heiko Stübneref17f692015-06-12 23:50:11 +02002393 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
Heiko Stübnerb547c802014-07-20 01:50:11 +02002394 if (rc < 0)
2395 return rc;
2396
2397 arg = rc;
2398 break;
david.wue3b357d2017-03-02 15:11:23 +08002399 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2400 if (!info->ctrl->schmitt_calc_reg)
2401 return -ENOTSUPP;
2402
2403 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2404 if (rc < 0)
2405 return rc;
2406
2407 arg = rc;
2408 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002409 default:
2410 return -ENOTSUPP;
2411 break;
2412 }
2413
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002414 *config = pinconf_to_config_packed(param, arg);
2415
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002416 return 0;
2417}
2418
2419static const struct pinconf_ops rockchip_pinconf_ops = {
2420 .pin_config_get = rockchip_pinconf_get,
2421 .pin_config_set = rockchip_pinconf_set,
Heiko Stübnered62f2f2014-07-20 01:48:45 +02002422 .is_generic = true,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002423};
2424
Heiko Stübner65fca612013-10-16 01:07:49 +02002425static const struct of_device_id rockchip_bank_match[] = {
2426 { .compatible = "rockchip,gpio-bank" },
Heiko Stübner6ca52742013-10-16 01:08:42 +02002427 { .compatible = "rockchip,rk3188-gpio-bank0" },
Heiko Stübner65fca612013-10-16 01:07:49 +02002428 {},
2429};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002430
2431static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2432 struct device_node *np)
2433{
2434 struct device_node *child;
2435
2436 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002437 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002438 continue;
2439
2440 info->nfunctions++;
2441 info->ngroups += of_get_child_count(child);
2442 }
2443}
2444
2445static int rockchip_pinctrl_parse_groups(struct device_node *np,
2446 struct rockchip_pin_group *grp,
2447 struct rockchip_pinctrl *info,
2448 u32 index)
2449{
2450 struct rockchip_pin_bank *bank;
2451 int size;
2452 const __be32 *list;
2453 int num;
2454 int i, j;
2455 int ret;
2456
Rob Herring94f4e542018-08-27 20:52:41 -05002457 dev_dbg(info->dev, "group(%d): %pOFn\n", index, np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002458
2459 /* Initialise group */
2460 grp->name = np->name;
2461
2462 /*
2463 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2464 * do sanity check and calculate pins number
2465 */
2466 list = of_get_property(np, "rockchip,pins", &size);
2467 /* we do not check return since it's safe node passed down */
2468 size /= sizeof(*list);
2469 if (!size || size % 4) {
2470 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2471 return -EINVAL;
2472 }
2473
2474 grp->npins = size / 4;
2475
Kees Cooka86854d2018-06-12 14:07:58 -07002476 grp->pins = devm_kcalloc(info->dev, grp->npins, sizeof(unsigned int),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002477 GFP_KERNEL);
Kees Cooka86854d2018-06-12 14:07:58 -07002478 grp->data = devm_kcalloc(info->dev,
2479 grp->npins,
2480 sizeof(struct rockchip_pin_config),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002481 GFP_KERNEL);
2482 if (!grp->pins || !grp->data)
2483 return -ENOMEM;
2484
2485 for (i = 0, j = 0; i < size; i += 4, j++) {
2486 const __be32 *phandle;
2487 struct device_node *np_config;
2488
2489 num = be32_to_cpu(*list++);
2490 bank = bank_num_to_bank(info, num);
2491 if (IS_ERR(bank))
2492 return PTR_ERR(bank);
2493
2494 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2495 grp->data[j].func = be32_to_cpu(*list++);
2496
2497 phandle = list++;
2498 if (!phandle)
2499 return -EINVAL;
2500
2501 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
Soren Brinkmanndd4d01f2015-01-09 07:43:46 -08002502 ret = pinconf_generic_parse_dt_config(np_config, NULL,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002503 &grp->data[j].configs, &grp->data[j].nconfigs);
2504 if (ret)
2505 return ret;
2506 }
2507
2508 return 0;
2509}
2510
2511static int rockchip_pinctrl_parse_functions(struct device_node *np,
2512 struct rockchip_pinctrl *info,
2513 u32 index)
2514{
2515 struct device_node *child;
2516 struct rockchip_pmx_func *func;
2517 struct rockchip_pin_group *grp;
2518 int ret;
2519 static u32 grp_index;
2520 u32 i = 0;
2521
Rob Herring94f4e542018-08-27 20:52:41 -05002522 dev_dbg(info->dev, "parse function(%d): %pOFn\n", index, np);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002523
2524 func = &info->functions[index];
2525
2526 /* Initialise function */
2527 func->name = np->name;
2528 func->ngroups = of_get_child_count(np);
2529 if (func->ngroups <= 0)
2530 return 0;
2531
Kees Cooka86854d2018-06-12 14:07:58 -07002532 func->groups = devm_kcalloc(info->dev,
2533 func->ngroups, sizeof(char *), GFP_KERNEL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002534 if (!func->groups)
2535 return -ENOMEM;
2536
2537 for_each_child_of_node(np, child) {
2538 func->groups[i] = child->name;
2539 grp = &info->groups[grp_index++];
2540 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
Julia Lawallf7a81b72015-12-21 17:39:47 +01002541 if (ret) {
2542 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002543 return ret;
Julia Lawallf7a81b72015-12-21 17:39:47 +01002544 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002545 }
2546
2547 return 0;
2548}
2549
2550static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2551 struct rockchip_pinctrl *info)
2552{
2553 struct device *dev = &pdev->dev;
2554 struct device_node *np = dev->of_node;
2555 struct device_node *child;
2556 int ret;
2557 int i;
2558
2559 rockchip_pinctrl_child_count(info, np);
2560
2561 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2562 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2563
Kees Cooka86854d2018-06-12 14:07:58 -07002564 info->functions = devm_kcalloc(dev,
2565 info->nfunctions,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002566 sizeof(struct rockchip_pmx_func),
2567 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002568 if (!info->functions)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002569 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002570
Kees Cooka86854d2018-06-12 14:07:58 -07002571 info->groups = devm_kcalloc(dev,
2572 info->ngroups,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002573 sizeof(struct rockchip_pin_group),
2574 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002575 if (!info->groups)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002576 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002577
2578 i = 0;
2579
2580 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002581 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002582 continue;
Heiko Stübner65fca612013-10-16 01:07:49 +02002583
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002584 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2585 if (ret) {
2586 dev_err(&pdev->dev, "failed to parse function\n");
Julia Lawallf7a81b72015-12-21 17:39:47 +01002587 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002588 return ret;
2589 }
2590 }
2591
2592 return 0;
2593}
2594
2595static int rockchip_pinctrl_register(struct platform_device *pdev,
2596 struct rockchip_pinctrl *info)
2597{
2598 struct pinctrl_desc *ctrldesc = &info->pctl;
2599 struct pinctrl_pin_desc *pindesc, *pdesc;
2600 struct rockchip_pin_bank *pin_bank;
2601 int pin, bank, ret;
2602 int k;
2603
2604 ctrldesc->name = "rockchip-pinctrl";
2605 ctrldesc->owner = THIS_MODULE;
2606 ctrldesc->pctlops = &rockchip_pctrl_ops;
2607 ctrldesc->pmxops = &rockchip_pmx_ops;
2608 ctrldesc->confops = &rockchip_pinconf_ops;
2609
Kees Cooka86854d2018-06-12 14:07:58 -07002610 pindesc = devm_kcalloc(&pdev->dev,
2611 info->ctrl->nr_pins, sizeof(*pindesc),
2612 GFP_KERNEL);
Markus Elfring98c8ee72017-12-23 22:02:47 +01002613 if (!pindesc)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002614 return -ENOMEM;
Markus Elfring98c8ee72017-12-23 22:02:47 +01002615
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002616 ctrldesc->pins = pindesc;
2617 ctrldesc->npins = info->ctrl->nr_pins;
2618
2619 pdesc = pindesc;
2620 for (bank = 0 , k = 0; bank < info->ctrl->nr_banks; bank++) {
2621 pin_bank = &info->ctrl->pin_banks[bank];
2622 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2623 pdesc->number = k;
2624 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2625 pin_bank->name, pin);
2626 pdesc++;
2627 }
2628 }
2629
Doug Anderson0fb7dcb2014-10-21 10:47:34 -07002630 ret = rockchip_pinctrl_parse_dt(pdev, info);
2631 if (ret)
2632 return ret;
2633
Laxman Dewangan0085a2b2016-02-24 14:44:07 +05302634 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002635 if (IS_ERR(info->pctl_dev)) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002636 dev_err(&pdev->dev, "could not register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002637 return PTR_ERR(info->pctl_dev);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002638 }
2639
2640 for (bank = 0; bank < info->ctrl->nr_banks; ++bank) {
2641 pin_bank = &info->ctrl->pin_banks[bank];
2642 pin_bank->grange.name = pin_bank->name;
2643 pin_bank->grange.id = bank;
2644 pin_bank->grange.pin_base = pin_bank->pin_base;
2645 pin_bank->grange.base = pin_bank->gpio_chip.base;
2646 pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
2647 pin_bank->grange.gc = &pin_bank->gpio_chip;
2648 pinctrl_add_gpio_range(info->pctl_dev, &pin_bank->grange);
2649 }
2650
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002651 return 0;
2652}
2653
2654/*
2655 * GPIO handling
2656 */
2657
2658static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
2659{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002660 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002661 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR;
2662 unsigned long flags;
2663 u32 data;
2664
Lin Huang07a06ae2015-08-11 18:12:04 +08002665 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002666 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002667
2668 data = readl(reg);
2669 data &= ~BIT(offset);
2670 if (value)
2671 data |= BIT(offset);
2672 writel(data, reg);
2673
John Keeping70b7aa72017-03-23 10:59:29 +00002674 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08002675 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002676}
2677
2678/*
2679 * Returns the level of the pin for input direction and setting of the DR
2680 * register for output gpios.
2681 */
2682static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset)
2683{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002684 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002685 u32 data;
2686
Lin Huang07a06ae2015-08-11 18:12:04 +08002687 clk_enable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002688 data = readl(bank->reg_base + GPIO_EXT_PORT);
Lin Huang07a06ae2015-08-11 18:12:04 +08002689 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002690 data >>= offset;
2691 data &= 1;
2692 return data;
2693}
2694
2695/*
2696 * gpiolib gpio_direction_input callback function. The setting of the pin
Markus Elfring85dc3972017-12-23 22:22:54 +01002697 * mux function as 'gpio input' will be handled by the pinctrl subsystem
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002698 * interface.
2699 */
2700static int rockchip_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
2701{
2702 return pinctrl_gpio_direction_input(gc->base + offset);
2703}
2704
2705/*
2706 * gpiolib gpio_direction_output callback function. The setting of the pin
Markus Elfring85dc3972017-12-23 22:22:54 +01002707 * mux function as 'gpio output' will be handled by the pinctrl subsystem
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002708 * interface.
2709 */
2710static int rockchip_gpio_direction_output(struct gpio_chip *gc,
2711 unsigned offset, int value)
2712{
2713 rockchip_gpio_set(gc, offset, value);
2714 return pinctrl_gpio_direction_output(gc->base + offset);
2715}
2716
Shawn Linb97038a2018-05-03 16:04:42 +08002717static void rockchip_gpio_set_debounce(struct gpio_chip *gc,
2718 unsigned int offset, bool enable)
2719{
2720 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
2721 void __iomem *reg = bank->reg_base + GPIO_DEBOUNCE;
2722 unsigned long flags;
2723 u32 data;
2724
2725 clk_enable(bank->clk);
2726 raw_spin_lock_irqsave(&bank->slock, flags);
2727
2728 data = readl(reg);
2729 if (enable)
2730 data |= BIT(offset);
2731 else
2732 data &= ~BIT(offset);
2733 writel(data, reg);
2734
2735 raw_spin_unlock_irqrestore(&bank->slock, flags);
2736 clk_disable(bank->clk);
2737}
2738
2739/*
2740 * gpiolib set_config callback function. The setting of the pin
2741 * mux function as 'gpio output' will be handled by the pinctrl subsystem
2742 * interface.
2743 */
2744static int rockchip_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
2745 unsigned long config)
2746{
2747 enum pin_config_param param = pinconf_to_config_param(config);
2748
2749 switch (param) {
2750 case PIN_CONFIG_INPUT_DEBOUNCE:
2751 rockchip_gpio_set_debounce(gc, offset, true);
2752 /*
2753 * Rockchip's gpio could only support up to one period
2754 * of the debounce clock(pclk), which is far away from
2755 * satisftying the requirement, as pclk is usually near
2756 * 100MHz shared by all peripherals. So the fact is it
2757 * has crippled debounce capability could only be useful
2758 * to prevent any spurious glitches from waking up the system
2759 * if the gpio is conguired as wakeup interrupt source. Let's
2760 * still return -ENOTSUPP as before, to make sure the caller
2761 * of gpiod_set_debounce won't change its behaviour.
2762 */
2763 default:
2764 return -ENOTSUPP;
2765 }
2766}
2767
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002768/*
2769 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
2770 * and a virtual IRQ, if not already present.
2771 */
2772static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
2773{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002774 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002775 unsigned int virq;
2776
2777 if (!bank->domain)
2778 return -ENXIO;
2779
2780 virq = irq_create_mapping(bank->domain, offset);
2781
2782 return (virq) ? : -ENXIO;
2783}
2784
2785static const struct gpio_chip rockchip_gpiolib_chip = {
Jonas Gorski98c85d52015-10-11 17:34:19 +02002786 .request = gpiochip_generic_request,
2787 .free = gpiochip_generic_free,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002788 .set = rockchip_gpio_set,
2789 .get = rockchip_gpio_get,
Caesar Wang6ba20a02016-03-15 15:55:45 +08002790 .get_direction = rockchip_gpio_get_direction,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002791 .direction_input = rockchip_gpio_direction_input,
2792 .direction_output = rockchip_gpio_direction_output,
Shawn Linb97038a2018-05-03 16:04:42 +08002793 .set_config = rockchip_gpio_set_config,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002794 .to_irq = rockchip_gpio_to_irq,
2795 .owner = THIS_MODULE,
2796};
2797
2798/*
2799 * Interrupt handling
2800 */
2801
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +02002802static void rockchip_irq_demux(struct irq_desc *desc)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002803{
Jiang Liu5663bb22015-06-04 12:13:16 +08002804 struct irq_chip *chip = irq_desc_get_chip(desc);
2805 struct rockchip_pin_bank *bank = irq_desc_get_handler_data(desc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002806 u32 pend;
2807
2808 dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
2809
2810 chained_irq_enter(chip, desc);
2811
2812 pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
2813
2814 while (pend) {
Thomas Gleixner415f7482015-07-13 01:52:00 +02002815 unsigned int irq, virq;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002816
2817 irq = __ffs(pend);
2818 pend &= ~BIT(irq);
2819 virq = irq_linear_revmap(bank->domain, irq);
2820
2821 if (!virq) {
2822 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
2823 continue;
2824 }
2825
2826 dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
2827
Heiko Stübner5a927502013-10-16 01:09:08 +02002828 /*
2829 * Triggering IRQ on both rising and falling edge
2830 * needs manual intervention.
2831 */
2832 if (bank->toggle_edge_mode & BIT(irq)) {
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002833 u32 data, data_old, polarity;
2834 unsigned long flags;
Heiko Stübner5a927502013-10-16 01:09:08 +02002835
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002836 data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
2837 do {
John Keeping70b7aa72017-03-23 10:59:29 +00002838 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002839
2840 polarity = readl_relaxed(bank->reg_base +
2841 GPIO_INT_POLARITY);
2842 if (data & BIT(irq))
2843 polarity &= ~BIT(irq);
2844 else
2845 polarity |= BIT(irq);
2846 writel(polarity,
2847 bank->reg_base + GPIO_INT_POLARITY);
2848
John Keeping70b7aa72017-03-23 10:59:29 +00002849 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002850
2851 data_old = data;
2852 data = readl_relaxed(bank->reg_base +
2853 GPIO_EXT_PORT);
2854 } while ((data & BIT(irq)) != (data_old & BIT(irq)));
Heiko Stübner5a927502013-10-16 01:09:08 +02002855 }
2856
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002857 generic_handle_irq(virq);
2858 }
2859
2860 chained_irq_exit(chip, desc);
2861}
2862
2863static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
2864{
2865 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2866 struct rockchip_pin_bank *bank = gc->private;
2867 u32 mask = BIT(d->hwirq);
2868 u32 polarity;
2869 u32 level;
2870 u32 data;
Doug Andersonfab262f2014-10-21 10:47:35 -07002871 unsigned long flags;
Heiko Stübner14797182014-03-26 00:57:00 +01002872 int ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002873
Heiko Stübner5a927502013-10-16 01:09:08 +02002874 /* make sure the pin is configured as gpio input */
Brian Norris1d80df92017-06-23 13:59:11 -07002875 ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
Heiko Stübner14797182014-03-26 00:57:00 +01002876 if (ret < 0)
2877 return ret;
2878
Brian Norris1d80df92017-06-23 13:59:11 -07002879 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002880 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002881
Heiko Stübner5a927502013-10-16 01:09:08 +02002882 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2883 data &= ~mask;
2884 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2885
John Keeping70b7aa72017-03-23 10:59:29 +00002886 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002887
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002888 if (type & IRQ_TYPE_EDGE_BOTH)
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002889 irq_set_handler_locked(d, handle_edge_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002890 else
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002891 irq_set_handler_locked(d, handle_level_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002892
John Keeping70b7aa72017-03-23 10:59:29 +00002893 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002894 irq_gc_lock(gc);
2895
2896 level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL);
2897 polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
2898
2899 switch (type) {
Heiko Stübner5a927502013-10-16 01:09:08 +02002900 case IRQ_TYPE_EDGE_BOTH:
2901 bank->toggle_edge_mode |= mask;
2902 level |= mask;
2903
2904 /*
2905 * Determine gpio state. If 1 next interrupt should be falling
2906 * otherwise rising.
2907 */
2908 data = readl(bank->reg_base + GPIO_EXT_PORT);
2909 if (data & mask)
2910 polarity &= ~mask;
2911 else
2912 polarity |= mask;
2913 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002914 case IRQ_TYPE_EDGE_RISING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002915 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002916 level |= mask;
2917 polarity |= mask;
2918 break;
2919 case IRQ_TYPE_EDGE_FALLING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002920 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002921 level |= mask;
2922 polarity &= ~mask;
2923 break;
2924 case IRQ_TYPE_LEVEL_HIGH:
Heiko Stübner5a927502013-10-16 01:09:08 +02002925 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002926 level &= ~mask;
2927 polarity |= mask;
2928 break;
2929 case IRQ_TYPE_LEVEL_LOW:
Heiko Stübner5a927502013-10-16 01:09:08 +02002930 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002931 level &= ~mask;
2932 polarity &= ~mask;
2933 break;
2934 default:
Axel Lin7cc5f972013-06-23 08:48:34 +08002935 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002936 raw_spin_unlock_irqrestore(&bank->slock, flags);
Brian Norris1d80df92017-06-23 13:59:11 -07002937 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002938 return -EINVAL;
2939 }
2940
2941 writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL);
2942 writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY);
2943
2944 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002945 raw_spin_unlock_irqrestore(&bank->slock, flags);
Brian Norris1d80df92017-06-23 13:59:11 -07002946 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002947
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002948 return 0;
2949}
2950
Doug Anderson68bda472014-11-19 14:51:32 -08002951static void rockchip_irq_suspend(struct irq_data *d)
2952{
2953 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2954 struct rockchip_pin_bank *bank = gc->private;
2955
Lin Huang07a06ae2015-08-11 18:12:04 +08002956 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002957 bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK);
2958 irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002959 clk_disable(bank->clk);
Doug Anderson68bda472014-11-19 14:51:32 -08002960}
2961
2962static void rockchip_irq_resume(struct irq_data *d)
2963{
2964 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2965 struct rockchip_pin_bank *bank = gc->private;
2966
Lin Huang07a06ae2015-08-11 18:12:04 +08002967 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002968 irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002969 clk_disable(bank->clk);
2970}
2971
Jeffy Chend4682892017-03-02 13:56:52 +08002972static void rockchip_irq_enable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08002973{
2974 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2975 struct rockchip_pin_bank *bank = gc->private;
2976
2977 clk_enable(bank->clk);
2978 irq_gc_mask_clr_bit(d);
2979}
2980
Jeffy Chend4682892017-03-02 13:56:52 +08002981static void rockchip_irq_disable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08002982{
2983 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2984 struct rockchip_pin_bank *bank = gc->private;
2985
2986 irq_gc_mask_set_bit(d);
2987 clk_disable(bank->clk);
Doug Andersonf2dd0282014-11-19 14:51:33 -08002988}
2989
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002990static int rockchip_interrupts_register(struct platform_device *pdev,
2991 struct rockchip_pinctrl *info)
2992{
2993 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2994 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2995 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
2996 struct irq_chip_generic *gc;
2997 int ret;
Lin Huang07a06ae2015-08-11 18:12:04 +08002998 int i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002999
3000 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3001 if (!bank->valid) {
3002 dev_warn(&pdev->dev, "bank %s is not valid\n",
3003 bank->name);
3004 continue;
3005 }
3006
Lin Huang07a06ae2015-08-11 18:12:04 +08003007 ret = clk_enable(bank->clk);
3008 if (ret) {
3009 dev_err(&pdev->dev, "failed to enable clock for bank %s\n",
3010 bank->name);
3011 continue;
3012 }
3013
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003014 bank->domain = irq_domain_add_linear(bank->of_node, 32,
3015 &irq_generic_chip_ops, NULL);
3016 if (!bank->domain) {
3017 dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n",
3018 bank->name);
Lin Huang07a06ae2015-08-11 18:12:04 +08003019 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003020 continue;
3021 }
3022
3023 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
3024 "rockchip_gpio_irq", handle_level_irq,
3025 clr, 0, IRQ_GC_INIT_MASK_CACHE);
3026 if (ret) {
3027 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
3028 bank->name);
3029 irq_domain_remove(bank->domain);
Lin Huang07a06ae2015-08-11 18:12:04 +08003030 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003031 continue;
3032 }
3033
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08003034 /*
3035 * Linux assumes that all interrupts start out disabled/masked.
3036 * Our driver only uses the concept of masked and always keeps
3037 * things enabled, so for us that's all masked and all enabled.
3038 */
3039 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
3040 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
3041
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003042 gc = irq_get_domain_generic_chip(bank->domain, 0);
3043 gc->reg_base = bank->reg_base;
3044 gc->private = bank;
Doug Andersonf2dd0282014-11-19 14:51:33 -08003045 gc->chip_types[0].regs.mask = GPIO_INTMASK;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003046 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
3047 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
Jeffy Chend4682892017-03-02 13:56:52 +08003048 gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
3049 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit;
3050 gc->chip_types[0].chip.irq_enable = rockchip_irq_enable;
3051 gc->chip_types[0].chip.irq_disable = rockchip_irq_disable;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003052 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
Doug Anderson68bda472014-11-19 14:51:32 -08003053 gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend;
3054 gc->chip_types[0].chip.irq_resume = rockchip_irq_resume;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003055 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
Doug Anderson876d7162014-10-21 10:47:32 -07003056 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003057
Thomas Gleixner03051bc2015-06-21 21:11:06 +02003058 irq_set_chained_handler_and_data(bank->irq,
3059 rockchip_irq_demux, bank);
Lin Huang07a06ae2015-08-11 18:12:04 +08003060
3061 /* map the gpio irqs here, when the clock is still running */
3062 for (j = 0 ; j < 32 ; j++)
3063 irq_create_mapping(bank->domain, j);
3064
3065 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003066 }
3067
3068 return 0;
3069}
3070
3071static int rockchip_gpiolib_register(struct platform_device *pdev,
3072 struct rockchip_pinctrl *info)
3073{
3074 struct rockchip_pin_ctrl *ctrl = info->ctrl;
3075 struct rockchip_pin_bank *bank = ctrl->pin_banks;
3076 struct gpio_chip *gc;
3077 int ret;
3078 int i;
3079
3080 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3081 if (!bank->valid) {
3082 dev_warn(&pdev->dev, "bank %s is not valid\n",
3083 bank->name);
3084 continue;
3085 }
3086
3087 bank->gpio_chip = rockchip_gpiolib_chip;
3088
3089 gc = &bank->gpio_chip;
3090 gc->base = bank->pin_base;
3091 gc->ngpio = bank->nr_pins;
Linus Walleij58383c782015-11-04 09:56:26 +01003092 gc->parent = &pdev->dev;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003093 gc->of_node = bank->of_node;
3094 gc->label = bank->name;
3095
Linus Walleij03bf81f2015-12-08 09:39:13 +01003096 ret = gpiochip_add_data(gc, bank);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003097 if (ret) {
3098 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
3099 gc->label, ret);
3100 goto fail;
3101 }
3102 }
3103
3104 rockchip_interrupts_register(pdev, info);
3105
3106 return 0;
3107
3108fail:
3109 for (--i, --bank; i >= 0; --i, --bank) {
3110 if (!bank->valid)
3111 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003112 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003113 }
3114 return ret;
3115}
3116
3117static int rockchip_gpiolib_unregister(struct platform_device *pdev,
3118 struct rockchip_pinctrl *info)
3119{
3120 struct rockchip_pin_ctrl *ctrl = info->ctrl;
3121 struct rockchip_pin_bank *bank = ctrl->pin_banks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003122 int i;
3123
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003124 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003125 if (!bank->valid)
3126 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003127 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003128 }
3129
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02003130 return 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003131}
3132
3133static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
Heiko Stübner622f3232014-05-05 13:58:46 +02003134 struct rockchip_pinctrl *info)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003135{
3136 struct resource res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02003137 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003138
3139 if (of_address_to_resource(bank->of_node, 0, &res)) {
Heiko Stübner622f3232014-05-05 13:58:46 +02003140 dev_err(info->dev, "cannot find IO resource for bank\n");
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003141 return -ENOENT;
3142 }
3143
Heiko Stübner622f3232014-05-05 13:58:46 +02003144 bank->reg_base = devm_ioremap_resource(info->dev, &res);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003145 if (IS_ERR(bank->reg_base))
3146 return PTR_ERR(bank->reg_base);
3147
Heiko Stübner6ca52742013-10-16 01:08:42 +02003148 /*
3149 * special case, where parts of the pull setting-registers are
3150 * part of the PMU register space
3151 */
3152 if (of_device_is_compatible(bank->of_node,
3153 "rockchip,rk3188-gpio-bank0")) {
Heiko Stübnera658efa2014-05-05 13:59:30 +02003154 struct device_node *node;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02003155
Heiko Stübnera658efa2014-05-05 13:59:30 +02003156 node = of_parse_phandle(bank->of_node->parent,
3157 "rockchip,pmu", 0);
3158 if (!node) {
3159 if (of_address_to_resource(bank->of_node, 1, &res)) {
3160 dev_err(info->dev, "cannot find IO resource for bank\n");
3161 return -ENOENT;
3162 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003163
Heiko Stübnera658efa2014-05-05 13:59:30 +02003164 base = devm_ioremap_resource(info->dev, &res);
3165 if (IS_ERR(base))
3166 return PTR_ERR(base);
3167 rockchip_regmap_config.max_register =
3168 resource_size(&res) - 4;
3169 rockchip_regmap_config.name =
3170 "rockchip,rk3188-gpio-bank0-pull";
3171 bank->regmap_pull = devm_regmap_init_mmio(info->dev,
3172 base,
3173 &rockchip_regmap_config);
3174 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003175 }
Heiko Stübner65fca612013-10-16 01:07:49 +02003176
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003177 bank->irq = irq_of_parse_and_map(bank->of_node, 0);
3178
3179 bank->clk = of_clk_get(bank->of_node, 0);
3180 if (IS_ERR(bank->clk))
3181 return PTR_ERR(bank->clk);
3182
Lin Huang07a06ae2015-08-11 18:12:04 +08003183 return clk_prepare(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003184}
3185
3186static const struct of_device_id rockchip_pinctrl_dt_match[];
3187
3188/* retrieve the soc specific data */
3189static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
3190 struct rockchip_pinctrl *d,
3191 struct platform_device *pdev)
3192{
3193 const struct of_device_id *match;
3194 struct device_node *node = pdev->dev.of_node;
3195 struct device_node *np;
3196 struct rockchip_pin_ctrl *ctrl;
3197 struct rockchip_pin_bank *bank;
David Wub6c23272016-02-01 10:58:21 +08003198 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003199
3200 match = of_match_node(rockchip_pinctrl_dt_match, node);
3201 ctrl = (struct rockchip_pin_ctrl *)match->data;
3202
3203 for_each_child_of_node(node, np) {
3204 if (!of_find_property(np, "gpio-controller", NULL))
3205 continue;
3206
3207 bank = ctrl->pin_banks;
3208 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
3209 if (!strcmp(bank->name, np->name)) {
3210 bank->of_node = np;
3211
Heiko Stübner622f3232014-05-05 13:58:46 +02003212 if (!rockchip_get_bank_data(bank, d))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003213 bank->valid = true;
3214
3215 break;
3216 }
3217 }
3218 }
3219
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003220 grf_offs = ctrl->grf_mux_offset;
3221 pmu_offs = ctrl->pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +08003222 drv_pmu_offs = ctrl->pmu_drv_offset;
3223 drv_grf_offs = ctrl->grf_drv_offset;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003224 bank = ctrl->pin_banks;
3225 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003226 int bank_pins = 0;
3227
John Keeping70b7aa72017-03-23 10:59:29 +00003228 raw_spin_lock_init(&bank->slock);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003229 bank->drvdata = d;
3230 bank->pin_base = ctrl->nr_pins;
3231 ctrl->nr_pins += bank->nr_pins;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003232
David Wub6c23272016-02-01 10:58:21 +08003233 /* calculate iomux and drv offsets */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003234 for (j = 0; j < 4; j++) {
3235 struct rockchip_iomux *iom = &bank->iomux[j];
David Wub6c23272016-02-01 10:58:21 +08003236 struct rockchip_drv *drv = &bank->drv[j];
Heiko Stübner03716e12014-06-16 01:36:57 +02003237 int inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003238
3239 if (bank_pins >= bank->nr_pins)
3240 break;
3241
David Wub6c23272016-02-01 10:58:21 +08003242 /* preset iomux offset value, set new start value */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003243 if (iom->offset >= 0) {
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003244 if (iom->type & IOMUX_SOURCE_PMU)
3245 pmu_offs = iom->offset;
3246 else
3247 grf_offs = iom->offset;
David Wub6c23272016-02-01 10:58:21 +08003248 } else { /* set current iomux offset */
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003249 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3250 pmu_offs : grf_offs;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003251 }
3252
David Wub6c23272016-02-01 10:58:21 +08003253 /* preset drv offset value, set new start value */
3254 if (drv->offset >= 0) {
3255 if (iom->type & IOMUX_SOURCE_PMU)
3256 drv_pmu_offs = drv->offset;
3257 else
3258 drv_grf_offs = drv->offset;
3259 } else { /* set current drv offset */
3260 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
3261 drv_pmu_offs : drv_grf_offs;
3262 }
3263
3264 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
3265 i, j, iom->offset, drv->offset);
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003266
3267 /*
3268 * Increase offset according to iomux width.
Heiko Stübner03716e12014-06-16 01:36:57 +02003269 * 4bit iomux'es are spread over two registers.
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003270 */
david.wu8b6c6f92017-02-10 18:23:47 +08003271 inc = (iom->type & (IOMUX_WIDTH_4BIT |
3272 IOMUX_WIDTH_3BIT)) ? 8 : 4;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003273 if (iom->type & IOMUX_SOURCE_PMU)
3274 pmu_offs += inc;
3275 else
3276 grf_offs += inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003277
David Wub6c23272016-02-01 10:58:21 +08003278 /*
3279 * Increase offset according to drv width.
3280 * 3bit drive-strenth'es are spread over two registers.
3281 */
3282 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
3283 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
3284 inc = 8;
3285 else
3286 inc = 4;
3287
3288 if (iom->type & IOMUX_SOURCE_PMU)
3289 drv_pmu_offs += inc;
3290 else
3291 drv_grf_offs += inc;
3292
Heiko Stübner6bc0d122014-06-16 01:36:33 +02003293 bank_pins += 8;
3294 }
David Wubd35b9b2017-05-26 15:20:20 +08003295
David Wuc04c3fa2017-07-21 14:27:14 +08003296 /* calculate the per-bank recalced_mask */
3297 for (j = 0; j < ctrl->niomux_recalced; j++) {
3298 int pin = 0;
3299
3300 if (ctrl->iomux_recalced[j].num == bank->bank_num) {
3301 pin = ctrl->iomux_recalced[j].pin;
3302 bank->recalced_mask |= BIT(pin);
3303 }
3304 }
3305
David Wubd35b9b2017-05-26 15:20:20 +08003306 /* calculate the per-bank route_mask */
3307 for (j = 0; j < ctrl->niomux_routes; j++) {
3308 int pin = 0;
3309
3310 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
3311 pin = ctrl->iomux_routes[j].pin;
3312 bank->route_mask |= BIT(pin);
3313 }
3314 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003315 }
3316
3317 return ctrl;
3318}
3319
Chris Zhong8dca9332014-10-29 19:52:00 +08003320#define RK3288_GRF_GPIO6C_IOMUX 0x64
3321#define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
3322
3323static u32 rk3288_grf_gpio6c_iomux;
3324
Chris Zhong9198f502014-10-29 19:51:59 +08003325static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
3326{
3327 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08003328 int ret = pinctrl_force_sleep(info->pctl_dev);
Chris Zhong9198f502014-10-29 19:51:59 +08003329
Chris Zhong8dca9332014-10-29 19:52:00 +08003330 if (ret)
3331 return ret;
3332
3333 /*
3334 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
3335 * the setting here, and restore it at resume.
3336 */
3337 if (info->ctrl->type == RK3288) {
3338 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3339 &rk3288_grf_gpio6c_iomux);
3340 if (ret) {
3341 pinctrl_force_default(info->pctl_dev);
3342 return ret;
3343 }
3344 }
3345
3346 return 0;
Chris Zhong9198f502014-10-29 19:51:59 +08003347}
3348
3349static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
3350{
3351 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08003352 int ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
3353 rk3288_grf_gpio6c_iomux |
3354 GPIO6C6_SEL_WRITE_ENABLE);
3355
3356 if (ret)
3357 return ret;
Chris Zhong9198f502014-10-29 19:51:59 +08003358
3359 return pinctrl_force_default(info->pctl_dev);
3360}
3361
3362static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
3363 rockchip_pinctrl_resume);
3364
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003365static int rockchip_pinctrl_probe(struct platform_device *pdev)
3366{
3367 struct rockchip_pinctrl *info;
3368 struct device *dev = &pdev->dev;
3369 struct rockchip_pin_ctrl *ctrl;
Heiko Stübner14dee862014-05-05 13:59:09 +02003370 struct device_node *np = pdev->dev.of_node, *node;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003371 struct resource *res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02003372 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003373 int ret;
3374
3375 if (!dev->of_node) {
3376 dev_err(dev, "device tree node not found\n");
3377 return -ENODEV;
3378 }
3379
Markus Elfring283b7ac2017-12-23 22:07:30 +01003380 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003381 if (!info)
3382 return -ENOMEM;
3383
Heiko Stübner622f3232014-05-05 13:58:46 +02003384 info->dev = dev;
3385
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003386 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
3387 if (!ctrl) {
3388 dev_err(dev, "driver data not available\n");
3389 return -EINVAL;
3390 }
3391 info->ctrl = ctrl;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003392
Heiko Stübner1e747e52014-05-05 13:59:51 +02003393 node = of_parse_phandle(np, "rockchip,grf", 0);
3394 if (node) {
3395 info->regmap_base = syscon_node_to_regmap(node);
3396 if (IS_ERR(info->regmap_base))
3397 return PTR_ERR(info->regmap_base);
3398 } else {
3399 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Heiko Stübner751a99a2014-05-05 13:58:20 +02003400 base = devm_ioremap_resource(&pdev->dev, res);
3401 if (IS_ERR(base))
3402 return PTR_ERR(base);
3403
3404 rockchip_regmap_config.max_register = resource_size(res) - 4;
Heiko Stübner1e747e52014-05-05 13:59:51 +02003405 rockchip_regmap_config.name = "rockchip,pinctrl";
3406 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
3407 &rockchip_regmap_config);
3408
3409 /* to check for the old dt-bindings */
3410 info->reg_size = resource_size(res);
3411
3412 /* Honor the old binding, with pull registers as 2nd resource */
3413 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
3414 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3415 base = devm_ioremap_resource(&pdev->dev, res);
3416 if (IS_ERR(base))
3417 return PTR_ERR(base);
3418
3419 rockchip_regmap_config.max_register =
3420 resource_size(res) - 4;
3421 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
3422 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
3423 base,
3424 &rockchip_regmap_config);
3425 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003426 }
3427
Heiko Stübner14dee862014-05-05 13:59:09 +02003428 /* try to find the optional reference to the pmu syscon */
3429 node = of_parse_phandle(np, "rockchip,pmu", 0);
3430 if (node) {
3431 info->regmap_pmu = syscon_node_to_regmap(node);
3432 if (IS_ERR(info->regmap_pmu))
3433 return PTR_ERR(info->regmap_pmu);
3434 }
3435
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003436 ret = rockchip_gpiolib_register(pdev, info);
3437 if (ret)
3438 return ret;
3439
3440 ret = rockchip_pinctrl_register(pdev, info);
3441 if (ret) {
3442 rockchip_gpiolib_unregister(pdev, info);
3443 return ret;
3444 }
3445
3446 platform_set_drvdata(pdev, info);
3447
3448 return 0;
3449}
3450
David Wu87065ca2018-05-14 19:59:51 +08003451static struct rockchip_pin_bank px30_pin_banks[] = {
3452 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3453 IOMUX_SOURCE_PMU,
3454 IOMUX_SOURCE_PMU,
3455 IOMUX_SOURCE_PMU
3456 ),
3457 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_WIDTH_4BIT,
3458 IOMUX_WIDTH_4BIT,
3459 IOMUX_WIDTH_4BIT,
3460 IOMUX_WIDTH_4BIT
3461 ),
3462 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", IOMUX_WIDTH_4BIT,
3463 IOMUX_WIDTH_4BIT,
3464 IOMUX_WIDTH_4BIT,
3465 IOMUX_WIDTH_4BIT
3466 ),
3467 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", IOMUX_WIDTH_4BIT,
3468 IOMUX_WIDTH_4BIT,
3469 IOMUX_WIDTH_4BIT,
3470 IOMUX_WIDTH_4BIT
3471 ),
3472};
3473
3474static struct rockchip_pin_ctrl px30_pin_ctrl = {
3475 .pin_banks = px30_pin_banks,
3476 .nr_banks = ARRAY_SIZE(px30_pin_banks),
3477 .label = "PX30-GPIO",
3478 .type = PX30,
3479 .grf_mux_offset = 0x0,
3480 .pmu_mux_offset = 0x0,
3481 .iomux_routes = px30_mux_route_data,
3482 .niomux_routes = ARRAY_SIZE(px30_mux_route_data),
3483 .pull_calc_reg = px30_calc_pull_reg_and_bit,
3484 .drv_calc_reg = px30_calc_drv_reg_and_bit,
3485 .schmitt_calc_reg = px30_calc_schmitt_reg_and_bit,
3486};
3487
Andy Yanb9c6dca2017-03-17 18:18:36 +01003488static struct rockchip_pin_bank rv1108_pin_banks[] = {
Andy Yan688daf22016-11-15 18:02:43 +08003489 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3490 IOMUX_SOURCE_PMU,
3491 IOMUX_SOURCE_PMU,
3492 IOMUX_SOURCE_PMU),
3493 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3494 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3495 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3496};
3497
Andy Yanb9c6dca2017-03-17 18:18:36 +01003498static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
3499 .pin_banks = rv1108_pin_banks,
3500 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
3501 .label = "RV1108-GPIO",
3502 .type = RV1108,
Andy Yan688daf22016-11-15 18:02:43 +08003503 .grf_mux_offset = 0x10,
3504 .pmu_mux_offset = 0x0,
David Wu12b8f012017-08-23 16:00:07 +08003505 .iomux_recalced = rv1108_mux_recalced_data,
3506 .niomux_recalced = ARRAY_SIZE(rv1108_mux_recalced_data),
Andy Yanb9c6dca2017-03-17 18:18:36 +01003507 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
3508 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
Andy Yan5caff7e2017-07-31 18:10:22 +08003509 .schmitt_calc_reg = rv1108_calc_schmitt_reg_and_bit,
Andy Yan688daf22016-11-15 18:02:43 +08003510};
3511
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003512static struct rockchip_pin_bank rk2928_pin_banks[] = {
3513 PIN_BANK(0, 32, "gpio0"),
3514 PIN_BANK(1, 32, "gpio1"),
3515 PIN_BANK(2, 32, "gpio2"),
3516 PIN_BANK(3, 32, "gpio3"),
3517};
3518
3519static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
3520 .pin_banks = rk2928_pin_banks,
3521 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
3522 .label = "RK2928-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003523 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003524 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003525 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003526};
3527
Xing Zhengc5ce7672015-08-28 13:46:47 +08003528static struct rockchip_pin_bank rk3036_pin_banks[] = {
3529 PIN_BANK(0, 32, "gpio0"),
3530 PIN_BANK(1, 32, "gpio1"),
3531 PIN_BANK(2, 32, "gpio2"),
3532};
3533
3534static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
3535 .pin_banks = rk3036_pin_banks,
3536 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
3537 .label = "RK3036-GPIO",
3538 .type = RK2928,
3539 .grf_mux_offset = 0xa8,
3540 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3541};
3542
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003543static struct rockchip_pin_bank rk3066a_pin_banks[] = {
3544 PIN_BANK(0, 32, "gpio0"),
3545 PIN_BANK(1, 32, "gpio1"),
3546 PIN_BANK(2, 32, "gpio2"),
3547 PIN_BANK(3, 32, "gpio3"),
3548 PIN_BANK(4, 32, "gpio4"),
3549 PIN_BANK(6, 16, "gpio6"),
3550};
3551
3552static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
3553 .pin_banks = rk3066a_pin_banks,
3554 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
3555 .label = "RK3066a-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003556 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003557 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003558 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003559};
3560
3561static struct rockchip_pin_bank rk3066b_pin_banks[] = {
3562 PIN_BANK(0, 32, "gpio0"),
3563 PIN_BANK(1, 32, "gpio1"),
3564 PIN_BANK(2, 32, "gpio2"),
3565 PIN_BANK(3, 32, "gpio3"),
3566};
3567
3568static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
3569 .pin_banks = rk3066b_pin_banks,
3570 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
3571 .label = "RK3066b-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003572 .type = RK3066B,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003573 .grf_mux_offset = 0x60,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003574};
3575
David Wud23c66d2017-07-21 14:27:15 +08003576static struct rockchip_pin_bank rk3128_pin_banks[] = {
3577 PIN_BANK(0, 32, "gpio0"),
3578 PIN_BANK(1, 32, "gpio1"),
3579 PIN_BANK(2, 32, "gpio2"),
3580 PIN_BANK(3, 32, "gpio3"),
3581};
3582
3583static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
3584 .pin_banks = rk3128_pin_banks,
3585 .nr_banks = ARRAY_SIZE(rk3128_pin_banks),
3586 .label = "RK3128-GPIO",
3587 .type = RK3128,
3588 .grf_mux_offset = 0xa8,
3589 .iomux_recalced = rk3128_mux_recalced_data,
3590 .niomux_recalced = ARRAY_SIZE(rk3128_mux_recalced_data),
3591 .iomux_routes = rk3128_mux_route_data,
3592 .niomux_routes = ARRAY_SIZE(rk3128_mux_route_data),
3593 .pull_calc_reg = rk3128_calc_pull_reg_and_bit,
3594};
3595
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003596static struct rockchip_pin_bank rk3188_pin_banks[] = {
Heiko Stübnerfc72c922014-06-16 01:36:05 +02003597 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003598 PIN_BANK(1, 32, "gpio1"),
3599 PIN_BANK(2, 32, "gpio2"),
3600 PIN_BANK(3, 32, "gpio3"),
3601};
3602
3603static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
3604 .pin_banks = rk3188_pin_banks,
3605 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
3606 .label = "RK3188-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003607 .type = RK3188,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003608 .grf_mux_offset = 0x60,
Heiko Stübner6ca52742013-10-16 01:08:42 +02003609 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003610};
3611
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003612static struct rockchip_pin_bank rk3228_pin_banks[] = {
3613 PIN_BANK(0, 32, "gpio0"),
3614 PIN_BANK(1, 32, "gpio1"),
3615 PIN_BANK(2, 32, "gpio2"),
3616 PIN_BANK(3, 32, "gpio3"),
3617};
3618
3619static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
3620 .pin_banks = rk3228_pin_banks,
3621 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
3622 .label = "RK3228-GPIO",
3623 .type = RK3288,
3624 .grf_mux_offset = 0x0,
David Wud4970ee2017-05-26 15:20:21 +08003625 .iomux_routes = rk3228_mux_route_data,
3626 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003627 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3628 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3629};
3630
Heiko Stübner304f0772014-06-16 01:38:14 +02003631static struct rockchip_pin_bank rk3288_pin_banks[] = {
3632 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
3633 IOMUX_SOURCE_PMU,
3634 IOMUX_SOURCE_PMU,
3635 IOMUX_UNROUTED
3636 ),
3637 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
3638 IOMUX_UNROUTED,
3639 IOMUX_UNROUTED,
3640 0
3641 ),
3642 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3643 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3644 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3645 IOMUX_WIDTH_4BIT,
3646 0,
3647 0
3648 ),
3649 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3650 0,
3651 0,
3652 IOMUX_UNROUTED
3653 ),
3654 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3655 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3656 0,
3657 IOMUX_WIDTH_4BIT,
3658 IOMUX_UNROUTED
3659 ),
3660 PIN_BANK(8, 16, "gpio8"),
3661};
3662
3663static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3664 .pin_banks = rk3288_pin_banks,
3665 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3666 .label = "RK3288-GPIO",
Heiko Stübner66d750e2014-07-20 01:49:17 +02003667 .type = RK3288,
Heiko Stübner304f0772014-06-16 01:38:14 +02003668 .grf_mux_offset = 0x0,
3669 .pmu_mux_offset = 0x84,
Heiko Stuebner4e96fd32017-10-21 10:53:10 +02003670 .iomux_routes = rk3288_mux_route_data,
3671 .niomux_routes = ARRAY_SIZE(rk3288_mux_route_data),
Heiko Stübner304f0772014-06-16 01:38:14 +02003672 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
Heiko Stübneref17f692015-06-12 23:50:11 +02003673 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
Heiko Stübner304f0772014-06-16 01:38:14 +02003674};
3675
david.wu3818e4a2017-02-10 18:23:49 +08003676static struct rockchip_pin_bank rk3328_pin_banks[] = {
3677 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3678 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3679 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
David Wuc04c3fa2017-07-21 14:27:14 +08003680 IOMUX_WIDTH_3BIT,
3681 IOMUX_WIDTH_3BIT,
david.wu3818e4a2017-02-10 18:23:49 +08003682 0),
3683 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3684 IOMUX_WIDTH_3BIT,
David Wuc04c3fa2017-07-21 14:27:14 +08003685 IOMUX_WIDTH_3BIT,
david.wu3818e4a2017-02-10 18:23:49 +08003686 0,
3687 0),
3688};
3689
3690static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3691 .pin_banks = rk3328_pin_banks,
3692 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3693 .label = "RK3328-GPIO",
3694 .type = RK3288,
3695 .grf_mux_offset = 0x0,
David Wuc04c3fa2017-07-21 14:27:14 +08003696 .iomux_recalced = rk3328_mux_recalced_data,
3697 .niomux_recalced = ARRAY_SIZE(rk3328_mux_recalced_data),
David Wucedc9642017-05-26 15:20:22 +08003698 .iomux_routes = rk3328_mux_route_data,
3699 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
david.wu3818e4a2017-02-10 18:23:49 +08003700 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3701 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
david.wu728d3f52017-03-02 15:11:24 +08003702 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
david.wu3818e4a2017-02-10 18:23:49 +08003703};
3704
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003705static struct rockchip_pin_bank rk3368_pin_banks[] = {
3706 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3707 IOMUX_SOURCE_PMU,
3708 IOMUX_SOURCE_PMU,
3709 IOMUX_SOURCE_PMU
3710 ),
3711 PIN_BANK(1, 32, "gpio1"),
3712 PIN_BANK(2, 32, "gpio2"),
3713 PIN_BANK(3, 32, "gpio3"),
3714};
3715
3716static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3717 .pin_banks = rk3368_pin_banks,
3718 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3719 .label = "RK3368-GPIO",
3720 .type = RK3368,
3721 .grf_mux_offset = 0x0,
3722 .pmu_mux_offset = 0x0,
3723 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3724 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3725};
3726
David Wub6c23272016-02-01 10:58:21 +08003727static struct rockchip_pin_bank rk3399_pin_banks[] = {
David Wu3ba67672016-05-11 11:39:28 +08003728 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3729 IOMUX_SOURCE_PMU,
3730 IOMUX_SOURCE_PMU,
3731 IOMUX_SOURCE_PMU,
3732 IOMUX_SOURCE_PMU,
3733 DRV_TYPE_IO_1V8_ONLY,
3734 DRV_TYPE_IO_1V8_ONLY,
3735 DRV_TYPE_IO_DEFAULT,
3736 DRV_TYPE_IO_DEFAULT,
David Wuc437f652017-09-30 20:13:20 +08003737 0x80,
3738 0x88,
David Wu3ba67672016-05-11 11:39:28 +08003739 -1,
3740 -1,
3741 PULL_TYPE_IO_1V8_ONLY,
3742 PULL_TYPE_IO_1V8_ONLY,
3743 PULL_TYPE_IO_DEFAULT,
3744 PULL_TYPE_IO_DEFAULT
3745 ),
David Wub6c23272016-02-01 10:58:21 +08003746 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3747 IOMUX_SOURCE_PMU,
3748 IOMUX_SOURCE_PMU,
3749 IOMUX_SOURCE_PMU,
3750 DRV_TYPE_IO_1V8_OR_3V0,
3751 DRV_TYPE_IO_1V8_OR_3V0,
3752 DRV_TYPE_IO_1V8_OR_3V0,
3753 DRV_TYPE_IO_1V8_OR_3V0,
David Wuc437f652017-09-30 20:13:20 +08003754 0xa0,
3755 0xa8,
3756 0xb0,
3757 0xb8
David Wub6c23272016-02-01 10:58:21 +08003758 ),
David Wu3ba67672016-05-11 11:39:28 +08003759 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3760 DRV_TYPE_IO_1V8_OR_3V0,
3761 DRV_TYPE_IO_1V8_ONLY,
3762 DRV_TYPE_IO_1V8_ONLY,
3763 PULL_TYPE_IO_DEFAULT,
3764 PULL_TYPE_IO_DEFAULT,
3765 PULL_TYPE_IO_1V8_ONLY,
3766 PULL_TYPE_IO_1V8_ONLY
3767 ),
David Wub6c23272016-02-01 10:58:21 +08003768 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3769 DRV_TYPE_IO_3V3_ONLY,
3770 DRV_TYPE_IO_3V3_ONLY,
3771 DRV_TYPE_IO_1V8_OR_3V0
3772 ),
3773 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3774 DRV_TYPE_IO_1V8_3V0_AUTO,
3775 DRV_TYPE_IO_1V8_OR_3V0,
3776 DRV_TYPE_IO_1V8_OR_3V0
3777 ),
3778};
3779
3780static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3781 .pin_banks = rk3399_pin_banks,
3782 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3783 .label = "RK3399-GPIO",
3784 .type = RK3399,
3785 .grf_mux_offset = 0xe000,
3786 .pmu_mux_offset = 0x0,
3787 .grf_drv_offset = 0xe100,
3788 .pmu_drv_offset = 0x80,
David Wuaccc1ce2017-05-26 15:20:23 +08003789 .iomux_routes = rk3399_mux_route_data,
3790 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
David Wub6c23272016-02-01 10:58:21 +08003791 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3792 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3793};
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003794
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003795static const struct of_device_id rockchip_pinctrl_dt_match[] = {
David Wu87065ca2018-05-14 19:59:51 +08003796 { .compatible = "rockchip,px30-pinctrl",
3797 .data = &px30_pin_ctrl },
Andy Yanb9c6dca2017-03-17 18:18:36 +01003798 { .compatible = "rockchip,rv1108-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003799 .data = &rv1108_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003800 { .compatible = "rockchip,rk2928-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003801 .data = &rk2928_pin_ctrl },
Xing Zhengc5ce7672015-08-28 13:46:47 +08003802 { .compatible = "rockchip,rk3036-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003803 .data = &rk3036_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003804 { .compatible = "rockchip,rk3066a-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003805 .data = &rk3066a_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003806 { .compatible = "rockchip,rk3066b-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003807 .data = &rk3066b_pin_ctrl },
David Wud23c66d2017-07-21 14:27:15 +08003808 { .compatible = "rockchip,rk3128-pinctrl",
3809 .data = (void *)&rk3128_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003810 { .compatible = "rockchip,rk3188-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003811 .data = &rk3188_pin_ctrl },
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003812 { .compatible = "rockchip,rk3228-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003813 .data = &rk3228_pin_ctrl },
Heiko Stübner304f0772014-06-16 01:38:14 +02003814 { .compatible = "rockchip,rk3288-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003815 .data = &rk3288_pin_ctrl },
david.wu3818e4a2017-02-10 18:23:49 +08003816 { .compatible = "rockchip,rk3328-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003817 .data = &rk3328_pin_ctrl },
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003818 { .compatible = "rockchip,rk3368-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003819 .data = &rk3368_pin_ctrl },
David Wub6c23272016-02-01 10:58:21 +08003820 { .compatible = "rockchip,rk3399-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003821 .data = &rk3399_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003822 {},
3823};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003824
3825static struct platform_driver rockchip_pinctrl_driver = {
3826 .probe = rockchip_pinctrl_probe,
3827 .driver = {
3828 .name = "rockchip-pinctrl",
Chris Zhong9198f502014-10-29 19:51:59 +08003829 .pm = &rockchip_pinctrl_dev_pm_ops,
Axel Lin0be9e702013-08-23 14:27:53 +08003830 .of_match_table = rockchip_pinctrl_dt_match,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003831 },
3832};
3833
3834static int __init rockchip_pinctrl_drv_register(void)
3835{
3836 return platform_driver_register(&rockchip_pinctrl_driver);
3837}
3838postcore_initcall(rockchip_pinctrl_drv_register);