3 Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
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.
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.
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/>.
23 #include <linux/types.h>
24 #include <linux/ioctl.h>
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)
31 struct mpu_read_write {
32 /* Memory address or register address depending on ioctl */
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,
45 /* User space PM event notification */
46 #define MPU_PM_EVENT_SUSPEND_PREPARE (3)
47 #define MPU_PM_EVENT_POST_SUSPEND (4)
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 */
73 MPU_SLAVE_READWINPARAMS,
74 MPU_SLAVE_SEARCHOFFSET,
75 /* AKM specific config keys */
77 /* MPU3050 and MPU6050 Keys */
85 MPU_SLAVE_FIFO_ENABLE,
91 MPU_SLAVE_PRODUCT_REVISION,
92 MPU_SLAVE_SILICON_REVISION,
94 MPU_SLAVE_GYRO_SENS_TRIM,
95 MPU_SLAVE_ACCEL_SENS_TRIM,
97 /* -------------------------- */
98 MPU_SLAVE_CONFIG_NUM_CONFIG_KEYS
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,
108 /* Structure for the following IOCTS's
112 * MPU_CONFIG_PRESSURE
113 * MPU_GET_CONFIG_GYRO
114 * MPU_GET_CONFIG_ACCEL
115 * MPU_GET_CONFIG_COMPASS
116 * MPU_GET_CONFIG_PRESSURE
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
127 struct ext_slave_config {
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 */
168 COMPASS_ID_LSM303DLH,
169 COMPASS_ID_LSM303DLM,
171 COMPASS_ID_HSCDTD002B,
172 COMPASS_ID_HSCDTD004A,
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,
185 EXT_SLAVE_BUS_INVALID = -1,
186 EXT_SLAVE_BUS_PRIMARY = 0,
187 EXT_SLAVE_BUS_SECONDARY = 1
192 * struct ext_slave_platform_data - Platform data for mpu3050 and mpu6050
195 * @type: the type of slave device based on the enum ext_slave_type
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
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.
211 struct ext_slave_platform_data {
222 struct fix_pnt_range {
227 static inline long range_fixedpoint_to_long_mg(struct fix_pnt_range rng)
229 return (long)(rng.mantissa * 1000 + rng.fraction / 10);
232 struct ext_slave_read_trigger {
238 * struct ext_slave_descr - Description of the slave device for programming.
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
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
258 * Defines the functions and information about the slave the mpu3050 and
259 * mpu6050 needs to use the slave device.
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,
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);
293 struct fix_pnt_range range;
294 struct ext_slave_read_trigger *trigger;
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
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.
309 struct mpu_platform_data {
312 __s8 orientation[GYRO_NUM_AXES * GYRO_NUM_AXES];
315 #define MPU_IOCTL (0x81) /* Magic number for MPU Iocts */
316 /* IOCTL commands for /dev/mpu */
318 /*--------------------------------------------------------------------------
319 * Deprecated, debugging only
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)
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)
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)
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)
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)
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)
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)
367 #endif /* __MPU_H_ */