]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/pinctrl/pinctrl-xway.c
pinctrl: tz1090-pdc: Convert to devm_ioremap_resource
[mirror_ubuntu-artful-kernel.git] / drivers / pinctrl / pinctrl-xway.c
CommitLineData
3f8c50c9
JC
1/*
2 * linux/drivers/pinctrl/pinmux-xway.c
3 * based on linux/drivers/pinctrl/pinmux-pxa910.c
4 *
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.
8 *
9 * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
10 */
11
9e0c1fb2 12#include <linux/err.h>
3f8c50c9
JC
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>
19#include <linux/io.h>
20#include <linux/device.h>
3f8c50c9
JC
21#include <linux/platform_device.h>
22
23#include "pinctrl-lantiq.h"
24
25#include <lantiq_soc.h>
26
27/* we have 3 1/2 banks of 16 bit each */
28#define PINS 16
29#define PORT3 3
30#define PORT(x) (x / PINS)
31#define PORT_PIN(x) (x % PINS)
32
33/* we have 2 mux bits that can be set for each pin */
34#define MUX_ALT0 0x1
35#define MUX_ALT1 0x2
36
37/*
38 * each bank has this offset apart from the 1/2 bank that is mixed into the
39 * other 3 ranges
40 */
41#define REG_OFF 0x30
42
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)
53
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)
59
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)
64
65#define MFP_XWAY(a, f0, f1, f2, f3) \
66 { \
67 .name = #a, \
68 .pin = a, \
69 .func = { \
70 XWAY_MUX_##f0, \
71 XWAY_MUX_##f1, \
72 XWAY_MUX_##f2, \
73 XWAY_MUX_##f3, \
74 }, \
75 }
76
77#define GRP_MUX(a, m, p) \
78 { .name = a, .mux = XWAY_MUX_##m, .pins = p, .npins = ARRAY_SIZE(p), }
79
80#define FUNC_MUX(f, m) \
81 { .func = f, .mux = XWAY_MUX_##m, }
82
83#define XWAY_MAX_PIN 32
84#define XR9_MAX_PIN 56
85
86enum xway_mux {
87 XWAY_MUX_GPIO = 0,
88 XWAY_MUX_SPI,
89 XWAY_MUX_ASC,
90 XWAY_MUX_PCI,
91 XWAY_MUX_CGU,
92 XWAY_MUX_EBU,
93 XWAY_MUX_JTAG,
94 XWAY_MUX_EXIN,
95 XWAY_MUX_TDM,
96 XWAY_MUX_STP,
97 XWAY_MUX_SIN,
98 XWAY_MUX_GPT,
99 XWAY_MUX_NMI,
100 XWAY_MUX_MDIO,
101 XWAY_MUX_MII,
102 XWAY_MUX_EPHY,
103 XWAY_MUX_DFE,
104 XWAY_MUX_SDIO,
0fabc835 105 XWAY_MUX_GPHY,
3f8c50c9
JC
106 XWAY_MUX_NONE = 0xffff,
107};
108
109static 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),
0fabc835 113 MFP_XWAY(GPIO2, GPIO, CGU, EXIN, GPHY),
3f8c50c9
JC
114 MFP_XWAY(GPIO3, GPIO, CGU, NONE, PCI),
115 MFP_XWAY(GPIO4, GPIO, STP, NONE, ASC),
0fabc835 116 MFP_XWAY(GPIO5, GPIO, STP, NONE, GPHY),
3f8c50c9 117 MFP_XWAY(GPIO6, GPIO, STP, GPT, ASC),
0fabc835 118 MFP_XWAY(GPIO7, GPIO, CGU, PCI, GPHY),
3f8c50c9
JC
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),
0fabc835
JC
155 MFP_XWAY(GPIO44, GPIO, NONE, GPHY, SIN),
156 MFP_XWAY(GPIO45, GPIO, NONE, GPHY, SIN),
3f8c50c9 157 MFP_XWAY(GPIO46, GPIO, NONE, NONE, EXIN),
0fabc835 158 MFP_XWAY(GPIO47, GPIO, NONE, GPHY, SIN),
3f8c50c9
JC
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),
167};
168
169static 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),
203};
204
205static const unsigned pins_jtag[] = {GPIO15, GPIO16, GPIO17, GPIO19, GPIO35};
206static const unsigned pins_asc0[] = {GPIO11, GPIO12};
207static const unsigned pins_asc0_cts_rts[] = {GPIO9, GPIO10};
208static const unsigned pins_stp[] = {GPIO4, GPIO5, GPIO6};
209static const unsigned pins_nmi[] = {GPIO8};
210static const unsigned pins_mdio[] = {GPIO42, GPIO43};
211
0fabc835
JC
212static const unsigned pins_gphy0_led0[] = {GPIO5};
213static const unsigned pins_gphy0_led1[] = {GPIO7};
214static const unsigned pins_gphy0_led2[] = {GPIO2};
215static const unsigned pins_gphy1_led0[] = {GPIO44};
216static const unsigned pins_gphy1_led1[] = {GPIO45};
217static const unsigned pins_gphy1_led2[] = {GPIO47};
218
3f8c50c9
JC
219static const unsigned pins_ebu_a24[] = {GPIO13};
220static const unsigned pins_ebu_clk[] = {GPIO21};
221static const unsigned pins_ebu_cs1[] = {GPIO23};
222static const unsigned pins_ebu_a23[] = {GPIO24};
223static const unsigned pins_ebu_wait[] = {GPIO26};
224static const unsigned pins_ebu_a25[] = {GPIO31};
225static const unsigned pins_ebu_rdy[] = {GPIO48};
226static const unsigned pins_ebu_rd[] = {GPIO49};
227
228static const unsigned pins_nand_ale[] = {GPIO13};
229static const unsigned pins_nand_cs1[] = {GPIO23};
230static const unsigned pins_nand_cle[] = {GPIO24};
231static const unsigned pins_nand_rdy[] = {GPIO48};
232static const unsigned pins_nand_rd[] = {GPIO49};
233
234static const unsigned pins_exin0[] = {GPIO0};
235static const unsigned pins_exin1[] = {GPIO1};
236static const unsigned pins_exin2[] = {GPIO2};
237static const unsigned pins_exin3[] = {GPIO39};
238static const unsigned pins_exin4[] = {GPIO46};
239static const unsigned pins_exin5[] = {GPIO9};
240
241static const unsigned pins_spi[] = {GPIO16, GPIO17, GPIO18};
242static const unsigned pins_spi_cs1[] = {GPIO15};
243static const unsigned pins_spi_cs2[] = {GPIO21};
244static const unsigned pins_spi_cs3[] = {GPIO13};
245static const unsigned pins_spi_cs4[] = {GPIO10};
246static const unsigned pins_spi_cs5[] = {GPIO9};
247static const unsigned pins_spi_cs6[] = {GPIO11};
248
249static const unsigned pins_gpt1[] = {GPIO28};
250static const unsigned pins_gpt2[] = {GPIO21};
251static const unsigned pins_gpt3[] = {GPIO6};
252
253static const unsigned pins_clkout0[] = {GPIO8};
254static const unsigned pins_clkout1[] = {GPIO7};
255static const unsigned pins_clkout2[] = {GPIO3};
256static const unsigned pins_clkout3[] = {GPIO2};
257
258static const unsigned pins_pci_gnt1[] = {GPIO30};
259static const unsigned pins_pci_gnt2[] = {GPIO23};
260static const unsigned pins_pci_gnt3[] = {GPIO19};
261static const unsigned pins_pci_gnt4[] = {GPIO38};
262static const unsigned pins_pci_req1[] = {GPIO29};
263static const unsigned pins_pci_req2[] = {GPIO31};
264static const unsigned pins_pci_req3[] = {GPIO3};
265static const unsigned pins_pci_req4[] = {GPIO37};
266
267static const unsigned ase_pins_jtag[] = {GPIO7, GPIO8, GPIO9, GPIO10, GPIO11};
268static const unsigned ase_pins_asc[] = {GPIO5, GPIO6};
269static const unsigned ase_pins_stp[] = {GPIO1, GPIO2, GPIO3};
270static const unsigned ase_pins_ephy[] = {GPIO2, GPIO3, GPIO4};
271static const unsigned ase_pins_dfe[] = {GPIO1, GPIO2};
272
273static const unsigned ase_pins_spi[] = {GPIO8, GPIO9, GPIO10};
274static const unsigned ase_pins_spi_cs1[] = {GPIO7};
275static const unsigned ase_pins_spi_cs2[] = {GPIO15};
276static const unsigned ase_pins_spi_cs3[] = {GPIO14};
277
278static const unsigned ase_pins_exin0[] = {GPIO6};
279static const unsigned ase_pins_exin1[] = {GPIO29};
280static const unsigned ase_pins_exin2[] = {GPIO0};
281
282static const unsigned ase_pins_gpt1[] = {GPIO5};
283static const unsigned ase_pins_gpt2[] = {GPIO4};
284static const unsigned ase_pins_gpt3[] = {GPIO25};
285
286static 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),
324/* xrx only */
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),
0fabc835
JC
333 GRP_MUX("gphy0 led0", GPHY, pins_gphy0_led0),
334 GRP_MUX("gphy0 led1", GPHY, pins_gphy0_led1),
335 GRP_MUX("gphy0 lde2", 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 lde2", GPHY, pins_gphy1_led2),
3f8c50c9
JC
339};
340
341static 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),
357};
358
359static const char * const xway_pci_grps[] = {"gnt1", "gnt2",
360 "gnt3", "req1",
361 "req2", "req3"};
362static const char * const xway_spi_grps[] = {"spi", "spi_cs1",
363 "spi_cs2", "spi_cs3",
364 "spi_cs4", "spi_cs5",
365 "spi_cs6"};
366static const char * const xway_cgu_grps[] = {"clkout0", "clkout1",
367 "clkout2", "clkout3"};
368static 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",
372 "nand cle"};
373static const char * const xway_exin_grps[] = {"exin0", "exin1", "exin2"};
374static const char * const xway_gpt_grps[] = {"gpt1", "gpt2", "gpt3"};
375static const char * const xway_asc_grps[] = {"asc0", "asc0 cts rts"};
376static const char * const xway_jtag_grps[] = {"jtag"};
377static const char * const xway_stp_grps[] = {"stp"};
378static const char * const xway_nmi_grps[] = {"nmi"};
379
380/* ar9/vr9/gr9 */
381static const char * const xrx_mdio_grps[] = {"mdio"};
0fabc835
JC
382static const char * const xrx_gphy_grps[] = {"gphy0 led0", "gphy0 led1",
383 "gphy0 led2", "gphy1 led0",
384 "gphy1 led1", "gphy1 led2"};
3f8c50c9
JC
385static 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",
390 "nand rd"};
391static const char * const xrx_exin_grps[] = {"exin0", "exin1", "exin2",
392 "exin3", "exin4", "exin5"};
393static const char * const xrx_pci_grps[] = {"gnt1", "gnt2",
394 "gnt3", "gnt4",
395 "req1", "req2",
396 "req3", "req4"};
397
398/* ase */
399static const char * const ase_exin_grps[] = {"exin0", "exin1", "exin2"};
400static const char * const ase_gpt_grps[] = {"gpt1", "gpt2", "gpt3"};
401static const char * const ase_dfe_grps[] = {"dfe"};
402static const char * const ase_ephy_grps[] = {"ephy"};
403static const char * const ase_asc_grps[] = {"asc"};
404static const char * const ase_jtag_grps[] = {"jtag"};
405static const char * const ase_stp_grps[] = {"stp"};
406static const char * const ase_spi_grps[] = {"spi", "spi_cs1",
407 "spi_cs2", "spi_cs3"};
408
409static 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)},
420};
421
422static 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)},
0fabc835 434 {"gphy", ARRAY_AND_SIZE(xrx_gphy_grps)},
3f8c50c9
JC
435};
436
437static 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)},
446};
447
448/* --------- pinconf related code --------- */
449static int xway_pinconf_get(struct pinctrl_dev *pctldev,
450 unsigned pin,
451 unsigned long *config)
452{
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);
456 u32 reg;
457
458 switch (param) {
459 case LTQ_PINCONF_PARAM_OPEN_DRAIN:
460 if (port == PORT3)
461 reg = GPIO3_OD;
462 else
362ba3cf 463 reg = GPIO_OD(pin);
3f8c50c9 464 *config = LTQ_PINCONF_PACK(param,
7541083f 465 !gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
3f8c50c9
JC
466 break;
467
468 case LTQ_PINCONF_PARAM_PULL:
469 if (port == PORT3)
470 reg = GPIO3_PUDEN;
471 else
362ba3cf
JC
472 reg = GPIO_PUDEN(pin);
473 if (!gpio_getbit(info->membase[0], reg, PORT_PIN(pin))) {
3f8c50c9
JC
474 *config = LTQ_PINCONF_PACK(param, 0);
475 break;
476 }
477
478 if (port == PORT3)
479 reg = GPIO3_PUDSEL;
480 else
362ba3cf
JC
481 reg = GPIO_PUDSEL(pin);
482 if (!gpio_getbit(info->membase[0], reg, PORT_PIN(pin)))
3f8c50c9
JC
483 *config = LTQ_PINCONF_PACK(param, 2);
484 else
485 *config = LTQ_PINCONF_PACK(param, 1);
486 break;
487
6360350c
JC
488 case LTQ_PINCONF_PARAM_OUTPUT:
489 reg = GPIO_DIR(pin);
490 *config = LTQ_PINCONF_PACK(param,
491 gpio_getbit(info->membase[0], reg, PORT_PIN(pin)));
492 break;
3f8c50c9
JC
493 default:
494 dev_err(pctldev->dev, "Invalid config param %04x\n", param);
495 return -ENOTSUPP;
496 }
497 return 0;
498}
499
500static int xway_pinconf_set(struct pinctrl_dev *pctldev,
501 unsigned pin,
502 unsigned long config)
503{
504 struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
505 enum ltq_pinconf_param param = LTQ_PINCONF_UNPACK_PARAM(config);
506 int arg = LTQ_PINCONF_UNPACK_ARG(config);
507 int port = PORT(pin);
508 u32 reg;
509
510 switch (param) {
511 case LTQ_PINCONF_PARAM_OPEN_DRAIN:
512 if (port == PORT3)
513 reg = GPIO3_OD;
514 else
362ba3cf 515 reg = GPIO_OD(pin);
93386287
JC
516 if (arg == 0)
517 gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
518 else
519 gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
3f8c50c9
JC
520 break;
521
522 case LTQ_PINCONF_PARAM_PULL:
523 if (port == PORT3)
524 reg = GPIO3_PUDEN;
525 else
362ba3cf 526 reg = GPIO_PUDEN(pin);
3f8c50c9 527 if (arg == 0) {
362ba3cf 528 gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
3f8c50c9
JC
529 break;
530 }
362ba3cf 531 gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
3f8c50c9
JC
532
533 if (port == PORT3)
534 reg = GPIO3_PUDSEL;
535 else
362ba3cf 536 reg = GPIO_PUDSEL(pin);
3f8c50c9 537 if (arg == 1)
362ba3cf 538 gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
3f8c50c9 539 else if (arg == 2)
362ba3cf 540 gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
3f8c50c9
JC
541 else
542 dev_err(pctldev->dev, "Invalid pull value %d\n", arg);
543 break;
544
6360350c
JC
545 case LTQ_PINCONF_PARAM_OUTPUT:
546 reg = GPIO_DIR(pin);
547 if (arg == 0)
548 gpio_clearbit(info->membase[0], reg, PORT_PIN(pin));
549 else
550 gpio_setbit(info->membase[0], reg, PORT_PIN(pin));
551 break;
552
3f8c50c9
JC
553 default:
554 dev_err(pctldev->dev, "Invalid config param %04x\n", param);
555 return -ENOTSUPP;
556 }
557 return 0;
558}
559
3a6b04ca
JC
560int xway_pinconf_group_set(struct pinctrl_dev *pctldev,
561 unsigned selector,
562 unsigned long config)
563{
564 struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctldev);
565 int i, ret = 0;
566
567 for (i = 0; i < info->grps[selector].npins && !ret; i++)
568 ret = xway_pinconf_set(pctldev,
569 info->grps[selector].pins[i], config);
570
571 return ret;
572}
573
022ab148 574static const struct pinconf_ops xway_pinconf_ops = {
3f8c50c9
JC
575 .pin_config_get = xway_pinconf_get,
576 .pin_config_set = xway_pinconf_set,
3a6b04ca 577 .pin_config_group_set = xway_pinconf_group_set,
3f8c50c9
JC
578};
579
580static struct pinctrl_desc xway_pctrl_desc = {
581 .owner = THIS_MODULE,
582 .confops = &xway_pinconf_ops,
583};
584
585static inline int xway_mux_apply(struct pinctrl_dev *pctrldev,
586 int pin, int mux)
587{
588 struct ltq_pinmux_info *info = pinctrl_dev_get_drvdata(pctrldev);
589 int port = PORT(pin);
590 u32 alt1_reg = GPIO_ALT1(pin);
591
592 if (port == PORT3)
593 alt1_reg = GPIO3_ALT1;
594
595 if (mux & MUX_ALT0)
596 gpio_setbit(info->membase[0], GPIO_ALT0(pin), PORT_PIN(pin));
597 else
598 gpio_clearbit(info->membase[0], GPIO_ALT0(pin), PORT_PIN(pin));
599
600 if (mux & MUX_ALT1)
601 gpio_setbit(info->membase[0], alt1_reg, PORT_PIN(pin));
602 else
603 gpio_clearbit(info->membase[0], alt1_reg, PORT_PIN(pin));
604
605 return 0;
606}
607
608static const struct ltq_cfg_param xway_cfg_params[] = {
609 {"lantiq,pull", LTQ_PINCONF_PARAM_PULL},
610 {"lantiq,open-drain", LTQ_PINCONF_PARAM_OPEN_DRAIN},
6360350c 611 {"lantiq,output", LTQ_PINCONF_PARAM_OUTPUT},
3f8c50c9
JC
612};
613
614static struct ltq_pinmux_info xway_info = {
615 .desc = &xway_pctrl_desc,
616 .apply_mux = xway_mux_apply,
617 .params = xway_cfg_params,
618 .num_params = ARRAY_SIZE(xway_cfg_params),
619};
620
621/* --------- gpio_chip related code --------- */
622static void xway_gpio_set(struct gpio_chip *chip, unsigned int pin, int val)
623{
624 struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
625
626 if (val)
627 gpio_setbit(info->membase[0], GPIO_OUT(pin), PORT_PIN(pin));
628 else
629 gpio_clearbit(info->membase[0], GPIO_OUT(pin), PORT_PIN(pin));
630}
631
632static int xway_gpio_get(struct gpio_chip *chip, unsigned int pin)
633{
634 struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
635
636 return gpio_getbit(info->membase[0], GPIO_IN(pin), PORT_PIN(pin));
637}
638
639static int xway_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
640{
641 struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
642
643 gpio_clearbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin));
644
645 return 0;
646}
647
648static int xway_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, int val)
649{
650 struct ltq_pinmux_info *info = dev_get_drvdata(chip->dev);
651
652 gpio_setbit(info->membase[0], GPIO_DIR(pin), PORT_PIN(pin));
653 xway_gpio_set(chip, pin, val);
654
655 return 0;
656}
657
658static int xway_gpio_req(struct gpio_chip *chip, unsigned offset)
659{
660 int gpio = chip->base + offset;
661
662 return pinctrl_request_gpio(gpio);
663}
664
665static void xway_gpio_free(struct gpio_chip *chip, unsigned offset)
666{
667 int gpio = chip->base + offset;
668
669 pinctrl_free_gpio(gpio);
670}
671
672static struct gpio_chip xway_chip = {
673 .label = "gpio-xway",
674 .direction_input = xway_gpio_dir_in,
675 .direction_output = xway_gpio_dir_out,
676 .get = xway_gpio_get,
677 .set = xway_gpio_set,
678 .request = xway_gpio_req,
679 .free = xway_gpio_free,
680 .base = -1,
681};
682
683
684/* --------- register the pinctrl layer --------- */
685static const unsigned xway_exin_pin_map[] = {GPIO0, GPIO1, GPIO2, GPIO39, GPIO46, GPIO9};
686static const unsigned ase_exin_pins_map[] = {GPIO6, GPIO29, GPIO0};
687
688static struct pinctrl_xway_soc {
689 int pin_count;
690 const struct ltq_mfp_pin *mfp;
691 const struct ltq_pin_group *grps;
692 unsigned int num_grps;
693 const struct ltq_pmx_func *funcs;
694 unsigned int num_funcs;
695 const unsigned *exin;
696 unsigned int num_exin;
697} soc_cfg[] = {
698 /* legacy xway */
699 {XWAY_MAX_PIN, xway_mfp,
700 xway_grps, ARRAY_SIZE(xway_grps),
701 danube_funcs, ARRAY_SIZE(danube_funcs),
702 xway_exin_pin_map, 3},
703 /* xway xr9 series */
704 {XR9_MAX_PIN, xway_mfp,
705 xway_grps, ARRAY_SIZE(xway_grps),
706 xrx_funcs, ARRAY_SIZE(xrx_funcs),
707 xway_exin_pin_map, 6},
708 /* xway ase series */
709 {XWAY_MAX_PIN, ase_mfp,
710 ase_grps, ARRAY_SIZE(ase_grps),
711 ase_funcs, ARRAY_SIZE(ase_funcs),
712 ase_exin_pins_map, 3},
713};
714
715static struct pinctrl_gpio_range xway_gpio_range = {
716 .name = "XWAY GPIO",
717 .gc = &xway_chip,
718};
719
720static const struct of_device_id xway_match[] = {
721 { .compatible = "lantiq,pinctrl-xway", .data = &soc_cfg[0]},
722 { .compatible = "lantiq,pinctrl-xr9", .data = &soc_cfg[1]},
723 { .compatible = "lantiq,pinctrl-ase", .data = &soc_cfg[2]},
724 {},
725};
726MODULE_DEVICE_TABLE(of, xway_match);
727
150632b0 728static int pinmux_xway_probe(struct platform_device *pdev)
3f8c50c9
JC
729{
730 const struct of_device_id *match;
731 const struct pinctrl_xway_soc *xway_soc;
732 struct resource *res;
733 int ret, i;
734
735 /* get and remap our register range */
736 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
9e0c1fb2
TR
737 xway_info.membase[0] = devm_ioremap_resource(&pdev->dev, res);
738 if (IS_ERR(xway_info.membase[0]))
739 return PTR_ERR(xway_info.membase[0]);
3f8c50c9
JC
740
741 match = of_match_device(xway_match, &pdev->dev);
742 if (match)
743 xway_soc = (const struct pinctrl_xway_soc *) match->data;
744 else
745 xway_soc = &soc_cfg[0];
746
747 /* find out how many pads we have */
748 xway_chip.ngpio = xway_soc->pin_count;
749
750 /* load our pad descriptors */
751 xway_info.pads = devm_kzalloc(&pdev->dev,
752 sizeof(struct pinctrl_pin_desc) * xway_chip.ngpio,
753 GFP_KERNEL);
754 if (!xway_info.pads) {
755 dev_err(&pdev->dev, "Failed to allocate pads\n");
756 return -ENOMEM;
757 }
758 for (i = 0; i < xway_chip.ngpio; i++) {
759 /* strlen("ioXY") + 1 = 5 */
760 char *name = devm_kzalloc(&pdev->dev, 5, GFP_KERNEL);
761
762 if (!name) {
763 dev_err(&pdev->dev, "Failed to allocate pad name\n");
764 return -ENOMEM;
765 }
766 snprintf(name, 5, "io%d", i);
767 xway_info.pads[i].number = GPIO0 + i;
768 xway_info.pads[i].name = name;
769 }
770 xway_pctrl_desc.pins = xway_info.pads;
771
772 /* load the gpio chip */
773 xway_chip.dev = &pdev->dev;
774 of_gpiochip_add(&xway_chip);
775 ret = gpiochip_add(&xway_chip);
776 if (ret) {
777 dev_err(&pdev->dev, "Failed to register gpio chip\n");
778 return ret;
779 }
780
781 /* setup the data needed by pinctrl */
782 xway_pctrl_desc.name = dev_name(&pdev->dev);
783 xway_pctrl_desc.npins = xway_chip.ngpio;
784
785 xway_info.num_pads = xway_chip.ngpio;
786 xway_info.num_mfp = xway_chip.ngpio;
787 xway_info.mfp = xway_soc->mfp;
788 xway_info.grps = xway_soc->grps;
789 xway_info.num_grps = xway_soc->num_grps;
790 xway_info.funcs = xway_soc->funcs;
791 xway_info.num_funcs = xway_soc->num_funcs;
792 xway_info.exin = xway_soc->exin;
793 xway_info.num_exin = xway_soc->num_exin;
794
795 /* register with the generic lantiq layer */
796 ret = ltq_pinctrl_register(pdev, &xway_info);
797 if (ret) {
798 dev_err(&pdev->dev, "Failed to register pinctrl driver\n");
799 return ret;
800 }
801
802 /* finish with registering the gpio range in pinctrl */
803 xway_gpio_range.npins = xway_chip.ngpio;
804 xway_gpio_range.base = xway_chip.base;
805 pinctrl_add_gpio_range(xway_info.pctrl, &xway_gpio_range);
806 dev_info(&pdev->dev, "Init done\n");
807 return 0;
808}
809
810static struct platform_driver pinmux_xway_driver = {
811 .probe = pinmux_xway_probe,
812 .driver = {
813 .name = "pinctrl-xway",
814 .owner = THIS_MODULE,
815 .of_match_table = xway_match,
816 },
817};
818
819static int __init pinmux_xway_init(void)
820{
821 return platform_driver_register(&pinmux_xway_driver);
822}
823
824core_initcall_sync(pinmux_xway_init);