1 /*
2  * VF610 pinctrl driver based on imx pinmux and pinconf core
3  *
4  * Copyright 2013 Freescale Semiconductor, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 
12 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
15 #include <linux/of.h>
16 #include <linux/of_device.h>
17 #include <linux/pinctrl/pinctrl.h>
18 
19 #include "pinctrl-imx.h"
20 
21 enum vf610_pads {
22 	VF610_PAD_PTA6 = 0,
23 	VF610_PAD_PTA8 = 1,
24 	VF610_PAD_PTA9 = 2,
25 	VF610_PAD_PTA10 = 3,
26 	VF610_PAD_PTA11 = 4,
27 	VF610_PAD_PTA12 = 5,
28 	VF610_PAD_PTA16 = 6,
29 	VF610_PAD_PTA17 = 7,
30 	VF610_PAD_PTA18 = 8,
31 	VF610_PAD_PTA19 = 9,
32 	VF610_PAD_PTA20 = 10,
33 	VF610_PAD_PTA21 = 11,
34 	VF610_PAD_PTA22 = 12,
35 	VF610_PAD_PTA23 = 13,
36 	VF610_PAD_PTA24 = 14,
37 	VF610_PAD_PTA25 = 15,
38 	VF610_PAD_PTA26 = 16,
39 	VF610_PAD_PTA27 = 17,
40 	VF610_PAD_PTA28 = 18,
41 	VF610_PAD_PTA29 = 19,
42 	VF610_PAD_PTA30 = 20,
43 	VF610_PAD_PTA31 = 21,
44 	VF610_PAD_PTB0 = 22,
45 	VF610_PAD_PTB1 = 23,
46 	VF610_PAD_PTB2 = 24,
47 	VF610_PAD_PTB3 = 25,
48 	VF610_PAD_PTB4 = 26,
49 	VF610_PAD_PTB5 = 27,
50 	VF610_PAD_PTB6 = 28,
51 	VF610_PAD_PTB7 = 29,
52 	VF610_PAD_PTB8 = 30,
53 	VF610_PAD_PTB9 = 31,
54 	VF610_PAD_PTB10 = 32,
55 	VF610_PAD_PTB11 = 33,
56 	VF610_PAD_PTB12 = 34,
57 	VF610_PAD_PTB13 = 35,
58 	VF610_PAD_PTB14 = 36,
59 	VF610_PAD_PTB15 = 37,
60 	VF610_PAD_PTB16 = 38,
61 	VF610_PAD_PTB17 = 39,
62 	VF610_PAD_PTB18 = 40,
63 	VF610_PAD_PTB19 = 41,
64 	VF610_PAD_PTB20 = 42,
65 	VF610_PAD_PTB21 = 43,
66 	VF610_PAD_PTB22 = 44,
67 	VF610_PAD_PTC0 = 45,
68 	VF610_PAD_PTC1 = 46,
69 	VF610_PAD_PTC2 = 47,
70 	VF610_PAD_PTC3 = 48,
71 	VF610_PAD_PTC4 = 49,
72 	VF610_PAD_PTC5 = 50,
73 	VF610_PAD_PTC6 = 51,
74 	VF610_PAD_PTC7 = 52,
75 	VF610_PAD_PTC8 = 53,
76 	VF610_PAD_PTC9 = 54,
77 	VF610_PAD_PTC10 = 55,
78 	VF610_PAD_PTC11 = 56,
79 	VF610_PAD_PTC12 = 57,
80 	VF610_PAD_PTC13 = 58,
81 	VF610_PAD_PTC14 = 59,
82 	VF610_PAD_PTC15 = 60,
83 	VF610_PAD_PTC16 = 61,
84 	VF610_PAD_PTC17 = 62,
85 	VF610_PAD_PTD31 = 63,
86 	VF610_PAD_PTD30 = 64,
87 	VF610_PAD_PTD29 = 65,
88 	VF610_PAD_PTD28 = 66,
89 	VF610_PAD_PTD27 = 67,
90 	VF610_PAD_PTD26 = 68,
91 	VF610_PAD_PTD25 = 69,
92 	VF610_PAD_PTD24 = 70,
93 	VF610_PAD_PTD23 = 71,
94 	VF610_PAD_PTD22 = 72,
95 	VF610_PAD_PTD21 = 73,
96 	VF610_PAD_PTD20 = 74,
97 	VF610_PAD_PTD19 = 75,
98 	VF610_PAD_PTD18 = 76,
99 	VF610_PAD_PTD17 = 77,
100 	VF610_PAD_PTD16 = 78,
101 	VF610_PAD_PTD0 = 79,
102 	VF610_PAD_PTD1 = 80,
103 	VF610_PAD_PTD2 = 81,
104 	VF610_PAD_PTD3 = 82,
105 	VF610_PAD_PTD4 = 83,
106 	VF610_PAD_PTD5 = 84,
107 	VF610_PAD_PTD6 = 85,
108 	VF610_PAD_PTD7 = 86,
109 	VF610_PAD_PTD8 = 87,
110 	VF610_PAD_PTD9 = 88,
111 	VF610_PAD_PTD10 = 89,
112 	VF610_PAD_PTD11 = 90,
113 	VF610_PAD_PTD12 = 91,
114 	VF610_PAD_PTD13 = 92,
115 	VF610_PAD_PTB23 = 93,
116 	VF610_PAD_PTB24 = 94,
117 	VF610_PAD_PTB25 = 95,
118 	VF610_PAD_PTB26 = 96,
119 	VF610_PAD_PTB27 = 97,
120 	VF610_PAD_PTB28 = 98,
121 	VF610_PAD_PTC26 = 99,
122 	VF610_PAD_PTC27 = 100,
123 	VF610_PAD_PTC28 = 101,
124 	VF610_PAD_PTC29 = 102,
125 	VF610_PAD_PTC30 = 103,
126 	VF610_PAD_PTC31 = 104,
127 	VF610_PAD_PTE0 = 105,
128 	VF610_PAD_PTE1 = 106,
129 	VF610_PAD_PTE2 = 107,
130 	VF610_PAD_PTE3 = 108,
131 	VF610_PAD_PTE4 = 109,
132 	VF610_PAD_PTE5 = 110,
133 	VF610_PAD_PTE6 = 111,
134 	VF610_PAD_PTE7 = 112,
135 	VF610_PAD_PTE8 = 113,
136 	VF610_PAD_PTE9 = 114,
137 	VF610_PAD_PTE10 = 115,
138 	VF610_PAD_PTE11 = 116,
139 	VF610_PAD_PTE12 = 117,
140 	VF610_PAD_PTE13 = 118,
141 	VF610_PAD_PTE14 = 119,
142 	VF610_PAD_PTE15 = 120,
143 	VF610_PAD_PTE16 = 121,
144 	VF610_PAD_PTE17 = 122,
145 	VF610_PAD_PTE18 = 123,
146 	VF610_PAD_PTE19 = 124,
147 	VF610_PAD_PTE20 = 125,
148 	VF610_PAD_PTE21 = 126,
149 	VF610_PAD_PTE22 = 127,
150 	VF610_PAD_PTE23 = 128,
151 	VF610_PAD_PTE24 = 129,
152 	VF610_PAD_PTE25 = 130,
153 	VF610_PAD_PTE26 = 131,
154 	VF610_PAD_PTE27 = 132,
155 	VF610_PAD_PTE28 = 133,
156 	VF610_PAD_PTA7 = 134,
157 };
158 
159 /* Pad names for the pinmux subsystem */
160 static const struct pinctrl_pin_desc vf610_pinctrl_pads[] = {
161 	IMX_PINCTRL_PIN(VF610_PAD_PTA6),
162 	IMX_PINCTRL_PIN(VF610_PAD_PTA8),
163 	IMX_PINCTRL_PIN(VF610_PAD_PTA9),
164 	IMX_PINCTRL_PIN(VF610_PAD_PTA10),
165 	IMX_PINCTRL_PIN(VF610_PAD_PTA11),
166 	IMX_PINCTRL_PIN(VF610_PAD_PTA12),
167 	IMX_PINCTRL_PIN(VF610_PAD_PTA16),
168 	IMX_PINCTRL_PIN(VF610_PAD_PTA17),
169 	IMX_PINCTRL_PIN(VF610_PAD_PTA18),
170 	IMX_PINCTRL_PIN(VF610_PAD_PTA19),
171 	IMX_PINCTRL_PIN(VF610_PAD_PTA20),
172 	IMX_PINCTRL_PIN(VF610_PAD_PTA21),
173 	IMX_PINCTRL_PIN(VF610_PAD_PTA22),
174 	IMX_PINCTRL_PIN(VF610_PAD_PTA23),
175 	IMX_PINCTRL_PIN(VF610_PAD_PTA24),
176 	IMX_PINCTRL_PIN(VF610_PAD_PTA25),
177 	IMX_PINCTRL_PIN(VF610_PAD_PTA26),
178 	IMX_PINCTRL_PIN(VF610_PAD_PTA27),
179 	IMX_PINCTRL_PIN(VF610_PAD_PTA28),
180 	IMX_PINCTRL_PIN(VF610_PAD_PTA29),
181 	IMX_PINCTRL_PIN(VF610_PAD_PTA30),
182 	IMX_PINCTRL_PIN(VF610_PAD_PTA31),
183 	IMX_PINCTRL_PIN(VF610_PAD_PTB0),
184 	IMX_PINCTRL_PIN(VF610_PAD_PTB1),
185 	IMX_PINCTRL_PIN(VF610_PAD_PTB2),
186 	IMX_PINCTRL_PIN(VF610_PAD_PTB3),
187 	IMX_PINCTRL_PIN(VF610_PAD_PTB4),
188 	IMX_PINCTRL_PIN(VF610_PAD_PTB5),
189 	IMX_PINCTRL_PIN(VF610_PAD_PTB6),
190 	IMX_PINCTRL_PIN(VF610_PAD_PTB7),
191 	IMX_PINCTRL_PIN(VF610_PAD_PTB8),
192 	IMX_PINCTRL_PIN(VF610_PAD_PTB9),
193 	IMX_PINCTRL_PIN(VF610_PAD_PTB10),
194 	IMX_PINCTRL_PIN(VF610_PAD_PTB11),
195 	IMX_PINCTRL_PIN(VF610_PAD_PTB12),
196 	IMX_PINCTRL_PIN(VF610_PAD_PTB13),
197 	IMX_PINCTRL_PIN(VF610_PAD_PTB14),
198 	IMX_PINCTRL_PIN(VF610_PAD_PTB15),
199 	IMX_PINCTRL_PIN(VF610_PAD_PTB16),
200 	IMX_PINCTRL_PIN(VF610_PAD_PTB17),
201 	IMX_PINCTRL_PIN(VF610_PAD_PTB18),
202 	IMX_PINCTRL_PIN(VF610_PAD_PTB19),
203 	IMX_PINCTRL_PIN(VF610_PAD_PTB20),
204 	IMX_PINCTRL_PIN(VF610_PAD_PTB21),
205 	IMX_PINCTRL_PIN(VF610_PAD_PTB22),
206 	IMX_PINCTRL_PIN(VF610_PAD_PTC0),
207 	IMX_PINCTRL_PIN(VF610_PAD_PTC1),
208 	IMX_PINCTRL_PIN(VF610_PAD_PTC2),
209 	IMX_PINCTRL_PIN(VF610_PAD_PTC3),
210 	IMX_PINCTRL_PIN(VF610_PAD_PTC4),
211 	IMX_PINCTRL_PIN(VF610_PAD_PTC5),
212 	IMX_PINCTRL_PIN(VF610_PAD_PTC6),
213 	IMX_PINCTRL_PIN(VF610_PAD_PTC7),
214 	IMX_PINCTRL_PIN(VF610_PAD_PTC8),
215 	IMX_PINCTRL_PIN(VF610_PAD_PTC9),
216 	IMX_PINCTRL_PIN(VF610_PAD_PTC10),
217 	IMX_PINCTRL_PIN(VF610_PAD_PTC11),
218 	IMX_PINCTRL_PIN(VF610_PAD_PTC12),
219 	IMX_PINCTRL_PIN(VF610_PAD_PTC13),
220 	IMX_PINCTRL_PIN(VF610_PAD_PTC14),
221 	IMX_PINCTRL_PIN(VF610_PAD_PTC15),
222 	IMX_PINCTRL_PIN(VF610_PAD_PTC16),
223 	IMX_PINCTRL_PIN(VF610_PAD_PTC17),
224 	IMX_PINCTRL_PIN(VF610_PAD_PTD31),
225 	IMX_PINCTRL_PIN(VF610_PAD_PTD30),
226 	IMX_PINCTRL_PIN(VF610_PAD_PTD29),
227 	IMX_PINCTRL_PIN(VF610_PAD_PTD28),
228 	IMX_PINCTRL_PIN(VF610_PAD_PTD27),
229 	IMX_PINCTRL_PIN(VF610_PAD_PTD26),
230 	IMX_PINCTRL_PIN(VF610_PAD_PTD25),
231 	IMX_PINCTRL_PIN(VF610_PAD_PTD24),
232 	IMX_PINCTRL_PIN(VF610_PAD_PTD23),
233 	IMX_PINCTRL_PIN(VF610_PAD_PTD22),
234 	IMX_PINCTRL_PIN(VF610_PAD_PTD21),
235 	IMX_PINCTRL_PIN(VF610_PAD_PTD20),
236 	IMX_PINCTRL_PIN(VF610_PAD_PTD19),
237 	IMX_PINCTRL_PIN(VF610_PAD_PTD18),
238 	IMX_PINCTRL_PIN(VF610_PAD_PTD17),
239 	IMX_PINCTRL_PIN(VF610_PAD_PTD16),
240 	IMX_PINCTRL_PIN(VF610_PAD_PTD0),
241 	IMX_PINCTRL_PIN(VF610_PAD_PTD1),
242 	IMX_PINCTRL_PIN(VF610_PAD_PTD2),
243 	IMX_PINCTRL_PIN(VF610_PAD_PTD3),
244 	IMX_PINCTRL_PIN(VF610_PAD_PTD4),
245 	IMX_PINCTRL_PIN(VF610_PAD_PTD5),
246 	IMX_PINCTRL_PIN(VF610_PAD_PTD6),
247 	IMX_PINCTRL_PIN(VF610_PAD_PTD7),
248 	IMX_PINCTRL_PIN(VF610_PAD_PTD8),
249 	IMX_PINCTRL_PIN(VF610_PAD_PTD9),
250 	IMX_PINCTRL_PIN(VF610_PAD_PTD10),
251 	IMX_PINCTRL_PIN(VF610_PAD_PTD11),
252 	IMX_PINCTRL_PIN(VF610_PAD_PTD12),
253 	IMX_PINCTRL_PIN(VF610_PAD_PTD13),
254 	IMX_PINCTRL_PIN(VF610_PAD_PTB23),
255 	IMX_PINCTRL_PIN(VF610_PAD_PTB24),
256 	IMX_PINCTRL_PIN(VF610_PAD_PTB25),
257 	IMX_PINCTRL_PIN(VF610_PAD_PTB26),
258 	IMX_PINCTRL_PIN(VF610_PAD_PTB27),
259 	IMX_PINCTRL_PIN(VF610_PAD_PTB28),
260 	IMX_PINCTRL_PIN(VF610_PAD_PTC26),
261 	IMX_PINCTRL_PIN(VF610_PAD_PTC27),
262 	IMX_PINCTRL_PIN(VF610_PAD_PTC28),
263 	IMX_PINCTRL_PIN(VF610_PAD_PTC29),
264 	IMX_PINCTRL_PIN(VF610_PAD_PTC30),
265 	IMX_PINCTRL_PIN(VF610_PAD_PTC31),
266 	IMX_PINCTRL_PIN(VF610_PAD_PTE0),
267 	IMX_PINCTRL_PIN(VF610_PAD_PTE1),
268 	IMX_PINCTRL_PIN(VF610_PAD_PTE2),
269 	IMX_PINCTRL_PIN(VF610_PAD_PTE3),
270 	IMX_PINCTRL_PIN(VF610_PAD_PTE4),
271 	IMX_PINCTRL_PIN(VF610_PAD_PTE5),
272 	IMX_PINCTRL_PIN(VF610_PAD_PTE6),
273 	IMX_PINCTRL_PIN(VF610_PAD_PTE7),
274 	IMX_PINCTRL_PIN(VF610_PAD_PTE8),
275 	IMX_PINCTRL_PIN(VF610_PAD_PTE9),
276 	IMX_PINCTRL_PIN(VF610_PAD_PTE10),
277 	IMX_PINCTRL_PIN(VF610_PAD_PTE11),
278 	IMX_PINCTRL_PIN(VF610_PAD_PTE12),
279 	IMX_PINCTRL_PIN(VF610_PAD_PTE13),
280 	IMX_PINCTRL_PIN(VF610_PAD_PTE14),
281 	IMX_PINCTRL_PIN(VF610_PAD_PTE15),
282 	IMX_PINCTRL_PIN(VF610_PAD_PTE16),
283 	IMX_PINCTRL_PIN(VF610_PAD_PTE17),
284 	IMX_PINCTRL_PIN(VF610_PAD_PTE18),
285 	IMX_PINCTRL_PIN(VF610_PAD_PTE19),
286 	IMX_PINCTRL_PIN(VF610_PAD_PTE20),
287 	IMX_PINCTRL_PIN(VF610_PAD_PTE21),
288 	IMX_PINCTRL_PIN(VF610_PAD_PTE22),
289 	IMX_PINCTRL_PIN(VF610_PAD_PTE23),
290 	IMX_PINCTRL_PIN(VF610_PAD_PTE24),
291 	IMX_PINCTRL_PIN(VF610_PAD_PTE25),
292 	IMX_PINCTRL_PIN(VF610_PAD_PTE26),
293 	IMX_PINCTRL_PIN(VF610_PAD_PTE27),
294 	IMX_PINCTRL_PIN(VF610_PAD_PTE28),
295 	IMX_PINCTRL_PIN(VF610_PAD_PTA7),
296 };
297 
298 static int vf610_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
299 					struct pinctrl_gpio_range *range,
300 					unsigned offset, bool input)
301 {
302 	struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
303 	const struct imx_pin_reg *pin_reg;
304 	u32 reg;
305 
306 	pin_reg = &ipctl->pin_regs[offset];
307 	if (pin_reg->mux_reg == -1)
308 		return -EINVAL;
309 
310 	/* IBE always enabled allows us to read the value "on the wire" */
311 	reg = readl(ipctl->base + pin_reg->mux_reg);
312 	if (input)
313 		reg &= ~0x2;
314 	else
315 		reg |= 0x2;
316 	writel(reg, ipctl->base + pin_reg->mux_reg);
317 
318 	return 0;
319 }
320 
321 static const struct imx_pinctrl_soc_info vf610_pinctrl_info = {
322 	.pins = vf610_pinctrl_pads,
323 	.npins = ARRAY_SIZE(vf610_pinctrl_pads),
324 	.flags = SHARE_MUX_CONF_REG | ZERO_OFFSET_VALID,
325 	.gpio_set_direction = vf610_pmx_gpio_set_direction,
326 	.mux_mask = 0x700000,
327 	.mux_shift = 20,
328 };
329 
330 static const struct of_device_id vf610_pinctrl_of_match[] = {
331 	{ .compatible = "fsl,vf610-iomuxc", },
332 	{ /* sentinel */ }
333 };
334 
335 static int vf610_pinctrl_probe(struct platform_device *pdev)
336 {
337 	return imx_pinctrl_probe(pdev, &vf610_pinctrl_info);
338 }
339 
340 static struct platform_driver vf610_pinctrl_driver = {
341 	.driver = {
342 		.name = "vf610-pinctrl",
343 		.of_match_table = vf610_pinctrl_of_match,
344 	},
345 	.probe = vf610_pinctrl_probe,
346 };
347 
348 static int __init vf610_pinctrl_init(void)
349 {
350 	return platform_driver_register(&vf610_pinctrl_driver);
351 }
352 arch_initcall(vf610_pinctrl_init);
353