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