]> asedeno.scripts.mit.edu Git - linux.git/commit
gpio: omap: fix omap2_set_gpio_debounce
authorGrygorii Strashko <grygorii.strashko@ti.com>
Tue, 18 Aug 2015 11:10:54 +0000 (14:10 +0300)
committerLinus Walleij <linus.walleij@linaro.org>
Wed, 26 Aug 2015 07:52:48 +0000 (09:52 +0200)
commite85ec6c3047be0646e7c572e24869c212b685c7c
treef74fd0cd279dd53693dc6e77010bb40109037a64
parent89d18e3af8b99481589e07f92fd966ceb86eff5d
gpio: omap: fix omap2_set_gpio_debounce

According to TRMs:

Required input line stable =
  (the value of the GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) Ã— 31,
where the value of the GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME bit field
is from 0 to 255.

But now omap2_set_gpio_debounce() will calculate debounce time and
behave incorrectly in the following cases:
1) requested debounce time is !0 and <32
   calculated DEBOUNCETIME = 0x1 == 62 us;
   expected value of DEBOUNCETIME = 0x0 == 31us
2) requested debounce time is 0
   calculated DEBOUNCETIME = 0x1 == 62 us;
   expected: disable debounce and DEBOUNCETIME = 0x0
3) requested debounce time is >32 and <63
   calculated DEBOUNCETIME = 0x0 and debounce will be disabled;
   expected: enable debounce and DEBOUNCETIME = 0x1 == 62 us

Hence, rework omap2_set_gpio_debounce() to fix above cases:
1) introduce local variable "enable" and use it to identify
when debounce need to be enabled or disabled. Disable debounce
if requested debounce time is 0.
2) use below formula for debounce time calculation:
   debounce = (DIV_ROUND_UP(debounce, 31) - 1) & 0xFF;

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Acked-by: Santosh Shilimkar <ssantosh@kernel.org>
Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-omap.c