Update MPU3050 kernel driver

1. Update MPU3050 drivers to Invensense MPU code update v3.3.4 ported from:
   https://android.googlesource.com/kernel/msm.git/+/android-msm-sony-cm-jb-3.0
2. Enable LSM303DLHA and LSM303DLHM as MPU3050 slaves instead of fake BMA150 and AK8975
3. Proper LSM303DLHA and LSM303DLHM power management when acting as MPU3050 slaves
4. Gyro axis configuration changed
5. Updates to sensor setup by John Newby
diff --git a/include/linux/i2c/lsm303dlh.h b/include/linux/i2c/lsm303dlh.h
index bb07cc6..9f07adf 100644
--- a/include/linux/i2c/lsm303dlh.h
+++ b/include/linux/i2c/lsm303dlh.h
@@ -39,6 +39,12 @@
 #define	LSM303DLH_MAG_DEV_NAME	"lsm303dlh_mag_sysfs"
 
 
+#define LSM303DLH_ACC_MIN_POLL_PERIOD_MS 1
+#define LSM303DLH_MAG_MIN_POLL_PERIOD_MS 5
+
+#define LSM303DLH_ACC_DEFAULT_INT1_GPIO (-EINVAL)
+#define LSM303DLH_ACC_DEFAULT_INT2_GPIO (-EINVAL)
+
 
 /************************************************/
 /* 	Accelerometer section defines	 	*/
@@ -57,7 +63,23 @@
 #define LSM303DLH_ACC_PM_OFF		LSM303DLH_ACC_DISABLE
 
 
+/* RESUME STATE INDICES */
+#define	RES_CTRL_REG1		0
+#define	RES_CTRL_REG2		1
+#define	RES_CTRL_REG3		2
+#define	RES_CTRL_REG4		3
+#define	RES_CTRL_REG5		4
+#define	RES_REFERENCE		5
 
+#define	RES_INT_CFG1		6
+#define	RES_INT_THS1		7
+#define	RES_INT_DUR1		8
+#define	RES_INT_CFG2		9
+#define	RES_INT_THS2		10
+#define	RES_INT_DUR2		11
+
+#define	RESUME_ENTRIES		12
+/* end RESUME STATE INDICES */
 
 /************************************************/
 /* 	Magnetometer section defines	 	*/
@@ -109,6 +131,40 @@
 	int gpio_int2;
 };
 
+struct lsm303dlh_acc_data {
+	struct i2c_client *client;
+	struct lsm303dlh_acc_platform_data *pdata;
+
+	struct mutex lock;
+	struct delayed_work input_work;
+
+	struct input_dev *input_dev;
+
+	int hw_initialized;
+	/* hw_working=-1 means not tested yet */
+	int hw_working;
+	int selftest_enabled;
+
+	atomic_t enabled;
+	int on_before_suspend;
+
+	u8 sensitivity;
+
+	u8 resume_state[RESUME_ENTRIES];
+
+	int irq1;
+	struct work_struct irq1_work;
+	struct workqueue_struct *irq1_work_queue;
+	int irq2;
+	struct work_struct irq2_work;
+	struct workqueue_struct *irq2_work_queue;
+
+	u8 reg_addr;
+
+	int ext_adap_enabled;
+	void *ext_handle;
+};
+
 struct lsm303dlh_mag_platform_data {
 
 	int poll_interval;
@@ -130,6 +186,30 @@
 	int (*power_off)(void);
 
 };
+
+struct lsm303dlh_mag_data {
+	struct i2c_client *client;
+	struct lsm303dlh_mag_platform_data *pdata;
+
+	struct mutex lock;
+
+	struct input_polled_dev *input_poll_dev;
+
+	int hw_initialized;
+	atomic_t enabled;
+	atomic_t self_test_enabled;
+
+	u16 xy_sensitivity;
+	u16 z_sensitivity;
+
+	u8 resume_state[3];
+
+	u8 reg_addr;
+
+	int on_before_suspend;
+	int ext_adap_enabled;
+	void *ext_handle;
+};
 #endif /* __KERNEL__ */
 
 #endif  /* __LSM303DLH_H__ */
diff --git a/include/linux/mpu.h b/include/linux/mpu.h
index d4e0e91..026a0b7 100644
--- a/include/linux/mpu.h
+++ b/include/linux/mpu.h
@@ -30,82 +30,44 @@
 #include "mpu3050.h"
 #endif
 
+/* Number of axes on each sensor */
 #define GYRO_NUM_AXES               (3)
 #define ACCEL_NUM_AXES              (3)
 #define COMPASS_NUM_AXES            (3)
 
-#define MPU_SET_MPU_CONFIG          (0x00)
-#define MPU_SET_INT_CONFIG          (0x01)
-#define MPU_SET_EXT_SYNC            (0x02)
-#define MPU_SET_FULL_SCALE          (0x03)
-#define MPU_SET_LPF                 (0x04)
-#define MPU_SET_CLK_SRC             (0x05)
-#define MPU_SET_DIVIDER             (0x06)
-#define MPU_SET_LEVEL_SHIFTER       (0x07)
-#define MPU_SET_DMP_ENABLE          (0x08)
-#define MPU_SET_FIFO_ENABLE         (0x09)
-#define MPU_SET_DMP_CFG1            (0x0a)
-#define MPU_SET_DMP_CFG2            (0x0b)
-#define MPU_SET_OFFSET_TC           (0x0c)
-#define MPU_SET_RAM                 (0x0d)
-
-#define MPU_SET_PLATFORM_DATA       (0x0e)
-
-#define MPU_GET_MPU_CONFIG          (0x80)
-#define MPU_GET_INT_CONFIG          (0x81)
-#define MPU_GET_EXT_SYNC            (0x82)
-#define MPU_GET_FULL_SCALE          (0x83)
-#define MPU_GET_LPF                 (0x84)
-#define MPU_GET_CLK_SRC             (0x85)
-#define MPU_GET_DIVIDER             (0x86)
-#define MPU_GET_LEVEL_SHIFTER       (0x87)
-#define MPU_GET_DMP_ENABLE          (0x88)
-#define MPU_GET_FIFO_ENABLE         (0x89)
-#define MPU_GET_DMP_CFG1            (0x8a)
-#define MPU_GET_DMP_CFG2            (0x8b)
-#define MPU_GET_OFFSET_TC           (0x8c)
-#define MPU_GET_RAM                 (0x8d)
-
-#define MPU_READ_REGISTER           (0x40)
-#define MPU_WRITE_REGISTER          (0x41)
-#define MPU_READ_MEMORY             (0x42)
-#define MPU_WRITE_MEMORY            (0x43)
-
-#define MPU_SUSPEND                 (0x44)
-#define MPU_RESUME                  (0x45)
-#define MPU_READ_COMPASS            (0x46)
-#define MPU_READ_ACCEL              (0x47)
-#define MPU_READ_PRESSURE           (0x48)
-
-#define MPU_CONFIG_ACCEL            (0x20)
-#define MPU_CONFIG_COMPASS          (0x21)
-#define MPU_CONFIG_PRESSURE         (0x22)
-
-#define MPU_GET_CONFIG_ACCEL        (0x28)
-#define MPU_GET_CONFIG_COMPASS      (0x29)
-#define MPU_GET_CONFIG_PRESSURE     (0x2a)
-
-#ifdef CONFIG_MACH_HTC
-#define HTC_READ_CAL_DATA
-#endif
-#ifdef HTC_READ_CAL_DATA
-#define MPU_READ_CAL_DATA           (0xef)
-extern unsigned char gyro_gsensor_kvalue[37];
-#endif
-
+/* Structure for the following IOCTL's:
+   MPU_READ
+   MPU_WRITE
+   MPU_READ_MEM
+   MPU_WRITE_MEM
+   MPU_READ_FIFO
+   MPU_WRITE_FIFO
+*/
 struct mpu_read_write {
+	/* Memory address or register address depending on ioctl */
 	unsigned short address;
 	unsigned short length;
 	unsigned char *data;
 };
 
+enum mpuirq_data_type {
+	MPUIRQ_DATA_TYPE_MPU_IRQ,
+	MPUIRQ_DATA_TYPE_SLAVE_IRQ,
+	MPUIRQ_DATA_TYPE_PM_EVENT,
+	MPUIRQ_DATA_TYPE_NUM_TYPES,
+};
+
+/* User space PM event notification */
+#define MPU_PM_EVENT_SUSPEND_PREPARE (3)
+#define MPU_PM_EVENT_POST_SUSPEND    (4)
+
 struct mpuirq_data {
 	int interruptcount;
 	unsigned long long irqtime;
 	int data_type;
-	int data_size;
-	void *data;
+	long data;
 };
+
 enum ext_slave_config_key {
 	MPU_SLAVE_CONFIG_ODR_SUSPEND,
 	MPU_SLAVE_CONFIG_ODR_RESUME,
@@ -119,15 +81,44 @@
 	MPU_SLAVE_CONFIG_IRQ_RESUME,
 	MPU_SLAVE_WRITE_REGISTERS,
 	MPU_SLAVE_READ_REGISTERS,
+	/* AMI 306 specific config keys */
+	MPU_SLAVE_PARAM,
+	MPU_SLAVE_WINDOW,
+	MPU_SLAVE_READWINPARAMS,
+	MPU_SLAVE_SEARCHOFFSET,
+	/* AKM specific config keys */
+	MPU_SLAVE_READ_SCALE,
+	/* YAS specific config keys */
+	MPU_SLAVE_OFFSET_VALS,
+	MPU_SLAVE_RANGE_CHECK,
+
 	MPU_SLAVE_CONFIG_NUM_CONFIG_KEYS,
 };
 
+/* For the MPU_SLAVE_CONFIG_IRQ_SUSPEND and MPU_SLAVE_CONFIG_IRQ_RESUME */
 enum ext_slave_config_irq_type {
 	MPU_SLAVE_IRQ_TYPE_NONE,
 	MPU_SLAVE_IRQ_TYPE_MOTION,
 	MPU_SLAVE_IRQ_TYPE_DATA_READY,
 };
 
+/* Structure for the following IOCTS's
+ * MPU_CONFIG_ACCEL
+ * MPU_CONFIG_COMPASS
+ * MPU_CONFIG_PRESSURE
+ * MPU_GET_CONFIG_ACCEL
+ * MPU_GET_CONFIG_COMPASS
+ * MPU_GET_CONFIG_PRESSURE
+ *
+ * @key one of enum ext_slave_config_key
+ * @len length of data pointed to by data
+ * @apply zero if communication with the chip is not necessary, false otherwise
+ *        This flag can be used to select cached data or to refresh cashed data
+ *        cache data to be pushed later or push immediately.  If true and the
+ *        slave is on the secondary bus the MPU will first enger bypass mode
+ *        before calling the slaves .config or .get_config funcion
+ * @data pointer to the data to confgure or get
+ */
 struct ext_slave_config {
 	int key;
 	int len;
@@ -140,7 +131,9 @@
 	EXT_SLAVE_TYPE_ACCELEROMETER,
 	EXT_SLAVE_TYPE_COMPASS,
 	EXT_SLAVE_TYPE_PRESSURE,
-	
+	/*EXT_SLAVE_TYPE_TEMPERATURE */
+
+	EXT_SLAVE_NUM_TYPES
 };
 
 enum ext_slave_id {
@@ -159,7 +152,6 @@
     ACCEL_ID_LIS3DH,
 
 	COMPASS_ID_AKM,
-	COMPASS_ID_AKM8963,
 	COMPASS_ID_AMI30X,
 	COMPASS_ID_YAS529,
 	COMPASS_ID_HMC5883,
@@ -186,6 +178,26 @@
 };
 
 
+/**
+ *  struct ext_slave_platform_data - Platform data for mpu3050 and mpu6050
+ *  slave devices
+ *
+ *  @get_slave_descr: Function pointer to retrieve the struct ext_slave_descr
+ *                    for this slave
+ *  @irq: the irq number attached to the slave if any.
+ *  @adapt_num: the I2C adapter number.
+ *  @bus: the bus the slave is attached to: enum ext_slave_bus
+ *  @address: the I2C slave address of the slave device.
+ *  @orientation: the mounting matrix of the device relative to MPU.
+ *  @irq_data: private data for the slave irq handler
+ *  @private_data: additional data, user customizable.  Not touched by the MPU
+ *                 driver.
+ *
+ * The orientation matricies are 3x3 rotation matricies
+ * that are applied to the data to rotate from the mounting orientation to the
+ * platform orientation.  The values must be one of 0, 1, or -1 and each row and
+ * column should have exactly 1 non-zero value.
+ */
 struct ext_slave_platform_data {
 	struct ext_slave_descr *(*get_slave_descr) (void);
 	int irq;
@@ -195,14 +207,49 @@
 	signed char orientation[9];
 	void *irq_data;
 	void *private_data;
+	void (*bypass_state)(int, char*);
+	int (*check_sleep_status)(void);
+	void (*vote_sleep_status)(int, int);
+
 };
 
-
-struct tFixPntRange {
+struct fix_pnt_range {
 	long mantissa;
 	long fraction;
 };
 
+static inline long range_fixedpoint_to_long_mg(struct fix_pnt_range rng)
+{
+	return (long)(rng.mantissa * 1000 + rng.fraction / 10);
+}
+
+struct ext_slave_read_trigger {
+	unsigned char reg;
+	unsigned char value;
+};
+
+/**
+ *  struct ext_slave_descr - Description of the slave device for programming.
+ *
+ *  @suspend:	function pointer to put the device in suspended state
+ *  @resume:	function pointer to put the device in running state
+ *  @read:	function that reads the device data
+ *  @init:	function used to preallocate memory used by the driver
+ *  @exit:	function used to free memory allocated for the driver
+ *  @config:	function used to configure the device
+ *  @get_config:function used to get the device's configuration
+ *
+ *  @name:	text name of the device
+ *  @type:	device type. enum ext_slave_type
+ *  @id:	enum ext_slave_id
+ *  @reg:	starting register address to retrieve data.
+ *  @len:	length in bytes of the sensor data.  Should be 6.
+ *  @endian:	byte order of the data. enum ext_slave_endian
+ *  @range:	full scale range of the slave ouput: struct tFixPntRange
+ *
+ *  Defines the functions and information about the slave the mpu3050 needs to
+ *  use the slave device.
+ */
 struct ext_slave_descr {
 	int (*init) (void *mlsl_handle,
 		     struct ext_slave_descr *slave,
@@ -242,78 +289,99 @@
 	unsigned char reg;
 	unsigned int len;
 	unsigned char endian;
-	struct tFixPntRange range;
+	struct fix_pnt_range range;
+	struct ext_slave_read_trigger *trigger;
 };
 
+/**
+ * struct mpu3050_platform_data - Platform data for the mpu driver
+ * @int_config:		Bits [7:3] of the int config register.
+ * @orientation:	Orientation matrix of the gyroscope
+ * @level_shifter:	0: VLogic, 1: VDD
+ * @accel:		Accel platform data
+ * @compass:		Compass platform data
+ * @pressure:		Pressure platform data
+ *
+ * Contains platform specific information on how to configure the MPU3050 to
+ * work on this platform.  The orientation matricies are 3x3 rotation matricies
+ * that are applied to the data to rotate from the mounting orientation to the
+ * platform orientation.  The values must be one of 0, 1, or -1 and each row and
+ * column should have exactly 1 non-zero value.
+ */
 struct mpu3050_platform_data {
 	unsigned char int_config;
-	signed char orientation[MPU_NUM_AXES * MPU_NUM_AXES];
+	signed char orientation[GYRO_NUM_AXES * GYRO_NUM_AXES];
 	unsigned char level_shifter;
 	struct ext_slave_platform_data accel;
 	struct ext_slave_platform_data compass;
 	struct ext_slave_platform_data pressure;
-	int (*g_sensors_reset)(void);
-	int (*power_LPM)(int on);
+	int (*setup)(struct device *dev, int enable);
+	void (*hw_config)(int enable);
+	void (*power_mode)(int enable);
 };
 
 
+/*
+    Accelerometer
+*/
 #define get_accel_slave_descr NULL
 
-#ifdef CONFIG_MPU_SENSORS_ADXL346	
+#ifdef CONFIG_MPU_SENSORS_ADXL346	/* ADI accelerometer */
 struct ext_slave_descr *adxl346_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr adxl346_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_BMA150	
+#ifdef CONFIG_MPU_SENSORS_BMA150	/* Bosch accelerometer */
 struct ext_slave_descr *bma150_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr bma150_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_BMA250	
+#ifdef CONFIG_MPU_SENSORS_BMA250	/* Bosch 250 accelerometer */
 struct ext_slave_descr *bma250_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr bma250_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_BMA222	
+#ifdef CONFIG_MPU_SENSORS_BMA222	/* Bosch 222 accelerometer */
 struct ext_slave_descr *bma222_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr bma222_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_KXSD9	
+#ifdef CONFIG_MPU_SENSORS_KXSD9	/* Kionix accelerometer */
 struct ext_slave_descr *kxsd9_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr kxsd9_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_KXTF9	
+#ifdef CONFIG_MPU_SENSORS_KXTF9	/* Kionix accelerometer */
 struct ext_slave_descr *kxtf9_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr kxtf9_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_LIS331DLH	
+#ifdef CONFIG_MPU_SENSORS_LIS331DLH	/* ST accelerometer */
 struct ext_slave_descr *lis331dlh_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr lis331dlh_get_slave_descr
 #endif
 
 
-#ifdef CONFIG_MPU_SENSORS_LIS3DH	
+#ifdef CONFIG_MPU_SENSORS_LIS3DH	/* ST accelerometer */
 struct ext_slave_descr *lis3dh_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr lis3dh_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_LSM303DLHA	
+#ifdef CONFIG_MPU_SENSORS_LSM303DLHA	/* ST accelerometer */
 struct ext_slave_descr *lsm303dlha_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr lsm303dlha_get_slave_descr
 #endif
 
+/* MPU6000 Accel */
 #if defined(CONFIG_MPU_SENSORS_MPU6000) || \
     defined(CONFIG_MPU_SENSORS_MPU6000_MODULE)
 struct ext_slave_descr *mantis_get_slave_descr(void);
@@ -321,80 +389,111 @@
 #define get_accel_slave_descr mantis_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_MMA8450	
+#ifdef CONFIG_MPU_SENSORS_MMA8450	/* Freescale accelerometer */
 struct ext_slave_descr *mma8450_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr mma8450_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_MMA845X	
+#ifdef CONFIG_MPU_SENSORS_MMA845X	/* Freescale accelerometer */
 struct ext_slave_descr *mma845x_get_slave_descr(void);
 #undef get_accel_slave_descr
 #define get_accel_slave_descr mma845x_get_slave_descr
 #endif
 
 
+/*
+    Compass
+*/
 #define get_compass_slave_descr NULL
 
-#ifdef CONFIG_MPU_SENSORS_AK8975	
+#ifdef CONFIG_MPU_SENSORS_AK8975	/* AKM compass */
 struct ext_slave_descr *ak8975_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr ak8975_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_AK8963	
-struct ext_slave_descr *ak8963_get_slave_descr(void);
-#undef get_compass_slave_descr
-#define get_compass_slave_descr ak8963_get_slave_descr
-#endif
-
-#ifdef CONFIG_MPU_SENSORS_AMI30X	
+#ifdef CONFIG_MPU_SENSORS_AMI30X	/* AICHI Steel compass */
 struct ext_slave_descr *ami30x_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr ami30x_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_HMC5883	
+#ifdef CONFIG_MPU_SENSORS_HMC5883	/* Honeywell compass */
 struct ext_slave_descr *hmc5883_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr hmc5883_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_MMC314X	
+#ifdef CONFIG_MPU_SENSORS_MMC314X	/* MEMSIC compass */
 struct ext_slave_descr *mmc314x_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr mmc314x_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_LSM303DLHM	
+#ifdef CONFIG_MPU_SENSORS_LSM303DLHM	/* ST compass */
 struct ext_slave_descr *lsm303dlhm_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr lsm303dlhm_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_YAS529	
+#ifdef CONFIG_MPU_SENSORS_YAS529	/* Yamaha compass */
 struct ext_slave_descr *yas529_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr yas529_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_HSCDTD002B	
+#ifdef CONFIG_MPU_SENSORS_HSCDTD002B	/* Alps HSCDTD002B compass */
 struct ext_slave_descr *hscdtd002b_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr hscdtd002b_get_slave_descr
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_HSCDTD004A	
+#ifdef CONFIG_MPU_SENSORS_HSCDTD004A	/* Alps HSCDTD004A compass */
 struct ext_slave_descr *hscdtd004a_get_slave_descr(void);
 #undef get_compass_slave_descr
 #define get_compass_slave_descr hscdtd004a_get_slave_descr
 #endif
+/*
+    Pressure
+*/
 #define get_pressure_slave_descr NULL
 
-#ifdef CONFIG_MPU_SENSORS_BMA085	
+#ifdef CONFIG_MPU_SENSORS_BMA085	/* BMA pressure */
 struct ext_slave_descr *bma085_get_slave_descr(void);
 #undef get_pressure_slave_descr
 #define get_pressure_slave_descr bma085_get_slave_descr
 #endif
 
-#endif				
+#define MPU_IOCTL (0x81) /* Magic number for MPU Iocts */
+/* IOCTL commands for /dev/mpu */
+#define MPU_SET_MPU_CONFIG	_IOWR(MPU_IOCTL, 0x00, struct mldl_cfg)
+#define MPU_GET_MPU_CONFIG	_IOW(MPU_IOCTL,  0x00, struct mldl_cfg)
+
+#define MPU_SET_PLATFORM_DATA	_IOWR(MPU_IOCTL, 0x01, struct mldl_cfg)
+
+#define MPU_READ		_IOWR(MPU_IOCTL, 0x10, struct mpu_read_write)
+#define MPU_WRITE		_IOW(MPU_IOCTL,  0x10, struct mpu_read_write)
+#define MPU_READ_MEM		_IOWR(MPU_IOCTL, 0x11, struct mpu_read_write)
+#define MPU_WRITE_MEM		_IOW(MPU_IOCTL,  0x11, struct mpu_read_write)
+#define MPU_READ_FIFO		_IOWR(MPU_IOCTL, 0x12, struct mpu_read_write)
+#define MPU_WRITE_FIFO		_IOW(MPU_IOCTL,  0x12, struct mpu_read_write)
+
+#define MPU_READ_COMPASS	_IOR(MPU_IOCTL, 0x12, unsigned char)
+#define MPU_READ_ACCEL		_IOR(MPU_IOCTL, 0x13, unsigned char)
+#define MPU_READ_PRESSURE	_IOR(MPU_IOCTL, 0x14, unsigned char)
+
+#define MPU_CONFIG_ACCEL	_IOW(MPU_IOCTL, 0x20, struct ext_slave_config)
+#define MPU_CONFIG_COMPASS	_IOW(MPU_IOCTL, 0x21, struct ext_slave_config)
+#define MPU_CONFIG_PRESSURE	_IOW(MPU_IOCTL, 0x22, struct ext_slave_config)
+
+#define MPU_GET_CONFIG_ACCEL	_IOWR(MPU_IOCTL, 0x20, struct ext_slave_config)
+#define MPU_GET_CONFIG_COMPASS	_IOWR(MPU_IOCTL, 0x21, struct ext_slave_config)
+#define MPU_GET_CONFIG_PRESSURE	_IOWR(MPU_IOCTL, 0x22, struct ext_slave_config)
+
+#define MPU_SUSPEND		_IO(MPU_IOCTL, 0x30)
+#define MPU_RESUME		_IO(MPU_IOCTL, 0x31)
+/* Userspace PM Event response */
+#define MPU_PM_EVENT_HANDLED	_IO(MPU_IOCTL, 0x32)
+
+#endif				/* __MPU_H_ */
diff --git a/include/linux/mpu3050.h b/include/linux/mpu3050.h
index 936d136..034dad8 100644
--- a/include/linux/mpu3050.h
+++ b/include/linux/mpu3050.h
@@ -1,105 +1,98 @@
 /*
  $License:
     Copyright (C) 2010 InvenSense Corporation, All Rights Reserved.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-  $
+ $
  */
 
 #ifndef __MPU3050_H_
 #define __MPU3050_H_
 
-#ifdef __KERNEL__
 #include <linux/types.h>
-#endif
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
 
-#ifdef M_HW
-#error MPU6000 build including MPU3050 header
+#if defined(MPUDEBUG)
+#define mpu_dbg(format, arg...)		\
+	printk(KERN_DEBUG format, ## arg);
+#else
+#define mpu_dbg(format, arg...)
 #endif
 
 #define MPU_NAME "mpu3050"
 #define DEFAULT_MPU_SLAVEADDR       0x68
 
+/*==== MPU REGISTER SET ====*/
 enum mpu_register {
-	MPUREG_WHO_AM_I = 0,	
-	MPUREG_PRODUCT_ID,	
-	MPUREG_02_RSVD,		
-	MPUREG_03_RSVD,		
-	MPUREG_04_RSVD,		
-	MPUREG_XG_OFFS_TC,	
-	MPUREG_06_RSVD,		
-	MPUREG_07_RSVD,		
-	MPUREG_YG_OFFS_TC,	
-	MPUREG_09_RSVD,		
-	MPUREG_0A_RSVD,		
-	MPUREG_ZG_OFFS_TC,	
-	MPUREG_X_OFFS_USRH,	
-	MPUREG_X_OFFS_USRL,	
-	MPUREG_Y_OFFS_USRH,	
-	MPUREG_Y_OFFS_USRL,	
-	MPUREG_Z_OFFS_USRH,	
-	MPUREG_Z_OFFS_USRL,	
-	MPUREG_FIFO_EN1,	
-	MPUREG_FIFO_EN2,	
-	MPUREG_AUX_SLV_ADDR,	
-	MPUREG_SMPLRT_DIV,	
-	MPUREG_DLPF_FS_SYNC,	
-	MPUREG_INT_CFG,		
-	MPUREG_ACCEL_BURST_ADDR,
-	MPUREG_19_RSVD,		
-	MPUREG_INT_STATUS,	
-	MPUREG_TEMP_OUT_H,	
-	MPUREG_TEMP_OUT_L,	
-	MPUREG_GYRO_XOUT_H,	
-	MPUREG_GYRO_XOUT_L,	
-	MPUREG_GYRO_YOUT_H,	
-	MPUREG_GYRO_YOUT_L,	
-	MPUREG_GYRO_ZOUT_H,	
-	MPUREG_GYRO_ZOUT_L,	
-	MPUREG_23_RSVD,		
-	MPUREG_24_RSVD,		
-	MPUREG_25_RSVD,		
-	MPUREG_26_RSVD,		
-	MPUREG_27_RSVD,		
-	MPUREG_28_RSVD,		
-	MPUREG_29_RSVD,		
-	MPUREG_2A_RSVD,		
-	MPUREG_2B_RSVD,		
-	MPUREG_2C_RSVD,		
-	MPUREG_2D_RSVD,		
-	MPUREG_2E_RSVD,		
-	MPUREG_2F_RSVD,		
-	MPUREG_30_RSVD,		
-	MPUREG_31_RSVD,		
-	MPUREG_32_RSVD,		
-	MPUREG_33_RSVD,		
-	MPUREG_34_RSVD,		
-	MPUREG_DMP_CFG_1,	
-	MPUREG_DMP_CFG_2,	
-	MPUREG_BANK_SEL,	
-	MPUREG_MEM_START_ADDR,	
-	MPUREG_MEM_R_W,		
-	MPUREG_FIFO_COUNTH,	
-	MPUREG_FIFO_COUNTL,	
-	MPUREG_FIFO_R_W,	
-	MPUREG_USER_CTRL,	
-	MPUREG_PWR_MGM,		
-	MPUREG_3F_RSVD,		
-	NUM_OF_MPU_REGISTERS	
+	MPUREG_WHO_AM_I = 0,	/* 00 0x00 */
+	MPUREG_PRODUCT_ID,	/* 01 0x01 */
+	MPUREG_02_RSVD,		/* 02 0x02 */
+	MPUREG_03_RSVD,		/* 03 0x03 */
+	MPUREG_04_RSVD,		/* 04 0x04 */
+	MPUREG_XG_OFFS_TC,	/* 05 0x05 */
+	MPUREG_06_RSVD,		/* 06 0x06 */
+	MPUREG_07_RSVD,		/* 07 0x07 */
+	MPUREG_YG_OFFS_TC,	/* 08 0x08 */
+	MPUREG_09_RSVD,		/* 09 0x09 */
+	MPUREG_0A_RSVD,		/* 10 0x0a */
+	MPUREG_ZG_OFFS_TC,	/* 11 0x0b */
+	MPUREG_X_OFFS_USRH,	/* 12 0x0c */
+	MPUREG_X_OFFS_USRL,	/* 13 0x0d */
+	MPUREG_Y_OFFS_USRH,	/* 14 0x0e */
+	MPUREG_Y_OFFS_USRL,	/* 15 0x0f */
+	MPUREG_Z_OFFS_USRH,	/* 16 0x10 */
+	MPUREG_Z_OFFS_USRL,	/* 17 0x11 */
+	MPUREG_FIFO_EN1,	/* 18 0x12 */
+	MPUREG_FIFO_EN2,	/* 19 0x13 */
+	MPUREG_AUX_SLV_ADDR,	/* 20 0x14 */
+	MPUREG_SMPLRT_DIV,	/* 21 0x15 */
+	MPUREG_DLPF_FS_SYNC,	/* 22 0x16 */
+	MPUREG_INT_CFG,		/* 23 0x17 */
+	MPUREG_ACCEL_BURST_ADDR,/* 24 0x18 */
+	MPUREG_19_RSVD,		/* 25 0x19 */
+	MPUREG_INT_STATUS,	/* 26 0x1a */
+	MPUREG_TEMP_OUT_H,	/* 27 0x1b */
+	MPUREG_TEMP_OUT_L,	/* 28 0x1c */
+	MPUREG_GYRO_XOUT_H,	/* 29 0x1d */
+	MPUREG_GYRO_XOUT_L,	/* 30 0x1e */
+	MPUREG_GYRO_YOUT_H,	/* 31 0x1f */
+	MPUREG_GYRO_YOUT_L,	/* 32 0x20 */
+	MPUREG_GYRO_ZOUT_H,	/* 33 0x21 */
+	MPUREG_GYRO_ZOUT_L,	/* 34 0x22 */
+	MPUREG_23_RSVD,		/* 35 0x23 */
+	MPUREG_24_RSVD,		/* 36 0x24 */
+	MPUREG_25_RSVD,		/* 37 0x25 */
+	MPUREG_26_RSVD,		/* 38 0x26 */
+	MPUREG_27_RSVD,		/* 39 0x27 */
+	MPUREG_28_RSVD,		/* 40 0x28 */
+	MPUREG_29_RSVD,		/* 41 0x29 */
+	MPUREG_2A_RSVD,		/* 42 0x2a */
+	MPUREG_2B_RSVD,		/* 43 0x2b */
+	MPUREG_2C_RSVD,		/* 44 0x2c */
+	MPUREG_2D_RSVD,		/* 45 0x2d */
+	MPUREG_2E_RSVD,		/* 46 0x2e */
+	MPUREG_2F_RSVD,		/* 47 0x2f */
+	MPUREG_30_RSVD,		/* 48 0x30 */
+	MPUREG_31_RSVD,		/* 49 0x31 */
+	MPUREG_32_RSVD,		/* 50 0x32 */
+	MPUREG_33_RSVD,		/* 51 0x33 */
+	MPUREG_34_RSVD,		/* 52 0x34 */
+	MPUREG_DMP_CFG_1,	/* 53 0x35 */
+	MPUREG_DMP_CFG_2,	/* 54 0x36 */
+	MPUREG_BANK_SEL,	/* 55 0x37 */
+	MPUREG_MEM_START_ADDR,	/* 56 0x38 */
+	MPUREG_MEM_R_W,		/* 57 0x39 */
+	MPUREG_FIFO_COUNTH,	/* 58 0x3a */
+	MPUREG_FIFO_COUNTL,	/* 59 0x3b */
+	MPUREG_FIFO_R_W,	/* 60 0x3c */
+	MPUREG_USER_CTRL,	/* 61 0x3d */
+	MPUREG_PWR_MGM,		/* 62 0x3e */
+	MPUREG_3F_RSVD,		/* 63 0x3f */
+	NUM_OF_MPU_REGISTERS	/* 64 0x40 */
 };
 
+/*==== BITS FOR MPU ====*/
 
+/*---- MPU 'FIFO_EN1' register (12) ----*/
 #define BIT_TEMP_OUT                0x80
 #define BIT_GYRO_XOUT               0x40
 #define BIT_GYRO_YOUT               0x20
@@ -108,8 +101,10 @@
 #define BIT_ACCEL_YOUT              0x04
 #define BIT_ACCEL_ZOUT              0x02
 #define BIT_AUX_1OUT                0x01
+/*---- MPU 'FIFO_EN2' register (13) ----*/
 #define BIT_AUX_2OUT                0x02
 #define BIT_AUX_3OUT                0x01
+/*---- MPU 'DLPF_FS_SYNC' register (16) ----*/
 #define BITS_EXT_SYNC_NONE          0x00
 #define BITS_EXT_SYNC_TEMP          0x20
 #define BITS_EXT_SYNC_GYROX         0x40
@@ -133,6 +128,7 @@
 #define BITS_DLPF_CFG_5HZ           0x06
 #define BITS_DLPF_CFG_2100HZ_NOLPF  0x07
 #define BITS_DLPF_CFG_MASK          0x07
+/*---- MPU 'INT_CFG' register (17) ----*/
 #define BIT_ACTL                    0x80
 #define BIT_ACTL_LOW                0x80
 #define BIT_ACTL_HIGH               0x00
@@ -147,13 +143,16 @@
 #define BIT_MPU_RDY_EN              0x04
 #define BIT_DMP_INT_EN              0x02
 #define BIT_RAW_RDY_EN              0x01
+/*---- MPU 'INT_STATUS' register (1A) ----*/
 #define BIT_INT_STATUS_FIFO_OVERLOW 0x80
 #define BIT_MPU_RDY                 0x04
 #define BIT_DMP_INT                 0x02
 #define BIT_RAW_RDY                 0x01
+/*---- MPU 'BANK_SEL' register (37) ----*/
 #define BIT_PRFTCH_EN               0x20
 #define BIT_CFG_USER_BANK           0x10
 #define BITS_MEM_SEL                0x0f
+/*---- MPU 'USER_CTRL' register (3D) ----*/
 #define BIT_DMP_EN                  0x80
 #define BIT_FIFO_EN                 0x40
 #define BIT_AUX_IF_EN               0x20
@@ -162,6 +161,7 @@
 #define BIT_DMP_RST                 0x04
 #define BIT_FIFO_RST                0x02
 #define BIT_GYRO_RST                0x01
+/*---- MPU 'PWR_MGM' register (3E) ----*/
 #define BIT_H_RESET                 0x80
 #define BIT_SLEEP                   0x40
 #define BIT_STBY_XG                 0x20
@@ -169,11 +169,13 @@
 #define BIT_STBY_ZG                 0x08
 #define BITS_CLKSEL                 0x07
 
-#define MPU_SILICON_REV_A4           1	
-#define MPU_SILICON_REV_B1           2	
-#define MPU_SILICON_REV_B4           3	
-#define MPU_SILICON_REV_B6           4	
+/*---- MPU Silicon Revision ----*/
+#define MPU_SILICON_REV_A4           1	/* MPU A4 Device */
+#define MPU_SILICON_REV_B1           2	/* MPU B1 Device */
+#define MPU_SILICON_REV_B4           3	/* MPU B4 Device */
+#define MPU_SILICON_REV_B6           4	/* MPU B6 Device */
 
+/*---- MPU Memory ----*/
 #define MPU_MEM_BANK_SIZE           (256)
 #define FIFO_HW_SIZE                (512)
 
@@ -184,12 +186,15 @@
 	MPU_MEM_RAM_BANK_3,
 	MPU_MEM_NUM_RAM_BANKS,
 	MPU_MEM_OTP_BANK_0 = MPU_MEM_NUM_RAM_BANKS,
-	
+	/* This one is always last */
 	MPU_MEM_NUM_BANKS
 };
 
 #define MPU_NUM_AXES (3)
 
+/*---- structure containing control variables used by MLDL ----*/
+/*---- MPU clock source settings ----*/
+/*---- MPU filter selections ----*/
 enum mpu_filter {
 	MPU_FILTER_256HZ_NOLPF2 = 0,
 	MPU_FILTER_188HZ,
@@ -237,4 +242,4 @@
 #define DLPF_FS_SYNC_VALUE(ext_sync, full_scale, lpf) \
     ((ext_sync << 5) | (full_scale << 3) | lpf)
 
-#endif				
+#endif				/* __MPU3050_H_ */