of: add helper function to retrive match data
authorJoachim Eastwood <manabian@gmail.com>
Wed, 6 May 2015 18:09:09 +0000 (20:09 +0200)
committerRob Herring <robh@kernel.org>
Thu, 28 May 2015 17:59:40 +0000 (12:59 -0500)
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>
drivers/of/device.c
include/linux/of_device.h

index 20c1332a00182cb43bb707e2a7468dce73cdf991..8b91ea241b10f553f058885b5cc083a35e2a81fe 100644 (file)
@@ -163,6 +163,18 @@ void of_device_unregister(struct platform_device *ofdev)
 }
 EXPORT_SYMBOL(of_device_unregister);
 
+const void *of_device_get_match_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_match_data);
+
 ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
 {
        const char *compat;
index 22801b10cef5dd279ade089b9c10e9aa4f134aeb..4c508549833a53fc76b59ba6a0bda354fc4d051f 100644 (file)
@@ -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_match_data(const struct device *dev);
+
 extern ssize_t of_device_get_modalias(struct device *dev,
                                        char *str, ssize_t len);
 
@@ -65,6 +67,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 inline const void *of_device_get_match_data(const struct device *dev)
+{
+       return NULL;
+}
+
 static inline int of_device_get_modalias(struct device *dev,
                                   char *str, ssize_t len)
 {