blob: 607f52ceb697a98f46694d5b4304698f6a9e6172 [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>
30#include <linux/gpio.h>
31#include <linux/of_address.h>
32#include <linux/of_irq.h>
33#include <linux/pinctrl/machine.h>
34#include <linux/pinctrl/pinconf.h>
35#include <linux/pinctrl/pinctrl.h>
36#include <linux/pinctrl/pinmux.h>
37#include <linux/pinctrl/pinconf-generic.h>
38#include <linux/irqchip/chained_irq.h>
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 {
Andy Yanb9c6dca2017-03-17 18:18:36 +010062 RV1108,
Heiko Stübnera2829262013-10-16 01:07:20 +020063 RK2928,
64 RK3066B,
65 RK3188,
Heiko Stübner66d750e2014-07-20 01:49:17 +020066 RK3288,
Heiko Stübnerdaecdc62015-06-12 23:51:01 +020067 RK3368,
David Wub6c23272016-02-01 10:58:21 +080068 RK3399,
Heiko Stübnera2829262013-10-16 01:07:20 +020069};
70
Heiko Stübnerfc72c922014-06-16 01:36:05 +020071/**
72 * Encode variants of iomux registers into a type variable
73 */
74#define IOMUX_GPIO_ONLY BIT(0)
Heiko Stübner03716e12014-06-16 01:36:57 +020075#define IOMUX_WIDTH_4BIT BIT(1)
Heiko Stübner95ec8ae2014-06-16 01:37:23 +020076#define IOMUX_SOURCE_PMU BIT(2)
Heiko Stübner62f49222014-06-16 01:37:49 +020077#define IOMUX_UNROUTED BIT(3)
david.wu8b6c6f92017-02-10 18:23:47 +080078#define IOMUX_WIDTH_3BIT BIT(4)
david.wuea262ad2017-02-10 18:23:48 +080079#define IOMUX_RECALCED BIT(5)
Heiko Stübnerfc72c922014-06-16 01:36:05 +020080
81/**
82 * @type: iomux variant using IOMUX_* constants
Heiko Stübner6bc0d122014-06-16 01:36:33 +020083 * @offset: if initialized to -1 it will be autocalculated, by specifying
84 * an initial offset value the relevant source offset can be reset
85 * to a new value for autocalculating the following iomux registers.
Heiko Stübnerfc72c922014-06-16 01:36:05 +020086 */
87struct rockchip_iomux {
88 int type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +020089 int offset;
Heiko Stübner65fca612013-10-16 01:07:49 +020090};
91
Heiko Stübnerd3e51162013-06-10 22:16:22 +020092/**
David Wub6c23272016-02-01 10:58:21 +080093 * enum type index corresponding to rockchip_perpin_drv_list arrays index.
94 */
95enum rockchip_pin_drv_type {
96 DRV_TYPE_IO_DEFAULT = 0,
97 DRV_TYPE_IO_1V8_OR_3V0,
98 DRV_TYPE_IO_1V8_ONLY,
99 DRV_TYPE_IO_1V8_3V0_AUTO,
100 DRV_TYPE_IO_3V3_ONLY,
101 DRV_TYPE_MAX
102};
103
104/**
David Wu3ba67672016-05-11 11:39:28 +0800105 * enum type index corresponding to rockchip_pull_list arrays index.
106 */
107enum rockchip_pin_pull_type {
108 PULL_TYPE_IO_DEFAULT = 0,
109 PULL_TYPE_IO_1V8_ONLY,
110 PULL_TYPE_MAX
111};
112
113/**
David Wub6c23272016-02-01 10:58:21 +0800114 * @drv_type: drive strength variant using rockchip_perpin_drv_type
115 * @offset: if initialized to -1 it will be autocalculated, by specifying
116 * an initial offset value the relevant source offset can be reset
117 * to a new value for autocalculating the following drive strength
118 * registers. if used chips own cal_drv func instead to calculate
119 * registers offset, the variant could be ignored.
120 */
121struct rockchip_drv {
122 enum rockchip_pin_drv_type drv_type;
123 int offset;
124};
125
126/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200127 * @reg_base: register base of the gpio bank
Heiko Stübner6ca52742013-10-16 01:08:42 +0200128 * @reg_pull: optional separate register for additional pull settings
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200129 * @clk: clock of the gpio bank
130 * @irq: interrupt of the gpio bank
Doug Anderson5ae0c7a2015-01-26 08:24:03 -0800131 * @saved_masks: Saved content of GPIO_INTEN at suspend time.
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200132 * @pin_base: first pin number
133 * @nr_pins: number of pins in this bank
134 * @name: name of the bank
135 * @bank_num: number of the bank, to account for holes
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200136 * @iomux: array describing the 4 iomux sources of the bank
David Wub6c23272016-02-01 10:58:21 +0800137 * @drv: array describing the 4 drive strength sources of the bank
David Wu3ba67672016-05-11 11:39:28 +0800138 * @pull_type: array describing the 4 pull type sources of the bank
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200139 * @valid: are all necessary informations present
140 * @of_node: dt node of this bank
141 * @drvdata: common pinctrl basedata
142 * @domain: irqdomain of the gpio bank
143 * @gpio_chip: gpiolib chip
144 * @grange: gpio range
145 * @slock: spinlock for the gpio bank
John Keeping88bb9422017-03-23 10:59:31 +0000146 * @irq_lock: bus lock for irq chip
147 * @new_irqs: newly configured irqs which must be muxed as GPIOs in
148 * irq_bus_sync_unlock()
David Wubd35b9b2017-05-26 15:20:20 +0800149 * @route_mask: bits describing the routing pins of per bank
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200150 */
151struct rockchip_pin_bank {
152 void __iomem *reg_base;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200153 struct regmap *regmap_pull;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200154 struct clk *clk;
155 int irq;
Doug Anderson5ae0c7a2015-01-26 08:24:03 -0800156 u32 saved_masks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200157 u32 pin_base;
158 u8 nr_pins;
159 char *name;
160 u8 bank_num;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200161 struct rockchip_iomux iomux[4];
David Wub6c23272016-02-01 10:58:21 +0800162 struct rockchip_drv drv[4];
David Wu3ba67672016-05-11 11:39:28 +0800163 enum rockchip_pin_pull_type pull_type[4];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200164 bool valid;
165 struct device_node *of_node;
166 struct rockchip_pinctrl *drvdata;
167 struct irq_domain *domain;
168 struct gpio_chip gpio_chip;
169 struct pinctrl_gpio_range grange;
John Keeping70b7aa72017-03-23 10:59:29 +0000170 raw_spinlock_t slock;
Heiko Stübner5a927502013-10-16 01:09:08 +0200171 u32 toggle_edge_mode;
John Keeping88bb9422017-03-23 10:59:31 +0000172 struct mutex irq_lock;
173 u32 new_irqs;
David Wubd35b9b2017-05-26 15:20:20 +0800174 u32 route_mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200175};
176
177#define PIN_BANK(id, pins, label) \
178 { \
179 .bank_num = id, \
180 .nr_pins = pins, \
181 .name = label, \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200182 .iomux = { \
183 { .offset = -1 }, \
184 { .offset = -1 }, \
185 { .offset = -1 }, \
186 { .offset = -1 }, \
187 }, \
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200188 }
189
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200190#define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
191 { \
192 .bank_num = id, \
193 .nr_pins = pins, \
194 .name = label, \
195 .iomux = { \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200196 { .type = iom0, .offset = -1 }, \
197 { .type = iom1, .offset = -1 }, \
198 { .type = iom2, .offset = -1 }, \
199 { .type = iom3, .offset = -1 }, \
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200200 }, \
201 }
202
David Wub6c23272016-02-01 10:58:21 +0800203#define PIN_BANK_DRV_FLAGS(id, pins, label, type0, type1, type2, type3) \
204 { \
205 .bank_num = id, \
206 .nr_pins = pins, \
207 .name = label, \
208 .iomux = { \
209 { .offset = -1 }, \
210 { .offset = -1 }, \
211 { .offset = -1 }, \
212 { .offset = -1 }, \
213 }, \
214 .drv = { \
215 { .drv_type = type0, .offset = -1 }, \
216 { .drv_type = type1, .offset = -1 }, \
217 { .drv_type = type2, .offset = -1 }, \
218 { .drv_type = type3, .offset = -1 }, \
219 }, \
220 }
221
David Wu3ba67672016-05-11 11:39:28 +0800222#define PIN_BANK_DRV_FLAGS_PULL_FLAGS(id, pins, label, drv0, drv1, \
223 drv2, drv3, pull0, pull1, \
224 pull2, pull3) \
225 { \
226 .bank_num = id, \
227 .nr_pins = pins, \
228 .name = label, \
229 .iomux = { \
230 { .offset = -1 }, \
231 { .offset = -1 }, \
232 { .offset = -1 }, \
233 { .offset = -1 }, \
234 }, \
235 .drv = { \
236 { .drv_type = drv0, .offset = -1 }, \
237 { .drv_type = drv1, .offset = -1 }, \
238 { .drv_type = drv2, .offset = -1 }, \
239 { .drv_type = drv3, .offset = -1 }, \
240 }, \
241 .pull_type[0] = pull0, \
242 .pull_type[1] = pull1, \
243 .pull_type[2] = pull2, \
244 .pull_type[3] = pull3, \
245 }
246
David Wub6c23272016-02-01 10:58:21 +0800247#define PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(id, pins, label, iom0, iom1, \
248 iom2, iom3, drv0, drv1, drv2, \
249 drv3, offset0, offset1, \
250 offset2, offset3) \
251 { \
252 .bank_num = id, \
253 .nr_pins = pins, \
254 .name = label, \
255 .iomux = { \
256 { .type = iom0, .offset = -1 }, \
257 { .type = iom1, .offset = -1 }, \
258 { .type = iom2, .offset = -1 }, \
259 { .type = iom3, .offset = -1 }, \
260 }, \
261 .drv = { \
262 { .drv_type = drv0, .offset = offset0 }, \
263 { .drv_type = drv1, .offset = offset1 }, \
264 { .drv_type = drv2, .offset = offset2 }, \
265 { .drv_type = drv3, .offset = offset3 }, \
266 }, \
267 }
268
David Wu3ba67672016-05-11 11:39:28 +0800269#define PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(id, pins, \
270 label, iom0, iom1, iom2, \
271 iom3, drv0, drv1, drv2, \
272 drv3, offset0, offset1, \
273 offset2, offset3, pull0, \
274 pull1, pull2, pull3) \
275 { \
276 .bank_num = id, \
277 .nr_pins = pins, \
278 .name = label, \
279 .iomux = { \
280 { .type = iom0, .offset = -1 }, \
281 { .type = iom1, .offset = -1 }, \
282 { .type = iom2, .offset = -1 }, \
283 { .type = iom3, .offset = -1 }, \
284 }, \
285 .drv = { \
286 { .drv_type = drv0, .offset = offset0 }, \
287 { .drv_type = drv1, .offset = offset1 }, \
288 { .drv_type = drv2, .offset = offset2 }, \
289 { .drv_type = drv3, .offset = offset3 }, \
290 }, \
291 .pull_type[0] = pull0, \
292 .pull_type[1] = pull1, \
293 .pull_type[2] = pull2, \
294 .pull_type[3] = pull3, \
295 }
296
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200297/**
David Wubd35b9b2017-05-26 15:20:20 +0800298 * struct rockchip_mux_recalced_data: represent a pin iomux data.
299 * @bank_num: bank number.
300 * @pin: index at register or used to calc index.
301 * @func: the min pin.
302 * @route_offset: the max pin.
303 * @route_val: the register offset.
304 */
305struct rockchip_mux_route_data {
306 u8 bank_num;
307 u8 pin;
308 u8 func;
309 u32 route_offset;
310 u32 route_val;
311};
312
313/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200314 */
315struct rockchip_pin_ctrl {
316 struct rockchip_pin_bank *pin_banks;
317 u32 nr_banks;
318 u32 nr_pins;
319 char *label;
Heiko Stübnera2829262013-10-16 01:07:20 +0200320 enum rockchip_pinctrl_type type;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200321 int grf_mux_offset;
322 int pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +0800323 int grf_drv_offset;
324 int pmu_drv_offset;
David Wubd35b9b2017-05-26 15:20:20 +0800325 struct rockchip_mux_route_data *iomux_routes;
326 u32 niomux_routes;
David Wub6c23272016-02-01 10:58:21 +0800327
Heiko Stübner751a99a2014-05-05 13:58:20 +0200328 void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
329 int pin_num, struct regmap **regmap,
330 int *reg, u8 *bit);
Heiko Stübneref17f692015-06-12 23:50:11 +0200331 void (*drv_calc_reg)(struct rockchip_pin_bank *bank,
332 int pin_num, struct regmap **regmap,
333 int *reg, u8 *bit);
david.wuea262ad2017-02-10 18:23:48 +0800334 void (*iomux_recalc)(u8 bank_num, int pin, int *reg,
335 u8 *bit, int *mask);
david.wue3b357d2017-03-02 15:11:23 +0800336 int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
337 int pin_num, struct regmap **regmap,
338 int *reg, u8 *bit);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200339};
340
341struct rockchip_pin_config {
342 unsigned int func;
343 unsigned long *configs;
344 unsigned int nconfigs;
345};
346
347/**
348 * struct rockchip_pin_group: represent group of pins of a pinmux function.
349 * @name: name of the pin group, used to lookup the group.
350 * @pins: the pins included in this group.
351 * @npins: number of pins included in this group.
352 * @func: the mux function number to be programmed when selected.
353 * @configs: the config values to be set for each pin
354 * @nconfigs: number of configs for each pin
355 */
356struct rockchip_pin_group {
357 const char *name;
358 unsigned int npins;
359 unsigned int *pins;
360 struct rockchip_pin_config *data;
361};
362
363/**
364 * struct rockchip_pmx_func: represent a pin function.
365 * @name: name of the pin function, used to lookup the function.
366 * @groups: one or more names of pin groups that provide this function.
367 * @num_groups: number of groups included in @groups.
368 */
369struct rockchip_pmx_func {
370 const char *name;
371 const char **groups;
372 u8 ngroups;
373};
374
375struct rockchip_pinctrl {
Heiko Stübner751a99a2014-05-05 13:58:20 +0200376 struct regmap *regmap_base;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200377 int reg_size;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200378 struct regmap *regmap_pull;
Heiko Stübner14dee862014-05-05 13:59:09 +0200379 struct regmap *regmap_pmu;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200380 struct device *dev;
381 struct rockchip_pin_ctrl *ctrl;
382 struct pinctrl_desc pctl;
383 struct pinctrl_dev *pctl_dev;
384 struct rockchip_pin_group *groups;
385 unsigned int ngroups;
386 struct rockchip_pmx_func *functions;
387 unsigned int nfunctions;
388};
389
david.wuea262ad2017-02-10 18:23:48 +0800390/**
391 * struct rockchip_mux_recalced_data: represent a pin iomux data.
392 * @num: bank number.
393 * @pin: pin number.
394 * @bit: index at register.
395 * @reg: register offset.
396 * @mask: mask bit
397 */
398struct rockchip_mux_recalced_data {
399 u8 num;
400 u8 pin;
401 u8 reg;
402 u8 bit;
403 u8 mask;
404};
405
Heiko Stübner751a99a2014-05-05 13:58:20 +0200406static struct regmap_config rockchip_regmap_config = {
407 .reg_bits = 32,
408 .val_bits = 32,
409 .reg_stride = 4,
410};
411
Arnd Bergmann56411f32016-06-13 17:18:34 +0200412static inline const struct rockchip_pin_group *pinctrl_name_to_group(
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200413 const struct rockchip_pinctrl *info,
414 const char *name)
415{
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200416 int i;
417
418 for (i = 0; i < info->ngroups; i++) {
Axel Lin1cb95392013-08-21 10:28:50 +0800419 if (!strcmp(info->groups[i].name, name))
420 return &info->groups[i];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200421 }
422
Axel Lin1cb95392013-08-21 10:28:50 +0800423 return NULL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200424}
425
426/*
427 * given a pin number that is local to a pin controller, find out the pin bank
428 * and the register base of the pin bank.
429 */
430static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
431 unsigned pin)
432{
433 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
434
Axel Lin51578b92013-08-23 15:49:00 +0800435 while (pin >= (b->pin_base + b->nr_pins))
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200436 b++;
437
438 return b;
439}
440
441static struct rockchip_pin_bank *bank_num_to_bank(
442 struct rockchip_pinctrl *info,
443 unsigned num)
444{
445 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
446 int i;
447
Axel Lin1cb95392013-08-21 10:28:50 +0800448 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200449 if (b->bank_num == num)
Axel Lin1cb95392013-08-21 10:28:50 +0800450 return b;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200451 }
452
Axel Lin1cb95392013-08-21 10:28:50 +0800453 return ERR_PTR(-EINVAL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200454}
455
456/*
457 * Pinctrl_ops handling
458 */
459
460static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
461{
462 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
463
464 return info->ngroups;
465}
466
467static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
468 unsigned selector)
469{
470 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
471
472 return info->groups[selector].name;
473}
474
475static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
476 unsigned selector, const unsigned **pins,
477 unsigned *npins)
478{
479 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
480
481 if (selector >= info->ngroups)
482 return -EINVAL;
483
484 *pins = info->groups[selector].pins;
485 *npins = info->groups[selector].npins;
486
487 return 0;
488}
489
490static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
491 struct device_node *np,
492 struct pinctrl_map **map, unsigned *num_maps)
493{
494 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
495 const struct rockchip_pin_group *grp;
496 struct pinctrl_map *new_map;
497 struct device_node *parent;
498 int map_num = 1;
499 int i;
500
501 /*
502 * first find the group of this node and check if we need to create
503 * config maps for pins
504 */
505 grp = pinctrl_name_to_group(info, np->name);
506 if (!grp) {
507 dev_err(info->dev, "unable to find group for node %s\n",
508 np->name);
509 return -EINVAL;
510 }
511
512 map_num += grp->npins;
513 new_map = devm_kzalloc(pctldev->dev, sizeof(*new_map) * map_num,
514 GFP_KERNEL);
515 if (!new_map)
516 return -ENOMEM;
517
518 *map = new_map;
519 *num_maps = map_num;
520
521 /* create mux map */
522 parent = of_get_parent(np);
523 if (!parent) {
524 devm_kfree(pctldev->dev, new_map);
525 return -EINVAL;
526 }
527 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
528 new_map[0].data.mux.function = parent->name;
529 new_map[0].data.mux.group = np->name;
530 of_node_put(parent);
531
532 /* create config map */
533 new_map++;
534 for (i = 0; i < grp->npins; i++) {
535 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
536 new_map[i].data.configs.group_or_pin =
537 pin_get_name(pctldev, grp->pins[i]);
538 new_map[i].data.configs.configs = grp->data[i].configs;
539 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
540 }
541
542 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
543 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
544
545 return 0;
546}
547
548static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
549 struct pinctrl_map *map, unsigned num_maps)
550{
551}
552
553static const struct pinctrl_ops rockchip_pctrl_ops = {
554 .get_groups_count = rockchip_get_groups_count,
555 .get_group_name = rockchip_get_group_name,
556 .get_group_pins = rockchip_get_group_pins,
557 .dt_node_to_map = rockchip_dt_node_to_map,
558 .dt_free_map = rockchip_dt_free_map,
559};
560
561/*
562 * Hardware access
563 */
564
david.wu3818e4a2017-02-10 18:23:49 +0800565static const struct rockchip_mux_recalced_data rk3328_mux_recalced_data[] = {
566 {
567 .num = 2,
568 .pin = 12,
569 .reg = 0x24,
570 .bit = 8,
571 .mask = 0x3
572 }, {
573 .num = 2,
574 .pin = 15,
575 .reg = 0x28,
576 .bit = 0,
577 .mask = 0x7
578 }, {
579 .num = 2,
580 .pin = 23,
581 .reg = 0x30,
582 .bit = 14,
583 .mask = 0x3
584 },
585};
586
587static void rk3328_recalc_mux(u8 bank_num, int pin, int *reg,
588 u8 *bit, int *mask)
589{
590 const struct rockchip_mux_recalced_data *data = NULL;
591 int i;
592
593 for (i = 0; i < ARRAY_SIZE(rk3328_mux_recalced_data); i++)
594 if (rk3328_mux_recalced_data[i].num == bank_num &&
595 rk3328_mux_recalced_data[i].pin == pin) {
596 data = &rk3328_mux_recalced_data[i];
597 break;
598 }
599
600 if (!data)
601 return;
602
603 *reg = data->reg;
604 *mask = data->mask;
605 *bit = data->bit;
606}
607
David Wud4970ee2017-05-26 15:20:21 +0800608static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
609 {
610 /* pwm0-0 */
611 .bank_num = 0,
612 .pin = 26,
613 .func = 1,
614 .route_offset = 0x50,
615 .route_val = BIT(16),
616 }, {
617 /* pwm0-1 */
618 .bank_num = 3,
619 .pin = 21,
620 .func = 1,
621 .route_offset = 0x50,
622 .route_val = BIT(16) | BIT(0),
623 }, {
624 /* pwm1-0 */
625 .bank_num = 0,
626 .pin = 27,
627 .func = 1,
628 .route_offset = 0x50,
629 .route_val = BIT(16 + 1),
630 }, {
631 /* pwm1-1 */
632 .bank_num = 0,
633 .pin = 30,
634 .func = 2,
635 .route_offset = 0x50,
636 .route_val = BIT(16 + 1) | BIT(1),
637 }, {
638 /* pwm2-0 */
639 .bank_num = 0,
640 .pin = 28,
641 .func = 1,
642 .route_offset = 0x50,
643 .route_val = BIT(16 + 2),
644 }, {
645 /* pwm2-1 */
646 .bank_num = 1,
647 .pin = 12,
648 .func = 2,
649 .route_offset = 0x50,
650 .route_val = BIT(16 + 2) | BIT(2),
651 }, {
652 /* pwm3-0 */
653 .bank_num = 3,
654 .pin = 26,
655 .func = 1,
656 .route_offset = 0x50,
657 .route_val = BIT(16 + 3),
658 }, {
659 /* pwm3-1 */
660 .bank_num = 1,
661 .pin = 11,
662 .func = 2,
663 .route_offset = 0x50,
664 .route_val = BIT(16 + 3) | BIT(3),
665 }, {
666 /* sdio-0_d0 */
667 .bank_num = 1,
668 .pin = 1,
669 .func = 1,
670 .route_offset = 0x50,
671 .route_val = BIT(16 + 4),
672 }, {
673 /* sdio-1_d0 */
674 .bank_num = 3,
675 .pin = 2,
676 .func = 1,
677 .route_offset = 0x50,
678 .route_val = BIT(16 + 4) | BIT(4),
679 }, {
680 /* spi-0_rx */
681 .bank_num = 0,
682 .pin = 13,
683 .func = 2,
684 .route_offset = 0x50,
685 .route_val = BIT(16 + 5),
686 }, {
687 /* spi-1_rx */
688 .bank_num = 2,
689 .pin = 0,
690 .func = 2,
691 .route_offset = 0x50,
692 .route_val = BIT(16 + 5) | BIT(5),
693 }, {
694 /* emmc-0_cmd */
695 .bank_num = 1,
696 .pin = 22,
697 .func = 2,
698 .route_offset = 0x50,
699 .route_val = BIT(16 + 7),
700 }, {
701 /* emmc-1_cmd */
702 .bank_num = 2,
703 .pin = 4,
704 .func = 2,
705 .route_offset = 0x50,
706 .route_val = BIT(16 + 7) | BIT(7),
707 }, {
708 /* uart2-0_rx */
709 .bank_num = 1,
710 .pin = 19,
711 .func = 2,
712 .route_offset = 0x50,
713 .route_val = BIT(16 + 8),
714 }, {
715 /* uart2-1_rx */
716 .bank_num = 1,
717 .pin = 10,
718 .func = 2,
719 .route_offset = 0x50,
720 .route_val = BIT(16 + 8) | BIT(8),
721 }, {
722 /* uart1-0_rx */
723 .bank_num = 1,
724 .pin = 10,
725 .func = 1,
726 .route_offset = 0x50,
727 .route_val = BIT(16 + 11),
728 }, {
729 /* uart1-1_rx */
730 .bank_num = 3,
731 .pin = 13,
732 .func = 1,
733 .route_offset = 0x50,
734 .route_val = BIT(16 + 11) | BIT(11),
735 },
736};
737
David Wucedc9642017-05-26 15:20:22 +0800738static struct rockchip_mux_route_data rk3328_mux_route_data[] = {
739 {
740 /* uart2dbg_rxm0 */
741 .bank_num = 1,
742 .pin = 1,
743 .func = 2,
744 .route_offset = 0x50,
745 .route_val = BIT(16) | BIT(16 + 1),
746 }, {
747 /* uart2dbg_rxm1 */
748 .bank_num = 2,
749 .pin = 1,
750 .func = 1,
751 .route_offset = 0x50,
752 .route_val = BIT(16) | BIT(16 + 1) | BIT(0),
753 }, {
754 /* gmac-m1-optimized_rxd0 */
755 .bank_num = 1,
756 .pin = 11,
757 .func = 2,
758 .route_offset = 0x50,
759 .route_val = BIT(16 + 2) | BIT(16 + 10) | BIT(2) | BIT(10),
760 }, {
761 /* pdm_sdi0m0 */
762 .bank_num = 2,
763 .pin = 19,
764 .func = 2,
765 .route_offset = 0x50,
766 .route_val = BIT(16 + 3),
767 }, {
768 /* pdm_sdi0m1 */
769 .bank_num = 1,
770 .pin = 23,
771 .func = 3,
772 .route_offset = 0x50,
773 .route_val = BIT(16 + 3) | BIT(3),
774 }, {
775 /* spi_rxdm2 */
776 .bank_num = 3,
777 .pin = 2,
778 .func = 4,
779 .route_offset = 0x50,
780 .route_val = BIT(16 + 4) | BIT(16 + 5) | BIT(5),
781 }, {
782 /* i2s2_sdim0 */
783 .bank_num = 1,
784 .pin = 24,
785 .func = 1,
786 .route_offset = 0x50,
787 .route_val = BIT(16 + 6),
788 }, {
789 /* i2s2_sdim1 */
790 .bank_num = 3,
791 .pin = 2,
792 .func = 6,
793 .route_offset = 0x50,
794 .route_val = BIT(16 + 6) | BIT(6),
795 }, {
796 /* card_iom1 */
797 .bank_num = 2,
798 .pin = 22,
799 .func = 3,
800 .route_offset = 0x50,
801 .route_val = BIT(16 + 7) | BIT(7),
802 }, {
803 /* tsp_d5m1 */
804 .bank_num = 2,
805 .pin = 16,
806 .func = 3,
807 .route_offset = 0x50,
808 .route_val = BIT(16 + 8) | BIT(8),
809 }, {
810 /* cif_data5m1 */
811 .bank_num = 2,
812 .pin = 16,
813 .func = 4,
814 .route_offset = 0x50,
815 .route_val = BIT(16 + 9) | BIT(9),
816 },
817};
818
David Wuaccc1ce2017-05-26 15:20:23 +0800819static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
820 {
821 /* uart2dbga_rx */
822 .bank_num = 4,
823 .pin = 8,
824 .func = 2,
825 .route_offset = 0xe21c,
826 .route_val = BIT(16 + 10) | BIT(16 + 11),
827 }, {
828 /* uart2dbgb_rx */
829 .bank_num = 4,
830 .pin = 16,
831 .func = 2,
832 .route_offset = 0xe21c,
833 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(10),
834 }, {
835 /* uart2dbgc_rx */
836 .bank_num = 4,
837 .pin = 19,
838 .func = 1,
839 .route_offset = 0xe21c,
840 .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(11),
841 }, {
842 /* pcie_clkreqn */
843 .bank_num = 2,
844 .pin = 26,
845 .func = 2,
846 .route_offset = 0xe21c,
847 .route_val = BIT(16 + 14),
848 }, {
849 /* pcie_clkreqnb */
850 .bank_num = 4,
851 .pin = 24,
852 .func = 1,
853 .route_offset = 0xe21c,
854 .route_val = BIT(16 + 14) | BIT(14),
855 },
856};
857
David Wubd35b9b2017-05-26 15:20:20 +0800858static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
859 int mux, u32 *reg, u32 *value)
860{
861 struct rockchip_pinctrl *info = bank->drvdata;
862 struct rockchip_pin_ctrl *ctrl = info->ctrl;
863 struct rockchip_mux_route_data *data;
864 int i;
865
866 for (i = 0; i < ctrl->niomux_routes; i++) {
867 data = &ctrl->iomux_routes[i];
868 if ((data->bank_num == bank->bank_num) &&
869 (data->pin == pin) && (data->func == mux))
870 break;
871 }
872
873 if (i >= ctrl->niomux_routes)
874 return false;
875
876 *reg = data->route_offset;
877 *value = data->route_val;
878
879 return true;
880}
881
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200882static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
883{
884 struct rockchip_pinctrl *info = bank->drvdata;
david.wuea262ad2017-02-10 18:23:48 +0800885 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200886 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200887 struct regmap *regmap;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200888 unsigned int val;
david.wuea262ad2017-02-10 18:23:48 +0800889 int reg, ret, mask, mux_type;
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200890 u8 bit;
891
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200892 if (iomux_num > 3)
893 return -EINVAL;
894
Heiko Stübner62f49222014-06-16 01:37:49 +0200895 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
896 dev_err(info->dev, "pin %d is unrouted\n", pin);
897 return -EINVAL;
898 }
899
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200900 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200901 return RK_FUNC_GPIO;
902
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200903 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
904 ? info->regmap_pmu : info->regmap_base;
905
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200906 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +0800907 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200908 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +0800909 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +0200910 if ((pin % 8) >= 4)
911 reg += 0x4;
912 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +0800913 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +0800914 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +0800915 if ((pin % 8) >= 5)
916 reg += 0x4;
917 bit = (pin % 8 % 5) * 3;
918 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +0200919 } else {
920 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +0800921 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +0200922 }
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200923
david.wuea262ad2017-02-10 18:23:48 +0800924 if (ctrl->iomux_recalc && (mux_type & IOMUX_RECALCED))
925 ctrl->iomux_recalc(bank->bank_num, pin, &reg, &bit, &mask);
926
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200927 ret = regmap_read(regmap, reg, &val);
Heiko Stübner751a99a2014-05-05 13:58:20 +0200928 if (ret)
929 return ret;
930
Heiko Stübner03716e12014-06-16 01:36:57 +0200931 return ((val >> bit) & mask);
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200932}
933
John Keeping05709c32017-03-23 10:59:30 +0000934static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
935 int pin, int mux)
936{
937 struct rockchip_pinctrl *info = bank->drvdata;
938 int iomux_num = (pin / 8);
939
940 if (iomux_num > 3)
941 return -EINVAL;
942
943 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
944 dev_err(info->dev, "pin %d is unrouted\n", pin);
945 return -EINVAL;
946 }
947
948 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
949 if (mux != RK_FUNC_GPIO) {
950 dev_err(info->dev,
951 "pin %d only supports a gpio mux\n", pin);
952 return -ENOTSUPP;
953 }
954 }
955
956 return 0;
957}
958
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200959/*
960 * Set a new mux function for a pin.
961 *
962 * The register is divided into the upper and lower 16 bit. When changing
963 * a value, the previous register value is not read and changed. Instead
964 * it seems the changed bits are marked in the upper 16 bit, while the
965 * changed value gets set in the same offset in the lower 16 bit.
966 * All pin settings seem to be 2 bit wide in both the upper and lower
967 * parts.
968 * @bank: pin bank to change
969 * @pin: pin to change
970 * @mux: new mux function to set
971 */
Heiko Stübner14797182014-03-26 00:57:00 +0100972static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200973{
974 struct rockchip_pinctrl *info = bank->drvdata;
david.wuea262ad2017-02-10 18:23:48 +0800975 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200976 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200977 struct regmap *regmap;
david.wuea262ad2017-02-10 18:23:48 +0800978 int reg, ret, mask, mux_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200979 u8 bit;
David Wubd35b9b2017-05-26 15:20:20 +0800980 u32 data, rmask, route_reg, route_val;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200981
John Keeping05709c32017-03-23 10:59:30 +0000982 ret = rockchip_verify_mux(bank, pin, mux);
983 if (ret < 0)
984 return ret;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200985
John Keeping05709c32017-03-23 10:59:30 +0000986 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
987 return 0;
Heiko Stübnerc4a532de2014-03-26 00:57:52 +0100988
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200989 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
990 bank->bank_num, pin, mux);
991
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200992 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
993 ? info->regmap_pmu : info->regmap_base;
994
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200995 /* get basic quadrupel of mux registers and the correct reg inside */
david.wuea262ad2017-02-10 18:23:48 +0800996 mux_type = bank->iomux[iomux_num].type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200997 reg = bank->iomux[iomux_num].offset;
david.wuea262ad2017-02-10 18:23:48 +0800998 if (mux_type & IOMUX_WIDTH_4BIT) {
Heiko Stübner03716e12014-06-16 01:36:57 +0200999 if ((pin % 8) >= 4)
1000 reg += 0x4;
1001 bit = (pin % 4) * 4;
david.wu8b6c6f92017-02-10 18:23:47 +08001002 mask = 0xf;
david.wuea262ad2017-02-10 18:23:48 +08001003 } else if (mux_type & IOMUX_WIDTH_3BIT) {
david.wu8b6c6f92017-02-10 18:23:47 +08001004 if ((pin % 8) >= 5)
1005 reg += 0x4;
1006 bit = (pin % 8 % 5) * 3;
1007 mask = 0x7;
Heiko Stübner03716e12014-06-16 01:36:57 +02001008 } else {
1009 bit = (pin % 8) * 2;
david.wu8b6c6f92017-02-10 18:23:47 +08001010 mask = 0x3;
Heiko Stübner03716e12014-06-16 01:36:57 +02001011 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001012
david.wuea262ad2017-02-10 18:23:48 +08001013 if (ctrl->iomux_recalc && (mux_type & IOMUX_RECALCED))
1014 ctrl->iomux_recalc(bank->bank_num, pin, &reg, &bit, &mask);
1015
David Wubd35b9b2017-05-26 15:20:20 +08001016 if (bank->route_mask & BIT(pin)) {
1017 if (rockchip_get_mux_route(bank, pin, mux, &route_reg,
1018 &route_val)) {
1019 ret = regmap_write(regmap, route_reg, route_val);
1020 if (ret)
1021 return ret;
1022 }
1023 }
1024
Heiko Stübner03716e12014-06-16 01:36:57 +02001025 data = (mask << (bit + 16));
Sonny Rao99e872d2014-07-31 22:58:00 -07001026 rmask = data | (data >> 16);
Heiko Stübner03716e12014-06-16 01:36:57 +02001027 data |= (mux & mask) << bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001028 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001029
Heiko Stübner751a99a2014-05-05 13:58:20 +02001030 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001031}
1032
Andy Yanb9c6dca2017-03-17 18:18:36 +01001033#define RV1108_PULL_PMU_OFFSET 0x10
1034#define RV1108_PULL_OFFSET 0x110
1035#define RV1108_PULL_PINS_PER_REG 8
1036#define RV1108_PULL_BITS_PER_PIN 2
1037#define RV1108_PULL_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001038
Andy Yanb9c6dca2017-03-17 18:18:36 +01001039static void rv1108_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001040 int pin_num, struct regmap **regmap,
1041 int *reg, u8 *bit)
1042{
1043 struct rockchip_pinctrl *info = bank->drvdata;
1044
1045 /* The first 24 pins of the first bank are located in PMU */
1046 if (bank->bank_num == 0) {
1047 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001048 *reg = RV1108_PULL_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001049 } else {
Andy Yanb9c6dca2017-03-17 18:18:36 +01001050 *reg = RV1108_PULL_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001051 *regmap = info->regmap_base;
1052 /* correct the offset, as we're starting with the 2nd bank */
1053 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001054 *reg += bank->bank_num * RV1108_PULL_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001055 }
1056
Andy Yanb9c6dca2017-03-17 18:18:36 +01001057 *reg += ((pin_num / RV1108_PULL_PINS_PER_REG) * 4);
1058 *bit = (pin_num % RV1108_PULL_PINS_PER_REG);
1059 *bit *= RV1108_PULL_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001060}
1061
Andy Yanb9c6dca2017-03-17 18:18:36 +01001062#define RV1108_DRV_PMU_OFFSET 0x20
1063#define RV1108_DRV_GRF_OFFSET 0x210
1064#define RV1108_DRV_BITS_PER_PIN 2
1065#define RV1108_DRV_PINS_PER_REG 8
1066#define RV1108_DRV_BANK_STRIDE 16
Andy Yan688daf22016-11-15 18:02:43 +08001067
Andy Yanb9c6dca2017-03-17 18:18:36 +01001068static void rv1108_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
Andy Yan688daf22016-11-15 18:02:43 +08001069 int pin_num, struct regmap **regmap,
1070 int *reg, u8 *bit)
1071{
1072 struct rockchip_pinctrl *info = bank->drvdata;
1073
1074 /* The first 24 pins of the first bank are located in PMU */
1075 if (bank->bank_num == 0) {
1076 *regmap = info->regmap_pmu;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001077 *reg = RV1108_DRV_PMU_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001078 } else {
1079 *regmap = info->regmap_base;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001080 *reg = RV1108_DRV_GRF_OFFSET;
Andy Yan688daf22016-11-15 18:02:43 +08001081
1082 /* correct the offset, as we're starting with the 2nd bank */
1083 *reg -= 0x10;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001084 *reg += bank->bank_num * RV1108_DRV_BANK_STRIDE;
Andy Yan688daf22016-11-15 18:02:43 +08001085 }
1086
Andy Yanb9c6dca2017-03-17 18:18:36 +01001087 *reg += ((pin_num / RV1108_DRV_PINS_PER_REG) * 4);
1088 *bit = pin_num % RV1108_DRV_PINS_PER_REG;
1089 *bit *= RV1108_DRV_BITS_PER_PIN;
Andy Yan688daf22016-11-15 18:02:43 +08001090}
1091
Heiko Stübnera2829262013-10-16 01:07:20 +02001092#define RK2928_PULL_OFFSET 0x118
1093#define RK2928_PULL_PINS_PER_REG 16
1094#define RK2928_PULL_BANK_STRIDE 8
1095
1096static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001097 int pin_num, struct regmap **regmap,
1098 int *reg, u8 *bit)
Heiko Stübnera2829262013-10-16 01:07:20 +02001099{
1100 struct rockchip_pinctrl *info = bank->drvdata;
1101
Heiko Stübner751a99a2014-05-05 13:58:20 +02001102 *regmap = info->regmap_base;
1103 *reg = RK2928_PULL_OFFSET;
Heiko Stübnera2829262013-10-16 01:07:20 +02001104 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
1105 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
1106
1107 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
1108};
1109
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001110#define RK3188_PULL_OFFSET 0x164
Heiko Stübner6ca52742013-10-16 01:08:42 +02001111#define RK3188_PULL_BITS_PER_PIN 2
1112#define RK3188_PULL_PINS_PER_REG 8
1113#define RK3188_PULL_BANK_STRIDE 16
Heiko Stübner14dee862014-05-05 13:59:09 +02001114#define RK3188_PULL_PMU_OFFSET 0x64
Heiko Stübner6ca52742013-10-16 01:08:42 +02001115
1116static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +02001117 int pin_num, struct regmap **regmap,
1118 int *reg, u8 *bit)
Heiko Stübner6ca52742013-10-16 01:08:42 +02001119{
1120 struct rockchip_pinctrl *info = bank->drvdata;
1121
1122 /* The first 12 pins of the first bank are located elsewhere */
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001123 if (bank->bank_num == 0 && pin_num < 12) {
Heiko Stübner14dee862014-05-05 13:59:09 +02001124 *regmap = info->regmap_pmu ? info->regmap_pmu
1125 : bank->regmap_pull;
1126 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001127 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001128 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1129 *bit *= RK3188_PULL_BITS_PER_PIN;
1130 } else {
Heiko Stübner751a99a2014-05-05 13:58:20 +02001131 *regmap = info->regmap_pull ? info->regmap_pull
1132 : info->regmap_base;
1133 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
1134
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001135 /* correct the offset, as it is the 2nd pull register */
1136 *reg -= 4;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001137 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1138 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1139
1140 /*
1141 * The bits in these registers have an inverse ordering
1142 * with the lowest pin being in bits 15:14 and the highest
1143 * pin in bits 1:0
1144 */
1145 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
1146 *bit *= RK3188_PULL_BITS_PER_PIN;
1147 }
1148}
1149
Heiko Stübner304f0772014-06-16 01:38:14 +02001150#define RK3288_PULL_OFFSET 0x140
1151static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1152 int pin_num, struct regmap **regmap,
1153 int *reg, u8 *bit)
1154{
1155 struct rockchip_pinctrl *info = bank->drvdata;
1156
1157 /* The first 24 pins of the first bank are located in PMU */
1158 if (bank->bank_num == 0) {
1159 *regmap = info->regmap_pmu;
1160 *reg = RK3188_PULL_PMU_OFFSET;
1161
1162 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1163 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1164 *bit *= RK3188_PULL_BITS_PER_PIN;
1165 } else {
1166 *regmap = info->regmap_base;
1167 *reg = RK3288_PULL_OFFSET;
1168
1169 /* correct the offset, as we're starting with the 2nd bank */
1170 *reg -= 0x10;
1171 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1172 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1173
1174 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1175 *bit *= RK3188_PULL_BITS_PER_PIN;
1176 }
1177}
1178
Heiko Stübnerb547c802014-07-20 01:50:11 +02001179#define RK3288_DRV_PMU_OFFSET 0x70
1180#define RK3288_DRV_GRF_OFFSET 0x1c0
1181#define RK3288_DRV_BITS_PER_PIN 2
1182#define RK3288_DRV_PINS_PER_REG 8
1183#define RK3288_DRV_BANK_STRIDE 16
Heiko Stübnerb547c802014-07-20 01:50:11 +02001184
1185static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1186 int pin_num, struct regmap **regmap,
1187 int *reg, u8 *bit)
1188{
1189 struct rockchip_pinctrl *info = bank->drvdata;
1190
1191 /* The first 24 pins of the first bank are located in PMU */
1192 if (bank->bank_num == 0) {
1193 *regmap = info->regmap_pmu;
1194 *reg = RK3288_DRV_PMU_OFFSET;
1195
1196 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1197 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1198 *bit *= RK3288_DRV_BITS_PER_PIN;
1199 } else {
1200 *regmap = info->regmap_base;
1201 *reg = RK3288_DRV_GRF_OFFSET;
1202
1203 /* correct the offset, as we're starting with the 2nd bank */
1204 *reg -= 0x10;
1205 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1206 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1207
1208 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1209 *bit *= RK3288_DRV_BITS_PER_PIN;
1210 }
1211}
1212
Jeffy Chenfea0fe62015-12-09 17:04:06 +08001213#define RK3228_PULL_OFFSET 0x100
1214
1215static void rk3228_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1216 int pin_num, struct regmap **regmap,
1217 int *reg, u8 *bit)
1218{
1219 struct rockchip_pinctrl *info = bank->drvdata;
1220
1221 *regmap = info->regmap_base;
1222 *reg = RK3228_PULL_OFFSET;
1223 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1224 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1225
1226 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1227 *bit *= RK3188_PULL_BITS_PER_PIN;
1228}
1229
1230#define RK3228_DRV_GRF_OFFSET 0x200
1231
1232static void rk3228_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1233 int pin_num, struct regmap **regmap,
1234 int *reg, u8 *bit)
1235{
1236 struct rockchip_pinctrl *info = bank->drvdata;
1237
1238 *regmap = info->regmap_base;
1239 *reg = RK3228_DRV_GRF_OFFSET;
1240 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1241 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1242
1243 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1244 *bit *= RK3288_DRV_BITS_PER_PIN;
1245}
1246
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001247#define RK3368_PULL_GRF_OFFSET 0x100
1248#define RK3368_PULL_PMU_OFFSET 0x10
1249
1250static void rk3368_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1251 int pin_num, struct regmap **regmap,
1252 int *reg, u8 *bit)
1253{
1254 struct rockchip_pinctrl *info = bank->drvdata;
1255
1256 /* The first 32 pins of the first bank are located in PMU */
1257 if (bank->bank_num == 0) {
1258 *regmap = info->regmap_pmu;
1259 *reg = RK3368_PULL_PMU_OFFSET;
1260
1261 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1262 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1263 *bit *= RK3188_PULL_BITS_PER_PIN;
1264 } else {
1265 *regmap = info->regmap_base;
1266 *reg = RK3368_PULL_GRF_OFFSET;
1267
1268 /* correct the offset, as we're starting with the 2nd bank */
1269 *reg -= 0x10;
1270 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1271 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1272
1273 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1274 *bit *= RK3188_PULL_BITS_PER_PIN;
1275 }
1276}
1277
1278#define RK3368_DRV_PMU_OFFSET 0x20
1279#define RK3368_DRV_GRF_OFFSET 0x200
1280
1281static void rk3368_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1282 int pin_num, struct regmap **regmap,
1283 int *reg, u8 *bit)
1284{
1285 struct rockchip_pinctrl *info = bank->drvdata;
1286
1287 /* The first 32 pins of the first bank are located in PMU */
1288 if (bank->bank_num == 0) {
1289 *regmap = info->regmap_pmu;
1290 *reg = RK3368_DRV_PMU_OFFSET;
1291
1292 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1293 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
1294 *bit *= RK3288_DRV_BITS_PER_PIN;
1295 } else {
1296 *regmap = info->regmap_base;
1297 *reg = RK3368_DRV_GRF_OFFSET;
1298
1299 /* correct the offset, as we're starting with the 2nd bank */
1300 *reg -= 0x10;
1301 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
1302 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
1303
1304 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
1305 *bit *= RK3288_DRV_BITS_PER_PIN;
1306 }
1307}
1308
David Wub6c23272016-02-01 10:58:21 +08001309#define RK3399_PULL_GRF_OFFSET 0xe040
1310#define RK3399_PULL_PMU_OFFSET 0x40
1311#define RK3399_DRV_3BITS_PER_PIN 3
1312
1313static void rk3399_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
1314 int pin_num, struct regmap **regmap,
1315 int *reg, u8 *bit)
1316{
1317 struct rockchip_pinctrl *info = bank->drvdata;
1318
1319 /* The bank0:16 and bank1:32 pins are located in PMU */
1320 if ((bank->bank_num == 0) || (bank->bank_num == 1)) {
1321 *regmap = info->regmap_pmu;
1322 *reg = RK3399_PULL_PMU_OFFSET;
1323
1324 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1325
1326 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1327 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
1328 *bit *= RK3188_PULL_BITS_PER_PIN;
1329 } else {
1330 *regmap = info->regmap_base;
1331 *reg = RK3399_PULL_GRF_OFFSET;
1332
1333 /* correct the offset, as we're starting with the 3rd bank */
1334 *reg -= 0x20;
1335 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
1336 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
1337
1338 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
1339 *bit *= RK3188_PULL_BITS_PER_PIN;
1340 }
1341}
1342
1343static void rk3399_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
1344 int pin_num, struct regmap **regmap,
1345 int *reg, u8 *bit)
1346{
1347 struct rockchip_pinctrl *info = bank->drvdata;
1348 int drv_num = (pin_num / 8);
1349
1350 /* The bank0:16 and bank1:32 pins are located in PMU */
1351 if ((bank->bank_num == 0) || (bank->bank_num == 1))
1352 *regmap = info->regmap_pmu;
1353 else
1354 *regmap = info->regmap_base;
1355
1356 *reg = bank->drv[drv_num].offset;
1357 if ((bank->drv[drv_num].drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
1358 (bank->drv[drv_num].drv_type == DRV_TYPE_IO_3V3_ONLY))
1359 *bit = (pin_num % 8) * 3;
1360 else
1361 *bit = (pin_num % 8) * 2;
1362}
1363
1364static int rockchip_perpin_drv_list[DRV_TYPE_MAX][8] = {
1365 { 2, 4, 8, 12, -1, -1, -1, -1 },
1366 { 3, 6, 9, 12, -1, -1, -1, -1 },
1367 { 5, 10, 15, 20, -1, -1, -1, -1 },
1368 { 4, 6, 8, 10, 12, 14, 16, 18 },
1369 { 4, 7, 10, 13, 16, 19, 22, 26 }
1370};
Heiko Stübneref17f692015-06-12 23:50:11 +02001371
1372static int rockchip_get_drive_perpin(struct rockchip_pin_bank *bank,
1373 int pin_num)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001374{
Heiko Stübneref17f692015-06-12 23:50:11 +02001375 struct rockchip_pinctrl *info = bank->drvdata;
1376 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001377 struct regmap *regmap;
1378 int reg, ret;
David Wub6c23272016-02-01 10:58:21 +08001379 u32 data, temp, rmask_bits;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001380 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001381 int drv_type = bank->drv[pin_num / 8].drv_type;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001382
Heiko Stübneref17f692015-06-12 23:50:11 +02001383 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001384
David Wub6c23272016-02-01 10:58:21 +08001385 switch (drv_type) {
1386 case DRV_TYPE_IO_1V8_3V0_AUTO:
1387 case DRV_TYPE_IO_3V3_ONLY:
1388 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1389 switch (bit) {
1390 case 0 ... 12:
1391 /* regular case, nothing to do */
1392 break;
1393 case 15:
1394 /*
1395 * drive-strength offset is special, as it is
1396 * spread over 2 registers
1397 */
1398 ret = regmap_read(regmap, reg, &data);
1399 if (ret)
1400 return ret;
1401
1402 ret = regmap_read(regmap, reg + 0x4, &temp);
1403 if (ret)
1404 return ret;
1405
1406 /*
1407 * the bit data[15] contains bit 0 of the value
1408 * while temp[1:0] contains bits 2 and 1
1409 */
1410 data >>= 15;
1411 temp &= 0x3;
1412 temp <<= 1;
1413 data |= temp;
1414
1415 return rockchip_perpin_drv_list[drv_type][data];
1416 case 18 ... 21:
1417 /* setting fully enclosed in the second register */
1418 reg += 4;
1419 bit -= 16;
1420 break;
1421 default:
1422 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1423 bit, drv_type);
1424 return -EINVAL;
1425 }
1426
1427 break;
1428 case DRV_TYPE_IO_DEFAULT:
1429 case DRV_TYPE_IO_1V8_OR_3V0:
1430 case DRV_TYPE_IO_1V8_ONLY:
1431 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1432 break;
1433 default:
1434 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1435 drv_type);
1436 return -EINVAL;
1437 }
1438
Heiko Stübnerb547c802014-07-20 01:50:11 +02001439 ret = regmap_read(regmap, reg, &data);
1440 if (ret)
1441 return ret;
1442
1443 data >>= bit;
David Wub6c23272016-02-01 10:58:21 +08001444 data &= (1 << rmask_bits) - 1;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001445
David Wub6c23272016-02-01 10:58:21 +08001446 return rockchip_perpin_drv_list[drv_type][data];
Heiko Stübnerb547c802014-07-20 01:50:11 +02001447}
1448
Heiko Stübneref17f692015-06-12 23:50:11 +02001449static int rockchip_set_drive_perpin(struct rockchip_pin_bank *bank,
1450 int pin_num, int strength)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001451{
1452 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübneref17f692015-06-12 23:50:11 +02001453 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001454 struct regmap *regmap;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001455 int reg, ret, i;
David Wub6c23272016-02-01 10:58:21 +08001456 u32 data, rmask, rmask_bits, temp;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001457 u8 bit;
David Wub6c23272016-02-01 10:58:21 +08001458 int drv_type = bank->drv[pin_num / 8].drv_type;
1459
1460 dev_dbg(info->dev, "setting drive of GPIO%d-%d to %d\n",
1461 bank->bank_num, pin_num, strength);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001462
Heiko Stübneref17f692015-06-12 23:50:11 +02001463 ctrl->drv_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001464
1465 ret = -EINVAL;
David Wub6c23272016-02-01 10:58:21 +08001466 for (i = 0; i < ARRAY_SIZE(rockchip_perpin_drv_list[drv_type]); i++) {
1467 if (rockchip_perpin_drv_list[drv_type][i] == strength) {
Heiko Stübnerb547c802014-07-20 01:50:11 +02001468 ret = i;
1469 break;
David Wub6c23272016-02-01 10:58:21 +08001470 } else if (rockchip_perpin_drv_list[drv_type][i] < 0) {
1471 ret = rockchip_perpin_drv_list[drv_type][i];
1472 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001473 }
1474 }
1475
1476 if (ret < 0) {
1477 dev_err(info->dev, "unsupported driver strength %d\n",
1478 strength);
1479 return ret;
1480 }
1481
David Wub6c23272016-02-01 10:58:21 +08001482 switch (drv_type) {
1483 case DRV_TYPE_IO_1V8_3V0_AUTO:
1484 case DRV_TYPE_IO_3V3_ONLY:
1485 rmask_bits = RK3399_DRV_3BITS_PER_PIN;
1486 switch (bit) {
1487 case 0 ... 12:
1488 /* regular case, nothing to do */
1489 break;
1490 case 15:
1491 /*
1492 * drive-strength offset is special, as it is spread
1493 * over 2 registers, the bit data[15] contains bit 0
1494 * of the value while temp[1:0] contains bits 2 and 1
1495 */
1496 data = (ret & 0x1) << 15;
1497 temp = (ret >> 0x1) & 0x3;
1498
1499 rmask = BIT(15) | BIT(31);
1500 data |= BIT(31);
1501 ret = regmap_update_bits(regmap, reg, rmask, data);
John Keepingf07bedc2017-03-23 10:59:28 +00001502 if (ret)
David Wub6c23272016-02-01 10:58:21 +08001503 return ret;
David Wub6c23272016-02-01 10:58:21 +08001504
1505 rmask = 0x3 | (0x3 << 16);
1506 temp |= (0x3 << 16);
1507 reg += 0x4;
1508 ret = regmap_update_bits(regmap, reg, rmask, temp);
1509
David Wub6c23272016-02-01 10:58:21 +08001510 return ret;
1511 case 18 ... 21:
1512 /* setting fully enclosed in the second register */
1513 reg += 4;
1514 bit -= 16;
1515 break;
1516 default:
David Wub6c23272016-02-01 10:58:21 +08001517 dev_err(info->dev, "unsupported bit: %d for pinctrl drive type: %d\n",
1518 bit, drv_type);
1519 return -EINVAL;
1520 }
1521 break;
1522 case DRV_TYPE_IO_DEFAULT:
1523 case DRV_TYPE_IO_1V8_OR_3V0:
1524 case DRV_TYPE_IO_1V8_ONLY:
1525 rmask_bits = RK3288_DRV_BITS_PER_PIN;
1526 break;
1527 default:
David Wub6c23272016-02-01 10:58:21 +08001528 dev_err(info->dev, "unsupported pinctrl drive type: %d\n",
1529 drv_type);
1530 return -EINVAL;
1531 }
1532
Heiko Stübnerb547c802014-07-20 01:50:11 +02001533 /* enable the write to the equivalent lower bits */
David Wub6c23272016-02-01 10:58:21 +08001534 data = ((1 << rmask_bits) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07001535 rmask = data | (data >> 16);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001536 data |= (ret << bit);
1537
Sonny Rao99e872d2014-07-31 22:58:00 -07001538 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001539
1540 return ret;
1541}
1542
David Wu3ba67672016-05-11 11:39:28 +08001543static int rockchip_pull_list[PULL_TYPE_MAX][4] = {
1544 {
1545 PIN_CONFIG_BIAS_DISABLE,
1546 PIN_CONFIG_BIAS_PULL_UP,
1547 PIN_CONFIG_BIAS_PULL_DOWN,
1548 PIN_CONFIG_BIAS_BUS_HOLD
1549 },
1550 {
1551 PIN_CONFIG_BIAS_DISABLE,
1552 PIN_CONFIG_BIAS_PULL_DOWN,
1553 PIN_CONFIG_BIAS_DISABLE,
1554 PIN_CONFIG_BIAS_PULL_UP
1555 },
1556};
1557
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001558static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
1559{
1560 struct rockchip_pinctrl *info = bank->drvdata;
1561 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001562 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001563 int reg, ret, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001564 u8 bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001565 u32 data;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001566
1567 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02001568 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001569 return PIN_CONFIG_BIAS_DISABLE;
1570
Heiko Stübner751a99a2014-05-05 13:58:20 +02001571 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
1572
1573 ret = regmap_read(regmap, reg, &data);
1574 if (ret)
1575 return ret;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001576
Heiko Stübnera2829262013-10-16 01:07:20 +02001577 switch (ctrl->type) {
1578 case RK2928:
Heiko Stübner751a99a2014-05-05 13:58:20 +02001579 return !(data & BIT(bit))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001580 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
1581 : PIN_CONFIG_BIAS_DISABLE;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001582 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001583 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02001584 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001585 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08001586 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08001587 pull_type = bank->pull_type[pin_num / 8];
Heiko Stübner751a99a2014-05-05 13:58:20 +02001588 data >>= bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +02001589 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
1590
David Wu3ba67672016-05-11 11:39:28 +08001591 return rockchip_pull_list[pull_type][data];
Heiko Stübnera2829262013-10-16 01:07:20 +02001592 default:
1593 dev_err(info->dev, "unsupported pinctrl type\n");
1594 return -EINVAL;
1595 };
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001596}
1597
1598static int rockchip_set_pull(struct rockchip_pin_bank *bank,
1599 int pin_num, int pull)
1600{
1601 struct rockchip_pinctrl *info = bank->drvdata;
1602 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001603 struct regmap *regmap;
David Wu3ba67672016-05-11 11:39:28 +08001604 int reg, ret, i, pull_type;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001605 u8 bit;
Sonny Rao99e872d2014-07-31 22:58:00 -07001606 u32 data, rmask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001607
1608 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
1609 bank->bank_num, pin_num, pull);
1610
1611 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +02001612 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001613 return pull ? -EINVAL : 0;
1614
Heiko Stübner751a99a2014-05-05 13:58:20 +02001615 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001616
Heiko Stübnera2829262013-10-16 01:07:20 +02001617 switch (ctrl->type) {
1618 case RK2928:
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001619 data = BIT(bit + 16);
1620 if (pull == PIN_CONFIG_BIAS_DISABLE)
1621 data |= BIT(bit);
Heiko Stübner751a99a2014-05-05 13:58:20 +02001622 ret = regmap_write(regmap, reg, data);
Heiko Stübnera2829262013-10-16 01:07:20 +02001623 break;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001624 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001625 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02001626 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001627 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08001628 case RK3399:
David Wu3ba67672016-05-11 11:39:28 +08001629 pull_type = bank->pull_type[pin_num / 8];
1630 ret = -EINVAL;
1631 for (i = 0; i < ARRAY_SIZE(rockchip_pull_list[pull_type]);
1632 i++) {
1633 if (rockchip_pull_list[pull_type][i] == pull) {
1634 ret = i;
1635 break;
1636 }
1637 }
1638
1639 if (ret < 0) {
1640 dev_err(info->dev, "unsupported pull setting %d\n",
1641 pull);
1642 return ret;
1643 }
1644
Heiko Stübner6ca52742013-10-16 01:08:42 +02001645 /* enable the write to the equivalent lower bits */
1646 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -07001647 rmask = data | (data >> 16);
David Wu3ba67672016-05-11 11:39:28 +08001648 data |= (ret << bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001649
Sonny Rao99e872d2014-07-31 22:58:00 -07001650 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübner6ca52742013-10-16 01:08:42 +02001651 break;
Heiko Stübnera2829262013-10-16 01:07:20 +02001652 default:
1653 dev_err(info->dev, "unsupported pinctrl type\n");
1654 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001655 }
1656
Heiko Stübner751a99a2014-05-05 13:58:20 +02001657 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001658}
1659
david.wu728d3f52017-03-02 15:11:24 +08001660#define RK3328_SCHMITT_BITS_PER_PIN 1
1661#define RK3328_SCHMITT_PINS_PER_REG 16
1662#define RK3328_SCHMITT_BANK_STRIDE 8
1663#define RK3328_SCHMITT_GRF_OFFSET 0x380
1664
1665static int rk3328_calc_schmitt_reg_and_bit(struct rockchip_pin_bank *bank,
1666 int pin_num,
1667 struct regmap **regmap,
1668 int *reg, u8 *bit)
1669{
1670 struct rockchip_pinctrl *info = bank->drvdata;
1671
1672 *regmap = info->regmap_base;
1673 *reg = RK3328_SCHMITT_GRF_OFFSET;
1674
1675 *reg += bank->bank_num * RK3328_SCHMITT_BANK_STRIDE;
1676 *reg += ((pin_num / RK3328_SCHMITT_PINS_PER_REG) * 4);
1677 *bit = pin_num % RK3328_SCHMITT_PINS_PER_REG;
1678
1679 return 0;
1680}
1681
david.wue3b357d2017-03-02 15:11:23 +08001682static int rockchip_get_schmitt(struct rockchip_pin_bank *bank, int pin_num)
1683{
1684 struct rockchip_pinctrl *info = bank->drvdata;
1685 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1686 struct regmap *regmap;
1687 int reg, ret;
1688 u8 bit;
1689 u32 data;
1690
1691 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
1692 if (ret)
1693 return ret;
1694
1695 ret = regmap_read(regmap, reg, &data);
1696 if (ret)
1697 return ret;
1698
1699 data >>= bit;
1700 return data & 0x1;
1701}
1702
1703static int rockchip_set_schmitt(struct rockchip_pin_bank *bank,
1704 int pin_num, int enable)
1705{
1706 struct rockchip_pinctrl *info = bank->drvdata;
1707 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1708 struct regmap *regmap;
1709 int reg, ret;
david.wue3b357d2017-03-02 15:11:23 +08001710 u8 bit;
1711 u32 data, rmask;
1712
1713 dev_dbg(info->dev, "setting input schmitt of GPIO%d-%d to %d\n",
1714 bank->bank_num, pin_num, enable);
1715
1716 ret = ctrl->schmitt_calc_reg(bank, pin_num, &regmap, &reg, &bit);
1717 if (ret)
1718 return ret;
1719
david.wue3b357d2017-03-02 15:11:23 +08001720 /* enable the write to the equivalent lower bits */
1721 data = BIT(bit + 16) | (enable << bit);
1722 rmask = BIT(bit + 16) | BIT(bit);
1723
John Keepingf07bedc2017-03-23 10:59:28 +00001724 return regmap_update_bits(regmap, reg, rmask, data);
david.wue3b357d2017-03-02 15:11:23 +08001725}
1726
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001727/*
1728 * Pinmux_ops handling
1729 */
1730
1731static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
1732{
1733 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1734
1735 return info->nfunctions;
1736}
1737
1738static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
1739 unsigned selector)
1740{
1741 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1742
1743 return info->functions[selector].name;
1744}
1745
1746static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
1747 unsigned selector, const char * const **groups,
1748 unsigned * const num_groups)
1749{
1750 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1751
1752 *groups = info->functions[selector].groups;
1753 *num_groups = info->functions[selector].ngroups;
1754
1755 return 0;
1756}
1757
Linus Walleij03e9f0c2014-09-03 13:02:56 +02001758static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
1759 unsigned group)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001760{
1761 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1762 const unsigned int *pins = info->groups[group].pins;
1763 const struct rockchip_pin_config *data = info->groups[group].data;
1764 struct rockchip_pin_bank *bank;
Heiko Stübner14797182014-03-26 00:57:00 +01001765 int cnt, ret = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001766
1767 dev_dbg(info->dev, "enable function %s group %s\n",
1768 info->functions[selector].name, info->groups[group].name);
1769
1770 /*
1771 * for each pin in the pin group selected, program the correspoding pin
1772 * pin function number in the config register.
1773 */
1774 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
1775 bank = pin_to_bank(info, pins[cnt]);
Heiko Stübner14797182014-03-26 00:57:00 +01001776 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
1777 data[cnt].func);
1778 if (ret)
1779 break;
1780 }
1781
1782 if (ret) {
1783 /* revert the already done pin settings */
1784 for (cnt--; cnt >= 0; cnt--)
1785 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
1786
1787 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001788 }
1789
1790 return 0;
1791}
1792
Caesar Wang6ba20a02016-03-15 15:55:45 +08001793static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
1794{
1795 struct rockchip_pin_bank *bank = gpiochip_get_data(chip);
1796 u32 data;
1797
1798 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
1799
1800 return !(data & BIT(offset));
1801}
1802
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001803/*
1804 * The calls to gpio_direction_output() and gpio_direction_input()
1805 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
1806 * function called from the gpiolib interface).
1807 */
Doug Andersone5c2c9d2014-10-21 10:47:33 -07001808static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip,
1809 int pin, bool input)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001810{
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001811 struct rockchip_pin_bank *bank;
Doug Andersone5c2c9d2014-10-21 10:47:33 -07001812 int ret;
Doug Andersonfab262f2014-10-21 10:47:35 -07001813 unsigned long flags;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001814 u32 data;
1815
Linus Walleij03bf81f2015-12-08 09:39:13 +01001816 bank = gpiochip_get_data(chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001817
Heiko Stübner14797182014-03-26 00:57:00 +01001818 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
1819 if (ret < 0)
1820 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001821
Lin Huang07a06ae2015-08-11 18:12:04 +08001822 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00001823 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07001824
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001825 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
1826 /* set bit to 1 for output, 0 for input */
1827 if (!input)
1828 data |= BIT(pin);
1829 else
1830 data &= ~BIT(pin);
1831 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
1832
John Keeping70b7aa72017-03-23 10:59:29 +00001833 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08001834 clk_disable(bank->clk);
Doug Andersonfab262f2014-10-21 10:47:35 -07001835
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001836 return 0;
1837}
1838
Doug Andersone5c2c9d2014-10-21 10:47:33 -07001839static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
1840 struct pinctrl_gpio_range *range,
1841 unsigned offset, bool input)
1842{
1843 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1844 struct gpio_chip *chip;
1845 int pin;
1846
1847 chip = range->gc;
1848 pin = offset - chip->base;
1849 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
1850 offset, range->name, pin, input ? "input" : "output");
1851
1852 return _rockchip_pmx_gpio_set_direction(chip, offset - chip->base,
1853 input);
1854}
1855
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001856static const struct pinmux_ops rockchip_pmx_ops = {
1857 .get_functions_count = rockchip_pmx_get_funcs_count,
1858 .get_function_name = rockchip_pmx_get_func_name,
1859 .get_function_groups = rockchip_pmx_get_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +02001860 .set_mux = rockchip_pmx_set,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001861 .gpio_set_direction = rockchip_pmx_gpio_set_direction,
1862};
1863
1864/*
1865 * Pinconf_ops handling
1866 */
1867
Heiko Stübner44b6d932013-06-16 17:41:16 +02001868static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
1869 enum pin_config_param pull)
1870{
Heiko Stübnera2829262013-10-16 01:07:20 +02001871 switch (ctrl->type) {
1872 case RK2928:
1873 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
1874 pull == PIN_CONFIG_BIAS_DISABLE);
1875 case RK3066B:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001876 return pull ? false : true;
Andy Yanb9c6dca2017-03-17 18:18:36 +01001877 case RV1108:
Heiko Stübnera2829262013-10-16 01:07:20 +02001878 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +02001879 case RK3288:
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02001880 case RK3368:
David Wub6c23272016-02-01 10:58:21 +08001881 case RK3399:
Heiko Stübnera2829262013-10-16 01:07:20 +02001882 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
Heiko Stübner44b6d932013-06-16 17:41:16 +02001883 }
1884
Heiko Stübnera2829262013-10-16 01:07:20 +02001885 return false;
Heiko Stübner44b6d932013-06-16 17:41:16 +02001886}
1887
Doug Andersone5c2c9d2014-10-21 10:47:33 -07001888static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001889static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset);
1890
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001891/* set the pin config settings for a specified pin */
1892static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Sherman Yin03b054e2013-08-27 11:32:12 -07001893 unsigned long *configs, unsigned num_configs)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001894{
1895 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1896 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
Sherman Yin03b054e2013-08-27 11:32:12 -07001897 enum pin_config_param param;
Mika Westerberg58957d22017-01-23 15:34:32 +03001898 u32 arg;
Sherman Yin03b054e2013-08-27 11:32:12 -07001899 int i;
1900 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001901
Sherman Yin03b054e2013-08-27 11:32:12 -07001902 for (i = 0; i < num_configs; i++) {
1903 param = pinconf_to_config_param(configs[i]);
1904 arg = pinconf_to_config_argument(configs[i]);
1905
1906 switch (param) {
1907 case PIN_CONFIG_BIAS_DISABLE:
1908 rc = rockchip_set_pull(bank, pin - bank->pin_base,
1909 param);
1910 if (rc)
1911 return rc;
1912 break;
1913 case PIN_CONFIG_BIAS_PULL_UP:
1914 case PIN_CONFIG_BIAS_PULL_DOWN:
1915 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02001916 case PIN_CONFIG_BIAS_BUS_HOLD:
Sherman Yin03b054e2013-08-27 11:32:12 -07001917 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
1918 return -ENOTSUPP;
1919
1920 if (!arg)
1921 return -EINVAL;
1922
1923 rc = rockchip_set_pull(bank, pin - bank->pin_base,
1924 param);
1925 if (rc)
1926 return rc;
1927 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001928 case PIN_CONFIG_OUTPUT:
Doug Andersone5c2c9d2014-10-21 10:47:33 -07001929 rockchip_gpio_set(&bank->gpio_chip,
1930 pin - bank->pin_base, arg);
1931 rc = _rockchip_pmx_gpio_set_direction(&bank->gpio_chip,
1932 pin - bank->pin_base, false);
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001933 if (rc)
1934 return rc;
1935 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001936 case PIN_CONFIG_DRIVE_STRENGTH:
1937 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02001938 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02001939 return -ENOTSUPP;
1940
Heiko Stübneref17f692015-06-12 23:50:11 +02001941 rc = rockchip_set_drive_perpin(bank,
1942 pin - bank->pin_base, arg);
Heiko Stübnerb547c802014-07-20 01:50:11 +02001943 if (rc < 0)
1944 return rc;
1945 break;
david.wue3b357d2017-03-02 15:11:23 +08001946 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
1947 if (!info->ctrl->schmitt_calc_reg)
1948 return -ENOTSUPP;
1949
1950 rc = rockchip_set_schmitt(bank,
1951 pin - bank->pin_base, arg);
1952 if (rc < 0)
1953 return rc;
1954 break;
Sherman Yin03b054e2013-08-27 11:32:12 -07001955 default:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001956 return -ENOTSUPP;
Sherman Yin03b054e2013-08-27 11:32:12 -07001957 break;
1958 }
1959 } /* for each config */
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001960
1961 return 0;
1962}
1963
1964/* get the pin config settings for a specified pin */
1965static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
1966 unsigned long *config)
1967{
1968 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1969 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
1970 enum pin_config_param param = pinconf_to_config_param(*config);
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001971 u16 arg;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001972 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001973
1974 switch (param) {
1975 case PIN_CONFIG_BIAS_DISABLE:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001976 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001977 return -EINVAL;
1978
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001979 arg = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001980 break;
Heiko Stübner44b6d932013-06-16 17:41:16 +02001981 case PIN_CONFIG_BIAS_PULL_UP:
1982 case PIN_CONFIG_BIAS_PULL_DOWN:
1983 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02001984 case PIN_CONFIG_BIAS_BUS_HOLD:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001985 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
1986 return -ENOTSUPP;
1987
1988 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
1989 return -EINVAL;
1990
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001991 arg = 1;
Heiko Stübner44b6d932013-06-16 17:41:16 +02001992 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001993 case PIN_CONFIG_OUTPUT:
1994 rc = rockchip_get_mux(bank, pin - bank->pin_base);
1995 if (rc != RK_FUNC_GPIO)
1996 return -EINVAL;
1997
1998 rc = rockchip_gpio_get(&bank->gpio_chip, pin - bank->pin_base);
1999 if (rc < 0)
2000 return rc;
2001
2002 arg = rc ? 1 : 0;
2003 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02002004 case PIN_CONFIG_DRIVE_STRENGTH:
2005 /* rk3288 is the first with per-pin drive-strength */
Heiko Stübneref17f692015-06-12 23:50:11 +02002006 if (!info->ctrl->drv_calc_reg)
Heiko Stübnerb547c802014-07-20 01:50:11 +02002007 return -ENOTSUPP;
2008
Heiko Stübneref17f692015-06-12 23:50:11 +02002009 rc = rockchip_get_drive_perpin(bank, pin - bank->pin_base);
Heiko Stübnerb547c802014-07-20 01:50:11 +02002010 if (rc < 0)
2011 return rc;
2012
2013 arg = rc;
2014 break;
david.wue3b357d2017-03-02 15:11:23 +08002015 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
2016 if (!info->ctrl->schmitt_calc_reg)
2017 return -ENOTSUPP;
2018
2019 rc = rockchip_get_schmitt(bank, pin - bank->pin_base);
2020 if (rc < 0)
2021 return rc;
2022
2023 arg = rc;
2024 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002025 default:
2026 return -ENOTSUPP;
2027 break;
2028 }
2029
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02002030 *config = pinconf_to_config_packed(param, arg);
2031
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002032 return 0;
2033}
2034
2035static const struct pinconf_ops rockchip_pinconf_ops = {
2036 .pin_config_get = rockchip_pinconf_get,
2037 .pin_config_set = rockchip_pinconf_set,
Heiko Stübnered62f2f2014-07-20 01:48:45 +02002038 .is_generic = true,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002039};
2040
Heiko Stübner65fca612013-10-16 01:07:49 +02002041static const struct of_device_id rockchip_bank_match[] = {
2042 { .compatible = "rockchip,gpio-bank" },
Heiko Stübner6ca52742013-10-16 01:08:42 +02002043 { .compatible = "rockchip,rk3188-gpio-bank0" },
Heiko Stübner65fca612013-10-16 01:07:49 +02002044 {},
2045};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002046
2047static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
2048 struct device_node *np)
2049{
2050 struct device_node *child;
2051
2052 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002053 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002054 continue;
2055
2056 info->nfunctions++;
2057 info->ngroups += of_get_child_count(child);
2058 }
2059}
2060
2061static int rockchip_pinctrl_parse_groups(struct device_node *np,
2062 struct rockchip_pin_group *grp,
2063 struct rockchip_pinctrl *info,
2064 u32 index)
2065{
2066 struct rockchip_pin_bank *bank;
2067 int size;
2068 const __be32 *list;
2069 int num;
2070 int i, j;
2071 int ret;
2072
2073 dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
2074
2075 /* Initialise group */
2076 grp->name = np->name;
2077
2078 /*
2079 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
2080 * do sanity check and calculate pins number
2081 */
2082 list = of_get_property(np, "rockchip,pins", &size);
2083 /* we do not check return since it's safe node passed down */
2084 size /= sizeof(*list);
2085 if (!size || size % 4) {
2086 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
2087 return -EINVAL;
2088 }
2089
2090 grp->npins = size / 4;
2091
2092 grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),
2093 GFP_KERNEL);
2094 grp->data = devm_kzalloc(info->dev, grp->npins *
2095 sizeof(struct rockchip_pin_config),
2096 GFP_KERNEL);
2097 if (!grp->pins || !grp->data)
2098 return -ENOMEM;
2099
2100 for (i = 0, j = 0; i < size; i += 4, j++) {
2101 const __be32 *phandle;
2102 struct device_node *np_config;
2103
2104 num = be32_to_cpu(*list++);
2105 bank = bank_num_to_bank(info, num);
2106 if (IS_ERR(bank))
2107 return PTR_ERR(bank);
2108
2109 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
2110 grp->data[j].func = be32_to_cpu(*list++);
2111
2112 phandle = list++;
2113 if (!phandle)
2114 return -EINVAL;
2115
2116 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
Soren Brinkmanndd4d01f2015-01-09 07:43:46 -08002117 ret = pinconf_generic_parse_dt_config(np_config, NULL,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002118 &grp->data[j].configs, &grp->data[j].nconfigs);
2119 if (ret)
2120 return ret;
2121 }
2122
2123 return 0;
2124}
2125
2126static int rockchip_pinctrl_parse_functions(struct device_node *np,
2127 struct rockchip_pinctrl *info,
2128 u32 index)
2129{
2130 struct device_node *child;
2131 struct rockchip_pmx_func *func;
2132 struct rockchip_pin_group *grp;
2133 int ret;
2134 static u32 grp_index;
2135 u32 i = 0;
2136
2137 dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
2138
2139 func = &info->functions[index];
2140
2141 /* Initialise function */
2142 func->name = np->name;
2143 func->ngroups = of_get_child_count(np);
2144 if (func->ngroups <= 0)
2145 return 0;
2146
2147 func->groups = devm_kzalloc(info->dev,
2148 func->ngroups * sizeof(char *), GFP_KERNEL);
2149 if (!func->groups)
2150 return -ENOMEM;
2151
2152 for_each_child_of_node(np, child) {
2153 func->groups[i] = child->name;
2154 grp = &info->groups[grp_index++];
2155 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
Julia Lawallf7a81b72015-12-21 17:39:47 +01002156 if (ret) {
2157 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002158 return ret;
Julia Lawallf7a81b72015-12-21 17:39:47 +01002159 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002160 }
2161
2162 return 0;
2163}
2164
2165static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
2166 struct rockchip_pinctrl *info)
2167{
2168 struct device *dev = &pdev->dev;
2169 struct device_node *np = dev->of_node;
2170 struct device_node *child;
2171 int ret;
2172 int i;
2173
2174 rockchip_pinctrl_child_count(info, np);
2175
2176 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
2177 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
2178
2179 info->functions = devm_kzalloc(dev, info->nfunctions *
2180 sizeof(struct rockchip_pmx_func),
2181 GFP_KERNEL);
2182 if (!info->functions) {
2183 dev_err(dev, "failed to allocate memory for function list\n");
2184 return -EINVAL;
2185 }
2186
2187 info->groups = devm_kzalloc(dev, info->ngroups *
2188 sizeof(struct rockchip_pin_group),
2189 GFP_KERNEL);
2190 if (!info->groups) {
2191 dev_err(dev, "failed allocate memory for ping group list\n");
2192 return -EINVAL;
2193 }
2194
2195 i = 0;
2196
2197 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02002198 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002199 continue;
Heiko Stübner65fca612013-10-16 01:07:49 +02002200
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002201 ret = rockchip_pinctrl_parse_functions(child, info, i++);
2202 if (ret) {
2203 dev_err(&pdev->dev, "failed to parse function\n");
Julia Lawallf7a81b72015-12-21 17:39:47 +01002204 of_node_put(child);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002205 return ret;
2206 }
2207 }
2208
2209 return 0;
2210}
2211
2212static int rockchip_pinctrl_register(struct platform_device *pdev,
2213 struct rockchip_pinctrl *info)
2214{
2215 struct pinctrl_desc *ctrldesc = &info->pctl;
2216 struct pinctrl_pin_desc *pindesc, *pdesc;
2217 struct rockchip_pin_bank *pin_bank;
2218 int pin, bank, ret;
2219 int k;
2220
2221 ctrldesc->name = "rockchip-pinctrl";
2222 ctrldesc->owner = THIS_MODULE;
2223 ctrldesc->pctlops = &rockchip_pctrl_ops;
2224 ctrldesc->pmxops = &rockchip_pmx_ops;
2225 ctrldesc->confops = &rockchip_pinconf_ops;
2226
2227 pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
2228 info->ctrl->nr_pins, GFP_KERNEL);
2229 if (!pindesc) {
2230 dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
2231 return -ENOMEM;
2232 }
2233 ctrldesc->pins = pindesc;
2234 ctrldesc->npins = info->ctrl->nr_pins;
2235
2236 pdesc = pindesc;
2237 for (bank = 0 , k = 0; bank < info->ctrl->nr_banks; bank++) {
2238 pin_bank = &info->ctrl->pin_banks[bank];
2239 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
2240 pdesc->number = k;
2241 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
2242 pin_bank->name, pin);
2243 pdesc++;
2244 }
2245 }
2246
Doug Anderson0fb7dcb2014-10-21 10:47:34 -07002247 ret = rockchip_pinctrl_parse_dt(pdev, info);
2248 if (ret)
2249 return ret;
2250
Laxman Dewangan0085a2b2016-02-24 14:44:07 +05302251 info->pctl_dev = devm_pinctrl_register(&pdev->dev, ctrldesc, info);
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002252 if (IS_ERR(info->pctl_dev)) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002253 dev_err(&pdev->dev, "could not register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +09002254 return PTR_ERR(info->pctl_dev);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002255 }
2256
2257 for (bank = 0; bank < info->ctrl->nr_banks; ++bank) {
2258 pin_bank = &info->ctrl->pin_banks[bank];
2259 pin_bank->grange.name = pin_bank->name;
2260 pin_bank->grange.id = bank;
2261 pin_bank->grange.pin_base = pin_bank->pin_base;
2262 pin_bank->grange.base = pin_bank->gpio_chip.base;
2263 pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
2264 pin_bank->grange.gc = &pin_bank->gpio_chip;
2265 pinctrl_add_gpio_range(info->pctl_dev, &pin_bank->grange);
2266 }
2267
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002268 return 0;
2269}
2270
2271/*
2272 * GPIO handling
2273 */
2274
2275static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
2276{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002277 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002278 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR;
2279 unsigned long flags;
2280 u32 data;
2281
Lin Huang07a06ae2015-08-11 18:12:04 +08002282 clk_enable(bank->clk);
John Keeping70b7aa72017-03-23 10:59:29 +00002283 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002284
2285 data = readl(reg);
2286 data &= ~BIT(offset);
2287 if (value)
2288 data |= BIT(offset);
2289 writel(data, reg);
2290
John Keeping70b7aa72017-03-23 10:59:29 +00002291 raw_spin_unlock_irqrestore(&bank->slock, flags);
Lin Huang07a06ae2015-08-11 18:12:04 +08002292 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002293}
2294
2295/*
2296 * Returns the level of the pin for input direction and setting of the DR
2297 * register for output gpios.
2298 */
2299static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset)
2300{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002301 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002302 u32 data;
2303
Lin Huang07a06ae2015-08-11 18:12:04 +08002304 clk_enable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002305 data = readl(bank->reg_base + GPIO_EXT_PORT);
Lin Huang07a06ae2015-08-11 18:12:04 +08002306 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002307 data >>= offset;
2308 data &= 1;
2309 return data;
2310}
2311
2312/*
2313 * gpiolib gpio_direction_input callback function. The setting of the pin
2314 * mux function as 'gpio input' will be handled by the pinctrl susbsystem
2315 * interface.
2316 */
2317static int rockchip_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
2318{
2319 return pinctrl_gpio_direction_input(gc->base + offset);
2320}
2321
2322/*
2323 * gpiolib gpio_direction_output callback function. The setting of the pin
2324 * mux function as 'gpio output' will be handled by the pinctrl susbsystem
2325 * interface.
2326 */
2327static int rockchip_gpio_direction_output(struct gpio_chip *gc,
2328 unsigned offset, int value)
2329{
2330 rockchip_gpio_set(gc, offset, value);
2331 return pinctrl_gpio_direction_output(gc->base + offset);
2332}
2333
2334/*
2335 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
2336 * and a virtual IRQ, if not already present.
2337 */
2338static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
2339{
Linus Walleij03bf81f2015-12-08 09:39:13 +01002340 struct rockchip_pin_bank *bank = gpiochip_get_data(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002341 unsigned int virq;
2342
2343 if (!bank->domain)
2344 return -ENXIO;
2345
2346 virq = irq_create_mapping(bank->domain, offset);
2347
2348 return (virq) ? : -ENXIO;
2349}
2350
2351static const struct gpio_chip rockchip_gpiolib_chip = {
Jonas Gorski98c85d52015-10-11 17:34:19 +02002352 .request = gpiochip_generic_request,
2353 .free = gpiochip_generic_free,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002354 .set = rockchip_gpio_set,
2355 .get = rockchip_gpio_get,
Caesar Wang6ba20a02016-03-15 15:55:45 +08002356 .get_direction = rockchip_gpio_get_direction,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002357 .direction_input = rockchip_gpio_direction_input,
2358 .direction_output = rockchip_gpio_direction_output,
2359 .to_irq = rockchip_gpio_to_irq,
2360 .owner = THIS_MODULE,
2361};
2362
2363/*
2364 * Interrupt handling
2365 */
2366
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +02002367static void rockchip_irq_demux(struct irq_desc *desc)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002368{
Jiang Liu5663bb22015-06-04 12:13:16 +08002369 struct irq_chip *chip = irq_desc_get_chip(desc);
2370 struct rockchip_pin_bank *bank = irq_desc_get_handler_data(desc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002371 u32 pend;
2372
2373 dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
2374
2375 chained_irq_enter(chip, desc);
2376
2377 pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
2378
2379 while (pend) {
Thomas Gleixner415f7482015-07-13 01:52:00 +02002380 unsigned int irq, virq;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002381
2382 irq = __ffs(pend);
2383 pend &= ~BIT(irq);
2384 virq = irq_linear_revmap(bank->domain, irq);
2385
2386 if (!virq) {
2387 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
2388 continue;
2389 }
2390
2391 dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
2392
Heiko Stübner5a927502013-10-16 01:09:08 +02002393 /*
2394 * Triggering IRQ on both rising and falling edge
2395 * needs manual intervention.
2396 */
2397 if (bank->toggle_edge_mode & BIT(irq)) {
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002398 u32 data, data_old, polarity;
2399 unsigned long flags;
Heiko Stübner5a927502013-10-16 01:09:08 +02002400
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002401 data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
2402 do {
John Keeping70b7aa72017-03-23 10:59:29 +00002403 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002404
2405 polarity = readl_relaxed(bank->reg_base +
2406 GPIO_INT_POLARITY);
2407 if (data & BIT(irq))
2408 polarity &= ~BIT(irq);
2409 else
2410 polarity |= BIT(irq);
2411 writel(polarity,
2412 bank->reg_base + GPIO_INT_POLARITY);
2413
John Keeping70b7aa72017-03-23 10:59:29 +00002414 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Anderson53b1bfc2014-12-22 10:47:29 -08002415
2416 data_old = data;
2417 data = readl_relaxed(bank->reg_base +
2418 GPIO_EXT_PORT);
2419 } while ((data & BIT(irq)) != (data_old & BIT(irq)));
Heiko Stübner5a927502013-10-16 01:09:08 +02002420 }
2421
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002422 generic_handle_irq(virq);
2423 }
2424
2425 chained_irq_exit(chip, desc);
2426}
2427
2428static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
2429{
2430 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2431 struct rockchip_pin_bank *bank = gc->private;
2432 u32 mask = BIT(d->hwirq);
2433 u32 polarity;
2434 u32 level;
2435 u32 data;
Doug Andersonfab262f2014-10-21 10:47:35 -07002436 unsigned long flags;
Heiko Stübner14797182014-03-26 00:57:00 +01002437 int ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002438
Heiko Stübner5a927502013-10-16 01:09:08 +02002439 /* make sure the pin is configured as gpio input */
John Keeping88bb9422017-03-23 10:59:31 +00002440 ret = rockchip_verify_mux(bank, d->hwirq, RK_FUNC_GPIO);
Heiko Stübner14797182014-03-26 00:57:00 +01002441 if (ret < 0)
2442 return ret;
2443
John Keeping88bb9422017-03-23 10:59:31 +00002444 bank->new_irqs |= mask;
2445
John Keeping70b7aa72017-03-23 10:59:29 +00002446 raw_spin_lock_irqsave(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002447
Heiko Stübner5a927502013-10-16 01:09:08 +02002448 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
2449 data &= ~mask;
2450 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
2451
John Keeping70b7aa72017-03-23 10:59:29 +00002452 raw_spin_unlock_irqrestore(&bank->slock, flags);
Doug Andersonfab262f2014-10-21 10:47:35 -07002453
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002454 if (type & IRQ_TYPE_EDGE_BOTH)
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002455 irq_set_handler_locked(d, handle_edge_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002456 else
Thomas Gleixner2dbf1bc2015-06-23 15:52:50 +02002457 irq_set_handler_locked(d, handle_level_irq);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002458
John Keeping70b7aa72017-03-23 10:59:29 +00002459 raw_spin_lock_irqsave(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002460 irq_gc_lock(gc);
2461
2462 level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL);
2463 polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
2464
2465 switch (type) {
Heiko Stübner5a927502013-10-16 01:09:08 +02002466 case IRQ_TYPE_EDGE_BOTH:
2467 bank->toggle_edge_mode |= mask;
2468 level |= mask;
2469
2470 /*
2471 * Determine gpio state. If 1 next interrupt should be falling
2472 * otherwise rising.
2473 */
2474 data = readl(bank->reg_base + GPIO_EXT_PORT);
2475 if (data & mask)
2476 polarity &= ~mask;
2477 else
2478 polarity |= mask;
2479 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002480 case IRQ_TYPE_EDGE_RISING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002481 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002482 level |= mask;
2483 polarity |= mask;
2484 break;
2485 case IRQ_TYPE_EDGE_FALLING:
Heiko Stübner5a927502013-10-16 01:09:08 +02002486 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002487 level |= mask;
2488 polarity &= ~mask;
2489 break;
2490 case IRQ_TYPE_LEVEL_HIGH:
Heiko Stübner5a927502013-10-16 01:09:08 +02002491 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002492 level &= ~mask;
2493 polarity |= mask;
2494 break;
2495 case IRQ_TYPE_LEVEL_LOW:
Heiko Stübner5a927502013-10-16 01:09:08 +02002496 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002497 level &= ~mask;
2498 polarity &= ~mask;
2499 break;
2500 default:
Axel Lin7cc5f972013-06-23 08:48:34 +08002501 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002502 raw_spin_unlock_irqrestore(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002503 return -EINVAL;
2504 }
2505
2506 writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL);
2507 writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY);
2508
2509 irq_gc_unlock(gc);
John Keeping70b7aa72017-03-23 10:59:29 +00002510 raw_spin_unlock_irqrestore(&bank->slock, flags);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002511
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002512 return 0;
2513}
2514
Doug Anderson68bda472014-11-19 14:51:32 -08002515static void rockchip_irq_suspend(struct irq_data *d)
2516{
2517 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2518 struct rockchip_pin_bank *bank = gc->private;
2519
Lin Huang07a06ae2015-08-11 18:12:04 +08002520 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002521 bank->saved_masks = irq_reg_readl(gc, GPIO_INTMASK);
2522 irq_reg_writel(gc, ~gc->wake_active, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002523 clk_disable(bank->clk);
Doug Anderson68bda472014-11-19 14:51:32 -08002524}
2525
2526static void rockchip_irq_resume(struct irq_data *d)
2527{
2528 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2529 struct rockchip_pin_bank *bank = gc->private;
2530
Lin Huang07a06ae2015-08-11 18:12:04 +08002531 clk_enable(bank->clk);
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002532 irq_reg_writel(gc, bank->saved_masks, GPIO_INTMASK);
Lin Huang07a06ae2015-08-11 18:12:04 +08002533 clk_disable(bank->clk);
2534}
2535
Jeffy Chend4682892017-03-02 13:56:52 +08002536static void rockchip_irq_enable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08002537{
2538 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2539 struct rockchip_pin_bank *bank = gc->private;
2540
2541 clk_enable(bank->clk);
2542 irq_gc_mask_clr_bit(d);
2543}
2544
Jeffy Chend4682892017-03-02 13:56:52 +08002545static void rockchip_irq_disable(struct irq_data *d)
Lin Huang07a06ae2015-08-11 18:12:04 +08002546{
2547 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2548 struct rockchip_pin_bank *bank = gc->private;
2549
2550 irq_gc_mask_set_bit(d);
2551 clk_disable(bank->clk);
Doug Andersonf2dd0282014-11-19 14:51:33 -08002552}
2553
John Keeping88bb9422017-03-23 10:59:31 +00002554static void rockchip_irq_bus_lock(struct irq_data *d)
2555{
2556 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2557 struct rockchip_pin_bank *bank = gc->private;
2558
2559 clk_enable(bank->clk);
2560 mutex_lock(&bank->irq_lock);
2561}
2562
2563static void rockchip_irq_bus_sync_unlock(struct irq_data *d)
2564{
2565 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2566 struct rockchip_pin_bank *bank = gc->private;
2567
2568 while (bank->new_irqs) {
2569 unsigned int irq = __ffs(bank->new_irqs);
2570 int ret;
2571
2572 ret = rockchip_set_mux(bank, irq, RK_FUNC_GPIO);
2573 WARN_ON(ret < 0);
2574
2575 bank->new_irqs &= ~BIT(irq);
2576 }
2577
2578 mutex_unlock(&bank->irq_lock);
2579 clk_disable(bank->clk);
2580}
2581
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002582static int rockchip_interrupts_register(struct platform_device *pdev,
2583 struct rockchip_pinctrl *info)
2584{
2585 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2586 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2587 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
2588 struct irq_chip_generic *gc;
2589 int ret;
Lin Huang07a06ae2015-08-11 18:12:04 +08002590 int i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002591
2592 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2593 if (!bank->valid) {
2594 dev_warn(&pdev->dev, "bank %s is not valid\n",
2595 bank->name);
2596 continue;
2597 }
2598
Lin Huang07a06ae2015-08-11 18:12:04 +08002599 ret = clk_enable(bank->clk);
2600 if (ret) {
2601 dev_err(&pdev->dev, "failed to enable clock for bank %s\n",
2602 bank->name);
2603 continue;
2604 }
2605
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002606 bank->domain = irq_domain_add_linear(bank->of_node, 32,
2607 &irq_generic_chip_ops, NULL);
2608 if (!bank->domain) {
2609 dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n",
2610 bank->name);
Lin Huang07a06ae2015-08-11 18:12:04 +08002611 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002612 continue;
2613 }
2614
2615 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
2616 "rockchip_gpio_irq", handle_level_irq,
2617 clr, 0, IRQ_GC_INIT_MASK_CACHE);
2618 if (ret) {
2619 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
2620 bank->name);
2621 irq_domain_remove(bank->domain);
Lin Huang07a06ae2015-08-11 18:12:04 +08002622 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002623 continue;
2624 }
2625
Doug Anderson5ae0c7a2015-01-26 08:24:03 -08002626 /*
2627 * Linux assumes that all interrupts start out disabled/masked.
2628 * Our driver only uses the concept of masked and always keeps
2629 * things enabled, so for us that's all masked and all enabled.
2630 */
2631 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK);
2632 writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN);
2633
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002634 gc = irq_get_domain_generic_chip(bank->domain, 0);
2635 gc->reg_base = bank->reg_base;
2636 gc->private = bank;
Doug Andersonf2dd0282014-11-19 14:51:33 -08002637 gc->chip_types[0].regs.mask = GPIO_INTMASK;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002638 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
2639 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
Jeffy Chend4682892017-03-02 13:56:52 +08002640 gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit;
2641 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit;
2642 gc->chip_types[0].chip.irq_enable = rockchip_irq_enable;
2643 gc->chip_types[0].chip.irq_disable = rockchip_irq_disable;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002644 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
Doug Anderson68bda472014-11-19 14:51:32 -08002645 gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend;
2646 gc->chip_types[0].chip.irq_resume = rockchip_irq_resume;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002647 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
John Keeping88bb9422017-03-23 10:59:31 +00002648 gc->chip_types[0].chip.irq_bus_lock = rockchip_irq_bus_lock;
2649 gc->chip_types[0].chip.irq_bus_sync_unlock =
2650 rockchip_irq_bus_sync_unlock;
Doug Anderson876d7162014-10-21 10:47:32 -07002651 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002652
Thomas Gleixner03051bc2015-06-21 21:11:06 +02002653 irq_set_chained_handler_and_data(bank->irq,
2654 rockchip_irq_demux, bank);
Lin Huang07a06ae2015-08-11 18:12:04 +08002655
2656 /* map the gpio irqs here, when the clock is still running */
2657 for (j = 0 ; j < 32 ; j++)
2658 irq_create_mapping(bank->domain, j);
2659
2660 clk_disable(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002661 }
2662
2663 return 0;
2664}
2665
2666static int rockchip_gpiolib_register(struct platform_device *pdev,
2667 struct rockchip_pinctrl *info)
2668{
2669 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2670 struct rockchip_pin_bank *bank = ctrl->pin_banks;
2671 struct gpio_chip *gc;
2672 int ret;
2673 int i;
2674
2675 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2676 if (!bank->valid) {
2677 dev_warn(&pdev->dev, "bank %s is not valid\n",
2678 bank->name);
2679 continue;
2680 }
2681
2682 bank->gpio_chip = rockchip_gpiolib_chip;
2683
2684 gc = &bank->gpio_chip;
2685 gc->base = bank->pin_base;
2686 gc->ngpio = bank->nr_pins;
Linus Walleij58383c782015-11-04 09:56:26 +01002687 gc->parent = &pdev->dev;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002688 gc->of_node = bank->of_node;
2689 gc->label = bank->name;
2690
Linus Walleij03bf81f2015-12-08 09:39:13 +01002691 ret = gpiochip_add_data(gc, bank);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002692 if (ret) {
2693 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
2694 gc->label, ret);
2695 goto fail;
2696 }
2697 }
2698
2699 rockchip_interrupts_register(pdev, info);
2700
2701 return 0;
2702
2703fail:
2704 for (--i, --bank; i >= 0; --i, --bank) {
2705 if (!bank->valid)
2706 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02002707 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002708 }
2709 return ret;
2710}
2711
2712static int rockchip_gpiolib_unregister(struct platform_device *pdev,
2713 struct rockchip_pinctrl *info)
2714{
2715 struct rockchip_pin_ctrl *ctrl = info->ctrl;
2716 struct rockchip_pin_bank *bank = ctrl->pin_banks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002717 int i;
2718
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02002719 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002720 if (!bank->valid)
2721 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02002722 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002723 }
2724
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02002725 return 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002726}
2727
2728static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
Heiko Stübner622f3232014-05-05 13:58:46 +02002729 struct rockchip_pinctrl *info)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002730{
2731 struct resource res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02002732 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002733
2734 if (of_address_to_resource(bank->of_node, 0, &res)) {
Heiko Stübner622f3232014-05-05 13:58:46 +02002735 dev_err(info->dev, "cannot find IO resource for bank\n");
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002736 return -ENOENT;
2737 }
2738
Heiko Stübner622f3232014-05-05 13:58:46 +02002739 bank->reg_base = devm_ioremap_resource(info->dev, &res);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002740 if (IS_ERR(bank->reg_base))
2741 return PTR_ERR(bank->reg_base);
2742
Heiko Stübner6ca52742013-10-16 01:08:42 +02002743 /*
2744 * special case, where parts of the pull setting-registers are
2745 * part of the PMU register space
2746 */
2747 if (of_device_is_compatible(bank->of_node,
2748 "rockchip,rk3188-gpio-bank0")) {
Heiko Stübnera658efa2014-05-05 13:59:30 +02002749 struct device_node *node;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02002750
Heiko Stübnera658efa2014-05-05 13:59:30 +02002751 node = of_parse_phandle(bank->of_node->parent,
2752 "rockchip,pmu", 0);
2753 if (!node) {
2754 if (of_address_to_resource(bank->of_node, 1, &res)) {
2755 dev_err(info->dev, "cannot find IO resource for bank\n");
2756 return -ENOENT;
2757 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02002758
Heiko Stübnera658efa2014-05-05 13:59:30 +02002759 base = devm_ioremap_resource(info->dev, &res);
2760 if (IS_ERR(base))
2761 return PTR_ERR(base);
2762 rockchip_regmap_config.max_register =
2763 resource_size(&res) - 4;
2764 rockchip_regmap_config.name =
2765 "rockchip,rk3188-gpio-bank0-pull";
2766 bank->regmap_pull = devm_regmap_init_mmio(info->dev,
2767 base,
2768 &rockchip_regmap_config);
2769 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02002770 }
Heiko Stübner65fca612013-10-16 01:07:49 +02002771
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002772 bank->irq = irq_of_parse_and_map(bank->of_node, 0);
2773
2774 bank->clk = of_clk_get(bank->of_node, 0);
2775 if (IS_ERR(bank->clk))
2776 return PTR_ERR(bank->clk);
2777
Lin Huang07a06ae2015-08-11 18:12:04 +08002778 return clk_prepare(bank->clk);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002779}
2780
2781static const struct of_device_id rockchip_pinctrl_dt_match[];
2782
2783/* retrieve the soc specific data */
2784static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
2785 struct rockchip_pinctrl *d,
2786 struct platform_device *pdev)
2787{
2788 const struct of_device_id *match;
2789 struct device_node *node = pdev->dev.of_node;
2790 struct device_node *np;
2791 struct rockchip_pin_ctrl *ctrl;
2792 struct rockchip_pin_bank *bank;
David Wub6c23272016-02-01 10:58:21 +08002793 int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002794
2795 match = of_match_node(rockchip_pinctrl_dt_match, node);
2796 ctrl = (struct rockchip_pin_ctrl *)match->data;
2797
2798 for_each_child_of_node(node, np) {
2799 if (!of_find_property(np, "gpio-controller", NULL))
2800 continue;
2801
2802 bank = ctrl->pin_banks;
2803 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
2804 if (!strcmp(bank->name, np->name)) {
2805 bank->of_node = np;
2806
Heiko Stübner622f3232014-05-05 13:58:46 +02002807 if (!rockchip_get_bank_data(bank, d))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002808 bank->valid = true;
2809
2810 break;
2811 }
2812 }
2813 }
2814
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02002815 grf_offs = ctrl->grf_mux_offset;
2816 pmu_offs = ctrl->pmu_mux_offset;
David Wub6c23272016-02-01 10:58:21 +08002817 drv_pmu_offs = ctrl->pmu_drv_offset;
2818 drv_grf_offs = ctrl->grf_drv_offset;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002819 bank = ctrl->pin_banks;
2820 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002821 int bank_pins = 0;
2822
John Keeping70b7aa72017-03-23 10:59:29 +00002823 raw_spin_lock_init(&bank->slock);
John Keeping88bb9422017-03-23 10:59:31 +00002824 mutex_init(&bank->irq_lock);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002825 bank->drvdata = d;
2826 bank->pin_base = ctrl->nr_pins;
2827 ctrl->nr_pins += bank->nr_pins;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002828
David Wub6c23272016-02-01 10:58:21 +08002829 /* calculate iomux and drv offsets */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002830 for (j = 0; j < 4; j++) {
2831 struct rockchip_iomux *iom = &bank->iomux[j];
David Wub6c23272016-02-01 10:58:21 +08002832 struct rockchip_drv *drv = &bank->drv[j];
Heiko Stübner03716e12014-06-16 01:36:57 +02002833 int inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002834
2835 if (bank_pins >= bank->nr_pins)
2836 break;
2837
David Wub6c23272016-02-01 10:58:21 +08002838 /* preset iomux offset value, set new start value */
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002839 if (iom->offset >= 0) {
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02002840 if (iom->type & IOMUX_SOURCE_PMU)
2841 pmu_offs = iom->offset;
2842 else
2843 grf_offs = iom->offset;
David Wub6c23272016-02-01 10:58:21 +08002844 } else { /* set current iomux offset */
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02002845 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2846 pmu_offs : grf_offs;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002847 }
2848
David Wub6c23272016-02-01 10:58:21 +08002849 /* preset drv offset value, set new start value */
2850 if (drv->offset >= 0) {
2851 if (iom->type & IOMUX_SOURCE_PMU)
2852 drv_pmu_offs = drv->offset;
2853 else
2854 drv_grf_offs = drv->offset;
2855 } else { /* set current drv offset */
2856 drv->offset = (iom->type & IOMUX_SOURCE_PMU) ?
2857 drv_pmu_offs : drv_grf_offs;
2858 }
2859
2860 dev_dbg(d->dev, "bank %d, iomux %d has iom_offset 0x%x drv_offset 0x%x\n",
2861 i, j, iom->offset, drv->offset);
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002862
2863 /*
2864 * Increase offset according to iomux width.
Heiko Stübner03716e12014-06-16 01:36:57 +02002865 * 4bit iomux'es are spread over two registers.
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002866 */
david.wu8b6c6f92017-02-10 18:23:47 +08002867 inc = (iom->type & (IOMUX_WIDTH_4BIT |
2868 IOMUX_WIDTH_3BIT)) ? 8 : 4;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02002869 if (iom->type & IOMUX_SOURCE_PMU)
2870 pmu_offs += inc;
2871 else
2872 grf_offs += inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002873
David Wub6c23272016-02-01 10:58:21 +08002874 /*
2875 * Increase offset according to drv width.
2876 * 3bit drive-strenth'es are spread over two registers.
2877 */
2878 if ((drv->drv_type == DRV_TYPE_IO_1V8_3V0_AUTO) ||
2879 (drv->drv_type == DRV_TYPE_IO_3V3_ONLY))
2880 inc = 8;
2881 else
2882 inc = 4;
2883
2884 if (iom->type & IOMUX_SOURCE_PMU)
2885 drv_pmu_offs += inc;
2886 else
2887 drv_grf_offs += inc;
2888
Heiko Stübner6bc0d122014-06-16 01:36:33 +02002889 bank_pins += 8;
2890 }
David Wubd35b9b2017-05-26 15:20:20 +08002891
2892 /* calculate the per-bank route_mask */
2893 for (j = 0; j < ctrl->niomux_routes; j++) {
2894 int pin = 0;
2895
2896 if (ctrl->iomux_routes[j].bank_num == bank->bank_num) {
2897 pin = ctrl->iomux_routes[j].pin;
2898 bank->route_mask |= BIT(pin);
2899 }
2900 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002901 }
2902
2903 return ctrl;
2904}
2905
Chris Zhong8dca9332014-10-29 19:52:00 +08002906#define RK3288_GRF_GPIO6C_IOMUX 0x64
2907#define GPIO6C6_SEL_WRITE_ENABLE BIT(28)
2908
2909static u32 rk3288_grf_gpio6c_iomux;
2910
Chris Zhong9198f502014-10-29 19:51:59 +08002911static int __maybe_unused rockchip_pinctrl_suspend(struct device *dev)
2912{
2913 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08002914 int ret = pinctrl_force_sleep(info->pctl_dev);
Chris Zhong9198f502014-10-29 19:51:59 +08002915
Chris Zhong8dca9332014-10-29 19:52:00 +08002916 if (ret)
2917 return ret;
2918
2919 /*
2920 * RK3288 GPIO6_C6 mux would be modified by Maskrom when resume, so save
2921 * the setting here, and restore it at resume.
2922 */
2923 if (info->ctrl->type == RK3288) {
2924 ret = regmap_read(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2925 &rk3288_grf_gpio6c_iomux);
2926 if (ret) {
2927 pinctrl_force_default(info->pctl_dev);
2928 return ret;
2929 }
2930 }
2931
2932 return 0;
Chris Zhong9198f502014-10-29 19:51:59 +08002933}
2934
2935static int __maybe_unused rockchip_pinctrl_resume(struct device *dev)
2936{
2937 struct rockchip_pinctrl *info = dev_get_drvdata(dev);
Chris Zhong8dca9332014-10-29 19:52:00 +08002938 int ret = regmap_write(info->regmap_base, RK3288_GRF_GPIO6C_IOMUX,
2939 rk3288_grf_gpio6c_iomux |
2940 GPIO6C6_SEL_WRITE_ENABLE);
2941
2942 if (ret)
2943 return ret;
Chris Zhong9198f502014-10-29 19:51:59 +08002944
2945 return pinctrl_force_default(info->pctl_dev);
2946}
2947
2948static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend,
2949 rockchip_pinctrl_resume);
2950
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002951static int rockchip_pinctrl_probe(struct platform_device *pdev)
2952{
2953 struct rockchip_pinctrl *info;
2954 struct device *dev = &pdev->dev;
2955 struct rockchip_pin_ctrl *ctrl;
Heiko Stübner14dee862014-05-05 13:59:09 +02002956 struct device_node *np = pdev->dev.of_node, *node;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002957 struct resource *res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02002958 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002959 int ret;
2960
2961 if (!dev->of_node) {
2962 dev_err(dev, "device tree node not found\n");
2963 return -ENODEV;
2964 }
2965
2966 info = devm_kzalloc(dev, sizeof(struct rockchip_pinctrl), GFP_KERNEL);
2967 if (!info)
2968 return -ENOMEM;
2969
Heiko Stübner622f3232014-05-05 13:58:46 +02002970 info->dev = dev;
2971
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002972 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
2973 if (!ctrl) {
2974 dev_err(dev, "driver data not available\n");
2975 return -EINVAL;
2976 }
2977 info->ctrl = ctrl;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02002978
Heiko Stübner1e747e52014-05-05 13:59:51 +02002979 node = of_parse_phandle(np, "rockchip,grf", 0);
2980 if (node) {
2981 info->regmap_base = syscon_node_to_regmap(node);
2982 if (IS_ERR(info->regmap_base))
2983 return PTR_ERR(info->regmap_base);
2984 } else {
2985 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Heiko Stübner751a99a2014-05-05 13:58:20 +02002986 base = devm_ioremap_resource(&pdev->dev, res);
2987 if (IS_ERR(base))
2988 return PTR_ERR(base);
2989
2990 rockchip_regmap_config.max_register = resource_size(res) - 4;
Heiko Stübner1e747e52014-05-05 13:59:51 +02002991 rockchip_regmap_config.name = "rockchip,pinctrl";
2992 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
2993 &rockchip_regmap_config);
2994
2995 /* to check for the old dt-bindings */
2996 info->reg_size = resource_size(res);
2997
2998 /* Honor the old binding, with pull registers as 2nd resource */
2999 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
3000 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3001 base = devm_ioremap_resource(&pdev->dev, res);
3002 if (IS_ERR(base))
3003 return PTR_ERR(base);
3004
3005 rockchip_regmap_config.max_register =
3006 resource_size(res) - 4;
3007 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
3008 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
3009 base,
3010 &rockchip_regmap_config);
3011 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02003012 }
3013
Heiko Stübner14dee862014-05-05 13:59:09 +02003014 /* try to find the optional reference to the pmu syscon */
3015 node = of_parse_phandle(np, "rockchip,pmu", 0);
3016 if (node) {
3017 info->regmap_pmu = syscon_node_to_regmap(node);
3018 if (IS_ERR(info->regmap_pmu))
3019 return PTR_ERR(info->regmap_pmu);
3020 }
3021
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003022 ret = rockchip_gpiolib_register(pdev, info);
3023 if (ret)
3024 return ret;
3025
3026 ret = rockchip_pinctrl_register(pdev, info);
3027 if (ret) {
3028 rockchip_gpiolib_unregister(pdev, info);
3029 return ret;
3030 }
3031
3032 platform_set_drvdata(pdev, info);
3033
3034 return 0;
3035}
3036
Andy Yanb9c6dca2017-03-17 18:18:36 +01003037static struct rockchip_pin_bank rv1108_pin_banks[] = {
Andy Yan688daf22016-11-15 18:02:43 +08003038 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3039 IOMUX_SOURCE_PMU,
3040 IOMUX_SOURCE_PMU,
3041 IOMUX_SOURCE_PMU),
3042 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3043 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, 0),
3044 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
3045};
3046
Andy Yanb9c6dca2017-03-17 18:18:36 +01003047static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
3048 .pin_banks = rv1108_pin_banks,
3049 .nr_banks = ARRAY_SIZE(rv1108_pin_banks),
3050 .label = "RV1108-GPIO",
3051 .type = RV1108,
Andy Yan688daf22016-11-15 18:02:43 +08003052 .grf_mux_offset = 0x10,
3053 .pmu_mux_offset = 0x0,
Andy Yanb9c6dca2017-03-17 18:18:36 +01003054 .pull_calc_reg = rv1108_calc_pull_reg_and_bit,
3055 .drv_calc_reg = rv1108_calc_drv_reg_and_bit,
Andy Yan688daf22016-11-15 18:02:43 +08003056};
3057
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003058static struct rockchip_pin_bank rk2928_pin_banks[] = {
3059 PIN_BANK(0, 32, "gpio0"),
3060 PIN_BANK(1, 32, "gpio1"),
3061 PIN_BANK(2, 32, "gpio2"),
3062 PIN_BANK(3, 32, "gpio3"),
3063};
3064
3065static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
3066 .pin_banks = rk2928_pin_banks,
3067 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
3068 .label = "RK2928-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003069 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003070 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003071 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003072};
3073
Xing Zhengc5ce7672015-08-28 13:46:47 +08003074static struct rockchip_pin_bank rk3036_pin_banks[] = {
3075 PIN_BANK(0, 32, "gpio0"),
3076 PIN_BANK(1, 32, "gpio1"),
3077 PIN_BANK(2, 32, "gpio2"),
3078};
3079
3080static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
3081 .pin_banks = rk3036_pin_banks,
3082 .nr_banks = ARRAY_SIZE(rk3036_pin_banks),
3083 .label = "RK3036-GPIO",
3084 .type = RK2928,
3085 .grf_mux_offset = 0xa8,
3086 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
3087};
3088
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003089static struct rockchip_pin_bank rk3066a_pin_banks[] = {
3090 PIN_BANK(0, 32, "gpio0"),
3091 PIN_BANK(1, 32, "gpio1"),
3092 PIN_BANK(2, 32, "gpio2"),
3093 PIN_BANK(3, 32, "gpio3"),
3094 PIN_BANK(4, 32, "gpio4"),
3095 PIN_BANK(6, 16, "gpio6"),
3096};
3097
3098static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
3099 .pin_banks = rk3066a_pin_banks,
3100 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
3101 .label = "RK3066a-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003102 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003103 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02003104 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003105};
3106
3107static struct rockchip_pin_bank rk3066b_pin_banks[] = {
3108 PIN_BANK(0, 32, "gpio0"),
3109 PIN_BANK(1, 32, "gpio1"),
3110 PIN_BANK(2, 32, "gpio2"),
3111 PIN_BANK(3, 32, "gpio3"),
3112};
3113
3114static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
3115 .pin_banks = rk3066b_pin_banks,
3116 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
3117 .label = "RK3066b-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003118 .type = RK3066B,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003119 .grf_mux_offset = 0x60,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003120};
3121
3122static struct rockchip_pin_bank rk3188_pin_banks[] = {
Heiko Stübnerfc72c922014-06-16 01:36:05 +02003123 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003124 PIN_BANK(1, 32, "gpio1"),
3125 PIN_BANK(2, 32, "gpio2"),
3126 PIN_BANK(3, 32, "gpio3"),
3127};
3128
3129static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
3130 .pin_banks = rk3188_pin_banks,
3131 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
3132 .label = "RK3188-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02003133 .type = RK3188,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02003134 .grf_mux_offset = 0x60,
Heiko Stübner6ca52742013-10-16 01:08:42 +02003135 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003136};
3137
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003138static struct rockchip_pin_bank rk3228_pin_banks[] = {
3139 PIN_BANK(0, 32, "gpio0"),
3140 PIN_BANK(1, 32, "gpio1"),
3141 PIN_BANK(2, 32, "gpio2"),
3142 PIN_BANK(3, 32, "gpio3"),
3143};
3144
3145static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
3146 .pin_banks = rk3228_pin_banks,
3147 .nr_banks = ARRAY_SIZE(rk3228_pin_banks),
3148 .label = "RK3228-GPIO",
3149 .type = RK3288,
3150 .grf_mux_offset = 0x0,
David Wud4970ee2017-05-26 15:20:21 +08003151 .iomux_routes = rk3228_mux_route_data,
3152 .niomux_routes = ARRAY_SIZE(rk3228_mux_route_data),
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003153 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3154 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3155};
3156
Heiko Stübner304f0772014-06-16 01:38:14 +02003157static struct rockchip_pin_bank rk3288_pin_banks[] = {
3158 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
3159 IOMUX_SOURCE_PMU,
3160 IOMUX_SOURCE_PMU,
3161 IOMUX_UNROUTED
3162 ),
3163 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
3164 IOMUX_UNROUTED,
3165 IOMUX_UNROUTED,
3166 0
3167 ),
3168 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
3169 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
3170 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
3171 IOMUX_WIDTH_4BIT,
3172 0,
3173 0
3174 ),
3175 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
3176 0,
3177 0,
3178 IOMUX_UNROUTED
3179 ),
3180 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
3181 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
3182 0,
3183 IOMUX_WIDTH_4BIT,
3184 IOMUX_UNROUTED
3185 ),
3186 PIN_BANK(8, 16, "gpio8"),
3187};
3188
3189static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
3190 .pin_banks = rk3288_pin_banks,
3191 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
3192 .label = "RK3288-GPIO",
Heiko Stübner66d750e2014-07-20 01:49:17 +02003193 .type = RK3288,
Heiko Stübner304f0772014-06-16 01:38:14 +02003194 .grf_mux_offset = 0x0,
3195 .pmu_mux_offset = 0x84,
3196 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
Heiko Stübneref17f692015-06-12 23:50:11 +02003197 .drv_calc_reg = rk3288_calc_drv_reg_and_bit,
Heiko Stübner304f0772014-06-16 01:38:14 +02003198};
3199
david.wu3818e4a2017-02-10 18:23:49 +08003200static struct rockchip_pin_bank rk3328_pin_banks[] = {
3201 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", 0, 0, 0, 0),
3202 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", 0, 0, 0, 0),
3203 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0,
3204 IOMUX_WIDTH_3BIT | IOMUX_RECALCED,
3205 IOMUX_WIDTH_3BIT | IOMUX_RECALCED,
3206 0),
3207 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3",
3208 IOMUX_WIDTH_3BIT,
3209 IOMUX_WIDTH_3BIT | IOMUX_RECALCED,
3210 0,
3211 0),
3212};
3213
3214static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
3215 .pin_banks = rk3328_pin_banks,
3216 .nr_banks = ARRAY_SIZE(rk3328_pin_banks),
3217 .label = "RK3328-GPIO",
3218 .type = RK3288,
3219 .grf_mux_offset = 0x0,
David Wucedc9642017-05-26 15:20:22 +08003220 .iomux_routes = rk3328_mux_route_data,
3221 .niomux_routes = ARRAY_SIZE(rk3328_mux_route_data),
david.wu3818e4a2017-02-10 18:23:49 +08003222 .pull_calc_reg = rk3228_calc_pull_reg_and_bit,
3223 .drv_calc_reg = rk3228_calc_drv_reg_and_bit,
3224 .iomux_recalc = rk3328_recalc_mux,
david.wu728d3f52017-03-02 15:11:24 +08003225 .schmitt_calc_reg = rk3328_calc_schmitt_reg_and_bit,
david.wu3818e4a2017-02-10 18:23:49 +08003226};
3227
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003228static struct rockchip_pin_bank rk3368_pin_banks[] = {
3229 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_SOURCE_PMU,
3230 IOMUX_SOURCE_PMU,
3231 IOMUX_SOURCE_PMU,
3232 IOMUX_SOURCE_PMU
3233 ),
3234 PIN_BANK(1, 32, "gpio1"),
3235 PIN_BANK(2, 32, "gpio2"),
3236 PIN_BANK(3, 32, "gpio3"),
3237};
3238
3239static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
3240 .pin_banks = rk3368_pin_banks,
3241 .nr_banks = ARRAY_SIZE(rk3368_pin_banks),
3242 .label = "RK3368-GPIO",
3243 .type = RK3368,
3244 .grf_mux_offset = 0x0,
3245 .pmu_mux_offset = 0x0,
3246 .pull_calc_reg = rk3368_calc_pull_reg_and_bit,
3247 .drv_calc_reg = rk3368_calc_drv_reg_and_bit,
3248};
3249
David Wub6c23272016-02-01 10:58:21 +08003250static struct rockchip_pin_bank rk3399_pin_banks[] = {
David Wu3ba67672016-05-11 11:39:28 +08003251 PIN_BANK_IOMUX_FLAGS_DRV_FLAGS_OFFSET_PULL_FLAGS(0, 32, "gpio0",
3252 IOMUX_SOURCE_PMU,
3253 IOMUX_SOURCE_PMU,
3254 IOMUX_SOURCE_PMU,
3255 IOMUX_SOURCE_PMU,
3256 DRV_TYPE_IO_1V8_ONLY,
3257 DRV_TYPE_IO_1V8_ONLY,
3258 DRV_TYPE_IO_DEFAULT,
3259 DRV_TYPE_IO_DEFAULT,
3260 0x0,
3261 0x8,
3262 -1,
3263 -1,
3264 PULL_TYPE_IO_1V8_ONLY,
3265 PULL_TYPE_IO_1V8_ONLY,
3266 PULL_TYPE_IO_DEFAULT,
3267 PULL_TYPE_IO_DEFAULT
3268 ),
David Wub6c23272016-02-01 10:58:21 +08003269 PIN_BANK_IOMUX_DRV_FLAGS_OFFSET(1, 32, "gpio1", IOMUX_SOURCE_PMU,
3270 IOMUX_SOURCE_PMU,
3271 IOMUX_SOURCE_PMU,
3272 IOMUX_SOURCE_PMU,
3273 DRV_TYPE_IO_1V8_OR_3V0,
3274 DRV_TYPE_IO_1V8_OR_3V0,
3275 DRV_TYPE_IO_1V8_OR_3V0,
3276 DRV_TYPE_IO_1V8_OR_3V0,
3277 0x20,
3278 0x28,
3279 0x30,
3280 0x38
3281 ),
David Wu3ba67672016-05-11 11:39:28 +08003282 PIN_BANK_DRV_FLAGS_PULL_FLAGS(2, 32, "gpio2", DRV_TYPE_IO_1V8_OR_3V0,
3283 DRV_TYPE_IO_1V8_OR_3V0,
3284 DRV_TYPE_IO_1V8_ONLY,
3285 DRV_TYPE_IO_1V8_ONLY,
3286 PULL_TYPE_IO_DEFAULT,
3287 PULL_TYPE_IO_DEFAULT,
3288 PULL_TYPE_IO_1V8_ONLY,
3289 PULL_TYPE_IO_1V8_ONLY
3290 ),
David Wub6c23272016-02-01 10:58:21 +08003291 PIN_BANK_DRV_FLAGS(3, 32, "gpio3", DRV_TYPE_IO_3V3_ONLY,
3292 DRV_TYPE_IO_3V3_ONLY,
3293 DRV_TYPE_IO_3V3_ONLY,
3294 DRV_TYPE_IO_1V8_OR_3V0
3295 ),
3296 PIN_BANK_DRV_FLAGS(4, 32, "gpio4", DRV_TYPE_IO_1V8_OR_3V0,
3297 DRV_TYPE_IO_1V8_3V0_AUTO,
3298 DRV_TYPE_IO_1V8_OR_3V0,
3299 DRV_TYPE_IO_1V8_OR_3V0
3300 ),
3301};
3302
3303static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
3304 .pin_banks = rk3399_pin_banks,
3305 .nr_banks = ARRAY_SIZE(rk3399_pin_banks),
3306 .label = "RK3399-GPIO",
3307 .type = RK3399,
3308 .grf_mux_offset = 0xe000,
3309 .pmu_mux_offset = 0x0,
3310 .grf_drv_offset = 0xe100,
3311 .pmu_drv_offset = 0x80,
David Wuaccc1ce2017-05-26 15:20:23 +08003312 .iomux_routes = rk3399_mux_route_data,
3313 .niomux_routes = ARRAY_SIZE(rk3399_mux_route_data),
David Wub6c23272016-02-01 10:58:21 +08003314 .pull_calc_reg = rk3399_calc_pull_reg_and_bit,
3315 .drv_calc_reg = rk3399_calc_drv_reg_and_bit,
3316};
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003317
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003318static const struct of_device_id rockchip_pinctrl_dt_match[] = {
Andy Yanb9c6dca2017-03-17 18:18:36 +01003319 { .compatible = "rockchip,rv1108-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003320 .data = &rv1108_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003321 { .compatible = "rockchip,rk2928-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003322 .data = &rk2928_pin_ctrl },
Xing Zhengc5ce7672015-08-28 13:46:47 +08003323 { .compatible = "rockchip,rk3036-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003324 .data = &rk3036_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003325 { .compatible = "rockchip,rk3066a-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003326 .data = &rk3066a_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003327 { .compatible = "rockchip,rk3066b-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003328 .data = &rk3066b_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003329 { .compatible = "rockchip,rk3188-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003330 .data = &rk3188_pin_ctrl },
Jeffy Chenfea0fe62015-12-09 17:04:06 +08003331 { .compatible = "rockchip,rk3228-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003332 .data = &rk3228_pin_ctrl },
Heiko Stübner304f0772014-06-16 01:38:14 +02003333 { .compatible = "rockchip,rk3288-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003334 .data = &rk3288_pin_ctrl },
david.wu3818e4a2017-02-10 18:23:49 +08003335 { .compatible = "rockchip,rk3328-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003336 .data = &rk3328_pin_ctrl },
Heiko Stübnerdaecdc62015-06-12 23:51:01 +02003337 { .compatible = "rockchip,rk3368-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003338 .data = &rk3368_pin_ctrl },
David Wub6c23272016-02-01 10:58:21 +08003339 { .compatible = "rockchip,rk3399-pinctrl",
Masahiro Yamadacdbbd262017-04-28 21:50:35 +09003340 .data = &rk3399_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003341 {},
3342};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003343
3344static struct platform_driver rockchip_pinctrl_driver = {
3345 .probe = rockchip_pinctrl_probe,
3346 .driver = {
3347 .name = "rockchip-pinctrl",
Chris Zhong9198f502014-10-29 19:51:59 +08003348 .pm = &rockchip_pinctrl_dev_pm_ops,
Axel Lin0be9e702013-08-23 14:27:53 +08003349 .of_match_table = rockchip_pinctrl_dt_match,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02003350 },
3351};
3352
3353static int __init rockchip_pinctrl_drv_register(void)
3354{
3355 return platform_driver_register(&rockchip_pinctrl_driver);
3356}
3357postcore_initcall(rockchip_pinctrl_drv_register);