[U-Boot] [PATCH] spi-uclass: claim bus before setting speed

The sunxi SPI peripheral driver attempts to interact with the peripheral in the set_speed function. It also resets the device completely (disabling clocks and power) when the bus is released and turns it back on when claiming. So, if the clock was set up before the bus was claimed, the speed change would have no effect, and the peripheral wouldn't work in many cases.
This change allows the peripheral driver to initialize the device before attempting to do anything else.
Signed-off-by: George Hilliard thirtythreeforty@gmail.com Cc: Jagan Teki jteki@openedev.com --- drivers/spi/spi-uclass.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 88cb2a12622..88aa883b206 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -51,6 +51,7 @@ int dm_spi_claim_bus(struct udevice *dev) struct dm_spi_bus *spi = dev_get_uclass_priv(bus); struct spi_slave *slave = dev_get_parent_priv(dev); int speed; + int ret;
speed = slave->max_hz; if (spi->max_hz) { @@ -61,15 +62,22 @@ int dm_spi_claim_bus(struct udevice *dev) } if (!speed) speed = SPI_DEFAULT_SPEED_HZ; + + if (ops->claim_bus) { + ret = ops->claim_bus(dev); + if (ret) + return log_ret(ret); + } + if (speed != slave->speed) { - int ret = spi_set_speed_mode(bus, speed, slave->mode); + ret = spi_set_speed_mode(bus, speed, slave->mode);
if (ret) return log_ret(ret); slave->speed = speed; }
- return log_ret(ops->claim_bus ? ops->claim_bus(dev) : 0); + return 0; }
void dm_spi_release_bus(struct udevice *dev)

On Thu, Jun 20, 2019 at 6:48 PM George Hilliard thirtythreeforty@gmail.com wrote:
The sunxi SPI peripheral driver attempts to interact with the peripheral in the set_speed function. It also resets the device completely (disabling clocks and power) when the bus is released and
We do set_speed even before this, during spi_get_bus_and_cs call. I don't think claim would have any effect here. and the set_speed here is to update if speed is diff b/w slave and the actual.
If claim required here, this would also need during spi_get_bus_and_cs, but this isn't the case.
turns it back on when claiming. So, if the clock was set up before the bus was claimed, the speed change would have no effect, and the peripheral wouldn't work in many cases.
Can you listed these cases, or some kind of non-working or no effect case would help here.
participants (2)
-
George Hilliard
-
Jagan Teki