Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux-2.6

2nd round of GPIO changes for v3.3 merge window

* tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux-2.6:
GPIO: sa1100: implement proper gpiolib gpio_to_irq conversion
gpio: pl061: remove combined interrupt
gpio: pl061: convert to use generic irq chip
GPIO: add bindings for managed devices
ARM: realview: convert pl061 no irq to 0 instead of -1
gpio: pl061: convert to use 0 for no irq
gpio: pl061: use chained_irq_* functions in irq handler
GPIO/pl061: Add suspend resume capability
drivers/gpio/gpio-tegra.c: use devm_request_and_ioremap

+214 -118
-3
arch/arm/mach-realview/realview_eb.c
··· 117 117 118 118 static struct pl061_platform_data gpio0_plat_data = { 119 119 .gpio_base = 0, 120 - .irq_base = -1, 121 120 }; 122 121 123 122 static struct pl061_platform_data gpio1_plat_data = { 124 123 .gpio_base = 8, 125 - .irq_base = -1, 126 124 }; 127 125 128 126 static struct pl061_platform_data gpio2_plat_data = { 129 127 .gpio_base = 16, 130 - .irq_base = -1, 131 128 }; 132 129 133 130 static struct pl022_ssp_controller ssp0_plat_data = {
-3
arch/arm/mach-realview/realview_pb1176.c
··· 113 113 114 114 static struct pl061_platform_data gpio0_plat_data = { 115 115 .gpio_base = 0, 116 - .irq_base = -1, 117 116 }; 118 117 119 118 static struct pl061_platform_data gpio1_plat_data = { 120 119 .gpio_base = 8, 121 - .irq_base = -1, 122 120 }; 123 121 124 122 static struct pl061_platform_data gpio2_plat_data = { 125 123 .gpio_base = 16, 126 - .irq_base = -1, 127 124 }; 128 125 129 126 static struct pl022_ssp_controller ssp0_plat_data = {
-3
arch/arm/mach-realview/realview_pb11mp.c
··· 112 112 113 113 static struct pl061_platform_data gpio0_plat_data = { 114 114 .gpio_base = 0, 115 - .irq_base = -1, 116 115 }; 117 116 118 117 static struct pl061_platform_data gpio1_plat_data = { 119 118 .gpio_base = 8, 120 - .irq_base = -1, 121 119 }; 122 120 123 121 static struct pl061_platform_data gpio2_plat_data = { 124 122 .gpio_base = 16, 125 - .irq_base = -1, 126 123 }; 127 124 128 125 static struct pl022_ssp_controller ssp0_plat_data = {
-3
arch/arm/mach-realview/realview_pba8.c
··· 102 102 103 103 static struct pl061_platform_data gpio0_plat_data = { 104 104 .gpio_base = 0, 105 - .irq_base = -1, 106 105 }; 107 106 108 107 static struct pl061_platform_data gpio1_plat_data = { 109 108 .gpio_base = 8, 110 - .irq_base = -1, 111 109 }; 112 110 113 111 static struct pl061_platform_data gpio2_plat_data = { 114 112 .gpio_base = 16, 115 - .irq_base = -1, 116 113 }; 117 114 118 115 static struct pl022_ssp_controller ssp0_plat_data = {
-3
arch/arm/mach-realview/realview_pbx.c
··· 124 124 125 125 static struct pl061_platform_data gpio0_plat_data = { 126 126 .gpio_base = 0, 127 - .irq_base = -1, 128 127 }; 129 128 130 129 static struct pl061_platform_data gpio1_plat_data = { 131 130 .gpio_base = 8, 132 - .irq_base = -1, 133 131 }; 134 132 135 133 static struct pl061_platform_data gpio2_plat_data = { 136 134 .gpio_base = 16, 137 - .irq_base = -1, 138 135 }; 139 136 140 137 static struct pl022_ssp_controller ssp0_plat_data = {
-3
arch/arm/mach-sa1100/include/mach/gpio.h
··· 51 51 52 52 #define gpio_cansleep __gpio_cansleep 53 53 54 - #define gpio_to_irq(gpio) ((gpio < 11) ? (IRQ_GPIO0 + gpio) : \ 55 - (IRQ_GPIO11 - 11 + gpio)) 56 - 57 54 #endif
+1
drivers/gpio/Kconfig
··· 138 138 config GPIO_PL061 139 139 bool "PrimeCell PL061 GPIO support" 140 140 depends on ARM_AMBA 141 + select GENERIC_IRQ_CHIP 141 142 help 142 143 Say yes here to support the PrimeCell PL061 GPIO device 143 144
+1 -1
drivers/gpio/Makefile
··· 2 2 3 3 ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG 4 4 5 - obj-$(CONFIG_GPIOLIB) += gpiolib.o 5 + obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o 6 6 7 7 # Device drivers. Generally keep list sorted alphabetically 8 8 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
+90
drivers/gpio/devres.c
··· 1 + /* 2 + * drivers/gpio/devres.c - managed gpio resources 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 6 + * as published by the Free Software Foundation. 7 + * 8 + * You should have received a copy of the GNU General Public License 9 + * along with this program; if not, write to the Free Software 10 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 11 + * 12 + * This file is based on kernel/irq/devres.c 13 + * 14 + * Copyright (c) 2011 John Crispin <blogic@openwrt.org> 15 + */ 16 + 17 + #include <linux/module.h> 18 + #include <linux/gpio.h> 19 + #include <linux/device.h> 20 + #include <linux/gfp.h> 21 + 22 + static void devm_gpio_release(struct device *dev, void *res) 23 + { 24 + unsigned *gpio = res; 25 + 26 + gpio_free(*gpio); 27 + } 28 + 29 + static int devm_gpio_match(struct device *dev, void *res, void *data) 30 + { 31 + unsigned *this = res, *gpio = data; 32 + 33 + return *this == *gpio; 34 + } 35 + 36 + /** 37 + * devm_gpio_request - request a gpio for a managed device 38 + * @dev: device to request the gpio for 39 + * @gpio: gpio to allocate 40 + * @label: the name of the requested gpio 41 + * 42 + * Except for the extra @dev argument, this function takes the 43 + * same arguments and performs the same function as 44 + * gpio_request(). GPIOs requested with this function will be 45 + * automatically freed on driver detach. 46 + * 47 + * If an GPIO allocated with this function needs to be freed 48 + * separately, devm_gpio_free() must be used. 49 + */ 50 + 51 + int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) 52 + { 53 + unsigned *dr; 54 + int rc; 55 + 56 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 57 + if (!dr) 58 + return -ENOMEM; 59 + 60 + rc = gpio_request(gpio, label); 61 + if (rc) { 62 + devres_free(dr); 63 + return rc; 64 + } 65 + 66 + *dr = gpio; 67 + devres_add(dev, dr); 68 + 69 + return 0; 70 + } 71 + EXPORT_SYMBOL(devm_gpio_request); 72 + 73 + /** 74 + * devm_gpio_free - free an interrupt 75 + * @dev: device to free gpio for 76 + * @gpio: gpio to free 77 + * 78 + * Except for the extra @dev argument, this function takes the 79 + * same arguments and performs the same function as gpio_free(). 80 + * This function instead of gpio_free() should be used to manually 81 + * free GPIOs allocated with devm_gpio_request(). 82 + */ 83 + void devm_gpio_free(struct device *dev, unsigned int gpio) 84 + { 85 + 86 + WARN_ON(devres_destroy(dev, devm_gpio_release, devm_gpio_match, 87 + &gpio)); 88 + gpio_free(gpio); 89 + } 90 + EXPORT_SYMBOL(devm_gpio_free);
+110 -90
drivers/gpio/gpio-pl061.c
··· 12 12 #include <linux/spinlock.h> 13 13 #include <linux/errno.h> 14 14 #include <linux/module.h> 15 - #include <linux/list.h> 16 15 #include <linux/io.h> 17 16 #include <linux/ioport.h> 18 17 #include <linux/irq.h> ··· 22 23 #include <linux/amba/bus.h> 23 24 #include <linux/amba/pl061.h> 24 25 #include <linux/slab.h> 26 + #include <linux/pm.h> 27 + #include <asm/mach/irq.h> 25 28 26 29 #define GPIODIR 0x400 27 30 #define GPIOIS 0x404 ··· 36 35 37 36 #define PL061_GPIO_NR 8 38 37 39 - struct pl061_gpio { 40 - /* We use a list of pl061_gpio structs for each trigger IRQ in the main 41 - * interrupts controller of the system. We need this to support systems 42 - * in which more that one PL061s are connected to the same IRQ. The ISR 43 - * interates through this list to find the source of the interrupt. 44 - */ 45 - struct list_head list; 38 + #ifdef CONFIG_PM 39 + struct pl061_context_save_regs { 40 + u8 gpio_data; 41 + u8 gpio_dir; 42 + u8 gpio_is; 43 + u8 gpio_ibe; 44 + u8 gpio_iev; 45 + u8 gpio_ie; 46 + }; 47 + #endif 46 48 49 + struct pl061_gpio { 47 50 /* Each of the two spinlocks protects a different set of hardware 48 51 * regiters and data structurs. This decouples the code of the IRQ from 49 52 * the GPIO code. This also makes the case of a GPIO routine call from 50 53 * the IRQ code simpler. 51 54 */ 52 55 spinlock_t lock; /* GPIO registers */ 53 - spinlock_t irq_lock; /* IRQ registers */ 54 56 55 57 void __iomem *base; 56 - unsigned irq_base; 58 + int irq_base; 59 + struct irq_chip_generic *irq_gc; 57 60 struct gpio_chip gc; 61 + 62 + #ifdef CONFIG_PM 63 + struct pl061_context_save_regs csave_regs; 64 + #endif 58 65 }; 59 66 60 67 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) ··· 127 118 { 128 119 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 129 120 130 - if (chip->irq_base == NO_IRQ) 121 + if (chip->irq_base <= 0) 131 122 return -EINVAL; 132 123 133 124 return chip->irq_base + offset; 134 125 } 135 126 136 - /* 137 - * PL061 GPIO IRQ 138 - */ 139 - static void pl061_irq_disable(struct irq_data *d) 140 - { 141 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 142 - int offset = d->irq - chip->irq_base; 143 - unsigned long flags; 144 - u8 gpioie; 145 - 146 - spin_lock_irqsave(&chip->irq_lock, flags); 147 - gpioie = readb(chip->base + GPIOIE); 148 - gpioie &= ~(1 << offset); 149 - writeb(gpioie, chip->base + GPIOIE); 150 - spin_unlock_irqrestore(&chip->irq_lock, flags); 151 - } 152 - 153 - static void pl061_irq_enable(struct irq_data *d) 154 - { 155 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 156 - int offset = d->irq - chip->irq_base; 157 - unsigned long flags; 158 - u8 gpioie; 159 - 160 - spin_lock_irqsave(&chip->irq_lock, flags); 161 - gpioie = readb(chip->base + GPIOIE); 162 - gpioie |= 1 << offset; 163 - writeb(gpioie, chip->base + GPIOIE); 164 - spin_unlock_irqrestore(&chip->irq_lock, flags); 165 - } 166 - 167 127 static int pl061_irq_type(struct irq_data *d, unsigned trigger) 168 128 { 169 - struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); 129 + struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 130 + struct pl061_gpio *chip = gc->private; 170 131 int offset = d->irq - chip->irq_base; 171 132 unsigned long flags; 172 133 u8 gpiois, gpioibe, gpioiev; ··· 144 165 if (offset < 0 || offset >= PL061_GPIO_NR) 145 166 return -EINVAL; 146 167 147 - spin_lock_irqsave(&chip->irq_lock, flags); 168 + raw_spin_lock_irqsave(&gc->lock, flags); 148 169 149 170 gpioiev = readb(chip->base + GPIOIEV); 150 171 ··· 173 194 174 195 writeb(gpioiev, chip->base + GPIOIEV); 175 196 176 - spin_unlock_irqrestore(&chip->irq_lock, flags); 197 + raw_spin_unlock_irqrestore(&gc->lock, flags); 177 198 178 199 return 0; 179 200 } 180 201 181 - static struct irq_chip pl061_irqchip = { 182 - .name = "GPIO", 183 - .irq_enable = pl061_irq_enable, 184 - .irq_disable = pl061_irq_disable, 185 - .irq_set_type = pl061_irq_type, 186 - }; 187 - 188 202 static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) 189 203 { 190 - struct list_head *chip_list = irq_get_handler_data(irq); 191 - struct list_head *ptr; 192 - struct pl061_gpio *chip; 204 + unsigned long pending; 205 + int offset; 206 + struct pl061_gpio *chip = irq_desc_get_handler_data(desc); 207 + struct irq_chip *irqchip = irq_desc_get_chip(desc); 193 208 194 - desc->irq_data.chip->irq_ack(&desc->irq_data); 195 - list_for_each(ptr, chip_list) { 196 - unsigned long pending; 197 - int offset; 209 + chained_irq_enter(irqchip, desc); 198 210 199 - chip = list_entry(ptr, struct pl061_gpio, list); 200 - pending = readb(chip->base + GPIOMIS); 201 - writeb(pending, chip->base + GPIOIC); 202 - 203 - if (pending == 0) 204 - continue; 205 - 211 + pending = readb(chip->base + GPIOMIS); 212 + writeb(pending, chip->base + GPIOIC); 213 + if (pending) { 206 214 for_each_set_bit(offset, &pending, PL061_GPIO_NR) 207 215 generic_handle_irq(pl061_to_irq(&chip->gc, offset)); 208 216 } 209 - desc->irq_data.chip->irq_unmask(&desc->irq_data); 217 + 218 + chained_irq_exit(irqchip, desc); 219 + } 220 + 221 + static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base) 222 + { 223 + struct irq_chip_type *ct; 224 + 225 + chip->irq_gc = irq_alloc_generic_chip("gpio-pl061", 1, irq_base, 226 + chip->base, handle_simple_irq); 227 + chip->irq_gc->private = chip; 228 + 229 + ct = chip->irq_gc->chip_types; 230 + ct->chip.irq_mask = irq_gc_mask_clr_bit; 231 + ct->chip.irq_unmask = irq_gc_mask_set_bit; 232 + ct->chip.irq_set_type = pl061_irq_type; 233 + ct->chip.irq_set_wake = irq_gc_set_wake; 234 + ct->regs.mask = GPIOIE; 235 + 236 + irq_setup_generic_chip(chip->irq_gc, IRQ_MSK(PL061_GPIO_NR), 237 + IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); 210 238 } 211 239 212 240 static int pl061_probe(struct amba_device *dev, const struct amba_id *id) 213 241 { 214 242 struct pl061_platform_data *pdata; 215 243 struct pl061_gpio *chip; 216 - struct list_head *chip_list; 217 244 int ret, irq, i; 218 - static DECLARE_BITMAP(init_irq, NR_IRQS); 219 245 220 246 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 221 247 if (chip == NULL) ··· 232 248 chip->irq_base = pdata->irq_base; 233 249 } else if (dev->dev.of_node) { 234 250 chip->gc.base = -1; 235 - chip->irq_base = NO_IRQ; 251 + chip->irq_base = 0; 236 252 } else { 237 253 ret = -ENODEV; 238 254 goto free_mem; ··· 251 267 } 252 268 253 269 spin_lock_init(&chip->lock); 254 - spin_lock_init(&chip->irq_lock); 255 - INIT_LIST_HEAD(&chip->list); 256 270 257 271 chip->gc.direction_input = pl061_direction_input; 258 272 chip->gc.direction_output = pl061_direction_output; ··· 270 288 * irq_chip support 271 289 */ 272 290 273 - if (chip->irq_base == NO_IRQ) 291 + if (chip->irq_base <= 0) 274 292 return 0; 293 + 294 + pl061_init_gc(chip, chip->irq_base); 275 295 276 296 writeb(0, chip->base + GPIOIE); /* disable irqs */ 277 297 irq = dev->irq[0]; ··· 282 298 goto iounmap; 283 299 } 284 300 irq_set_chained_handler(irq, pl061_irq_handler); 285 - if (!test_and_set_bit(irq, init_irq)) { /* list initialized? */ 286 - chip_list = kmalloc(sizeof(*chip_list), GFP_KERNEL); 287 - if (chip_list == NULL) { 288 - clear_bit(irq, init_irq); 289 - ret = -ENOMEM; 290 - goto iounmap; 291 - } 292 - INIT_LIST_HEAD(chip_list); 293 - irq_set_handler_data(irq, chip_list); 294 - } else 295 - chip_list = irq_get_handler_data(irq); 296 - list_add(&chip->list, chip_list); 301 + irq_set_handler_data(irq, chip); 297 302 298 303 for (i = 0; i < PL061_GPIO_NR; i++) { 299 304 if (pdata) { ··· 292 319 else 293 320 pl061_direction_input(&chip->gc, i); 294 321 } 295 - 296 - irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip, 297 - handle_simple_irq); 298 - set_irq_flags(i+chip->irq_base, IRQF_VALID); 299 - irq_set_chip_data(i + chip->irq_base, chip); 300 322 } 323 + 324 + amba_set_drvdata(dev, chip); 301 325 302 326 return 0; 303 327 ··· 307 337 308 338 return ret; 309 339 } 340 + 341 + #ifdef CONFIG_PM 342 + static int pl061_suspend(struct device *dev) 343 + { 344 + struct pl061_gpio *chip = dev_get_drvdata(dev); 345 + int offset; 346 + 347 + chip->csave_regs.gpio_data = 0; 348 + chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR); 349 + chip->csave_regs.gpio_is = readb(chip->base + GPIOIS); 350 + chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE); 351 + chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV); 352 + chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE); 353 + 354 + for (offset = 0; offset < PL061_GPIO_NR; offset++) { 355 + if (chip->csave_regs.gpio_dir & (1 << offset)) 356 + chip->csave_regs.gpio_data |= 357 + pl061_get_value(&chip->gc, offset) << offset; 358 + } 359 + 360 + return 0; 361 + } 362 + 363 + static int pl061_resume(struct device *dev) 364 + { 365 + struct pl061_gpio *chip = dev_get_drvdata(dev); 366 + int offset; 367 + 368 + for (offset = 0; offset < PL061_GPIO_NR; offset++) { 369 + if (chip->csave_regs.gpio_dir & (1 << offset)) 370 + pl061_direction_output(&chip->gc, offset, 371 + chip->csave_regs.gpio_data & 372 + (1 << offset)); 373 + else 374 + pl061_direction_input(&chip->gc, offset); 375 + } 376 + 377 + writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS); 378 + writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE); 379 + writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV); 380 + writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE); 381 + 382 + return 0; 383 + } 384 + 385 + static SIMPLE_DEV_PM_OPS(pl061_dev_pm_ops, pl061_suspend, pl061_resume); 386 + #endif 310 387 311 388 static struct amba_id pl061_ids[] = { 312 389 { ··· 368 351 static struct amba_driver pl061_gpio_driver = { 369 352 .drv = { 370 353 .name = "pl061_gpio", 354 + #ifdef CONFIG_PM 355 + .pm = &pl061_dev_pm_ops, 356 + #endif 371 357 }, 372 358 .id_table = pl061_ids, 373 359 .probe = pl061_probe,
+6
drivers/gpio/gpio-sa1100.c
··· 47 47 return 0; 48 48 } 49 49 50 + static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset) 51 + { 52 + return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset); 53 + } 54 + 50 55 static struct gpio_chip sa1100_gpio_chip = { 51 56 .label = "gpio", 52 57 .direction_input = sa1100_direction_input, 53 58 .direction_output = sa1100_direction_output, 54 59 .set = sa1100_gpio_set, 55 60 .get = sa1100_gpio_get, 61 + .to_irq = sa1100_to_irq, 56 62 .base = 0, 57 63 .ngpio = GPIO_MAX + 1, 58 64 };
+1 -8
drivers/gpio/gpio-tegra.c
··· 361 361 return -ENODEV; 362 362 } 363 363 364 - if (!devm_request_mem_region(&pdev->dev, res->start, 365 - resource_size(res), 366 - dev_name(&pdev->dev))) { 367 - dev_err(&pdev->dev, "Couldn't request MEM resource\n"); 368 - return -ENODEV; 369 - } 370 - 371 - regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 364 + regs = devm_request_and_ioremap(&pdev->dev, res); 372 365 if (!regs) { 373 366 dev_err(&pdev->dev, "Couldn't ioremap regs\n"); 374 367 return -ENODEV;
+4
include/asm-generic/gpio.h
··· 177 177 extern int gpio_request_array(const struct gpio *array, size_t num); 178 178 extern void gpio_free_array(const struct gpio *array, size_t num); 179 179 180 + /* bindings for managed devices that want to request gpios */ 181 + int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); 182 + void devm_gpio_free(struct device *dev, unsigned int gpio); 183 + 180 184 #ifdef CONFIG_GPIO_SYSFS 181 185 182 186 /*
+1 -1
include/linux/amba/pl061.h
··· 7 7 unsigned gpio_base; 8 8 9 9 /* number of the first IRQ. 10 - * If the IRQ functionality in not desired this must be set to NO_IRQ. 10 + * If the IRQ functionality in not desired this must be set to 0. 11 11 */ 12 12 unsigned irq_base; 13 13