linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX
@ 2019-10-20 15:30 Stephan Gerhold
  2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stephan Gerhold @ 2019-10-20 15:30 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, alsa-devel, linux-kernel, Stephan Gerhold

According to the PM8916 Hardware Register Description,
CDC_D_CDC_CONN_HPHR_DAC_CTL has only a single bit (RX_SEL)
to switch between RX1 (0) and RX2 (1). It is not possible to
disable it entirely to achieve the "ZERO" state.

However, at the moment the "RDAC2 MUX" mixer defines three possible
values ("ZERO", "RX2" and "RX1"). Setting the mixer to "ZERO"
actually configures it to RX1. Setting the mixer to "RX1" has
(seemingly) no effect.

Remove "ZERO" and replace it with "RX1" to fix this.

Fixes: 585e881e5b9e ("ASoC: codecs: Add msm8916-wcd analog codec")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
 sound/soc/codecs/msm8916-wcd-analog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index 667e9f73aba3..e3d311fb510e 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -306,7 +306,7 @@ struct pm8916_wcd_analog_priv {
 };
 
 static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
-static const char *const rdac2_mux_text[] = { "ZERO", "RX2", "RX1" };
+static const char *const rdac2_mux_text[] = { "RX1", "RX2" };
 static const char *const hph_text[] = { "ZERO", "Switch", };
 
 static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
@@ -321,7 +321,7 @@ static const struct soc_enum adc2_enum = SOC_ENUM_SINGLE_VIRT(
 
 /* RDAC2 MUX */
 static const struct soc_enum rdac2_mux_enum = SOC_ENUM_SINGLE(
-			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 3, rdac2_mux_text);
+			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 2, rdac2_mux_text);
 
 static const struct snd_kcontrol_new spkr_switch[] = {
 	SOC_DAPM_SINGLE("Switch", CDC_A_SPKR_DAC_CTL, 7, 1, 0)
-- 
2.23.0


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

* [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece
  2019-10-20 15:30 [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Stephan Gerhold
@ 2019-10-20 15:30 ` Stephan Gerhold
  2019-10-21  9:32   ` Srinivas Kandagatla
  2019-10-21 18:00   ` Applied "ASoC: msm8916-wcd-analog: Add earpiece" to the asoc tree Mark Brown
  2019-10-21  9:32 ` [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Srinivas Kandagatla
  2019-10-21 18:00 ` Applied "ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX" to the asoc tree Mark Brown
  2 siblings, 2 replies; 6+ messages in thread
From: Stephan Gerhold @ 2019-10-20 15:30 UTC (permalink / raw)
  To: Mark Brown
  Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, alsa-devel, linux-kernel, Stephan Gerhold

PM8916 supports an earpiece as another (small) speaker.
The earpiece is routed through RX MIX1 similarly to
the headphones, except that RDAC2 MUX is set to RX1.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
This patch is based on code from the downstream driver
(msm8x16-wcd.c, [1]) with some cleanup.

This enables the earpiece on the Samsung Galaxy A5 (2015),
which has recently gained mainline support in [2].

[1]: https://source.codeaurora.org/quic/la/kernel/msm-3.10/tree/sound/soc/codecs/msm8x16-wcd.c?h=LA.BR.1.2.9.1-02310-8x16.0
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1329c1ab0730b521e6cd3051c56a2ff3d55f21e6
---
 sound/soc/codecs/msm8916-wcd-analog.c | 54 ++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index e3d311fb510e..f53235be77d9 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -228,6 +228,10 @@
 #define CDC_A_RX_EAR_CTL			(0xf19E)
 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK		BIT(0)
 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE	BIT(0)
+#define RX_EAR_CTL_PA_EAR_PA_EN_MASK		BIT(6)
+#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE		BIT(6)
+#define RX_EAR_CTL_PA_SEL_MASK			BIT(7)
+#define RX_EAR_CTL_PA_SEL			BIT(7)
 
 #define CDC_A_SPKR_DAC_CTL		(0xf1B0)
 #define SPKR_DAC_CTL_DAC_RESET_MASK	BIT(4)
@@ -312,6 +316,7 @@ static const char *const hph_text[] = { "ZERO", "Switch", };
 static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
 					ARRAY_SIZE(hph_text), hph_text);
 
+static const struct snd_kcontrol_new ear_mux = SOC_DAPM_ENUM("EAR_S", hph_enum);
 static const struct snd_kcontrol_new hphl_mux = SOC_DAPM_ENUM("HPHL", hph_enum);
 static const struct snd_kcontrol_new hphr_mux = SOC_DAPM_ENUM("HPHR", hph_enum);
 
@@ -685,6 +690,34 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
+					    struct snd_kcontrol *kcontrol,
+					    int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
+		break;
+	case SND_SOC_DAPM_POST_PMU:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_EAR_PA_EN_MASK,
+				    RX_EAR_CTL_PA_EAR_PA_EN_ENABLE);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_EAR_PA_EN_MASK, 0);
+		/* Delay to reduce ear turn off pop */
+		usleep_range(7000, 7100);
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_SEL_MASK, 0);
+		break;
+	}
+	return 0;
+}
+
 static const struct reg_default wcd_reg_defaults_2_0[] = {
 	{CDC_A_RX_COM_OCP_CTL, 0xD1},
 	{CDC_A_RX_COM_OCP_COUNT, 0xFF},
@@ -801,12 +834,20 @@ static const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = {
 	{"PDM_TX", NULL, "A_MCLK2"},
 	{"A_MCLK2", NULL, "A_MCLK"},
 
+	/* Earpiece (RX MIX1) */
+	{"EAR", NULL, "EAR_S"},
+	{"EAR_S", "Switch", "EAR PA"},
+	{"EAR PA", NULL, "RX_BIAS"},
+	{"EAR PA", NULL, "HPHL DAC"},
+	{"EAR PA", NULL, "HPHR DAC"},
+	{"EAR PA", NULL, "EAR CP"},
+
 	/* Headset (RX MIX1 and RX MIX2) */
 	{"HEADPHONE", NULL, "HPHL PA"},
 	{"HEADPHONE", NULL, "HPHR PA"},
 
-	{"HPHL PA", NULL, "EAR_HPHL_CLK"},
-	{"HPHR PA", NULL, "EAR_HPHR_CLK"},
+	{"HPHL DAC", NULL, "EAR_HPHL_CLK"},
+	{"HPHR DAC", NULL, "EAR_HPHR_CLK"},
 
 	{"CP", NULL, "NCP_CLK"},
 
@@ -847,11 +888,20 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
 	SND_SOC_DAPM_INPUT("AMIC1"),
 	SND_SOC_DAPM_INPUT("AMIC3"),
 	SND_SOC_DAPM_INPUT("AMIC2"),
+	SND_SOC_DAPM_OUTPUT("EAR"),
 	SND_SOC_DAPM_OUTPUT("HEADPHONE"),
 
 	/* RX stuff */
 	SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
 
+	SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM,
+			   0, 0, NULL, 0,
+			   pm8916_wcd_analog_enable_ear_pa,
+			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+			   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+	SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
+	SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
+
 	SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
 	SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
 	SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
-- 
2.23.0


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

* Re: [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece
  2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
@ 2019-10-21  9:32   ` Srinivas Kandagatla
  2019-10-21 18:00   ` Applied "ASoC: msm8916-wcd-analog: Add earpiece" to the asoc tree Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2019-10-21  9:32 UTC (permalink / raw)
  To: Stephan Gerhold, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel



On 20/10/2019 16:30, Stephan Gerhold wrote:
> PM8916 supports an earpiece as another (small) speaker.
> The earpiece is routed through RX MIX1 similarly to
> the headphones, except that RDAC2 MUX is set to RX1.
> 
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>


Looks good to me.

Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

> ---
> This patch is based on code from the downstream driver
> (msm8x16-wcd.c, [1]) with some cleanup.
> 
> This enables the earpiece on the Samsung Galaxy A5 (2015),
> which has recently gained mainline support in [2].
> 
> [1]: https://source.codeaurora.org/quic/la/kernel/msm-3.10/tree/sound/soc/codecs/msm8x16-wcd.c?h=LA.BR.1.2.9.1-02310-8x16.0
> [2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1329c1ab0730b521e6cd3051c56a2ff3d55f21e6
> ---
>   sound/soc/codecs/msm8916-wcd-analog.c | 54 ++++++++++++++++++++++++++-
>   1 file changed, 52 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
> index e3d311fb510e..f53235be77d9 100644
> --- a/sound/soc/codecs/msm8916-wcd-analog.c
> +++ b/sound/soc/codecs/msm8916-wcd-analog.c
> @@ -228,6 +228,10 @@
>   #define CDC_A_RX_EAR_CTL			(0xf19E)
>   #define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK		BIT(0)
>   #define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE	BIT(0)
> +#define RX_EAR_CTL_PA_EAR_PA_EN_MASK		BIT(6)
> +#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE		BIT(6)
> +#define RX_EAR_CTL_PA_SEL_MASK			BIT(7)
> +#define RX_EAR_CTL_PA_SEL			BIT(7)
>   
>   #define CDC_A_SPKR_DAC_CTL		(0xf1B0)
>   #define SPKR_DAC_CTL_DAC_RESET_MASK	BIT(4)
> @@ -312,6 +316,7 @@ static const char *const hph_text[] = { "ZERO", "Switch", };
>   static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
>   					ARRAY_SIZE(hph_text), hph_text);
>   
> +static const struct snd_kcontrol_new ear_mux = SOC_DAPM_ENUM("EAR_S", hph_enum);
>   static const struct snd_kcontrol_new hphl_mux = SOC_DAPM_ENUM("HPHL", hph_enum);
>   static const struct snd_kcontrol_new hphr_mux = SOC_DAPM_ENUM("HPHR", hph_enum);
>   
> @@ -685,6 +690,34 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
>   	return 0;
>   }
>   
> +static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
> +					    struct snd_kcontrol *kcontrol,
> +					    int event)
> +{
> +	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
> +
> +	switch (event) {
> +	case SND_SOC_DAPM_PRE_PMU:
> +		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
> +				    RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
> +		break;
> +	case SND_SOC_DAPM_POST_PMU:
> +		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
> +				    RX_EAR_CTL_PA_EAR_PA_EN_MASK,
> +				    RX_EAR_CTL_PA_EAR_PA_EN_ENABLE);
> +		break;
> +	case SND_SOC_DAPM_POST_PMD:
> +		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
> +				    RX_EAR_CTL_PA_EAR_PA_EN_MASK, 0);
> +		/* Delay to reduce ear turn off pop */
> +		usleep_range(7000, 7100);
> +		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
> +				    RX_EAR_CTL_PA_SEL_MASK, 0);
> +		break;
> +	}
> +	return 0;
> +}
> +
>   static const struct reg_default wcd_reg_defaults_2_0[] = {
>   	{CDC_A_RX_COM_OCP_CTL, 0xD1},
>   	{CDC_A_RX_COM_OCP_COUNT, 0xFF},
> @@ -801,12 +834,20 @@ static const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = {
>   	{"PDM_TX", NULL, "A_MCLK2"},
>   	{"A_MCLK2", NULL, "A_MCLK"},
>   
> +	/* Earpiece (RX MIX1) */
> +	{"EAR", NULL, "EAR_S"},
> +	{"EAR_S", "Switch", "EAR PA"},
> +	{"EAR PA", NULL, "RX_BIAS"},
> +	{"EAR PA", NULL, "HPHL DAC"},
> +	{"EAR PA", NULL, "HPHR DAC"},
> +	{"EAR PA", NULL, "EAR CP"},
> +
>   	/* Headset (RX MIX1 and RX MIX2) */
>   	{"HEADPHONE", NULL, "HPHL PA"},
>   	{"HEADPHONE", NULL, "HPHR PA"},
>   
> -	{"HPHL PA", NULL, "EAR_HPHL_CLK"},
> -	{"HPHR PA", NULL, "EAR_HPHR_CLK"},
> +	{"HPHL DAC", NULL, "EAR_HPHL_CLK"},
> +	{"HPHR DAC", NULL, "EAR_HPHR_CLK"},
>   
>   	{"CP", NULL, "NCP_CLK"},
>   
> @@ -847,11 +888,20 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
>   	SND_SOC_DAPM_INPUT("AMIC1"),
>   	SND_SOC_DAPM_INPUT("AMIC3"),
>   	SND_SOC_DAPM_INPUT("AMIC2"),
> +	SND_SOC_DAPM_OUTPUT("EAR"),
>   	SND_SOC_DAPM_OUTPUT("HEADPHONE"),
>   
>   	/* RX stuff */
>   	SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
>   
> +	SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM,
> +			   0, 0, NULL, 0,
> +			   pm8916_wcd_analog_enable_ear_pa,
> +			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
> +			   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
> +	SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
> +	SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
> +
>   	SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
>   	SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
>   	SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
> 

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

* Re: [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX
  2019-10-20 15:30 [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Stephan Gerhold
  2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
@ 2019-10-21  9:32 ` Srinivas Kandagatla
  2019-10-21 18:00 ` Applied "ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX" to the asoc tree Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2019-10-21  9:32 UTC (permalink / raw)
  To: Stephan Gerhold, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel



On 20/10/2019 16:30, Stephan Gerhold wrote:
> According to the PM8916 Hardware Register Description,
> CDC_D_CDC_CONN_HPHR_DAC_CTL has only a single bit (RX_SEL)
> to switch between RX1 (0) and RX2 (1). It is not possible to
> disable it entirely to achieve the "ZERO" state.
> 
> However, at the moment the "RDAC2 MUX" mixer defines three possible
> values ("ZERO", "RX2" and "RX1"). Setting the mixer to "ZERO"
> actually configures it to RX1. Setting the mixer to "RX1" has
> (seemingly) no effect.
> 
> Remove "ZERO" and replace it with "RX1" to fix this.
> 
> Fixes: 585e881e5b9e ("ASoC: codecs: Add msm8916-wcd analog codec")
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>

Thanks for the patch, Nice catch!

Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>


> ---
>   sound/soc/codecs/msm8916-wcd-analog.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
> index 667e9f73aba3..e3d311fb510e 100644
> --- a/sound/soc/codecs/msm8916-wcd-analog.c
> +++ b/sound/soc/codecs/msm8916-wcd-analog.c
> @@ -306,7 +306,7 @@ struct pm8916_wcd_analog_priv {
>   };
>   
>   static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
> -static const char *const rdac2_mux_text[] = { "ZERO", "RX2", "RX1" };
> +static const char *const rdac2_mux_text[] = { "RX1", "RX2" };
>   static const char *const hph_text[] = { "ZERO", "Switch", };
>   
>   static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
> @@ -321,7 +321,7 @@ static const struct soc_enum adc2_enum = SOC_ENUM_SINGLE_VIRT(
>   
>   /* RDAC2 MUX */
>   static const struct soc_enum rdac2_mux_enum = SOC_ENUM_SINGLE(
> -			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 3, rdac2_mux_text);
> +			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 2, rdac2_mux_text);
>   
>   static const struct snd_kcontrol_new spkr_switch[] = {
>   	SOC_DAPM_SINGLE("Switch", CDC_A_SPKR_DAC_CTL, 7, 1, 0)
> 

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

* Applied "ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX" to the asoc tree
  2019-10-20 15:30 [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Stephan Gerhold
  2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
  2019-10-21  9:32 ` [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Srinivas Kandagatla
@ 2019-10-21 18:00 ` Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2019-10-21 18:00 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: alsa-devel, Jaroslav Kysela, Liam Girdwood, linux-kernel,
	Mark Brown, Srinivas Kandagatla, Takashi Iwai

The patch

   ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 9110d1b0e229cebb1ffce0c04db2b22beffd513d Mon Sep 17 00:00:00 2001
From: Stephan Gerhold <stephan@gerhold.net>
Date: Sun, 20 Oct 2019 17:30:06 +0200
Subject: [PATCH] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX

According to the PM8916 Hardware Register Description,
CDC_D_CDC_CONN_HPHR_DAC_CTL has only a single bit (RX_SEL)
to switch between RX1 (0) and RX2 (1). It is not possible to
disable it entirely to achieve the "ZERO" state.

However, at the moment the "RDAC2 MUX" mixer defines three possible
values ("ZERO", "RX2" and "RX1"). Setting the mixer to "ZERO"
actually configures it to RX1. Setting the mixer to "RX1" has
(seemingly) no effect.

Remove "ZERO" and replace it with "RX1" to fix this.

Fixes: 585e881e5b9e ("ASoC: codecs: Add msm8916-wcd analog codec")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20191020153007.206070-1-stephan@gerhold.net
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/msm8916-wcd-analog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index 667e9f73aba3..e3d311fb510e 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -306,7 +306,7 @@ struct pm8916_wcd_analog_priv {
 };
 
 static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
-static const char *const rdac2_mux_text[] = { "ZERO", "RX2", "RX1" };
+static const char *const rdac2_mux_text[] = { "RX1", "RX2" };
 static const char *const hph_text[] = { "ZERO", "Switch", };
 
 static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
@@ -321,7 +321,7 @@ static const struct soc_enum adc2_enum = SOC_ENUM_SINGLE_VIRT(
 
 /* RDAC2 MUX */
 static const struct soc_enum rdac2_mux_enum = SOC_ENUM_SINGLE(
-			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 3, rdac2_mux_text);
+			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 2, rdac2_mux_text);
 
 static const struct snd_kcontrol_new spkr_switch[] = {
 	SOC_DAPM_SINGLE("Switch", CDC_A_SPKR_DAC_CTL, 7, 1, 0)
-- 
2.20.1


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

* Applied "ASoC: msm8916-wcd-analog: Add earpiece" to the asoc tree
  2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
  2019-10-21  9:32   ` Srinivas Kandagatla
@ 2019-10-21 18:00   ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2019-10-21 18:00 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: alsa-devel, Jaroslav Kysela, Liam Girdwood, linux-kernel,
	Mark Brown, Srinivas Kandagatla, Takashi Iwai

The patch

   ASoC: msm8916-wcd-analog: Add earpiece

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 7d2f70f248ab0e4251591cf7b36cc43281941f56 Mon Sep 17 00:00:00 2001
From: Stephan Gerhold <stephan@gerhold.net>
Date: Sun, 20 Oct 2019 17:30:07 +0200
Subject: [PATCH] ASoC: msm8916-wcd-analog: Add earpiece

PM8916 supports an earpiece as another (small) speaker.
The earpiece is routed through RX MIX1 similarly to
the headphones, except that RDAC2 MUX is set to RX1.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20191020153007.206070-2-stephan@gerhold.net
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/msm8916-wcd-analog.c | 54 ++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index 667e9f73aba3..4168b0a0aafb 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -228,6 +228,10 @@
 #define CDC_A_RX_EAR_CTL			(0xf19E)
 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK		BIT(0)
 #define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE	BIT(0)
+#define RX_EAR_CTL_PA_EAR_PA_EN_MASK		BIT(6)
+#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE		BIT(6)
+#define RX_EAR_CTL_PA_SEL_MASK			BIT(7)
+#define RX_EAR_CTL_PA_SEL			BIT(7)
 
 #define CDC_A_SPKR_DAC_CTL		(0xf1B0)
 #define SPKR_DAC_CTL_DAC_RESET_MASK	BIT(4)
@@ -312,6 +316,7 @@ static const char *const hph_text[] = { "ZERO", "Switch", };
 static const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
 					ARRAY_SIZE(hph_text), hph_text);
 
+static const struct snd_kcontrol_new ear_mux = SOC_DAPM_ENUM("EAR_S", hph_enum);
 static const struct snd_kcontrol_new hphl_mux = SOC_DAPM_ENUM("HPHL", hph_enum);
 static const struct snd_kcontrol_new hphr_mux = SOC_DAPM_ENUM("HPHR", hph_enum);
 
@@ -685,6 +690,34 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
+					    struct snd_kcontrol *kcontrol,
+					    int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
+		break;
+	case SND_SOC_DAPM_POST_PMU:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_EAR_PA_EN_MASK,
+				    RX_EAR_CTL_PA_EAR_PA_EN_ENABLE);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_EAR_PA_EN_MASK, 0);
+		/* Delay to reduce ear turn off pop */
+		usleep_range(7000, 7100);
+		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+				    RX_EAR_CTL_PA_SEL_MASK, 0);
+		break;
+	}
+	return 0;
+}
+
 static const struct reg_default wcd_reg_defaults_2_0[] = {
 	{CDC_A_RX_COM_OCP_CTL, 0xD1},
 	{CDC_A_RX_COM_OCP_COUNT, 0xFF},
@@ -801,12 +834,20 @@ static const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = {
 	{"PDM_TX", NULL, "A_MCLK2"},
 	{"A_MCLK2", NULL, "A_MCLK"},
 
+	/* Earpiece (RX MIX1) */
+	{"EAR", NULL, "EAR_S"},
+	{"EAR_S", "Switch", "EAR PA"},
+	{"EAR PA", NULL, "RX_BIAS"},
+	{"EAR PA", NULL, "HPHL DAC"},
+	{"EAR PA", NULL, "HPHR DAC"},
+	{"EAR PA", NULL, "EAR CP"},
+
 	/* Headset (RX MIX1 and RX MIX2) */
 	{"HEADPHONE", NULL, "HPHL PA"},
 	{"HEADPHONE", NULL, "HPHR PA"},
 
-	{"HPHL PA", NULL, "EAR_HPHL_CLK"},
-	{"HPHR PA", NULL, "EAR_HPHR_CLK"},
+	{"HPHL DAC", NULL, "EAR_HPHL_CLK"},
+	{"HPHR DAC", NULL, "EAR_HPHR_CLK"},
 
 	{"CP", NULL, "NCP_CLK"},
 
@@ -847,11 +888,20 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
 	SND_SOC_DAPM_INPUT("AMIC1"),
 	SND_SOC_DAPM_INPUT("AMIC3"),
 	SND_SOC_DAPM_INPUT("AMIC2"),
+	SND_SOC_DAPM_OUTPUT("EAR"),
 	SND_SOC_DAPM_OUTPUT("HEADPHONE"),
 
 	/* RX stuff */
 	SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
 
+	SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM,
+			   0, 0, NULL, 0,
+			   pm8916_wcd_analog_enable_ear_pa,
+			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+			   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+	SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
+	SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
+
 	SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
 	SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
 	SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
-- 
2.20.1


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

end of thread, other threads:[~2019-10-21 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20 15:30 [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Stephan Gerhold
2019-10-20 15:30 ` [PATCH 2/2] ASoC: msm8916-wcd-analog: Add earpiece Stephan Gerhold
2019-10-21  9:32   ` Srinivas Kandagatla
2019-10-21 18:00   ` Applied "ASoC: msm8916-wcd-analog: Add earpiece" to the asoc tree Mark Brown
2019-10-21  9:32 ` [PATCH 1/2] ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX Srinivas Kandagatla
2019-10-21 18:00 ` Applied "ASoC: msm8916-wcd-analog: Fix RX1 selection in RDAC2 MUX" to the asoc tree 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).