2 * linux/drivers/pinctrl/pinmux-xway.c
3 * based on linux/drivers/pinctrl/pinmux-pxa910.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * publishhed by the Free Software Foundation.
9 * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/of_platform.h>
15 #include <linux/of_address.h>
16 #include <linux/of_gpio.h>
17 #include <linux/ioport.h>
19 #include <linux/device.h>
20 #include <linux/platform_device.h>
22 #include "pinctrl-lantiq.h"
24 #include <lantiq_soc.h>
26 /* we have 3 1/2 banks of 16 bit each */
29 #define PORT(x) (x / PINS)
30 #define PORT_PIN(x) (x % PINS)
32 /* we have 2 mux bits that can be set for each pin */
37 * each bank has this offset apart from the 1/2 bank that is mixed into the
42 /* these are the offsets to our registers */
43 #define GPIO_BASE(p) (REG_OFF * PORT(p))
44 #define GPIO_OUT(p) GPIO_BASE(p)
45 #define GPIO_IN(p) (GPIO_BASE(p) + 0x04)
46 #define GPIO_DIR(p) (GPIO_BASE(p) + 0x08)
47 #define GPIO_ALT0(p) (GPIO_BASE(p) + 0x0C)
48 #define GPIO_ALT1(p) (GPIO_BASE(p) + 0x10)
49 #define GPIO_OD(p) (GPIO_BASE(p) + 0x14)
50 #define GPIO_PUDSEL(p) (GPIO_BASE(p) + 0x1c)
51 #define GPIO_PUDEN(p) (GPIO_BASE(p) + 0x20)
53 /* the 1/2 port needs special offsets for some registers */
54 #define GPIO3_OD (GPIO_BASE(0) + 0x24)
55 #define GPIO3_PUDSEL (GPIO_BASE(0) + 0x28)
56 #define GPIO3_PUDEN (GPIO_BASE(0) + 0x2C)
57 #define GPIO3_ALT1 (GPIO_BASE(PINS) + 0x24)
59 /* macros to help us access the registers */
60 #define gpio_getbit(m, r, p) (!!(ltq_r32(m + r) & BIT(p)))
61 #define gpio_setbit(m, r, p) ltq_w32_mask(0, BIT(p), m + r)
62 #define gpio_clearbit(m, r, p) ltq_w32_mask(BIT(p), 0, m + r)
64 #define MFP_XWAY(a, f0, f1, f2, f3) \
76 #define GRP_MUX(a, m, p) \
77 { .name = a, .mux = XWAY_MUX_##m, .pins = p, .npins = ARRAY_SIZE(p), }
79 #define FUNC_MUX(f, m) \
80 { .func = f, .mux = XWAY_MUX_##m, }
82 #define XWAY_MAX_PIN 32
83 #define XR9_MAX_PIN 56
104 XWAY_MUX_NONE
= 0xffff,
107 static const struct ltq_mfp_pin xway_mfp
[] = {
108 /* pin f0 f1 f2 f3 */
109 MFP_XWAY(GPIO0
, GPIO
, EXIN
, NONE
, TDM
),
110 MFP_XWAY(GPIO1
, GPIO
, EXIN
, NONE
, NONE
),
111 MFP_XWAY(GPIO2
, GPIO
, CGU
, EXIN
, NONE
),
112 MFP_XWAY(GPIO3
, GPIO
, CGU
, NONE
, PCI
),
113 MFP_XWAY(GPIO4
, GPIO
, STP
, NONE
, ASC
),
114 MFP_XWAY(GPIO5
, GPIO
, STP
, NONE
, NONE
),
115 MFP_XWAY(GPIO6
, GPIO
, STP
, GPT
, ASC
),
116 MFP_XWAY(GPIO7
, GPIO
, CGU
, PCI
, NONE
),
117 MFP_XWAY(GPIO8
, GPIO
, CGU
, NMI
, NONE
),
118 MFP_XWAY(GPIO9
, GPIO
, ASC
, SPI
, EXIN
),
119 MFP_XWAY(GPIO10
, GPIO
, ASC
, SPI
, NONE
),
120 MFP_XWAY(GPIO11
, GPIO
, ASC
, PCI
, SPI
),
121 MFP_XWAY(GPIO12
, GPIO
, ASC
, NONE
, NONE
),
122 MFP_XWAY(GPIO13
, GPIO
, EBU
, SPI
, NONE
),
123 MFP_XWAY(GPIO14
, GPIO
, CGU
, PCI
, NONE
),
124 MFP_XWAY(GPIO15
, GPIO
, SPI
, JTAG
, NONE
),
125 MFP_XWAY(GPIO16
, GPIO
, SPI
, NONE
, JTAG
),
126 MFP_XWAY(GPIO17
, GPIO
, SPI
, NONE
, JTAG
),
127 MFP_XWAY(GPIO18
, GPIO
, SPI
, NONE
, JTAG
),
128 MFP_XWAY(GPIO19
, GPIO
, PCI
, NONE
, NONE
),
129 MFP_XWAY(GPIO20
, GPIO
, JTAG
, NONE
, NONE
),
130 MFP_XWAY(GPIO21
, GPIO
, PCI
, EBU
, GPT
),
131 MFP_XWAY(GPIO22
, GPIO
, SPI
, NONE
, NONE
),
132 MFP_XWAY(GPIO23
, GPIO
, EBU
, PCI
, STP
),
133 MFP_XWAY(GPIO24
, GPIO
, EBU
, TDM
, PCI
),
134 MFP_XWAY(GPIO25
, GPIO
, TDM
, NONE
, ASC
),
135 MFP_XWAY(GPIO26
, GPIO
, EBU
, NONE
, TDM
),
136 MFP_XWAY(GPIO27
, GPIO
, TDM
, NONE
, ASC
),
137 MFP_XWAY(GPIO28
, GPIO
, GPT
, NONE
, NONE
),
138 MFP_XWAY(GPIO29
, GPIO
, PCI
, NONE
, NONE
),
139 MFP_XWAY(GPIO30
, GPIO
, PCI
, NONE
, NONE
),
140 MFP_XWAY(GPIO31
, GPIO
, EBU
, PCI
, NONE
),
141 MFP_XWAY(GPIO32
, GPIO
, NONE
, NONE
, EBU
),
142 MFP_XWAY(GPIO33
, GPIO
, NONE
, NONE
, EBU
),
143 MFP_XWAY(GPIO34
, GPIO
, NONE
, NONE
, EBU
),
144 MFP_XWAY(GPIO35
, GPIO
, NONE
, NONE
, EBU
),
145 MFP_XWAY(GPIO36
, GPIO
, SIN
, NONE
, EBU
),
146 MFP_XWAY(GPIO37
, GPIO
, PCI
, NONE
, NONE
),
147 MFP_XWAY(GPIO38
, GPIO
, PCI
, NONE
, NONE
),
148 MFP_XWAY(GPIO39
, GPIO
, EXIN
, NONE
, NONE
),
149 MFP_XWAY(GPIO40
, GPIO
, NONE
, NONE
, NONE
),
150 MFP_XWAY(GPIO41
, GPIO
, NONE
, NONE
, NONE
),
151 MFP_XWAY(GPIO42
, GPIO
, MDIO
, NONE
, NONE
),
152 MFP_XWAY(GPIO43
, GPIO
, MDIO
, NONE
, NONE
),
153 MFP_XWAY(GPIO44
, GPIO
, NONE
, NONE
, SIN
),
154 MFP_XWAY(GPIO45
, GPIO
, NONE
, NONE
, SIN
),
155 MFP_XWAY(GPIO46
, GPIO
, NONE
, NONE
, EXIN
),
156 MFP_XWAY(GPIO47
, GPIO
, NONE
, NONE
, SIN
),
157 MFP_XWAY(GPIO48
, GPIO
, EBU
, NONE
, NONE
),
158 MFP_XWAY(GPIO49
, GPIO
, EBU
, NONE
, NONE
),
159 MFP_XWAY(GPIO50
, GPIO
, NONE
, NONE
, NONE
),
160 MFP_XWAY(GPIO51
, GPIO
, NONE
, NONE
, NONE
),
161 MFP_XWAY(GPIO52
, GPIO
, NONE
, NONE
, NONE
),
162 MFP_XWAY(GPIO53
, GPIO
, NONE
, NONE
, NONE
),
163 MFP_XWAY(GPIO54
, GPIO
, NONE
, NONE
, NONE
),
164 MFP_XWAY(GPIO55
, GPIO
, NONE
, NONE
, NONE
),
167 static const struct ltq_mfp_pin ase_mfp
[] = {
168 /* pin f0 f1 f2 f3 */
169 MFP_XWAY(GPIO0
, GPIO
, EXIN
, MII
, TDM
),
170 MFP_XWAY(GPIO1
, GPIO
, STP
, DFE
, EBU
),
171 MFP_XWAY(GPIO2
, GPIO
, STP
, DFE
, EPHY
),
172 MFP_XWAY(GPIO3
, GPIO
, STP
, EPHY
, EBU
),
173 MFP_XWAY(GPIO4
, GPIO
, GPT
, EPHY
, MII
),
174 MFP_XWAY(GPIO5
, GPIO
, MII
, ASC
, GPT
),
175 MFP_XWAY(GPIO6
, GPIO
, MII
, ASC
, EXIN
),
176 MFP_XWAY(GPIO7
, GPIO
, SPI
, MII
, JTAG
),
177 MFP_XWAY(GPIO8
, GPIO
, SPI
, MII
, JTAG
),
178 MFP_XWAY(GPIO9
, GPIO
, SPI
, MII
, JTAG
),
179 MFP_XWAY(GPIO10
, GPIO
, SPI
, MII
, JTAG
),
180 MFP_XWAY(GPIO11
, GPIO
, EBU
, CGU
, JTAG
),
181 MFP_XWAY(GPIO12
, GPIO
, EBU
, MII
, SDIO
),
182 MFP_XWAY(GPIO13
, GPIO
, EBU
, MII
, CGU
),
183 MFP_XWAY(GPIO14
, GPIO
, EBU
, SPI
, CGU
),
184 MFP_XWAY(GPIO15
, GPIO
, EBU
, SPI
, SDIO
),
185 MFP_XWAY(GPIO16
, GPIO
, NONE
, NONE
, NONE
),
186 MFP_XWAY(GPIO17
, GPIO
, NONE
, NONE
, NONE
),
187 MFP_XWAY(GPIO18
, GPIO
, NONE
, NONE
, NONE
),
188 MFP_XWAY(GPIO19
, GPIO
, EBU
, MII
, SDIO
),
189 MFP_XWAY(GPIO20
, GPIO
, EBU
, MII
, SDIO
),
190 MFP_XWAY(GPIO21
, GPIO
, EBU
, MII
, SDIO
),
191 MFP_XWAY(GPIO22
, GPIO
, EBU
, MII
, CGU
),
192 MFP_XWAY(GPIO23
, GPIO
, EBU
, MII
, CGU
),
193 MFP_XWAY(GPIO24
, GPIO
, EBU
, NONE
, MII
),
194 MFP_XWAY(GPIO25
, GPIO
, EBU
, MII
, GPT
),
195 MFP_XWAY(GPIO26
, GPIO
, EBU
, MII
, SDIO
),
196 MFP_XWAY(GPIO27
, GPIO
, EBU
, NONE
, MII
),
197 MFP_XWAY(GPIO28
, GPIO
, MII
, EBU
, SDIO
),
198 MFP_XWAY(GPIO29
, GPIO
, EBU
, MII
, EXIN
),
199 MFP_XWAY(GPIO30
, GPIO
, NONE
, NONE
, NONE
),
200 MFP_XWAY(GPIO31
, GPIO
, NONE
, NONE
, NONE
),
203 static const unsigned pins_jtag
[] = {GPIO15
, GPIO16
, GPIO17
, GPIO19
, GPIO35
};
204 static const unsigned pins_asc0
[] = {GPIO11
, GPIO12
};
205 static const unsigned pins_asc0_cts_rts
[] = {GPIO9
, GPIO10
};
206 static const unsigned pins_stp
[] = {GPIO4
, GPIO5
, GPIO6
};
207 static const unsigned pins_nmi
[] = {GPIO8
};
208 static const unsigned pins_mdio
[] = {GPIO42
, GPIO43
};
210 static const unsigned pins_ebu_a24
[] = {GPIO13
};
211 static const unsigned pins_ebu_clk
[] = {GPIO21
};
212 static const unsigned pins_ebu_cs1
[] = {GPIO23
};
213 static const unsigned pins_ebu_a23
[] = {GPIO24
};
214 static const unsigned pins_ebu_wait
[] = {GPIO26
};
215 static const unsigned pins_ebu_a25
[] = {GPIO31
};
216 static const unsigned pins_ebu_rdy
[] = {GPIO48
};
217 static const unsigned pins_ebu_rd
[] = {GPIO49
};
219 static const unsigned pins_nand_ale
[] = {GPIO13
};
220 static const unsigned pins_nand_cs1
[] = {GPIO23
};
221 static const unsigned pins_nand_cle
[] = {GPIO24
};
222 static const unsigned pins_nand_rdy
[] = {GPIO48
};
223 static const unsigned pins_nand_rd
[] = {GPIO49
};
225 static const unsigned pins_exin0
[] = {GPIO0
};
226 static const unsigned pins_exin1
[] = {GPIO1
};
227 static const unsigned pins_exin2
[] = {GPIO2
};
228 static const unsigned pins_exin3
[] = {GPIO39
};
229 static const unsigned pins_exin4
[] = {GPIO46
};
230 static const unsigned pins_exin5
[] = {GPIO9
};
232 static const unsigned pins_spi
[] = {GPIO16
, GPIO17
, GPIO18
};
233 static const unsigned pins_spi_cs1
[] = {GPIO15
};
234 static const unsigned pins_spi_cs2
[] = {GPIO21
};
235 static const unsigned pins_spi_cs3
[] = {GPIO13
};
236 static const unsigned pins_spi_cs4
[] = {GPIO10
};
237 static const unsigned pins_spi_cs5
[] = {GPIO9
};
238 static const unsigned pins_spi_cs6
[] = {GPIO11
};
240 static const unsigned pins_gpt1
[] = {GPIO28
};
241 static const unsigned pins_gpt2
[] = {GPIO21
};
242 static const unsigned pins_gpt3
[] = {GPIO6
};
244 static const unsigned pins_clkout0
[] = {GPIO8
};
245 static const unsigned pins_clkout1
[] = {GPIO7
};
246 static const unsigned pins_clkout2
[] = {GPIO3
};
247 static const unsigned pins_clkout3
[] = {GPIO2
};
249 static const unsigned pins_pci_gnt1
[] = {GPIO30
};
250 static const unsigned pins_pci_gnt2
[] = {GPIO23
};
251 static const unsigned pins_pci_gnt3
[] = {GPIO19
};
252 static const unsigned pins_pci_gnt4
[] = {GPIO38
};
253 static const unsigned pins_pci_req1
[] = {GPIO29
};
254 static const unsigned pins_pci_req2
[] = {GPIO31
};
255 static const unsigned pins_pci_req3
[] = {GPIO3
};
256 static const unsigned pins_pci_req4
[] = {GPIO37
};
258 static const unsigned ase_pins_jtag
[] = {GPIO7
, GPIO8
, GPIO9
, GPIO10
, GPIO11
};
259 static const unsigned ase_pins_asc
[] = {GPIO5
, GPIO6
};
260 static const unsigned ase_pins_stp
[] = {GPIO1
, GPIO2
, GPIO3
};
261 static const unsigned ase_pins_ephy
[] = {GPIO2
, GPIO3
, GPIO4
};
262 static const unsigned ase_pins_dfe
[] = {GPIO1
, GPIO2
};
264 static const unsigned ase_pins_spi
[] = {GPIO8
, GPIO9
, GPIO10
};
265 static const unsigned ase_pins_spi_cs1
[] = {GPIO7
};
266 static const unsigned ase_pins_spi_cs2
[] = {GPIO15
};
267 static const unsigned ase_pins_spi_cs3
[] = {GPIO14
};
269 static const unsigned ase_pins_exin0
[] = {GPIO6
};
270 static const unsigned ase_pins_exin1
[] = {GPIO29
};
271 static const unsigned ase_pins_exin2
[] = {GPIO0
};
273 static const unsigned ase_pins_gpt1
[] = {GPIO5
};
274 static const unsigned ase_pins_gpt2
[] = {GPIO4
};
275 static const unsigned ase_pins_gpt3
[] = {GPIO25
};
277 static const struct ltq_pin_group xway_grps
[] = {
278 GRP_MUX("exin0", EXIN
, pins_exin0
),
279 GRP_MUX("exin1", EXIN
, pins_exin1
),
280 GRP_MUX("exin2", EXIN
, pins_exin2
),
281 GRP_MUX("jtag", JTAG
, pins_jtag
),
282 GRP_MUX("ebu a23", EBU
, pins_ebu_a23
),
283 GRP_MUX("ebu a24", EBU
, pins_ebu_a24
),
284 GRP_MUX("ebu a25", EBU
, pins_ebu_a25
),
285 GRP_MUX("ebu clk", EBU
, pins_ebu_clk
),
286 GRP_MUX("ebu cs1", EBU
, pins_ebu_cs1
),
287 GRP_MUX("ebu wait", EBU
, pins_ebu_wait
),
288 GRP_MUX("nand ale", EBU
, pins_nand_ale
),
289 GRP_MUX("nand cs1", EBU
, pins_nand_cs1
),
290 GRP_MUX("nand cle", EBU
, pins_nand_cle
),
291 GRP_MUX("spi", SPI
, pins_spi
),
292 GRP_MUX("spi_cs1", SPI
, pins_spi_cs1
),
293 GRP_MUX("spi_cs2", SPI
, pins_spi_cs2
),
294 GRP_MUX("spi_cs3", SPI
, pins_spi_cs3
),
295 GRP_MUX("spi_cs4", SPI
, pins_spi_cs4
),
296 GRP_MUX("spi_cs5", SPI
, pins_spi_cs5
),
297 GRP_MUX("spi_cs6", SPI
, pins_spi_cs6
),
298 GRP_MUX("asc0", ASC
, pins_asc0
),
299 GRP_MUX("asc0 cts rts", ASC
, pins_asc0_cts_rts
),
300 GRP_MUX("stp", STP
, pins_stp
),
301 GRP_MUX("nmi", NMI
, pins_nmi
),
302 GRP_MUX("gpt1", GPT
, pins_gpt1
),
303 GRP_MUX("gpt2", GPT
, pins_gpt2
),
304 GRP_MUX("gpt3", GPT
, pins_gpt3
),
305 GRP_MUX("clkout0", CGU
, pins_clkout0
),
306 GRP_MUX("clkout1", CGU
, pins_clkout1
),
307 GRP_MUX("clkout2", CGU
, pins_clkout2
),
308 GRP_MUX("clkout3", CGU
, pins_clkout3
),
309 GRP_MUX("gnt1", PCI
, pins_pci_gnt1
),
310 GRP_MUX("gnt2", PCI
, pins_pci_gnt2
),
311 GRP_MUX("gnt3", PCI
, pins_pci_gnt3
),
312 GRP_MUX("req1", PCI
, pins_pci_req1
),
313 GRP_MUX("req2", PCI
, pins_pci_req2
),
314 GRP_MUX("req3", PCI
, pins_pci_req3
),
316 GRP_MUX("nand rdy", EBU
, pins_nand_rdy
),
317 GRP_MUX("nand rd", EBU
, pins_nand_rd
),
318 GRP_MUX("exin3", EXIN
, pins_exin3
),
319 GRP_MUX("exin4", EXIN
, pins_exin4
),
320 GRP_MUX("exin5", EXIN
, pins_exin5
),
321 GRP_MUX("gnt4", PCI
, pins_pci_gnt4
),
322 GRP_MUX("req4", PCI
, pins_pci_gnt4
),
323 GRP_MUX("mdio", MDIO
, pins_mdio
),
326 static const struct ltq_pin_group ase_grps
[] = {
327 GRP_MUX("exin0", EXIN
, ase_pins_exin0
),
328 GRP_MUX("exin1", EXIN
, ase_pins_exin1
),
329 GRP_MUX("exin2", EXIN
, ase_pins_exin2
),
330 GRP_MUX("jtag", JTAG
, ase_pins_jtag
),
331 GRP_MUX("stp", STP
, ase_pins_stp
),
332 GRP_MUX("asc", ASC
, ase_pins_asc
),
333 GRP_MUX("gpt1", GPT
, ase_pins_gpt1
),
334 GRP_MUX("gpt2", GPT
, ase_pins_gpt2
),
335 GRP_MUX("gpt3", GPT
, ase_pins_gpt3
),
336 GRP_MUX("ephy", EPHY
, ase_pins_ephy
),
337 GRP_MUX("dfe", DFE
, ase_pins_dfe
),
338 GRP_MUX("spi", SPI
, ase_pins_spi
),
339 GRP_MUX("spi_cs1", SPI
, ase_pins_spi_cs1
),
340 GRP_MUX("spi_cs2", SPI
, ase_pins_spi_cs2
),
341 GRP_MUX("spi_cs3", SPI
, ase_pins_spi_cs3
),
344 static const char * const xway_pci_grps
[] = {"gnt1", "gnt2",
347 static const char * const xway_spi_grps
[] = {"spi", "spi_cs1",
348 "spi_cs2", "spi_cs3",
349 "spi_cs4", "spi_cs5",
351 static const char * const xway_cgu_grps
[] = {"clkout0", "clkout1",
352 "clkout2", "clkout3"};
353 static const char * const xway_ebu_grps
[] = {"ebu a23", "ebu a24",
354 "ebu a25", "ebu cs1",
355 "ebu wait", "ebu clk",
356 "nand ale", "nand cs1",
358 static const char * const xway_exin_grps
[] = {"exin0", "exin1", "exin2"};
359 static const char * const xway_gpt_grps
[] = {"gpt1", "gpt2", "gpt3"};
360 static const char * const xway_asc_grps
[] = {"asc0", "asc0 cts rts"};
361 static const char * const xway_jtag_grps
[] = {"jtag"};
362 static const char * const xway_stp_grps
[] = {"stp"};
363 static const char * const xway_nmi_grps
[] = {"nmi"};
366 static const char * const xrx_mdio_grps
[] = {"mdio"};
367 static const char * const xrx_ebu_grps
[] = {"ebu a23", "ebu a24",
368 "ebu a25", "ebu cs1",
369 "ebu wait", "ebu clk",
370 "nand ale", "nand cs1",
371 "nand cle", "nand rdy",
373 static const char * const xrx_exin_grps
[] = {"exin0", "exin1", "exin2",
374 "exin3", "exin4", "exin5"};
375 static const char * const xrx_pci_grps
[] = {"gnt1", "gnt2",
381 static const char * const ase_exin_grps
[] = {"exin0", "exin1", "exin2"};
382 static const char * const ase_gpt_grps
[] = {"gpt1", "gpt2", "gpt3"};
383 static const char * const ase_dfe_grps
[] = {"dfe"};
384 static const char * const ase_ephy_grps
[] = {"ephy"};
385 static const char * const ase_asc_grps
[] = {"asc"};
386 static const char * const ase_jtag_grps
[] = {"jtag"};
387 static const char * const ase_stp_grps
[] = {"stp"};
388 static const char * const ase_spi_grps
[] = {"spi", "spi_cs1",
389 "spi_cs2", "spi_cs3"};
391 static const struct ltq_pmx_func danube_funcs
[] = {
392 {"spi", ARRAY_AND_SIZE(xway_spi_grps
)},
393 {"asc", ARRAY_AND_SIZE(xway_asc_grps
)},
394 {"cgu", ARRAY_AND_SIZE(xway_cgu_grps
)},
395 {"jtag", ARRAY_AND_SIZE(xway_jtag_grps
)},
396 {"exin", ARRAY_AND_SIZE(xway_exin_grps
)},
397 {"stp", ARRAY_AND_SIZE(xway_stp_grps
)},
398 {"gpt", ARRAY_AND_SIZE(xway_gpt_grps
)},
399 {"nmi", ARRAY_AND_SIZE(xway_nmi_grps
)},
400 {"pci", ARRAY_AND_SIZE(xway_pci_grps
)},
401 {"ebu", ARRAY_AND_SIZE(xway_ebu_grps
)},
404 static const struct ltq_pmx_func xrx_funcs
[] = {
405 {"spi", ARRAY_AND_SIZE(xway_spi_grps
)},
406 {"asc", ARRAY_AND_SIZE(xway_asc_grps
)},
407 {"cgu", ARRAY_AND_SIZE(xway_cgu_grps
)},
408 {"jtag", ARRAY_AND_SIZE(xway_jtag_grps
)},
409 {"exin", ARRAY_AND_SIZE(xrx_exin_grps
)},
410 {"stp", ARRAY_AND_SIZE(xway_stp_grps
)},
411 {"gpt", ARRAY_AND_SIZE(xway_gpt_grps
)},
412 {"nmi", ARRAY_AND_SIZE(xway_nmi_grps
)},
413 {"pci", ARRAY_AND_SIZE(xrx_pci_grps
)},
414 {"ebu", ARRAY_AND_SIZE(xrx_ebu_grps
)},
415 {"mdio", ARRAY_AND_SIZE(xrx_mdio_grps
)},
418 static const struct ltq_pmx_func ase_funcs
[] = {
419 {"spi", ARRAY_AND_SIZE(ase_spi_grps
)},
420 {"asc", ARRAY_AND_SIZE(ase_asc_grps
)},
421 {"jtag", ARRAY_AND_SIZE(ase_jtag_grps
)},
422 {"exin", ARRAY_AND_SIZE(ase_exin_grps
)},
423 {"stp", ARRAY_AND_SIZE(ase_stp_grps
)},
424 {"gpt", ARRAY_AND_SIZE(ase_gpt_grps
)},
425 {"ephy", ARRAY_AND_SIZE(ase_ephy_grps
)},
426 {"dfe", ARRAY_AND_SIZE(ase_dfe_grps
)},
429 /* --------- pinconf related code --------- */
430 static int xway_pinconf_get(struct pinctrl_dev
*pctldev
,
432 unsigned long *config
)
434 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctldev
);
435 enum ltq_pinconf_param param
= LTQ_PINCONF_UNPACK_PARAM(*config
);
436 int port
= PORT(pin
);
440 case LTQ_PINCONF_PARAM_OPEN_DRAIN
:
445 *config
= LTQ_PINCONF_PACK(param
,
446 !!gpio_getbit(info
->membase
[0], reg
, PORT_PIN(port
)));
449 case LTQ_PINCONF_PARAM_PULL
:
453 reg
= GPIO_PUDEN(port
);
454 if (!gpio_getbit(info
->membase
[0], reg
, PORT_PIN(port
))) {
455 *config
= LTQ_PINCONF_PACK(param
, 0);
462 reg
= GPIO_PUDSEL(port
);
463 if (!gpio_getbit(info
->membase
[0], reg
, PORT_PIN(port
)))
464 *config
= LTQ_PINCONF_PACK(param
, 2);
466 *config
= LTQ_PINCONF_PACK(param
, 1);
470 dev_err(pctldev
->dev
, "Invalid config param %04x\n", param
);
476 static int xway_pinconf_set(struct pinctrl_dev
*pctldev
,
478 unsigned long config
)
480 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctldev
);
481 enum ltq_pinconf_param param
= LTQ_PINCONF_UNPACK_PARAM(config
);
482 int arg
= LTQ_PINCONF_UNPACK_ARG(config
);
483 int port
= PORT(pin
);
487 case LTQ_PINCONF_PARAM_OPEN_DRAIN
:
492 gpio_setbit(info
->membase
[0], reg
, PORT_PIN(port
));
495 case LTQ_PINCONF_PARAM_PULL
:
499 reg
= GPIO_PUDEN(port
);
501 gpio_clearbit(info
->membase
[0], reg
, PORT_PIN(port
));
504 gpio_setbit(info
->membase
[0], reg
, PORT_PIN(port
));
509 reg
= GPIO_PUDSEL(port
);
511 gpio_clearbit(info
->membase
[0], reg
, PORT_PIN(port
));
513 gpio_setbit(info
->membase
[0], reg
, PORT_PIN(port
));
515 dev_err(pctldev
->dev
, "Invalid pull value %d\n", arg
);
519 dev_err(pctldev
->dev
, "Invalid config param %04x\n", param
);
525 static struct pinconf_ops xway_pinconf_ops
= {
526 .pin_config_get
= xway_pinconf_get
,
527 .pin_config_set
= xway_pinconf_set
,
530 static struct pinctrl_desc xway_pctrl_desc
= {
531 .owner
= THIS_MODULE
,
532 .confops
= &xway_pinconf_ops
,
535 static inline int xway_mux_apply(struct pinctrl_dev
*pctrldev
,
538 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctrldev
);
539 int port
= PORT(pin
);
540 u32 alt1_reg
= GPIO_ALT1(pin
);
543 alt1_reg
= GPIO3_ALT1
;
546 gpio_setbit(info
->membase
[0], GPIO_ALT0(pin
), PORT_PIN(pin
));
548 gpio_clearbit(info
->membase
[0], GPIO_ALT0(pin
), PORT_PIN(pin
));
551 gpio_setbit(info
->membase
[0], alt1_reg
, PORT_PIN(pin
));
553 gpio_clearbit(info
->membase
[0], alt1_reg
, PORT_PIN(pin
));
558 static const struct ltq_cfg_param xway_cfg_params
[] = {
559 {"lantiq,pull", LTQ_PINCONF_PARAM_PULL
},
560 {"lantiq,open-drain", LTQ_PINCONF_PARAM_OPEN_DRAIN
},
563 static struct ltq_pinmux_info xway_info
= {
564 .desc
= &xway_pctrl_desc
,
565 .apply_mux
= xway_mux_apply
,
566 .params
= xway_cfg_params
,
567 .num_params
= ARRAY_SIZE(xway_cfg_params
),
570 /* --------- gpio_chip related code --------- */
571 static void xway_gpio_set(struct gpio_chip
*chip
, unsigned int pin
, int val
)
573 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
576 gpio_setbit(info
->membase
[0], GPIO_OUT(pin
), PORT_PIN(pin
));
578 gpio_clearbit(info
->membase
[0], GPIO_OUT(pin
), PORT_PIN(pin
));
581 static int xway_gpio_get(struct gpio_chip
*chip
, unsigned int pin
)
583 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
585 return gpio_getbit(info
->membase
[0], GPIO_IN(pin
), PORT_PIN(pin
));
588 static int xway_gpio_dir_in(struct gpio_chip
*chip
, unsigned int pin
)
590 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
592 gpio_clearbit(info
->membase
[0], GPIO_DIR(pin
), PORT_PIN(pin
));
597 static int xway_gpio_dir_out(struct gpio_chip
*chip
, unsigned int pin
, int val
)
599 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
601 gpio_setbit(info
->membase
[0], GPIO_DIR(pin
), PORT_PIN(pin
));
602 xway_gpio_set(chip
, pin
, val
);
607 static int xway_gpio_req(struct gpio_chip
*chip
, unsigned offset
)
609 int gpio
= chip
->base
+ offset
;
611 return pinctrl_request_gpio(gpio
);
614 static void xway_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
616 int gpio
= chip
->base
+ offset
;
618 pinctrl_free_gpio(gpio
);
621 static struct gpio_chip xway_chip
= {
622 .label
= "gpio-xway",
623 .direction_input
= xway_gpio_dir_in
,
624 .direction_output
= xway_gpio_dir_out
,
625 .get
= xway_gpio_get
,
626 .set
= xway_gpio_set
,
627 .request
= xway_gpio_req
,
628 .free
= xway_gpio_free
,
633 /* --------- register the pinctrl layer --------- */
634 static const unsigned xway_exin_pin_map
[] = {GPIO0
, GPIO1
, GPIO2
, GPIO39
, GPIO46
, GPIO9
};
635 static const unsigned ase_exin_pins_map
[] = {GPIO6
, GPIO29
, GPIO0
};
637 static struct pinctrl_xway_soc
{
639 const struct ltq_mfp_pin
*mfp
;
640 const struct ltq_pin_group
*grps
;
641 unsigned int num_grps
;
642 const struct ltq_pmx_func
*funcs
;
643 unsigned int num_funcs
;
644 const unsigned *exin
;
645 unsigned int num_exin
;
648 {XWAY_MAX_PIN
, xway_mfp
,
649 xway_grps
, ARRAY_SIZE(xway_grps
),
650 danube_funcs
, ARRAY_SIZE(danube_funcs
),
651 xway_exin_pin_map
, 3},
652 /* xway xr9 series */
653 {XR9_MAX_PIN
, xway_mfp
,
654 xway_grps
, ARRAY_SIZE(xway_grps
),
655 xrx_funcs
, ARRAY_SIZE(xrx_funcs
),
656 xway_exin_pin_map
, 6},
657 /* xway ase series */
658 {XWAY_MAX_PIN
, ase_mfp
,
659 ase_grps
, ARRAY_SIZE(ase_grps
),
660 ase_funcs
, ARRAY_SIZE(ase_funcs
),
661 ase_exin_pins_map
, 3},
664 static struct pinctrl_gpio_range xway_gpio_range
= {
669 static const struct of_device_id xway_match
[] = {
670 { .compatible
= "lantiq,pinctrl-xway", .data
= &soc_cfg
[0]},
671 { .compatible
= "lantiq,pinctrl-xr9", .data
= &soc_cfg
[1]},
672 { .compatible
= "lantiq,pinctrl-ase", .data
= &soc_cfg
[2]},
675 MODULE_DEVICE_TABLE(of
, xway_match
);
677 static int pinmux_xway_probe(struct platform_device
*pdev
)
679 const struct of_device_id
*match
;
680 const struct pinctrl_xway_soc
*xway_soc
;
681 struct resource
*res
;
684 /* get and remap our register range */
685 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
687 dev_err(&pdev
->dev
, "Failed to get resource\n");
690 xway_info
.membase
[0] = devm_request_and_ioremap(&pdev
->dev
, res
);
691 if (!xway_info
.membase
[0]) {
692 dev_err(&pdev
->dev
, "Failed to remap resource\n");
696 match
= of_match_device(xway_match
, &pdev
->dev
);
698 xway_soc
= (const struct pinctrl_xway_soc
*) match
->data
;
700 xway_soc
= &soc_cfg
[0];
702 /* find out how many pads we have */
703 xway_chip
.ngpio
= xway_soc
->pin_count
;
705 /* load our pad descriptors */
706 xway_info
.pads
= devm_kzalloc(&pdev
->dev
,
707 sizeof(struct pinctrl_pin_desc
) * xway_chip
.ngpio
,
709 if (!xway_info
.pads
) {
710 dev_err(&pdev
->dev
, "Failed to allocate pads\n");
713 for (i
= 0; i
< xway_chip
.ngpio
; i
++) {
714 /* strlen("ioXY") + 1 = 5 */
715 char *name
= devm_kzalloc(&pdev
->dev
, 5, GFP_KERNEL
);
718 dev_err(&pdev
->dev
, "Failed to allocate pad name\n");
721 snprintf(name
, 5, "io%d", i
);
722 xway_info
.pads
[i
].number
= GPIO0
+ i
;
723 xway_info
.pads
[i
].name
= name
;
725 xway_pctrl_desc
.pins
= xway_info
.pads
;
727 /* load the gpio chip */
728 xway_chip
.dev
= &pdev
->dev
;
729 of_gpiochip_add(&xway_chip
);
730 ret
= gpiochip_add(&xway_chip
);
732 dev_err(&pdev
->dev
, "Failed to register gpio chip\n");
736 /* setup the data needed by pinctrl */
737 xway_pctrl_desc
.name
= dev_name(&pdev
->dev
);
738 xway_pctrl_desc
.npins
= xway_chip
.ngpio
;
740 xway_info
.num_pads
= xway_chip
.ngpio
;
741 xway_info
.num_mfp
= xway_chip
.ngpio
;
742 xway_info
.mfp
= xway_soc
->mfp
;
743 xway_info
.grps
= xway_soc
->grps
;
744 xway_info
.num_grps
= xway_soc
->num_grps
;
745 xway_info
.funcs
= xway_soc
->funcs
;
746 xway_info
.num_funcs
= xway_soc
->num_funcs
;
747 xway_info
.exin
= xway_soc
->exin
;
748 xway_info
.num_exin
= xway_soc
->num_exin
;
750 /* register with the generic lantiq layer */
751 ret
= ltq_pinctrl_register(pdev
, &xway_info
);
753 dev_err(&pdev
->dev
, "Failed to register pinctrl driver\n");
757 /* finish with registering the gpio range in pinctrl */
758 xway_gpio_range
.npins
= xway_chip
.ngpio
;
759 xway_gpio_range
.base
= xway_chip
.base
;
760 pinctrl_add_gpio_range(xway_info
.pctrl
, &xway_gpio_range
);
761 dev_info(&pdev
->dev
, "Init done\n");
765 static struct platform_driver pinmux_xway_driver
= {
766 .probe
= pinmux_xway_probe
,
768 .name
= "pinctrl-xway",
769 .owner
= THIS_MODULE
,
770 .of_match_table
= xway_match
,
774 static int __init
pinmux_xway_init(void)
776 return platform_driver_register(&pinmux_xway_driver
);
779 core_initcall_sync(pinmux_xway_init
);