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

MFD: ucb1x00-core: add wakeup support

Add genirq wakeup support for the ucb1x00 device. This allows an
attached gpio_keys driver to wakeup the system. Touchscreen is also
possible.

When there are no wakeup sources, ask the platform to assert the reset
signal to avoid any unexpected behaviour; this also puts the reset
signal at the right level when power is removed from the device.

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

+63
+59
drivers/mfd/ucb1x00-core.c
··· 362 362 return 0; 363 363 } 364 364 365 + static int ucb1x00_irq_set_wake(struct irq_data *data, unsigned int on) 366 + { 367 + struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); 368 + struct ucb1x00_plat_data *pdata = ucb->mcp->attached_device.platform_data; 369 + unsigned mask = 1 << (data->irq - ucb->irq_base); 370 + 371 + if (!pdata || !pdata->can_wakeup) 372 + return -EINVAL; 373 + 374 + raw_spin_lock(&ucb->irq_lock); 375 + if (on) 376 + ucb->irq_wake |= mask; 377 + else 378 + ucb->irq_wake &= ~mask; 379 + raw_spin_unlock(&ucb->irq_lock); 380 + 381 + return 0; 382 + } 383 + 365 384 static struct irq_chip ucb1x00_irqchip = { 366 385 .name = "ucb1x00", 367 386 .irq_ack = ucb1x00_irq_noop, 368 387 .irq_mask = ucb1x00_irq_mask, 369 388 .irq_unmask = ucb1x00_irq_unmask, 370 389 .irq_set_type = ucb1x00_irq_set_type, 390 + .irq_set_wake = ucb1x00_irq_set_wake, 371 391 }; 372 392 373 393 static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) ··· 585 565 586 566 mcp_set_drvdata(mcp, ucb); 587 567 568 + if (pdata) 569 + device_set_wakeup_capable(&ucb->dev, pdata->can_wakeup); 570 + 588 571 INIT_LIST_HEAD(&ucb->devs); 589 572 mutex_lock(&ucb1x00_mutex); 590 573 list_add_tail(&ucb->node, &ucb1x00_devices); ··· 671 648 672 649 static int ucb1x00_suspend(struct device *dev) 673 650 { 651 + struct ucb1x00_plat_data *pdata = dev->platform_data; 674 652 struct ucb1x00 *ucb = dev_get_drvdata(dev); 675 653 struct ucb1x00_dev *udev; 676 654 ··· 681 657 udev->drv->suspend(udev); 682 658 } 683 659 mutex_unlock(&ucb1x00_mutex); 660 + 661 + if (ucb->irq_wake) { 662 + unsigned long flags; 663 + 664 + raw_spin_lock_irqsave(&ucb->irq_lock, flags); 665 + ucb1x00_enable(ucb); 666 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 667 + ucb->irq_wake); 668 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 669 + ucb->irq_wake); 670 + ucb1x00_disable(ucb); 671 + raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); 672 + 673 + enable_irq_wake(ucb->irq); 674 + } else if (pdata && pdata->reset) 675 + pdata->reset(UCB_RST_SUSPEND); 676 + 684 677 return 0; 685 678 } 686 679 687 680 static int ucb1x00_resume(struct device *dev) 688 681 { 682 + struct ucb1x00_plat_data *pdata = dev->platform_data; 689 683 struct ucb1x00 *ucb = dev_get_drvdata(dev); 690 684 struct ucb1x00_dev *udev; 685 + 686 + if (!ucb->irq_wake && pdata && pdata->reset) 687 + pdata->reset(UCB_RST_RESUME); 691 688 692 689 ucb1x00_enable(ucb); 693 690 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); 694 691 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); 692 + 693 + if (ucb->irq_wake) { 694 + unsigned long flags; 695 + 696 + raw_spin_lock_irqsave(&ucb->irq_lock, flags); 697 + ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & 698 + ucb->irq_mask); 699 + ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & 700 + ucb->irq_mask); 701 + raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); 702 + 703 + disable_irq_wake(ucb->irq); 704 + } 695 705 ucb1x00_disable(ucb); 706 + 696 707 mutex_lock(&ucb1x00_mutex); 697 708 list_for_each_entry(udev, &ucb->devs, dev_node) { 698 709 if (udev->drv->resume)
+4
include/linux/mfd/ucb1x00.h
··· 106 106 107 107 enum ucb1x00_reset { 108 108 UCB_RST_PROBE, 109 + UCB_RST_RESUME, 110 + UCB_RST_SUSPEND, 109 111 UCB_RST_REMOVE, 110 112 UCB_RST_PROBE_FAIL, 111 113 }; ··· 116 114 void (*reset)(enum ucb1x00_reset); 117 115 unsigned irq_base; 118 116 int gpio_base; 117 + unsigned can_wakeup; 119 118 }; 120 119 121 120 struct ucb1x00 { ··· 133 130 u16 irq_fal_enbl; 134 131 u16 irq_ris_enbl; 135 132 u16 irq_mask; 133 + u16 irq_wake; 136 134 struct device dev; 137 135 struct list_head node; 138 136 struct list_head devs;