All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] spi: prevent overriding established bus settings
@ 2019-11-21  4:38 Marcin Wojtas
  2019-11-21  9:29 ` Marcin Wojtas
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Marcin Wojtas @ 2019-11-21  4:38 UTC (permalink / raw)
  To: u-boot

The SPI stack relies on a proper bus speed/mode configuration
by calling dm_spi_claim_bus(). However the hitherto code
allowed to accidentally override those settings in
the spi_get_bus_and_cs() routine.

The initially established speed could be discarded by using
the slave platdata, which turned out to be an issue on
the platforms whose slave maximum supported frequency
is not on par with the maximum frequency of the bus controller.

This patch fixes above issue by configuring the bus from
spi_get_bus_and_cs() only in case it was not done before.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 76c4b53..fcbe532 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -296,6 +296,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 {
 	struct udevice *bus, *dev;
 	struct dm_spi_slave_platdata *plat;
+	struct spi_slave *slave;
 	bool created = false;
 	int ret;
 
@@ -351,19 +352,20 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
 		slave->dev = dev;
 	}
 
-	plat = dev_get_parent_platdata(dev);
+	slave = dev_get_parent_priv(dev);
 
-	/* get speed and mode from platdata when available */
-	if (plat->max_hz) {
-		speed = plat->max_hz;
-		mode = plat->mode;
+	/*
+	 * In case the operation speed is not yet established by
+	 * dm_spi_claim_bus() ensure the bus is configured properly.
+	 */
+	if (!slave->speed) {
+		ret = spi_claim_bus(slave);
+		if (ret)
+			goto err;
 	}
-	ret = spi_set_speed_mode(bus, speed, mode);
-	if (ret)
-		goto err;
 
 	*busp = bus;
-	*devp = dev_get_parent_priv(dev);
+	*devp = slave;
 	debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp);
 
 	return 0;
-- 
2.7.4

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

* [U-Boot] [PATCH] spi: prevent overriding established bus settings
  2019-11-21  4:38 [U-Boot] [PATCH] spi: prevent overriding established bus settings Marcin Wojtas
@ 2019-11-21  9:29 ` Marcin Wojtas
  2019-12-11  7:18   ` Marcin Wojtas
  2019-12-28  2:26 ` [U-Boot] " Simon Glass
  2020-01-26 13:30 ` Jagan Teki
  2 siblings, 1 reply; 7+ messages in thread
From: Marcin Wojtas @ 2019-11-21  9:29 UTC (permalink / raw)
  To: u-boot

+ Simon

czw., 21 lis 2019 o 05:39 Marcin Wojtas <mw@semihalf.com> napisał(a):

> The SPI stack relies on a proper bus speed/mode configuration
> by calling dm_spi_claim_bus(). However the hitherto code
> allowed to accidentally override those settings in
> the spi_get_bus_and_cs() routine.
>
> The initially established speed could be discarded by using
> the slave platdata, which turned out to be an issue on
> the platforms whose slave maximum supported frequency
> is not on par with the maximum frequency of the bus controller.
>
> This patch fixes above issue by configuring the bus from
> spi_get_bus_and_cs() only in case it was not done before.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  drivers/spi/spi-uclass.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index 76c4b53..fcbe532 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -296,6 +296,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed,
> int mode,
>  {
>         struct udevice *bus, *dev;
>         struct dm_spi_slave_platdata *plat;
> +       struct spi_slave *slave;
>         bool created = false;
>         int ret;
>
> @@ -351,19 +352,20 @@ int spi_get_bus_and_cs(int busnum, int cs, int
> speed, int mode,
>                 slave->dev = dev;
>         }
>
> -       plat = dev_get_parent_platdata(dev);
> +       slave = dev_get_parent_priv(dev);
>
> -       /* get speed and mode from platdata when available */
> -       if (plat->max_hz) {
> -               speed = plat->max_hz;
> -               mode = plat->mode;
> +       /*
> +        * In case the operation speed is not yet established by
> +        * dm_spi_claim_bus() ensure the bus is configured properly.
> +        */
> +       if (!slave->speed) {
> +               ret = spi_claim_bus(slave);
> +               if (ret)
> +                       goto err;
>         }
> -       ret = spi_set_speed_mode(bus, speed, mode);
> -       if (ret)
> -               goto err;
>
>         *busp = bus;
> -       *devp = dev_get_parent_priv(dev);
> +       *devp = slave;
>         debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp);
>
>         return 0;
> --
> 2.7.4
>
>

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

* [PATCH] spi: prevent overriding established bus settings
  2019-11-21  9:29 ` Marcin Wojtas
@ 2019-12-11  7:18   ` Marcin Wojtas
  0 siblings, 0 replies; 7+ messages in thread
From: Marcin Wojtas @ 2019-12-11  7:18 UTC (permalink / raw)
  To: u-boot

Hi,

Any comments on the patch?

Best regards,
Marcin

czw., 21 lis 2019 o 10:29 Marcin Wojtas <mw@semihalf.com> napisał(a):

> + Simon
>
> czw., 21 lis 2019 o 05:39 Marcin Wojtas <mw@semihalf.com> napisał(a):
>
>> The SPI stack relies on a proper bus speed/mode configuration
>> by calling dm_spi_claim_bus(). However the hitherto code
>> allowed to accidentally override those settings in
>> the spi_get_bus_and_cs() routine.
>>
>> The initially established speed could be discarded by using
>> the slave platdata, which turned out to be an issue on
>> the platforms whose slave maximum supported frequency
>> is not on par with the maximum frequency of the bus controller.
>>
>> This patch fixes above issue by configuring the bus from
>> spi_get_bus_and_cs() only in case it was not done before.
>>
>> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
>> ---
>>  drivers/spi/spi-uclass.c | 20 +++++++++++---------
>>  1 file changed, 11 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
>> index 76c4b53..fcbe532 100644
>> --- a/drivers/spi/spi-uclass.c
>> +++ b/drivers/spi/spi-uclass.c
>> @@ -296,6 +296,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed,
>> int mode,
>>  {
>>         struct udevice *bus, *dev;
>>         struct dm_spi_slave_platdata *plat;
>> +       struct spi_slave *slave;
>>         bool created = false;
>>         int ret;
>>
>> @@ -351,19 +352,20 @@ int spi_get_bus_and_cs(int busnum, int cs, int
>> speed, int mode,
>>                 slave->dev = dev;
>>         }
>>
>> -       plat = dev_get_parent_platdata(dev);
>> +       slave = dev_get_parent_priv(dev);
>>
>> -       /* get speed and mode from platdata when available */
>> -       if (plat->max_hz) {
>> -               speed = plat->max_hz;
>> -               mode = plat->mode;
>> +       /*
>> +        * In case the operation speed is not yet established by
>> +        * dm_spi_claim_bus() ensure the bus is configured properly.
>> +        */
>> +       if (!slave->speed) {
>> +               ret = spi_claim_bus(slave);
>> +               if (ret)
>> +                       goto err;
>>         }
>> -       ret = spi_set_speed_mode(bus, speed, mode);
>> -       if (ret)
>> -               goto err;
>>
>>         *busp = bus;
>> -       *devp = dev_get_parent_priv(dev);
>> +       *devp = slave;
>>         debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp);
>>
>>         return 0;
>> --
>> 2.7.4
>>
>>

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

* [U-Boot] [PATCH] spi: prevent overriding established bus settings
  2019-11-21  4:38 [U-Boot] [PATCH] spi: prevent overriding established bus settings Marcin Wojtas
  2019-11-21  9:29 ` Marcin Wojtas
@ 2019-12-28  2:26 ` Simon Glass
  2020-01-16  9:55   ` Marcin Wojtas
  2020-01-26 13:30 ` Jagan Teki
  2 siblings, 1 reply; 7+ messages in thread
From: Simon Glass @ 2019-12-28  2:26 UTC (permalink / raw)
  To: u-boot

On Thu, 21 Nov 2019 at 04:45, Marcin Wojtas <mw@semihalf.com> wrote:
>
> The SPI stack relies on a proper bus speed/mode configuration
> by calling dm_spi_claim_bus(). However the hitherto code
> allowed to accidentally override those settings in
> the spi_get_bus_and_cs() routine.
>
> The initially established speed could be discarded by using
> the slave platdata, which turned out to be an issue on
> the platforms whose slave maximum supported frequency
> is not on par with the maximum frequency of the bus controller.
>
> This patch fixes above issue by configuring the bus from
> spi_get_bus_and_cs() only in case it was not done before.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  drivers/spi/spi-uclass.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH] spi: prevent overriding established bus settings
  2019-12-28  2:26 ` [U-Boot] " Simon Glass
@ 2020-01-16  9:55   ` Marcin Wojtas
  0 siblings, 0 replies; 7+ messages in thread
From: Marcin Wojtas @ 2020-01-16  9:55 UTC (permalink / raw)
  To: u-boot

Hi Jagan,

sob., 28 gru 2019 o 03:27 Simon Glass <sjg@chromium.org> napisał(a):
>
> On Thu, 21 Nov 2019 at 04:45, Marcin Wojtas <mw@semihalf.com> wrote:
> >
> > The SPI stack relies on a proper bus speed/mode configuration
> > by calling dm_spi_claim_bus(). However the hitherto code
> > allowed to accidentally override those settings in
> > the spi_get_bus_and_cs() routine.
> >
> > The initially established speed could be discarded by using
> > the slave platdata, which turned out to be an issue on
> > the platforms whose slave maximum supported frequency
> > is not on par with the maximum frequency of the bus controller.
> >
> > This patch fixes above issue by configuring the bus from
> > spi_get_bus_and_cs() only in case it was not done before.
> >
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  drivers/spi/spi-uclass.c | 20 +++++++++++---------
> >  1 file changed, 11 insertions(+), 9 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Is there a chance to merge the patch, or do you have any objections?

Best regards,
Marcin

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

* [PATCH] spi: prevent overriding established bus settings
  2019-11-21  4:38 [U-Boot] [PATCH] spi: prevent overriding established bus settings Marcin Wojtas
  2019-11-21  9:29 ` Marcin Wojtas
  2019-12-28  2:26 ` [U-Boot] " Simon Glass
@ 2020-01-26 13:30 ` Jagan Teki
  2020-01-26 13:39   ` Marcin Wojtas
  2 siblings, 1 reply; 7+ messages in thread
From: Jagan Teki @ 2020-01-26 13:30 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 21, 2019 at 10:09 AM Marcin Wojtas <mw@semihalf.com> wrote:
>
> The SPI stack relies on a proper bus speed/mode configuration
> by calling dm_spi_claim_bus(). However the hitherto code
> allowed to accidentally override those settings in
> the spi_get_bus_and_cs() routine.
>
> The initially established speed could be discarded by using
> the slave platdata, which turned out to be an issue on
> the platforms whose slave maximum supported frequency
> is not on par with the maximum frequency of the bus controller.
>
> This patch fixes above issue by configuring the bus from
> spi_get_bus_and_cs() only in case it was not done before.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---

Applied to u-boot-spi/master

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

* [PATCH] spi: prevent overriding established bus settings
  2020-01-26 13:30 ` Jagan Teki
@ 2020-01-26 13:39   ` Marcin Wojtas
  0 siblings, 0 replies; 7+ messages in thread
From: Marcin Wojtas @ 2020-01-26 13:39 UTC (permalink / raw)
  To: u-boot

niedz., 26 sty 2020 o 14:30 Jagan Teki <jagan@amarulasolutions.com> napisał(a):
>
> On Thu, Nov 21, 2019 at 10:09 AM Marcin Wojtas <mw@semihalf.com> wrote:
> >
> > The SPI stack relies on a proper bus speed/mode configuration
> > by calling dm_spi_claim_bus(). However the hitherto code
> > allowed to accidentally override those settings in
> > the spi_get_bus_and_cs() routine.
> >
> > The initially established speed could be discarded by using
> > the slave platdata, which turned out to be an issue on
> > the platforms whose slave maximum supported frequency
> > is not on par with the maximum frequency of the bus controller.
> >
> > This patch fixes above issue by configuring the bus from
> > spi_get_bus_and_cs() only in case it was not done before.
> >
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
>
> Applied to u-boot-spi/master

Great, thanks!
Marcin

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

end of thread, other threads:[~2020-01-26 13:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21  4:38 [U-Boot] [PATCH] spi: prevent overriding established bus settings Marcin Wojtas
2019-11-21  9:29 ` Marcin Wojtas
2019-12-11  7:18   ` Marcin Wojtas
2019-12-28  2:26 ` [U-Boot] " Simon Glass
2020-01-16  9:55   ` Marcin Wojtas
2020-01-26 13:30 ` Jagan Teki
2020-01-26 13:39   ` Marcin Wojtas

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.