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
7 commit e38a9a437fb93ddafab5030165e4c6a3a5021669 upstream.
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
17 This patch based on a patch by Al Cooper which was intended for the
18 BCM7211. This is a bugfixed and improved version.
20 Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
21 Acked-by: Eric Anholt <eric@anholt.net>
23 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 105 ++++++++++++++++++++++++--
24 1 file changed, 100 insertions(+), 5 deletions(-)
26 --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
27 +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
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 */
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)
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)
43 /* argument: bcm2835_pinconf_pull */
44 #define BCM2835_PINCONF_PARAM_PULL (PIN_CONFIG_END + 1)
46 +#define BCM2711_PULL_NONE 0x0
47 +#define BCM2711_PULL_UP 0x1
48 +#define BCM2711_PULL_DOWN 0x2
50 struct bcm2835_pinctrl {
53 @@ -975,6 +984,77 @@ static const struct pinconf_ops bcm2835_
54 .pin_config_set = bcm2835_pinconf_set,
57 +static void bcm2711_pull_config_set(struct bcm2835_pinctrl *pc,
58 + unsigned int pin, unsigned int arg)
64 + off = PUD_2711_REG_OFFSET(pin);
65 + shifter = PUD_2711_REG_SHIFT(pin);
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);
73 +static int bcm2711_pinconf_set(struct pinctrl_dev *pctldev,
74 + unsigned int pin, unsigned long *configs,
75 + unsigned int num_configs)
77 + struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
81 + for (i = 0; i < num_configs; i++) {
82 + param = pinconf_to_config_param(configs[i]);
83 + arg = pinconf_to_config_argument(configs[i]);
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;
93 + arg = BCM2711_PULL_NONE;
95 + bcm2711_pull_config_set(pc, pin, arg);
98 + /* Set pull generic bindings */
99 + case PIN_CONFIG_BIAS_DISABLE:
100 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_NONE);
102 + case PIN_CONFIG_BIAS_PULL_DOWN:
103 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_DOWN);
105 + case PIN_CONFIG_BIAS_PULL_UP:
106 + bcm2711_pull_config_set(pc, pin, BCM2711_PULL_UP);
109 + /* Set output-high or output-low */
110 + case PIN_CONFIG_OUTPUT:
111 + bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin);
117 + } /* for each config */
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,
128 static struct pinctrl_desc bcm2835_pinctrl_desc = {
130 .pins = bcm2835_gpio_pins,
131 @@ -990,6 +1070,18 @@ static struct pinctrl_gpio_range bcm2835
132 .npins = BCM2835_NUM_GPIOS,
135 +static const struct of_device_id bcm2835_pinctrl_match[] = {
137 + .compatible = "brcm,bcm2835-gpio",
138 + .data = &bcm2835_pinconf_ops,
141 + .compatible = "brcm,bcm2711-gpio",
142 + .data = &bcm2711_pinconf_ops,
147 static int bcm2835_pinctrl_probe(struct platform_device *pdev)
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;
154 + const struct of_device_id *match;
156 BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_pins) != BCM2835_NUM_GPIOS);
157 BUILD_BUG_ON(ARRAY_SIZE(bcm2835_gpio_groups) != BCM2835_NUM_GPIOS);
159 @@ -1073,6 +1167,12 @@ static int bcm2835_pinctrl_probe(struct
160 bcm2835_gpio_irq_handler);
163 + match = of_match_node(bcm2835_pinctrl_match, pdev->dev.of_node);
165 + bcm2835_pinctrl_desc.confops =
166 + (const struct pinconf_ops *)match->data;
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
176 -static const struct of_device_id bcm2835_pinctrl_match[] = {
177 - { .compatible = "brcm,bcm2835-gpio" },
181 static struct platform_driver bcm2835_pinctrl_driver = {
182 .probe = bcm2835_pinctrl_probe,