diff options
author | Patrice Chotard <patrice.chotard@foss.st.com> | 2022-03-30 09:33:13 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-05-23 09:33:10 -0400 |
commit | 61708bb0a24caad99b0e79de52077dafb59688d6 (patch) | |
tree | 92509d695141d0455f7fe329a870ad57e39a6a34 /drivers/spi/spi-uclass.c | |
parent | 827a232623e9b00e7d1b4b62b46e803d7168bbf5 (diff) |
spi: spi-uclass: Add new spi_get_bus_and_cs() implementation
Move legacy spi_get_bus_and_cs() code to _spi_get_bus_and_cs().
Add new spi_get_bus_and_cs() implementation which rely on DT
for speed and mode and don't need any drv_name nor dev_name
parameters. This will prepare the ground for next patch.
Update all callers to use _spi_get_bus_and_cs() to keep the
same behavior.
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Marek Behun <marek.behun@nic.cz>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Vignesh R <vigneshr@ti.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
Cc: Lukasz Majewski <lukma@denx.de>
Cc: Marek Vasut <marex@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Stefan Roese <sr@denx.de>
Cc: "Pali Rohár" <pali@kernel.org>
Cc: Konstantin Porotchkin <kostap@marvell.com>
Cc: Igal Liberman <igall@marvell.com>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Pratyush Yadav <p.yadav@ti.com>
Cc: Sean Anderson <seanga2@gmail.com>
Cc: Anji J <anji.jagarlmudi@nxp.com>
Cc: Biwen Li <biwen.li@nxp.com>
Cc: Priyanka Jain <priyanka.jain@nxp.com>
Cc: Chaitanya Sakinam <chaitanya.sakinam@nxp.com>
Diffstat (limited to 'drivers/spi/spi-uclass.c')
-rw-r--r-- | drivers/spi/spi-uclass.c | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index f8ec312d715..f2791c4b88e 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -340,9 +340,65 @@ int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, return ret; } -int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, - const char *drv_name, const char *dev_name, - struct udevice **busp, struct spi_slave **devp) +int spi_get_bus_and_cs(int busnum, int cs, struct udevice **busp, + struct spi_slave **devp) +{ + struct udevice *bus, *dev; + struct dm_spi_bus *bus_data; + struct spi_slave *slave; + int ret; + +#if CONFIG_IS_ENABLED(OF_PLATDATA) + ret = uclass_first_device_err(UCLASS_SPI, &bus); +#else + ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus); +#endif + if (ret) { + log_err("Invalid bus %d (err=%d)\n", busnum, ret); + return ret; + } + ret = spi_find_chip_select(bus, cs, &dev); + if (ret) { + dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); + return ret; + } + + if (!device_active(dev)) { + struct spi_slave *slave; + + ret = device_probe(dev); + if (ret) + goto err; + slave = dev_get_parent_priv(dev); + slave->dev = dev; + } + + slave = dev_get_parent_priv(dev); + bus_data = dev_get_uclass_priv(bus); + + /* + * In case the operation speed is not yet established by + * dm_spi_claim_bus() ensure the bus is configured properly. + */ + if (!bus_data->speed) { + ret = spi_claim_bus(slave); + if (ret) + goto err; + } + *busp = bus; + *devp = slave; + + return 0; + +err: + log_debug("%s: Error path, device '%s'\n", __func__, dev->name); + + return ret; +} + +int _spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, + const char *drv_name, const char *dev_name, + struct udevice **busp, struct spi_slave **devp) { struct udevice *bus, *dev; struct dm_spi_slave_plat *plat; @@ -453,8 +509,8 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, struct udevice *dev; int ret; - ret = spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, - &slave); + ret = _spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, + &slave); if (ret) return NULL; |