2 * Pinctrl driver for Rockchip SoCs
4 * Copyright (c) 2013 MundoReader S.L.
5 * Author: Heiko Stuebner <heiko@sntech.de>
7 * With some ideas taken from pinctrl-samsung:
8 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
9 * http://www.samsung.com
10 * Copyright (c) 2012 Linaro Ltd
11 * http://www.linaro.org
14 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
29 #include <linux/bitops.h>
30 #include <linux/gpio.h>
31 #include <linux/of_address.h>
32 #include <linux/of_irq.h>
33 #include <linux/pinctrl/machine.h>
34 #include <linux/pinctrl/pinconf.h>
35 #include <linux/pinctrl/pinctrl.h>
36 #include <linux/pinctrl/pinmux.h>
37 #include <linux/pinctrl/pinconf-generic.h>
38 #include <linux/irqchip/chained_irq.h>
39 #include <linux/clk.h>
40 #include <linux/regmap.h>
41 #include <linux/mfd/syscon.h>
42 #include <dt-bindings/pinctrl/rockchip.h>
47 /* GPIO control registers */
48 #define GPIO_SWPORT_DR 0x00
49 #define GPIO_SWPORT_DDR 0x04
50 #define GPIO_INTEN 0x30
51 #define GPIO_INTMASK 0x34
52 #define GPIO_INTTYPE_LEVEL 0x38
53 #define GPIO_INT_POLARITY 0x3c
54 #define GPIO_INT_STATUS 0x40
55 #define GPIO_INT_RAWSTATUS 0x44
56 #define GPIO_DEBOUNCE 0x48
57 #define GPIO_PORTS_EOI 0x4c
58 #define GPIO_EXT_PORT 0x50
59 #define GPIO_LS_SYNC 0x60
61 enum rockchip_pinctrl_type
{
67 enum rockchip_pin_bank_type
{
73 * @reg_base: register base of the gpio bank
74 * @reg_pull: optional separate register for additional pull settings
75 * @clk: clock of the gpio bank
76 * @irq: interrupt of the gpio bank
77 * @pin_base: first pin number
78 * @nr_pins: number of pins in this bank
79 * @name: name of the bank
80 * @bank_num: number of the bank, to account for holes
81 * @valid: are all necessary informations present
82 * @of_node: dt node of this bank
83 * @drvdata: common pinctrl basedata
84 * @domain: irqdomain of the gpio bank
85 * @gpio_chip: gpiolib chip
87 * @slock: spinlock for the gpio bank
89 struct rockchip_pin_bank
{
90 void __iomem
*reg_base
;
91 struct regmap
*regmap_pull
;
98 enum rockchip_pin_bank_type bank_type
;
100 struct device_node
*of_node
;
101 struct rockchip_pinctrl
*drvdata
;
102 struct irq_domain
*domain
;
103 struct gpio_chip gpio_chip
;
104 struct pinctrl_gpio_range grange
;
106 u32 toggle_edge_mode
;
109 #define PIN_BANK(id, pins, label) \
118 struct rockchip_pin_ctrl
{
119 struct rockchip_pin_bank
*pin_banks
;
123 enum rockchip_pinctrl_type type
;
125 void (*pull_calc_reg
)(struct rockchip_pin_bank
*bank
,
126 int pin_num
, struct regmap
**regmap
,
130 struct rockchip_pin_config
{
132 unsigned long *configs
;
133 unsigned int nconfigs
;
137 * struct rockchip_pin_group: represent group of pins of a pinmux function.
138 * @name: name of the pin group, used to lookup the group.
139 * @pins: the pins included in this group.
140 * @npins: number of pins included in this group.
141 * @func: the mux function number to be programmed when selected.
142 * @configs: the config values to be set for each pin
143 * @nconfigs: number of configs for each pin
145 struct rockchip_pin_group
{
149 struct rockchip_pin_config
*data
;
153 * struct rockchip_pmx_func: represent a pin function.
154 * @name: name of the pin function, used to lookup the function.
155 * @groups: one or more names of pin groups that provide this function.
156 * @num_groups: number of groups included in @groups.
158 struct rockchip_pmx_func
{
164 struct rockchip_pinctrl
{
165 struct regmap
*regmap_base
;
167 struct regmap
*regmap_pull
;
168 struct regmap
*regmap_pmu
;
170 struct rockchip_pin_ctrl
*ctrl
;
171 struct pinctrl_desc pctl
;
172 struct pinctrl_dev
*pctl_dev
;
173 struct rockchip_pin_group
*groups
;
174 unsigned int ngroups
;
175 struct rockchip_pmx_func
*functions
;
176 unsigned int nfunctions
;
179 static struct regmap_config rockchip_regmap_config
= {
185 static inline struct rockchip_pin_bank
*gc_to_pin_bank(struct gpio_chip
*gc
)
187 return container_of(gc
, struct rockchip_pin_bank
, gpio_chip
);
190 static const inline struct rockchip_pin_group
*pinctrl_name_to_group(
191 const struct rockchip_pinctrl
*info
,
196 for (i
= 0; i
< info
->ngroups
; i
++) {
197 if (!strcmp(info
->groups
[i
].name
, name
))
198 return &info
->groups
[i
];
205 * given a pin number that is local to a pin controller, find out the pin bank
206 * and the register base of the pin bank.
208 static struct rockchip_pin_bank
*pin_to_bank(struct rockchip_pinctrl
*info
,
211 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
213 while (pin
>= (b
->pin_base
+ b
->nr_pins
))
219 static struct rockchip_pin_bank
*bank_num_to_bank(
220 struct rockchip_pinctrl
*info
,
223 struct rockchip_pin_bank
*b
= info
->ctrl
->pin_banks
;
226 for (i
= 0; i
< info
->ctrl
->nr_banks
; i
++, b
++) {
227 if (b
->bank_num
== num
)
231 return ERR_PTR(-EINVAL
);
235 * Pinctrl_ops handling
238 static int rockchip_get_groups_count(struct pinctrl_dev
*pctldev
)
240 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
242 return info
->ngroups
;
245 static const char *rockchip_get_group_name(struct pinctrl_dev
*pctldev
,
248 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
250 return info
->groups
[selector
].name
;
253 static int rockchip_get_group_pins(struct pinctrl_dev
*pctldev
,
254 unsigned selector
, const unsigned **pins
,
257 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
259 if (selector
>= info
->ngroups
)
262 *pins
= info
->groups
[selector
].pins
;
263 *npins
= info
->groups
[selector
].npins
;
268 static int rockchip_dt_node_to_map(struct pinctrl_dev
*pctldev
,
269 struct device_node
*np
,
270 struct pinctrl_map
**map
, unsigned *num_maps
)
272 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
273 const struct rockchip_pin_group
*grp
;
274 struct pinctrl_map
*new_map
;
275 struct device_node
*parent
;
280 * first find the group of this node and check if we need to create
281 * config maps for pins
283 grp
= pinctrl_name_to_group(info
, np
->name
);
285 dev_err(info
->dev
, "unable to find group for node %s\n",
290 map_num
+= grp
->npins
;
291 new_map
= devm_kzalloc(pctldev
->dev
, sizeof(*new_map
) * map_num
,
300 parent
= of_get_parent(np
);
302 devm_kfree(pctldev
->dev
, new_map
);
305 new_map
[0].type
= PIN_MAP_TYPE_MUX_GROUP
;
306 new_map
[0].data
.mux
.function
= parent
->name
;
307 new_map
[0].data
.mux
.group
= np
->name
;
310 /* create config map */
312 for (i
= 0; i
< grp
->npins
; i
++) {
313 new_map
[i
].type
= PIN_MAP_TYPE_CONFIGS_PIN
;
314 new_map
[i
].data
.configs
.group_or_pin
=
315 pin_get_name(pctldev
, grp
->pins
[i
]);
316 new_map
[i
].data
.configs
.configs
= grp
->data
[i
].configs
;
317 new_map
[i
].data
.configs
.num_configs
= grp
->data
[i
].nconfigs
;
320 dev_dbg(pctldev
->dev
, "maps: function %s group %s num %d\n",
321 (*map
)->data
.mux
.function
, (*map
)->data
.mux
.group
, map_num
);
326 static void rockchip_dt_free_map(struct pinctrl_dev
*pctldev
,
327 struct pinctrl_map
*map
, unsigned num_maps
)
331 static const struct pinctrl_ops rockchip_pctrl_ops
= {
332 .get_groups_count
= rockchip_get_groups_count
,
333 .get_group_name
= rockchip_get_group_name
,
334 .get_group_pins
= rockchip_get_group_pins
,
335 .dt_node_to_map
= rockchip_dt_node_to_map
,
336 .dt_free_map
= rockchip_dt_free_map
,
343 static int rockchip_get_mux(struct rockchip_pin_bank
*bank
, int pin
)
345 struct rockchip_pinctrl
*info
= bank
->drvdata
;
350 if (bank
->bank_type
== RK3188_BANK0
&& pin
< 16)
353 /* get basic quadrupel of mux registers and the correct reg inside */
354 reg
= info
->ctrl
->mux_offset
;
355 reg
+= bank
->bank_num
* 0x10;
356 reg
+= (pin
/ 8) * 4;
359 ret
= regmap_read(info
->regmap_base
, reg
, &val
);
363 return ((val
>> bit
) & 3);
367 * Set a new mux function for a pin.
369 * The register is divided into the upper and lower 16 bit. When changing
370 * a value, the previous register value is not read and changed. Instead
371 * it seems the changed bits are marked in the upper 16 bit, while the
372 * changed value gets set in the same offset in the lower 16 bit.
373 * All pin settings seem to be 2 bit wide in both the upper and lower
375 * @bank: pin bank to change
376 * @pin: pin to change
377 * @mux: new mux function to set
379 static int rockchip_set_mux(struct rockchip_pin_bank
*bank
, int pin
, int mux
)
381 struct rockchip_pinctrl
*info
= bank
->drvdata
;
388 * The first 16 pins of rk3188_bank0 are always gpios and do not have
389 * a mux register at all.
391 if (bank
->bank_type
== RK3188_BANK0
&& pin
< 16) {
392 if (mux
!= RK_FUNC_GPIO
) {
394 "pin %d only supports a gpio mux\n", pin
);
401 dev_dbg(info
->dev
, "setting mux of GPIO%d-%d to %d\n",
402 bank
->bank_num
, pin
, mux
);
404 /* get basic quadrupel of mux registers and the correct reg inside */
405 reg
= info
->ctrl
->mux_offset
;
406 reg
+= bank
->bank_num
* 0x10;
407 reg
+= (pin
/ 8) * 4;
410 spin_lock_irqsave(&bank
->slock
, flags
);
412 data
= (3 << (bit
+ 16));
413 data
|= (mux
& 3) << bit
;
414 ret
= regmap_write(info
->regmap_base
, reg
, data
);
416 spin_unlock_irqrestore(&bank
->slock
, flags
);
421 #define RK2928_PULL_OFFSET 0x118
422 #define RK2928_PULL_PINS_PER_REG 16
423 #define RK2928_PULL_BANK_STRIDE 8
425 static void rk2928_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
426 int pin_num
, struct regmap
**regmap
,
429 struct rockchip_pinctrl
*info
= bank
->drvdata
;
431 *regmap
= info
->regmap_base
;
432 *reg
= RK2928_PULL_OFFSET
;
433 *reg
+= bank
->bank_num
* RK2928_PULL_BANK_STRIDE
;
434 *reg
+= (pin_num
/ RK2928_PULL_PINS_PER_REG
) * 4;
436 *bit
= pin_num
% RK2928_PULL_PINS_PER_REG
;
439 #define RK3188_PULL_OFFSET 0x164
440 #define RK3188_PULL_BITS_PER_PIN 2
441 #define RK3188_PULL_PINS_PER_REG 8
442 #define RK3188_PULL_BANK_STRIDE 16
443 #define RK3188_PULL_PMU_OFFSET 0x64
445 static void rk3188_calc_pull_reg_and_bit(struct rockchip_pin_bank
*bank
,
446 int pin_num
, struct regmap
**regmap
,
449 struct rockchip_pinctrl
*info
= bank
->drvdata
;
451 /* The first 12 pins of the first bank are located elsewhere */
452 if (bank
->bank_type
== RK3188_BANK0
&& pin_num
< 12) {
453 *regmap
= info
->regmap_pmu
? info
->regmap_pmu
455 *reg
= info
->regmap_pmu
? RK3188_PULL_PMU_OFFSET
: 0;
456 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
457 *bit
= pin_num
% RK3188_PULL_PINS_PER_REG
;
458 *bit
*= RK3188_PULL_BITS_PER_PIN
;
460 *regmap
= info
->regmap_pull
? info
->regmap_pull
462 *reg
= info
->regmap_pull
? 0 : RK3188_PULL_OFFSET
;
464 /* correct the offset, as it is the 2nd pull register */
466 *reg
+= bank
->bank_num
* RK3188_PULL_BANK_STRIDE
;
467 *reg
+= ((pin_num
/ RK3188_PULL_PINS_PER_REG
) * 4);
470 * The bits in these registers have an inverse ordering
471 * with the lowest pin being in bits 15:14 and the highest
474 *bit
= 7 - (pin_num
% RK3188_PULL_PINS_PER_REG
);
475 *bit
*= RK3188_PULL_BITS_PER_PIN
;
479 static int rockchip_get_pull(struct rockchip_pin_bank
*bank
, int pin_num
)
481 struct rockchip_pinctrl
*info
= bank
->drvdata
;
482 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
483 struct regmap
*regmap
;
488 /* rk3066b does support any pulls */
489 if (ctrl
->type
== RK3066B
)
490 return PIN_CONFIG_BIAS_DISABLE
;
492 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
494 ret
= regmap_read(regmap
, reg
, &data
);
498 switch (ctrl
->type
) {
500 return !(data
& BIT(bit
))
501 ? PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
502 : PIN_CONFIG_BIAS_DISABLE
;
505 data
&= (1 << RK3188_PULL_BITS_PER_PIN
) - 1;
509 return PIN_CONFIG_BIAS_DISABLE
;
511 return PIN_CONFIG_BIAS_PULL_UP
;
513 return PIN_CONFIG_BIAS_PULL_DOWN
;
515 return PIN_CONFIG_BIAS_BUS_HOLD
;
518 dev_err(info
->dev
, "unknown pull setting\n");
521 dev_err(info
->dev
, "unsupported pinctrl type\n");
526 static int rockchip_set_pull(struct rockchip_pin_bank
*bank
,
527 int pin_num
, int pull
)
529 struct rockchip_pinctrl
*info
= bank
->drvdata
;
530 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
531 struct regmap
*regmap
;
537 dev_dbg(info
->dev
, "setting pull of GPIO%d-%d to %d\n",
538 bank
->bank_num
, pin_num
, pull
);
540 /* rk3066b does support any pulls */
541 if (ctrl
->type
== RK3066B
)
542 return pull
? -EINVAL
: 0;
544 ctrl
->pull_calc_reg(bank
, pin_num
, ®map
, ®
, &bit
);
546 switch (ctrl
->type
) {
548 spin_lock_irqsave(&bank
->slock
, flags
);
550 data
= BIT(bit
+ 16);
551 if (pull
== PIN_CONFIG_BIAS_DISABLE
)
553 ret
= regmap_write(regmap
, reg
, data
);
555 spin_unlock_irqrestore(&bank
->slock
, flags
);
558 spin_lock_irqsave(&bank
->slock
, flags
);
560 /* enable the write to the equivalent lower bits */
561 data
= ((1 << RK3188_PULL_BITS_PER_PIN
) - 1) << (bit
+ 16);
564 case PIN_CONFIG_BIAS_DISABLE
:
566 case PIN_CONFIG_BIAS_PULL_UP
:
569 case PIN_CONFIG_BIAS_PULL_DOWN
:
572 case PIN_CONFIG_BIAS_BUS_HOLD
:
576 spin_unlock_irqrestore(&bank
->slock
, flags
);
577 dev_err(info
->dev
, "unsupported pull setting %d\n",
582 ret
= regmap_write(regmap
, reg
, data
);
584 spin_unlock_irqrestore(&bank
->slock
, flags
);
587 dev_err(info
->dev
, "unsupported pinctrl type\n");
595 * Pinmux_ops handling
598 static int rockchip_pmx_get_funcs_count(struct pinctrl_dev
*pctldev
)
600 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
602 return info
->nfunctions
;
605 static const char *rockchip_pmx_get_func_name(struct pinctrl_dev
*pctldev
,
608 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
610 return info
->functions
[selector
].name
;
613 static int rockchip_pmx_get_groups(struct pinctrl_dev
*pctldev
,
614 unsigned selector
, const char * const **groups
,
615 unsigned * const num_groups
)
617 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
619 *groups
= info
->functions
[selector
].groups
;
620 *num_groups
= info
->functions
[selector
].ngroups
;
625 static int rockchip_pmx_enable(struct pinctrl_dev
*pctldev
, unsigned selector
,
628 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
629 const unsigned int *pins
= info
->groups
[group
].pins
;
630 const struct rockchip_pin_config
*data
= info
->groups
[group
].data
;
631 struct rockchip_pin_bank
*bank
;
634 dev_dbg(info
->dev
, "enable function %s group %s\n",
635 info
->functions
[selector
].name
, info
->groups
[group
].name
);
638 * for each pin in the pin group selected, program the correspoding pin
639 * pin function number in the config register.
641 for (cnt
= 0; cnt
< info
->groups
[group
].npins
; cnt
++) {
642 bank
= pin_to_bank(info
, pins
[cnt
]);
643 ret
= rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
,
650 /* revert the already done pin settings */
651 for (cnt
--; cnt
>= 0; cnt
--)
652 rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
, 0);
660 static void rockchip_pmx_disable(struct pinctrl_dev
*pctldev
,
661 unsigned selector
, unsigned group
)
663 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
664 const unsigned int *pins
= info
->groups
[group
].pins
;
665 struct rockchip_pin_bank
*bank
;
668 dev_dbg(info
->dev
, "disable function %s group %s\n",
669 info
->functions
[selector
].name
, info
->groups
[group
].name
);
671 for (cnt
= 0; cnt
< info
->groups
[group
].npins
; cnt
++) {
672 bank
= pin_to_bank(info
, pins
[cnt
]);
673 rockchip_set_mux(bank
, pins
[cnt
] - bank
->pin_base
, 0);
678 * The calls to gpio_direction_output() and gpio_direction_input()
679 * leads to this function call (via the pinctrl_gpio_direction_{input|output}()
680 * function called from the gpiolib interface).
682 static int rockchip_pmx_gpio_set_direction(struct pinctrl_dev
*pctldev
,
683 struct pinctrl_gpio_range
*range
,
684 unsigned offset
, bool input
)
686 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
687 struct rockchip_pin_bank
*bank
;
688 struct gpio_chip
*chip
;
693 bank
= gc_to_pin_bank(chip
);
694 pin
= offset
- chip
->base
;
696 dev_dbg(info
->dev
, "gpio_direction for pin %u as %s-%d to %s\n",
697 offset
, range
->name
, pin
, input
? "input" : "output");
699 ret
= rockchip_set_mux(bank
, pin
, RK_FUNC_GPIO
);
703 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
704 /* set bit to 1 for output, 0 for input */
709 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
714 static const struct pinmux_ops rockchip_pmx_ops
= {
715 .get_functions_count
= rockchip_pmx_get_funcs_count
,
716 .get_function_name
= rockchip_pmx_get_func_name
,
717 .get_function_groups
= rockchip_pmx_get_groups
,
718 .enable
= rockchip_pmx_enable
,
719 .disable
= rockchip_pmx_disable
,
720 .gpio_set_direction
= rockchip_pmx_gpio_set_direction
,
724 * Pinconf_ops handling
727 static bool rockchip_pinconf_pull_valid(struct rockchip_pin_ctrl
*ctrl
,
728 enum pin_config_param pull
)
730 switch (ctrl
->type
) {
732 return (pull
== PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
||
733 pull
== PIN_CONFIG_BIAS_DISABLE
);
735 return pull
? false : true;
737 return (pull
!= PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
);
743 static int rockchip_gpio_direction_output(struct gpio_chip
*gc
,
744 unsigned offset
, int value
);
745 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
);
747 /* set the pin config settings for a specified pin */
748 static int rockchip_pinconf_set(struct pinctrl_dev
*pctldev
, unsigned int pin
,
749 unsigned long *configs
, unsigned num_configs
)
751 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
752 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
753 enum pin_config_param param
;
758 for (i
= 0; i
< num_configs
; i
++) {
759 param
= pinconf_to_config_param(configs
[i
]);
760 arg
= pinconf_to_config_argument(configs
[i
]);
763 case PIN_CONFIG_BIAS_DISABLE
:
764 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
769 case PIN_CONFIG_BIAS_PULL_UP
:
770 case PIN_CONFIG_BIAS_PULL_DOWN
:
771 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
772 case PIN_CONFIG_BIAS_BUS_HOLD
:
773 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
779 rc
= rockchip_set_pull(bank
, pin
- bank
->pin_base
,
784 case PIN_CONFIG_OUTPUT
:
785 rc
= rockchip_gpio_direction_output(&bank
->gpio_chip
,
786 pin
- bank
->pin_base
,
795 } /* for each config */
800 /* get the pin config settings for a specified pin */
801 static int rockchip_pinconf_get(struct pinctrl_dev
*pctldev
, unsigned int pin
,
802 unsigned long *config
)
804 struct rockchip_pinctrl
*info
= pinctrl_dev_get_drvdata(pctldev
);
805 struct rockchip_pin_bank
*bank
= pin_to_bank(info
, pin
);
806 enum pin_config_param param
= pinconf_to_config_param(*config
);
811 case PIN_CONFIG_BIAS_DISABLE
:
812 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
817 case PIN_CONFIG_BIAS_PULL_UP
:
818 case PIN_CONFIG_BIAS_PULL_DOWN
:
819 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT
:
820 case PIN_CONFIG_BIAS_BUS_HOLD
:
821 if (!rockchip_pinconf_pull_valid(info
->ctrl
, param
))
824 if (rockchip_get_pull(bank
, pin
- bank
->pin_base
) != param
)
829 case PIN_CONFIG_OUTPUT
:
830 rc
= rockchip_get_mux(bank
, pin
- bank
->pin_base
);
831 if (rc
!= RK_FUNC_GPIO
)
834 rc
= rockchip_gpio_get(&bank
->gpio_chip
, pin
- bank
->pin_base
);
845 *config
= pinconf_to_config_packed(param
, arg
);
850 static const struct pinconf_ops rockchip_pinconf_ops
= {
851 .pin_config_get
= rockchip_pinconf_get
,
852 .pin_config_set
= rockchip_pinconf_set
,
855 static const struct of_device_id rockchip_bank_match
[] = {
856 { .compatible
= "rockchip,gpio-bank" },
857 { .compatible
= "rockchip,rk3188-gpio-bank0" },
861 static void rockchip_pinctrl_child_count(struct rockchip_pinctrl
*info
,
862 struct device_node
*np
)
864 struct device_node
*child
;
866 for_each_child_of_node(np
, child
) {
867 if (of_match_node(rockchip_bank_match
, child
))
871 info
->ngroups
+= of_get_child_count(child
);
875 static int rockchip_pinctrl_parse_groups(struct device_node
*np
,
876 struct rockchip_pin_group
*grp
,
877 struct rockchip_pinctrl
*info
,
880 struct rockchip_pin_bank
*bank
;
887 dev_dbg(info
->dev
, "group(%d): %s\n", index
, np
->name
);
889 /* Initialise group */
890 grp
->name
= np
->name
;
893 * the binding format is rockchip,pins = <bank pin mux CONFIG>,
894 * do sanity check and calculate pins number
896 list
= of_get_property(np
, "rockchip,pins", &size
);
897 /* we do not check return since it's safe node passed down */
898 size
/= sizeof(*list
);
899 if (!size
|| size
% 4) {
900 dev_err(info
->dev
, "wrong pins number or pins and configs should be by 4\n");
904 grp
->npins
= size
/ 4;
906 grp
->pins
= devm_kzalloc(info
->dev
, grp
->npins
* sizeof(unsigned int),
908 grp
->data
= devm_kzalloc(info
->dev
, grp
->npins
*
909 sizeof(struct rockchip_pin_config
),
911 if (!grp
->pins
|| !grp
->data
)
914 for (i
= 0, j
= 0; i
< size
; i
+= 4, j
++) {
915 const __be32
*phandle
;
916 struct device_node
*np_config
;
918 num
= be32_to_cpu(*list
++);
919 bank
= bank_num_to_bank(info
, num
);
921 return PTR_ERR(bank
);
923 grp
->pins
[j
] = bank
->pin_base
+ be32_to_cpu(*list
++);
924 grp
->data
[j
].func
= be32_to_cpu(*list
++);
930 np_config
= of_find_node_by_phandle(be32_to_cpup(phandle
));
931 ret
= pinconf_generic_parse_dt_config(np_config
,
932 &grp
->data
[j
].configs
, &grp
->data
[j
].nconfigs
);
940 static int rockchip_pinctrl_parse_functions(struct device_node
*np
,
941 struct rockchip_pinctrl
*info
,
944 struct device_node
*child
;
945 struct rockchip_pmx_func
*func
;
946 struct rockchip_pin_group
*grp
;
948 static u32 grp_index
;
951 dev_dbg(info
->dev
, "parse function(%d): %s\n", index
, np
->name
);
953 func
= &info
->functions
[index
];
955 /* Initialise function */
956 func
->name
= np
->name
;
957 func
->ngroups
= of_get_child_count(np
);
958 if (func
->ngroups
<= 0)
961 func
->groups
= devm_kzalloc(info
->dev
,
962 func
->ngroups
* sizeof(char *), GFP_KERNEL
);
966 for_each_child_of_node(np
, child
) {
967 func
->groups
[i
] = child
->name
;
968 grp
= &info
->groups
[grp_index
++];
969 ret
= rockchip_pinctrl_parse_groups(child
, grp
, info
, i
++);
977 static int rockchip_pinctrl_parse_dt(struct platform_device
*pdev
,
978 struct rockchip_pinctrl
*info
)
980 struct device
*dev
= &pdev
->dev
;
981 struct device_node
*np
= dev
->of_node
;
982 struct device_node
*child
;
986 rockchip_pinctrl_child_count(info
, np
);
988 dev_dbg(&pdev
->dev
, "nfunctions = %d\n", info
->nfunctions
);
989 dev_dbg(&pdev
->dev
, "ngroups = %d\n", info
->ngroups
);
991 info
->functions
= devm_kzalloc(dev
, info
->nfunctions
*
992 sizeof(struct rockchip_pmx_func
),
994 if (!info
->functions
) {
995 dev_err(dev
, "failed to allocate memory for function list\n");
999 info
->groups
= devm_kzalloc(dev
, info
->ngroups
*
1000 sizeof(struct rockchip_pin_group
),
1002 if (!info
->groups
) {
1003 dev_err(dev
, "failed allocate memory for ping group list\n");
1009 for_each_child_of_node(np
, child
) {
1010 if (of_match_node(rockchip_bank_match
, child
))
1013 ret
= rockchip_pinctrl_parse_functions(child
, info
, i
++);
1015 dev_err(&pdev
->dev
, "failed to parse function\n");
1023 static int rockchip_pinctrl_register(struct platform_device
*pdev
,
1024 struct rockchip_pinctrl
*info
)
1026 struct pinctrl_desc
*ctrldesc
= &info
->pctl
;
1027 struct pinctrl_pin_desc
*pindesc
, *pdesc
;
1028 struct rockchip_pin_bank
*pin_bank
;
1032 ctrldesc
->name
= "rockchip-pinctrl";
1033 ctrldesc
->owner
= THIS_MODULE
;
1034 ctrldesc
->pctlops
= &rockchip_pctrl_ops
;
1035 ctrldesc
->pmxops
= &rockchip_pmx_ops
;
1036 ctrldesc
->confops
= &rockchip_pinconf_ops
;
1038 pindesc
= devm_kzalloc(&pdev
->dev
, sizeof(*pindesc
) *
1039 info
->ctrl
->nr_pins
, GFP_KERNEL
);
1041 dev_err(&pdev
->dev
, "mem alloc for pin descriptors failed\n");
1044 ctrldesc
->pins
= pindesc
;
1045 ctrldesc
->npins
= info
->ctrl
->nr_pins
;
1048 for (bank
= 0 , k
= 0; bank
< info
->ctrl
->nr_banks
; bank
++) {
1049 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
1050 for (pin
= 0; pin
< pin_bank
->nr_pins
; pin
++, k
++) {
1052 pdesc
->name
= kasprintf(GFP_KERNEL
, "%s-%d",
1053 pin_bank
->name
, pin
);
1058 info
->pctl_dev
= pinctrl_register(ctrldesc
, &pdev
->dev
, info
);
1059 if (!info
->pctl_dev
) {
1060 dev_err(&pdev
->dev
, "could not register pinctrl driver\n");
1064 for (bank
= 0; bank
< info
->ctrl
->nr_banks
; ++bank
) {
1065 pin_bank
= &info
->ctrl
->pin_banks
[bank
];
1066 pin_bank
->grange
.name
= pin_bank
->name
;
1067 pin_bank
->grange
.id
= bank
;
1068 pin_bank
->grange
.pin_base
= pin_bank
->pin_base
;
1069 pin_bank
->grange
.base
= pin_bank
->gpio_chip
.base
;
1070 pin_bank
->grange
.npins
= pin_bank
->gpio_chip
.ngpio
;
1071 pin_bank
->grange
.gc
= &pin_bank
->gpio_chip
;
1072 pinctrl_add_gpio_range(info
->pctl_dev
, &pin_bank
->grange
);
1075 ret
= rockchip_pinctrl_parse_dt(pdev
, info
);
1077 pinctrl_unregister(info
->pctl_dev
);
1088 static int rockchip_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
1090 return pinctrl_request_gpio(chip
->base
+ offset
);
1093 static void rockchip_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
1095 pinctrl_free_gpio(chip
->base
+ offset
);
1098 static void rockchip_gpio_set(struct gpio_chip
*gc
, unsigned offset
, int value
)
1100 struct rockchip_pin_bank
*bank
= gc_to_pin_bank(gc
);
1101 void __iomem
*reg
= bank
->reg_base
+ GPIO_SWPORT_DR
;
1102 unsigned long flags
;
1105 spin_lock_irqsave(&bank
->slock
, flags
);
1108 data
&= ~BIT(offset
);
1110 data
|= BIT(offset
);
1113 spin_unlock_irqrestore(&bank
->slock
, flags
);
1117 * Returns the level of the pin for input direction and setting of the DR
1118 * register for output gpios.
1120 static int rockchip_gpio_get(struct gpio_chip
*gc
, unsigned offset
)
1122 struct rockchip_pin_bank
*bank
= gc_to_pin_bank(gc
);
1125 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
1132 * gpiolib gpio_direction_input callback function. The setting of the pin
1133 * mux function as 'gpio input' will be handled by the pinctrl susbsystem
1136 static int rockchip_gpio_direction_input(struct gpio_chip
*gc
, unsigned offset
)
1138 return pinctrl_gpio_direction_input(gc
->base
+ offset
);
1142 * gpiolib gpio_direction_output callback function. The setting of the pin
1143 * mux function as 'gpio output' will be handled by the pinctrl susbsystem
1146 static int rockchip_gpio_direction_output(struct gpio_chip
*gc
,
1147 unsigned offset
, int value
)
1149 rockchip_gpio_set(gc
, offset
, value
);
1150 return pinctrl_gpio_direction_output(gc
->base
+ offset
);
1154 * gpiolib gpio_to_irq callback function. Creates a mapping between a GPIO pin
1155 * and a virtual IRQ, if not already present.
1157 static int rockchip_gpio_to_irq(struct gpio_chip
*gc
, unsigned offset
)
1159 struct rockchip_pin_bank
*bank
= gc_to_pin_bank(gc
);
1165 virq
= irq_create_mapping(bank
->domain
, offset
);
1167 return (virq
) ? : -ENXIO
;
1170 static const struct gpio_chip rockchip_gpiolib_chip
= {
1171 .request
= rockchip_gpio_request
,
1172 .free
= rockchip_gpio_free
,
1173 .set
= rockchip_gpio_set
,
1174 .get
= rockchip_gpio_get
,
1175 .direction_input
= rockchip_gpio_direction_input
,
1176 .direction_output
= rockchip_gpio_direction_output
,
1177 .to_irq
= rockchip_gpio_to_irq
,
1178 .owner
= THIS_MODULE
,
1182 * Interrupt handling
1185 static void rockchip_irq_demux(unsigned int irq
, struct irq_desc
*desc
)
1187 struct irq_chip
*chip
= irq_get_chip(irq
);
1188 struct rockchip_pin_bank
*bank
= irq_get_handler_data(irq
);
1189 u32 polarity
= 0, data
= 0;
1191 bool edge_changed
= false;
1193 dev_dbg(bank
->drvdata
->dev
, "got irq for bank %s\n", bank
->name
);
1195 chained_irq_enter(chip
, desc
);
1197 pend
= readl_relaxed(bank
->reg_base
+ GPIO_INT_STATUS
);
1199 if (bank
->toggle_edge_mode
) {
1200 polarity
= readl_relaxed(bank
->reg_base
+
1202 data
= readl_relaxed(bank
->reg_base
+ GPIO_EXT_PORT
);
1210 virq
= irq_linear_revmap(bank
->domain
, irq
);
1213 dev_err(bank
->drvdata
->dev
, "unmapped irq %d\n", irq
);
1217 dev_dbg(bank
->drvdata
->dev
, "handling irq %d\n", irq
);
1220 * Triggering IRQ on both rising and falling edge
1221 * needs manual intervention.
1223 if (bank
->toggle_edge_mode
& BIT(irq
)) {
1224 if (data
& BIT(irq
))
1225 polarity
&= ~BIT(irq
);
1227 polarity
|= BIT(irq
);
1229 edge_changed
= true;
1232 generic_handle_irq(virq
);
1235 if (bank
->toggle_edge_mode
&& edge_changed
) {
1236 /* Interrupt params should only be set with ints disabled */
1237 data
= readl_relaxed(bank
->reg_base
+ GPIO_INTEN
);
1238 writel_relaxed(0, bank
->reg_base
+ GPIO_INTEN
);
1239 writel(polarity
, bank
->reg_base
+ GPIO_INT_POLARITY
);
1240 writel(data
, bank
->reg_base
+ GPIO_INTEN
);
1243 chained_irq_exit(chip
, desc
);
1246 static int rockchip_irq_set_type(struct irq_data
*d
, unsigned int type
)
1248 struct irq_chip_generic
*gc
= irq_data_get_irq_chip_data(d
);
1249 struct rockchip_pin_bank
*bank
= gc
->private;
1250 u32 mask
= BIT(d
->hwirq
);
1256 /* make sure the pin is configured as gpio input */
1257 ret
= rockchip_set_mux(bank
, d
->hwirq
, RK_FUNC_GPIO
);
1261 data
= readl_relaxed(bank
->reg_base
+ GPIO_SWPORT_DDR
);
1263 writel_relaxed(data
, bank
->reg_base
+ GPIO_SWPORT_DDR
);
1265 if (type
& IRQ_TYPE_EDGE_BOTH
)
1266 __irq_set_handler_locked(d
->irq
, handle_edge_irq
);
1268 __irq_set_handler_locked(d
->irq
, handle_level_irq
);
1272 level
= readl_relaxed(gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
1273 polarity
= readl_relaxed(gc
->reg_base
+ GPIO_INT_POLARITY
);
1276 case IRQ_TYPE_EDGE_BOTH
:
1277 bank
->toggle_edge_mode
|= mask
;
1281 * Determine gpio state. If 1 next interrupt should be falling
1284 data
= readl(bank
->reg_base
+ GPIO_EXT_PORT
);
1290 case IRQ_TYPE_EDGE_RISING
:
1291 bank
->toggle_edge_mode
&= ~mask
;
1295 case IRQ_TYPE_EDGE_FALLING
:
1296 bank
->toggle_edge_mode
&= ~mask
;
1300 case IRQ_TYPE_LEVEL_HIGH
:
1301 bank
->toggle_edge_mode
&= ~mask
;
1305 case IRQ_TYPE_LEVEL_LOW
:
1306 bank
->toggle_edge_mode
&= ~mask
;
1315 writel_relaxed(level
, gc
->reg_base
+ GPIO_INTTYPE_LEVEL
);
1316 writel_relaxed(polarity
, gc
->reg_base
+ GPIO_INT_POLARITY
);
1323 static int rockchip_interrupts_register(struct platform_device
*pdev
,
1324 struct rockchip_pinctrl
*info
)
1326 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1327 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
1328 unsigned int clr
= IRQ_NOREQUEST
| IRQ_NOPROBE
| IRQ_NOAUTOEN
;
1329 struct irq_chip_generic
*gc
;
1333 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
1335 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
1340 bank
->domain
= irq_domain_add_linear(bank
->of_node
, 32,
1341 &irq_generic_chip_ops
, NULL
);
1342 if (!bank
->domain
) {
1343 dev_warn(&pdev
->dev
, "could not initialize irq domain for bank %s\n",
1348 ret
= irq_alloc_domain_generic_chips(bank
->domain
, 32, 1,
1349 "rockchip_gpio_irq", handle_level_irq
,
1350 clr
, 0, IRQ_GC_INIT_MASK_CACHE
);
1352 dev_err(&pdev
->dev
, "could not alloc generic chips for bank %s\n",
1354 irq_domain_remove(bank
->domain
);
1358 gc
= irq_get_domain_generic_chip(bank
->domain
, 0);
1359 gc
->reg_base
= bank
->reg_base
;
1361 gc
->chip_types
[0].regs
.mask
= GPIO_INTEN
;
1362 gc
->chip_types
[0].regs
.ack
= GPIO_PORTS_EOI
;
1363 gc
->chip_types
[0].chip
.irq_ack
= irq_gc_ack_set_bit
;
1364 gc
->chip_types
[0].chip
.irq_mask
= irq_gc_mask_clr_bit
;
1365 gc
->chip_types
[0].chip
.irq_unmask
= irq_gc_mask_set_bit
;
1366 gc
->chip_types
[0].chip
.irq_set_wake
= irq_gc_set_wake
;
1367 gc
->chip_types
[0].chip
.irq_set_type
= rockchip_irq_set_type
;
1369 irq_set_handler_data(bank
->irq
, bank
);
1370 irq_set_chained_handler(bank
->irq
, rockchip_irq_demux
);
1376 static int rockchip_gpiolib_register(struct platform_device
*pdev
,
1377 struct rockchip_pinctrl
*info
)
1379 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1380 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
1381 struct gpio_chip
*gc
;
1385 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
1387 dev_warn(&pdev
->dev
, "bank %s is not valid\n",
1392 bank
->gpio_chip
= rockchip_gpiolib_chip
;
1394 gc
= &bank
->gpio_chip
;
1395 gc
->base
= bank
->pin_base
;
1396 gc
->ngpio
= bank
->nr_pins
;
1397 gc
->dev
= &pdev
->dev
;
1398 gc
->of_node
= bank
->of_node
;
1399 gc
->label
= bank
->name
;
1401 ret
= gpiochip_add(gc
);
1403 dev_err(&pdev
->dev
, "failed to register gpio_chip %s, error code: %d\n",
1409 rockchip_interrupts_register(pdev
, info
);
1414 for (--i
, --bank
; i
>= 0; --i
, --bank
) {
1418 if (gpiochip_remove(&bank
->gpio_chip
))
1419 dev_err(&pdev
->dev
, "gpio chip %s remove failed\n",
1420 bank
->gpio_chip
.label
);
1425 static int rockchip_gpiolib_unregister(struct platform_device
*pdev
,
1426 struct rockchip_pinctrl
*info
)
1428 struct rockchip_pin_ctrl
*ctrl
= info
->ctrl
;
1429 struct rockchip_pin_bank
*bank
= ctrl
->pin_banks
;
1433 for (i
= 0; !ret
&& i
< ctrl
->nr_banks
; ++i
, ++bank
) {
1437 ret
= gpiochip_remove(&bank
->gpio_chip
);
1441 dev_err(&pdev
->dev
, "gpio chip remove failed\n");
1446 static int rockchip_get_bank_data(struct rockchip_pin_bank
*bank
,
1447 struct rockchip_pinctrl
*info
)
1449 struct resource res
;
1452 if (of_address_to_resource(bank
->of_node
, 0, &res
)) {
1453 dev_err(info
->dev
, "cannot find IO resource for bank\n");
1457 bank
->reg_base
= devm_ioremap_resource(info
->dev
, &res
);
1458 if (IS_ERR(bank
->reg_base
))
1459 return PTR_ERR(bank
->reg_base
);
1462 * special case, where parts of the pull setting-registers are
1463 * part of the PMU register space
1465 if (of_device_is_compatible(bank
->of_node
,
1466 "rockchip,rk3188-gpio-bank0")) {
1467 struct device_node
*node
;
1469 bank
->bank_type
= RK3188_BANK0
;
1471 node
= of_parse_phandle(bank
->of_node
->parent
,
1474 if (of_address_to_resource(bank
->of_node
, 1, &res
)) {
1475 dev_err(info
->dev
, "cannot find IO resource for bank\n");
1479 base
= devm_ioremap_resource(info
->dev
, &res
);
1481 return PTR_ERR(base
);
1482 rockchip_regmap_config
.max_register
=
1483 resource_size(&res
) - 4;
1484 rockchip_regmap_config
.name
=
1485 "rockchip,rk3188-gpio-bank0-pull";
1486 bank
->regmap_pull
= devm_regmap_init_mmio(info
->dev
,
1488 &rockchip_regmap_config
);
1492 bank
->bank_type
= COMMON_BANK
;
1495 bank
->irq
= irq_of_parse_and_map(bank
->of_node
, 0);
1497 bank
->clk
= of_clk_get(bank
->of_node
, 0);
1498 if (IS_ERR(bank
->clk
))
1499 return PTR_ERR(bank
->clk
);
1501 return clk_prepare_enable(bank
->clk
);
1504 static const struct of_device_id rockchip_pinctrl_dt_match
[];
1506 /* retrieve the soc specific data */
1507 static struct rockchip_pin_ctrl
*rockchip_pinctrl_get_soc_data(
1508 struct rockchip_pinctrl
*d
,
1509 struct platform_device
*pdev
)
1511 const struct of_device_id
*match
;
1512 struct device_node
*node
= pdev
->dev
.of_node
;
1513 struct device_node
*np
;
1514 struct rockchip_pin_ctrl
*ctrl
;
1515 struct rockchip_pin_bank
*bank
;
1518 match
= of_match_node(rockchip_pinctrl_dt_match
, node
);
1519 ctrl
= (struct rockchip_pin_ctrl
*)match
->data
;
1521 for_each_child_of_node(node
, np
) {
1522 if (!of_find_property(np
, "gpio-controller", NULL
))
1525 bank
= ctrl
->pin_banks
;
1526 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
1527 if (!strcmp(bank
->name
, np
->name
)) {
1530 if (!rockchip_get_bank_data(bank
, d
))
1538 bank
= ctrl
->pin_banks
;
1539 for (i
= 0; i
< ctrl
->nr_banks
; ++i
, ++bank
) {
1540 spin_lock_init(&bank
->slock
);
1542 bank
->pin_base
= ctrl
->nr_pins
;
1543 ctrl
->nr_pins
+= bank
->nr_pins
;
1549 static int rockchip_pinctrl_probe(struct platform_device
*pdev
)
1551 struct rockchip_pinctrl
*info
;
1552 struct device
*dev
= &pdev
->dev
;
1553 struct rockchip_pin_ctrl
*ctrl
;
1554 struct device_node
*np
= pdev
->dev
.of_node
, *node
;
1555 struct resource
*res
;
1559 if (!dev
->of_node
) {
1560 dev_err(dev
, "device tree node not found\n");
1564 info
= devm_kzalloc(dev
, sizeof(struct rockchip_pinctrl
), GFP_KERNEL
);
1570 ctrl
= rockchip_pinctrl_get_soc_data(info
, pdev
);
1572 dev_err(dev
, "driver data not available\n");
1577 node
= of_parse_phandle(np
, "rockchip,grf", 0);
1579 info
->regmap_base
= syscon_node_to_regmap(node
);
1580 if (IS_ERR(info
->regmap_base
))
1581 return PTR_ERR(info
->regmap_base
);
1583 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1584 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1586 return PTR_ERR(base
);
1588 rockchip_regmap_config
.max_register
= resource_size(res
) - 4;
1589 rockchip_regmap_config
.name
= "rockchip,pinctrl";
1590 info
->regmap_base
= devm_regmap_init_mmio(&pdev
->dev
, base
,
1591 &rockchip_regmap_config
);
1593 /* to check for the old dt-bindings */
1594 info
->reg_size
= resource_size(res
);
1596 /* Honor the old binding, with pull registers as 2nd resource */
1597 if (ctrl
->type
== RK3188
&& info
->reg_size
< 0x200) {
1598 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1599 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1601 return PTR_ERR(base
);
1603 rockchip_regmap_config
.max_register
=
1604 resource_size(res
) - 4;
1605 rockchip_regmap_config
.name
= "rockchip,pinctrl-pull";
1606 info
->regmap_pull
= devm_regmap_init_mmio(&pdev
->dev
,
1608 &rockchip_regmap_config
);
1612 /* try to find the optional reference to the pmu syscon */
1613 node
= of_parse_phandle(np
, "rockchip,pmu", 0);
1615 info
->regmap_pmu
= syscon_node_to_regmap(node
);
1616 if (IS_ERR(info
->regmap_pmu
))
1617 return PTR_ERR(info
->regmap_pmu
);
1620 ret
= rockchip_gpiolib_register(pdev
, info
);
1624 ret
= rockchip_pinctrl_register(pdev
, info
);
1626 rockchip_gpiolib_unregister(pdev
, info
);
1630 platform_set_drvdata(pdev
, info
);
1635 static struct rockchip_pin_bank rk2928_pin_banks
[] = {
1636 PIN_BANK(0, 32, "gpio0"),
1637 PIN_BANK(1, 32, "gpio1"),
1638 PIN_BANK(2, 32, "gpio2"),
1639 PIN_BANK(3, 32, "gpio3"),
1642 static struct rockchip_pin_ctrl rk2928_pin_ctrl
= {
1643 .pin_banks
= rk2928_pin_banks
,
1644 .nr_banks
= ARRAY_SIZE(rk2928_pin_banks
),
1645 .label
= "RK2928-GPIO",
1648 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
1651 static struct rockchip_pin_bank rk3066a_pin_banks
[] = {
1652 PIN_BANK(0, 32, "gpio0"),
1653 PIN_BANK(1, 32, "gpio1"),
1654 PIN_BANK(2, 32, "gpio2"),
1655 PIN_BANK(3, 32, "gpio3"),
1656 PIN_BANK(4, 32, "gpio4"),
1657 PIN_BANK(6, 16, "gpio6"),
1660 static struct rockchip_pin_ctrl rk3066a_pin_ctrl
= {
1661 .pin_banks
= rk3066a_pin_banks
,
1662 .nr_banks
= ARRAY_SIZE(rk3066a_pin_banks
),
1663 .label
= "RK3066a-GPIO",
1666 .pull_calc_reg
= rk2928_calc_pull_reg_and_bit
,
1669 static struct rockchip_pin_bank rk3066b_pin_banks
[] = {
1670 PIN_BANK(0, 32, "gpio0"),
1671 PIN_BANK(1, 32, "gpio1"),
1672 PIN_BANK(2, 32, "gpio2"),
1673 PIN_BANK(3, 32, "gpio3"),
1676 static struct rockchip_pin_ctrl rk3066b_pin_ctrl
= {
1677 .pin_banks
= rk3066b_pin_banks
,
1678 .nr_banks
= ARRAY_SIZE(rk3066b_pin_banks
),
1679 .label
= "RK3066b-GPIO",
1684 static struct rockchip_pin_bank rk3188_pin_banks
[] = {
1685 PIN_BANK(0, 32, "gpio0"),
1686 PIN_BANK(1, 32, "gpio1"),
1687 PIN_BANK(2, 32, "gpio2"),
1688 PIN_BANK(3, 32, "gpio3"),
1691 static struct rockchip_pin_ctrl rk3188_pin_ctrl
= {
1692 .pin_banks
= rk3188_pin_banks
,
1693 .nr_banks
= ARRAY_SIZE(rk3188_pin_banks
),
1694 .label
= "RK3188-GPIO",
1697 .pull_calc_reg
= rk3188_calc_pull_reg_and_bit
,
1700 static const struct of_device_id rockchip_pinctrl_dt_match
[] = {
1701 { .compatible
= "rockchip,rk2928-pinctrl",
1702 .data
= (void *)&rk2928_pin_ctrl
},
1703 { .compatible
= "rockchip,rk3066a-pinctrl",
1704 .data
= (void *)&rk3066a_pin_ctrl
},
1705 { .compatible
= "rockchip,rk3066b-pinctrl",
1706 .data
= (void *)&rk3066b_pin_ctrl
},
1707 { .compatible
= "rockchip,rk3188-pinctrl",
1708 .data
= (void *)&rk3188_pin_ctrl
},
1711 MODULE_DEVICE_TABLE(of
, rockchip_pinctrl_dt_match
);
1713 static struct platform_driver rockchip_pinctrl_driver
= {
1714 .probe
= rockchip_pinctrl_probe
,
1716 .name
= "rockchip-pinctrl",
1717 .owner
= THIS_MODULE
,
1718 .of_match_table
= rockchip_pinctrl_dt_match
,
1722 static int __init
rockchip_pinctrl_drv_register(void)
1724 return platform_driver_register(&rockchip_pinctrl_driver
);
1726 postcore_initcall(rockchip_pinctrl_drv_register
);
1728 MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1729 MODULE_DESCRIPTION("Rockchip pinctrl driver");
1730 MODULE_LICENSE("GPL v2");