Merge "Header file for HDMI-CEC HAL interface definition" into klp-modular-dev
diff --git a/include/hardware/mcu.h b/include/hardware/mcu.h
new file mode 100644
index 0000000..6fe2cfe
--- /dev/null
+++ b/include/hardware/mcu.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef ANDROID_INCLUDE_HARDWARE_MCU_H
+#define ANDROID_INCLUDE_HARDWARE_MCU_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define MCU_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+/*
+ * The id of this module
+ */
+#define MCU_HARDWARE_MODULE_ID "mcu"
+
+/*
+ * MCU message keys passed to (*sendMessage)
+ */
+#define MCU_PARAMETER_MSG_ENABLE_MCU "enable_mcu"
+
+/*
+ * MCU message values passed to (*sendMessage)
+ */
+#define MCU_PARAMETER_ARG_ON "on"
+#define MCU_PARAMETER_ARG_OFF "off"
+
+/*
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct mcu_module {
+ struct hw_module_t common;
+
+ /*
+ * (*init)() performs MCU module setup actions at runtime startup, such
+ * as to initialize an external MCU. This is called only by the MCU HAL
+ * instance loaded by PowerManagerService.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*init)(struct mcu_module *module);
+
+ /*
+ * (*sendMessage)() passes a message/argument pair to the MCU to execute
+ * a function. msg is NULL-terminated. If arg is text, then arg_len must
+ * reflect the string length. result is a heap-allocated buffer that the
+ * caller must free. If there is no result, then *result will be NULL and
+ * *result_len will be 0.
+ *
+ * Returns 0 on success or -errno in case of error (for example, if the
+ * MCU does not support the specified message.)
+ *
+ */
+ int (*sendMessage)(struct mcu_module *module, const char *msg,
+ const void *arg, size_t arg_len, void **result,
+ size_t *result_len);
+
+} mcu_module_t;
+
+__END_DECLS
+
+#endif // ANDROID_INCLUDE_HARDWARE_MCU_H
diff --git a/include/hardware/vibrator.h b/include/hardware/vibrator.h
new file mode 100644
index 0000000..795d23e
--- /dev/null
+++ b/include/hardware/vibrator.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef _HARDWARE_VIBRATOR_H
+#define _HARDWARE_VIBRATOR_H
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0)
+
+/**
+ * The id of this module
+ */
+#define VIBRATOR_HARDWARE_MODULE_ID "vibrator"
+
+/**
+ * The id of the main vibrator device
+ */
+#define VIBRATOR_DEVICE_ID_MAIN "main_vibrator"
+
+struct vibrator_device;
+typedef struct vibrator_device {
+ struct hw_device_t common;
+
+ /** Turn on vibrator
+ *
+ * What happens when this function is called while the the timeout of a
+ * previous call has not expired is implementation dependent.
+ *
+ * @param timeout_ms number of milliseconds to vibrate
+ *
+ * @return 0 in case of success, negative errno code else
+ */
+ int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms);
+
+ /** Turn off vibrator
+ *
+ * It is not guaranteed that the vibrator will be immediately stopped: the
+ * behaviour is implementation dependent.
+ *
+ * @return 0 in case of success, negative errno code else
+ */
+ int (*vibrator_off)(struct vibrator_device* vibradev);
+} vibrator_device_t;
+
+static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device)
+{
+ return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device);
+}
+
+__END_DECLS
+
+#endif // _HARDWARE_VIBRATOR_H
diff --git a/modules/Android.mk b/modules/Android.mk
index 1935b11..f1a6c1c 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,3 +1,4 @@
hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \
- power usbaudio audio_remote_submix camera consumerir sensors
+ power usbaudio audio_remote_submix camera consumerir sensors vibrator \
+ mcu
include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index f773079..49ed312 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -23,7 +23,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.primary.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_hw.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
@@ -35,7 +35,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio_policy.stub
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_policy.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
index 5f54902..50c8cb2 100644
--- a/modules/audio_remote_submix/Android.mk
+++ b/modules/audio_remote_submix/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.r_submix.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
audio_hw.cpp
LOCAL_C_INCLUDES += \
diff --git a/modules/camera/Android.mk b/modules/camera/Android.mk
index e02a143..fbe44c5 100644
--- a/modules/camera/Android.mk
+++ b/modules/camera/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := camera.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_C_INCLUDES += \
system/core/include \
diff --git a/modules/consumerir/Android.mk b/modules/consumerir/Android.mk
index ed6aa0f..b881572 100644
--- a/modules/consumerir/Android.mk
+++ b/modules/consumerir/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := consumerir.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := consumerir.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
index b24c4cd..e1fd7d4 100644
--- a/modules/gralloc/Android.mk
+++ b/modules/gralloc/Android.mk
@@ -19,7 +19,7 @@
# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_SRC_FILES := \
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index f1e819b..35c0fae 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -19,7 +19,7 @@
# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SHARED_LIBRARIES := liblog libEGL
LOCAL_SRC_FILES := hwcomposer.cpp
LOCAL_MODULE := hwcomposer.default
diff --git a/modules/local_time/Android.mk b/modules/local_time/Android.mk
index f840dc7..91885aa 100644
--- a/modules/local_time/Android.mk
+++ b/modules/local_time/Android.mk
@@ -26,7 +26,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := local_time.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := local_time_hw.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/mcu/Android.mk b/modules/mcu/Android.mk
new file mode 100644
index 0000000..ec40e3a
--- /dev/null
+++ b/modules/mcu/Android.mk
@@ -0,0 +1,25 @@
+# Copyright (C) 2014 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)
+
+LOCAL_MODULE := mcu.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := mcu.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/mcu/mcu.c b/modules/mcu/mcu.c
new file mode 100644
index 0000000..47300f9
--- /dev/null
+++ b/modules/mcu/mcu.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define LOG_TAG "Legacy MCU HAL"
+#include <utils/Log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/mcu.h>
+
+static int mcu_init(struct mcu_module *module)
+{
+ return 0;
+}
+
+static int mcu_send_message(struct mcu_module *module, const char *msg,
+ const void *arg, size_t arg_len, void **result,
+ size_t *result_len)
+{
+ return 0;
+}
+
+static struct hw_module_methods_t mcu_module_methods = {
+ .open = NULL,
+};
+
+struct mcu_module HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = MCU_MODULE_API_VERSION_0_1,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = MCU_HARDWARE_MODULE_ID,
+ .name = "Default MCU HAL",
+ .author = "The Android Open Source Project",
+ .methods = &mcu_module_methods,
+ },
+
+ .init = mcu_init,
+ .sendMessage = mcu_send_message,
+};
diff --git a/modules/nfc-nci/Android.mk b/modules/nfc-nci/Android.mk
index 97262ef..c1f679a 100644
--- a/modules/nfc-nci/Android.mk
+++ b/modules/nfc-nci/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := nfc_nci.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := nfc_nci_example.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/nfc/Android.mk b/modules/nfc/Android.mk
index 429fb43..29b239c 100644
--- a/modules/nfc/Android.mk
+++ b/modules/nfc/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := nfc.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := nfc_pn544_example.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/power/Android.mk b/modules/power/Android.mk
index 50ab221..c868ded 100644
--- a/modules/power/Android.mk
+++ b/modules/power/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := power.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := power.c
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE_TAGS := optional
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index 6b5e66d..199eb09 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.usb.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
audio_hw.c
LOCAL_C_INCLUDES += \
diff --git a/modules/vibrator/Android.mk b/modules/vibrator/Android.mk
new file mode 100644
index 0000000..b6b480c
--- /dev/null
+++ b/modules/vibrator/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2012 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)
+
+LOCAL_MODULE := vibrator.default
+
+# HAL module implementation stored in
+# hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_C_INCLUDES := hardware/libhardware
+LOCAL_SRC_FILES := vibrator.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
new file mode 100644
index 0000000..ce4c03c
--- /dev/null
+++ b/modules/vibrator/vibrator.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <hardware/vibrator.h>
+#include <hardware/hardware.h>
+
+#include <cutils/log.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+
+static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable";
+
+static int vibra_exists() {
+ int fd;
+
+ fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+ if(fd < 0) {
+ ALOGE("Vibrator file does not exist : %d", fd);
+ return 0;
+ }
+
+ close(fd);
+ return 1;
+}
+
+static int sendit(unsigned int timeout_ms)
+{
+ int to_write, written, ret, fd;
+
+ char value[20]; /* large enough for millions of years */
+
+ fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+ if(fd < 0) {
+ return -errno;
+ }
+
+ to_write = snprintf(value, sizeof(value), "%u\n", timeout_ms);
+ written = TEMP_FAILURE_RETRY(write(fd, value, to_write));
+
+ if (written == -1) {
+ ret = -errno;
+ } else if (written != to_write) {
+ /* even though EAGAIN is an errno value that could be set
+ by write() in some cases, none of them apply here. So, this return
+ value can be clearly identified when debugging and suggests the
+ caller that it may try to call vibraror_on() again */
+ ret = -EAGAIN;
+ } else {
+ ret = 0;
+ }
+
+ errno = 0;
+ close(fd);
+
+ return ret;
+}
+
+static int vibra_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
+{
+ /* constant on, up to maximum allowed time */
+ return sendit(timeout_ms);
+}
+
+static int vibra_off(vibrator_device_t* vibradev __unused)
+{
+ return sendit(0);
+}
+
+static int vibra_close(hw_device_t *device)
+{
+ free(device);
+ return 0;
+}
+
+static int vibra_open(const hw_module_t* module, const char* id __unused,
+ hw_device_t** device __unused) {
+ if (!vibra_exists()) {
+ ALOGE("Vibrator device does not exist. Cannot start vibrator");
+ return -ENODEV;
+ }
+
+ vibrator_device_t *vibradev = calloc(1, sizeof(vibrator_device_t));
+
+ if (!vibradev) {
+ ALOGE("Can not allocate memory for the vibrator device");
+ return -ENOMEM;
+ }
+
+ vibradev->common.tag = HARDWARE_DEVICE_TAG;
+ vibradev->common.module = (hw_module_t *) module;
+ vibradev->common.version = HARDWARE_DEVICE_API_VERSION(1,0);
+ vibradev->common.close = vibra_close;
+
+ vibradev->vibrator_on = vibra_on;
+ vibradev->vibrator_off = vibra_off;
+
+ *device = (hw_device_t *) vibradev;
+
+ return 0;
+}
+
+/*===========================================================================*/
+/* Default vibrator HW module interface definition */
+/*===========================================================================*/
+
+static struct hw_module_methods_t vibrator_module_methods = {
+ .open = vibra_open,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = VIBRATOR_API_VERSION,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = VIBRATOR_HARDWARE_MODULE_ID,
+ .name = "Default vibrator HAL",
+ .author = "The Android Open Source Project",
+ .methods = &vibrator_module_methods,
+};