ASoC: apple: mca: support simultaneous I2S capture on the frontend
Subsystems (3)
v2 cover ASoC: apple: mca: support simultaneous I2S capture on the frontend
Hi folks,
This is technically version 2 of a patchset that was supposed to have been applied quite some time ago, but seemingly never was. The original cover letter is as follows:
This series introduces a number of changes to the ASoC driver for the Apple MCA peripheral to enable support for bidirectional I2S. This is achieved by allowing frontends to act as clock consumers and logically ORing data input lines when multiple backends are linked to a frontend.
This allows the Texas Instruments speaker amps used on Apple Silicon Macs (Apple-specific revisions of TAS2764 and TAS2770) to send their IVSENSE data back to the SoC. Since these amps do not have any sort of integrated speaker protection logic, we must use the IVSENSE data and the Thiele/Small Parameters of the attached speaker(s) to implement our own in software.
---
It is not so bad that these patches did not end up applied, as some changes ended up being necessary:
---
Changes in v2:
- Drop readx_poll_timeout use. It ended up being unreliable. Fall back to just bumping up the delay on SERDES reset :/
- Rebase on asoc/for-next
- Drop the one patch that was applied
- Drop clock shutdown relocation patch. This was not actually required and the incorrect thing to do anyway.
---
Link to v1: https://lore.kernel.org/asahi/[email protected]/
Regards,
James
To: Martin Povišer <[email protected]>
To: Liam Girdwood <[email protected]>
To: Mark Brown <[email protected]>
To: Jaroslav Kysela <[email protected]>
To: Takashi Iwai <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Hector Martin (2):
ASoC: apple: mca: Do not mark clocks in use for non-providers
ASoC: apple: mca: Add delay after configuring clock
James Calligeros (1):
ASoC: apple: mca: increase SERDES reset delay
Martin Povišer (4):
ASoC: apple: mca: Separate data & clock port setup
ASoC: apple: mca: Factor out mca_be_get_fe
ASoC: apple: mca: Support FEs being clock consumers
ASoC: apple: mca: Support capture on multiples BEs
sound/soc/apple/mca.c | 301 +++++++++++++++++-------- 1 file changed, 208 insertions(+), 93 deletions(-)
---
base-commit: e67251245f42eb4479636d4c082cdbe60b23f5b3
change-id: 20260623-apple-audio-redux-b7b43d9c02af
Best regards,
Signature · 1 line
James Calligeros <[email protected]>
PATCH v2 1/7 ASoC: apple: mca: increase SERDES reset delay
The SERDES clusters in this peripheral take a long time to warm up. We tried polling the reset bit until cleared, however this is not a reliable signal of readiness to be configured. Only waiting ~25 us to give the cluster a chance to settle makes it work reliably.
Increase the 2 us delay to 25 us and hope we never have to do this again.
--- sound/soc/apple/mca.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/apple/mca.c +3 -3
@@ -210,10 +210,10 @@ static void mca_fe_early_trigger(struct snd_pcm_substream *substream, int cmd,SERDES_STATUS_EN |SERDES_STATUS_RST , SERDES_STATUS_RST);/* -* Experiments suggest that it takes at most ~1 us -* for the bit to clear, so wait 2 us for good measure. +* The SERDES cluster needs a bit of time to reset itself +* and settle before we start poking it. This is... slow... */ -udelay (2 ); +udelay (25 );WARN_ON (readl_relaxed (cl->base + serdes_unit +REG_SERDES_STATUS ) &SERDES_STATUS_RST ); mca_modify(cl, serdes_conf, SERDES_CONF_SYNC_SEL,
Signature · 1 line
2.54.0
PATCH v2 2/7 ASoC: apple: mca: Separate data & clock port setup
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
Up until now FEs were always the clock providers -- feeding the clocks on any ports (BEs) they are attached to. This will soon change and FEs will be allowed to be clock consumers. Once that happens, the routing of clocks and data will to some degree decouple.
In advance of the change, make preparations:
* Narrow down semantics of what was formerly the 'port_driver' field to refer to clocks only.
* On 'startup' of BEs, separate the clock and data aspects of the port setup.
--- sound/soc/apple/mca.c | 63 ++++++++++++++++--------- 1 file changed, 40 insertions(+), 23 deletions(-)
sound/soc/apple/mca.c +40 -23
@@ -133,8 +133,8 @@ struct mca_cluster {struct clk *clk_parent;struct dma_chan *dma_chans[SNDRV_PCM_STREAM_LAST +1 ]; -bool port_started[SNDRV_PCM_STREAM_LAST +1 ]; -int port_driver;/* The cluster driving this cluster's port */ +bool port_clk_started[SNDRV_PCM_STREAM_LAST +1 ]; +int port_clk_driver;/* The cluster driving this cluster's port */ bool clocks_in_use[SNDRV_PCM_STREAM_LAST +1 ];struct device_link *pd_link;
@@ -157,7 +157,7 @@ struct mca_data {struct reset_control *rstc;struct device_link *pd_link; -/* Mutex for accessing port_driver of foreign clusters */ +/* Mutex for accessing port_clk_driver of foreign clusters */ struct mutex port_mutex;int nclusters;
@@ -311,7 +311,7 @@ static bool mca_fe_clocks_in_use(struct mca_cluster *cl)for (i =0 ; i < mca->nclusters; i++) { be_cl = &mca->clusters[i]; -if (be_cl->port_driver != cl->no) +if (be_cl->port_clk_driver != cl->no)continue ;for_each_pcm_streams (stream) {
@@ -331,10 +331,10 @@ static int mca_be_prepare(struct snd_pcm_substream *substream,struct mca_cluster *fe_cl;int ret; -if (cl->port_driver <0 ) +if (cl->port_clk_driver <0 )return -EINVAL ; - fe_cl = &mca->clusters[cl->port_driver]; + fe_cl = &mca->clusters[cl->port_clk_driver];/* * Typically the CODECs we are paired with will require clocks
@@ -708,12 +708,15 @@ static const struct snd_soc_dai_ops mca_fe_ops = { .trigger = mca_fe_trigger, }; -static bool mca_be_started (struct mca_cluster *cl) +/* +* Is there a FE attached which will be feeding this port's clocks? +*/ +static bool mca_be_clk_started (struct mca_cluster *cl) {int stream;for_each_pcm_streams (stream) -if (cl->port_started[stream]) +if (cl->port_clk_started[stream])return true;return false; }
@@ -744,28 +747,38 @@ static int mca_be_startup(struct snd_pcm_substream *substream, fe_cl =mca_dai_to_cluster (snd_soc_rtd_to_cpu (fe,0 )); -if (mca_be_started (cl)) { +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +writel_relaxed (PORT_DATA_SEL_TXA (fe_cl->no), + cl->base +REG_PORT_DATA_SEL ); +mca_modify (cl,REG_PORT_ENABLES ,PORT_ENABLES_TX_DATA , +PORT_ENABLES_TX_DATA ); + } + +if (mca_be_clk_started (cl)) {/* * Port is already started in the other direction. * Make sure there isn't a conflict with another cluster -* driving the port. +* driving the port clocks. */ -if (cl->port_driver != fe_cl->no) +if (cl->port_clk_driver != fe_cl->no)return -EINVAL ; - cl->port_started[substream->stream] = true; + cl->port_clk_started[substream->stream] = true;return 0 ; } -writel_relaxed (PORT_ENABLES_CLOCKS |PORT_ENABLES_TX_DATA , - cl->base +REG_PORT_ENABLES );writel_relaxed (FIELD_PREP (PORT_CLOCK_SEL , fe_cl->no +1 ), cl->base +REG_PORT_CLOCK_SEL ); +writel_relaxed (PORT_DATA_SEL_TXA (fe_cl->no), cl->base +REG_PORT_DATA_SEL ); + +mca_modify (cl,REG_PORT_ENABLES ,PORT_ENABLES_CLOCKS , +PORT_ENABLES_CLOCKS ); +scoped_guard (mutex, &mca->port_mutex) - cl->port_driver = fe_cl->no; - cl->port_started[substream->stream] = true; + cl->port_clk_driver = fe_cl->no; + cl->port_clk_started[substream->stream] = true;return 0 ; }
@@ -776,17 +789,21 @@ static void mca_be_shutdown(struct snd_pcm_substream *substream,struct mca_cluster *cl =mca_dai_to_cluster (dai);struct mca_data *mca = cl->host; - cl->port_started[substream->stream] = false; +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +mca_modify (cl,REG_PORT_ENABLES ,PORT_ENABLES_TX_DATA ,0 ); +writel_relaxed (0 , cl->base +REG_PORT_DATA_SEL ); + } -if (!mca_be_started (cl)) { + cl->port_clk_started[substream->stream] = false; +if (!mca_be_clk_started (cl)) {/* * Were we the last direction to shutdown? -* Turn off the lights. +* Turn off the lights (clocks). */ -writel_relaxed (0 , cl->base +REG_PORT_ENABLES ); -writel_relaxed (0 , cl->base +REG_PORT_DATA_SEL ); +mca_modify (cl,REG_PORT_ENABLES ,PORT_ENABLES_CLOCKS ,0 ); +writel_relaxed (0 , cl->base +REG_PORT_CLOCK_SEL );scoped_guard (mutex, &mca->port_mutex) - cl->port_driver = -1; + cl->port_clk_driver = -1; } }
@@ -1092,7 +1109,7 @@ static int apple_mca_probe(struct platform_device *pdev) cl->host = mca; cl->no = i; cl->base = base +CLUSTER_STRIDE * i; - cl->port_driver =-1 ; + cl->port_clk_driver =-1 ; cl->clk_parent =of_clk_get (pdev->dev.of_node, i);if (IS_ERR (cl->clk_parent)) { dev_err(&pdev->dev, "unable to obtain clock %d: %ld\n",
Signature · 1 line
2.54.0
PATCH v2 3/7 ASoC: apple: mca: Factor out mca_be_get_fe
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
This is a function that we also want to use from within mca_be_shutdown, so factor it out.
--- sound/soc/apple/mca.c | 31 ++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-)
sound/soc/apple/mca.c +18 -13
@@ -721,30 +721,35 @@ static bool mca_be_clk_started(struct mca_cluster *cl)return false; } -static int mca_be_startup (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) +static struct snd_soc_pcm_runtime *mca_be_get_fe (struct snd_soc_pcm_runtime *be, +int stream) { -struct snd_soc_pcm_runtime *be =snd_soc_substream_to_rtd (substream); -struct snd_soc_pcm_runtime *fe; -struct mca_cluster *cl =mca_dai_to_cluster (dai); -struct mca_cluster *fe_cl; -struct mca_data *mca = cl->host; +struct snd_soc_pcm_runtime *fe =NULL ;struct snd_soc_dpcm *dpcm; - fe =NULL ; - -for_each_dpcm_fe (be, substream->stream, dpcm) { +for_each_dpcm_fe (be, stream, dpcm) {if (fe && dpcm->fe != fe) { -dev_err (mca->dev,"many FE per one BE unsupported\n" ); -return -EINVAL ; +dev_err (be->dev,"many FE per one BE unsupported\n" ); +return NULL ; } fe = dpcm->fe; } +return fe; +} + +static int mca_be_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *be =snd_soc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *fe =mca_be_get_fe (be, substream->stream); +struct mca_cluster *cl =mca_dai_to_cluster (dai); +struct mca_cluster *fe_cl; +struct mca_data *mca = cl->host; +if (!fe)return -EINVAL ; - fe_cl =mca_dai_to_cluster (snd_soc_rtd_to_cpu (fe,0 ));if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) {
Signature · 1 line
2.54.0
PATCH v2 4/7 ASoC: apple: mca: Support FEs being clock consumers
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
Support FEs being I2S clock consumers. This does not mean we support accepting clocks from outside the SoC (although it paves the way for that support in the future), but it means multiple FEs can attach to one BE, one being clock producer and the rest clock consumers.
This is useful for grabbing I/V sense data on some machines, since in such a scenario the format of the sense data on the I2S bus differs from that of the audio data (the two formats differing in slot width). With two FEs attached to the bus, we can split the responsibilities and command different slot widths to the two.
--- sound/soc/apple/mca.c | 129 ++++++++++++++++++++----- 1 file changed, 106 insertions(+), 23 deletions(-)
sound/soc/apple/mca.c +106 -23
@@ -133,12 +133,17 @@ struct mca_cluster {struct clk *clk_parent;struct dma_chan *dma_chans[SNDRV_PCM_STREAM_LAST +1 ]; +bool clk_provider; +bool port_clk_started[SNDRV_PCM_STREAM_LAST +1 ];int port_clk_driver;/* The cluster driving this cluster's port */ bool clocks_in_use[SNDRV_PCM_STREAM_LAST +1 ];struct device_link *pd_link; +/* In case of clock consumer FE */ +int syncgen_in_use; +unsigned int bclk_ratio;/* Masks etc. picked up via the set_tdm_slot method */
@@ -256,11 +261,32 @@ static int mca_fe_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } +static int mca_fe_get_port (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *fe =snd_soc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *be; +struct snd_soc_dpcm *dpcm; + + be =NULL ; +for_each_dpcm_be (fe, substream->stream, dpcm) { + be = dpcm->be; +break ; + } + +if (!be) +return -EINVAL ; + +return mca_dai_to_cluster (snd_soc_rtd_to_cpu (be,0 ))->no; +} +static int mca_fe_enable_clocks (struct mca_cluster *cl) {struct mca_data *mca = cl->host;int ret; +if (!cl->clk_provider) +return -EINVAL ; + ret =clk_prepare_enable (cl->clk_parent);if (ret) { dev_err(mca->dev,
@@ -332,7 +358,7 @@ static int mca_be_prepare(struct snd_pcm_substream *substream,int ret;if (cl->port_clk_driver <0 ) -return -EINVAL ; +return 0 ; fe_cl = &mca->clusters[cl->port_clk_driver];
@@ -360,7 +386,7 @@ static int mca_be_hw_free(struct snd_pcm_substream *substream,struct mca_data *mca = cl->host;struct mca_cluster *fe_cl; -if (cl->port_driver <0 ) +if (cl->port_clk_driver <0 )return -EINVAL ;/*
@@ -368,7 +394,7 @@ static int mca_be_hw_free(struct snd_pcm_substream *substream,* belong to the same PCM, accesses should have been * synchronized at ASoC level. */ - fe_cl = &mca->clusters[cl->port_driver]; + fe_cl = &mca->clusters[cl->port_clk_driver];if (!mca_fe_clocks_in_use (fe_cl))return 0 ;/* Nothing to do */
@@ -380,6 +406,57 @@ static int mca_be_hw_free(struct snd_pcm_substream *substream,return 0 ; } +static int mca_fe_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct mca_cluster *cl =mca_dai_to_cluster (dai); +struct mca_data *mca = cl->host; + +if (cl->clk_provider) +return 0 ; + +/* Turn on the cluster power domain if not already in use */ +if (!cl->syncgen_in_use) { +int port =mca_fe_get_port (substream); + + cl->pd_link =device_link_add (mca->dev, cl->pd_dev, +DL_FLAG_STATELESS |DL_FLAG_PM_RUNTIME | +DL_FLAG_RPM_ACTIVE ); +if (!cl->pd_link) { +dev_err (mca->dev, +"cluster %d: unable to prop-up power domain\n" , cl->no); +return -EINVAL ; + } + +writel_relaxed (port +6 +1 , + cl->base +REG_SYNCGEN_MCLK_SEL ); +mca_modify (cl,REG_SYNCGEN_STATUS ,SYNCGEN_STATUS_EN , +SYNCGEN_STATUS_EN ); + } + cl->syncgen_in_use |=1 << substream->stream; + +return 0 ; +} + +static int mca_fe_hw_free (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct mca_cluster *cl =mca_dai_to_cluster (dai); + +if (cl->clk_provider) +return 0 ; + + cl->syncgen_in_use &= ~(1 << substream->stream); +if (cl->syncgen_in_use) +return 0 ; + +mca_modify (cl,REG_SYNCGEN_STATUS ,SYNCGEN_STATUS_EN ,0 ); +if (cl->pd_link) +device_link_del (cl->pd_link); + +return 0 ; +} +static unsigned int mca_crop_mask (unsigned int mask,int nchans) {while (hweight32 (mask) > nchans)
@@ -505,9 +582,18 @@ static int mca_fe_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)u32 serdes_conf =0 ;u32 bitstart; -if ((fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) != -SND_SOC_DAIFMT_BP_FP ) +switch (fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) { +case SND_SOC_DAIFMT_BP_FP : + cl->clk_provider = true; +break ; + +case SND_SOC_DAIFMT_BC_FC : + cl->clk_provider = false; +break ; + +default : goto err; + }switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S :
@@ -564,24 +650,6 @@ static int mca_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)return 0 ; } -static int mca_fe_get_port (struct snd_pcm_substream *substream) -{ -struct snd_soc_pcm_runtime *fe =snd_soc_substream_to_rtd (substream); -struct snd_soc_pcm_runtime *be; -struct snd_soc_dpcm *dpcm; - - be =NULL ; -for_each_dpcm_be (fe, substream->stream, dpcm) { - be = dpcm->be; -break ; - } - -if (!be) -return -EINVAL ; - -return mca_dai_to_cluster (snd_soc_rtd_to_cpu (be,0 ))->no; -} -static int mca_fe_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params,struct snd_soc_dai *dai)
@@ -706,6 +774,8 @@ static const struct snd_soc_dai_ops mca_fe_ops = { .set_tdm_slot = mca_fe_set_tdm_slot, .hw_params = mca_fe_hw_params, .trigger = mca_fe_trigger, + .prepare = mca_fe_prepare, + .hw_free = mca_fe_hw_free, };/*
@@ -759,6 +829,9 @@ static int mca_be_startup(struct snd_pcm_substream *substream, PORT_ENABLES_TX_DATA); } +if (!fe_cl->clk_provider) +return 0 ; +if (mca_be_clk_started (cl)) {/* * Port is already started in the other direction.
@@ -791,14 +864,24 @@ static int mca_be_startup(struct snd_pcm_substream *substream,static void mca_be_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { +struct snd_soc_pcm_runtime *be =snd_soc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *fe =mca_be_get_fe (be, substream->stream);struct mca_cluster *cl =mca_dai_to_cluster (dai); +struct mca_cluster *fe_cl;struct mca_data *mca = cl->host; +if (!fe) +return ; + fe_cl =mca_dai_to_cluster (snd_soc_rtd_to_cpu (fe,0 )); +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) {mca_modify (cl,REG_PORT_ENABLES ,PORT_ENABLES_TX_DATA ,0 );writel_relaxed (0 , cl->base +REG_PORT_DATA_SEL ); } +if (!fe_cl->clk_provider) +return ; + cl->port_clk_started[substream->stream] = false;if (!mca_be_clk_started (cl)) {/*
Signature · 1 line
2.54.0
Re: [PATCH v2 4/7] ASoC: apple: mca: Support FEs being clock consumers
Quoted 41 lines · James Calligeros
From: Martin Povišer <[email protected]>
Support FEs being I2S clock consumers. This does not mean we support accepting clocks from outside the SoC (although it paves the way for that support in the future), but it means multiple FEs can attach to one BE, one being clock producer and the rest clock consumers.
This is useful for grabbing I/V sense data on some machines, since in such a scenario the format of the sense data on the I2S bus differs from that of the audio data (the two formats differing in slot width). With two FEs attached to the bus, we can split the responsibilities and command different slot widths to the two.
Signed-off-by Martin Povišer <[email protected]>Signed-off-by James Calligeros <[email protected]>--- sound/soc/apple/mca.c | 129 ++++++++++++++++++++----- 1 file changed, 106 insertions(+), 23 deletions(-)sound/soc/apple/mca.c +14
-0@@ -380,6 +406,57 @@ static int mca_be_hw_free(struct snd_pcm_substream *substream,return 0 ; } +static int mca_fe_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct mca_cluster *cl =mca_dai_to_cluster (dai); +struct mca_data *mca = cl->host; + +if (cl->clk_provider) +return 0 ; + +/* Turn on the cluster power domain if not already in use */ +if (!cl->syncgen_in_use) { +int port =mca_fe_get_port (substream); + + cl->pd_link = device_link_add(mca->dev, cl->pd_dev,
sound/soc/apple/mca.c static int mca_be_hw_free(struct snd_pcm_substream *substream, · line 432
Quoted 10 lines
sound/soc/apple/mca.c +10
-0+DL_FLAG_STATELESS |DL_FLAG_PM_RUNTIME | + DL_FLAG_RPM_ACTIVE); +if (!cl->pd_link) { +dev_err (mca->dev, +"cluster %d: unable to prop-up power domain\n" , cl->no); +return -EINVAL ; + } + +writel_relaxed (port +6 +1 , + cl->base +REG_SYNCGEN_MCLK_SEL );
Where does the "6 + 1" come from, and should it have its own #define?
-Josh
Re: [PATCH v2 4/7] ASoC: apple: mca: Support FEs being clock consumers
Hi Josh,
Quoted 5 lines · Australian Eastern Standard Time Joshua Peisach
sound/soc/apple/mca.c static int mca_be_hw_free(struct snd_pcm_substream *substream, · line 432
Quoted 2 lines · James Calligeros
sound/soc/apple/mca.c +2
-0+writel_relaxed (port +6 +1 , + cl->base +REG_SYNCGEN_MCLK_SEL );Where does the "6 + 1" come from, and should it have its own #define?
This actually only ever gets set to 0b111 (port = 0), and trying to set it to anything else breaks the machines which consume VISENSE data from the connected codecs. I will just replace this with a static value for v3, which seems to work on all the machines we currently support downstream.
Quoted 1 line
-Josh
James
PATCH v2 5/7 ASoC: apple: mca: Support capture on multiples BEs
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
When multiple BEs are linked to a FE, the former behavior was to source the data line from the DIN pin of the first BE only. Change this to ORing the DIN inputs of all linked BEs.
As long as the unused slots on each BE's line are zeroed out and the slots on the BEs don't overlap, this will work out well.
--- sound/soc/apple/mca.c | 31 +++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-)
sound/soc/apple/mca.c +14 -17
@@ -261,22 +261,19 @@ static int mca_fe_trigger(struct snd_pcm_substream *substream, int cmd,return 0 ; } -static int mca_fe_get_port (struct snd_pcm_substream *substream) +static int mca_fe_get_portmask (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *fe =snd_soc_substream_to_rtd (substream); -struct snd_soc_pcm_runtime *be;struct snd_soc_dpcm *dpcm; +int mask =0 ; - be =NULL ;for_each_dpcm_be (fe, substream->stream, dpcm) { - be = dpcm->be; -break ; - } +int no =mca_dai_to_cluster (snd_soc_rtd_to_cpu (dpcm->be,0 ))->no; -if (!be) -return -EINVAL ; + mask |=1 << no; + } -return mca_dai_to_cluster (snd_soc_rtd_to_cpu (be,0 ))->no; +return mask; }static int mca_fe_enable_clocks (struct mca_cluster *cl)
@@ -417,7 +414,7 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream,/* Turn on the cluster power domain if not already in use */ if (!cl->syncgen_in_use) { -int port =mca_fe_get_port (substream); +int port =ffs (mca_fe_get_portmask (substream)) -1 ; cl->pd_link = device_link_add(mca->dev, cl->pd_dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
@@ -467,7 +464,7 @@ static unsigned int mca_crop_mask(unsigned int mask, int nchans)static int mca_configure_serdes (struct mca_cluster *cl,int serdes_unit,unsigned int mask,int slots,int nchans, -int slot_width,bool is_tx,int port) +int slot_width,bool is_tx,int portmask) {__iomem void *serdes_base = cl->base + serdes_unit;u32 serdes_conf, serdes_conf_mask;
@@ -526,7 +523,7 @@ static int mca_configure_serdes(struct mca_cluster *cl, int serdes_unit, serdes_base + REG_RX_SERDES_SLOTMASK);writel_relaxed (~((u32 )mca_crop_mask (mask, nchans)), serdes_base +REG_RX_SERDES_SLOTMASK +0x4 ); -writel_relaxed (1 << port, +writel_relaxed (portmask, serdes_base +REG_RX_SERDES_PORT ); }
@@ -663,7 +660,7 @@ static int mca_fe_hw_params(struct snd_pcm_substream *substream,unsigned long bclk_ratio;unsigned int tdm_slots, tdm_slot_width, tdm_mask;u32 regval, pad; -int ret, port, nchans_ceiled; +int ret, portmask, nchans_ceiled;if (!cl->tdm_slot_width) {/*
@@ -712,13 +709,13 @@ static int mca_fe_hw_params(struct snd_pcm_substream *substream, tdm_mask = (1 << tdm_slots) -1 ; } - port =mca_fe_get_port (substream); -if (port <0 ) -return port; + portmask =mca_fe_get_portmask (substream); +if (!portmask) +return -EINVAL ; ret =mca_configure_serdes (cl, is_tx ?CLUSTER_TX_OFF :CLUSTER_RX_OFF , tdm_mask, tdm_slots,params_channels (params), - tdm_slot_width, is_tx, port); + tdm_slot_width, is_tx, portmask);if (ret)return ret;
Signature · 1 line
2.54.0
PATCH v2 6/7 ASoC: apple: mca: Do not mark clocks in use for non-providers
In reply to James CalligerosFrom: Hector Martin <[email protected]>
On the speakers PCM, this sequence:
1. Open playback
2. Open sense
3. Close playback
4. Close sense
would result in the sense FE being marked as clocks in use at (2), since there is a clock provider (playback FE). Then at (4) this would WARN since there is no driver any more when closing the in use clocks.
If (1) and (2) are reversed this does not happen, since the sense PCM is not marked as using the clocks when there is no provider yet. So, check explicitly whether the substream FE is a clock provider in be_prepare, and skip everything if it isn't.
--- sound/soc/apple/mca.c | 67 ++++++++++++++----------- 1 file changed, 37 insertions(+), 30 deletions(-)
sound/soc/apple/mca.c +37 -30
@@ -346,36 +346,6 @@ static bool mca_fe_clocks_in_use(struct mca_cluster *cl)return false; } -static int mca_be_prepare (struct snd_pcm_substream *substream, -struct snd_soc_dai *dai) -{ -struct mca_cluster *cl =mca_dai_to_cluster (dai); -struct mca_data *mca = cl->host; -struct mca_cluster *fe_cl; -int ret; - -if (cl->port_clk_driver <0 ) -return 0 ; - - fe_cl = &mca->clusters[cl->port_clk_driver]; - -/* -* Typically the CODECs we are paired with will require clocks -* to be present at time of unmute with the 'mute_stream' op -* or at time of DAPM widget power-up. We need to enable clocks -* here at the latest (frontend prepare would be too late). -*/ -if (!mca_fe_clocks_in_use (fe_cl)) { - ret =mca_fe_enable_clocks (fe_cl); -if (ret <0 ) -return ret; - } - - cl->clocks_in_use[substream->stream] = true; - -return 0 ; -} -static int mca_be_hw_free (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) {
@@ -806,6 +776,43 @@ static struct snd_soc_pcm_runtime *mca_be_get_fe(struct snd_soc_pcm_runtime *be,return fe; } +static int mca_be_prepare (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *be =snd_soc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *fe =mca_be_get_fe (be, substream->stream); +struct mca_cluster *cl =mca_dai_to_cluster (dai); +struct mca_data *mca = cl->host; +struct mca_cluster *fe_cl, *fe_clk_cl; +int ret; + + fe_cl =mca_dai_to_cluster (snd_soc_rtd_to_cpu (fe,0 )); + +if (!fe_cl->clk_provider) +return 0 ; + +if (cl->port_clk_driver <0 ) +return 0 ; + + fe_clk_cl = &mca->clusters[cl->port_clk_driver]; + +/* +* Typically the CODECs we are paired with will require clocks +* to be present at time of unmute with the 'mute_stream' op +* or at time of DAPM widget power-up. We need to enable clocks +* here at the latest (frontend prepare would be too late). +*/ +if (!mca_fe_clocks_in_use (fe_clk_cl)) { + ret =mca_fe_enable_clocks (fe_clk_cl); +if (ret <0 ) +return ret; + } + + cl->clocks_in_use[substream->stream] = true; + +return 0 ; +} +static int mca_be_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) {
Signature · 1 line
2.54.0
PATCH v2 7/7 ASoC: apple: mca: Add delay after configuring clock
In reply to James CalligerosFrom: Hector Martin <[email protected]>
Right after the early FE setup, ADMAC gets told to start the DMA. This can end up in a weird "slip" state with the channels transposed. Waiting a bit fixes this; presumably this allows the clock to stabilize.
--- sound/soc/apple/mca.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/soc/apple/mca.c +6 -0
@@ -225,6 +225,12 @@ static void mca_fe_early_trigger(struct snd_pcm_substream *substream, int cmd, FIELD_PREP(SERDES_CONF_SYNC_SEL, 0));mca_modify (cl, serdes_conf,SERDES_CONF_SYNC_SEL ,FIELD_PREP (SERDES_CONF_SYNC_SEL , cl->no +1 )); +/* +* ADMAC gets started right after this. This delay seems +* to be needed for that to be reliable, e.g. ensure the +* clock is stable? +*/ +udelay (100 );break ;default :break ;
Signature · 1 line
2.54.0