From ebc06142fd19d23b06ed726f0291c565fce487da Mon Sep 17 00:00:00 2001 From: Daniel Hillenbrand Date: Fri, 23 Aug 2013 22:08:04 +0200 Subject: exynos4210: liblights: big cleanup http://review.cyanogenmod.org/#/c/48922/ Change-Id: I5fa9602649c5d0e902dfc9ba9e50e8197d0dfb76 --- exynos4/exynos4210/liblights/lights.c | 191 +--------------------------------- 1 file changed, 4 insertions(+), 187 deletions(-) diff --git a/exynos4/exynos4210/liblights/lights.c b/exynos4/exynos4210/liblights/lights.c index 7be7d7b..5eedad4 100644 --- a/exynos4/exynos4210/liblights/lights.c +++ b/exynos4/exynos4210/liblights/lights.c @@ -37,7 +37,6 @@ static pthread_once_t g_init = PTHREAD_ONCE_INIT; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; -static int g_enable_touchlight = -1; char const*const PANEL_FILE = "/sys/class/backlight/panel/brightness"; @@ -47,39 +46,12 @@ char const*const BUTTON_FILE = "/sys/class/sec/sec_touchkey/brightness"; #endif -#ifdef LED_NOTIFICATION -static char const RED_LED_DIR[] = "/sys/class/leds/red"; -static char const BLUE_LED_DIR[] = "/sys/class/leds/blue"; -#endif // LED_NOTIFICATION void init_globals(void) { // init the mutex pthread_mutex_init(&g_lock, NULL); } -void -load_settings() -{ - FILE* fp = fopen("/data/.disable_touchlight", "r"); - if (!fp) { - g_enable_touchlight = 1; - } else { - g_enable_touchlight = (int)(fgetc(fp)); - if (g_enable_touchlight == '1') - g_enable_touchlight = 1; - else - g_enable_touchlight = 0; - - fclose(fp); - } -} - -#ifdef LED_NOTIFICATION -static struct led_state { - unsigned int enabled; - int delay_on, delay_off; -} battery_red, battery_blue, notifications_red, notifications_blue; -#endif // LED_NOTIFICATION static int write_int(char const* path, int value) { @@ -102,45 +74,6 @@ write_int(char const* path, int value) } } -#ifdef LED_NOTIFICATION -static int write_str(char const *path, char const *str) -{ - int fd; - static int already_warned = 0; - - ALOGV("write_str: path=\"%s\", str=\"%s\".", path, str); - fd = open(path, O_RDWR); - - if (fd >= 0) { - int amt = write(fd, str, strlen(str)); - close(fd); - return amt == -1 ? -errno : 0; - } else { - if (already_warned == 0) { - ALOGE("write_str failed to open %s\n", path); - already_warned = 1; - } - return -errno; - } -} - -/* Should check for snprintf truncation, but as these functions only use - * internal paths, meh. */ -static int write_df_int(char const *dir, char const *file, int value) -{ - char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/%s", dir, file); - return write_int(path, value); -} - -static int write_df_str(char const *dir, char const *file, char const *str) -{ - char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/%s", dir, file); - return write_str(path, str); -} -#endif // LED_NOTIFICATION - static int is_lit(struct light_state_t const* state) { @@ -155,75 +88,6 @@ rgb_to_brightness(struct light_state_t const* state) + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8; } -#ifdef LED_NOTIFICATION -static void comp_led_states(struct led_state *red, struct led_state *blue, - struct light_state_t const* state) -{ - unsigned int color = state->color; - int delay_on, delay_off; - - switch (state->flashMode) { - case LIGHT_FLASH_TIMED: - delay_on = state->flashOnMS; - delay_off = state->flashOffMS; - break; - default: - ALOGI("Unsuported flashMode %d, default to NONE.", state->flashMode); - case LIGHT_FLASH_NONE: - delay_on = delay_off = 0; - break; - } - - red->enabled = !!(color >> 16 & 0xff); - red->delay_on = delay_on; - red->delay_off = delay_off; - - blue->enabled = !!(color & 0xff); - blue->delay_on = delay_on; - blue->delay_off = delay_off; - - ALOGV("comp_led_states: red=(%u, %d, %d), blue=(%u, %d, %d).", - red->enabled, red->delay_on, red->delay_off, blue->enabled, - blue->delay_on, blue->delay_off); -} - -static int set_led(char const *dir, struct led_state const *battery, - struct led_state const *notifications) -{ - - struct led_state const *state = NULL; - int res; - - if (notifications->enabled) - state = notifications; - else if (battery->enabled) - state = battery; - - if (state != NULL) { - int delay_on = state->delay_on; - int delay_off = state->delay_off; - - if (delay_on > 0 && delay_off > 0) { - /* Handling of blink_count is wrong in the kernel, blinking indefinitely - * for any non-zero value. TW lights just sets it to 1. */ - if ((res = write_df_str(dir, "trigger", "notification")) < 0) return res; - if ((res = write_df_str(dir, "brightness", "255" )) < 0) return res; - if ((res = write_df_str(dir, "blink_count", "1" )) < 0) return res; - if ((res = write_df_int(dir, "delay_on", delay_on )) < 0) return res; - if ((res = write_df_int(dir, "delay_off", delay_off )) < 0) return res; - } else { - if ((res = write_df_str(dir, "trigger", "none")) < 0) return res; - if ((res = write_df_str(dir, "brightness", "255" )) < 0) return res; - } - } else { - if ((res = write_df_str(dir, "trigger", "none")) < 0) return res; - if ((res = write_df_str(dir, "brightness", "0" )) < 0) return res; - } - - return 0; -} -#endif // LED_NOTIFICATION - static int set_light_backlight(struct light_device_t* dev, struct light_state_t const* state) @@ -234,14 +98,6 @@ set_light_backlight(struct light_device_t* dev, pthread_mutex_lock(&g_lock); err = write_int(PANEL_FILE, brightness); - -#ifndef EXYNOS4210_TABLET - if (!s_previous_brightness && (brightness > 0)) { - err = write_int(BUTTON_FILE, brightness > 0 ? 1 : 2); - s_previous_brightness = brightness; - } -#endif - pthread_mutex_unlock(&g_lock); return err; @@ -257,16 +113,9 @@ set_light_buttons(struct light_device_t* dev, int err = 0; int brightness = rgb_to_brightness(state); - load_settings(); - pthread_mutex_lock(&g_lock); - if (brightness > 0) { - ALOGD("set_light_buttons on=%d\n", g_enable_touchlight ? 1 : 0); - err = write_int(BUTTON_FILE, g_enable_touchlight ? 1 : 2); - } else { - ALOGD("set_light_buttons off\n"); - err = write_int(BUTTON_FILE, 2); - } + ALOGD("set_light_buttons: %d\n", brightness > 0 ? 1 : 2); + err = write_int(BUTTON_FILE, brightness > 0 ? 1 : 2); pthread_mutex_unlock(&g_lock); return err; @@ -277,46 +126,14 @@ static int set_light_battery(struct light_device_t* dev, struct light_state_t const* state) { - int res = 0; - -#ifdef LED_NOTIFICATION - ALOGD("set_light_battery: color=%#010x, fM=%u, fOnMS=%d, fOffMs=%d.", - state->color, state->flashMode, state->flashOnMS, state->flashOffMS); - - pthread_mutex_lock(&g_lock); - - comp_led_states(&battery_red, &battery_blue, state); - - if ((res = set_led(RED_LED_DIR, &battery_red, ¬ifications_red)) >= 0) - res = set_led(BLUE_LED_DIR, &battery_blue, ¬ifications_blue); - - pthread_mutex_unlock(&g_lock); -#endif // LED_NOTIFICATION - - return res; + return 0; } static int set_light_notification(struct light_device_t* dev, struct light_state_t const* state) { - int res = 0; - -#ifdef LED_NOTIFICATION - ALOGD("set_light_notification: color=%#010x, fM=%u, fOnMS=%d, fOffMs=%d.", - state->color, state->flashMode, state->flashOnMS, state->flashOffMS); - - pthread_mutex_lock(&g_lock); - - comp_led_states(¬ifications_red, ¬ifications_blue, state); - - if ((res = set_led(RED_LED_DIR, &battery_red, ¬ifications_red)) >= 0) - res = set_led(BLUE_LED_DIR, &battery_blue, ¬ifications_blue); - - pthread_mutex_unlock(&g_lock); -#endif // LED_NOTIFICATION - - return res; + return 0; } static int -- cgit v1.2.3 From 0189eda6e853a0fc32446a8fe018bb6602eb546a Mon Sep 17 00:00:00 2001 From: Daniel Hillenbrand Date: Fri, 23 Aug 2013 22:12:45 +0200 Subject: exynos4x12: liblights: generic button backlight implementation http://review.cyanogenmod.org/#/c/48922/ Change-Id: I929fcb4f1c2a912e026328cb09f9be527adbaea9 --- exynos4/exynos4x12/liblights/lights.c | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/exynos4/exynos4x12/liblights/lights.c b/exynos4/exynos4x12/liblights/lights.c index ec917c1..87fa134 100644 --- a/exynos4/exynos4x12/liblights/lights.c +++ b/exynos4/exynos4x12/liblights/lights.c @@ -148,6 +148,7 @@ static int get_dimmed_color(struct light_state_t const *state, int brightness) return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) + ((blue * brightness) / 255); } +/* Panel backlight */ static int set_light_backlight(struct light_device_t *dev, struct light_state_t const *state) { @@ -156,26 +157,30 @@ static int set_light_backlight(struct light_device_t *dev, int previous_brightness = read_int(PANEL_FILE); pthread_mutex_lock(&g_lock); - err = write_int(PANEL_FILE, brightness); - -#ifndef EXYNOS4X12_TABLET - if (!previous_brightness && (brightness > 0)) { - err = write_int(BUTTON_FILE, brightness > 0 ? 1 : 2); - } -#endif pthread_mutex_unlock(&g_lock); return err; } -static int close_lights(struct light_device_t *dev) +/* Touchkey backlight */ +static int +set_light_buttons(struct light_device_t* dev, + struct light_state_t const* state) { - ALOGV("close_light is called"); - if (dev) - free(dev); - +#ifdef EXYNOS4X12_TABLET return 0; +#else + int err = 0; + int brightness = rgb_to_brightness(state); + + pthread_mutex_lock(&g_lock); + ALOGD("set_light_buttons: %d\n", brightness > 0 ? 1 : 2); + err = write_int(BUTTON_FILE, brightness > 0 ? 1 : 2); + pthread_mutex_unlock(&g_lock); + + return err; +#endif } /* LEDs */ @@ -273,6 +278,15 @@ static int set_light_leds_attention(struct light_device_t *dev, return set_light_leds(state, 1); } +static int close_lights(struct light_device_t *dev) +{ + ALOGV("close_light is called"); + if (dev) + free(dev); + + return 0; +} + static int open_lights(const struct hw_module_t *module, char const *name, struct hw_device_t **device) { @@ -281,6 +295,8 @@ static int open_lights(const struct hw_module_t *module, char const *name, if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) set_light = set_light_backlight; + else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) + set_light = set_light_buttons; else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) set_light = set_light_leds_notifications; else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) -- cgit v1.2.3