diff mbox series

[3/5] spi: Implement spi_set_wordlen for driver model

Message ID 20240614-mipi_dbi-v1-3-946eb82f8533@jookia.org
State Under Review
Delegated to: Anatolij Gustschin
Headers show
Series video: add support for MIPI DBI interface | expand

Commit Message

John Watts June 14, 2024, 12:18 p.m. UTC
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@jookia.org>
---
 drivers/spi/spi-uclass.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox series

Patch

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;