From: Ayush Singh <ayush@beagleboard.org>
To: Mark Brown <broonie@kernel.org>,
herve.codina@bootlin.com, luca.ceresoli@bootlin.com,
conor+dt@kernel.org, Jason Kridner <jkridner@beagleboard.org>,
Deepak Khatri <lorforlinux@beagleboard.org>,
Dhruva Gole <d-gole@ti.com>,
Robert Nelson <robertcnelson@beagleboard.org>,
Andrew Davis <afd@ti.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Ayush Singh <ayush@beagleboard.org>
Subject: [PATCH 1/4] spi: Follow spi-parent when retrieving a controller from node
Date: Tue, 29 Jul 2025 15:21:00 +0530 [thread overview]
Message-ID: <20250729-spi-bus-extension-v1-1-b20c73f2161a@beagleboard.org> (raw)
In-Reply-To: <20250729-spi-bus-extension-v1-0-b20c73f2161a@beagleboard.org>
spi bus extension were introduced to decouple spi busses when they are
wired to connectors. Combined with devicetree overlays, they introduce
an additional level of indirection, which is needed to decouple the
overlay (describing the hardware available on addon baord) and the base
tree (describing resources provided to the addon board).
For instance, the following devicetree fragment, available once
overlays are applied, is legit:
```
spi1: spi@abcd0000 {
compatible = "xyz,spi-ctrl";
spi-bus-extension@0 {
reg = <0>;
spi-bus = <&spi-ctrl>;
};
...
};
connector {
spi-ctrl {
spi-parent = <&spi1>;
#address-cells = <1>;
#size-cells = <0>;
spi-bus-extension@0 {
reg = <0>;
spi-bus = <&spi-other-connector>;
};
device@1 {
compatible = "xyz,foo";
reg = <1>;
};
};
devices {
other-connector {
spi-at-other-connector {
spi-parent = <&spi-ctrl>;
#address-cells = <1>;
#size-cells = <0>;
device@2 {
compatible = "xyz,bar";
reg = <2>;
};
};
};
};
};
```
Current implementation of of_find_spi_controller_by_node() supposes that
the node parameter correspond to the adapter.
This assumption is no more valid with spi bus extensions. Indeed, the
node parameter can reference an spi bus extension node and not the
related adapter.
In the example, spi-ctrl and spi-at-other-connector nodes are chained
bus extensions and those node can be passed to
of_find_spi_controller_by_node() in order to get the related adapter (i.e
the adapter handling the bus and its extensions: spi@abcd0000).
Extend of_find_spi_controller_by_node() to perform the walking from the
given node through spi-parent references up to the adapter.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
drivers/spi/spi.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a388f372b27a7f29d18f1dd5e862902811016fc6..0030e0be0d9b2f9e2b0c4a1d806b42bdb4ecb5d2 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4776,11 +4776,18 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node)
/* The spi controllers are not using spi_bus, so we find it with another way */
static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
{
+ struct device_node *ctlr_node = node;
struct device *dev;
- dev = class_find_device_by_of_node(&spi_controller_class, node);
+ while (of_property_present(ctlr_node, "spi-parent")) {
+ ctlr_node = of_parse_phandle(ctlr_node, "spi-parent", 0);
+ if (!ctlr_node)
+ return NULL;
+ }
+
+ dev = class_find_device_by_of_node(&spi_controller_class, ctlr_node);
if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
- dev = class_find_device_by_of_node(&spi_target_class, node);
+ dev = class_find_device_by_of_node(&spi_target_class, ctlr_node);
if (!dev)
return NULL;
--
2.50.1
next prev parent reply other threads:[~2025-07-29 9:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 9:50 [PATCH 0/4] spi: Introduce spi bus extensions Ayush Singh
2025-07-29 9:51 ` Ayush Singh [this message]
2025-07-29 9:51 ` [PATCH 2/4] spi: Move children registration in a dedicated function Ayush Singh
2025-07-29 9:51 ` [PATCH 3/4] spi: Handle spi bus extension Ayush Singh
2025-07-29 12:46 ` Krzysztof Kozlowski
2025-07-29 12:52 ` Ayush Singh
2025-07-29 13:09 ` Krzysztof Kozlowski
2025-07-29 9:51 ` [PATCH 4/4] devicetree: bindings: spi: Introduce SPI bus extensions Ayush Singh
2025-07-29 12:52 ` Krzysztof Kozlowski
2025-07-30 15:45 ` Luca Ceresoli
2025-07-30 18:30 ` Andrew Davis
2025-07-29 13:12 ` Rob Herring (Arm)
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=20250729-spi-bus-extension-v1-1-b20c73f2161a@beagleboard.org \
--to=ayush@beagleboard.org \
--cc=afd@ti.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=d-gole@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=herve.codina@bootlin.com \
--cc=jkridner@beagleboard.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=lorforlinux@beagleboard.org \
--cc=luca.ceresoli@bootlin.com \
--cc=robertcnelson@beagleboard.org \
--cc=robh@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).