Skip to contentSkip to conversation

ASoC: wm8741: Add differential mono mode support

RFC PATCH Superseded Sergej Sawazki 3 participants 8 messages May 1, 2015 – May 5, 2015

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ASoC: wm8741: Add differential mono mode support

The WM8741 DAC supports several differential output modes (stereo, stereo reversed, mono left, mono right). Add platform data and DT bindings to configure it.

---
 Documentation/devicetree/bindings/sound/wm8741.txt |  11 ++
 sound/soc/codecs/wm8741.c                          | 129 ++++++++++++++++++---
 sound/soc/codecs/wm8741.h                          |  10 ++
 3 files changed, 137 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/sound/wm8741.txt +11 -0
index 74bda58..a133154 100644
@@ -10,9 +10,20 @@ Required properties:
   - reg : the I2C address of the device for I2C, the chip select
           number for SPI.
 
+Optional properties:
+
+  - diff-mode: Differential output mode configuration. Default value for field
+    DIFF in register R8 (MODE_CONTROL_2). If absent, the default is 0, shall be:
+    0 = stereo
+    1 = mono left
+    2 = stereo reversed
+    3 = mono right
+
 Example:
 
 codec: wm8741@1a {
 	compatible = "wlf,wm8741";
 	reg = <0x1a>;
+
+	diff-mode = <3>;
 };
sound/soc/codecs/wm8741.c +116 -13

189 lines not on this page · raw message

sound/soc/codecs/wm8741.h +10 -0
index 56c1b1d..c8835f6 100644
@@ -194,6 +194,12 @@
 #define WM8741_DITHER_SHIFT                          0  /* DITHER - [1:0] */
 #define WM8741_DITHER_WIDTH                          2  /* DITHER - [1:0] */
 
+/* DIFF field values */
+#define WM8741_DIFF_MODE_STEREO                      0  /* stereo normal */
+#define WM8741_DIFF_MODE_STEREO_REVERSED             2  /* stereo reversed */
+#define WM8741_DIFF_MODE_MONO_LEFT                   1  /* mono left */
+#define WM8741_DIFF_MODE_MONO_RIGHT                  3  /* mono right */
+
 /*
  * R32 (0x20) - ADDITONAL_CONTROL_1
  */
@@ -208,4 +214,8 @@
 
 #define  WM8741_SYSCLK 0
 
+struct wm8741_platform_data {
+	u32 diff_mode;   /* Differential Output Mode */
+};
+
 #endif
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 64 lines · Sergej Sawazki

The WM8741 DAC supports several differential output modes (stereo, stereo reversed, mono left, mono right). Add platform data and DT bindings to configure it.

---
 Documentation/devicetree/bindings/sound/wm8741.txt |  11 ++
 sound/soc/codecs/wm8741.c                          | 129 ++++++++++++++++++---
 sound/soc/codecs/wm8741.h                          |  10 ++
 3 files changed, 137 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/sound/wm8741.txt +11 -0
index 74bda58..a133154 100644
@@ -10,9 +10,20 @@ Required properties:
   - reg : the I2C address of the device for I2C, the chip select
           number for SPI.
 
+Optional properties:
+
+  - diff-mode: Differential output mode configuration. Default value for field
+    DIFF in register R8 (MODE_CONTROL_2). If absent, the default is 0, shall be:
+    0 = stereo
+    1 = mono left
+    2 = stereo reversed
+    3 = mono right
+
 Example:
 
 codec: wm8741@1a {
 	compatible = "wlf,wm8741";
 	reg = <0x1a>;
+
+	diff-mode = <3>;
 };
sound/soc/codecs/wm8741.c +6 -1
index 9e71c76..9b777a6 100644
@@ -41,6 +41,7 @@ static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = {
 
 /* codec private data */
 struct wm8741_priv {
+	struct wm8741_platform_data pdata;
 	struct regmap *regmap;
 	struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
 	unsigned int sysclk;
@@ -87,13 +88,27 @@ static int wm8741_reset(struct snd_soc_codec *codec)
 static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, -12700, 13, 0);
 static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 400, 0);
 
-static const struct snd_kcontrol_new wm8741_snd_controls[] = {
+static const struct snd_kcontrol_new wm8741_snd_controls_stereo[] = {
 SOC_DOUBLE_R_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
 		 WM8741_DACRLSB_ATTENUATION, 1, 255, 1, dac_tlv_fine),
 SOC_DOUBLE_R_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION,
 		 WM8741_DACRMSB_ATTENUATION, 0, 511, 1, dac_tlv),
 };
 
+static const struct snd_kcontrol_new wm8741_snd_controls_mono_left[] = {
+SOC_SINGLE_TLV("Fine Playback Volume Left", WM8741_DACLLSB_ATTENUATION,
+		 1, 255, 1, dac_tlv_fine),
+SOC_SINGLE_TLV("Playback Volume Left", WM8741_DACLMSB_ATTENUATION,

sound/soc/codecs/wm8741.c static int wm8741_reset(struct snd_soc_codec *codec) · line 111

Quoted 10 lines
sound/soc/codecs/wm8741.c +10 -0
+		 0, 511, 1, dac_tlv),
+};
+
+static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = {
+	SOC_SINGLE_TLV("Fine Playback Volume Right", WM8741_DACRLSB_ATTENUATION,
+		1, 255, 1, dac_tlv_fine),
+	SOC_SINGLE_TLV("Playback Volume Right", WM8741_DACRMSB_ATTENUATION,
+		0, 511, 1, dac_tlv),
+};
+

Tabbing here could use being fixed, but functionally the change looks fine to me.

Thanks,
Charles

maintainer
#2 lore raw
In reply to Sergej Sawazki

sound/soc/codecs/wm8741.c static int wm8741_reset(struct snd_soc_codec *codec) · line 110

Quoted 6 lines · Sergej Sawazki
sound/soc/codecs/wm8741.c +6 -0
+static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = {
+	SOC_SINGLE_TLV("Fine Playback Volume Right", WM8741_DACRLSB_ATTENUATION,
+		1, 255, 1, dac_tlv_fine),
+	SOC_SINGLE_TLV("Playback Volume Right", WM8741_DACRMSB_ATTENUATION,
+		0, 511, 1, dac_tlv),
+};

Please follow the control naming standard in ControlNames.txt: all volume controls must have Volume as the last word in the name.

sound/soc/codecs/wm8741.c static struct snd_soc_dai_driver wm8741_dai = { · line 417

Quoted 6 lines
sound/soc/codecs/wm8741.c +1 -1
 	.name = "wm8741",
 	.playback = {
 		.stream_name = "Playback",
-		.channels_min = 2,  /* Mono modes not yet supported */
+		.channels_min = 1,
 		.channels_max = 2,

This should be varying with the platform data: in the mono modes we can't do stereo and I suspect the stereo modes may have issues with mono.

#3 lore raw

Am 04.05.2015 um 13:25 schrieb Mark Brown:

Quoted 11 lines · Sergej Sawazki

sound/soc/codecs/wm8741.c static int wm8741_reset(struct snd_soc_codec *codec) · line 110

Quoted 7 lines
sound/soc/codecs/wm8741.c +6 -0
+static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = {
+	SOC_SINGLE_TLV("Fine Playback Volume Right", WM8741_DACRLSB_ATTENUATION,
+		1, 255, 1, dac_tlv_fine),
+	SOC_SINGLE_TLV("Playback Volume Right", WM8741_DACRMSB_ATTENUATION,
+		0, 511, 1, dac_tlv),
+};

Please follow the control naming standard in ControlNames.txt: all volume controls must have Volume as the last word in the name.

Thanks for this information. I would suggest "Right Fine Playback Volume". Where "Right" is the "CHANNEL" from ControlNames.txt. However, there is no "Right" in the "CHANNEL" section. What do you think?

Quoted 10 lines

sound/soc/codecs/wm8741.c static struct snd_soc_dai_driver wm8741_dai = { · line 417

Quoted 6 lines
  	.name = "wm8741",
  	.playback = {
  		.stream_name = "Playback",
sound/soc/codecs/wm8741.c +1 -1
-		.channels_min = 2,  /* Mono modes not yet supported */
+		.channels_min = 1,
  		.channels_max = 2,

This should be varying with the platform data: in the mono modes we can't do stereo and I suspect the stereo modes may have issues with mono.

I think this should be always ".channels_min = 2". In "mono mode" the DAC plays either the right or the left channel, however the I2S signal is expected to be stereo.

Sergej

maintainer
#4 lore raw
Quoted 13 lines · Sergej Sawazki

Am 04.05.2015 um 13:25 schrieb Mark Brown:

Quoted 11 lines · Sergej Sawazki

sound/soc/codecs/wm8741.c static int wm8741_reset(struct snd_soc_codec *codec) · line 110

Quoted 7 lines
sound/soc/codecs/wm8741.c +6 -0
+static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = {
+	SOC_SINGLE_TLV("Fine Playback Volume Right", WM8741_DACRLSB_ATTENUATION,
+		1, 255, 1, dac_tlv_fine),
+	SOC_SINGLE_TLV("Playback Volume Right", WM8741_DACRMSB_ATTENUATION,
+		0, 511, 1, dac_tlv),
+};

Please follow the control naming standard in ControlNames.txt: all volume controls must have Volume as the last word in the name.

Quoted 4 lines

Thanks for this information. I would suggest "Right Fine Playback Volume". Where "Right" is the "CHANNEL" from ControlNames.txt. However, there is no "Right" in the "CHANNEL" section. What do you think?

If the device is in a mono mode it shouldn't have Left or Right in the control name at all.

Quoted 10 lines
Quoted 9 lines

sound/soc/codecs/wm8741.c static struct snd_soc_dai_driver wm8741_dai = { · line 417

Quoted 5 lines
sound/soc/codecs/wm8741.c +1 -1
 	.playback = {
 		.stream_name = "Playback",
-		.channels_min = 2,  /* Mono modes not yet supported */
+		.channels_min = 1,
 		.channels_max = 2,

This should be varying with the platform data: in the mono modes we can't do stereo and I suspect the stereo modes may have issues with mono.

Quoted 3 lines

I think this should be always ".channels_min = 2". In "mono mode" the DAC plays either the right or the left channel, however the I2S signal is expected to be stereo.

Does the device only do I2S or can it do DSP modes as well (and if it does are they OK with an actual mono signal)?

#5 lore raw

Am 5. Mai 2015 13:22:39 MESZ, schrieb Mark Brown <[email protected]>:

Quoted 17 lines · Sergej Sawazki
Quoted 4 lines

Am 04.05.2015 um 13:25 schrieb Mark Brown:

Quoted 3 lines · Sergej Sawazki
Quoted 2 lines

+static const struct snd_kcontrol_new

wm8741_snd_controls_mono_right[] = {

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	SOC_SINGLE_TLV("Fine Playback Volume Right",

WM8741_DACRLSB_ATTENUATION,

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		1, 255, 1, dac_tlv_fine),
+	SOC_SINGLE_TLV("Playback Volume Right",

WM8741_DACRMSB_ATTENUATION,

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		0, 511, 1, dac_tlv),
+};

Please follow the control naming standard in ControlNames.txt: all volume controls must have Volume as the last word in the name.

Quoted 7 lines
Quoted 4 lines

Thanks for this information. I would suggest "Right Fine Playback Volume". Where "Right" is the "CHANNEL" from ControlNames.txt. However, there is no "Right" in the "CHANNEL" section. What do you think?

If the device is in a mono mode it shouldn't have Left or Right in the control name at all.

The mono mode of the device should not be confused with the ALSA mono mode. If the device is in mono mode it either plays the left (mono left mode) or the right (mono right mode) channel.

My board has two of this DACs (left and right channel). The control names should be different, hence my suggestion for the "Left" and "Right" prefixes.

Another approach would be to say that the machine driver is responsible for mixer controls if the devices are in mono mode. What do you think?

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

sound/soc/codecs/wm8741.c static struct snd_soc_dai_driver wm8741_dai = { · line 417

Quoted 5 lines
sound/soc/codecs/wm8741.c +1 -1
 	.playback = {
 		.stream_name = "Playback",
-		.channels_min = 2,  /* Mono modes not yet supported */
+		.channels_min = 1,
 		.channels_max = 2,

This should be varying with the platform data: in the mono modes we can't do stereo and I suspect the stereo modes may have issues with mono.

Quoted 6 lines
Quoted 3 lines

I think this should be always ".channels_min = 2". In "mono mode" the DAC plays either the right or the left channel, however the I2S signal is expected to be stereo.

Does the device only do I2S or can it do DSP modes as well (and if it does are they OK with an actual mono signal)?

It can do DSP A and B, but they do not support an actual mono signal (left + right only).

Signature · 1 line
Sergej
maintainer
#6 lore raw
Quoted 8 lines · Sergej Sawazki

The mono mode of the device should not be confused with the ALSA mono mode. If the device is in mono mode it either plays the left (mono left mode) or the right (mono right mode) channel.

My board has two of this DACs (left and right channel). The control names should be different, hence my suggestion for the "Left" and "Right" prefixes.

That's fine and totally normal.

Quoted 3 lines

Another approach would be to say that the machine driver is responsible for mixer controls if the devices are in mono mode. What do you think?

Yes, the machine driver should do this - you may have left and right on your board but these configurations are for example often used with 5.1 systems.

#7 lore raw

Am 5. Mai 2015 15:57:31 MESZ, schrieb Mark Brown <[email protected]>:

Quoted 13 lines · Sergej Sawazki
Quoted 9 lines

The mono mode of the device should not be confused with the ALSA mono mode. If the device is in mono mode it either plays the left (mono left mode) or the right (mono right mode) channel.

My board has two of this DACs (left and right channel). The control names should be different, hence my suggestion for the "Left" and "Right" prefixes.

That's fine and totally normal.

Quoted 7 lines
Quoted 3 lines

Another approach would be to say that the machine driver is responsible for mixer controls if the devices are in mono mode. What do you think?

Yes, the machine driver should do this - you may have left and right on your board but these configurations are for example often used with 5.1 systems.

Good point. Thanks. I am going to resend the patch as v2.