blob: 8a3c582108c5f225c8b72bd5c17e0b8e6e58a817 [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
26#include <linux/module.h>
27#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 {
62 RK2928,
63 RK3066B,
64 RK3188,
Heiko Stübner66d750e2014-07-20 01:49:17 +020065 RK3288,
Heiko Stübnera2829262013-10-16 01:07:20 +020066};
67
Heiko Stübnerfc72c922014-06-16 01:36:05 +020068/**
69 * Encode variants of iomux registers into a type variable
70 */
71#define IOMUX_GPIO_ONLY BIT(0)
Heiko Stübner03716e12014-06-16 01:36:57 +020072#define IOMUX_WIDTH_4BIT BIT(1)
Heiko Stübner95ec8ae2014-06-16 01:37:23 +020073#define IOMUX_SOURCE_PMU BIT(2)
Heiko Stübner62f49222014-06-16 01:37:49 +020074#define IOMUX_UNROUTED BIT(3)
Heiko Stübnerfc72c922014-06-16 01:36:05 +020075
76/**
77 * @type: iomux variant using IOMUX_* constants
Heiko Stübner6bc0d122014-06-16 01:36:33 +020078 * @offset: if initialized to -1 it will be autocalculated, by specifying
79 * an initial offset value the relevant source offset can be reset
80 * to a new value for autocalculating the following iomux registers.
Heiko Stübnerfc72c922014-06-16 01:36:05 +020081 */
82struct rockchip_iomux {
83 int type;
Heiko Stübner6bc0d122014-06-16 01:36:33 +020084 int offset;
Heiko Stübner65fca612013-10-16 01:07:49 +020085};
86
Heiko Stübnerd3e51162013-06-10 22:16:22 +020087/**
88 * @reg_base: register base of the gpio bank
Heiko Stübner6ca52742013-10-16 01:08:42 +020089 * @reg_pull: optional separate register for additional pull settings
Heiko Stübnerd3e51162013-06-10 22:16:22 +020090 * @clk: clock of the gpio bank
91 * @irq: interrupt of the gpio bank
92 * @pin_base: first pin number
93 * @nr_pins: number of pins in this bank
94 * @name: name of the bank
95 * @bank_num: number of the bank, to account for holes
Heiko Stübnerfc72c922014-06-16 01:36:05 +020096 * @iomux: array describing the 4 iomux sources of the bank
Heiko Stübnerd3e51162013-06-10 22:16:22 +020097 * @valid: are all necessary informations present
98 * @of_node: dt node of this bank
99 * @drvdata: common pinctrl basedata
100 * @domain: irqdomain of the gpio bank
101 * @gpio_chip: gpiolib chip
102 * @grange: gpio range
103 * @slock: spinlock for the gpio bank
104 */
105struct rockchip_pin_bank {
106 void __iomem *reg_base;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200107 struct regmap *regmap_pull;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200108 struct clk *clk;
109 int irq;
110 u32 pin_base;
111 u8 nr_pins;
112 char *name;
113 u8 bank_num;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200114 struct rockchip_iomux iomux[4];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200115 bool valid;
116 struct device_node *of_node;
117 struct rockchip_pinctrl *drvdata;
118 struct irq_domain *domain;
119 struct gpio_chip gpio_chip;
120 struct pinctrl_gpio_range grange;
121 spinlock_t slock;
Heiko Stübner5a927502013-10-16 01:09:08 +0200122 u32 toggle_edge_mode;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200123};
124
125#define PIN_BANK(id, pins, label) \
126 { \
127 .bank_num = id, \
128 .nr_pins = pins, \
129 .name = label, \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200130 .iomux = { \
131 { .offset = -1 }, \
132 { .offset = -1 }, \
133 { .offset = -1 }, \
134 { .offset = -1 }, \
135 }, \
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200136 }
137
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200138#define PIN_BANK_IOMUX_FLAGS(id, pins, label, iom0, iom1, iom2, iom3) \
139 { \
140 .bank_num = id, \
141 .nr_pins = pins, \
142 .name = label, \
143 .iomux = { \
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200144 { .type = iom0, .offset = -1 }, \
145 { .type = iom1, .offset = -1 }, \
146 { .type = iom2, .offset = -1 }, \
147 { .type = iom3, .offset = -1 }, \
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200148 }, \
149 }
150
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200151/**
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200152 */
153struct rockchip_pin_ctrl {
154 struct rockchip_pin_bank *pin_banks;
155 u32 nr_banks;
156 u32 nr_pins;
157 char *label;
Heiko Stübnera2829262013-10-16 01:07:20 +0200158 enum rockchip_pinctrl_type type;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200159 int grf_mux_offset;
160 int pmu_mux_offset;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200161 void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
162 int pin_num, struct regmap **regmap,
163 int *reg, u8 *bit);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200164};
165
166struct rockchip_pin_config {
167 unsigned int func;
168 unsigned long *configs;
169 unsigned int nconfigs;
170};
171
172/**
173 * struct rockchip_pin_group: represent group of pins of a pinmux function.
174 * @name: name of the pin group, used to lookup the group.
175 * @pins: the pins included in this group.
176 * @npins: number of pins included in this group.
177 * @func: the mux function number to be programmed when selected.
178 * @configs: the config values to be set for each pin
179 * @nconfigs: number of configs for each pin
180 */
181struct rockchip_pin_group {
182 const char *name;
183 unsigned int npins;
184 unsigned int *pins;
185 struct rockchip_pin_config *data;
186};
187
188/**
189 * struct rockchip_pmx_func: represent a pin function.
190 * @name: name of the pin function, used to lookup the function.
191 * @groups: one or more names of pin groups that provide this function.
192 * @num_groups: number of groups included in @groups.
193 */
194struct rockchip_pmx_func {
195 const char *name;
196 const char **groups;
197 u8 ngroups;
198};
199
200struct rockchip_pinctrl {
Heiko Stübner751a99a2014-05-05 13:58:20 +0200201 struct regmap *regmap_base;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200202 int reg_size;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200203 struct regmap *regmap_pull;
Heiko Stübner14dee862014-05-05 13:59:09 +0200204 struct regmap *regmap_pmu;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200205 struct device *dev;
206 struct rockchip_pin_ctrl *ctrl;
207 struct pinctrl_desc pctl;
208 struct pinctrl_dev *pctl_dev;
209 struct rockchip_pin_group *groups;
210 unsigned int ngroups;
211 struct rockchip_pmx_func *functions;
212 unsigned int nfunctions;
213};
214
Heiko Stübner751a99a2014-05-05 13:58:20 +0200215static struct regmap_config rockchip_regmap_config = {
216 .reg_bits = 32,
217 .val_bits = 32,
218 .reg_stride = 4,
219};
220
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200221static inline struct rockchip_pin_bank *gc_to_pin_bank(struct gpio_chip *gc)
222{
223 return container_of(gc, struct rockchip_pin_bank, gpio_chip);
224}
225
226static const inline struct rockchip_pin_group *pinctrl_name_to_group(
227 const struct rockchip_pinctrl *info,
228 const char *name)
229{
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200230 int i;
231
232 for (i = 0; i < info->ngroups; i++) {
Axel Lin1cb95392013-08-21 10:28:50 +0800233 if (!strcmp(info->groups[i].name, name))
234 return &info->groups[i];
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200235 }
236
Axel Lin1cb95392013-08-21 10:28:50 +0800237 return NULL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200238}
239
240/*
241 * given a pin number that is local to a pin controller, find out the pin bank
242 * and the register base of the pin bank.
243 */
244static struct rockchip_pin_bank *pin_to_bank(struct rockchip_pinctrl *info,
245 unsigned pin)
246{
247 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
248
Axel Lin51578b92013-08-23 15:49:00 +0800249 while (pin >= (b->pin_base + b->nr_pins))
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200250 b++;
251
252 return b;
253}
254
255static struct rockchip_pin_bank *bank_num_to_bank(
256 struct rockchip_pinctrl *info,
257 unsigned num)
258{
259 struct rockchip_pin_bank *b = info->ctrl->pin_banks;
260 int i;
261
Axel Lin1cb95392013-08-21 10:28:50 +0800262 for (i = 0; i < info->ctrl->nr_banks; i++, b++) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200263 if (b->bank_num == num)
Axel Lin1cb95392013-08-21 10:28:50 +0800264 return b;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200265 }
266
Axel Lin1cb95392013-08-21 10:28:50 +0800267 return ERR_PTR(-EINVAL);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200268}
269
270/*
271 * Pinctrl_ops handling
272 */
273
274static int rockchip_get_groups_count(struct pinctrl_dev *pctldev)
275{
276 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
277
278 return info->ngroups;
279}
280
281static const char *rockchip_get_group_name(struct pinctrl_dev *pctldev,
282 unsigned selector)
283{
284 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
285
286 return info->groups[selector].name;
287}
288
289static int rockchip_get_group_pins(struct pinctrl_dev *pctldev,
290 unsigned selector, const unsigned **pins,
291 unsigned *npins)
292{
293 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
294
295 if (selector >= info->ngroups)
296 return -EINVAL;
297
298 *pins = info->groups[selector].pins;
299 *npins = info->groups[selector].npins;
300
301 return 0;
302}
303
304static int rockchip_dt_node_to_map(struct pinctrl_dev *pctldev,
305 struct device_node *np,
306 struct pinctrl_map **map, unsigned *num_maps)
307{
308 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
309 const struct rockchip_pin_group *grp;
310 struct pinctrl_map *new_map;
311 struct device_node *parent;
312 int map_num = 1;
313 int i;
314
315 /*
316 * first find the group of this node and check if we need to create
317 * config maps for pins
318 */
319 grp = pinctrl_name_to_group(info, np->name);
320 if (!grp) {
321 dev_err(info->dev, "unable to find group for node %s\n",
322 np->name);
323 return -EINVAL;
324 }
325
326 map_num += grp->npins;
327 new_map = devm_kzalloc(pctldev->dev, sizeof(*new_map) * map_num,
328 GFP_KERNEL);
329 if (!new_map)
330 return -ENOMEM;
331
332 *map = new_map;
333 *num_maps = map_num;
334
335 /* create mux map */
336 parent = of_get_parent(np);
337 if (!parent) {
338 devm_kfree(pctldev->dev, new_map);
339 return -EINVAL;
340 }
341 new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
342 new_map[0].data.mux.function = parent->name;
343 new_map[0].data.mux.group = np->name;
344 of_node_put(parent);
345
346 /* create config map */
347 new_map++;
348 for (i = 0; i < grp->npins; i++) {
349 new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;
350 new_map[i].data.configs.group_or_pin =
351 pin_get_name(pctldev, grp->pins[i]);
352 new_map[i].data.configs.configs = grp->data[i].configs;
353 new_map[i].data.configs.num_configs = grp->data[i].nconfigs;
354 }
355
356 dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
357 (*map)->data.mux.function, (*map)->data.mux.group, map_num);
358
359 return 0;
360}
361
362static void rockchip_dt_free_map(struct pinctrl_dev *pctldev,
363 struct pinctrl_map *map, unsigned num_maps)
364{
365}
366
367static const struct pinctrl_ops rockchip_pctrl_ops = {
368 .get_groups_count = rockchip_get_groups_count,
369 .get_group_name = rockchip_get_group_name,
370 .get_group_pins = rockchip_get_group_pins,
371 .dt_node_to_map = rockchip_dt_node_to_map,
372 .dt_free_map = rockchip_dt_free_map,
373};
374
375/*
376 * Hardware access
377 */
378
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200379static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
380{
381 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200382 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200383 struct regmap *regmap;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200384 unsigned int val;
Heiko Stübner03716e12014-06-16 01:36:57 +0200385 int reg, ret, mask;
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200386 u8 bit;
387
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200388 if (iomux_num > 3)
389 return -EINVAL;
390
Heiko Stübner62f49222014-06-16 01:37:49 +0200391 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
392 dev_err(info->dev, "pin %d is unrouted\n", pin);
393 return -EINVAL;
394 }
395
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200396 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200397 return RK_FUNC_GPIO;
398
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200399 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
400 ? info->regmap_pmu : info->regmap_base;
401
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200402 /* get basic quadrupel of mux registers and the correct reg inside */
Heiko Stübner03716e12014-06-16 01:36:57 +0200403 mask = (bank->iomux[iomux_num].type & IOMUX_WIDTH_4BIT) ? 0xf : 0x3;
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200404 reg = bank->iomux[iomux_num].offset;
Heiko Stübner03716e12014-06-16 01:36:57 +0200405 if (bank->iomux[iomux_num].type & IOMUX_WIDTH_4BIT) {
406 if ((pin % 8) >= 4)
407 reg += 0x4;
408 bit = (pin % 4) * 4;
409 } else {
410 bit = (pin % 8) * 2;
411 }
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200412
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200413 ret = regmap_read(regmap, reg, &val);
Heiko Stübner751a99a2014-05-05 13:58:20 +0200414 if (ret)
415 return ret;
416
Heiko Stübner03716e12014-06-16 01:36:57 +0200417 return ((val >> bit) & mask);
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200418}
419
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200420/*
421 * Set a new mux function for a pin.
422 *
423 * The register is divided into the upper and lower 16 bit. When changing
424 * a value, the previous register value is not read and changed. Instead
425 * it seems the changed bits are marked in the upper 16 bit, while the
426 * changed value gets set in the same offset in the lower 16 bit.
427 * All pin settings seem to be 2 bit wide in both the upper and lower
428 * parts.
429 * @bank: pin bank to change
430 * @pin: pin to change
431 * @mux: new mux function to set
432 */
Heiko Stübner14797182014-03-26 00:57:00 +0100433static int rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200434{
435 struct rockchip_pinctrl *info = bank->drvdata;
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200436 int iomux_num = (pin / 8);
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200437 struct regmap *regmap;
Heiko Stübner03716e12014-06-16 01:36:57 +0200438 int reg, ret, mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200439 unsigned long flags;
440 u8 bit;
Sonny Rao99e872d2014-07-31 22:58:00 -0700441 u32 data, rmask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200442
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200443 if (iomux_num > 3)
444 return -EINVAL;
445
Heiko Stübner62f49222014-06-16 01:37:49 +0200446 if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
447 dev_err(info->dev, "pin %d is unrouted\n", pin);
448 return -EINVAL;
449 }
450
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200451 if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY) {
Heiko Stübnerc4a532de2014-03-26 00:57:52 +0100452 if (mux != RK_FUNC_GPIO) {
453 dev_err(info->dev,
454 "pin %d only supports a gpio mux\n", pin);
455 return -ENOTSUPP;
456 } else {
457 return 0;
458 }
459 }
460
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200461 dev_dbg(info->dev, "setting mux of GPIO%d-%d to %d\n",
462 bank->bank_num, pin, mux);
463
Heiko Stübner95ec8ae2014-06-16 01:37:23 +0200464 regmap = (bank->iomux[iomux_num].type & IOMUX_SOURCE_PMU)
465 ? info->regmap_pmu : info->regmap_base;
466
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200467 /* get basic quadrupel of mux registers and the correct reg inside */
Heiko Stübner03716e12014-06-16 01:36:57 +0200468 mask = (bank->iomux[iomux_num].type & IOMUX_WIDTH_4BIT) ? 0xf : 0x3;
Heiko Stübner6bc0d122014-06-16 01:36:33 +0200469 reg = bank->iomux[iomux_num].offset;
Heiko Stübner03716e12014-06-16 01:36:57 +0200470 if (bank->iomux[iomux_num].type & IOMUX_WIDTH_4BIT) {
471 if ((pin % 8) >= 4)
472 reg += 0x4;
473 bit = (pin % 4) * 4;
474 } else {
475 bit = (pin % 8) * 2;
476 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200477
478 spin_lock_irqsave(&bank->slock, flags);
479
Heiko Stübner03716e12014-06-16 01:36:57 +0200480 data = (mask << (bit + 16));
Sonny Rao99e872d2014-07-31 22:58:00 -0700481 rmask = data | (data >> 16);
Heiko Stübner03716e12014-06-16 01:36:57 +0200482 data |= (mux & mask) << bit;
Sonny Rao99e872d2014-07-31 22:58:00 -0700483 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200484
485 spin_unlock_irqrestore(&bank->slock, flags);
Heiko Stübner14797182014-03-26 00:57:00 +0100486
Heiko Stübner751a99a2014-05-05 13:58:20 +0200487 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200488}
489
Heiko Stübnera2829262013-10-16 01:07:20 +0200490#define RK2928_PULL_OFFSET 0x118
491#define RK2928_PULL_PINS_PER_REG 16
492#define RK2928_PULL_BANK_STRIDE 8
493
494static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +0200495 int pin_num, struct regmap **regmap,
496 int *reg, u8 *bit)
Heiko Stübnera2829262013-10-16 01:07:20 +0200497{
498 struct rockchip_pinctrl *info = bank->drvdata;
499
Heiko Stübner751a99a2014-05-05 13:58:20 +0200500 *regmap = info->regmap_base;
501 *reg = RK2928_PULL_OFFSET;
Heiko Stübnera2829262013-10-16 01:07:20 +0200502 *reg += bank->bank_num * RK2928_PULL_BANK_STRIDE;
503 *reg += (pin_num / RK2928_PULL_PINS_PER_REG) * 4;
504
505 *bit = pin_num % RK2928_PULL_PINS_PER_REG;
506};
507
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200508#define RK3188_PULL_OFFSET 0x164
Heiko Stübner6ca52742013-10-16 01:08:42 +0200509#define RK3188_PULL_BITS_PER_PIN 2
510#define RK3188_PULL_PINS_PER_REG 8
511#define RK3188_PULL_BANK_STRIDE 16
Heiko Stübner14dee862014-05-05 13:59:09 +0200512#define RK3188_PULL_PMU_OFFSET 0x64
Heiko Stübner6ca52742013-10-16 01:08:42 +0200513
514static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
Heiko Stübner751a99a2014-05-05 13:58:20 +0200515 int pin_num, struct regmap **regmap,
516 int *reg, u8 *bit)
Heiko Stübner6ca52742013-10-16 01:08:42 +0200517{
518 struct rockchip_pinctrl *info = bank->drvdata;
519
520 /* The first 12 pins of the first bank are located elsewhere */
Heiko Stübnerfc72c922014-06-16 01:36:05 +0200521 if (bank->bank_num == 0 && pin_num < 12) {
Heiko Stübner14dee862014-05-05 13:59:09 +0200522 *regmap = info->regmap_pmu ? info->regmap_pmu
523 : bank->regmap_pull;
524 *reg = info->regmap_pmu ? RK3188_PULL_PMU_OFFSET : 0;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200525 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
Heiko Stübner6ca52742013-10-16 01:08:42 +0200526 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
527 *bit *= RK3188_PULL_BITS_PER_PIN;
528 } else {
Heiko Stübner751a99a2014-05-05 13:58:20 +0200529 *regmap = info->regmap_pull ? info->regmap_pull
530 : info->regmap_base;
531 *reg = info->regmap_pull ? 0 : RK3188_PULL_OFFSET;
532
Heiko Stübnerbfc7a422014-05-05 13:58:00 +0200533 /* correct the offset, as it is the 2nd pull register */
534 *reg -= 4;
Heiko Stübner6ca52742013-10-16 01:08:42 +0200535 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
536 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
537
538 /*
539 * The bits in these registers have an inverse ordering
540 * with the lowest pin being in bits 15:14 and the highest
541 * pin in bits 1:0
542 */
543 *bit = 7 - (pin_num % RK3188_PULL_PINS_PER_REG);
544 *bit *= RK3188_PULL_BITS_PER_PIN;
545 }
546}
547
Heiko Stübner304f0772014-06-16 01:38:14 +0200548#define RK3288_PULL_OFFSET 0x140
549static void rk3288_calc_pull_reg_and_bit(struct rockchip_pin_bank *bank,
550 int pin_num, struct regmap **regmap,
551 int *reg, u8 *bit)
552{
553 struct rockchip_pinctrl *info = bank->drvdata;
554
555 /* The first 24 pins of the first bank are located in PMU */
556 if (bank->bank_num == 0) {
557 *regmap = info->regmap_pmu;
558 *reg = RK3188_PULL_PMU_OFFSET;
559
560 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
561 *bit = pin_num % RK3188_PULL_PINS_PER_REG;
562 *bit *= RK3188_PULL_BITS_PER_PIN;
563 } else {
564 *regmap = info->regmap_base;
565 *reg = RK3288_PULL_OFFSET;
566
567 /* correct the offset, as we're starting with the 2nd bank */
568 *reg -= 0x10;
569 *reg += bank->bank_num * RK3188_PULL_BANK_STRIDE;
570 *reg += ((pin_num / RK3188_PULL_PINS_PER_REG) * 4);
571
572 *bit = (pin_num % RK3188_PULL_PINS_PER_REG);
573 *bit *= RK3188_PULL_BITS_PER_PIN;
574 }
575}
576
Heiko Stübnerb547c802014-07-20 01:50:11 +0200577#define RK3288_DRV_PMU_OFFSET 0x70
578#define RK3288_DRV_GRF_OFFSET 0x1c0
579#define RK3288_DRV_BITS_PER_PIN 2
580#define RK3288_DRV_PINS_PER_REG 8
581#define RK3288_DRV_BANK_STRIDE 16
582static int rk3288_drv_list[] = { 2, 4, 8, 12 };
583
584static void rk3288_calc_drv_reg_and_bit(struct rockchip_pin_bank *bank,
585 int pin_num, struct regmap **regmap,
586 int *reg, u8 *bit)
587{
588 struct rockchip_pinctrl *info = bank->drvdata;
589
590 /* The first 24 pins of the first bank are located in PMU */
591 if (bank->bank_num == 0) {
592 *regmap = info->regmap_pmu;
593 *reg = RK3288_DRV_PMU_OFFSET;
594
595 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
596 *bit = pin_num % RK3288_DRV_PINS_PER_REG;
597 *bit *= RK3288_DRV_BITS_PER_PIN;
598 } else {
599 *regmap = info->regmap_base;
600 *reg = RK3288_DRV_GRF_OFFSET;
601
602 /* correct the offset, as we're starting with the 2nd bank */
603 *reg -= 0x10;
604 *reg += bank->bank_num * RK3288_DRV_BANK_STRIDE;
605 *reg += ((pin_num / RK3288_DRV_PINS_PER_REG) * 4);
606
607 *bit = (pin_num % RK3288_DRV_PINS_PER_REG);
608 *bit *= RK3288_DRV_BITS_PER_PIN;
609 }
610}
611
612static int rk3288_get_drive(struct rockchip_pin_bank *bank, int pin_num)
613{
614 struct regmap *regmap;
615 int reg, ret;
616 u32 data;
617 u8 bit;
618
619 rk3288_calc_drv_reg_and_bit(bank, pin_num, &regmap, &reg, &bit);
620
621 ret = regmap_read(regmap, reg, &data);
622 if (ret)
623 return ret;
624
625 data >>= bit;
626 data &= (1 << RK3288_DRV_BITS_PER_PIN) - 1;
627
628 return rk3288_drv_list[data];
629}
630
631static int rk3288_set_drive(struct rockchip_pin_bank *bank, int pin_num,
632 int strength)
633{
634 struct rockchip_pinctrl *info = bank->drvdata;
635 struct regmap *regmap;
636 unsigned long flags;
637 int reg, ret, i;
Sonny Rao99e872d2014-07-31 22:58:00 -0700638 u32 data, rmask;
Heiko Stübnerb547c802014-07-20 01:50:11 +0200639 u8 bit;
640
641 rk3288_calc_drv_reg_and_bit(bank, pin_num, &regmap, &reg, &bit);
642
643 ret = -EINVAL;
644 for (i = 0; i < ARRAY_SIZE(rk3288_drv_list); i++) {
645 if (rk3288_drv_list[i] == strength) {
646 ret = i;
647 break;
648 }
649 }
650
651 if (ret < 0) {
652 dev_err(info->dev, "unsupported driver strength %d\n",
653 strength);
654 return ret;
655 }
656
657 spin_lock_irqsave(&bank->slock, flags);
658
659 /* enable the write to the equivalent lower bits */
660 data = ((1 << RK3288_DRV_BITS_PER_PIN) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -0700661 rmask = data | (data >> 16);
Heiko Stübnerb547c802014-07-20 01:50:11 +0200662 data |= (ret << bit);
663
Sonny Rao99e872d2014-07-31 22:58:00 -0700664 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübnerb547c802014-07-20 01:50:11 +0200665 spin_unlock_irqrestore(&bank->slock, flags);
666
667 return ret;
668}
669
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200670static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)
671{
672 struct rockchip_pinctrl *info = bank->drvdata;
673 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200674 struct regmap *regmap;
675 int reg, ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200676 u8 bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +0200677 u32 data;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200678
679 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +0200680 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200681 return PIN_CONFIG_BIAS_DISABLE;
682
Heiko Stübner751a99a2014-05-05 13:58:20 +0200683 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
684
685 ret = regmap_read(regmap, reg, &data);
686 if (ret)
687 return ret;
Heiko Stübner6ca52742013-10-16 01:08:42 +0200688
Heiko Stübnera2829262013-10-16 01:07:20 +0200689 switch (ctrl->type) {
690 case RK2928:
Heiko Stübner751a99a2014-05-05 13:58:20 +0200691 return !(data & BIT(bit))
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200692 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
693 : PIN_CONFIG_BIAS_DISABLE;
Heiko Stübnera2829262013-10-16 01:07:20 +0200694 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +0200695 case RK3288:
Heiko Stübner751a99a2014-05-05 13:58:20 +0200696 data >>= bit;
Heiko Stübner6ca52742013-10-16 01:08:42 +0200697 data &= (1 << RK3188_PULL_BITS_PER_PIN) - 1;
698
699 switch (data) {
700 case 0:
701 return PIN_CONFIG_BIAS_DISABLE;
702 case 1:
703 return PIN_CONFIG_BIAS_PULL_UP;
704 case 2:
705 return PIN_CONFIG_BIAS_PULL_DOWN;
706 case 3:
707 return PIN_CONFIG_BIAS_BUS_HOLD;
708 }
709
710 dev_err(info->dev, "unknown pull setting\n");
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200711 return -EIO;
Heiko Stübnera2829262013-10-16 01:07:20 +0200712 default:
713 dev_err(info->dev, "unsupported pinctrl type\n");
714 return -EINVAL;
715 };
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200716}
717
718static int rockchip_set_pull(struct rockchip_pin_bank *bank,
719 int pin_num, int pull)
720{
721 struct rockchip_pinctrl *info = bank->drvdata;
722 struct rockchip_pin_ctrl *ctrl = info->ctrl;
Heiko Stübner751a99a2014-05-05 13:58:20 +0200723 struct regmap *regmap;
724 int reg, ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200725 unsigned long flags;
726 u8 bit;
Sonny Rao99e872d2014-07-31 22:58:00 -0700727 u32 data, rmask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200728
729 dev_dbg(info->dev, "setting pull of GPIO%d-%d to %d\n",
730 bank->bank_num, pin_num, pull);
731
732 /* rk3066b does support any pulls */
Heiko Stübnera2829262013-10-16 01:07:20 +0200733 if (ctrl->type == RK3066B)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200734 return pull ? -EINVAL : 0;
735
Heiko Stübner751a99a2014-05-05 13:58:20 +0200736 ctrl->pull_calc_reg(bank, pin_num, &regmap, &reg, &bit);
Heiko Stübner6ca52742013-10-16 01:08:42 +0200737
Heiko Stübnera2829262013-10-16 01:07:20 +0200738 switch (ctrl->type) {
739 case RK2928:
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200740 spin_lock_irqsave(&bank->slock, flags);
741
742 data = BIT(bit + 16);
743 if (pull == PIN_CONFIG_BIAS_DISABLE)
744 data |= BIT(bit);
Heiko Stübner751a99a2014-05-05 13:58:20 +0200745 ret = regmap_write(regmap, reg, data);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200746
747 spin_unlock_irqrestore(&bank->slock, flags);
Heiko Stübnera2829262013-10-16 01:07:20 +0200748 break;
749 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +0200750 case RK3288:
Heiko Stübner6ca52742013-10-16 01:08:42 +0200751 spin_lock_irqsave(&bank->slock, flags);
752
753 /* enable the write to the equivalent lower bits */
754 data = ((1 << RK3188_PULL_BITS_PER_PIN) - 1) << (bit + 16);
Sonny Rao99e872d2014-07-31 22:58:00 -0700755 rmask = data | (data >> 16);
Heiko Stübner6ca52742013-10-16 01:08:42 +0200756
757 switch (pull) {
758 case PIN_CONFIG_BIAS_DISABLE:
759 break;
760 case PIN_CONFIG_BIAS_PULL_UP:
761 data |= (1 << bit);
762 break;
763 case PIN_CONFIG_BIAS_PULL_DOWN:
764 data |= (2 << bit);
765 break;
766 case PIN_CONFIG_BIAS_BUS_HOLD:
767 data |= (3 << bit);
768 break;
769 default:
Dan Carpenterd32c3e22013-11-14 11:22:54 +0300770 spin_unlock_irqrestore(&bank->slock, flags);
Heiko Stübner6ca52742013-10-16 01:08:42 +0200771 dev_err(info->dev, "unsupported pull setting %d\n",
772 pull);
773 return -EINVAL;
774 }
775
Sonny Rao99e872d2014-07-31 22:58:00 -0700776 ret = regmap_update_bits(regmap, reg, rmask, data);
Heiko Stübner6ca52742013-10-16 01:08:42 +0200777
778 spin_unlock_irqrestore(&bank->slock, flags);
779 break;
Heiko Stübnera2829262013-10-16 01:07:20 +0200780 default:
781 dev_err(info->dev, "unsupported pinctrl type\n");
782 return -EINVAL;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200783 }
784
Heiko Stübner751a99a2014-05-05 13:58:20 +0200785 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200786}
787
788/*
789 * Pinmux_ops handling
790 */
791
792static int rockchip_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
793{
794 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
795
796 return info->nfunctions;
797}
798
799static const char *rockchip_pmx_get_func_name(struct pinctrl_dev *pctldev,
800 unsigned selector)
801{
802 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
803
804 return info->functions[selector].name;
805}
806
807static int rockchip_pmx_get_groups(struct pinctrl_dev *pctldev,
808 unsigned selector, const char * const **groups,
809 unsigned * const num_groups)
810{
811 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
812
813 *groups = info->functions[selector].groups;
814 *num_groups = info->functions[selector].ngroups;
815
816 return 0;
817}
818
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200819static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
820 unsigned group)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200821{
822 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
823 const unsigned int *pins = info->groups[group].pins;
824 const struct rockchip_pin_config *data = info->groups[group].data;
825 struct rockchip_pin_bank *bank;
Heiko Stübner14797182014-03-26 00:57:00 +0100826 int cnt, ret = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200827
828 dev_dbg(info->dev, "enable function %s group %s\n",
829 info->functions[selector].name, info->groups[group].name);
830
831 /*
832 * for each pin in the pin group selected, program the correspoding pin
833 * pin function number in the config register.
834 */
835 for (cnt = 0; cnt < info->groups[group].npins; cnt++) {
836 bank = pin_to_bank(info, pins[cnt]);
Heiko Stübner14797182014-03-26 00:57:00 +0100837 ret = rockchip_set_mux(bank, pins[cnt] - bank->pin_base,
838 data[cnt].func);
839 if (ret)
840 break;
841 }
842
843 if (ret) {
844 /* revert the already done pin settings */
845 for (cnt--; cnt >= 0; cnt--)
846 rockchip_set_mux(bank, pins[cnt] - bank->pin_base, 0);
847
848 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200849 }
850
851 return 0;
852}
853
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200854/*
855 * The calls to gpio_direction_output() and gpio_direction_input()
856 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
857 * function called from the gpiolib interface).
858 */
Doug Andersone5c2c9d2014-10-21 10:47:33 -0700859static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *chip,
860 int pin, bool input)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200861{
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200862 struct rockchip_pin_bank *bank;
Doug Andersone5c2c9d2014-10-21 10:47:33 -0700863 int ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200864 u32 data;
865
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200866 bank = gc_to_pin_bank(chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200867
Heiko Stübner14797182014-03-26 00:57:00 +0100868 ret = rockchip_set_mux(bank, pin, RK_FUNC_GPIO);
869 if (ret < 0)
870 return ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200871
872 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
873 /* set bit to 1 for output, 0 for input */
874 if (!input)
875 data |= BIT(pin);
876 else
877 data &= ~BIT(pin);
878 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
879
880 return 0;
881}
882
Doug Andersone5c2c9d2014-10-21 10:47:33 -0700883static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
884 struct pinctrl_gpio_range *range,
885 unsigned offset, bool input)
886{
887 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
888 struct gpio_chip *chip;
889 int pin;
890
891 chip = range->gc;
892 pin = offset - chip->base;
893 dev_dbg(info->dev, "gpio_direction for pin %u as %s-%d to %s\n",
894 offset, range->name, pin, input ? "input" : "output");
895
896 return _rockchip_pmx_gpio_set_direction(chip, offset - chip->base,
897 input);
898}
899
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200900static const struct pinmux_ops rockchip_pmx_ops = {
901 .get_functions_count = rockchip_pmx_get_funcs_count,
902 .get_function_name = rockchip_pmx_get_func_name,
903 .get_function_groups = rockchip_pmx_get_groups,
Linus Walleij03e9f0c2014-09-03 13:02:56 +0200904 .set_mux = rockchip_pmx_set,
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200905 .gpio_set_direction = rockchip_pmx_gpio_set_direction,
906};
907
908/*
909 * Pinconf_ops handling
910 */
911
Heiko Stübner44b6d932013-06-16 17:41:16 +0200912static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl *ctrl,
913 enum pin_config_param pull)
914{
Heiko Stübnera2829262013-10-16 01:07:20 +0200915 switch (ctrl->type) {
916 case RK2928:
917 return (pull == PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ||
918 pull == PIN_CONFIG_BIAS_DISABLE);
919 case RK3066B:
Heiko Stübner44b6d932013-06-16 17:41:16 +0200920 return pull ? false : true;
Heiko Stübnera2829262013-10-16 01:07:20 +0200921 case RK3188:
Heiko Stübner66d750e2014-07-20 01:49:17 +0200922 case RK3288:
Heiko Stübnera2829262013-10-16 01:07:20 +0200923 return (pull != PIN_CONFIG_BIAS_PULL_PIN_DEFAULT);
Heiko Stübner44b6d932013-06-16 17:41:16 +0200924 }
925
Heiko Stübnera2829262013-10-16 01:07:20 +0200926 return false;
Heiko Stübner44b6d932013-06-16 17:41:16 +0200927}
928
Doug Andersone5c2c9d2014-10-21 10:47:33 -0700929static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200930static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset);
931
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200932/* set the pin config settings for a specified pin */
933static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Sherman Yin03b054e2013-08-27 11:32:12 -0700934 unsigned long *configs, unsigned num_configs)
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200935{
936 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
937 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
Sherman Yin03b054e2013-08-27 11:32:12 -0700938 enum pin_config_param param;
939 u16 arg;
940 int i;
941 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200942
Sherman Yin03b054e2013-08-27 11:32:12 -0700943 for (i = 0; i < num_configs; i++) {
944 param = pinconf_to_config_param(configs[i]);
945 arg = pinconf_to_config_argument(configs[i]);
946
947 switch (param) {
948 case PIN_CONFIG_BIAS_DISABLE:
949 rc = rockchip_set_pull(bank, pin - bank->pin_base,
950 param);
951 if (rc)
952 return rc;
953 break;
954 case PIN_CONFIG_BIAS_PULL_UP:
955 case PIN_CONFIG_BIAS_PULL_DOWN:
956 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +0200957 case PIN_CONFIG_BIAS_BUS_HOLD:
Sherman Yin03b054e2013-08-27 11:32:12 -0700958 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
959 return -ENOTSUPP;
960
961 if (!arg)
962 return -EINVAL;
963
964 rc = rockchip_set_pull(bank, pin - bank->pin_base,
965 param);
966 if (rc)
967 return rc;
968 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200969 case PIN_CONFIG_OUTPUT:
Doug Andersone5c2c9d2014-10-21 10:47:33 -0700970 rockchip_gpio_set(&bank->gpio_chip,
971 pin - bank->pin_base, arg);
972 rc = _rockchip_pmx_gpio_set_direction(&bank->gpio_chip,
973 pin - bank->pin_base, false);
Heiko Stübnera076e2e2014-04-23 14:28:59 +0200974 if (rc)
975 return rc;
976 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +0200977 case PIN_CONFIG_DRIVE_STRENGTH:
978 /* rk3288 is the first with per-pin drive-strength */
979 if (info->ctrl->type != RK3288)
980 return -ENOTSUPP;
981
982 rc = rk3288_set_drive(bank, pin - bank->pin_base, arg);
983 if (rc < 0)
984 return rc;
985 break;
Sherman Yin03b054e2013-08-27 11:32:12 -0700986 default:
Heiko Stübner44b6d932013-06-16 17:41:16 +0200987 return -ENOTSUPP;
Sherman Yin03b054e2013-08-27 11:32:12 -0700988 break;
989 }
990 } /* for each config */
Heiko Stübnerd3e51162013-06-10 22:16:22 +0200991
992 return 0;
993}
994
995/* get the pin config settings for a specified pin */
996static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
997 unsigned long *config)
998{
999 struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1000 struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
1001 enum pin_config_param param = pinconf_to_config_param(*config);
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001002 u16 arg;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001003 int rc;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001004
1005 switch (param) {
1006 case PIN_CONFIG_BIAS_DISABLE:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001007 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001008 return -EINVAL;
1009
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001010 arg = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001011 break;
Heiko Stübner44b6d932013-06-16 17:41:16 +02001012 case PIN_CONFIG_BIAS_PULL_UP:
1013 case PIN_CONFIG_BIAS_PULL_DOWN:
1014 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
Heiko Stübner6ca52742013-10-16 01:08:42 +02001015 case PIN_CONFIG_BIAS_BUS_HOLD:
Heiko Stübner44b6d932013-06-16 17:41:16 +02001016 if (!rockchip_pinconf_pull_valid(info->ctrl, param))
1017 return -ENOTSUPP;
1018
1019 if (rockchip_get_pull(bank, pin - bank->pin_base) != param)
1020 return -EINVAL;
1021
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001022 arg = 1;
Heiko Stübner44b6d932013-06-16 17:41:16 +02001023 break;
Heiko Stübnera076e2e2014-04-23 14:28:59 +02001024 case PIN_CONFIG_OUTPUT:
1025 rc = rockchip_get_mux(bank, pin - bank->pin_base);
1026 if (rc != RK_FUNC_GPIO)
1027 return -EINVAL;
1028
1029 rc = rockchip_gpio_get(&bank->gpio_chip, pin - bank->pin_base);
1030 if (rc < 0)
1031 return rc;
1032
1033 arg = rc ? 1 : 0;
1034 break;
Heiko Stübnerb547c802014-07-20 01:50:11 +02001035 case PIN_CONFIG_DRIVE_STRENGTH:
1036 /* rk3288 is the first with per-pin drive-strength */
1037 if (info->ctrl->type != RK3288)
1038 return -ENOTSUPP;
1039
1040 rc = rk3288_get_drive(bank, pin - bank->pin_base);
1041 if (rc < 0)
1042 return rc;
1043
1044 arg = rc;
1045 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001046 default:
1047 return -ENOTSUPP;
1048 break;
1049 }
1050
Heiko Stübnerdab3eba2014-04-23 14:27:51 +02001051 *config = pinconf_to_config_packed(param, arg);
1052
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001053 return 0;
1054}
1055
1056static const struct pinconf_ops rockchip_pinconf_ops = {
1057 .pin_config_get = rockchip_pinconf_get,
1058 .pin_config_set = rockchip_pinconf_set,
Heiko Stübnered62f2f2014-07-20 01:48:45 +02001059 .is_generic = true,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001060};
1061
Heiko Stübner65fca612013-10-16 01:07:49 +02001062static const struct of_device_id rockchip_bank_match[] = {
1063 { .compatible = "rockchip,gpio-bank" },
Heiko Stübner6ca52742013-10-16 01:08:42 +02001064 { .compatible = "rockchip,rk3188-gpio-bank0" },
Heiko Stübner65fca612013-10-16 01:07:49 +02001065 {},
1066};
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001067
1068static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,
1069 struct device_node *np)
1070{
1071 struct device_node *child;
1072
1073 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02001074 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001075 continue;
1076
1077 info->nfunctions++;
1078 info->ngroups += of_get_child_count(child);
1079 }
1080}
1081
1082static int rockchip_pinctrl_parse_groups(struct device_node *np,
1083 struct rockchip_pin_group *grp,
1084 struct rockchip_pinctrl *info,
1085 u32 index)
1086{
1087 struct rockchip_pin_bank *bank;
1088 int size;
1089 const __be32 *list;
1090 int num;
1091 int i, j;
1092 int ret;
1093
1094 dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
1095
1096 /* Initialise group */
1097 grp->name = np->name;
1098
1099 /*
1100 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
1101 * do sanity check and calculate pins number
1102 */
1103 list = of_get_property(np, "rockchip,pins", &size);
1104 /* we do not check return since it's safe node passed down */
1105 size /= sizeof(*list);
1106 if (!size || size % 4) {
1107 dev_err(info->dev, "wrong pins number or pins and configs should be by 4\n");
1108 return -EINVAL;
1109 }
1110
1111 grp->npins = size / 4;
1112
1113 grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),
1114 GFP_KERNEL);
1115 grp->data = devm_kzalloc(info->dev, grp->npins *
1116 sizeof(struct rockchip_pin_config),
1117 GFP_KERNEL);
1118 if (!grp->pins || !grp->data)
1119 return -ENOMEM;
1120
1121 for (i = 0, j = 0; i < size; i += 4, j++) {
1122 const __be32 *phandle;
1123 struct device_node *np_config;
1124
1125 num = be32_to_cpu(*list++);
1126 bank = bank_num_to_bank(info, num);
1127 if (IS_ERR(bank))
1128 return PTR_ERR(bank);
1129
1130 grp->pins[j] = bank->pin_base + be32_to_cpu(*list++);
1131 grp->data[j].func = be32_to_cpu(*list++);
1132
1133 phandle = list++;
1134 if (!phandle)
1135 return -EINVAL;
1136
1137 np_config = of_find_node_by_phandle(be32_to_cpup(phandle));
1138 ret = pinconf_generic_parse_dt_config(np_config,
1139 &grp->data[j].configs, &grp->data[j].nconfigs);
1140 if (ret)
1141 return ret;
1142 }
1143
1144 return 0;
1145}
1146
1147static int rockchip_pinctrl_parse_functions(struct device_node *np,
1148 struct rockchip_pinctrl *info,
1149 u32 index)
1150{
1151 struct device_node *child;
1152 struct rockchip_pmx_func *func;
1153 struct rockchip_pin_group *grp;
1154 int ret;
1155 static u32 grp_index;
1156 u32 i = 0;
1157
1158 dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
1159
1160 func = &info->functions[index];
1161
1162 /* Initialise function */
1163 func->name = np->name;
1164 func->ngroups = of_get_child_count(np);
1165 if (func->ngroups <= 0)
1166 return 0;
1167
1168 func->groups = devm_kzalloc(info->dev,
1169 func->ngroups * sizeof(char *), GFP_KERNEL);
1170 if (!func->groups)
1171 return -ENOMEM;
1172
1173 for_each_child_of_node(np, child) {
1174 func->groups[i] = child->name;
1175 grp = &info->groups[grp_index++];
1176 ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
1177 if (ret)
1178 return ret;
1179 }
1180
1181 return 0;
1182}
1183
1184static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
1185 struct rockchip_pinctrl *info)
1186{
1187 struct device *dev = &pdev->dev;
1188 struct device_node *np = dev->of_node;
1189 struct device_node *child;
1190 int ret;
1191 int i;
1192
1193 rockchip_pinctrl_child_count(info, np);
1194
1195 dev_dbg(&pdev->dev, "nfunctions = %d\n", info->nfunctions);
1196 dev_dbg(&pdev->dev, "ngroups = %d\n", info->ngroups);
1197
1198 info->functions = devm_kzalloc(dev, info->nfunctions *
1199 sizeof(struct rockchip_pmx_func),
1200 GFP_KERNEL);
1201 if (!info->functions) {
1202 dev_err(dev, "failed to allocate memory for function list\n");
1203 return -EINVAL;
1204 }
1205
1206 info->groups = devm_kzalloc(dev, info->ngroups *
1207 sizeof(struct rockchip_pin_group),
1208 GFP_KERNEL);
1209 if (!info->groups) {
1210 dev_err(dev, "failed allocate memory for ping group list\n");
1211 return -EINVAL;
1212 }
1213
1214 i = 0;
1215
1216 for_each_child_of_node(np, child) {
Heiko Stübner65fca612013-10-16 01:07:49 +02001217 if (of_match_node(rockchip_bank_match, child))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001218 continue;
Heiko Stübner65fca612013-10-16 01:07:49 +02001219
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001220 ret = rockchip_pinctrl_parse_functions(child, info, i++);
1221 if (ret) {
1222 dev_err(&pdev->dev, "failed to parse function\n");
1223 return ret;
1224 }
1225 }
1226
1227 return 0;
1228}
1229
1230static int rockchip_pinctrl_register(struct platform_device *pdev,
1231 struct rockchip_pinctrl *info)
1232{
1233 struct pinctrl_desc *ctrldesc = &info->pctl;
1234 struct pinctrl_pin_desc *pindesc, *pdesc;
1235 struct rockchip_pin_bank *pin_bank;
1236 int pin, bank, ret;
1237 int k;
1238
1239 ctrldesc->name = "rockchip-pinctrl";
1240 ctrldesc->owner = THIS_MODULE;
1241 ctrldesc->pctlops = &rockchip_pctrl_ops;
1242 ctrldesc->pmxops = &rockchip_pmx_ops;
1243 ctrldesc->confops = &rockchip_pinconf_ops;
1244
1245 pindesc = devm_kzalloc(&pdev->dev, sizeof(*pindesc) *
1246 info->ctrl->nr_pins, GFP_KERNEL);
1247 if (!pindesc) {
1248 dev_err(&pdev->dev, "mem alloc for pin descriptors failed\n");
1249 return -ENOMEM;
1250 }
1251 ctrldesc->pins = pindesc;
1252 ctrldesc->npins = info->ctrl->nr_pins;
1253
1254 pdesc = pindesc;
1255 for (bank = 0 , k = 0; bank < info->ctrl->nr_banks; bank++) {
1256 pin_bank = &info->ctrl->pin_banks[bank];
1257 for (pin = 0; pin < pin_bank->nr_pins; pin++, k++) {
1258 pdesc->number = k;
1259 pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
1260 pin_bank->name, pin);
1261 pdesc++;
1262 }
1263 }
1264
1265 info->pctl_dev = pinctrl_register(ctrldesc, &pdev->dev, info);
1266 if (!info->pctl_dev) {
1267 dev_err(&pdev->dev, "could not register pinctrl driver\n");
1268 return -EINVAL;
1269 }
1270
1271 for (bank = 0; bank < info->ctrl->nr_banks; ++bank) {
1272 pin_bank = &info->ctrl->pin_banks[bank];
1273 pin_bank->grange.name = pin_bank->name;
1274 pin_bank->grange.id = bank;
1275 pin_bank->grange.pin_base = pin_bank->pin_base;
1276 pin_bank->grange.base = pin_bank->gpio_chip.base;
1277 pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
1278 pin_bank->grange.gc = &pin_bank->gpio_chip;
1279 pinctrl_add_gpio_range(info->pctl_dev, &pin_bank->grange);
1280 }
1281
1282 ret = rockchip_pinctrl_parse_dt(pdev, info);
1283 if (ret) {
1284 pinctrl_unregister(info->pctl_dev);
1285 return ret;
1286 }
1287
1288 return 0;
1289}
1290
1291/*
1292 * GPIO handling
1293 */
1294
Axel Lin0351c282013-08-27 22:30:17 +08001295static int rockchip_gpio_request(struct gpio_chip *chip, unsigned offset)
1296{
1297 return pinctrl_request_gpio(chip->base + offset);
1298}
1299
1300static void rockchip_gpio_free(struct gpio_chip *chip, unsigned offset)
1301{
1302 pinctrl_free_gpio(chip->base + offset);
1303}
1304
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001305static void rockchip_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
1306{
1307 struct rockchip_pin_bank *bank = gc_to_pin_bank(gc);
1308 void __iomem *reg = bank->reg_base + GPIO_SWPORT_DR;
1309 unsigned long flags;
1310 u32 data;
1311
1312 spin_lock_irqsave(&bank->slock, flags);
1313
1314 data = readl(reg);
1315 data &= ~BIT(offset);
1316 if (value)
1317 data |= BIT(offset);
1318 writel(data, reg);
1319
1320 spin_unlock_irqrestore(&bank->slock, flags);
1321}
1322
1323/*
1324 * Returns the level of the pin for input direction and setting of the DR
1325 * register for output gpios.
1326 */
1327static int rockchip_gpio_get(struct gpio_chip *gc, unsigned offset)
1328{
1329 struct rockchip_pin_bank *bank = gc_to_pin_bank(gc);
1330 u32 data;
1331
1332 data = readl(bank->reg_base + GPIO_EXT_PORT);
1333 data >>= offset;
1334 data &= 1;
1335 return data;
1336}
1337
1338/*
1339 * gpiolib gpio_direction_input callback function. The setting of the pin
1340 * mux function as 'gpio input' will be handled by the pinctrl susbsystem
1341 * interface.
1342 */
1343static int rockchip_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
1344{
1345 return pinctrl_gpio_direction_input(gc->base + offset);
1346}
1347
1348/*
1349 * gpiolib gpio_direction_output callback function. The setting of the pin
1350 * mux function as 'gpio output' will be handled by the pinctrl susbsystem
1351 * interface.
1352 */
1353static int rockchip_gpio_direction_output(struct gpio_chip *gc,
1354 unsigned offset, int value)
1355{
1356 rockchip_gpio_set(gc, offset, value);
1357 return pinctrl_gpio_direction_output(gc->base + offset);
1358}
1359
1360/*
1361 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
1362 * and a virtual IRQ, if not already present.
1363 */
1364static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
1365{
1366 struct rockchip_pin_bank *bank = gc_to_pin_bank(gc);
1367 unsigned int virq;
1368
1369 if (!bank->domain)
1370 return -ENXIO;
1371
1372 virq = irq_create_mapping(bank->domain, offset);
1373
1374 return (virq) ? : -ENXIO;
1375}
1376
1377static const struct gpio_chip rockchip_gpiolib_chip = {
Axel Lin0351c282013-08-27 22:30:17 +08001378 .request = rockchip_gpio_request,
1379 .free = rockchip_gpio_free,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001380 .set = rockchip_gpio_set,
1381 .get = rockchip_gpio_get,
1382 .direction_input = rockchip_gpio_direction_input,
1383 .direction_output = rockchip_gpio_direction_output,
1384 .to_irq = rockchip_gpio_to_irq,
1385 .owner = THIS_MODULE,
1386};
1387
1388/*
1389 * Interrupt handling
1390 */
1391
1392static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc)
1393{
1394 struct irq_chip *chip = irq_get_chip(irq);
1395 struct rockchip_pin_bank *bank = irq_get_handler_data(irq);
Heiko Stübner5a927502013-10-16 01:09:08 +02001396 u32 polarity = 0, data = 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001397 u32 pend;
Heiko Stübner5a927502013-10-16 01:09:08 +02001398 bool edge_changed = false;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001399
1400 dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name);
1401
1402 chained_irq_enter(chip, desc);
1403
1404 pend = readl_relaxed(bank->reg_base + GPIO_INT_STATUS);
1405
Heiko Stübner5a927502013-10-16 01:09:08 +02001406 if (bank->toggle_edge_mode) {
1407 polarity = readl_relaxed(bank->reg_base +
1408 GPIO_INT_POLARITY);
1409 data = readl_relaxed(bank->reg_base + GPIO_EXT_PORT);
1410 }
1411
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001412 while (pend) {
1413 unsigned int virq;
1414
1415 irq = __ffs(pend);
1416 pend &= ~BIT(irq);
1417 virq = irq_linear_revmap(bank->domain, irq);
1418
1419 if (!virq) {
1420 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq);
1421 continue;
1422 }
1423
1424 dev_dbg(bank->drvdata->dev, "handling irq %d\n", irq);
1425
Heiko Stübner5a927502013-10-16 01:09:08 +02001426 /*
1427 * Triggering IRQ on both rising and falling edge
1428 * needs manual intervention.
1429 */
1430 if (bank->toggle_edge_mode & BIT(irq)) {
1431 if (data & BIT(irq))
1432 polarity &= ~BIT(irq);
1433 else
1434 polarity |= BIT(irq);
1435
1436 edge_changed = true;
1437 }
1438
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001439 generic_handle_irq(virq);
1440 }
1441
Heiko Stübner5a927502013-10-16 01:09:08 +02001442 if (bank->toggle_edge_mode && edge_changed) {
1443 /* Interrupt params should only be set with ints disabled */
1444 data = readl_relaxed(bank->reg_base + GPIO_INTEN);
1445 writel_relaxed(0, bank->reg_base + GPIO_INTEN);
1446 writel(polarity, bank->reg_base + GPIO_INT_POLARITY);
1447 writel(data, bank->reg_base + GPIO_INTEN);
1448 }
1449
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001450 chained_irq_exit(chip, desc);
1451}
1452
1453static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
1454{
1455 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1456 struct rockchip_pin_bank *bank = gc->private;
1457 u32 mask = BIT(d->hwirq);
1458 u32 polarity;
1459 u32 level;
1460 u32 data;
Heiko Stübner14797182014-03-26 00:57:00 +01001461 int ret;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001462
Heiko Stübner5a927502013-10-16 01:09:08 +02001463 /* make sure the pin is configured as gpio input */
Heiko Stübner14797182014-03-26 00:57:00 +01001464 ret = rockchip_set_mux(bank, d->hwirq, RK_FUNC_GPIO);
1465 if (ret < 0)
1466 return ret;
1467
Heiko Stübner5a927502013-10-16 01:09:08 +02001468 data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR);
1469 data &= ~mask;
1470 writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR);
1471
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001472 if (type & IRQ_TYPE_EDGE_BOTH)
1473 __irq_set_handler_locked(d->irq, handle_edge_irq);
1474 else
1475 __irq_set_handler_locked(d->irq, handle_level_irq);
1476
1477 irq_gc_lock(gc);
1478
1479 level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL);
1480 polarity = readl_relaxed(gc->reg_base + GPIO_INT_POLARITY);
1481
1482 switch (type) {
Heiko Stübner5a927502013-10-16 01:09:08 +02001483 case IRQ_TYPE_EDGE_BOTH:
1484 bank->toggle_edge_mode |= mask;
1485 level |= mask;
1486
1487 /*
1488 * Determine gpio state. If 1 next interrupt should be falling
1489 * otherwise rising.
1490 */
1491 data = readl(bank->reg_base + GPIO_EXT_PORT);
1492 if (data & mask)
1493 polarity &= ~mask;
1494 else
1495 polarity |= mask;
1496 break;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001497 case IRQ_TYPE_EDGE_RISING:
Heiko Stübner5a927502013-10-16 01:09:08 +02001498 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001499 level |= mask;
1500 polarity |= mask;
1501 break;
1502 case IRQ_TYPE_EDGE_FALLING:
Heiko Stübner5a927502013-10-16 01:09:08 +02001503 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001504 level |= mask;
1505 polarity &= ~mask;
1506 break;
1507 case IRQ_TYPE_LEVEL_HIGH:
Heiko Stübner5a927502013-10-16 01:09:08 +02001508 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001509 level &= ~mask;
1510 polarity |= mask;
1511 break;
1512 case IRQ_TYPE_LEVEL_LOW:
Heiko Stübner5a927502013-10-16 01:09:08 +02001513 bank->toggle_edge_mode &= ~mask;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001514 level &= ~mask;
1515 polarity &= ~mask;
1516 break;
1517 default:
Axel Lin7cc5f972013-06-23 08:48:34 +08001518 irq_gc_unlock(gc);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001519 return -EINVAL;
1520 }
1521
1522 writel_relaxed(level, gc->reg_base + GPIO_INTTYPE_LEVEL);
1523 writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY);
1524
1525 irq_gc_unlock(gc);
1526
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001527 return 0;
1528}
1529
1530static int rockchip_interrupts_register(struct platform_device *pdev,
1531 struct rockchip_pinctrl *info)
1532{
1533 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1534 struct rockchip_pin_bank *bank = ctrl->pin_banks;
1535 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
1536 struct irq_chip_generic *gc;
1537 int ret;
1538 int i;
1539
1540 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
1541 if (!bank->valid) {
1542 dev_warn(&pdev->dev, "bank %s is not valid\n",
1543 bank->name);
1544 continue;
1545 }
1546
1547 bank->domain = irq_domain_add_linear(bank->of_node, 32,
1548 &irq_generic_chip_ops, NULL);
1549 if (!bank->domain) {
1550 dev_warn(&pdev->dev, "could not initialize irq domain for bank %s\n",
1551 bank->name);
1552 continue;
1553 }
1554
1555 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1,
1556 "rockchip_gpio_irq", handle_level_irq,
1557 clr, 0, IRQ_GC_INIT_MASK_CACHE);
1558 if (ret) {
1559 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n",
1560 bank->name);
1561 irq_domain_remove(bank->domain);
1562 continue;
1563 }
1564
1565 gc = irq_get_domain_generic_chip(bank->domain, 0);
1566 gc->reg_base = bank->reg_base;
1567 gc->private = bank;
1568 gc->chip_types[0].regs.mask = GPIO_INTEN;
1569 gc->chip_types[0].regs.ack = GPIO_PORTS_EOI;
1570 gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
1571 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
1572 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
1573 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
1574 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type;
Doug Anderson876d7162014-10-21 10:47:32 -07001575 gc->wake_enabled = IRQ_MSK(bank->nr_pins);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001576
1577 irq_set_handler_data(bank->irq, bank);
1578 irq_set_chained_handler(bank->irq, rockchip_irq_demux);
1579 }
1580
1581 return 0;
1582}
1583
1584static int rockchip_gpiolib_register(struct platform_device *pdev,
1585 struct rockchip_pinctrl *info)
1586{
1587 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1588 struct rockchip_pin_bank *bank = ctrl->pin_banks;
1589 struct gpio_chip *gc;
1590 int ret;
1591 int i;
1592
1593 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
1594 if (!bank->valid) {
1595 dev_warn(&pdev->dev, "bank %s is not valid\n",
1596 bank->name);
1597 continue;
1598 }
1599
1600 bank->gpio_chip = rockchip_gpiolib_chip;
1601
1602 gc = &bank->gpio_chip;
1603 gc->base = bank->pin_base;
1604 gc->ngpio = bank->nr_pins;
1605 gc->dev = &pdev->dev;
1606 gc->of_node = bank->of_node;
1607 gc->label = bank->name;
1608
1609 ret = gpiochip_add(gc);
1610 if (ret) {
1611 dev_err(&pdev->dev, "failed to register gpio_chip %s, error code: %d\n",
1612 gc->label, ret);
1613 goto fail;
1614 }
1615 }
1616
1617 rockchip_interrupts_register(pdev, info);
1618
1619 return 0;
1620
1621fail:
1622 for (--i, --bank; i >= 0; --i, --bank) {
1623 if (!bank->valid)
1624 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02001625 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001626 }
1627 return ret;
1628}
1629
1630static int rockchip_gpiolib_unregister(struct platform_device *pdev,
1631 struct rockchip_pinctrl *info)
1632{
1633 struct rockchip_pin_ctrl *ctrl = info->ctrl;
1634 struct rockchip_pin_bank *bank = ctrl->pin_banks;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001635 int i;
1636
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02001637 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001638 if (!bank->valid)
1639 continue;
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02001640 gpiochip_remove(&bank->gpio_chip);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001641 }
1642
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02001643 return 0;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001644}
1645
1646static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
Heiko Stübner622f3232014-05-05 13:58:46 +02001647 struct rockchip_pinctrl *info)
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001648{
1649 struct resource res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001650 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001651
1652 if (of_address_to_resource(bank->of_node, 0, &res)) {
Heiko Stübner622f3232014-05-05 13:58:46 +02001653 dev_err(info->dev, "cannot find IO resource for bank\n");
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001654 return -ENOENT;
1655 }
1656
Heiko Stübner622f3232014-05-05 13:58:46 +02001657 bank->reg_base = devm_ioremap_resource(info->dev, &res);
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001658 if (IS_ERR(bank->reg_base))
1659 return PTR_ERR(bank->reg_base);
1660
Heiko Stübner6ca52742013-10-16 01:08:42 +02001661 /*
1662 * special case, where parts of the pull setting-registers are
1663 * part of the PMU register space
1664 */
1665 if (of_device_is_compatible(bank->of_node,
1666 "rockchip,rk3188-gpio-bank0")) {
Heiko Stübnera658efa2014-05-05 13:59:30 +02001667 struct device_node *node;
Heiko Stübnerbfc7a422014-05-05 13:58:00 +02001668
Heiko Stübnera658efa2014-05-05 13:59:30 +02001669 node = of_parse_phandle(bank->of_node->parent,
1670 "rockchip,pmu", 0);
1671 if (!node) {
1672 if (of_address_to_resource(bank->of_node, 1, &res)) {
1673 dev_err(info->dev, "cannot find IO resource for bank\n");
1674 return -ENOENT;
1675 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02001676
Heiko Stübnera658efa2014-05-05 13:59:30 +02001677 base = devm_ioremap_resource(info->dev, &res);
1678 if (IS_ERR(base))
1679 return PTR_ERR(base);
1680 rockchip_regmap_config.max_register =
1681 resource_size(&res) - 4;
1682 rockchip_regmap_config.name =
1683 "rockchip,rk3188-gpio-bank0-pull";
1684 bank->regmap_pull = devm_regmap_init_mmio(info->dev,
1685 base,
1686 &rockchip_regmap_config);
1687 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02001688 }
Heiko Stübner65fca612013-10-16 01:07:49 +02001689
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001690 bank->irq = irq_of_parse_and_map(bank->of_node, 0);
1691
1692 bank->clk = of_clk_get(bank->of_node, 0);
1693 if (IS_ERR(bank->clk))
1694 return PTR_ERR(bank->clk);
1695
1696 return clk_prepare_enable(bank->clk);
1697}
1698
1699static const struct of_device_id rockchip_pinctrl_dt_match[];
1700
1701/* retrieve the soc specific data */
1702static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(
1703 struct rockchip_pinctrl *d,
1704 struct platform_device *pdev)
1705{
1706 const struct of_device_id *match;
1707 struct device_node *node = pdev->dev.of_node;
1708 struct device_node *np;
1709 struct rockchip_pin_ctrl *ctrl;
1710 struct rockchip_pin_bank *bank;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001711 int grf_offs, pmu_offs, i, j;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001712
1713 match = of_match_node(rockchip_pinctrl_dt_match, node);
1714 ctrl = (struct rockchip_pin_ctrl *)match->data;
1715
1716 for_each_child_of_node(node, np) {
1717 if (!of_find_property(np, "gpio-controller", NULL))
1718 continue;
1719
1720 bank = ctrl->pin_banks;
1721 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
1722 if (!strcmp(bank->name, np->name)) {
1723 bank->of_node = np;
1724
Heiko Stübner622f3232014-05-05 13:58:46 +02001725 if (!rockchip_get_bank_data(bank, d))
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001726 bank->valid = true;
1727
1728 break;
1729 }
1730 }
1731 }
1732
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001733 grf_offs = ctrl->grf_mux_offset;
1734 pmu_offs = ctrl->pmu_mux_offset;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001735 bank = ctrl->pin_banks;
1736 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001737 int bank_pins = 0;
1738
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001739 spin_lock_init(&bank->slock);
1740 bank->drvdata = d;
1741 bank->pin_base = ctrl->nr_pins;
1742 ctrl->nr_pins += bank->nr_pins;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001743
1744 /* calculate iomux offsets */
1745 for (j = 0; j < 4; j++) {
1746 struct rockchip_iomux *iom = &bank->iomux[j];
Heiko Stübner03716e12014-06-16 01:36:57 +02001747 int inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001748
1749 if (bank_pins >= bank->nr_pins)
1750 break;
1751
1752 /* preset offset value, set new start value */
1753 if (iom->offset >= 0) {
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001754 if (iom->type & IOMUX_SOURCE_PMU)
1755 pmu_offs = iom->offset;
1756 else
1757 grf_offs = iom->offset;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001758 } else { /* set current offset */
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001759 iom->offset = (iom->type & IOMUX_SOURCE_PMU) ?
1760 pmu_offs : grf_offs;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001761 }
1762
1763 dev_dbg(d->dev, "bank %d, iomux %d has offset 0x%x\n",
1764 i, j, iom->offset);
1765
1766 /*
1767 * Increase offset according to iomux width.
Heiko Stübner03716e12014-06-16 01:36:57 +02001768 * 4bit iomux'es are spread over two registers.
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001769 */
Heiko Stübner03716e12014-06-16 01:36:57 +02001770 inc = (iom->type & IOMUX_WIDTH_4BIT) ? 8 : 4;
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001771 if (iom->type & IOMUX_SOURCE_PMU)
1772 pmu_offs += inc;
1773 else
1774 grf_offs += inc;
Heiko Stübner6bc0d122014-06-16 01:36:33 +02001775
1776 bank_pins += 8;
1777 }
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001778 }
1779
1780 return ctrl;
1781}
1782
1783static int rockchip_pinctrl_probe(struct platform_device *pdev)
1784{
1785 struct rockchip_pinctrl *info;
1786 struct device *dev = &pdev->dev;
1787 struct rockchip_pin_ctrl *ctrl;
Heiko Stübner14dee862014-05-05 13:59:09 +02001788 struct device_node *np = pdev->dev.of_node, *node;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001789 struct resource *res;
Heiko Stübner751a99a2014-05-05 13:58:20 +02001790 void __iomem *base;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001791 int ret;
1792
1793 if (!dev->of_node) {
1794 dev_err(dev, "device tree node not found\n");
1795 return -ENODEV;
1796 }
1797
1798 info = devm_kzalloc(dev, sizeof(struct rockchip_pinctrl), GFP_KERNEL);
1799 if (!info)
1800 return -ENOMEM;
1801
Heiko Stübner622f3232014-05-05 13:58:46 +02001802 info->dev = dev;
1803
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001804 ctrl = rockchip_pinctrl_get_soc_data(info, pdev);
1805 if (!ctrl) {
1806 dev_err(dev, "driver data not available\n");
1807 return -EINVAL;
1808 }
1809 info->ctrl = ctrl;
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001810
Heiko Stübner1e747e52014-05-05 13:59:51 +02001811 node = of_parse_phandle(np, "rockchip,grf", 0);
1812 if (node) {
1813 info->regmap_base = syscon_node_to_regmap(node);
1814 if (IS_ERR(info->regmap_base))
1815 return PTR_ERR(info->regmap_base);
1816 } else {
1817 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Heiko Stübner751a99a2014-05-05 13:58:20 +02001818 base = devm_ioremap_resource(&pdev->dev, res);
1819 if (IS_ERR(base))
1820 return PTR_ERR(base);
1821
1822 rockchip_regmap_config.max_register = resource_size(res) - 4;
Heiko Stübner1e747e52014-05-05 13:59:51 +02001823 rockchip_regmap_config.name = "rockchip,pinctrl";
1824 info->regmap_base = devm_regmap_init_mmio(&pdev->dev, base,
1825 &rockchip_regmap_config);
1826
1827 /* to check for the old dt-bindings */
1828 info->reg_size = resource_size(res);
1829
1830 /* Honor the old binding, with pull registers as 2nd resource */
1831 if (ctrl->type == RK3188 && info->reg_size < 0x200) {
1832 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1833 base = devm_ioremap_resource(&pdev->dev, res);
1834 if (IS_ERR(base))
1835 return PTR_ERR(base);
1836
1837 rockchip_regmap_config.max_register =
1838 resource_size(res) - 4;
1839 rockchip_regmap_config.name = "rockchip,pinctrl-pull";
1840 info->regmap_pull = devm_regmap_init_mmio(&pdev->dev,
1841 base,
1842 &rockchip_regmap_config);
1843 }
Heiko Stübner6ca52742013-10-16 01:08:42 +02001844 }
1845
Heiko Stübner14dee862014-05-05 13:59:09 +02001846 /* try to find the optional reference to the pmu syscon */
1847 node = of_parse_phandle(np, "rockchip,pmu", 0);
1848 if (node) {
1849 info->regmap_pmu = syscon_node_to_regmap(node);
1850 if (IS_ERR(info->regmap_pmu))
1851 return PTR_ERR(info->regmap_pmu);
1852 }
1853
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001854 ret = rockchip_gpiolib_register(pdev, info);
1855 if (ret)
1856 return ret;
1857
1858 ret = rockchip_pinctrl_register(pdev, info);
1859 if (ret) {
1860 rockchip_gpiolib_unregister(pdev, info);
1861 return ret;
1862 }
1863
1864 platform_set_drvdata(pdev, info);
1865
1866 return 0;
1867}
1868
1869static struct rockchip_pin_bank rk2928_pin_banks[] = {
1870 PIN_BANK(0, 32, "gpio0"),
1871 PIN_BANK(1, 32, "gpio1"),
1872 PIN_BANK(2, 32, "gpio2"),
1873 PIN_BANK(3, 32, "gpio3"),
1874};
1875
1876static struct rockchip_pin_ctrl rk2928_pin_ctrl = {
1877 .pin_banks = rk2928_pin_banks,
1878 .nr_banks = ARRAY_SIZE(rk2928_pin_banks),
1879 .label = "RK2928-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02001880 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001881 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02001882 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001883};
1884
1885static struct rockchip_pin_bank rk3066a_pin_banks[] = {
1886 PIN_BANK(0, 32, "gpio0"),
1887 PIN_BANK(1, 32, "gpio1"),
1888 PIN_BANK(2, 32, "gpio2"),
1889 PIN_BANK(3, 32, "gpio3"),
1890 PIN_BANK(4, 32, "gpio4"),
1891 PIN_BANK(6, 16, "gpio6"),
1892};
1893
1894static struct rockchip_pin_ctrl rk3066a_pin_ctrl = {
1895 .pin_banks = rk3066a_pin_banks,
1896 .nr_banks = ARRAY_SIZE(rk3066a_pin_banks),
1897 .label = "RK3066a-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02001898 .type = RK2928,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001899 .grf_mux_offset = 0xa8,
Heiko Stübnera2829262013-10-16 01:07:20 +02001900 .pull_calc_reg = rk2928_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001901};
1902
1903static struct rockchip_pin_bank rk3066b_pin_banks[] = {
1904 PIN_BANK(0, 32, "gpio0"),
1905 PIN_BANK(1, 32, "gpio1"),
1906 PIN_BANK(2, 32, "gpio2"),
1907 PIN_BANK(3, 32, "gpio3"),
1908};
1909
1910static struct rockchip_pin_ctrl rk3066b_pin_ctrl = {
1911 .pin_banks = rk3066b_pin_banks,
1912 .nr_banks = ARRAY_SIZE(rk3066b_pin_banks),
1913 .label = "RK3066b-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02001914 .type = RK3066B,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001915 .grf_mux_offset = 0x60,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001916};
1917
1918static struct rockchip_pin_bank rk3188_pin_banks[] = {
Heiko Stübnerfc72c922014-06-16 01:36:05 +02001919 PIN_BANK_IOMUX_FLAGS(0, 32, "gpio0", IOMUX_GPIO_ONLY, 0, 0, 0),
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001920 PIN_BANK(1, 32, "gpio1"),
1921 PIN_BANK(2, 32, "gpio2"),
1922 PIN_BANK(3, 32, "gpio3"),
1923};
1924
1925static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
1926 .pin_banks = rk3188_pin_banks,
1927 .nr_banks = ARRAY_SIZE(rk3188_pin_banks),
1928 .label = "RK3188-GPIO",
Heiko Stübnera2829262013-10-16 01:07:20 +02001929 .type = RK3188,
Heiko Stübner95ec8ae2014-06-16 01:37:23 +02001930 .grf_mux_offset = 0x60,
Heiko Stübner6ca52742013-10-16 01:08:42 +02001931 .pull_calc_reg = rk3188_calc_pull_reg_and_bit,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001932};
1933
Heiko Stübner304f0772014-06-16 01:38:14 +02001934static struct rockchip_pin_bank rk3288_pin_banks[] = {
1935 PIN_BANK_IOMUX_FLAGS(0, 24, "gpio0", IOMUX_SOURCE_PMU,
1936 IOMUX_SOURCE_PMU,
1937 IOMUX_SOURCE_PMU,
1938 IOMUX_UNROUTED
1939 ),
1940 PIN_BANK_IOMUX_FLAGS(1, 32, "gpio1", IOMUX_UNROUTED,
1941 IOMUX_UNROUTED,
1942 IOMUX_UNROUTED,
1943 0
1944 ),
1945 PIN_BANK_IOMUX_FLAGS(2, 32, "gpio2", 0, 0, 0, IOMUX_UNROUTED),
1946 PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, IOMUX_WIDTH_4BIT),
1947 PIN_BANK_IOMUX_FLAGS(4, 32, "gpio4", IOMUX_WIDTH_4BIT,
1948 IOMUX_WIDTH_4BIT,
1949 0,
1950 0
1951 ),
1952 PIN_BANK_IOMUX_FLAGS(5, 32, "gpio5", IOMUX_UNROUTED,
1953 0,
1954 0,
1955 IOMUX_UNROUTED
1956 ),
1957 PIN_BANK_IOMUX_FLAGS(6, 32, "gpio6", 0, 0, 0, IOMUX_UNROUTED),
1958 PIN_BANK_IOMUX_FLAGS(7, 32, "gpio7", 0,
1959 0,
1960 IOMUX_WIDTH_4BIT,
1961 IOMUX_UNROUTED
1962 ),
1963 PIN_BANK(8, 16, "gpio8"),
1964};
1965
1966static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
1967 .pin_banks = rk3288_pin_banks,
1968 .nr_banks = ARRAY_SIZE(rk3288_pin_banks),
1969 .label = "RK3288-GPIO",
Heiko Stübner66d750e2014-07-20 01:49:17 +02001970 .type = RK3288,
Heiko Stübner304f0772014-06-16 01:38:14 +02001971 .grf_mux_offset = 0x0,
1972 .pmu_mux_offset = 0x84,
1973 .pull_calc_reg = rk3288_calc_pull_reg_and_bit,
1974};
1975
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001976static const struct of_device_id rockchip_pinctrl_dt_match[] = {
1977 { .compatible = "rockchip,rk2928-pinctrl",
1978 .data = (void *)&rk2928_pin_ctrl },
1979 { .compatible = "rockchip,rk3066a-pinctrl",
1980 .data = (void *)&rk3066a_pin_ctrl },
1981 { .compatible = "rockchip,rk3066b-pinctrl",
1982 .data = (void *)&rk3066b_pin_ctrl },
1983 { .compatible = "rockchip,rk3188-pinctrl",
1984 .data = (void *)&rk3188_pin_ctrl },
Heiko Stübner304f0772014-06-16 01:38:14 +02001985 { .compatible = "rockchip,rk3288-pinctrl",
1986 .data = (void *)&rk3288_pin_ctrl },
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001987 {},
1988};
1989MODULE_DEVICE_TABLE(of, rockchip_pinctrl_dt_match);
1990
1991static struct platform_driver rockchip_pinctrl_driver = {
1992 .probe = rockchip_pinctrl_probe,
1993 .driver = {
1994 .name = "rockchip-pinctrl",
1995 .owner = THIS_MODULE,
Axel Lin0be9e702013-08-23 14:27:53 +08001996 .of_match_table = rockchip_pinctrl_dt_match,
Heiko Stübnerd3e51162013-06-10 22:16:22 +02001997 },
1998};
1999
2000static int __init rockchip_pinctrl_drv_register(void)
2001{
2002 return platform_driver_register(&rockchip_pinctrl_driver);
2003}
2004postcore_initcall(rockchip_pinctrl_drv_register);
2005
2006MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
2007MODULE_DESCRIPTION("Rockchip pinctrl driver");
2008MODULE_LICENSE("GPL v2");