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

MFD: ucb1x00: convert to use genirq

Convert the ucb1x00 driver to use genirq's interrupt services, rather
than its own private implementation. This allows a wider range of
drivers to use the GPIO interrupts (such as the gpio_keys driver)
without being aware of the UCB1x00's private IRQ system.

This prevents the UCB1x00 core driver from being built as a module,
so adjust the configuration to add that restriction.

Acked-by: Jochen Friedrich <jochen@scram.de>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

+137 -184
+3 -2
drivers/mfd/Kconfig
··· 847 847 848 848 # Chip drivers 849 849 config MCP_UCB1200 850 - tristate "Support for UCB1200 / UCB1300" 851 - depends on MCP 850 + bool "Support for UCB1200 / UCB1300" 851 + depends on MCP_SA11X0 852 + select MCP 852 853 853 854 config MCP_UCB1200_TS 854 855 tristate "Touchscreen interface support"
+100 -157
drivers/mfd/ucb1x00-core.c
··· 23 23 #include <linux/init.h> 24 24 #include <linux/errno.h> 25 25 #include <linux/interrupt.h> 26 + #include <linux/irq.h> 26 27 #include <linux/device.h> 27 28 #include <linux/mutex.h> 28 29 #include <linux/mfd/ucb1x00.h> ··· 179 178 return 0; 180 179 } 181 180 181 + static int ucb1x00_to_irq(struct gpio_chip *chip, unsigned offset) 182 + { 183 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio); 184 + 185 + return ucb->irq_base > 0 ? ucb->irq_base + offset : -ENXIO; 186 + } 187 + 182 188 /* 183 189 * UCB1300 data sheet says we must: 184 190 * 1. enable ADC => 5us (including reference startup time) ··· 282 274 * SIBCLK to talk to the chip. We leave the clock running until 283 275 * we have finished processing all interrupts from the chip. 284 276 */ 285 - static irqreturn_t ucb1x00_irq(int irqnr, void *devid) 277 + static void ucb1x00_irq(unsigned int irq, struct irq_desc *desc) 286 278 { 287 - struct ucb1x00 *ucb = devid; 288 - struct ucb1x00_irq *irq; 279 + struct ucb1x00 *ucb = irq_desc_get_handler_data(desc); 289 280 unsigned int isr, i; 290 281 291 282 ucb1x00_enable(ucb); ··· 292 285 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, isr); 293 286 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0); 294 287 295 - for (i = 0, irq = ucb->irq_handler; i < 16 && isr; i++, isr >>= 1, irq++) 296 - if (isr & 1 && irq->fn) 297 - irq->fn(i, irq->devid); 288 + for (i = 0; i < 16 && isr; i++, isr >>= 1, irq++) 289 + if (isr & 1) 290 + generic_handle_irq(ucb->irq_base + i); 298 291 ucb1x00_disable(ucb); 299 - 300 - return IRQ_HANDLED; 301 292 } 302 293 303 - /** 304 - * ucb1x00_hook_irq - hook a UCB1x00 interrupt 305 - * @ucb: UCB1x00 structure describing chip 306 - * @idx: interrupt index 307 - * @fn: function to call when interrupt is triggered 308 - * @devid: device id to pass to interrupt handler 309 - * 310 - * Hook the specified interrupt. You can only register one handler 311 - * for each interrupt source. The interrupt source is not enabled 312 - * by this function; use ucb1x00_enable_irq instead. 313 - * 314 - * Interrupt handlers will be called with other interrupts enabled. 315 - * 316 - * Returns zero on success, or one of the following errors: 317 - * -EINVAL if the interrupt index is invalid 318 - * -EBUSY if the interrupt has already been hooked 319 - */ 320 - int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid) 294 + static void ucb1x00_irq_update(struct ucb1x00 *ucb, unsigned mask) 321 295 { 322 - struct ucb1x00_irq *irq; 323 - int ret = -EINVAL; 324 - 325 - if (idx < 16) { 326 - irq = ucb->irq_handler + idx; 327 - ret = -EBUSY; 328 - 329 - spin_lock_irq(&ucb->lock); 330 - if (irq->fn == NULL) { 331 - irq->devid = devid; 332 - irq->fn = fn; 333 - ret = 0; 334 - } 335 - spin_unlock_irq(&ucb->lock); 336 - } 337 - return ret; 296 + ucb1x00_enable(ucb); 297 + if (ucb->irq_ris_enbl & mask) 298 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 299 + ucb->irq_mask); 300 + if (ucb->irq_fal_enbl & mask) 301 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 302 + ucb->irq_mask); 303 + ucb1x00_disable(ucb); 338 304 } 339 305 340 - /** 341 - * ucb1x00_enable_irq - enable an UCB1x00 interrupt source 342 - * @ucb: UCB1x00 structure describing chip 343 - * @idx: interrupt index 344 - * @edges: interrupt edges to enable 345 - * 346 - * Enable the specified interrupt to trigger on %UCB_RISING, 347 - * %UCB_FALLING or both edges. The interrupt should have been 348 - * hooked by ucb1x00_hook_irq. 349 - */ 350 - void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges) 306 + static void ucb1x00_irq_noop(struct irq_data *data) 351 307 { 352 - unsigned long flags; 353 - 354 - if (idx < 16) { 355 - spin_lock_irqsave(&ucb->lock, flags); 356 - 357 - ucb1x00_enable(ucb); 358 - if (edges & UCB_RISING) { 359 - ucb->irq_ris_enbl |= 1 << idx; 360 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 361 - } 362 - if (edges & UCB_FALLING) { 363 - ucb->irq_fal_enbl |= 1 << idx; 364 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 365 - } 366 - ucb1x00_disable(ucb); 367 - spin_unlock_irqrestore(&ucb->lock, flags); 368 - } 369 308 } 370 309 371 - /** 372 - * ucb1x00_disable_irq - disable an UCB1x00 interrupt source 373 - * @ucb: UCB1x00 structure describing chip 374 - * @edges: interrupt edges to disable 375 - * 376 - * Disable the specified interrupt triggering on the specified 377 - * (%UCB_RISING, %UCB_FALLING or both) edges. 378 - */ 379 - void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges) 310 + static void ucb1x00_irq_mask(struct irq_data *data) 380 311 { 381 - unsigned long flags; 312 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 313 + unsigned mask = 1 << (data->irq - ucb->irq_base); 382 314 383 - if (idx < 16) { 384 - spin_lock_irqsave(&ucb->lock, flags); 385 - 386 - ucb1x00_enable(ucb); 387 - if (edges & UCB_RISING) { 388 - ucb->irq_ris_enbl &= ~(1 << idx); 389 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 390 - } 391 - if (edges & UCB_FALLING) { 392 - ucb->irq_fal_enbl &= ~(1 << idx); 393 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 394 - } 395 - ucb1x00_disable(ucb); 396 - spin_unlock_irqrestore(&ucb->lock, flags); 397 - } 315 + raw_spin_lock(&ucb->irq_lock); 316 + ucb->irq_mask &= ~mask; 317 + ucb1x00_irq_update(ucb, mask); 318 + raw_spin_unlock(&ucb->irq_lock); 398 319 } 399 320 400 - /** 401 - * ucb1x00_free_irq - disable and free the specified UCB1x00 interrupt 402 - * @ucb: UCB1x00 structure describing chip 403 - * @idx: interrupt index 404 - * @devid: device id. 405 - * 406 - * Disable the interrupt source and remove the handler. devid must 407 - * match the devid passed when hooking the interrupt. 408 - * 409 - * Returns zero on success, or one of the following errors: 410 - * -EINVAL if the interrupt index is invalid 411 - * -ENOENT if devid does not match 412 - */ 413 - int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid) 321 + static void ucb1x00_irq_unmask(struct irq_data *data) 414 322 { 415 - struct ucb1x00_irq *irq; 416 - int ret; 323 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 324 + unsigned mask = 1 << (data->irq - ucb->irq_base); 417 325 418 - if (idx >= 16) 419 - goto bad; 420 - 421 - irq = ucb->irq_handler + idx; 422 - ret = -ENOENT; 423 - 424 - spin_lock_irq(&ucb->lock); 425 - if (irq->devid == devid) { 426 - ucb->irq_ris_enbl &= ~(1 << idx); 427 - ucb->irq_fal_enbl &= ~(1 << idx); 428 - 429 - ucb1x00_enable(ucb); 430 - ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl); 431 - ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl); 432 - ucb1x00_disable(ucb); 433 - 434 - irq->fn = NULL; 435 - irq->devid = NULL; 436 - ret = 0; 437 - } 438 - spin_unlock_irq(&ucb->lock); 439 - return ret; 440 - 441 - bad: 442 - printk(KERN_ERR "Freeing bad UCB1x00 irq %d\n", idx); 443 - return -EINVAL; 326 + raw_spin_lock(&ucb->irq_lock); 327 + ucb->irq_mask |= mask; 328 + ucb1x00_irq_update(ucb, mask); 329 + raw_spin_unlock(&ucb->irq_lock); 444 330 } 331 + 332 + static int ucb1x00_irq_set_type(struct irq_data *data, unsigned int type) 333 + { 334 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 335 + unsigned mask = 1 << (data->irq - ucb->irq_base); 336 + 337 + raw_spin_lock(&ucb->irq_lock); 338 + if (type & IRQ_TYPE_EDGE_RISING) 339 + ucb->irq_ris_enbl |= mask; 340 + else 341 + ucb->irq_ris_enbl &= ~mask; 342 + 343 + if (type & IRQ_TYPE_EDGE_FALLING) 344 + ucb->irq_fal_enbl |= mask; 345 + else 346 + ucb->irq_fal_enbl &= ~mask; 347 + if (ucb->irq_mask & mask) { 348 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 349 + ucb->irq_mask); 350 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 351 + ucb->irq_mask); 352 + } 353 + raw_spin_unlock(&ucb->irq_lock); 354 + 355 + return 0; 356 + } 357 + 358 + static struct irq_chip ucb1x00_irqchip = { 359 + .name = "ucb1x00", 360 + .irq_ack = ucb1x00_irq_noop, 361 + .irq_mask = ucb1x00_irq_mask, 362 + .irq_unmask = ucb1x00_irq_unmask, 363 + .irq_set_type = ucb1x00_irq_set_type, 364 + }; 445 365 446 366 static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) 447 367 { ··· 479 545 struct ucb1x00_plat_data *pdata = mcp->attached_device.platform_data; 480 546 struct ucb1x00_driver *drv; 481 547 struct ucb1x00 *ucb; 482 - unsigned int id; 548 + unsigned id, i, irq_base; 483 549 int ret = -ENODEV; 484 - int temp; 485 550 486 551 /* Tell the platform to deassert the UCB1x00 reset */ 487 552 if (pdata && pdata->reset) ··· 505 572 ucb->dev.parent = &mcp->attached_device; 506 573 dev_set_name(&ucb->dev, "ucb1x00"); 507 574 508 - spin_lock_init(&ucb->lock); 575 + raw_spin_lock_init(&ucb->irq_lock); 509 576 spin_lock_init(&ucb->io_lock); 510 577 mutex_init(&ucb->adc_mutex); 511 578 ··· 526 593 } 527 594 528 595 ucb->gpio.base = -1; 596 + irq_base = pdata ? pdata->irq_base : 0; 597 + ucb->irq_base = irq_alloc_descs(-1, irq_base, 16, -1); 598 + if (ucb->irq_base < 0) { 599 + dev_err(&ucb->dev, "unable to allocate 16 irqs: %d\n", 600 + ucb->irq_base); 601 + goto err_irq_alloc; 602 + } 603 + 604 + for (i = 0; i < 16; i++) { 605 + unsigned irq = ucb->irq_base + i; 606 + 607 + irq_set_chip_and_handler(irq, &ucb1x00_irqchip, handle_edge_irq); 608 + irq_set_chip_data(irq, ucb); 609 + set_irq_flags(irq, IRQF_VALID | IRQ_NOREQUEST); 610 + } 611 + 612 + irq_set_irq_type(ucb->irq, IRQ_TYPE_EDGE_RISING); 613 + irq_set_handler_data(ucb->irq, ucb); 614 + irq_set_chained_handler(ucb->irq, ucb1x00_irq); 615 + 529 616 if (pdata && pdata->gpio_base) { 530 617 ucb->gpio.label = dev_name(&ucb->dev); 531 618 ucb->gpio.dev = &ucb->dev; ··· 556 603 ucb->gpio.get = ucb1x00_gpio_get; 557 604 ucb->gpio.direction_input = ucb1x00_gpio_direction_input; 558 605 ucb->gpio.direction_output = ucb1x00_gpio_direction_output; 606 + ucb->gpio.to_irq = ucb1x00_to_irq; 559 607 ret = gpiochip_add(&ucb->gpio); 560 608 if (ret) 561 609 goto err_gpio_add; 562 610 } else 563 611 dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); 564 - 565 - ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING, 566 - "UCB1x00", ucb); 567 - if (ret) { 568 - dev_err(&ucb->dev, "ucb1x00: unable to grab irq%d: %d\n", 569 - ucb->irq, ret); 570 - goto err_irq; 571 - } 572 612 573 613 mcp_set_drvdata(mcp, ucb); 574 614 ··· 575 629 576 630 return ret; 577 631 578 - err_irq: 579 - if (ucb->gpio.base != -1) 580 - temp = gpiochip_remove(&ucb->gpio); 581 632 err_gpio_add: 633 + irq_set_chained_handler(ucb->irq, NULL); 634 + err_irq_alloc: 635 + if (ucb->irq_base > 0) 636 + irq_free_descs(ucb->irq_base, 16); 582 637 err_no_irq: 583 638 device_del(&ucb->dev); 584 639 err_dev_add: ··· 611 664 dev_err(&ucb->dev, "Can't remove gpio chip: %d\n", ret); 612 665 } 613 666 614 - free_irq(ucb->irq, ucb); 667 + irq_set_chained_handler(ucb->irq, NULL); 668 + irq_free_descs(ucb->irq_base, 16); 615 669 device_unregister(&ucb->dev); 616 670 617 671 if (pdata && pdata->reset) ··· 719 771 EXPORT_SYMBOL(ucb1x00_adc_enable); 720 772 EXPORT_SYMBOL(ucb1x00_adc_read); 721 773 EXPORT_SYMBOL(ucb1x00_adc_disable); 722 - 723 - EXPORT_SYMBOL(ucb1x00_hook_irq); 724 - EXPORT_SYMBOL(ucb1x00_free_irq); 725 - EXPORT_SYMBOL(ucb1x00_enable_irq); 726 - EXPORT_SYMBOL(ucb1x00_disable_irq); 727 774 728 775 EXPORT_SYMBOL(ucb1x00_register_driver); 729 776 EXPORT_SYMBOL(ucb1x00_unregister_driver);
+30 -7
drivers/mfd/ucb1x00-ts.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/moduleparam.h> 22 22 #include <linux/init.h> 23 - #include <linux/smp.h> 23 + #include <linux/interrupt.h> 24 24 #include <linux/sched.h> 25 + #include <linux/spinlock.h> 25 26 #include <linux/completion.h> 26 27 #include <linux/delay.h> 27 28 #include <linux/string.h> ··· 42 41 struct input_dev *idev; 43 42 struct ucb1x00 *ucb; 44 43 44 + spinlock_t irq_lock; 45 + unsigned irq_disabled; 45 46 wait_queue_head_t irq_wait; 46 47 struct task_struct *rtask; 47 48 u16 x_res; ··· 240 237 if (ucb1x00_ts_pen_down(ts)) { 241 238 set_current_state(TASK_INTERRUPTIBLE); 242 239 243 - ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, machine_is_collie() ? UCB_RISING : UCB_FALLING); 240 + spin_lock_irq(&ts->irq_lock); 241 + if (ts->irq_disabled) { 242 + ts->irq_disabled = 0; 243 + enable_irq(ts->ucb->irq_base + UCB_IRQ_TSPX); 244 + } 245 + spin_unlock_irq(&ts->irq_lock); 244 246 ucb1x00_disable(ts->ucb); 245 247 246 248 /* ··· 288 280 * We only detect touch screen _touches_ with this interrupt 289 281 * handler, and even then we just schedule our task. 290 282 */ 291 - static void ucb1x00_ts_irq(int idx, void *id) 283 + static irqreturn_t ucb1x00_ts_irq(int irq, void *id) 292 284 { 293 285 struct ucb1x00_ts *ts = id; 294 286 295 - ucb1x00_disable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING); 287 + spin_lock(&ts->irq_lock); 288 + ts->irq_disabled = 1; 289 + disable_irq_nosync(ts->ucb->irq_base + UCB_IRQ_TSPX); 290 + spin_unlock(&ts->irq_lock); 296 291 wake_up(&ts->irq_wait); 292 + 293 + return IRQ_HANDLED; 297 294 } 298 295 299 296 static int ucb1x00_ts_open(struct input_dev *idev) 300 297 { 301 298 struct ucb1x00_ts *ts = input_get_drvdata(idev); 299 + unsigned long flags = 0; 302 300 int ret = 0; 303 301 304 302 BUG_ON(ts->rtask); 305 303 304 + if (machine_is_collie()) 305 + flags = IRQF_TRIGGER_RISING; 306 + else 307 + flags = IRQF_TRIGGER_FALLING; 308 + 309 + ts->irq_disabled = 0; 310 + 306 311 init_waitqueue_head(&ts->irq_wait); 307 - ret = ucb1x00_hook_irq(ts->ucb, UCB_IRQ_TSPX, ucb1x00_ts_irq, ts); 312 + ret = request_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ucb1x00_ts_irq, 313 + flags, "ucb1x00-ts", ts); 308 314 if (ret < 0) 309 315 goto out; 310 316 ··· 335 313 if (!IS_ERR(ts->rtask)) { 336 314 ret = 0; 337 315 } else { 338 - ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts); 316 + free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); 339 317 ts->rtask = NULL; 340 318 ret = -EFAULT; 341 319 } ··· 355 333 kthread_stop(ts->rtask); 356 334 357 335 ucb1x00_enable(ts->ucb); 358 - ucb1x00_free_irq(ts->ucb, UCB_IRQ_TSPX, ts); 336 + free_irq(ts->ucb->irq_base + UCB_IRQ_TSPX, ts); 359 337 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 0); 360 338 ucb1x00_disable(ts->ucb); 361 339 } ··· 380 358 ts->ucb = dev->ucb; 381 359 ts->idev = idev; 382 360 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; 361 + spin_lock_init(&ts->irq_lock); 383 362 384 363 idev->name = "Touchscreen panel"; 385 364 idev->id.product = ts->ucb->id;
+4 -18
include/linux/mfd/ucb1x00.h
··· 112 112 113 113 struct ucb1x00_plat_data { 114 114 void (*reset)(enum ucb1x00_reset); 115 + unsigned irq_base; 115 116 int gpio_base; 116 117 }; 117 118 118 - struct ucb1x00_irq { 119 - void *devid; 120 - void (*fn)(int, void *); 121 - }; 122 - 123 119 struct ucb1x00 { 124 - spinlock_t lock; 120 + raw_spinlock_t irq_lock; 125 121 struct mcp *mcp; 126 122 unsigned int irq; 123 + int irq_base; 127 124 struct mutex adc_mutex; 128 125 spinlock_t io_lock; 129 126 u16 id; ··· 129 132 u16 adc_cr; 130 133 u16 irq_fal_enbl; 131 134 u16 irq_ris_enbl; 132 - struct ucb1x00_irq irq_handler[16]; 135 + u16 irq_mask; 133 136 struct device dev; 134 137 struct list_head node; 135 138 struct list_head devs; ··· 251 254 unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync); 252 255 void ucb1x00_adc_enable(struct ucb1x00 *ucb); 253 256 void ucb1x00_adc_disable(struct ucb1x00 *ucb); 254 - 255 - /* 256 - * Which edges of the IRQ do you want to control today? 257 - */ 258 - #define UCB_RISING (1 << 0) 259 - #define UCB_FALLING (1 << 1) 260 - 261 - int ucb1x00_hook_irq(struct ucb1x00 *ucb, unsigned int idx, void (*fn)(int, void *), void *devid); 262 - void ucb1x00_enable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges); 263 - void ucb1x00_disable_irq(struct ucb1x00 *ucb, unsigned int idx, int edges); 264 - int ucb1x00_free_irq(struct ucb1x00 *ucb, unsigned int idx, void *devid); 265 257 266 258 #endif