forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/rockchip/rockchip_multi_dais.c
....@@ -23,9 +23,18 @@
2323 #define DAIS_DRV_NAME "rockchip-mdais"
2424 #define RK3308_GRF_SOC_CON2 0x308
2525
26
+#define SOUND_NAME_PREFIX "sound-name-prefix"
27
+
2628 static inline struct rk_mdais_dev *to_info(struct snd_soc_dai *dai)
2729 {
2830 return snd_soc_dai_get_drvdata(dai);
31
+}
32
+
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;
2938 }
3039
3140 static void hw_refine_channels(struct snd_pcm_hw_params *params,
....@@ -52,26 +61,51 @@
5261 if (IS_ERR(cparams))
5362 return PTR_ERR(cparams);
5463
55
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
56
- channel_maps = mdais->playback_channel_maps;
57
- else
58
- channel_maps = mdais->capture_channel_maps;
64
+ channel_maps = mdais_channel_maps(mdais, substream);
5965
6066 for (i = 0; i < mdais->num_dais; i++) {
6167 child = mdais->dais[i].dai;
62
- if (channel_maps[i])
63
- hw_refine_channels(cparams, channel_maps[i]);
68
+ if (!channel_maps[i])
69
+ continue;
70
+
71
+ hw_refine_channels(cparams, channel_maps[i]);
6472 if (child->driver->ops && child->driver->ops->hw_params) {
6573 ret = child->driver->ops->hw_params(substream, cparams, child);
6674 if (ret < 0) {
67
- 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",
6876 dai->name, ret);
69
- return ret;
77
+ break;
7078 }
7179 }
7280 }
7381
7482 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
+
75109 return 0;
76110 }
77111
....@@ -80,9 +114,16 @@
80114 {
81115 struct rk_mdais_dev *mdais = to_info(dai);
82116 struct snd_soc_dai *child;
117
+ unsigned int *channel_maps;
83118 int ret = 0, i = 0;
84119
120
+ channel_maps = mdais_channel_maps(mdais, substream);
121
+
85122 for (i = 0; i < mdais->num_dais; i++) {
123
+ /* skip DAIs which have no channel mapping */
124
+ if (!channel_maps[i])
125
+ continue;
126
+
86127 child = mdais->dais[i].dai;
87128 if (child->driver->ops && child->driver->ops->trigger) {
88129 ret = child->driver->ops->trigger(substream,
....@@ -100,9 +141,15 @@
100141 {
101142 struct rk_mdais_dev *mdais = to_info(dai);
102143 struct snd_soc_dai *child;
144
+ unsigned int *channel_maps;
103145 int ret = 0, i = 0;
104146
147
+ channel_maps = mdais_channel_maps(mdais, substream);
148
+
105149 for (i = 0; i < mdais->num_dais; i++) {
150
+ if (!channel_maps[i])
151
+ continue;
152
+
106153 child = mdais->dais[i].dai;
107154 if (child->driver->ops && child->driver->ops->startup) {
108155 ret = child->driver->ops->startup(substream, child);
....@@ -119,9 +166,15 @@
119166 {
120167 struct rk_mdais_dev *mdais = to_info(dai);
121168 struct snd_soc_dai *child;
169
+ unsigned int *channel_maps;
122170 int i = 0;
123171
172
+ channel_maps = mdais_channel_maps(mdais, substream);
173
+
124174 for (i = 0; i < mdais->num_dais; i++) {
175
+ if (!channel_maps[i])
176
+ continue;
177
+
125178 child = mdais->dais[i].dai;
126179 if (child->driver->ops && child->driver->ops->shutdown) {
127180 child->driver->ops->shutdown(substream, child);
....@@ -134,9 +187,15 @@
134187 {
135188 struct rk_mdais_dev *mdais = to_info(dai);
136189 struct snd_soc_dai *child;
190
+ unsigned int *channel_maps;
137191 int ret = 0, i = 0;
138192
193
+ channel_maps = mdais_channel_maps(mdais, substream);
194
+
139195 for (i = 0; i < mdais->num_dais; i++) {
196
+ if (!channel_maps[i])
197
+ continue;
198
+
140199 child = mdais->dais[i].dai;
141200 if (child->driver->ops && child->driver->ops->prepare) {
142201 ret = child->driver->ops->prepare(substream, child);
....@@ -210,20 +269,38 @@
210269 static int rockchip_mdais_dai_probe(struct snd_soc_dai *dai)
211270 {
212271 struct rk_mdais_dev *mdais = to_info(dai);
272
+ struct snd_soc_component *comp;
213273 struct snd_soc_dai *child;
274
+ const char *str;
214275 int ret, i = 0;
215276
216277 for (i = 0; i < mdais->num_dais; i++) {
217278 child = mdais->dais[i].dai;
279
+ comp = child->component;
218280 if (!child->probed && child->driver->probe) {
219
- child->component->card = dai->component->card;
281
+ if (!comp->name_prefix) {
282
+ ret = device_property_read_string(child->dev,
283
+ SOUND_NAME_PREFIX, &str);
284
+ if (!ret)
285
+ comp->name_prefix = str;
286
+ }
287
+
288
+ comp->card = dai->component->card;
220289 ret = child->driver->probe(child);
221290 if (ret < 0) {
222291 dev_err(child->dev,
223
- "ASoC: failed to probe DAI %s: %d\n",
292
+ "Failed to probe DAI %s: %d\n",
224293 child->name, ret);
225294 return ret;
226295 }
296
+
297
+ ret = snd_soc_add_component_controls(comp,
298
+ comp->driver->controls,
299
+ comp->driver->num_controls);
300
+ if (ret)
301
+ dev_err(dai->dev, "%s: Failed to add controls, should add '%s' in DT\n",
302
+ dev_name(child->dev), SOUND_NAME_PREFIX);
303
+
227304 dai->probed = 1;
228305 }
229306 }
....@@ -233,6 +310,7 @@
233310
234311 static const struct snd_soc_dai_ops rockchip_mdais_dai_ops = {
235312 .hw_params = rockchip_mdais_hw_params,
313
+ .hw_free = rockchip_mdais_hw_free,
236314 .set_sysclk = rockchip_mdais_set_sysclk,
237315 .set_fmt = rockchip_mdais_set_fmt,
238316 .set_tdm_slot = rockchip_mdais_tdm_slot,
....@@ -258,7 +336,7 @@
258336
259337 dai_component.of_node = np;
260338
261
- return snd_soc_find_dai(&dai_component);
339
+ return snd_soc_find_dai_with_mutex(&dai_component);
262340 }
263341
264342 static int mdais_runtime_suspend(struct device *dev)
....@@ -373,9 +451,9 @@
373451 .probe = rockchip_mdais_dai_probe,
374452 .playback = {
375453 .stream_name = "Playback",
376
- .channels_min = 2,
377
- .channels_max = 32,
378
- .rates = SNDRV_PCM_RATE_8000_192000,
454
+ .channels_min = 1,
455
+ .channels_max = 512,
456
+ .rates = SNDRV_PCM_RATE_8000_384000,
379457 .formats = (SNDRV_PCM_FMTBIT_S8 |
380458 SNDRV_PCM_FMTBIT_S16_LE |
381459 SNDRV_PCM_FMTBIT_S20_3LE |
....@@ -384,9 +462,9 @@
384462 },
385463 .capture = {
386464 .stream_name = "Capture",
387
- .channels_min = 2,
388
- .channels_max = 32,
389
- .rates = SNDRV_PCM_RATE_8000_192000,
465
+ .channels_min = 1,
466
+ .channels_max = 512,
467
+ .rates = SNDRV_PCM_RATE_8000_384000,
390468 .formats = (SNDRV_PCM_FMTBIT_S8 |
391469 SNDRV_PCM_FMTBIT_S16_LE |
392470 SNDRV_PCM_FMTBIT_S20_3LE |