1 /*
2  * Marvell Berlin BG2 pinctrl driver.
3  *
4  * Copyright (C) 2014 Marvell Technology Group Ltd.
5  *
6  * Antoine Ténart <antoine.tenart@free-electrons.com>
7  *
8  * This file is licensed under the terms of the GNU General Public
9  * License version 2. This program is licensed "as is" without any
10  * warranty of any kind, whether express or implied.
11  */
12 
13 #include <linux/init.h>
14 #include <linux/of_device.h>
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
17 
18 #include "berlin.h"
19 
20 static const struct berlin_desc_group berlin2_soc_pinctrl_groups[] = {
21 	/* G */
22 	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x1, 0x00,
23 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SS0n */
24 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
25 	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x2, 0x01,
26 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SS1n */
27 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
28 		BERLIN_PINCTRL_FUNCTION(0x2, "usb1")),
29 	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x2, 0x02,
30 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
31 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"), /* SS2n */
32 		BERLIN_PINCTRL_FUNCTION(0x2, "pwm"),
33 		BERLIN_PINCTRL_FUNCTION(0x3, "i2s0")),
34 	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x2, 0x04,
35 		BERLIN_PINCTRL_FUNCTION(0x0, "soc"),
36 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"), /* SS3n */
37 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio"),
38 		BERLIN_PINCTRL_FUNCTION(0x3, "i2s1")),
39 	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x2, 0x06,
40 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* CLK/SDI/SDO */
41 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
42 		BERLIN_PINCTRL_FUNCTION(0x2, "pwm")),
43 	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x08,
44 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
45 		BERLIN_PINCTRL_FUNCTION(0x1, "sts1"),
46 		BERLIN_PINCTRL_FUNCTION(0x2, "et"),
47 		/*
48 		 * Mode 0x3 mux i2s2 mclk *and* i2s3 mclk:
49 		 * add two functions so it can be used with other groups
50 		 * within the same subnode in the device tree
51 		 */
52 		BERLIN_PINCTRL_FUNCTION(0x3, "i2s2"),
53 		BERLIN_PINCTRL_FUNCTION(0x3, "i2s3")),
54 	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x2, 0x0b,
55 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
56 		BERLIN_PINCTRL_FUNCTION(0x1, "sts0"),
57 		BERLIN_PINCTRL_FUNCTION(0x2, "et")),
58 	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x0d,
59 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
60 		BERLIN_PINCTRL_FUNCTION(0x1, "sts0"),
61 		BERLIN_PINCTRL_FUNCTION(0x2, "et"),
62 		BERLIN_PINCTRL_FUNCTION(0x3, "vdac")),
63 	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x10,
64 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
65 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
66 		BERLIN_PINCTRL_FUNCTION(0x2, "et"),
67 		BERLIN_PINCTRL_FUNCTION(0x3, "usb0_dbg"),
68 		BERLIN_PINCTRL_FUNCTION(0x4, "sata_dbg"),
69 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
70 	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x13,
71 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
72 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
73 		BERLIN_PINCTRL_FUNCTION(0x2, "et"),
74 		BERLIN_PINCTRL_FUNCTION(0x3, "usb0_dbg"),
75 		BERLIN_PINCTRL_FUNCTION(0x4, "sata_dbg"),
76 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
77 	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x16,
78 		BERLIN_PINCTRL_FUNCTION(0x0, "soc"),
79 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi0"),
80 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio"),
81 		BERLIN_PINCTRL_FUNCTION(0x3, "ptp")),
82 	BERLIN_PINCTRL_GROUP("G11", 0x00, 0x2, 0x18,
83 		BERLIN_PINCTRL_FUNCTION(0x0, "soc"),
84 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
85 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio"),
86 		BERLIN_PINCTRL_FUNCTION(0x3, "eddc")),
87 	BERLIN_PINCTRL_GROUP("G12", 0x00, 0x3, 0x1a,
88 		BERLIN_PINCTRL_FUNCTION(0x0, "sts2"),
89 		BERLIN_PINCTRL_FUNCTION(0x1, "sata"),
90 		BERLIN_PINCTRL_FUNCTION(0x2, "sd1"),
91 		BERLIN_PINCTRL_FUNCTION(0x3, "usb0_dbg"),
92 		BERLIN_PINCTRL_FUNCTION(0x4, "sts1"),
93 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
94 	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x00,
95 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
96 		BERLIN_PINCTRL_FUNCTION(0x1, "sata"),
97 		BERLIN_PINCTRL_FUNCTION(0x2, "sd1"),
98 		BERLIN_PINCTRL_FUNCTION(0x3, "usb0_dbg"),
99 		BERLIN_PINCTRL_FUNCTION(0x4, "sts1"),
100 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
101 	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x03,
102 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
103 	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x2, 0x04,
104 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
105 		BERLIN_PINCTRL_FUNCTION(0x2, "et"),
106 		BERLIN_PINCTRL_FUNCTION(0x3, "osco")),
107 	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x06,
108 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
109 		BERLIN_PINCTRL_FUNCTION(0x1, "dvio"),
110 		BERLIN_PINCTRL_FUNCTION(0x2, "fp")),
111 	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x09,
112 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
113 		BERLIN_PINCTRL_FUNCTION(0x1, "dvio"),
114 		BERLIN_PINCTRL_FUNCTION(0x2, "fp")),
115 	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x1, 0x0c,
116 		BERLIN_PINCTRL_FUNCTION(0x0, "pll"),
117 		BERLIN_PINCTRL_FUNCTION(0x1, "i2s0")),
118 	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x1, 0x0d,
119 		BERLIN_PINCTRL_FUNCTION(0x0, "i2s0"),
120 		BERLIN_PINCTRL_FUNCTION(0x1, "pwm")),
121 	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x1, 0x0e,
122 		BERLIN_PINCTRL_FUNCTION(0x0, "spdif"),
123 		BERLIN_PINCTRL_FUNCTION(0x1, "arc")),
124 	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x0f,
125 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
126 		BERLIN_PINCTRL_FUNCTION(0x1, "dvio"),
127 		BERLIN_PINCTRL_FUNCTION(0x2, "fp"),
128 		BERLIN_PINCTRL_FUNCTION(0x3, "adac_dbg"),
129 		BERLIN_PINCTRL_FUNCTION(0x4, "pdm_a"),	/* gpio17..19,pdm */
130 		BERLIN_PINCTRL_FUNCTION(0x7, "pdm_b")),	/* gpio12..14,pdm */
131 	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x12,
132 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
133 		BERLIN_PINCTRL_FUNCTION(0x1, "dv0"),
134 		BERLIN_PINCTRL_FUNCTION(0x2, "fp"),
135 		BERLIN_PINCTRL_FUNCTION(0x3, "twsi0"),
136 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm")),
137 	BERLIN_PINCTRL_GROUP("G23", 0x04, 0x3, 0x15,
138 		BERLIN_PINCTRL_FUNCTION(0x0, "vclki"),
139 		BERLIN_PINCTRL_FUNCTION(0x1, "dv0"),
140 		BERLIN_PINCTRL_FUNCTION(0x2, "fp"),
141 		BERLIN_PINCTRL_FUNCTION(0x3, "i2s0"),
142 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
143 		BERLIN_PINCTRL_FUNCTION(0x7, "pdm")),
144 	BERLIN_PINCTRL_GROUP("G24", 0x04, 0x2, 0x18,
145 		BERLIN_PINCTRL_FUNCTION(0x0, "i2s2"),
146 		BERLIN_PINCTRL_FUNCTION(0x1, "i2s1")),
147 	BERLIN_PINCTRL_GROUP("G25", 0x04, 0x2, 0x1a,
148 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
149 		BERLIN_PINCTRL_FUNCTION(0x1, "nand"),
150 		BERLIN_PINCTRL_FUNCTION(0x2, "i2s2")),
151 	BERLIN_PINCTRL_GROUP("G26", 0x04, 0x1, 0x1c,
152 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
153 		BERLIN_PINCTRL_FUNCTION(0x1, "emmc")),
154 	BERLIN_PINCTRL_GROUP("G27", 0x04, 0x1, 0x1d,
155 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
156 		BERLIN_PINCTRL_FUNCTION(0x1, "nand")),
157 	BERLIN_PINCTRL_GROUP("G28", 0x04, 0x2, 0x1e,
158 		BERLIN_PINCTRL_FUNCTION(0x0, "dvo"),
159 		BERLIN_PINCTRL_FUNCTION(0x2, "sp")),
160 };
161 
162 static const struct berlin_desc_group berlin2_sysmgr_pinctrl_groups[] = {
163 	/* GSM */
164 	BERLIN_PINCTRL_GROUP("GSM0", 0x40, 0x2, 0x00,
165 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
166 		BERLIN_PINCTRL_FUNCTION(0x1, "spi2"), /* SS0n */
167 		BERLIN_PINCTRL_FUNCTION(0x2, "eth1")),
168 	BERLIN_PINCTRL_GROUP("GSM1", 0x40, 0x2, 0x02,
169 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
170 		BERLIN_PINCTRL_FUNCTION(0x1, "spi2"), /* SS1n */
171 		BERLIN_PINCTRL_FUNCTION(0x2, "eth1")),
172 	BERLIN_PINCTRL_GROUP("GSM2", 0x40, 0x2, 0x04,
173 		BERLIN_PINCTRL_FUNCTION(0x0, "twsi2"),
174 		BERLIN_PINCTRL_FUNCTION(0x1, "spi2")), /* SS2n/SS3n */
175 	BERLIN_PINCTRL_GROUP("GSM3", 0x40, 0x2, 0x06,
176 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
177 		BERLIN_PINCTRL_FUNCTION(0x1, "uart0"),	/* CTS/RTS */
178 		BERLIN_PINCTRL_FUNCTION(0x2, "uart2"),	/* RX/TX */
179 		BERLIN_PINCTRL_FUNCTION(0x3, "twsi2")),
180 	BERLIN_PINCTRL_GROUP("GSM4", 0x40, 0x2, 0x08,
181 		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
182 		BERLIN_PINCTRL_FUNCTION(0x1, "irda0")),
183 	BERLIN_PINCTRL_GROUP("GSM5", 0x40, 0x2, 0x0a,
184 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
185 		BERLIN_PINCTRL_FUNCTION(0x1, "uart1"),	/* RX/TX */
186 		BERLIN_PINCTRL_FUNCTION(0x2, "irda1"),
187 		BERLIN_PINCTRL_FUNCTION(0x3, "twsi3")),
188 	BERLIN_PINCTRL_GROUP("GSM6", 0x40, 0x2, 0x0c,
189 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
190 		BERLIN_PINCTRL_FUNCTION(0x1, "spi2"), /* CLK/SDO */
191 		BERLIN_PINCTRL_FUNCTION(0x1, "clki")),
192 	BERLIN_PINCTRL_GROUP("GSM7", 0x40, 0x1, 0x0e,
193 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
194 		BERLIN_PINCTRL_FUNCTION(0x1, "hdmi")),
195 	BERLIN_PINCTRL_GROUP("GSM8", 0x40, 0x1, 0x0f,
196 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
197 		BERLIN_PINCTRL_FUNCTION(0x1, "hdmi")),
198 	BERLIN_PINCTRL_GROUP("GSM9", 0x40, 0x1, 0x10,
199 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
200 		BERLIN_PINCTRL_FUNCTION(0x1, "led")),
201 	BERLIN_PINCTRL_GROUP("GSM10", 0x40, 0x1, 0x11,
202 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
203 		BERLIN_PINCTRL_FUNCTION(0x1, "led")),
204 	BERLIN_PINCTRL_GROUP("GSM11", 0x40, 0x1, 0x12,
205 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
206 		BERLIN_PINCTRL_FUNCTION(0x1, "led")),
207 };
208 
209 static const struct berlin_pinctrl_desc berlin2_soc_pinctrl_data = {
210 	.groups = berlin2_soc_pinctrl_groups,
211 	.ngroups = ARRAY_SIZE(berlin2_soc_pinctrl_groups),
212 };
213 
214 static const struct berlin_pinctrl_desc berlin2_sysmgr_pinctrl_data = {
215 	.groups = berlin2_sysmgr_pinctrl_groups,
216 	.ngroups = ARRAY_SIZE(berlin2_sysmgr_pinctrl_groups),
217 };
218 
219 static const struct of_device_id berlin2_pinctrl_match[] = {
220 	{
221 		.compatible = "marvell,berlin2-soc-pinctrl",
222 		.data = &berlin2_soc_pinctrl_data
223 	},
224 	{
225 		.compatible = "marvell,berlin2-system-pinctrl",
226 		.data = &berlin2_sysmgr_pinctrl_data
227 	},
228 	{}
229 };
230 
231 static int berlin2_pinctrl_probe(struct platform_device *pdev)
232 {
233 	const struct of_device_id *match =
234 		of_match_device(berlin2_pinctrl_match, &pdev->dev);
235 
236 	return berlin_pinctrl_probe(pdev, match->data);
237 }
238 
239 static struct platform_driver berlin2_pinctrl_driver = {
240 	.probe	= berlin2_pinctrl_probe,
241 	.driver	= {
242 		.name = "berlin-bg2-pinctrl",
243 		.of_match_table = berlin2_pinctrl_match,
244 	},
245 };
246 builtin_platform_driver(berlin2_pinctrl_driver);
247