hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/dma/mmp_tdma.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver For Marvell Two-channel DMA Engine
34 *
45 * Copyright: Marvell International Ltd.
5
- *
6
- * The code contained herein is licensed under the GNU General Public
7
- * License. You may obtain a copy of the GNU General Public License
8
- * Version 2 or later at the following locations:
9
- *
106 */
117
128 #include <linux/err.h>
....@@ -116,6 +112,7 @@
116112 u32 burst_sz;
117113 enum dma_slave_buswidth buswidth;
118114 enum dma_status status;
115
+ struct dma_slave_config slave_config;
119116
120117 int idx;
121118 enum mmp_tdma_type type;
....@@ -138,6 +135,10 @@
138135 };
139136
140137 #define to_mmp_tdma_chan(dchan) container_of(dchan, struct mmp_tdma_chan, chan)
138
+
139
+static int mmp_tdma_config_write(struct dma_chan *chan,
140
+ enum dma_transfer_direction dir,
141
+ struct dma_slave_config *dmaengine_cfg);
141142
142143 static void mmp_tdma_chan_set_desc(struct mmp_tdma_chan *tdmac, dma_addr_t phys)
143144 {
....@@ -234,7 +235,7 @@
234235 tdcr |= TDCR_BURSTSZ_128B;
235236 break;
236237 default:
237
- dev_err(tdmac->dev, "mmp_tdma: unknown burst size.\n");
238
+ dev_err(tdmac->dev, "unknown burst size.\n");
238239 return -EINVAL;
239240 }
240241
....@@ -249,7 +250,7 @@
249250 tdcr |= TDCR_SSZ_32_BITS;
250251 break;
251252 default:
252
- dev_err(tdmac->dev, "mmp_tdma: unknown bus size.\n");
253
+ dev_err(tdmac->dev, "unknown bus size.\n");
253254 return -EINVAL;
254255 }
255256 } else if (tdmac->type == PXA910_SQU) {
....@@ -275,7 +276,7 @@
275276 tdcr |= TDCR_BURSTSZ_SQU_32B;
276277 break;
277278 default:
278
- dev_err(tdmac->dev, "mmp_tdma: unknown burst size.\n");
279
+ dev_err(tdmac->dev, "unknown burst size.\n");
279280 return -EINVAL;
280281 }
281282 }
....@@ -345,9 +346,9 @@
345346 return IRQ_NONE;
346347 }
347348
348
-static void dma_do_tasklet(unsigned long data)
349
+static void dma_do_tasklet(struct tasklet_struct *t)
349350 {
350
- struct mmp_tdma_chan *tdmac = (struct mmp_tdma_chan *)data;
351
+ struct mmp_tdma_chan *tdmac = from_tasklet(tdmac, t, tasklet);
351352
352353 dmaengine_desc_get_callback_invoke(&tdmac->desc, NULL);
353354 }
....@@ -428,8 +429,15 @@
428429 int num_periods = buf_len / period_len;
429430 int i = 0, buf = 0;
430431
431
- if (tdmac->status != DMA_COMPLETE)
432
+ if (!is_slave_direction(direction)) {
433
+ dev_err(tdmac->dev, "unsupported transfer direction\n");
432434 return NULL;
435
+ }
436
+
437
+ if (tdmac->status != DMA_COMPLETE) {
438
+ dev_err(tdmac->dev, "controller busy");
439
+ return NULL;
440
+ }
433441
434442 if (period_len > TDMA_MAX_XFER_BYTES) {
435443 dev_err(tdmac->dev,
....@@ -442,6 +450,9 @@
442450 tdmac->desc_num = num_periods;
443451 desc = mmp_tdma_alloc_descriptor(tdmac);
444452 if (!desc)
453
+ goto err_out;
454
+
455
+ if (mmp_tdma_config_write(chan, direction, &tdmac->slave_config))
445456 goto err_out;
446457
447458 while (buf < buf_len) {
....@@ -497,7 +508,18 @@
497508 {
498509 struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
499510
500
- if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
511
+ memcpy(&tdmac->slave_config, dmaengine_cfg, sizeof(*dmaengine_cfg));
512
+
513
+ return 0;
514
+}
515
+
516
+static int mmp_tdma_config_write(struct dma_chan *chan,
517
+ enum dma_transfer_direction dir,
518
+ struct dma_slave_config *dmaengine_cfg)
519
+{
520
+ struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
521
+
522
+ if (dir == DMA_DEV_TO_MEM) {
501523 tdmac->dev_addr = dmaengine_cfg->src_addr;
502524 tdmac->burst_sz = dmaengine_cfg->src_maxburst;
503525 tdmac->buswidth = dmaengine_cfg->src_addr_width;
....@@ -506,7 +528,7 @@
506528 tdmac->burst_sz = dmaengine_cfg->dst_maxburst;
507529 tdmac->buswidth = dmaengine_cfg->dst_addr_width;
508530 }
509
- tdmac->dir = dmaengine_cfg->direction;
531
+ tdmac->dir = dir;
510532
511533 return mmp_tdma_config_chan(chan);
512534 }
....@@ -532,9 +554,9 @@
532554
533555 static int mmp_tdma_remove(struct platform_device *pdev)
534556 {
535
- struct mmp_tdma_device *tdev = platform_get_drvdata(pdev);
557
+ if (pdev->dev.of_node)
558
+ of_dma_controller_free(pdev->dev.of_node);
536559
537
- dma_async_device_unregister(&tdev->device);
538560 return 0;
539561 }
540562
....@@ -564,7 +586,7 @@
564586 tdmac->pool = pool;
565587 tdmac->status = DMA_COMPLETE;
566588 tdev->tdmac[tdmac->idx] = tdmac;
567
- tasklet_init(&tdmac->tasklet, dma_do_tasklet, (unsigned long)tdmac);
589
+ tasklet_setup(&tdmac->tasklet, dma_do_tasklet);
568590
569591 /* add the channel to tdma_chan list */
570592 list_add_tail(&tdmac->chan.device_node,
....@@ -573,18 +595,12 @@
573595 }
574596
575597 struct mmp_tdma_filter_param {
576
- struct device_node *of_node;
577598 unsigned int chan_id;
578599 };
579600
580601 static bool mmp_tdma_filter_fn(struct dma_chan *chan, void *fn_param)
581602 {
582603 struct mmp_tdma_filter_param *param = fn_param;
583
- struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
584
- struct dma_device *pdma_device = tdmac->chan.device;
585
-
586
- if (pdma_device->dev->of_node != param->of_node)
587
- return false;
588604
589605 if (chan->chan_id != param->chan_id)
590606 return false;
....@@ -602,13 +618,13 @@
602618 if (dma_spec->args_count != 1)
603619 return NULL;
604620
605
- param.of_node = ofdma->of_node;
606621 param.chan_id = dma_spec->args[0];
607622
608623 if (param.chan_id >= TDMA_CHANNEL_NUM)
609624 return NULL;
610625
611
- return dma_request_channel(mask, mmp_tdma_filter_fn, &param);
626
+ return __dma_request_channel(&mask, mmp_tdma_filter_fn, &param,
627
+ ofdma->of_node);
612628 }
613629
614630 static const struct of_device_id mmp_tdma_dt_ids[] = {
....@@ -666,7 +682,7 @@
666682 if (irq_num != chan_num) {
667683 irq = platform_get_irq(pdev, 0);
668684 ret = devm_request_irq(&pdev->dev, irq,
669
- mmp_tdma_int_handler, 0, "tdma", tdev);
685
+ mmp_tdma_int_handler, IRQF_SHARED, "tdma", tdev);
670686 if (ret)
671687 return ret;
672688 }
....@@ -695,10 +711,21 @@
695711 tdev->device.device_terminate_all = mmp_tdma_terminate_all;
696712 tdev->device.copy_align = DMAENGINE_ALIGN_8_BYTES;
697713
714
+ tdev->device.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
715
+ if (type == MMP_AUD_TDMA) {
716
+ tdev->device.max_burst = SZ_128;
717
+ tdev->device.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
718
+ tdev->device.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
719
+ } else if (type == PXA910_SQU) {
720
+ tdev->device.max_burst = SZ_32;
721
+ }
722
+ tdev->device.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
723
+ tdev->device.descriptor_reuse = true;
724
+
698725 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
699726 platform_set_drvdata(pdev, tdev);
700727
701
- ret = dma_async_device_register(&tdev->device);
728
+ ret = dmaenginem_async_device_register(&tdev->device);
702729 if (ret) {
703730 dev_err(tdev->device.dev, "unable to register\n");
704731 return ret;
....@@ -710,7 +737,7 @@
710737 if (ret) {
711738 dev_err(tdev->device.dev,
712739 "failed to register controller\n");
713
- dma_async_device_unregister(&tdev->device);
740
+ return ret;
714741 }
715742 }
716743