forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/staging/mt7621-dma/hsdma-mt7621.c
....@@ -1,12 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Copyright (C) 2015, Michael Lee <igvtee@gmail.com>
34 * MTK HSDMA support
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License as published by the
7
- * Free Software Foundation; either version 2 of the License, or (at your
8
- * option) any later version.
9
- *
105 */
116
127 #include <linux/dmaengine.h>
....@@ -191,7 +186,7 @@
191186 }
192187
193188 static inline void mtk_hsdma_write(struct mtk_hsdam_engine *hsdma,
194
- unsigned reg, u32 val)
189
+ unsigned int reg, u32 val)
195190 {
196191 writel(val, hsdma->base + reg);
197192 }
....@@ -213,8 +208,8 @@
213208
214209 static void hsdma_dump_reg(struct mtk_hsdam_engine *hsdma)
215210 {
216
- dev_dbg(hsdma->ddev.dev, "tbase %08x, tcnt %08x, " \
217
- "tctx %08x, tdtx: %08x, rbase %08x, " \
211
+ dev_dbg(hsdma->ddev.dev, "tbase %08x, tcnt %08x, "
212
+ "tctx %08x, tdtx: %08x, rbase %08x, "
218213 "rcnt %08x, rctx %08x, rdtx %08x\n",
219214 mtk_hsdma_read(hsdma, HSDMA_REG_TX_BASE),
220215 mtk_hsdma_read(hsdma, HSDMA_REG_TX_CNT),
....@@ -225,8 +220,7 @@
225220 mtk_hsdma_read(hsdma, HSDMA_REG_RX_CRX),
226221 mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX));
227222
228
- dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, " \
229
- "intr_stat %08x, intr_mask %08x\n",
223
+ dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, intr_stat %08x, intr_mask %08x\n",
230224 mtk_hsdma_read(hsdma, HSDMA_REG_INFO),
231225 mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG),
232226 mtk_hsdma_read(hsdma, HSDMA_REG_DELAY_INT),
....@@ -242,15 +236,15 @@
242236 int i;
243237
244238 dev_dbg(hsdma->ddev.dev, "tx idx: %d, rx idx: %d\n",
245
- chan->tx_idx, chan->rx_idx);
239
+ chan->tx_idx, chan->rx_idx);
246240
247241 for (i = 0; i < HSDMA_DESCS_NUM; i++) {
248242 tx_desc = &chan->tx_ring[i];
249243 rx_desc = &chan->rx_ring[i];
250244
251
- dev_dbg(hsdma->ddev.dev, "%d tx addr0: %08x, flags %08x, " \
245
+ dev_dbg(hsdma->ddev.dev, "%d tx addr0: %08x, flags %08x, "
252246 "tx addr1: %08x, rx addr0 %08x, flags %08x\n",
253
- i, tx_desc->addr0, tx_desc->flags, \
247
+ i, tx_desc->addr0, tx_desc->flags,
254248 tx_desc->addr1, rx_desc->addr0, rx_desc->flags);
255249 }
256250 }
....@@ -269,8 +263,7 @@
269263 /* init desc value */
270264 for (i = 0; i < HSDMA_DESCS_NUM; i++) {
271265 chan->tx_ring[i].addr0 = 0;
272
- chan->tx_ring[i].flags = HSDMA_DESC_LS0 |
273
- HSDMA_DESC_DONE;
266
+ chan->tx_ring[i].flags = HSDMA_DESC_LS0 | HSDMA_DESC_DONE;
274267 }
275268 for (i = 0; i < HSDMA_DESCS_NUM; i++) {
276269 chan->rx_ring[i].addr0 = 0;
....@@ -419,8 +412,9 @@
419412 vchan_cookie_complete(&desc->vdesc);
420413 chan_issued = gdma_next_desc(chan);
421414 }
422
- } else
415
+ } else {
423416 dev_dbg(hsdma->ddev.dev, "no desc to complete\n");
417
+ }
424418
425419 if (chan_issued)
426420 set_bit(chan->id, &hsdma->chan_issued);
....@@ -439,8 +433,7 @@
439433 if (likely(status & HSDMA_INT_RX_Q0))
440434 tasklet_schedule(&hsdma->task);
441435 else
442
- dev_dbg(hsdma->ddev.dev, "unhandle irq status %08x\n",
443
- status);
436
+ dev_dbg(hsdma->ddev.dev, "unhandle irq status %08x\n", status);
444437 /* clean intr bits */
445438 mtk_hsdma_write(hsdma, HSDMA_REG_INT_STATUS, status);
446439
....@@ -457,8 +450,9 @@
457450 if (gdma_next_desc(chan)) {
458451 set_bit(chan->id, &hsdma->chan_issued);
459452 tasklet_schedule(&hsdma->task);
460
- } else
453
+ } else {
461454 dev_dbg(hsdma->ddev.dev, "no desc to issue\n");
455
+ }
462456 }
463457 spin_unlock_bh(&chan->vchan.lock);
464458 }
....@@ -473,7 +467,7 @@
473467 if (len <= 0)
474468 return NULL;
475469
476
- desc = kzalloc(sizeof(struct mtk_hsdma_desc), GFP_ATOMIC);
470
+ desc = kzalloc(sizeof(*desc), GFP_ATOMIC);
477471 if (!desc) {
478472 dev_err(c->device->dev, "alloc memcpy decs error\n");
479473 return NULL;
....@@ -539,9 +533,9 @@
539533 mtk_hsdma_chan_done(hsdma, chan);
540534 }
541535
542
-static void mtk_hsdma_tasklet(unsigned long arg)
536
+static void mtk_hsdma_tasklet(struct tasklet_struct *t)
543537 {
544
- struct mtk_hsdam_engine *hsdma = (struct mtk_hsdam_engine *)arg;
538
+ struct mtk_hsdam_engine *hsdma = from_tasklet(hsdma, t, task);
545539
546540 mtk_hsdma_rx(hsdma);
547541 mtk_hsdma_tx(hsdma);
....@@ -553,7 +547,8 @@
553547 int i;
554548
555549 chan->tx_ring = dma_alloc_coherent(hsdma->ddev.dev,
556
- 2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
550
+ 2 * HSDMA_DESCS_NUM *
551
+ sizeof(*chan->tx_ring),
557552 &chan->desc_addr, GFP_ATOMIC | __GFP_ZERO);
558553 if (!chan->tx_ring)
559554 goto no_mem;
....@@ -574,8 +569,8 @@
574569 {
575570 if (chan->tx_ring) {
576571 dma_free_coherent(hsdma->ddev.dev,
577
- 2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
578
- chan->tx_ring, chan->desc_addr);
572
+ 2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
573
+ chan->tx_ring, chan->desc_addr);
579574 chan->tx_ring = NULL;
580575 chan->rx_ring = NULL;
581576 }
....@@ -655,7 +650,6 @@
655650 struct mtk_hsdma_chan *chan;
656651 struct mtk_hsdam_engine *hsdma;
657652 struct dma_device *dd;
658
- struct resource *res;
659653 int ret;
660654 int irq;
661655 void __iomem *base;
....@@ -669,23 +663,18 @@
669663 return -EINVAL;
670664
671665 hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL);
672
- if (!hsdma) {
673
- dev_err(&pdev->dev, "alloc dma device failed\n");
666
+ if (!hsdma)
674667 return -EINVAL;
675
- }
676668
677
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
678
- base = devm_ioremap_resource(&pdev->dev, res);
669
+ base = devm_platform_ioremap_resource(pdev, 0);
679670 if (IS_ERR(base))
680671 return PTR_ERR(base);
681672 hsdma->base = base + HSDMA_BASE_OFFSET;
682
- tasklet_init(&hsdma->task, mtk_hsdma_tasklet, (unsigned long)hsdma);
673
+ tasklet_setup(&hsdma->task, mtk_hsdma_tasklet);
683674
684675 irq = platform_get_irq(pdev, 0);
685
- if (irq < 0) {
686
- dev_err(&pdev->dev, "failed to get irq\n");
676
+ if (irq < 0)
687677 return -EINVAL;
688
- }
689678 ret = devm_request_irq(&pdev->dev, irq, mtk_hsdma_irq,
690679 0, dev_name(&pdev->dev), hsdma);
691680 if (ret) {