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