forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/au1x/dbdma2.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Au12x0/Au1550 PSC ALSA ASoC audio support.
34 *
45 * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
56 * Manuel Lauss <manuel.lauss@gmail.com>
67 *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
118 * DMA glue for Au1x-PSC audio.
12
- *
139 */
1410
1511
....@@ -186,27 +182,23 @@
186182 return 0;
187183 }
188184
189
-static inline struct au1xpsc_audio_dmadata *to_dmadata(struct snd_pcm_substream *ss)
185
+static inline struct au1xpsc_audio_dmadata *to_dmadata(struct snd_pcm_substream *ss,
186
+ struct snd_soc_component *component)
190187 {
191
- struct snd_soc_pcm_runtime *rtd = ss->private_data;
192
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
193188 struct au1xpsc_audio_dmadata *pcd = snd_soc_component_get_drvdata(component);
194189 return &pcd[ss->stream];
195190 }
196191
197
-static int au1xpsc_pcm_hw_params(struct snd_pcm_substream *substream,
192
+static int au1xpsc_pcm_hw_params(struct snd_soc_component *component,
193
+ struct snd_pcm_substream *substream,
198194 struct snd_pcm_hw_params *params)
199195 {
200196 struct snd_pcm_runtime *runtime = substream->runtime;
201197 struct au1xpsc_audio_dmadata *pcd;
202198 int stype, ret;
203199
204
- ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
205
- if (ret < 0)
206
- goto out;
207
-
208200 stype = substream->stream;
209
- pcd = to_dmadata(substream);
201
+ pcd = to_dmadata(substream, component);
210202
211203 DBG("runtime->dma_area = 0x%08lx dma_addr_t = 0x%08lx dma_size = %zu "
212204 "runtime->min_align %lu\n",
....@@ -236,15 +228,10 @@
236228 return ret;
237229 }
238230
239
-static int au1xpsc_pcm_hw_free(struct snd_pcm_substream *substream)
231
+static int au1xpsc_pcm_prepare(struct snd_soc_component *component,
232
+ struct snd_pcm_substream *substream)
240233 {
241
- snd_pcm_lib_free_pages(substream);
242
- return 0;
243
-}
244
-
245
-static int au1xpsc_pcm_prepare(struct snd_pcm_substream *substream)
246
-{
247
- struct au1xpsc_audio_dmadata *pcd = to_dmadata(substream);
234
+ struct au1xpsc_audio_dmadata *pcd = to_dmadata(substream, component);
248235
249236 au1xxx_dbdma_reset(pcd->ddma_chan);
250237
....@@ -259,9 +246,10 @@
259246 return 0;
260247 }
261248
262
-static int au1xpsc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
249
+static int au1xpsc_pcm_trigger(struct snd_soc_component *component,
250
+ struct snd_pcm_substream *substream, int cmd)
263251 {
264
- u32 c = to_dmadata(substream)->ddma_chan;
252
+ u32 c = to_dmadata(substream, component)->ddma_chan;
265253
266254 switch (cmd) {
267255 case SNDRV_PCM_TRIGGER_START:
....@@ -279,18 +267,21 @@
279267 }
280268
281269 static snd_pcm_uframes_t
282
-au1xpsc_pcm_pointer(struct snd_pcm_substream *substream)
270
+au1xpsc_pcm_pointer(struct snd_soc_component *component,
271
+ struct snd_pcm_substream *substream)
283272 {
284
- return bytes_to_frames(substream->runtime, to_dmadata(substream)->pos);
273
+ return bytes_to_frames(substream->runtime,
274
+ to_dmadata(substream, component)->pos);
285275 }
286276
287
-static int au1xpsc_pcm_open(struct snd_pcm_substream *substream)
277
+static int au1xpsc_pcm_open(struct snd_soc_component *component,
278
+ struct snd_pcm_substream *substream)
288279 {
289
- struct au1xpsc_audio_dmadata *pcd = to_dmadata(substream);
290
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
280
+ struct au1xpsc_audio_dmadata *pcd = to_dmadata(substream, component);
281
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
291282 int stype = substream->stream, *dmaids;
292283
293
- dmaids = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
284
+ dmaids = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
294285 if (!dmaids)
295286 return -ENODEV; /* whoa, has ordering changed? */
296287
....@@ -300,29 +291,20 @@
300291 return 0;
301292 }
302293
303
-static int au1xpsc_pcm_close(struct snd_pcm_substream *substream)
294
+static int au1xpsc_pcm_close(struct snd_soc_component *component,
295
+ struct snd_pcm_substream *substream)
304296 {
305
- au1x_pcm_dbdma_free(to_dmadata(substream));
297
+ au1x_pcm_dbdma_free(to_dmadata(substream, component));
306298 return 0;
307299 }
308300
309
-static const struct snd_pcm_ops au1xpsc_pcm_ops = {
310
- .open = au1xpsc_pcm_open,
311
- .close = au1xpsc_pcm_close,
312
- .ioctl = snd_pcm_lib_ioctl,
313
- .hw_params = au1xpsc_pcm_hw_params,
314
- .hw_free = au1xpsc_pcm_hw_free,
315
- .prepare = au1xpsc_pcm_prepare,
316
- .trigger = au1xpsc_pcm_trigger,
317
- .pointer = au1xpsc_pcm_pointer,
318
-};
319
-
320
-static int au1xpsc_pcm_new(struct snd_soc_pcm_runtime *rtd)
301
+static int au1xpsc_pcm_new(struct snd_soc_component *component,
302
+ struct snd_soc_pcm_runtime *rtd)
321303 {
322304 struct snd_card *card = rtd->card->snd_card;
323305 struct snd_pcm *pcm = rtd->pcm;
324306
325
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
307
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
326308 card->dev, AU1XPSC_BUFFER_MIN_BYTES, (4096 * 1024) - 1);
327309
328310 return 0;
....@@ -331,8 +313,13 @@
331313 /* au1xpsc audio platform */
332314 static struct snd_soc_component_driver au1xpsc_soc_component = {
333315 .name = DRV_NAME,
334
- .ops = &au1xpsc_pcm_ops,
335
- .pcm_new = au1xpsc_pcm_new,
316
+ .open = au1xpsc_pcm_open,
317
+ .close = au1xpsc_pcm_close,
318
+ .hw_params = au1xpsc_pcm_hw_params,
319
+ .prepare = au1xpsc_pcm_prepare,
320
+ .trigger = au1xpsc_pcm_trigger,
321
+ .pointer = au1xpsc_pcm_pointer,
322
+ .pcm_construct = au1xpsc_pcm_new,
336323 };
337324
338325 static int au1xpsc_pcm_drvprobe(struct platform_device *pdev)