All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
@ 2018-01-18  8:15 Simon Goldschmidt
  2018-01-18  8:23 ` Michael Nazzareno Trimarchi
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Simon Goldschmidt @ 2018-01-18  8:15 UTC (permalink / raw)
  To: u-boot

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'.

Signed-off-by: Simon Goldschmidt <sgoldschmidt@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)
-- 
2.11.0


Pepperl+Fuchs GmbH, Mannheim
Geschaeftsfuehrer/Managing Directors: Dr.-Ing. Gunther Kegel (Vors./CEO), Werner Guthier, Mehmet Hatiboglu
Vorsitzender des Aufsichtsrats/Chairman of the supervisory board: Claus Michael
Registergericht/Register Court: AG Mannheim HRB 4713

Wichtiger Hinweis:
Diese E-Mail einschliesslich ihrer Anhaenge enthaelt vertrauliche und rechtlich geschuetzte Informationen, die nur fuer den Adressaten bestimmt sind. 
Sollten Sie nicht der bezeichnete Adressat sein, so teilen Sie dies bitte dem Absender umgehend mit und loeschen Sie diese Nachricht und ihre Anhaenge. Die unbefugte Weitergabe, das Anfertigen von Kopien und jede Veraenderung der E-Mail ist untersagt. Der Absender haftet nicht fuer Inhalte von veraenderten E-Mails.


Important Information:
This e-mail message including its attachments contains confidential and legally protected information solely intended for the addressee. If you are not the intended addressee of this message, please contact the addresser immediately and delete this message including its attachments. The unauthorized dissemination, copying and change of this e-mail are strictly forbidden. The addresser shall not be liable for the content of such changed e-mails.

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:15 [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz Simon Goldschmidt
@ 2018-01-18  8:23 ` Michael Nazzareno Trimarchi
  2018-01-18  8:27   ` Simon Goldschmidt
  2018-01-22  0:29 ` Simon Glass
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Michael Nazzareno Trimarchi @ 2018-01-18  8:23 UTC (permalink / raw)
  To: u-boot

Hi

On Thu, Jan 18, 2018 at 9:15 AM, Simon Goldschmidt
<sgoldschmidt@de.pepperl-fuchs.com> 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'.
>
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@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;

You should add a warming message

Michael

>         }
>         ret = spi_set_speed_mode(bus, speed, mode);
>         if (ret)
> --
> 2.11.0
>
>
> Pepperl+Fuchs GmbH, Mannheim
> Geschaeftsfuehrer/Managing Directors: Dr.-Ing. Gunther Kegel (Vors./CEO), Werner Guthier, Mehmet Hatiboglu
> Vorsitzender des Aufsichtsrats/Chairman of the supervisory board: Claus Michael
> Registergericht/Register Court: AG Mannheim HRB 4713
>
> Wichtiger Hinweis:
> Diese E-Mail einschliesslich ihrer Anhaenge enthaelt vertrauliche und rechtlich geschuetzte Informationen, die nur fuer den Adressaten bestimmt sind.
> Sollten Sie nicht der bezeichnete Adressat sein, so teilen Sie dies bitte dem Absender umgehend mit und loeschen Sie diese Nachricht und ihre Anhaenge. Die unbefugte Weitergabe, das Anfertigen von Kopien und jede Veraenderung der E-Mail ist untersagt. Der Absender haftet nicht fuer Inhalte von veraenderten E-Mails.
>
>
> Important Information:
> This e-mail message including its attachments contains confidential and legally protected information solely intended for the addressee. If you are not the intended addressee of this message, please contact the addresser immediately and delete this message including its attachments. The unauthorized dissemination, copying and change of this e-mail are strictly forbidden. The addresser shall not be liable for the content of such changed e-mails.
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:23 ` Michael Nazzareno Trimarchi
@ 2018-01-18  8:27   ` Simon Goldschmidt
  2018-01-18  8:43     ` Michael Nazzareno Trimarchi
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Goldschmidt @ 2018-01-18  8:27 UTC (permalink / raw)
  To: u-boot

On 18.01.2018 09:23, Michael Nazzareno Trimarchi wrote:
> Hi
>
> On Thu, Jan 18, 2018 at 9:15 AM, Simon Goldschmidt
> <sgoldschmidt@de.pepperl-fuchs.com> 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'.
>>
>> Signed-off-by: Simon Goldschmidt <sgoldschmidt@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;
> You should add a warming message

Hmm, I just copied what 'dm_spi_claim_bus' does some hundred lines above 
in the same file. Why should one code path warn when the other doesn't?

Simon

>
> Michael
>
>>          }
>>          ret = spi_set_speed_mode(bus, speed, mode);
>>          if (ret)
>> --
>> 2.11.0
<snip>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:27   ` Simon Goldschmidt
@ 2018-01-18  8:43     ` Michael Nazzareno Trimarchi
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Nazzareno Trimarchi @ 2018-01-18  8:43 UTC (permalink / raw)
  To: u-boot

Hi

On Thu, Jan 18, 2018 at 9:27 AM, Simon Goldschmidt
<sgoldschmidt@de.pepperl-fuchs.com> wrote:
> On 18.01.2018 09:23, Michael Nazzareno Trimarchi wrote:
>>
>> Hi
>>
>> On Thu, Jan 18, 2018 at 9:15 AM, Simon Goldschmidt
>> <sgoldschmidt@de.pepperl-fuchs.com> 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'.
>>>
>>> Signed-off-by: Simon Goldschmidt <sgoldschmidt@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;
>>
>> You should add a warming message
>
>
> Hmm, I just copied what 'dm_spi_claim_bus' does some hundred lines above in
> the same file. Why should one code path warn when the other doesn't?

I just check this page but if you have some missing definition in
device tree maybe make sense to
make it visible

Michael

>
> Simon
>
>>
>> Michael
>>
>>>          }
>>>          ret = spi_set_speed_mode(bus, speed, mode);
>>>          if (ret)
>>> --
>>> 2.11.0
>
> <snip>
>



-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:15 [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz Simon Goldschmidt
  2018-01-18  8:23 ` Michael Nazzareno Trimarchi
@ 2018-01-22  0:29 ` Simon Glass
  2018-01-22 13:06   ` Simon Goldschmidt
  2018-01-22  5:04 ` Vignesh R
  2018-01-22  6:01 ` Jagan Teki
  3 siblings, 1 reply; 10+ messages in thread
From: Simon Glass @ 2018-01-22  0:29 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On 18 January 2018 at 01:15, Simon Goldschmidt
<sgoldschmidt@de.pepperl-fuchs.com> 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'.
>
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
> ---
>
>  drivers/spi/spi-uclass.c | 2 ++
>  1 file changed, 2 insertions(+)
>

Another option is to have a sensible default when reading from the DT
fails. See spi_slave_ofdata_to_platdata() - you can add the default
there.

Would that work?

Regards,
Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:15 [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz Simon Goldschmidt
  2018-01-18  8:23 ` Michael Nazzareno Trimarchi
  2018-01-22  0:29 ` Simon Glass
@ 2018-01-22  5:04 ` Vignesh R
  2018-01-22 13:16   ` Simon Goldschmidt
  2018-01-22  6:01 ` Jagan Teki
  3 siblings, 1 reply; 10+ messages in thread
From: Vignesh R @ 2018-01-22  5:04 UTC (permalink / raw)
  To: u-boot



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.

> Signed-off-by: Simon Goldschmidt <sgoldschmidt@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)
> 

-- 
Regards
Vignesh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-18  8:15 [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz Simon Goldschmidt
                   ` (2 preceding siblings ...)
  2018-01-22  5:04 ` Vignesh R
@ 2018-01-22  6:01 ` Jagan Teki
  2018-01-22 13:21   ` Simon Goldschmidt
  3 siblings, 1 reply; 10+ messages in thread
From: Jagan Teki @ 2018-01-22  6:01 UTC (permalink / raw)
  To: u-boot

On Thu, Jan 18, 2018 at 1:45 PM, Simon Goldschmidt
<sgoldschmidt@de.pepperl-fuchs.com> 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'.

Better go-with default baudrate if speed == 0 this what usually does
in remaining drivers.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-22  0:29 ` Simon Glass
@ 2018-01-22 13:06   ` Simon Goldschmidt
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Goldschmidt @ 2018-01-22 13:06 UTC (permalink / raw)
  To: u-boot

On 22.01.2018 01:29, Simon Glass wrote:
> Hi Simon,
>
> On 18 January 2018 at 01:15, Simon Goldschmidt
> <sgoldschmidt@de.pepperl-fuchs.com> 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'.
>>
>> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
>> ---
>>
>>   drivers/spi/spi-uclass.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
> Another option is to have a sensible default when reading from the DT
> fails. See spi_slave_ofdata_to_platdata() - you can add the default
> there.
>
> Would that work?

This seems like a good idea, but I'm not sure it fixes my 
'divide-by-zero' bug because that bug also triggered if the  subnode of 
my spi controller was missing the compatible field for 'spi-flash'. I'd 
have to check that.

Regards,
Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-22  5:04 ` Vignesh R
@ 2018-01-22 13:16   ` Simon Goldschmidt
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Goldschmidt @ 2018-01-22 13:16 UTC (permalink / raw)
  To: u-boot

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@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)
>>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz
  2018-01-22  6:01 ` Jagan Teki
@ 2018-01-22 13:21   ` Simon Goldschmidt
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Goldschmidt @ 2018-01-22 13:21 UTC (permalink / raw)
  To: u-boot

On 22.01.2018 07:01, Jagan Teki wrote:
> On Thu, Jan 18, 2018 at 1:45 PM, Simon Goldschmidt
> <sgoldschmidt@de.pepperl-fuchs.com> 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'.
> Better go-with default baudrate if speed == 0 this what usually does
> in remaining drivers.

That's what I did. I set a default value of 100 kHz. The difference 
seems to me that the remaining drivers are host drivers whereas I was 
trying to fix an invalid declaration of a df chip.

Regards,
Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-01-22 13:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18  8:15 [U-Boot] [PATCH] dm: spi: prevent setting a speed of 0 Hz Simon Goldschmidt
2018-01-18  8:23 ` Michael Nazzareno Trimarchi
2018-01-18  8:27   ` Simon Goldschmidt
2018-01-18  8:43     ` Michael Nazzareno Trimarchi
2018-01-22  0:29 ` Simon Glass
2018-01-22 13:06   ` Simon Goldschmidt
2018-01-22  5:04 ` Vignesh R
2018-01-22 13:16   ` Simon Goldschmidt
2018-01-22  6:01 ` Jagan Teki
2018-01-22 13:21   ` Simon Goldschmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.