[2 of 4][ALM:10923711] [FP4]:develope aw8695 vibrator

 &&&%%%comment:[FP4]:develope aw8695 vibrator
 &&&%%%bug number:10923711
 &&&%%%product name:sm7225_r_fp4
 &&&%%%root cause:Coding
 &&&%%%Bug category:T2M
 &&&%%%Module_Impact:HAL
 &&&%%%Test_Suggestion:reset
 &&&%%%Solution:develope hal
 &&&%%%Test_Report:local test is ok
 &&&%%%VAL Can Test:NO

Change-Id: Ice57d70ef64d9b2d688b1e8c39110ac08f93de46
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
index 8042b57..bb0ce67 100644
--- a/modules/vibrator/vibrator.c
+++ b/modules/vibrator/vibrator.c
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "vibrator_hw"
+#define LOG_NDEBUG 1
 #include <hardware/hardware.h>
 #include <hardware/vibrator.h>
 
@@ -136,6 +138,71 @@
     return write_led_file("activate", "0");
 }
 
+static const char AW_DEVICE[] = "/sys/class/leds/vibrator_aw8695";
+static int write_aw_file(const char *file, const char *value)
+{
+    char file_str[50];
+
+    snprintf(file_str, sizeof(file_str), "%s/%s", AW_DEVICE, file);
+    return write_value(file_str, value);
+}
+
+static bool vibra_aw_exists()
+{
+    char file_str[50];
+
+    snprintf(file_str, sizeof(file_str), "%s/%s", AW_DEVICE, "activate");
+    return device_exists(file_str);
+}
+
+static int vibra_aw_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
+{
+    int ret;
+    char value[TIMEOUT_STR_LEN]; /* large enough for millions of years */
+
+    ALOGI("%s time = %d ", __func__,timeout_ms);
+    if(timeout_ms <= 50) // MODIFIED by hongwei.tian, 2019-12-18,BUG-8509225
+    {
+        ret = write_aw_file("seq", "0x00 0x01");
+        if (ret)
+            return ret;
+        ret = write_aw_file("seq", "0x01 0x00");
+        if (ret)
+            return ret;
+        ret = write_aw_file("loop", "0x00 0x00");
+        if (ret)
+            return ret;
+        ret = write_aw_file("brightness", "1");
+        if (ret)
+            return ret;
+        ALOGI("%s short viber = %d ", __func__,timeout_ms);
+        return 0;
+    }
+    ret = write_aw_file("activate_mode", "0");
+    if (ret)
+        return ret;
+
+    ret = write_aw_file("index", "2");
+    if (ret)
+        return ret;
+
+    snprintf(value, sizeof(value), "%u\n", timeout_ms);
+    ret = write_aw_file("duration", value);
+    if (ret)
+        return ret;
+
+    return write_aw_file("activate", "1");
+}
+
+static int vibra_aw_off(vibrator_device_t* vibradev __unused)
+{
+    return write_aw_file("activate", "0");
+}
+typedef enum VIBRA_TYPE {
+	VIBRA_TIMEOUT = 0,
+	VIBRA_LED,
+    VIBRA_AW,
+}VIBRA_TYPE;
 static int vibra_close(hw_device_t *device)
 {
     free(device);
@@ -145,13 +212,22 @@
 static int vibra_open(const hw_module_t* module, const char* id __unused,
                       hw_device_t** device __unused) {
     bool use_led;
+    VIBRA_TYPE  vibra_type = VIBRA_LED;
 
-    if (vibra_exists()) {
+    /* MODIFIED-BEGIN by hongwei.tian, 2020-06-02,BUG-9491648*/
+    if (vibra_aw_exists()) {
+        ALOGD("Vibrator using LED AW trigger");
+        use_led = true;
+        vibra_type = VIBRA_AW;
+    } else if (vibra_exists()) {
+    /* MODIFIED-END by hongwei.tian,BUG-9491648*/
         ALOGD("Vibrator using timed_output");
+        vibra_type = VIBRA_TIMEOUT;
         use_led = false;
     } else if (vibra_led_exists()) {
         ALOGD("Vibrator using LED trigger");
         use_led = true;
+        vibra_type = VIBRA_LED;
     } else {
         ALOGE("Vibrator device does not exist. Cannot start vibrator");
         return -ENODEV;
@@ -170,8 +246,16 @@
     vibradev->common.close = vibra_close;
 
     if (use_led) {
-        vibradev->vibrator_on = vibra_led_on;
-        vibradev->vibrator_off = vibra_led_off;
+        if(vibra_type == VIBRA_LED)
+        {
+            vibradev->vibrator_on = vibra_led_on;
+            vibradev->vibrator_off = vibra_led_off;
+        }
+        else
+        {
+            vibradev->vibrator_on = vibra_aw_on;
+            vibradev->vibrator_off = vibra_aw_off;
+        }
     } else {
         vibradev->vibrator_on = vibra_on;
         vibradev->vibrator_off = vibra_off;