diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2014-02-20 10:16:54 +0100 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2014-02-20 10:16:54 +0100 |
commit | eec0d833d918145db1c81c28cd624b9cfc2b18f7 (patch) | |
tree | 57ac8aaaf2a5cffe83e29121c77de63aa703d283 /liblight | |
parent | d7ddd4016d6b1aa0c2d7468e691acd361810f7b6 (diff) | |
download | device_samsung_tuna-eec0d833d918145db1c81c28cd624b9cfc2b18f7.zip device_samsung_tuna-eec0d833d918145db1c81c28cd624b9cfc2b18f7.tar.gz device_samsung_tuna-eec0d833d918145db1c81c28cd624b9cfc2b18f7.tar.bz2 |
liblight: Blank/unblank framebuffer on screen off/on
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'liblight')
-rw-r--r-- | liblight/lights.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/liblight/lights.c b/liblight/lights.c index 1dfcd8b..776b7d7 100644 --- a/liblight/lights.c +++ b/liblight/lights.c @@ -25,9 +25,11 @@ #include <sys/types.h> #include <hardware/lights.h> #include <linux/leds-an30259a.h> +#include <linux/fb.h> static pthread_once_t g_init = PTHREAD_ONCE_INIT; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; +static int g_blanked = 0; char const *const LCD_FILE = "/sys/class/backlight/s6e8aa0/brightness"; char const *const LED_FILE = "/dev/an30259a_leds"; @@ -80,6 +82,39 @@ static int rgb_to_brightness(struct light_state_t const *state) + (150*((color>>8) & 0x00ff)) + (29*(color & 0x00ff))) >> 8; } +static int fb_blank(int blank) +{ + int fd = -1; + int rc; + + fd = open("/dev/graphics/fb0", O_RDWR); + if (fd < 0) { + ALOGE("Opening framebuffer failed"); + goto error; + } + + if (blank) + rc = ioctl(fd, FBIOBLANK, FB_BLANK_POWERDOWN); + else + rc = ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK); + if (rc < 0) { + ALOGE("Blanking framebuffer failed"); + goto error; + } + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (fd >= 0) + close(fd); + + return rc; +} + static int set_light_backlight(struct light_device_t *dev, struct light_state_t const *state) { @@ -89,6 +124,16 @@ static int set_light_backlight(struct light_device_t *dev, pthread_mutex_lock(&g_lock); err = write_int(LCD_FILE, brightness); + if (brightness == 0) { + err |= fb_blank(1); + ALOGD("Blanked frambuffer"); + g_blanked = 1; + } else if (g_blanked) { + err |= fb_blank(0); + ALOGD("Unblanked frambuffer"); + g_blanked = 0; + } + pthread_mutex_unlock(&g_lock); return err; } |