Skip to content

Commit e85ec6c

Browse files
grygoriySlinusw
authored andcommitted
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>
1 parent 89d18e3 commit e85ec6c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

drivers/gpio/gpio-omap.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/platform_data/gpio-omap.h>
3030

3131
#define OFF_MODE 1
32+
#define OMAP4_GPIO_DEBOUNCINGTIME_MASK 0xFF
3233

3334
static LIST_HEAD(omap_gpio_list);
3435

@@ -204,25 +205,25 @@ static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
204205
* @offset: the gpio number on this @bank
205206
* @debounce: debounce time to use
206207
*
207-
* OMAP's debounce time is in 31us steps so we need
208-
* to convert and round up to the closest unit.
208+
* OMAP's debounce time is in 31us steps
209+
* <debounce time> = (GPIO_DEBOUNCINGTIME[7:0].DEBOUNCETIME + 1) x 31
210+
* so we need to convert and round up to the closest unit.
209211
*/
210212
static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
211213
unsigned debounce)
212214
{
213215
void __iomem *reg;
214216
u32 val;
215217
u32 l;
218+
bool enable = !!debounce;
216219

217220
if (!bank->dbck_flag)
218221
return;
219222

220-
if (debounce < 32)
221-
debounce = 0x01;
222-
else if (debounce > 7936)
223-
debounce = 0xff;
224-
else
225-
debounce = (debounce / 0x1f) - 1;
223+
if (enable) {
224+
debounce = DIV_ROUND_UP(debounce, 31) - 1;
225+
debounce &= OMAP4_GPIO_DEBOUNCINGTIME_MASK;
226+
}
226227

227228
l = BIT(offset);
228229

@@ -233,7 +234,7 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
233234
reg = bank->base + bank->regs->debounce_en;
234235
val = readl_relaxed(reg);
235236

236-
if (debounce)
237+
if (enable)
237238
val |= l;
238239
else
239240
val &= ~l;

0 commit comments

Comments
 (0)