Skip to content

Commit a5c2db9

Browse files
andy-shevbroonie
authored andcommitted
spi: dw-mid: refactor to use helpers
This patch splits few helpers, namely dw_spi_dma_prepare_rx(), dw_spi_dma_prepare_tx(), and dw_spi_dma_setup() which will be useful for the consequent improvements. There is no functional change. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent b7a4024 commit a5c2db9

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

drivers/spi/spi-dw-mid.c

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,11 @@ static void dw_spi_dma_done(void *arg)
111111
dw_spi_xfer_done(dws);
112112
}
113113

114-
static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
114+
static struct dma_async_tx_descriptor *dw_spi_dma_prepare_tx(struct dw_spi *dws)
115115
{
116-
struct dma_async_tx_descriptor *txdesc, *rxdesc;
117-
struct dma_slave_config txconf, rxconf;
118-
u16 dma_ctrl = 0;
119-
120-
/* 1. setup DMA related registers */
121-
if (cs_change) {
122-
spi_enable_chip(dws, 0);
123-
dw_writew(dws, DW_SPI_DMARDLR, 0xf);
124-
dw_writew(dws, DW_SPI_DMATDLR, 0x10);
125-
if (dws->tx_dma)
126-
dma_ctrl |= SPI_DMA_TDMAE;
127-
if (dws->rx_dma)
128-
dma_ctrl |= SPI_DMA_RDMAE;
129-
dw_writew(dws, DW_SPI_DMACR, dma_ctrl);
130-
spi_enable_chip(dws, 1);
131-
}
116+
struct dma_slave_config txconf;
117+
struct dma_async_tx_descriptor *txdesc;
132118

133-
dws->dma_chan_done = 0;
134-
135-
/* 2. Prepare the TX dma transfer */
136119
txconf.direction = DMA_MEM_TO_DEV;
137120
txconf.dst_addr = dws->dma_addr;
138121
txconf.dst_maxburst = LNW_DMA_MSIZE_16;
@@ -154,7 +137,14 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
154137
txdesc->callback = dw_spi_dma_done;
155138
txdesc->callback_param = dws;
156139

157-
/* 3. Prepare the RX dma transfer */
140+
return txdesc;
141+
}
142+
143+
static struct dma_async_tx_descriptor *dw_spi_dma_prepare_rx(struct dw_spi *dws)
144+
{
145+
struct dma_slave_config rxconf;
146+
struct dma_async_tx_descriptor *rxdesc;
147+
158148
rxconf.direction = DMA_DEV_TO_MEM;
159149
rxconf.src_addr = dws->dma_addr;
160150
rxconf.src_maxburst = LNW_DMA_MSIZE_16;
@@ -176,6 +166,43 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
176166
rxdesc->callback = dw_spi_dma_done;
177167
rxdesc->callback_param = dws;
178168

169+
return rxdesc;
170+
}
171+
172+
static void dw_spi_dma_setup(struct dw_spi *dws)
173+
{
174+
u16 dma_ctrl = 0;
175+
176+
spi_enable_chip(dws, 0);
177+
178+
dw_writew(dws, DW_SPI_DMARDLR, 0xf);
179+
dw_writew(dws, DW_SPI_DMATDLR, 0x10);
180+
181+
if (dws->tx_dma)
182+
dma_ctrl |= SPI_DMA_TDMAE;
183+
if (dws->rx_dma)
184+
dma_ctrl |= SPI_DMA_RDMAE;
185+
dw_writew(dws, DW_SPI_DMACR, dma_ctrl);
186+
187+
spi_enable_chip(dws, 1);
188+
}
189+
190+
static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
191+
{
192+
struct dma_async_tx_descriptor *txdesc, *rxdesc;
193+
194+
/* 1. setup DMA related registers */
195+
if (cs_change)
196+
dw_spi_dma_setup(dws);
197+
198+
dws->dma_chan_done = 0;
199+
200+
/* 2. Prepare the TX dma transfer */
201+
txdesc = dw_spi_dma_prepare_tx(dws);
202+
203+
/* 3. Prepare the RX dma transfer */
204+
rxdesc = dw_spi_dma_prepare_rx(dws);
205+
179206
/* rx must be started before tx due to spi instinct */
180207
dmaengine_submit(rxdesc);
181208
dma_async_issue_pending(dws->rxchan);

0 commit comments

Comments
 (0)