From: Paul Barker Date: Wed, 5 Oct 2022 12:18:34 +0000 (+0100) Subject: spi: Implement spi_set_speed X-Git-Url: http://git.dujemihanovic.xyz/html/static/git-favicon.png?a=commitdiff_plain;h=c98f6fed93ca49a956d628200b2dfa1454ce6fbb;p=u-boot.git spi: Implement spi_set_speed This function is already defined in spi.h but no implementation of it currently exists in the tree. The implementation is based on the static function spi_set_speed_mode(). The function prototype is modified so that an success or error condition can be returned to the caller. Signed-off-by: Paul Barker Reviewed-by: Heinrich Schuchardt --- diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index f2791c4b88..c929e7c1d0 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -130,6 +130,21 @@ void spi_release_bus(struct spi_slave *slave) dm_spi_release_bus(slave->dev); } +int spi_set_speed(struct spi_slave *slave, uint hz) +{ + struct dm_spi_ops *ops; + int ret; + + ops = spi_get_ops(slave->dev->parent); + if (ops->set_speed) + ret = ops->set_speed(slave->dev->parent, hz); + else + ret = -EINVAL; + if (ret) + dev_err(slave->dev, "Cannot set speed (err=%d)\n", ret); + return ret; +} + int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, void *din, unsigned long flags) { diff --git a/include/spi.h b/include/spi.h index 9a8c1fb260..1bc18e6552 100644 --- a/include/spi.h +++ b/include/spi.h @@ -352,8 +352,10 @@ void spi_cs_deactivate(struct spi_slave *slave); * This sets a new speed to be applied for next spi_xfer(). * @slave: The SPI slave * @hz: The transfer speed + * + * Returns: 0 on success, or a negative value on error. */ -void spi_set_speed(struct spi_slave *slave, uint hz); +int spi_set_speed(struct spi_slave *slave, uint hz); /** * Write 8 bits, then read 8 bits.