1 |
From 4f70231a2e20124f9eea0103d939be116eb7d404 Mon Sep 17 00:00:00 2001 |
2 |
From: Nathan Chancellor <natechancellor@gmail.com> |
3 |
Date: Mon, 8 Oct 2018 11:08:47 -0700 |
4 |
Subject: [PATCH 017/145] spi: spi-ep93xx: Use dma_data_direction for |
5 |
ep93xx_spi_dma_{finish,prepare} |
6 |
|
7 |
[ Upstream commit a1108c7b2efb892350ba6a0e932dfd45622f4e2b ] |
8 |
|
9 |
Clang warns when one enumerated type is implicitly converted to another. |
10 |
|
11 |
drivers/spi/spi-ep93xx.c:342:62: warning: implicit conversion from |
12 |
enumeration type 'enum dma_transfer_direction' to different enumeration |
13 |
type 'enum dma_data_direction' [-Wenum-conversion] |
14 |
nents = dma_map_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); |
15 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ |
16 |
./include/linux/dma-mapping.h:428:58: note: expanded from macro |
17 |
'dma_map_sg' |
18 |
#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0) |
19 |
~~~~~~~~~~~~~~~~ ^ |
20 |
drivers/spi/spi-ep93xx.c:348:57: warning: implicit conversion from |
21 |
enumeration type 'enum dma_transfer_direction' to different enumeration |
22 |
type 'enum dma_data_direction' [-Wenum-conversion] |
23 |
dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); |
24 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ |
25 |
./include/linux/dma-mapping.h:429:62: note: expanded from macro |
26 |
'dma_unmap_sg' |
27 |
#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0) |
28 |
~~~~~~~~~~~~~~~~~~ ^ |
29 |
drivers/spi/spi-ep93xx.c:377:56: warning: implicit conversion from |
30 |
enumeration type 'enum dma_transfer_direction' to different enumeration |
31 |
type 'enum dma_data_direction' [-Wenum-conversion] |
32 |
dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); |
33 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ |
34 |
./include/linux/dma-mapping.h:429:62: note: expanded from macro |
35 |
'dma_unmap_sg' |
36 |
#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0) |
37 |
~~~~~~~~~~~~~~~~~~ ^ |
38 |
3 warnings generated. |
39 |
|
40 |
dma_{,un}map_sg expect an enum of type dma_data_direction but this |
41 |
driver uses dma_transfer_direction for everything. Convert the driver to |
42 |
use dma_data_direction for these two functions. |
43 |
|
44 |
There are two places that strictly require an enum of type |
45 |
dma_transfer_direction: the direction member in struct dma_slave_config |
46 |
and the direction parameter in dmaengine_prep_slave_sg. To avoid using |
47 |
an explicit cast, add a simple function, ep93xx_dma_data_to_trans_dir, |
48 |
to safely map between the two types because they are not 1 to 1 in |
49 |
meaning. |
50 |
|
51 |
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> |
52 |
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> |
53 |
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> |
54 |
Signed-off-by: Mark Brown <broonie@kernel.org> |
55 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
56 |
--- |
57 |
drivers/spi/spi-ep93xx.c | 36 +++++++++++++++++++++++++----------- |
58 |
1 file changed, 25 insertions(+), 11 deletions(-) |
59 |
|
60 |
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c |
61 |
index f1526757aaf6..79fc3940245a 100644 |
62 |
--- a/drivers/spi/spi-ep93xx.c |
63 |
+++ b/drivers/spi/spi-ep93xx.c |
64 |
@@ -246,6 +246,19 @@ static int ep93xx_spi_read_write(struct spi_master *master) |
65 |
return -EINPROGRESS; |
66 |
} |
67 |
|
68 |
+static enum dma_transfer_direction |
69 |
+ep93xx_dma_data_to_trans_dir(enum dma_data_direction dir) |
70 |
+{ |
71 |
+ switch (dir) { |
72 |
+ case DMA_TO_DEVICE: |
73 |
+ return DMA_MEM_TO_DEV; |
74 |
+ case DMA_FROM_DEVICE: |
75 |
+ return DMA_DEV_TO_MEM; |
76 |
+ default: |
77 |
+ return DMA_TRANS_NONE; |
78 |
+ } |
79 |
+} |
80 |
+ |
81 |
/** |
82 |
* ep93xx_spi_dma_prepare() - prepares a DMA transfer |
83 |
* @master: SPI master |
84 |
@@ -257,7 +270,7 @@ static int ep93xx_spi_read_write(struct spi_master *master) |
85 |
*/ |
86 |
static struct dma_async_tx_descriptor * |
87 |
ep93xx_spi_dma_prepare(struct spi_master *master, |
88 |
- enum dma_transfer_direction dir) |
89 |
+ enum dma_data_direction dir) |
90 |
{ |
91 |
struct ep93xx_spi *espi = spi_master_get_devdata(master); |
92 |
struct spi_transfer *xfer = master->cur_msg->state; |
93 |
@@ -277,9 +290,9 @@ ep93xx_spi_dma_prepare(struct spi_master *master, |
94 |
buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; |
95 |
|
96 |
memset(&conf, 0, sizeof(conf)); |
97 |
- conf.direction = dir; |
98 |
+ conf.direction = ep93xx_dma_data_to_trans_dir(dir); |
99 |
|
100 |
- if (dir == DMA_DEV_TO_MEM) { |
101 |
+ if (dir == DMA_FROM_DEVICE) { |
102 |
chan = espi->dma_rx; |
103 |
buf = xfer->rx_buf; |
104 |
sgt = &espi->rx_sgt; |
105 |
@@ -343,7 +356,8 @@ ep93xx_spi_dma_prepare(struct spi_master *master, |
106 |
if (!nents) |
107 |
return ERR_PTR(-ENOMEM); |
108 |
|
109 |
- txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, dir, DMA_CTRL_ACK); |
110 |
+ txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, conf.direction, |
111 |
+ DMA_CTRL_ACK); |
112 |
if (!txd) { |
113 |
dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); |
114 |
return ERR_PTR(-ENOMEM); |
115 |
@@ -360,13 +374,13 @@ ep93xx_spi_dma_prepare(struct spi_master *master, |
116 |
* unmapped. |
117 |
*/ |
118 |
static void ep93xx_spi_dma_finish(struct spi_master *master, |
119 |
- enum dma_transfer_direction dir) |
120 |
+ enum dma_data_direction dir) |
121 |
{ |
122 |
struct ep93xx_spi *espi = spi_master_get_devdata(master); |
123 |
struct dma_chan *chan; |
124 |
struct sg_table *sgt; |
125 |
|
126 |
- if (dir == DMA_DEV_TO_MEM) { |
127 |
+ if (dir == DMA_FROM_DEVICE) { |
128 |
chan = espi->dma_rx; |
129 |
sgt = &espi->rx_sgt; |
130 |
} else { |
131 |
@@ -381,8 +395,8 @@ static void ep93xx_spi_dma_callback(void *callback_param) |
132 |
{ |
133 |
struct spi_master *master = callback_param; |
134 |
|
135 |
- ep93xx_spi_dma_finish(master, DMA_MEM_TO_DEV); |
136 |
- ep93xx_spi_dma_finish(master, DMA_DEV_TO_MEM); |
137 |
+ ep93xx_spi_dma_finish(master, DMA_TO_DEVICE); |
138 |
+ ep93xx_spi_dma_finish(master, DMA_FROM_DEVICE); |
139 |
|
140 |
spi_finalize_current_transfer(master); |
141 |
} |
142 |
@@ -392,15 +406,15 @@ static int ep93xx_spi_dma_transfer(struct spi_master *master) |
143 |
struct ep93xx_spi *espi = spi_master_get_devdata(master); |
144 |
struct dma_async_tx_descriptor *rxd, *txd; |
145 |
|
146 |
- rxd = ep93xx_spi_dma_prepare(master, DMA_DEV_TO_MEM); |
147 |
+ rxd = ep93xx_spi_dma_prepare(master, DMA_FROM_DEVICE); |
148 |
if (IS_ERR(rxd)) { |
149 |
dev_err(&master->dev, "DMA RX failed: %ld\n", PTR_ERR(rxd)); |
150 |
return PTR_ERR(rxd); |
151 |
} |
152 |
|
153 |
- txd = ep93xx_spi_dma_prepare(master, DMA_MEM_TO_DEV); |
154 |
+ txd = ep93xx_spi_dma_prepare(master, DMA_TO_DEVICE); |
155 |
if (IS_ERR(txd)) { |
156 |
- ep93xx_spi_dma_finish(master, DMA_DEV_TO_MEM); |
157 |
+ ep93xx_spi_dma_finish(master, DMA_FROM_DEVICE); |
158 |
dev_err(&master->dev, "DMA TX failed: %ld\n", PTR_ERR(txd)); |
159 |
return PTR_ERR(txd); |
160 |
} |
161 |
-- |
162 |
2.19.1 |
163 |
|