From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>,
Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 5/6] spi: factor out spi_of_register_slave()
Date: Thu, 19 Nov 2026 19:58:15 +0100 [thread overview]
Message-ID: <20261119185828.92337-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261119185828.92337-1-a.fatoum@barebox.org>
Let's move the registration of a single device node into its own
function. A follow-up commit will use it to register only the node
requested by the rescan hook.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/spi/spi.c | 77 +++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b1806a2ea445..850ea2c7b62f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -150,10 +150,48 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,
}
}
+static void spi_of_register_slave(struct spi_controller *ctrl,
+ struct device_node *n)
+{
+ struct spi_board_info chip = {};
+ struct property *reg;
+
+ if (n->dev) {
+ dev_dbg(ctrl->dev, "skipping already registered %s\n",
+ dev_name(n->dev));
+ return;
+ }
+
+ chip.name = xstrdup(n->name);
+ chip.bus_num = ctrl->bus_num;
+ /* Mode (clock phase/polarity/etc.) */
+ if (of_property_read_bool(n, "spi-cpha"))
+ chip.mode |= SPI_CPHA;
+ if (of_property_read_bool(n, "spi-cpol"))
+ chip.mode |= SPI_CPOL;
+ if (of_property_read_bool(n, "spi-cs-high"))
+ chip.mode |= SPI_CS_HIGH;
+ if (of_property_read_bool(n, "spi-3wire"))
+ chip.mode |= SPI_3WIRE;
+ of_property_read_u32(n, "spi-max-frequency",
+ &chip.max_speed_hz);
+
+ /* Device CS delays */
+ of_spi_parse_dt_cs_delay(n, &chip.cs_setup, "spi-cs-setup-delay-ns");
+ of_spi_parse_dt_cs_delay(n, &chip.cs_hold, "spi-cs-hold-delay-ns");
+ of_spi_parse_dt_cs_delay(n, &chip.cs_inactive, "spi-cs-inactive-delay-ns");
+
+ reg = of_find_property(n, "reg", NULL);
+ if (!reg)
+ return;
+ chip.chip_select = of_read_number(reg->value, 1);
+ chip.device_node = n;
+ spi_new_device(ctrl, &chip);
+}
+
static void spi_of_register_slaves(struct spi_controller *ctrl)
{
struct device_node *n;
- struct property *reg;
struct device_node *node = ctrl->dev->of_node;
if (!IS_ENABLED(CONFIG_OFDEVICE))
@@ -162,41 +200,8 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
if (!node)
return;
- 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.) */
- if (of_property_read_bool(n, "spi-cpha"))
- chip.mode |= SPI_CPHA;
- if (of_property_read_bool(n, "spi-cpol"))
- chip.mode |= SPI_CPOL;
- if (of_property_read_bool(n, "spi-cs-high"))
- chip.mode |= SPI_CS_HIGH;
- if (of_property_read_bool(n, "spi-3wire"))
- chip.mode |= SPI_3WIRE;
- of_property_read_u32(n, "spi-max-frequency",
- &chip.max_speed_hz);
-
- /* Device CS delays */
- of_spi_parse_dt_cs_delay(n, &chip.cs_setup, "spi-cs-setup-delay-ns");
- of_spi_parse_dt_cs_delay(n, &chip.cs_hold, "spi-cs-hold-delay-ns");
- of_spi_parse_dt_cs_delay(n, &chip.cs_inactive, "spi-cs-inactive-delay-ns");
-
- reg = of_find_property(n, "reg", NULL);
- if (!reg)
- continue;
- chip.chip_select = of_read_number(reg->value, 1);
- chip.device_node = n;
- spi_new_device(ctrl, &chip);
- }
+ for_each_available_child_of_node(node, n)
+ spi_of_register_slave(ctrl, n);
}
static void spi_controller_rescan(struct device *dev, struct device_node *np)
--
2.47.3
next prev parent reply other threads:[~2026-11-19 19:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:58 [PATCH 1/6] spi: fix NULL pointer dereference for board info devices Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 2/6] driver: pass the requested node to the rescan hook Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 3/6] i2c: factor out of_i2c_register_device() Ahmad Fatoum
2026-11-19 18:58 ` [PATCH 4/6] i2c: allow creating siblings on demand while populating the bus Ahmad Fatoum
2026-11-20 11:04 ` Alexander Shiyan
2026-11-19 18:58 ` Ahmad Fatoum [this message]
2026-11-19 18:58 ` [PATCH 6/6] spi: " Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119185828.92337-5-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=eagle.alexander923@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox