forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/txx9/txx9aclc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic TXx9 ACLC platform driver
34 *
....@@ -5,10 +6,6 @@
56 *
67 * Based on RBTX49xx patch from CELF patch archive.
78 * (C) Copyright TOSHIBA CORPORATION 2004-2006
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License version 2 as
11
- * published by the Free Software Foundation.
129 */
1310
1411 #include <linux/module.h>
....@@ -50,18 +47,12 @@
5047 .buffer_bytes_max = 32 * 1024,
5148 };
5249
53
-static int txx9aclc_pcm_hw_params(struct snd_pcm_substream *substream,
50
+static int txx9aclc_pcm_hw_params(struct snd_soc_component *component,
51
+ struct snd_pcm_substream *substream,
5452 struct snd_pcm_hw_params *params)
5553 {
56
- struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
5754 struct snd_pcm_runtime *runtime = substream->runtime;
58
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
5955 struct txx9aclc_dmadata *dmadata = runtime->private_data;
60
- int ret;
61
-
62
- ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
63
- if (ret < 0)
64
- return ret;
6556
6657 dev_dbg(component->dev,
6758 "runtime->dma_area = %#lx dma_addr = %#lx dma_bytes = %zd "
....@@ -79,12 +70,8 @@
7970 return 0;
8071 }
8172
82
-static int txx9aclc_pcm_hw_free(struct snd_pcm_substream *substream)
83
-{
84
- return snd_pcm_lib_free_pages(substream);
85
-}
86
-
87
-static int txx9aclc_pcm_prepare(struct snd_pcm_substream *substream)
73
+static int txx9aclc_pcm_prepare(struct snd_soc_component *component,
74
+ struct snd_pcm_substream *substream)
8875 {
8976 struct snd_pcm_runtime *runtime = substream->runtime;
9077 struct txx9aclc_dmadata *dmadata = runtime->private_data;
....@@ -115,7 +102,7 @@
115102 if (dmadata->frag_count >= 0) {
116103 dmadata->dmacount--;
117104 if (!WARN_ON(dmadata->dmacount < 0))
118
- tasklet_schedule(&dmadata->tasklet);
105
+ queue_work(system_highpri_wq, &dmadata->work);
119106 }
120107 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
121108 }
....@@ -147,9 +134,10 @@
147134
148135 #define NR_DMA_CHAIN 2
149136
150
-static void txx9aclc_dma_tasklet(unsigned long data)
137
+static void txx9aclc_dma_work(struct work_struct *work)
151138 {
152
- struct txx9aclc_dmadata *dmadata = (struct txx9aclc_dmadata *)data;
139
+ struct txx9aclc_dmadata *dmadata =
140
+ container_of(work, struct txx9aclc_dmadata, work);
153141 struct dma_chan *chan = dmadata->dma_chan;
154142 struct dma_async_tx_descriptor *desc;
155143 struct snd_pcm_substream *substream = dmadata->substream;
....@@ -206,7 +194,8 @@
206194 spin_unlock_irqrestore(&dmadata->dma_lock, flags);
207195 }
208196
209
-static int txx9aclc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
197
+static int txx9aclc_pcm_trigger(struct snd_soc_component *component,
198
+ struct snd_pcm_substream *substream, int cmd)
210199 {
211200 struct txx9aclc_dmadata *dmadata = substream->runtime->private_data;
212201 struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata;
....@@ -220,7 +209,7 @@
220209 switch (cmd) {
221210 case SNDRV_PCM_TRIGGER_START:
222211 dmadata->frag_count = -1;
223
- tasklet_schedule(&dmadata->tasklet);
212
+ queue_work(system_highpri_wq, &dmadata->work);
224213 break;
225214 case SNDRV_PCM_TRIGGER_STOP:
226215 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
....@@ -239,14 +228,16 @@
239228 }
240229
241230 static snd_pcm_uframes_t
242
-txx9aclc_pcm_pointer(struct snd_pcm_substream *substream)
231
+txx9aclc_pcm_pointer(struct snd_soc_component *component,
232
+ struct snd_pcm_substream *substream)
243233 {
244234 struct txx9aclc_dmadata *dmadata = substream->runtime->private_data;
245235
246236 return bytes_to_frames(substream->runtime, dmadata->pos);
247237 }
248238
249
-static int txx9aclc_pcm_open(struct snd_pcm_substream *substream)
239
+static int txx9aclc_pcm_open(struct snd_soc_component *component,
240
+ struct snd_pcm_substream *substream)
250241 {
251242 struct txx9aclc_soc_device *dev = &txx9aclc_soc_device;
252243 struct txx9aclc_dmadata *dmadata = &dev->dmadata[substream->stream];
....@@ -264,7 +255,8 @@
264255 return 0;
265256 }
266257
267
-static int txx9aclc_pcm_close(struct snd_pcm_substream *substream)
258
+static int txx9aclc_pcm_close(struct snd_soc_component *component,
259
+ struct snd_pcm_substream *substream)
268260 {
269261 struct txx9aclc_dmadata *dmadata = substream->runtime->private_data;
270262 struct dma_chan *chan = dmadata->dma_chan;
....@@ -274,23 +266,12 @@
274266 return 0;
275267 }
276268
277
-static const struct snd_pcm_ops txx9aclc_pcm_ops = {
278
- .open = txx9aclc_pcm_open,
279
- .close = txx9aclc_pcm_close,
280
- .ioctl = snd_pcm_lib_ioctl,
281
- .hw_params = txx9aclc_pcm_hw_params,
282
- .hw_free = txx9aclc_pcm_hw_free,
283
- .prepare = txx9aclc_pcm_prepare,
284
- .trigger = txx9aclc_pcm_trigger,
285
- .pointer = txx9aclc_pcm_pointer,
286
-};
287
-
288
-static int txx9aclc_pcm_new(struct snd_soc_pcm_runtime *rtd)
269
+static int txx9aclc_pcm_new(struct snd_soc_component *component,
270
+ struct snd_soc_pcm_runtime *rtd)
289271 {
290272 struct snd_card *card = rtd->card->snd_card;
291
- struct snd_soc_dai *dai = rtd->cpu_dai;
273
+ struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0);
292274 struct snd_pcm *pcm = rtd->pcm;
293
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
294275 struct platform_device *pdev = to_platform_device(component->dev);
295276 struct txx9aclc_soc_device *dev;
296277 struct resource *r;
....@@ -313,8 +294,10 @@
313294 if (ret)
314295 goto exit;
315296 }
316
- return snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
297
+
298
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
317299 card->dev, 64 * 1024, 4 * 1024 * 1024);
300
+ return 0;
318301
319302 exit:
320303 for (i = 0; i < 2; i++) {
....@@ -370,8 +353,7 @@
370353 "playback" : "capture");
371354 return -EBUSY;
372355 }
373
- tasklet_init(&dmadata->tasklet, txx9aclc_dma_tasklet,
374
- (unsigned long)dmadata);
356
+ INIT_WORK(&dmadata->work, txx9aclc_dma_work);
375357 return 0;
376358 }
377359
....@@ -410,8 +392,13 @@
410392 .name = DRV_NAME,
411393 .probe = txx9aclc_pcm_probe,
412394 .remove = txx9aclc_pcm_remove,
413
- .ops = &txx9aclc_pcm_ops,
414
- .pcm_new = txx9aclc_pcm_new,
395
+ .open = txx9aclc_pcm_open,
396
+ .close = txx9aclc_pcm_close,
397
+ .hw_params = txx9aclc_pcm_hw_params,
398
+ .prepare = txx9aclc_pcm_prepare,
399
+ .trigger = txx9aclc_pcm_trigger,
400
+ .pointer = txx9aclc_pcm_pointer,
401
+ .pcm_construct = txx9aclc_pcm_new,
415402 };
416403
417404 static int txx9aclc_soc_platform_probe(struct platform_device *pdev)