From: Ayush Singh <ayushdevel1325@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Ayush Singh <ayushdevel1325@gmail.com>,
jkridner@beagleboard.org, robertcnelson@beagleboard.org,
Vaishnav M A <vaishnav@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>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Jiri Slaby <jirislaby@kernel.org>,
Johan Hovold <johan@kernel.org>, Alex Elder <elder@kernel.org>,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-spi@vger.kernel.org, linux-serial@vger.kernel.org,
greybus-dev@lists.linaro.org
Subject: [PATCH v3 2/8] w1: Add w1_find_master_device
Date: Sat, 16 Mar 2024 00:19:00 +0530 [thread overview]
Message-ID: <20240315184908.500352-3-ayushdevel1325@gmail.com> (raw)
In-Reply-To: <20240315184908.500352-1-ayushdevel1325@gmail.com>
Add helper to find w1_master from w1_bus_master, which is present in
drvdata of platform device.
Signed-off-by: Vaishnav M A <vaishnav@beagleboard.org>
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
drivers/w1/w1.c | 6 +++---
drivers/w1/w1_int.c | 27 +++++++++++++++++++++++++++
include/linux/w1.h | 1 +
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index afb1cc4606c5..ce8a3f93f2ef 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -673,9 +673,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node,
sl->family->of_match_table);
- dev_set_name(&sl->dev, "%02x-%012llx",
- (unsigned int) sl->reg_num.family,
- (unsigned long long) sl->reg_num.id);
+ dev_set_name(&sl->dev, "%s-%02x-%012llx", sl->master->name,
+ (unsigned int)sl->reg_num.family,
+ (unsigned long long)sl->reg_num.id);
snprintf(&sl->name[0], sizeof(sl->name),
"%02x-%012llx",
(unsigned int) sl->reg_num.family,
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 3a71c5eb2f83..2bfef8e67687 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -242,3 +242,30 @@ void w1_remove_master_device(struct w1_bus_master *bm)
__w1_remove_master_device(found);
}
EXPORT_SYMBOL(w1_remove_master_device);
+
+/**
+ * w1_find_master_device() - find a master device
+ * @bm: master bus device to search
+ */
+struct w1_master *w1_find_master_device(struct w1_bus_master *bm)
+{
+ struct w1_master *dev, *found = NULL;
+
+ list_for_each_entry(dev, &w1_masters, w1_master_entry) {
+ if (!dev->initialized)
+ continue;
+
+ if (dev->bus_master->data == bm->data) {
+ found = dev;
+ break;
+ }
+ }
+
+ if (!found) {
+ pr_err("device doesn't exist.\n");
+ return ERR_PTR(-ENODEV);
+ }
+
+ return found;
+}
+EXPORT_SYMBOL(w1_find_master_device);
diff --git a/include/linux/w1.h b/include/linux/w1.h
index 9a2a0ef39018..24269d0dd5d1 100644
--- a/include/linux/w1.h
+++ b/include/linux/w1.h
@@ -242,6 +242,7 @@ struct w1_master {
int w1_add_master_device(struct w1_bus_master *master);
void w1_remove_master_device(struct w1_bus_master *master);
+struct w1_master *w1_find_master_device(struct w1_bus_master *master);
/**
* struct w1_family_ops - operations for a family type
--
2.44.0
next prev parent reply other threads:[~2024-03-15 18:49 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 18:48 [PATCH v3 0/8] misc: Add mikroBUS driver Ayush Singh
2024-03-15 18:48 ` [PATCH v3 1/8] dt-bindings: misc: Add mikrobus-connector Ayush Singh
2024-03-15 20:09 ` Krzysztof Kozlowski
2024-03-15 20:20 ` Russell King (Oracle)
2024-03-15 20:40 ` Krzysztof Kozlowski
2024-03-15 21:00 ` Russell King (Oracle)
2024-03-17 20:59 ` Rob Herring
2024-03-18 12:37 ` Ayush Singh
2024-03-15 18:49 ` Ayush Singh [this message]
2024-03-15 19:40 ` [PATCH v3 2/8] w1: Add w1_find_master_device Russell King (Oracle)
2024-03-15 20:14 ` Krzysztof Kozlowski
2024-03-15 18:49 ` [PATCH v3 3/8] spi: Make of_find_spi_controller_by_node() available Ayush Singh
2024-03-15 18:49 ` [PATCH v3 4/8] serdev: add of_ helper to get serdev controller Ayush Singh
2024-03-15 20:16 ` Krzysztof Kozlowski
2024-03-15 18:49 ` [PATCH v3 5/8] regulator: fixed-helper: export regulator_register_always_on Ayush Singh
2024-03-15 18:49 ` [PATCH v3 6/8] greybus: Add mikroBUS manifest types Ayush Singh
2024-04-11 12:03 ` Greg Kroah-Hartman
2024-03-15 18:49 ` [PATCH v3 7/8] mikrobus: Add mikrobus driver Ayush Singh
2024-03-15 19:03 ` Mark Brown
2024-03-15 19:32 ` Russell King (Oracle)
[not found] ` <46ba778a-5966-4b99-b820-f0d047a56227@gmail.com>
2024-03-15 21:19 ` Russell King (Oracle)
2024-03-15 22:10 ` Vaishnav Achath
2024-03-15 20:35 ` Krzysztof Kozlowski
2024-03-16 13:06 ` Ayush Singh
2024-03-19 5:32 ` Krzysztof Kozlowski
2024-03-19 6:59 ` Ayush Singh
2024-03-20 11:56 ` Krzysztof Kozlowski
2024-03-16 8:18 ` kernel test robot
2024-03-16 9:00 ` kernel test robot
2024-03-15 18:49 ` [PATCH v3 8/8] dts: ti: k3-am625-beagleplay: Add mikroBUS Ayush Singh
2024-03-15 20:20 ` Krzysztof Kozlowski
2024-03-15 21:20 ` [PATCH v3 0/8] misc: Add mikroBUS driver Vaishnav M A
2024-03-15 21:41 ` Ayush Singh
2024-03-15 22:24 ` Vaishnav Achath
2024-03-17 14:41 ` Andrew Lunn
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=20240315184908.500352-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=jirislaby@kernel.org \
--cc=jkridner@beagleboard.org \
--cc=johan@kernel.org \
--cc=kristo@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=nm@ti.com \
--cc=robertcnelson@beagleboard.org \
--cc=robh@kernel.org \
--cc=vaishnav@beagleboard.org \
--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).