Skip to contentSkip to conversation

spi: prevent overriding established bus settings

PATCH New Marcin Wojtas 3 participants 7 messages Nov 21, 2019 – Jan 26, 2020 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

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.

---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/spi/spi-uclass.c +11 -9
index 76c4b53..fcbe532 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

+ Simon

czw., 21 lis 2019 o 05:39 Marcin Wojtas <[email protected]> napisaÅ‚(a):

Quoted 66 lines

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.

---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/spi/spi-uclass.c +11 -9
index 76c4b53..fcbe532 100644
@@ -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

#2 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

Hi,

Any comments on the patch?

Best regards,
Marcin

czw., 21 lis 2019 o 10:29 Marcin Wojtas <[email protected]> napisał(a):

Quoted 70 lines

+ Simon

czw., 21 lis 2019 o 05:39 Marcin Wojtas <[email protected]> napisał(a):

Quoted 66 lines

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.

---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/spi/spi-uclass.c +11 -9
index 76c4b53..fcbe532 100644
@@ -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

#3 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

In reply to Marcin Wojtas
Quoted 11 lines · Marcin Wojtas

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.

Quoted 7 lines

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

---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
#4 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

Hi Jagan,

sob., 28 gru 2019 o 03:27 Simon Glass <[email protected]> napisaÅ‚(a):

Quoted 16 lines · Marcin Wojtas
Quoted 14 lines

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.

Quoted 6 lines
Quoted 4 lines
---
 drivers/spi/spi-uclass.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

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

Best regards,
Marcin

#5 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

In reply to Marcin Wojtas
Quoted 11 lines · Marcin Wojtas

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.

Quoted 5 lines

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

---

Applied to u-boot-spi/master

#6 lore raw

PATCH 1/1 spi: prevent overriding established bus settings

niedz., 26 sty 2020 o 14:30 Jagan Teki <[email protected]> napisaÅ‚(a):

Quoted 13 lines · Marcin Wojtas
Quoted 11 lines

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.

Quoted 7 lines
Quoted 5 lines

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

---

Applied to u-boot-spi/master

Great, thanks!
Marcin