On 11/12/2017 04:30 PM, Baruch Siach wrote:
Calling .set_speed with zero speed is definitely a bug. Instead of crashing,
set hz to 1 so that we get the lowest possible frequency rate.

Did this actually occur? Why?


Signed-off-by: Baruch Siach <bar...@tkos.co.il>
---
v2: Don't fail; set lowest rate (Jagan)
---
  drivers/spi/kirkwood_spi.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index 0c6bd295cde9..5744849a5ad9 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -257,6 +257,9 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
        struct kwspi_registers *reg = plat->spireg;
        u32 data;
+ /* Avoid divide by zero; instead, set the lowest possible speed */
+       if (hz == 0)
+               hz = 1;

Shouldn't we write a debug message here like in other drivers?

debug("%s: can't set 0 Hz (actual will be 1 Hz)\n", __func__);

Does any bus member support 1 Hz? Wouldn't 125 kHz be a more reasonable value?

Could a division by zero valued max_hz occur in spi_setup_slave too?

Best regards

Heinrich

        /* calculate spi clock prescaller using max_hz */
        data = ((CONFIG_SYS_TCLK / 2) / hz) + 0x10;
        data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;


_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to