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 */
161 COMPASS_ID_LSM303DLH,
162 COMPASS_ID_LSM303DLM,
164 COMPASS_ID_HSCDTD002B,
165 COMPASS_ID_HSCDTD004A,
170 enum ext_slave_endian {
171 EXT_SLAVE_BIG_ENDIAN,
172 EXT_SLAVE_LITTLE_ENDIAN,
173 EXT_SLAVE_FS8_BIG_ENDIAN,
174 EXT_SLAVE_FS16_BIG_ENDIAN,
178 EXT_SLAVE_BUS_INVALID = -1,
179 EXT_SLAVE_BUS_PRIMARY = 0,
180 EXT_SLAVE_BUS_SECONDARY = 1
185 * struct ext_slave_platform_data - Platform data for mpu3050 and mpu6050
188 * @type: the type of slave device based on the enum ext_slave_type
190 * @irq: the irq number attached to the slave if any.
191 * @adapt_num: the I2C adapter number.
192 * @bus: the bus the slave is attached to: enum ext_slave_bus
193 * @address: the I2C slave address of the slave device.
194 * @orientation: the mounting matrix of the device relative to MPU.
195 * @irq_data: private data for the slave irq handler
196 * @private_data: additional data, user customizable. Not touched by the MPU
199 * The orientation matricies are 3x3 rotation matricies
200 * that are applied to the data to rotate from the mounting orientation to the
201 * platform orientation. The values must be one of 0, 1, or -1 and each row and
202 * column should have exactly 1 non-zero value.
204 struct ext_slave_platform_data {
215 struct fix_pnt_range {
220 static inline long range_fixedpoint_to_long_mg(struct fix_pnt_range rng)
222 return (long)(rng.mantissa * 1000 + rng.fraction / 10);
225 struct ext_slave_read_trigger {
231 * struct ext_slave_descr - Description of the slave device for programming.
233 * @suspend: function pointer to put the device in suspended state
234 * @resume: function pointer to put the device in running state
235 * @read: function that reads the device data
236 * @init: function used to preallocate memory used by the driver
237 * @exit: function used to free memory allocated for the driver
238 * @config: function used to configure the device
239 * @get_config:function used to get the device's configuration
241 * @name: text name of the device
242 * @type: device type. enum ext_slave_type
243 * @id: enum ext_slave_id
244 * @read_reg: starting register address to retrieve data.
245 * @read_len: length in bytes of the sensor data. Typically 6.
246 * @endian: byte order of the data. enum ext_slave_endian
247 * @range: full scale range of the slave ouput: struct fix_pnt_range
248 * @trigger: If reading data first requires writing a register this is the
251 * Defines the functions and information about the slave the mpu3050 and
252 * mpu6050 needs to use the slave device.
254 struct ext_slave_descr {
255 int (*init) (void *mlsl_handle,
256 struct ext_slave_descr *slave,
257 struct ext_slave_platform_data *pdata);
258 int (*exit) (void *mlsl_handle,
259 struct ext_slave_descr *slave,
260 struct ext_slave_platform_data *pdata);
261 int (*suspend) (void *mlsl_handle,
262 struct ext_slave_descr *slave,
263 struct ext_slave_platform_data *pdata);
264 int (*resume) (void *mlsl_handle,
265 struct ext_slave_descr *slave,
266 struct ext_slave_platform_data *pdata);
267 int (*read) (void *mlsl_handle,
268 struct ext_slave_descr *slave,
269 struct ext_slave_platform_data *pdata,
271 int (*config) (void *mlsl_handle,
272 struct ext_slave_descr *slave,
273 struct ext_slave_platform_data *pdata,
274 struct ext_slave_config *config);
275 int (*get_config) (void *mlsl_handle,
276 struct ext_slave_descr *slave,
277 struct ext_slave_platform_data *pdata,
278 struct ext_slave_config *config);
286 struct fix_pnt_range range;
287 struct ext_slave_read_trigger *trigger;
291 * struct mpu_platform_data - Platform data for the mpu driver
292 * @int_config: Bits [7:3] of the int config register.
293 * @level_shifter: 0: VLogic, 1: VDD
294 * @orientation: Orientation matrix of the gyroscope
296 * Contains platform specific information on how to configure the MPU3050 to
297 * work on this platform. The orientation matricies are 3x3 rotation matricies
298 * that are applied to the data to rotate from the mounting orientation to the
299 * platform orientation. The values must be one of 0, 1, or -1 and each row and
300 * column should have exactly 1 non-zero value.
302 struct mpu_platform_data {
305 __s8 orientation[GYRO_NUM_AXES * GYRO_NUM_AXES];
308 #if defined __KERNEL__ || defined LINUX
309 #define MPU_IOCTL (0x81) /* Magic number for MPU Iocts */
310 /* IOCTL commands for /dev/mpu */
312 /*--------------------------------------------------------------------------
313 * Deprecated, debugging only
315 #define MPU_SET_MPU_PLATFORM_DATA \
316 _IOWR(MPU_IOCTL, 0x01, struct mpu_platform_data)
317 #define MPU_SET_EXT_SLAVE_PLATFORM_DATA \
318 _IOWR(MPU_IOCTL, 0x01, struct ext_slave_platform_data)
319 /*--------------------------------------------------------------------------*/
320 #define MPU_GET_EXT_SLAVE_PLATFORM_DATA \
321 _IOWR(MPU_IOCTL, 0x02, struct ext_slave_platform_data)
322 #define MPU_GET_MPU_PLATFORM_DATA \
323 _IOWR(MPU_IOCTL, 0x02, struct mpu_platform_data)
324 #define MPU_GET_EXT_SLAVE_DESCR \
325 _IOWR(MPU_IOCTL, 0x02, struct ext_slave_descr)
327 #define MPU_READ _IOWR(MPU_IOCTL, 0x10, struct mpu_read_write)
328 #define MPU_WRITE _IOW(MPU_IOCTL, 0x10, struct mpu_read_write)
329 #define MPU_READ_MEM _IOWR(MPU_IOCTL, 0x11, struct mpu_read_write)
330 #define MPU_WRITE_MEM _IOW(MPU_IOCTL, 0x11, struct mpu_read_write)
331 #define MPU_READ_FIFO _IOWR(MPU_IOCTL, 0x12, struct mpu_read_write)
332 #define MPU_WRITE_FIFO _IOW(MPU_IOCTL, 0x12, struct mpu_read_write)
334 #define MPU_READ_COMPASS _IOR(MPU_IOCTL, 0x12, __u8)
335 #define MPU_READ_ACCEL _IOR(MPU_IOCTL, 0x13, __u8)
336 #define MPU_READ_PRESSURE _IOR(MPU_IOCTL, 0x14, __u8)
338 #define MPU_CONFIG_GYRO _IOW(MPU_IOCTL, 0x20, struct ext_slave_config)
339 #define MPU_CONFIG_ACCEL _IOW(MPU_IOCTL, 0x21, struct ext_slave_config)
340 #define MPU_CONFIG_COMPASS _IOW(MPU_IOCTL, 0x22, struct ext_slave_config)
341 #define MPU_CONFIG_PRESSURE _IOW(MPU_IOCTL, 0x23, struct ext_slave_config)
343 #define MPU_GET_CONFIG_GYRO _IOWR(MPU_IOCTL, 0x20, struct ext_slave_config)
344 #define MPU_GET_CONFIG_ACCEL _IOWR(MPU_IOCTL, 0x21, struct ext_slave_config)
345 #define MPU_GET_CONFIG_COMPASS _IOWR(MPU_IOCTL, 0x22, struct ext_slave_config)
346 #define MPU_GET_CONFIG_PRESSURE _IOWR(MPU_IOCTL, 0x23, struct ext_slave_config)
348 #define MPU_SUSPEND _IOW(MPU_IOCTL, 0x30, __u32)
349 #define MPU_RESUME _IOW(MPU_IOCTL, 0x31, __u32)
350 /* Userspace PM Event response */
351 #define MPU_PM_EVENT_HANDLED _IO(MPU_IOCTL, 0x32)
353 #define MPU_GET_REQUESTED_SENSORS _IOR(MPU_IOCTL, 0x40, __u8)
354 #define MPU_SET_REQUESTED_SENSORS _IOW(MPU_IOCTL, 0x40, __u8)
355 #define MPU_GET_IGNORE_SYSTEM_SUSPEND _IOR(MPU_IOCTL, 0x41, __u8)
356 #define MPU_SET_IGNORE_SYSTEM_SUSPEND _IOW(MPU_IOCTL, 0x41, __u8)
357 #define MPU_GET_MLDL_STATUS _IOR(MPU_IOCTL, 0x42, __u8)
358 #define MPU_GET_I2C_SLAVES_ENABLED _IOR(MPU_IOCTL, 0x43, __u8)
362 #endif /* __MPU_H_ */