hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/sound/soc/rockchip/rockchip_multi_dais.c
....@@ -30,6 +30,13 @@
3030 return snd_soc_dai_get_drvdata(dai);
3131 }
3232
33
+static inline unsigned int *mdais_channel_maps(struct rk_mdais_dev *mdais,
34
+ struct snd_pcm_substream *substream)
35
+{
36
+ return substream->stream ? mdais->capture_channel_maps :
37
+ mdais->playback_channel_maps;
38
+}
39
+
3340 static void hw_refine_channels(struct snd_pcm_hw_params *params,
3441 unsigned int channel)
3542 {
....@@ -54,26 +61,51 @@
5461 if (IS_ERR(cparams))
5562 return PTR_ERR(cparams);
5663
57
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
58
- channel_maps = mdais->playback_channel_maps;
59
- else
60
- channel_maps = mdais->capture_channel_maps;
64
+ channel_maps = mdais_channel_maps(mdais, substream);
6165
6266 for (i = 0; i < mdais->num_dais; i++) {
6367 child = mdais->dais[i].dai;
64
- if (channel_maps[i])
65
- hw_refine_channels(cparams, channel_maps[i]);
68
+ if (!channel_maps[i])
69
+ continue;
70
+
71
+ hw_refine_channels(cparams, channel_maps[i]);
6672 if (child->driver->ops && child->driver->ops->hw_params) {
6773 ret = child->driver->ops->hw_params(substream, cparams, child);
6874 if (ret < 0) {
69
- dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
75
+ dev_err(dai->dev, "Failed to set %s hw params: %d\n",
7076 dai->name, ret);
71
- return ret;
77
+ break;
7278 }
7379 }
7480 }
7581
7682 kfree(cparams);
83
+
84
+ return ret;
85
+}
86
+
87
+static int rockchip_mdais_hw_free(struct snd_pcm_substream *substream,
88
+ struct snd_soc_dai *dai)
89
+{
90
+ struct rk_mdais_dev *mdais = to_info(dai);
91
+ struct snd_soc_dai *child;
92
+ unsigned int *channel_maps;
93
+ int ret = 0, i = 0;
94
+
95
+ channel_maps = mdais_channel_maps(mdais, substream);
96
+
97
+ for (i = 0; i < mdais->num_dais; i++) {
98
+ child = mdais->dais[i].dai;
99
+ if (!channel_maps[i])
100
+ continue;
101
+
102
+ if (child->driver->ops && child->driver->ops->hw_free) {
103
+ ret = child->driver->ops->hw_free(substream, child);
104
+ if (ret < 0)
105
+ return ret;
106
+ }
107
+ }
108
+
77109 return 0;
78110 }
79111
....@@ -85,10 +117,7 @@
85117 unsigned int *channel_maps;
86118 int ret = 0, i = 0;
87119
88
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
89
- channel_maps = mdais->playback_channel_maps;
90
- else
91
- channel_maps = mdais->capture_channel_maps;
120
+ channel_maps = mdais_channel_maps(mdais, substream);
92121
93122 for (i = 0; i < mdais->num_dais; i++) {
94123 /* skip DAIs which have no channel mapping */
....@@ -112,9 +141,15 @@
112141 {
113142 struct rk_mdais_dev *mdais = to_info(dai);
114143 struct snd_soc_dai *child;
144
+ unsigned int *channel_maps;
115145 int ret = 0, i = 0;
116146
147
+ channel_maps = mdais_channel_maps(mdais, substream);
148
+
117149 for (i = 0; i < mdais->num_dais; i++) {
150
+ if (!channel_maps[i])
151
+ continue;
152
+
118153 child = mdais->dais[i].dai;
119154 if (child->driver->ops && child->driver->ops->startup) {
120155 ret = child->driver->ops->startup(substream, child);
....@@ -131,9 +166,15 @@
131166 {
132167 struct rk_mdais_dev *mdais = to_info(dai);
133168 struct snd_soc_dai *child;
169
+ unsigned int *channel_maps;
134170 int i = 0;
135171
172
+ channel_maps = mdais_channel_maps(mdais, substream);
173
+
136174 for (i = 0; i < mdais->num_dais; i++) {
175
+ if (!channel_maps[i])
176
+ continue;
177
+
137178 child = mdais->dais[i].dai;
138179 if (child->driver->ops && child->driver->ops->shutdown) {
139180 child->driver->ops->shutdown(substream, child);
....@@ -146,9 +187,15 @@
146187 {
147188 struct rk_mdais_dev *mdais = to_info(dai);
148189 struct snd_soc_dai *child;
190
+ unsigned int *channel_maps;
149191 int ret = 0, i = 0;
150192
193
+ channel_maps = mdais_channel_maps(mdais, substream);
194
+
151195 for (i = 0; i < mdais->num_dais; i++) {
196
+ if (!channel_maps[i])
197
+ continue;
198
+
152199 child = mdais->dais[i].dai;
153200 if (child->driver->ops && child->driver->ops->prepare) {
154201 ret = child->driver->ops->prepare(substream, child);
....@@ -242,7 +289,7 @@
242289 ret = child->driver->probe(child);
243290 if (ret < 0) {
244291 dev_err(child->dev,
245
- "ASoC: failed to probe DAI %s: %d\n",
292
+ "Failed to probe DAI %s: %d\n",
246293 child->name, ret);
247294 return ret;
248295 }
....@@ -263,6 +310,7 @@
263310
264311 static const struct snd_soc_dai_ops rockchip_mdais_dai_ops = {
265312 .hw_params = rockchip_mdais_hw_params,
313
+ .hw_free = rockchip_mdais_hw_free,
266314 .set_sysclk = rockchip_mdais_set_sysclk,
267315 .set_fmt = rockchip_mdais_set_fmt,
268316 .set_tdm_slot = rockchip_mdais_tdm_slot,