1 /*
2 * Copyright (C) 2022 HiHope Open Source Organization .
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8 #include <sound/memalloc.h>
9 #include <linux/delay.h>
10 #include <linux/device.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/notifier.h>
17 #include <linux/of.h>
18 #include <linux/of_dma.h>
19 #include <linux/of_device.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
22 #include <linux/stat.h>
23 #include <linux/string.h>
24 #include <linux/sysfs.h>
25 #include <linux/suspend.h>
26
27 #include "audio_platform_base.h"
28 #include "audio_dma_base.h"
29 #include "osal_io.h"
30 #include "osal_uaccess.h"
31 #include "audio_driver_log.h"
32 #include "rk3568_dma_ops.h"
33
34 #define HDF_LOG_TAG rk3568_platform_ops
35
36 #define I2S_TXDR 0x24
37 #define I2S_RXDR 0x28
38
39 #define DMA_TX_CHANNEL 0
40 #define DMA_RX_CHANNEL 1
41
42 #define DMA_CHANNEL_MAX 2
43
44 struct DmaRuntimeData {
45 struct dma_chan *dmaChn[DMA_CHANNEL_MAX];
46 dma_cookie_t cookie[DMA_CHANNEL_MAX];
47 struct device *dmaDev;
48 char *i2sDtsTreePath;
49 struct device_node *dmaOfNode;
50 uint32_t i2sAddr;
51 struct HdfDeviceObject *device;
52 };
53
GetDmaDevice(struct PlatformData * data)54 static int32_t GetDmaDevice(struct PlatformData *data)
55 {
56 struct DmaRuntimeData *dmaRtd = NULL;
57 struct platform_device *platformdev = NULL;
58 const char *i2s1DtsTreePath;
59
60 if (data == NULL || data->regConfig == NULL) {
61 AUDIO_DEVICE_LOG_ERR("PlatformData is null.");
62 return HDF_FAILURE;
63 }
64
65 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
66 if (dmaRtd == NULL) {
67 AUDIO_DEVICE_LOG_ERR("dmaRtd is null.");
68 return HDF_FAILURE;
69 }
70
71 i2s1DtsTreePath = data->regConfig->audioIdInfo.chipName;
72 dmaRtd->i2sAddr = data->regConfig->audioIdInfo.chipIdRegister;
73 dmaRtd->dmaOfNode = of_find_node_by_path(i2s1DtsTreePath);
74 if (dmaRtd->dmaOfNode == NULL) {
75 AUDIO_DEVICE_LOG_ERR("get device node failed.");
76 return HDF_FAILURE;
77 }
78
79 platformdev = of_find_device_by_node(dmaRtd->dmaOfNode);
80 if (platformdev == NULL) {
81 AUDIO_DEVICE_LOG_ERR("get platformdev failed.");
82 return HDF_FAILURE;
83 }
84
85 dmaRtd->dmaDev = &platformdev->dev;
86 return HDF_SUCCESS;
87 }
88
GetDmaChannel(struct PlatformData * data)89 static int32_t GetDmaChannel(struct PlatformData *data)
90 {
91 struct DmaRuntimeData *dmaRtd = NULL;
92 struct device_node *dmaOfNode = NULL;
93 struct device *dmaDevice = NULL;
94 struct property *dma_names = NULL;
95 const char *dma_name = NULL;
96 bool hasRender = false;
97 bool hasCapture = false;
98 static const char * const dmaChannelNames[] = {
99 [DMA_TX_CHANNEL] = "tx", [DMA_RX_CHANNEL] = "rx",
100 };
101
102 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
103 if (dmaRtd == NULL) {
104 AUDIO_DEVICE_LOG_ERR("dmaRtd is null.");
105 return HDF_FAILURE;
106 }
107
108 dmaOfNode = dmaRtd->dmaOfNode;
109 if (dmaOfNode == NULL) {
110 AUDIO_DEVICE_LOG_ERR("dmaOfNode is null.");
111 return HDF_FAILURE;
112 }
113 of_property_for_each_string(dmaOfNode, "dma-names", dma_names, dma_name) {
114 if (strcmp(dma_name, "rx") == 0) {
115 hasCapture = true;
116 }
117 if (strcmp(dma_name, "tx") == 0) {
118 hasRender = true;
119 }
120 }
121
122 dmaDevice = dmaRtd->dmaDev;
123 if (dmaDevice == NULL) {
124 AUDIO_DEVICE_LOG_ERR("dmaDevice is null.");
125 return HDF_FAILURE;
126 }
127 if (hasRender) {
128 dmaRtd->dmaChn[DMA_TX_CHANNEL] = dma_request_slave_channel(dmaDevice, dmaChannelNames[DMA_TX_CHANNEL]);
129 if (dmaRtd->dmaChn[DMA_TX_CHANNEL] == NULL) {
130 AUDIO_DEVICE_LOG_ERR("dma_request_slave_channel DMA_TX_CHANNEL failed");
131 return HDF_FAILURE;
132 }
133 }
134 if (hasCapture) {
135 dmaRtd->dmaChn[DMA_RX_CHANNEL] = dma_request_slave_channel(dmaDevice, dmaChannelNames[DMA_RX_CHANNEL]);
136 if (dmaRtd->dmaChn[DMA_RX_CHANNEL] == NULL) {
137 AUDIO_DEVICE_LOG_ERR("dma_request_slave_channel DMA_RX_CHANNEL failed");
138 return HDF_FAILURE;
139 }
140 }
141 return HDF_SUCCESS;
142 }
143
DmaRtdInit(struct PlatformData * data)144 static int32_t DmaRtdInit(struct PlatformData *data)
145 {
146 struct DmaRuntimeData *dmaRtd = NULL;
147 int ret;
148
149 if (data == NULL || data->regConfig == NULL) {
150 AUDIO_DEVICE_LOG_ERR("data is null.");
151 return HDF_FAILURE;
152 }
153
154 dmaRtd = kzalloc(sizeof(*dmaRtd), GFP_KERNEL);
155 if (!dmaRtd) {
156 AUDIO_DEVICE_LOG_ERR("AudioRenderBuffInit: fail.");
157 return HDF_FAILURE;
158 }
159 data->dmaPrv = dmaRtd;
160
161 ret = GetDmaDevice(data);
162 if (ret != HDF_SUCCESS) {
163 AUDIO_DEVICE_LOG_ERR("GetDmaDevice: fail.");
164 return HDF_FAILURE;
165 }
166
167 ret = GetDmaChannel(data);
168 if (ret != HDF_SUCCESS) {
169 AUDIO_DEVICE_LOG_ERR("GetDmaChannel: fail.");
170 return HDF_FAILURE;
171 }
172
173 AUDIO_DEVICE_LOG_DEBUG("success.");
174 return HDF_SUCCESS;
175 }
176
AudioDmaDeviceInit(const struct AudioCard * card,const struct PlatformDevice * platform)177 int32_t AudioDmaDeviceInit(const struct AudioCard *card, const struct PlatformDevice *platform)
178 {
179 struct PlatformData *data = NULL;
180 struct DmaRuntimeData *dmaRtd = NULL;
181 int ret;
182 (void)platform;
183
184 if (card == NULL) {
185 AUDIO_DEVICE_LOG_ERR("card is null.");
186 return HDF_FAILURE;
187 }
188
189 data = PlatformDataFromCard(card);
190 if (data == NULL) {
191 AUDIO_DEVICE_LOG_ERR("PlatformDataFromCard failed.");
192 return HDF_FAILURE;
193 }
194
195 if (data->platformInitFlag) {
196 AUDIO_DRIVER_LOG_DEBUG("platform init complete!");
197 return HDF_SUCCESS;
198 }
199
200 ret = DmaRtdInit(data);
201 if (ret != HDF_SUCCESS) {
202 AUDIO_DEVICE_LOG_ERR("DmaRtdInit failed.");
203 return HDF_FAILURE;
204 }
205
206 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
207 if (dmaRtd == NULL) {
208 AUDIO_DEVICE_LOG_ERR("dmaRtd is null.");
209 return HDF_FAILURE;
210 }
211 dmaRtd->device = card->device;
212
213 data->platformInitFlag = true;
214 AUDIO_DEVICE_LOG_DEBUG("success.");
215 return HDF_SUCCESS;
216 }
217
Rk3568DmaBufAlloc(struct PlatformData * data,const enum AudioStreamType streamType)218 int32_t Rk3568DmaBufAlloc(struct PlatformData *data, const enum AudioStreamType streamType)
219 {
220 uint32_t preallocBufSize;
221 struct DmaRuntimeData *dmaRtd = NULL;
222 struct device *dmaDevice = NULL;
223
224 if (data == NULL) {
225 AUDIO_DEVICE_LOG_ERR("data is null");
226 return HDF_FAILURE;
227 }
228
229 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
230 if (dmaRtd == NULL) {
231 AUDIO_DEVICE_LOG_ERR("dmaRtd is null.");
232 return HDF_FAILURE;
233 }
234
235 dmaDevice = dmaRtd->dmaDev;
236 if (dmaDevice == NULL) {
237 AUDIO_DEVICE_LOG_ERR("dmaDevice is null");
238 return HDF_FAILURE;
239 }
240
241 if (streamType == AUDIO_CAPTURE_STREAM) {
242 if (data->captureBufInfo.virtAddr == NULL) {
243 preallocBufSize = data->captureBufInfo.cirBufMax;
244 dmaDevice->coherent_dma_mask = 0xffffffffUL;
245 data->captureBufInfo.virtAddr = dma_alloc_wc(dmaDevice, preallocBufSize,
246 (dma_addr_t *)&data->captureBufInfo.phyAddr, GFP_DMA | GFP_KERNEL);
247 }
248 } else if (streamType == AUDIO_RENDER_STREAM) {
249 if (data->renderBufInfo.virtAddr == NULL) {
250 preallocBufSize = data->renderBufInfo.cirBufMax;
251 dmaDevice->coherent_dma_mask = 0xffffffffUL;
252 data->renderBufInfo.virtAddr = dma_alloc_wc(dmaDevice, preallocBufSize,
253 (dma_addr_t *)&data->renderBufInfo.phyAddr, GFP_DMA | GFP_KERNEL);
254 }
255 } else {
256 AUDIO_DEVICE_LOG_ERR("stream Type is invalude.");
257 return HDF_FAILURE;
258 }
259
260 AUDIO_DEVICE_LOG_DEBUG("success.");
261 return HDF_SUCCESS;
262 }
263
Rk3568DmaBufFree(struct PlatformData * data,const enum AudioStreamType streamType)264 int32_t Rk3568DmaBufFree(struct PlatformData *data, const enum AudioStreamType streamType)
265 {
266 struct DmaRuntimeData *dmaRtd = NULL;
267 struct device *dmaDevice = NULL;
268
269 if (data == NULL || data->dmaPrv == NULL) {
270 AUDIO_DEVICE_LOG_ERR("data is null");
271 return HDF_FAILURE;
272 }
273
274 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
275 dmaDevice = dmaRtd->dmaDev;
276 if (dmaDevice == NULL) {
277 AUDIO_DEVICE_LOG_ERR("dmaDevice is null");
278 return HDF_FAILURE;
279 }
280
281 if (streamType == AUDIO_CAPTURE_STREAM) {
282 dma_free_wc(dmaDevice, data->captureBufInfo.cirBufMax, data->captureBufInfo.virtAddr,
283 data->captureBufInfo.phyAddr);
284 } else if (streamType == AUDIO_RENDER_STREAM) {
285 dma_free_wc(dmaDevice, data->renderBufInfo.cirBufMax, data->renderBufInfo.virtAddr,
286 data->renderBufInfo.phyAddr);
287 } else {
288 AUDIO_DEVICE_LOG_ERR("stream Type is invalude.");
289 return HDF_FAILURE;
290 }
291
292 AUDIO_DEVICE_LOG_DEBUG("success");
293 return HDF_SUCCESS;
294 }
295
Rk3568DmaRequestChannel(const struct PlatformData * data,const enum AudioStreamType streamType)296 int32_t Rk3568DmaRequestChannel(const struct PlatformData *data, const enum AudioStreamType streamType)
297 {
298 (void)data;
299 AUDIO_DEVICE_LOG_DEBUG("sucess");
300 return HDF_SUCCESS;
301 }
302
Rk3568DmaConfigChannel(const struct PlatformData * data,const enum AudioStreamType streamType)303 int32_t Rk3568DmaConfigChannel(const struct PlatformData *data, const enum AudioStreamType streamType)
304 {
305 struct dma_chan *dmaChan = NULL;
306 struct dma_slave_config slaveConfig;
307 int32_t ret = 0;
308 struct DmaRuntimeData *dmaRtd = NULL;
309
310 if (data == NULL || data->dmaPrv == NULL) {
311 AUDIO_DEVICE_LOG_ERR("data is null");
312 return HDF_FAILURE;
313 }
314
315 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
316 (void)memset_s(&slaveConfig, sizeof(slaveConfig), 0, sizeof(slaveConfig));
317 if (streamType == AUDIO_RENDER_STREAM) {
318 dmaChan = (struct dma_chan *)dmaRtd->dmaChn[DMA_TX_CHANNEL]; // tx
319 slaveConfig.direction = DMA_MEM_TO_DEV;
320 slaveConfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
321 slaveConfig.dst_addr = dmaRtd->i2sAddr + I2S_TXDR;
322 slaveConfig.dst_maxburst = 8; // Max Transimit 8 Byte
323 } else {
324 dmaChan = (struct dma_chan *)dmaRtd->dmaChn[DMA_RX_CHANNEL];
325 slaveConfig.direction = DMA_DEV_TO_MEM;
326 slaveConfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
327 slaveConfig.src_addr = dmaRtd->i2sAddr + I2S_RXDR;
328 slaveConfig.src_maxburst = 8; // Max Transimit 8 Byte
329 }
330 slaveConfig.device_fc = 0;
331 slaveConfig.slave_id = 0;
332
333 if (dmaChan == NULL) {
334 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
335 return HDF_FAILURE;
336 }
337 ret = dmaengine_slave_config(dmaChan, &slaveConfig);
338 if (ret != 0) {
339 AUDIO_DEVICE_LOG_ERR("dmaengine_slave_config failed");
340 return HDF_FAILURE;
341 }
342 AUDIO_DEVICE_LOG_DEBUG("success");
343 return HDF_SUCCESS;
344 }
345
BytesToFrames(uint32_t frameBits,uint32_t size,uint32_t * pointer)346 static int32_t BytesToFrames(uint32_t frameBits, uint32_t size, uint32_t *pointer)
347 {
348 if (pointer == NULL || frameBits == 0) {
349 AUDIO_DEVICE_LOG_ERR("input para is error.");
350 return HDF_FAILURE;
351 }
352 *pointer = size / frameBits;
353 return HDF_SUCCESS;
354 }
355
Rk3568PcmPointer(struct PlatformData * data,const enum AudioStreamType streamType,uint32_t * pointer)356 int32_t Rk3568PcmPointer(struct PlatformData *data, const enum AudioStreamType streamType, uint32_t *pointer)
357 {
358 uint32_t bufSize;
359 struct dma_chan *dmaChan = NULL;
360 struct dma_tx_state dmaState;
361 uint32_t currentPointer;
362 int ret;
363 struct DmaRuntimeData *dmaRtd = NULL;
364
365 if (data == NULL || data->dmaPrv == NULL) {
366 AUDIO_DEVICE_LOG_ERR("data is null");
367 return HDF_FAILURE;
368 }
369 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
370
371 if (streamType == AUDIO_RENDER_STREAM) {
372 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
373 bufSize = data->renderBufInfo.cirBufSize;
374 if (dmaChan == NULL) {
375 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
376 return HDF_FAILURE;
377 }
378 dmaengine_tx_status(dmaChan, dmaRtd->cookie[DMA_TX_CHANNEL], &dmaState);
379
380 if (dmaState.residue > 0) {
381 currentPointer = bufSize - dmaState.residue;
382 ret = BytesToFrames(data->renderPcmInfo.frameSize, currentPointer, pointer);
383 if (ret != HDF_SUCCESS) {
384 AUDIO_DEVICE_LOG_ERR("BytesToFrames is failed.");
385 return HDF_FAILURE;
386 }
387 } else {
388 *pointer = 0;
389 }
390 } else {
391 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
392 bufSize = data->captureBufInfo.cirBufSize;
393 if (dmaChan == NULL) {
394 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
395 return HDF_FAILURE;
396 }
397 dmaengine_tx_status(dmaChan, dmaRtd->cookie[DMA_RX_CHANNEL], &dmaState);
398
399 if (dmaState.residue > 0) {
400 currentPointer = bufSize - dmaState.residue;
401 ret = BytesToFrames(data->capturePcmInfo.frameSize, currentPointer, pointer);
402 if (ret != HDF_SUCCESS) {
403 AUDIO_DEVICE_LOG_ERR("BytesToFrames is failed.");
404 return HDF_FAILURE;
405 }
406 } else {
407 *pointer = 0;
408 }
409 }
410
411 return HDF_SUCCESS;
412 }
413
Rk3568DmaPrep(const struct PlatformData * data,const enum AudioStreamType streamType)414 int32_t Rk3568DmaPrep(const struct PlatformData *data, const enum AudioStreamType streamType)
415 {
416 (void)data;
417 return HDF_SUCCESS;
418 }
419
RenderPcmDmaComplete(void * arg)420 static void RenderPcmDmaComplete(void *arg)
421 {
422 struct PlatformData *data = NULL;
423 struct DmaRuntimeData *dmaRtd = NULL;
424 struct dma_chan *dmaChan = NULL;
425
426 data = (struct PlatformData *)arg;
427 if (data == NULL || data->dmaPrv == NULL) {
428 AUDIO_DEVICE_LOG_ERR("data is null.");
429 return;
430 }
431
432 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
433 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
434 if (dmaChan == NULL) {
435 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
436 return;
437 }
438 if (!AudioDmaTransferStatusIsNormal(data, AUDIO_RENDER_STREAM)) {
439 dmaengine_terminate_async(dmaChan);
440 }
441 }
442
CapturePcmDmaComplete(void * arg)443 static void CapturePcmDmaComplete(void *arg)
444 {
445 struct AudioEvent reportMsg;
446 struct PlatformData *data = NULL;
447 struct DmaRuntimeData *dmaRtd = NULL;
448 struct dma_chan *dmaChan = NULL;
449
450 data = (struct PlatformData *)arg;
451 if (data == NULL || data->dmaPrv == NULL) {
452 AUDIO_DEVICE_LOG_ERR("data is null.");
453 return;
454 }
455 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
456 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
457 if (dmaChan == NULL) {
458 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
459 return;
460 }
461
462 if (!AudioDmaTransferStatusIsNormal(data, AUDIO_CAPTURE_STREAM)) {
463 dmaengine_terminate_async(dmaChan);
464 }
465 reportMsg.eventType = HDF_AUDIO_CAPTURE_THRESHOLD;
466 reportMsg.deviceType = HDF_AUDIO_PRIMARY_DEVICE;
467 #ifdef CONFIG_AUDIO_ENABLE_CAP_THRESHOLD
468 if (AudioCapSilenceThresholdEvent(dmaRtd->device, &reportMsg) != HDF_SUCCESS) {
469 AUDIO_DRIVER_LOG_ERR("AudioCapSilenceThresholdEvent failed.");
470 }
471 #endif
472 }
473
Rk3568DmaSubmit(const struct PlatformData * data,const enum AudioStreamType streamType)474 int32_t Rk3568DmaSubmit(const struct PlatformData *data, const enum AudioStreamType streamType)
475 {
476 struct dma_async_tx_descriptor *desc = NULL;
477 enum dma_transfer_direction direction;
478 unsigned long flags = 3;
479 struct dma_chan *dmaChan = NULL;
480 struct DmaRuntimeData *dmaRtd = NULL;
481
482 if (data == NULL || data->dmaPrv == NULL) {
483 AUDIO_DEVICE_LOG_ERR("input para is null.");
484 return HDF_FAILURE;
485 }
486
487 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
488
489 if (streamType == AUDIO_RENDER_STREAM) {
490 direction = DMA_MEM_TO_DEV;
491 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
492 if (dmaChan == NULL) {
493 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
494 return HDF_FAILURE;
495 }
496 desc = dmaengine_prep_dma_cyclic(dmaChan,
497 data->renderBufInfo.phyAddr,
498 data->renderBufInfo.cirBufSize,
499 data->renderBufInfo.periodSize, direction, flags);
500 if (!desc) {
501 AUDIO_DEVICE_LOG_ERR("DMA_TX_CHANNEL desc create failed");
502 return -ENOMEM;
503 }
504 desc->callback = RenderPcmDmaComplete;
505 desc->callback_param = (void *)data;
506
507 dmaRtd->cookie[DMA_TX_CHANNEL] = dmaengine_submit(desc);
508 } else {
509 direction = DMA_DEV_TO_MEM;
510 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
511 if (dmaChan == NULL) {
512 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
513 return HDF_FAILURE;
514 }
515
516 desc = dmaengine_prep_dma_cyclic(dmaChan,
517 data->captureBufInfo.phyAddr,
518 data->captureBufInfo.cirBufSize,
519 data->captureBufInfo.periodSize, direction, flags);
520 if (!desc) {
521 AUDIO_DEVICE_LOG_ERR("DMA_RX_CHANNEL desc create failed");
522 return -ENOMEM;
523 }
524 desc->callback = CapturePcmDmaComplete;
525 desc->callback_param = (void *)data;
526 dmaRtd->cookie[DMA_RX_CHANNEL] = dmaengine_submit(desc);
527 }
528
529 AUDIO_DEVICE_LOG_DEBUG("success");
530 return 0;
531 }
532
Rk3568DmaPending(struct PlatformData * data,const enum AudioStreamType streamType)533 int32_t Rk3568DmaPending(struct PlatformData *data, const enum AudioStreamType streamType)
534 {
535 struct dma_chan *dmaChan = NULL;
536 struct DmaRuntimeData *dmaRtd = NULL;
537
538 if (data == NULL || data->dmaPrv == NULL) {
539 AUDIO_DEVICE_LOG_ERR("data is null");
540 return HDF_FAILURE;
541 }
542
543 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
544 if (dmaRtd->dmaChn[0] == NULL) {
545 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
546 return HDF_FAILURE;
547 }
548
549 AUDIO_DEVICE_LOG_DEBUG("streamType = %d", streamType);
550 if (streamType == AUDIO_RENDER_STREAM) {
551 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
552 } else {
553 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
554 }
555 if (dmaChan == NULL) {
556 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
557 return HDF_FAILURE;
558 }
559
560 dma_async_issue_pending(dmaChan);
561 AUDIO_DEVICE_LOG_DEBUG("dmaChan chan_id = %d.", dmaChan->chan_id);
562
563 AUDIO_DEVICE_LOG_DEBUG("success");
564 return HDF_SUCCESS;
565 }
566
Rk3568DmaPause(struct PlatformData * data,const enum AudioStreamType streamType)567 int32_t Rk3568DmaPause(struct PlatformData *data, const enum AudioStreamType streamType)
568 {
569 struct dma_chan *dmaChan = NULL;
570 struct DmaRuntimeData *dmaRtd = NULL;
571
572 if (data == NULL || data->dmaPrv == NULL) {
573 AUDIO_DEVICE_LOG_ERR("data is null");
574 return HDF_FAILURE;
575 }
576
577 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
578 if (dmaRtd->dmaChn[0] == NULL) {
579 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
580 return HDF_FAILURE;
581 }
582
583 if (streamType == AUDIO_RENDER_STREAM) {
584 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
585 } else {
586 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
587 }
588 // can not use dmaengine_pause function
589 if (dmaChan == NULL) {
590 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
591 return HDF_FAILURE;
592 }
593 dmaengine_terminate_async(dmaChan);
594
595 AUDIO_DEVICE_LOG_DEBUG("success");
596 return HDF_SUCCESS;
597 }
Rk3568DmaResume(const struct PlatformData * data,const enum AudioStreamType streamType)598 int32_t Rk3568DmaResume(const struct PlatformData *data, const enum AudioStreamType streamType)
599 {
600 int ret;
601 struct dma_chan *dmaChan = NULL;
602 struct DmaRuntimeData *dmaRtd = NULL;
603
604 if (data == NULL || data->dmaPrv == NULL) {
605 AUDIO_DEVICE_LOG_ERR("data is null");
606 return HDF_FAILURE;
607 }
608
609 dmaRtd = (struct DmaRuntimeData *)data->dmaPrv;
610 if (dmaRtd->dmaChn[0] == NULL) {
611 AUDIO_DEVICE_LOG_ERR("dmaRtd->dmaChn is null");
612 return HDF_FAILURE;
613 }
614
615 if (streamType == AUDIO_RENDER_STREAM) {
616 dmaChan = dmaRtd->dmaChn[DMA_TX_CHANNEL];
617 } else {
618 dmaChan = dmaRtd->dmaChn[DMA_RX_CHANNEL];
619 }
620 if (dmaChan == NULL) {
621 AUDIO_DEVICE_LOG_ERR("dmaChan is null");
622 return HDF_FAILURE;
623 }
624
625 // use start Operation function
626 ret = Rk3568DmaSubmit(data, streamType);
627 if (ret != HDF_SUCCESS) {
628 AUDIO_DEVICE_LOG_ERR("call Rk3568DmaSubmit failed");
629 return HDF_FAILURE;
630 }
631 dma_async_issue_pending(dmaChan);
632
633 AUDIO_DEVICE_LOG_DEBUG("success");
634 return HDF_SUCCESS;
635 }
636