1 /*
2  * Pinctrl data for Wondermedia WM8650 SoC
3  *
4  * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #include <linux/io.h>
17 #include <linux/module.h>
18 #include <linux/pinctrl/pinctrl.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 
22 #include "pinctrl-wmt.h"
23 
24 /*
25  * Describe the register offsets within the GPIO memory space
26  * The dedicated external GPIO's should always be listed in bank 0
27  * so they are exported in the 0..31 range which is what users
28  * expect.
29  *
30  * Do not reorder these banks as it will change the pin numbering
31  */
32 static const struct wmt_pinctrl_bank_registers wm8650_banks[] = {
33 	WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0),		/* 0 */
34 	WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4),		/* 1 */
35 	WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8),		/* 2 */
36 	WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC),		/* 3 */
37 	WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0),		/* 4 */
38 	WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4),		/* 5 */
39 	WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8),		/* 6 */
40 	WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC),		/* 7 */
41 };
42 
43 /* Please keep sorted by bank/bit */
44 #define WMT_PIN_EXTGPIO0	WMT_PIN(0, 0)
45 #define WMT_PIN_EXTGPIO1	WMT_PIN(0, 1)
46 #define WMT_PIN_EXTGPIO2	WMT_PIN(0, 2)
47 #define WMT_PIN_EXTGPIO3	WMT_PIN(0, 3)
48 #define WMT_PIN_EXTGPIO4	WMT_PIN(0, 4)
49 #define WMT_PIN_EXTGPIO5	WMT_PIN(0, 5)
50 #define WMT_PIN_EXTGPIO6	WMT_PIN(0, 6)
51 #define WMT_PIN_EXTGPIO7	WMT_PIN(0, 7)
52 #define WMT_PIN_WAKEUP0		WMT_PIN(0, 16)
53 #define WMT_PIN_WAKEUP1		WMT_PIN(0, 17)
54 #define WMT_PIN_SUSGPIO0	WMT_PIN(0, 21)
55 #define WMT_PIN_SD0CD		WMT_PIN(0, 28)
56 #define WMT_PIN_SD1CD		WMT_PIN(0, 29)
57 #define WMT_PIN_VDOUT0		WMT_PIN(1, 0)
58 #define WMT_PIN_VDOUT1		WMT_PIN(1, 1)
59 #define WMT_PIN_VDOUT2		WMT_PIN(1, 2)
60 #define WMT_PIN_VDOUT3		WMT_PIN(1, 3)
61 #define WMT_PIN_VDOUT4		WMT_PIN(1, 4)
62 #define WMT_PIN_VDOUT5		WMT_PIN(1, 5)
63 #define WMT_PIN_VDOUT6		WMT_PIN(1, 6)
64 #define WMT_PIN_VDOUT7		WMT_PIN(1, 7)
65 #define WMT_PIN_VDOUT8		WMT_PIN(1, 8)
66 #define WMT_PIN_VDOUT9		WMT_PIN(1, 9)
67 #define WMT_PIN_VDOUT10		WMT_PIN(1, 10)
68 #define WMT_PIN_VDOUT11		WMT_PIN(1, 11)
69 #define WMT_PIN_VDOUT12		WMT_PIN(1, 12)
70 #define WMT_PIN_VDOUT13		WMT_PIN(1, 13)
71 #define WMT_PIN_VDOUT14		WMT_PIN(1, 14)
72 #define WMT_PIN_VDOUT15		WMT_PIN(1, 15)
73 #define WMT_PIN_VDOUT16		WMT_PIN(1, 16)
74 #define WMT_PIN_VDOUT17		WMT_PIN(1, 17)
75 #define WMT_PIN_VDOUT18		WMT_PIN(1, 18)
76 #define WMT_PIN_VDOUT19		WMT_PIN(1, 19)
77 #define WMT_PIN_VDOUT20		WMT_PIN(1, 20)
78 #define WMT_PIN_VDOUT21		WMT_PIN(1, 21)
79 #define WMT_PIN_VDOUT22		WMT_PIN(1, 22)
80 #define WMT_PIN_VDOUT23		WMT_PIN(1, 23)
81 #define WMT_PIN_VDIN0		WMT_PIN(2, 0)
82 #define WMT_PIN_VDIN1		WMT_PIN(2, 1)
83 #define WMT_PIN_VDIN2		WMT_PIN(2, 2)
84 #define WMT_PIN_VDIN3		WMT_PIN(2, 3)
85 #define WMT_PIN_VDIN4		WMT_PIN(2, 4)
86 #define WMT_PIN_VDIN5		WMT_PIN(2, 5)
87 #define WMT_PIN_VDIN6		WMT_PIN(2, 6)
88 #define WMT_PIN_VDIN7		WMT_PIN(2, 7)
89 #define WMT_PIN_I2C1SCL		WMT_PIN(2, 12)
90 #define WMT_PIN_I2C1SDA		WMT_PIN(2, 13)
91 #define WMT_PIN_SPI0MOSI	WMT_PIN(2, 24)
92 #define WMT_PIN_SPI0MISO	WMT_PIN(2, 25)
93 #define WMT_PIN_SPI0SS0		WMT_PIN(2, 26)
94 #define WMT_PIN_SPI0CLK		WMT_PIN(2, 27)
95 #define WMT_PIN_SD0DATA0	WMT_PIN(3, 8)
96 #define WMT_PIN_SD0DATA1	WMT_PIN(3, 9)
97 #define WMT_PIN_SD0DATA2	WMT_PIN(3, 10)
98 #define WMT_PIN_SD0DATA3	WMT_PIN(3, 11)
99 #define WMT_PIN_SD0CLK		WMT_PIN(3, 12)
100 #define WMT_PIN_SD0WP		WMT_PIN(3, 13)
101 #define WMT_PIN_SD0CMD		WMT_PIN(3, 14)
102 #define WMT_PIN_SD1DATA0	WMT_PIN(3, 24)
103 #define WMT_PIN_SD1DATA1	WMT_PIN(3, 25)
104 #define WMT_PIN_SD1DATA2	WMT_PIN(3, 26)
105 #define WMT_PIN_SD1DATA3	WMT_PIN(3, 27)
106 #define WMT_PIN_SD1DATA4	WMT_PIN(3, 28)
107 #define WMT_PIN_SD1DATA5	WMT_PIN(3, 29)
108 #define WMT_PIN_SD1DATA6	WMT_PIN(3, 30)
109 #define WMT_PIN_SD1DATA7	WMT_PIN(3, 31)
110 #define WMT_PIN_I2C0SCL		WMT_PIN(5, 8)
111 #define WMT_PIN_I2C0SDA		WMT_PIN(5, 9)
112 #define WMT_PIN_UART0RTS	WMT_PIN(5, 16)
113 #define WMT_PIN_UART0TXD	WMT_PIN(5, 17)
114 #define WMT_PIN_UART0CTS	WMT_PIN(5, 18)
115 #define WMT_PIN_UART0RXD	WMT_PIN(5, 19)
116 #define WMT_PIN_UART1RTS	WMT_PIN(5, 20)
117 #define WMT_PIN_UART1TXD	WMT_PIN(5, 21)
118 #define WMT_PIN_UART1CTS	WMT_PIN(5, 22)
119 #define WMT_PIN_UART1RXD	WMT_PIN(5, 23)
120 #define WMT_PIN_UART2RTS	WMT_PIN(5, 24)
121 #define WMT_PIN_UART2TXD	WMT_PIN(5, 25)
122 #define WMT_PIN_UART2CTS	WMT_PIN(5, 26)
123 #define WMT_PIN_UART2RXD	WMT_PIN(5, 27)
124 #define WMT_PIN_UART3RTS	WMT_PIN(5, 28)
125 #define WMT_PIN_UART3TXD	WMT_PIN(5, 29)
126 #define WMT_PIN_UART3CTS	WMT_PIN(5, 30)
127 #define WMT_PIN_UART3RXD	WMT_PIN(5, 31)
128 #define WMT_PIN_KPADROW0	WMT_PIN(6, 16)
129 #define WMT_PIN_KPADROW1	WMT_PIN(6, 17)
130 #define WMT_PIN_KPADCOL0	WMT_PIN(6, 18)
131 #define WMT_PIN_KPADCOL1	WMT_PIN(6, 19)
132 #define WMT_PIN_SD1CLK		WMT_PIN(7, 0)
133 #define WMT_PIN_SD1CMD		WMT_PIN(7, 1)
134 #define WMT_PIN_SD1WP		WMT_PIN(7, 13)
135 
136 static const struct pinctrl_pin_desc wm8650_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_SUSGPIO0, "susgpio0"),
148 	PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
149 	PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
150 	PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
151 	PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
152 	PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
153 	PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
154 	PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
155 	PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
156 	PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
157 	PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
158 	PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
159 	PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
160 	PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
161 	PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
162 	PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
163 	PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
164 	PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
165 	PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
166 	PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
167 	PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
168 	PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
169 	PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
170 	PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
171 	PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
172 	PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
173 	PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
174 	PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
175 	PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
176 	PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
177 	PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
178 	PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
179 	PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
180 	PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
181 	PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
182 	PINCTRL_PIN(WMT_PIN_I2C1SCL, "i2c1_scl"),
183 	PINCTRL_PIN(WMT_PIN_I2C1SDA, "i2c1_sda"),
184 	PINCTRL_PIN(WMT_PIN_SPI0MOSI, "spi0_mosi"),
185 	PINCTRL_PIN(WMT_PIN_SPI0MISO, "spi0_miso"),
186 	PINCTRL_PIN(WMT_PIN_SPI0SS0, "spi0_ss0"),
187 	PINCTRL_PIN(WMT_PIN_SPI0CLK, "spi0_clk"),
188 	PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
189 	PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
190 	PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
191 	PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
192 	PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
193 	PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
194 	PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
195 	PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
196 	PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
197 	PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
198 	PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
199 	PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
200 	PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
201 	PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
202 	PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
203 	PINCTRL_PIN(WMT_PIN_I2C0SCL, "i2c0_scl"),
204 	PINCTRL_PIN(WMT_PIN_I2C0SDA, "i2c0_sda"),
205 	PINCTRL_PIN(WMT_PIN_UART0RTS, "uart0_rts"),
206 	PINCTRL_PIN(WMT_PIN_UART0TXD, "uart0_txd"),
207 	PINCTRL_PIN(WMT_PIN_UART0CTS, "uart0_cts"),
208 	PINCTRL_PIN(WMT_PIN_UART0RXD, "uart0_rxd"),
209 	PINCTRL_PIN(WMT_PIN_UART1RTS, "uart1_rts"),
210 	PINCTRL_PIN(WMT_PIN_UART1TXD, "uart1_txd"),
211 	PINCTRL_PIN(WMT_PIN_UART1CTS, "uart1_cts"),
212 	PINCTRL_PIN(WMT_PIN_UART1RXD, "uart1_rxd"),
213 	PINCTRL_PIN(WMT_PIN_UART2RTS, "uart2_rts"),
214 	PINCTRL_PIN(WMT_PIN_UART2TXD, "uart2_txd"),
215 	PINCTRL_PIN(WMT_PIN_UART2CTS, "uart2_cts"),
216 	PINCTRL_PIN(WMT_PIN_UART2RXD, "uart2_rxd"),
217 	PINCTRL_PIN(WMT_PIN_UART3RTS, "uart3_rts"),
218 	PINCTRL_PIN(WMT_PIN_UART3TXD, "uart3_txd"),
219 	PINCTRL_PIN(WMT_PIN_UART3CTS, "uart3_cts"),
220 	PINCTRL_PIN(WMT_PIN_UART3RXD, "uart3_rxd"),
221 	PINCTRL_PIN(WMT_PIN_KPADROW0, "kpadrow0"),
222 	PINCTRL_PIN(WMT_PIN_KPADROW1, "kpadrow1"),
223 	PINCTRL_PIN(WMT_PIN_KPADCOL0, "kpadcol0"),
224 	PINCTRL_PIN(WMT_PIN_KPADCOL1, "kpadcol1"),
225 	PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
226 	PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
227 	PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
228 };
229 
230 /* Order of these names must match the above list */
231 static const char * const wm8650_groups[] = {
232 	"extgpio0",
233 	"extgpio1",
234 	"extgpio2",
235 	"extgpio3",
236 	"extgpio4",
237 	"extgpio5",
238 	"extgpio6",
239 	"extgpio7",
240 	"wakeup0",
241 	"wakeup1",
242 	"susgpio0",
243 	"sd0_cd",
244 	"sd1_cd",
245 	"vdout0",
246 	"vdout1",
247 	"vdout2",
248 	"vdout3",
249 	"vdout4",
250 	"vdout5",
251 	"vdout6",
252 	"vdout7",
253 	"vdout8",
254 	"vdout9",
255 	"vdout10",
256 	"vdout11",
257 	"vdout12",
258 	"vdout13",
259 	"vdout14",
260 	"vdout15",
261 	"vdout16",
262 	"vdout17",
263 	"vdout18",
264 	"vdout19",
265 	"vdout20",
266 	"vdout21",
267 	"vdout22",
268 	"vdout23",
269 	"vdin0",
270 	"vdin1",
271 	"vdin2",
272 	"vdin3",
273 	"vdin4",
274 	"vdin5",
275 	"vdin6",
276 	"vdin7",
277 	"i2c1_scl",
278 	"i2c1_sda",
279 	"spi0_mosi",
280 	"spi0_miso",
281 	"spi0_ss0",
282 	"spi0_clk",
283 	"sd0_data0",
284 	"sd0_data1",
285 	"sd0_data2",
286 	"sd0_data3",
287 	"sd0_clk",
288 	"sd0_wp",
289 	"sd0_cmd",
290 	"sd1_data0",
291 	"sd1_data1",
292 	"sd1_data2",
293 	"sd1_data3",
294 	"sd1_data4",
295 	"sd1_data5",
296 	"sd1_data6",
297 	"sd1_data7",
298 	"i2c0_scl",
299 	"i2c0_sda",
300 	"uart0_rts",
301 	"uart0_txd",
302 	"uart0_cts",
303 	"uart0_rxd",
304 	"uart1_rts",
305 	"uart1_txd",
306 	"uart1_cts",
307 	"uart1_rxd",
308 	"uart2_rts",
309 	"uart2_txd",
310 	"uart2_cts",
311 	"uart2_rxd",
312 	"uart3_rts",
313 	"uart3_txd",
314 	"uart3_cts",
315 	"uart3_rxd",
316 	"kpadrow0",
317 	"kpadrow1",
318 	"kpadcol0",
319 	"kpadcol1",
320 	"sd1_clk",
321 	"sd1_cmd",
322 	"sd1_wp",
323 };
324 
325 static int wm8650_pinctrl_probe(struct platform_device *pdev)
326 {
327 	struct wmt_pinctrl_data *data;
328 
329 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
330 	if (!data) {
331 		dev_err(&pdev->dev, "failed to allocate data\n");
332 		return -ENOMEM;
333 	}
334 
335 	data->banks = wm8650_banks;
336 	data->nbanks = ARRAY_SIZE(wm8650_banks);
337 	data->pins = wm8650_pins;
338 	data->npins = ARRAY_SIZE(wm8650_pins);
339 	data->groups = wm8650_groups;
340 	data->ngroups = ARRAY_SIZE(wm8650_groups);
341 
342 	return wmt_pinctrl_probe(pdev, data);
343 }
344 
345 static int wm8650_pinctrl_remove(struct platform_device *pdev)
346 {
347 	return wmt_pinctrl_remove(pdev);
348 }
349 
350 static const struct of_device_id wmt_pinctrl_of_match[] = {
351 	{ .compatible = "wm,wm8650-pinctrl" },
352 	{ /* sentinel */ },
353 };
354 
355 static struct platform_driver wmt_pinctrl_driver = {
356 	.probe	= wm8650_pinctrl_probe,
357 	.remove	= wm8650_pinctrl_remove,
358 	.driver = {
359 		.name	= "pinctrl-wm8650",
360 		.of_match_table	= wmt_pinctrl_of_match,
361 	},
362 };
363 
364 module_platform_driver(wmt_pinctrl_driver);
365 
366 MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
367 MODULE_DESCRIPTION("Wondermedia WM8650 Pincontrol driver");
368 MODULE_LICENSE("GPL v2");
369 MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);
370