1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Pinctrl data for Wondermedia WM8850 SoC
4  *
5  * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
6  */
7 
8 #include <linux/io.h>
9 #include <linux/init.h>
10 #include <linux/pinctrl/pinctrl.h>
11 #include <linux/platform_device.h>
12 #include <linux/slab.h>
13 
14 #include "pinctrl-wmt.h"
15 
16 /*
17  * Describe the register offsets within the GPIO memory space
18  * The dedicated external GPIO's should always be listed in bank 0
19  * so they are exported in the 0..31 range which is what users
20  * expect.
21  *
22  * Do not reorder these banks as it will change the pin numbering
23  */
24 static const struct wmt_pinctrl_bank_registers wm8850_banks[] = {
25 	WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0),		/* 0 */
26 	WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4),		/* 1 */
27 	WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8),		/* 2 */
28 	WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC),		/* 3 */
29 	WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0),		/* 4 */
30 	WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4),		/* 5 */
31 	WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8),		/* 6 */
32 	WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC),		/* 7 */
33 	WMT_PINCTRL_BANK(0x60, 0xA0, 0xE0, 0x20, 0x4A0, 0x4E0),		/* 8 */
34 	WMT_PINCTRL_BANK(0x70, 0xB0, 0xF0, 0x30, 0x4B0, 0x4F0),		/* 9 */
35 	WMT_PINCTRL_BANK(0x7C, 0xBC, 0xDC, 0x3C, 0x4BC, 0x4FC),		/* 10 */
36 };
37 
38 /* Please keep sorted by bank/bit */
39 #define WMT_PIN_EXTGPIO0	WMT_PIN(0, 0)
40 #define WMT_PIN_EXTGPIO1	WMT_PIN(0, 1)
41 #define WMT_PIN_EXTGPIO2	WMT_PIN(0, 2)
42 #define WMT_PIN_EXTGPIO3	WMT_PIN(0, 3)
43 #define WMT_PIN_EXTGPIO4	WMT_PIN(0, 4)
44 #define WMT_PIN_EXTGPIO5	WMT_PIN(0, 5)
45 #define WMT_PIN_EXTGPIO6	WMT_PIN(0, 6)
46 #define WMT_PIN_EXTGPIO7	WMT_PIN(0, 7)
47 #define WMT_PIN_WAKEUP0		WMT_PIN(0, 16)
48 #define WMT_PIN_WAKEUP1		WMT_PIN(0, 17)
49 #define WMT_PIN_WAKEUP2		WMT_PIN(0, 18)
50 #define WMT_PIN_WAKEUP3		WMT_PIN(0, 19)
51 #define WMT_PIN_SUSGPIO0	WMT_PIN(0, 21)
52 #define WMT_PIN_SUSGPIO1	WMT_PIN(0, 22)
53 #define WMT_PIN_SD0CD		WMT_PIN(0, 28)
54 #define WMT_PIN_VDOUT0		WMT_PIN(1, 0)
55 #define WMT_PIN_VDOUT1		WMT_PIN(1, 1)
56 #define WMT_PIN_VDOUT2		WMT_PIN(1, 2)
57 #define WMT_PIN_VDOUT3		WMT_PIN(1, 3)
58 #define WMT_PIN_VDOUT4		WMT_PIN(1, 4)
59 #define WMT_PIN_VDOUT5		WMT_PIN(1, 5)
60 #define WMT_PIN_VDOUT6		WMT_PIN(1, 6)
61 #define WMT_PIN_VDOUT7		WMT_PIN(1, 7)
62 #define WMT_PIN_VDOUT8		WMT_PIN(1, 8)
63 #define WMT_PIN_VDOUT9		WMT_PIN(1, 9)
64 #define WMT_PIN_VDOUT10		WMT_PIN(1, 10)
65 #define WMT_PIN_VDOUT11		WMT_PIN(1, 11)
66 #define WMT_PIN_VDOUT12		WMT_PIN(1, 12)
67 #define WMT_PIN_VDOUT13		WMT_PIN(1, 13)
68 #define WMT_PIN_VDOUT14		WMT_PIN(1, 14)
69 #define WMT_PIN_VDOUT15		WMT_PIN(1, 15)
70 #define WMT_PIN_VDOUT16		WMT_PIN(1, 16)
71 #define WMT_PIN_VDOUT17		WMT_PIN(1, 17)
72 #define WMT_PIN_VDOUT18		WMT_PIN(1, 18)
73 #define WMT_PIN_VDOUT19		WMT_PIN(1, 19)
74 #define WMT_PIN_VDOUT20		WMT_PIN(1, 20)
75 #define WMT_PIN_VDOUT21		WMT_PIN(1, 21)
76 #define WMT_PIN_VDOUT22		WMT_PIN(1, 22)
77 #define WMT_PIN_VDOUT23		WMT_PIN(1, 23)
78 #define WMT_PIN_VDIN0		WMT_PIN(2, 0)
79 #define WMT_PIN_VDIN1		WMT_PIN(2, 1)
80 #define WMT_PIN_VDIN2		WMT_PIN(2, 2)
81 #define WMT_PIN_VDIN3		WMT_PIN(2, 3)
82 #define WMT_PIN_VDIN4		WMT_PIN(2, 4)
83 #define WMT_PIN_VDIN5		WMT_PIN(2, 5)
84 #define WMT_PIN_VDIN6		WMT_PIN(2, 6)
85 #define WMT_PIN_VDIN7		WMT_PIN(2, 7)
86 #define WMT_PIN_SPI0_MOSI	WMT_PIN(2, 24)
87 #define WMT_PIN_SPI0_MISO	WMT_PIN(2, 25)
88 #define WMT_PIN_SPI0_SS		WMT_PIN(2, 26)
89 #define WMT_PIN_SPI0_CLK	WMT_PIN(2, 27)
90 #define WMT_PIN_SPI0_SSB	WMT_PIN(2, 28)
91 #define WMT_PIN_SD0CLK		WMT_PIN(3, 17)
92 #define WMT_PIN_SD0CMD		WMT_PIN(3, 18)
93 #define WMT_PIN_SD0WP		WMT_PIN(3, 19)
94 #define WMT_PIN_SD0DATA0	WMT_PIN(3, 20)
95 #define WMT_PIN_SD0DATA1	WMT_PIN(3, 21)
96 #define WMT_PIN_SD0DATA2	WMT_PIN(3, 22)
97 #define WMT_PIN_SD0DATA3	WMT_PIN(3, 23)
98 #define WMT_PIN_SD1DATA0	WMT_PIN(3, 24)
99 #define WMT_PIN_SD1DATA1	WMT_PIN(3, 25)
100 #define WMT_PIN_SD1DATA2	WMT_PIN(3, 26)
101 #define WMT_PIN_SD1DATA3	WMT_PIN(3, 27)
102 #define WMT_PIN_SD1DATA4	WMT_PIN(3, 28)
103 #define WMT_PIN_SD1DATA5	WMT_PIN(3, 29)
104 #define WMT_PIN_SD1DATA6	WMT_PIN(3, 30)
105 #define WMT_PIN_SD1DATA7	WMT_PIN(3, 31)
106 #define WMT_PIN_I2C0_SCL	WMT_PIN(5, 8)
107 #define WMT_PIN_I2C0_SDA	WMT_PIN(5, 9)
108 #define WMT_PIN_I2C1_SCL	WMT_PIN(5, 10)
109 #define WMT_PIN_I2C1_SDA	WMT_PIN(5, 11)
110 #define WMT_PIN_I2C2_SCL	WMT_PIN(5, 12)
111 #define WMT_PIN_I2C2_SDA	WMT_PIN(5, 13)
112 #define WMT_PIN_UART0_RTS	WMT_PIN(5, 16)
113 #define WMT_PIN_UART0_TXD	WMT_PIN(5, 17)
114 #define WMT_PIN_UART0_CTS	WMT_PIN(5, 18)
115 #define WMT_PIN_UART0_RXD	WMT_PIN(5, 19)
116 #define WMT_PIN_UART1_RTS	WMT_PIN(5, 20)
117 #define WMT_PIN_UART1_TXD	WMT_PIN(5, 21)
118 #define WMT_PIN_UART1_CTS	WMT_PIN(5, 22)
119 #define WMT_PIN_UART1_RXD	WMT_PIN(5, 23)
120 #define WMT_PIN_UART2_RTS	WMT_PIN(5, 24)
121 #define WMT_PIN_UART2_TXD	WMT_PIN(5, 25)
122 #define WMT_PIN_UART2_CTS	WMT_PIN(5, 26)
123 #define WMT_PIN_UART2_RXD	WMT_PIN(5, 27)
124 #define WMT_PIN_SD2WP		WMT_PIN(6, 3)
125 #define WMT_PIN_SD2CMD		WMT_PIN(6, 6)
126 #define WMT_PIN_SD2CLK		WMT_PIN(6, 7)
127 #define WMT_PIN_SD2PWR		WMT_PIN(6, 9)
128 #define WMT_PIN_SD1CLK		WMT_PIN(7, 0)
129 #define WMT_PIN_SD1CMD		WMT_PIN(7, 1)
130 #define WMT_PIN_SD1PWR		WMT_PIN(7, 10)
131 #define WMT_PIN_SD1WP		WMT_PIN(7, 11)
132 #define WMT_PIN_SD1CD		WMT_PIN(7, 12)
133 #define WMT_PIN_PWMOUT1		WMT_PIN(7, 26)
134 #define WMT_PIN_PWMOUT0		WMT_PIN(7, 27)
135 
136 static const struct pinctrl_pin_desc wm8850_pins[] = {
137 	PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
138 	PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
139 	PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
140 	PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
141 	PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
142 	PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
143 	PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
144 	PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
145 	PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
146 	PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
147 	PINCTRL_PIN(WMT_PIN_WAKEUP2, "wakeup2"),
148 	PINCTRL_PIN(WMT_PIN_WAKEUP3, "wakeup3"),
149 	PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
150 	PINCTRL_PIN(WMT_PIN_SUSGPIO1, "susgpio1"),
151 	PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
152 	PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
153 	PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
154 	PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
155 	PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
156 	PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
157 	PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
158 	PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
159 	PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
160 	PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
161 	PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
162 	PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
163 	PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
164 	PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
165 	PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
166 	PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
167 	PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
168 	PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
169 	PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
170 	PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
171 	PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
172 	PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
173 	PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
174 	PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
175 	PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
176 	PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
177 	PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
178 	PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
179 	PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
180 	PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
181 	PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
182 	PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
183 	PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
184 	PINCTRL_PIN(WMT_PIN_SPI0_MOSI, "spi0_mosi"),
185 	PINCTRL_PIN(WMT_PIN_SPI0_MISO, "spi0_miso"),
186 	PINCTRL_PIN(WMT_PIN_SPI0_SS, "spi0_ss"),
187 	PINCTRL_PIN(WMT_PIN_SPI0_CLK, "spi0_clk"),
188 	PINCTRL_PIN(WMT_PIN_SPI0_SSB, "spi0_ssb"),
189 	PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
190 	PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
191 	PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
192 	PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
193 	PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
194 	PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
195 	PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
196 	PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
197 	PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
198 	PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
199 	PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
200 	PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
201 	PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
202 	PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
203 	PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
204 	PINCTRL_PIN(WMT_PIN_I2C0_SCL, "i2c0_scl"),
205 	PINCTRL_PIN(WMT_PIN_I2C0_SDA, "i2c0_sda"),
206 	PINCTRL_PIN(WMT_PIN_I2C1_SCL, "i2c1_scl"),
207 	PINCTRL_PIN(WMT_PIN_I2C1_SDA, "i2c1_sda"),
208 	PINCTRL_PIN(WMT_PIN_I2C2_SCL, "i2c2_scl"),
209 	PINCTRL_PIN(WMT_PIN_I2C2_SDA, "i2c2_sda"),
210 	PINCTRL_PIN(WMT_PIN_UART0_RTS, "uart0_rts"),
211 	PINCTRL_PIN(WMT_PIN_UART0_TXD, "uart0_txd"),
212 	PINCTRL_PIN(WMT_PIN_UART0_CTS, "uart0_cts"),
213 	PINCTRL_PIN(WMT_PIN_UART0_RXD, "uart0_rxd"),
214 	PINCTRL_PIN(WMT_PIN_UART1_RTS, "uart1_rts"),
215 	PINCTRL_PIN(WMT_PIN_UART1_TXD, "uart1_txd"),
216 	PINCTRL_PIN(WMT_PIN_UART1_CTS, "uart1_cts"),
217 	PINCTRL_PIN(WMT_PIN_UART1_RXD, "uart1_rxd"),
218 	PINCTRL_PIN(WMT_PIN_UART2_RTS, "uart2_rts"),
219 	PINCTRL_PIN(WMT_PIN_UART2_TXD, "uart2_txd"),
220 	PINCTRL_PIN(WMT_PIN_UART2_CTS, "uart2_cts"),
221 	PINCTRL_PIN(WMT_PIN_UART2_RXD, "uart2_rxd"),
222 	PINCTRL_PIN(WMT_PIN_SD2WP, "sd2_wp"),
223 	PINCTRL_PIN(WMT_PIN_SD2CMD, "sd2_cmd"),
224 	PINCTRL_PIN(WMT_PIN_SD2CLK, "sd2_clk"),
225 	PINCTRL_PIN(WMT_PIN_SD2PWR, "sd2_pwr"),
226 	PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
227 	PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
228 	PINCTRL_PIN(WMT_PIN_SD1PWR, "sd1_pwr"),
229 	PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
230 	PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
231 	PINCTRL_PIN(WMT_PIN_PWMOUT1, "pwmout1"),
232 	PINCTRL_PIN(WMT_PIN_PWMOUT0, "pwmout0"),
233 };
234 
235 /* Order of these names must match the above list */
236 static const char * const wm8850_groups[] = {
237 	"extgpio0",
238 	"extgpio1",
239 	"extgpio2",
240 	"extgpio3",
241 	"extgpio4",
242 	"extgpio5",
243 	"extgpio6",
244 	"extgpio7",
245 	"wakeup0",
246 	"wakeup1",
247 	"wakeup2",
248 	"wakeup3",
249 	"susgpio0",
250 	"susgpio1",
251 	"sd0_cd",
252 	"vdout0",
253 	"vdout1",
254 	"vdout2",
255 	"vdout3",
256 	"vdout4",
257 	"vdout5",
258 	"vdout6",
259 	"vdout7",
260 	"vdout8",
261 	"vdout9",
262 	"vdout10",
263 	"vdout11",
264 	"vdout12",
265 	"vdout13",
266 	"vdout14",
267 	"vdout15",
268 	"vdout16",
269 	"vdout17",
270 	"vdout18",
271 	"vdout19",
272 	"vdout20",
273 	"vdout21",
274 	"vdout22",
275 	"vdout23",
276 	"vdin0",
277 	"vdin1",
278 	"vdin2",
279 	"vdin3",
280 	"vdin4",
281 	"vdin5",
282 	"vdin6",
283 	"vdin7",
284 	"spi0_mosi",
285 	"spi0_miso",
286 	"spi0_ss",
287 	"spi0_clk",
288 	"spi0_ssb",
289 	"sd0_clk",
290 	"sd0_cmd",
291 	"sd0_wp",
292 	"sd0_data0",
293 	"sd0_data1",
294 	"sd0_data2",
295 	"sd0_data3",
296 	"sd1_data0",
297 	"sd1_data1",
298 	"sd1_data2",
299 	"sd1_data3",
300 	"sd1_data4",
301 	"sd1_data5",
302 	"sd1_data6",
303 	"sd1_data7",
304 	"i2c0_scl",
305 	"i2c0_sda",
306 	"i2c1_scl",
307 	"i2c1_sda",
308 	"i2c2_scl",
309 	"i2c2_sda",
310 	"uart0_rts",
311 	"uart0_txd",
312 	"uart0_cts",
313 	"uart0_rxd",
314 	"uart1_rts",
315 	"uart1_txd",
316 	"uart1_cts",
317 	"uart1_rxd",
318 	"uart2_rts",
319 	"uart2_txd",
320 	"uart2_cts",
321 	"uart2_rxd",
322 	"sd2_wp",
323 	"sd2_cmd",
324 	"sd2_clk",
325 	"sd2_pwr",
326 	"sd1_clk",
327 	"sd1_cmd",
328 	"sd1_pwr",
329 	"sd1_wp",
330 	"sd1_cd",
331 	"pwmout1",
332 	"pwmout0",
333 };
334 
wm8850_pinctrl_probe(struct platform_device * pdev)335 static int wm8850_pinctrl_probe(struct platform_device *pdev)
336 {
337 	struct wmt_pinctrl_data *data;
338 
339 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
340 	if (!data)
341 		return -ENOMEM;
342 
343 	data->banks = wm8850_banks;
344 	data->nbanks = ARRAY_SIZE(wm8850_banks);
345 	data->pins = wm8850_pins;
346 	data->npins = ARRAY_SIZE(wm8850_pins);
347 	data->groups = wm8850_groups;
348 	data->ngroups = ARRAY_SIZE(wm8850_groups);
349 
350 	return wmt_pinctrl_probe(pdev, data);
351 }
352 
353 static const struct of_device_id wmt_pinctrl_of_match[] = {
354 	{ .compatible = "wm,wm8850-pinctrl" },
355 	{ /* sentinel */ },
356 };
357 
358 static struct platform_driver wmt_pinctrl_driver = {
359 	.probe	= wm8850_pinctrl_probe,
360 	.driver = {
361 		.name	= "pinctrl-wm8850",
362 		.of_match_table	= wmt_pinctrl_of_match,
363 		.suppress_bind_attrs = true,
364 	},
365 };
366 builtin_platform_driver(wmt_pinctrl_driver);
367