linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
	suzuki.poulose@arm.com,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	linux-i2c@vger.kernel.org, Mark Brown <broonie@kernel.org>
Subject: [PATCH v2 21/28] drivers: Introduce bus_find_device_by_acpi_dev() helper
Date: Fri, 14 Jun 2019 18:54:16 +0100	[thread overview]
Message-ID: <1560534863-15115-22-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com>

Add a wrapper to bus_find_device() to search for a device
by the ACPI COMPANION device, reusing the generic match function.
Also convert the existing users to make use of the new helper.

Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/i2c/i2c-core-acpi.c |  8 +-------
 drivers/spi/spi.c           |  8 +-------
 include/linux/device.h      | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 8af35f11..7c6435c 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -328,11 +328,6 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
 	return ACPI_HANDLE(dev) == (acpi_handle)data;
 }
 
-static int i2c_acpi_find_match_device(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
-
 static struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
 {
 	struct device *dev;
@@ -346,8 +341,7 @@ static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, adev,
-			      i2c_acpi_find_match_device);
+	dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
 	return dev ? i2c_verify_client(dev) : NULL;
 }
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index cc4d83e..8737d69 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3627,11 +3627,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
 	return ACPI_COMPANION(dev->parent) == data;
 }
 
-static int spi_acpi_device_match(struct device *dev, const void *data)
-{
-	return ACPI_COMPANION(dev) == data;
-}
-
 static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
@@ -3651,8 +3646,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
 
-	dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
-
+	dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
 	return dev ? to_spi_device(dev) : NULL;
 }
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 1c137ab..6768e2b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -235,6 +235,28 @@ bus_find_next_device(struct bus_type *bus,struct device *cur)
 	return bus_find_device(bus, cur, NULL, device_match_any);
 }
 
+#ifdef CONFIG_ACPI
+struct acpi_device;
+
+/**
+ * bus_find_device_by_acpi_dev : device iterator for locating a particular device
+ * matching the ACPI COMPANION device.
+ * @bus: bus type
+ * @adev: ACPI COMPANION device to match.
+ */
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
+{
+	return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
+}
+#else
+static inline struct device *
+bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
+{
+	return NULL;
+}
+#endif
+
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
-- 
2.7.4


  parent reply	other threads:[~2019-06-14 17:55 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com>
2019-06-14 17:53 ` [PATCH v2 01/28] staging: most-core: Use bus_find_device_by_name Suzuki K Poulose
2019-06-14 17:53 ` [PATCH v2 02/28] mfd: Remove unused helper syscon_regmap_lookup_by_pdevname Suzuki K Poulose
2019-07-25 10:50   ` Lee Jones
2019-06-14 17:53 ` [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb Suzuki K Poulose
2019-06-17 22:08   ` Rafael J. Wysocki
2019-06-24  3:20     ` Greg Kroah-Hartman
2019-06-14 17:53 ` [PATCH v2 04/28] bus_find_device: Unify the match callback with class_find_device Suzuki K Poulose
2019-06-14 20:30   ` Rob Herring
2019-06-14 20:30   ` Wolfram Sang
2019-06-14 17:54 ` [PATCH v2 05/28] driver_find_device: Unify the match function with class_find_device() Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 06/28] drivers: Add generic helper to match by of_node Suzuki K Poulose
2019-06-14 20:31   ` Wolfram Sang
2019-06-17  9:59     ` Suzuki K Poulose
2019-06-17 10:06       ` Wolfram Sang
2019-06-14 17:54 ` [PATCH v2 07/28] drivers: Add generic helper to match by fwnode Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 08/28] drivers: Add generic helper to match by device type Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
2019-06-17 22:07   ` Rafael J. Wysocki
2019-06-18  8:38     ` Suzuki K Poulose
2019-06-18  8:40       ` Rafael J. Wysocki
2019-06-14 17:54 ` [PATCH v2 10/28] drivers: Add generic helper to match by name Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 11/28] drivers: Add generic helper to match any device Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 12/28] drivers: Introduce class_find_device_by_name() helper Suzuki K Poulose
2019-06-21 11:02   ` Pavel Machek
2019-06-24 10:08   ` Alexandre Belloni
2019-06-14 17:54 ` [PATCH v2 13/28] drivers: Introduce class_find_device_by_of_node() helper Suzuki K Poulose
2019-06-22  5:25   ` Peter Rosin
2019-06-24  8:34     ` Suzuki K Poulose
2019-06-24 14:07       ` Peter Rosin
2019-06-24 15:19         ` Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 14/28] drivers: Introduce class_find_device_by_fwnode() helper Suzuki K Poulose
2019-06-18 10:42   ` Heikki Krogerus
2019-06-14 17:54 ` [PATCH v2 15/28] drivers: Introduce class_find_device_by_devt() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 16/28] drivers: Introduce class_find_device_by_acpi_dev() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 17/28] drivers: Introduce bus_find_device_by_of_node() helper Suzuki K Poulose
2019-06-14 20:32   ` Wolfram Sang
2019-07-09 16:19   ` Rob Herring
2019-06-14 17:54 ` [PATCH v2 18/28] drivers: Introduce bus_find_device_by_fwnode() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 19/28] drivers: Introduce bus_find_device_by_devt() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 20/28] drivers: Introduce bus_find_next_device() helper Suzuki K Poulose
2019-06-14 17:54 ` Suzuki K Poulose [this message]
2019-06-14 18:08   ` [PATCH v2 21/28] drivers: Introduce bus_find_device_by_acpi_dev() helper Mark Brown
2019-06-17  9:39   ` Mika Westerberg
2019-06-17 10:07   ` Wolfram Sang
2019-06-14 17:54 ` [PATCH v2 22/28] drivers: Introduce driver_find_device_by_name() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 23/28] drivers: Introduce driver_find_device_by_of_node() helper Suzuki K Poulose
2019-07-25 10:51   ` Lee Jones
2019-07-25 13:38     ` Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 24/28] drivers: Introduce driver_find_device_by_fwnode() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 25/28] drivers: Introduce driver_find_device_by_devt() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 26/28] drivers: Introduce driver_find_next_device() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 27/28] drivers: Introduce driver_find_device_by_acpi_dev() helper Suzuki K Poulose
2019-06-14 17:54 ` [PATCH v2 28/28] platform: Add platform_find_device_by_driver() helper Suzuki K Poulose
2019-06-14 18:24 ` [PATCH v2 00/28] drivers: Consolidate device lookup helpers Joe Perches
2019-06-17 10:07   ` Suzuki K Poulose
     [not found] ` <20190624032348.GA28919@kroah.com>
2019-06-24  8:31   ` Suzuki K Poulose

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=1560534863-15115-22-git-send-email-suzuki.poulose@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=wsa@the-dreams.de \
    /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).