My general question: If "my" codec needs to alter the state of the DAPM tree, how can the codec ask or inform the DAPM components of this?
This problem occurs on tlv320aic32x4 codecs, but probably applies to many others as well.
Using the tlv320aic32x4 a simple loop like this may "crash" the codec:
while true do speaker-test -c 2 -t sine -l 1 -r 48000 > /dev/null speaker-test -c 2 -t sine -l 1 -r 44100 > /dev/null done
A "crash" means, in this respect that the chip loses some of its settings, malfunctions and often it results in NACKs on I2C commands.
I've been trying to properly fix this, but it just won't fit in the framework.
The cause is that the DAPM starts the DAC and/or ADC cores while the clocks aren't running, and stops the clocks before shutting down the cores.
There is the overall bug of the driver that starts and stops all the clocks in the aic32x4_set_bias_level in the wrong order - it should start them from source to sink, and stop them in the opposite direction, so the PLL must be the first to start and last to stop. Apparently this isn't really critical as I've never observed failure as a result of this.
What I cannot fix is that changing the parameters (like clock frequency) must stop the DAC core.
The DAPM framework just sets the BIAS to "ON" only once, and does not shut down until after a time out. Which is good. But if the next stream to play needs a different clock setting, the DAC must be stopped first, the code must wait until the DAC has powered down, and then the clocks can be stopped and altered. When all settings are done, the DAC can be restarted.
Starting the DAC is the DAPM's task, it's this line that does the job:
SND_SOC_DAPM_DAC("Left DAC", "Left Playback", AIC32X4_DACSETUP, 7, 0),
I can detect the change in the hw_params, and on the first stream to play, this is called while still in STANDBY or lower levels. However, when the codec is already in ON bias level, how do I tell DAPM that I had to shut down the DAC in order to change the parameters? Just toggling the related bits will keep the DAC powered down. A routine to store and restore the power state is possible, but very ineffective. Especially since the "I must shutdown" conclusion can also be in the clock setting routine. That would result in multiple down-up cycles.