summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2016-05-05 13:07:59 -0700
committerJohn Stultz <john.stultz@linaro.org>2016-05-10 11:27:41 -0700
commit5e924d3657b394ecaebd37e2df86b475b88801e8 (patch)
treedddb443569de5b9ddbeebb320ee72d6d7cec8dba
parentd10663e0a00efedb5d466b1a1d821c9a1b24c99f (diff)
downloadflo-5e924d3657b394ecaebd37e2df86b475b88801e8.tar.gz
flo: Add sysfs based lights HAL for backlight
Brorrow the flounder lights HAL to support the generic sysfs backlight interface for the upstream flo panel. Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--device-common.mk2
-rw-r--r--init.flo.rc4
-rw-r--r--lights/Android.mk32
-rw-r--r--lights/lights.c156
4 files changed, 193 insertions, 1 deletions
diff --git a/device-common.mk b/device-common.mk
index 3bc4e9b..6a19e9c 100644
--- a/device-common.mk
+++ b/device-common.mk
@@ -34,7 +34,7 @@ PRODUCT_PACKAGES := \
wpa_supplicant.conf
PRODUCT_PACKAGES += \
- lights.msm8960
+ lights.flo
PRODUCT_PACKAGES += \
charger_res_images
diff --git a/init.flo.rc b/init.flo.rc
index d9fb3fe..9b839e1 100644
--- a/init.flo.rc
+++ b/init.flo.rc
@@ -159,6 +159,10 @@ on post-fs-data
mkdir /data/system 0775 system system
#symlink /data/misc/wifi/wpa_supplicant /data/system/wpa_supplicant
+ # set perms on backlight
+ chown system system /sys/class/backlight/4700000.qcom,mdss_dsi.0/brightness
+ chmod 0664 /sys/class/backlight/4700000.qcom,mdss_dsi.0/brightness
+
#Create directory used by sensor subsystem(dsps)
mkdir /data/system/sensors
chmod 775 /data/system/sensors
diff --git a/lights/Android.mk b/lights/Android.mk
new file mode 100644
index 0000000..e39d05a
--- /dev/null
+++ b/lights/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2008 The Android 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# HAL module implemenation, not prelinked and stored in
+# hw/<COPYPIX_HARDWARE_MODULE_ID>.<ro.board.platform>.so
+
+LOCAL_SRC_FILES := lights.c
+
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SHARED_LIBRARIES := liblog
+
+LOCAL_MODULE := lights.flo
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/lights/lights.c b/lights/lights.c
new file mode 100644
index 0000000..79ac361
--- /dev/null
+++ b/lights/lights.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2008 The Android 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 <malloc.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <hardware/lights.h>
+#include <hardware/hardware.h>
+
+static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
+char const* const MODE_RGB_FILE = "/sys/class/leds/indicator/ModeRGB";
+char const* const BACKLIGHT_FILE = "/sys/class/backlight/4700000.qcom,mdss_dsi.0/brightness";
+static int write_int(char const *path, int value)
+{
+ int fd;
+ static int already_warned = -1;
+ fd = open(path, O_RDWR);
+ if (fd >= 0) {
+ char buffer[20];
+ int bytes = snprintf(buffer, 20, "%d\n", value);
+ int amt = write(fd, buffer, bytes);
+ close(fd);
+ return amt == -1 ? -errno : 0;
+ } else {
+ if (already_warned == -1) {
+ ALOGE("write_int failed to open %s\n", path);
+ already_warned = 1;
+ }
+ return -errno;
+ }
+}
+
+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_notifications(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ int err = 0;
+#if 0
+ pthread_mutex_lock(&g_lock);
+ ALOGV("set_light_notifications, flashMode:%x, color:%x", state->flashMode, state->color);
+ if(state->flashMode)
+ err = write_int(MODE_RGB_FILE, 0x6ffffff);
+ else
+ err = write_int(MODE_RGB_FILE, 0x00);
+ pthread_mutex_unlock(&g_lock);
+#endif
+ return err;
+}
+
+static int set_light_backlight(struct light_device_t *dev,
+ struct light_state_t const *state)
+{
+ int err;
+ int brightness = rgb_to_brightness(state);
+
+ pthread_mutex_lock(&g_lock);
+ err = write_int(BACKLIGHT_FILE, brightness);
+ pthread_mutex_unlock(&g_lock);
+
+ return err;
+}
+
+/** Close the lights device */
+static int close_lights(struct light_device_t *dev)
+{
+ if (dev)
+ free(dev);
+ return 0;
+}
+
+/** 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)
+{
+ struct light_device_t *dev = malloc(sizeof(struct light_device_t));
+ int (*set_light) (struct light_device_t *dev,
+ struct light_state_t const *state);
+ pthread_t lighting_poll_thread;
+ ALOGV("open lights");
+ if (dev == NULL) {
+ ALOGE("failed to allocate memory");
+ return -1;
+ }
+ memset(dev, 0, sizeof(*dev));
+
+ if (0 == strcmp(LIGHT_ID_BACKLIGHT, name))
+ set_light = set_light_backlight;
+#if 0
+ else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name))
+ set_light = set_light_notifications;
+#endif
+ else
+ return -EINVAL;
+
+ pthread_mutex_init(&g_lock, NULL);
+
+ 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_methods =
+{
+ .open = open_lights,
+};
+
+/*
+ * The backlight Module
+ */
+struct hw_module_t HAL_MODULE_INFO_SYM =
+{
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = LIGHTS_HARDWARE_MODULE_ID,
+ .name = "Flo/mainline lights module",
+ .author = "NVIDIA,Linaro",
+ .methods = &lights_methods,
+};