From: Ayush Singh <ayushdevel1325@gmail.com>
To: linux-kernel@vger.kernel.org (open list)
Cc: Ayush Singh <ayushdevel1325@gmail.com>,
jkridner@beagleboard.org, robertcnelson@beagleboard.org,
lorforlinux@beagleboard.org, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>, Nishanth Menon <nm@ti.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
Tero Kristo <kristo@kernel.org>,
Derek Kiernan <derek.kiernan@amd.com>,
Dragan Cvetic <dragan.cvetic@amd.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Vaishnav M A <vaishnav.a@ti.com>, Mark Brown <broonie@kernel.org>,
Johan Hovold <johan@kernel.org>, Alex Elder <elder@kernel.org>,
devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND
FLATTENED DEVICE TREE BINDINGS),
linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS
INSTRUMENTS K3 ARCHITECTURE),
linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM),
greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM)
Subject: [PATCH v4 2/5] spi: Make of_find_spi_controller_by_node() available
Date: Mon, 18 Mar 2024 01:07:10 +0530 [thread overview]
Message-ID: <20240317193714.403132-3-ayushdevel1325@gmail.com> (raw)
In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com>
DONOTMERGE
This externalizes and exports the symbol
of_find_spi_controller_by_node() from the SPI core akin to how
of_find_i2c_adapter_by_node() is already available. As we will
need this also for non-dynamic OF setups, we move it under a
CONFIG_OF check.
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
drivers/spi/spi.c | 206 ++++++++++++++++++++--------------------
include/linux/spi/spi.h | 4 +
2 files changed, 108 insertions(+), 102 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ba4d3fde2054..9ec507d92f80 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2320,6 +2320,93 @@ void spi_flush_queue(struct spi_controller *ctlr)
/*-------------------------------------------------------------------------*/
+static void spi_controller_release(struct device *dev)
+{
+ struct spi_controller *ctlr;
+
+ ctlr = container_of(dev, struct spi_controller, dev);
+ kfree(ctlr);
+}
+
+static struct class spi_master_class = {
+ .name = "spi_master",
+ .dev_release = spi_controller_release,
+ .dev_groups = spi_master_groups,
+};
+
+static ssize_t slave_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct spi_controller *ctlr = container_of(dev, struct spi_controller,
+ dev);
+ struct device *child;
+
+ child = device_find_any_child(&ctlr->dev);
+ return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
+}
+
+static ssize_t slave_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct spi_controller *ctlr = container_of(dev, struct spi_controller,
+ dev);
+ struct spi_device *spi;
+ struct device *child;
+ char name[32];
+ int rc;
+
+ rc = sscanf(buf, "%31s", name);
+ if (rc != 1 || !name[0])
+ return -EINVAL;
+
+ child = device_find_any_child(&ctlr->dev);
+ if (child) {
+ /* Remove registered slave */
+ device_unregister(child);
+ put_device(child);
+ }
+
+ if (strcmp(name, "(null)")) {
+ /* Register new slave */
+ spi = spi_alloc_device(ctlr);
+ if (!spi)
+ return -ENOMEM;
+
+ strscpy(spi->modalias, name, sizeof(spi->modalias));
+
+ rc = spi_add_device(spi);
+ if (rc) {
+ spi_dev_put(spi);
+ return rc;
+ }
+ }
+
+ return count;
+}
+
+static DEVICE_ATTR_RW(slave);
+
+static struct attribute *spi_slave_attrs[] = {
+ &dev_attr_slave.attr,
+ NULL,
+};
+
+static const struct attribute_group spi_slave_group = {
+ .attrs = spi_slave_attrs,
+};
+
+static const struct attribute_group *spi_slave_groups[] = {
+ &spi_controller_statistics_group,
+ &spi_slave_group,
+ NULL,
+};
+
+static struct class spi_slave_class = {
+ .name = "spi_slave",
+ .dev_release = spi_controller_release,
+ .dev_groups = spi_slave_groups,
+};
+
#if defined(CONFIG_OF)
static void of_spi_parse_dt_cs_delay(struct device_node *nc,
struct spi_delay *delay, const char *prop)
@@ -2543,6 +2630,23 @@ static void of_register_spi_devices(struct spi_controller *ctlr)
}
}
}
+
+/* The spi controllers are not using spi_bus, so we find it with another way */
+struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
+{
+ struct device *dev;
+
+ dev = class_find_device_by_of_node(&spi_master_class, node);
+ if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
+ dev = class_find_device_by_of_node(&spi_slave_class, node);
+ if (!dev)
+ return NULL;
+
+ /* Reference got in class_find_device */
+ return container_of(dev, struct spi_controller, dev);
+}
+EXPORT_SYMBOL_GPL(of_find_spi_controller_by_node);
+
#else
static void of_register_spi_devices(struct spi_controller *ctlr) { }
#endif
@@ -2942,20 +3046,6 @@ static void acpi_register_spi_devices(struct spi_controller *ctlr)
static inline void acpi_register_spi_devices(struct spi_controller *ctlr) {}
#endif /* CONFIG_ACPI */
-static void spi_controller_release(struct device *dev)
-{
- struct spi_controller *ctlr;
-
- ctlr = container_of(dev, struct spi_controller, dev);
- kfree(ctlr);
-}
-
-static struct class spi_master_class = {
- .name = "spi_master",
- .dev_release = spi_controller_release,
- .dev_groups = spi_master_groups,
-};
-
#ifdef CONFIG_SPI_SLAVE
/**
* spi_slave_abort - abort the ongoing transfer request on an SPI slave
@@ -2983,79 +3073,6 @@ int spi_target_abort(struct spi_device *spi)
return -ENOTSUPP;
}
EXPORT_SYMBOL_GPL(spi_target_abort);
-
-static ssize_t slave_show(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- struct spi_controller *ctlr = container_of(dev, struct spi_controller,
- dev);
- struct device *child;
-
- child = device_find_any_child(&ctlr->dev);
- return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
-}
-
-static ssize_t slave_store(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct spi_controller *ctlr = container_of(dev, struct spi_controller,
- dev);
- struct spi_device *spi;
- struct device *child;
- char name[32];
- int rc;
-
- rc = sscanf(buf, "%31s", name);
- if (rc != 1 || !name[0])
- return -EINVAL;
-
- child = device_find_any_child(&ctlr->dev);
- if (child) {
- /* Remove registered slave */
- device_unregister(child);
- put_device(child);
- }
-
- if (strcmp(name, "(null)")) {
- /* Register new slave */
- spi = spi_alloc_device(ctlr);
- if (!spi)
- return -ENOMEM;
-
- strscpy(spi->modalias, name, sizeof(spi->modalias));
-
- rc = spi_add_device(spi);
- if (rc) {
- spi_dev_put(spi);
- return rc;
- }
- }
-
- return count;
-}
-
-static DEVICE_ATTR_RW(slave);
-
-static struct attribute *spi_slave_attrs[] = {
- &dev_attr_slave.attr,
- NULL,
-};
-
-static const struct attribute_group spi_slave_group = {
- .attrs = spi_slave_attrs,
-};
-
-static const struct attribute_group *spi_slave_groups[] = {
- &spi_controller_statistics_group,
- &spi_slave_group,
- NULL,
-};
-
-static struct class spi_slave_class = {
- .name = "spi_slave",
- .dev_release = spi_controller_release,
- .dev_groups = spi_slave_groups,
-};
#else
extern struct class spi_slave_class; /* dummy */
#endif
@@ -4749,21 +4766,6 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node)
return dev ? to_spi_device(dev) : NULL;
}
-/* 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 *dev;
-
- dev = class_find_device_by_of_node(&spi_master_class, node);
- if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
- dev = class_find_device_by_of_node(&spi_slave_class, node);
- if (!dev)
- return NULL;
-
- /* Reference got in class_find_device */
- return container_of(dev, struct spi_controller, dev);
-}
-
static int of_spi_notify(struct notifier_block *nb, unsigned long action,
void *arg)
{
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index e400d454b3f0..f6fb7bad9a90 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1684,4 +1684,8 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)
return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers);
}
+#if IS_ENABLED(CONFIG_OF)
+struct spi_controller *of_find_spi_controller_by_node(struct device_node *node);
+#endif
+
#endif /* __LINUX_SPI_H */
--
2.44.0
next prev parent reply other threads:[~2024-03-17 19:38 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-17 19:37 [PATCH v4 0/5] misc: Add mikroBUS driver Ayush Singh
2024-03-17 19:37 ` [PATCH v4 1/5] dt-bindings: misc: Add mikrobus-connector Ayush Singh
2024-03-18 12:22 ` Michael Walle
2024-03-18 17:20 ` Ayush Singh
2024-03-19 5:58 ` Krzysztof Kozlowski
2024-03-19 7:36 ` Ayush Singh
2024-03-19 9:38 ` Michael Walle
2024-03-19 11:36 ` Ayush Singh
2024-03-19 12:08 ` Michael Walle
2024-03-19 13:03 ` Ayush Singh
2024-03-19 14:21 ` Michael Walle
2024-03-19 17:19 ` Vaishnav Achath
2024-03-19 17:35 ` Ayush Singh
2024-03-19 19:32 ` Andrew Lunn
2024-03-20 16:39 ` Ayush Singh
2024-03-20 18:44 ` Andrew Lunn
2024-03-21 7:35 ` Vaishnav Achath
2024-03-21 12:31 ` Andrew Lunn
2024-03-19 12:25 ` Andrew Lunn
2024-03-19 17:35 ` Vaishnav Achath
2024-03-19 18:19 ` Conor Dooley
2024-03-21 6:30 ` Vaishnav Achath
2024-03-19 19:23 ` Andrew Lunn
2024-03-21 7:07 ` Vaishnav Achath
2024-03-21 9:38 ` Michael Walle
2024-03-21 11:55 ` Vaishnav Achath
2024-03-21 12:44 ` Michael Walle
2024-03-21 12:55 ` Andrew Lunn
2024-03-19 6:03 ` Krzysztof Kozlowski
2024-03-19 6:42 ` Ayush Singh
2024-03-19 19:37 ` Conor Dooley
2024-03-22 18:15 ` Ayush Singh
2024-03-22 18:51 ` Andrew Lunn
2024-03-17 19:37 ` Ayush Singh [this message]
2024-03-19 8:16 ` [PATCH v4 2/5] spi: Make of_find_spi_controller_by_node() available Markus Elfring
2024-03-17 19:37 ` [PATCH v4 3/5] greybus: Add mikroBUS manifest types Ayush Singh
2024-03-19 8:26 ` Vaishnav Achath
2024-03-17 19:37 ` [PATCH v4 4/5] mikrobus: Add mikroBUS driver Ayush Singh
2024-03-17 19:59 ` Randy Dunlap
2024-03-18 17:34 ` Markus Elfring
2024-03-18 17:58 ` Markus Elfring
2024-03-18 18:41 ` Alex Elder
2024-03-18 18:55 ` Greg Kroah-Hartman
2024-03-18 18:12 ` Markus Elfring
2024-03-19 6:04 ` Krzysztof Kozlowski
2024-03-19 6:47 ` Ayush Singh
2024-03-19 8:00 ` Vaishnav Achath
2024-03-20 7:33 ` Krzysztof Kozlowski
2024-03-19 8:49 ` Vaishnav Achath
2024-03-17 19:37 ` [PATCH v4 5/5] dts: ti: k3-am625-beagleplay: Add mikroBUS Ayush Singh
2024-03-19 5:59 ` Krzysztof Kozlowski
2024-03-19 6:34 ` Ayush Singh
2024-03-20 7:31 ` Krzysztof Kozlowski
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=20240317193714.403132-3-ayushdevel1325@gmail.com \
--to=ayushdevel1325@gmail.com \
--cc=arnd@arndb.de \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=derek.kiernan@amd.com \
--cc=devicetree@vger.kernel.org \
--cc=dragan.cvetic@amd.com \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=jkridner@beagleboard.org \
--cc=johan@kernel.org \
--cc=kristo@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=lorforlinux@beagleboard.org \
--cc=nm@ti.com \
--cc=robertcnelson@beagleboard.org \
--cc=robh@kernel.org \
--cc=vaishnav.a@ti.com \
--cc=vigneshr@ti.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;
as well as URLs for NNTP newsgroup(s).