Skip to contentSkip to conversation

spi: sirf: Avoid duplicate code in various bits_per_word cases

PATCH Applied Axel Lin 3 participants 3 messages Jan 15, 2014 – Jan 27, 2014 2 messages not in the archive SPI

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH v2 1/1 spi: sirf: Avoid duplicate code in various bits_per_word cases

Trivial cleanup to avoid duplicate code in various bits_per_word cases.

---
 drivers/spi/spi-sirf.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/spi/spi-sirf.c +6 -15
index ed5e501..4b43310 100644
@@ -459,11 +459,6 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 		regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_8;
 		sspi->rx_word = spi_sirfsoc_rx_word_u8;
 		sspi->tx_word = spi_sirfsoc_tx_word_u8;
-		txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_BYTE;
-		rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_BYTE;
-		sspi->word_width = 1;
 		break;
 	case 12:
 	case 16:
@@ -471,26 +466,22 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
 			SIRFSOC_SPI_TRAN_DAT_FORMAT_16;
 		sspi->rx_word = spi_sirfsoc_rx_word_u16;
 		sspi->tx_word = spi_sirfsoc_tx_word_u16;
-		txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_WORD;
-		rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_WORD;
-		sspi->word_width = 2;
 		break;
 	case 32:
 		regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_32;
 		sspi->rx_word = spi_sirfsoc_rx_word_u32;
 		sspi->tx_word = spi_sirfsoc_tx_word_u32;
-		txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_DWORD;
-		rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
-					SIRFSOC_SPI_FIFO_WIDTH_DWORD;
-		sspi->word_width = 4;
 		break;
 	default:
 		BUG();
 	}
 
+	sspi->word_width = DIV_ROUND_UP(bits_per_word, 8);
+	txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
+					   sspi->word_width;
+	rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
+					   sspi->word_width;
+
 	if (!(spi->mode & SPI_CS_HIGH))
 		regval |= SIRFSOC_SPI_CS_IDLE_STAT;
 	if (!(spi->mode & SPI_LSB_FIRST))
Signature · 8 lines
1.8.1.2



--
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

A message that is not in the archive (sent off-list or not yet received): 5EB3BFCD089AD643B9BB63439F5FD5E9012BC1048F@SHAASIEXM01.ASIA.ROOT.PRI

A message that is not in the archive (sent off-list or not yet received): 5EB3BFCD089AD643B9BB63439F5FD5E9012BC1048F-W2enlP78h2wYZnBWG7VmBdnKn0HB1kRyVQQcQy+6Uvc@public.gmane.org

Reviewed-by
#3 lore raw

2014/1/15 Barry Song <[email protected]>:

Quoted 11 lines
Quoted 11 lines

-----Original Message-----
From: Axel Lin [mailto:[email protected]]
Sent: Wednesday, January 15, 2014 5:08 PM
To: Mark Brown
Cc: Zhiwu Song; Barry Song; Qipan Li; [email protected]
Subject: [PATCH v2] spi: sirf: Avoid duplicate code in various bits_per_word cases

Trivial cleanup to avoid duplicate code in various bits_per_word cases.

looks good to me. Thank, Axel.

Quoted 52 lines
Quoted 52 lines
---
 drivers/spi/spi-sirf.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/spi/spi-sirf.c index renamed from drivers/spi/spi-sirf.c +0 -0

ed5e501..4b43310 100644

drivers/spi/spi-sirf.c +0 -1
@@ -459,11 +459,6 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi,
 struct spi_transfer *t)
              regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_8;
              sspi->rx_word = spi_sirfsoc_rx_word_u8;
              sspi->tx_word = spi_sirfsoc_tx_word_u8;
-             txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -2
-                                     SIRFSOC_SPI_FIFO_WIDTH_BYTE;
-             rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -3
-                                     SIRFSOC_SPI_FIFO_WIDTH_BYTE;
-             sspi->word_width = 1;
              break;
      case 12:
      case 16:
@@ -471,26 +466,22 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi,
 struct spi_transfer *t)
                      SIRFSOC_SPI_TRAN_DAT_FORMAT_16;
              sspi->rx_word = spi_sirfsoc_rx_word_u16;
              sspi->tx_word = spi_sirfsoc_tx_word_u16;
-             txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -2
-                                     SIRFSOC_SPI_FIFO_WIDTH_WORD;
-             rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -3
-                                     SIRFSOC_SPI_FIFO_WIDTH_WORD;
-             sspi->word_width = 2;
              break;
      case 32:
              regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_32;
              sspi->rx_word = spi_sirfsoc_rx_word_u32;
              sspi->tx_word = spi_sirfsoc_tx_word_u32;
-             txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -2
-                                     SIRFSOC_SPI_FIFO_WIDTH_DWORD;
-             rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE

/ 2) |

drivers/spi/spi-sirf.c +0 -2
-                                     SIRFSOC_SPI_FIFO_WIDTH_DWORD;
-             sspi->word_width = 4;
              break;
      default:
              BUG();
      }
Quoted 11 lines
Quoted 11 lines
drivers/spi/spi-sirf.c +6 -1
+     sspi->word_width = DIV_ROUND_UP(bits_per_word, 8);
+     txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
+                                        sspi->word_width;
+     rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
+                                        sspi->word_width;
+
      if (!(spi->mode & SPI_CS_HIGH))
              regval |= SIRFSOC_SPI_CS_IDLE_STAT;
      if (!(spi->mode & SPI_LSB_FIRST))
--

1.8.1.2

-barry
--
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