function to retrive of_device_id data
Hi DT maintainers,
A common driver pattern for retrieving the data field in a of_device_id struct seems to be:
const struct of_device_id *match;
match = of_match_device(driver_of_match, &pdev->dev);
driver->data = match->data;I was looking for a simple function to perform the above action but couldn't find one.
What do you think about the following patch to add such a function?
--- drivers/of/device.c | 12 ++++++++++++ include/linux/of_device.h | 7 +++++++ 2 files changed, 19 insertions(+)
drivers/of/device.c +12 -0
@@ -79,6 +79,18 @@ void of_device_unregister(struct platform_device *ofdev) }EXPORT_SYMBOL (of_device_unregister); +const void *of_device_get_data (const struct device *dev) +{ +const struct of_device_id *match; + + match =of_match_device (dev->driver->of_match_table, dev); +if (!match) +return NULL ; + +return match->data; +} +EXPORT_SYMBOL (of_device_get_data); +ssize_t of_device_get_modalias (struct device *dev,char *str,ssize_t len) {const char *compat;
include/linux/of_device.h +7 -0
@@ -33,6 +33,8 @@ extern int of_device_add(struct platform_device *pdev);extern int of_device_register (struct platform_device *ofdev);extern void of_device_unregister (struct platform_device *ofdev); +extern const void *of_device_get_data (const struct device *dev); +extern ssize_t of_device_get_modalias (struct device *dev,char *str,ssize_t len);
@@ -64,6 +66,11 @@ static inline int of_driver_match_device(struct device *dev,static inline void of_device_uevent (struct device *dev,struct kobj_uevent_env *env) { } +static const void *of_device_get_data (const struct device *dev) +{ +return NULL ; +} +static inline int of_device_get_modalias (struct device *dev,char *str,ssize_t len) {
Signature · 6 lines
1.8.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1430687943-13051-1-git-send-email-manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 11 lines · Joachim Eastwood
Hi DT maintainers,
A common driver pattern for retrieving the data field in a
of_device_idstruct seems to be:const struct of_device_id *match; match = of_match_device(driver_of_match, &pdev->dev); driver->data = match->data;I was looking for a simple function to perform the above action but couldn't find one.
What do you think about the following patch to add such a function?
Looks fine to me. I'd prefer it be called of_device_get_match_data() though.
Rob
Quoted 54 lines
--- drivers/of/device.c | 12 ++++++++++++ include/linux/of_device.h | 7 +++++++ 2 files changed, 19 insertions(+)drivers/of/device.c +12
-0@@ -79,6 +79,18 @@ void of_device_unregister(struct platform_device *ofdev) }EXPORT_SYMBOL (of_device_unregister); +const void *of_device_get_data (const struct device *dev) +{ +const struct of_device_id *match; + + match =of_match_device (dev->driver->of_match_table, dev); +if (!match) +return NULL ; + +return match->data; +} +EXPORT_SYMBOL (of_device_get_data); +ssize_t of_device_get_modalias (struct device *dev,char *str,ssize_t len) {const char *compat;include/linux/of_device.h +7
-1@@ -33,6 +33,8 @@ extern int of_device_add(struct platform_device *pdev);extern int of_device_register (struct platform_device *ofdev);extern void of_device_unregister (struct platform_device *ofdev); +extern const void *of_device_get_data (const struct device *dev); +extern ssize_t of_device_get_modalias (struct device *dev,char *str,ssize_t len);@@ -64,6 +66,11 @@ static inline int of_driver_match_device(struct device *dev,static inline void of_device_uevent (struct device *dev,struct kobj_uevent_env *env) { } +static const void *of_device_get_data (const struct device *dev) +{ +return NULL ; +} +static inline int of_device_get_modalias (struct device *dev,char *str,ssize_t len) { --
Quoted 2 lines
1.8.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAL_JsqKLaZFr7_ZWhkfQLqMpCr8BCn2xh2GAbEOwysau7E-1+w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 9 lines · Rob Herring
Quoted 8 lines · Joachim Eastwood
Hi DT maintainers,
A common driver pattern for retrieving the data field in a
of_device_idstruct seems to be:const struct of_device_id *match; match = of_match_device(driver_of_match, &pdev->dev); driver->data = match->data;
Quoted 5 lines
Quoted 3 lines
I was looking for a simple function to perform the above action but couldn't find one.
What do you think about the following patch to add such a function?
Looks fine to me. I'd prefer it be called
of_device_get_match_data()though.
I'll rename it and post a proper patch with a change log, tomorrow.
regards,
Joachim Eastwood
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html