Skip to contentSkip to conversation

spi: bitbang: Clean up the driver

PATCH In review Andy Shevchenko 2 participants 7 messages May 17, 2024 – Jun 6, 2024 SPI

lore
Share & tools
lore
#0 lore raw

cover spi: bitbang: Clean up the driver

A few cleanups to the driver. No functional change intended.

Andy Shevchenko (3):
spi: bitbang: Use typedef for txrx_*() callbacks
spi: bitbang: Convert unsigned to unsigned int
spi: bitbang: Replace hard coded number of SPI modes

 drivers/spi/spi-bitbang.c       | 73 ++++++++++++---------------------
 include/linux/spi/spi_bitbang.h |  7 ++--
 2 files changed, 31 insertions(+), 49 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/3 spi: bitbang: Use typedef for txrx_*() callbacks

With a typedef for the txrx_*() callbacks the code looks neater. Note that typedef for a function is okay to have.

---
 drivers/spi/spi-bitbang.c       | 31 +++++++++----------------------
 include/linux/spi/spi_bitbang.h |  7 ++++---
 2 files changed, 13 insertions(+), 25 deletions(-)
drivers/spi/spi-bitbang.c +9 -22
index ca5cc67555c5..d88110acdc5f 100644
@@ -38,26 +38,19 @@
  * working quickly, or testing for differences that aren't speed related.
  */
 
+typedef unsigned int (*spi_bb_txrx_bufs_fn)(struct spi_device *, spi_bb_txrx_word_fn,
+					    unsigned int, struct spi_transfer *,
+					    unsigned int);
+
 struct spi_bitbang_cs {
 	unsigned	nsecs;	/* (clock cycle time)/2 */
-	u32		(*txrx_word)(struct spi_device *spi, unsigned nsecs,
-					u32 word, u8 bits, unsigned flags);
-	unsigned	(*txrx_bufs)(struct spi_device *,
-					u32 (*txrx_word)(
-						struct spi_device *spi,
-						unsigned nsecs,
-						u32 word, u8 bits,
-						unsigned flags),
-					unsigned, struct spi_transfer *,
-					unsigned);
+	spi_bb_txrx_word_fn txrx_word;
+	spi_bb_txrx_bufs_fn txrx_bufs;
 };
 
 static unsigned bitbang_txrx_8(
 	struct spi_device	*spi,
-	u32			(*txrx_word)(struct spi_device *spi,
-					unsigned nsecs,
-					u32 word, u8 bits,
-					unsigned flags),
+	spi_bb_txrx_word_fn txrx_word,
 	unsigned		ns,
 	struct spi_transfer	*t,
 	unsigned flags
@@ -83,10 +76,7 @@ static unsigned bitbang_txrx_8(
 
 static unsigned bitbang_txrx_16(
 	struct spi_device	*spi,
-	u32			(*txrx_word)(struct spi_device *spi,
-					unsigned nsecs,
-					u32 word, u8 bits,
-					unsigned flags),
+	spi_bb_txrx_word_fn txrx_word,
 	unsigned		ns,
 	struct spi_transfer	*t,
 	unsigned flags
@@ -112,10 +102,7 @@ static unsigned bitbang_txrx_16(
 
 static unsigned bitbang_txrx_32(
 	struct spi_device	*spi,
-	u32			(*txrx_word)(struct spi_device *spi,
-					unsigned nsecs,
-					u32 word, u8 bits,
-					unsigned flags),
+	spi_bb_txrx_word_fn txrx_word,
 	unsigned		ns,
 	struct spi_transfer	*t,
 	unsigned flags
include/linux/spi/spi_bitbang.h +4 -3
index b930eca2ef7b..7ca08b430ed5 100644
@@ -4,6 +4,8 @@
 
 #include <linux/workqueue.h>
 
+typedef u32 (*spi_bb_txrx_word_fn)(struct spi_device *, unsigned int, u32, u8, unsigned int);
+
 struct spi_bitbang {
 	struct mutex		lock;
 	u8			busy;
@@ -28,9 +30,8 @@ struct spi_bitbang {
 	int	(*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
 
 	/* txrx_word[SPI_MODE_*]() just looks like a shift register */
-	u32	(*txrx_word[4])(struct spi_device *spi,
-			unsigned nsecs,
-			u32 word, u8 bits, unsigned flags);
+	spi_bb_txrx_word_fn txrx_word[4];
+
 	int	(*set_line_direction)(struct spi_device *spi, bool output);
 };
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH 2/3 spi: bitbang: Convert unsigned to unsigned int

In reply to Andy Shevchenko

Simple type conversion with no functional change implied. While at it, adjust indentation where it makes sense.

---
 drivers/spi/spi-bitbang.c | 42 +++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 24 deletions(-)
drivers/spi/spi-bitbang.c +18 -24
index d88110acdc5f..afb1b1105ec2 100644
@@ -43,21 +43,19 @@ typedef unsigned int (*spi_bb_txrx_bufs_fn)(struct spi_device *, spi_bb_txrx_wor
 					    unsigned int);
 
 struct spi_bitbang_cs {
-	unsigned	nsecs;	/* (clock cycle time)/2 */
+	unsigned int nsecs;	/* (clock cycle time) / 2 */
 	spi_bb_txrx_word_fn txrx_word;
 	spi_bb_txrx_bufs_fn txrx_bufs;
 };
 
-static unsigned bitbang_txrx_8(
-	struct spi_device	*spi,
+static unsigned int bitbang_txrx_8(struct spi_device *spi,
 	spi_bb_txrx_word_fn txrx_word,
-	unsigned		ns,
+	unsigned int ns,
 	struct spi_transfer	*t,
-	unsigned flags
-)
+	unsigned int flags)
 {
-	unsigned		bits = t->bits_per_word;
-	unsigned		count = t->len;
+	unsigned int		bits = t->bits_per_word;
+	unsigned int		count = t->len;
 	const u8		*tx = t->tx_buf;
 	u8			*rx = t->rx_buf;
 
@@ -74,16 +72,14 @@ static unsigned bitbang_txrx_8(
 	return t->len - count;
 }
 
-static unsigned bitbang_txrx_16(
-	struct spi_device	*spi,
+static unsigned int bitbang_txrx_16(struct spi_device *spi,
 	spi_bb_txrx_word_fn txrx_word,
-	unsigned		ns,
+	unsigned int ns,
 	struct spi_transfer	*t,
-	unsigned flags
-)
+	unsigned int flags)
 {
-	unsigned		bits = t->bits_per_word;
-	unsigned		count = t->len;
+	unsigned int		bits = t->bits_per_word;
+	unsigned int		count = t->len;
 	const u16		*tx = t->tx_buf;
 	u16			*rx = t->rx_buf;
 
@@ -100,16 +96,14 @@ static unsigned bitbang_txrx_16(
 	return t->len - count;
 }
 
-static unsigned bitbang_txrx_32(
-	struct spi_device	*spi,
+static unsigned int bitbang_txrx_32(struct spi_device *spi,
 	spi_bb_txrx_word_fn txrx_word,
-	unsigned		ns,
+	unsigned int ns,
 	struct spi_transfer	*t,
-	unsigned flags
-)
+	unsigned int flags)
 {
-	unsigned		bits = t->bits_per_word;
-	unsigned		count = t->len;
+	unsigned int		bits = t->bits_per_word;
+	unsigned int		count = t->len;
 	const u32		*tx = t->tx_buf;
 	u32			*rx = t->rx_buf;
 
@@ -221,7 +215,7 @@ EXPORT_SYMBOL_GPL(spi_bitbang_cleanup);
 static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
 {
 	struct spi_bitbang_cs	*cs = spi->controller_state;
-	unsigned		nsecs = cs->nsecs;
+	unsigned int		nsecs = cs->nsecs;
 	struct spi_bitbang	*bitbang;
 
 	bitbang = spi_controller_get_devdata(spi->controller);
@@ -234,7 +228,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
 	}
 
 	if (spi->mode & SPI_3WIRE) {
-		unsigned flags;
+		unsigned int flags;
 
 		flags = t->tx_buf ? SPI_CONTROLLER_NO_RX : SPI_CONTROLLER_NO_TX;
 		return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t, flags);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#3 lore raw

PATCH 3/3 spi: bitbang: Replace hard coded number of SPI modes

In reply to Andy Shevchenko

Instead of using hard coded number of modes, replace it with SPI_MODE_X_MASK + 1 to show relation to the SPI modes.

---
 include/linux/spi/spi_bitbang.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/spi/spi_bitbang.h +1 -1
index 7ca08b430ed5..d4cb83195f7a 100644
@@ -30,7 +30,7 @@ struct spi_bitbang {
 	int	(*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
 
 	/* txrx_word[SPI_MODE_*]() just looks like a shift register */
-	spi_bb_txrx_word_fn txrx_word[4];
+	spi_bb_txrx_word_fn txrx_word[SPI_MODE_X_MASK + 1];
 
 	int	(*set_line_direction)(struct spi_device *spi, bool output);
 };
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#4 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

A few cleanups to the driver. No functional change intended.

Andy Shevchenko (3):
spi: bitbang: Use typedef for txrx_*() callbacks
spi: bitbang: Convert unsigned to unsigned int
spi: bitbang: Replace hard coded number of SPI modes

Hmm... It's not the first time I noticed that the series (despite even appearing in the CI, but then disappearing) left abandoned without clear feedback,

Should I do something here?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

A few cleanups to the driver. No functional change intended.

Andy Shevchenko (3):
spi: bitbang: Use typedef for txrx_*() callbacks
spi: bitbang: Convert unsigned to unsigned int
spi: bitbang: Replace hard coded number of SPI modes

Quoted 5 lines

Hmm... It's not the first time I noticed that the series (despite even appearing in the CI, but then disappearing) left abandoned without clear feedback,

Should I do something here?

Please don't send content free pings and please allow a reasonable time for review. People get busy, go on holiday, attend conferences and so on so unless there is some reason for urgency (like critical bug fixes) please allow at least a couple of weeks for review. If there have been review comments then people may be waiting for those to be addressed.

Sending content free pings adds to the mail volume (if they are seen at all) which is often the problem and since they can't be reviewed directly if something has gone wrong you'll have to resend the patches anyway, so sending again is generally a better approach though there are some other maintainers who like them - if in doubt look at how patches for the subsystem are normally handled.

#6 lore raw
Quoted 9 lines · Mark Brown
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

A few cleanups to the driver. No functional change intended.

Andy Shevchenko (3):
spi: bitbang: Use typedef for txrx_*() callbacks
spi: bitbang: Convert unsigned to unsigned int
spi: bitbang: Replace hard coded number of SPI modes

Quoted 5 lines
Quoted 5 lines

Hmm... It's not the first time I noticed that the series (despite even appearing in the CI, but then disappearing) left abandoned without clear feedback,

Should I do something here?

Okay, it's just an announce is missing.
I found them in the repository. Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko