diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2014-06-02 09:38:03 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-06-02 10:49:32 -0400 |
commit | 5f684c34fc82be84ece158aa5c5c7c5072daa9a0 (patch) | |
tree | f8e211cd6651b941517fc450750800fd09ff7aa3 /drivers/spi | |
parent | 3beb61dbfcf188399cbc36ce1eeb8b2ba724de38 (diff) |
spi: rspi: Extract rspi_wait_for_{tx_empty,rx_full}()
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-rspi.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c index 5639f9529e0b..d04a4acce231 100644 --- a/drivers/spi/spi-rspi.c +++ b/drivers/spi/spi-rspi.c | |||
@@ -405,11 +405,22 @@ static int rspi_wait_for_interrupt(struct rspi_data *rspi, u8 wait_mask, | |||
405 | return 0; | 405 | return 0; |
406 | } | 406 | } |
407 | 407 | ||
408 | static inline int rspi_wait_for_tx_empty(struct rspi_data *rspi) | ||
409 | { | ||
410 | return rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); | ||
411 | } | ||
412 | |||
413 | static inline int rspi_wait_for_rx_full(struct rspi_data *rspi) | ||
414 | { | ||
415 | return rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE); | ||
416 | } | ||
417 | |||
408 | static int rspi_data_out(struct rspi_data *rspi, u8 data) | 418 | static int rspi_data_out(struct rspi_data *rspi, u8 data) |
409 | { | 419 | { |
410 | if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { | 420 | int error = rspi_wait_for_tx_empty(rspi); |
421 | if (error < 0) { | ||
411 | dev_err(&rspi->master->dev, "transmit timeout\n"); | 422 | dev_err(&rspi->master->dev, "transmit timeout\n"); |
412 | return -ETIMEDOUT; | 423 | return error; |
413 | } | 424 | } |
414 | rspi_write_data(rspi, data); | 425 | rspi_write_data(rspi, data); |
415 | return 0; | 426 | return 0; |
@@ -417,11 +428,13 @@ static int rspi_data_out(struct rspi_data *rspi, u8 data) | |||
417 | 428 | ||
418 | static int rspi_data_in(struct rspi_data *rspi) | 429 | static int rspi_data_in(struct rspi_data *rspi) |
419 | { | 430 | { |
431 | int error; | ||
420 | u8 data; | 432 | u8 data; |
421 | 433 | ||
422 | if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) { | 434 | error = rspi_wait_for_rx_full(rspi); |
435 | if (error < 0) { | ||
423 | dev_err(&rspi->master->dev, "receive timeout\n"); | 436 | dev_err(&rspi->master->dev, "receive timeout\n"); |
424 | return -ETIMEDOUT; | 437 | return error; |
425 | } | 438 | } |
426 | data = rspi_read_data(rspi); | 439 | data = rspi_read_data(rspi); |
427 | return data; | 440 | return data; |
@@ -737,7 +750,7 @@ static int rspi_transfer_out_in(struct rspi_data *rspi, | |||
737 | } | 750 | } |
738 | 751 | ||
739 | /* Wait for the last transmission */ | 752 | /* Wait for the last transmission */ |
740 | rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); | 753 | rspi_wait_for_tx_empty(rspi); |
741 | 754 | ||
742 | return 0; | 755 | return 0; |
743 | } | 756 | } |
@@ -783,7 +796,7 @@ static int rspi_rz_transfer_out_in(struct rspi_data *rspi, | |||
783 | } | 796 | } |
784 | 797 | ||
785 | /* Wait for the last transmission */ | 798 | /* Wait for the last transmission */ |
786 | rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); | 799 | rspi_wait_for_tx_empty(rspi); |
787 | 800 | ||
788 | return 0; | 801 | return 0; |
789 | } | 802 | } |
@@ -818,7 +831,7 @@ static int qspi_transfer_out_in(struct rspi_data *rspi, | |||
818 | } | 831 | } |
819 | 832 | ||
820 | /* Wait for the last transmission */ | 833 | /* Wait for the last transmission */ |
821 | rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); | 834 | rspi_wait_for_tx_empty(rspi); |
822 | 835 | ||
823 | return 0; | 836 | return 0; |
824 | } | 837 | } |
@@ -836,7 +849,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) | |||
836 | } | 849 | } |
837 | 850 | ||
838 | /* Wait for the last transmission */ | 851 | /* Wait for the last transmission */ |
839 | rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); | 852 | rspi_wait_for_tx_empty(rspi); |
840 | 853 | ||
841 | return 0; | 854 | return 0; |
842 | } | 855 | } |