1 // SPDX-License-Identifier: GPL-2.0+
3 * R7S72100 processor support
5 * Copyright (C) 2019 Marek Vasut <marek.vasut@gmail.com>
10 #include <asm/global_data.h>
12 #include <dm/pinctrl.h>
13 #include <linux/bitops.h>
15 #include <linux/err.h>
17 #define P(bank) (0x0000 + (bank) * 4)
18 #define PSR(bank) (0x0100 + (bank) * 4)
19 #define PPR(bank) (0x0200 + (bank) * 4)
20 #define PM(bank) (0x0300 + (bank) * 4)
21 #define PMC(bank) (0x0400 + (bank) * 4)
22 #define PFC(bank) (0x0500 + (bank) * 4)
23 #define PFCE(bank) (0x0600 + (bank) * 4)
24 #define PNOT(bank) (0x0700 + (bank) * 4)
25 #define PMSR(bank) (0x0800 + (bank) * 4)
26 #define PMCSR(bank) (0x0900 + (bank) * 4)
27 #define PFCAE(bank) (0x0A00 + (bank) * 4)
28 #define PIBC(bank) (0x4000 + (bank) * 4)
29 #define PBDC(bank) (0x4100 + (bank) * 4)
30 #define PIPC(bank) (0x4200 + (bank) * 4)
32 #define RZA1_PINS_PER_PORT 16
34 DECLARE_GLOBAL_DATA_PTR;
36 struct r7s72100_pfc_plat {
40 static void r7s72100_pfc_set_function(struct udevice *dev, u16 bank, u16 line,
41 u16 func, u16 inbuf, u16 bidir)
43 struct r7s72100_pfc_plat *plat = dev_get_plat(dev);
45 clrsetbits_le16(plat->base + PFCAE(bank), BIT(line),
46 (func & BIT(2)) ? BIT(line) : 0);
47 clrsetbits_le16(plat->base + PFCE(bank), BIT(line),
48 (func & BIT(1)) ? BIT(line) : 0);
49 clrsetbits_le16(plat->base + PFC(bank), BIT(line),
50 (func & BIT(0)) ? BIT(line) : 0);
52 clrsetbits_le16(plat->base + PIBC(bank), BIT(line),
53 inbuf ? BIT(line) : 0);
54 clrsetbits_le16(plat->base + PBDC(bank), BIT(line),
55 bidir ? BIT(line) : 0);
57 setbits_le32(plat->base + PMCSR(bank), BIT(line + 16) | BIT(line));
59 setbits_le16(plat->base + PIPC(bank), BIT(line));
62 static int r7s72100_pfc_set_state(struct udevice *dev, struct udevice *config)
64 const void *blob = gd->fdt_blob;
65 int node = dev_of_offset(config);
70 count = fdtdec_get_int_array_count(blob, node, "pinmux",
71 cells, ARRAY_SIZE(cells));
73 printf("%s: bad pinmux array %d\n", __func__, count);
77 if (count > ARRAY_SIZE(cells)) {
78 printf("%s: unsupported pinmux array count %d\n",
83 for (i = 0 ; i < count; i++) {
84 func = (cells[i] >> 16) & 0xf;
85 if (func == 0 || func > 8) {
86 printf("Invalid cell %i in node %s!\n",
87 count, ofnode_get_name(dev_ofnode(config)));
91 func = (func - 1) & 0x7;
93 bank = (cells[i] / RZA1_PINS_PER_PORT) & 0xff;
94 line = cells[i] % RZA1_PINS_PER_PORT;
97 if (bank == 3 && line == 3 && func == 1)
100 r7s72100_pfc_set_function(dev, bank, line, func, 0, bidir);
106 const struct pinctrl_ops r7s72100_pfc_ops = {
107 .set_state = r7s72100_pfc_set_state,
110 static int r7s72100_pfc_probe(struct udevice *dev)
112 struct r7s72100_pfc_plat *plat = dev_get_plat(dev);
113 fdt_addr_t addr_base;
116 addr_base = dev_read_addr(dev);
117 if (addr_base == FDT_ADDR_T_NONE)
120 plat->base = (void __iomem *)addr_base;
122 dev_for_each_subnode(node, dev) {
123 struct udevice *cdev;
125 if (!ofnode_read_bool(node, "gpio-controller"))
128 device_bind_driver_to_node(dev, "r7s72100-gpio",
129 ofnode_get_name(node),
136 static const struct udevice_id r7s72100_pfc_match[] = {
137 { .compatible = "renesas,r7s72100-ports" },
141 U_BOOT_DRIVER(r7s72100_pfc) = {
142 .name = "r7s72100_pfc",
143 .id = UCLASS_PINCTRL,
144 .of_match = r7s72100_pfc_match,
145 .probe = r7s72100_pfc_probe,
146 .plat_auto = sizeof(struct r7s72100_pfc_plat),
147 .ops = &r7s72100_pfc_ops,