summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/vt8500/pinctrl-wm8850.c
blob: ecadce9c91d53ca538ef15e82e41870568166cda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
 * Pinctrl data for Wondermedia WM8850 SoC
 *
 * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#include <linux/io.h>
#include <linux/module.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

#include "pinctrl-wmt.h"

/*
 * Describe the register offsets within the GPIO memory space
 * The dedicated external GPIO's should always be listed in bank 0
 * so they are exported in the 0..31 range which is what users
 * expect.
 *
 * Do not reorder these banks as it will change the pin numbering
 */
static const struct wmt_pinctrl_bank_registers wm8850_banks[] = {
	WMT_PINCTRL_BANK(0x40, 0x80, 0xC0, 0x00, 0x480, 0x4C0),		/* 0 */
	WMT_PINCTRL_BANK(0x44, 0x84, 0xC4, 0x04, 0x484, 0x4C4),		/* 1 */
	WMT_PINCTRL_BANK(0x48, 0x88, 0xC8, 0x08, 0x488, 0x4C8),		/* 2 */
	WMT_PINCTRL_BANK(0x4C, 0x8C, 0xCC, 0x0C, 0x48C, 0x4CC),		/* 3 */
	WMT_PINCTRL_BANK(0x50, 0x90, 0xD0, 0x10, 0x490, 0x4D0),		/* 4 */
	WMT_PINCTRL_BANK(0x54, 0x94, 0xD4, 0x14, 0x494, 0x4D4),		/* 5 */
	WMT_PINCTRL_BANK(0x58, 0x98, 0xD8, 0x18, 0x498, 0x4D8),		/* 6 */
	WMT_PINCTRL_BANK(0x5C, 0x9C, 0xDC, 0x1C, 0x49C, 0x4DC),		/* 7 */
	WMT_PINCTRL_BANK(0x60, 0xA0, 0xE0, 0x20, 0x4A0, 0x4E0),		/* 8 */
	WMT_PINCTRL_BANK(0x70, 0xB0, 0xF0, 0x30, 0x4B0, 0x4F0),		/* 9 */
	WMT_PINCTRL_BANK(0x7C, 0xBC, 0xDC, 0x3C, 0x4BC, 0x4FC),		/* 10 */
};

/* Please keep sorted by bank/bit */
#define WMT_PIN_EXTGPIO0	WMT_PIN(0, 0)
#define WMT_PIN_EXTGPIO1	WMT_PIN(0, 1)
#define WMT_PIN_EXTGPIO2	WMT_PIN(0, 2)
#define WMT_PIN_EXTGPIO3	WMT_PIN(0, 3)
#define WMT_PIN_EXTGPIO4	WMT_PIN(0, 4)
#define WMT_PIN_EXTGPIO5	WMT_PIN(0, 5)
#define WMT_PIN_EXTGPIO6	WMT_PIN(0, 6)
#define WMT_PIN_EXTGPIO7	WMT_PIN(0, 7)
#define WMT_PIN_WAKEUP0		WMT_PIN(0, 16)
#define WMT_PIN_WAKEUP1		WMT_PIN(0, 17)
#define WMT_PIN_WAKEUP2		WMT_PIN(0, 18)
#define WMT_PIN_WAKEUP3		WMT_PIN(0, 19)
#define WMT_PIN_SUSGPIO0	WMT_PIN(0, 21)
#define WMT_PIN_SUSGPIO1	WMT_PIN(0, 22)
#define WMT_PIN_SD0CD		WMT_PIN(0, 28)
#define WMT_PIN_VDOUT0		WMT_PIN(1, 0)
#define WMT_PIN_VDOUT1		WMT_PIN(1, 1)
#define WMT_PIN_VDOUT2		WMT_PIN(1, 2)
#define WMT_PIN_VDOUT3		WMT_PIN(1, 3)
#define WMT_PIN_VDOUT4		WMT_PIN(1, 4)
#define WMT_PIN_VDOUT5		WMT_PIN(1, 5)
#define WMT_PIN_VDOUT6		WMT_PIN(1, 6)
#define WMT_PIN_VDOUT7		WMT_PIN(1, 7)
#define WMT_PIN_VDOUT8		WMT_PIN(1, 8)
#define WMT_PIN_VDOUT9		WMT_PIN(1, 9)
#define WMT_PIN_VDOUT10		WMT_PIN(1, 10)
#define WMT_PIN_VDOUT11		WMT_PIN(1, 11)
#define WMT_PIN_VDOUT12		WMT_PIN(1, 12)
#define WMT_PIN_VDOUT13		WMT_PIN(1, 13)
#define WMT_PIN_VDOUT14		WMT_PIN(1, 14)
#define WMT_PIN_VDOUT15		WMT_PIN(1, 15)
#define WMT_PIN_VDOUT16		WMT_PIN(1, 16)
#define WMT_PIN_VDOUT17		WMT_PIN(1, 17)
#define WMT_PIN_VDOUT18		WMT_PIN(1, 18)
#define WMT_PIN_VDOUT19		WMT_PIN(1, 19)
#define WMT_PIN_VDOUT20		WMT_PIN(1, 20)
#define WMT_PIN_VDOUT21		WMT_PIN(1, 21)
#define WMT_PIN_VDOUT22		WMT_PIN(1, 22)
#define WMT_PIN_VDOUT23		WMT_PIN(1, 23)
#define WMT_PIN_VDIN0		WMT_PIN(2, 0)
#define WMT_PIN_VDIN1		WMT_PIN(2, 1)
#define WMT_PIN_VDIN2		WMT_PIN(2, 2)
#define WMT_PIN_VDIN3		WMT_PIN(2, 3)
#define WMT_PIN_VDIN4		WMT_PIN(2, 4)
#define WMT_PIN_VDIN5		WMT_PIN(2, 5)
#define WMT_PIN_VDIN6		WMT_PIN(2, 6)
#define WMT_PIN_VDIN7		WMT_PIN(2, 7)
#define WMT_PIN_SPI0_MOSI	WMT_PIN(2, 24)
#define WMT_PIN_SPI0_MISO	WMT_PIN(2, 25)
#define WMT_PIN_SPI0_SS		WMT_PIN(2, 26)
#define WMT_PIN_SPI0_CLK	WMT_PIN(2, 27)
#define WMT_PIN_SPI0_SSB	WMT_PIN(2, 28)
#define WMT_PIN_SD0CLK		WMT_PIN(3, 17)
#define WMT_PIN_SD0CMD		WMT_PIN(3, 18)
#define WMT_PIN_SD0WP		WMT_PIN(3, 19)
#define WMT_PIN_SD0DATA0	WMT_PIN(3, 20)
#define WMT_PIN_SD0DATA1	WMT_PIN(3, 21)
#define WMT_PIN_SD0DATA2	WMT_PIN(3, 22)
#define WMT_PIN_SD0DATA3	WMT_PIN(3, 23)
#define WMT_PIN_SD1DATA0	WMT_PIN(3, 24)
#define WMT_PIN_SD1DATA1	WMT_PIN(3, 25)
#define WMT_PIN_SD1DATA2	WMT_PIN(3, 26)
#define WMT_PIN_SD1DATA3	WMT_PIN(3, 27)
#define WMT_PIN_SD1DATA4	WMT_PIN(3, 28)
#define WMT_PIN_SD1DATA5	WMT_PIN(3, 29)
#define WMT_PIN_SD1DATA6	WMT_PIN(3, 30)
#define WMT_PIN_SD1DATA7	WMT_PIN(3, 31)
#define WMT_PIN_I2C0_SCL	WMT_PIN(5, 8)
#define WMT_PIN_I2C0_SDA	WMT_PIN(5, 9)
#define WMT_PIN_I2C1_SCL	WMT_PIN(5, 10)
#define WMT_PIN_I2C1_SDA	WMT_PIN(5, 11)
#define WMT_PIN_I2C2_SCL	WMT_PIN(5, 12)
#define WMT_PIN_I2C2_SDA	WMT_PIN(5, 13)
#define WMT_PIN_UART0_RTS	WMT_PIN(5, 16)
#define WMT_PIN_UART0_TXD	WMT_PIN(5, 17)
#define WMT_PIN_UART0_CTS	WMT_PIN(5, 18)
#define WMT_PIN_UART0_RXD	WMT_PIN(5, 19)
#define WMT_PIN_UART1_RTS	WMT_PIN(5, 20)
#define WMT_PIN_UART1_TXD	WMT_PIN(5, 21)
#define WMT_PIN_UART1_CTS	WMT_PIN(5, 22)
#define WMT_PIN_UART1_RXD	WMT_PIN(5, 23)
#define WMT_PIN_UART2_RTS	WMT_PIN(5, 24)
#define WMT_PIN_UART2_TXD	WMT_PIN(5, 25)
#define WMT_PIN_UART2_CTS	WMT_PIN(5, 26)
#define WMT_PIN_UART2_RXD	WMT_PIN(5, 27)
#define WMT_PIN_SD2WP		WMT_PIN(6, 3)
#define WMT_PIN_SD2CMD		WMT_PIN(6, 6)
#define WMT_PIN_SD2CLK		WMT_PIN(6, 7)
#define WMT_PIN_SD2PWR		WMT_PIN(6, 9)
#define WMT_PIN_SD1CLK		WMT_PIN(7, 0)
#define WMT_PIN_SD1CMD		WMT_PIN(7, 1)
#define WMT_PIN_SD1PWR		WMT_PIN(7, 10)
#define WMT_PIN_SD1WP		WMT_PIN(7, 11)
#define WMT_PIN_SD1CD		WMT_PIN(7, 12)
#define WMT_PIN_PWMOUT1		WMT_PIN(7, 26)
#define WMT_PIN_PWMOUT0		WMT_PIN(7, 27)

static const struct pinctrl_pin_desc wm8850_pins[] = {
	PINCTRL_PIN(WMT_PIN_EXTGPIO0, "extgpio0"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO1, "extgpio1"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO2, "extgpio2"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO3, "extgpio3"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO4, "extgpio4"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO5, "extgpio5"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO6, "extgpio6"),
	PINCTRL_PIN(WMT_PIN_EXTGPIO7, "extgpio7"),
	PINCTRL_PIN(WMT_PIN_WAKEUP0, "wakeup0"),
	PINCTRL_PIN(WMT_PIN_WAKEUP1, "wakeup1"),
	PINCTRL_PIN(WMT_PIN_WAKEUP2, "wakeup2"),
	PINCTRL_PIN(WMT_PIN_WAKEUP3, "wakeup3"),
	PINCTRL_PIN(WMT_PIN_SUSGPIO0, "susgpio0"),
	PINCTRL_PIN(WMT_PIN_SUSGPIO1, "susgpio1"),
	PINCTRL_PIN(WMT_PIN_SD0CD, "sd0_cd"),
	PINCTRL_PIN(WMT_PIN_VDOUT0, "vdout0"),
	PINCTRL_PIN(WMT_PIN_VDOUT1, "vdout1"),
	PINCTRL_PIN(WMT_PIN_VDOUT2, "vdout2"),
	PINCTRL_PIN(WMT_PIN_VDOUT3, "vdout3"),
	PINCTRL_PIN(WMT_PIN_VDOUT4, "vdout4"),
	PINCTRL_PIN(WMT_PIN_VDOUT5, "vdout5"),
	PINCTRL_PIN(WMT_PIN_VDOUT6, "vdout6"),
	PINCTRL_PIN(WMT_PIN_VDOUT7, "vdout7"),
	PINCTRL_PIN(WMT_PIN_VDOUT8, "vdout8"),
	PINCTRL_PIN(WMT_PIN_VDOUT9, "vdout9"),
	PINCTRL_PIN(WMT_PIN_VDOUT10, "vdout10"),
	PINCTRL_PIN(WMT_PIN_VDOUT11, "vdout11"),
	PINCTRL_PIN(WMT_PIN_VDOUT12, "vdout12"),
	PINCTRL_PIN(WMT_PIN_VDOUT13, "vdout13"),
	PINCTRL_PIN(WMT_PIN_VDOUT14, "vdout14"),
	PINCTRL_PIN(WMT_PIN_VDOUT15, "vdout15"),
	PINCTRL_PIN(WMT_PIN_VDOUT16, "vdout16"),
	PINCTRL_PIN(WMT_PIN_VDOUT17, "vdout17"),
	PINCTRL_PIN(WMT_PIN_VDOUT18, "vdout18"),
	PINCTRL_PIN(WMT_PIN_VDOUT19, "vdout19"),
	PINCTRL_PIN(WMT_PIN_VDOUT20, "vdout20"),
	PINCTRL_PIN(WMT_PIN_VDOUT21, "vdout21"),
	PINCTRL_PIN(WMT_PIN_VDOUT22, "vdout22"),
	PINCTRL_PIN(WMT_PIN_VDOUT23, "vdout23"),
	PINCTRL_PIN(WMT_PIN_VDIN0, "vdin0"),
	PINCTRL_PIN(WMT_PIN_VDIN1, "vdin1"),
	PINCTRL_PIN(WMT_PIN_VDIN2, "vdin2"),
	PINCTRL_PIN(WMT_PIN_VDIN3, "vdin3"),
	PINCTRL_PIN(WMT_PIN_VDIN4, "vdin4"),
	PINCTRL_PIN(WMT_PIN_VDIN5, "vdin5"),
	PINCTRL_PIN(WMT_PIN_VDIN6, "vdin6"),
	PINCTRL_PIN(WMT_PIN_VDIN7, "vdin7"),
	PINCTRL_PIN(WMT_PIN_SPI0_MOSI, "spi0_mosi"),
	PINCTRL_PIN(WMT_PIN_SPI0_MISO, "spi0_miso"),
	PINCTRL_PIN(WMT_PIN_SPI0_SS, "spi0_ss"),
	PINCTRL_PIN(WMT_PIN_SPI0_CLK, "spi0_clk"),
	PINCTRL_PIN(WMT_PIN_SPI0_SSB, "spi0_ssb"),
	PINCTRL_PIN(WMT_PIN_SD0CLK, "sd0_clk"),
	PINCTRL_PIN(WMT_PIN_SD0CMD, "sd0_cmd"),
	PINCTRL_PIN(WMT_PIN_SD0WP, "sd0_wp"),
	PINCTRL_PIN(WMT_PIN_SD0DATA0, "sd0_data0"),
	PINCTRL_PIN(WMT_PIN_SD0DATA1, "sd0_data1"),
	PINCTRL_PIN(WMT_PIN_SD0DATA2, "sd0_data2"),
	PINCTRL_PIN(WMT_PIN_SD0DATA3, "sd0_data3"),
	PINCTRL_PIN(WMT_PIN_SD1DATA0, "sd1_data0"),
	PINCTRL_PIN(WMT_PIN_SD1DATA1, "sd1_data1"),
	PINCTRL_PIN(WMT_PIN_SD1DATA2, "sd1_data2"),
	PINCTRL_PIN(WMT_PIN_SD1DATA3, "sd1_data3"),
	PINCTRL_PIN(WMT_PIN_SD1DATA4, "sd1_data4"),
	PINCTRL_PIN(WMT_PIN_SD1DATA5, "sd1_data5"),
	PINCTRL_PIN(WMT_PIN_SD1DATA6, "sd1_data6"),
	PINCTRL_PIN(WMT_PIN_SD1DATA7, "sd1_data7"),
	PINCTRL_PIN(WMT_PIN_I2C0_SCL, "i2c0_scl"),
	PINCTRL_PIN(WMT_PIN_I2C0_SDA, "i2c0_sda"),
	PINCTRL_PIN(WMT_PIN_I2C1_SCL, "i2c1_scl"),
	PINCTRL_PIN(WMT_PIN_I2C1_SDA, "i2c1_sda"),
	PINCTRL_PIN(WMT_PIN_I2C2_SCL, "i2c2_scl"),
	PINCTRL_PIN(WMT_PIN_I2C2_SDA, "i2c2_sda"),
	PINCTRL_PIN(WMT_PIN_UART0_RTS, "uart0_rts"),
	PINCTRL_PIN(WMT_PIN_UART0_TXD, "uart0_txd"),
	PINCTRL_PIN(WMT_PIN_UART0_CTS, "uart0_cts"),
	PINCTRL_PIN(WMT_PIN_UART0_RXD, "uart0_rxd"),
	PINCTRL_PIN(WMT_PIN_UART1_RTS, "uart1_rts"),
	PINCTRL_PIN(WMT_PIN_UART1_TXD, "uart1_txd"),
	PINCTRL_PIN(WMT_PIN_UART1_CTS, "uart1_cts"),
	PINCTRL_PIN(WMT_PIN_UART1_RXD, "uart1_rxd"),
	PINCTRL_PIN(WMT_PIN_UART2_RTS, "uart2_rts"),
	PINCTRL_PIN(WMT_PIN_UART2_TXD, "uart2_txd"),
	PINCTRL_PIN(WMT_PIN_UART2_CTS, "uart2_cts"),
	PINCTRL_PIN(WMT_PIN_UART2_RXD, "uart2_rxd"),
	PINCTRL_PIN(WMT_PIN_SD2WP, "sd2_wp"),
	PINCTRL_PIN(WMT_PIN_SD2CMD, "sd2_cmd"),
	PINCTRL_PIN(WMT_PIN_SD2CLK, "sd2_clk"),
	PINCTRL_PIN(WMT_PIN_SD2PWR, "sd2_pwr"),
	PINCTRL_PIN(WMT_PIN_SD1CLK, "sd1_clk"),
	PINCTRL_PIN(WMT_PIN_SD1CMD, "sd1_cmd"),
	PINCTRL_PIN(WMT_PIN_SD1PWR, "sd1_pwr"),
	PINCTRL_PIN(WMT_PIN_SD1WP, "sd1_wp"),
	PINCTRL_PIN(WMT_PIN_SD1CD, "sd1_cd"),
	PINCTRL_PIN(WMT_PIN_PWMOUT1, "pwmout1"),
	PINCTRL_PIN(WMT_PIN_PWMOUT0, "pwmout0"),
};

/* Order of these names must match the above list */
static const char * const wm8850_groups[] = {
	"extgpio0",
	"extgpio1",
	"extgpio2",
	"extgpio3",
	"extgpio4",
	"extgpio5",
	"extgpio6",
	"extgpio7",
	"wakeup0",
	"wakeup1",
	"wakeup2",
	"wakeup3",
	"susgpio0",
	"susgpio1",
	"sd0_cd",
	"vdout0",
	"vdout1",
	"vdout2",
	"vdout3",
	"vdout4",
	"vdout5",
	"vdout6",
	"vdout7",
	"vdout8",
	"vdout9",
	"vdout10",
	"vdout11",
	"vdout12",
	"vdout13",
	"vdout14",
	"vdout15",
	"vdout16",
	"vdout17",
	"vdout18",
	"vdout19",
	"vdout20",
	"vdout21",
	"vdout22",
	"vdout23",
	"vdin0",
	"vdin1",
	"vdin2",
	"vdin3",
	"vdin4",
	"vdin5",
	"vdin6",
	"vdin7",
	"spi0_mosi",
	"spi0_miso",
	"spi0_ss",
	"spi0_clk",
	"spi0_ssb",
	"sd0_clk",
	"sd0_cmd",
	"sd0_wp",
	"sd0_data0",
	"sd0_data1",
	"sd0_data2",
	"sd0_data3",
	"sd1_data0",
	"sd1_data1",
	"sd1_data2",
	"sd1_data3",
	"sd1_data4",
	"sd1_data5",
	"sd1_data6",
	"sd1_data7",
	"i2c0_scl",
	"i2c0_sda",
	"i2c1_scl",
	"i2c1_sda",
	"i2c2_scl",
	"i2c2_sda",
	"uart0_rts",
	"uart0_txd",
	"uart0_cts",
	"uart0_rxd",
	"uart1_rts",
	"uart1_txd",
	"uart1_cts",
	"uart1_rxd",
	"uart2_rts",
	"uart2_txd",
	"uart2_cts",
	"uart2_rxd",
	"sd2_wp",
	"sd2_cmd",
	"sd2_clk",
	"sd2_pwr",
	"sd1_clk",
	"sd1_cmd",
	"sd1_pwr",
	"sd1_wp",
	"sd1_cd",
	"pwmout1",
	"pwmout0",
};

static int wm8850_pinctrl_probe(struct platform_device *pdev)
{
	struct wmt_pinctrl_data *data;

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data) {
		dev_err(&pdev->dev, "failed to allocate data\n");
		return -ENOMEM;
	}

	data->banks = wm8850_banks;
	data->nbanks = ARRAY_SIZE(wm8850_banks);
	data->pins = wm8850_pins;
	data->npins = ARRAY_SIZE(wm8850_pins);
	data->groups = wm8850_groups;
	data->ngroups = ARRAY_SIZE(wm8850_groups);

	return wmt_pinctrl_probe(pdev, data);
}

static int wm8850_pinctrl_remove(struct platform_device *pdev)
{
	return wmt_pinctrl_remove(pdev);
}

static struct of_device_id wmt_pinctrl_of_match[] = {
	{ .compatible = "wm,wm8850-pinctrl" },
	{ /* sentinel */ },
};

static struct platform_driver wmt_pinctrl_driver = {
	.probe	= wm8850_pinctrl_probe,
	.remove	= wm8850_pinctrl_remove,
	.driver = {
		.name	= "pinctrl-wm8850",
		.owner	= THIS_MODULE,
		.of_match_table	= wmt_pinctrl_of_match,
	},
};

module_platform_driver(wmt_pinctrl_driver);

MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>");
MODULE_DESCRIPTION("Wondermedia WM8850 Pincontrol driver");
MODULE_LICENSE("GPL v2");
MODULE_DEVICE_TABLE(of, wmt_pinctrl_of_match);