dts:arm:rk3288-box: ddr frequency set to 533 when playing 4K video.
[firefly-linux-kernel-4.4.55.git] / include / linux / mpu.h
1 /*
2  $License:
3     Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
4  $
5  */
6
7 #ifndef __MPU_H_
8 #define __MPU_H_
9
10 #ifdef __KERNEL__
11 #include <linux/types.h>
12 #include <linux/ioctl.h>
13 #elif defined LINUX
14 #include <sys/ioctl.h>
15 #include <linux/types.h>
16 #else
17 #include "mltypes.h"
18 #endif
19
20 /* Number of axes on each sensor */
21 #define GYRO_NUM_AXES               (3)
22 #define ACCEL_NUM_AXES              (3)
23 #define COMPASS_NUM_AXES            (3)
24
25 struct mpu_read_write {
26         /* Memory address or register address depending on ioctl */
27         __u16 address;
28         __u16 length;
29         __u8 *data;
30 };
31
32 enum mpuirq_data_type {
33         MPUIRQ_DATA_TYPE_MPU_IRQ,
34         MPUIRQ_DATA_TYPE_SLAVE_IRQ,
35         MPUIRQ_DATA_TYPE_PM_EVENT,
36         MPUIRQ_DATA_TYPE_NUM_TYPES,
37 };
38
39 /* User space PM event notification */
40 #define MPU_PM_EVENT_SUSPEND_PREPARE (3)
41 #define MPU_PM_EVENT_POST_SUSPEND    (4)
42
43 struct mpuirq_data {
44         __u32 interruptcount;
45         __u64 irqtime;
46         __u32 data_type;
47         __s32 data;
48 };
49
50 enum ext_slave_config_key {
51         MPU_SLAVE_CONFIG_ODR_SUSPEND,
52         MPU_SLAVE_CONFIG_ODR_RESUME,
53         MPU_SLAVE_CONFIG_FSR_SUSPEND,
54         MPU_SLAVE_CONFIG_FSR_RESUME,
55         MPU_SLAVE_CONFIG_MOT_THS,
56         MPU_SLAVE_CONFIG_NMOT_THS,
57         MPU_SLAVE_CONFIG_MOT_DUR,
58         MPU_SLAVE_CONFIG_NMOT_DUR,
59         MPU_SLAVE_CONFIG_IRQ_SUSPEND,
60         MPU_SLAVE_CONFIG_IRQ_RESUME,
61         MPU_SLAVE_WRITE_REGISTERS,
62         MPU_SLAVE_READ_REGISTERS,
63         MPU_SLAVE_CONFIG_INTERNAL_REFERENCE,
64         /* AMI 306 specific config keys */
65         MPU_SLAVE_PARAM,
66         MPU_SLAVE_WINDOW,
67         MPU_SLAVE_READWINPARAMS,
68         MPU_SLAVE_SEARCHOFFSET,
69         /* AKM specific config keys */
70         MPU_SLAVE_READ_SCALE,
71         /* MPU3050 and MPU6050 Keys */
72         MPU_SLAVE_INT_CONFIG,
73         MPU_SLAVE_EXT_SYNC,
74         MPU_SLAVE_FULL_SCALE,
75         MPU_SLAVE_LPF,
76         MPU_SLAVE_CLK_SRC,
77         MPU_SLAVE_DIVIDER,
78         MPU_SLAVE_DMP_ENABLE,
79         MPU_SLAVE_FIFO_ENABLE,
80         MPU_SLAVE_DMP_CFG1,
81         MPU_SLAVE_DMP_CFG2,
82         MPU_SLAVE_TC,
83         MPU_SLAVE_GYRO,
84         MPU_SLAVE_ADDR,
85         MPU_SLAVE_PRODUCT_REVISION,
86         MPU_SLAVE_SILICON_REVISION,
87         MPU_SLAVE_PRODUCT_ID,
88         MPU_SLAVE_GYRO_SENS_TRIM,
89         MPU_SLAVE_ACCEL_SENS_TRIM,
90         MPU_SLAVE_RAM,
91         /* -------------------------- */
92         MPU_SLAVE_CONFIG_NUM_CONFIG_KEYS
93 };
94
95 /* For the MPU_SLAVE_CONFIG_IRQ_SUSPEND and MPU_SLAVE_CONFIG_IRQ_RESUME */
96 enum ext_slave_config_irq_type {
97         MPU_SLAVE_IRQ_TYPE_NONE,
98         MPU_SLAVE_IRQ_TYPE_MOTION,
99         MPU_SLAVE_IRQ_TYPE_DATA_READY,
100 };
101
102 /* Structure for the following IOCTS's
103  * MPU_CONFIG_GYRO
104  * MPU_CONFIG_ACCEL
105  * MPU_CONFIG_COMPASS
106  * MPU_CONFIG_PRESSURE
107  * MPU_GET_CONFIG_GYRO
108  * MPU_GET_CONFIG_ACCEL
109  * MPU_GET_CONFIG_COMPASS
110  * MPU_GET_CONFIG_PRESSURE
111  *
112  * @key one of enum ext_slave_config_key
113  * @len length of data pointed to by data
114  * @apply zero if communication with the chip is not necessary, false otherwise
115  *        This flag can be used to select cached data or to refresh cashed data
116  *        cache data to be pushed later or push immediately.  If true and the
117  *        slave is on the secondary bus the MPU will first enger bypass mode
118  *        before calling the slaves .config or .get_config funcion
119  * @data pointer to the data to confgure or get
120  */
121 struct ext_slave_config {
122         __u8 key;
123         __u16 len;
124         __u8 apply;
125         void *data;
126 };
127
128 enum ext_slave_type {
129         EXT_SLAVE_TYPE_GYROSCOPE,
130         EXT_SLAVE_TYPE_ACCEL,
131         EXT_SLAVE_TYPE_COMPASS,
132         EXT_SLAVE_TYPE_PRESSURE,
133         /*EXT_SLAVE_TYPE_TEMPERATURE */
134
135         EXT_SLAVE_NUM_TYPES
136 };
137
138 enum ext_slave_id {
139         ID_INVALID = 0,
140
141         ACCEL_ID_LIS331,
142         ACCEL_ID_LSM303DLX,
143         ACCEL_ID_LIS3DH,
144         ACCEL_ID_KXSD9,
145         ACCEL_ID_KXTF9,
146         ACCEL_ID_BMA150,
147         ACCEL_ID_BMA222,
148         ACCEL_ID_BMA250,
149         ACCEL_ID_ADXL34X,
150         ACCEL_ID_MMA8450,
151         ACCEL_ID_MMA845X,
152         ACCEL_ID_MPU6050,
153
154         COMPASS_ID_AK8975,
155         COMPASS_ID_AK8972,
156         COMPASS_ID_AK8963,
157         COMPASS_ID_AMI30X,
158         COMPASS_ID_AMI306,
159         COMPASS_ID_YAS529,
160         COMPASS_ID_YAS530,
161         COMPASS_ID_HMC5883,
162         COMPASS_ID_LSM303DLH,
163         COMPASS_ID_LSM303DLM,
164         COMPASS_ID_MMC314X,
165         COMPASS_ID_MMC328X,
166         COMPASS_ID_HSCDTD002B,
167         COMPASS_ID_HSCDTD004A,
168
169         PRESSURE_ID_BMA085,
170 };
171
172 enum ext_slave_endian {
173         EXT_SLAVE_BIG_ENDIAN,
174         EXT_SLAVE_LITTLE_ENDIAN,
175         EXT_SLAVE_FS8_BIG_ENDIAN,
176         EXT_SLAVE_FS16_BIG_ENDIAN,
177 };
178
179 enum ext_slave_bus {
180         EXT_SLAVE_BUS_INVALID = -1,
181         EXT_SLAVE_BUS_PRIMARY = 0,
182         EXT_SLAVE_BUS_SECONDARY = 1
183 };
184
185
186 /**
187  *  struct ext_slave_platform_data - Platform data for mpu3050 and mpu6050
188  *  slave devices
189  *
190  *  @type: the type of slave device based on the enum ext_slave_type
191  *         definitions.
192  *  @irq: the irq number attached to the slave if any.
193  *  @adapt_num: the I2C adapter number.
194  *  @bus: the bus the slave is attached to: enum ext_slave_bus
195  *  @address: the I2C slave address of the slave device.
196  *  @orientation: the mounting matrix of the device relative to MPU.
197  *  @irq_data: private data for the slave irq handler
198  *  @private_data: additional data, user customizable.  Not touched by the MPU
199  *                 driver.
200  *
201  * The orientation matricies are 3x3 rotation matricies
202  * that are applied to the data to rotate from the mounting orientation to the
203  * platform orientation.  The values must be one of 0, 1, or -1 and each row and
204  * column should have exactly 1 non-zero value.
205  */
206 struct ext_slave_platform_data {
207         __u8 type;
208         __u32 irq;
209         __u32 adapt_num;
210         __u32 bus;
211         __u8 address;
212         __s8 orientation[9];
213         void *irq_data;
214         void *private_data;
215 };
216
217 struct fix_pnt_range {
218         __s32 mantissa;
219         __s32 fraction;
220 };
221
222 static inline long range_fixedpoint_to_long_mg(struct fix_pnt_range rng)
223 {
224         return (long)(rng.mantissa * 1000 + rng.fraction / 10);
225 }
226
227 struct ext_slave_read_trigger {
228         __u8 reg;
229         __u8 value;
230 };
231
232 /**
233  *  struct ext_slave_descr - Description of the slave device for programming.
234  *
235  *  @suspend:   function pointer to put the device in suspended state
236  *  @resume:    function pointer to put the device in running state
237  *  @read:      function that reads the device data
238  *  @init:      function used to preallocate memory used by the driver
239  *  @exit:      function used to free memory allocated for the driver
240  *  @config:    function used to configure the device
241  *  @get_config:function used to get the device's configuration
242  *
243  *  @name:      text name of the device
244  *  @type:      device type. enum ext_slave_type
245  *  @id:        enum ext_slave_id
246  *  @read_reg:  starting register address to retrieve data.
247  *  @read_len:  length in bytes of the sensor data.  Typically  6.
248  *  @endian:    byte order of the data. enum ext_slave_endian
249  *  @range:     full scale range of the slave ouput: struct fix_pnt_range
250  *  @trigger:   If reading data first requires writing a register this is the
251  *              data to write.
252  *
253  *  Defines the functions and information about the slave the mpu3050 and
254  *  mpu6050 needs to use the slave device.
255  */
256 struct ext_slave_descr {
257         int (*init) (void *mlsl_handle,
258                      struct ext_slave_descr *slave,
259                      struct ext_slave_platform_data *pdata);
260         int (*exit) (void *mlsl_handle,
261                      struct ext_slave_descr *slave,
262                      struct ext_slave_platform_data *pdata);
263         int (*suspend) (void *mlsl_handle,
264                         struct ext_slave_descr *slave,
265                         struct ext_slave_platform_data *pdata);
266         int (*resume) (void *mlsl_handle,
267                        struct ext_slave_descr *slave,
268                        struct ext_slave_platform_data *pdata);
269         int (*read) (void *mlsl_handle,
270                      struct ext_slave_descr *slave,
271                      struct ext_slave_platform_data *pdata,
272                      __u8 *data);
273         int (*config) (void *mlsl_handle,
274                        struct ext_slave_descr *slave,
275                        struct ext_slave_platform_data *pdata,
276                        struct ext_slave_config *config);
277         int (*get_config) (void *mlsl_handle,
278                            struct ext_slave_descr *slave,
279                            struct ext_slave_platform_data *pdata,
280                            struct ext_slave_config *config);
281
282         char *name;
283         __u8 type;
284         __u8 id;
285         __u8 read_reg;
286         __u8 read_len;
287         __u8 endian;
288         struct fix_pnt_range range;
289         struct ext_slave_read_trigger *trigger;
290 };
291
292 /**
293  * struct mpu_platform_data - Platform data for the mpu driver
294  * @int_config:         Bits [7:3] of the int config register.
295  * @level_shifter:      0: VLogic, 1: VDD
296  * @orientation:        Orientation matrix of the gyroscope
297  *
298  * Contains platform specific information on how to configure the MPU3050 to
299  * work on this platform.  The orientation matricies are 3x3 rotation matricies
300  * that are applied to the data to rotate from the mounting orientation to the
301  * platform orientation.  The values must be one of 0, 1, or -1 and each row and
302  * column should have exactly 1 non-zero value.
303  */
304 struct mpu_platform_data {
305         __u32 int_config;
306         __u32 level_shifter;
307         __s8 orientation[GYRO_NUM_AXES * GYRO_NUM_AXES];
308 };
309
310 #if defined __KERNEL__ || defined LINUX
311 #define MPU_IOCTL (0x81) /* Magic number for MPU Iocts */
312 /* IOCTL commands for /dev/mpu */
313
314 /*--------------------------------------------------------------------------
315  * Deprecated, debugging only
316  */
317 #define MPU_SET_MPU_PLATFORM_DATA       \
318         _IOWR(MPU_IOCTL, 0x01, struct mpu_platform_data)
319 #define MPU_SET_EXT_SLAVE_PLATFORM_DATA \
320         _IOWR(MPU_IOCTL, 0x01, struct ext_slave_platform_data)
321 /*--------------------------------------------------------------------------*/
322 #define MPU_GET_EXT_SLAVE_PLATFORM_DATA \
323         _IOWR(MPU_IOCTL, 0x02, struct ext_slave_platform_data)
324 #define MPU_GET_MPU_PLATFORM_DATA       \
325         _IOWR(MPU_IOCTL, 0x02, struct mpu_platform_data)
326 #define MPU_GET_EXT_SLAVE_DESCR \
327         _IOWR(MPU_IOCTL, 0x02, struct ext_slave_descr)
328
329 #define MPU_READ                _IOWR(MPU_IOCTL, 0x10, struct mpu_read_write)
330 #define MPU_WRITE               _IOW(MPU_IOCTL,  0x10, struct mpu_read_write)
331 #define MPU_READ_MEM            _IOWR(MPU_IOCTL, 0x11, struct mpu_read_write)
332 #define MPU_WRITE_MEM           _IOW(MPU_IOCTL,  0x11, struct mpu_read_write)
333 #define MPU_READ_FIFO           _IOWR(MPU_IOCTL, 0x12, struct mpu_read_write)
334 #define MPU_WRITE_FIFO          _IOW(MPU_IOCTL,  0x12, struct mpu_read_write)
335
336 #define MPU_READ_COMPASS        _IOR(MPU_IOCTL, 0x12, __u8)
337 #define MPU_READ_ACCEL          _IOR(MPU_IOCTL, 0x13, __u8)
338 #define MPU_READ_PRESSURE       _IOR(MPU_IOCTL, 0x14, __u8)
339
340 #define MPU_CONFIG_GYRO         _IOW(MPU_IOCTL, 0x20, struct ext_slave_config)
341 #define MPU_CONFIG_ACCEL        _IOW(MPU_IOCTL, 0x21, struct ext_slave_config)
342 #define MPU_CONFIG_COMPASS      _IOW(MPU_IOCTL, 0x22, struct ext_slave_config)
343 #define MPU_CONFIG_PRESSURE     _IOW(MPU_IOCTL, 0x23, struct ext_slave_config)
344
345 #define MPU_GET_CONFIG_GYRO     _IOWR(MPU_IOCTL, 0x20, struct ext_slave_config)
346 #define MPU_GET_CONFIG_ACCEL    _IOWR(MPU_IOCTL, 0x21, struct ext_slave_config)
347 #define MPU_GET_CONFIG_COMPASS  _IOWR(MPU_IOCTL, 0x22, struct ext_slave_config)
348 #define MPU_GET_CONFIG_PRESSURE _IOWR(MPU_IOCTL, 0x23, struct ext_slave_config)
349
350 #define MPU_SUSPEND             _IOW(MPU_IOCTL, 0x30, __u32)
351 #define MPU_RESUME              _IOW(MPU_IOCTL, 0x31, __u32)
352 /* Userspace PM Event response */
353 #define MPU_PM_EVENT_HANDLED    _IO(MPU_IOCTL, 0x32)
354
355 #define MPU_GET_REQUESTED_SENSORS       _IOR(MPU_IOCTL, 0x40, __u8)
356 #define MPU_SET_REQUESTED_SENSORS       _IOW(MPU_IOCTL, 0x40, __u8)
357 #define MPU_GET_IGNORE_SYSTEM_SUSPEND   _IOR(MPU_IOCTL, 0x41, __u8)
358 #define MPU_SET_IGNORE_SYSTEM_SUSPEND   _IOW(MPU_IOCTL, 0x41, __u8)
359 #define MPU_GET_MLDL_STATUS             _IOR(MPU_IOCTL, 0x42, __u8)
360 #define MPU_GET_I2C_SLAVES_ENABLED      _IOR(MPU_IOCTL, 0x43, __u8)
361
362 #endif
363
364 #endif                          /* __MPU_H_ */