Linux ACPI
 help / color / mirror / Atom feed
From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
To: linux-kernel@vger.kernel.org
Cc: devicetree@vger.kernel.org, linux-acpi@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	Javier Martinez Canillas <javier@osg.samsung.com>,
	Mark Brown <broonie@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 06/22] device property: add fwnode_ensure_device()
Date: Tue, 28 Jul 2015 15:19:37 +0200	[thread overview]
Message-ID: <1438089593-7696-7-git-send-email-tomeu.vizoso@collabora.com> (raw)
In-Reply-To: <1438089593-7696-1-git-send-email-tomeu.vizoso@collabora.com>

Checks if the device associated with this firmware node has been already
probed, and probes it if not.

It can be used by resource getters to make sure that the requested
resource is available, if at all possible.

For OF nodes, it finds the platform device that encloses this node and
tries to probe it.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---

Changes in v2:
- Add fwnode_ensure_device() so the mechanism for probing devices on
  demand is independent of the firmware format.

 drivers/base/property.c  | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/property.h |  2 ++
 2 files changed, 60 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index efa74803af30..a63d9bc3d8f7 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -15,8 +15,11 @@
 #include <linux/kernel.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_platform.h>
 #include <linux/property.h>
 
+#include "base.h"
+
 /**
  * device_add_property_set - Add a collection of properties to a device object.
  * @dev: Device to add properties to.
@@ -548,3 +551,58 @@ const char *fwnode_get_name(struct fwnode_handle *fwnode)
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(fwnode_get_name);
+
+/**
+ * fwnode_ensure_device - probes the device associated to this firmware node
+ * @fwnode: Firmware node whose device is to be probed
+ *
+ * Checks if the device associated with this firmware node has been already
+ * probed, and probes it if not.  It can be used by resource getters to make
+ * sure that the requested resource is available, if at all possible.
+ */
+void fwnode_ensure_device(struct fwnode_handle *fwnode)
+{
+	struct device *dev = NULL;
+
+	/*
+	 * In general, OF nodes don't have a single device associated to them,
+	 * but those directly beneath the root of the tree or that are
+	 * children of simple memory mapped bus nodes do have just one
+	 * platform device. See Documentation/devicetree/usage-model.txt for
+	 * a more extended explanation.
+	 *
+	 * of_platform_device_find() will return such a platform device and
+	 * probing it should cause the target device to be probed as well
+	 * because platform devices are expected to register their children
+	 * when probing.
+	 */
+	if (is_of_node(fwnode))
+		dev = of_platform_device_find(to_of_node(fwnode));
+	else if (is_acpi_node(fwnode))
+		dev = acpi_dev_get_device(to_acpi_node(fwnode));
+
+	if (!dev) {
+		/*
+		 * Cannot be a warning because some fwnodes will have
+		 * matching data but aren't really supposed to be probed.
+		 */
+		pr_debug("Couldn't find device for %s\n",
+			 fwnode_get_name(fwnode));
+		return;
+	}
+
+	/*
+	 * Device is bound or is being probed right now. If we have bad luck
+	 * and the dependency isn't ready when it's needed, deferred probe
+	 * will save us.
+	 */
+	if (dev->driver)
+		return;
+
+	bus_probe_device(dev);
+
+	if (!dev->driver)
+		pr_warn("Probe failed for %s (%s)\n",
+			fwnode_get_name(fwnode), dev_name(dev));
+}
+EXPORT_SYMBOL_GPL(fwnode_ensure_device);
diff --git a/include/linux/property.h b/include/linux/property.h
index 826f156f7288..6b99296bcad7 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -168,4 +168,6 @@ void device_add_property_set(struct device *dev, struct property_set *pset);
 
 bool device_dma_is_coherent(struct device *dev);
 
+void fwnode_ensure_device(struct fwnode_handle *fwnode);
+
 #endif /* _LINUX_PROPERTY_H_ */
-- 
2.4.3

  parent reply	other threads:[~2015-07-28 13:19 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 13:19 [PATCH v2 0/22] On-demand device probing Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 01/22] platform: delay device-driver matches until late_initcall Tomeu Vizoso
2015-07-30  3:20   ` Rob Herring
2015-07-31 10:06     ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 02/22] of/platform: Set fwnode field for new devices Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 03/22] device property: add fwnode_get_name() Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 04/22] of/platform: add of_platform_device_find() Tomeu Vizoso
2015-07-28 13:39   ` Rob Herring
2015-07-28 13:54     ` Tomeu Vizoso
2015-07-28 15:31       ` Rob Herring
2015-07-29  6:14         ` Tomeu Vizoso
     [not found]           ` <CAAObsKA+vMsgiC52jReJckeDjXhdd=_NBocFbMapdwFReiY1SQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-29 11:20             ` Tomeu Vizoso
2015-07-29 12:15               ` Tomeu Vizoso
2015-07-29 15:27               ` Rob Herring
2015-07-31 10:32                 ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 05/22] ACPI: add acpi_dev_get_device() Tomeu Vizoso
     [not found]   ` <1438089593-7696-6-git-send-email-tomeu.vizoso-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2015-07-30  3:08     ` Rob Herring
2015-07-28 13:19 ` Tomeu Vizoso [this message]
2015-07-28 13:19 ` [PATCH v2 07/22] gpio: Probe GPIO drivers on demand Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 08/22] gpio: Probe pinctrl devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 09/22] regulator: core: Reduce critical area in _regulator_get Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 10/22] regulator: core: Probe regulators on demand Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 11/22] drm: Probe panels " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 12/22] drm/tegra: Probe dpaux devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 13/22] i2c: core: Probe i2c master " Tomeu Vizoso
2015-08-09 12:34   ` Wolfram Sang
2015-08-09 13:37     ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 14/22] pwm: Probe PWM chip " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 15/22] backlight: Probe backlight " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 16/22] usb: phy: Probe phy " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 17/22] clk: Probe clk providers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 18/22] pinctrl: Probe pinctrl devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 19/22] phy: core: Probe phy providers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 20/22] dma: of: Probe DMA controllers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 21/22] power-supply: Probe power supplies " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 22/22] ASoC: core: Probe components " Tomeu Vizoso
     [not found] ` <1438089593-7696-1-git-send-email-tomeu.vizoso-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2015-07-29  0:36   ` [PATCH v2 0/22] On-demand device probing Rafael J. Wysocki
2015-07-30  3:06 ` Rob Herring
2015-07-31 10:28   ` Tomeu Vizoso

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=1438089593-7696-7-git-send-email-tomeu.vizoso@collabora.com \
    --to=tomeu.vizoso@collabora.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=javier@osg.samsung.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=swarren@wwwdotorg.org \
    --cc=thierry.reding@gmail.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