All of lore.kernel.org
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch
@ 2020-02-04  3:04 Tzung-Bi Shih
  2020-02-10 18:38 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Tzung-Bi Shih @ 2020-02-04  3:04 UTC (permalink / raw)
  To: broonie; +Cc: tzungbi, alsa-devel, dgreid, cychiang, jiaxin.yu

Some machine may share the same I2S lines for multiple codecs. For
example, mediatek/mt8183/mt8183-da7219-max98357 shares the same lines
between max98357a and da7219.  When writing audio data through the I2S
lines, all codecs on the lines would try to generate sound if they
accepts DO line.  As a result, multiple codecs generate sound at a
time.

Adds a separate switch to max98357a.  Userspace program has choices to
turn on or off the switch.  Note that, userspace program should change
the switch before opening the stream.  The switch won't take effects if
the stream is already there.

Default value of the switch is on to not break existing driver usages
(who are unlikely aware of existence of the switch).

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
---
 sound/soc/codecs/max98357a.c | 39 +++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c
index 16313b973eaa..a2c3be69a0ee 100644
--- a/sound/soc/codecs/max98357a.c
+++ b/sound/soc/codecs/max98357a.c
@@ -22,6 +22,7 @@
 struct max98357a_priv {
 	struct gpio_desc *sdmode;
 	unsigned int sdmode_delay;
+	int spk_switch;
 };
 
 static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
@@ -29,7 +30,7 @@ static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
 {
 	struct max98357a_priv *max98357a = snd_soc_dai_get_drvdata(dai);
 
-	if (!max98357a->sdmode)
+	if (!max98357a->sdmode || !max98357a->spk_switch)
 		return 0;
 
 	switch (cmd) {
@@ -49,6 +50,37 @@ static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+static int max98357a_get_spk_switch(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct max98357a_priv *max98357a =
+		snd_soc_component_get_drvdata(component);
+
+	ucontrol->value.integer.value[0] = max98357a->spk_switch;
+	return 0;
+}
+
+static int max98357a_put_spk_switch(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct max98357a_priv *max98357a =
+		snd_soc_component_get_drvdata(component);
+
+	max98357a->spk_switch = ucontrol->value.integer.value[0];
+	dev_info(component->dev,
+		 "put speaker switch: %d\n", max98357a->spk_switch);
+	return 0;
+}
+
+static const struct snd_kcontrol_new max98357a_snd_controls[] = {
+	SOC_SINGLE_BOOL_EXT("Speaker Switch", 0,
+		max98357a_get_spk_switch, max98357a_put_spk_switch),
+};
+
 static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
 	SND_SOC_DAPM_OUTPUT("Speaker"),
 };
@@ -58,6 +90,8 @@ static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
 };
 
 static const struct snd_soc_component_driver max98357a_component_driver = {
+	.controls		= max98357a_snd_controls,
+	.num_controls		= ARRAY_SIZE(max98357a_snd_controls),
 	.dapm_widgets		= max98357a_dapm_widgets,
 	.num_dapm_widgets	= ARRAY_SIZE(max98357a_dapm_widgets),
 	.dapm_routes		= max98357a_dapm_routes,
@@ -117,6 +151,9 @@ static int max98357a_platform_probe(struct platform_device *pdev)
 			"default: no delay\n");
 	}
 
+	/* For drivers who are not aware of the switch, default set to on. */
+	max98357a->spk_switch = 1;
+
 	dev_set_drvdata(&pdev->dev, max98357a);
 
 	return devm_snd_soc_register_component(&pdev->dev,
-- 
2.25.0.341.g760bfbb309-goog

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch
  2020-02-04  3:04 [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch Tzung-Bi Shih
@ 2020-02-10 18:38 ` Mark Brown
  2020-02-11 10:32   ` Tzung-Bi Shih
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2020-02-10 18:38 UTC (permalink / raw)
  To: Tzung-Bi Shih; +Cc: alsa-devel, dgreid, cychiang, jiaxin.yu


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

On Tue, Feb 04, 2020 at 11:04:06AM +0800, Tzung-Bi Shih wrote:

> Some machine may share the same I2S lines for multiple codecs. For
> example, mediatek/mt8183/mt8183-da7219-max98357 shares the same lines
> between max98357a and da7219.  When writing audio data through the I2S
> lines, all codecs on the lines would try to generate sound if they
> accepts DO line.  As a result, multiple codecs generate sound at a
> time.

Rather than adding this in the driver it would be better to add some
_PIN_SWITCH() widgets to the speaker outputs, those exist for
essentially this purpose.

> +	max98357a->spk_switch = ucontrol->value.integer.value[0];
> +	dev_info(component->dev,
> +		 "put speaker switch: %d\n", max98357a->spk_switch);

These _info() prints are too noisy.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch
  2020-02-10 18:38 ` Mark Brown
@ 2020-02-11 10:32   ` Tzung-Bi Shih
  2020-02-11 11:29     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Tzung-Bi Shih @ 2020-02-11 10:32 UTC (permalink / raw)
  To: Mark Brown
  Cc: ALSA development, Dylan Reid, Jimmy Cheng-Yi Chiang,
	Jiaxin Yu (俞家鑫)

On Tue, Feb 11, 2020 at 2:38 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Tue, Feb 04, 2020 at 11:04:06AM +0800, Tzung-Bi Shih wrote:
>
> > Some machine may share the same I2S lines for multiple codecs. For
> > example, mediatek/mt8183/mt8183-da7219-max98357 shares the same lines
> > between max98357a and da7219.  When writing audio data through the I2S
> > lines, all codecs on the lines would try to generate sound if they
> > accepts DO line.  As a result, multiple codecs generate sound at a
> > time.
>
> Rather than adding this in the driver it would be better to add some
> _PIN_SWITCH() widgets to the speaker outputs, those exist for
> essentially this purpose.

(We take rockchip/rk3399_gru_sound.c as a reference to use SOC_DAPM_PIN_SWITCH.)

Did you mean (in machine driver):
- Add SND_SOC_DAPM_SPK("Speakers", NULL)
- Add SOC_DAPM_PIN_SWITCH("Speakers")
- Add DAPM route "Speaker" (from max98357a) to "Speakers"
User space program controls "Speakers Switch" to toggle the switch?

We found the method cannot avoid max98357a->sdmode being set.  As a
result, max98357a consumes power even if we don't switch on it.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch
  2020-02-11 10:32   ` Tzung-Bi Shih
@ 2020-02-11 11:29     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2020-02-11 11:29 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: ALSA development, Dylan Reid, Jimmy Cheng-Yi Chiang,
	Jiaxin Yu (俞家鑫)


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

On Tue, Feb 11, 2020 at 06:32:20PM +0800, Tzung-Bi Shih wrote:

> Did you mean (in machine driver):
> - Add SND_SOC_DAPM_SPK("Speakers", NULL)
> - Add SOC_DAPM_PIN_SWITCH("Speakers")
> - Add DAPM route "Speaker" (from max98357a) to "Speakers"
> User space program controls "Speakers Switch" to toggle the switch?

Yes.

> We found the method cannot avoid max98357a->sdmode being set.  As a
> result, max98357a consumes power even if we don't switch on it.

That seems like something that you can address by improving integration
with DAPM.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

end of thread, other threads:[~2020-02-11 11:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04  3:04 [alsa-devel] [PATCH] ASoC: max98357a: add speaker switch Tzung-Bi Shih
2020-02-10 18:38 ` Mark Brown
2020-02-11 10:32   ` Tzung-Bi Shih
2020-02-11 11:29     ` 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.