soundwire: cadence: use dai_runtime_array instead of dma_data
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tue, 1 Nov 2022 02:35:21 +0000 (10:35 +0800)
committerVinod Koul <vkoul@kernel.org>
Wed, 9 Nov 2022 04:29:46 +0000 (09:59 +0530)
Simplify the code with a Cadence-specific dai_runtime_array, indexed
with dai->id, instead of abusing dma_data.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20221101023521.2384586-3-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/cadence_master.c
drivers/soundwire/cadence_master.h
drivers/soundwire/intel.c

index 235617b..a1de363 100644 (file)
@@ -1709,13 +1709,10 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai,
        struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
        struct sdw_cdns_dai_runtime *dai_runtime;
 
+       dai_runtime = cdns->dai_runtime_array[dai->id];
+
        if (stream) {
                /* first paranoia check */
-               if (direction == SNDRV_PCM_STREAM_PLAYBACK)
-                       dai_runtime = dai->playback_dma_data;
-               else
-                       dai_runtime = dai->capture_dma_data;
-
                if (dai_runtime) {
                        dev_err(dai->dev,
                                "dai_runtime already allocated for dai %s\n",
@@ -1734,20 +1731,21 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai,
                dai_runtime->link_id = cdns->instance;
 
                dai_runtime->stream = stream;
+               dai_runtime->direction = direction;
 
-               if (direction == SNDRV_PCM_STREAM_PLAYBACK)
-                       dai->playback_dma_data = dai_runtime;
-               else
-                       dai->capture_dma_data = dai_runtime;
+               cdns->dai_runtime_array[dai->id] = dai_runtime;
        } else {
-               /* for NULL stream we release allocated dai_runtime */
-               if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
-                       kfree(dai->playback_dma_data);
-                       dai->playback_dma_data = NULL;
-               } else {
-                       kfree(dai->capture_dma_data);
-                       dai->capture_dma_data = NULL;
+               /* second paranoia check */
+               if (!dai_runtime) {
+                       dev_err(dai->dev,
+                               "dai_runtime not allocated for dai %s\n",
+                               dai->name);
+                       return -EINVAL;
                }
+
+               /* for NULL stream we release allocated dai_runtime */
+               kfree(dai_runtime);
+               cdns->dai_runtime_array[dai->id] = NULL;
        }
        return 0;
 }
index 93f23bd..0434d70 100644 (file)
@@ -81,6 +81,7 @@ struct sdw_cdns_stream_config {
  * @hw_params: hw_params to be applied in .prepare step
  * @suspended: status set when suspended, to be used in .prepare
  * @paused: status set in .trigger, to be used in suspend
+ * @direction: stream direction
  */
 struct sdw_cdns_dai_runtime {
        char *name;
@@ -92,6 +93,7 @@ struct sdw_cdns_dai_runtime {
        struct snd_pcm_hw_params *hw_params;
        bool suspended;
        bool paused;
+       int direction;
 };
 
 /**
@@ -108,6 +110,7 @@ struct sdw_cdns_dai_runtime {
  * @registers: Cadence registers
  * @link_up: Link status
  * @msg_count: Messages sent on bus
+ * @dai_runtime_array: runtime context for each allocated DAI.
  */
 struct sdw_cdns {
        struct device *dev;
@@ -135,6 +138,8 @@ struct sdw_cdns {
        struct work_struct work;
 
        struct list_head list;
+
+       struct sdw_cdns_dai_runtime **dai_runtime_array;
 };
 
 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
index 1e9c6df..e8855a2 100644 (file)
@@ -831,7 +831,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
        int ch, dir;
        int ret;
 
-       dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
+       dai_runtime = cdns->dai_runtime_array[dai->id];
        if (!dai_runtime)
                return -EIO;
 
@@ -902,7 +902,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
        int ch, dir;
        int ret = 0;
 
-       dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
+       dai_runtime = cdns->dai_runtime_array[dai->id];
        if (!dai_runtime) {
                dev_err(dai->dev, "failed to get dai runtime in %s\n",
                        __func__);
@@ -949,7 +949,7 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
        struct sdw_cdns_dai_runtime *dai_runtime;
        int ret;
 
-       dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
+       dai_runtime = cdns->dai_runtime_array[dai->id];
        if (!dai_runtime)
                return -EIO;
 
@@ -996,13 +996,10 @@ static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai,
 static void *intel_get_sdw_stream(struct snd_soc_dai *dai,
                                  int direction)
 {
+       struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
        struct sdw_cdns_dai_runtime *dai_runtime;
 
-       if (direction == SNDRV_PCM_STREAM_PLAYBACK)
-               dai_runtime = dai->playback_dma_data;
-       else
-               dai_runtime = dai->capture_dma_data;
-
+       dai_runtime = cdns->dai_runtime_array[dai->id];
        if (!dai_runtime)
                return ERR_PTR(-EINVAL);
 
@@ -1025,7 +1022,7 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn
        if (res->ops && res->ops->trigger)
                res->ops->trigger(dai, cmd, substream->stream);
 
-       dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
+       dai_runtime = cdns->dai_runtime_array[dai->id];
        if (!dai_runtime) {
                dev_err(dai->dev, "failed to get dai runtime in %s\n",
                        __func__);
@@ -1092,15 +1089,9 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
                struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
                struct sdw_intel *sdw = cdns_to_intel(cdns);
                struct sdw_cdns_dai_runtime *dai_runtime;
-               int stream;
                int ret;
 
-               dai_runtime = dai->playback_dma_data;
-               stream = SNDRV_PCM_STREAM_PLAYBACK;
-               if (!dai_runtime) {
-                       dai_runtime = dai->capture_dma_data;
-                       stream = SNDRV_PCM_STREAM_CAPTURE;
-               }
+               dai_runtime = cdns->dai_runtime_array[dai->id];
 
                if (!dai_runtime)
                        continue;
@@ -1111,7 +1102,7 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
                if (dai_runtime->paused) {
                        dai_runtime->suspended = true;
 
-                       ret = intel_free_stream(sdw, stream, dai, sdw->instance);
+                       ret = intel_free_stream(sdw, dai_runtime->direction, dai, sdw->instance);
                        if (ret < 0)
                                return ret;
                }
@@ -1178,6 +1169,7 @@ static int intel_create_dai(struct sdw_cdns *cdns,
 
 static int intel_register_dai(struct sdw_intel *sdw)
 {
+       struct sdw_cdns_dai_runtime **dai_runtime_array;
        struct sdw_cdns_stream_config config;
        struct sdw_cdns *cdns = &sdw->cdns;
        struct sdw_cdns_streams *stream;
@@ -1195,6 +1187,13 @@ static int intel_register_dai(struct sdw_intel *sdw)
        /* DAIs are created based on total number of PDIs supported */
        num_dai = cdns->pcm.num_pdi;
 
+       dai_runtime_array = devm_kcalloc(cdns->dev, num_dai,
+                                        sizeof(struct sdw_cdns_dai_runtime *),
+                                        GFP_KERNEL);
+       if (!dai_runtime_array)
+               return -ENOMEM;
+       cdns->dai_runtime_array = dai_runtime_array;
+
        dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL);
        if (!dais)
                return -ENOMEM;