ASoC/SoundWire: dai: expand 'stream' concept beyond SoundWire
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 24 Dec 2021 02:10:31 +0000 (10:10 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 24 Dec 2021 14:06:47 +0000 (14:06 +0000)
The HDAudio ASoC support relies on the set_tdm_slots() helper to store
the HDaudio stream tag in the tx_mask. This only works because of the
pre-existing order in soc-pcm.c, where the hw_params() is handled for
codec_dais *before* cpu_dais. When the order is reversed, the
stream_tag is used as a mask in the codec fixup functions:

/* fixup params based on TDM slot masks */
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
    codec_dai->tx_mask)
soc_pcm_codec_params_fixup(&codec_params,
   codec_dai->tx_mask);

As a result of this confusion, the codec_params_fixup() ends-up
generating bad channel masks, depending on what stream_tag was
allocated.

We could add a flag to state that the tx_mask is really not a mask,
but it would be quite ugly to persist in overloading concepts.

Instead, this patch suggests a more generic get/set 'stream' API based
on the existing model for SoundWire. We can expand the concept to
store 'stream' opaque information that is specific to different DAI
types. In the case of HDAudio DAIs, we only need to store a stream tag
as an unsigned char pointer. The TDM rx_ and tx_masks should really
only be used to store masks.

Rename get_sdw_stream/set_sdw_stream callbacks and helpers as
get_stream/set_stream. No functionality change beyond the rename.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Acked-By: Vinod Koul <vkoul@kernel.org>
Link: https://lore.kernel.org/r/20211224021034.26635-5-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
19 files changed:
drivers/soundwire/intel.c
drivers/soundwire/qcom.c
drivers/soundwire/stream.c
include/sound/soc-dai.h
sound/soc/codecs/max98373-sdw.c
sound/soc/codecs/rt1308-sdw.c
sound/soc/codecs/rt1316-sdw.c
sound/soc/codecs/rt5682-sdw.c
sound/soc/codecs/rt700.c
sound/soc/codecs/rt711-sdca.c
sound/soc/codecs/rt711.c
sound/soc/codecs/rt715-sdca.c
sound/soc/codecs/rt715.c
sound/soc/codecs/sdw-mockup.c
sound/soc/codecs/wcd938x.c
sound/soc/codecs/wsa881x.c
sound/soc/intel/boards/sof_sdw.c
sound/soc/qcom/sdm845.c
sound/soc/qcom/sm8250.c

index 3d29f02ad5a6b74155822898d43bcc57baeb2c2a..70d164372a2bad36e6b4887872bc68b79c378c4d 100644 (file)
@@ -1129,8 +1129,8 @@ static const struct snd_soc_dai_ops intel_pcm_dai_ops = {
        .hw_free = intel_hw_free,
        .trigger = intel_trigger,
        .shutdown = intel_shutdown,
-       .set_sdw_stream = intel_pcm_set_sdw_stream,
-       .get_sdw_stream = intel_get_sdw_stream,
+       .set_stream = intel_pcm_set_sdw_stream,
+       .get_stream = intel_get_sdw_stream,
 };
 
 static const struct snd_soc_dai_ops intel_pdm_dai_ops = {
@@ -1139,8 +1139,8 @@ static const struct snd_soc_dai_ops intel_pdm_dai_ops = {
        .prepare = intel_prepare,
        .hw_free = intel_hw_free,
        .shutdown = intel_shutdown,
-       .set_sdw_stream = intel_pdm_set_sdw_stream,
-       .get_sdw_stream = intel_get_sdw_stream,
+       .set_stream = intel_pdm_set_sdw_stream,
+       .get_stream = intel_get_sdw_stream,
 };
 
 static const struct snd_soc_component_driver dai_component = {
index a317bea2d42dd3d5b518dc79ed5b700cab02cd5b..9d42891ac3d693aa04efe9efa52a872aaa9c366d 100644 (file)
@@ -1024,8 +1024,8 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream,
        ctrl->sruntime[dai->id] = sruntime;
 
        for_each_rtd_codec_dais(rtd, i, codec_dai) {
-               ret = snd_soc_dai_set_sdw_stream(codec_dai, sruntime,
-                                                substream->stream);
+               ret = snd_soc_dai_set_stream(codec_dai, sruntime,
+                                            substream->stream);
                if (ret < 0 && ret != -ENOTSUPP) {
                        dev_err(dai->dev, "Failed to set sdw stream on %s\n",
                                codec_dai->name);
@@ -1051,8 +1051,8 @@ static const struct snd_soc_dai_ops qcom_swrm_pdm_dai_ops = {
        .hw_free = qcom_swrm_hw_free,
        .startup = qcom_swrm_startup,
        .shutdown = qcom_swrm_shutdown,
-       .set_sdw_stream = qcom_swrm_set_sdw_stream,
-       .get_sdw_stream = qcom_swrm_get_sdw_stream,
+       .set_stream = qcom_swrm_set_sdw_stream,
+       .get_stream = qcom_swrm_get_sdw_stream,
 };
 
 static const struct snd_soc_component_driver qcom_swrm_dai_component = {
index 5d4f6b308ef7314dfab873ac723c4b78cd9a6c00..980f26d49b66f03db0b1ac8a4fbda927192d11cd 100644 (file)
@@ -1863,7 +1863,7 @@ static int set_stream(struct snd_pcm_substream *substream,
 
        /* Set stream pointer on all DAIs */
        for_each_rtd_dais(rtd, i, dai) {
-               ret = snd_soc_dai_set_sdw_stream(dai, sdw_stream, substream->stream);
+               ret = snd_soc_dai_set_stream(dai, sdw_stream, substream->stream);
                if (ret < 0) {
                        dev_err(rtd->dev, "failed to set stream pointer on dai %s\n", dai->name);
                        break;
@@ -1934,7 +1934,7 @@ void sdw_shutdown_stream(void *sdw_substream)
        /* Find stream from first CPU DAI */
        dai = asoc_rtd_to_cpu(rtd, 0);
 
-       sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
+       sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
 
        if (IS_ERR(sdw_stream)) {
                dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
index 5d4dd7c5450bc028081544167f5dba8d4c4477d5..bbd821d2df9ca976c973398ea7a60da71efbbab8 100644 (file)
@@ -295,9 +295,9 @@ struct snd_soc_dai_ops {
                        unsigned int *rx_num, unsigned int *rx_slot);
        int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
 
-       int (*set_sdw_stream)(struct snd_soc_dai *dai,
-                       void *stream, int direction);
-       void *(*get_sdw_stream)(struct snd_soc_dai *dai, int direction);
+       int (*set_stream)(struct snd_soc_dai *dai,
+                         void *stream, int direction);
+       void *(*get_stream)(struct snd_soc_dai *dai, int direction);
 
        /*
         * DAI digital mute - optional.
@@ -515,42 +515,42 @@ static inline void *snd_soc_dai_get_drvdata(struct snd_soc_dai *dai)
 }
 
 /**
- * snd_soc_dai_set_sdw_stream() - Configures a DAI for SDW stream operation
+ * snd_soc_dai_set_stream() - Configures a DAI for stream operation
  * @dai: DAI
- * @stream: STREAM
+ * @stream: STREAM (opaque structure depending on DAI type)
  * @direction: Stream direction(Playback/Capture)
- * SoundWire subsystem doesn't have a notion of direction and we reuse
+ * Some subsystems, such as SoundWire, don't have a notion of direction and we reuse
  * the ASoC stream direction to configure sink/source ports.
  * Playback maps to source ports and Capture for sink ports.
  *
  * This should be invoked with NULL to clear the stream set previously.
  * Returns 0 on success, a negative error code otherwise.
  */
-static inline int snd_soc_dai_set_sdw_stream(struct snd_soc_dai *dai,
-                               void *stream, int direction)
+static inline int snd_soc_dai_set_stream(struct snd_soc_dai *dai,
+                                        void *stream, int direction)
 {
-       if (dai->driver->ops->set_sdw_stream)
-               return dai->driver->ops->set_sdw_stream(dai, stream, direction);
+       if (dai->driver->ops->set_stream)
+               return dai->driver->ops->set_stream(dai, stream, direction);
        else
                return -ENOTSUPP;
 }
 
 /**
- * snd_soc_dai_get_sdw_stream() - Retrieves SDW stream from DAI
+ * snd_soc_dai_get_stream() - Retrieves stream from DAI
  * @dai: DAI
  * @direction: Stream direction(Playback/Capture)
  *
  * This routine only retrieves that was previously configured
- * with snd_soc_dai_get_sdw_stream()
+ * with snd_soc_dai_get_stream()
  *
  * Returns pointer to stream or an ERR_PTR value, e.g.
  * ERR_PTR(-ENOTSUPP) if callback is not supported;
  */
-static inline void *snd_soc_dai_get_sdw_stream(struct snd_soc_dai *dai,
-                                              int direction)
+static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
+                                          int direction)
 {
-       if (dai->driver->ops->get_sdw_stream)
-               return dai->driver->ops->get_sdw_stream(dai, direction);
+       if (dai->driver->ops->get_stream)
+               return dai->driver->ops->get_stream(dai, direction);
        else
                return ERR_PTR(-ENOTSUPP);
 }
index dc520effc61cb81e451a806e922329ef20441e3e..f47e956d4f55aca2938acc3c92c96489dc4aa89d 100644 (file)
@@ -741,7 +741,7 @@ static int max98373_sdw_set_tdm_slot(struct snd_soc_dai *dai,
 static const struct snd_soc_dai_ops max98373_dai_sdw_ops = {
        .hw_params = max98373_sdw_dai_hw_params,
        .hw_free = max98373_pcm_hw_free,
-       .set_sdw_stream = max98373_set_sdw_stream,
+       .set_stream = max98373_set_sdw_stream,
        .shutdown = max98373_shutdown,
        .set_tdm_slot = max98373_sdw_set_tdm_slot,
 };
index f716668de6400e912fed92fc03eb388151328d85..149a76075c76a11e6b7229a0db24905b17b9afd7 100644 (file)
@@ -613,7 +613,7 @@ static const struct snd_soc_component_driver soc_component_sdw_rt1308 = {
 static const struct snd_soc_dai_ops rt1308_aif_dai_ops = {
        .hw_params = rt1308_sdw_hw_params,
        .hw_free        = rt1308_sdw_pcm_hw_free,
-       .set_sdw_stream = rt1308_set_sdw_stream,
+       .set_stream     = rt1308_set_sdw_stream,
        .shutdown       = rt1308_sdw_shutdown,
        .set_tdm_slot   = rt1308_sdw_set_tdm_slot,
 };
index 09b4914bba1bfef806165fbbc32aa79817bfbf7a..c66d7b20cb4dda120e3d5364d5149da56d8ee9ea 100644 (file)
@@ -602,7 +602,7 @@ static const struct snd_soc_component_driver soc_component_sdw_rt1316 = {
 static const struct snd_soc_dai_ops rt1316_aif_dai_ops = {
        .hw_params = rt1316_sdw_hw_params,
        .hw_free        = rt1316_sdw_pcm_hw_free,
-       .set_sdw_stream = rt1316_set_sdw_stream,
+       .set_stream     = rt1316_set_sdw_stream,
        .shutdown       = rt1316_sdw_shutdown,
 };
 
index 31a4f286043e46644e2f8f8dd5190020d9c46fb0..248257a2e4e0f32abff0173ad50511292da6fbb7 100644 (file)
@@ -272,7 +272,7 @@ static int rt5682_sdw_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt5682_sdw_ops = {
        .hw_params      = rt5682_sdw_hw_params,
        .hw_free        = rt5682_sdw_hw_free,
-       .set_sdw_stream = rt5682_set_sdw_stream,
+       .set_stream     = rt5682_set_sdw_stream,
        .shutdown       = rt5682_sdw_shutdown,
 };
 
index 921382724f9cdba6685b490c0d1933c67981c6fc..e61a8257bf64707a17ce4b41541f0918c5a74b8d 100644 (file)
@@ -1005,7 +1005,7 @@ static int rt700_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt700_ops = {
        .hw_params      = rt700_pcm_hw_params,
        .hw_free        = rt700_pcm_hw_free,
-       .set_sdw_stream = rt700_set_sdw_stream,
+       .set_stream     = rt700_set_sdw_stream,
        .shutdown       = rt700_shutdown,
 };
 
index 2e992589f1e420020f3e20bda359aec377db6605..bdb1375f03388553d80c9c841b88eb90abaa8a7c 100644 (file)
@@ -1358,7 +1358,7 @@ static int rt711_sdca_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt711_sdca_ops = {
        .hw_params      = rt711_sdca_pcm_hw_params,
        .hw_free        = rt711_sdca_pcm_hw_free,
-       .set_sdw_stream = rt711_sdca_set_sdw_stream,
+       .set_stream     = rt711_sdca_set_sdw_stream,
        .shutdown       = rt711_sdca_shutdown,
 };
 
index a7c5608a0ef8798ba6eca91e9a98dddf865d8985..6770825d037a8a73a7cd43e80805acb834f6c8a4 100644 (file)
@@ -1089,7 +1089,7 @@ static int rt711_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt711_ops = {
        .hw_params      = rt711_pcm_hw_params,
        .hw_free        = rt711_pcm_hw_free,
-       .set_sdw_stream = rt711_set_sdw_stream,
+       .set_stream     = rt711_set_sdw_stream,
        .shutdown       = rt711_shutdown,
 };
 
index 66e166568c50875719a670c425ed24a17d76d9c7..bfa536bd71960cfd50eee5b5de6a798aa37dffd4 100644 (file)
@@ -938,7 +938,7 @@ static int rt715_sdca_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt715_sdca_ops = {
        .hw_params      = rt715_sdca_pcm_hw_params,
        .hw_free        = rt715_sdca_pcm_hw_free,
-       .set_sdw_stream = rt715_sdca_set_sdw_stream,
+       .set_stream     = rt715_sdca_set_sdw_stream,
        .shutdown       = rt715_sdca_shutdown,
 };
 
index 1352869cc08670f71e28ddbdedf5649f0577cd3d..a64d11a747513655270be2ed36b0cbebabe0f7d4 100644 (file)
@@ -909,7 +909,7 @@ static int rt715_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops rt715_ops = {
        .hw_params      = rt715_pcm_hw_params,
        .hw_free        = rt715_pcm_hw_free,
-       .set_sdw_stream = rt715_set_sdw_stream,
+       .set_stream     = rt715_set_sdw_stream,
        .shutdown       = rt715_shutdown,
 };
 
index 8ea13cfa9f8ede000bb44d8603a62cb11522fefe..7c612aaf31c75c3447d98c26668f8af8366c65cc 100644 (file)
@@ -138,7 +138,7 @@ static int sdw_mockup_pcm_hw_free(struct snd_pcm_substream *substream,
 static const struct snd_soc_dai_ops sdw_mockup_ops = {
        .hw_params      = sdw_mockup_pcm_hw_params,
        .hw_free        = sdw_mockup_pcm_hw_free,
-       .set_sdw_stream = sdw_mockup_set_sdw_stream,
+       .set_stream     = sdw_mockup_set_sdw_stream,
        .shutdown       = sdw_mockup_shutdown,
 };
 
index 67151c7770c65064f55ad7378a6ba794f93bf7b7..0b5266c56a3fb8adf67d2284fbed08d31fc73665 100644 (file)
@@ -4287,7 +4287,7 @@ static int wcd938x_codec_set_sdw_stream(struct snd_soc_dai *dai,
 static const struct snd_soc_dai_ops wcd938x_sdw_dai_ops = {
        .hw_params = wcd938x_codec_hw_params,
        .hw_free = wcd938x_codec_free,
-       .set_sdw_stream = wcd938x_codec_set_sdw_stream,
+       .set_stream = wcd938x_codec_set_sdw_stream,
 };
 
 static struct snd_soc_dai_driver wcd938x_dais[] = {
index 2da4a5fa7a18d85a5181f589b0be4adb9cca3030..ffc025e01bce4705490ca87c5ba25e04b767e912 100644 (file)
@@ -1018,7 +1018,7 @@ static const struct snd_soc_dai_ops wsa881x_dai_ops = {
        .hw_params = wsa881x_hw_params,
        .hw_free = wsa881x_hw_free,
        .mute_stream = wsa881x_digital_mute,
-       .set_sdw_stream = wsa881x_set_sdw_stream,
+       .set_stream = wsa881x_set_sdw_stream,
 };
 
 static struct snd_soc_dai_driver wsa881x_dais[] = {
index de303a9808791352c3088c81713bf9dd5cc2130a..da515eb1ddbe748ad2209366ec3f709d737898f2 100644 (file)
@@ -347,7 +347,7 @@ int sdw_prepare(struct snd_pcm_substream *substream)
        /* Find stream from first CPU DAI */
        dai = asoc_rtd_to_cpu(rtd, 0);
 
-       sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
+       sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
 
        if (IS_ERR(sdw_stream)) {
                dev_err(rtd->dev, "no stream found for DAI %s", dai->name);
@@ -367,7 +367,7 @@ int sdw_trigger(struct snd_pcm_substream *substream, int cmd)
        /* Find stream from first CPU DAI */
        dai = asoc_rtd_to_cpu(rtd, 0);
 
-       sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
+       sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
 
        if (IS_ERR(sdw_stream)) {
                dev_err(rtd->dev, "no stream found for DAI %s", dai->name);
@@ -406,7 +406,7 @@ int sdw_hw_free(struct snd_pcm_substream *substream)
        /* Find stream from first CPU DAI */
        dai = asoc_rtd_to_cpu(rtd, 0);
 
-       sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream);
+       sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
 
        if (IS_ERR(sdw_stream)) {
                dev_err(rtd->dev, "no stream found for DAI %s", dai->name);
index 10d724bd1d67caf31d2188801a799754a4126a99..5c1d13eccbee5f1952cd8a8a8418a1eb581e6f8f 100644 (file)
@@ -57,8 +57,8 @@ static int sdm845_slim_snd_hw_params(struct snd_pcm_substream *substream,
        int ret = 0, i;
 
        for_each_rtd_codec_dais(rtd, i, codec_dai) {
-               sruntime = snd_soc_dai_get_sdw_stream(codec_dai,
-                                                     substream->stream);
+               sruntime = snd_soc_dai_get_stream(codec_dai,
+                                                 substream->stream);
                if (sruntime != ERR_PTR(-ENOTSUPP))
                        pdata->sruntime[cpu_dai->id] = sruntime;
 
index b2ca2579810b06138fc2b7d8deddb60920924e58..114a29e01c0fe50c82e98831acbb40be3e75f7bb 100644 (file)
@@ -136,8 +136,8 @@ static int sm8250_snd_hw_params(struct snd_pcm_substream *substream,
        case TX_CODEC_DMA_TX_2:
        case TX_CODEC_DMA_TX_3:
                for_each_rtd_codec_dais(rtd, i, codec_dai) {
-                       sruntime = snd_soc_dai_get_sdw_stream(codec_dai,
-                                                     substream->stream);
+                       sruntime = snd_soc_dai_get_stream(codec_dai,
+                                                         substream->stream);
                        if (sruntime != ERR_PTR(-ENOTSUPP))
                                pdata->sruntime[cpu_dai->id] = sruntime;
                }