* ASoc: soc_core.c stream direction from snd_soc_dai @ 2020-03-11 22:54 Matt Flax 2020-03-12 22:55 ` Pierre-Louis Bossart 0 siblings, 1 reply; 9+ messages in thread From: Matt Flax @ 2020-03-11 22:54 UTC (permalink / raw) To: alsa-devel 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 ? Matt ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 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 0 siblings, 1 reply; 9+ messages in thread From: Pierre-Louis Bossart @ 2020-03-12 22:55 UTC (permalink / raw) To: Matt Flax, alsa-devel 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. My 2 cents -Pierre ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2020-03-12 22:55 ` Pierre-Louis Bossart @ 2020-03-12 23:19 ` Matt Flax 2020-03-13 3:56 ` Matt Flax 0 siblings, 1 reply; 9+ messages in thread From: Matt Flax @ 2020-03-12 23:19 UTC (permalink / raw) To: Pierre-Louis Bossart, alsa-devel 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. Matt > My 2 cents > -Pierre ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2020-03-12 23:19 ` Matt Flax @ 2020-03-13 3:56 ` Matt Flax 2020-03-13 9:59 ` Lars-Peter Clausen 0 siblings, 1 reply; 9+ messages in thread From: Matt Flax @ 2020-03-13 3:56 UTC (permalink / raw) To: Pierre-Louis Bossart, alsa-devel 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2020-03-13 3:56 ` Matt Flax @ 2020-03-13 9:59 ` Lars-Peter Clausen 2021-02-20 9:29 ` Shengjiu Wang 0 siblings, 1 reply; 9+ messages in thread From: Lars-Peter Clausen @ 2020-03-13 9:59 UTC (permalink / raw) To: Matt Flax, Pierre-Louis Bossart, alsa-devel On 3/13/20 4:56 AM, Matt Flax wrote: > > 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 ? You'd have to do this manually in your driver. The core itself does not support synchronizing streams on different DAIs. You can do this by saving the rate when it is set on the first stream and then apply a constraint to the second stream using snd_pcm_hw_constraint_single() it the driver's startup() callback. Have a look at the uda134x.c or twl4030.c driver as an example. But I think Pierre was mainly talking about the case where there are separate clocks for each direction and the rates don't have to be the same. I believe long term it might make sense to extend the core to allow different formats for input and output direction on the same DAI. - Lars ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2020-03-13 9:59 ` Lars-Peter Clausen @ 2021-02-20 9:29 ` Shengjiu Wang 2021-02-23 13:57 ` Mark Brown 0 siblings, 1 reply; 9+ messages in thread From: Shengjiu Wang @ 2021-02-20 9:29 UTC (permalink / raw) To: Lars-Peter Clausen, Mark Brown Cc: alsa-devel, Pierre-Louis Bossart, Matt Flax On Fri, Mar 13, 2020 at 6:01 PM Lars-Peter Clausen <lars@metafoo.de> wrote: > > On 3/13/20 4:56 AM, Matt Flax wrote: > > > > 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 ? > > You'd have to do this manually in your driver. The core itself does not > support synchronizing streams on different DAIs. > > You can do this by saving the rate when it is set on the first stream > and then apply a constraint to the second stream using > snd_pcm_hw_constraint_single() it the driver's startup() callback. > > Have a look at the uda134x.c or twl4030.c driver as an example. > > But I think Pierre was mainly talking about the case where there are > separate clocks for each direction and the rates don't have to be the > same. I believe long term it might make sense to extend the core to > allow different formats for input and output direction on the same DAI. > Sorry for resuming this old thread. I have the same requirement for supporting different formats for input and output on the same DAI. One of the suggestions is to use two DAIs. but sometimes the CPU/CODEC may have the same format for playback and capture, then one DAI is enough. it means that we need to define 3 DAIs for the CPU/CODEC, one supports playback and capture, another two support capture and playback separately, is it some kind of duplicate? So I'd like to extend the set_fmt() interface, but this impacts all the drivers. Best regards Wang shengjiu ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2021-02-20 9:29 ` Shengjiu Wang @ 2021-02-23 13:57 ` Mark Brown 2021-02-26 5:58 ` Shengjiu Wang 0 siblings, 1 reply; 9+ messages in thread From: Mark Brown @ 2021-02-23 13:57 UTC (permalink / raw) To: Shengjiu Wang Cc: alsa-devel, Lars-Peter Clausen, Pierre-Louis Bossart, Matt Flax [-- Attachment #1: Type: text/plain, Size: 964 bytes --] On Sat, Feb 20, 2021 at 05:29:03PM +0800, Shengjiu Wang wrote: > One of the suggestions is to use two DAIs. but sometimes the > CPU/CODEC may have the same format for playback and capture, > then one DAI is enough. it means that we need to define 3 DAIs > for the CPU/CODEC, one supports playback and capture, another > two support capture and playback separately, is it some kind of > duplicate? > So I'd like to extend the set_fmt() interface, but this impacts all > the drivers. I'm not sure having two DAIs is an issue if you have them running the smae format - does it cause any practical problems or is it just that it doesn't seem elegant to you? There were quite a few devices that pretty much just had two unidirectional DAIs, in those cases it seems like a sensible representation for the hardware. If you can set unrelated formats on transmit and receive then it's not clear that it's actually the same DAI in anything except logical labelling. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2021-02-23 13:57 ` Mark Brown @ 2021-02-26 5:58 ` Shengjiu Wang 2021-02-26 17:06 ` Mark Brown 0 siblings, 1 reply; 9+ messages in thread From: Shengjiu Wang @ 2021-02-26 5:58 UTC (permalink / raw) To: Mark Brown Cc: alsa-devel, Lars-Peter Clausen, Pierre-Louis Bossart, Matt Flax On Tue, Feb 23, 2021 at 9:58 PM Mark Brown <broonie@kernel.org> wrote: > > On Sat, Feb 20, 2021 at 05:29:03PM +0800, Shengjiu Wang wrote: > > > One of the suggestions is to use two DAIs. but sometimes the > > CPU/CODEC may have the same format for playback and capture, > > then one DAI is enough. it means that we need to define 3 DAIs > > for the CPU/CODEC, one supports playback and capture, another > > two support capture and playback separately, is it some kind of > > duplicate? > > > So I'd like to extend the set_fmt() interface, but this impacts all > > the drivers. > > I'm not sure having two DAIs is an issue if you have them running the > smae format - does it cause any practical problems or is it just that it > doesn't seem elegant to you? There were quite a few devices that pretty > much just had two unidirectional DAIs, in those cases it seems like a > sensible representation for the hardware. If you can set unrelated > formats on transmit and receive then it's not clear that it's actually > the same DAI in anything except logical labelling. When an i2s device, Sometimes it is connected as async mode, there is different clock for tx and rx then there should be two DAIs, Sometimes it is connected as sync mode, then there should be one DAI. So we need to register different DAIs according to the async or sync mode when the driver probes. right? best regards wang shengjiu ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ASoc: soc_core.c stream direction from snd_soc_dai 2021-02-26 5:58 ` Shengjiu Wang @ 2021-02-26 17:06 ` Mark Brown 0 siblings, 0 replies; 9+ messages in thread From: Mark Brown @ 2021-02-26 17:06 UTC (permalink / raw) To: Shengjiu Wang Cc: alsa-devel, Lars-Peter Clausen, Pierre-Louis Bossart, Matt Flax [-- Attachment #1: Type: text/plain, Size: 1078 bytes --] On Fri, Feb 26, 2021 at 01:58:12PM +0800, Shengjiu Wang wrote: > On Tue, Feb 23, 2021 at 9:58 PM Mark Brown <broonie@kernel.org> wrote: > > I'm not sure having two DAIs is an issue if you have them running the > > smae format - does it cause any practical problems or is it just that it > > doesn't seem elegant to you? There were quite a few devices that pretty > > much just had two unidirectional DAIs, in those cases it seems like a > > sensible representation for the hardware. If you can set unrelated > > formats on transmit and receive then it's not clear that it's actually > > the same DAI in anything except logical labelling. > When an i2s device, Sometimes it is connected as async mode, there is > different clock for tx and rx then there should be two DAIs, Sometimes > it is connected as sync mode, then there should be one DAI. > So we need to register different DAIs according to the async or sync mode > when the driver probes. right? You should just be able to connect the same device twice for the other end of the link, once for Tx and once for Rx. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-02-26 17:08 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 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
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).