diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-12-15 16:13:16 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-12-16 07:49:40 +0100 |
commit | e4835b01e132c70567e12af53a7213e5ef175e80 (patch) | |
tree | 78da8553afd309a9561ecb85b2736973503b14e3 | |
parent | 769866a8aa8991984d493f2625224d7096dcb3aa (diff) | |
download | barebox-e4835b01e132c70567e12af53a7213e5ef175e80.tar.gz |
video: Add backlight support
This adds a small backlight layer. It provides a backlight device
on which the brightness parameter can be used to adjust the brightness.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/video/Kconfig | 4 | ||||
-rw-r--r-- | drivers/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/backlight.c | 90 | ||||
-rw-r--r-- | include/video/backlight.h | 20 |
4 files changed, 115 insertions, 0 deletions
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index f096a5456b..e108d8a5b9 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -93,4 +93,8 @@ config DRIVER_VIDEO_EDID This enabled support for reading and parsing EDID data from an attached monitor. +config DRIVER_VIDEO_BACKLIGHT + bool "Add backlight support" + help + Enable this for backlight support. endif diff --git a/drivers/video/Makefile b/drivers/video/Makefile index ae9f6e545e..0655b0f705 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -1,6 +1,7 @@ obj-$(CONFIG_VIDEO) += fb.o obj-$(CONFIG_DRIVER_VIDEO_EDID) += edid.o obj-$(CONFIG_OFDEVICE) += of_display_timing.o +obj-$(CONFIG_DRIVER_VIDEO_BACKLIGHT) += backlight.o obj-$(CONFIG_DRIVER_VIDEO_ATMEL) += atmel_lcdfb.o atmel_lcdfb_core.o obj-$(CONFIG_DRIVER_VIDEO_ATMEL_HLCD) += atmel_hlcdfb.o atmel_lcdfb_core.o diff --git a/drivers/video/backlight.c b/drivers/video/backlight.c new file mode 100644 index 0000000000..ddde6f8523 --- /dev/null +++ b/drivers/video/backlight.c @@ -0,0 +1,90 @@ +#include <common.h> +#include <driver.h> +#include <linux/list.h> +#include <video/backlight.h> + +static LIST_HEAD(backlights); + +int backlight_set_brightness(struct backlight_device *bl, int brightness) +{ + int ret, step, i, num_steps; + + if (brightness > bl->brightness_max) + brightness = bl->brightness_max; + + if (brightness == bl->brightness_cur) + return 0; + + if (brightness > bl->brightness_cur) + step = 1; + else + step = -1; + + i = bl->brightness_cur; + + num_steps = abs(brightness - bl->brightness_cur); + + while (1) { + i += step; + + ret = bl->brightness_set(bl, i); + if (ret) + return ret; + + if (i == brightness) + break; + + udelay(100000 / num_steps); + } + + + bl->brightness_cur = bl->brightness = brightness; + + return ret; +} + +int backlight_set_brightness_default(struct backlight_device *bl) +{ + int ret; + + ret = backlight_set_brightness(bl, bl->brightness_default); + + return ret; +} + +static int backlight_brightness_set(struct param_d *p, void *priv) +{ + struct backlight_device *bl = priv; + + return backlight_set_brightness(bl, bl->brightness); +} + +int backlight_register(struct backlight_device *bl) +{ + int ret; + + sprintf(bl->dev.name, "backlight"); + bl->dev.id = DEVICE_ID_DYNAMIC; + + ret = register_device(&bl->dev); + if (ret) + return ret; + + dev_add_param_int(&bl->dev, "brightness", backlight_brightness_set, + NULL, &bl->brightness, "%d", bl); + + list_add_tail(&bl->list, &backlights); + + return ret; +} + +struct backlight_device *of_backlight_find(struct device_node *node) +{ + struct backlight_device *bl; + + list_for_each_entry(bl, &backlights, list) + if (bl->node == node) + return bl; + + return NULL; +} diff --git a/include/video/backlight.h b/include/video/backlight.h new file mode 100644 index 0000000000..56e0341ea4 --- /dev/null +++ b/include/video/backlight.h @@ -0,0 +1,20 @@ +#ifndef __VIDEO_BACKLIGHT_H +#define __VIDEO_BACKLIGHT_H + +struct backlight_device { + int brightness; + int brightness_cur; + int brightness_max; + int brightness_default; + int (*brightness_set)(struct backlight_device *, int brightness); + struct list_head list; + struct device_d dev; + struct device_node *node; +}; + +int backlight_set_brightness(struct backlight_device *, int brightness); +int backlight_set_brightness_default(struct backlight_device *); +int backlight_register(struct backlight_device *); +struct backlight_device *of_backlight_find(struct device_node *node); + +#endif /* __VIDEO_BACKLIGHT_H */ |