diff options
author | Joachim Eastwood <manabian@gmail.com> | 2015-05-06 14:09:09 -0400 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2015-05-28 13:59:40 -0400 |
commit | 3386e0fa905c31bf1dafa2cbe2ecceb7e5ce2e66 (patch) | |
tree | 7096ea89f1d2e5aa2366cf85b548d1c53284ed38 | |
parent | 31712c98f8180c7bd3f33eefa461f0e1142e18f5 (diff) |
of: add helper function to retrive match data
It's a common operation for device drivers to retrive the data
member from of_device_id struct in their probe function.
Most driver end up doing:
const struct of_device_id *match;
match = of_match_device(driver_of_match, &pdev->dev);
driver->data = match->data;
With the of_device_get_match_data helper function all this can
done in one go.
Signed-off-by: Joachim Eastwood <manabian@gmail.com>
[robh: add missing inline to dummmy declaration]
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/device.c | 12 | ||||
-rw-r--r-- | include/linux/of_device.h | 7 |
2 files changed, 19 insertions, 0 deletions
diff --git a/drivers/of/device.c b/drivers/of/device.c index 20c1332a0018..8b91ea241b10 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c | |||
@@ -163,6 +163,18 @@ void of_device_unregister(struct platform_device *ofdev) | |||
163 | } | 163 | } |
164 | EXPORT_SYMBOL(of_device_unregister); | 164 | EXPORT_SYMBOL(of_device_unregister); |
165 | 165 | ||
166 | const void *of_device_get_match_data(const struct device *dev) | ||
167 | { | ||
168 | const struct of_device_id *match; | ||
169 | |||
170 | match = of_match_device(dev->driver->of_match_table, dev); | ||
171 | if (!match) | ||
172 | return NULL; | ||
173 | |||
174 | return match->data; | ||
175 | } | ||
176 | EXPORT_SYMBOL(of_device_get_match_data); | ||
177 | |||
166 | ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) | 178 | ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) |
167 | { | 179 | { |
168 | const char *compat; | 180 | const char *compat; |
diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 22801b10cef5..4c508549833a 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h | |||
@@ -33,6 +33,8 @@ extern int of_device_add(struct platform_device *pdev); | |||
33 | extern int of_device_register(struct platform_device *ofdev); | 33 | extern int of_device_register(struct platform_device *ofdev); |
34 | extern void of_device_unregister(struct platform_device *ofdev); | 34 | extern void of_device_unregister(struct platform_device *ofdev); |
35 | 35 | ||
36 | extern const void *of_device_get_match_data(const struct device *dev); | ||
37 | |||
36 | extern ssize_t of_device_get_modalias(struct device *dev, | 38 | extern ssize_t of_device_get_modalias(struct device *dev, |
37 | char *str, ssize_t len); | 39 | char *str, ssize_t len); |
38 | 40 | ||
@@ -65,6 +67,11 @@ static inline int of_driver_match_device(struct device *dev, | |||
65 | static inline void of_device_uevent(struct device *dev, | 67 | static inline void of_device_uevent(struct device *dev, |
66 | struct kobj_uevent_env *env) { } | 68 | struct kobj_uevent_env *env) { } |
67 | 69 | ||
70 | static inline const void *of_device_get_match_data(const struct device *dev) | ||
71 | { | ||
72 | return NULL; | ||
73 | } | ||
74 | |||
68 | static inline int of_device_get_modalias(struct device *dev, | 75 | static inline int of_device_get_modalias(struct device *dev, |
69 | char *str, ssize_t len) | 76 | char *str, ssize_t len) |
70 | { | 77 | { |