From: Rob Herring <robherring2@gmail.com>
To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Cc: Grant Likely <grant.likely@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <rob.herring@calxeda.com>
Subject: [RFC PATCH 1/2] driver core: introduce module_platform_driver_match_and_probe
Date: Wed, 30 Oct 2013 01:12:50 -0500 [thread overview]
Message-ID: <1383113571-13029-2-git-send-email-robherring2@gmail.com> (raw)
In-Reply-To: <1383113571-13029-1-git-send-email-robherring2@gmail.com>
From: Rob Herring <rob.herring@calxeda.com>
Introduce a helper to match, create and probe a platform device. This
is for drivers such as cpuidle or cpufreq that typically don't have a
bus device node and need to match on a system-level compatible property.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
include/linux/platform_device.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index ce8e4ff..0b4b1c9 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -12,6 +12,7 @@
#define _PLATFORM_DEVICE_H_
#include <linux/device.h>
+#include <linux/err.h>
#include <linux/mod_devicetable.h>
#define PLATFORM_DEVID_NONE (-1)
@@ -241,6 +242,28 @@ extern struct platform_device *platform_create_bundle(
struct resource *res, unsigned int n_res,
const void *data, size_t size);
+/*
+ * module_platform_driver_match_and_probe() - Helper macro for drivers without
+ * a bus device node and need to match on an arbitrary compatible property.
+ * This eliminates a lot of boilerplate. Each module may only use this macro
+ * once, and calling it replaces module_init() and module_exit()
+ */
+#define module_platform_driver_match_and_probe(__platform_driver, __platform_probe) \
+static int __init __platform_driver##_init(void) \
+{ \
+ if (of_find_matching_node(NULL, (__platform_driver).driver.of_match_table)) \
+ return PTR_ERR_OR_ZERO(platform_create_bundle(&(__platform_driver), \
+ __platform_probe, NULL, 0, NULL, 0)); \
+ else \
+ return -ENODEV; \
+} \
+module_init(__platform_driver##_init); \
+static void __exit __platform_driver##_exit(void) \
+{ \
+ platform_driver_unregister(&(__platform_driver)); \
+} \
+module_exit(__platform_driver##_exit);
+
/* early platform driver interface */
struct early_platform_driver {
const char *class_str;
--
1.8.1.2
next prev parent reply other threads:[~2013-10-30 6:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-30 6:12 [RFC PATCH 0/2] DT match helpers for initcalls and platform devices Rob Herring
2013-10-30 6:12 ` Rob Herring
[not found] ` < 20131030082621.GA22787@ulmo.nvidia.com>
2013-10-30 6:12 ` Rob Herring [this message]
2013-11-21 12:47 ` [RFC PATCH 1/2] driver core: introduce module_platform_driver_match_and_probe Grant Likely
2013-11-21 22:33 ` Rob Herring
2013-10-30 6:12 ` [RFC PATCH 2/2] of: add initcall with match boilerplate helpers Rob Herring
2013-11-21 12:50 ` Grant Likely
2013-11-21 23:23 ` Rob Herring
[not found] ` <1383113571-13029-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-10-30 8:26 ` [RFC PATCH 0/2] DT match helpers for initcalls and platform devices Thierry Reding
2013-10-30 8:26 ` Thierry Reding
[not found] ` <20131030082621.GA22787-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2013-10-30 20:02 ` Rob Herring
2013-10-30 20:02 ` Rob Herring
[not found] ` <CAL_JsqJ3GANeMNi3iXQY_rB-NoovmwZx7EXfbG=rS6MxS=NLvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-30 21:40 ` Rob Herring
2013-10-30 21:40 ` Rob Herring
2013-11-21 12:53 ` Grant Likely
[not found] ` < 1383113571-13029-2-git-send-email-robherring2@gmail.com>
[not found] ` <20131121124736. 6EBEBC40A2C@trevor.secretlab.ca>
[not found] ` < CAL_JsqLK_ivSphWq3xLpQqUjF1nEvPjf2WQ4hJ+hThcTFae-Kg@mail.gmail.com>
[not found] ` <CAL_JsqLK_ivSphWq3xLpQqUjF1nEvPjf2WQ4hJ+hThcTFae-Kg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-11-21 23:11 ` [RFC PATCH 1/2] driver core: introduce module_platform_driver_match_and_probe Grant Likely
2013-11-21 23:11 ` Grant Likely
[not found] ` < 1383113571-13029-3-git-send-email-robherring2@gmail.com>
[not found] ` <20131121125007. 17A8FC40A2C@trevor.secretlab.ca>
[not found] ` < CAL_JsqKHZtidrzJPH+c-zyFUQNsxtEKxOYg+Nzyo9JYNDNexug@mail.gmail.com>
[not found] ` <CAL_JsqKHZtidrzJPH+c-zyFUQNsxtEKxOYg+Nzyo9JYNDNexug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-11-27 15:22 ` [RFC PATCH 2/2] of: add initcall with match boilerplate helpers Grant Likely
2013-11-27 15:22 ` Grant Likely
2013-12-05 17:57 ` Rob Herring
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=1383113571-13029-2-git-send-email-robherring2@gmail.com \
--to=robherring2@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob.herring@calxeda.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.