12 #include <linux/slab.h>
13 #include <linux/module.h>
19 #include <linux/device.h>
24 #include <lantiq_soc.h>
29 #define PORT(x) (x / PINS)
30 #define PORT_PIN(x) (x % PINS)
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)
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)
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
205 static const unsigned pins_asc0_cts_rts[] = {
GPIO9,
GPIO10};
207 static const unsigned pins_nmi[] = {
GPIO8};
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};
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};
259 static const unsigned ase_pins_asc[] = {
GPIO5,
GPIO6};
262 static const unsigned ase_pins_dfe[] = {
GPIO1,
GPIO2};
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};
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),
299 GRP_MUX(
"asc0 cts rts",
ASC, pins_asc0_cts_rts),
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),
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),
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),
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),
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"};
430 static int xway_pinconf_get(
struct pinctrl_dev *pctldev,
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)
483 int port =
PORT(pin);
515 dev_err(pctldev->
dev,
"Invalid pull value %d\n", arg);
519 dev_err(pctldev->
dev,
"Invalid config param %04x\n", param);
526 .pin_config_get = xway_pinconf_get,
527 .pin_config_set = xway_pinconf_set,
530 static struct pinctrl_desc xway_pctrl_desc = {
535 static inline int xway_mux_apply(
struct pinctrl_dev *pctrldev,
539 int port =
PORT(pin);
564 .desc = &xway_pctrl_desc,
565 .apply_mux = xway_mux_apply,
566 .params = xway_cfg_params,
571 static void xway_gpio_set(
struct gpio_chip *
chip,
unsigned int pin,
int val)
581 static int xway_gpio_get(
struct gpio_chip *chip,
unsigned int pin)
588 static int xway_gpio_dir_in(
struct gpio_chip *chip,
unsigned int pin)
597 static int xway_gpio_dir_out(
struct gpio_chip *chip,
unsigned int pin,
int val)
602 xway_gpio_set(chip, pin, val);
607 static int xway_gpio_req(
struct gpio_chip *chip,
unsigned offset)
614 static void xway_gpio_free(
struct gpio_chip *chip,
unsigned offset)
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,
637 static struct pinctrl_xway_soc {
641 unsigned int num_grps;
644 const unsigned *exin;
645 unsigned int num_exin;
651 xway_exin_pin_map, 3},
656 xway_exin_pin_map, 6},
661 ase_exin_pins_map, 3},
664 static struct pinctrl_gpio_range xway_gpio_range = {
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]},
680 const struct pinctrl_xway_soc *xway_soc;
687 dev_err(&pdev->
dev,
"Failed to get resource\n");
692 dev_err(&pdev->
dev,
"Failed to remap resource\n");
698 xway_soc = (
const struct pinctrl_xway_soc *) match->
data;
700 xway_soc = &soc_cfg[0];
703 xway_chip.ngpio = xway_soc->pin_count;
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++) {
718 dev_err(&pdev->
dev,
"Failed to allocate pad name\n");
725 xway_pctrl_desc.pins = xway_info.
pads;
728 xway_chip.dev = &pdev->
dev;
732 dev_err(&pdev->
dev,
"Failed to register gpio chip\n");
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;
753 dev_err(&pdev->
dev,
"Failed to register pinctrl driver\n");
758 xway_gpio_range.npins = xway_chip.ngpio;
759 xway_gpio_range.base = xway_chip.base;
766 .probe = pinmux_xway_probe,
768 .name =
"pinctrl-xway",
770 .of_match_table = xway_match,
774 static int __init pinmux_xway_init(
void)