Commit 7dddead7 authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Vinod Koul

soundwire: cadence: use dai_runtime_array instead of dma_data

Simplify the code with a Cadence-specific dai_runtime_array, indexed
with dai->id, instead of abusing dma_data.
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarPéter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20221101023521.2384586-3-yung-chuan.liao@linux.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent e0767e39
...@@ -1709,13 +1709,10 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai, ...@@ -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 *cdns = snd_soc_dai_get_drvdata(dai);
struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_dai_runtime *dai_runtime;
dai_runtime = cdns->dai_runtime_array[dai->id];
if (stream) { if (stream) {
/* first paranoia check */ /* 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) { if (dai_runtime) {
dev_err(dai->dev, dev_err(dai->dev,
"dai_runtime already allocated for dai %s\n", "dai_runtime already allocated for dai %s\n",
...@@ -1734,20 +1731,21 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai, ...@@ -1734,20 +1731,21 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai,
dai_runtime->link_id = cdns->instance; dai_runtime->link_id = cdns->instance;
dai_runtime->stream = stream; dai_runtime->stream = stream;
dai_runtime->direction = direction;
if (direction == SNDRV_PCM_STREAM_PLAYBACK) cdns->dai_runtime_array[dai->id] = dai_runtime;
dai->playback_dma_data = dai_runtime;
else
dai->capture_dma_data = dai_runtime;
} else { } else {
/* for NULL stream we release allocated dai_runtime */ /* second paranoia check */
if (direction == SNDRV_PCM_STREAM_PLAYBACK) { if (!dai_runtime) {
kfree(dai->playback_dma_data); dev_err(dai->dev,
dai->playback_dma_data = NULL; "dai_runtime not allocated for dai %s\n",
} else { dai->name);
kfree(dai->capture_dma_data); return -EINVAL;
dai->capture_dma_data = NULL;
} }
/* for NULL stream we release allocated dai_runtime */
kfree(dai_runtime);
cdns->dai_runtime_array[dai->id] = NULL;
} }
return 0; return 0;
} }
......
...@@ -81,6 +81,7 @@ struct sdw_cdns_stream_config { ...@@ -81,6 +81,7 @@ struct sdw_cdns_stream_config {
* @hw_params: hw_params to be applied in .prepare step * @hw_params: hw_params to be applied in .prepare step
* @suspended: status set when suspended, to be used in .prepare * @suspended: status set when suspended, to be used in .prepare
* @paused: status set in .trigger, to be used in suspend * @paused: status set in .trigger, to be used in suspend
* @direction: stream direction
*/ */
struct sdw_cdns_dai_runtime { struct sdw_cdns_dai_runtime {
char *name; char *name;
...@@ -92,6 +93,7 @@ struct sdw_cdns_dai_runtime { ...@@ -92,6 +93,7 @@ struct sdw_cdns_dai_runtime {
struct snd_pcm_hw_params *hw_params; struct snd_pcm_hw_params *hw_params;
bool suspended; bool suspended;
bool paused; bool paused;
int direction;
}; };
/** /**
...@@ -108,6 +110,7 @@ struct sdw_cdns_dai_runtime { ...@@ -108,6 +110,7 @@ struct sdw_cdns_dai_runtime {
* @registers: Cadence registers * @registers: Cadence registers
* @link_up: Link status * @link_up: Link status
* @msg_count: Messages sent on bus * @msg_count: Messages sent on bus
* @dai_runtime_array: runtime context for each allocated DAI.
*/ */
struct sdw_cdns { struct sdw_cdns {
struct device *dev; struct device *dev;
...@@ -135,6 +138,8 @@ struct sdw_cdns { ...@@ -135,6 +138,8 @@ struct sdw_cdns {
struct work_struct work; struct work_struct work;
struct list_head list; struct list_head list;
struct sdw_cdns_dai_runtime **dai_runtime_array;
}; };
#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus) #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
......
...@@ -831,7 +831,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream, ...@@ -831,7 +831,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
int ch, dir; int ch, dir;
int ret; int ret;
dai_runtime = snd_soc_dai_get_dma_data(dai, substream); dai_runtime = cdns->dai_runtime_array[dai->id];
if (!dai_runtime) if (!dai_runtime)
return -EIO; return -EIO;
...@@ -902,7 +902,7 @@ static int intel_prepare(struct snd_pcm_substream *substream, ...@@ -902,7 +902,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
int ch, dir; int ch, dir;
int ret = 0; int ret = 0;
dai_runtime = snd_soc_dai_get_dma_data(dai, substream); dai_runtime = cdns->dai_runtime_array[dai->id];
if (!dai_runtime) { if (!dai_runtime) {
dev_err(dai->dev, "failed to get dai runtime in %s\n", dev_err(dai->dev, "failed to get dai runtime in %s\n",
__func__); __func__);
...@@ -949,7 +949,7 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) ...@@ -949,7 +949,7 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_dai_runtime *dai_runtime;
int ret; int ret;
dai_runtime = snd_soc_dai_get_dma_data(dai, substream); dai_runtime = cdns->dai_runtime_array[dai->id];
if (!dai_runtime) if (!dai_runtime)
return -EIO; return -EIO;
...@@ -996,13 +996,10 @@ static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai, ...@@ -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, static void *intel_get_sdw_stream(struct snd_soc_dai *dai,
int direction) int direction)
{ {
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_dai_runtime *dai_runtime;
if (direction == SNDRV_PCM_STREAM_PLAYBACK) dai_runtime = cdns->dai_runtime_array[dai->id];
dai_runtime = dai->playback_dma_data;
else
dai_runtime = dai->capture_dma_data;
if (!dai_runtime) if (!dai_runtime)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -1025,7 +1022,7 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn ...@@ -1025,7 +1022,7 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn
if (res->ops && res->ops->trigger) if (res->ops && res->ops->trigger)
res->ops->trigger(dai, cmd, substream->stream); 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) { if (!dai_runtime) {
dev_err(dai->dev, "failed to get dai runtime in %s\n", dev_err(dai->dev, "failed to get dai runtime in %s\n",
__func__); __func__);
...@@ -1092,15 +1089,9 @@ static int intel_component_dais_suspend(struct snd_soc_component *component) ...@@ -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_cdns *cdns = snd_soc_dai_get_drvdata(dai);
struct sdw_intel *sdw = cdns_to_intel(cdns); struct sdw_intel *sdw = cdns_to_intel(cdns);
struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_dai_runtime *dai_runtime;
int stream;
int ret; int ret;
dai_runtime = dai->playback_dma_data; dai_runtime = cdns->dai_runtime_array[dai->id];
stream = SNDRV_PCM_STREAM_PLAYBACK;
if (!dai_runtime) {
dai_runtime = dai->capture_dma_data;
stream = SNDRV_PCM_STREAM_CAPTURE;
}
if (!dai_runtime) if (!dai_runtime)
continue; continue;
...@@ -1111,7 +1102,7 @@ static int intel_component_dais_suspend(struct snd_soc_component *component) ...@@ -1111,7 +1102,7 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
if (dai_runtime->paused) { if (dai_runtime->paused) {
dai_runtime->suspended = true; 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) if (ret < 0)
return ret; return ret;
} }
...@@ -1178,6 +1169,7 @@ static int intel_create_dai(struct sdw_cdns *cdns, ...@@ -1178,6 +1169,7 @@ static int intel_create_dai(struct sdw_cdns *cdns,
static int intel_register_dai(struct sdw_intel *sdw) 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_stream_config config;
struct sdw_cdns *cdns = &sdw->cdns; struct sdw_cdns *cdns = &sdw->cdns;
struct sdw_cdns_streams *stream; struct sdw_cdns_streams *stream;
...@@ -1195,6 +1187,13 @@ static int intel_register_dai(struct sdw_intel *sdw) ...@@ -1195,6 +1187,13 @@ static int intel_register_dai(struct sdw_intel *sdw)
/* DAIs are created based on total number of PDIs supported */ /* DAIs are created based on total number of PDIs supported */
num_dai = cdns->pcm.num_pdi; 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); dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL);
if (!dais) if (!dais)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment