All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] TWL4030: Add event callback to enable hands-free.
@ 2008-12-11  1:52 Stanley.Miao
  2008-12-11 12:53 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Stanley.Miao @ 2008-12-11  1:52 UTC (permalink / raw)
  To: alsa-devel

A special sequence is required to enable hands-free on TWL4030.

Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
---
 sound/soc/codecs/twl4030.c |   33 +++++++++++++++++++++++++++++----
 sound/soc/codecs/twl4030.h |    6 ++++++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 71ab534..86d6553 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -325,6 +325,29 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
 	return ret;
 }
 
+static int handsfree_event(struct snd_soc_dapm_widget *w,
+		struct snd_kcontrol *kcontrol, int event)
+{
+	struct soc_enum *e = (struct soc_enum *)w->kcontrols->private_value;
+	unsigned char hs_ctl;
+
+
+	hs_ctl = twl4030_read_reg_cache(w->codec, e->reg);
+
+	if (hs_ctl & TWL4030_HF_CTL_REF_EN) {
+		hs_ctl |= TWL4030_HF_CTL_RAMP_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+		hs_ctl |= TWL4030_HF_CTL_LOOP_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+		hs_ctl |= TWL4030_HF_CTL_HB_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+	} else {
+		twl4030_write(w->codec, e->reg, 0x0);
+	}
+
+	return 0;
+}
+
 /*
  * Some of the gain controls in TWL (mostly those which are associated with
  * the outputs) are implemented in an interesting way:
@@ -807,10 +830,12 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
 	SND_SOC_DAPM_MUX("CarkitR Mux", SND_SOC_NOPM, 0, 0,
 		&twl4030_dapm_carkitr_control),
 	/* HandsfreeL/R */
-	SND_SOC_DAPM_MUX("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
-		&twl4030_dapm_handsfreel_control),
-	SND_SOC_DAPM_MUX("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
-		&twl4030_dapm_handsfreer_control),
+	SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
+		&twl4030_dapm_handsfreel_control, handsfree_event,
+		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
+	SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
+		&twl4030_dapm_handsfreer_control, handsfree_event,
+		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
 
 	SND_SOC_DAPM_ADC("ADCL", "Left Capture", SND_SOC_NOPM, 0, 0),
 	SND_SOC_DAPM_ADC("ADCR", "Right Capture", SND_SOC_NOPM, 0, 0),
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h
index a2065d4..54615c7 100644
--- a/sound/soc/codecs/twl4030.h
+++ b/sound/soc/codecs/twl4030.h
@@ -191,6 +191,12 @@
 #define TWL4030_RAMP_DELAY_2581MS	0x1C
 #define TWL4030_RAMP_EN			0x02
 
+/* HFL_CTL (0x29, 0x2A) Fields */
+#define TWL4030_HF_CTL_HB_EN		0x04
+#define TWL4030_HF_CTL_LOOP_EN		0x08
+#define TWL4030_HF_CTL_RAMP_EN		0x10
+#define TWL4030_HF_CTL_REF_EN		0x20
+
 /* APLL_CTL (0x3A) Fields */
 
 #define TWL4030_APLL_EN			0x10
-- 
1.5.6.3

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

* Re: [PATCH] TWL4030: Add event callback to enable hands-free.
  2008-12-11  1:52 [PATCH] TWL4030: Add event callback to enable hands-free Stanley.Miao
@ 2008-12-11 12:53 ` Mark Brown
  2008-12-11 15:28   ` [PATCHv2] TWL4030: hands-free start-up sequence Stanley.Miao
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2008-12-11 12:53 UTC (permalink / raw)
  To: Stanley.Miao; +Cc: alsa-devel

On Thu, Dec 11, 2008 at 09:52:01AM +0800, Stanley.Miao wrote:
> A special sequence is required to enable hands-free on TWL4030.
> 
> Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>

I've applied this but I'm a bit nervous about this:

> +	} else {
> +		twl4030_write(w->codec, e->reg, 0x0);
> +	}

since that's clearing bits other than those which were enabled.  It
looks like there aren't any other bits in the register but it'd be good
to be more explicit about this.

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

* [PATCHv2] TWL4030: hands-free start-up sequence.
  2008-12-11 12:53 ` Mark Brown
@ 2008-12-11 15:28   ` Stanley.Miao
  2008-12-11 15:32     ` stanley.miao
  0 siblings, 1 reply; 4+ messages in thread
From: Stanley.Miao @ 2008-12-11 15:28 UTC (permalink / raw)
  To: alsa-devel; +Cc: broonie

A special start-up sequence is required to reduce the pop-noise of Class D
amplifier when enable hands-free on TWL4030.

Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
---
 sound/soc/codecs/twl4030.c |   34 ++++++++++++++++++++++++++++++----
 sound/soc/codecs/twl4030.h |    6 ++++++
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 1377302..5184888 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -322,6 +322,30 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
 	return ret;
 }
 
+static int handsfree_event(struct snd_soc_dapm_widget *w,
+		struct snd_kcontrol *kcontrol, int event)
+{
+	struct soc_enum *e = (struct soc_enum *)w->kcontrols->private_value;
+	unsigned char hs_ctl;
+
+	hs_ctl = twl4030_read_reg_cache(w->codec, e->reg);
+
+	if (hs_ctl & TWL4030_HF_CTL_REF_EN) {
+		hs_ctl |= TWL4030_HF_CTL_RAMP_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+		hs_ctl |= TWL4030_HF_CTL_LOOP_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+		hs_ctl |= TWL4030_HF_CTL_HB_EN;
+		twl4030_write(w->codec, e->reg, hs_ctl);
+	} else {
+		hs_ctl &= ~(TWL4030_HF_CTL_RAMP_EN | TWL4030_HF_CTL_LOOP_EN
+				| TWL4030_HF_CTL_HB_EN);
+		twl4030_write(w->codec, e->reg, hs_ctl);
+	}
+
+	return 0;
+}
+
 /*
  * Some of the gain controls in TWL (mostly those which are associated with
  * the outputs) are implemented in an interesting way:
@@ -806,10 +830,12 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
 	SND_SOC_DAPM_MUX("CarkitR Mux", SND_SOC_NOPM, 0, 0,
 		&twl4030_dapm_carkitr_control),
 	/* HandsfreeL/R */
-	SND_SOC_DAPM_MUX("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
-		&twl4030_dapm_handsfreel_control),
-	SND_SOC_DAPM_MUX("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
-		&twl4030_dapm_handsfreer_control),
+	SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
+		&twl4030_dapm_handsfreel_control, handsfree_event,
+		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
+	SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
+		&twl4030_dapm_handsfreer_control, handsfree_event,
+		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
 
 	SND_SOC_DAPM_ADC("ADCL", "Left Capture", SND_SOC_NOPM, 0, 0),
 	SND_SOC_DAPM_ADC("ADCR", "Right Capture", SND_SOC_NOPM, 0, 0),
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h
index a2065d4..54615c7 100644
--- a/sound/soc/codecs/twl4030.h
+++ b/sound/soc/codecs/twl4030.h
@@ -191,6 +191,12 @@
 #define TWL4030_RAMP_DELAY_2581MS	0x1C
 #define TWL4030_RAMP_EN			0x02
 
+/* HFL_CTL (0x29, 0x2A) Fields */
+#define TWL4030_HF_CTL_HB_EN		0x04
+#define TWL4030_HF_CTL_LOOP_EN		0x08
+#define TWL4030_HF_CTL_RAMP_EN		0x10
+#define TWL4030_HF_CTL_REF_EN		0x20
+
 /* APLL_CTL (0x3A) Fields */
 
 #define TWL4030_APLL_EN			0x10
-- 
1.5.6.3

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

* Re: [PATCHv2] TWL4030: hands-free start-up sequence.
  2008-12-11 15:28   ` [PATCHv2] TWL4030: hands-free start-up sequence Stanley.Miao
@ 2008-12-11 15:32     ` stanley.miao
  0 siblings, 0 replies; 4+ messages in thread
From: stanley.miao @ 2008-12-11 15:32 UTC (permalink / raw)
  To: alsa-devel; +Cc: broonie

Changes from last version:

1, clear the bits explicitly.

Stanley.

On Thu, 2008-12-11 at 23:28 +0800, Stanley.Miao wrote:
> A special start-up sequence is required to reduce the pop-noise of Class D
> amplifier when enable hands-free on TWL4030.
> 
> Signed-off-by: Stanley.Miao <stanley.miao@windriver.com>
> ---
>  sound/soc/codecs/twl4030.c |   34 ++++++++++++++++++++++++++++++----
>  sound/soc/codecs/twl4030.h |    6 ++++++
>  2 files changed, 36 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
> index 1377302..5184888 100644
> --- a/sound/soc/codecs/twl4030.c
> +++ b/sound/soc/codecs/twl4030.c
> @@ -322,6 +322,30 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
>  	return ret;
>  }
>  
> +static int handsfree_event(struct snd_soc_dapm_widget *w,
> +		struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct soc_enum *e = (struct soc_enum *)w->kcontrols->private_value;
> +	unsigned char hs_ctl;
> +
> +	hs_ctl = twl4030_read_reg_cache(w->codec, e->reg);
> +
> +	if (hs_ctl & TWL4030_HF_CTL_REF_EN) {
> +		hs_ctl |= TWL4030_HF_CTL_RAMP_EN;
> +		twl4030_write(w->codec, e->reg, hs_ctl);
> +		hs_ctl |= TWL4030_HF_CTL_LOOP_EN;
> +		twl4030_write(w->codec, e->reg, hs_ctl);
> +		hs_ctl |= TWL4030_HF_CTL_HB_EN;
> +		twl4030_write(w->codec, e->reg, hs_ctl);
> +	} else {
> +		hs_ctl &= ~(TWL4030_HF_CTL_RAMP_EN | TWL4030_HF_CTL_LOOP_EN
> +				| TWL4030_HF_CTL_HB_EN);
> +		twl4030_write(w->codec, e->reg, hs_ctl);
> +	}
> +
> +	return 0;
> +}
> +
>  /*
>   * Some of the gain controls in TWL (mostly those which are associated with
>   * the outputs) are implemented in an interesting way:
> @@ -806,10 +830,12 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
>  	SND_SOC_DAPM_MUX("CarkitR Mux", SND_SOC_NOPM, 0, 0,
>  		&twl4030_dapm_carkitr_control),
>  	/* HandsfreeL/R */
> -	SND_SOC_DAPM_MUX("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
> -		&twl4030_dapm_handsfreel_control),
> -	SND_SOC_DAPM_MUX("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
> -		&twl4030_dapm_handsfreer_control),
> +	SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0,
> +		&twl4030_dapm_handsfreel_control, handsfree_event,
> +		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
> +	SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0,
> +		&twl4030_dapm_handsfreer_control, handsfree_event,
> +		SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
>  
>  	SND_SOC_DAPM_ADC("ADCL", "Left Capture", SND_SOC_NOPM, 0, 0),
>  	SND_SOC_DAPM_ADC("ADCR", "Right Capture", SND_SOC_NOPM, 0, 0),
> diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h
> index a2065d4..54615c7 100644
> --- a/sound/soc/codecs/twl4030.h
> +++ b/sound/soc/codecs/twl4030.h
> @@ -191,6 +191,12 @@
>  #define TWL4030_RAMP_DELAY_2581MS	0x1C
>  #define TWL4030_RAMP_EN			0x02
>  
> +/* HFL_CTL (0x29, 0x2A) Fields */
> +#define TWL4030_HF_CTL_HB_EN		0x04
> +#define TWL4030_HF_CTL_LOOP_EN		0x08
> +#define TWL4030_HF_CTL_RAMP_EN		0x10
> +#define TWL4030_HF_CTL_REF_EN		0x20
> +
>  /* APLL_CTL (0x3A) Fields */
>  
>  #define TWL4030_APLL_EN			0x10

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

end of thread, other threads:[~2008-12-11 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-11  1:52 [PATCH] TWL4030: Add event callback to enable hands-free Stanley.Miao
2008-12-11 12:53 ` Mark Brown
2008-12-11 15:28   ` [PATCHv2] TWL4030: hands-free start-up sequence Stanley.Miao
2008-12-11 15:32     ` stanley.miao

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.