summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2023-03-07 15:17:16 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-03-10 10:28:37 +0100
commit2366fa3a808e296de826feb8b890aff5652114db (patch)
tree90f9d5b23c5e9e73cf8b79e954db2423332602e6 /drivers/spi/spi.c
parent0aa0204cf3b2e63f4c546f3bfd02835d70e99007 (diff)
downloadbarebox-2366fa3a808e296de826feb8b890aff5652114db.tar.gz
barebox-2366fa3a808e296de826feb8b890aff5652114db.tar.xz
spi: implement rescan
Implement rescan to register and probe newly added devices via device tree overlays. While this is easy to do at SPI core level this is not the whole truth. Many SPI controllers do not use their native chipselects for the SPI devices, but GPIOs instead. These currently won't be rescanned when new devices are added, so the chipselects for the new devices must be be present in the base device tree already. You have been warned. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3684647f6e..584d4ab777 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -29,6 +29,7 @@ struct boardinfo {
};
static LIST_HEAD(board_list);
+static LIST_HEAD(spi_controller_list);
/**
* spi_new_device - instantiate one new SPI device
@@ -120,6 +121,12 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
for_each_available_child_of_node(node, n) {
struct spi_board_info chip = {};
+ if (n->dev) {
+ dev_dbg(ctrl->dev, "skipping already registered %s\n",
+ dev_name(n->dev));
+ continue;
+ }
+
chip.name = xstrdup(n->name);
chip.bus_num = ctrl->bus_num;
/* Mode (clock phase/polarity/etc.) */
@@ -142,6 +149,17 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
}
}
+static void spi_controller_rescan(struct device *dev)
+{
+ struct spi_controller *ctrl;
+
+ list_for_each_entry(ctrl, &spi_controller_list, list) {
+ if (ctrl->dev != dev)
+ continue;
+ spi_of_register_slaves(ctrl);
+ }
+}
+
/**
* spi_register_board_info - register SPI devices for a given board
* @info: array of chip descriptors
@@ -196,8 +214,6 @@ static void scan_boardinfo(struct spi_controller *ctrl)
}
}
-static LIST_HEAD(spi_controller_list);
-
static int spi_controller_check_ops(struct spi_controller *ctlr)
{
/*
@@ -274,6 +290,9 @@ int spi_register_controller(struct spi_controller *ctrl)
scan_boardinfo(ctrl);
status = 0;
+ if (!ctrl->dev->rescan)
+ ctrl->dev->rescan = spi_controller_rescan;
+
return status;
}
EXPORT_SYMBOL(spi_register_controller);