aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Wojtas2019-11-21 05:38:47 +0100
committerJagan Teki2020-01-27 22:27:22 +0530
commitf7dd5370986087af9b9cfa601f34b344ec910b87 (patch)
treef53543a131106d6b7f096342c456dceca70f022c
parent6954756a1567bd4dc36081651c266dbcf9ad4ef5 (diff)
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. Signed-off-by: Marcin Wojtas <mw@semihalf.com> Reviewed-by: Simon Glass <sjg@chromium.org> Acked-by: Jagan Teki <jagan@amarulasolutions.com>
-rw-r--r--drivers/spi/spi-uclass.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 5ced8905f80..9208b16db4f 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -323,6 +323,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;
@@ -378,19 +379,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;