From 970e9f83acc56c5a8ef5334661ce102ed1e0b36c Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 29 Nov 2012 14:18:29 +1100 Subject: [PATCH] backlight: add of_find_backlight_by_node() This function finds the struct backlight_device for a given device tree node. A dummy function is provided so that it safely compiles out if OF support is disabled. Signed-off-by: Thierry Reding Acked-by: Jingoo Han Reviewed-by: Grant Likely Signed-off-by: Andrew Morton --- drivers/video/backlight/backlight.c | 17 +++++++++++++++++ include/linux/backlight.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 297db2fa91f5..0d1ed4f008c8 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -370,6 +370,23 @@ void backlight_device_unregister(struct backlight_device *bd) } EXPORT_SYMBOL(backlight_device_unregister); +#if IS_ENABLED(CONFIG_OF) +static int of_parent_match(struct device *dev, void *data) +{ + return dev->parent && dev->parent->of_node == data; +} + +struct backlight_device *of_find_backlight_by_node(struct device_node *node) +{ + struct device *dev; + + dev = class_find_device(backlight_class, NULL, node, of_parent_match); + + return dev ? to_backlight_device(dev) : NULL; +} +EXPORT_SYMBOL(of_find_backlight_by_node); +#endif + static void __exit backlight_class_exit(void) { class_destroy(backlight_class); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 5ffc6dda4675..11840e9bde97 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -134,4 +134,14 @@ struct generic_bl_info { void (*kick_battery)(void); }; +#if IS_ENABLED(CONFIG_OF) +struct backlight_device *of_find_backlight_by_node(struct device_node *node); +#else +static inline struct backlight_device * +of_find_backlight_by_node(struct device_node *node) +{ + return NULL; +} +#endif + #endif -- 2.39.5