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
....@@ -83,10 +117,7 @@
83117 unsigned int *channel_maps;
84118 int ret = 0, i = 0;
85119
86
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
87
- channel_maps = mdais->playback_channel_maps;
88
- else
89
- channel_maps = mdais->capture_channel_maps;
120
+ channel_maps = mdais_channel_maps(mdais, substream);
90121
91122 for (i = 0; i < mdais->num_dais; i++) {
92123 /* skip DAIs which have no channel mapping */
....@@ -110,9 +141,15 @@
110141 {
111142 struct rk_mdais_dev *mdais = to_info(dai);
112143 struct snd_soc_dai *child;
144
+ unsigned int *channel_maps;
113145 int ret = 0, i = 0;
114146
147
+ channel_maps = mdais_channel_maps(mdais, substream);
148
+
115149 for (i = 0; i < mdais->num_dais; i++) {
150
+ if (!channel_maps[i])
151
+ continue;
152
+
116153 child = mdais->dais[i].dai;
117154 if (child->driver->ops && child->driver->ops->startup) {
118155 ret = child->driver->ops->startup(substream, child);
....@@ -129,9 +166,15 @@
129166 {
130167 struct rk_mdais_dev *mdais = to_info(dai);
131168 struct snd_soc_dai *child;
169
+ unsigned int *channel_maps;
132170 int i = 0;
133171
172
+ channel_maps = mdais_channel_maps(mdais, substream);
173
+
134174 for (i = 0; i < mdais->num_dais; i++) {
175
+ if (!channel_maps[i])
176
+ continue;
177
+
135178 child = mdais->dais[i].dai;
136179 if (child->driver->ops && child->driver->ops->shutdown) {
137180 child->driver->ops->shutdown(substream, child);
....@@ -144,9 +187,15 @@
144187 {
145188 struct rk_mdais_dev *mdais = to_info(dai);
146189 struct snd_soc_dai *child;
190
+ unsigned int *channel_maps;
147191 int ret = 0, i = 0;
148192
193
+ channel_maps = mdais_channel_maps(mdais, substream);
194
+
149195 for (i = 0; i < mdais->num_dais; i++) {
196
+ if (!channel_maps[i])
197
+ continue;
198
+
150199 child = mdais->dais[i].dai;
151200 if (child->driver->ops && child->driver->ops->prepare) {
152201 ret = child->driver->ops->prepare(substream, child);
....@@ -220,20 +269,38 @@
220269 static int rockchip_mdais_dai_probe(struct snd_soc_dai *dai)
221270 {
222271 struct rk_mdais_dev *mdais = to_info(dai);
272
+ struct snd_soc_component *comp;
223273 struct snd_soc_dai *child;
274
+ const char *str;
224275 int ret, i = 0;
225276
226277 for (i = 0; i < mdais->num_dais; i++) {
227278 child = mdais->dais[i].dai;
279
+ comp = child->component;
228280 if (!child->probed && child->driver->probe) {
229
- 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;
230289 ret = child->driver->probe(child);
231290 if (ret < 0) {
232291 dev_err(child->dev,
233
- "ASoC: failed to probe DAI %s: %d\n",
292
+ "Failed to probe DAI %s: %d\n",
234293 child->name, ret);
235294 return ret;
236295 }
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
+
237304 dai->probed = 1;
238305 }
239306 }
....@@ -243,6 +310,7 @@
243310
244311 static const struct snd_soc_dai_ops rockchip_mdais_dai_ops = {
245312 .hw_params = rockchip_mdais_hw_params,
313
+ .hw_free = rockchip_mdais_hw_free,
246314 .set_sysclk = rockchip_mdais_set_sysclk,
247315 .set_fmt = rockchip_mdais_set_fmt,
248316 .set_tdm_slot = rockchip_mdais_tdm_slot,
....@@ -383,9 +451,9 @@
383451 .probe = rockchip_mdais_dai_probe,
384452 .playback = {
385453 .stream_name = "Playback",
386
- .channels_min = 2,
387
- .channels_max = 32,
388
- .rates = SNDRV_PCM_RATE_8000_192000,
454
+ .channels_min = 1,
455
+ .channels_max = 512,
456
+ .rates = SNDRV_PCM_RATE_8000_384000,
389457 .formats = (SNDRV_PCM_FMTBIT_S8 |
390458 SNDRV_PCM_FMTBIT_S16_LE |
391459 SNDRV_PCM_FMTBIT_S20_3LE |
....@@ -394,9 +462,9 @@
394462 },
395463 .capture = {
396464 .stream_name = "Capture",
397
- .channels_min = 2,
398
- .channels_max = 32,
399
- .rates = SNDRV_PCM_RATE_8000_192000,
465
+ .channels_min = 1,
466
+ .channels_max = 512,
467
+ .rates = SNDRV_PCM_RATE_8000_384000,
400468 .formats = (SNDRV_PCM_FMTBIT_S8 |
401469 SNDRV_PCM_FMTBIT_S16_LE |
402470 SNDRV_PCM_FMTBIT_S20_3LE |