Skip to contentSkip to conversation

spi: spi-ep93xx: remove bits_per_word() helper

PATCH Applied H Hartley Sweeten 3 participants 3 messages Jun 28, 2013 – Jun 30, 2013 SPI

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 4/8 spi: spi-ep93xx: remove bits_per_word() helper

This inline helper function is only used to determine the bus width of the current transfer (8 or 16 bit). Add a bool flag to the private structure and set it appropriately for each transfer.

Cc Ryan Mallon <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Mark Brown <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/spi/spi-ep93xx.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/spi/spi-ep93xx.c +5 -11
index bcfd35a..4fab3bb 100644
@@ -116,6 +116,7 @@ struct ep93xx_spi {
 	unsigned long			min_rate;
 	unsigned long			max_rate;
 	bool				running;
+	bool				word_xfer;
 	struct workqueue_struct		*wq;
 	struct work_struct		msg_work;
 	struct completion		wait;
@@ -407,17 +408,9 @@ static void ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
 	writew(cr0, espi->regs_base + SSPCR0);
 }
 
-static inline int bits_per_word(const struct ep93xx_spi *espi)
-{
-	struct spi_message *msg = espi->current_msg;
-	struct spi_transfer *t = msg->state;
-
-	return t->bits_per_word;
-}
-
 static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 tx_val = 0;
 
 		if (t->tx_buf)
@@ -436,7 +429,7 @@ static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 
 static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 rx_val;
 
 		rx_val = readw(espi->regs_base + SSPDR);
@@ -522,7 +515,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
 	size_t len = t->len;
 	int i, ret, nents;
 
-	if (bits_per_word(espi) > 8)
+	if (espi->word_xfer)
 		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
 	else
 		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
@@ -699,6 +692,7 @@ static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi,
 
 	ep93xx_spi_chip_setup(espi, chip);
 
+	espi->word_xfer = (t->bits_per_word > 8) ? true : false;
 	espi->rx = 0;
 	espi->tx = 0;
 
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 18 lines · H Hartley Sweeten

This inline helper function is only used to determine the bus width of the current transfer (8 or 16 bit). Add a bool flag to the private structure and set it appropriately for each transfer.

Cc Ryan Mallon <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Mark Brown <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/spi/spi-ep93xx.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/spi/spi-ep93xx.c +0 -0
index bcfd35a..4fab3bb 100644

drivers/spi/spi-ep93xx.c struct ep93xx_spi { · line 119

Quoted 4 lines
drivers/spi/spi-ep93xx.c +1 -0
@@ -116,6 +116,7 @@ struct ep93xx_spi {
 	unsigned long			min_rate;
 	unsigned long			max_rate;
 	bool				running;
+	bool				word_xfer;

I think this is a slightly confusing name. Maybe something like is_16bit_xfer would be better?

Quoted 41 lines
drivers/spi/spi-ep93xx.c +3 -11
 	struct workqueue_struct		*wq;
 	struct work_struct		msg_work;
 	struct completion		wait;
@@ -407,17 +408,9 @@ static void ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
 	writew(cr0, espi->regs_base + SSPCR0);
 }
 
-static inline int bits_per_word(const struct ep93xx_spi *espi)
-{
-	struct spi_message *msg = espi->current_msg;
-	struct spi_transfer *t = msg->state;
-
-	return t->bits_per_word;
-}
-
 static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 tx_val = 0;
 
 		if (t->tx_buf)
@@ -436,7 +429,7 @@ static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 
 static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 rx_val;
 
 		rx_val = readw(espi->regs_base + SSPDR);
@@ -522,7 +515,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
 	size_t len = t->len;
 	int i, ret, nents;
 
-	if (bits_per_word(espi) > 8)
+	if (espi->word_xfer)
 		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
 	else
 		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;

drivers/spi/spi-ep93xx.c static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi, · line 695

Quoted 4 lines
drivers/spi/spi-ep93xx.c +1 -0
@@ -699,6 +692,7 @@ static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi,
 
 	ep93xx_spi_chip_setup(espi, chip);
 
+	espi->word_xfer = (t->bits_per_word > 8) ? true : false;
	espi->word_xfer = (t->bits_per_word > 8);

This patch is fine, but not sure it is entirely worth it. The information is already stored in t->bits_per_word and the cost of retrieving it is pretty minimal.

~Ryan

#2 lore raw
Quoted 71 lines · Ryan Mallon
Quoted 18 lines · H Hartley Sweeten

This inline helper function is only used to determine the bus width of the current transfer (8 or 16 bit). Add a bool flag to the private structure and set it appropriately for each transfer.

Cc Ryan Mallon <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Mark Brown <[email protected]>
Cc Grant Likely <[email protected]>
---
 drivers/spi/spi-ep93xx.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/spi/spi-ep93xx.c +0 -0
index bcfd35a..4fab3bb 100644

drivers/spi/spi-ep93xx.c struct ep93xx_spi { · line 119

Quoted 4 lines
drivers/spi/spi-ep93xx.c +1 -0
@@ -116,6 +116,7 @@ struct ep93xx_spi {
 	unsigned long			min_rate;
 	unsigned long			max_rate;
 	bool				running;
+	bool				word_xfer;

I think this is a slightly confusing name. Maybe something like is_16bit_xfer would be better?

Quoted 42 lines
drivers/spi/spi-ep93xx.c +3 -11
 	struct workqueue_struct		*wq;
 	struct work_struct		msg_work;
 	struct completion		wait;
@@ -407,17 +408,9 @@ static void ep93xx_spi_chip_setup(const struct ep93xx_spi *espi,
 	writew(cr0, espi->regs_base + SSPCR0);
 }
 
-static inline int bits_per_word(const struct ep93xx_spi *espi)
-{
-	struct spi_message *msg = espi->current_msg;
-	struct spi_transfer *t = msg->state;
-
-	return t->bits_per_word;
-}
-
 static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 tx_val = 0;
 
 		if (t->tx_buf)
@@ -436,7 +429,7 @@ static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
 
 static void ep93xx_do_read(struct ep93xx_spi *espi, struct spi_transfer *t)
 {
-	if (bits_per_word(espi) > 8) {
+	if (espi->word_xfer) {
 		u16 rx_val;
 
 		rx_val = readw(espi->regs_base + SSPDR);
@@ -522,7 +515,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
 	size_t len = t->len;
 	int i, ret, nents;
 
-	if (bits_per_word(espi) > 8)
+	if (espi->word_xfer)
 		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
 	else
 		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
@@ -699,6 +692,7 @@ static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi,
 
Quoted 6 lines

drivers/spi/spi-ep93xx.c static void ep93xx_spi_process_transfer(struct ep93xx_spi *espi, · line 695

Quoted 3 lines
drivers/spi/spi-ep93xx.c +1 -0
 	ep93xx_spi_chip_setup(espi, chip);
 
+	espi->word_xfer = (t->bits_per_word > 8) ? true : false;
	espi->word_xfer = (t->bits_per_word > 8);

Or even

	espi->word_xfer = t->bits_per_word > 8;
Quoted 3 lines

This patch is fine, but not sure it is entirely worth it. The information is already stored in t->bits_per_word and the cost of retrieving it is pretty minimal.

I agree.