[alsa-devel] [PATCH] ASoC: TWL4030: Disable DACs in analog loopback
In analog loopback mode, DACs should not be enabled. For that reason, DAC widgets (DAC Right1, DAC Left1, DAC Right2, DAC Left2) will power DACs only during playback.
Analog loopback requires to set a master enable bit when any of the analog bypass switches are enabled.
Signed-off-by: Misael Lopez Cruz x0052729@ti.com --- sound/soc/codecs/twl4030.c | 34 +++++++++++++++++++++------------- 1 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index efa1a80..d3184a0 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -64,7 +64,7 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { 0x00, /* REG_VRXPGA (0x14) */ 0x00, /* REG_VSTPGA (0x15) */ 0x00, /* REG_VRX2ARXPGA (0x16) */ - 0x0c, /* REG_AVDAC_CTL (0x17) */ + 0x00, /* REG_AVDAC_CTL (0x17) */ 0x00, /* REG_ARX2VTXPGA (0x18) */ 0x00, /* REG_ARXL1_APGA_CTL (0x19) */ 0x00, /* REG_ARXR1_APGA_CTL (0x1A) */ @@ -585,7 +585,7 @@ static int bypass_event(struct snd_soc_dapm_widget *w, struct soc_mixer_control *m = (struct soc_mixer_control *)w->kcontrols->private_value; struct twl4030_priv *twl4030 = w->codec->private_data; - unsigned char reg; + unsigned char reg, misc;
reg = twl4030_read_reg_cache(w->codec, m->reg);
@@ -605,6 +605,14 @@ static int bypass_event(struct snd_soc_dapm_widget *w, twl4030->bypass_state &= ~(1 << (m->shift ? 5 : 4)); }
+ /* Enable master analog loopback mode if any analog switch is enabled*/ + misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1); + if (twl4030->bypass_state & 0xF) + misc |= TWL4030_FMLOOP_EN; + else + misc &= ~TWL4030_FMLOOP_EN; + twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc); + if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) { if (twl4030->bypass_state) twl4030_codec_mute(w->codec, 0); @@ -927,13 +935,13 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
/* DACs */ SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", - SND_SOC_NOPM, 0, 0), + TWL4030_REG_AVDAC_CTL, 0, 0), SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback", - SND_SOC_NOPM, 0, 0), + TWL4030_REG_AVDAC_CTL, 1, 0), SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback", - SND_SOC_NOPM, 0, 0), + TWL4030_REG_AVDAC_CTL, 2, 0), SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", - SND_SOC_NOPM, 0, 0), + TWL4030_REG_AVDAC_CTL, 3, 0), SND_SOC_DAPM_DAC("DAC Voice", "Voice Playback", TWL4030_REG_AVDAC_CTL, 4, 0),
@@ -971,14 +979,14 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { &twl4030_dapm_dbypassr_control, bypass_event, SND_SOC_DAPM_POST_REG),
- SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL, + SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", SND_SOC_NOPM, + 0, 0, NULL, 0), + SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", SND_SOC_NOPM, + 0, 0, NULL, 0), + SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", SND_SOC_NOPM, + 0, 0, NULL, 0), + SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), - SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", TWL4030_REG_AVDAC_CTL, - 1, 0, NULL, 0), - SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", TWL4030_REG_AVDAC_CTL, - 2, 0, NULL, 0), - SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL, - 3, 0, NULL, 0),
/* Output MIXER controls */ /* Earpiece */
On Thursday 30 April 2009 10:31:20 ext Lopez Cruz, Misael wrote:
In analog loopback mode, DACs should not be enabled. For that reason, DAC widgets (DAC Right1, DAC Left1, DAC Right2, DAC Left2) will power DACs only during playback.
Analog loopback requires to set a master enable bit when any of the analog bypass switches are enabled.
I have also noticed this, also in analog loopback mode the bits in the OPTION register can be cleared, since we don't need those to have analog loopback.
But I'm afraid, this patch does break the Digital loopback, which needs the DACs to be powered, in case when the capture path is set in analog mode the ADC(s) also need to be powered.
Both analog and digital loopback connects to 'Analog XY Playback Mixer', which turns on/off the physical DAC on the given route. I have been thinking of - as a part of a big clean up - to separate these, since as you have pointed out, the DACs are not needed for the analog loopback.
Signed-off-by: Misael Lopez Cruz x0052729@ti.com
sound/soc/codecs/twl4030.c | 34 +++++++++++++++++++++------------- 1 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index efa1a80..d3184a0 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -64,7 +64,7 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { 0x00, /* REG_VRXPGA (0x14) */ 0x00, /* REG_VSTPGA (0x15) */ 0x00, /* REG_VRX2ARXPGA (0x16) */
- 0x0c, /* REG_AVDAC_CTL (0x17) */
- 0x00, /* REG_AVDAC_CTL (0x17) */ 0x00, /* REG_ARX2VTXPGA (0x18) */ 0x00, /* REG_ARXL1_APGA_CTL (0x19) */ 0x00, /* REG_ARXR1_APGA_CTL (0x1A) */
Now that we have the DAPM routing for most of the things, these defaults needs to be revisited... They are left as they were mostly, but now it is safe to turn off most of the thing by default.
@@ -585,7 +585,7 @@ static int bypass_event(struct snd_soc_dapm_widget *w, struct soc_mixer_control *m = (struct soc_mixer_control *)w->kcontrols->private_value; struct twl4030_priv *twl4030 = w->codec->private_data;
- unsigned char reg;
unsigned char reg, misc;
reg = twl4030_read_reg_cache(w->codec, m->reg);
@@ -605,6 +605,14 @@ static int bypass_event(struct snd_soc_dapm_widget *w, twl4030->bypass_state &= ~(1 << (m->shift ? 5 : 4)); }
- /* Enable master analog loopback mode if any analog switch is enabled*/
- misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1);
- if (twl4030->bypass_state & 0xF)
misc |= TWL4030_FMLOOP_EN;
- else
misc &= ~TWL4030_FMLOOP_EN;
- twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc);
Oh, so there is another register/bit to be configured to enable the analog loopback ;) I certainly missed this bit...
if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) { if (twl4030->bypass_state) twl4030_codec_mute(w->codec, 0); @@ -927,13 +935,13 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
/* DACs */ SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback",
SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback",TWL4030_REG_AVDAC_CTL, 0, 0),
SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback",TWL4030_REG_AVDAC_CTL, 1, 0),
SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback",TWL4030_REG_AVDAC_CTL, 2, 0),
SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC Voice", "Voice Playback", TWL4030_REG_AVDAC_CTL, 4, 0),TWL4030_REG_AVDAC_CTL, 3, 0),
@@ -971,14 +979,14 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { &twl4030_dapm_dbypassr_control, bypass_event, SND_SOC_DAPM_POST_REG),
- SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL,
- SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", SND_SOC_NOPM,
0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", SND_SOC_NOPM,
0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", SND_SOC_NOPM,
0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", TWL4030_REG_AVDAC_CTL,
1, 0, NULL, 0),
SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", TWL4030_REG_AVDAC_CTL,
2, 0, NULL, 0),
SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL,
3, 0, NULL, 0),
/* Output MIXER controls */ /* Earpiece */
In analog loopback mode, DACs should not be enabled. For that reason, DAC widgets (DAC Right1, DAC Left1, DAC Right2, DAC Left2) will power DACs only during playback.
Analog loopback requires to set a master enable bit when any of the analog bypass switches are enabled.
I have also noticed this, also in analog loopback mode the bits in the OPTION register can be cleared, since we don't need those to have analog loopback.
At least, the digital filters (configured in OPTION reg) are enabled when the corresponding DAC is enabled, can we attach them to a DAC somehow? Could it be a valid approach?
But I'm afraid, this patch does break the Digital loopback, which needs the DACs to be powered, in case when the capture path is set in analog mode the ADC(s) also need to be powered.
I think that digital loopback should mix TX with RX only when both digital paths are enabled, i.e. in a full-duplex scenario. I don't expect it to automatically enable DACs for me, although maybe I'm wrong and my argument breaks what digital loopback means :( Please clarify.
Both analog and digital loopback connects to 'Analog XY Playback Mixer', which turns on/off the physical DAC on the given route.
That was a part of the audio map that doesn't make much sense to me, joining analog and digital loopback.
I have been thinking of - as a part of a big clean up - to separate these, since as you have pointed out, the DACs are not needed for the analog loopback.
On Thursday 30 April 2009 12:53:20 ext Lopez Cruz, Misael wrote:
At least, the digital filters (configured in OPTION reg) are enabled when the corresponding DAC is enabled, can we attach them to a DAC somehow? Could it be a valid approach?
The digital filters corresponding to the Stereo path (ATXL1_EN, ATXR1_EN, ARXL2_EN, ARXR2_EN) can be enabled dynamically, when the: - Playback is running (enable only the ARXL2_EN, ARXR2_EN bits) - Capture is running (enable only the ATXL1_EN, ATXR1_EN bits) - Digital loopback is enabled (in pairs the ATXL1_EN/ARXL2_EN or ATXR1_EN/ARXR2_EN bits - the first pair is for left digital loopback, the second is for the right digital loopback).
But I'm afraid, this patch does break the Digital loopback, which needs the DACs to be powered, in case when the capture path is set in analog mode the ADC(s) also need to be powered.
I think that digital loopback should mix TX with RX only when both digital paths are enabled, i.e. in a full-duplex scenario.
Well, yes... short of. You can still enable the digital loopback without active stream. The TWL codec will be in the same state as it if you are using full duplex mode. The only difference is that the CPU dai is not running. The analog loopback also mixing the RX and TX data, but in the analog domain. If you have only the loopback enabled (analog or digital) the RX path is silent in both cases...
While we are here with the loopbacks: When only the analog loopback is enabled the PLL can be disabled for the codec (APLL_CTL:APLL_EN = 0). I have some preliminary implementation for this, but it needs some more tuning...
I don't expect it to automatically enable DACs for me, although maybe I'm wrong and my argument breaks what digital loopback means :( Please clarify.
You have to specifically flip the user control to enable the digital loopback, it is not done automatically.
Both analog and digital loopback connects to 'Analog XY Playback Mixer', which turns on/off the physical DAC on the given route.
That was a part of the audio map that doesn't make much sense to me, joining analog and digital loopback.
It was like that, because the TRM has no information on these loopback at all, so I have chosen this safe path (I have got the digital loopback implemented first) and marked for myself to revisit it later.
I have been thinking of - as a part of a big clean up - to separate these, since as you have pointed out, the DACs are not needed for the analog loopback.
But I'm afraid, this patch does break the Digital loopback, which needs the DACs to be powered, in case when the capture path is set in analog mode the ADC(s) also need to be powered.
I think that digital loopback should mix TX with RX only when both digital paths are enabled, i.e. in a full-duplex scenario.
Well, yes... short of. You can still enable the digital loopback without active stream. The TWL codec will be in the same state as it if you are using full duplex mode. The only difference is that the CPU dai is not running. The analog loopback also mixing the RX and TX data, but in the analog domain. If you have only the loopback enabled (analog or digital) the RX path is silent in both cases...
I got your point, thanks for the explanation. I think that we can take this part of the patch:
+ /* Enable master analog loopback mode if any analog switch is enabled*/ + misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1); + if (twl4030->bypass_state & 0xF) + misc |= TWL4030_FMLOOP_EN; + else + misc &= ~TWL4030_FMLOOP_EN; + twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc);
This bit MISC_SET_1[FMLOOP_EN] needs to set to 1 when any of the analog bypass switches are enabled. Without setting this bit, the loopback is kind of weak.
If it's fine for you, I can create a new patch for supporting the VDL analog bypass switch and add above change in that same patch.
On Thursday 30 April 2009 13:53:19 ext Lopez Cruz, Misael wrote:
I got your point, thanks for the explanation. I think that we can take this part of the patch:
- /* Enable master analog loopback mode if any analog switch is enabled*/
- misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1);
- if (twl4030->bypass_state & 0xF)
misc |= TWL4030_FMLOOP_EN;
- else
misc &= ~TWL4030_FMLOOP_EN;
- twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc);
This bit MISC_SET_1[FMLOOP_EN] needs to set to 1 when any of the analog bypass switches are enabled. Without setting this bit, the loopback is kind of weak.
If it's fine for you, I can create a new patch for supporting the VDL analog bypass switch and add above change in that same patch.
Yes, this is fine. Please send those as a separate patch (the above mentioned and the VDL analog bypass).
Thank you, Péter
participants (2)
-
Lopez Cruz, Misael
-
Peter Ujfalusi