diff options
author | Illia Smyrnov <illia.smyrnov@ti.com> | 2013-06-14 12:12:07 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-06-17 05:13:29 -0400 |
commit | 56cd5c1578135120d73a7054140855728f8cca36 (patch) | |
tree | bd3b9af0fadf61034e56601f8de30bc0eaa259a4 | |
parent | 0514dd76ea556859d398aaff725817e1c97579ea (diff) |
spi: omap2-mcspi: Move bytes per word calculation to the function
Introduce mcspi_bytes_per_word function as replacement for the next code
fragment:
int c = (word_len <= 8) ? 1 :
(word_len <= 16) ? 2 :
/* word_len <= 32 */ 4;
This code used 2 times in current driver code and will be used 2 times in
the next FIFO buffer support patch. Replace it with inline function with clear
name to improve code legibility.
Signed-off-by: Illia Smyrnov <illia.smyrnov@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | drivers/spi/spi-omap2-mcspi.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 000922abcb87..5a93a0df551f 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c | |||
@@ -186,6 +186,16 @@ static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val) | |||
186 | mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0); | 186 | mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0); |
187 | } | 187 | } |
188 | 188 | ||
189 | static inline int mcspi_bytes_per_word(int word_len) | ||
190 | { | ||
191 | if (word_len <= 8) | ||
192 | return 1; | ||
193 | else if (word_len <= 16) | ||
194 | return 2; | ||
195 | else /* word_len <= 32 */ | ||
196 | return 4; | ||
197 | } | ||
198 | |||
189 | static void omap2_mcspi_set_dma_req(const struct spi_device *spi, | 199 | static void omap2_mcspi_set_dma_req(const struct spi_device *spi, |
190 | int is_read, int enable) | 200 | int is_read, int enable) |
191 | { | 201 | { |
@@ -432,10 +442,9 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, | |||
432 | else /* word_len <= 32 */ | 442 | else /* word_len <= 32 */ |
433 | ((u32 *)xfer->rx_buf)[elements++] = w; | 443 | ((u32 *)xfer->rx_buf)[elements++] = w; |
434 | } else { | 444 | } else { |
445 | int bytes_per_word = mcspi_bytes_per_word(word_len); | ||
435 | dev_err(&spi->dev, "DMA RX penultimate word empty"); | 446 | dev_err(&spi->dev, "DMA RX penultimate word empty"); |
436 | count -= (word_len <= 8) ? 2 : | 447 | count -= (bytes_per_word << 1); |
437 | (word_len <= 16) ? 4 : | ||
438 | /* word_len <= 32 */ 8; | ||
439 | omap2_mcspi_set_enable(spi, 1); | 448 | omap2_mcspi_set_enable(spi, 1); |
440 | return count; | 449 | return count; |
441 | } | 450 | } |
@@ -453,9 +462,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, | |||
453 | ((u32 *)xfer->rx_buf)[elements] = w; | 462 | ((u32 *)xfer->rx_buf)[elements] = w; |
454 | } else { | 463 | } else { |
455 | dev_err(&spi->dev, "DMA RX last word empty"); | 464 | dev_err(&spi->dev, "DMA RX last word empty"); |
456 | count -= (word_len <= 8) ? 1 : | 465 | count -= mcspi_bytes_per_word(word_len); |
457 | (word_len <= 16) ? 2 : | ||
458 | /* word_len <= 32 */ 4; | ||
459 | } | 466 | } |
460 | omap2_mcspi_set_enable(spi, 1); | 467 | omap2_mcspi_set_enable(spi, 1); |
461 | return count; | 468 | return count; |