aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinod Koul <vinod.koul@intel.com>2011-02-09 04:14:17 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-02-09 18:02:43 -0500
commitfa9879edebdaad4cfcd2dbe3eaa2ba0dc4f0a262 (patch)
tree47032fd4e879f7390999b180f0557261647742f8
parent866fd9366a5b2c7d17eb10f7e7b1c17393ed0beb (diff)
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 <vinod.koul@intel.com> Signed-off-by: Harsha Priya <priya.harsha@intel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--include/sound/soc.h23
-rw-r--r--sound/soc/soc-jack.c46
2 files changed, 69 insertions, 0 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 4b6c0a8c332f..4ccf1e4e0dd0 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -234,6 +234,7 @@ struct snd_soc_codec;
234struct snd_soc_codec_driver; 234struct snd_soc_codec_driver;
235struct soc_enum; 235struct soc_enum;
236struct snd_soc_jack; 236struct snd_soc_jack;
237struct snd_soc_jack_zone;
237struct snd_soc_jack_pin; 238struct snd_soc_jack_pin;
238struct snd_soc_cache_ops; 239struct snd_soc_cache_ops;
239#include <sound/soc-dapm.h> 240#include <sound/soc-dapm.h>
@@ -307,6 +308,9 @@ void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
307 struct notifier_block *nb); 308 struct notifier_block *nb);
308void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack, 309void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
309 struct notifier_block *nb); 310 struct notifier_block *nb);
311int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
312 struct snd_soc_jack_zone *zones);
313int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
310#ifdef CONFIG_GPIOLIB 314#ifdef CONFIG_GPIOLIB
311int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, 315int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
312 struct snd_soc_jack_gpio *gpios); 316 struct snd_soc_jack_gpio *gpios);
@@ -407,6 +411,24 @@ struct snd_soc_jack_pin {
407}; 411};
408 412
409/** 413/**
414 * struct snd_soc_jack_zone - Describes voltage zones of jack detection
415 *
416 * @min_mv: start voltage in mv
417 * @max_mv: end voltage in mv
418 * @jack_type: type of jack that is expected for this voltage
419 * @debounce_time: debounce_time for jack, codec driver should wait for this
420 * duration before reading the adc for voltages
421 * @:list: list container
422 */
423struct snd_soc_jack_zone {
424 unsigned int min_mv;
425 unsigned int max_mv;
426 unsigned int jack_type;
427 unsigned int debounce_time;
428 struct list_head list;
429};
430
431/**
410 * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection 432 * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
411 * 433 *
412 * @gpio: gpio number 434 * @gpio: gpio number
@@ -435,6 +457,7 @@ struct snd_soc_jack {
435 struct list_head pins; 457 struct list_head pins;
436 int status; 458 int status;
437 struct blocking_notifier_head notifier; 459 struct blocking_notifier_head notifier;
460 struct list_head jack_zones;
438}; 461};
439 462
440/* SoC PCM stream information */ 463/* SoC PCM stream information */
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,
37{ 37{
38 jack->codec = codec; 38 jack->codec = codec;
39 INIT_LIST_HEAD(&jack->pins); 39 INIT_LIST_HEAD(&jack->pins);
40 INIT_LIST_HEAD(&jack->jack_zones);
40 BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); 41 BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
41 42
42 return snd_jack_new(codec->card->snd_card, id, type, &jack->jack); 43 return snd_jack_new(codec->card->snd_card, id, type, &jack->jack);
@@ -112,6 +113,51 @@ out:
112EXPORT_SYMBOL_GPL(snd_soc_jack_report); 113EXPORT_SYMBOL_GPL(snd_soc_jack_report);
113 114
114/** 115/**
116 * snd_soc_jack_add_zones - Associate voltage zones with jack
117 *
118 * @jack: ASoC jack
119 * @count: Number of zones
120 * @zone: Array of zones
121 *
122 * After this function has been called the zones specified in the
123 * array will be associated with the jack.
124 */
125int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
126 struct snd_soc_jack_zone *zones)
127{
128 int i;
129
130 for (i = 0; i < count; i++) {
131 INIT_LIST_HEAD(&zones[i].list);
132 list_add(&(zones[i].list), &jack->jack_zones);
133 }
134 return 0;
135}
136EXPORT_SYMBOL_GPL(snd_soc_jack_add_zones);
137
138/**
139 * snd_soc_jack_get_type - Based on the mic bias value, this function returns
140 * the type of jack from the zones delcared in the jack type
141 *
142 * @micbias_voltage: mic bias voltage at adc channel when jack is plugged in
143 *
144 * Based on the mic bias value passed, this function helps identify
145 * the type of jack from the already delcared jack zones
146 */
147int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage)
148{
149 struct snd_soc_jack_zone *zone;
150
151 list_for_each_entry(zone, &jack->jack_zones, list) {
152 if (micbias_voltage >= zone->min_mv &&
153 micbias_voltage < zone->max_mv)
154 return zone->jack_type;
155 }
156 return 0;
157}
158EXPORT_SYMBOL_GPL(snd_soc_jack_get_type);
159
160/**
115 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack 161 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
116 * 162 *
117 * @jack: ASoC jack 163 * @jack: ASoC jack