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

Merge branch 'gpio/next' of git://git.secretlab.ca/git/linux-2.6

* 'gpio/next' of git://git.secretlab.ca/git/linux-2.6:
gpio/via: rename VIA local config struct
basic_mmio_gpio: split into a gpio library and platform device
gpio: remove some legacy comments in build files
gpio: add trace events for setting direction and value
gpio/pca953x: Use handle_simple_irq instead of handle_edge_irq
gpiolib: export gpiochip_find
gpio: remove redundant Kconfig depends on GPIOLIB
basic_mmio_gpio: convert to non-__raw* accessors
basic_mmio_gpio: support direction registers
basic_mmio_gpio: support different input/output registers
basic_mmio_gpio: detect output method at probe time
basic_mmio_gpio: request register regions
basic_mmio_gpio: allow overriding number of gpio
basic_mmio_gpio: convert to platform_{get,set}_drvdata()
basic_mmio_gpio: remove runtime width/endianness evaluation

+559 -178
+14 -9
drivers/gpio/Kconfig
··· 1 1 # 2 - # platform-neutral GPIO infrastructure and expanders 2 + # GPIO infrastructure and drivers 3 3 # 4 4 5 5 config ARCH_WANT_OPTIONAL_GPIOLIB ··· 31 31 help 32 32 This enables GPIO support through the generic GPIO library. 33 33 You only need to enable this, if you also want to enable 34 - one or more of the GPIO expansion card drivers below. 34 + one or more of the GPIO drivers below. 35 35 36 36 If unsure, say N. 37 37 ··· 63 63 Kernel drivers may also request that a particular GPIO be 64 64 exported to userspace; this can be useful when debugging. 65 65 66 - # put expanders in the right section, in alphabetical order 66 + # put drivers in the right section, in alphabetical order 67 67 68 68 config GPIO_MAX730X 69 69 tristate 70 70 71 - comment "Memory mapped GPIO expanders:" 71 + comment "Memory mapped GPIO drivers:" 72 + 73 + config GPIO_BASIC_MMIO_CORE 74 + tristate 75 + help 76 + Provides core functionality for basic memory-mapped GPIO controllers. 72 77 73 78 config GPIO_BASIC_MMIO 74 79 tristate "Basic memory-mapped GPIO controllers support" 80 + select GPIO_BASIC_MMIO_CORE 75 81 help 76 82 Say yes here to support basic memory-mapped GPIO controllers. 77 83 78 84 config GPIO_IT8761E 79 85 tristate "IT8761E GPIO support" 80 - depends on GPIOLIB 81 86 help 82 87 Say yes here to support GPIO functionality of IT8761E super I/O chip. 83 88 ··· 106 101 107 102 config GPIO_SCH 108 103 tristate "Intel SCH/TunnelCreek GPIO" 109 - depends on GPIOLIB && PCI && X86 104 + depends on PCI && X86 110 105 select MFD_CORE 111 106 select LPC_SCH 112 107 help ··· 126 121 127 122 config GPIO_VX855 128 123 tristate "VIA VX855/VX875 GPIO" 129 - depends on GPIOLIB && MFD_SUPPORT && PCI 124 + depends on MFD_SUPPORT && PCI 130 125 select MFD_CORE 131 126 select MFD_VX855 132 127 help ··· 352 347 353 348 config GPIO_TIMBERDALE 354 349 bool "Support for timberdale GPIO IP" 355 - depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM 350 + depends on MFD_TIMBERDALE && HAS_IOMEM 356 351 ---help--- 357 352 Add support for the GPIO IP in the timberdale FPGA. 358 353 359 354 config GPIO_RDC321X 360 355 tristate "RDC R-321x GPIO support" 361 - depends on PCI && GPIOLIB 356 + depends on PCI 362 357 select MFD_SUPPORT 363 358 select MFD_CORE 364 359 select MFD_RDC321X
+2 -5
drivers/gpio/Makefile
··· 1 - # generic gpio support: dedicated expander chips, etc 2 - # 3 - # NOTE: platform-specific GPIO drivers don't belong in the 4 - # drivers/gpio directory; put them with other platform setup 5 - # code, IRQ controllers, board init, etc. 1 + # generic gpio support: platform drivers, dedicated expander chips, etc 6 2 7 3 ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG 8 4 ··· 6 10 7 11 obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o 8 12 obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o 13 + obj-$(CONFIG_GPIO_BASIC_MMIO_CORE) += basic_mmio_gpio.o 9 14 obj-$(CONFIG_GPIO_BASIC_MMIO) += basic_mmio_gpio.o 10 15 obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o 11 16 obj-$(CONFIG_GPIO_MAX730X) += max730x.o
+388 -137
drivers/gpio/basic_mmio_gpio.c
··· 45 45 */ 46 46 47 47 #include <linux/init.h> 48 + #include <linux/err.h> 48 49 #include <linux/bug.h> 49 50 #include <linux/kernel.h> 50 51 #include <linux/module.h> ··· 62 61 #include <linux/mod_devicetable.h> 63 62 #include <linux/basic_mmio_gpio.h> 64 63 65 - struct bgpio_chip { 66 - struct gpio_chip gc; 67 - void __iomem *reg_dat; 68 - void __iomem *reg_set; 69 - void __iomem *reg_clr; 70 - 71 - /* Number of bits (GPIOs): <register width> * 8. */ 72 - int bits; 73 - 74 - /* 75 - * Some GPIO controllers work with the big-endian bits notation, 76 - * e.g. in a 8-bits register, GPIO7 is the least significant bit. 77 - */ 78 - int big_endian_bits; 79 - 80 - /* 81 - * Used to lock bgpio_chip->data. Also, this is needed to keep 82 - * shadowed and real data registers writes together. 83 - */ 84 - spinlock_t lock; 85 - 86 - /* Shadowed data register to clear/set bits safely. */ 87 - unsigned long data; 88 - }; 89 - 90 - static struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc) 64 + static void bgpio_write8(void __iomem *reg, unsigned long data) 91 65 { 92 - return container_of(gc, struct bgpio_chip, gc); 66 + writeb(data, reg); 93 67 } 94 68 95 - static unsigned long bgpio_in(struct bgpio_chip *bgc) 69 + static unsigned long bgpio_read8(void __iomem *reg) 96 70 { 97 - switch (bgc->bits) { 98 - case 8: 99 - return __raw_readb(bgc->reg_dat); 100 - case 16: 101 - return __raw_readw(bgc->reg_dat); 102 - case 32: 103 - return __raw_readl(bgc->reg_dat); 71 + return readb(reg); 72 + } 73 + 74 + static void bgpio_write16(void __iomem *reg, unsigned long data) 75 + { 76 + writew(data, reg); 77 + } 78 + 79 + static unsigned long bgpio_read16(void __iomem *reg) 80 + { 81 + return readw(reg); 82 + } 83 + 84 + static void bgpio_write32(void __iomem *reg, unsigned long data) 85 + { 86 + writel(data, reg); 87 + } 88 + 89 + static unsigned long bgpio_read32(void __iomem *reg) 90 + { 91 + return readl(reg); 92 + } 93 + 104 94 #if BITS_PER_LONG >= 64 105 - case 64: 106 - return __raw_readq(bgc->reg_dat); 107 - #endif 108 - } 109 - return -EINVAL; 95 + static void bgpio_write64(void __iomem *reg, unsigned long data) 96 + { 97 + writeq(data, reg); 110 98 } 111 99 112 - static void bgpio_out(struct bgpio_chip *bgc, void __iomem *reg, 113 - unsigned long data) 100 + static unsigned long bgpio_read64(void __iomem *reg) 114 101 { 115 - switch (bgc->bits) { 116 - case 8: 117 - __raw_writeb(data, reg); 118 - return; 119 - case 16: 120 - __raw_writew(data, reg); 121 - return; 122 - case 32: 123 - __raw_writel(data, reg); 124 - return; 125 - #if BITS_PER_LONG >= 64 126 - case 64: 127 - __raw_writeq(data, reg); 128 - return; 129 - #endif 130 - } 102 + return readq(reg); 131 103 } 104 + #endif /* BITS_PER_LONG >= 64 */ 132 105 133 106 static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin) 134 107 { 135 - if (bgc->big_endian_bits) 136 - return 1 << (bgc->bits - 1 - pin); 137 - else 138 - return 1 << pin; 108 + return 1 << pin; 109 + } 110 + 111 + static unsigned long bgpio_pin2mask_be(struct bgpio_chip *bgc, 112 + unsigned int pin) 113 + { 114 + return 1 << (bgc->bits - 1 - pin); 139 115 } 140 116 141 117 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 142 118 { 143 119 struct bgpio_chip *bgc = to_bgpio_chip(gc); 144 120 145 - return bgpio_in(bgc) & bgpio_pin2mask(bgc, gpio); 121 + return bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio); 146 122 } 147 123 148 124 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 149 125 { 150 126 struct bgpio_chip *bgc = to_bgpio_chip(gc); 151 - unsigned long mask = bgpio_pin2mask(bgc, gpio); 127 + unsigned long mask = bgc->pin2mask(bgc, gpio); 152 128 unsigned long flags; 153 - 154 - if (bgc->reg_set) { 155 - if (val) 156 - bgpio_out(bgc, bgc->reg_set, mask); 157 - else 158 - bgpio_out(bgc, bgc->reg_clr, mask); 159 - return; 160 - } 161 129 162 130 spin_lock_irqsave(&bgc->lock, flags); 163 131 ··· 135 165 else 136 166 bgc->data &= ~mask; 137 167 138 - bgpio_out(bgc, bgc->reg_dat, bgc->data); 168 + bgc->write_reg(bgc->reg_dat, bgc->data); 139 169 140 170 spin_unlock_irqrestore(&bgc->lock, flags); 141 171 } 142 172 173 + static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, 174 + int val) 175 + { 176 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 177 + unsigned long mask = bgc->pin2mask(bgc, gpio); 178 + 179 + if (val) 180 + bgc->write_reg(bgc->reg_set, mask); 181 + else 182 + bgc->write_reg(bgc->reg_clr, mask); 183 + } 184 + 185 + static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) 186 + { 187 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 188 + unsigned long mask = bgc->pin2mask(bgc, gpio); 189 + unsigned long flags; 190 + 191 + spin_lock_irqsave(&bgc->lock, flags); 192 + 193 + if (val) 194 + bgc->data |= mask; 195 + else 196 + bgc->data &= ~mask; 197 + 198 + bgc->write_reg(bgc->reg_set, bgc->data); 199 + 200 + spin_unlock_irqrestore(&bgc->lock, flags); 201 + } 202 + 203 + static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) 204 + { 205 + return 0; 206 + } 207 + 208 + static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, 209 + int val) 210 + { 211 + gc->set(gc, gpio, val); 212 + 213 + return 0; 214 + } 215 + 143 216 static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 144 217 { 218 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 219 + unsigned long flags; 220 + 221 + spin_lock_irqsave(&bgc->lock, flags); 222 + 223 + bgc->dir &= ~bgc->pin2mask(bgc, gpio); 224 + bgc->write_reg(bgc->reg_dir, bgc->dir); 225 + 226 + spin_unlock_irqrestore(&bgc->lock, flags); 227 + 145 228 return 0; 146 229 } 147 230 148 231 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 149 232 { 150 - bgpio_set(gc, gpio, val); 233 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 234 + unsigned long flags; 235 + 236 + gc->set(gc, gpio, val); 237 + 238 + spin_lock_irqsave(&bgc->lock, flags); 239 + 240 + bgc->dir |= bgc->pin2mask(bgc, gpio); 241 + bgc->write_reg(bgc->reg_dir, bgc->dir); 242 + 243 + spin_unlock_irqrestore(&bgc->lock, flags); 244 + 151 245 return 0; 152 246 } 153 247 154 - static int __devinit bgpio_probe(struct platform_device *pdev) 248 + static int bgpio_dir_in_inv(struct gpio_chip *gc, unsigned int gpio) 155 249 { 156 - const struct platform_device_id *platid = platform_get_device_id(pdev); 157 - struct device *dev = &pdev->dev; 158 - struct bgpio_pdata *pdata = dev_get_platdata(dev); 159 - struct bgpio_chip *bgc; 160 - struct resource *res_dat; 161 - struct resource *res_set; 162 - struct resource *res_clr; 163 - resource_size_t dat_sz; 164 - int bits; 165 - int ret; 250 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 251 + unsigned long flags; 166 252 167 - res_dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); 168 - if (!res_dat) 169 - return -EINVAL; 253 + spin_lock_irqsave(&bgc->lock, flags); 170 254 171 - dat_sz = resource_size(res_dat); 172 - if (!is_power_of_2(dat_sz)) 173 - return -EINVAL; 255 + bgc->dir |= bgc->pin2mask(bgc, gpio); 256 + bgc->write_reg(bgc->reg_dir, bgc->dir); 174 257 175 - bits = dat_sz * 8; 176 - if (bits > BITS_PER_LONG) 177 - return -EINVAL; 258 + spin_unlock_irqrestore(&bgc->lock, flags); 178 259 179 - bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL); 180 - if (!bgc) 181 - return -ENOMEM; 260 + return 0; 261 + } 182 262 183 - bgc->reg_dat = devm_ioremap(dev, res_dat->start, dat_sz); 184 - if (!bgc->reg_dat) 185 - return -ENOMEM; 263 + static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val) 264 + { 265 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 266 + unsigned long flags; 186 267 187 - res_set = platform_get_resource_byname(pdev, IORESOURCE_MEM, "set"); 188 - res_clr = platform_get_resource_byname(pdev, IORESOURCE_MEM, "clr"); 189 - if (res_set && res_clr) { 190 - if (resource_size(res_set) != resource_size(res_clr) || 191 - resource_size(res_set) != dat_sz) 192 - return -EINVAL; 268 + gc->set(gc, gpio, val); 193 269 194 - bgc->reg_set = devm_ioremap(dev, res_set->start, dat_sz); 195 - bgc->reg_clr = devm_ioremap(dev, res_clr->start, dat_sz); 196 - if (!bgc->reg_set || !bgc->reg_clr) 197 - return -ENOMEM; 198 - } else if (res_set || res_clr) { 270 + spin_lock_irqsave(&bgc->lock, flags); 271 + 272 + bgc->dir &= ~bgc->pin2mask(bgc, gpio); 273 + bgc->write_reg(bgc->reg_dir, bgc->dir); 274 + 275 + spin_unlock_irqrestore(&bgc->lock, flags); 276 + 277 + return 0; 278 + } 279 + 280 + static int bgpio_setup_accessors(struct device *dev, 281 + struct bgpio_chip *bgc, 282 + bool be) 283 + { 284 + 285 + switch (bgc->bits) { 286 + case 8: 287 + bgc->read_reg = bgpio_read8; 288 + bgc->write_reg = bgpio_write8; 289 + break; 290 + case 16: 291 + bgc->read_reg = bgpio_read16; 292 + bgc->write_reg = bgpio_write16; 293 + break; 294 + case 32: 295 + bgc->read_reg = bgpio_read32; 296 + bgc->write_reg = bgpio_write32; 297 + break; 298 + #if BITS_PER_LONG >= 64 299 + case 64: 300 + bgc->read_reg = bgpio_read64; 301 + bgc->write_reg = bgpio_write64; 302 + break; 303 + #endif /* BITS_PER_LONG >= 64 */ 304 + default: 305 + dev_err(dev, "unsupported data width %u bits\n", bgc->bits); 199 306 return -EINVAL; 200 307 } 201 308 202 - spin_lock_init(&bgc->lock); 309 + bgc->pin2mask = be ? bgpio_pin2mask_be : bgpio_pin2mask; 203 310 204 - bgc->bits = bits; 205 - bgc->big_endian_bits = !strcmp(platid->name, "basic-mmio-gpio-be"); 206 - bgc->data = bgpio_in(bgc); 311 + return 0; 312 + } 207 313 208 - bgc->gc.ngpio = bits; 209 - bgc->gc.direction_input = bgpio_dir_in; 210 - bgc->gc.direction_output = bgpio_dir_out; 314 + /* 315 + * Create the device and allocate the resources. For setting GPIO's there are 316 + * three supported configurations: 317 + * 318 + * - single input/output register resource (named "dat"). 319 + * - set/clear pair (named "set" and "clr"). 320 + * - single output register resource and single input resource ("set" and 321 + * dat"). 322 + * 323 + * For the single output register, this drives a 1 by setting a bit and a zero 324 + * by clearing a bit. For the set clr pair, this drives a 1 by setting a bit 325 + * in the set register and clears it by setting a bit in the clear register. 326 + * The configuration is detected by which resources are present. 327 + * 328 + * For setting the GPIO direction, there are three supported configurations: 329 + * 330 + * - simple bidirection GPIO that requires no configuration. 331 + * - an output direction register (named "dirout") where a 1 bit 332 + * indicates the GPIO is an output. 333 + * - an input direction register (named "dirin") where a 1 bit indicates 334 + * the GPIO is an input. 335 + */ 336 + static int bgpio_setup_io(struct bgpio_chip *bgc, 337 + void __iomem *dat, 338 + void __iomem *set, 339 + void __iomem *clr) 340 + { 341 + 342 + bgc->reg_dat = dat; 343 + if (!bgc->reg_dat) 344 + return -EINVAL; 345 + 346 + if (set && clr) { 347 + bgc->reg_set = set; 348 + bgc->reg_clr = clr; 349 + bgc->gc.set = bgpio_set_with_clear; 350 + } else if (set && !clr) { 351 + bgc->reg_set = set; 352 + bgc->gc.set = bgpio_set_set; 353 + } else { 354 + bgc->gc.set = bgpio_set; 355 + } 356 + 211 357 bgc->gc.get = bgpio_get; 212 - bgc->gc.set = bgpio_set; 358 + 359 + return 0; 360 + } 361 + 362 + static int bgpio_setup_direction(struct bgpio_chip *bgc, 363 + void __iomem *dirout, 364 + void __iomem *dirin) 365 + { 366 + if (dirout && dirin) { 367 + return -EINVAL; 368 + } else if (dirout) { 369 + bgc->reg_dir = dirout; 370 + bgc->gc.direction_output = bgpio_dir_out; 371 + bgc->gc.direction_input = bgpio_dir_in; 372 + } else if (dirin) { 373 + bgc->reg_dir = dirin; 374 + bgc->gc.direction_output = bgpio_dir_out_inv; 375 + bgc->gc.direction_input = bgpio_dir_in_inv; 376 + } else { 377 + bgc->gc.direction_output = bgpio_simple_dir_out; 378 + bgc->gc.direction_input = bgpio_simple_dir_in; 379 + } 380 + 381 + return 0; 382 + } 383 + 384 + int __devexit bgpio_remove(struct bgpio_chip *bgc) 385 + { 386 + int err = gpiochip_remove(&bgc->gc); 387 + 388 + kfree(bgc); 389 + 390 + return err; 391 + } 392 + EXPORT_SYMBOL_GPL(bgpio_remove); 393 + 394 + int __devinit bgpio_init(struct bgpio_chip *bgc, 395 + struct device *dev, 396 + unsigned long sz, 397 + void __iomem *dat, 398 + void __iomem *set, 399 + void __iomem *clr, 400 + void __iomem *dirout, 401 + void __iomem *dirin, 402 + bool big_endian) 403 + { 404 + int ret; 405 + 406 + if (!is_power_of_2(sz)) 407 + return -EINVAL; 408 + 409 + bgc->bits = sz * 8; 410 + if (bgc->bits > BITS_PER_LONG) 411 + return -EINVAL; 412 + 413 + spin_lock_init(&bgc->lock); 213 414 bgc->gc.dev = dev; 214 415 bgc->gc.label = dev_name(dev); 416 + bgc->gc.base = -1; 417 + bgc->gc.ngpio = bgc->bits; 215 418 216 - if (pdata) 217 - bgc->gc.base = pdata->base; 218 - else 219 - bgc->gc.base = -1; 220 - 221 - dev_set_drvdata(dev, bgc); 222 - 223 - ret = gpiochip_add(&bgc->gc); 419 + ret = bgpio_setup_io(bgc, dat, set, clr); 224 420 if (ret) 225 - dev_err(dev, "gpiochip_add() failed: %d\n", ret); 421 + return ret; 422 + 423 + ret = bgpio_setup_accessors(dev, bgc, big_endian); 424 + if (ret) 425 + return ret; 426 + 427 + ret = bgpio_setup_direction(bgc, dirout, dirin); 428 + if (ret) 429 + return ret; 430 + 431 + bgc->data = bgc->read_reg(bgc->reg_dat); 432 + 433 + return ret; 434 + } 435 + EXPORT_SYMBOL_GPL(bgpio_init); 436 + 437 + #ifdef CONFIG_GPIO_BASIC_MMIO 438 + 439 + static void __iomem *bgpio_map(struct platform_device *pdev, 440 + const char *name, 441 + resource_size_t sane_sz, 442 + int *err) 443 + { 444 + struct device *dev = &pdev->dev; 445 + struct resource *r; 446 + resource_size_t start; 447 + resource_size_t sz; 448 + void __iomem *ret; 449 + 450 + *err = 0; 451 + 452 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); 453 + if (!r) 454 + return NULL; 455 + 456 + sz = resource_size(r); 457 + if (sz != sane_sz) { 458 + *err = -EINVAL; 459 + return NULL; 460 + } 461 + 462 + start = r->start; 463 + if (!devm_request_mem_region(dev, start, sz, r->name)) { 464 + *err = -EBUSY; 465 + return NULL; 466 + } 467 + 468 + ret = devm_ioremap(dev, start, sz); 469 + if (!ret) { 470 + *err = -ENOMEM; 471 + return NULL; 472 + } 226 473 227 474 return ret; 228 475 } 229 476 230 - static int __devexit bgpio_remove(struct platform_device *pdev) 477 + static int __devinit bgpio_pdev_probe(struct platform_device *pdev) 231 478 { 232 - struct bgpio_chip *bgc = dev_get_drvdata(&pdev->dev); 479 + struct device *dev = &pdev->dev; 480 + struct resource *r; 481 + void __iomem *dat; 482 + void __iomem *set; 483 + void __iomem *clr; 484 + void __iomem *dirout; 485 + void __iomem *dirin; 486 + unsigned long sz; 487 + bool be; 488 + int err; 489 + struct bgpio_chip *bgc; 490 + struct bgpio_pdata *pdata = dev_get_platdata(dev); 233 491 234 - return gpiochip_remove(&bgc->gc); 492 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); 493 + if (!r) 494 + return -EINVAL; 495 + 496 + sz = resource_size(r); 497 + 498 + dat = bgpio_map(pdev, "dat", sz, &err); 499 + if (!dat) 500 + return err ? err : -EINVAL; 501 + 502 + set = bgpio_map(pdev, "set", sz, &err); 503 + if (err) 504 + return err; 505 + 506 + clr = bgpio_map(pdev, "clr", sz, &err); 507 + if (err) 508 + return err; 509 + 510 + dirout = bgpio_map(pdev, "dirout", sz, &err); 511 + if (err) 512 + return err; 513 + 514 + dirin = bgpio_map(pdev, "dirin", sz, &err); 515 + if (err) 516 + return err; 517 + 518 + be = !strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be"); 519 + 520 + bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); 521 + if (!bgc) 522 + return -ENOMEM; 523 + 524 + err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, be); 525 + if (err) 526 + return err; 527 + 528 + if (pdata) { 529 + bgc->gc.base = pdata->base; 530 + if (pdata->ngpio > 0) 531 + bgc->gc.ngpio = pdata->ngpio; 532 + } 533 + 534 + platform_set_drvdata(pdev, bgc); 535 + 536 + return gpiochip_add(&bgc->gc); 537 + } 538 + 539 + static int __devexit bgpio_pdev_remove(struct platform_device *pdev) 540 + { 541 + struct bgpio_chip *bgc = platform_get_drvdata(pdev); 542 + 543 + return bgpio_remove(bgc); 235 544 } 236 545 237 546 static const struct platform_device_id bgpio_id_table[] = { ··· 525 276 .name = "basic-mmio-gpio", 526 277 }, 527 278 .id_table = bgpio_id_table, 528 - .probe = bgpio_probe, 529 - .remove = __devexit_p(bgpio_remove), 279 + .probe = bgpio_pdev_probe, 280 + .remove = __devexit_p(bgpio_pdev_remove), 530 281 }; 531 282 532 - static int __init bgpio_init(void) 283 + static int __init bgpio_platform_init(void) 533 284 { 534 285 return platform_driver_register(&bgpio_driver); 535 286 } 536 - module_init(bgpio_init); 287 + module_init(bgpio_platform_init); 537 288 538 - static void __exit bgpio_exit(void) 289 + static void __exit bgpio_platform_exit(void) 539 290 { 540 291 platform_driver_unregister(&bgpio_driver); 541 292 } 542 - module_exit(bgpio_exit); 293 + module_exit(bgpio_platform_exit); 294 + 295 + #endif /* CONFIG_GPIO_BASIC_MMIO */ 543 296 544 297 MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers"); 545 298 MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
+17 -2
drivers/gpio/gpiolib.c
··· 12 12 #include <linux/idr.h> 13 13 #include <linux/slab.h> 14 14 15 + #define CREATE_TRACE_POINTS 16 + #include <trace/events/gpio.h> 15 17 16 18 /* Optional implementation infrastructure for GPIO interfaces. 17 19 * ··· 1167 1165 1168 1166 return chip; 1169 1167 } 1168 + EXPORT_SYMBOL_GPL(gpiochip_find); 1170 1169 1171 1170 /* These "optional" allocation calls help prevent drivers from stomping 1172 1171 * on each other, and help provide better diagnostics in debugfs. ··· 1407 1404 status = chip->direction_input(chip, gpio); 1408 1405 if (status == 0) 1409 1406 clear_bit(FLAG_IS_OUT, &desc->flags); 1407 + 1408 + trace_gpio_direction(chip->base + gpio, 1, status); 1410 1409 lose: 1411 1410 return status; 1412 1411 fail: ··· 1462 1457 status = chip->direction_output(chip, gpio, value); 1463 1458 if (status == 0) 1464 1459 set_bit(FLAG_IS_OUT, &desc->flags); 1460 + trace_gpio_value(chip->base + gpio, 0, value); 1461 + trace_gpio_direction(chip->base + gpio, 0, status); 1465 1462 lose: 1466 1463 return status; 1467 1464 fail: ··· 1553 1546 int __gpio_get_value(unsigned gpio) 1554 1547 { 1555 1548 struct gpio_chip *chip; 1549 + int value; 1556 1550 1557 1551 chip = gpio_to_chip(gpio); 1558 1552 WARN_ON(chip->can_sleep); 1559 - return chip->get ? chip->get(chip, gpio - chip->base) : 0; 1553 + value = chip->get ? chip->get(chip, gpio - chip->base) : 0; 1554 + trace_gpio_value(gpio, 1, value); 1555 + return value; 1560 1556 } 1561 1557 EXPORT_SYMBOL_GPL(__gpio_get_value); 1562 1558 ··· 1578 1568 1579 1569 chip = gpio_to_chip(gpio); 1580 1570 WARN_ON(chip->can_sleep); 1571 + trace_gpio_value(gpio, 0, value); 1581 1572 chip->set(chip, gpio - chip->base, value); 1582 1573 } 1583 1574 EXPORT_SYMBOL_GPL(__gpio_set_value); ··· 1629 1618 int gpio_get_value_cansleep(unsigned gpio) 1630 1619 { 1631 1620 struct gpio_chip *chip; 1621 + int value; 1632 1622 1633 1623 might_sleep_if(extra_checks); 1634 1624 chip = gpio_to_chip(gpio); 1635 - return chip->get ? chip->get(chip, gpio - chip->base) : 0; 1625 + value = chip->get ? chip->get(chip, gpio - chip->base) : 0; 1626 + trace_gpio_value(gpio, 1, value); 1627 + return value; 1636 1628 } 1637 1629 EXPORT_SYMBOL_GPL(gpio_get_value_cansleep); 1638 1630 ··· 1645 1631 1646 1632 might_sleep_if(extra_checks); 1647 1633 chip = gpio_to_chip(gpio); 1634 + trace_gpio_value(gpio, 0, value); 1648 1635 chip->set(chip, gpio - chip->base, value); 1649 1636 } 1650 1637 EXPORT_SYMBOL_GPL(gpio_set_value_cansleep);
+1 -1
drivers/gpio/pca953x.c
··· 397 397 398 398 irq_set_chip_data(irq, chip); 399 399 irq_set_chip_and_handler(irq, &pca953x_irq_chip, 400 - handle_edge_irq); 400 + handle_simple_irq); 401 401 #ifdef CONFIG_ARM 402 402 set_irq_flags(irq, IRQF_VALID); 403 403 #else
+25 -24
drivers/video/via/via-gpio.c
··· 145 145 } 146 146 147 147 148 - static struct viafb_gpio_cfg gpio_config = { 148 + static struct viafb_gpio_cfg viafb_gpio_config = { 149 149 .gpio_chip = { 150 150 .label = "VIAFB onboard GPIO", 151 151 .owner = THIS_MODULE, ··· 183 183 { 184 184 int i; 185 185 186 - for (i = 0; i < gpio_config.gpio_chip.ngpio; i += 2) 187 - viafb_gpio_enable(gpio_config.active_gpios[i]); 186 + for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i += 2) 187 + viafb_gpio_enable(viafb_gpio_config.active_gpios[i]); 188 188 return 0; 189 189 } 190 190 ··· 201 201 { 202 202 int i; 203 203 204 - for (i = 0; i < gpio_config.gpio_chip.ngpio; i++) 205 - if (!strcmp(name, gpio_config.active_gpios[i]->vg_name)) 206 - return gpio_config.gpio_chip.base + i; 204 + for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i++) 205 + if (!strcmp(name, viafb_gpio_config.active_gpios[i]->vg_name)) 206 + return viafb_gpio_config.gpio_chip.base + i; 207 207 return -1; 208 208 } 209 209 EXPORT_SYMBOL_GPL(viafb_gpio_lookup); ··· 229 229 for (gpio = viafb_all_gpios; 230 230 gpio < viafb_all_gpios + VIAFB_NUM_GPIOS; gpio++) 231 231 if (gpio->vg_port_index == port_cfg[i].ioport_index) { 232 - gpio_config.active_gpios[ngpio] = gpio; 233 - gpio_config.gpio_names[ngpio] = gpio->vg_name; 232 + viafb_gpio_config.active_gpios[ngpio] = gpio; 233 + viafb_gpio_config.gpio_names[ngpio] = 234 + gpio->vg_name; 234 235 ngpio++; 235 236 } 236 237 } 237 - gpio_config.gpio_chip.ngpio = ngpio; 238 - gpio_config.gpio_chip.names = gpio_config.gpio_names; 239 - gpio_config.vdev = vdev; 238 + viafb_gpio_config.gpio_chip.ngpio = ngpio; 239 + viafb_gpio_config.gpio_chip.names = viafb_gpio_config.gpio_names; 240 + viafb_gpio_config.vdev = vdev; 240 241 if (ngpio == 0) { 241 242 printk(KERN_INFO "viafb: no GPIOs configured\n"); 242 243 return 0; ··· 246 245 * Enable the ports. They come in pairs, with a single 247 246 * enable bit for both. 248 247 */ 249 - spin_lock_irqsave(&gpio_config.vdev->reg_lock, flags); 248 + spin_lock_irqsave(&viafb_gpio_config.vdev->reg_lock, flags); 250 249 for (i = 0; i < ngpio; i += 2) 251 - viafb_gpio_enable(gpio_config.active_gpios[i]); 252 - spin_unlock_irqrestore(&gpio_config.vdev->reg_lock, flags); 250 + viafb_gpio_enable(viafb_gpio_config.active_gpios[i]); 251 + spin_unlock_irqrestore(&viafb_gpio_config.vdev->reg_lock, flags); 253 252 /* 254 253 * Get registered. 255 254 */ 256 - gpio_config.gpio_chip.base = -1; /* Dynamic */ 257 - ret = gpiochip_add(&gpio_config.gpio_chip); 255 + viafb_gpio_config.gpio_chip.base = -1; /* Dynamic */ 256 + ret = gpiochip_add(&viafb_gpio_config.gpio_chip); 258 257 if (ret) { 259 258 printk(KERN_ERR "viafb: failed to add gpios (%d)\n", ret); 260 - gpio_config.gpio_chip.ngpio = 0; 259 + viafb_gpio_config.gpio_chip.ngpio = 0; 261 260 } 262 261 #ifdef CONFIG_PM 263 262 viafb_pm_register(&viafb_gpio_pm_hooks); ··· 278 277 /* 279 278 * Get unregistered. 280 279 */ 281 - if (gpio_config.gpio_chip.ngpio > 0) { 282 - ret = gpiochip_remove(&gpio_config.gpio_chip); 280 + if (viafb_gpio_config.gpio_chip.ngpio > 0) { 281 + ret = gpiochip_remove(&viafb_gpio_config.gpio_chip); 283 282 if (ret) { /* Somebody still using it? */ 284 283 printk(KERN_ERR "Viafb: GPIO remove failed\n"); 285 284 return ret; ··· 288 287 /* 289 288 * Disable the ports. 290 289 */ 291 - spin_lock_irqsave(&gpio_config.vdev->reg_lock, flags); 292 - for (i = 0; i < gpio_config.gpio_chip.ngpio; i += 2) 293 - viafb_gpio_disable(gpio_config.active_gpios[i]); 294 - gpio_config.gpio_chip.ngpio = 0; 295 - spin_unlock_irqrestore(&gpio_config.vdev->reg_lock, flags); 290 + spin_lock_irqsave(&viafb_gpio_config.vdev->reg_lock, flags); 291 + for (i = 0; i < viafb_gpio_config.gpio_chip.ngpio; i += 2) 292 + viafb_gpio_disable(viafb_gpio_config.active_gpios[i]); 293 + viafb_gpio_config.gpio_chip.ngpio = 0; 294 + spin_unlock_irqrestore(&viafb_gpio_config.vdev->reg_lock, flags); 296 295 return ret; 297 296 } 298 297
+56
include/linux/basic_mmio_gpio.h
··· 13 13 #ifndef __BASIC_MMIO_GPIO_H 14 14 #define __BASIC_MMIO_GPIO_H 15 15 16 + #include <linux/gpio.h> 17 + #include <linux/types.h> 18 + #include <linux/compiler.h> 19 + 16 20 struct bgpio_pdata { 17 21 int base; 22 + int ngpio; 18 23 }; 24 + 25 + struct device; 26 + 27 + struct bgpio_chip { 28 + struct gpio_chip gc; 29 + 30 + unsigned long (*read_reg)(void __iomem *reg); 31 + void (*write_reg)(void __iomem *reg, unsigned long data); 32 + 33 + void __iomem *reg_dat; 34 + void __iomem *reg_set; 35 + void __iomem *reg_clr; 36 + void __iomem *reg_dir; 37 + 38 + /* Number of bits (GPIOs): <register width> * 8. */ 39 + int bits; 40 + 41 + /* 42 + * Some GPIO controllers work with the big-endian bits notation, 43 + * e.g. in a 8-bits register, GPIO7 is the least significant bit. 44 + */ 45 + unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin); 46 + 47 + /* 48 + * Used to lock bgpio_chip->data. Also, this is needed to keep 49 + * shadowed and real data registers writes together. 50 + */ 51 + spinlock_t lock; 52 + 53 + /* Shadowed data register to clear/set bits safely. */ 54 + unsigned long data; 55 + 56 + /* Shadowed direction registers to clear/set direction safely. */ 57 + unsigned long dir; 58 + }; 59 + 60 + static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc) 61 + { 62 + return container_of(gc, struct bgpio_chip, gc); 63 + } 64 + 65 + int __devexit bgpio_remove(struct bgpio_chip *bgc); 66 + int __devinit bgpio_init(struct bgpio_chip *bgc, 67 + struct device *dev, 68 + unsigned long sz, 69 + void __iomem *dat, 70 + void __iomem *set, 71 + void __iomem *clr, 72 + void __iomem *dirout, 73 + void __iomem *dirin, 74 + bool big_endian); 19 75 20 76 #endif /* __BASIC_MMIO_GPIO_H */
+56
include/trace/events/gpio.h
··· 1 + #undef TRACE_SYSTEM 2 + #define TRACE_SYSTEM gpio 3 + 4 + #if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) 5 + #define _TRACE_GPIO_H 6 + 7 + #include <linux/tracepoint.h> 8 + 9 + TRACE_EVENT(gpio_direction, 10 + 11 + TP_PROTO(unsigned gpio, int in, int err), 12 + 13 + TP_ARGS(gpio, in, err), 14 + 15 + TP_STRUCT__entry( 16 + __field(unsigned, gpio) 17 + __field(int, in) 18 + __field(int, err) 19 + ), 20 + 21 + TP_fast_assign( 22 + __entry->gpio = gpio; 23 + __entry->in = in; 24 + __entry->err = err; 25 + ), 26 + 27 + TP_printk("%u %3s (%d)", __entry->gpio, 28 + __entry->in ? "in" : "out", __entry->err) 29 + ); 30 + 31 + TRACE_EVENT(gpio_value, 32 + 33 + TP_PROTO(unsigned gpio, int get, int value), 34 + 35 + TP_ARGS(gpio, get, value), 36 + 37 + TP_STRUCT__entry( 38 + __field(unsigned, gpio) 39 + __field(int, get) 40 + __field(int, value) 41 + ), 42 + 43 + TP_fast_assign( 44 + __entry->gpio = gpio; 45 + __entry->get = get; 46 + __entry->value = value; 47 + ), 48 + 49 + TP_printk("%u %3s %d", __entry->gpio, 50 + __entry->get ? "get" : "set", __entry->value) 51 + ); 52 + 53 + #endif /* if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) */ 54 + 55 + /* This part must be outside protection */ 56 + #include <trace/define_trace.h>