linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] drivers: Introduce generic device lookup helpers
@ 2019-06-05 15:13 Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 04/13] drivers: Add generic helper to match by of_node Suzuki K Poulose
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Lunn, Shyam Sundar S K, rafael, Will Deacon, Ulf Hansson,
	dri-devel, Pavel Machek, Stefan Schmidt, Wolfram Sang, linux-acpi,
	Doug Ledford, Jiri Slaby, Tomas Winkler, Dan Murphy, gregkh,
	linux-usb, Seung-Woo Kim, linux-spi, Joe Perches, linux-wpan,
	Alexandre Belloni, David Airlie, Rafael J . Wysocki ,
	Thierry Reding, Srinivas Kandagatla, linux-

We have device iterators to find a particular device matching a criteria
for a given bus/class/driver. i.e, {bus,class,driver}_find_device() APIs.
The matching criteria is a function pointer for the APIs. Often the lookup
is based on a generic property of a device (e.g, name, fwnode, of node pointer
or device type) rather than a driver specific information. However, each driver
writes up its own "match" function, spilling the similar match functions all
over the driver subsystems.

Additionally the prototype for the "match" functions accepted by the above APIs
have a minute difference which prevents us otherwise sharing the match functions.
i.e,
	int (*match)(struct device *dev, void *data) for {bus/driver}_find_device()
	  vs
	int (*match)(struct device *dev, const void *) for class_find_device()

If we promote the former to accept a "const void*" parameter, we could share one
single match function for all the helpers. This series achieves the following:

 1) Unify the prototype for "match" functions accepted by the device lookup APIs.
 2) Introduce generic match functions to match devices by the generic attributes
    of a device (e.g, name, fwnode, of_node and devt).

Also, in order to prevent creation of such match functions in the future,
we introduce wrapper functions for the look up APIs, which automatically
uses the appropriate match functions.

i.e,
	{bus/class/driver}_find_device_by_name
	{bus/class/driver}_find_device_by_of_node
	{bus/class/driver}_find_device_by_fwnode
	{bus/class/driver}_find_device_by_devt

Additionally, this series also adds wrapper for finding a device by matching
a device driver for platform bus devices - platform_find_device_by_driver() to
avoid a few drivers hard coding the platform bus specific details.

This is part 1 of revised version of the series posted here [0], to allow for better
management of the merging. Part 2 of the series, where these new helpers are consumed
by the individual driver subsystems will be posted once this is series is merged.
The entire tree with both the parts in is available at [1]

[0] https://marc.info/?i=1559577023-558-1-git-send-email-suzuki.poulose@arm.com
[1] git://linux-arm.org/linux-skp.git driver-cleanup/v1

Cc: Alan Tull <atull@kernel.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Corey Minyard <minyard@acm.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: David Airlie <airlied@linux.ie>
Cc: David Kershner <david.kershner@unisys.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Doug Ledford <dledford@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: Elie Morisse <syniurge@gmail.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Grant Likely <grant.likely@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Joe Perches <joe@perches.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Len Brown <lenb@kernel.org
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: Peter Rosin <peda@axentia.se>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Sebastian Ott <sebott@linux.ibm.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: devicetree@vger.kernel.org
Cc: linux-acpi@vger.kernel.org
Cc: linux-fpga@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-leds@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org

Suzuki K Poulose (13):
  acpi: utils: Cleanup acpi_dev_match_cb
  bus_find_device: Unify the match callback with class_find_device
  driver_find_device: Unify the match function with class_find_device()
  drivers: Add generic helper to match by of_node
  drivers: Add generic helper to match by fwnode
  drivers: Add generic helper to match by devt
  drivers: Add generic match helper by ACPI_COMPANION device
  drivers: Add generic helper to match by name
  drivers: Add generic helper to match any device
  drivers: Introduce variants of class_find_device()
  drivers: Introduce variants for bus_find_device()
  drivers: Introduce variants of driver_find_device()
  platform: Add platform_find_device_by_driver() helper

 arch/powerpc/platforms/pseries/ibmebus.c           |   4 +-
 drivers/acpi/acpi_lpss.c                           |   4 +-
 drivers/acpi/sleep.c                               |   2 +-
 drivers/acpi/utils.c                               |  11 +-
 drivers/amba/tegra-ahb.c                           |   4 +-
 drivers/base/bus.c                                 |  28 +--
 drivers/base/core.c                                |  36 ++++
 drivers/base/devcon.c                              |   2 +-
 drivers/base/driver.c                              |   4 +-
 drivers/base/platform.c                            |  14 ++
 drivers/char/ipmi/ipmi_msghandler.c                |   8 +-
 drivers/char/ipmi/ipmi_si_platform.c               |   2 +-
 drivers/firmware/efi/dev-path-parser.c             |   4 +-
 drivers/gpu/drm/drm_mipi_dsi.c                     |   2 +-
 drivers/gpu/drm/tegra/dc.c                         |   4 +-
 drivers/hwtracing/coresight/coresight.c            |   6 +-
 drivers/hwtracing/coresight/of_coresight.c         |   2 +-
 drivers/hwtracing/intel_th/core.c                  |   5 +-
 drivers/i2c/busses/i2c-amd-mp2-pci.c               |   2 +-
 drivers/i2c/i2c-core-acpi.c                        |   4 +-
 drivers/i2c/i2c-core-of.c                          |   4 +-
 drivers/iio/inkern.c                               |   2 +-
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c         |   2 +-
 drivers/iommu/arm-smmu-v3.c                        |   2 +-
 drivers/iommu/arm-smmu.c                           |   2 +-
 drivers/mfd/altera-sysmgr.c                        |   4 +-
 drivers/mfd/syscon.c                               |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |   2 +-
 drivers/net/ethernet/ti/cpsw-phy-sel.c             |   4 +-
 drivers/net/ethernet/ti/davinci_emac.c             |   2 +-
 drivers/net/ethernet/toshiba/tc35815.c             |   4 +-
 drivers/nvmem/core.c                               |   2 +-
 drivers/of/of_mdio.c                               |   2 +-
 drivers/of/platform.c                              |   2 +-
 drivers/pci/probe.c                                |   2 +-
 drivers/pci/search.c                               |   4 +-
 drivers/s390/cio/ccwgroup.c                        |   2 +-
 drivers/s390/cio/chsc_sch.c                        |   2 +-
 drivers/s390/cio/css.c                             |   4 +-
 drivers/s390/cio/device.c                          |   6 +-
 drivers/s390/cio/scm.c                             |   4 +-
 drivers/s390/crypto/ap_bus.c                       |   8 +-
 drivers/scsi/scsi_proc.c                           |   2 +-
 drivers/spi/spi.c                                  |   4 +-
 drivers/staging/most/core.c                        |   4 +-
 drivers/thunderbolt/switch.c                       |   4 +-
 drivers/usb/core/devio.c                           |   4 +-
 drivers/usb/core/usb.c                             |   4 +-
 drivers/usb/phy/phy-am335x-control.c               |   4 +-
 drivers/usb/phy/phy-isp1301.c                      |   4 +-
 drivers/visorbus/visorbus_main.c                   |   4 +-
 include/linux/device.h                             | 188 ++++++++++++++++++++-
 include/linux/platform_device.h                    |   3 +
 sound/soc/rockchip/rk3399_gru_sound.c              |   2 +-
 54 files changed, 320 insertions(+), 123 deletions(-)

-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 04/13] drivers: Add generic helper to match by of_node
  2019-06-05 15:13 [PATCH 00/13] drivers: Introduce generic device lookup helpers Suzuki K Poulose
@ 2019-06-05 15:13 ` Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 11/13] drivers: Introduce variants for bus_find_device() Suzuki K Poulose
  2 siblings, 0 replies; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, suzuki.poulose, Alan Tull, Andrew Lunn,
	Daniel Vetter, David Airlie, David S. Miller, devicetree,
	dri-devel, Florian Fainelli, Frank Rowand, Heiner Kallweit,
	Jiri Slaby, Jonathan Hunter, Lee Jones, Liam Girdwood, linux-fpga,
	linux-i2c, linux-spi, Maarten Lankhorst, Mark Brown,
	Mathieu Poirier <mathieu.poiri

Add a helper to match device by the of_node. This will be later used
to provide generic lookup functions by of_node.

Cc: Alan Tull <atull@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: devicetree@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-fpga@vger.kernel.org
Cc: linux-i2c@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: Peter Rosin <peda@axentia.se>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Thor Thayer <thor.thayer@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index fd7511e..9211908 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3328,3 +3328,9 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
 	dev->of_node_reused = true;
 }
 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
+
+int device_match_of_node(struct device *dev, const void *np)
+{
+	return dev->of_node == np;
+}
+EXPORT_SYMBOL_GPL(device_match_of_node);
diff --git a/include/linux/device.h b/include/linux/device.h
index 4d7c881..7093085 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -163,6 +163,8 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter,
 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 
+int device_match_of_node(struct device *dev, const void *np);
+
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-05 15:13 [PATCH 00/13] drivers: Introduce generic device lookup helpers Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 04/13] drivers: Add generic helper to match by of_node Suzuki K Poulose
@ 2019-06-05 15:13 ` Suzuki K Poulose
  2019-06-06  9:17   ` Rafael J. Wysocki
  2019-06-05 15:13 ` [PATCH 11/13] drivers: Introduce variants for bus_find_device() Suzuki K Poulose
  2 siblings, 1 reply; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, suzuki.poulose, Len Brown, linux-acpi, linux-spi,
	Mark Brown

Add a generic helper to match a device by the acpi device.

Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: linux-spi@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/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index b827ca1..597095b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3346,3 +3346,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
 	return dev->devt == *(dev_t *)pdevt;
 }
 EXPORT_SYMBOL_GPL(device_match_devt);
+
+int device_match_acpi_dev(struct device *dev, const void *adev)
+{
+	return ACPI_COMPANION(dev) == adev;
+}
+EXPORT_SYMBOL(device_match_acpi_dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index f315692..a03b50d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
+int device_match_acpi_dev(struct device *dev, const void *adev);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 11/13] drivers: Introduce variants for bus_find_device()
  2019-06-05 15:13 [PATCH 00/13] drivers: Introduce generic device lookup helpers Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 04/13] drivers: Add generic helper to match by of_node Suzuki K Poulose
  2019-06-05 15:13 ` [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
@ 2019-06-05 15:13 ` Suzuki K Poulose
  2 siblings, 0 replies; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-05 15:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, suzuki.poulose, Alexander Shishkin, Andrew Lunn,
	Daniel Vetter, David Airlie, David S. Miller, devicetree,
	Doug Ledford, dri-devel, Florian Fainelli, Frank Rowand,
	Heiko Stuebner, Jason Gunthorpe, Liam Girdwood, linux-i2c,
	linux-rockchip, linux-spi, linux-usb, Maarten Lankhorst,
	Mark Brown, Mathieu 

Similar to the class_find_device_by_*() introduce the variants
for bus_find_device() to automatically search for device by
generic device properties.

Here is the list of new helpers :

	bus_find_device_by_of_node
	bus_find_device_by_fwnode
	bus_find_device_by_devt
	bus_find_next_device

While at it convert the bus_find_device_by_name to static inline
reusing the generic helper to match the name.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: devicetree@vger.kernel.org
Cc: Doug Ledford <dledford@redhat.com>
Cc: dri-devel@lists.freedesktop.org
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-i2c@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-spi@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/bus.c     | 24 -------------------
 include/linux/device.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 61 insertions(+), 27 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index df3cac7..a1d1e82 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device);
 
-static int match_name(struct device *dev, const void *data)
-{
-	const char *name = data;
-
-	return sysfs_streq(name, dev_name(dev));
-}
-
-/**
- * bus_find_device_by_name - device iterator for locating a particular device of a specific name
- * @bus: bus type
- * @start: Device to begin with
- * @name: name of the device to match
- *
- * This is similar to the bus_find_device() function above, but it handles
- * searching by a name automatically, no need to write another strcmp matching
- * function.
- */
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start, const char *name)
-{
-	return bus_find_device(bus, start, (void *)name, match_name);
-}
-EXPORT_SYMBOL_GPL(bus_find_device_by_name);
-
 /**
  * subsys_find_device_by_id - find a device with a specific enumeration number
  * @subsys: subsystem
diff --git a/include/linux/device.h b/include/linux/device.h
index 4396edc..10de79d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -175,9 +175,67 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 struct device *bus_find_device(struct bus_type *bus, struct device *start,
 			       const void *data,
 			       int (*match)(struct device *dev, const void *data));
-struct device *bus_find_device_by_name(struct bus_type *bus,
-				       struct device *start,
-				       const char *name);
+/**
+ * bus_find_device_by_name - device iterator for locating a particular device
+ * of a specific name.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @name: name of the device to match
+ */
+static inline struct device *bus_find_device_by_name(struct bus_type *bus,
+						     struct device *start,
+						     const char *name)
+{
+	return bus_find_device(bus, start, name, device_match_name);
+}
+
+/**
+ * bus_find_device_by_of_node : device iterator for locating a particular device
+ * matching the of_node.
+ * @bus: bus type
+ * @np: of_node of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
+{
+	return bus_find_device(bus, NULL, np, device_match_of_node);
+}
+
+/**
+ * bus_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @bus: bus type
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
+{
+	return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
+}
+
+/**
+ * bus_find_device_by_devt : device iterator for locating a particular device
+ * matching the device type.
+ * @bus: bus type
+ * @start: device to start the search from
+ * @devt: device type of the device to match.
+ */
+static inline struct device *
+bus_find_device_by_devt(struct bus_type *bus, struct device *start, dev_t devt)
+{
+	return bus_find_device(bus, start, &devt, device_match_devt);
+}
+
+/**
+ * bus_find_next_device - Find the next device after a given device in a
+ * given bus.
+ */
+static inline struct device *
+bus_find_next_device(struct bus_type *bus,struct device *cur)
+{
+	return bus_find_device(bus, cur, NULL, device_match_any);
+}
+
 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-05 15:13 ` [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
@ 2019-06-06  9:17   ` Rafael J. Wysocki
  2019-06-06  9:28     ` Suzuki K Poulose
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2019-06-06  9:17 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Rafael J. Wysocki,
	Len Brown, ACPI Devel Maling List, linux-spi, Mark Brown

On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Add a generic helper to match a device by the acpi device.

"by its ACPI companion device object", please.

Also, it would be good to combine this patch with the patch(es) that
cause device_match_acpi_dev() to be actually used.

Helpers without any users are arguably not useful.

>
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-spi@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/base/core.c    | 6 ++++++
>  include/linux/device.h | 1 +
>  2 files changed, 7 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index b827ca1..597095b 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3346,3 +3346,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
>         return dev->devt == *(dev_t *)pdevt;
>  }
>  EXPORT_SYMBOL_GPL(device_match_devt);
> +
> +int device_match_acpi_dev(struct device *dev, const void *adev)
> +{
> +       return ACPI_COMPANION(dev) == adev;
> +}
> +EXPORT_SYMBOL(device_match_acpi_dev);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index f315692..a03b50d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
> +int device_match_acpi_dev(struct device *dev, const void *adev);
>
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>                      int (*fn)(struct device *dev, void *data));
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-06  9:17   ` Rafael J. Wysocki
@ 2019-06-06  9:28     ` Suzuki K Poulose
  2019-06-06  9:57       ` Rafael J. Wysocki
  0 siblings, 1 reply; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-06  9:28 UTC (permalink / raw)
  To: rafael; +Cc: linux-kernel, gregkh, lenb, linux-acpi, linux-spi, broonie



On 06/06/2019 10:17, Rafael J. Wysocki wrote:
> On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>
>> Add a generic helper to match a device by the acpi device.
> 
> "by its ACPI companion device object", please.

Sure.

> 
> Also, it would be good to combine this patch with the patch(es) that
> cause device_match_acpi_dev() to be actually used.
> 
> Helpers without any users are arguably not useful.

Sure, the helpers will be part of the part2 of the whole series,
which will actually have the individual subsystems consuming the
new helpers. For your reference, it is available here :

http://linux-arm.org/git?p=linux-skp.git;a=shortlog;h=refs/heads/driver-cleanup/v2

e.g: 
http://linux-arm.org/git?p=linux-skp.git;a=commit;h=59534e843e2f214f1f29659993f6e423bef16b28

I could simply pull those patches into this part, if you prefer that.
However, that would be true for the other patches in the part2.
I am open to suggestions, on how to split the series.

Cheers
Suzuki

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-06  9:28     ` Suzuki K Poulose
@ 2019-06-06  9:57       ` Rafael J. Wysocki
  2019-06-12  9:43         ` Suzuki K Poulose
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2019-06-06  9:57 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Greg Kroah-Hartman,
	Len Brown, ACPI Devel Maling List, linux-spi, Mark Brown

On Thu, Jun 6, 2019 at 11:28 AM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
>
>
> On 06/06/2019 10:17, Rafael J. Wysocki wrote:
> > On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >>
> >> Add a generic helper to match a device by the acpi device.
> >
> > "by its ACPI companion device object", please.
>
> Sure.
>
> >
> > Also, it would be good to combine this patch with the patch(es) that
> > cause device_match_acpi_dev() to be actually used.
> >
> > Helpers without any users are arguably not useful.
>
> Sure, the helpers will be part of the part2 of the whole series,
> which will actually have the individual subsystems consuming the
> new helpers. For your reference, it is available here :
>
> http://linux-arm.org/git?p=linux-skp.git;a=shortlog;h=refs/heads/driver-cleanup/v2
>
> e.g:
> http://linux-arm.org/git?p=linux-skp.git;a=commit;h=59534e843e2f214f1f29659993f6e423bef16b28
>
> I could simply pull those patches into this part, if you prefer that.

Not really.

I'd rather do it the other way around: push the introduction of the
helpers to part 2.

> However, that would be true for the other patches in the part2.
> I am open to suggestions, on how to split the series.

You can introduce each helper along with its users in one patch.

This way the total number of patches will be reduced and they will be
easier to review IMO.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-06  9:57       ` Rafael J. Wysocki
@ 2019-06-12  9:43         ` Suzuki K Poulose
  2019-06-12 22:07           ` Rafael J. Wysocki
  0 siblings, 1 reply; 9+ messages in thread
From: Suzuki K Poulose @ 2019-06-12  9:43 UTC (permalink / raw)
  To: rafael; +Cc: linux-kernel, gregkh, lenb, linux-acpi, linux-spi, broonie

Hi Rafael,

On 06/06/2019 10:57, Rafael J. Wysocki wrote:
> On Thu, Jun 6, 2019 at 11:28 AM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>
>>
>>
>> On 06/06/2019 10:17, Rafael J. Wysocki wrote:
>>> On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>>>
>>>> Add a generic helper to match a device by the acpi device.
>>>
>>> "by its ACPI companion device object", please.
>>
>> Sure.
>>
>>>
>>> Also, it would be good to combine this patch with the patch(es) that
>>> cause device_match_acpi_dev() to be actually used.
>>>
>>> Helpers without any users are arguably not useful.
>>
>> Sure, the helpers will be part of the part2 of the whole series,
>> which will actually have the individual subsystems consuming the
>> new helpers. For your reference, it is available here :
>>
>> http://linux-arm.org/git?p=linux-skp.git;a=shortlog;h=refs/heads/driver-cleanup/v2
>>
>> e.g:
>> http://linux-arm.org/git?p=linux-skp.git;a=commit;h=59534e843e2f214f1f29659993f6e423bef16b28
>>
>> I could simply pull those patches into this part, if you prefer that.
> 
> Not really.
> 
> I'd rather do it the other way around: push the introduction of the
> helpers to part 2.

Sure, I will do that.

> 
>> However, that would be true for the other patches in the part2.
>> I am open to suggestions, on how to split the series.
> 
> You can introduce each helper along with its users in one patch.
> 
> This way the total number of patches will be reduced and they will be
> easier to review IMO.
> 

Wouldn't it make the merging complicated ? I am still not clear how we plan
to merge the part 2 ?

Cheers
Suzuki

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-12  9:43         ` Suzuki K Poulose
@ 2019-06-12 22:07           ` Rafael J. Wysocki
  0 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2019-06-12 22:07 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: rafael, linux-kernel, gregkh, lenb, linux-acpi, linux-spi,
	broonie

On Wednesday, June 12, 2019 11:43:38 AM CEST Suzuki K Poulose wrote:
> Hi Rafael,
> 
> On 06/06/2019 10:57, Rafael J. Wysocki wrote:
> > On Thu, Jun 6, 2019 at 11:28 AM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >>
> >>
> >>
> >> On 06/06/2019 10:17, Rafael J. Wysocki wrote:
> >>> On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >>>>
> >>>> Add a generic helper to match a device by the acpi device.
> >>>
> >>> "by its ACPI companion device object", please.
> >>
> >> Sure.
> >>
> >>>
> >>> Also, it would be good to combine this patch with the patch(es) that
> >>> cause device_match_acpi_dev() to be actually used.
> >>>
> >>> Helpers without any users are arguably not useful.
> >>
> >> Sure, the helpers will be part of the part2 of the whole series,
> >> which will actually have the individual subsystems consuming the
> >> new helpers. For your reference, it is available here :
> >>
> >> http://linux-arm.org/git?p=linux-skp.git;a=shortlog;h=refs/heads/driver-cleanup/v2
> >>
> >> e.g:
> >> http://linux-arm.org/git?p=linux-skp.git;a=commit;h=59534e843e2f214f1f29659993f6e423bef16b28
> >>
> >> I could simply pull those patches into this part, if you prefer that.
> > 
> > Not really.
> > 
> > I'd rather do it the other way around: push the introduction of the
> > helpers to part 2.
> 
> Sure, I will do that.
> 
> > 
> >> However, that would be true for the other patches in the part2.
> >> I am open to suggestions, on how to split the series.
> > 
> > You can introduce each helper along with its users in one patch.
> > 
> > This way the total number of patches will be reduced and they will be
> > easier to review IMO.
> > 
> 
> Wouldn't it make the merging complicated ? I am still not clear how we plan
> to merge the part 2 ?

I wouldn't worry about it that much.  Without review, you have nothing to merge anyway.

Technically, every patch with a new helper and its users can go in via the Greg's tree
as long as it has been ACKed by the maintainers of the code touched by it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-06-12 22:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-05 15:13 [PATCH 00/13] drivers: Introduce generic device lookup helpers Suzuki K Poulose
2019-06-05 15:13 ` [PATCH 04/13] drivers: Add generic helper to match by of_node Suzuki K Poulose
2019-06-05 15:13 ` [PATCH 07/13] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
2019-06-06  9:17   ` Rafael J. Wysocki
2019-06-06  9:28     ` Suzuki K Poulose
2019-06-06  9:57       ` Rafael J. Wysocki
2019-06-12  9:43         ` Suzuki K Poulose
2019-06-12 22:07           ` Rafael J. Wysocki
2019-06-05 15:13 ` [PATCH 11/13] drivers: Introduce variants for bus_find_device() Suzuki K Poulose

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).