--- /dev/null
+/*
+ * Copyright (C) 2009 The Android-x86 Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#define LOG_TAG "lights"
+
+#include <cutils/log.h>
+
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <hardware/lights.h>
+
+/******************************************************************************/
+
+static pthread_once_t g_init = PTHREAD_ONCE_INIT;
+static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
+static int g_haveTrackballLight = 0;
+static struct light_state_t g_notification;
+static struct light_state_t g_battery;
+static int g_backlight = 255;
+static int g_trackball = -1;
+static int g_buttons = 0;
+static int g_attention = 0;
+
+/**
+ * device methods
+ */
+
+void init_globals(void)
+{
+ // init the mutex
+ pthread_mutex_init(&g_lock, NULL);
+}
+
+static int
+write_int(char const* path, int value)
+{
+ int fd;
+ static int already_warned = 0;
+
+ fd = open(path, O_RDWR);
+ if (fd >= 0) {
+ char buffer[20];
+ int bytes = sprintf(buffer, "%d\n", value);
+ int amt = write(fd, buffer, bytes);
+ close(fd);
+ return amt == -1 ? -errno : 0;
+ } else {
+ if (already_warned == 0) {
+ LOGE("write_int failed to open %s\n", path);
+ already_warned = 1;
+ }
+ return -errno;
+ }
+}
+
+static int
+is_lit(struct light_state_t const* state)
+{
+ return state->color & 0x00ffffff;
+}
+
+static int
+rgb_to_brightness(struct light_state_t const* state)
+{
+ int color = state->color & 0x00ffffff;
+ return ((77*((color>>16)&0x00ff))
+ + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
+}
+
+static int
+set_light_backlight(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ int err = 0;
+ int brightness = rgb_to_brightness(state); // brightness range: 0 - 255
+ pthread_mutex_lock(&g_lock);
+ g_backlight = brightness;
+ err = write_int("/sys/class/backlight/vilivs5-bl/brightness", brightness>>4); // eeepc brightness range: 0 - 15
+ LOGI("set_light_backlight brightness=%d, brightness>>4 = %d\n", brightness, brightness>>4);
+ if (g_haveTrackballLight) {
+ handle_trackball_light_locked(dev);
+ }
+ pthread_mutex_unlock(&g_lock);
+ return err;
+}
+
+static int
+set_light_keyboard(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ int err = 0;
+ /*
+ int on = is_lit(state);
+ pthread_mutex_lock(&g_lock);
+ err = write_int("/sys/class/leds/keyboard-backlight/brightness", on?255:0);
+ pthread_mutex_unlock(&g_lock);
+ */
+ return err;
+}
+
+static int
+set_light_buttons(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ int err = 0;
+ /*
+ int on = is_lit(state);
+ pthread_mutex_lock(&g_lock);
+ g_buttons = on;
+ err = write_int("/sys/class/leds/button-backlight/brightness", on?255:0);
+ pthread_mutex_unlock(&g_lock);
+ */
+ return err;
+}
+
+static void
+handle_speaker_battery_locked(struct light_device_t* dev)
+{
+ /*
+ if (is_lit(&g_battery)) {
+ set_speaker_light_locked(dev, &g_battery);
+ } else {
+ set_speaker_light_locked(dev, &g_notification);
+ }
+ */
+}
+
+static int
+set_light_battery(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ /*
+ pthread_mutex_lock(&g_lock);
+ g_battery = *state;
+ if (g_haveTrackballLight) {
+ set_speaker_light_locked(dev, state);
+ }
+ handle_speaker_battery_locked(dev);
+ pthread_mutex_unlock(&g_lock);
+ */
+ return 0;
+}
+
+static int
+set_light_notifications(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ /*
+ pthread_mutex_lock(&g_lock);
+ g_notification = *state;
+ LOGV("set_light_notifications g_trackball=%d color=0x%08x",
+ g_trackball, state->color);
+ if (g_haveTrackballLight) {
+ handle_trackball_light_locked(dev);
+ }
+ handle_speaker_battery_locked(dev);
+ pthread_mutex_unlock(&g_lock);
+ */
+ return 0;
+}
+
+static int
+set_light_attention(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ /*
+ pthread_mutex_lock(&g_lock);
+ g_notification = *state;
+ LOGV("set_light_attention g_trackball=%d color=0x%08x",
+ g_trackball, state->color);
+ g_attention = rgb_to_brightness(state);
+ if (g_haveTrackballLight) {
+ handle_trackball_light_locked(dev);
+ }
+ pthread_mutex_unlock(&g_lock);
+ */
+ return 0;
+}
+
+
+/** Close the lights device */
+static int
+close_lights(struct light_device_t *dev)
+{
+ if (dev) {
+ free(dev);
+ }
+ return 0;
+}
+
+
+/******************************************************************************/
+
+/**
+ * module methods
+ */
+
+/** Open a new instance of a lights device using name */
+static int open_lights(const struct hw_module_t* module, char const* name,
+ struct hw_device_t** device)
+{
+ int (*set_light)(struct light_device_t* dev,
+ struct light_state_t const* state);
+
+ if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) {
+ set_light = set_light_backlight;
+ }
+ else if (0 == strcmp(LIGHT_ID_KEYBOARD, name)) {
+ set_light = set_light_keyboard;
+ }
+ else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) {
+ set_light = set_light_buttons;
+ }
+ else if (0 == strcmp(LIGHT_ID_BATTERY, name)) {
+ set_light = set_light_battery;
+ }
+ else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) {
+ set_light = set_light_notifications;
+ }
+ else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) {
+ set_light = set_light_attention;
+ }
+ else {
+ return -EINVAL;
+ }
+
+ pthread_once(&g_init, init_globals);
+
+ struct light_device_t *dev = malloc(sizeof(struct light_device_t));
+ memset(dev, 0, sizeof(*dev));
+
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t*)module;
+ dev->common.close = (int (*)(struct hw_device_t*))close_lights;
+ dev->set_light = set_light;
+
+ *device = (struct hw_device_t*)dev;
+ return 0;
+}
+
+
+static struct hw_module_methods_t lights_module_methods = {
+ .open = open_lights,
+};
+
+/*
+ * The lights Module
+ */
+const struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = LIGHTS_HARDWARE_MODULE_ID,
+ .name = "S5 lights Module",
+ .author = "kelly2.blue@gmail.com",
+ .methods = &lights_module_methods,
+};
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.32.15
-# Tue Jun 29 15:08:16 2010
+# Tue Jun 29 16:20:18 2010
#
# CONFIG_64BIT is not set
CONFIG_X86_32=y
CONFIG_INET=y
# CONFIG_IP_MULTICAST is not set
# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_ASK_IP_FIB_HASH is not set
-# CONFIG_IP_FIB_TRIE is not set
CONFIG_IP_FIB_HASH=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
# CONFIG_INET_DIAG is not set
# CONFIG_TCP_CONG_ADVANCED is not set
CONFIG_TCP_CONG_CUBIC=y
-# CONFIG_DEFAULT_BIC is not set
-# CONFIG_DEFAULT_CUBIC is not set
-# CONFIG_DEFAULT_HTCP is not set
-# CONFIG_DEFAULT_VEGAS is not set
-# CONFIG_DEFAULT_WESTWOOD is not set
-# CONFIG_DEFAULT_RENO is not set
CONFIG_DEFAULT_TCP_CONG="cubic"
# CONFIG_TCP_MD5SIG is not set
CONFIG_IPV6=y
# CONFIG_NETFILTER is not set
# CONFIG_IP_DCCP is not set
# CONFIG_IP_SCTP is not set
-# CONFIG_SCTP_HMAC_NONE is not set
-# CONFIG_SCTP_HMAC_SHA1 is not set
-# CONFIG_SCTP_HMAC_MD5 is not set
# CONFIG_RDS is not set
# CONFIG_TIPC is not set
# CONFIG_ATM is not set
# CONFIG_HOSTAP is not set
# CONFIG_B43 is not set
# CONFIG_B43LEGACY is not set
-# CONFIG_B43LEGACY_DMA_AND_PIO_MODE is not set
-# CONFIG_B43LEGACY_DMA_MODE is not set
-# CONFIG_B43LEGACY_PIO_MODE is not set
# CONFIG_ZD1211RW is not set
# CONFIG_RT2X00 is not set
# CONFIG_HERMES is not set
# CONFIG_AGP_EFFICEON is not set
CONFIG_VGA_ARB=y
# CONFIG_DRM is not set
-# CONFIG_DRM_I830 is not set
-# CONFIG_DRM_I915 is not set
# CONFIG_VGASTATE is not set
CONFIG_VIDEO_OUTPUT_CONTROL=y
CONFIG_FB=y
# CONFIG_FB_ARK is not set
# CONFIG_FB_PM3 is not set
# CONFIG_FB_CARMINE is not set
-# CONFIG_FB_CARMINE_DRAM_EVAL is not set
-# CONFIG_CARMINE_DRAM_CUSTOM is not set
# CONFIG_FB_GEODE is not set
# CONFIG_FB_VIRTUAL is not set
# CONFIG_FB_METRONOME is not set
# CONFIG_BACKLIGHT_PROGEAR is not set
# CONFIG_BACKLIGHT_MBP_NVIDIA is not set
# CONFIG_BACKLIGHT_SAHARA is not set
+CONFIG_BACKLIGHT_VILIVS5=y
#
# Display device support
# CONFIG_USB_R8A66597_HCD is not set
# CONFIG_USB_WHCI_HCD is not set
# CONFIG_USB_HWA_HCD is not set
-# CONFIG_USB_GADGET_MUSB_HDRC is not set
#
# USB Device Class drivers
# CONFIG_USB_ISIGHTFW is not set
# CONFIG_USB_VST is not set
# CONFIG_USB_GADGET is not set
-# CONFIG_USB_GADGET_AT91 is not set
-# CONFIG_USB_GADGET_ATMEL_USBA is not set
-# CONFIG_USB_GADGET_FSL_USB2 is not set
-# CONFIG_USB_GADGET_LH7A40X is not set
-# CONFIG_USB_GADGET_OMAP is not set
-# CONFIG_USB_GADGET_PXA25X is not set
-# CONFIG_USB_GADGET_R8A66597 is not set
-# CONFIG_USB_GADGET_PXA27X is not set
-# CONFIG_USB_GADGET_S3C_HSOTG is not set
-# CONFIG_USB_GADGET_IMX is not set
-# CONFIG_USB_GADGET_S3C2410 is not set
-# CONFIG_USB_GADGET_M66592 is not set
-# CONFIG_USB_GADGET_AMD5536UDC is not set
-# CONFIG_USB_GADGET_FSL_QE is not set
-# CONFIG_USB_GADGET_CI13XXX is not set
-# CONFIG_USB_GADGET_NET2280 is not set
-# CONFIG_USB_GADGET_GOKU is not set
-# CONFIG_USB_GADGET_LANGWELL is not set
-# CONFIG_USB_GADGET_DUMMY_HCD is not set
-# CONFIG_USB_ZERO is not set
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_ETH is not set
-# CONFIG_USB_GADGETFS is not set
-# CONFIG_USB_FILE_STORAGE is not set
-# CONFIG_USB_G_SERIAL is not set
-# CONFIG_USB_MIDI_GADGET is not set
-# CONFIG_USB_G_PRINTER is not set
-# CONFIG_USB_ANDROID is not set
-# CONFIG_USB_CDC_COMPOSITE is not set
#
# OTG and related infrastructure
# CONFIG_BEFS_FS is not set
# CONFIG_BFS_FS is not set
# CONFIG_EFS_FS is not set
-# CONFIG_JFFS2_CMODE_NONE is not set
-# CONFIG_JFFS2_CMODE_PRIORITY is not set
-# CONFIG_JFFS2_CMODE_SIZE is not set
-# CONFIG_JFFS2_CMODE_FAVOURLZO is not set
# CONFIG_CRAMFS is not set
CONFIG_SQUASHFS=y
# CONFIG_SQUASHFS_EMBEDDED is not set
# CONFIG_HPFS_FS is not set
# CONFIG_QNX4FS_FS is not set
# CONFIG_ROMFS_FS is not set
-# CONFIG_ROMFS_BACKED_BY_BLOCK is not set
-# CONFIG_ROMFS_BACKED_BY_MTD is not set
-# CONFIG_ROMFS_BACKED_BY_BOTH is not set
# CONFIG_SYSV_FS is not set
# CONFIG_UFS_FS is not set
CONFIG_NETWORK_FILESYSTEMS=y
CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
CONFIG_TRACING_SUPPORT=y
# CONFIG_FTRACE is not set
-# CONFIG_BRANCH_PROFILE_NONE is not set
-# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
-# CONFIG_PROFILE_ALL_BRANCHES is not set
# CONFIG_PROVIDE_OHCI1394_DMA_INIT is not set
# CONFIG_DYNAMIC_DEBUG is not set
# CONFIG_DMA_API_DEBUG is not set