[PATCH 3/5] spi: Implement spi_set_wordlen for driver model
John Watts
contact at jookia.org
Fri Jun 14 14:18:43 CEST 2024
Implement spi_set_wordlen for driver model devices.
Not all drivers support this interface, so we will assume the default
wordlen is safe and allow setting that unconditionally.
Signed-off-by: John Watts <contact at jookia.org>
---
drivers/spi/spi-uclass.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index f4795e6867..c2baf9a262 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -130,6 +130,35 @@ void spi_release_bus(struct spi_slave *slave)
dm_spi_release_bus(slave->dev);
}
+static int spi_try_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
+{
+ struct dm_spi_ops *ops;
+
+ ops = spi_get_ops(slave->dev->parent);
+ if (ops->set_wordlen)
+ return ops->set_wordlen(slave->dev->parent, wordlen);
+ else if (wordlen == SPI_DEFAULT_WORDLEN)
+ return 0;
+ else
+ return -EINVAL;
+}
+
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
+{
+ int oldwordlen = slave->wordlen;
+ int ret;
+
+ ret = spi_try_set_wordlen(slave, wordlen);
+ if (ret < 0) {
+ dev_err(slave->dev, "Cannot set wordlen (err=%d)\n", ret);
+ return ret;
+ }
+
+ slave->wordlen = wordlen;
+
+ return oldwordlen;
+}
+
int spi_set_speed(struct spi_slave *slave, uint hz)
{
struct dm_spi_ops *ops;
--
2.45.2
More information about the U-Boot
mailing list