From: Herve Codina <herve.codina@bootlin.com>
To: Herve Codina <herve.codina@bootlin.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Qiang Zhao <qiang.zhao@nxp.com>,
Shengjiu Wang <shengjiu.wang@gmail.com>,
Xiubo Li <Xiubo.Lee@gmail.com>,
Fabio Estevam <festevam@gmail.com>,
Nicolin Chen <nicoleotsuka@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org,
linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [PATCH 04/10] ASoC: fsl: fsl_qmc_audio: Identify the QMC channel involved in completion routines
Date: Thu, 20 Jun 2024 10:42:51 +0200 [thread overview]
Message-ID: <20240620084300.397853-5-herve.codina@bootlin.com> (raw)
In-Reply-To: <20240620084300.397853-1-herve.codina@bootlin.com>
The current QMC audio driver uses only one QMC channel per DAI. The
context used by QMC channel transfer (read and write) completion
routines does not contains any QMC channel and the only one available
per DAI is used to schedule the next transfer.
This works pretty well with only one QMC channel per DAI.
The future support for non-inlerleave mode will use several QMC channel
per DAI. In that case, QMC channel transfer completion routines need to
identify the QMC channel related to the completion.
In order to fill this lack, even if identifying the current QMC channel
among several QMC channels is not needed for the current code, add one
indirection level and introduce the qmc_dai_chan data structrure.
This structure contains the QMC channel involved in the completion and
refererences to the runtime context (capture and playback) used by the
DAI.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
sound/soc/fsl/fsl_qmc_audio.c | 72 +++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 25 deletions(-)
diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c
index e8281e548746..b07770257bad 100644
--- a/sound/soc/fsl/fsl_qmc_audio.c
+++ b/sound/soc/fsl/fsl_qmc_audio.c
@@ -17,13 +17,19 @@
#include <sound/pcm_params.h>
#include <sound/soc.h>
+struct qmc_dai_chan {
+ struct qmc_dai_prtd *prtd_tx;
+ struct qmc_dai_prtd *prtd_rx;
+ struct qmc_chan *qmc_chan;
+};
+
struct qmc_dai {
char *name;
int id;
struct device *dev;
- struct qmc_chan *qmc_chan;
unsigned int nb_tx_ts;
unsigned int nb_rx_ts;
+ struct qmc_dai_chan chan;
};
struct qmc_audio {
@@ -86,9 +92,12 @@ static int qmc_audio_pcm_hw_params(struct snd_soc_component *component,
static void qmc_audio_pcm_write_complete(void *context)
{
- struct qmc_dai_prtd *prtd = context;
+ struct qmc_dai_chan *chan = context;
+ struct qmc_dai_prtd *prtd;
int ret;
+ prtd = chan->prtd_tx;
+
prtd->buffer_ended += prtd->period_size;
if (prtd->buffer_ended >= prtd->buffer_size)
prtd->buffer_ended = 0;
@@ -97,9 +106,10 @@ static void qmc_audio_pcm_write_complete(void *context)
if (prtd->ch_dma_addr_current >= prtd->ch_dma_addr_end)
prtd->ch_dma_addr_current = prtd->ch_dma_addr_start;
- ret = qmc_chan_write_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_write_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_write_complete, prtd);
+ qmc_audio_pcm_write_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(prtd->qmc_dai->dev, "write_submit failed %d\n",
ret);
@@ -110,9 +120,12 @@ static void qmc_audio_pcm_write_complete(void *context)
static void qmc_audio_pcm_read_complete(void *context, size_t length, unsigned int flags)
{
- struct qmc_dai_prtd *prtd = context;
+ struct qmc_dai_chan *chan = context;
+ struct qmc_dai_prtd *prtd;
int ret;
+ prtd = chan->prtd_rx;
+
if (length != prtd->ch_dma_size) {
dev_err(prtd->qmc_dai->dev, "read complete length = %zu, exp %zu\n",
length, prtd->ch_dma_size);
@@ -126,9 +139,10 @@ static void qmc_audio_pcm_read_complete(void *context, size_t length, unsigned i
if (prtd->ch_dma_addr_current >= prtd->ch_dma_addr_end)
prtd->ch_dma_addr_current = prtd->ch_dma_addr_start;
- ret = qmc_chan_read_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_read_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_read_complete, prtd);
+ qmc_audio_pcm_read_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(prtd->qmc_dai->dev, "read_submit failed %d\n",
ret);
@@ -151,10 +165,13 @@ static int qmc_audio_pcm_trigger(struct snd_soc_component *component,
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ prtd->qmc_dai->chan.prtd_tx = prtd;
+
/* Submit first chunk ... */
- ret = qmc_chan_write_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_write_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_write_complete, prtd);
+ qmc_audio_pcm_write_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(component->dev, "write_submit failed %d\n",
ret);
@@ -167,19 +184,23 @@ static int qmc_audio_pcm_trigger(struct snd_soc_component *component,
prtd->ch_dma_addr_current = prtd->ch_dma_addr_start;
/* ... and send it */
- ret = qmc_chan_write_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_write_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_write_complete, prtd);
+ qmc_audio_pcm_write_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(component->dev, "write_submit failed %d\n",
ret);
return ret;
}
} else {
+ prtd->qmc_dai->chan.prtd_rx = prtd;
+
/* Submit first chunk ... */
- ret = qmc_chan_read_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_read_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_read_complete, prtd);
+ qmc_audio_pcm_read_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(component->dev, "read_submit failed %d\n",
ret);
@@ -192,9 +213,10 @@ static int qmc_audio_pcm_trigger(struct snd_soc_component *component,
prtd->ch_dma_addr_current = prtd->ch_dma_addr_start;
/* ... and send it */
- ret = qmc_chan_read_submit(prtd->qmc_dai->qmc_chan,
+ ret = qmc_chan_read_submit(prtd->qmc_dai->chan.qmc_chan,
prtd->ch_dma_addr_current, prtd->ch_dma_size,
- qmc_audio_pcm_read_complete, prtd);
+ qmc_audio_pcm_read_complete,
+ &prtd->qmc_dai->chan);
if (ret) {
dev_err(component->dev, "write_submit failed %d\n",
ret);
@@ -489,7 +511,7 @@ static int qmc_dai_hw_params(struct snd_pcm_substream *substream,
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
chan_param.mode = QMC_TRANSPARENT;
chan_param.transp.max_rx_buf_size = params_period_bytes(params);
- ret = qmc_chan_set_param(qmc_dai->qmc_chan, &chan_param);
+ ret = qmc_chan_set_param(qmc_dai->chan.qmc_chan, &chan_param);
if (ret) {
dev_err(dai->dev, "set param failed %d\n",
ret);
@@ -520,23 +542,23 @@ static int qmc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- ret = qmc_chan_start(qmc_dai->qmc_chan, direction);
+ ret = qmc_chan_start(qmc_dai->chan.qmc_chan, direction);
if (ret)
return ret;
break;
case SNDRV_PCM_TRIGGER_STOP:
- ret = qmc_chan_stop(qmc_dai->qmc_chan, direction);
+ ret = qmc_chan_stop(qmc_dai->chan.qmc_chan, direction);
if (ret)
return ret;
- ret = qmc_chan_reset(qmc_dai->qmc_chan, direction);
+ ret = qmc_chan_reset(qmc_dai->chan.qmc_chan, direction);
if (ret)
return ret;
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- ret = qmc_chan_stop(qmc_dai->qmc_chan, direction);
+ ret = qmc_chan_stop(qmc_dai->chan.qmc_chan, direction);
if (ret)
return ret;
break;
@@ -613,10 +635,10 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_audio, struct device_node *
if (!qmc_dai->name)
return -ENOMEM;
- qmc_dai->qmc_chan = devm_qmc_chan_get_byphandle(qmc_audio->dev, np,
- "fsl,qmc-chan");
- if (IS_ERR(qmc_dai->qmc_chan)) {
- ret = PTR_ERR(qmc_dai->qmc_chan);
+ qmc_dai->chan.qmc_chan = devm_qmc_chan_get_byphandle(qmc_audio->dev, np,
+ "fsl,qmc-chan");
+ if (IS_ERR(qmc_dai->chan.qmc_chan)) {
+ ret = PTR_ERR(qmc_dai->chan.qmc_chan);
return dev_err_probe(qmc_audio->dev, ret,
"dai %d get QMC channel failed\n", qmc_dai->id);
}
@@ -624,7 +646,7 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_audio, struct device_node *
qmc_soc_dai_driver->id = qmc_dai->id;
qmc_soc_dai_driver->name = qmc_dai->name;
- ret = qmc_chan_get_info(qmc_dai->qmc_chan, &info);
+ ret = qmc_chan_get_info(qmc_dai->chan.qmc_chan, &info);
if (ret) {
dev_err(qmc_audio->dev, "dai %d get QMC channel info failed %d\n",
qmc_dai->id, ret);
--
2.45.0
next prev parent reply other threads:[~2024-06-20 8:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 8:42 [PATCH 00/10] Add support for non-interleaved mode in qmc_audio Herve Codina
2024-06-20 8:42 ` [PATCH 01/10] ASoC: fsl: fsl_qmc_audio: Check devm_kasprintf() returned value Herve Codina
2024-06-20 8:42 ` [PATCH 02/10] ASoC: fsl: fsl_qmc_audio: Fix issues detected by checkpatch Herve Codina
2024-06-20 8:42 ` [PATCH 03/10] ASoC: fsl: fsl_qmc_audio: Split channel buffer and PCM pointer handling Herve Codina
2024-06-20 8:42 ` Herve Codina [this message]
2024-06-20 8:42 ` [PATCH 05/10] ASoC: fsl: fsl_qmc_audio: Introduce qmc_audio_pcm_{read,write}_submit() Herve Codina
2024-06-20 8:42 ` [PATCH 06/10] ASoC: fsl: fsl_qmc_audio: Introduce qmc_dai_constraints_interleaved() Herve Codina
2024-06-20 8:42 ` [PATCH 07/10] soc: fsl: cpm1: qmc: Introduce functions to get a channel from a phandle list Herve Codina
2024-06-20 8:42 ` [PATCH 08/10] soc: fsl: cpm1: qmc: Introduce qmc_chan_count_phandles() Herve Codina
2024-06-20 8:42 ` [PATCH 09/10] dt-bindings: sound: fsl,qmc-audio: Add support for multiple QMC channels per DAI Herve Codina
2024-06-27 21:25 ` Rob Herring (Arm)
2024-06-20 8:42 ` [PATCH 10/10] ASoC: fsl: fsl_qmc_audio: Add support for non-interleaved mode Herve Codina
2024-07-01 7:47 ` Herve Codina
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=20240620084300.397853-5-herve.codina@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=Xiubo.Lee@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nicoleotsuka@gmail.com \
--cc=perex@perex.cz \
--cc=qiang.zhao@nxp.com \
--cc=robh@kernel.org \
--cc=shengjiu.wang@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tiwai@suse.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).