Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 Jamie Iles |
| 4 | * |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 5 | * All enquiries to support@picochip.com |
| 6 | */ |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 7 | #include <linux/acpi.h> |
Phil Edworthy | e6bf377 | 2018-03-12 18:30:56 +0000 | [diff] [blame] | 8 | #include <linux/clk.h> |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 9 | #include <linux/err.h> |
Phil Edworthy | e6bf377 | 2018-03-12 18:30:56 +0000 | [diff] [blame] | 10 | #include <linux/gpio/driver.h> |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/ioport.h> |
| 15 | #include <linux/irq.h> |
| 16 | #include <linux/irqdomain.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/of.h> |
| 19 | #include <linux/of_address.h> |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 21 | #include <linux/of_irq.h> |
| 22 | #include <linux/platform_device.h> |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 23 | #include <linux/property.h> |
Alan Tull | 07901a9 | 2017-10-11 11:34:44 -0500 | [diff] [blame] | 24 | #include <linux/reset.h> |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 26 | #include <linux/platform_data/gpio-dwapb.h> |
| 27 | #include <linux/slab.h> |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 28 | |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 29 | #include "gpiolib.h" |
Andy Shevchenko | 77cb907 | 2019-07-30 13:43:36 +0300 | [diff] [blame] | 30 | #include "gpiolib-acpi.h" |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 31 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 32 | #define GPIO_SWPORTA_DR 0x00 |
| 33 | #define GPIO_SWPORTA_DDR 0x04 |
| 34 | #define GPIO_SWPORTB_DR 0x0c |
| 35 | #define GPIO_SWPORTB_DDR 0x10 |
| 36 | #define GPIO_SWPORTC_DR 0x18 |
| 37 | #define GPIO_SWPORTC_DDR 0x1c |
| 38 | #define GPIO_SWPORTD_DR 0x24 |
| 39 | #define GPIO_SWPORTD_DDR 0x28 |
| 40 | #define GPIO_INTEN 0x30 |
| 41 | #define GPIO_INTMASK 0x34 |
| 42 | #define GPIO_INTTYPE_LEVEL 0x38 |
| 43 | #define GPIO_INT_POLARITY 0x3c |
| 44 | #define GPIO_INTSTATUS 0x40 |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 45 | #define GPIO_PORTA_DEBOUNCE 0x48 |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 46 | #define GPIO_PORTA_EOI 0x4c |
| 47 | #define GPIO_EXT_PORTA 0x50 |
| 48 | #define GPIO_EXT_PORTB 0x54 |
| 49 | #define GPIO_EXT_PORTC 0x58 |
| 50 | #define GPIO_EXT_PORTD 0x5c |
| 51 | |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 52 | #define DWAPB_DRIVER_NAME "gpio-dwapb" |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 53 | #define DWAPB_MAX_PORTS 4 |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 54 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 55 | #define GPIO_EXT_PORT_STRIDE 0x04 /* register stride 32 bits */ |
| 56 | #define GPIO_SWPORT_DR_STRIDE 0x0c /* register stride 3*32 bits */ |
| 57 | #define GPIO_SWPORT_DDR_STRIDE 0x0c /* register stride 3*32 bits */ |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 58 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 59 | #define GPIO_REG_OFFSET_V2 1 |
| 60 | |
| 61 | #define GPIO_INTMASK_V2 0x44 |
| 62 | #define GPIO_INTTYPE_LEVEL_V2 0x34 |
| 63 | #define GPIO_INT_POLARITY_V2 0x38 |
| 64 | #define GPIO_INTSTATUS_V2 0x3c |
| 65 | #define GPIO_PORTA_EOI_V2 0x40 |
| 66 | |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 67 | #define DWAPB_NR_CLOCKS 2 |
| 68 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 69 | struct dwapb_gpio; |
| 70 | |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_PM_SLEEP |
| 72 | /* Store GPIO context across system-wide suspend/resume transitions */ |
| 73 | struct dwapb_context { |
| 74 | u32 data; |
| 75 | u32 dir; |
| 76 | u32 ext; |
| 77 | u32 int_en; |
| 78 | u32 int_mask; |
| 79 | u32 int_type; |
| 80 | u32 int_pol; |
| 81 | u32 int_deb; |
Hoan Tran | 6437c7b | 2017-09-08 15:41:15 -0700 | [diff] [blame] | 82 | u32 wake_en; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 83 | }; |
| 84 | #endif |
| 85 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 86 | struct dwapb_gpio_port { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 87 | struct gpio_chip gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 88 | bool is_registered; |
| 89 | struct dwapb_gpio *gpio; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 90 | #ifdef CONFIG_PM_SLEEP |
| 91 | struct dwapb_context *ctx; |
| 92 | #endif |
| 93 | unsigned int idx; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct dwapb_gpio { |
| 97 | struct device *dev; |
| 98 | void __iomem *regs; |
| 99 | struct dwapb_gpio_port *ports; |
| 100 | unsigned int nr_ports; |
| 101 | struct irq_domain *domain; |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 102 | unsigned int flags; |
Alan Tull | 07901a9 | 2017-10-11 11:34:44 -0500 | [diff] [blame] | 103 | struct reset_control *rst; |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 104 | struct clk_bulk_data clks[DWAPB_NR_CLOCKS]; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 105 | }; |
| 106 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 107 | static inline u32 gpio_reg_v2_convert(unsigned int offset) |
| 108 | { |
| 109 | switch (offset) { |
| 110 | case GPIO_INTMASK: |
| 111 | return GPIO_INTMASK_V2; |
| 112 | case GPIO_INTTYPE_LEVEL: |
| 113 | return GPIO_INTTYPE_LEVEL_V2; |
| 114 | case GPIO_INT_POLARITY: |
| 115 | return GPIO_INT_POLARITY_V2; |
| 116 | case GPIO_INTSTATUS: |
| 117 | return GPIO_INTSTATUS_V2; |
| 118 | case GPIO_PORTA_EOI: |
| 119 | return GPIO_PORTA_EOI_V2; |
| 120 | } |
| 121 | |
| 122 | return offset; |
| 123 | } |
| 124 | |
| 125 | static inline u32 gpio_reg_convert(struct dwapb_gpio *gpio, unsigned int offset) |
| 126 | { |
| 127 | if (gpio->flags & GPIO_REG_OFFSET_V2) |
| 128 | return gpio_reg_v2_convert(offset); |
| 129 | |
| 130 | return offset; |
| 131 | } |
| 132 | |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 133 | static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) |
| 134 | { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 135 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 136 | void __iomem *reg_base = gpio->regs; |
| 137 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 138 | return gc->read_reg(reg_base + gpio_reg_convert(gpio, offset)); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, |
| 142 | u32 val) |
| 143 | { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 144 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 145 | void __iomem *reg_base = gpio->regs; |
| 146 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 147 | gc->write_reg(reg_base + gpio_reg_convert(gpio, offset), val); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 150 | static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) |
| 151 | { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 152 | struct dwapb_gpio_port *port = gpiochip_get_data(gc); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 153 | struct dwapb_gpio *gpio = port->gpio; |
| 154 | |
| 155 | return irq_find_mapping(gpio->domain, offset); |
| 156 | } |
| 157 | |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 158 | static struct dwapb_gpio_port *dwapb_offs_to_port(struct dwapb_gpio *gpio, unsigned int offs) |
| 159 | { |
| 160 | struct dwapb_gpio_port *port; |
| 161 | int i; |
| 162 | |
| 163 | for (i = 0; i < gpio->nr_ports; i++) { |
| 164 | port = &gpio->ports[i]; |
| 165 | if (port->idx == offs / 32) |
| 166 | return port; |
| 167 | } |
| 168 | |
| 169 | return NULL; |
| 170 | } |
| 171 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 172 | static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) |
| 173 | { |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 174 | struct dwapb_gpio_port *port = dwapb_offs_to_port(gpio, offs); |
| 175 | struct gpio_chip *gc; |
| 176 | u32 pol; |
| 177 | int val; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 178 | |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 179 | if (!port) |
| 180 | return; |
| 181 | gc = &port->gc; |
| 182 | |
| 183 | pol = dwapb_read(gpio, GPIO_INT_POLARITY); |
| 184 | /* Just read the current value right out of the data register */ |
| 185 | val = gc->get(gc, offs % 32); |
| 186 | if (val) |
| 187 | pol &= ~BIT(offs); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 188 | else |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 189 | pol |= BIT(offs); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 190 | |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 191 | dwapb_write(gpio, GPIO_INT_POLARITY, pol); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 192 | } |
| 193 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 194 | static u32 dwapb_do_irq(struct dwapb_gpio *gpio) |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 195 | { |
Andy Shevchenko | 038aa1f | 2020-04-15 17:15:22 +0300 | [diff] [blame^] | 196 | unsigned long irq_status; |
| 197 | int hwirq; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 198 | |
Andy Shevchenko | 038aa1f | 2020-04-15 17:15:22 +0300 | [diff] [blame^] | 199 | irq_status = dwapb_read(gpio, GPIO_INTSTATUS); |
| 200 | for_each_set_bit(hwirq, &irq_status, 32) { |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 201 | int gpio_irq = irq_find_mapping(gpio->domain, hwirq); |
Andy Shevchenko | 038aa1f | 2020-04-15 17:15:22 +0300 | [diff] [blame^] | 202 | u32 irq_type = irq_get_trigger_type(gpio_irq); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 203 | |
| 204 | generic_handle_irq(gpio_irq); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 205 | |
Andy Shevchenko | 038aa1f | 2020-04-15 17:15:22 +0300 | [diff] [blame^] | 206 | if ((irq_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 207 | dwapb_toggle_trigger(gpio, hwirq); |
| 208 | } |
| 209 | |
Andy Shevchenko | 038aa1f | 2020-04-15 17:15:22 +0300 | [diff] [blame^] | 210 | return irq_status; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 213 | static void dwapb_irq_handler(struct irq_desc *desc) |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 214 | { |
Jiang Liu | 476f8b4 | 2015-06-04 12:13:15 +0800 | [diff] [blame] | 215 | struct dwapb_gpio *gpio = irq_desc_get_handler_data(desc); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 216 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 217 | |
| 218 | dwapb_do_irq(gpio); |
| 219 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 220 | if (chip->irq_eoi) |
| 221 | chip->irq_eoi(irq_desc_get_irq_data(desc)); |
| 222 | } |
| 223 | |
| 224 | static void dwapb_irq_enable(struct irq_data *d) |
| 225 | { |
| 226 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 227 | struct dwapb_gpio *gpio = igc->private; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 228 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 229 | unsigned long flags; |
| 230 | u32 val; |
| 231 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 232 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 233 | val = dwapb_read(gpio, GPIO_INTEN); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 234 | val |= BIT(d->hwirq); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 235 | dwapb_write(gpio, GPIO_INTEN, val); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 236 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static void dwapb_irq_disable(struct irq_data *d) |
| 240 | { |
| 241 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 242 | struct dwapb_gpio *gpio = igc->private; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 243 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 244 | unsigned long flags; |
| 245 | u32 val; |
| 246 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 247 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 248 | val = dwapb_read(gpio, GPIO_INTEN); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 249 | val &= ~BIT(d->hwirq); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 250 | dwapb_write(gpio, GPIO_INTEN, val); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 251 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 252 | } |
| 253 | |
Linus Walleij | 57ef042 | 2014-03-14 18:16:20 +0100 | [diff] [blame] | 254 | static int dwapb_irq_reqres(struct irq_data *d) |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 255 | { |
| 256 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 257 | struct dwapb_gpio *gpio = igc->private; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 258 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Andy Shevchenko | 10ed353 | 2018-07-30 15:38:33 +0300 | [diff] [blame] | 259 | int ret; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 260 | |
Andy Shevchenko | 10ed353 | 2018-07-30 15:38:33 +0300 | [diff] [blame] | 261 | ret = gpiochip_lock_as_irq(gc, irqd_to_hwirq(d)); |
| 262 | if (ret) { |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 263 | dev_err(gpio->dev, "unable to lock HW IRQ %lu for IRQ\n", |
| 264 | irqd_to_hwirq(d)); |
Andy Shevchenko | 10ed353 | 2018-07-30 15:38:33 +0300 | [diff] [blame] | 265 | return ret; |
Linus Walleij | 57ef042 | 2014-03-14 18:16:20 +0100 | [diff] [blame] | 266 | } |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
Linus Walleij | 57ef042 | 2014-03-14 18:16:20 +0100 | [diff] [blame] | 270 | static void dwapb_irq_relres(struct irq_data *d) |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 271 | { |
| 272 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 273 | struct dwapb_gpio *gpio = igc->private; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 274 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 275 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 276 | gpiochip_unlock_as_irq(gc, irqd_to_hwirq(d)); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static int dwapb_irq_set_type(struct irq_data *d, u32 type) |
| 280 | { |
| 281 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 282 | struct dwapb_gpio *gpio = igc->private; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 283 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 284 | int bit = d->hwirq; |
| 285 | unsigned long level, polarity, flags; |
| 286 | |
| 287 | if (type & ~(IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | |
| 288 | IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) |
| 289 | return -EINVAL; |
| 290 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 291 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 292 | level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); |
| 293 | polarity = dwapb_read(gpio, GPIO_INT_POLARITY); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 294 | |
| 295 | switch (type) { |
| 296 | case IRQ_TYPE_EDGE_BOTH: |
| 297 | level |= BIT(bit); |
| 298 | dwapb_toggle_trigger(gpio, bit); |
| 299 | break; |
| 300 | case IRQ_TYPE_EDGE_RISING: |
| 301 | level |= BIT(bit); |
| 302 | polarity |= BIT(bit); |
| 303 | break; |
| 304 | case IRQ_TYPE_EDGE_FALLING: |
| 305 | level |= BIT(bit); |
| 306 | polarity &= ~BIT(bit); |
| 307 | break; |
| 308 | case IRQ_TYPE_LEVEL_HIGH: |
| 309 | level &= ~BIT(bit); |
| 310 | polarity |= BIT(bit); |
| 311 | break; |
| 312 | case IRQ_TYPE_LEVEL_LOW: |
| 313 | level &= ~BIT(bit); |
| 314 | polarity &= ~BIT(bit); |
| 315 | break; |
| 316 | } |
| 317 | |
Sebastian Andrzej Siewior | 6a2f4b7 | 2014-05-26 22:58:14 +0200 | [diff] [blame] | 318 | irq_setup_alt_chip(d, type); |
| 319 | |
Weike Chen | 67809b9 | 2014-09-17 09:18:40 -0700 | [diff] [blame] | 320 | dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); |
Xiaoguang Chen | edadced | 2017-06-02 07:27:15 +0800 | [diff] [blame] | 321 | if (type != IRQ_TYPE_EDGE_BOTH) |
| 322 | dwapb_write(gpio, GPIO_INT_POLARITY, polarity); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 323 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
Hoan Tran | 6437c7b | 2017-09-08 15:41:15 -0700 | [diff] [blame] | 328 | #ifdef CONFIG_PM_SLEEP |
| 329 | static int dwapb_irq_set_wake(struct irq_data *d, unsigned int enable) |
| 330 | { |
| 331 | struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); |
| 332 | struct dwapb_gpio *gpio = igc->private; |
| 333 | struct dwapb_context *ctx = gpio->ports[0].ctx; |
| 334 | |
| 335 | if (enable) |
| 336 | ctx->wake_en |= BIT(d->hwirq); |
| 337 | else |
| 338 | ctx->wake_en &= ~BIT(d->hwirq); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | #endif |
| 343 | |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 344 | static int dwapb_gpio_set_debounce(struct gpio_chip *gc, |
| 345 | unsigned offset, unsigned debounce) |
| 346 | { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 347 | struct dwapb_gpio_port *port = gpiochip_get_data(gc); |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 348 | struct dwapb_gpio *gpio = port->gpio; |
| 349 | unsigned long flags, val_deb; |
Linus Walleij | d97a1b5 | 2017-10-20 12:26:51 +0200 | [diff] [blame] | 350 | unsigned long mask = BIT(offset); |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 351 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 352 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 353 | |
| 354 | val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); |
| 355 | if (debounce) |
| 356 | dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb | mask); |
| 357 | else |
| 358 | dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); |
| 359 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 360 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
Mika Westerberg | 2956b5d | 2017-01-23 15:34:34 +0300 | [diff] [blame] | 365 | static int dwapb_gpio_set_config(struct gpio_chip *gc, unsigned offset, |
| 366 | unsigned long config) |
| 367 | { |
| 368 | u32 debounce; |
| 369 | |
| 370 | if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE) |
| 371 | return -ENOTSUPP; |
| 372 | |
| 373 | debounce = pinconf_to_config_argument(config); |
| 374 | return dwapb_gpio_set_debounce(gc, offset, debounce); |
| 375 | } |
| 376 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 377 | static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id) |
| 378 | { |
| 379 | u32 worked; |
| 380 | struct dwapb_gpio *gpio = dev_id; |
| 381 | |
| 382 | worked = dwapb_do_irq(gpio); |
| 383 | |
| 384 | return worked ? IRQ_HANDLED : IRQ_NONE; |
| 385 | } |
| 386 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 387 | static void dwapb_configure_irqs(struct dwapb_gpio *gpio, |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 388 | struct dwapb_gpio_port *port, |
| 389 | struct dwapb_port_property *pp) |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 390 | { |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 391 | struct gpio_chip *gc = &port->gc; |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 392 | struct fwnode_handle *fwnode = pp->fwnode; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 393 | struct irq_chip_generic *irq_gc = NULL; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 394 | unsigned int hwirq, ngpio = gc->ngpio; |
| 395 | struct irq_chip_type *ct; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 396 | int err, i; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 397 | |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 398 | gpio->domain = irq_domain_create_linear(fwnode, ngpio, |
| 399 | &irq_generic_chip_ops, gpio); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 400 | if (!gpio->domain) |
| 401 | return; |
| 402 | |
Sebastian Andrzej Siewior | 6a2f4b7 | 2014-05-26 22:58:14 +0200 | [diff] [blame] | 403 | err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 2, |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 404 | DWAPB_DRIVER_NAME, handle_level_irq, |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 405 | IRQ_NOREQUEST, 0, |
| 406 | IRQ_GC_INIT_NESTED_LOCK); |
| 407 | if (err) { |
| 408 | dev_info(gpio->dev, "irq_alloc_domain_generic_chips failed\n"); |
| 409 | irq_domain_remove(gpio->domain); |
| 410 | gpio->domain = NULL; |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | irq_gc = irq_get_domain_generic_chip(gpio->domain, 0); |
| 415 | if (!irq_gc) { |
| 416 | irq_domain_remove(gpio->domain); |
| 417 | gpio->domain = NULL; |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | irq_gc->reg_base = gpio->regs; |
| 422 | irq_gc->private = gpio; |
| 423 | |
Sebastian Andrzej Siewior | 6a2f4b7 | 2014-05-26 22:58:14 +0200 | [diff] [blame] | 424 | for (i = 0; i < 2; i++) { |
| 425 | ct = &irq_gc->chip_types[i]; |
| 426 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
| 427 | ct->chip.irq_mask = irq_gc_mask_set_bit; |
| 428 | ct->chip.irq_unmask = irq_gc_mask_clr_bit; |
| 429 | ct->chip.irq_set_type = dwapb_irq_set_type; |
| 430 | ct->chip.irq_enable = dwapb_irq_enable; |
| 431 | ct->chip.irq_disable = dwapb_irq_disable; |
| 432 | ct->chip.irq_request_resources = dwapb_irq_reqres; |
| 433 | ct->chip.irq_release_resources = dwapb_irq_relres; |
Hoan Tran | 6437c7b | 2017-09-08 15:41:15 -0700 | [diff] [blame] | 434 | #ifdef CONFIG_PM_SLEEP |
| 435 | ct->chip.irq_set_wake = dwapb_irq_set_wake; |
| 436 | #endif |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 437 | ct->regs.ack = gpio_reg_convert(gpio, GPIO_PORTA_EOI); |
| 438 | ct->regs.mask = gpio_reg_convert(gpio, GPIO_INTMASK); |
Sebastian Andrzej Siewior | 6a2f4b7 | 2014-05-26 22:58:14 +0200 | [diff] [blame] | 439 | ct->type = IRQ_TYPE_LEVEL_MASK; |
| 440 | } |
| 441 | |
| 442 | irq_gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK; |
| 443 | irq_gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; |
| 444 | irq_gc->chip_types[1].handler = handle_edge_irq; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 445 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 446 | if (!pp->irq_shared) { |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 447 | int i; |
| 448 | |
| 449 | for (i = 0; i < pp->ngpio; i++) { |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 450 | if (pp->irq[i] >= 0) |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 451 | irq_set_chained_handler_and_data(pp->irq[i], |
| 452 | dwapb_irq_handler, gpio); |
| 453 | } |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 454 | } else { |
| 455 | /* |
| 456 | * Request a shared IRQ since where MFD would have devices |
| 457 | * using the same irq pin |
| 458 | */ |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 459 | err = devm_request_irq(gpio->dev, pp->irq[0], |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 460 | dwapb_irq_handler_mfd, |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 461 | IRQF_SHARED, DWAPB_DRIVER_NAME, gpio); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 462 | if (err) { |
| 463 | dev_err(gpio->dev, "error requesting IRQ\n"); |
| 464 | irq_domain_remove(gpio->domain); |
| 465 | gpio->domain = NULL; |
| 466 | return; |
| 467 | } |
| 468 | } |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 469 | |
| 470 | for (hwirq = 0 ; hwirq < ngpio ; hwirq++) |
| 471 | irq_create_mapping(gpio->domain, hwirq); |
| 472 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 473 | port->gc.to_irq = dwapb_gpio_to_irq; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void dwapb_irq_teardown(struct dwapb_gpio *gpio) |
| 477 | { |
| 478 | struct dwapb_gpio_port *port = &gpio->ports[0]; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 479 | struct gpio_chip *gc = &port->gc; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 480 | unsigned int ngpio = gc->ngpio; |
| 481 | irq_hw_number_t hwirq; |
| 482 | |
| 483 | if (!gpio->domain) |
| 484 | return; |
| 485 | |
| 486 | for (hwirq = 0 ; hwirq < ngpio ; hwirq++) |
| 487 | irq_dispose_mapping(irq_find_mapping(gpio->domain, hwirq)); |
| 488 | |
| 489 | irq_domain_remove(gpio->domain); |
| 490 | gpio->domain = NULL; |
| 491 | } |
| 492 | |
| 493 | static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 494 | struct dwapb_port_property *pp, |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 495 | unsigned int offs) |
| 496 | { |
| 497 | struct dwapb_gpio_port *port; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 498 | void __iomem *dat, *set, *dirout; |
| 499 | int err; |
| 500 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 501 | port = &gpio->ports[offs]; |
| 502 | port->gpio = gpio; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 503 | port->idx = pp->idx; |
| 504 | |
| 505 | #ifdef CONFIG_PM_SLEEP |
| 506 | port->ctx = devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL); |
| 507 | if (!port->ctx) |
| 508 | return -ENOMEM; |
| 509 | #endif |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 510 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 511 | dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_STRIDE); |
| 512 | set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_STRIDE); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 513 | dirout = gpio->regs + GPIO_SWPORTA_DDR + |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 514 | (pp->idx * GPIO_SWPORT_DDR_STRIDE); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 515 | |
Linus Walleij | 62c1623 | 2018-02-08 18:00:05 +0100 | [diff] [blame] | 516 | /* This registers 32 GPIO lines per port */ |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 517 | err = bgpio_init(&port->gc, gpio->dev, 4, dat, set, NULL, dirout, |
Linus Walleij | d97a1b5 | 2017-10-20 12:26:51 +0200 | [diff] [blame] | 518 | NULL, 0); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 519 | if (err) { |
Jiang Qiu | e815918 | 2016-04-28 17:32:01 +0800 | [diff] [blame] | 520 | dev_err(gpio->dev, "failed to init gpio chip for port%d\n", |
| 521 | port->idx); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 522 | return err; |
| 523 | } |
| 524 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 525 | #ifdef CONFIG_OF_GPIO |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 526 | port->gc.of_node = to_of_node(pp->fwnode); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 527 | #endif |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 528 | port->gc.ngpio = pp->ngpio; |
| 529 | port->gc.base = pp->gpio_base; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 530 | |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 531 | /* Only port A support debounce */ |
| 532 | if (pp->idx == 0) |
Mika Westerberg | 2956b5d | 2017-01-23 15:34:34 +0300 | [diff] [blame] | 533 | port->gc.set_config = dwapb_gpio_set_config; |
Weike Chen | 5d60d9e | 2014-09-17 09:18:41 -0700 | [diff] [blame] | 534 | |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 535 | if (pp->has_irq) |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 536 | dwapb_configure_irqs(gpio, port, pp); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 537 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 538 | err = gpiochip_add_data(&port->gc, port); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 539 | if (err) |
Jiang Qiu | e815918 | 2016-04-28 17:32:01 +0800 | [diff] [blame] | 540 | dev_err(gpio->dev, "failed to register gpiochip for port%d\n", |
| 541 | port->idx); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 542 | else |
| 543 | port->is_registered = true; |
| 544 | |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 545 | /* Add GPIO-signaled ACPI event support */ |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 546 | if (pp->has_irq) |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 547 | acpi_gpiochip_request_interrupts(&port->gc); |
| 548 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 549 | return err; |
| 550 | } |
| 551 | |
| 552 | static void dwapb_gpio_unregister(struct dwapb_gpio *gpio) |
| 553 | { |
| 554 | unsigned int m; |
| 555 | |
| 556 | for (m = 0; m < gpio->nr_ports; ++m) |
| 557 | if (gpio->ports[m].is_registered) |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 558 | gpiochip_remove(&gpio->ports[m].gc); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 559 | } |
| 560 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 561 | static struct dwapb_platform_data * |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 562 | dwapb_gpio_get_pdata(struct device *dev) |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 563 | { |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 564 | struct fwnode_handle *fwnode; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 565 | struct dwapb_platform_data *pdata; |
| 566 | struct dwapb_port_property *pp; |
| 567 | int nports; |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 568 | int i, j; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 569 | |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 570 | nports = device_get_child_node_count(dev); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 571 | if (nports == 0) |
| 572 | return ERR_PTR(-ENODEV); |
| 573 | |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 574 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 575 | if (!pdata) |
| 576 | return ERR_PTR(-ENOMEM); |
| 577 | |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 578 | pdata->properties = devm_kcalloc(dev, nports, sizeof(*pp), GFP_KERNEL); |
| 579 | if (!pdata->properties) |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 580 | return ERR_PTR(-ENOMEM); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 581 | |
| 582 | pdata->nports = nports; |
| 583 | |
| 584 | i = 0; |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 585 | device_for_each_child_node(dev, fwnode) { |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 586 | struct device_node *np = NULL; |
| 587 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 588 | pp = &pdata->properties[i++]; |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 589 | pp->fwnode = fwnode; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 590 | |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 591 | if (fwnode_property_read_u32(fwnode, "reg", &pp->idx) || |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 592 | pp->idx >= DWAPB_MAX_PORTS) { |
Jiang Qiu | e815918 | 2016-04-28 17:32:01 +0800 | [diff] [blame] | 593 | dev_err(dev, |
| 594 | "missing/invalid port index for port%d\n", i); |
Wei Yongjun | bfab7c8 | 2016-07-10 02:17:36 +0000 | [diff] [blame] | 595 | fwnode_handle_put(fwnode); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 596 | return ERR_PTR(-EINVAL); |
| 597 | } |
| 598 | |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 599 | if (fwnode_property_read_u32(fwnode, "snps,nr-gpios", |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 600 | &pp->ngpio)) { |
Jiang Qiu | e815918 | 2016-04-28 17:32:01 +0800 | [diff] [blame] | 601 | dev_info(dev, |
| 602 | "failed to get number of gpios for port%d\n", |
| 603 | i); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 604 | pp->ngpio = 32; |
| 605 | } |
| 606 | |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 607 | pp->irq_shared = false; |
| 608 | pp->gpio_base = -1; |
| 609 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 610 | /* |
| 611 | * Only port A can provide interrupts in all configurations of |
| 612 | * the IP. |
| 613 | */ |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 614 | if (pp->idx != 0) |
| 615 | continue; |
| 616 | |
| 617 | if (dev->of_node && fwnode_property_read_bool(fwnode, |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 618 | "interrupt-controller")) { |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 619 | np = to_of_node(fwnode); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 622 | for (j = 0; j < pp->ngpio; j++) { |
| 623 | pp->irq[j] = -ENXIO; |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 624 | |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 625 | if (np) |
| 626 | pp->irq[j] = of_irq_get(np, j); |
| 627 | else if (has_acpi_companion(dev)) |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 628 | pp->irq[j] = platform_get_irq(to_platform_device(dev), j); |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 629 | |
| 630 | if (pp->irq[j] >= 0) |
| 631 | pp->has_irq = true; |
Phil Edworthy | e6ca26a | 2018-04-26 17:19:47 +0100 | [diff] [blame] | 632 | } |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 633 | |
Phil Edworthy | da069d5 | 2018-05-23 09:52:44 +0100 | [diff] [blame] | 634 | if (!pp->has_irq) |
| 635 | dev_warn(dev, "no irq for port%d\n", pp->idx); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return pdata; |
| 639 | } |
| 640 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 641 | static const struct of_device_id dwapb_of_match[] = { |
| 642 | { .compatible = "snps,dw-apb-gpio", .data = (void *)0}, |
| 643 | { .compatible = "apm,xgene-gpio-v2", .data = (void *)GPIO_REG_OFFSET_V2}, |
| 644 | { /* Sentinel */ } |
| 645 | }; |
| 646 | MODULE_DEVICE_TABLE(of, dwapb_of_match); |
| 647 | |
| 648 | static const struct acpi_device_id dwapb_acpi_match[] = { |
| 649 | {"HISI0181", 0}, |
| 650 | {"APMC0D07", 0}, |
| 651 | {"APMC0D81", GPIO_REG_OFFSET_V2}, |
| 652 | { } |
| 653 | }; |
| 654 | MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match); |
| 655 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 656 | static int dwapb_gpio_probe(struct platform_device *pdev) |
| 657 | { |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 658 | unsigned int i; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 659 | struct dwapb_gpio *gpio; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 660 | int err; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 661 | struct device *dev = &pdev->dev; |
| 662 | struct dwapb_platform_data *pdata = dev_get_platdata(dev); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 663 | |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 664 | if (!pdata) { |
Jiang Qiu | 4ba8cfa | 2016-04-28 17:32:02 +0800 | [diff] [blame] | 665 | pdata = dwapb_gpio_get_pdata(dev); |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 666 | if (IS_ERR(pdata)) |
| 667 | return PTR_ERR(pdata); |
| 668 | } |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 669 | |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 670 | if (!pdata->nports) |
| 671 | return -ENODEV; |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 672 | |
| 673 | gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 674 | if (!gpio) |
| 675 | return -ENOMEM; |
| 676 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 677 | gpio->dev = &pdev->dev; |
| 678 | gpio->nr_ports = pdata->nports; |
| 679 | |
Alan Tull | 07901a9 | 2017-10-11 11:34:44 -0500 | [diff] [blame] | 680 | gpio->rst = devm_reset_control_get_optional_shared(dev, NULL); |
| 681 | if (IS_ERR(gpio->rst)) |
| 682 | return PTR_ERR(gpio->rst); |
| 683 | |
| 684 | reset_control_deassert(gpio->rst); |
| 685 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 686 | gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 687 | sizeof(*gpio->ports), GFP_KERNEL); |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 688 | if (!gpio->ports) |
| 689 | return -ENOMEM; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 690 | |
Enrico Weigelt, metux IT consult | 2a7194e | 2019-03-11 19:54:47 +0100 | [diff] [blame] | 691 | gpio->regs = devm_platform_ioremap_resource(pdev, 0); |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 692 | if (IS_ERR(gpio->regs)) |
| 693 | return PTR_ERR(gpio->regs); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 694 | |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 695 | /* Optional bus and debounce clocks */ |
| 696 | gpio->clks[0].id = "bus"; |
| 697 | gpio->clks[1].id = "db"; |
| 698 | err = devm_clk_bulk_get_optional(&pdev->dev, DWAPB_NR_CLOCKS, |
| 699 | gpio->clks); |
| 700 | if (err) { |
| 701 | dev_err(&pdev->dev, "Cannot get APB/Debounce clocks\n"); |
| 702 | return err; |
Serge Semin | 3ea8094c | 2020-03-23 22:53:59 +0300 | [diff] [blame] | 703 | } |
| 704 | |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 705 | err = clk_bulk_prepare_enable(DWAPB_NR_CLOCKS, gpio->clks); |
Serge Semin | 3ea8094c | 2020-03-23 22:53:59 +0300 | [diff] [blame] | 706 | if (err) { |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 707 | dev_err(&pdev->dev, "Cannot enable APB/Debounce clocks\n"); |
Serge Semin | 3ea8094c | 2020-03-23 22:53:59 +0300 | [diff] [blame] | 708 | return err; |
Phil Edworthy | e6bf377 | 2018-03-12 18:30:56 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 711 | gpio->flags = 0; |
| 712 | if (dev->of_node) { |
Thierry Reding | 7114b7b | 2018-04-30 09:38:09 +0200 | [diff] [blame] | 713 | gpio->flags = (uintptr_t)of_device_get_match_data(dev); |
Hoan Tran | a72b8c4 | 2017-02-21 11:32:43 -0800 | [diff] [blame] | 714 | } else if (has_acpi_companion(dev)) { |
| 715 | const struct acpi_device_id *acpi_id; |
| 716 | |
| 717 | acpi_id = acpi_match_device(dwapb_acpi_match, dev); |
| 718 | if (acpi_id) { |
| 719 | if (acpi_id->driver_data) |
| 720 | gpio->flags = acpi_id->driver_data; |
| 721 | } |
| 722 | } |
| 723 | |
Weike Chen | 3d2613c | 2014-09-17 09:18:39 -0700 | [diff] [blame] | 724 | for (i = 0; i < gpio->nr_ports; i++) { |
| 725 | err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 726 | if (err) |
| 727 | goto out_unregister; |
| 728 | } |
| 729 | platform_set_drvdata(pdev, gpio); |
| 730 | |
Axel Lin | da9df93 | 2014-12-28 15:23:14 +0800 | [diff] [blame] | 731 | return 0; |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 732 | |
| 733 | out_unregister: |
| 734 | dwapb_gpio_unregister(gpio); |
| 735 | dwapb_irq_teardown(gpio); |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 736 | clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 737 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 738 | return err; |
| 739 | } |
| 740 | |
| 741 | static int dwapb_gpio_remove(struct platform_device *pdev) |
| 742 | { |
| 743 | struct dwapb_gpio *gpio = platform_get_drvdata(pdev); |
| 744 | |
| 745 | dwapb_gpio_unregister(gpio); |
| 746 | dwapb_irq_teardown(gpio); |
Alan Tull | 07901a9 | 2017-10-11 11:34:44 -0500 | [diff] [blame] | 747 | reset_control_assert(gpio->rst); |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 748 | clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 753 | #ifdef CONFIG_PM_SLEEP |
| 754 | static int dwapb_gpio_suspend(struct device *dev) |
| 755 | { |
Wolfram Sang | deb19ac | 2018-10-21 21:59:56 +0200 | [diff] [blame] | 756 | struct dwapb_gpio *gpio = dev_get_drvdata(dev); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 757 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 758 | unsigned long flags; |
| 759 | int i; |
| 760 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 761 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 762 | for (i = 0; i < gpio->nr_ports; i++) { |
| 763 | unsigned int offset; |
| 764 | unsigned int idx = gpio->ports[i].idx; |
| 765 | struct dwapb_context *ctx = gpio->ports[i].ctx; |
| 766 | |
Linus Walleij | 58a3b92 | 2014-09-24 13:30:24 +0200 | [diff] [blame] | 767 | BUG_ON(!ctx); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 768 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 769 | offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 770 | ctx->dir = dwapb_read(gpio, offset); |
| 771 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 772 | offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 773 | ctx->data = dwapb_read(gpio, offset); |
| 774 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 775 | offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 776 | ctx->ext = dwapb_read(gpio, offset); |
| 777 | |
| 778 | /* Only port A can provide interrupts */ |
| 779 | if (idx == 0) { |
| 780 | ctx->int_mask = dwapb_read(gpio, GPIO_INTMASK); |
| 781 | ctx->int_en = dwapb_read(gpio, GPIO_INTEN); |
| 782 | ctx->int_pol = dwapb_read(gpio, GPIO_INT_POLARITY); |
| 783 | ctx->int_type = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); |
| 784 | ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); |
| 785 | |
| 786 | /* Mask out interrupts */ |
Hoan Tran | 6437c7b | 2017-09-08 15:41:15 -0700 | [diff] [blame] | 787 | dwapb_write(gpio, GPIO_INTMASK, |
| 788 | 0xffffffff & ~ctx->wake_en); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 791 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 792 | |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 793 | clk_bulk_disable_unprepare(DWAPB_NR_CLOCKS, gpio->clks); |
Phil Edworthy | e6bf377 | 2018-03-12 18:30:56 +0000 | [diff] [blame] | 794 | |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | static int dwapb_gpio_resume(struct device *dev) |
| 799 | { |
Wolfram Sang | deb19ac | 2018-10-21 21:59:56 +0200 | [diff] [blame] | 800 | struct dwapb_gpio *gpio = dev_get_drvdata(dev); |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 801 | struct gpio_chip *gc = &gpio->ports[0].gc; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 802 | unsigned long flags; |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 803 | int i, err; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 804 | |
Serge Semin | 5c544c9 | 2020-03-23 22:54:00 +0300 | [diff] [blame] | 805 | err = clk_bulk_prepare_enable(DWAPB_NR_CLOCKS, gpio->clks); |
| 806 | if (err) { |
| 807 | dev_err(gpio->dev, "Cannot reenable APB/Debounce clocks\n"); |
| 808 | return err; |
| 809 | } |
Phil Edworthy | e6bf377 | 2018-03-12 18:30:56 +0000 | [diff] [blame] | 810 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 811 | spin_lock_irqsave(&gc->bgpio_lock, flags); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 812 | for (i = 0; i < gpio->nr_ports; i++) { |
| 813 | unsigned int offset; |
| 814 | unsigned int idx = gpio->ports[i].idx; |
| 815 | struct dwapb_context *ctx = gpio->ports[i].ctx; |
| 816 | |
Linus Walleij | 58a3b92 | 2014-09-24 13:30:24 +0200 | [diff] [blame] | 817 | BUG_ON(!ctx); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 818 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 819 | offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 820 | dwapb_write(gpio, offset, ctx->data); |
| 821 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 822 | offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 823 | dwapb_write(gpio, offset, ctx->dir); |
| 824 | |
Linus Walleij | 89f99fe | 2018-02-08 17:03:58 +0100 | [diff] [blame] | 825 | offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_STRIDE; |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 826 | dwapb_write(gpio, offset, ctx->ext); |
| 827 | |
| 828 | /* Only port A can provide interrupts */ |
| 829 | if (idx == 0) { |
| 830 | dwapb_write(gpio, GPIO_INTTYPE_LEVEL, ctx->int_type); |
| 831 | dwapb_write(gpio, GPIO_INT_POLARITY, ctx->int_pol); |
| 832 | dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, ctx->int_deb); |
| 833 | dwapb_write(gpio, GPIO_INTEN, ctx->int_en); |
| 834 | dwapb_write(gpio, GPIO_INTMASK, ctx->int_mask); |
| 835 | |
| 836 | /* Clear out spurious interrupts */ |
| 837 | dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); |
| 838 | } |
| 839 | } |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 840 | spin_unlock_irqrestore(&gc->bgpio_lock, flags); |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | #endif |
| 845 | |
| 846 | static SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, dwapb_gpio_suspend, |
| 847 | dwapb_gpio_resume); |
| 848 | |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 849 | static struct platform_driver dwapb_gpio_driver = { |
| 850 | .driver = { |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 851 | .name = DWAPB_DRIVER_NAME, |
Weike Chen | 1e960db | 2014-09-17 09:18:42 -0700 | [diff] [blame] | 852 | .pm = &dwapb_gpio_pm_ops, |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 853 | .of_match_table = of_match_ptr(dwapb_of_match), |
Jiang Qiu | e6cb348 | 2016-04-28 17:32:03 +0800 | [diff] [blame] | 854 | .acpi_match_table = ACPI_PTR(dwapb_acpi_match), |
Jamie Iles | 7779b345 | 2014-02-25 17:01:01 -0600 | [diff] [blame] | 855 | }, |
| 856 | .probe = dwapb_gpio_probe, |
| 857 | .remove = dwapb_gpio_remove, |
| 858 | }; |
| 859 | |
| 860 | module_platform_driver(dwapb_gpio_driver); |
| 861 | |
| 862 | MODULE_LICENSE("GPL"); |
| 863 | MODULE_AUTHOR("Jamie Iles"); |
| 864 | MODULE_DESCRIPTION("Synopsys DesignWare APB GPIO driver"); |
Andy Shevchenko | c58220c | 2020-04-15 17:15:21 +0300 | [diff] [blame] | 865 | MODULE_ALIAS("platform:" DWAPB_DRIVER_NAME); |