Port Missing parts of the Robust Clock patches for VSTAB.

Introduce ioctl to get 32KHz clock

Expose ioctl to userspace from the RPMSG driver
(probably not the wisest thing)

Signed-off-by: Milen Mitkov <mmitkov@mm-sol.com>

IO:Take gyro timestamp from the 32KHz timer

    This is done so that we are in sync with ducati for
    vstab algorithm usage.

    Signed-off-by: Milen Mitkov <mmitkov@mm-sol.com>

Change-Id: Idc87c750ad4910a00c57b86c8b05f12698878d8a
diff --git a/drivers/rpmsg/rpmsg_omx.c b/drivers/rpmsg/rpmsg_omx.c
index e82d266..f9f8d43 100644
--- a/drivers/rpmsg/rpmsg_omx.c
+++ b/drivers/rpmsg/rpmsg_omx.c
@@ -41,6 +41,8 @@
 #ifdef CONFIG_ION_OMAP
 #include <linux/ion.h>
 #include <linux/omap_ion.h>
+#include <plat/usb.h>
+#include <plat/omap44xx.h>
 
 extern struct ion_device *omap_ion_device;
 #endif
@@ -577,6 +579,26 @@
 		break;
 	}
 #endif
+#ifdef CONFIG_ION_OMAP
+	case OMX_GET_TIMER:
+	{
+		struct omx_get_timer data;
+		struct timespec ts;
+
+		/*read_persistent_clock(&ts);*/
+		data.persistent_timer = read_robust_clock();
+
+		data.clock32k = omap_readl(OMAP4430_32KSYNCT_BASE + 0x10);
+
+		if (copy_to_user((char __user *) arg, &data, sizeof(data))) {
+				dev_err(omxserv->dev,
+				"GetTimer: %s: %d: copy_to_user fail: %d\n", __func__,
+				_IOC_NR(cmd), ret);
+		}
+
+	break;
+	}
+#endif
 	default:
 		dev_warn(omxserv->dev, "unhandled ioctl cmd: %d\n", cmd);
 		break;
diff --git a/drivers/staging/iio/imu/inv_mpu/inv_mpu_core.c b/drivers/staging/iio/imu/inv_mpu/inv_mpu_core.c
index cec67ea..eb60c8c 100644
--- a/drivers/staging/iio/imu/inv_mpu/inv_mpu_core.c
+++ b/drivers/staging/iio/imu/inv_mpu/inv_mpu_core.c
@@ -51,9 +51,7 @@
 
 s64 get_time_ns(void)
 {
-	struct timespec ts;
-	ktime_get_ts(&ts);
-	return timespec_to_ns(&ts);
+    return read_robust_clock();
 }
 
 static const short AKM8975_ST_Lower[3] = {-100, -100, -1000};
diff --git a/include/linux/rpmsg_omx.h b/include/linux/rpmsg_omx.h
index 3d5e42a..c433823 100644
--- a/include/linux/rpmsg_omx.h
+++ b/include/linux/rpmsg_omx.h
@@ -54,8 +54,9 @@
 #define OMX_IOCIONREGISTER	_IOWR(OMX_IOC_MAGIC, 2, struct ion_fd_data)
 #define OMX_IOCIONUNREGISTER	_IOWR(OMX_IOC_MAGIC, 3, struct ion_fd_data)
 #define OMX_IOCPVRREGISTER	_IOWR(OMX_IOC_MAGIC, 4, struct omx_pvr_data)
+#define OMX_GET_TIMER		_IOWR(OMX_IOC_MAGIC, 5, struct omx_get_timer)
 
-#define OMX_IOC_MAXNR	(4)
+#define OMX_IOC_MAXNR	(5)
 
 #ifdef __KERNEL__
 
@@ -155,4 +156,9 @@
 				   function. */
 };
 
+struct omx_get_timer {
+    long long int persistent_timer;
+    unsigned int clock32k;
+};
+
 #endif /* RPMSG_OMX_H */