aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ipq806x/patches-4.9/0016-spi-qup-allow-mulitple-DMA-transactions-per-spi-xfer.patch
blob: ce59d492e276a43708b346e9bf29da7cd19958a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From 6b2bb8803f19116bad41a271f9035d4c853f4553 Mon Sep 17 00:00:00 2001
From: Matthew McClintock <mmcclint@codeaurora.org>
Date: Thu, 5 May 2016 10:07:11 -0500
Subject: [PATCH 16/37] spi: qup: allow mulitple DMA transactions per spi xfer

Much like the block mode changes, we are breaking up DMA transactions
into 64K chunks so we can reset the QUP engine.

Signed-off-by: Matthew McClintock <mmcclint@codeaurora.org>
---
 drivers/spi/spi-qup.c |  120 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 86 insertions(+), 34 deletions(-)

--- a/drivers/spi/spi-qup.c
+++ b/drivers/spi/spi-qup.c
@@ -566,6 +566,21 @@ static int spi_qup_io_config(struct spi_
 	return 0;
 }
 
+static unsigned int spi_qup_sgl_get_size(struct scatterlist *sgl, unsigned int nents)
+{
+	struct scatterlist *sg;
+	int i;
+	unsigned int length = 0;
+
+	if (!nents)
+		return 0;
+
+	for_each_sg(sgl, sg, nents, i)
+		length += sg_dma_len(sg);
+
+	return length;
+}
+
 static int spi_qup_do_dma(struct spi_device *spi, struct spi_transfer *xfer,
 unsigned long timeout)
 {
@@ -573,53 +588,90 @@ unsigned long timeout)
 	struct spi_qup *qup = spi_master_get_devdata(master);
 	dma_async_tx_callback rx_done = NULL, tx_done = NULL;
 	int ret;
+	struct scatterlist *tx_sgl, *rx_sgl;
 
-	ret = spi_qup_io_config(spi, xfer);
-	if (ret)
-		return ret;
+	rx_sgl = xfer->rx_sg.sgl;
+	tx_sgl = xfer->tx_sg.sgl;
 
-	/* before issuing the descriptors, set the QUP to run */
-	ret = spi_qup_set_state(qup, QUP_STATE_RUN);
-	if (ret) {
-		dev_warn(qup->dev, "cannot set RUN state\n");
-		return ret;
-	}
+	do {
+		int rx_nents = 0, tx_nents = 0;
 
-	if (!qup->qup_v1) {
-		if (xfer->rx_buf)
-			rx_done = spi_qup_dma_done;
+		if (rx_sgl) {
+			rx_nents = sg_nents_for_len(rx_sgl, SPI_MAX_XFER);
+			if (rx_nents < 0)
+				rx_nents = sg_nents(rx_sgl);
 
-		if (xfer->tx_buf)
-			tx_done = spi_qup_dma_done;
-	}
+			qup->n_words = spi_qup_sgl_get_size(rx_sgl, rx_nents) /
+						qup->w_size;
+		}
 
-	if (xfer->rx_buf) {
-		ret = spi_qup_prep_sg(master, xfer->rx_sg.sgl,
-				      xfer->rx_sg.nents, DMA_DEV_TO_MEM,
-				      rx_done, &qup->done);
-		if (ret)
-			return ret;
+		if (tx_sgl) {
+			tx_nents = sg_nents_for_len(tx_sgl, SPI_MAX_XFER);
+			if (tx_nents < 0)
+				tx_nents = sg_nents(tx_sgl);
 
-		dma_async_issue_pending(master->dma_rx);
-	}
+			qup->n_words = spi_qup_sgl_get_size(tx_sgl, tx_nents) /
+						qup->w_size;
+		}
 
-	if (xfer->tx_buf) {
-		ret = spi_qup_prep_sg(master, xfer->tx_sg.sgl,
-				      xfer->tx_sg.nents, DMA_MEM_TO_DEV,
-				      tx_done, &qup->dma_tx_done);
+
+		ret = spi_qup_io_config(spi, xfer);
 		if (ret)
 			return ret;
 
-		dma_async_issue_pending(master->dma_tx);
-	}
+		/* before issuing the descriptors, set the QUP to run */
+		ret = spi_qup_set_state(qup, QUP_STATE_RUN);
+		if (ret) {
+			dev_warn(qup->dev, "cannot set RUN state\n");
+			return ret;
+		}
 
-	if (xfer->rx_buf && !wait_for_completion_timeout(&qup->done, timeout))
-		return -ETIMEDOUT;
+		if (!qup->qup_v1) {
+			if (rx_sgl) {
+				rx_done = spi_qup_dma_done;
+			}
 
-	if (xfer->tx_buf && !wait_for_completion_timeout(&qup->dma_tx_done, timeout))
-		ret = -ETIMEDOUT;
+			if (tx_sgl) {
+				tx_done = spi_qup_dma_done;
+			}
+		}
 
-	return ret;
+		if (rx_sgl) {
+			ret = spi_qup_prep_sg(master, rx_sgl, rx_nents,
+					      DMA_DEV_TO_MEM, rx_done,
+					      &qup->done);
+			if (ret)
+				return ret;
+
+			dma_async_issue_pending(master->dma_rx);
+		}
+
+		if (tx_sgl) {
+			ret = spi_qup_prep_sg(master, tx_sgl, tx_nents,
+					      DMA_MEM_TO_DEV, tx_done,
+					      &qup->dma_tx_done);
+			if (ret)
+				return ret;
+
+			dma_async_issue_pending(master->dma_tx);
+		}
+
+		if (rx_sgl && !wait_for_completion_timeout(&qup->done, timeout)) {
+			pr_emerg(" rx timed out");
+			return -ETIMEDOUT;
+		}
+
+		if (tx_sgl && !wait_for_completion_timeout(&qup->dma_tx_done, timeout)) {
+			pr_emerg(" tx timed out\n");
+			return -ETIMEDOUT;
+		}
+
+		for (; rx_sgl && rx_nents--; rx_sgl = sg_next(rx_sgl));
+		for (; tx_sgl && tx_nents--; tx_sgl = sg_next(tx_sgl));
+
+	} while (rx_sgl || tx_sgl);
+
+	return 0;
 }
 
 static int spi_qup_do_pio(struct spi_device *spi, struct spi_transfer *xfer,