e06247753d148314f664aaa24de6699ad6141b84
[openwrt/staging/zorun.git] /
1 From 268bd5b5557ccb0ac4eae998ad7c6261c240b89b Mon Sep 17 00:00:00 2001
2 From: Stefan Wahren <wahrenst@gmx.net>
3 Date: Sun, 21 Jul 2019 16:01:36 +0200
4 Subject: [PATCH] pinctrl: bcm2835: Add support for BCM2711 pull-up
5 functionality
6
7 commit e38a9a437fb93ddafab5030165e4c6a3a5021669 upstream.
8
9 The BCM2711 has a new way of selecting the pull-up/pull-down setting
10 for a GPIO pin. The registers used for the BCM2835, GP_PUD and
11 GP_PUDCLKn0, are no longer connected. A new set of registers,
12 GP_GPIO_PUP_PDN_CNTRL_REGx must be used. This commit will add
13 a new compatible string "brcm,bcm2711-gpio" and the kernel
14 driver will use it to select which method is used to select
15 pull-up/pull-down.
16
17 This patch based on a patch by Al Cooper which was intended for the
18 BCM7211. This is a bugfixed and improved version.
19
20 Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
21 Acked-by: Eric Anholt <eric@anholt.net>
22 ---
23 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 105 ++++++++++++++++++++++++--
24 1 file changed, 100 insertions(+), 5 deletions(-)
25
26 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
27 +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
28 @@ -57,15 +57,24 @@
29 #define GPAFEN0 0x88 /* Pin Async Falling Edge Detect */
30 #define GPPUD 0x94 /* Pin Pull-up/down Enable */
31 #define GPPUDCLK0 0x98 /* Pin Pull-up/down Enable Clock */
32 +#define GP_GPIO_PUP_PDN_CNTRL_REG0 0xe4 /* 2711 Pin Pull-up/down select */
33
34 #define FSEL_REG(p) (GPFSEL0 + (((p) / 10) * 4))
35 #define FSEL_SHIFT(p) (((p) % 10) * 3)
36 #define GPIO_REG_OFFSET(p) ((p) / 32)
37 #define GPIO_REG_SHIFT(p) ((p) % 32)
38
39 +#define PUD_2711_MASK 0x3
40 +#define PUD_2711_REG_OFFSET(p) ((p) / 16)
41 +#define PUD_2711_REG_SHIFT(p) (((p) % 16) * 2)
42 +
43 /* argument: bcm2835_pinconf_pull */
44 #define BCM2835_PINCONF_PARAM_PULL (PIN_CONFIG_END + 1)
45
46 +#define BCM2711_PULL_NONE 0x0
47 +#define BCM2711_PULL_UP 0x1
48 +#define BCM2711_PULL_DOWN 0x2
49 +
50 struct bcm2835_pinctrl {
51 struct device *dev;
52 void __iomem *base;
53 @@ -975,6 +984,77 @@ static const struct pinconf_ops bcm2835_
54 .pin_config_set = bcm2835_pinconf_set,
55 };
56
57 +static void bcm2711_pull_config_set(struct bcm2835_pinctrl *pc,
58 + unsigned int pin, unsigned int arg)
59 +{
60 + u32 shifter;
61 + u32 value;
62 + u32 off;
63 +
64 + off = PUD_2711_REG_OFFSET(pin);
65 + shifter = PUD_2711_REG_SHIFT(pin);
66 +
67 + value = bcm2835_gpio_rd(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4));
68 + value &= ~(PUD_2711_MASK << shifter);
69 + value |= (arg << shifter);
70 + bcm2835_gpio_wr(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (off * 4), value);
71 +}
72 +
73 +static int bcm2711_pinconf_set(struct pinctrl_dev *pctldev,
74 + unsigned int pin, unsigned long *configs,
75 + unsigned int num_configs)
76 +{
77 + struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
78 + u32 param, arg;
79 + int i;
80 +
81 + for (i = 0; i < num_configs; i++) {
82 + param = pinconf_to_config_param(configs[i]);
83 + arg = pinconf_to_config_argument(configs[i]);
84 +
85 + switch (param) {
86 + /* convert legacy brcm,pull */
87 + case BCM2835_PINCONF_PARAM_PULL:
88 + if (arg == BCM2835_PUD_UP)
89 + arg = BCM2711_PULL_UP;
90 + else if (arg == BCM2835_PUD_DOWN)
91 + arg = BCM2711_PULL_DOWN;
92 + else
93 + arg = BCM2711_PULL_NONE;
94 +
95 + bcm2711_pull_config_set(pc, pin, arg);
96 + break;
97 +
98 + /* Set pull generic bindings */
99 + case PIN_CONFIG_BIAS_DISABLE:
100 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_NONE);
101 + break;
102 + case PIN_CONFIG_BIAS_PULL_DOWN:
103 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_DOWN);
104 + break;
105 + case PIN_CONFIG_BIAS_PULL_UP:
106 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_UP);
107 + break;
108 +
109 + /* Set output-high or output-low */
110 + case PIN_CONFIG_OUTPUT:
111 + bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin);
112 + break;
113 +
114 + default:
115 + return -ENOTSUPP;
116 + }
117 + } /* for each config */
118 +
119 + return 0;
120 +}
121 +
122 +static const struct pinconf_ops bcm2711_pinconf_ops = {
123 + .is_generic = true,
124 + .pin_config_get = bcm2835_pinconf_get,
125 + .pin_config_set = bcm2711_pinconf_set,
126 +};
127 +
128 static struct pinctrl_desc bcm2835_pinctrl_desc = {
129 .name = MODULE_NAME,
130 .pins = bcm2835_gpio_pins,
131 @@ -990,6 +1070,18 @@ static struct pinctrl_gpio_range bcm2835
132 .npins = BCM2835_NUM_GPIOS,
133 };
134
135 +static const struct of_device_id bcm2835_pinctrl_match[] = {
136 + {
137 + .compatible = "brcm,bcm2835-gpio",
138 + .data = &bcm2835_pinconf_ops,
139 + },
140 + {
141 + .compatible = "brcm,bcm2711-gpio",
142 + .data = &bcm2711_pinconf_ops,
143 + },
144 + {}
145 +};
146 +
147 static int bcm2835_pinctrl_probe(struct platform_device *pdev)
148 {
149 struct device *dev = &pdev->dev;
150 @@ -997,6 +1089,8 @@ static int bcm2835_pinctrl_probe(struct
151 struct bcm2835_pinctrl *pc;
152 struct resource iomem;
153 int err, i;
154 + const struct of_device_id *match;
155 +
156 BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_pins) != BCM2835_NUM_GPIOS);
157 BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_groups) != BCM2835_NUM_GPIOS);
158
159 @@ -1073,6 +1167,12 @@ static int bcm2835_pinctrl_probe(struct
160 bcm2835_gpio_irq_handler);
161 }
162
163 + match = of_match_node(bcm2835_pinctrl_match, pdev->dev.of_node);
164 + if (match) {
165 + bcm2835_pinctrl_desc.confops =
166 + (const struct pinconf_ops *)match->data;
167 + }
168 +
169 pc->pctl_dev = devm_pinctrl_register(dev, &bcm2835_pinctrl_desc, pc);
170 if (IS_ERR(pc->pctl_dev)) {
171 gpiochip_remove(&pc->gpio_chip);
172 @@ -1087,11 +1187,6 @@ static int bcm2835_pinctrl_probe(struct
173 return 0;
174 }
175
176 -static const struct of_device_id bcm2835_pinctrl_match[] = {
177 - { .compatible = "brcm,bcm2835-gpio" },
178 - {}
179 -};
180 -
181 static struct platform_driver bcm2835_pinctrl_driver = {
182 .probe = bcm2835_pinctrl_probe,
183 .driver = {