alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Matt Flax <flatmax@flatmax.org>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	alsa-devel@alsa-project.org
Subject: Re: ASoc: soc_core.c stream direction from snd_soc_dai
Date: Fri, 13 Mar 2020 14:56:40 +1100	[thread overview]
Message-ID: <52e1a640-b46f-b494-2047-849c1999eb28@flatmax.org> (raw)
In-Reply-To: <73148789-58f7-2228-ae42-465cdafcff4c@flatmax.org>


On 13/3/20 10:19 am, Matt Flax wrote:
>
> On 13/3/20 9:55 am, Pierre-Louis Bossart wrote:
>>
>>
>> On 3/11/20 5:54 PM, Matt Flax wrote:
>>> Hi there,
>>>
>>> A large number of audio codecs allow different formats for playback 
>>> and capture. This becomes very useful when there are different 
>>> latencies between playback and capture hardware data lines. For 
>>> example digital isolation chips typically have a 1 bit delay in 
>>> propagation as the bit clock rate gets faster for higher sample 
>>> rates. By setting the capture and playback formats to differ by one 
>>> or two bit clock cycles, the delay problem is solved.
>>>
>>> There doesn't seem to be a simple way to detect stream direction in 
>>> the codec driver's set_fmt function.
>>>
>>> The snd_soc_runtime_set_dai_fmt function :
>>>
>>> https://github.com/torvalds/linux/blob/master/sound/soc/soc-core.c#L1480 
>>>
>>>
>>> calls the snd_soc_dai_set_fmt function :
>>>
>>> https://github.com/torvalds/linux/blob/master/sound/soc/soc-dai.c#L101
>>>
>>> which calls the set_fmt function :
>>>
>>> https://github.com/torvalds/linux/blob/master/include/sound/soc-dai.h#L189 
>>>
>>>
>>>
>>> The snd_soc_dai_ops set_fmt function is defined as :
>>>
>>>      int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
>>>
>>>
>>> Is there a simple way to find the stream direction from a snd_soc_dai ?
>>>
>>> If the stream direction can be detected then the playback and 
>>> capture formats can be set independently for the codec.
>>>
>>> It there a different way to set the playback and capture formats for 
>>> the codec independently at runtime, depending on the sample rate ?
>>
>> FWIW I remember a discussion in the past on how to deal with 
>> interfaces that may have different clocks sources for capture and 
>> playback (typically with the 6-pin version of I2S/TDM), and the 
>> answer was: use two dais, with one dealing with capture and the other 
>> with playback.
>>
>> I would bet this applies for the format as well. If you use a DAI 
>> that can do both directions, then indeed there's no obvious way to 
>> specify that formats or clock ownership could be different between 
>> the two directions.
>>
>> It would probably make sense anyway to have a representation with two 
>> dais, e.g. the codec capture dai receives data from somewhere and the 
>> codec playback dai forwards it to another destination.
>>
> I think I get it ...
>
> This approach would keep extra stream selective functionality out of 
> soc-dai.c. That is probably a good thing for the simplicity of the core.
>
> A machine driver could then call snd_soc_dai_set_fmt passing in the 
> correct codec_dai from the codec_dais array for the stream they want 
> to operate on.
>
In an example case, cs4271 ... how do we enforce symmetric rates ?

static struct snd_soc_dai_driver cs4271_dai[] = {
     {
         .name = "cs4271-hifi-p",
         .playback = {
             .stream_name    = "Playback",
             .channels_min    = 2,
             .channels_max    = 2,
             .rates        = CS4271_PCM_RATES,
             .formats    = CS4271_PCM_FORMATS,
         },
         .ops = &cs4271_dai_ops,
         .symmetric_rates = 1,
     },
     {
         .name = "cs4271-hifi-c",
         .capture = {
             .stream_name    = "Capture",
             .channels_min    = 2,
             .channels_max    = 2,
             .rates        = CS4271_PCM_RATES,
             .formats    = CS4271_PCM_FORMATS,
         },
         .ops = &cs4271_dai_ops,
         .symmetric_rates = 1,
     }
};



> Matt
>
>
>> My 2 cents
>> -Pierre

  reply	other threads:[~2020-03-13  3:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 22:54 ASoc: soc_core.c stream direction from snd_soc_dai Matt Flax
2020-03-12 22:55 ` Pierre-Louis Bossart
2020-03-12 23:19   ` Matt Flax
2020-03-13  3:56     ` Matt Flax [this message]
2020-03-13  9:59       ` Lars-Peter Clausen
2021-02-20  9:29         ` Shengjiu Wang
2021-02-23 13:57           ` Mark Brown
2021-02-26  5:58             ` Shengjiu Wang
2021-02-26 17:06               ` 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=52e1a640-b46f-b494-2047-849c1999eb28@flatmax.org \
    --to=flatmax@flatmax.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    /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).