blob: 034dad80dd2944d4a059f70274965e9601c085b0 [file] [log] [blame]
Flemmard0604a8e2013-05-23 16:15:48 -07001/*
2 $License:
3 Copyright (C) 2010 InvenSense Corporation, All Rights Reserved.
trostanski576fee12013-12-13 09:50:30 +01004 $
Flemmard0604a8e2013-05-23 16:15:48 -07005 */
6
7#ifndef __MPU3050_H_
8#define __MPU3050_H_
9
Flemmard0604a8e2013-05-23 16:15:48 -070010#include <linux/types.h>
trostanski576fee12013-12-13 09:50:30 +010011#include <linux/i2c.h>
12#include <linux/i2c-dev.h>
Flemmard0604a8e2013-05-23 16:15:48 -070013
trostanski576fee12013-12-13 09:50:30 +010014#if defined(MPUDEBUG)
15#define mpu_dbg(format, arg...) \
16 printk(KERN_DEBUG format, ## arg);
17#else
18#define mpu_dbg(format, arg...)
Flemmard0604a8e2013-05-23 16:15:48 -070019#endif
20
21#define MPU_NAME "mpu3050"
22#define DEFAULT_MPU_SLAVEADDR 0x68
23
trostanski576fee12013-12-13 09:50:30 +010024/*==== MPU REGISTER SET ====*/
Flemmard0604a8e2013-05-23 16:15:48 -070025enum mpu_register {
trostanski576fee12013-12-13 09:50:30 +010026 MPUREG_WHO_AM_I = 0, /* 00 0x00 */
27 MPUREG_PRODUCT_ID, /* 01 0x01 */
28 MPUREG_02_RSVD, /* 02 0x02 */
29 MPUREG_03_RSVD, /* 03 0x03 */
30 MPUREG_04_RSVD, /* 04 0x04 */
31 MPUREG_XG_OFFS_TC, /* 05 0x05 */
32 MPUREG_06_RSVD, /* 06 0x06 */
33 MPUREG_07_RSVD, /* 07 0x07 */
34 MPUREG_YG_OFFS_TC, /* 08 0x08 */
35 MPUREG_09_RSVD, /* 09 0x09 */
36 MPUREG_0A_RSVD, /* 10 0x0a */
37 MPUREG_ZG_OFFS_TC, /* 11 0x0b */
38 MPUREG_X_OFFS_USRH, /* 12 0x0c */
39 MPUREG_X_OFFS_USRL, /* 13 0x0d */
40 MPUREG_Y_OFFS_USRH, /* 14 0x0e */
41 MPUREG_Y_OFFS_USRL, /* 15 0x0f */
42 MPUREG_Z_OFFS_USRH, /* 16 0x10 */
43 MPUREG_Z_OFFS_USRL, /* 17 0x11 */
44 MPUREG_FIFO_EN1, /* 18 0x12 */
45 MPUREG_FIFO_EN2, /* 19 0x13 */
46 MPUREG_AUX_SLV_ADDR, /* 20 0x14 */
47 MPUREG_SMPLRT_DIV, /* 21 0x15 */
48 MPUREG_DLPF_FS_SYNC, /* 22 0x16 */
49 MPUREG_INT_CFG, /* 23 0x17 */
50 MPUREG_ACCEL_BURST_ADDR,/* 24 0x18 */
51 MPUREG_19_RSVD, /* 25 0x19 */
52 MPUREG_INT_STATUS, /* 26 0x1a */
53 MPUREG_TEMP_OUT_H, /* 27 0x1b */
54 MPUREG_TEMP_OUT_L, /* 28 0x1c */
55 MPUREG_GYRO_XOUT_H, /* 29 0x1d */
56 MPUREG_GYRO_XOUT_L, /* 30 0x1e */
57 MPUREG_GYRO_YOUT_H, /* 31 0x1f */
58 MPUREG_GYRO_YOUT_L, /* 32 0x20 */
59 MPUREG_GYRO_ZOUT_H, /* 33 0x21 */
60 MPUREG_GYRO_ZOUT_L, /* 34 0x22 */
61 MPUREG_23_RSVD, /* 35 0x23 */
62 MPUREG_24_RSVD, /* 36 0x24 */
63 MPUREG_25_RSVD, /* 37 0x25 */
64 MPUREG_26_RSVD, /* 38 0x26 */
65 MPUREG_27_RSVD, /* 39 0x27 */
66 MPUREG_28_RSVD, /* 40 0x28 */
67 MPUREG_29_RSVD, /* 41 0x29 */
68 MPUREG_2A_RSVD, /* 42 0x2a */
69 MPUREG_2B_RSVD, /* 43 0x2b */
70 MPUREG_2C_RSVD, /* 44 0x2c */
71 MPUREG_2D_RSVD, /* 45 0x2d */
72 MPUREG_2E_RSVD, /* 46 0x2e */
73 MPUREG_2F_RSVD, /* 47 0x2f */
74 MPUREG_30_RSVD, /* 48 0x30 */
75 MPUREG_31_RSVD, /* 49 0x31 */
76 MPUREG_32_RSVD, /* 50 0x32 */
77 MPUREG_33_RSVD, /* 51 0x33 */
78 MPUREG_34_RSVD, /* 52 0x34 */
79 MPUREG_DMP_CFG_1, /* 53 0x35 */
80 MPUREG_DMP_CFG_2, /* 54 0x36 */
81 MPUREG_BANK_SEL, /* 55 0x37 */
82 MPUREG_MEM_START_ADDR, /* 56 0x38 */
83 MPUREG_MEM_R_W, /* 57 0x39 */
84 MPUREG_FIFO_COUNTH, /* 58 0x3a */
85 MPUREG_FIFO_COUNTL, /* 59 0x3b */
86 MPUREG_FIFO_R_W, /* 60 0x3c */
87 MPUREG_USER_CTRL, /* 61 0x3d */
88 MPUREG_PWR_MGM, /* 62 0x3e */
89 MPUREG_3F_RSVD, /* 63 0x3f */
90 NUM_OF_MPU_REGISTERS /* 64 0x40 */
Flemmard0604a8e2013-05-23 16:15:48 -070091};
92
trostanski576fee12013-12-13 09:50:30 +010093/*==== BITS FOR MPU ====*/
Flemmard0604a8e2013-05-23 16:15:48 -070094
trostanski576fee12013-12-13 09:50:30 +010095/*---- MPU 'FIFO_EN1' register (12) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -070096#define BIT_TEMP_OUT 0x80
97#define BIT_GYRO_XOUT 0x40
98#define BIT_GYRO_YOUT 0x20
99#define BIT_GYRO_ZOUT 0x10
100#define BIT_ACCEL_XOUT 0x08
101#define BIT_ACCEL_YOUT 0x04
102#define BIT_ACCEL_ZOUT 0x02
103#define BIT_AUX_1OUT 0x01
trostanski576fee12013-12-13 09:50:30 +0100104/*---- MPU 'FIFO_EN2' register (13) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700105#define BIT_AUX_2OUT 0x02
106#define BIT_AUX_3OUT 0x01
trostanski576fee12013-12-13 09:50:30 +0100107/*---- MPU 'DLPF_FS_SYNC' register (16) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700108#define BITS_EXT_SYNC_NONE 0x00
109#define BITS_EXT_SYNC_TEMP 0x20
110#define BITS_EXT_SYNC_GYROX 0x40
111#define BITS_EXT_SYNC_GYROY 0x60
112#define BITS_EXT_SYNC_GYROZ 0x80
113#define BITS_EXT_SYNC_ACCELX 0xA0
114#define BITS_EXT_SYNC_ACCELY 0xC0
115#define BITS_EXT_SYNC_ACCELZ 0xE0
116#define BITS_EXT_SYNC_MASK 0xE0
117#define BITS_FS_250DPS 0x00
118#define BITS_FS_500DPS 0x08
119#define BITS_FS_1000DPS 0x10
120#define BITS_FS_2000DPS 0x18
121#define BITS_FS_MASK 0x18
122#define BITS_DLPF_CFG_256HZ_NOLPF2 0x00
123#define BITS_DLPF_CFG_188HZ 0x01
124#define BITS_DLPF_CFG_98HZ 0x02
125#define BITS_DLPF_CFG_42HZ 0x03
126#define BITS_DLPF_CFG_20HZ 0x04
127#define BITS_DLPF_CFG_10HZ 0x05
128#define BITS_DLPF_CFG_5HZ 0x06
129#define BITS_DLPF_CFG_2100HZ_NOLPF 0x07
130#define BITS_DLPF_CFG_MASK 0x07
trostanski576fee12013-12-13 09:50:30 +0100131/*---- MPU 'INT_CFG' register (17) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700132#define BIT_ACTL 0x80
133#define BIT_ACTL_LOW 0x80
134#define BIT_ACTL_HIGH 0x00
135#define BIT_OPEN 0x40
136#define BIT_OPEN_DRAIN 0x40
137#define BIT_PUSH_PULL 0x00
138#define BIT_LATCH_INT_EN 0x20
139#define BIT_LATCH_INT_EN 0x20
140#define BIT_INT_PULSE_WIDTH_50US 0x00
141#define BIT_INT_ANYRD_2CLEAR 0x10
142#define BIT_INT_STAT_READ_2CLEAR 0x00
143#define BIT_MPU_RDY_EN 0x04
144#define BIT_DMP_INT_EN 0x02
145#define BIT_RAW_RDY_EN 0x01
trostanski576fee12013-12-13 09:50:30 +0100146/*---- MPU 'INT_STATUS' register (1A) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700147#define BIT_INT_STATUS_FIFO_OVERLOW 0x80
148#define BIT_MPU_RDY 0x04
149#define BIT_DMP_INT 0x02
150#define BIT_RAW_RDY 0x01
trostanski576fee12013-12-13 09:50:30 +0100151/*---- MPU 'BANK_SEL' register (37) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700152#define BIT_PRFTCH_EN 0x20
153#define BIT_CFG_USER_BANK 0x10
154#define BITS_MEM_SEL 0x0f
trostanski576fee12013-12-13 09:50:30 +0100155/*---- MPU 'USER_CTRL' register (3D) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700156#define BIT_DMP_EN 0x80
157#define BIT_FIFO_EN 0x40
158#define BIT_AUX_IF_EN 0x20
159#define BIT_AUX_RD_LENG 0x10
160#define BIT_AUX_IF_RST 0x08
161#define BIT_DMP_RST 0x04
162#define BIT_FIFO_RST 0x02
163#define BIT_GYRO_RST 0x01
trostanski576fee12013-12-13 09:50:30 +0100164/*---- MPU 'PWR_MGM' register (3E) ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700165#define BIT_H_RESET 0x80
166#define BIT_SLEEP 0x40
167#define BIT_STBY_XG 0x20
168#define BIT_STBY_YG 0x10
169#define BIT_STBY_ZG 0x08
170#define BITS_CLKSEL 0x07
171
trostanski576fee12013-12-13 09:50:30 +0100172/*---- MPU Silicon Revision ----*/
173#define MPU_SILICON_REV_A4 1 /* MPU A4 Device */
174#define MPU_SILICON_REV_B1 2 /* MPU B1 Device */
175#define MPU_SILICON_REV_B4 3 /* MPU B4 Device */
176#define MPU_SILICON_REV_B6 4 /* MPU B6 Device */
Flemmard0604a8e2013-05-23 16:15:48 -0700177
trostanski576fee12013-12-13 09:50:30 +0100178/*---- MPU Memory ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700179#define MPU_MEM_BANK_SIZE (256)
180#define FIFO_HW_SIZE (512)
181
182enum MPU_MEMORY_BANKS {
183 MPU_MEM_RAM_BANK_0 = 0,
184 MPU_MEM_RAM_BANK_1,
185 MPU_MEM_RAM_BANK_2,
186 MPU_MEM_RAM_BANK_3,
187 MPU_MEM_NUM_RAM_BANKS,
188 MPU_MEM_OTP_BANK_0 = MPU_MEM_NUM_RAM_BANKS,
trostanski576fee12013-12-13 09:50:30 +0100189 /* This one is always last */
Flemmard0604a8e2013-05-23 16:15:48 -0700190 MPU_MEM_NUM_BANKS
191};
192
193#define MPU_NUM_AXES (3)
194
trostanski576fee12013-12-13 09:50:30 +0100195/*---- structure containing control variables used by MLDL ----*/
196/*---- MPU clock source settings ----*/
197/*---- MPU filter selections ----*/
Flemmard0604a8e2013-05-23 16:15:48 -0700198enum mpu_filter {
199 MPU_FILTER_256HZ_NOLPF2 = 0,
200 MPU_FILTER_188HZ,
201 MPU_FILTER_98HZ,
202 MPU_FILTER_42HZ,
203 MPU_FILTER_20HZ,
204 MPU_FILTER_10HZ,
205 MPU_FILTER_5HZ,
206 MPU_FILTER_2100HZ_NOLPF,
207 NUM_MPU_FILTER
208};
209
210enum mpu_fullscale {
211 MPU_FS_250DPS = 0,
212 MPU_FS_500DPS,
213 MPU_FS_1000DPS,
214 MPU_FS_2000DPS,
215 NUM_MPU_FS
216};
217
218enum mpu_clock_sel {
219 MPU_CLK_SEL_INTERNAL = 0,
220 MPU_CLK_SEL_PLLGYROX,
221 MPU_CLK_SEL_PLLGYROY,
222 MPU_CLK_SEL_PLLGYROZ,
223 MPU_CLK_SEL_PLLEXT32K,
224 MPU_CLK_SEL_PLLEXT19M,
225 MPU_CLK_SEL_RESERVED,
226 MPU_CLK_SEL_STOP,
227 NUM_CLK_SEL
228};
229
230enum mpu_ext_sync {
231 MPU_EXT_SYNC_NONE = 0,
232 MPU_EXT_SYNC_TEMP,
233 MPU_EXT_SYNC_GYROX,
234 MPU_EXT_SYNC_GYROY,
235 MPU_EXT_SYNC_GYROZ,
236 MPU_EXT_SYNC_ACCELX,
237 MPU_EXT_SYNC_ACCELY,
238 MPU_EXT_SYNC_ACCELZ,
239 NUM_MPU_EXT_SYNC
240};
241
242#define DLPF_FS_SYNC_VALUE(ext_sync, full_scale, lpf) \
243 ((ext_sync << 5) | (full_scale << 3) | lpf)
244
trostanski576fee12013-12-13 09:50:30 +0100245#endif /* __MPU3050_H_ */