1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Pinctrl data for Wondermedia WM8650 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 wm8650_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 };
34 
35 /* Please keep sorted by bank/bit */
36 #define WMT_PIN_EXTGPIO0	WMT_PIN(0, 0)
37 #define WMT_PIN_EXTGPIO1	WMT_PIN(0, 1)
38 #define WMT_PIN_EXTGPIO2	WMT_PIN(0, 2)
39 #define WMT_PIN_EXTGPIO3	WMT_PIN(0, 3)
40 #define WMT_PIN_EXTGPIO4	WMT_PIN(0, 4)
41 #define WMT_PIN_EXTGPIO5	WMT_PIN(0, 5)
42 #define WMT_PIN_EXTGPIO6	WMT_PIN(0, 6)
43 #define WMT_PIN_EXTGPIO7	WMT_PIN(0, 7)
44 #define WMT_PIN_WAKEUP0		WMT_PIN(0, 16)
45 #define WMT_PIN_WAKEUP1		WMT_PIN(0, 17)
46 #define WMT_PIN_SUSGPIO0	WMT_PIN(0, 21)
47 #define WMT_PIN_SD0CD		WMT_PIN(0, 28)
48 #define WMT_PIN_SD1CD		WMT_PIN(0, 29)
49 #define WMT_PIN_VDOUT0		WMT_PIN(1, 0)
50 #define WMT_PIN_VDOUT1		WMT_PIN(1, 1)
51 #define WMT_PIN_VDOUT2		WMT_PIN(1, 2)
52 #define WMT_PIN_VDOUT3		WMT_PIN(1, 3)
53 #define WMT_PIN_VDOUT4		WMT_PIN(1, 4)
54 #define WMT_PIN_VDOUT5		WMT_PIN(1, 5)
55 #define WMT_PIN_VDOUT6		WMT_PIN(1, 6)
56 #define WMT_PIN_VDOUT7		WMT_PIN(1, 7)
57 #define WMT_PIN_VDOUT8		WMT_PIN(1, 8)
58 #define WMT_PIN_VDOUT9		WMT_PIN(1, 9)
59 #define WMT_PIN_VDOUT10		WMT_PIN(1, 10)
60 #define WMT_PIN_VDOUT11		WMT_PIN(1, 11)
61 #define WMT_PIN_VDOUT12		WMT_PIN(1, 12)
62 #define WMT_PIN_VDOUT13		WMT_PIN(1, 13)
63 #define WMT_PIN_VDOUT14		WMT_PIN(1, 14)
64 #define WMT_PIN_VDOUT15		WMT_PIN(1, 15)
65 #define WMT_PIN_VDOUT16		WMT_PIN(1, 16)
66 #define WMT_PIN_VDOUT17		WMT_PIN(1, 17)
67 #define WMT_PIN_VDOUT18		WMT_PIN(1, 18)
68 #define WMT_PIN_VDOUT19		WMT_PIN(1, 19)
69 #define WMT_PIN_VDOUT20		WMT_PIN(1, 20)
70 #define WMT_PIN_VDOUT21		WMT_PIN(1, 21)
71 #define WMT_PIN_VDOUT22		WMT_PIN(1, 22)
72 #define WMT_PIN_VDOUT23		WMT_PIN(1, 23)
73 #define WMT_PIN_VDIN0		WMT_PIN(2, 0)
74 #define WMT_PIN_VDIN1		WMT_PIN(2, 1)
75 #define WMT_PIN_VDIN2		WMT_PIN(2, 2)
76 #define WMT_PIN_VDIN3		WMT_PIN(2, 3)
77 #define WMT_PIN_VDIN4		WMT_PIN(2, 4)
78 #define WMT_PIN_VDIN5		WMT_PIN(2, 5)
79 #define WMT_PIN_VDIN6		WMT_PIN(2, 6)
80 #define WMT_PIN_VDIN7		WMT_PIN(2, 7)
81 #define WMT_PIN_I2C1SCL		WMT_PIN(2, 12)
82 #define WMT_PIN_I2C1SDA		WMT_PIN(2, 13)
83 #define WMT_PIN_SPI0MOSI	WMT_PIN(2, 24)
84 #define WMT_PIN_SPI0MISO	WMT_PIN(2, 25)
85 #define WMT_PIN_SPI0SS0		WMT_PIN(2, 26)
86 #define WMT_PIN_SPI0CLK		WMT_PIN(2, 27)
87 #define WMT_PIN_SD0DATA0	WMT_PIN(3, 8)
88 #define WMT_PIN_SD0DATA1	WMT_PIN(3, 9)
89 #define WMT_PIN_SD0DATA2	WMT_PIN(3, 10)
90 #define WMT_PIN_SD0DATA3	WMT_PIN(3, 11)
91 #define WMT_PIN_SD0CLK		WMT_PIN(3, 12)
92 #define WMT_PIN_SD0WP		WMT_PIN(3, 13)
93 #define WMT_PIN_SD0CMD		WMT_PIN(3, 14)
94 #define WMT_PIN_SD1DATA0	WMT_PIN(3, 24)
95 #define WMT_PIN_SD1DATA1	WMT_PIN(3, 25)
96 #define WMT_PIN_SD1DATA2	WMT_PIN(3, 26)
97 #define WMT_PIN_SD1DATA3	WMT_PIN(3, 27)
98 #define WMT_PIN_SD1DATA4	WMT_PIN(3, 28)
99 #define WMT_PIN_SD1DATA5	WMT_PIN(3, 29)
100 #define WMT_PIN_SD1DATA6	WMT_PIN(3, 30)
101 #define WMT_PIN_SD1DATA7	WMT_PIN(3, 31)
102 #define WMT_PIN_I2C0SCL		WMT_PIN(5, 8)
103 #define WMT_PIN_I2C0SDA		WMT_PIN(5, 9)
104 #define WMT_PIN_UART0RTS	WMT_PIN(5, 16)
105 #define WMT_PIN_UART0TXD	WMT_PIN(5, 17)
106 #define WMT_PIN_UART0CTS	WMT_PIN(5, 18)
107 #define WMT_PIN_UART0RXD	WMT_PIN(5, 19)
108 #define WMT_PIN_UART1RTS	WMT_PIN(5, 20)
109 #define WMT_PIN_UART1TXD	WMT_PIN(5, 21)
110 #define WMT_PIN_UART1CTS	WMT_PIN(5, 22)
111 #define WMT_PIN_UART1RXD	WMT_PIN(5, 23)
112 #define WMT_PIN_UART2RTS	WMT_PIN(5, 24)
113 #define WMT_PIN_UART2TXD	WMT_PIN(5, 25)
114 #define WMT_PIN_UART2CTS	WMT_PIN(5, 26)
115 #define WMT_PIN_UART2RXD	WMT_PIN(5, 27)
116 #define WMT_PIN_UART3RTS	WMT_PIN(5, 28)
117 #define WMT_PIN_UART3TXD	WMT_PIN(5, 29)
118 #define WMT_PIN_UART3CTS	WMT_PIN(5, 30)
119 #define WMT_PIN_UART3RXD	WMT_PIN(5, 31)
120 #define WMT_PIN_KPADROW0	WMT_PIN(6, 16)
121 #define WMT_PIN_KPADROW1	WMT_PIN(6, 17)
122 #define WMT_PIN_KPADCOL0	WMT_PIN(6, 18)
123 #define WMT_PIN_KPADCOL1	WMT_PIN(6, 19)
124 #define WMT_PIN_SD1CLK		WMT_PIN(7, 0)
125 #define WMT_PIN_SD1CMD		WMT_PIN(7, 1)
126 #define WMT_PIN_SD1WP		WMT_PIN(7, 13)
127 
128 static const struct pinctrl_pin_desc wm8650_pins[] = {
129 	PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
130 	PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
131 	PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
132 	PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
133 	PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
134 	PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
135 	PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
136 	PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
137 	PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
138 	PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
139 	PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
140 	PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
141 	PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
142 	PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
143 	PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
144 	PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
145 	PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
146 	PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
147 	PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
148 	PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
149 	PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
150 	PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
151 	PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
152 	PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
153 	PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
154 	PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
155 	PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
156 	PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
157 	PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
158 	PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
159 	PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
160 	PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
161 	PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
162 	PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
163 	PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
164 	PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
165 	PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
166 	PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
167 	PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
168 	PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
169 	PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
170 	PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
171 	PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
172 	PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
173 	PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
174 	PINCTRL_PIN(WMT_PIN_I2C1SCL, "i2c1_scl"),
175 	PINCTRL_PIN(WMT_PIN_I2C1SDA, "i2c1_sda"),
176 	PINCTRL_PIN(WMT_PIN_SPI0MOSI, "spi0_mosi"),
177 	PINCTRL_PIN(WMT_PIN_SPI0MISO, "spi0_miso"),
178 	PINCTRL_PIN(WMT_PIN_SPI0SS0, "spi0_ss0"),
179 	PINCTRL_PIN(WMT_PIN_SPI0CLK, "spi0_clk"),
180 	PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
181 	PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
182 	PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
183 	PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
184 	PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
185 	PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
186 	PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
187 	PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
188 	PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
189 	PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
190 	PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
191 	PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
192 	PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
193 	PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
194 	PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
195 	PINCTRL_PIN(WMT_PIN_I2C0SCL, "i2c0_scl"),
196 	PINCTRL_PIN(WMT_PIN_I2C0SDA, "i2c0_sda"),
197 	PINCTRL_PIN(WMT_PIN_UART0RTS, "uart0_rts"),
198 	PINCTRL_PIN(WMT_PIN_UART0TXD, "uart0_txd"),
199 	PINCTRL_PIN(WMT_PIN_UART0CTS, "uart0_cts"),
200 	PINCTRL_PIN(WMT_PIN_UART0RXD, "uart0_rxd"),
201 	PINCTRL_PIN(WMT_PIN_UART1RTS, "uart1_rts"),
202 	PINCTRL_PIN(WMT_PIN_UART1TXD, "uart1_txd"),
203 	PINCTRL_PIN(WMT_PIN_UART1CTS, "uart1_cts"),
204 	PINCTRL_PIN(WMT_PIN_UART1RXD, "uart1_rxd"),
205 	PINCTRL_PIN(WMT_PIN_UART2RTS, "uart2_rts"),
206 	PINCTRL_PIN(WMT_PIN_UART2TXD, "uart2_txd"),
207 	PINCTRL_PIN(WMT_PIN_UART2CTS, "uart2_cts"),
208 	PINCTRL_PIN(WMT_PIN_UART2RXD, "uart2_rxd"),
209 	PINCTRL_PIN(WMT_PIN_UART3RTS, "uart3_rts"),
210 	PINCTRL_PIN(WMT_PIN_UART3TXD, "uart3_txd"),
211 	PINCTRL_PIN(WMT_PIN_UART3CTS, "uart3_cts"),
212 	PINCTRL_PIN(WMT_PIN_UART3RXD, "uart3_rxd"),
213 	PINCTRL_PIN(WMT_PIN_KPADROW0, "kpadrow0"),
214 	PINCTRL_PIN(WMT_PIN_KPADROW1, "kpadrow1"),
215 	PINCTRL_PIN(WMT_PIN_KPADCOL0, "kpadcol0"),
216 	PINCTRL_PIN(WMT_PIN_KPADCOL1, "kpadcol1"),
217 	PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
218 	PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
219 	PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
220 };
221 
222 /* Order of these names must match the above list */
223 static const char * const wm8650_groups[] = {
224 	"extgpio0",
225 	"extgpio1",
226 	"extgpio2",
227 	"extgpio3",
228 	"extgpio4",
229 	"extgpio5",
230 	"extgpio6",
231 	"extgpio7",
232 	"wakeup0",
233 	"wakeup1",
234 	"susgpio0",
235 	"sd0_cd",
236 	"sd1_cd",
237 	"vdout0",
238 	"vdout1",
239 	"vdout2",
240 	"vdout3",
241 	"vdout4",
242 	"vdout5",
243 	"vdout6",
244 	"vdout7",
245 	"vdout8",
246 	"vdout9",
247 	"vdout10",
248 	"vdout11",
249 	"vdout12",
250 	"vdout13",
251 	"vdout14",
252 	"vdout15",
253 	"vdout16",
254 	"vdout17",
255 	"vdout18",
256 	"vdout19",
257 	"vdout20",
258 	"vdout21",
259 	"vdout22",
260 	"vdout23",
261 	"vdin0",
262 	"vdin1",
263 	"vdin2",
264 	"vdin3",
265 	"vdin4",
266 	"vdin5",
267 	"vdin6",
268 	"vdin7",
269 	"i2c1_scl",
270 	"i2c1_sda",
271 	"spi0_mosi",
272 	"spi0_miso",
273 	"spi0_ss0",
274 	"spi0_clk",
275 	"sd0_data0",
276 	"sd0_data1",
277 	"sd0_data2",
278 	"sd0_data3",
279 	"sd0_clk",
280 	"sd0_wp",
281 	"sd0_cmd",
282 	"sd1_data0",
283 	"sd1_data1",
284 	"sd1_data2",
285 	"sd1_data3",
286 	"sd1_data4",
287 	"sd1_data5",
288 	"sd1_data6",
289 	"sd1_data7",
290 	"i2c0_scl",
291 	"i2c0_sda",
292 	"uart0_rts",
293 	"uart0_txd",
294 	"uart0_cts",
295 	"uart0_rxd",
296 	"uart1_rts",
297 	"uart1_txd",
298 	"uart1_cts",
299 	"uart1_rxd",
300 	"uart2_rts",
301 	"uart2_txd",
302 	"uart2_cts",
303 	"uart2_rxd",
304 	"uart3_rts",
305 	"uart3_txd",
306 	"uart3_cts",
307 	"uart3_rxd",
308 	"kpadrow0",
309 	"kpadrow1",
310 	"kpadcol0",
311 	"kpadcol1",
312 	"sd1_clk",
313 	"sd1_cmd",
314 	"sd1_wp",
315 };
316 
317 static int wm8650_pinctrl_probe(struct platform_device *pdev)
318 {
319 	struct wmt_pinctrl_data *data;
320 
321 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
322 	if (!data)
323 		return -ENOMEM;
324 
325 	data->banks = wm8650_banks;
326 	data->nbanks = ARRAY_SIZE(wm8650_banks);
327 	data->pins = wm8650_pins;
328 	data->npins = ARRAY_SIZE(wm8650_pins);
329 	data->groups = wm8650_groups;
330 	data->ngroups = ARRAY_SIZE(wm8650_groups);
331 
332 	return wmt_pinctrl_probe(pdev, data);
333 }
334 
335 static const struct of_device_id wmt_pinctrl_of_match[] = {
336 	{ .compatible = "wm,wm8650-pinctrl" },
337 	{ /* sentinel */ },
338 };
339 
340 static struct platform_driver wmt_pinctrl_driver = {
341 	.probe	= wm8650_pinctrl_probe,
342 	.driver = {
343 		.name	= "pinctrl-wm8650",
344 		.of_match_table	= wmt_pinctrl_of_match,
345 		.suppress_bind_attrs = true,
346 	},
347 };
348 builtin_platform_driver(wmt_pinctrl_driver);
349