summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--liblight/lights.c45
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;
}