ASoC: soc_jack - add function to add jack zones and determine jack type
PATCH 1/3 ASoC: soc_jack - add function to add jack zones and determine jack type
Based on the voltage value in adc channel,jack plugged in needs to be determined
This patch adds a helper functions that adds the adc voltage zones and determines the jack type given the mic bias value.
When a jack is created, the voltage zones can to be added to it. Later when a jack is inserted, the micbias voltage can be measured and used to find the jack type
For any codec that would give the mic bias value on a jack insertion, this function would return the type of jack based on mic bias range
--- include/sound/soc.h | 20 +++++++++++++++ sound/soc/soc-jack.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 0 deletions(-)
include/sound/soc.h +20 -0
@@ -234,6 +234,7 @@ struct snd_soc_codec;struct snd_soc_codec_driver ;struct soc_enum ;struct snd_soc_jack ; +struct snd_soc_jack_zone ;struct snd_soc_jack_pin ;struct snd_soc_cache_ops ;#include <sound/soc-dapm.h>
@@ -307,6 +308,9 @@ void snd_soc_jack_notifier_register(struct snd_soc_jack *jack, struct notifier_block *nb);void snd_soc_jack_notifier_unregister (struct snd_soc_jack *jack,struct notifier_block *nb); +int snd_soc_jack_add_zones (struct snd_soc_jack *jack,int count, +struct snd_soc_jack_zone *zones); +int snd_soc_jack_get_type (struct snd_soc_jack *jack,int micbias_voltage);#ifdef CONFIG_GPIOLIB int snd_soc_jack_add_gpios (struct snd_soc_jack *jack,int count,struct snd_soc_jack_gpio *gpios);
@@ -406,6 +410,21 @@ struct snd_soc_jack_pin {bool invert; }; +/* struct snd_soc_jack_zone - Describes voltage zones of jack detection +* +* @adc_value_start: start range of voltage value in adc channel +* when jack is pluggedin +* @adc_value_end: end range of voltage value in adc channel +* when jack is pluggedin +* @jack_type: type of jack that is expected for this voltage +*/ +struct snd_soc_jack_zone { +unsigned int adc_value_start; +unsigned int adc_value_end; +unsigned int jack_type; +struct list_head list; +}; +/** * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection *
@@ -435,6 +454,7 @@ struct snd_soc_jack {struct list_head pins;int status;struct blocking_notifier_head notifier; +struct list_head jack_zones; };/* SoC PCM stream information */
sound/soc/soc-jack.c +67 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Quoted 4 lines · Harsha Priya
include/sound/soc.h +4
-0+/* struct snd_soc_jack_zone - Describes voltage zones of jack detection +* +* @adc_value_start: start range of voltage value in adc channel +* when jack is pluggedin
include/sound/soc.h struct snd_soc_jack_pin { · line 426
Quoted 10 lines
include/sound/soc.h +10
-0+* @adc_value_end: end range of voltage value in adc channel +* when jack is pluggedin +* @jack_type: type of jack that is expected for this voltage +*/ +struct snd_soc_jack_zone { +unsigned int adc_value_start; +unsigned int adc_value_end; +unsigned int jack_type; +struct list_head list; +};
This is a lot better than the previous version but I think we do need to include settling time support in here. As I said before most hardware used for this isn't specialised and won't have debounce support, and in cases like detection of simple headphones on a headset jack the settling time is essential in order to distinguish between that and a headset with a microphone short button active.
I'd also like to change adc_value_x to be {min,max}_mv or something similar for clarity, min and max are more obvious and using mv makes it clear what units are being used and that we're not working in terms of raw ADC values or similar.
sound/soc/soc-jack.c out: · line 117
Quoted 3 lines
sound/soc/soc-jack.c +3
-0+static int snd_soc_validate_jack_type (int type) +{ +switch (type) {
I don't see the need for this and in any case...
sound/soc/soc-jack.c out: · line 125
Quoted 8 lines
sound/soc/soc-jack.c +8
-0+case SND_JACK_HEADPHONE : +case SND_JACK_MICROPHONE : +case SND_JACK_HEADSET : +case SND_JACK_LINEOUT : +case SND_JACK_MECHANICAL : +case SND_JACK_VIDEOOUT : +case SND_JACK_AVOUT : +break ;
...this doesn't cover things like buttons implemented by shorting different resistances to ground.
sound/soc/soc-jack.c out: · line 178
Quoted 10 lines
sound/soc/soc-jack.c +10
-0+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->adc_value_start && + micbias_voltage < zone->adc_value_end) +return zone->jack_type; + } +return -ENODEV ;
Returning 0 would be more helpful - that'd mean that you could just report the result straight off. However, as I said last time I do think that we should be doing something more active to manage the detection here. That's pretty essential for anything time based.
Quoted 14 lines
Quoted 14 lines
include/sound/soc.h +13
-0+/* struct snd_soc_jack_zone - Describes voltage zones of jack detection +* +* @adc_value_start: start range of voltage value in adc channel +* when jack is pluggedin +* @adc_value_end: end range of voltage value in adc channel +* when jack is pluggedin +* @jack_type: type of jack that is expected for this voltage +*/ +struct snd_soc_jack_zone { +unsigned int adc_value_start; +unsigned int adc_value_end; +unsigned int jack_type; +struct list_head list;
Quoted 8 lines
Quoted 1 line
+};
This is a lot better than the previous version but I think we do need to include settling time support in here. As I said before most hardware used for this isn't specialised and won't have debounce support, and in cases like detection of simple headphones on a headset jack the settling time is essential in order to distinguish between that and a headset with a microphone short button active.
I will add it as a part of this structure.
Quoted 5 lines
I'd also like to change
adc_value_xto be {min,max}_mv or something similar for clarity, min and max are more obvious and using mv makes it clear what units are being used and that we're not working in terms of raw ADC values or similar.
I will change the names accordingly.
Quoted 6 lines
sound/soc/soc-jack.c out: · line 117
Quoted 4 lines
sound/soc/soc-jack.c +3
-0+static int snd_soc_validate_jack_type (int type) +{ +switch (type) {I don't see the need for this and in any case...
I wanted to make sure that when they add a type it's a type recognized by ALSA
Quoted 11 lines
sound/soc/soc-jack.c out: · line 125
Quoted 9 lines
sound/soc/soc-jack.c +8
-0+case SND_JACK_HEADPHONE : +case SND_JACK_MICROPHONE : +case SND_JACK_HEADSET : +case SND_JACK_LINEOUT : +case SND_JACK_MECHANICAL : +case SND_JACK_VIDEOOUT : +case SND_JACK_AVOUT : +break ;...this doesn't cover things like buttons implemented by shorting
I will add the buttons.
Quoted 17 lines
different resistances to ground.
sound/soc/soc-jack.c out: · line 178
Quoted 10 lines
sound/soc/soc-jack.c +10
-0+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->adc_value_start && + micbias_voltage < zone->adc_value_end) +return zone->jack_type; + } +return -ENODEV ;Returning 0 would be more helpful - that'd mean that you could just report the result straight off. However, as I said last time I do think that we should be doing something more active to manage the detection here. That's pretty essential for anything time based.
I will change the return value.
-Harsha