* [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
@ 2011-01-28 17:09 Harsha Priya
2011-01-31 12:06 ` Liam Girdwood
2011-01-31 12:08 ` Mark Brown
0 siblings, 2 replies; 7+ messages in thread
From: Harsha Priya @ 2011-01-28 17:09 UTC (permalink / raw)
To: alsa-devel; +Cc: Harsha Priya, Vinod Koul, broonie, lrg
This patch adds a helper function that determines the jack type
given the mic bias value. 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
Signed-off-by: Harsha Priya <priya.harsha@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
---
include/sound/soc.h | 15 +++++++++++++++
sound/soc/soc-jack.c | 18 ++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 7ecdaef..afe98eb 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -246,6 +246,19 @@ typedef int (*hw_write_t)(void *,const char* ,int);
extern struct snd_ac97_bus_ops soc_ac97_ops;
+enum soc_mic_bias_zones {
+ /* mic bias volutage range for Headphones*/
+ SND_SOC_JACK_HP_START = 0,
+ SND_SOC_JACK_HP_END = 400,
+ /* mic bias volutage range for American Headset*/
+ SND_SOC_JACK_AM_HS_START = 400,
+ SND_SOC_JACK_AM_HS_END = 650,
+ /* mic bias volutage range for Headset*/
+ SND_SOC_JACK_HS_START = 650,
+ SND_SOC_JACK_HS_END = 2000,
+ SND_SOC_UNDEFINED,
+};
+
enum snd_soc_control_type {
SND_SOC_CUSTOM,
SND_SOC_I2C,
@@ -307,6 +320,8 @@ 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_get_type(int mic_bias);
+
#ifdef CONFIG_GPIOLIB
int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
struct snd_soc_jack_gpio *gpios);
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index ac5a5bc..462965a 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -186,6 +186,24 @@ void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
}
EXPORT_SYMBOL_GPL(snd_soc_jack_notifier_unregister);
+/**
+ * snd_soc_jack_get_type - Based on the mic bias value, this function returns
+ * the type of jack
+ *
+ * @mic_bias: mic bias value detected
+ *
+ * Based on the mic bias value passed, this function helps identify
+ * the type of jack as either SND_JACK_HEADSET or SND_JACK_HEADPHONE.
+ */
+int snd_soc_jack_get_type(int mic_bias)
+{
+ if (mic_bias >= SND_SOC_JACK_HP_START && mic_bias < SND_SOC_JACK_HS_END)
+ return SND_JACK_HEADSET;
+ else
+ return SND_JACK_HEADPHONE;
+}
+EXPORT_SYMBOL_GPL(snd_soc_jack_get_type);
+
#ifdef CONFIG_GPIOLIB
/* gpio detect */
static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
--
1.7.3.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-01-28 17:09 [PATCH 1/3] ASoC: soc_jack - add function to determine jack type Harsha Priya
@ 2011-01-31 12:06 ` Liam Girdwood
2011-01-31 12:08 ` Mark Brown
1 sibling, 0 replies; 7+ messages in thread
From: Liam Girdwood @ 2011-01-31 12:06 UTC (permalink / raw)
To: Harsha Priya; +Cc: Koul, alsa-devel, broonie, Vinod
On Fri, 2011-01-28 at 22:39 +0530, Harsha Priya wrote:
> This patch adds a helper function that determines the jack type
> given the mic bias value. 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
>
> Signed-off-by: Harsha Priya <priya.harsha@intel.com>
> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
> ---
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
--
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-01-28 17:09 [PATCH 1/3] ASoC: soc_jack - add function to determine jack type Harsha Priya
2011-01-31 12:06 ` Liam Girdwood
@ 2011-01-31 12:08 ` Mark Brown
2011-02-01 13:19 ` Harsha, Priya
1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2011-01-31 12:08 UTC (permalink / raw)
To: Harsha Priya; +Cc: Vinod Koul, alsa-devel, lrg
On Fri, Jan 28, 2011 at 10:39:39PM +0530, Harsha Priya wrote:
> given the mic bias value. 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
I think this is too minimal as an API for this. There's two things I'm
missing here. The major one is that there's no handling of debounce -
jack insertion is a very slow and very analogue process relative to CPUs
so taking a single reading is likely to give false measurements.
The other is that there's no facility for either scaling the voltages
with micbias (obviously the specific voltages read are going to vary
depending on what the micbias voltage on a given system is) or for
adding other things that can be detected. For example, some systems
have buttons on their headset which pull micbias to ground via varying
resistances with individual buttons being detected by measuring the
different voltages resulting from the different resistances.
It'd be worth taking a look at the sec_jack stuff that Samsung have used
in at least some of their Android devices:
http://android.git.kernel.org/?p=kernel/samsung.git;a=blob;f=include/linux/sec_jack.h
It's quite hard coded in code terms but it covers things like the
debounce.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-01-31 12:08 ` Mark Brown
@ 2011-02-01 13:19 ` Harsha, Priya
2011-02-01 13:22 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Harsha, Priya @ 2011-02-01 13:19 UTC (permalink / raw)
To: Mark Brown; +Cc: Koul, Vinod, alsa-devel@alsa-project.org, lrg@slimlogic.co.uk
>> given the mic bias value. 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
>
>I think this is too minimal as an API for this. There's two things I'm
>missing here. The major one is that there's no handling of debounce -
>jack insertion is a very slow and very analogue process relative to CPUs
>so taking a single reading is likely to give false measurements.
I believe this should be part of codec driver that would make sure that it has
determined the right adc value and then call the function to find the jack type.
In the sn95031 codec, this is handled in hardware with programmable debounce
values. The default value takes care of ensuring that the adc value is read is for
right jack event.
Later, I will add a kcontrol for the same to enable programming it.
>
>The other is that there's no facility for either scaling the voltages
>with micbias (obviously the specific voltages read are going to vary
>depending on what the micbias voltage on a given system is)
I can add a field "system_micbias" field and the ranges fields to snd_soc_jack
structure. The machine driver can set these details when it creates a jack. The
new API can give the jack or button type based on this range. This way its
scalable. Will this help? Let us know, if there is a better way
>adding other things that can be detected. For example, some systems
>have buttons on their headset which pull micbias to ground via varying
>resistances with individual buttons being detected by measuring the
>different voltages resulting from the different resistances.
>
>It'd be worth taking a look at the sec_jack stuff that Samsung have used
>in at least some of their Android devices:
>
> http://android.git.kernel.org/?p=kernel/samsung.git;a=blob;f=include/linux/sec_jack.h
>
>It's quite hard coded in code terms but it covers things like the
>debounce.
Thanks for the link.
-Harsha
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-02-01 13:19 ` Harsha, Priya
@ 2011-02-01 13:22 ` Mark Brown
2011-02-01 13:35 ` Harsha, Priya
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2011-02-01 13:22 UTC (permalink / raw)
To: Harsha, Priya
Cc: Koul, Vinod, alsa-devel@alsa-project.org, lrg@slimlogic.co.uk
On Tue, Feb 01, 2011 at 06:49:11PM +0530, Harsha, Priya wrote:
> >I think this is too minimal as an API for this. There's two things I'm
> >missing here. The major one is that there's no handling of debounce -
> >jack insertion is a very slow and very analogue process relative to CPUs
> >so taking a single reading is likely to give false measurements.
> I believe this should be part of codec driver that would make sure that it has
> determined the right adc value and then call the function to find the jack type.
This is not in general possible - there are generally AUXADCs in many
devices, CPUs and PMICs both commonly have them, and the majority of
them just take a reading when asked to do so. Generic software needs to
be able to handle this.
> In the sn95031 codec, this is handled in hardware with programmable debounce
> values. The default value takes care of ensuring that the adc value is read is for
> right jack event.
That's great, but we can't rely on this in generic code.
> Later, I will add a kcontrol for the same to enable programming it.
Hrm?
> I can add a field "system_micbias" field and the ranges fields to snd_soc_jack
> structure. The machine driver can set these details when it creates a jack. The
> new API can give the jack or button type based on this range. This way its
> scalable. Will this help? Let us know, if there is a better way
Probably.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-02-01 13:22 ` Mark Brown
@ 2011-02-01 13:35 ` Harsha, Priya
2011-02-01 13:43 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Harsha, Priya @ 2011-02-01 13:35 UTC (permalink / raw)
To: Mark Brown; +Cc: Koul, Vinod, alsa-devel@alsa-project.org, lrg@slimlogic.co.uk
>> I believe this should be part of codec driver that would make sure that it has
>> determined the right adc value and then call the function to find the jack type.
>
>This is not in general possible - there are generally AUXADCs in many
>devices, CPUs and PMICs both commonly have them, and the majority of
>them just take a reading when asked to do so. Generic software needs to
>be able to handle this.
What if I add a field debouce to snd_soc_jack and machine driver needs to program
the value. The codec driver should wait for that time before reading the adc values
Will this help
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] ASoC: soc_jack - add function to determine jack type
2011-02-01 13:35 ` Harsha, Priya
@ 2011-02-01 13:43 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2011-02-01 13:43 UTC (permalink / raw)
To: Harsha, Priya
Cc: Koul, Vinod, alsa-devel@alsa-project.org, lrg@slimlogic.co.uk
On Tue, Feb 01, 2011 at 07:05:26PM +0530, Harsha, Priya wrote:
Please fix the word wrapping in your MUA to wrap at less than 80
columns.
> What if I add a field debouce to snd_soc_jack and machine driver needs
> to program the value. The codec driver should wait for that time
> before reading the adc values Will this help
The driver providing the ADC (which may not be part of a CODEC at all)
shouldn't have to worry about this stuff unless it's done the
debouncing - we should avoid having to open code functionality in
individual drivers. It feels like we should have actual code for
managing the process of detecting what's connected, with flexibility to
handle things like pre-debouncing. If some of it is left sketchy in the
first instance that's OK but we should have an idea what the overall
picture is.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-02-01 13:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-28 17:09 [PATCH 1/3] ASoC: soc_jack - add function to determine jack type Harsha Priya
2011-01-31 12:06 ` Liam Girdwood
2011-01-31 12:08 ` Mark Brown
2011-02-01 13:19 ` Harsha, Priya
2011-02-01 13:22 ` Mark Brown
2011-02-01 13:35 ` Harsha, Priya
2011-02-01 13:43 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).