ASoC: Use delayed work for debounce of GPIO based jacks

Rather than block the workqueue by sleeping to do the debounce use delayed
work to implement the debounce time. This should also means that we extend
the debounce time on each new bounce, potentially allowing shorter debounce
times for clean insertions.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
Mark Brown 2010-10-06 15:54:28 -07:00
parent de535a5be5
commit 4c14d78e8a
2 changed files with 6 additions and 7 deletions

View File

@ -385,7 +385,7 @@ struct snd_soc_jack_gpio {
int invert; int invert;
int debounce_time; int debounce_time;
struct snd_soc_jack *jack; struct snd_soc_jack *jack;
struct work_struct work; struct delayed_work work;
int (*jack_status_check)(void); int (*jack_status_check)(void);
}; };

View File

@ -188,9 +188,6 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
int enable; int enable;
int report; int report;
if (gpio->debounce_time > 0)
mdelay(gpio->debounce_time);
enable = gpio_get_value(gpio->gpio); enable = gpio_get_value(gpio->gpio);
if (gpio->invert) if (gpio->invert)
enable = !enable; enable = !enable;
@ -211,7 +208,8 @@ static irqreturn_t gpio_handler(int irq, void *data)
{ {
struct snd_soc_jack_gpio *gpio = data; struct snd_soc_jack_gpio *gpio = data;
schedule_work(&gpio->work); schedule_delayed_work(&gpio->work,
msecs_to_jiffies(gpio->debounce_time));
return IRQ_HANDLED; return IRQ_HANDLED;
} }
@ -221,7 +219,7 @@ static void gpio_work(struct work_struct *work)
{ {
struct snd_soc_jack_gpio *gpio; struct snd_soc_jack_gpio *gpio;
gpio = container_of(work, struct snd_soc_jack_gpio, work); gpio = container_of(work, struct snd_soc_jack_gpio, work.work);
snd_soc_jack_gpio_detect(gpio); snd_soc_jack_gpio_detect(gpio);
} }
@ -262,7 +260,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
if (ret) if (ret)
goto err; goto err;
INIT_WORK(&gpios[i].work, gpio_work); INIT_DELAYED_WORK(&gpios[i].work, gpio_work);
gpios[i].jack = jack; gpios[i].jack = jack;
ret = request_irq(gpio_to_irq(gpios[i].gpio), ret = request_irq(gpio_to_irq(gpios[i].gpio),
@ -312,6 +310,7 @@ void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
gpio_unexport(gpios[i].gpio); gpio_unexport(gpios[i].gpio);
#endif #endif
free_irq(gpio_to_irq(gpios[i].gpio), &gpios[i]); free_irq(gpio_to_irq(gpios[i].gpio), &gpios[i]);
cancel_delayed_work_sync(&gpios[i].work);
gpio_free(gpios[i].gpio); gpio_free(gpios[i].gpio);
gpios[i].jack = NULL; gpios[i].jack = NULL;
} }