[U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz

Simon Goldschmidt sgoldschmidt at de.pepperl-fuchs.com
Mon Jan 22 13:16:09 UTC 2018


On 22.01.2018 06:04, Vignesh R wrote:
> On Thursday 18 January 2018 01:45 PM, Simon Goldschmidt wrote:
>> When the device tree is missing a correct spi slave description below
>> the bus, the 'set_speed' callback can be called with 'speed' == 0 Hz.
>> At least with cadence qspi, this leads to a division by zero.
>>
>> Prevent this by initializing speed to 100 kHz in this case, as is
>> done in 'dm_spi_claim_bus'.
>>
> As per doc/device-tree-bindings/spi/spi-bus.txt,
> spi-max-frequency - (required) Maximum SPI clocking speed of device in Hz
>
> IMO, the correct fix would be to error out with proper warning, if
> spi-max-frequency property is absent in DT.

By now, I think so, too. Fallback to 100.000 Hz really hurts when 
loading a 16 MByte fit image from qspi. A warning is required at least, 
but completely failing might be better indeed...

Regards,
Simon

>
>> Signed-off-by: Simon Goldschmidt <sgoldschmidt at de.pepperl-fuchs.com>
>> ---
>>
>>   drivers/spi/spi-uclass.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
>> index e06a603ab1..41ecef77db 100644
>> --- a/drivers/spi/spi-uclass.c
>> +++ b/drivers/spi/spi-uclass.c
>> @@ -325,6 +325,8 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
>>   	if (!speed) {
>>   		speed = plat->max_hz;
>>   		mode = plat->mode;
>> +		if (!speed)
>> +			speed = 100000;
>>   	}
>>   	ret = spi_set_speed_mode(bus, speed, mode);
>>   	if (ret)
>>



More information about the U-Boot mailing list