2013-10-30 06:13:07

by Rob Herring

[permalink] [raw]
Subject: [RFC PATCH 0/2] DT match helpers for initcalls and platform devices

From: Rob Herring <[email protected]>

This series adds a couple of boilerplate helpers to match with DT for
initcalls and platform device creation and probe. The goal here is to
remove more platform code out of arch/arm and eventually the machine
descriptors.

Rob

Rob Herring (2):
driver core: introduce module_platform_driver_match_and_probe
of: add initcall with match boilerplate helpers

include/linux/of.h | 12 ++++++++++++
include/linux/platform_device.h | 23 +++++++++++++++++++++++
2 files changed, 35 insertions(+)

--
1.8.1.2


2013-10-30 06:13:09

by Rob Herring

[permalink] [raw]
Subject: [RFC PATCH 1/2] driver core: introduce module_platform_driver_match_and_probe

From: Rob Herring <[email protected]>

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 <[email protected]>
Cc: Grant Likely <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
---
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

2013-10-30 06:13:46

by Rob Herring

[permalink] [raw]
Subject: [RFC PATCH 2/2] of: add initcall with match boilerplate helpers

From: Rob Herring <[email protected]>

Add boilerplate helpers to create initcalls which are conditional on
matching on devicetree properties.

Cc: Grant Likely <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
---
include/linux/of.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index f95aee3..a1327c9 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -592,6 +592,18 @@ static inline int of_property_read_u32(const struct device_node *np,
s; \
s = of_prop_next_string(prop, s))

+#define of_initcall_match(__func, __lvl, __match) \
+static int __init __func##_init(void) \
+{ \
+ if (of_find_matching_node(NULL, __match)) \
+ return __func(); \
+ else \
+ return -ENODEV; \
+} \
+__lvl(__func##_init);
+
+#define of_module_init_match(__func, __match) of_initcall_match(__func, module_init, __match)
+
#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
--
1.8.1.2

2013-10-30 08:26:30

by Thierry Reding

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] DT match helpers for initcalls and platform devices

On Wed, Oct 30, 2013 at 01:12:49AM -0500, Rob Herring wrote:
> From: Rob Herring <[email protected]>
>
> This series adds a couple of boilerplate helpers to match with DT for
> initcalls and platform device creation and probe. The goal here is to
> remove more platform code out of arch/arm and eventually the machine
> descriptors.

I fear that this is a step backwards because it makes it easier for
people to do the wrong thing. We've been doing the same with interrupt
controllers and clocks. With those there's at least the argument that
they need to be available really early and therefore cannot use the
regular driver model. But for everything else, shouldn't we enforce
proper drivers to be written?

Perhaps if you can point me to some examples I could get more context
why and where this would be useful.

Thierry


Attachments:
(No filename) (833.00 B)
(No filename) (836.00 B)
Download all attachments

2013-10-30 20:02:42

by Rob Herring

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] DT match helpers for initcalls and platform devices

On Wed, Oct 30, 2013 at 3:26 AM, Thierry Reding
<[email protected]> wrote:
> On Wed, Oct 30, 2013 at 01:12:49AM -0500, Rob Herring wrote:
>> From: Rob Herring <[email protected]>
>>
>> This series adds a couple of boilerplate helpers to match with DT for
>> initcalls and platform device creation and probe. The goal here is to
>> remove more platform code out of arch/arm and eventually the machine
>> descriptors.
>
> I fear that this is a step backwards because it makes it easier for
> people to do the wrong thing. We've been doing the same with interrupt
> controllers and clocks. With those there's at least the argument that
> they need to be available really early and therefore cannot use the
> regular driver model. But for everything else, shouldn't we enforce
> proper drivers to be written?

You think both are a step backwards or just the initcall one? For
initcalls, there are things which are not drivers, but just one time
init. The example on highbank is highbank_pm_init. In some cases like
cpuidle, they have been converted to platform drivers, but then we
have platform code to create devices if we are on the relevant
platform. There is not really a real device node that exists for some
of these drivers and we need to create the device rather than the
device getting created by scanning the buses in the DT.

I think this is less error prone because we've had cases of
unconditional initcalls which break multi-platform kernels.

> Perhaps if you can point me to some examples I could get more context
> why and where this would be useful.

I'll push out a WIP branch later which has the above examples and
removes the machine_desc struct for highbank. This all is more for
arm64 which doesn't have or want to have a machine_desc.

Rob

2013-10-30 21:40:41

by Rob Herring

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] DT match helpers for initcalls and platform devices

On Wed, Oct 30, 2013 at 3:02 PM, Rob Herring <[email protected]> wrote:
> On Wed, Oct 30, 2013 at 3:26 AM, Thierry Reding
> <[email protected]> wrote:
>> On Wed, Oct 30, 2013 at 01:12:49AM -0500, Rob Herring wrote:
>>> From: Rob Herring <[email protected]>
>>>
>>> This series adds a couple of boilerplate helpers to match with DT for
>>> initcalls and platform device creation and probe. The goal here is to
>>> remove more platform code out of arch/arm and eventually the machine
>>> descriptors.
>>
>> I fear that this is a step backwards because it makes it easier for
>> people to do the wrong thing. We've been doing the same with interrupt
>> controllers and clocks. With those there's at least the argument that
>> they need to be available really early and therefore cannot use the
>> regular driver model. But for everything else, shouldn't we enforce
>> proper drivers to be written?
>
> You think both are a step backwards or just the initcall one? For
> initcalls, there are things which are not drivers, but just one time
> init. The example on highbank is highbank_pm_init. In some cases like
> cpuidle, they have been converted to platform drivers, but then we
> have platform code to create devices if we are on the relevant
> platform. There is not really a real device node that exists for some
> of these drivers and we need to create the device rather than the
> device getting created by scanning the buses in the DT.
>
> I think this is less error prone because we've had cases of
> unconditional initcalls which break multi-platform kernels.
>
>> Perhaps if you can point me to some examples I could get more context
>> why and where this would be useful.
>
> I'll push out a WIP branch later which has the above examples and
> removes the machine_desc struct for highbank. This all is more for
> arm64 which doesn't have or want to have a machine_desc.

Here is a branch with example users:

git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git
highbank-rm-mach-desc

Rob