alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: tlv320aic32x4 Codec ADC and DAC must shutdown to alter clocks
Date: Wed, 12 Mar 2014 16:08:40 +0100	[thread overview]
Message-ID: <53207878.2060107@topic.nl> (raw)

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.


-- 
Mike Looijmans

             reply	other threads:[~2014-03-12 15:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12 15:08 Mike Looijmans [this message]
2014-03-12 23:31 ` tlv320aic32x4 Codec ADC and DAC must shutdown to alter clocks Mark Brown
2014-03-13  7:09   ` Mike Looijmans
2014-03-13 14:04     ` Mark Brown
2014-03-14  9:47       ` Mike Looijmans
2014-03-28 14:13         ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53207878.2060107@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).