From fa9879edebdaad4cfcd2dbe3eaa2ba0dc4f0a262 Mon Sep 17 00:00:00 2001 From: Vinod Koul Date: Wed, 9 Feb 2011 14:44:17 +0530 Subject: ASoC: add support for multiple jack types This patch adds soc-jack support for adding voltage zones and for detecting jack type Signed-off-by: Vinod Koul Signed-off-by: Harsha Priya Signed-off-by: Mark Brown --- sound/soc/soc-jack.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'sound/soc/soc-jack.c') diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index ac5a5bc7375a..99dbaf756b44 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -37,6 +37,7 @@ int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, { jack->codec = codec; INIT_LIST_HEAD(&jack->pins); + INIT_LIST_HEAD(&jack->jack_zones); BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); return snd_jack_new(codec->card->snd_card, id, type, &jack->jack); @@ -111,6 +112,51 @@ out: } EXPORT_SYMBOL_GPL(snd_soc_jack_report); +/** + * snd_soc_jack_add_zones - Associate voltage zones with jack + * + * @jack: ASoC jack + * @count: Number of zones + * @zone: Array of zones + * + * After this function has been called the zones specified in the + * array will be associated with the jack. + */ +int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count, + struct snd_soc_jack_zone *zones) +{ + int i; + + for (i = 0; i < count; i++) { + INIT_LIST_HEAD(&zones[i].list); + list_add(&(zones[i].list), &jack->jack_zones); + } + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_jack_add_zones); + +/** + * snd_soc_jack_get_type - Based on the mic bias value, this function returns + * the type of jack from the zones delcared in the jack type + * + * @micbias_voltage: mic bias voltage at adc channel when jack is plugged in + * + * Based on the mic bias value passed, this function helps identify + * the type of jack from the already delcared jack zones + */ +int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage) +{ + struct snd_soc_jack_zone *zone; + + list_for_each_entry(zone, &jack->jack_zones, list) { + if (micbias_voltage >= zone->min_mv && + micbias_voltage < zone->max_mv) + return zone->jack_type; + } + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_jack_get_type); + /** * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack * -- cgit v1.2.3 From 535787b6ae081171a5e7dbf0158ef9fa56d59dc8 Mon Sep 17 00:00:00 2001 From: Jarkko Nikula Date: Thu, 10 Feb 2011 17:22:23 +0200 Subject: ASoC: Allow use sleeping gpio in soc-jack It is safe to use sleeping gpio in snd_soc_jack_gpio_detect as it is not called from interrupt context. This avoids WARN_ON from __gpio_get_value if sleeping gpio is registered for jack. Signed-off-by: Jarkko Nikula Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- sound/soc/soc-jack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/soc-jack.c') diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 99dbaf756b44..4579ee090bbf 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -240,7 +240,7 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio) int enable; int report; - enable = gpio_get_value(gpio->gpio); + enable = gpio_get_value_cansleep(gpio->gpio); if (gpio->invert) enable = !enable; -- cgit v1.2.3 From 7887ab3a274dc5f1d1d94ca0cd41ae495d01f94f Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 17 Feb 2011 16:35:55 -0800 Subject: ASoC: Allow GPIO jack detection to be configured as a wake source Some systems wish to use jacks as wake sources. Provide a wake flag in the GPIO configuration which causes the driver to enable the IRQ as a wake source. Signed-off-by: Mark Brown Acked-by: Liam Girdwood --- include/sound/soc.h | 3 +++ sound/soc/soc-jack.c | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'sound/soc/soc-jack.c') diff --git a/include/sound/soc.h b/include/sound/soc.h index 4ccf1e4e0dd0..fb57c33482e5 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -436,6 +436,7 @@ struct snd_soc_jack_zone { * @report: value to report when jack detected * @invert: report presence in low state * @debouce_time: debouce time in ms + * @wake: enable as wake source */ #ifdef CONFIG_GPIOLIB struct snd_soc_jack_gpio { @@ -444,6 +445,8 @@ struct snd_soc_jack_gpio { int report; int invert; int debounce_time; + bool wake; + struct snd_soc_jack *jack; struct delayed_work work; diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 4579ee090bbf..1382251ed2a2 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -330,6 +330,14 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, if (ret) goto err; + if (gpios[i].wake) { + ret = set_irq_wake(gpio_to_irq(gpios[i].gpio), 1); + if (ret != 0) + printk(KERN_ERR + "Failed to mark GPIO %d as wake source: %d\n", + gpios[i].gpio, ret); + } + #ifdef CONFIG_GPIO_SYSFS /* Expose GPIO value over sysfs for diagnostic purposes */ gpio_export(gpios[i].gpio, false); -- cgit v1.2.3 From 1d2c27f94142e4ee9248dac1c93e001b707f3b74 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 22 Feb 2011 12:42:35 -0800 Subject: ASoC: Pass the jack to jack notifiers We're currently not passing anything and this will make the card and so on more discoverable. Signed-off-by: Mark Brown Acked-by: Liam Girdwood --- sound/soc/soc-jack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/soc-jack.c') diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index 1382251ed2a2..fcab80b36a37 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -101,7 +101,7 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) } /* Report before the DAPM sync to help users updating micbias status */ - blocking_notifier_call_chain(&jack->notifier, status, NULL); + blocking_notifier_call_chain(&jack->notifier, status, jack); snd_soc_dapm_sync(dapm); -- cgit v1.2.3