blob: 4d4b3767670220a03076301ced6b3b12cffcd265 [file] [log] [blame]
Baruch Siach1e9c2852009-06-18 16:48:58 -07001/*
Grant Likelyc103de22011-06-04 18:38:28 -06002 * Copyright (C) 2008, 2009 Provigent Ltd.
Baruch Siach1e9c2852009-06-18 16:48:58 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Driver for the ARM PrimeCell(tm) General Purpose Input/Output (PL061)
9 *
10 * Data sheet: ARM DDI 0190B, September 2000
11 */
12#include <linux/spinlock.h>
13#include <linux/errno.h>
14#include <linux/module.h>
Baruch Siach1e9c2852009-06-18 16:48:58 -070015#include <linux/io.h>
16#include <linux/ioport.h>
17#include <linux/irq.h>
Catalin Marinasde88cbb2013-01-18 15:31:37 +000018#include <linux/irqchip/chained_irq.h>
Baruch Siach1e9c2852009-06-18 16:48:58 -070019#include <linux/bitops.h>
Baruch Siach1e9c2852009-06-18 16:48:58 -070020#include <linux/gpio.h>
21#include <linux/device.h>
22#include <linux/amba/bus.h>
23#include <linux/amba/pl061.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Haojian Zhuang39b70ee2013-02-17 19:42:51 +080025#include <linux/pinctrl/consumer.h>
Deepak Sikrie198a8de2011-11-18 15:20:12 +053026#include <linux/pm.h>
Baruch Siach1e9c2852009-06-18 16:48:58 -070027
28#define GPIODIR 0x400
29#define GPIOIS 0x404
30#define GPIOIBE 0x408
31#define GPIOIEV 0x40C
32#define GPIOIE 0x410
33#define GPIORIS 0x414
34#define GPIOMIS 0x418
35#define GPIOIC 0x41C
36
37#define PL061_GPIO_NR 8
38
Deepak Sikrie198a8de2011-11-18 15:20:12 +053039#ifdef CONFIG_PM
40struct pl061_context_save_regs {
41 u8 gpio_data;
42 u8 gpio_dir;
43 u8 gpio_is;
44 u8 gpio_ibe;
45 u8 gpio_iev;
46 u8 gpio_ie;
47};
48#endif
Baruch Siach1e9c2852009-06-18 16:48:58 -070049
Baruch Siach1e9c2852009-06-18 16:48:58 -070050struct pl061_gpio {
Baruch Siach835c1922012-11-22 11:46:14 +020051 spinlock_t lock;
Baruch Siach1e9c2852009-06-18 16:48:58 -070052
53 void __iomem *base;
Baruch Siach1e9c2852009-06-18 16:48:58 -070054 struct gpio_chip gc;
Deepak Sikrie198a8de2011-11-18 15:20:12 +053055
56#ifdef CONFIG_PM
57 struct pl061_context_save_regs csave_regs;
58#endif
Baruch Siach1e9c2852009-06-18 16:48:58 -070059};
60
61static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
62{
63 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
64 unsigned long flags;
65 unsigned char gpiodir;
66
67 if (offset >= gc->ngpio)
68 return -EINVAL;
69
70 spin_lock_irqsave(&chip->lock, flags);
71 gpiodir = readb(chip->base + GPIODIR);
Javier Martinez Canillasbea41502014-04-27 02:00:50 +020072 gpiodir &= ~(BIT(offset));
Baruch Siach1e9c2852009-06-18 16:48:58 -070073 writeb(gpiodir, chip->base + GPIODIR);
74 spin_unlock_irqrestore(&chip->lock, flags);
75
76 return 0;
77}
78
79static int pl061_direction_output(struct gpio_chip *gc, unsigned offset,
80 int value)
81{
82 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
83 unsigned long flags;
84 unsigned char gpiodir;
85
86 if (offset >= gc->ngpio)
87 return -EINVAL;
88
89 spin_lock_irqsave(&chip->lock, flags);
Javier Martinez Canillasbea41502014-04-27 02:00:50 +020090 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
Baruch Siach1e9c2852009-06-18 16:48:58 -070091 gpiodir = readb(chip->base + GPIODIR);
Javier Martinez Canillasbea41502014-04-27 02:00:50 +020092 gpiodir |= BIT(offset);
Baruch Siach1e9c2852009-06-18 16:48:58 -070093 writeb(gpiodir, chip->base + GPIODIR);
viresh kumar64b997c52010-04-21 09:42:05 +010094
95 /*
96 * gpio value is set again, because pl061 doesn't allow to set value of
97 * a gpio pin before configuring it in OUT mode.
98 */
Javier Martinez Canillasbea41502014-04-27 02:00:50 +020099 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
Baruch Siach1e9c2852009-06-18 16:48:58 -0700100 spin_unlock_irqrestore(&chip->lock, flags);
101
102 return 0;
103}
104
105static int pl061_get_value(struct gpio_chip *gc, unsigned offset)
106{
107 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
108
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200109 return !!readb(chip->base + (BIT(offset + 2)));
Baruch Siach1e9c2852009-06-18 16:48:58 -0700110}
111
112static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value)
113{
114 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
115
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200116 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
Baruch Siach1e9c2852009-06-18 16:48:58 -0700117}
118
Lennert Buytenhekb2221862011-01-12 17:00:16 -0800119static int pl061_irq_type(struct irq_data *d, unsigned trigger)
Baruch Siach1e9c2852009-06-18 16:48:58 -0700120{
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100121 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
122 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800123 int offset = irqd_to_hwirq(d);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700124 unsigned long flags;
125 u8 gpiois, gpioibe, gpioiev;
Linus Walleij438a2c92013-11-26 12:59:51 +0100126 u8 bit = BIT(offset);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700127
Axel Linc1cc9b92010-05-26 14:42:19 -0700128 if (offset < 0 || offset >= PL061_GPIO_NR)
Baruch Siach1e9c2852009-06-18 16:48:58 -0700129 return -EINVAL;
130
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200131 if ((trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) &&
132 (trigger & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)))
133 {
134 dev_err(gc->dev,
135 "trying to configure line %d for both level and edge "
136 "detection, choose one!\n",
137 offset);
138 return -EINVAL;
139 }
140
Dan Carpenter21d4de12015-10-08 10:12:01 +0300141
142 spin_lock_irqsave(&chip->lock, flags);
143
144 gpioiev = readb(chip->base + GPIOIEV);
145 gpiois = readb(chip->base + GPIOIS);
146 gpioibe = readb(chip->base + GPIOIBE);
147
Linus Walleij438a2c92013-11-26 12:59:51 +0100148 if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200149 bool polarity = trigger & IRQ_TYPE_LEVEL_HIGH;
150
151 /* Disable edge detection */
152 gpioibe &= ~bit;
153 /* Enable level detection */
Linus Walleij438a2c92013-11-26 12:59:51 +0100154 gpiois |= bit;
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200155 /* Select polarity */
156 if (polarity)
Linus Walleij438a2c92013-11-26 12:59:51 +0100157 gpioiev |= bit;
158 else
159 gpioiev &= ~bit;
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700160 irq_set_handler_locked(d, handle_level_irq);
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200161 dev_dbg(gc->dev, "line %d: IRQ on %s level\n",
162 offset,
163 polarity ? "HIGH" : "LOW");
164 } else if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
165 /* Disable level detection */
166 gpiois &= ~bit;
167 /* Select both edges, setting this makes GPIOEV be ignored */
Linus Walleij438a2c92013-11-26 12:59:51 +0100168 gpioibe |= bit;
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700169 irq_set_handler_locked(d, handle_edge_irq);
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200170 dev_dbg(gc->dev, "line %d: IRQ on both edges\n", offset);
171 } else if ((trigger & IRQ_TYPE_EDGE_RISING) ||
172 (trigger & IRQ_TYPE_EDGE_FALLING)) {
173 bool rising = trigger & IRQ_TYPE_EDGE_RISING;
174
175 /* Disable level detection */
176 gpiois &= ~bit;
177 /* Clear detection on both edges */
Linus Walleij438a2c92013-11-26 12:59:51 +0100178 gpioibe &= ~bit;
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200179 /* Select edge */
180 if (rising)
Linus Walleij438a2c92013-11-26 12:59:51 +0100181 gpioiev |= bit;
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200182 else
Linus Walleij438a2c92013-11-26 12:59:51 +0100183 gpioiev &= ~bit;
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700184 irq_set_handler_locked(d, handle_edge_irq);
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200185 dev_dbg(gc->dev, "line %d: IRQ on %s edge\n",
186 offset,
187 rising ? "RISING" : "FALLING");
188 } else {
189 /* No trigger: disable everything */
190 gpiois &= ~bit;
191 gpioibe &= ~bit;
192 gpioiev &= ~bit;
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700193 irq_set_handler_locked(d, handle_bad_irq);
Linus Walleij1dbf7f22015-09-17 14:21:25 +0200194 dev_warn(gc->dev, "no trigger selected for line %d\n",
195 offset);
Linus Walleij438a2c92013-11-26 12:59:51 +0100196 }
197
198 writeb(gpiois, chip->base + GPIOIS);
199 writeb(gpioibe, chip->base + GPIOIBE);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700200 writeb(gpioiev, chip->base + GPIOIEV);
201
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800202 spin_unlock_irqrestore(&chip->lock, flags);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700203
204 return 0;
205}
206
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200207static void pl061_irq_handler(struct irq_desc *desc)
Baruch Siach1e9c2852009-06-18 16:48:58 -0700208{
Rob Herring2de0dbc2012-01-04 10:36:07 -0600209 unsigned long pending;
210 int offset;
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100211 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
212 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
Rob Herringdece9042011-12-09 14:12:53 -0600213 struct irq_chip *irqchip = irq_desc_get_chip(desc);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700214
Rob Herringdece9042011-12-09 14:12:53 -0600215 chained_irq_enter(irqchip, desc);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700216
Rob Herring2de0dbc2012-01-04 10:36:07 -0600217 pending = readb(chip->base + GPIOMIS);
Rob Herring2de0dbc2012-01-04 10:36:07 -0600218 if (pending) {
Akinobu Mita984b3f52010-03-05 13:41:37 -0800219 for_each_set_bit(offset, &pending, PL061_GPIO_NR)
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100220 generic_handle_irq(irq_find_mapping(gc->irqdomain,
221 offset));
Baruch Siach1e9c2852009-06-18 16:48:58 -0700222 }
Rob Herring2de0dbc2012-01-04 10:36:07 -0600223
Rob Herringdece9042011-12-09 14:12:53 -0600224 chained_irq_exit(irqchip, desc);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700225}
226
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800227static void pl061_irq_mask(struct irq_data *d)
Rob Herring3ab52472011-10-21 08:05:53 -0500228{
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100229 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
230 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200231 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800232 u8 gpioie;
Rob Herring3ab52472011-10-21 08:05:53 -0500233
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800234 spin_lock(&chip->lock);
235 gpioie = readb(chip->base + GPIOIE) & ~mask;
236 writeb(gpioie, chip->base + GPIOIE);
237 spin_unlock(&chip->lock);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700238}
239
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800240static void pl061_irq_unmask(struct irq_data *d)
241{
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100242 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
243 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200244 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800245 u8 gpioie;
246
247 spin_lock(&chip->lock);
248 gpioie = readb(chip->base + GPIOIE) | mask;
249 writeb(gpioie, chip->base + GPIOIE);
250 spin_unlock(&chip->lock);
251}
252
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700253/**
254 * pl061_irq_ack() - ACK an edge IRQ
255 * @d: IRQ data for this IRQ
256 *
257 * This gets called from the edge IRQ handler to ACK the edge IRQ
258 * in the GPIOIC (interrupt-clear) register. For level IRQs this is
259 * not needed: these go away when the level signal goes away.
260 */
261static void pl061_irq_ack(struct irq_data *d)
262{
263 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
264 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
265 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
266
267 spin_lock(&chip->lock);
268 writeb(mask, chip->base + GPIOIC);
269 spin_unlock(&chip->lock);
270}
271
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800272static struct irq_chip pl061_irqchip = {
Linus Walleij9ae7e9e2013-11-26 14:19:44 +0100273 .name = "pl061",
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700274 .irq_ack = pl061_irq_ack,
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800275 .irq_mask = pl061_irq_mask,
276 .irq_unmask = pl061_irq_unmask,
277 .irq_set_type = pl061_irq_type,
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800278};
279
Tobias Klauser8944df72012-10-05 11:45:28 +0200280static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
Baruch Siach1e9c2852009-06-18 16:48:58 -0700281{
Tobias Klauser8944df72012-10-05 11:45:28 +0200282 struct device *dev = &adev->dev;
Jingoo Hane56aee12013-07-30 17:08:05 +0900283 struct pl061_platform_data *pdata = dev_get_platdata(dev);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700284 struct pl061_gpio *chip;
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800285 int ret, irq, i, irq_base;
Baruch Siach1e9c2852009-06-18 16:48:58 -0700286
Tobias Klauser8944df72012-10-05 11:45:28 +0200287 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700288 if (chip == NULL)
289 return -ENOMEM;
290
Rob Herring76c05c82011-08-10 16:31:46 -0500291 if (pdata) {
292 chip->gc.base = pdata->gpio_base;
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800293 irq_base = pdata->irq_base;
Linus Walleij78087552013-11-22 10:11:49 +0100294 if (irq_base <= 0) {
295 dev_err(&adev->dev, "invalid IRQ base in pdata\n");
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800296 return -ENODEV;
Linus Walleij78087552013-11-22 10:11:49 +0100297 }
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800298 } else {
Rob Herring76c05c82011-08-10 16:31:46 -0500299 chip->gc.base = -1;
Haojian Zhuangf1f70472013-02-17 19:42:49 +0800300 irq_base = 0;
301 }
Rob Herring76c05c82011-08-10 16:31:46 -0500302
Jingoo Han09bafc32014-02-12 11:53:58 +0900303 chip->base = devm_ioremap_resource(dev, &adev->res);
304 if (IS_ERR(chip->base))
305 return PTR_ERR(chip->base);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700306
307 spin_lock_init(&chip->lock);
Jonas Gorski31831f42015-10-11 17:34:18 +0200308 if (of_property_read_bool(dev->of_node, "gpio-ranges")) {
309 chip->gc.request = gpiochip_generic_request;
310 chip->gc.free = gpiochip_generic_free;
311 }
Baruch Siach1e9c2852009-06-18 16:48:58 -0700312
313 chip->gc.direction_input = pl061_direction_input;
314 chip->gc.direction_output = pl061_direction_output;
315 chip->gc.get = pl061_get_value;
316 chip->gc.set = pl061_set_value;
Baruch Siach1e9c2852009-06-18 16:48:58 -0700317 chip->gc.ngpio = PL061_GPIO_NR;
Tobias Klauser8944df72012-10-05 11:45:28 +0200318 chip->gc.label = dev_name(dev);
319 chip->gc.dev = dev;
Baruch Siach1e9c2852009-06-18 16:48:58 -0700320 chip->gc.owner = THIS_MODULE;
321
Baruch Siach1e9c2852009-06-18 16:48:58 -0700322 ret = gpiochip_add(&chip->gc);
323 if (ret)
Tobias Klauser8944df72012-10-05 11:45:28 +0200324 return ret;
Baruch Siach1e9c2852009-06-18 16:48:58 -0700325
326 /*
327 * irq_chip support
328 */
Baruch Siach1e9c2852009-06-18 16:48:58 -0700329 writeb(0, chip->base + GPIOIE); /* disable irqs */
Tobias Klauser8944df72012-10-05 11:45:28 +0200330 irq = adev->irq[0];
Linus Walleij78087552013-11-22 10:11:49 +0100331 if (irq < 0) {
332 dev_err(&adev->dev, "invalid IRQ\n");
Tobias Klauser8944df72012-10-05 11:45:28 +0200333 return -ENODEV;
Linus Walleij78087552013-11-22 10:11:49 +0100334 }
Tobias Klauser8944df72012-10-05 11:45:28 +0200335
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100336 ret = gpiochip_irqchip_add(&chip->gc, &pl061_irqchip,
Linus Walleij26ba9cd2015-09-24 17:52:52 -0700337 irq_base, handle_bad_irq,
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100338 IRQ_TYPE_NONE);
339 if (ret) {
340 dev_info(&adev->dev, "could not add irqchip\n");
341 return ret;
Linus Walleij78087552013-11-22 10:11:49 +0100342 }
Linus Walleij8d5b24b2014-03-25 10:42:35 +0100343 gpiochip_set_chained_irqchip(&chip->gc, &pl061_irqchip,
344 irq, pl061_irq_handler);
Linus Walleij2ba31542013-11-27 08:47:02 +0100345
Baruch Siach1e9c2852009-06-18 16:48:58 -0700346 for (i = 0; i < PL061_GPIO_NR; i++) {
Rob Herring76c05c82011-08-10 16:31:46 -0500347 if (pdata) {
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200348 if (pdata->directions & (BIT(i)))
Rob Herring76c05c82011-08-10 16:31:46 -0500349 pl061_direction_output(&chip->gc, i,
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200350 pdata->values & (BIT(i)));
Rob Herring76c05c82011-08-10 16:31:46 -0500351 else
352 pl061_direction_input(&chip->gc, i);
353 }
Baruch Siach1e9c2852009-06-18 16:48:58 -0700354 }
355
Tobias Klauser8944df72012-10-05 11:45:28 +0200356 amba_set_drvdata(adev, chip);
Fabio Estevam76b36272014-02-26 08:12:37 -0300357 dev_info(&adev->dev, "PL061 GPIO chip @%pa registered\n",
358 &adev->res.start);
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530359
Baruch Siach1e9c2852009-06-18 16:48:58 -0700360 return 0;
Baruch Siach1e9c2852009-06-18 16:48:58 -0700361}
362
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530363#ifdef CONFIG_PM
364static int pl061_suspend(struct device *dev)
365{
366 struct pl061_gpio *chip = dev_get_drvdata(dev);
367 int offset;
368
369 chip->csave_regs.gpio_data = 0;
370 chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR);
371 chip->csave_regs.gpio_is = readb(chip->base + GPIOIS);
372 chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE);
373 chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV);
374 chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE);
375
376 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200377 if (chip->csave_regs.gpio_dir & (BIT(offset)))
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530378 chip->csave_regs.gpio_data |=
379 pl061_get_value(&chip->gc, offset) << offset;
380 }
381
382 return 0;
383}
384
385static int pl061_resume(struct device *dev)
386{
387 struct pl061_gpio *chip = dev_get_drvdata(dev);
388 int offset;
389
390 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200391 if (chip->csave_regs.gpio_dir & (BIT(offset)))
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530392 pl061_direction_output(&chip->gc, offset,
393 chip->csave_regs.gpio_data &
Javier Martinez Canillasbea41502014-04-27 02:00:50 +0200394 (BIT(offset)));
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530395 else
396 pl061_direction_input(&chip->gc, offset);
397 }
398
399 writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS);
400 writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE);
401 writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV);
402 writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE);
403
404 return 0;
405}
406
Viresh Kumar6e33ace2012-01-11 15:25:20 +0530407static const struct dev_pm_ops pl061_dev_pm_ops = {
408 .suspend = pl061_suspend,
409 .resume = pl061_resume,
410 .freeze = pl061_suspend,
411 .restore = pl061_resume,
412};
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530413#endif
414
Russell King2c39c9e2010-07-27 08:50:16 +0100415static struct amba_id pl061_ids[] = {
Baruch Siach1e9c2852009-06-18 16:48:58 -0700416 {
417 .id = 0x00041061,
418 .mask = 0x000fffff,
419 },
420 { 0, 0 },
421};
422
Dave Martin955b6782011-10-05 15:15:21 +0100423MODULE_DEVICE_TABLE(amba, pl061_ids);
424
Baruch Siach1e9c2852009-06-18 16:48:58 -0700425static struct amba_driver pl061_gpio_driver = {
426 .drv = {
427 .name = "pl061_gpio",
Deepak Sikrie198a8de2011-11-18 15:20:12 +0530428#ifdef CONFIG_PM
429 .pm = &pl061_dev_pm_ops,
430#endif
Baruch Siach1e9c2852009-06-18 16:48:58 -0700431 },
432 .id_table = pl061_ids,
433 .probe = pl061_probe,
434};
435
436static int __init pl061_gpio_init(void)
437{
438 return amba_driver_register(&pl061_gpio_driver);
439}
Haojian Zhuang5985d762013-01-18 15:31:13 +0800440module_init(pl061_gpio_init);
Baruch Siach1e9c2852009-06-18 16:48:58 -0700441
442MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
443MODULE_DESCRIPTION("PL061 GPIO driver");
444MODULE_LICENSE("GPL");