Merge "AArch64: Port invensense"
diff --git a/60xx/libsensors/MPLSensor.cpp b/60xx/libsensors/MPLSensor.cpp
index d669bf4..1346ef1 100644
--- a/60xx/libsensors/MPLSensor.cpp
+++ b/60xx/libsensors/MPLSensor.cpp
@@ -1047,7 +1047,7 @@
 
 int MPLSensor::getPowerFd() const
 {
-    int hdl = (int) inv_get_serial_handle();
+    int hdl = (uintptr_t) inv_get_serial_handle();
     //ALOGV("MPLSensor::getPowerFd returning %d", hdl);
     return hdl;
 }
@@ -1068,7 +1068,7 @@
     VFUNC_LOG;
     mpuirq_data irqd;
 
-    int fd = (int) inv_get_serial_handle();
+    int fd = (uintptr_t) inv_get_serial_handle();
     read(fd, &irqd, sizeof(irqd));
 
     if (irqd.data == MPU_PM_EVENT_SUSPEND_PREPARE) {
diff --git a/60xx/mlsdk/mllite/mldl_cfg_mpu.c b/60xx/mlsdk/mllite/mldl_cfg_mpu.c
index f89f94c..3d4496e 100644
--- a/60xx/mlsdk/mllite/mldl_cfg_mpu.c
+++ b/60xx/mlsdk/mllite/mldl_cfg_mpu.c
@@ -84,9 +84,9 @@
 #endif
 
     if (mldl_cfg->accel) {
-        MPL_LOGD("slave_accel->suspend      = %02x\n", (int)mldl_cfg->accel->suspend);
-        MPL_LOGD("slave_accel->resume       = %02x\n", (int)mldl_cfg->accel->resume);
-        MPL_LOGD("slave_accel->read         = %02x\n", (int)mldl_cfg->accel->read);
+        MPL_LOGD("slave_accel->suspend      = %p\n", mldl_cfg->accel->suspend);
+        MPL_LOGD("slave_accel->resume       = %p\n", mldl_cfg->accel->resume);
+        MPL_LOGD("slave_accel->read         = %p\n", mldl_cfg->accel->read);
         MPL_LOGD("slave_accel->type         = %02x\n", mldl_cfg->accel->type);
         MPL_LOGD("slave_accel->read_reg     = %02x\n",
                  mldl_cfg->accel->read_reg);
@@ -100,9 +100,9 @@
     }
 
     if (mldl_cfg->compass) {
-        MPL_LOGD("slave_compass->suspend    = %02x\n", (int)mldl_cfg->compass->suspend);
-        MPL_LOGD("slave_compass->resume     = %02x\n", (int)mldl_cfg->compass->resume);
-        MPL_LOGD("slave_compass->read       = %02x\n", (int)mldl_cfg->compass->read);
+        MPL_LOGD("slave_compass->suspend    = %p\n", mldl_cfg->compass->suspend);
+        MPL_LOGD("slave_compass->resume     = %p\n", mldl_cfg->compass->resume);
+        MPL_LOGD("slave_compass->read       = %p\n", mldl_cfg->compass->read);
         MPL_LOGD("slave_compass->type       = %02x\n", mldl_cfg->compass->type);
         MPL_LOGD("slave_compass->read_reg   = %02x\n",
                  mldl_cfg->compass->read_reg);
@@ -116,9 +116,9 @@
     }
 
     if (mldl_cfg->pressure) {
-        MPL_LOGD("slave_pressure->suspend    = %02x\n", (int)mldl_cfg->pressure->suspend);
-        MPL_LOGD("slave_pressure->resume     = %02x\n", (int)mldl_cfg->pressure->resume);
-        MPL_LOGD("slave_pressure->read       = %02x\n", (int)mldl_cfg->pressure->read);
+        MPL_LOGD("slave_pressure->suspend    = %p\n", mldl_cfg->pressure->suspend);
+        MPL_LOGD("slave_pressure->resume     = %p\n", mldl_cfg->pressure->resume);
+        MPL_LOGD("slave_pressure->read       = %p\n", mldl_cfg->pressure->read);
         MPL_LOGD("slave_pressure->type       = %02x\n", mldl_cfg->pressure->type);
         MPL_LOGD("slave_pressure->read_reg   = %02x\n",
                  mldl_cfg->pressure->read_reg);
@@ -131,7 +131,7 @@
         MPL_LOGD("slave_pressure             = NULL\n");
     }
 
-    MPL_LOGD("accel->get_slave_descr    = %x\n",(unsigned int) accel->get_slave_descr);
+    MPL_LOGD("accel->get_slave_descr    = %p\n",accel->get_slave_descr);
     MPL_LOGD("accel->adapt_num          = %02x\n", accel->adapt_num);
     MPL_LOGD("accel->bus                = %02x\n", accel->bus);
     MPL_LOGD("accel->address            = %02x\n", accel->address);
@@ -142,7 +142,7 @@
              accel->orientation[0],accel->orientation[1],accel->orientation[2],
              accel->orientation[3],accel->orientation[4],accel->orientation[5],
              accel->orientation[6],accel->orientation[7],accel->orientation[8]);
-    MPL_LOGD("compass->get_slave_descr  = %x\n",(unsigned int) compass->get_slave_descr);
+    MPL_LOGD("compass->get_slave_descr  = %p\n",compass->get_slave_descr);
     MPL_LOGD("compass->adapt_num        = %02x\n", compass->adapt_num);
     MPL_LOGD("compass->bus              = %02x\n", compass->bus);
     MPL_LOGD("compass->address          = %02x\n", compass->address);
@@ -153,7 +153,7 @@
              compass->orientation[0],compass->orientation[1],compass->orientation[2],
              compass->orientation[3],compass->orientation[4],compass->orientation[5],
              compass->orientation[6],compass->orientation[7],compass->orientation[8]);
-    MPL_LOGD("pressure->get_slave_descr  = %x\n",(unsigned int) pressure->get_slave_descr);
+    MPL_LOGD("pressure->get_slave_descr  = %p\n",pressure->get_slave_descr);
     MPL_LOGD("pressure->adapt_num        = %02x\n", pressure->adapt_num);
     MPL_LOGD("pressure->bus              = %02x\n", pressure->bus);
     MPL_LOGD("pressure->address          = %02x\n", pressure->address);
@@ -175,8 +175,8 @@
              pdata->orientation[3],pdata->orientation[4],pdata->orientation[5],
              pdata->orientation[6],pdata->orientation[7],pdata->orientation[8]);
 
-    MPL_LOGD("Struct sizes: mldl_cfg: %d, "
-             "ext_slave_descr:%d, mpu_platform_data:%d: RamOffset: %d\n", 
+    MPL_LOGD("Struct sizes: mldl_cfg: %zu, "
+             "ext_slave_descr:%zu, mpu_platform_data:%zu: RamOffset: %zu\n",
              sizeof(struct mldl_cfg), sizeof(struct ext_slave_descr), 
              sizeof(struct mpu_platform_data), 
              offsetof(struct mldl_cfg, ram));
@@ -210,7 +210,7 @@
                  void *pressure_handle)
 {
     int result;
-    result = ioctl((int)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
@@ -259,17 +259,17 @@
     int result;
     
     mldl_cfg->requested_sensors = sensors;
-    result = ioctl((int)mlsl_handle, MPU_SET_MPU_CONFIG, mldl_cfg);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_SET_MPU_CONFIG, mldl_cfg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
     }
-    result = ioctl((int)mlsl_handle, MPU_RESUME, NULL);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_RESUME, NULL);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
     }
-    result = ioctl((int)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
@@ -294,17 +294,17 @@
     //MPL_LOGI("%s: suspending sensors to %04lx\n", __func__,
     //         mldl_cfg->requested_sensors);
 
-    result = ioctl((int)mlsl_handle, MPU_SET_MPU_CONFIG, mldl_cfg);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_SET_MPU_CONFIG, mldl_cfg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
     }
-    result = ioctl((int)mlsl_handle, MPU_SUSPEND, NULL);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_SUSPEND, NULL);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
     }
-    result = ioctl((int)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
+    result = ioctl((int)(uintptr_t)mlsl_handle, MPU_GET_MPU_CONFIG, mldl_cfg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
@@ -343,13 +343,13 @@
 
     switch (slave->type) {
     case EXT_SLAVE_TYPE_ACCELEROMETER:
-        result = ioctl((int)gyro_handle, MPU_READ_ACCEL, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_READ_ACCEL, data);
         break;
     case EXT_SLAVE_TYPE_COMPASS:
-        result = ioctl((int)gyro_handle, MPU_READ_COMPASS, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_READ_COMPASS, data);
         break;
     case EXT_SLAVE_TYPE_PRESSURE:
-        result = ioctl((int)gyro_handle, MPU_READ_PRESSURE, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_READ_PRESSURE, data);
         break;
     default:
         LOG_RESULT_LOCATION(INV_ERROR_INVALID_PARAMETER);
@@ -387,21 +387,21 @@
 
     switch (slave->type) {
     case EXT_SLAVE_TYPE_ACCELEROMETER:
-        result = ioctl((int)gyro_handle, MPU_CONFIG_ACCEL, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_CONFIG_ACCEL, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
         }
         break;
     case EXT_SLAVE_TYPE_COMPASS:
-        result = ioctl((int)gyro_handle, MPU_CONFIG_COMPASS, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_CONFIG_COMPASS, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
         }
         break;
     case EXT_SLAVE_TYPE_PRESSURE:
-        result = ioctl((int)gyro_handle, MPU_CONFIG_PRESSURE, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_CONFIG_PRESSURE, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
@@ -445,21 +445,21 @@
     }
     switch (slave->type) {
     case EXT_SLAVE_TYPE_ACCELEROMETER:
-        result = ioctl((int)gyro_handle, MPU_GET_CONFIG_ACCEL, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_GET_CONFIG_ACCEL, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
         }
         break;
     case EXT_SLAVE_TYPE_COMPASS:
-        result = ioctl((int)gyro_handle, MPU_GET_CONFIG_COMPASS, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_GET_CONFIG_COMPASS, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
         }
         break;
     case EXT_SLAVE_TYPE_PRESSURE:
-        result = ioctl((int)gyro_handle, MPU_GET_CONFIG_PRESSURE, data);
+        result = ioctl((int)(uintptr_t)gyro_handle, MPU_GET_CONFIG_PRESSURE, data);
         if (result) {
             LOG_RESULT_LOCATION(result);
             return result;
diff --git a/60xx/mlsdk/platform/include/mlos.h b/60xx/mlsdk/platform/include/mlos.h
index 78f0a83..0aeda96 100644
--- a/60xx/mlsdk/platform/include/mlos.h
+++ b/60xx/mlsdk/platform/include/mlos.h
@@ -30,7 +30,8 @@
 #endif
 
 #if defined(LINUX) || defined(__KERNEL__)
-typedef unsigned int HANDLE;
+#include <stdint.h>
+typedef uintptr_t HANDLE;
 #endif
 
 	/* ------------ */
diff --git a/60xx/mlsdk/platform/linux/mlsl_linux_mpu.c b/60xx/mlsdk/platform/linux/mlsl_linux_mpu.c
index 29930b3..1bd71de 100644
--- a/60xx/mlsdk/platform/linux/mlsl_linux_mpu.c
+++ b/60xx/mlsdk/platform/linux/mlsl_linux_mpu.c
@@ -236,8 +236,8 @@
     if (NULL == port) {
         port = I2CDEV;
     }
-    *sl_handle = (void*) open(port, O_RDWR);
-    if(sl_handle < 0) {
+    *sl_handle = (void*)(uintptr_t) open(port, O_RDWR);
+    if((intptr_t)*sl_handle < 0) {
         /* ERROR HANDLING; you can check errno to see what went wrong */
         MPL_LOGE("inv_serial_open\n");
         MPL_LOGE("I2C Error %d: Cannot open Adapter %s\n", errno, port);
@@ -253,7 +253,7 @@
 {
     INVENSENSE_FUNC_START;
 
-    close((int)sl_handle);
+    close((int)(uintptr_t)sl_handle);
 
     return INV_SUCCESS;
 }
@@ -291,7 +291,7 @@
     msg.length  = length;
     msg.data    = (unsigned char*)data;
 
-    if ((result = ioctl((int)sl_handle, MPU_WRITE, &msg))) {
+    if ((result = ioctl((int)(uintptr_t)sl_handle, MPU_WRITE, &msg))) {
         MPL_LOGE("I2C Error: could not write: R:%02x L:%d %d \n",
                  data[0], length, result);
        return result;
@@ -328,7 +328,7 @@
     msg.length  = length;
     msg.data    = data;
 
-    result = ioctl((int)sl_handle, MPU_READ, &msg);
+    result = ioctl((int)(uintptr_t)sl_handle, MPU_READ, &msg);
 
     if (result != INV_SUCCESS) {
         MPL_LOGE("I2C Error %08x: could not read: R:%02x L:%d\n",
@@ -363,7 +363,7 @@
     msg.length  = length;
     msg.data    = (unsigned char *)data;
 
-    result = ioctl((int)sl_handle, MPU_WRITE_MEM, &msg);
+    result = ioctl((int)(uintptr_t)sl_handle, MPU_WRITE_MEM, &msg);
     if (result) {
         LOG_RESULT_LOCATION(result);
         return result;
@@ -399,7 +399,7 @@
     msg.length  = length;
     msg.data    = data;
 
-    result = ioctl((int)sl_handle, MPU_READ_MEM, &msg);
+    result = ioctl((int)(uintptr_t)sl_handle, MPU_READ_MEM, &msg);
     if (result != INV_SUCCESS) {
         MPL_LOGE("I2C Error %08x: could not read memory: A:%04x L:%d\n",
                  result, memAddr, length);
@@ -435,7 +435,7 @@
     msg.length  = length;
     msg.data    = (unsigned char *)data;
 
-    result = ioctl((int)sl_handle, MPU_WRITE_FIFO, &msg);
+    result = ioctl((int)(uintptr_t)sl_handle, MPU_WRITE_FIFO, &msg);
     if (result != INV_SUCCESS) {
         MPL_LOGE("I2C Error: could not write fifo: %02x %02x\n",
                   MPUREG_FIFO_R_W, length);
@@ -471,7 +471,7 @@
     msg.length  = length;
     msg.data    = data;
 
-    result = ioctl((int)sl_handle, MPU_READ_FIFO, &msg);
+    result = ioctl((int)(uintptr_t)sl_handle, MPU_READ_FIFO, &msg);
     if (result != INV_SUCCESS) {
         MPL_LOGE("I2C Error %08x: could not read fifo: R:%02x L:%d\n",
                  result, MPUREG_FIFO_R_W, length);