diff options
author | Meghana Madhyastha <meghana.madhyastha@gmail.com> | 2018-01-24 11:35:30 -0500 |
---|---|---|
committer | Sean Paul <seanpaul@chromium.org> | 2018-01-29 10:34:53 -0500 |
commit | c2adda27d202fa8f70a5d6e8b0c12b449c8868b8 (patch) | |
tree | 4dae2ef4d28ae0b0e73022cae120a78d174f3aca | |
parent | 5b698be0497d8be986e2050e9b1c145b2e0603c2 (diff) |
video: backlight: Add of_find_backlight helper in backlight.c
Add of_find_backlight, a helper function which is a generic version
of tinydrm_of_find_backlight that can be used by other drivers to avoid
repetition of code and simplify things.
Acked-by: Daniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Meghana Madhyastha <meghana.madhyastha@gmail.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/116d160ba78be2e6dcbdcb6855622bce67da9472.1516810725.git.meghana.madhyastha@gmail.com
-rw-r--r-- | drivers/video/backlight/backlight.c | 43 | ||||
-rw-r--r-- | include/linux/backlight.h | 19 |
2 files changed, 62 insertions, 0 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 8049e7656daa..553bf5c4807c 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c | |||
@@ -580,6 +580,49 @@ struct backlight_device *of_find_backlight_by_node(struct device_node *node) | |||
580 | EXPORT_SYMBOL(of_find_backlight_by_node); | 580 | EXPORT_SYMBOL(of_find_backlight_by_node); |
581 | #endif | 581 | #endif |
582 | 582 | ||
583 | /** | ||
584 | * of_find_backlight - Get backlight device | ||
585 | * @dev: Device | ||
586 | * | ||
587 | * This function looks for a property named 'backlight' on the DT node | ||
588 | * connected to @dev and looks up the backlight device. | ||
589 | * | ||
590 | * Call backlight_put() to drop the reference on the backlight device. | ||
591 | * | ||
592 | * Returns: | ||
593 | * A pointer to the backlight device if found. | ||
594 | * Error pointer -EPROBE_DEFER if the DT property is set, but no backlight | ||
595 | * device is found. | ||
596 | * NULL if there's no backlight property. | ||
597 | */ | ||
598 | struct backlight_device *of_find_backlight(struct device *dev) | ||
599 | { | ||
600 | struct backlight_device *bd = NULL; | ||
601 | struct device_node *np; | ||
602 | |||
603 | if (!dev) | ||
604 | return NULL; | ||
605 | |||
606 | if (IS_ENABLED(CONFIG_OF) && dev->of_node) { | ||
607 | np = of_parse_phandle(dev->of_node, "backlight", 0); | ||
608 | if (np) { | ||
609 | bd = of_find_backlight_by_node(np); | ||
610 | of_node_put(np); | ||
611 | if (!bd) | ||
612 | return ERR_PTR(-EPROBE_DEFER); | ||
613 | /* | ||
614 | * Note: gpio_backlight uses brightness as | ||
615 | * power state during probe | ||
616 | */ | ||
617 | if (!bd->props.brightness) | ||
618 | bd->props.brightness = bd->props.max_brightness; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | return bd; | ||
623 | } | ||
624 | EXPORT_SYMBOL(of_find_backlight); | ||
625 | |||
583 | static void __exit backlight_class_exit(void) | 626 | static void __exit backlight_class_exit(void) |
584 | { | 627 | { |
585 | class_destroy(backlight_class); | 628 | class_destroy(backlight_class); |
diff --git a/include/linux/backlight.h b/include/linux/backlight.h index ace825e2ca2d..ddc9bade4fb2 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h | |||
@@ -162,6 +162,16 @@ static inline int backlight_disable(struct backlight_device *bd) | |||
162 | return backlight_update_status(bd); | 162 | return backlight_update_status(bd); |
163 | } | 163 | } |
164 | 164 | ||
165 | /** | ||
166 | * backlight_put - Drop backlight reference | ||
167 | * @bd: the backlight device to put | ||
168 | */ | ||
169 | static inline void backlight_put(struct backlight_device *bd) | ||
170 | { | ||
171 | if (bd) | ||
172 | put_device(&bd->dev); | ||
173 | } | ||
174 | |||
165 | extern struct backlight_device *backlight_device_register(const char *name, | 175 | extern struct backlight_device *backlight_device_register(const char *name, |
166 | struct device *dev, void *devdata, const struct backlight_ops *ops, | 176 | struct device *dev, void *devdata, const struct backlight_ops *ops, |
167 | const struct backlight_properties *props); | 177 | const struct backlight_properties *props); |
@@ -205,4 +215,13 @@ of_find_backlight_by_node(struct device_node *node) | |||
205 | } | 215 | } |
206 | #endif | 216 | #endif |
207 | 217 | ||
218 | #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) | ||
219 | struct backlight_device *of_find_backlight(struct device *dev); | ||
220 | #else | ||
221 | static inline struct backlight_device *of_find_backlight(struct device *dev) | ||
222 | { | ||
223 | return NULL; | ||
224 | } | ||
225 | #endif | ||
226 | |||
208 | #endif | 227 | #endif |