Skip to content

Commit 7dddead

Browse files
plbossartvinodkoul
authored andcommitted
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: Pierre-Louis Bossart <[email protected]> Reviewed-by: Péter Ujfalusi <[email protected]> Signed-off-by: Bard Liao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e0767e3 commit 7dddead

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

drivers/soundwire/cadence_master.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,13 +1709,10 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai,
17091709
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
17101710
struct sdw_cdns_dai_runtime *dai_runtime;
17111711

1712+
dai_runtime = cdns->dai_runtime_array[dai->id];
1713+
17121714
if (stream) {
17131715
/* first paranoia check */
1714-
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
1715-
dai_runtime = dai->playback_dma_data;
1716-
else
1717-
dai_runtime = dai->capture_dma_data;
1718-
17191716
if (dai_runtime) {
17201717
dev_err(dai->dev,
17211718
"dai_runtime already allocated for dai %s\n",
@@ -1734,20 +1731,21 @@ int cdns_set_sdw_stream(struct snd_soc_dai *dai,
17341731
dai_runtime->link_id = cdns->instance;
17351732

17361733
dai_runtime->stream = stream;
1734+
dai_runtime->direction = direction;
17371735

1738-
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
1739-
dai->playback_dma_data = dai_runtime;
1740-
else
1741-
dai->capture_dma_data = dai_runtime;
1736+
cdns->dai_runtime_array[dai->id] = dai_runtime;
17421737
} else {
1743-
/* for NULL stream we release allocated dai_runtime */
1744-
if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
1745-
kfree(dai->playback_dma_data);
1746-
dai->playback_dma_data = NULL;
1747-
} else {
1748-
kfree(dai->capture_dma_data);
1749-
dai->capture_dma_data = NULL;
1738+
/* second paranoia check */
1739+
if (!dai_runtime) {
1740+
dev_err(dai->dev,
1741+
"dai_runtime not allocated for dai %s\n",
1742+
dai->name);
1743+
return -EINVAL;
17501744
}
1745+
1746+
/* for NULL stream we release allocated dai_runtime */
1747+
kfree(dai_runtime);
1748+
cdns->dai_runtime_array[dai->id] = NULL;
17511749
}
17521750
return 0;
17531751
}

drivers/soundwire/cadence_master.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct sdw_cdns_stream_config {
8181
* @hw_params: hw_params to be applied in .prepare step
8282
* @suspended: status set when suspended, to be used in .prepare
8383
* @paused: status set in .trigger, to be used in suspend
84+
* @direction: stream direction
8485
*/
8586
struct sdw_cdns_dai_runtime {
8687
char *name;
@@ -92,6 +93,7 @@ struct sdw_cdns_dai_runtime {
9293
struct snd_pcm_hw_params *hw_params;
9394
bool suspended;
9495
bool paused;
96+
int direction;
9597
};
9698

9799
/**
@@ -108,6 +110,7 @@ struct sdw_cdns_dai_runtime {
108110
* @registers: Cadence registers
109111
* @link_up: Link status
110112
* @msg_count: Messages sent on bus
113+
* @dai_runtime_array: runtime context for each allocated DAI.
111114
*/
112115
struct sdw_cdns {
113116
struct device *dev;
@@ -135,6 +138,8 @@ struct sdw_cdns {
135138
struct work_struct work;
136139

137140
struct list_head list;
141+
142+
struct sdw_cdns_dai_runtime **dai_runtime_array;
138143
};
139144

140145
#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)

drivers/soundwire/intel.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
831831
int ch, dir;
832832
int ret;
833833

834-
dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
834+
dai_runtime = cdns->dai_runtime_array[dai->id];
835835
if (!dai_runtime)
836836
return -EIO;
837837

@@ -902,7 +902,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
902902
int ch, dir;
903903
int ret = 0;
904904

905-
dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
905+
dai_runtime = cdns->dai_runtime_array[dai->id];
906906
if (!dai_runtime) {
907907
dev_err(dai->dev, "failed to get dai runtime in %s\n",
908908
__func__);
@@ -949,7 +949,7 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
949949
struct sdw_cdns_dai_runtime *dai_runtime;
950950
int ret;
951951

952-
dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
952+
dai_runtime = cdns->dai_runtime_array[dai->id];
953953
if (!dai_runtime)
954954
return -EIO;
955955

@@ -996,13 +996,10 @@ static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai,
996996
static void *intel_get_sdw_stream(struct snd_soc_dai *dai,
997997
int direction)
998998
{
999+
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
9991000
struct sdw_cdns_dai_runtime *dai_runtime;
10001001

1001-
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
1002-
dai_runtime = dai->playback_dma_data;
1003-
else
1004-
dai_runtime = dai->capture_dma_data;
1005-
1002+
dai_runtime = cdns->dai_runtime_array[dai->id];
10061003
if (!dai_runtime)
10071004
return ERR_PTR(-EINVAL);
10081005

@@ -1025,7 +1022,7 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn
10251022
if (res->ops && res->ops->trigger)
10261023
res->ops->trigger(dai, cmd, substream->stream);
10271024

1028-
dai_runtime = snd_soc_dai_get_dma_data(dai, substream);
1025+
dai_runtime = cdns->dai_runtime_array[dai->id];
10291026
if (!dai_runtime) {
10301027
dev_err(dai->dev, "failed to get dai runtime in %s\n",
10311028
__func__);
@@ -1092,15 +1089,9 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
10921089
struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
10931090
struct sdw_intel *sdw = cdns_to_intel(cdns);
10941091
struct sdw_cdns_dai_runtime *dai_runtime;
1095-
int stream;
10961092
int ret;
10971093

1098-
dai_runtime = dai->playback_dma_data;
1099-
stream = SNDRV_PCM_STREAM_PLAYBACK;
1100-
if (!dai_runtime) {
1101-
dai_runtime = dai->capture_dma_data;
1102-
stream = SNDRV_PCM_STREAM_CAPTURE;
1103-
}
1094+
dai_runtime = cdns->dai_runtime_array[dai->id];
11041095

11051096
if (!dai_runtime)
11061097
continue;
@@ -1111,7 +1102,7 @@ static int intel_component_dais_suspend(struct snd_soc_component *component)
11111102
if (dai_runtime->paused) {
11121103
dai_runtime->suspended = true;
11131104

1114-
ret = intel_free_stream(sdw, stream, dai, sdw->instance);
1105+
ret = intel_free_stream(sdw, dai_runtime->direction, dai, sdw->instance);
11151106
if (ret < 0)
11161107
return ret;
11171108
}
@@ -1178,6 +1169,7 @@ static int intel_create_dai(struct sdw_cdns *cdns,
11781169

11791170
static int intel_register_dai(struct sdw_intel *sdw)
11801171
{
1172+
struct sdw_cdns_dai_runtime **dai_runtime_array;
11811173
struct sdw_cdns_stream_config config;
11821174
struct sdw_cdns *cdns = &sdw->cdns;
11831175
struct sdw_cdns_streams *stream;
@@ -1195,6 +1187,13 @@ static int intel_register_dai(struct sdw_intel *sdw)
11951187
/* DAIs are created based on total number of PDIs supported */
11961188
num_dai = cdns->pcm.num_pdi;
11971189

1190+
dai_runtime_array = devm_kcalloc(cdns->dev, num_dai,
1191+
sizeof(struct sdw_cdns_dai_runtime *),
1192+
GFP_KERNEL);
1193+
if (!dai_runtime_array)
1194+
return -ENOMEM;
1195+
cdns->dai_runtime_array = dai_runtime_array;
1196+
11981197
dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL);
11991198
if (!dais)
12001199
return -ENOMEM;

0 commit comments

Comments
 (0)