diff options
author | Felipe Balbi <felipe.balbi@nokia.com> | 2010-05-26 17:42:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-27 12:12:42 -0400 |
commit | 168ef3d9a56bd8bffe0ef4189c450888b4aefefe (patch) | |
tree | 13f3d29419be6a8853f7cce807658a42a3d2f22a /arch | |
parent | c4b5be98fe78508e7199d6919eb712feba9a4f01 (diff) |
arm: omap: gpio: implement set_debounce method
OMAP supports debouncing of gpio lines, implement the method using
gpiolib.
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/plat-omap/gpio.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c index dc2ac42d6319..1a65865fcfb6 100644 --- a/arch/arm/plat-omap/gpio.c +++ b/arch/arm/plat-omap/gpio.c | |||
@@ -624,6 +624,59 @@ do { \ | |||
624 | __raw_writel(l, base + reg); \ | 624 | __raw_writel(l, base + reg); \ |
625 | } while(0) | 625 | } while(0) |
626 | 626 | ||
627 | /** | ||
628 | * _set_gpio_debounce - low level gpio debounce time | ||
629 | * @bank: the gpio bank we're acting upon | ||
630 | * @gpio: the gpio number on this @gpio | ||
631 | * @debounce: debounce time to use | ||
632 | * | ||
633 | * OMAP's debounce time is in 31us steps so we need | ||
634 | * to convert and round up to the closest unit. | ||
635 | */ | ||
636 | static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, | ||
637 | unsigned debounce) | ||
638 | { | ||
639 | void __iomem *reg = bank->base; | ||
640 | u32 val; | ||
641 | u32 l; | ||
642 | |||
643 | if (debounce < 32) | ||
644 | debounce = 0x01; | ||
645 | else if (debounce > 7936) | ||
646 | debounce = 0xff; | ||
647 | else | ||
648 | debounce = (debounce / 0x1f) - 1; | ||
649 | |||
650 | l = 1 << get_gpio_index(gpio); | ||
651 | |||
652 | if (cpu_is_omap44xx()) | ||
653 | reg += OMAP4_GPIO_DEBOUNCINGTIME; | ||
654 | else | ||
655 | reg += OMAP24XX_GPIO_DEBOUNCE_VAL; | ||
656 | |||
657 | __raw_writel(debounce, reg); | ||
658 | |||
659 | reg = bank->base; | ||
660 | if (cpu_is_omap44xx()) | ||
661 | reg += OMAP4_GPIO_DEBOUNCENABLE; | ||
662 | else | ||
663 | reg += OMAP24XX_GPIO_DEBOUNCE_EN; | ||
664 | |||
665 | val = __raw_readl(reg); | ||
666 | |||
667 | if (debounce) { | ||
668 | val |= l; | ||
669 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) | ||
670 | clk_enable(bank->dbck); | ||
671 | } else { | ||
672 | val &= ~l; | ||
673 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) | ||
674 | clk_disable(bank->dbck); | ||
675 | } | ||
676 | |||
677 | __raw_writel(val, reg); | ||
678 | } | ||
679 | |||
627 | void omap_set_gpio_debounce(int gpio, int enable) | 680 | void omap_set_gpio_debounce(int gpio, int enable) |
628 | { | 681 | { |
629 | struct gpio_bank *bank; | 682 | struct gpio_bank *bank; |
@@ -1656,6 +1709,20 @@ static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) | |||
1656 | return 0; | 1709 | return 0; |
1657 | } | 1710 | } |
1658 | 1711 | ||
1712 | static int gpio_debounce(struct gpio_chip *chip, unsigned offset, | ||
1713 | unsigned debounce) | ||
1714 | { | ||
1715 | struct gpio_bank *bank; | ||
1716 | unsigned long flags; | ||
1717 | |||
1718 | bank = container_of(chip, struct gpio_bank, chip); | ||
1719 | spin_lock_irqsave(&bank->lock, flags); | ||
1720 | _set_gpio_debounce(bank, offset, debounce); | ||
1721 | spin_unlock_irqrestore(&bank->lock, flags); | ||
1722 | |||
1723 | return 0; | ||
1724 | } | ||
1725 | |||
1659 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 1726 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
1660 | { | 1727 | { |
1661 | struct gpio_bank *bank; | 1728 | struct gpio_bank *bank; |
@@ -1909,6 +1976,7 @@ static int __init _omap_gpio_init(void) | |||
1909 | bank->chip.direction_input = gpio_input; | 1976 | bank->chip.direction_input = gpio_input; |
1910 | bank->chip.get = gpio_get; | 1977 | bank->chip.get = gpio_get; |
1911 | bank->chip.direction_output = gpio_output; | 1978 | bank->chip.direction_output = gpio_output; |
1979 | bank->chip.set_debounce = gpio_debounce; | ||
1912 | bank->chip.set = gpio_set; | 1980 | bank->chip.set = gpio_set; |
1913 | bank->chip.to_irq = gpio_2irq; | 1981 | bank->chip.to_irq = gpio_2irq; |
1914 | if (bank_is_mpuio(bank)) { | 1982 | if (bank_is_mpuio(bank)) { |