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