All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: rt5640: add headset detection function
@ 2013-07-23  6:54 bardliao
  2013-07-23 13:00 ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: bardliao @ 2013-07-23  6:54 UTC (permalink / raw)
  To: broonie, lgirdwood; +Cc: oder_chiou, bardliao, alsa-devel, flove

From: Bard Liao <bardliao@realtek.com>

Add headset detection function to rt5640 codec driver.

Signed-off-by: Bard Liao <bardliao@realtek.com>
---
 sound/soc/codecs/rt5640.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5640.h |  3 +++
 2 files changed, 64 insertions(+)

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index ce585e3..dc0d063 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -1911,6 +1911,67 @@ static int rt5640_resume(struct snd_soc_codec *codec)
 #define rt5640_resume NULL
 #endif
 
+/**
+ * rt5640_headset_detect - Detect headset.
+ * @codec: SoC audio codec device.
+ * @jack_insert: Jack insert or not.
+ *
+ * Detect whether is headset or not when jack inserted.
+ *
+ * Returns detect status.
+ */
+int rt5640_headset_detect(struct snd_soc_codec *codec,
+				struct snd_soc_jack *jack, int jack_insert)
+{
+	int jack_type = 0;
+	int sclk_src = 0;
+	int reg63, reg64;
+
+	if (jack_insert) {
+		reg63 = snd_soc_read(codec, RT5640_PWR_ANLG1);
+		reg64 = snd_soc_read(codec, RT5640_PWR_ANLG2);
+		if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) {
+			snd_soc_write(codec, RT5640_PWR_ANLG1, 0xa814);
+			sclk_src = snd_soc_read(codec, RT5640_GLB_CLK) &
+				RT5640_SCLK_SRC_MASK;
+			snd_soc_update_bits(codec, RT5640_GLB_CLK,
+				RT5640_SCLK_SRC_MASK,
+				0x2 << RT5640_SCLK_SRC_SFT);
+		}
+		snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
+			RT5640_PWR_LDO2, RT5640_PWR_LDO2);
+		snd_soc_update_bits(codec, RT5640_PWR_ANLG2,
+			RT5640_PWR_MB1, RT5640_PWR_MB1);
+		snd_soc_update_bits(codec, RT5640_MICBIAS,
+			RT5640_MIC1_OVCD_MASK | RT5640_MIC1_OVTH_MASK |
+			RT5640_PWR_CLK25M_MASK | RT5640_PWR_MB_MASK,
+			RT5640_MIC1_OVCD_EN | RT5640_MIC1_OVTH_600UA |
+			RT5640_PWR_MB_PU | RT5640_PWR_CLK25M_PU);
+		snd_soc_update_bits(codec, RT5640_DUMMY1, 0x1, 0x1);
+		msleep(100);
+		if (snd_soc_read(codec, RT5640_IRQ_CTRL2) & 0x8)
+			jack_type = SND_JACK_HEADPHONE;
+		else
+			jack_type = SND_JACK_HEADSET;
+		snd_soc_update_bits(codec, RT5640_IRQ_CTRL2,
+			RT5640_MB1_OC_CLR, 0);
+		if (SND_SOC_BIAS_OFF == codec->dapm.bias_level)
+			snd_soc_update_bits(codec, RT5640_GLB_CLK,
+				RT5640_SCLK_SRC_MASK, sclk_src);
+		snd_soc_write(codec, RT5640_PWR_ANLG1, reg63);
+		snd_soc_write(codec, RT5640_PWR_ANLG2, reg64);
+		snd_soc_jack_report(jack, jack_type, SND_JACK_HEADSET);
+	} else {
+		snd_soc_update_bits(codec, RT5640_MICBIAS,
+			RT5640_MIC1_OVCD_MASK,
+			RT5640_MIC1_OVCD_DIS);
+		snd_soc_jack_report(jack, 0, jack->jack->type);
+	}
+
+	return jack_type;
+}
+EXPORT_SYMBOL_GPL(rt5640_headset_detect);
+
 #define RT5640_STEREO_RATES SNDRV_PCM_RATE_8000_96000
 #define RT5640_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
 			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
diff --git a/sound/soc/codecs/rt5640.h b/sound/soc/codecs/rt5640.h
index c48286d..263615b 100644
--- a/sound/soc/codecs/rt5640.h
+++ b/sound/soc/codecs/rt5640.h
@@ -2089,4 +2089,7 @@ struct rt5640_priv {
 	int dmic_en;
 };
 
+int rt5640_headset_detect(struct snd_soc_codec *codec,
+				struct snd_soc_jack *jack, int jack_insert);
+
 #endif
-- 
1.8.1.1.439.g50a6b54

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-23  6:54 [PATCH] ASoC: rt5640: add headset detection function bardliao
@ 2013-07-23 13:00 ` Mark Brown
  2013-07-25  3:36   ` Bard Liao
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2013-07-23 13:00 UTC (permalink / raw)
  To: bardliao; +Cc: oder_chiou, alsa-devel, lgirdwood, flove


[-- Attachment #1.1: Type: text/plain, Size: 541 bytes --]

On Tue, Jul 23, 2013 at 02:54:29PM +0800, bardliao@realtek.com wrote:

> + * @codec: SoC audio codec device.
> + * @jack_insert: Jack insert or not.
> + *
> + * Detect whether is headset or not when jack inserted.
> + *
> + * Returns detect status.
> + */
> +int rt5640_headset_detect(struct snd_soc_codec *codec,
> +				struct snd_soc_jack *jack, int jack_insert)

This doesn't look like it implements jack detection, it looks like it's
some sort of callback.  I'd expect to see some sort of interrupt for
example...

What's going on here?

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-23 13:00 ` Mark Brown
@ 2013-07-25  3:36   ` Bard Liao
  2013-07-25  9:15     ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Bard Liao @ 2013-07-25  3:36 UTC (permalink / raw)
  To: Mark Brown; +Cc: Oder Chiou, alsa-devel, lgirdwood, Flove

> -----Original Message-----
> From: Mark Brown [mailto:broonie@kernel.org]
> Sent: Tuesday, July 23, 2013 9:00 PM
> To: Bard Liao
> Cc: lgirdwood@gmail.com; alsa-devel@alsa-project.org; Flove; Oder Chiou
> Subject: Re: [PATCH] ASoC: rt5640: add headset detection function
> 
> On Tue, Jul 23, 2013 at 02:54:29PM +0800, bardliao@realtek.com wrote:
> 
> > + * @codec: SoC audio codec device.
> > + * @jack_insert: Jack insert or not.
> > + *
> > + * Detect whether is headset or not when jack inserted.
> > + *
> > + * Returns detect status.
> > + */
> > +int rt5640_headset_detect(struct snd_soc_codec *codec,
> > +				struct snd_soc_jack *jack, int jack_insert)
> 
> This doesn't look like it implements jack detection, it looks like it's some sort of
> callback.  I'd expect to see some sort of interrupt for example...
> 
> What's going on here?

Usually, our customers use cpu's gpio as the interrupt pin of jack insert/remove.
So we assume they will handle the interrupt event in machine driver.
When machine driver get a jack insert/remove event, it will call this function to know the jack type(headset or headphone).
Should I handle the interrupt event in codec driver?


> 
> ------Please consider the environment before printing this e-mail.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-25  3:36   ` Bard Liao
@ 2013-07-25  9:15     ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2013-07-25  9:15 UTC (permalink / raw)
  To: Bard Liao; +Cc: Oder Chiou, alsa-devel, lgirdwood, Flove


[-- Attachment #1.1: Type: text/plain, Size: 455 bytes --]

On Thu, Jul 25, 2013 at 11:36:42AM +0800, Bard Liao wrote:

> Usually, our customers use cpu's gpio as the interrupt pin of jack insert/remove.
> So we assume they will handle the interrupt event in machine driver.
> When machine driver get a jack insert/remove event, it will call this function to know the jack type(headset or headphone).
> Should I handle the interrupt event in codec driver?

Yes, of course.  Interrupts are just interrupts on Linux.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-08 13:12   ` Bard Liao
@ 2013-07-08 13:31     ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2013-07-08 13:31 UTC (permalink / raw)
  To: Bard Liao; +Cc: Oder Chiou, alsa-devel, swarren, swarren, lgirdwood, Flove


[-- Attachment #1.1: Type: text/plain, Size: 373 bytes --]

On Mon, Jul 08, 2013 at 09:12:06PM +0800, Bard Liao wrote:

> > > Add headset detection function to rt5640 codec driver.

> > No, use the standard soc-jack framework for reporting accessories.

> Do you mean call snd_soc_jack_report in rt5640_headset_detect to report the jack type?

Yes, with an appropriate way of setting up the jack.  Look at how other
drivers do this.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-08 11:26 ` Mark Brown
@ 2013-07-08 13:12   ` Bard Liao
  2013-07-08 13:31     ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Bard Liao @ 2013-07-08 13:12 UTC (permalink / raw)
  To: Mark Brown; +Cc: Oder Chiou, alsa-devel, swarren, swarren, lgirdwood, Flove

> -----Original Message-----
> From: Mark Brown [mailto:broonie@kernel.org]
> Sent: Monday, July 08, 2013 7:27 PM
> To: Bard Liao
> Cc: lgirdwood@gmail.com; alsa-devel@alsa-project.org; Flove; Oder Chiou;
> swarren@nvidia.com; swarren@wwwdotorg.org
> Subject: Re: [PATCH] ASoC: rt5640: add headset detection function
> 
> On Mon, Jul 08, 2013 at 02:33:09PM +0800, bardliao@realtek.com wrote:
> > From: Bard Liao <bardliao@realtek.com>
> >
> > Add headset detection function to rt5640 codec driver.
> 
> No, use the standard soc-jack framework for reporting accessories.

Do you mean call snd_soc_jack_report in rt5640_headset_detect to report the jack type?

> 
> ------Please consider the environment before printing this e-mail.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ASoC: rt5640: add headset detection function
  2013-07-08  6:33 bardliao
@ 2013-07-08 11:26 ` Mark Brown
  2013-07-08 13:12   ` Bard Liao
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2013-07-08 11:26 UTC (permalink / raw)
  To: bardliao; +Cc: oder_chiou, alsa-devel, swarren, swarren, lgirdwood, flove


[-- Attachment #1.1: Type: text/plain, Size: 245 bytes --]

On Mon, Jul 08, 2013 at 02:33:09PM +0800, bardliao@realtek.com wrote:
> From: Bard Liao <bardliao@realtek.com>
> 
> Add headset detection function to rt5640 codec driver.

No, use the standard soc-jack framework for reporting accessories.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] ASoC: rt5640: add headset detection function
@ 2013-07-08  6:33 bardliao
  2013-07-08 11:26 ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: bardliao @ 2013-07-08  6:33 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, alsa-devel, swarren, swarren, bardliao, flove

From: Bard Liao <bardliao@realtek.com>

Add headset detection function to rt5640 codec driver.

Signed-off-by: Bard Liao <bardliao@realtek.com>
---
 sound/soc/codecs/rt5640.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5640.h |  2 ++
 2 files changed, 62 insertions(+)

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index ce585e3..657efb7 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -1911,6 +1911,66 @@ static int rt5640_resume(struct snd_soc_codec *codec)
 #define rt5640_resume NULL
 #endif
 
+/**
+ * rt5640_headset_detect - Detect headset.
+ * @codec: SoC audio codec device.
+ * @jack_insert: Jack insert or not.
+ *
+ * Detect whether is headset or not when jack inserted.
+ *
+ * Returns detect status.
+ */
+int rt5640_headset_detect(struct snd_soc_codec *codec, int jack_insert)
+{
+	int jack_type;
+	int sclk_src = 0;
+	int reg63, reg64;
+
+	if (jack_insert) {
+		reg63 = snd_soc_read(codec, RT5640_PWR_ANLG1);
+		reg64 = snd_soc_read(codec, RT5640_PWR_ANLG2);
+		if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) {
+			snd_soc_write(codec, RT5640_PWR_ANLG1, 0xa814);
+			sclk_src = snd_soc_read(codec, RT5640_GLB_CLK) &
+				RT5640_SCLK_SRC_MASK;
+			snd_soc_update_bits(codec, RT5640_GLB_CLK,
+				RT5640_SCLK_SRC_MASK,
+				0x2 << RT5640_SCLK_SRC_SFT);
+		}
+		snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
+			RT5640_PWR_LDO2, RT5640_PWR_LDO2);
+		snd_soc_update_bits(codec, RT5640_PWR_ANLG2,
+			RT5640_PWR_MB1, RT5640_PWR_MB1);
+		snd_soc_update_bits(codec, RT5640_MICBIAS,
+			RT5640_MIC1_OVCD_MASK | RT5640_MIC1_OVTH_MASK |
+			RT5640_PWR_CLK25M_MASK | RT5640_PWR_MB_MASK,
+			RT5640_MIC1_OVCD_EN | RT5640_MIC1_OVTH_600UA |
+			RT5640_PWR_MB_PU | RT5640_PWR_CLK25M_PU);
+		snd_soc_update_bits(codec, RT5640_DUMMY1, 0x1, 0x1);
+		msleep(100);
+		if (snd_soc_read(codec, RT5640_IRQ_CTRL2) & 0x8)
+			jack_type = RT5640_HEADPHO_DET;
+		else
+			jack_type = RT5640_HEADSET_DET;
+		snd_soc_update_bits(codec, RT5640_IRQ_CTRL2,
+			RT5640_MB1_OC_CLR, 0);
+		if (SND_SOC_BIAS_OFF == codec->dapm.bias_level)
+			snd_soc_update_bits(codec, RT5640_GLB_CLK,
+				RT5640_SCLK_SRC_MASK, sclk_src);
+		snd_soc_write(codec, RT5640_PWR_ANLG1, reg63);
+		snd_soc_write(codec, RT5640_PWR_ANLG2, reg64);
+	} else {
+		snd_soc_update_bits(codec, RT5640_MICBIAS,
+			RT5640_MIC1_OVCD_MASK,
+			RT5640_MIC1_OVCD_DIS);
+
+		jack_type = RT5640_NO_JACK;
+	}
+
+	return jack_type;
+}
+EXPORT_SYMBOL_GPL(rt5640_headset_detect);
+
 #define RT5640_STEREO_RATES SNDRV_PCM_RATE_8000_96000
 #define RT5640_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
 			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
diff --git a/sound/soc/codecs/rt5640.h b/sound/soc/codecs/rt5640.h
index c48286d..c3856c8 100644
--- a/sound/soc/codecs/rt5640.h
+++ b/sound/soc/codecs/rt5640.h
@@ -2089,4 +2089,6 @@ struct rt5640_priv {
 	int dmic_en;
 };
 
+int rt5640_headset_detect(struct snd_soc_codec *codec, int jack_insert);
+
 #endif
-- 
1.8.1.1.439.g50a6b54

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-07-25  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23  6:54 [PATCH] ASoC: rt5640: add headset detection function bardliao
2013-07-23 13:00 ` Mark Brown
2013-07-25  3:36   ` Bard Liao
2013-07-25  9:15     ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2013-07-08  6:33 bardliao
2013-07-08 11:26 ` Mark Brown
2013-07-08 13:12   ` Bard Liao
2013-07-08 13:31     ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.