[PATCH 1/5] spi: Return old wordlen in spit_set_wordlen

John Watts contact at jookia.org
Fri Jun 14 14:18:41 CEST 2024


Return the current wordlen to the caller so they can restore it back
when done. This is required to avoid clobbering the bus state.

Signed-off-by: John Watts <contact at jookia.org>
---
 drivers/spi/spi.c | 4 +++-
 include/spi.h     | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 22910de0dd..3649c9c25b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -10,6 +10,8 @@
 
 int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
 {
+	int oldwordlen = slave->wordlen;
+
 	if (wordlen == 0 || wordlen > 32) {
 		printf("spi: invalid wordlen %u\n", wordlen);
 		return -1;
@@ -17,7 +19,7 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
 
 	slave->wordlen = wordlen;
 
-	return 0;
+	return oldwordlen;
 }
 
 void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
diff --git a/include/spi.h b/include/spi.h
index 7e38cc2a2a..d5acf4f9e9 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -259,7 +259,7 @@ void spi_release_bus(struct spi_slave *slave);
  * @slave:	The SPI slave
  * @wordlen:	The number of bits in a word
  *
- * Returns: 0 on success, -1 on failure.
+ * Returns: The old word length on success, -1 on failure.
  */
 int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
 

-- 
2.45.2



More information about the U-Boot mailing list