Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 1 | /* |
Grant Likely | c103de2 | 2011-06-04 18:38:28 -0600 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009 Provigent Ltd. |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 3 | * |
| 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> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/irq.h> |
| 19 | #include <linux/bitops.h> |
| 20 | #include <linux/workqueue.h> |
| 21 | #include <linux/gpio.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/amba/bus.h> |
| 24 | #include <linux/amba/pl061.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Deepak Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 26 | #include <linux/pm.h> |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 27 | |
| 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 Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 39 | #ifdef CONFIG_PM |
| 40 | struct 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 |
| 49 | |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 50 | struct pl061_gpio { |
| 51 | /* We use a list of pl061_gpio structs for each trigger IRQ in the main |
| 52 | * interrupts controller of the system. We need this to support systems |
| 53 | * in which more that one PL061s are connected to the same IRQ. The ISR |
| 54 | * interates through this list to find the source of the interrupt. |
| 55 | */ |
| 56 | struct list_head list; |
| 57 | |
| 58 | /* Each of the two spinlocks protects a different set of hardware |
| 59 | * regiters and data structurs. This decouples the code of the IRQ from |
| 60 | * the GPIO code. This also makes the case of a GPIO routine call from |
| 61 | * the IRQ code simpler. |
| 62 | */ |
| 63 | spinlock_t lock; /* GPIO registers */ |
| 64 | spinlock_t irq_lock; /* IRQ registers */ |
| 65 | |
| 66 | void __iomem *base; |
| 67 | unsigned irq_base; |
| 68 | struct gpio_chip gc; |
Deepak Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 69 | |
| 70 | #ifdef CONFIG_PM |
| 71 | struct pl061_context_save_regs csave_regs; |
| 72 | #endif |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) |
| 76 | { |
| 77 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
| 78 | unsigned long flags; |
| 79 | unsigned char gpiodir; |
| 80 | |
| 81 | if (offset >= gc->ngpio) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | spin_lock_irqsave(&chip->lock, flags); |
| 85 | gpiodir = readb(chip->base + GPIODIR); |
| 86 | gpiodir &= ~(1 << offset); |
| 87 | writeb(gpiodir, chip->base + GPIODIR); |
| 88 | spin_unlock_irqrestore(&chip->lock, flags); |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int pl061_direction_output(struct gpio_chip *gc, unsigned offset, |
| 94 | int value) |
| 95 | { |
| 96 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
| 97 | unsigned long flags; |
| 98 | unsigned char gpiodir; |
| 99 | |
| 100 | if (offset >= gc->ngpio) |
| 101 | return -EINVAL; |
| 102 | |
| 103 | spin_lock_irqsave(&chip->lock, flags); |
| 104 | writeb(!!value << offset, chip->base + (1 << (offset + 2))); |
| 105 | gpiodir = readb(chip->base + GPIODIR); |
| 106 | gpiodir |= 1 << offset; |
| 107 | writeb(gpiodir, chip->base + GPIODIR); |
viresh kumar | 64b997c | 2010-04-21 09:42:05 +0100 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * gpio value is set again, because pl061 doesn't allow to set value of |
| 111 | * a gpio pin before configuring it in OUT mode. |
| 112 | */ |
| 113 | writeb(!!value << offset, chip->base + (1 << (offset + 2))); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 114 | spin_unlock_irqrestore(&chip->lock, flags); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int pl061_get_value(struct gpio_chip *gc, unsigned offset) |
| 120 | { |
| 121 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
| 122 | |
| 123 | return !!readb(chip->base + (1 << (offset + 2))); |
| 124 | } |
| 125 | |
| 126 | static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value) |
| 127 | { |
| 128 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
| 129 | |
| 130 | writeb(!!value << offset, chip->base + (1 << (offset + 2))); |
| 131 | } |
| 132 | |
Baruch Siach | 50efacf | 2009-06-30 11:41:39 -0700 | [diff] [blame] | 133 | static int pl061_to_irq(struct gpio_chip *gc, unsigned offset) |
| 134 | { |
| 135 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
| 136 | |
Rob Herring | 76c05c8 | 2011-08-10 16:31:46 -0500 | [diff] [blame] | 137 | if (chip->irq_base == NO_IRQ) |
Baruch Siach | 50efacf | 2009-06-30 11:41:39 -0700 | [diff] [blame] | 138 | return -EINVAL; |
| 139 | |
| 140 | return chip->irq_base + offset; |
| 141 | } |
| 142 | |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 143 | /* |
| 144 | * PL061 GPIO IRQ |
| 145 | */ |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 146 | static void pl061_irq_disable(struct irq_data *d) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 147 | { |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 148 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
| 149 | int offset = d->irq - chip->irq_base; |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 150 | unsigned long flags; |
| 151 | u8 gpioie; |
| 152 | |
| 153 | spin_lock_irqsave(&chip->irq_lock, flags); |
| 154 | gpioie = readb(chip->base + GPIOIE); |
| 155 | gpioie &= ~(1 << offset); |
| 156 | writeb(gpioie, chip->base + GPIOIE); |
| 157 | spin_unlock_irqrestore(&chip->irq_lock, flags); |
| 158 | } |
| 159 | |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 160 | static void pl061_irq_enable(struct irq_data *d) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 161 | { |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 162 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
| 163 | int offset = d->irq - chip->irq_base; |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 164 | unsigned long flags; |
| 165 | u8 gpioie; |
| 166 | |
| 167 | spin_lock_irqsave(&chip->irq_lock, flags); |
| 168 | gpioie = readb(chip->base + GPIOIE); |
| 169 | gpioie |= 1 << offset; |
| 170 | writeb(gpioie, chip->base + GPIOIE); |
| 171 | spin_unlock_irqrestore(&chip->irq_lock, flags); |
| 172 | } |
| 173 | |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 174 | static int pl061_irq_type(struct irq_data *d, unsigned trigger) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 175 | { |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 176 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
| 177 | int offset = d->irq - chip->irq_base; |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 178 | unsigned long flags; |
| 179 | u8 gpiois, gpioibe, gpioiev; |
| 180 | |
Axel Lin | c1cc9b9 | 2010-05-26 14:42:19 -0700 | [diff] [blame] | 181 | if (offset < 0 || offset >= PL061_GPIO_NR) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 182 | return -EINVAL; |
| 183 | |
| 184 | spin_lock_irqsave(&chip->irq_lock, flags); |
| 185 | |
| 186 | gpioiev = readb(chip->base + GPIOIEV); |
| 187 | |
| 188 | gpiois = readb(chip->base + GPIOIS); |
| 189 | if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { |
| 190 | gpiois |= 1 << offset; |
| 191 | if (trigger & IRQ_TYPE_LEVEL_HIGH) |
| 192 | gpioiev |= 1 << offset; |
| 193 | else |
| 194 | gpioiev &= ~(1 << offset); |
| 195 | } else |
| 196 | gpiois &= ~(1 << offset); |
| 197 | writeb(gpiois, chip->base + GPIOIS); |
| 198 | |
| 199 | gpioibe = readb(chip->base + GPIOIBE); |
| 200 | if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) |
| 201 | gpioibe |= 1 << offset; |
| 202 | else { |
| 203 | gpioibe &= ~(1 << offset); |
| 204 | if (trigger & IRQ_TYPE_EDGE_RISING) |
| 205 | gpioiev |= 1 << offset; |
viresh kumar | db7e1bc | 2010-04-29 12:22:52 +0100 | [diff] [blame] | 206 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 207 | gpioiev &= ~(1 << offset); |
| 208 | } |
| 209 | writeb(gpioibe, chip->base + GPIOIBE); |
| 210 | |
| 211 | writeb(gpioiev, chip->base + GPIOIEV); |
| 212 | |
| 213 | spin_unlock_irqrestore(&chip->irq_lock, flags); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static struct irq_chip pl061_irqchip = { |
| 219 | .name = "GPIO", |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 220 | .irq_enable = pl061_irq_enable, |
| 221 | .irq_disable = pl061_irq_disable, |
| 222 | .irq_set_type = pl061_irq_type, |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) |
| 226 | { |
Thomas Gleixner | b51804b | 2011-03-24 21:27:36 +0000 | [diff] [blame] | 227 | struct list_head *chip_list = irq_get_handler_data(irq); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 228 | struct list_head *ptr; |
| 229 | struct pl061_gpio *chip; |
| 230 | |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 231 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 232 | list_for_each(ptr, chip_list) { |
| 233 | unsigned long pending; |
Baruch Siach | 50efacf | 2009-06-30 11:41:39 -0700 | [diff] [blame] | 234 | int offset; |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 235 | |
| 236 | chip = list_entry(ptr, struct pl061_gpio, list); |
| 237 | pending = readb(chip->base + GPIOMIS); |
| 238 | writeb(pending, chip->base + GPIOIC); |
| 239 | |
| 240 | if (pending == 0) |
| 241 | continue; |
| 242 | |
Akinobu Mita | 984b3f5 | 2010-03-05 13:41:37 -0800 | [diff] [blame] | 243 | for_each_set_bit(offset, &pending, PL061_GPIO_NR) |
Baruch Siach | 50efacf | 2009-06-30 11:41:39 -0700 | [diff] [blame] | 244 | generic_handle_irq(pl061_to_irq(&chip->gc, offset)); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 245 | } |
Lennert Buytenhek | b222186 | 2011-01-12 17:00:16 -0800 | [diff] [blame] | 246 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame] | 249 | static int pl061_probe(struct amba_device *dev, const struct amba_id *id) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 250 | { |
| 251 | struct pl061_platform_data *pdata; |
| 252 | struct pl061_gpio *chip; |
| 253 | struct list_head *chip_list; |
| 254 | int ret, irq, i; |
Baruch Siach | 79d7f4e | 2009-06-30 11:41:38 -0700 | [diff] [blame] | 255 | static DECLARE_BITMAP(init_irq, NR_IRQS); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 256 | |
| 257 | pdata = dev->dev.platform_data; |
| 258 | if (pdata == NULL) |
| 259 | return -ENODEV; |
| 260 | |
| 261 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
| 262 | if (chip == NULL) |
| 263 | return -ENOMEM; |
| 264 | |
Rob Herring | 76c05c8 | 2011-08-10 16:31:46 -0500 | [diff] [blame] | 265 | pdata = dev->dev.platform_data; |
| 266 | if (pdata) { |
| 267 | chip->gc.base = pdata->gpio_base; |
| 268 | chip->irq_base = pdata->irq_base; |
| 269 | } else if (dev->dev.of_node) { |
| 270 | chip->gc.base = -1; |
| 271 | chip->irq_base = NO_IRQ; |
| 272 | } else { |
| 273 | ret = -ENODEV; |
| 274 | goto free_mem; |
| 275 | } |
| 276 | |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 277 | if (!request_mem_region(dev->res.start, |
| 278 | resource_size(&dev->res), "pl061")) { |
| 279 | ret = -EBUSY; |
| 280 | goto free_mem; |
| 281 | } |
| 282 | |
| 283 | chip->base = ioremap(dev->res.start, resource_size(&dev->res)); |
| 284 | if (chip->base == NULL) { |
| 285 | ret = -ENOMEM; |
| 286 | goto release_region; |
| 287 | } |
| 288 | |
| 289 | spin_lock_init(&chip->lock); |
| 290 | spin_lock_init(&chip->irq_lock); |
| 291 | INIT_LIST_HEAD(&chip->list); |
| 292 | |
| 293 | chip->gc.direction_input = pl061_direction_input; |
| 294 | chip->gc.direction_output = pl061_direction_output; |
| 295 | chip->gc.get = pl061_get_value; |
| 296 | chip->gc.set = pl061_set_value; |
Baruch Siach | 50efacf | 2009-06-30 11:41:39 -0700 | [diff] [blame] | 297 | chip->gc.to_irq = pl061_to_irq; |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 298 | chip->gc.ngpio = PL061_GPIO_NR; |
| 299 | chip->gc.label = dev_name(&dev->dev); |
| 300 | chip->gc.dev = &dev->dev; |
| 301 | chip->gc.owner = THIS_MODULE; |
| 302 | |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 303 | ret = gpiochip_add(&chip->gc); |
| 304 | if (ret) |
| 305 | goto iounmap; |
| 306 | |
| 307 | /* |
| 308 | * irq_chip support |
| 309 | */ |
| 310 | |
Rob Herring | 76c05c8 | 2011-08-10 16:31:46 -0500 | [diff] [blame] | 311 | if (chip->irq_base == NO_IRQ) |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 312 | return 0; |
| 313 | |
| 314 | writeb(0, chip->base + GPIOIE); /* disable irqs */ |
| 315 | irq = dev->irq[0]; |
| 316 | if (irq < 0) { |
| 317 | ret = -ENODEV; |
| 318 | goto iounmap; |
| 319 | } |
Thomas Gleixner | b51804b | 2011-03-24 21:27:36 +0000 | [diff] [blame] | 320 | irq_set_chained_handler(irq, pl061_irq_handler); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 321 | if (!test_and_set_bit(irq, init_irq)) { /* list initialized? */ |
| 322 | chip_list = kmalloc(sizeof(*chip_list), GFP_KERNEL); |
| 323 | if (chip_list == NULL) { |
Baruch Siach | 79d7f4e | 2009-06-30 11:41:38 -0700 | [diff] [blame] | 324 | clear_bit(irq, init_irq); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 325 | ret = -ENOMEM; |
| 326 | goto iounmap; |
| 327 | } |
| 328 | INIT_LIST_HEAD(chip_list); |
Thomas Gleixner | b51804b | 2011-03-24 21:27:36 +0000 | [diff] [blame] | 329 | irq_set_handler_data(irq, chip_list); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 330 | } else |
Thomas Gleixner | b51804b | 2011-03-24 21:27:36 +0000 | [diff] [blame] | 331 | chip_list = irq_get_handler_data(irq); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 332 | list_add(&chip->list, chip_list); |
| 333 | |
| 334 | for (i = 0; i < PL061_GPIO_NR; i++) { |
Rob Herring | 76c05c8 | 2011-08-10 16:31:46 -0500 | [diff] [blame] | 335 | if (pdata) { |
| 336 | if (pdata->directions & (1 << i)) |
| 337 | pl061_direction_output(&chip->gc, i, |
| 338 | pdata->values & (1 << i)); |
| 339 | else |
| 340 | pl061_direction_input(&chip->gc, i); |
| 341 | } |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 342 | |
Thomas Gleixner | 08f1b80 | 2011-03-24 21:27:37 +0000 | [diff] [blame] | 343 | irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip, |
| 344 | handle_simple_irq); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 345 | set_irq_flags(i+chip->irq_base, IRQF_VALID); |
Thomas Gleixner | b51804b | 2011-03-24 21:27:36 +0000 | [diff] [blame] | 346 | irq_set_chip_data(i + chip->irq_base, chip); |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Deepak Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 349 | amba_set_drvdata(dev, chip); |
| 350 | |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | |
| 353 | iounmap: |
| 354 | iounmap(chip->base); |
| 355 | release_region: |
| 356 | release_mem_region(dev->res.start, resource_size(&dev->res)); |
| 357 | free_mem: |
| 358 | kfree(chip); |
| 359 | |
| 360 | return ret; |
| 361 | } |
| 362 | |
Deepak Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 363 | #ifdef CONFIG_PM |
| 364 | static 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++) { |
| 377 | if (chip->csave_regs.gpio_dir & (1 << offset)) |
| 378 | chip->csave_regs.gpio_data |= |
| 379 | pl061_get_value(&chip->gc, offset) << offset; |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static 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++) { |
| 391 | if (chip->csave_regs.gpio_dir & (1 << offset)) |
| 392 | pl061_direction_output(&chip->gc, offset, |
| 393 | chip->csave_regs.gpio_data & |
| 394 | (1 << offset)); |
| 395 | 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 | |
| 407 | static SIMPLE_DEV_PM_OPS(pl061_dev_pm_ops, pl061_suspend, pl061_resume); |
| 408 | #endif |
| 409 | |
Russell King | 2c39c9e | 2010-07-27 08:50:16 +0100 | [diff] [blame] | 410 | static struct amba_id pl061_ids[] = { |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 411 | { |
| 412 | .id = 0x00041061, |
| 413 | .mask = 0x000fffff, |
| 414 | }, |
| 415 | { 0, 0 }, |
| 416 | }; |
| 417 | |
| 418 | static struct amba_driver pl061_gpio_driver = { |
| 419 | .drv = { |
| 420 | .name = "pl061_gpio", |
Deepak Sikri | e198a8d | 2011-11-18 15:20:12 +0530 | [diff] [blame^] | 421 | #ifdef CONFIG_PM |
| 422 | .pm = &pl061_dev_pm_ops, |
| 423 | #endif |
Baruch Siach | 1e9c285 | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 424 | }, |
| 425 | .id_table = pl061_ids, |
| 426 | .probe = pl061_probe, |
| 427 | }; |
| 428 | |
| 429 | static int __init pl061_gpio_init(void) |
| 430 | { |
| 431 | return amba_driver_register(&pl061_gpio_driver); |
| 432 | } |
| 433 | subsys_initcall(pl061_gpio_init); |
| 434 | |
| 435 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); |
| 436 | MODULE_DESCRIPTION("PL061 GPIO driver"); |
| 437 | MODULE_LICENSE("GPL"); |