diff options
author | David Brownell <dbrownell@users.sourceforge.net> | 2009-01-06 17:42:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 18:59:25 -0500 |
commit | cabb3fc4bd1628c37c37e054960eb3e4bf30dc26 (patch) | |
tree | db8acce21cc4c9762da5f815779ec702f5a59c0c | |
parent | ba6c4033b9db22cb54e7e03dae5b624b7b0ffaf9 (diff) |
twl4030-gpio: cleanup debounce
Provide a static debounce configuration mechanism for twl4030 GPIOs,
replacing the previous dynamic one. The single user of that mechanism was
for MMC card detect debouncing.
Boards can provide a bitmask saying which GPIOs to debounce (30 msec).
It's always enabled for pins with the MMC card-detect/VMMCx link active,
so most boards won't need to set the debounce mask.
This is a net code shrink, including runtime footprint.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/gpio/twl4030-gpio.c | 54 | ||||
-rw-r--r-- | include/linux/i2c/twl4030.h | 9 |
2 files changed, 26 insertions, 37 deletions
diff --git a/drivers/gpio/twl4030-gpio.c b/drivers/gpio/twl4030-gpio.c index 37d3eec8730a..afad14792141 100644 --- a/drivers/gpio/twl4030-gpio.c +++ b/drivers/gpio/twl4030-gpio.c | |||
@@ -202,37 +202,6 @@ static int twl4030_get_gpio_datain(int gpio) | |||
202 | return ret; | 202 | return ret; |
203 | } | 203 | } |
204 | 204 | ||
205 | /* | ||
206 | * Configure debounce timing value for a GPIO pin on TWL4030 | ||
207 | */ | ||
208 | int twl4030_set_gpio_debounce(int gpio, int enable) | ||
209 | { | ||
210 | u8 d_bnk = gpio >> 3; | ||
211 | u8 d_msk = BIT(gpio & 0x7); | ||
212 | u8 reg = 0; | ||
213 | u8 base = 0; | ||
214 | int ret = 0; | ||
215 | |||
216 | if (unlikely((gpio >= TWL4030_GPIO_MAX) | ||
217 | || !(gpio_usage_count & BIT(gpio)))) | ||
218 | return -EPERM; | ||
219 | |||
220 | base = REG_GPIO_DEBEN1 + d_bnk; | ||
221 | mutex_lock(&gpio_lock); | ||
222 | ret = gpio_twl4030_read(base); | ||
223 | if (ret >= 0) { | ||
224 | if (enable) | ||
225 | reg = ret | d_msk; | ||
226 | else | ||
227 | reg = ret & ~d_msk; | ||
228 | |||
229 | ret = gpio_twl4030_write(base, reg); | ||
230 | } | ||
231 | mutex_unlock(&gpio_lock); | ||
232 | return ret; | ||
233 | } | ||
234 | EXPORT_SYMBOL(twl4030_set_gpio_debounce); | ||
235 | |||
236 | /*----------------------------------------------------------------------*/ | 205 | /*----------------------------------------------------------------------*/ |
237 | 206 | ||
238 | static int twl_request(struct gpio_chip *chip, unsigned offset) | 207 | static int twl_request(struct gpio_chip *chip, unsigned offset) |
@@ -405,6 +374,23 @@ static int __devinit gpio_twl4030_pulls(u32 ups, u32 downs) | |||
405 | REG_GPIOPUPDCTR1, 5); | 374 | REG_GPIOPUPDCTR1, 5); |
406 | } | 375 | } |
407 | 376 | ||
377 | static int __devinit gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) | ||
378 | { | ||
379 | u8 message[4]; | ||
380 | |||
381 | /* 30 msec of debouncing is always used for MMC card detect, | ||
382 | * and is optional for everything else. | ||
383 | */ | ||
384 | message[1] = (debounce & 0xff) | (mmc_cd & 0x03); | ||
385 | debounce >>= 8; | ||
386 | message[2] = (debounce & 0xff); | ||
387 | debounce >>= 8; | ||
388 | message[3] = (debounce & 0x03); | ||
389 | |||
390 | return twl4030_i2c_write(TWL4030_MODULE_GPIO, message, | ||
391 | REG_GPIO_DEBEN1, 3); | ||
392 | } | ||
393 | |||
408 | static int gpio_twl4030_remove(struct platform_device *pdev); | 394 | static int gpio_twl4030_remove(struct platform_device *pdev); |
409 | 395 | ||
410 | static int __devinit gpio_twl4030_probe(struct platform_device *pdev) | 396 | static int __devinit gpio_twl4030_probe(struct platform_device *pdev) |
@@ -439,6 +425,12 @@ no_irqs: | |||
439 | pdata->pullups, pdata->pulldowns, | 425 | pdata->pullups, pdata->pulldowns, |
440 | ret); | 426 | ret); |
441 | 427 | ||
428 | ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd); | ||
429 | if (ret) | ||
430 | dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n", | ||
431 | pdata->debounce, pdata->mmc_cd, | ||
432 | ret); | ||
433 | |||
442 | twl_gpiochip.base = pdata->gpio_base; | 434 | twl_gpiochip.base = pdata->gpio_base; |
443 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; | 435 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; |
444 | twl_gpiochip.dev = &pdev->dev; | 436 | twl_gpiochip.dev = &pdev->dev; |
diff --git a/include/linux/i2c/twl4030.h b/include/linux/i2c/twl4030.h index a8f84c01f82e..8137f660a5cc 100644 --- a/include/linux/i2c/twl4030.h +++ b/include/linux/i2c/twl4030.h | |||
@@ -234,6 +234,9 @@ struct twl4030_gpio_platform_data { | |||
234 | /* gpio-n should control VMMC(n+1) if BIT(n) in mmc_cd is set */ | 234 | /* gpio-n should control VMMC(n+1) if BIT(n) in mmc_cd is set */ |
235 | u8 mmc_cd; | 235 | u8 mmc_cd; |
236 | 236 | ||
237 | /* if BIT(N) is set, or VMMC(n+1) is linked, debounce GPIO-N */ | ||
238 | u32 debounce; | ||
239 | |||
237 | /* For gpio-N, bit (1 << N) in "pullups" is set if that pullup | 240 | /* For gpio-N, bit (1 << N) in "pullups" is set if that pullup |
238 | * should be enabled. Else, if that bit is set in "pulldowns", | 241 | * should be enabled. Else, if that bit is set in "pulldowns", |
239 | * that pulldown is enabled. Don't waste power by letting any | 242 | * that pulldown is enabled. Don't waste power by letting any |
@@ -307,12 +310,6 @@ int twl4030_sih_setup(int module); | |||
307 | #define TWL4030_VAUX3_DEV_GRP 0x1F | 310 | #define TWL4030_VAUX3_DEV_GRP 0x1F |
308 | #define TWL4030_VAUX3_DEDICATED 0x22 | 311 | #define TWL4030_VAUX3_DEDICATED 0x22 |
309 | 312 | ||
310 | /* | ||
311 | * Exported TWL4030 GPIO APIs | ||
312 | * | ||
313 | * WARNING -- use standard GPIO and IRQ calls instead; these will vanish. | ||
314 | */ | ||
315 | int twl4030_set_gpio_debounce(int gpio, int enable); | ||
316 | 313 | ||
317 | #if defined(CONFIG_TWL4030_BCI_BATTERY) || \ | 314 | #if defined(CONFIG_TWL4030_BCI_BATTERY) || \ |
318 | defined(CONFIG_TWL4030_BCI_BATTERY_MODULE) | 315 | defined(CONFIG_TWL4030_BCI_BATTERY_MODULE) |