1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Allwinner A31 SoCs special pins pinctrl driver.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2014 Boris Brezillon
5*4882a593Smuzhiyun * Boris Brezillon <boris.brezillon@free-electrons.com>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (C) 2014 Maxime Ripard
8*4882a593Smuzhiyun * Maxime Ripard <maxime.ripard@free-electrons.com>
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * This file is licensed under the terms of the GNU General Public
11*4882a593Smuzhiyun * License version 2. This program is licensed "as is" without any
12*4882a593Smuzhiyun * warranty of any kind, whether express or implied.
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/init.h>
16*4882a593Smuzhiyun #include <linux/platform_device.h>
17*4882a593Smuzhiyun #include <linux/of.h>
18*4882a593Smuzhiyun #include <linux/of_device.h>
19*4882a593Smuzhiyun #include <linux/pinctrl/pinctrl.h>
20*4882a593Smuzhiyun #include <linux/reset.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #include "pinctrl-sunxi.h"
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun static const struct sunxi_desc_pin sun6i_a31_r_pins[] = {
25*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 0),
26*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
27*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
28*4882a593Smuzhiyun SUNXI_FUNCTION(0x2, "s_i2c"), /* SCK */
29*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_p2wi")), /* SCK */
30*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 1),
31*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
32*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
33*4882a593Smuzhiyun SUNXI_FUNCTION(0x2, "s_i2c"), /* SDA */
34*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_p2wi")), /* SDA */
35*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 2),
36*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
37*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
38*4882a593Smuzhiyun SUNXI_FUNCTION(0x2, "s_uart")), /* TX */
39*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 3),
40*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
41*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
42*4882a593Smuzhiyun SUNXI_FUNCTION(0x2, "s_uart")), /* RX */
43*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 4),
44*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
45*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
46*4882a593Smuzhiyun SUNXI_FUNCTION(0x2, "s_ir")), /* RX */
47*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 5),
48*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
49*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
50*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 0, 0), /* PL_EINT0 */
51*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_jtag")), /* MS */
52*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 6),
53*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
54*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
55*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 0, 1), /* PL_EINT1 */
56*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_jtag")), /* CK */
57*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 7),
58*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
59*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
60*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 0, 2), /* PL_EINT2 */
61*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_jtag")), /* DO */
62*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(L, 8),
63*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
64*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
65*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 0, 3), /* PL_EINT3 */
66*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "s_jtag")), /* DI */
67*4882a593Smuzhiyun /* Hole */
68*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 0),
69*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
70*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
71*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 0)), /* PM_EINT0 */
72*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 1),
73*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
74*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
75*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 1)), /* PM_EINT1 */
76*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 2),
77*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
78*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
79*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 2), /* PM_EINT2 */
80*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "1wire")),
81*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 3),
82*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
83*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
84*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 3)), /* PM_EINT3 */
85*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 4),
86*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
87*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
88*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 4)), /* PM_EINT4 */
89*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 5),
90*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
91*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
92*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 5)), /* PM_EINT5 */
93*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 6),
94*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
95*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
96*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 6)), /* PM_EINT6 */
97*4882a593Smuzhiyun SUNXI_PIN(SUNXI_PINCTRL_PIN(M, 7),
98*4882a593Smuzhiyun SUNXI_FUNCTION(0x0, "gpio_in"),
99*4882a593Smuzhiyun SUNXI_FUNCTION(0x1, "gpio_out"),
100*4882a593Smuzhiyun SUNXI_FUNCTION_IRQ_BANK(0x2, 1, 7), /* PM_EINT7 */
101*4882a593Smuzhiyun SUNXI_FUNCTION(0x3, "rtc")), /* CLKO */
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun static const struct sunxi_pinctrl_desc sun6i_a31_r_pinctrl_data = {
105*4882a593Smuzhiyun .pins = sun6i_a31_r_pins,
106*4882a593Smuzhiyun .npins = ARRAY_SIZE(sun6i_a31_r_pins),
107*4882a593Smuzhiyun .pin_base = PL_BASE,
108*4882a593Smuzhiyun .irq_banks = 2,
109*4882a593Smuzhiyun .disable_strict_mode = true,
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun
sun6i_a31_r_pinctrl_probe(struct platform_device * pdev)112*4882a593Smuzhiyun static int sun6i_a31_r_pinctrl_probe(struct platform_device *pdev)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun struct reset_control *rstc;
115*4882a593Smuzhiyun int ret;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
118*4882a593Smuzhiyun if (IS_ERR(rstc)) {
119*4882a593Smuzhiyun dev_err(&pdev->dev, "Reset controller missing\n");
120*4882a593Smuzhiyun return PTR_ERR(rstc);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun ret = reset_control_deassert(rstc);
124*4882a593Smuzhiyun if (ret)
125*4882a593Smuzhiyun return ret;
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun ret = sunxi_pinctrl_init(pdev,
128*4882a593Smuzhiyun &sun6i_a31_r_pinctrl_data);
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun if (ret)
131*4882a593Smuzhiyun reset_control_assert(rstc);
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun return ret;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun static const struct of_device_id sun6i_a31_r_pinctrl_match[] = {
137*4882a593Smuzhiyun { .compatible = "allwinner,sun6i-a31-r-pinctrl", },
138*4882a593Smuzhiyun {}
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun static struct platform_driver sun6i_a31_r_pinctrl_driver = {
142*4882a593Smuzhiyun .probe = sun6i_a31_r_pinctrl_probe,
143*4882a593Smuzhiyun .driver = {
144*4882a593Smuzhiyun .name = "sun6i-a31-r-pinctrl",
145*4882a593Smuzhiyun .of_match_table = sun6i_a31_r_pinctrl_match,
146*4882a593Smuzhiyun },
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun builtin_platform_driver(sun6i_a31_r_pinctrl_driver);
149