Skip to contentSkip to conversation

ASoC: pandora: switch clock back to internal on stop

PATCH In review Grazvydas Ignotas 4 participants 8 messages Feb 18, 2012 – Feb 22, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: pandora: switch clock back to internal on stop

For some reason, OMAP doesn't enter lower power states with functional clock (CLKS) source set to external, so switch it back to internal when done playing.

---
 sound/soc/omap/omap3pandora.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
sound/soc/omap/omap3pandora.c +22 -0
index 07794bd..1be26df 100644
@@ -77,6 +77,27 @@ static int omap3pandora_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+static int omap3pandora_hw_free(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	int ret;
+
+	/*
+	 * For some reason, if we don't set clock back to internal, OMAP power
+	 * saving features don't work properly (per power domain doesn't enter
+	 * lower power states). Switch it back until better solution is found.
+	 */
+	ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_FCLK,
+				     0, SND_SOC_CLOCK_IN);
+	if (ret < 0) {
+		pr_err(PREFIX "can't set cpu system clock\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static int omap3pandora_dac_event(struct snd_soc_dapm_widget *w,
 	struct snd_kcontrol *k, int event)
 {
@@ -201,6 +222,7 @@ static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
 
 static struct snd_soc_ops omap3pandora_ops = {
 	.hw_params = omap3pandora_hw_params,
+	.hw_free = omap3pandora_hw_free,
 };
 
 /* Digital audio interface glue - connects codec <--> CPU */
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 5 lines · Grazvydas Ignotas

For some reason, OMAP doesn't enter lower power states with functional clock (CLKS) source set to external, so switch it back to internal when done playing.

Might be an idea to do this in the McBSP driver - have it do the switch transparently, then flip back when the port is brought up again?

#2 lore raw
Quoted 9 lines · Mark Brown
Quoted 5 lines · Grazvydas Ignotas

For some reason, OMAP doesn't enter lower power states with functional clock (CLKS) source set to external, so switch it back to internal when done playing.

Might be an idea to do this in the McBSP driver - have it do the switch transparently, then flip back when the port is brought up again?

Maybe, but I think pandora is the only one using external clock in mainline and mcbsp currently doesn't track this state, just does a register write. If you still prefer it on mcbsp side, I can do it after Peter's mcbsp merge work is finished I guess.

Signature · 5 lines
Gražvydas
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 5 lines · Grazvydas Ignotas
Quoted 2 lines

Might be an idea to do this in the McBSP driver - have it do the switch transparently, then flip back when the port is brought up again?

Maybe, but I think pandora is the only one using external clock in mainline

I have patch on top of the mcbsp merge series which allows users (developers) to switch between McBSP2 master/slave configuration on Beagle. It will have two PCM:
0 is the current configuration (twl4030 master, mcbsp2 slave) 1 is the same as with pandora (twl4030 slave, mcbsp2 master - CLKS pin is the source for the SRG).
With this I can help to track down the suspend issue you see on Pandora. I hope.

Quoted 2 lines

and mcbsp currently doesn't track this state, just does a register write.

I was also thinking that this should be handled by the mcbsp driver. I'm really not sure why we need to do this - it might be clock/hwmod issue at the end.
We could do this unconditionally when all streams has been stopped on the mcbsp port IMHO.

Quoted 2 lines

If you still prefer it on mcbsp side, I can do it after Peter's mcbsp merge work is finished I guess.

I'll wait for Janusz for OMAP1 results before I send the v2 series. So far so good: now the Pandora like configuration also works.

Signature · 5 lines
Péter
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
Quoted 7 lines · Peter Ujfalusi
Quoted 5 lines · Grazvydas Ignotas
Quoted 2 lines

Might be an idea to do this in the McBSP driver - have it do the switch transparently, then flip back when the port is brought up again?

Maybe, but I think pandora is the only one using external clock in mainline

Quoted 8 lines

I have patch on top of the mcbsp merge series which allows users (developers) to switch between McBSP2 master/slave configuration on Beagle. It will have two PCM:
0 is the current configuration (twl4030 master, mcbsp2 slave) 1 is the same as with pandora (twl4030 slave, mcbsp2 master - CLKS pin is the source for the SRG).
With this I can help to track down the suspend issue you see on Pandora. I hope.

Sounds good, I can wait for this I guess.

Slightly off-topic: would you mind getting OSS emulation working on OMAP? We talked about it some years back.. I'm still carrying this hack in pandora tree:
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=7717278f6e

We have found in-kernel OSS emulation to have best compatibility and performance, and the later is important for a games machine with an aging SoC..

The other issue with pandora on mainline is frequent buffer underflows just after the stream starts. Games tend to use tiny buffers with a goal to have low audio latency, and this often ends up with endless loop of stream start and underflow events. We used this hack on earlier kernels (the comment is probably not entirely correct, and fifo_samples should be multiplied by channels I guess):
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=d3ef3adfa

This can of course be fixed in a program itself, but the idea was to reduce effort needed to port things to pandora, and now I'll have to be carrying this for compatibility, but I wonder how that looks from mainline point of view.

Signature · 5 lines
Gražvydas
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 1 line · Grazvydas Ignotas

Sounds good, I can wait for this I guess.

I just wonder why not just switch to twl4030 master scenario for pandora? I know that there are products out there using this scenario (I mean real consumer devices), and AFAIK they work pretty well. What is the main reason to keep pandora in McBSP master mode? What is the benefit for the platform? Can you send the per domain to suspend during audio playback?

Quoted 4 lines

Slightly off-topic: would you mind getting OSS emulation working on OMAP? We talked about it some years back.. I'm still carrying this hack in pandora tree:
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=7717278f6e

Hrm, yes I remember. Was it so that the OSS emulation calls hw_params several times, each with different parameter to configure, or something?

If you do not have duplex operation this might be OK to do, but there are cases when we return -EINVAL if a parameter is not correct... To be honest I have not used OSS emulation for quite a long time, and systems tend to use PulseAudio or AudioFlinger nowdays.
If it is really important for you we can take a look, it might bring enhancements for other users as well at the end.

We also have the same mechanism in place in omap-mcbsp.c (to not allow reconfiguration of the mcbsp port) so 'fixing' twl4030 might not be enough for you.

Quoted 3 lines

We have found in-kernel OSS emulation to have best compatibility and performance, and the later is important for a games machine with an aging SoC..

Is it still the case?

Quoted 7 lines

The other issue with pandora on mainline is frequent buffer underflows just after the stream starts. Games tend to use tiny buffers with a goal to have low audio latency, and this often ends up with endless loop of stream start and underflow events. We used this hack on earlier kernels (the comment is probably not entirely correct, and fifo_samples should be multiplied by channels I guess):
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=d3ef3adfa

So we want to make sure that application written at least FIFO amount of data into the buffer before we start the McBSP/DMA, right? Not sure if it is a valid thing to just override the start_threshold. But if we do something like this it might be better to have support in the core (ASoC, or even in ALSA)..

Quoted 4 lines

This can of course be fixed in a program itself, but the idea was to reduce effort needed to port things to pandora, and now I'll have to be carrying this for compatibility, but I wonder how that looks from mainline point of view.

We can try to figure out something, but I have a feeling that this would be useful for other platforms as well.

Signature · 5 lines
Péter
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 8 lines · Peter Ujfalusi
Quoted 1 line · Grazvydas Ignotas

Sounds good, I can wait for this I guess.

I just wonder why not just switch to twl4030 master scenario for pandora? I know that there are products out there using this scenario (I mean real consumer devices), and AFAIK they work pretty well. What is the main reason to keep pandora in McBSP master mode? What is the benefit for the platform?

Pandora uses 256*fs clock for it's external DAC, which was added for improved audio quality (mcbsp2 is connected there instead of twl). twl4030 can only provide 256*fs clock in slave mode. So twl4030 is not used for playback, but is still used for audio in.

Speaking of which, there is crazy amount of twl4030 audio controls available that are not relevant to pandora, since these things are not connected, confusing the users. I think there were plans to hide snd_soc_dapm_nc_pin() marked things, but that never materialized?

Quoted 2 lines

Can you send the per domain to suspend
during audio playback?

I suppose not, pm_debug counters are not increasing while audio is playing. Is that supposed to be possible?

Quoted 7 lines
Quoted 4 lines

Slightly off-topic: would you mind getting OSS emulation working on OMAP? We talked about it some years back.. I'm still carrying this hack in pandora tree:
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=7717278f6e

Hrm, yes I remember. Was it so that the OSS emulation calls hw_params several times, each with different parameter to configure, or something?

Yes, OSS has separate ioctl's for setting rate, channels, etc, each of which translates separate hw_params call, and twl4030 only accepts first one, so most things end up unconfigured. What's worse the program isn't even told some parameters were not set because there is no error returned.

Quoted 6 lines

If you do not have duplex operation this might be OK to do, but there are cases when we return -EINVAL if a parameter is not correct... To be honest I have not used OSS emulation for quite a long time, and systems tend to use PulseAudio or AudioFlinger nowdays.
If it is really important for you we can take a look, it might bring enhancements for other users as well at the end.

At least for now we are using kernel OSS emulation, so it would be nice to have it working. PulseAudio was problematic some time back, maybe it's good now, but it's hard to imagine adding another audio layer would not affect performance. Additional latency or CPU use is not good for a games console, even if it's small.

Quoted 3 lines

We also have the same mechanism in place in omap-mcbsp.c (to not allow reconfiguration of the mcbsp port) so 'fixing' twl4030 might not be enough for you.

True, it seems first hw_params matches all others in most cases so it was not an issue.

Quoted 5 lines
Quoted 3 lines

We have found in-kernel OSS emulation to have best compatibility and performance, and the later is important for a games machine with an aging SoC..

Is it still the case?

Well at least for performance I think it still is, and pandora is stuck with OMAP3s at least for a while more.

Quoted 10 lines
Quoted 7 lines

The other issue with pandora on mainline is frequent buffer underflows just after the stream starts. Games tend to use tiny buffers with a goal to have low audio latency, and this often ends up with endless loop of stream start and underflow events. We used this hack on earlier kernels (the comment is probably not entirely correct, and fifo_samples should be multiplied by channels I guess):
http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff;h=d3ef3adfa

So we want to make sure that application written at least FIFO amount of data into the buffer before we start the McBSP/DMA, right?

I think it should be at least 2x fifo as IIRC underflow condition is triggered when there is nothing left to DMA.

Some retro console emulators work like this:
while (1) {
emulate the 'guest' CPU for 1 video frame
generate 1 video frame's worth of audio data and send to host hardware draw video frame, read controls, etc
sleep if there is time left
}

So in this case host audio hardware is always kept very close to underflow condition, but has very low audio latency. This doesn't work well with current mainline.

Quoted 3 lines

Not sure if it is a valid thing to just override the start_threshold. But if we do something like this it might be better to have support in the core (ASoC, or even in ALSA)..

Sure, that would work for us too.

Quoted 7 lines
Quoted 4 lines

This can of course be fixed in a program itself, but the idea was to reduce effort needed to port things to pandora, and now I'll have to be carrying this for compatibility, but I wonder how that looks from mainline point of view.

We can try to figure out something, but I have a feeling that this would be useful for other platforms as well.

Sounds promising.

Signature · 5 lines
Gražvydas
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
In reply to Peter Ujfalusi
Quoted 7 lines · Peter Ujfalusi

I have patch on top of the mcbsp merge series which allows users (developers) to switch between McBSP2 master/slave configuration on Beagle. It will have two PCM:
0 is the current configuration (twl4030 master, mcbsp2 slave) 1 is the same as with pandora (twl4030 slave, mcbsp2 master - CLKS pin is the source for the SRG).

Side note: Don't forget the FCLK as a SRG source for McBSP master case. It's quite useful when bringing up and testing new hw.

Signature · 1 line
jarkko