Linus Walleij | 36e2add | 2018-09-07 22:04:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 2 | /* |
Paul Gortmaker | adaaf63 | 2016-08-22 12:48:33 -0400 | [diff] [blame] | 3 | * Freescale vf610 GPIO support through PORT and GPIO |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2014 Toradex AG. |
| 6 | * |
| 7 | * Author: Stefan Agner <stefan@agner.ch>. |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 8 | */ |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 9 | #include <linux/bitops.h> |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 10 | #include <linux/clk.h> |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 11 | #include <linux/err.h> |
Linus Walleij | 45e8296 | 2018-09-07 22:03:07 +0200 | [diff] [blame] | 12 | #include <linux/gpio/driver.h> |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/irq.h> |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/of.h> |
| 20 | #include <linux/of_device.h> |
| 21 | #include <linux/of_irq.h> |
| 22 | |
| 23 | #define VF610_GPIO_PER_PORT 32 |
| 24 | |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 25 | struct fsl_gpio_soc_data { |
| 26 | /* SoCs has a Port Data Direction Register (PDDR) */ |
| 27 | bool have_paddr; |
| 28 | }; |
| 29 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 30 | struct vf610_gpio_port { |
| 31 | struct gpio_chip gc; |
Andrey Smirnov | 338aa10 | 2019-03-10 23:27:31 -0700 | [diff] [blame] | 32 | struct irq_chip ic; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 33 | void __iomem *base; |
| 34 | void __iomem *gpio_base; |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 35 | const struct fsl_gpio_soc_data *sdata; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 36 | u8 irqc[VF610_GPIO_PER_PORT]; |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 37 | struct clk *clk_port; |
| 38 | struct clk *clk_gpio; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 39 | int irq; |
| 40 | }; |
| 41 | |
| 42 | #define GPIO_PDOR 0x00 |
| 43 | #define GPIO_PSOR 0x04 |
| 44 | #define GPIO_PCOR 0x08 |
| 45 | #define GPIO_PTOR 0x0c |
| 46 | #define GPIO_PDIR 0x10 |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 47 | #define GPIO_PDDR 0x14 |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 48 | |
| 49 | #define PORT_PCR(n) ((n) * 0x4) |
| 50 | #define PORT_PCR_IRQC_OFFSET 16 |
| 51 | |
| 52 | #define PORT_ISFR 0xa0 |
| 53 | #define PORT_DFER 0xc0 |
| 54 | #define PORT_DFCR 0xc4 |
| 55 | #define PORT_DFWR 0xc8 |
| 56 | |
| 57 | #define PORT_INT_OFF 0x0 |
| 58 | #define PORT_INT_LOGIC_ZERO 0x8 |
| 59 | #define PORT_INT_RISING_EDGE 0x9 |
| 60 | #define PORT_INT_FALLING_EDGE 0xa |
| 61 | #define PORT_INT_EITHER_EDGE 0xb |
| 62 | #define PORT_INT_LOGIC_ONE 0xc |
| 63 | |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 64 | static const struct fsl_gpio_soc_data imx_data = { |
| 65 | .have_paddr = true, |
| 66 | }; |
| 67 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 68 | static const struct of_device_id vf610_gpio_dt_ids[] = { |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 69 | { .compatible = "fsl,vf610-gpio", .data = NULL, }, |
| 70 | { .compatible = "fsl,imx7ulp-gpio", .data = &imx_data, }, |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 71 | { /* sentinel */ } |
| 72 | }; |
| 73 | |
| 74 | static inline void vf610_gpio_writel(u32 val, void __iomem *reg) |
| 75 | { |
| 76 | writel_relaxed(val, reg); |
| 77 | } |
| 78 | |
| 79 | static inline u32 vf610_gpio_readl(void __iomem *reg) |
| 80 | { |
| 81 | return readl_relaxed(reg); |
| 82 | } |
| 83 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 84 | static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) |
| 85 | { |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 86 | struct vf610_gpio_port *port = gpiochip_get_data(gc); |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 87 | unsigned long mask = BIT(gpio); |
Andrey Smirnov | 4a8909d | 2019-03-10 23:27:33 -0700 | [diff] [blame] | 88 | unsigned long offset = GPIO_PDIR; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 89 | |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 90 | if (port->sdata && port->sdata->have_paddr) { |
| 91 | mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR); |
Andrey Smirnov | 4a8909d | 2019-03-10 23:27:33 -0700 | [diff] [blame] | 92 | if (mask) |
| 93 | offset = GPIO_PDOR; |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 94 | } |
Andrey Smirnov | 4a8909d | 2019-03-10 23:27:33 -0700 | [diff] [blame] | 95 | |
| 96 | return !!(vf610_gpio_readl(port->gpio_base + offset) & BIT(gpio)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) |
| 100 | { |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 101 | struct vf610_gpio_port *port = gpiochip_get_data(gc); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 102 | unsigned long mask = BIT(gpio); |
Andrey Smirnov | a262555 | 2019-03-10 23:27:32 -0700 | [diff] [blame] | 103 | unsigned long offset = val ? GPIO_PSOR : GPIO_PCOR; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 104 | |
Andrey Smirnov | a262555 | 2019-03-10 23:27:32 -0700 | [diff] [blame] | 105 | vf610_gpio_writel(mask, port->gpio_base + offset); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
| 109 | { |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 110 | struct vf610_gpio_port *port = gpiochip_get_data(chip); |
| 111 | unsigned long mask = BIT(gpio); |
| 112 | u32 val; |
| 113 | |
| 114 | if (port->sdata && port->sdata->have_paddr) { |
| 115 | val = vf610_gpio_readl(port->gpio_base + GPIO_PDDR); |
| 116 | val &= ~mask; |
| 117 | vf610_gpio_writel(val, port->gpio_base + GPIO_PDDR); |
| 118 | } |
| 119 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 120 | return pinctrl_gpio_direction_input(chip->base + gpio); |
| 121 | } |
| 122 | |
| 123 | static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, |
| 124 | int value) |
| 125 | { |
Dong Aisheng | 659d8a6 | 2017-08-01 22:04:17 +0800 | [diff] [blame] | 126 | struct vf610_gpio_port *port = gpiochip_get_data(chip); |
| 127 | unsigned long mask = BIT(gpio); |
| 128 | |
| 129 | if (port->sdata && port->sdata->have_paddr) |
| 130 | vf610_gpio_writel(mask, port->gpio_base + GPIO_PDDR); |
| 131 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 132 | vf610_gpio_set(chip, gpio, value); |
| 133 | |
| 134 | return pinctrl_gpio_direction_output(chip->base + gpio); |
| 135 | } |
| 136 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 137 | static void vf610_gpio_irq_handler(struct irq_desc *desc) |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 138 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 139 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 140 | gpiochip_get_data(irq_desc_get_handler_data(desc)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 141 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 142 | int pin; |
| 143 | unsigned long irq_isfr; |
| 144 | |
| 145 | chained_irq_enter(chip, desc); |
| 146 | |
| 147 | irq_isfr = vf610_gpio_readl(port->base + PORT_ISFR); |
| 148 | |
| 149 | for_each_set_bit(pin, &irq_isfr, VF610_GPIO_PER_PORT) { |
| 150 | vf610_gpio_writel(BIT(pin), port->base + PORT_ISFR); |
| 151 | |
Marc Zyngier | dbd1c54 | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 152 | generic_handle_domain_irq(port->gc.irq.domain, pin); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | chained_irq_exit(chip, desc); |
| 156 | } |
| 157 | |
| 158 | static void vf610_gpio_irq_ack(struct irq_data *d) |
| 159 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 160 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 161 | gpiochip_get_data(irq_data_get_irq_chip_data(d)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 162 | int gpio = d->hwirq; |
| 163 | |
| 164 | vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR); |
| 165 | } |
| 166 | |
| 167 | static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type) |
| 168 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 169 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 170 | gpiochip_get_data(irq_data_get_irq_chip_data(d)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 171 | u8 irqc; |
| 172 | |
| 173 | switch (type) { |
| 174 | case IRQ_TYPE_EDGE_RISING: |
| 175 | irqc = PORT_INT_RISING_EDGE; |
| 176 | break; |
| 177 | case IRQ_TYPE_EDGE_FALLING: |
| 178 | irqc = PORT_INT_FALLING_EDGE; |
| 179 | break; |
| 180 | case IRQ_TYPE_EDGE_BOTH: |
| 181 | irqc = PORT_INT_EITHER_EDGE; |
| 182 | break; |
| 183 | case IRQ_TYPE_LEVEL_LOW: |
| 184 | irqc = PORT_INT_LOGIC_ZERO; |
| 185 | break; |
| 186 | case IRQ_TYPE_LEVEL_HIGH: |
| 187 | irqc = PORT_INT_LOGIC_ONE; |
| 188 | break; |
| 189 | default: |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | port->irqc[d->hwirq] = irqc; |
| 194 | |
Stefan Agner | fd96811 | 2015-08-21 15:56:42 -0700 | [diff] [blame] | 195 | if (type & IRQ_TYPE_LEVEL_MASK) |
Thomas Gleixner | a7147db | 2015-09-16 12:51:00 +0200 | [diff] [blame] | 196 | irq_set_handler_locked(d, handle_level_irq); |
Stefan Agner | fd96811 | 2015-08-21 15:56:42 -0700 | [diff] [blame] | 197 | else |
Thomas Gleixner | a7147db | 2015-09-16 12:51:00 +0200 | [diff] [blame] | 198 | irq_set_handler_locked(d, handle_edge_irq); |
Stefan Agner | fd96811 | 2015-08-21 15:56:42 -0700 | [diff] [blame] | 199 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static void vf610_gpio_irq_mask(struct irq_data *d) |
| 204 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 205 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 206 | gpiochip_get_data(irq_data_get_irq_chip_data(d)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 207 | void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); |
| 208 | |
| 209 | vf610_gpio_writel(0, pcr_base); |
| 210 | } |
| 211 | |
| 212 | static void vf610_gpio_irq_unmask(struct irq_data *d) |
| 213 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 214 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 215 | gpiochip_get_data(irq_data_get_irq_chip_data(d)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 216 | void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq); |
| 217 | |
| 218 | vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET, |
| 219 | pcr_base); |
| 220 | } |
| 221 | |
| 222 | static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) |
| 223 | { |
Linus Walleij | 2f93064 | 2015-08-27 14:13:46 +0200 | [diff] [blame] | 224 | struct vf610_gpio_port *port = |
Linus Walleij | 65389b4 | 2015-12-07 15:03:30 +0100 | [diff] [blame] | 225 | gpiochip_get_data(irq_data_get_irq_chip_data(d)); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 226 | |
| 227 | if (enable) |
| 228 | enable_irq_wake(port->irq); |
| 229 | else |
| 230 | disable_irq_wake(port->irq); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Andrey Smirnov | db9ed63 | 2019-03-10 23:27:34 -0700 | [diff] [blame] | 235 | static void vf610_gpio_disable_clk(void *data) |
| 236 | { |
| 237 | clk_disable_unprepare(data); |
| 238 | } |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 239 | |
| 240 | static int vf610_gpio_probe(struct platform_device *pdev) |
| 241 | { |
| 242 | struct device *dev = &pdev->dev; |
| 243 | struct device_node *np = dev->of_node; |
| 244 | struct vf610_gpio_port *port; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 245 | struct gpio_chip *gc; |
Linus Walleij | e599256 | 2019-08-09 16:19:16 +0200 | [diff] [blame] | 246 | struct gpio_irq_chip *girq; |
Andrey Smirnov | 338aa10 | 2019-03-10 23:27:31 -0700 | [diff] [blame] | 247 | struct irq_chip *ic; |
Andrew Lunn | 7ae710f | 2019-01-27 22:58:00 +0100 | [diff] [blame] | 248 | int i; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 249 | int ret; |
| 250 | |
Andrey Smirnov | 2e35bb6 | 2019-03-10 23:27:37 -0700 | [diff] [blame] | 251 | port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 252 | if (!port) |
| 253 | return -ENOMEM; |
| 254 | |
Thierry Reding | 23e577e | 2018-04-30 09:38:18 +0200 | [diff] [blame] | 255 | port->sdata = of_device_get_match_data(dev); |
Enrico Weigelt, metux IT consult | df53665b | 2019-03-11 19:55:16 +0100 | [diff] [blame] | 256 | port->base = devm_platform_ioremap_resource(pdev, 0); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 257 | if (IS_ERR(port->base)) |
| 258 | return PTR_ERR(port->base); |
| 259 | |
Enrico Weigelt, metux IT consult | df53665b | 2019-03-11 19:55:16 +0100 | [diff] [blame] | 260 | port->gpio_base = devm_platform_ioremap_resource(pdev, 1); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 261 | if (IS_ERR(port->gpio_base)) |
| 262 | return PTR_ERR(port->gpio_base); |
| 263 | |
| 264 | port->irq = platform_get_irq(pdev, 0); |
| 265 | if (port->irq < 0) |
| 266 | return port->irq; |
| 267 | |
Andrey Smirnov | 2e35bb6 | 2019-03-10 23:27:37 -0700 | [diff] [blame] | 268 | port->clk_port = devm_clk_get(dev, "port"); |
Andrey Smirnov | 663ba74 | 2019-04-28 22:49:48 -0700 | [diff] [blame] | 269 | ret = PTR_ERR_OR_ZERO(port->clk_port); |
| 270 | if (!ret) { |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 271 | ret = clk_prepare_enable(port->clk_port); |
| 272 | if (ret) |
| 273 | return ret; |
Andrey Smirnov | db9ed63 | 2019-03-10 23:27:34 -0700 | [diff] [blame] | 274 | ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk, |
| 275 | port->clk_port); |
| 276 | if (ret) |
| 277 | return ret; |
Andrey Smirnov | 663ba74 | 2019-04-28 22:49:48 -0700 | [diff] [blame] | 278 | } else if (ret == -EPROBE_DEFER) { |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 279 | /* |
| 280 | * Percolate deferrals, for anything else, |
| 281 | * just live without the clocking. |
| 282 | */ |
Andrey Smirnov | 663ba74 | 2019-04-28 22:49:48 -0700 | [diff] [blame] | 283 | return ret; |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Andrey Smirnov | 2e35bb6 | 2019-03-10 23:27:37 -0700 | [diff] [blame] | 286 | port->clk_gpio = devm_clk_get(dev, "gpio"); |
Andrey Smirnov | 663ba74 | 2019-04-28 22:49:48 -0700 | [diff] [blame] | 287 | ret = PTR_ERR_OR_ZERO(port->clk_gpio); |
| 288 | if (!ret) { |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 289 | ret = clk_prepare_enable(port->clk_gpio); |
Andrey Smirnov | db9ed63 | 2019-03-10 23:27:34 -0700 | [diff] [blame] | 290 | if (ret) |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 291 | return ret; |
Andrey Smirnov | fc57949 | 2019-03-10 23:27:35 -0700 | [diff] [blame] | 292 | ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk, |
| 293 | port->clk_gpio); |
| 294 | if (ret) |
| 295 | return ret; |
Andrey Smirnov | 663ba74 | 2019-04-28 22:49:48 -0700 | [diff] [blame] | 296 | } else if (ret == -EPROBE_DEFER) { |
| 297 | return ret; |
A.s. Dong | 9139362 | 2018-11-10 14:21:18 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 300 | gc = &port->gc; |
| 301 | gc->of_node = np; |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 302 | gc->parent = dev; |
Axel Lin | d32efe3 | 2015-02-13 21:04:42 +0800 | [diff] [blame] | 303 | gc->label = "vf610-gpio"; |
| 304 | gc->ngpio = VF610_GPIO_PER_PORT; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 305 | gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT; |
| 306 | |
Jonas Gorski | 203f0da | 2015-10-11 17:34:16 +0200 | [diff] [blame] | 307 | gc->request = gpiochip_generic_request; |
| 308 | gc->free = gpiochip_generic_free; |
Axel Lin | d32efe3 | 2015-02-13 21:04:42 +0800 | [diff] [blame] | 309 | gc->direction_input = vf610_gpio_direction_input; |
| 310 | gc->get = vf610_gpio_get; |
| 311 | gc->direction_output = vf610_gpio_direction_output; |
| 312 | gc->set = vf610_gpio_set; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 313 | |
Andrey Smirnov | 338aa10 | 2019-03-10 23:27:31 -0700 | [diff] [blame] | 314 | ic = &port->ic; |
| 315 | ic->name = "gpio-vf610"; |
| 316 | ic->irq_ack = vf610_gpio_irq_ack; |
| 317 | ic->irq_mask = vf610_gpio_irq_mask; |
| 318 | ic->irq_unmask = vf610_gpio_irq_unmask; |
| 319 | ic->irq_set_type = vf610_gpio_irq_set_type; |
| 320 | ic->irq_set_wake = vf610_gpio_irq_set_wake; |
| 321 | |
Andrew Lunn | 7ae710f | 2019-01-27 22:58:00 +0100 | [diff] [blame] | 322 | /* Mask all GPIO interrupts */ |
| 323 | for (i = 0; i < gc->ngpio; i++) |
| 324 | vf610_gpio_writel(0, port->base + PORT_PCR(i)); |
| 325 | |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 326 | /* Clear the interrupt status register for all GPIO's */ |
| 327 | vf610_gpio_writel(~0, port->base + PORT_ISFR); |
| 328 | |
Linus Walleij | e599256 | 2019-08-09 16:19:16 +0200 | [diff] [blame] | 329 | girq = &gc->irq; |
| 330 | girq->chip = ic; |
| 331 | girq->parent_handler = vf610_gpio_irq_handler; |
| 332 | girq->num_parents = 1; |
| 333 | girq->parents = devm_kcalloc(&pdev->dev, 1, |
| 334 | sizeof(*girq->parents), |
| 335 | GFP_KERNEL); |
| 336 | if (!girq->parents) |
| 337 | return -ENOMEM; |
| 338 | girq->parents[0] = port->irq; |
| 339 | girq->default_type = IRQ_TYPE_NONE; |
| 340 | girq->handler = handle_edge_irq; |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 341 | |
Linus Walleij | e599256 | 2019-08-09 16:19:16 +0200 | [diff] [blame] | 342 | return devm_gpiochip_add_data(dev, gc, port); |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static struct platform_driver vf610_gpio_driver = { |
| 346 | .driver = { |
| 347 | .name = "gpio-vf610", |
Stefan Agner | 7f2691a | 2014-10-16 21:47:58 +0200 | [diff] [blame] | 348 | .of_match_table = vf610_gpio_dt_ids, |
| 349 | }, |
| 350 | .probe = vf610_gpio_probe, |
| 351 | }; |
| 352 | |
Geliang Tang | df950da | 2016-11-23 22:47:48 +0800 | [diff] [blame] | 353 | builtin_platform_driver(vf610_gpio_driver); |