3 Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
11 #include <linux/types.h>
12 #include <linux/ioctl.h>
14 #include <sys/ioctl.h>
15 #include <linux/types.h>
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)
25 struct mpu_read_write {
26 /* Memory address or register address depending on ioctl */
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,
39 /* User space PM event notification */
40 #define MPU_PM_EVENT_SUSPEND_PREPARE (3)
41 #define MPU_PM_EVENT_POST_SUSPEND (4)
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 */
67 MPU_SLAVE_READWINPARAMS,
68 MPU_SLAVE_SEARCHOFFSET,
69 /* AKM specific config keys */
71 /* MPU3050 and MPU6050 Keys */
79 MPU_SLAVE_FIFO_ENABLE,
85 MPU_SLAVE_PRODUCT_REVISION,
86 MPU_SLAVE_SILICON_REVISION,
88 MPU_SLAVE_GYRO_SENS_TRIM,
89 MPU_SLAVE_ACCEL_SENS_TRIM,
91 /* -------------------------- */
92 MPU_SLAVE_CONFIG_NUM_CONFIG_KEYS
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,
102 /* Structure for the following IOCTS's
106 * MPU_CONFIG_PRESSURE
107 * MPU_GET_CONFIG_GYRO
108 * MPU_GET_CONFIG_ACCEL
109 * MPU_GET_CONFIG_COMPASS
110 * MPU_GET_CONFIG_PRESSURE
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
121 struct ext_slave_config {
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 */
162 COMPASS_ID_LSM303DLH,
163 COMPASS_ID_LSM303DLM,
166 COMPASS_ID_HSCDTD002B,
167 COMPASS_ID_HSCDTD004A,
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,
180 EXT_SLAVE_BUS_INVALID = -1,
181 EXT_SLAVE_BUS_PRIMARY = 0,
182 EXT_SLAVE_BUS_SECONDARY = 1
187 * struct ext_slave_platform_data - Platform data for mpu3050 and mpu6050
190 * @type: the type of slave device based on the enum ext_slave_type
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
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.
206 struct ext_slave_platform_data {
217 struct fix_pnt_range {
222 static inline long range_fixedpoint_to_long_mg(struct fix_pnt_range rng)
224 return (long)(rng.mantissa * 1000 + rng.fraction / 10);
227 struct ext_slave_read_trigger {
233 * struct ext_slave_descr - Description of the slave device for programming.
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
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
253 * Defines the functions and information about the slave the mpu3050 and
254 * mpu6050 needs to use the slave device.
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,
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);
288 struct fix_pnt_range range;
289 struct ext_slave_read_trigger *trigger;
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
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.
304 struct mpu_platform_data {
307 __s8 orientation[GYRO_NUM_AXES * GYRO_NUM_AXES];
310 #if defined __KERNEL__ || defined LINUX
311 #define MPU_IOCTL (0x81) /* Magic number for MPU Iocts */
312 /* IOCTL commands for /dev/mpu */
314 /*--------------------------------------------------------------------------
315 * Deprecated, debugging only
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)
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)
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)
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)
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)
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)
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)
364 #endif /* __MPU_H_ */