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/err.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/of_platform.h>
16 #include <linux/of_address.h>
17 #include <linux/of_gpio.h>
18 #include <linux/ioport.h>
20 #include <linux/device.h>
21 #include <linux/platform_device.h>
23 #include "pinctrl-lantiq.h"
25 #include <lantiq_soc.h>
27 /* we have 3 1/2 banks of 16 bit each */
30 #define PORT(x) (x / PINS)
31 #define PORT_PIN(x) (x % PINS)
33 /* we have 2 mux bits that can be set for each pin */
38 * each bank has this offset apart from the 1/2 bank that is mixed into the
43 /* these are the offsets to our registers */
44 #define GPIO_BASE(p) (REG_OFF * PORT(p))
45 #define GPIO_OUT(p) GPIO_BASE(p)
46 #define GPIO_IN(p) (GPIO_BASE(p) + 0x04)
47 #define GPIO_DIR(p) (GPIO_BASE(p) + 0x08)
48 #define GPIO_ALT0(p) (GPIO_BASE(p) + 0x0C)
49 #define GPIO_ALT1(p) (GPIO_BASE(p) + 0x10)
50 #define GPIO_OD(p) (GPIO_BASE(p) + 0x14)
51 #define GPIO_PUDSEL(p) (GPIO_BASE(p) + 0x1c)
52 #define GPIO_PUDEN(p) (GPIO_BASE(p) + 0x20)
54 /* the 1/2 port needs special offsets for some registers */
55 #define GPIO3_OD (GPIO_BASE(0) + 0x24)
56 #define GPIO3_PUDSEL (GPIO_BASE(0) + 0x28)
57 #define GPIO3_PUDEN (GPIO_BASE(0) + 0x2C)
58 #define GPIO3_ALT1 (GPIO_BASE(PINS) + 0x24)
60 /* macros to help us access the registers */
61 #define gpio_getbit(m, r, p) (!!(ltq_r32(m + r) & BIT(p)))
62 #define gpio_setbit(m, r, p) ltq_w32_mask(0, BIT(p), m + r)
63 #define gpio_clearbit(m, r, p) ltq_w32_mask(BIT(p), 0, m + r)
65 #define MFP_XWAY(a, f0, f1, f2, f3) \
77 #define GRP_MUX(a, m, p) \
78 { .name = a, .mux = XWAY_MUX_##m, .pins = p, .npins = ARRAY_SIZE(p), }
80 #define FUNC_MUX(f, m) \
81 { .func = f, .mux = XWAY_MUX_##m, }
83 #define XWAY_MAX_PIN 32
84 #define XR9_MAX_PIN 56
106 XWAY_MUX_NONE
= 0xffff,
109 static const struct ltq_mfp_pin xway_mfp
[] = {
110 /* pin f0 f1 f2 f3 */
111 MFP_XWAY(GPIO0
, GPIO
, EXIN
, NONE
, TDM
),
112 MFP_XWAY(GPIO1
, GPIO
, EXIN
, NONE
, NONE
),
113 MFP_XWAY(GPIO2
, GPIO
, CGU
, EXIN
, GPHY
),
114 MFP_XWAY(GPIO3
, GPIO
, CGU
, NONE
, PCI
),
115 MFP_XWAY(GPIO4
, GPIO
, STP
, NONE
, ASC
),
116 MFP_XWAY(GPIO5
, GPIO
, STP
, NONE
, GPHY
),
117 MFP_XWAY(GPIO6
, GPIO
, STP
, GPT
, ASC
),
118 MFP_XWAY(GPIO7
, GPIO
, CGU
, PCI
, GPHY
),
119 MFP_XWAY(GPIO8
, GPIO
, CGU
, NMI
, NONE
),
120 MFP_XWAY(GPIO9
, GPIO
, ASC
, SPI
, EXIN
),
121 MFP_XWAY(GPIO10
, GPIO
, ASC
, SPI
, NONE
),
122 MFP_XWAY(GPIO11
, GPIO
, ASC
, PCI
, SPI
),
123 MFP_XWAY(GPIO12
, GPIO
, ASC
, NONE
, NONE
),
124 MFP_XWAY(GPIO13
, GPIO
, EBU
, SPI
, NONE
),
125 MFP_XWAY(GPIO14
, GPIO
, CGU
, PCI
, NONE
),
126 MFP_XWAY(GPIO15
, GPIO
, SPI
, JTAG
, NONE
),
127 MFP_XWAY(GPIO16
, GPIO
, SPI
, NONE
, JTAG
),
128 MFP_XWAY(GPIO17
, GPIO
, SPI
, NONE
, JTAG
),
129 MFP_XWAY(GPIO18
, GPIO
, SPI
, NONE
, JTAG
),
130 MFP_XWAY(GPIO19
, GPIO
, PCI
, NONE
, NONE
),
131 MFP_XWAY(GPIO20
, GPIO
, JTAG
, NONE
, NONE
),
132 MFP_XWAY(GPIO21
, GPIO
, PCI
, EBU
, GPT
),
133 MFP_XWAY(GPIO22
, GPIO
, SPI
, NONE
, NONE
),
134 MFP_XWAY(GPIO23
, GPIO
, EBU
, PCI
, STP
),
135 MFP_XWAY(GPIO24
, GPIO
, EBU
, TDM
, PCI
),
136 MFP_XWAY(GPIO25
, GPIO
, TDM
, NONE
, ASC
),
137 MFP_XWAY(GPIO26
, GPIO
, EBU
, NONE
, TDM
),
138 MFP_XWAY(GPIO27
, GPIO
, TDM
, NONE
, ASC
),
139 MFP_XWAY(GPIO28
, GPIO
, GPT
, NONE
, NONE
),
140 MFP_XWAY(GPIO29
, GPIO
, PCI
, NONE
, NONE
),
141 MFP_XWAY(GPIO30
, GPIO
, PCI
, NONE
, NONE
),
142 MFP_XWAY(GPIO31
, GPIO
, EBU
, PCI
, NONE
),
143 MFP_XWAY(GPIO32
, GPIO
, NONE
, NONE
, EBU
),
144 MFP_XWAY(GPIO33
, GPIO
, NONE
, NONE
, EBU
),
145 MFP_XWAY(GPIO34
, GPIO
, NONE
, NONE
, EBU
),
146 MFP_XWAY(GPIO35
, GPIO
, NONE
, NONE
, EBU
),
147 MFP_XWAY(GPIO36
, GPIO
, SIN
, NONE
, EBU
),
148 MFP_XWAY(GPIO37
, GPIO
, PCI
, NONE
, NONE
),
149 MFP_XWAY(GPIO38
, GPIO
, PCI
, NONE
, NONE
),
150 MFP_XWAY(GPIO39
, GPIO
, EXIN
, NONE
, NONE
),
151 MFP_XWAY(GPIO40
, GPIO
, NONE
, NONE
, NONE
),
152 MFP_XWAY(GPIO41
, GPIO
, NONE
, NONE
, NONE
),
153 MFP_XWAY(GPIO42
, GPIO
, MDIO
, NONE
, NONE
),
154 MFP_XWAY(GPIO43
, GPIO
, MDIO
, NONE
, NONE
),
155 MFP_XWAY(GPIO44
, GPIO
, NONE
, GPHY
, SIN
),
156 MFP_XWAY(GPIO45
, GPIO
, NONE
, GPHY
, SIN
),
157 MFP_XWAY(GPIO46
, GPIO
, NONE
, NONE
, EXIN
),
158 MFP_XWAY(GPIO47
, GPIO
, NONE
, GPHY
, SIN
),
159 MFP_XWAY(GPIO48
, GPIO
, EBU
, NONE
, NONE
),
160 MFP_XWAY(GPIO49
, GPIO
, EBU
, NONE
, NONE
),
161 MFP_XWAY(GPIO50
, GPIO
, NONE
, NONE
, NONE
),
162 MFP_XWAY(GPIO51
, GPIO
, NONE
, NONE
, NONE
),
163 MFP_XWAY(GPIO52
, GPIO
, NONE
, NONE
, NONE
),
164 MFP_XWAY(GPIO53
, GPIO
, NONE
, NONE
, NONE
),
165 MFP_XWAY(GPIO54
, GPIO
, NONE
, NONE
, NONE
),
166 MFP_XWAY(GPIO55
, GPIO
, NONE
, NONE
, NONE
),
169 static const struct ltq_mfp_pin ase_mfp
[] = {
170 /* pin f0 f1 f2 f3 */
171 MFP_XWAY(GPIO0
, GPIO
, EXIN
, MII
, TDM
),
172 MFP_XWAY(GPIO1
, GPIO
, STP
, DFE
, EBU
),
173 MFP_XWAY(GPIO2
, GPIO
, STP
, DFE
, EPHY
),
174 MFP_XWAY(GPIO3
, GPIO
, STP
, EPHY
, EBU
),
175 MFP_XWAY(GPIO4
, GPIO
, GPT
, EPHY
, MII
),
176 MFP_XWAY(GPIO5
, GPIO
, MII
, ASC
, GPT
),
177 MFP_XWAY(GPIO6
, GPIO
, MII
, ASC
, EXIN
),
178 MFP_XWAY(GPIO7
, GPIO
, SPI
, MII
, JTAG
),
179 MFP_XWAY(GPIO8
, GPIO
, SPI
, MII
, JTAG
),
180 MFP_XWAY(GPIO9
, GPIO
, SPI
, MII
, JTAG
),
181 MFP_XWAY(GPIO10
, GPIO
, SPI
, MII
, JTAG
),
182 MFP_XWAY(GPIO11
, GPIO
, EBU
, CGU
, JTAG
),
183 MFP_XWAY(GPIO12
, GPIO
, EBU
, MII
, SDIO
),
184 MFP_XWAY(GPIO13
, GPIO
, EBU
, MII
, CGU
),
185 MFP_XWAY(GPIO14
, GPIO
, EBU
, SPI
, CGU
),
186 MFP_XWAY(GPIO15
, GPIO
, EBU
, SPI
, SDIO
),
187 MFP_XWAY(GPIO16
, GPIO
, NONE
, NONE
, NONE
),
188 MFP_XWAY(GPIO17
, GPIO
, NONE
, NONE
, NONE
),
189 MFP_XWAY(GPIO18
, GPIO
, NONE
, NONE
, NONE
),
190 MFP_XWAY(GPIO19
, GPIO
, EBU
, MII
, SDIO
),
191 MFP_XWAY(GPIO20
, GPIO
, EBU
, MII
, SDIO
),
192 MFP_XWAY(GPIO21
, GPIO
, EBU
, MII
, SDIO
),
193 MFP_XWAY(GPIO22
, GPIO
, EBU
, MII
, CGU
),
194 MFP_XWAY(GPIO23
, GPIO
, EBU
, MII
, CGU
),
195 MFP_XWAY(GPIO24
, GPIO
, EBU
, NONE
, MII
),
196 MFP_XWAY(GPIO25
, GPIO
, EBU
, MII
, GPT
),
197 MFP_XWAY(GPIO26
, GPIO
, EBU
, MII
, SDIO
),
198 MFP_XWAY(GPIO27
, GPIO
, EBU
, NONE
, MII
),
199 MFP_XWAY(GPIO28
, GPIO
, MII
, EBU
, SDIO
),
200 MFP_XWAY(GPIO29
, GPIO
, EBU
, MII
, EXIN
),
201 MFP_XWAY(GPIO30
, GPIO
, NONE
, NONE
, NONE
),
202 MFP_XWAY(GPIO31
, GPIO
, NONE
, NONE
, NONE
),
205 static const unsigned pins_jtag
[] = {GPIO15
, GPIO16
, GPIO17
, GPIO19
, GPIO35
};
206 static const unsigned pins_asc0
[] = {GPIO11
, GPIO12
};
207 static const unsigned pins_asc0_cts_rts
[] = {GPIO9
, GPIO10
};
208 static const unsigned pins_stp
[] = {GPIO4
, GPIO5
, GPIO6
};
209 static const unsigned pins_nmi
[] = {GPIO8
};
210 static const unsigned pins_mdio
[] = {GPIO42
, GPIO43
};
212 static const unsigned pins_gphy0_led0
[] = {GPIO5
};
213 static const unsigned pins_gphy0_led1
[] = {GPIO7
};
214 static const unsigned pins_gphy0_led2
[] = {GPIO2
};
215 static const unsigned pins_gphy1_led0
[] = {GPIO44
};
216 static const unsigned pins_gphy1_led1
[] = {GPIO45
};
217 static const unsigned pins_gphy1_led2
[] = {GPIO47
};
219 static const unsigned pins_ebu_a24
[] = {GPIO13
};
220 static const unsigned pins_ebu_clk
[] = {GPIO21
};
221 static const unsigned pins_ebu_cs1
[] = {GPIO23
};
222 static const unsigned pins_ebu_a23
[] = {GPIO24
};
223 static const unsigned pins_ebu_wait
[] = {GPIO26
};
224 static const unsigned pins_ebu_a25
[] = {GPIO31
};
225 static const unsigned pins_ebu_rdy
[] = {GPIO48
};
226 static const unsigned pins_ebu_rd
[] = {GPIO49
};
228 static const unsigned pins_nand_ale
[] = {GPIO13
};
229 static const unsigned pins_nand_cs1
[] = {GPIO23
};
230 static const unsigned pins_nand_cle
[] = {GPIO24
};
231 static const unsigned pins_nand_rdy
[] = {GPIO48
};
232 static const unsigned pins_nand_rd
[] = {GPIO49
};
234 static const unsigned pins_exin0
[] = {GPIO0
};
235 static const unsigned pins_exin1
[] = {GPIO1
};
236 static const unsigned pins_exin2
[] = {GPIO2
};
237 static const unsigned pins_exin3
[] = {GPIO39
};
238 static const unsigned pins_exin4
[] = {GPIO46
};
239 static const unsigned pins_exin5
[] = {GPIO9
};
241 static const unsigned pins_spi
[] = {GPIO16
, GPIO17
, GPIO18
};
242 static const unsigned pins_spi_cs1
[] = {GPIO15
};
243 static const unsigned pins_spi_cs2
[] = {GPIO21
};
244 static const unsigned pins_spi_cs3
[] = {GPIO13
};
245 static const unsigned pins_spi_cs4
[] = {GPIO10
};
246 static const unsigned pins_spi_cs5
[] = {GPIO9
};
247 static const unsigned pins_spi_cs6
[] = {GPIO11
};
249 static const unsigned pins_gpt1
[] = {GPIO28
};
250 static const unsigned pins_gpt2
[] = {GPIO21
};
251 static const unsigned pins_gpt3
[] = {GPIO6
};
253 static const unsigned pins_clkout0
[] = {GPIO8
};
254 static const unsigned pins_clkout1
[] = {GPIO7
};
255 static const unsigned pins_clkout2
[] = {GPIO3
};
256 static const unsigned pins_clkout3
[] = {GPIO2
};
258 static const unsigned pins_pci_gnt1
[] = {GPIO30
};
259 static const unsigned pins_pci_gnt2
[] = {GPIO23
};
260 static const unsigned pins_pci_gnt3
[] = {GPIO19
};
261 static const unsigned pins_pci_gnt4
[] = {GPIO38
};
262 static const unsigned pins_pci_req1
[] = {GPIO29
};
263 static const unsigned pins_pci_req2
[] = {GPIO31
};
264 static const unsigned pins_pci_req3
[] = {GPIO3
};
265 static const unsigned pins_pci_req4
[] = {GPIO37
};
267 static const unsigned ase_pins_jtag
[] = {GPIO7
, GPIO8
, GPIO9
, GPIO10
, GPIO11
};
268 static const unsigned ase_pins_asc
[] = {GPIO5
, GPIO6
};
269 static const unsigned ase_pins_stp
[] = {GPIO1
, GPIO2
, GPIO3
};
270 static const unsigned ase_pins_ephy
[] = {GPIO2
, GPIO3
, GPIO4
};
271 static const unsigned ase_pins_dfe
[] = {GPIO1
, GPIO2
};
273 static const unsigned ase_pins_spi
[] = {GPIO8
, GPIO9
, GPIO10
};
274 static const unsigned ase_pins_spi_cs1
[] = {GPIO7
};
275 static const unsigned ase_pins_spi_cs2
[] = {GPIO15
};
276 static const unsigned ase_pins_spi_cs3
[] = {GPIO14
};
278 static const unsigned ase_pins_exin0
[] = {GPIO6
};
279 static const unsigned ase_pins_exin1
[] = {GPIO29
};
280 static const unsigned ase_pins_exin2
[] = {GPIO0
};
282 static const unsigned ase_pins_gpt1
[] = {GPIO5
};
283 static const unsigned ase_pins_gpt2
[] = {GPIO4
};
284 static const unsigned ase_pins_gpt3
[] = {GPIO25
};
286 static const struct ltq_pin_group xway_grps
[] = {
287 GRP_MUX("exin0", EXIN
, pins_exin0
),
288 GRP_MUX("exin1", EXIN
, pins_exin1
),
289 GRP_MUX("exin2", EXIN
, pins_exin2
),
290 GRP_MUX("jtag", JTAG
, pins_jtag
),
291 GRP_MUX("ebu a23", EBU
, pins_ebu_a23
),
292 GRP_MUX("ebu a24", EBU
, pins_ebu_a24
),
293 GRP_MUX("ebu a25", EBU
, pins_ebu_a25
),
294 GRP_MUX("ebu clk", EBU
, pins_ebu_clk
),
295 GRP_MUX("ebu cs1", EBU
, pins_ebu_cs1
),
296 GRP_MUX("ebu wait", EBU
, pins_ebu_wait
),
297 GRP_MUX("nand ale", EBU
, pins_nand_ale
),
298 GRP_MUX("nand cs1", EBU
, pins_nand_cs1
),
299 GRP_MUX("nand cle", EBU
, pins_nand_cle
),
300 GRP_MUX("spi", SPI
, pins_spi
),
301 GRP_MUX("spi_cs1", SPI
, pins_spi_cs1
),
302 GRP_MUX("spi_cs2", SPI
, pins_spi_cs2
),
303 GRP_MUX("spi_cs3", SPI
, pins_spi_cs3
),
304 GRP_MUX("spi_cs4", SPI
, pins_spi_cs4
),
305 GRP_MUX("spi_cs5", SPI
, pins_spi_cs5
),
306 GRP_MUX("spi_cs6", SPI
, pins_spi_cs6
),
307 GRP_MUX("asc0", ASC
, pins_asc0
),
308 GRP_MUX("asc0 cts rts", ASC
, pins_asc0_cts_rts
),
309 GRP_MUX("stp", STP
, pins_stp
),
310 GRP_MUX("nmi", NMI
, pins_nmi
),
311 GRP_MUX("gpt1", GPT
, pins_gpt1
),
312 GRP_MUX("gpt2", GPT
, pins_gpt2
),
313 GRP_MUX("gpt3", GPT
, pins_gpt3
),
314 GRP_MUX("clkout0", CGU
, pins_clkout0
),
315 GRP_MUX("clkout1", CGU
, pins_clkout1
),
316 GRP_MUX("clkout2", CGU
, pins_clkout2
),
317 GRP_MUX("clkout3", CGU
, pins_clkout3
),
318 GRP_MUX("gnt1", PCI
, pins_pci_gnt1
),
319 GRP_MUX("gnt2", PCI
, pins_pci_gnt2
),
320 GRP_MUX("gnt3", PCI
, pins_pci_gnt3
),
321 GRP_MUX("req1", PCI
, pins_pci_req1
),
322 GRP_MUX("req2", PCI
, pins_pci_req2
),
323 GRP_MUX("req3", PCI
, pins_pci_req3
),
325 GRP_MUX("nand rdy", EBU
, pins_nand_rdy
),
326 GRP_MUX("nand rd", EBU
, pins_nand_rd
),
327 GRP_MUX("exin3", EXIN
, pins_exin3
),
328 GRP_MUX("exin4", EXIN
, pins_exin4
),
329 GRP_MUX("exin5", EXIN
, pins_exin5
),
330 GRP_MUX("gnt4", PCI
, pins_pci_gnt4
),
331 GRP_MUX("req4", PCI
, pins_pci_gnt4
),
332 GRP_MUX("mdio", MDIO
, pins_mdio
),
333 GRP_MUX("gphy0 led0", GPHY
, pins_gphy0_led0
),
334 GRP_MUX("gphy0 led1", GPHY
, pins_gphy0_led1
),
335 GRP_MUX("gphy0 led2", GPHY
, pins_gphy0_led2
),
336 GRP_MUX("gphy1 led0", GPHY
, pins_gphy1_led0
),
337 GRP_MUX("gphy1 led1", GPHY
, pins_gphy1_led1
),
338 GRP_MUX("gphy1 led2", GPHY
, pins_gphy1_led2
),
341 static const struct ltq_pin_group ase_grps
[] = {
342 GRP_MUX("exin0", EXIN
, ase_pins_exin0
),
343 GRP_MUX("exin1", EXIN
, ase_pins_exin1
),
344 GRP_MUX("exin2", EXIN
, ase_pins_exin2
),
345 GRP_MUX("jtag", JTAG
, ase_pins_jtag
),
346 GRP_MUX("stp", STP
, ase_pins_stp
),
347 GRP_MUX("asc", ASC
, ase_pins_asc
),
348 GRP_MUX("gpt1", GPT
, ase_pins_gpt1
),
349 GRP_MUX("gpt2", GPT
, ase_pins_gpt2
),
350 GRP_MUX("gpt3", GPT
, ase_pins_gpt3
),
351 GRP_MUX("ephy", EPHY
, ase_pins_ephy
),
352 GRP_MUX("dfe", DFE
, ase_pins_dfe
),
353 GRP_MUX("spi", SPI
, ase_pins_spi
),
354 GRP_MUX("spi_cs1", SPI
, ase_pins_spi_cs1
),
355 GRP_MUX("spi_cs2", SPI
, ase_pins_spi_cs2
),
356 GRP_MUX("spi_cs3", SPI
, ase_pins_spi_cs3
),
359 static const char * const xway_pci_grps
[] = {"gnt1", "gnt2",
362 static const char * const xway_spi_grps
[] = {"spi", "spi_cs1",
363 "spi_cs2", "spi_cs3",
364 "spi_cs4", "spi_cs5",
366 static const char * const xway_cgu_grps
[] = {"clkout0", "clkout1",
367 "clkout2", "clkout3"};
368 static const char * const xway_ebu_grps
[] = {"ebu a23", "ebu a24",
369 "ebu a25", "ebu cs1",
370 "ebu wait", "ebu clk",
371 "nand ale", "nand cs1",
373 static const char * const xway_exin_grps
[] = {"exin0", "exin1", "exin2"};
374 static const char * const xway_gpt_grps
[] = {"gpt1", "gpt2", "gpt3"};
375 static const char * const xway_asc_grps
[] = {"asc0", "asc0 cts rts"};
376 static const char * const xway_jtag_grps
[] = {"jtag"};
377 static const char * const xway_stp_grps
[] = {"stp"};
378 static const char * const xway_nmi_grps
[] = {"nmi"};
381 static const char * const xrx_mdio_grps
[] = {"mdio"};
382 static const char * const xrx_gphy_grps
[] = {"gphy0 led0", "gphy0 led1",
383 "gphy0 led2", "gphy1 led0",
384 "gphy1 led1", "gphy1 led2"};
385 static const char * const xrx_ebu_grps
[] = {"ebu a23", "ebu a24",
386 "ebu a25", "ebu cs1",
387 "ebu wait", "ebu clk",
388 "nand ale", "nand cs1",
389 "nand cle", "nand rdy",
391 static const char * const xrx_exin_grps
[] = {"exin0", "exin1", "exin2",
392 "exin3", "exin4", "exin5"};
393 static const char * const xrx_pci_grps
[] = {"gnt1", "gnt2",
399 static const char * const ase_exin_grps
[] = {"exin0", "exin1", "exin2"};
400 static const char * const ase_gpt_grps
[] = {"gpt1", "gpt2", "gpt3"};
401 static const char * const ase_dfe_grps
[] = {"dfe"};
402 static const char * const ase_ephy_grps
[] = {"ephy"};
403 static const char * const ase_asc_grps
[] = {"asc"};
404 static const char * const ase_jtag_grps
[] = {"jtag"};
405 static const char * const ase_stp_grps
[] = {"stp"};
406 static const char * const ase_spi_grps
[] = {"spi", "spi_cs1",
407 "spi_cs2", "spi_cs3"};
409 static const struct ltq_pmx_func danube_funcs
[] = {
410 {"spi", ARRAY_AND_SIZE(xway_spi_grps
)},
411 {"asc", ARRAY_AND_SIZE(xway_asc_grps
)},
412 {"cgu", ARRAY_AND_SIZE(xway_cgu_grps
)},
413 {"jtag", ARRAY_AND_SIZE(xway_jtag_grps
)},
414 {"exin", ARRAY_AND_SIZE(xway_exin_grps
)},
415 {"stp", ARRAY_AND_SIZE(xway_stp_grps
)},
416 {"gpt", ARRAY_AND_SIZE(xway_gpt_grps
)},
417 {"nmi", ARRAY_AND_SIZE(xway_nmi_grps
)},
418 {"pci", ARRAY_AND_SIZE(xway_pci_grps
)},
419 {"ebu", ARRAY_AND_SIZE(xway_ebu_grps
)},
422 static const struct ltq_pmx_func xrx_funcs
[] = {
423 {"spi", ARRAY_AND_SIZE(xway_spi_grps
)},
424 {"asc", ARRAY_AND_SIZE(xway_asc_grps
)},
425 {"cgu", ARRAY_AND_SIZE(xway_cgu_grps
)},
426 {"jtag", ARRAY_AND_SIZE(xway_jtag_grps
)},
427 {"exin", ARRAY_AND_SIZE(xrx_exin_grps
)},
428 {"stp", ARRAY_AND_SIZE(xway_stp_grps
)},
429 {"gpt", ARRAY_AND_SIZE(xway_gpt_grps
)},
430 {"nmi", ARRAY_AND_SIZE(xway_nmi_grps
)},
431 {"pci", ARRAY_AND_SIZE(xrx_pci_grps
)},
432 {"ebu", ARRAY_AND_SIZE(xrx_ebu_grps
)},
433 {"mdio", ARRAY_AND_SIZE(xrx_mdio_grps
)},
434 {"gphy", ARRAY_AND_SIZE(xrx_gphy_grps
)},
437 static const struct ltq_pmx_func ase_funcs
[] = {
438 {"spi", ARRAY_AND_SIZE(ase_spi_grps
)},
439 {"asc", ARRAY_AND_SIZE(ase_asc_grps
)},
440 {"jtag", ARRAY_AND_SIZE(ase_jtag_grps
)},
441 {"exin", ARRAY_AND_SIZE(ase_exin_grps
)},
442 {"stp", ARRAY_AND_SIZE(ase_stp_grps
)},
443 {"gpt", ARRAY_AND_SIZE(ase_gpt_grps
)},
444 {"ephy", ARRAY_AND_SIZE(ase_ephy_grps
)},
445 {"dfe", ARRAY_AND_SIZE(ase_dfe_grps
)},
448 /* --------- pinconf related code --------- */
449 static int xway_pinconf_get(struct pinctrl_dev
*pctldev
,
451 unsigned long *config
)
453 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctldev
);
454 enum ltq_pinconf_param param
= LTQ_PINCONF_UNPACK_PARAM(*config
);
455 int port
= PORT(pin
);
459 case LTQ_PINCONF_PARAM_OPEN_DRAIN
:
464 *config
= LTQ_PINCONF_PACK(param
,
465 !gpio_getbit(info
->membase
[0], reg
, PORT_PIN(pin
)));
468 case LTQ_PINCONF_PARAM_PULL
:
472 reg
= GPIO_PUDEN(pin
);
473 if (!gpio_getbit(info
->membase
[0], reg
, PORT_PIN(pin
))) {
474 *config
= LTQ_PINCONF_PACK(param
, 0);
481 reg
= GPIO_PUDSEL(pin
);
482 if (!gpio_getbit(info
->membase
[0], reg
, PORT_PIN(pin
)))
483 *config
= LTQ_PINCONF_PACK(param
, 2);
485 *config
= LTQ_PINCONF_PACK(param
, 1);
488 case LTQ_PINCONF_PARAM_OUTPUT
:
490 *config
= LTQ_PINCONF_PACK(param
,
491 gpio_getbit(info
->membase
[0], reg
, PORT_PIN(pin
)));
494 dev_err(pctldev
->dev
, "Invalid config param %04x\n", param
);
500 static int xway_pinconf_set(struct pinctrl_dev
*pctldev
,
502 unsigned long *configs
,
503 unsigned num_configs
)
505 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctldev
);
506 enum ltq_pinconf_param param
;
508 int port
= PORT(pin
);
512 for (i
= 0; i
< num_configs
; i
++) {
513 param
= LTQ_PINCONF_UNPACK_PARAM(configs
[i
]);
514 arg
= LTQ_PINCONF_UNPACK_ARG(configs
[i
]);
517 case LTQ_PINCONF_PARAM_OPEN_DRAIN
:
523 gpio_setbit(info
->membase
[0],
527 gpio_clearbit(info
->membase
[0],
532 case LTQ_PINCONF_PARAM_PULL
:
536 reg
= GPIO_PUDEN(pin
);
538 gpio_clearbit(info
->membase
[0],
543 gpio_setbit(info
->membase
[0], reg
, PORT_PIN(pin
));
548 reg
= GPIO_PUDSEL(pin
);
550 gpio_clearbit(info
->membase
[0],
554 gpio_setbit(info
->membase
[0],
558 dev_err(pctldev
->dev
,
559 "Invalid pull value %d\n", arg
);
562 case LTQ_PINCONF_PARAM_OUTPUT
:
565 gpio_clearbit(info
->membase
[0],
569 gpio_setbit(info
->membase
[0],
575 dev_err(pctldev
->dev
,
576 "Invalid config param %04x\n", param
);
579 } /* for each config */
584 int xway_pinconf_group_set(struct pinctrl_dev
*pctldev
,
586 unsigned long *configs
,
587 unsigned num_configs
)
589 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctldev
);
592 for (i
= 0; i
< info
->grps
[selector
].npins
&& !ret
; i
++)
593 ret
= xway_pinconf_set(pctldev
,
594 info
->grps
[selector
].pins
[i
],
601 static const struct pinconf_ops xway_pinconf_ops
= {
602 .pin_config_get
= xway_pinconf_get
,
603 .pin_config_set
= xway_pinconf_set
,
604 .pin_config_group_set
= xway_pinconf_group_set
,
607 static struct pinctrl_desc xway_pctrl_desc
= {
608 .owner
= THIS_MODULE
,
609 .confops
= &xway_pinconf_ops
,
612 static inline int xway_mux_apply(struct pinctrl_dev
*pctrldev
,
615 struct ltq_pinmux_info
*info
= pinctrl_dev_get_drvdata(pctrldev
);
616 int port
= PORT(pin
);
617 u32 alt1_reg
= GPIO_ALT1(pin
);
620 alt1_reg
= GPIO3_ALT1
;
623 gpio_setbit(info
->membase
[0], GPIO_ALT0(pin
), PORT_PIN(pin
));
625 gpio_clearbit(info
->membase
[0], GPIO_ALT0(pin
), PORT_PIN(pin
));
628 gpio_setbit(info
->membase
[0], alt1_reg
, PORT_PIN(pin
));
630 gpio_clearbit(info
->membase
[0], alt1_reg
, PORT_PIN(pin
));
635 static const struct ltq_cfg_param xway_cfg_params
[] = {
636 {"lantiq,pull", LTQ_PINCONF_PARAM_PULL
},
637 {"lantiq,open-drain", LTQ_PINCONF_PARAM_OPEN_DRAIN
},
638 {"lantiq,output", LTQ_PINCONF_PARAM_OUTPUT
},
641 static struct ltq_pinmux_info xway_info
= {
642 .desc
= &xway_pctrl_desc
,
643 .apply_mux
= xway_mux_apply
,
644 .params
= xway_cfg_params
,
645 .num_params
= ARRAY_SIZE(xway_cfg_params
),
648 /* --------- gpio_chip related code --------- */
649 static void xway_gpio_set(struct gpio_chip
*chip
, unsigned int pin
, int val
)
651 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
654 gpio_setbit(info
->membase
[0], GPIO_OUT(pin
), PORT_PIN(pin
));
656 gpio_clearbit(info
->membase
[0], GPIO_OUT(pin
), PORT_PIN(pin
));
659 static int xway_gpio_get(struct gpio_chip
*chip
, unsigned int pin
)
661 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
663 return gpio_getbit(info
->membase
[0], GPIO_IN(pin
), PORT_PIN(pin
));
666 static int xway_gpio_dir_in(struct gpio_chip
*chip
, unsigned int pin
)
668 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
670 gpio_clearbit(info
->membase
[0], GPIO_DIR(pin
), PORT_PIN(pin
));
675 static int xway_gpio_dir_out(struct gpio_chip
*chip
, unsigned int pin
, int val
)
677 struct ltq_pinmux_info
*info
= dev_get_drvdata(chip
->dev
);
679 gpio_setbit(info
->membase
[0], GPIO_DIR(pin
), PORT_PIN(pin
));
680 xway_gpio_set(chip
, pin
, val
);
685 static int xway_gpio_req(struct gpio_chip
*chip
, unsigned offset
)
687 int gpio
= chip
->base
+ offset
;
689 return pinctrl_request_gpio(gpio
);
692 static void xway_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
694 int gpio
= chip
->base
+ offset
;
696 pinctrl_free_gpio(gpio
);
699 static struct gpio_chip xway_chip
= {
700 .label
= "gpio-xway",
701 .direction_input
= xway_gpio_dir_in
,
702 .direction_output
= xway_gpio_dir_out
,
703 .get
= xway_gpio_get
,
704 .set
= xway_gpio_set
,
705 .request
= xway_gpio_req
,
706 .free
= xway_gpio_free
,
711 /* --------- register the pinctrl layer --------- */
712 static const unsigned xway_exin_pin_map
[] = {GPIO0
, GPIO1
, GPIO2
, GPIO39
, GPIO46
, GPIO9
};
713 static const unsigned ase_exin_pins_map
[] = {GPIO6
, GPIO29
, GPIO0
};
715 static struct pinctrl_xway_soc
{
717 const struct ltq_mfp_pin
*mfp
;
718 const struct ltq_pin_group
*grps
;
719 unsigned int num_grps
;
720 const struct ltq_pmx_func
*funcs
;
721 unsigned int num_funcs
;
722 const unsigned *exin
;
723 unsigned int num_exin
;
726 {XWAY_MAX_PIN
, xway_mfp
,
727 xway_grps
, ARRAY_SIZE(xway_grps
),
728 danube_funcs
, ARRAY_SIZE(danube_funcs
),
729 xway_exin_pin_map
, 3},
730 /* xway xr9 series */
731 {XR9_MAX_PIN
, xway_mfp
,
732 xway_grps
, ARRAY_SIZE(xway_grps
),
733 xrx_funcs
, ARRAY_SIZE(xrx_funcs
),
734 xway_exin_pin_map
, 6},
735 /* xway ase series */
736 {XWAY_MAX_PIN
, ase_mfp
,
737 ase_grps
, ARRAY_SIZE(ase_grps
),
738 ase_funcs
, ARRAY_SIZE(ase_funcs
),
739 ase_exin_pins_map
, 3},
742 static struct pinctrl_gpio_range xway_gpio_range
= {
747 static const struct of_device_id xway_match
[] = {
748 { .compatible
= "lantiq,pinctrl-xway", .data
= &soc_cfg
[0]},
749 { .compatible
= "lantiq,pinctrl-xr9", .data
= &soc_cfg
[1]},
750 { .compatible
= "lantiq,pinctrl-ase", .data
= &soc_cfg
[2]},
753 MODULE_DEVICE_TABLE(of
, xway_match
);
755 static int pinmux_xway_probe(struct platform_device
*pdev
)
757 const struct of_device_id
*match
;
758 const struct pinctrl_xway_soc
*xway_soc
;
759 struct resource
*res
;
762 /* get and remap our register range */
763 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
764 xway_info
.membase
[0] = devm_ioremap_resource(&pdev
->dev
, res
);
765 if (IS_ERR(xway_info
.membase
[0]))
766 return PTR_ERR(xway_info
.membase
[0]);
768 match
= of_match_device(xway_match
, &pdev
->dev
);
770 xway_soc
= (const struct pinctrl_xway_soc
*) match
->data
;
772 xway_soc
= &soc_cfg
[0];
774 /* find out how many pads we have */
775 xway_chip
.ngpio
= xway_soc
->pin_count
;
777 /* load our pad descriptors */
778 xway_info
.pads
= devm_kzalloc(&pdev
->dev
,
779 sizeof(struct pinctrl_pin_desc
) * xway_chip
.ngpio
,
781 if (!xway_info
.pads
) {
782 dev_err(&pdev
->dev
, "Failed to allocate pads\n");
785 for (i
= 0; i
< xway_chip
.ngpio
; i
++) {
786 /* strlen("ioXY") + 1 = 5 */
787 char *name
= devm_kzalloc(&pdev
->dev
, 5, GFP_KERNEL
);
790 dev_err(&pdev
->dev
, "Failed to allocate pad name\n");
793 snprintf(name
, 5, "io%d", i
);
794 xway_info
.pads
[i
].number
= GPIO0
+ i
;
795 xway_info
.pads
[i
].name
= name
;
797 xway_pctrl_desc
.pins
= xway_info
.pads
;
799 /* load the gpio chip */
800 xway_chip
.dev
= &pdev
->dev
;
801 ret
= gpiochip_add(&xway_chip
);
803 dev_err(&pdev
->dev
, "Failed to register gpio chip\n");
807 /* setup the data needed by pinctrl */
808 xway_pctrl_desc
.name
= dev_name(&pdev
->dev
);
809 xway_pctrl_desc
.npins
= xway_chip
.ngpio
;
811 xway_info
.num_pads
= xway_chip
.ngpio
;
812 xway_info
.num_mfp
= xway_chip
.ngpio
;
813 xway_info
.mfp
= xway_soc
->mfp
;
814 xway_info
.grps
= xway_soc
->grps
;
815 xway_info
.num_grps
= xway_soc
->num_grps
;
816 xway_info
.funcs
= xway_soc
->funcs
;
817 xway_info
.num_funcs
= xway_soc
->num_funcs
;
818 xway_info
.exin
= xway_soc
->exin
;
819 xway_info
.num_exin
= xway_soc
->num_exin
;
821 /* register with the generic lantiq layer */
822 ret
= ltq_pinctrl_register(pdev
, &xway_info
);
824 gpiochip_remove(&xway_chip
);
825 dev_err(&pdev
->dev
, "Failed to register pinctrl driver\n");
829 /* finish with registering the gpio range in pinctrl */
830 xway_gpio_range
.npins
= xway_chip
.ngpio
;
831 xway_gpio_range
.base
= xway_chip
.base
;
832 pinctrl_add_gpio_range(xway_info
.pctrl
, &xway_gpio_range
);
833 dev_info(&pdev
->dev
, "Init done\n");
837 static struct platform_driver pinmux_xway_driver
= {
838 .probe
= pinmux_xway_probe
,
840 .name
= "pinctrl-xway",
841 .of_match_table
= xway_match
,
845 static int __init
pinmux_xway_init(void)
847 return platform_driver_register(&pinmux_xway_driver
);
850 core_initcall_sync(pinmux_xway_init
);