Vibra: Adapt AOSP (default) vibrator HAL into a hardware module.

Android's implementation of vibrator needs to be done inside a
hardware module, so that it can make a vendor implementation possible.

Hw module's name becomes vibrator.default.so.

This change is related to other changes in:
 - frameworks/base
 - hardware/libhardware_legacy
 - device/generic/goldfish
 - platform/build

Change-Id: I844279f5535289f079d412fdc44c5cb3c9c1130c
Author: Vincent Becker <vincentx.becker@intel.com>
Signed-off-by: Vincent Becker <vincentx.becker@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: David Wagner <david.wagner@intel.com>
Author-tracking-BZ: 49760 94611
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