spi: dw: refactor to use SPI core message handling
cover spi: dw: refactor to use SPI core message handling
This patch series is dedicated to refactoring of spi-dw driver to use SPI core message handling. The driver has been tested in PIO mode on Intel Medfield device in loopback mode.
Andy Shevchenko (5):
spi: dw: move piece of code out of condition
spi: dw: get TX level without an additional variable
spi: dw: refactor code that handles clk_div
spi: dw: always reprogram CTRL0
spi: dw: move to SPI core message handling
drivers/spi/spi-dw-mid.c | 4 +- drivers/spi/spi-dw.c | 208 ++++++++++++----------------------------------- drivers/spi/spi-dw.h | 22 ----- 3 files changed, 55 insertions(+), 179 deletions(-)
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/5 spi: dw: move piece of code out of condition
In reply to a message not in the archiveThere is no sense to keep a member assignment in the internal structure inside the condition which reprograms HW. It makes code readability better if kept outside of the condition.
--- drivers/spi/spi-dw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +3 -2
@@ -494,10 +494,11 @@ static void pump_transfers(unsigned long data)dw_writew (dws,DW_SPI_TXFLTR , txint_level);spi_enable_chip (dws,1 ); -if (cs_change) - dws->prev_chip = chip; } +if (cs_change) + dws->prev_chip = chip; +if (dws->dma_mapped) dws->dma_ops->dma_transfer (dws, cs_change);
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/5 spi: dw: get TX level without an additional variable
In reply to a message not in the archiveThere is no need to have an additional variable to get a TX level. The patch refactors this piece of code.
--- drivers/spi/spi-dw.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/spi/spi-dw.c +4 -7
@@ -365,7 +365,7 @@ static void pump_transfers(unsigned long data)u8 bits =0 ;u8 imask =0 ;u8 cs_change =0 ; -u16 txint_level =0 ; +u16 txlevel =0 ;u16 clk_div =0 ;u32 speed =0 ;u32 cr0 =0 ;
@@ -461,10 +461,7 @@ static void pump_transfers(unsigned long data)* we only need set the TXEI IRQ, as TX/RX always happen syncronizely */ if (!dws->dma_mapped && !chip->poll_mode) { -int templen = dws->len / dws->n_bytes; - - txint_level = dws->fifo_len /2 ; - txint_level = (templen > txint_level) ? txint_level : templen; + txlevel =min_t (u16, dws->fifo_len /2 , dws->len / dws->n_bytes); imask |=SPI_INT_TXEI |SPI_INT_TXOI |SPI_INT_RXUI |SPI_INT_RXOI ;
@@ -490,8 +487,8 @@ static void pump_transfers(unsigned long data)spi_mask_intr (dws,0xff );if (imask)spi_umask_intr (dws, imask); -if (txint_level) -dw_writew (dws,DW_SPI_TXFLTR , txint_level); +if (txlevel) +dw_writew (dws,DW_SPI_TXFLTR , txlevel);spi_enable_chip (dws,1 ); }
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/5 spi: dw: refactor code that handles clk_div
In reply to a message not in the archiveThis patch does the following changes:
a) the calculation of clk_div is simplified to oneliner;
b) chip->clk_div is updated if clk_div is not zero, therefore the condition is simplified by using chip->clk_div in both cases;
c) while here, the redundant parentheses are removed.
--- drivers/spi/spi-dw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/spi/spi-dw.c +3 -4
@@ -416,12 +416,11 @@ static void pump_transfers(unsigned long data)if (transfer->speed_hz) { speed = chip->speed_hz; -if ((transfer->speed_hz != speed) || (!chip->clk_div)) { +if ((transfer->speed_hz != speed) || !chip->clk_div) { speed = transfer->speed_hz;/* clk_div doesn't support odd number */ - clk_div = dws->max_freq / speed; - clk_div = (clk_div +1 ) &0xfffe ; + clk_div = (dws->max_freq / speed +1 ) &0xfffe ; chip->speed_hz = speed; chip->clk_div = clk_div;
@@ -480,7 +479,7 @@ static void pump_transfers(unsigned long data)if (dw_readw (dws,DW_SPI_CTRL0 ) != cr0)dw_writew (dws,DW_SPI_CTRL0 , cr0); -spi_set_clk (dws, clk_div ? clk_div : chip->clk_div); +spi_set_clk (dws, chip->clk_div);spi_chip_sel (dws, spi,1 );/* Set the interrupt mask, for poll mode just disable all int */
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/5 spi: dw: always reprogram CTRL0
In reply to a message not in the archiveInstead of an additional reading from the register let's update it even if the value is kept the same.
--- drivers/spi/spi-dw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-dw.c +1 -2
@@ -476,8 +476,7 @@ static void pump_transfers(unsigned long data)if (dw_readw (dws,DW_SPI_CTRL0 ) != cr0 || cs_change || clk_div || imask) {spi_enable_chip (dws,0 ); -if (dw_readw (dws,DW_SPI_CTRL0 ) != cr0) -dw_writew (dws,DW_SPI_CTRL0 , cr0); +dw_writew (dws,DW_SPI_CTRL0 , cr0);spi_set_clk (dws, chip->clk_div);spi_chip_sel (dws, spi,1 );
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/5 spi: dw: move to SPI core message handling
In reply to a message not in the archiveThis patch removes a lot of duplicate code since SPI core provides a nice message handling.
--- drivers/spi/spi-dw-mid.c | 4 +- drivers/spi/spi-dw.c | 182 +++++++++++------------------------------------ drivers/spi/spi-dw.h | 22 ------ 3 files changed, 44 insertions(+), 164 deletions(-)
drivers/spi/spi-dw-mid.c +2 -2
@@ -110,7 +110,7 @@ static void dw_spi_dma_tx_done(void *arg)if (test_and_clear_bit (TX_BUSY , &dws->dma_chan_busy) &BIT (RX_BUSY ))return ; -dw_spi_xfer_done (dws); +spi_finalize_current_transfer (dws->master); }static struct dma_async_tx_descriptor *dw_spi_dma_prepare_tx (struct dw_spi *dws)
@@ -155,7 +155,7 @@ static void dw_spi_dma_rx_done(void *arg)if (test_and_clear_bit (RX_BUSY , &dws->dma_chan_busy) &BIT (TX_BUSY ))return ; -dw_spi_xfer_done (dws); +spi_finalize_current_transfer (dws->master); }static struct dma_async_tx_descriptor *dw_spi_dma_prepare_rx (struct dw_spi *dws)
drivers/spi/spi-dw.c +42 -140
310 lines not on this page · raw message
drivers/spi/spi-dw.h +0 -22
@@ -109,13 +109,7 @@ struct dw_spi {u16 bus_num;u16 num_cs;/* supported slave numbers */ -/* Message Transfer pump */ -struct tasklet_struct pump_transfers; -/* Current message transfer state info */ -struct spi_message *cur_msg; -struct spi_transfer *cur_transfer; -struct chip_data *cur_chip;struct chip_data *prev_chip;size_t len;void *tx;
@@ -182,22 +176,6 @@ static inline void spi_set_clk(struct dw_spi *dws, u16 div)dw_writel (dws,DW_SPI_BAUDR , div); } -static inline void spi_chip_sel (struct dw_spi *dws,struct spi_device *spi, -int active) -{ -u16 cs = spi->chip_select; -int gpio_val = active ? (spi->mode &SPI_CS_HIGH ) : - !(spi->mode &SPI_CS_HIGH ); - -if (dws->cs_control) - dws->cs_control (active); -if (gpio_is_valid (spi->cs_gpio)) -gpio_set_value (spi->cs_gpio, gpio_val); - -if (active) -dw_writel (dws,DW_SPI_SER ,1 << cs); -} -/* Disable IRQ bits */ static inline void spi_mask_intr (struct dw_spi *dws,u32 mask) {
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 5/5] spi: dw: move to SPI core message handling
In reply to a message not in the archiveQuoted 11 lines · Andy Shevchenko
This patch removes a lot of duplicate code since SPI core provides a nice message handling.
drivers/spi/spi-dw.c +0
-6-void dw_spi_xfer_done (struct dw_spi *dws) -{ -/* Update total byte transferred return count actual bytes read */ - dws->cur_msg->actual_length += dws->len; - -/* Move to next transfer */
drivers/spi/spi-dw.c static void dw_reader(struct dw_spi *dws) · line 298
Quoted 10 lines
drivers/spi/spi-dw.c +0
-10- dws->cur_msg->state =next_transfer (dws); - -/* Handle end of message */ -if (dws->cur_msg->state ==DONE_STATE ) { - dws->cur_msg->status =0 ; -giveback (dws); - }else -tasklet_schedule (&dws->pump_transfers); -} -EXPORT_SYMBOL_GPL (dw_spi_xfer_done);
This one should be removed from spi-dw.h as well.
Signature · 7 lines
Andy Shevchenko <[email protected]> Intel Finland Oy -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 5/5] spi: dw: move to SPI core message handling
In reply to a message not in the archiveQuoted 6 lines · Andy Shevchenko
drivers/spi/spi-dw.c static void dw_reader(struct dw_spi *dws) · line 284
Quoted 2 lines · Andy Shevchenko
drivers/spi/spi-dw.c +0
-2-void dw_spi_xfer_done (struct dw_spi *dws) -{This one should be removed from
spi-dw.has well.
OK, I've applied 1-4 but not this one.
Re: [PATCH v1 5/5] spi: dw: move to SPI core message handling
In reply to a message not in the archiveQuoted 2 lines · Andy Shevchenko
This patch removes a lot of duplicate code since SPI core provides a nice message handling.
This looks good modulo the issue you identified BTW.