From a3262e08035631af07b02141e7e52a4902c3a632 Mon Sep 17 00:00:00 2001 From: Jie Zhang Date: Thu, 7 May 2026 23:25:37 -0400 Subject: [PATCH] spi: uclass: validate chip select when probe Move chip select validation from spi_find_chip_select() into spi_child_pre_probe(), where the bus is guaranteed to be active and driver private data is initialized. This avoids false CS rejections when spi_find_chip_select() is called on an unprobed bus, and simplifies the lookup function. Signed-off-by: Jie Zhang --- drivers/spi/spi-uclass.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index d6049753740b..a7dac8c9863d 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -203,6 +203,17 @@ static int spi_child_pre_probe(struct udevice *dev) { struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); struct spi_slave *slave = dev_get_parent_priv(dev); + struct udevice *bus = dev_get_parent(dev); + struct dm_spi_ops *ops = spi_get_ops(bus); + int ret; + + if (ops->cs_info) { + ret = ops->cs_info(bus, plat->cs[0], NULL); + if (ret) { + dev_err(dev, "Invalid chip select %u\n", plat->cs[0]); + return ret; + } + } /* * This is needed because we pass struct spi_slave around the place @@ -229,32 +240,7 @@ int spi_chip_select(struct udevice *dev) int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp) { - struct dm_spi_ops *ops; - struct spi_cs_info info; struct udevice *dev; - int ret; - - /* - * Ask the driver. For the moment we don't have CS info. - * When we do we could provide the driver with a helper function - * to figure out what chip selects are valid, or just handle the - * request. - */ - ops = spi_get_ops(bus); - if (ops->cs_info) { - ret = ops->cs_info(bus, cs, &info); - } else { - /* - * We could assume there is at least one valid chip select. - * The driver didn't care enough to tell us. - */ - ret = 0; - } - - if (ret) { - dev_err(bus, "Invalid cs %d (err=%d)\n", cs, ret); - return ret; - } for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) {