hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/dma/mmp_pdma.c
....@@ -1,9 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2012 Marvell International Ltd.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 */
85
96 #include <linux/err.h>
....@@ -96,6 +93,7 @@
9693 struct dma_async_tx_descriptor desc;
9794 struct mmp_pdma_phy *phy;
9895 enum dma_transfer_direction dir;
96
+ struct dma_slave_config slave_config;
9997
10098 struct mmp_pdma_desc_sw *cyclic_first; /* first desc_sw if channel
10199 * is in cyclic mode */
....@@ -139,6 +137,10 @@
139137 container_of(dchan, struct mmp_pdma_chan, chan)
140138 #define to_mmp_pdma_dev(dmadev) \
141139 container_of(dmadev, struct mmp_pdma_device, device)
140
+
141
+static int mmp_pdma_config_write(struct dma_chan *dchan,
142
+ struct dma_slave_config *cfg,
143
+ enum dma_transfer_direction direction);
142144
143145 static void set_desc(struct mmp_pdma_phy *phy, dma_addr_t addr)
144146 {
....@@ -288,7 +290,7 @@
288290 spin_unlock_irqrestore(&pdev->phy_lock, flags);
289291 }
290292
291
-/**
293
+/*
292294 * start_pending_queue - transfer any pending transactions
293295 * pending list ==> running list
294296 */
....@@ -379,7 +381,7 @@
379381 return desc;
380382 }
381383
382
-/**
384
+/*
383385 * mmp_pdma_alloc_chan_resources - Allocate resources for DMA channel.
384386 *
385387 * This function will create a dma pool for descriptor allocation.
....@@ -537,6 +539,8 @@
537539
538540 chan->byte_align = false;
539541
542
+ mmp_pdma_config_write(dchan, &chan->slave_config, dir);
543
+
540544 for_each_sg(sgl, sg, sg_len, i) {
541545 addr = sg_dma_address(sg);
542546 avail = sg_dma_len(sgl);
....@@ -619,6 +623,7 @@
619623 return NULL;
620624
621625 chan = to_mmp_pdma_chan(dchan);
626
+ mmp_pdma_config_write(dchan, &chan->slave_config, direction);
622627
623628 switch (direction) {
624629 case DMA_MEM_TO_DEV:
....@@ -684,8 +689,9 @@
684689 return NULL;
685690 }
686691
687
-static int mmp_pdma_config(struct dma_chan *dchan,
688
- struct dma_slave_config *cfg)
692
+static int mmp_pdma_config_write(struct dma_chan *dchan,
693
+ struct dma_slave_config *cfg,
694
+ enum dma_transfer_direction direction)
689695 {
690696 struct mmp_pdma_chan *chan = to_mmp_pdma_chan(dchan);
691697 u32 maxburst = 0, addr = 0;
....@@ -694,12 +700,12 @@
694700 if (!dchan)
695701 return -EINVAL;
696702
697
- if (cfg->direction == DMA_DEV_TO_MEM) {
703
+ if (direction == DMA_DEV_TO_MEM) {
698704 chan->dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC;
699705 maxburst = cfg->src_maxburst;
700706 width = cfg->src_addr_width;
701707 addr = cfg->src_addr;
702
- } else if (cfg->direction == DMA_MEM_TO_DEV) {
708
+ } else if (direction == DMA_MEM_TO_DEV) {
703709 chan->dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG;
704710 maxburst = cfg->dst_maxburst;
705711 width = cfg->dst_addr_width;
....@@ -720,9 +726,18 @@
720726 else if (maxburst == 32)
721727 chan->dcmd |= DCMD_BURST32;
722728
723
- chan->dir = cfg->direction;
729
+ chan->dir = direction;
724730 chan->dev_addr = addr;
725731
732
+ return 0;
733
+}
734
+
735
+static int mmp_pdma_config(struct dma_chan *dchan,
736
+ struct dma_slave_config *cfg)
737
+{
738
+ struct mmp_pdma_chan *chan = to_mmp_pdma_chan(dchan);
739
+
740
+ memcpy(&chan->slave_config, cfg, sizeof(*cfg));
726741 return 0;
727742 }
728743
....@@ -833,7 +848,7 @@
833848 return ret;
834849 }
835850
836
-/**
851
+/*
837852 * mmp_pdma_issue_pending - Issue the DMA start command
838853 * pending list ==> running list
839854 */
....@@ -852,9 +867,9 @@
852867 * Do call back
853868 * Start pending list
854869 */
855
-static void dma_do_tasklet(unsigned long data)
870
+static void dma_do_tasklet(struct tasklet_struct *t)
856871 {
857
- struct mmp_pdma_chan *chan = (struct mmp_pdma_chan *)data;
872
+ struct mmp_pdma_chan *chan = from_tasklet(chan, t, tasklet);
858873 struct mmp_pdma_desc_sw *desc, *_desc;
859874 LIST_HEAD(chain_cleanup);
860875 unsigned long flags;
....@@ -924,6 +939,8 @@
924939 struct mmp_pdma_phy *phy;
925940 int i, irq = 0, irq_num = 0;
926941
942
+ if (op->dev.of_node)
943
+ of_dma_controller_free(op->dev.of_node);
927944
928945 for (i = 0; i < pdev->dma_channels; i++) {
929946 if (platform_get_irq(op, i) > 0)
....@@ -970,7 +987,7 @@
970987 spin_lock_init(&chan->desc_lock);
971988 chan->dev = pdev->dev;
972989 chan->chan.device = &pdev->device;
973
- tasklet_init(&chan->tasklet, dma_do_tasklet, (unsigned long)chan);
990
+ tasklet_setup(&chan->tasklet, dma_do_tasklet);
974991 INIT_LIST_HEAD(&chan->chain_pending);
975992 INIT_LIST_HEAD(&chan->chain_running);
976993
....@@ -1037,7 +1054,7 @@
10371054 pdev->dma_channels = dma_channels;
10381055
10391056 for (i = 0; i < dma_channels; i++) {
1040
- if (platform_get_irq(op, i) > 0)
1057
+ if (platform_get_irq_optional(op, i) > 0)
10411058 irq_num++;
10421059 }
10431060