1 /* Date: 2013/06/17 22:13:00
6 * This software program is licensed subject to the GNU General Public License
7 * (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html
9 * (C) Copyright 2011 Bosch Sensortec GmbH
15 brief This file contains all function implementations for the BMA2X2 in linux
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/i2c.h>
22 #include <linux/input.h>
23 #include <linux/workqueue.h>
24 #include <linux/mutex.h>
25 #include <linux/slab.h>
26 #include <linux/mutex.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
30 #include <linux/uaccess.h>
31 #ifdef CONFIG_HAS_EARLYSUSPEND
32 #include <linux/earlysuspend.h>
34 #include <linux/sensors_core.h>
35 #include <linux/bst_sensor_common.h>
38 #define SENSOR_NAME "bma2x2"
41 #define SLOPE_THRESHOLD_VALUE 32
42 #define SLOPE_DURATION_VALUE 1
43 #define INTERRUPT_LATCH_MODE 13
44 #define INTERRUPT_ENABLE 1
45 #define INTERRUPT_DISABLE 0
46 #define MAP_SLOPE_INTERRUPT 2
47 #define SLOPE_X_INDEX 5
48 #define SLOPE_Y_INDEX 6
49 #define SLOPE_Z_INDEX 7
50 #define BMA2X2_MAX_DELAY 200
51 #define BMA2X2_RANGE_SET 3 /* +/- 2G */
52 #define BMA2X2_BW_SET 12 /* 125HZ */
54 #define LOW_G_INTERRUPT REL_Z
55 #define HIGH_G_INTERRUPT REL_HWHEEL
56 #define SLOP_INTERRUPT REL_DIAL
57 #define DOUBLE_TAP_INTERRUPT REL_WHEEL
58 #define SINGLE_TAP_INTERRUPT REL_MISC
59 #define ORIENT_INTERRUPT ABS_PRESSURE
60 #define FLAT_INTERRUPT ABS_DISTANCE
61 #define SLOW_NO_MOTION_INTERRUPT REL_Y
63 #define HIGH_G_INTERRUPT_X_HAPPENED 1
64 #define HIGH_G_INTERRUPT_Y_HAPPENED 2
65 #define HIGH_G_INTERRUPT_Z_HAPPENED 3
66 #define HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED 4
67 #define HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED 5
68 #define HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED 6
69 #define SLOPE_INTERRUPT_X_HAPPENED 7
70 #define SLOPE_INTERRUPT_Y_HAPPENED 8
71 #define SLOPE_INTERRUPT_Z_HAPPENED 9
72 #define SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED 10
73 #define SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED 11
74 #define SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED 12
75 #define DOUBLE_TAP_INTERRUPT_HAPPENED 13
76 #define SINGLE_TAP_INTERRUPT_HAPPENED 14
77 #define UPWARD_PORTRAIT_UP_INTERRUPT_HAPPENED 15
78 #define UPWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED 16
79 #define UPWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED 17
80 #define UPWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED 18
81 #define DOWNWARD_PORTRAIT_UP_INTERRUPT_HAPPENED 19
82 #define DOWNWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED 20
83 #define DOWNWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED 21
84 #define DOWNWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED 22
85 #define FLAT_INTERRUPT_TURE_HAPPENED 23
86 #define FLAT_INTERRUPT_FALSE_HAPPENED 24
87 #define LOW_G_INTERRUPT_HAPPENED 25
88 #define SLOW_NO_MOTION_INTERRUPT_HAPPENED 26
94 #define PAD_DOUBLE_TAP 3
95 #define PAD_SINGLE_TAP 4
98 #define PAD_SLOW_NO_MOTION 7
101 #define BMA2X2_EEP_OFFSET 0x16
102 #define BMA2X2_IMAGE_BASE 0x38
103 #define BMA2X2_IMAGE_LEN 22
106 #define BMA2X2_CHIP_ID_REG 0x00
107 #define BMA2X2_VERSION_REG 0x01
108 #define BMA2X2_X_AXIS_LSB_REG 0x02
109 #define BMA2X2_X_AXIS_MSB_REG 0x03
110 #define BMA2X2_Y_AXIS_LSB_REG 0x04
111 #define BMA2X2_Y_AXIS_MSB_REG 0x05
112 #define BMA2X2_Z_AXIS_LSB_REG 0x06
113 #define BMA2X2_Z_AXIS_MSB_REG 0x07
114 #define BMA2X2_TEMPERATURE_REG 0x08
115 #define BMA2X2_STATUS1_REG 0x09
116 #define BMA2X2_STATUS2_REG 0x0A
117 #define BMA2X2_STATUS_TAP_SLOPE_REG 0x0B
118 #define BMA2X2_STATUS_ORIENT_HIGH_REG 0x0C
119 #define BMA2X2_STATUS_FIFO_REG 0x0E
120 #define BMA2X2_RANGE_SEL_REG 0x0F
121 #define BMA2X2_BW_SEL_REG 0x10
122 #define BMA2X2_MODE_CTRL_REG 0x11
123 #define BMA2X2_LOW_NOISE_CTRL_REG 0x12
124 #define BMA2X2_DATA_CTRL_REG 0x13
125 #define BMA2X2_RESET_REG 0x14
126 #define BMA2X2_INT_ENABLE1_REG 0x16
127 #define BMA2X2_INT_ENABLE2_REG 0x17
128 #define BMA2X2_INT_SLO_NO_MOT_REG 0x18
129 #define BMA2X2_INT1_PAD_SEL_REG 0x19
130 #define BMA2X2_INT_DATA_SEL_REG 0x1A
131 #define BMA2X2_INT2_PAD_SEL_REG 0x1B
132 #define BMA2X2_INT_SRC_REG 0x1E
133 #define BMA2X2_INT_SET_REG 0x20
134 #define BMA2X2_INT_CTRL_REG 0x21
135 #define BMA2X2_LOW_DURN_REG 0x22
136 #define BMA2X2_LOW_THRES_REG 0x23
137 #define BMA2X2_LOW_HIGH_HYST_REG 0x24
138 #define BMA2X2_HIGH_DURN_REG 0x25
139 #define BMA2X2_HIGH_THRES_REG 0x26
140 #define BMA2X2_SLOPE_DURN_REG 0x27
141 #define BMA2X2_SLOPE_THRES_REG 0x28
142 #define BMA2X2_SLO_NO_MOT_THRES_REG 0x29
143 #define BMA2X2_TAP_PARAM_REG 0x2A
144 #define BMA2X2_TAP_THRES_REG 0x2B
145 #define BMA2X2_ORIENT_PARAM_REG 0x2C
146 #define BMA2X2_THETA_BLOCK_REG 0x2D
147 #define BMA2X2_THETA_FLAT_REG 0x2E
148 #define BMA2X2_FLAT_HOLD_TIME_REG 0x2F
149 #define BMA2X2_FIFO_WML_TRIG 0x30
150 #define BMA2X2_SELF_TEST_REG 0x32
151 #define BMA2X2_EEPROM_CTRL_REG 0x33
152 #define BMA2X2_SERIAL_CTRL_REG 0x34
153 #define BMA2X2_EXTMODE_CTRL_REG 0x35
154 #define BMA2X2_OFFSET_CTRL_REG 0x36
155 #define BMA2X2_OFFSET_PARAMS_REG 0x37
156 #define BMA2X2_OFFSET_X_AXIS_REG 0x38
157 #define BMA2X2_OFFSET_Y_AXIS_REG 0x39
158 #define BMA2X2_OFFSET_Z_AXIS_REG 0x3A
159 #define BMA2X2_GP0_REG 0x3B
160 #define BMA2X2_GP1_REG 0x3C
161 #define BMA2X2_FIFO_MODE_REG 0x3E
162 #define BMA2X2_FIFO_DATA_OUTPUT_REG 0x3F
167 #define BMA2X2_CHIP_ID__POS 0
168 #define BMA2X2_CHIP_ID__MSK 0xFF
169 #define BMA2X2_CHIP_ID__LEN 8
170 #define BMA2X2_CHIP_ID__REG BMA2X2_CHIP_ID_REG
172 #define BMA2X2_VERSION__POS 0
173 #define BMA2X2_VERSION__LEN 8
174 #define BMA2X2_VERSION__MSK 0xFF
175 #define BMA2X2_VERSION__REG BMA2X2_VERSION_REG
177 #define BMA2x2_SLO_NO_MOT_DUR__POS 2
178 #define BMA2x2_SLO_NO_MOT_DUR__LEN 6
179 #define BMA2x2_SLO_NO_MOT_DUR__MSK 0xFC
180 #define BMA2x2_SLO_NO_MOT_DUR__REG BMA2X2_SLOPE_DURN_REG
182 #define BMA2X2_NEW_DATA_X__POS 0
183 #define BMA2X2_NEW_DATA_X__LEN 1
184 #define BMA2X2_NEW_DATA_X__MSK 0x01
185 #define BMA2X2_NEW_DATA_X__REG BMA2X2_X_AXIS_LSB_REG
187 #define BMA2X2_ACC_X14_LSB__POS 2
188 #define BMA2X2_ACC_X14_LSB__LEN 6
189 #define BMA2X2_ACC_X14_LSB__MSK 0xFC
190 #define BMA2X2_ACC_X14_LSB__REG BMA2X2_X_AXIS_LSB_REG
192 #define BMA2X2_ACC_X12_LSB__POS 4
193 #define BMA2X2_ACC_X12_LSB__LEN 4
194 #define BMA2X2_ACC_X12_LSB__MSK 0xF0
195 #define BMA2X2_ACC_X12_LSB__REG BMA2X2_X_AXIS_LSB_REG
197 #define BMA2X2_ACC_X10_LSB__POS 6
198 #define BMA2X2_ACC_X10_LSB__LEN 2
199 #define BMA2X2_ACC_X10_LSB__MSK 0xC0
200 #define BMA2X2_ACC_X10_LSB__REG BMA2X2_X_AXIS_LSB_REG
202 #define BMA2X2_ACC_X8_LSB__POS 0
203 #define BMA2X2_ACC_X8_LSB__LEN 0
204 #define BMA2X2_ACC_X8_LSB__MSK 0x00
205 #define BMA2X2_ACC_X8_LSB__REG BMA2X2_X_AXIS_LSB_REG
207 #define BMA2X2_ACC_X_MSB__POS 0
208 #define BMA2X2_ACC_X_MSB__LEN 8
209 #define BMA2X2_ACC_X_MSB__MSK 0xFF
210 #define BMA2X2_ACC_X_MSB__REG BMA2X2_X_AXIS_MSB_REG
212 #define BMA2X2_NEW_DATA_Y__POS 0
213 #define BMA2X2_NEW_DATA_Y__LEN 1
214 #define BMA2X2_NEW_DATA_Y__MSK 0x01
215 #define BMA2X2_NEW_DATA_Y__REG BMA2X2_Y_AXIS_LSB_REG
217 #define BMA2X2_ACC_Y14_LSB__POS 2
218 #define BMA2X2_ACC_Y14_LSB__LEN 6
219 #define BMA2X2_ACC_Y14_LSB__MSK 0xFC
220 #define BMA2X2_ACC_Y14_LSB__REG BMA2X2_Y_AXIS_LSB_REG
222 #define BMA2X2_ACC_Y12_LSB__POS 4
223 #define BMA2X2_ACC_Y12_LSB__LEN 4
224 #define BMA2X2_ACC_Y12_LSB__MSK 0xF0
225 #define BMA2X2_ACC_Y12_LSB__REG BMA2X2_Y_AXIS_LSB_REG
227 #define BMA2X2_ACC_Y10_LSB__POS 6
228 #define BMA2X2_ACC_Y10_LSB__LEN 2
229 #define BMA2X2_ACC_Y10_LSB__MSK 0xC0
230 #define BMA2X2_ACC_Y10_LSB__REG BMA2X2_Y_AXIS_LSB_REG
232 #define BMA2X2_ACC_Y8_LSB__POS 0
233 #define BMA2X2_ACC_Y8_LSB__LEN 0
234 #define BMA2X2_ACC_Y8_LSB__MSK 0x00
235 #define BMA2X2_ACC_Y8_LSB__REG BMA2X2_Y_AXIS_LSB_REG
237 #define BMA2X2_ACC_Y_MSB__POS 0
238 #define BMA2X2_ACC_Y_MSB__LEN 8
239 #define BMA2X2_ACC_Y_MSB__MSK 0xFF
240 #define BMA2X2_ACC_Y_MSB__REG BMA2X2_Y_AXIS_MSB_REG
242 #define BMA2X2_NEW_DATA_Z__POS 0
243 #define BMA2X2_NEW_DATA_Z__LEN 1
244 #define BMA2X2_NEW_DATA_Z__MSK 0x01
245 #define BMA2X2_NEW_DATA_Z__REG BMA2X2_Z_AXIS_LSB_REG
247 #define BMA2X2_ACC_Z14_LSB__POS 2
248 #define BMA2X2_ACC_Z14_LSB__LEN 6
249 #define BMA2X2_ACC_Z14_LSB__MSK 0xFC
250 #define BMA2X2_ACC_Z14_LSB__REG BMA2X2_Z_AXIS_LSB_REG
252 #define BMA2X2_ACC_Z12_LSB__POS 4
253 #define BMA2X2_ACC_Z12_LSB__LEN 4
254 #define BMA2X2_ACC_Z12_LSB__MSK 0xF0
255 #define BMA2X2_ACC_Z12_LSB__REG BMA2X2_Z_AXIS_LSB_REG
257 #define BMA2X2_ACC_Z10_LSB__POS 6
258 #define BMA2X2_ACC_Z10_LSB__LEN 2
259 #define BMA2X2_ACC_Z10_LSB__MSK 0xC0
260 #define BMA2X2_ACC_Z10_LSB__REG BMA2X2_Z_AXIS_LSB_REG
262 #define BMA2X2_ACC_Z8_LSB__POS 0
263 #define BMA2X2_ACC_Z8_LSB__LEN 0
264 #define BMA2X2_ACC_Z8_LSB__MSK 0x00
265 #define BMA2X2_ACC_Z8_LSB__REG BMA2X2_Z_AXIS_LSB_REG
267 #define BMA2X2_ACC_Z_MSB__POS 0
268 #define BMA2X2_ACC_Z_MSB__LEN 8
269 #define BMA2X2_ACC_Z_MSB__MSK 0xFF
270 #define BMA2X2_ACC_Z_MSB__REG BMA2X2_Z_AXIS_MSB_REG
272 #define BMA2X2_TEMPERATURE__POS 0
273 #define BMA2X2_TEMPERATURE__LEN 8
274 #define BMA2X2_TEMPERATURE__MSK 0xFF
275 #define BMA2X2_TEMPERATURE__REG BMA2X2_TEMP_RD_REG
277 #define BMA2X2_LOWG_INT_S__POS 0
278 #define BMA2X2_LOWG_INT_S__LEN 1
279 #define BMA2X2_LOWG_INT_S__MSK 0x01
280 #define BMA2X2_LOWG_INT_S__REG BMA2X2_STATUS1_REG
282 #define BMA2X2_HIGHG_INT_S__POS 1
283 #define BMA2X2_HIGHG_INT_S__LEN 1
284 #define BMA2X2_HIGHG_INT_S__MSK 0x02
285 #define BMA2X2_HIGHG_INT_S__REG BMA2X2_STATUS1_REG
287 #define BMA2X2_SLOPE_INT_S__POS 2
288 #define BMA2X2_SLOPE_INT_S__LEN 1
289 #define BMA2X2_SLOPE_INT_S__MSK 0x04
290 #define BMA2X2_SLOPE_INT_S__REG BMA2X2_STATUS1_REG
293 #define BMA2X2_SLO_NO_MOT_INT_S__POS 3
294 #define BMA2X2_SLO_NO_MOT_INT_S__LEN 1
295 #define BMA2X2_SLO_NO_MOT_INT_S__MSK 0x08
296 #define BMA2X2_SLO_NO_MOT_INT_S__REG BMA2X2_STATUS1_REG
298 #define BMA2X2_DOUBLE_TAP_INT_S__POS 4
299 #define BMA2X2_DOUBLE_TAP_INT_S__LEN 1
300 #define BMA2X2_DOUBLE_TAP_INT_S__MSK 0x10
301 #define BMA2X2_DOUBLE_TAP_INT_S__REG BMA2X2_STATUS1_REG
303 #define BMA2X2_SINGLE_TAP_INT_S__POS 5
304 #define BMA2X2_SINGLE_TAP_INT_S__LEN 1
305 #define BMA2X2_SINGLE_TAP_INT_S__MSK 0x20
306 #define BMA2X2_SINGLE_TAP_INT_S__REG BMA2X2_STATUS1_REG
308 #define BMA2X2_ORIENT_INT_S__POS 6
309 #define BMA2X2_ORIENT_INT_S__LEN 1
310 #define BMA2X2_ORIENT_INT_S__MSK 0x40
311 #define BMA2X2_ORIENT_INT_S__REG BMA2X2_STATUS1_REG
313 #define BMA2X2_FLAT_INT_S__POS 7
314 #define BMA2X2_FLAT_INT_S__LEN 1
315 #define BMA2X2_FLAT_INT_S__MSK 0x80
316 #define BMA2X2_FLAT_INT_S__REG BMA2X2_STATUS1_REG
318 #define BMA2X2_FIFO_FULL_INT_S__POS 5
319 #define BMA2X2_FIFO_FULL_INT_S__LEN 1
320 #define BMA2X2_FIFO_FULL_INT_S__MSK 0x20
321 #define BMA2X2_FIFO_FULL_INT_S__REG BMA2X2_STATUS2_REG
323 #define BMA2X2_FIFO_WM_INT_S__POS 6
324 #define BMA2X2_FIFO_WM_INT_S__LEN 1
325 #define BMA2X2_FIFO_WM_INT_S__MSK 0x40
326 #define BMA2X2_FIFO_WM_INT_S__REG BMA2X2_STATUS2_REG
328 #define BMA2X2_DATA_INT_S__POS 7
329 #define BMA2X2_DATA_INT_S__LEN 1
330 #define BMA2X2_DATA_INT_S__MSK 0x80
331 #define BMA2X2_DATA_INT_S__REG BMA2X2_STATUS2_REG
333 #define BMA2X2_SLOPE_FIRST_X__POS 0
334 #define BMA2X2_SLOPE_FIRST_X__LEN 1
335 #define BMA2X2_SLOPE_FIRST_X__MSK 0x01
336 #define BMA2X2_SLOPE_FIRST_X__REG BMA2X2_STATUS_TAP_SLOPE_REG
338 #define BMA2X2_SLOPE_FIRST_Y__POS 1
339 #define BMA2X2_SLOPE_FIRST_Y__LEN 1
340 #define BMA2X2_SLOPE_FIRST_Y__MSK 0x02
341 #define BMA2X2_SLOPE_FIRST_Y__REG BMA2X2_STATUS_TAP_SLOPE_REG
343 #define BMA2X2_SLOPE_FIRST_Z__POS 2
344 #define BMA2X2_SLOPE_FIRST_Z__LEN 1
345 #define BMA2X2_SLOPE_FIRST_Z__MSK 0x04
346 #define BMA2X2_SLOPE_FIRST_Z__REG BMA2X2_STATUS_TAP_SLOPE_REG
348 #define BMA2X2_SLOPE_SIGN_S__POS 3
349 #define BMA2X2_SLOPE_SIGN_S__LEN 1
350 #define BMA2X2_SLOPE_SIGN_S__MSK 0x08
351 #define BMA2X2_SLOPE_SIGN_S__REG BMA2X2_STATUS_TAP_SLOPE_REG
353 #define BMA2X2_TAP_FIRST_X__POS 4
354 #define BMA2X2_TAP_FIRST_X__LEN 1
355 #define BMA2X2_TAP_FIRST_X__MSK 0x10
356 #define BMA2X2_TAP_FIRST_X__REG BMA2X2_STATUS_TAP_SLOPE_REG
358 #define BMA2X2_TAP_FIRST_Y__POS 5
359 #define BMA2X2_TAP_FIRST_Y__LEN 1
360 #define BMA2X2_TAP_FIRST_Y__MSK 0x20
361 #define BMA2X2_TAP_FIRST_Y__REG BMA2X2_STATUS_TAP_SLOPE_REG
363 #define BMA2X2_TAP_FIRST_Z__POS 6
364 #define BMA2X2_TAP_FIRST_Z__LEN 1
365 #define BMA2X2_TAP_FIRST_Z__MSK 0x40
366 #define BMA2X2_TAP_FIRST_Z__REG BMA2X2_STATUS_TAP_SLOPE_REG
368 #define BMA2X2_TAP_SIGN_S__POS 7
369 #define BMA2X2_TAP_SIGN_S__LEN 1
370 #define BMA2X2_TAP_SIGN_S__MSK 0x80
371 #define BMA2X2_TAP_SIGN_S__REG BMA2X2_STATUS_TAP_SLOPE_REG
373 #define BMA2X2_HIGHG_FIRST_X__POS 0
374 #define BMA2X2_HIGHG_FIRST_X__LEN 1
375 #define BMA2X2_HIGHG_FIRST_X__MSK 0x01
376 #define BMA2X2_HIGHG_FIRST_X__REG BMA2X2_STATUS_ORIENT_HIGH_REG
378 #define BMA2X2_HIGHG_FIRST_Y__POS 1
379 #define BMA2X2_HIGHG_FIRST_Y__LEN 1
380 #define BMA2X2_HIGHG_FIRST_Y__MSK 0x02
381 #define BMA2X2_HIGHG_FIRST_Y__REG BMA2X2_STATUS_ORIENT_HIGH_REG
383 #define BMA2X2_HIGHG_FIRST_Z__POS 2
384 #define BMA2X2_HIGHG_FIRST_Z__LEN 1
385 #define BMA2X2_HIGHG_FIRST_Z__MSK 0x04
386 #define BMA2X2_HIGHG_FIRST_Z__REG BMA2X2_STATUS_ORIENT_HIGH_REG
388 #define BMA2X2_HIGHG_SIGN_S__POS 3
389 #define BMA2X2_HIGHG_SIGN_S__LEN 1
390 #define BMA2X2_HIGHG_SIGN_S__MSK 0x08
391 #define BMA2X2_HIGHG_SIGN_S__REG BMA2X2_STATUS_ORIENT_HIGH_REG
393 #define BMA2X2_ORIENT_S__POS 4
394 #define BMA2X2_ORIENT_S__LEN 3
395 #define BMA2X2_ORIENT_S__MSK 0x70
396 #define BMA2X2_ORIENT_S__REG BMA2X2_STATUS_ORIENT_HIGH_REG
398 #define BMA2X2_FLAT_S__POS 7
399 #define BMA2X2_FLAT_S__LEN 1
400 #define BMA2X2_FLAT_S__MSK 0x80
401 #define BMA2X2_FLAT_S__REG BMA2X2_STATUS_ORIENT_HIGH_REG
403 #define BMA2X2_FIFO_FRAME_COUNTER_S__POS 0
404 #define BMA2X2_FIFO_FRAME_COUNTER_S__LEN 7
405 #define BMA2X2_FIFO_FRAME_COUNTER_S__MSK 0x7F
406 #define BMA2X2_FIFO_FRAME_COUNTER_S__REG BMA2X2_STATUS_FIFO_REG
408 #define BMA2X2_FIFO_OVERRUN_S__POS 7
409 #define BMA2X2_FIFO_OVERRUN_S__LEN 1
410 #define BMA2X2_FIFO_OVERRUN_S__MSK 0x80
411 #define BMA2X2_FIFO_OVERRUN_S__REG BMA2X2_STATUS_FIFO_REG
413 #define BMA2X2_RANGE_SEL__POS 0
414 #define BMA2X2_RANGE_SEL__LEN 4
415 #define BMA2X2_RANGE_SEL__MSK 0x0F
416 #define BMA2X2_RANGE_SEL__REG BMA2X2_RANGE_SEL_REG
418 #define BMA2X2_BANDWIDTH__POS 0
419 #define BMA2X2_BANDWIDTH__LEN 5
420 #define BMA2X2_BANDWIDTH__MSK 0x1F
421 #define BMA2X2_BANDWIDTH__REG BMA2X2_BW_SEL_REG
423 #define BMA2X2_SLEEP_DUR__POS 1
424 #define BMA2X2_SLEEP_DUR__LEN 4
425 #define BMA2X2_SLEEP_DUR__MSK 0x1E
426 #define BMA2X2_SLEEP_DUR__REG BMA2X2_MODE_CTRL_REG
428 #define BMA2X2_MODE_CTRL__POS 5
429 #define BMA2X2_MODE_CTRL__LEN 3
430 #define BMA2X2_MODE_CTRL__MSK 0xE0
431 #define BMA2X2_MODE_CTRL__REG BMA2X2_MODE_CTRL_REG
433 #define BMA2X2_DEEP_SUSPEND__POS 5
434 #define BMA2X2_DEEP_SUSPEND__LEN 1
435 #define BMA2X2_DEEP_SUSPEND__MSK 0x20
436 #define BMA2X2_DEEP_SUSPEND__REG BMA2X2_MODE_CTRL_REG
438 #define BMA2X2_EN_LOW_POWER__POS 6
439 #define BMA2X2_EN_LOW_POWER__LEN 1
440 #define BMA2X2_EN_LOW_POWER__MSK 0x40
441 #define BMA2X2_EN_LOW_POWER__REG BMA2X2_MODE_CTRL_REG
443 #define BMA2X2_EN_SUSPEND__POS 7
444 #define BMA2X2_EN_SUSPEND__LEN 1
445 #define BMA2X2_EN_SUSPEND__MSK 0x80
446 #define BMA2X2_EN_SUSPEND__REG BMA2X2_MODE_CTRL_REG
448 #define BMA2X2_SLEEP_TIMER__POS 5
449 #define BMA2X2_SLEEP_TIMER__LEN 1
450 #define BMA2X2_SLEEP_TIMER__MSK 0x20
451 #define BMA2X2_SLEEP_TIMER__REG BMA2X2_LOW_NOISE_CTRL_REG
453 #define BMA2X2_LOW_POWER_MODE__POS 6
454 #define BMA2X2_LOW_POWER_MODE__LEN 1
455 #define BMA2X2_LOW_POWER_MODE__MSK 0x40
456 #define BMA2X2_LOW_POWER_MODE__REG BMA2X2_LOW_NOISE_CTRL_REG
458 #define BMA2X2_EN_LOW_NOISE__POS 7
459 #define BMA2X2_EN_LOW_NOISE__LEN 1
460 #define BMA2X2_EN_LOW_NOISE__MSK 0x80
461 #define BMA2X2_EN_LOW_NOISE__REG BMA2X2_LOW_NOISE_CTRL_REG
463 #define BMA2X2_DIS_SHADOW_PROC__POS 6
464 #define BMA2X2_DIS_SHADOW_PROC__LEN 1
465 #define BMA2X2_DIS_SHADOW_PROC__MSK 0x40
466 #define BMA2X2_DIS_SHADOW_PROC__REG BMA2X2_DATA_CTRL_REG
468 #define BMA2X2_EN_DATA_HIGH_BW__POS 7
469 #define BMA2X2_EN_DATA_HIGH_BW__LEN 1
470 #define BMA2X2_EN_DATA_HIGH_BW__MSK 0x80
471 #define BMA2X2_EN_DATA_HIGH_BW__REG BMA2X2_DATA_CTRL_REG
473 #define BMA2X2_EN_SOFT_RESET__POS 0
474 #define BMA2X2_EN_SOFT_RESET__LEN 8
475 #define BMA2X2_EN_SOFT_RESET__MSK 0xFF
476 #define BMA2X2_EN_SOFT_RESET__REG BMA2X2_RESET_REG
478 #define BMA2X2_EN_SOFT_RESET_VALUE 0xB6
480 #define BMA2X2_EN_SLOPE_X_INT__POS 0
481 #define BMA2X2_EN_SLOPE_X_INT__LEN 1
482 #define BMA2X2_EN_SLOPE_X_INT__MSK 0x01
483 #define BMA2X2_EN_SLOPE_X_INT__REG BMA2X2_INT_ENABLE1_REG
485 #define BMA2X2_EN_SLOPE_Y_INT__POS 1
486 #define BMA2X2_EN_SLOPE_Y_INT__LEN 1
487 #define BMA2X2_EN_SLOPE_Y_INT__MSK 0x02
488 #define BMA2X2_EN_SLOPE_Y_INT__REG BMA2X2_INT_ENABLE1_REG
490 #define BMA2X2_EN_SLOPE_Z_INT__POS 2
491 #define BMA2X2_EN_SLOPE_Z_INT__LEN 1
492 #define BMA2X2_EN_SLOPE_Z_INT__MSK 0x04
493 #define BMA2X2_EN_SLOPE_Z_INT__REG BMA2X2_INT_ENABLE1_REG
495 #define BMA2X2_EN_DOUBLE_TAP_INT__POS 4
496 #define BMA2X2_EN_DOUBLE_TAP_INT__LEN 1
497 #define BMA2X2_EN_DOUBLE_TAP_INT__MSK 0x10
498 #define BMA2X2_EN_DOUBLE_TAP_INT__REG BMA2X2_INT_ENABLE1_REG
500 #define BMA2X2_EN_SINGLE_TAP_INT__POS 5
501 #define BMA2X2_EN_SINGLE_TAP_INT__LEN 1
502 #define BMA2X2_EN_SINGLE_TAP_INT__MSK 0x20
503 #define BMA2X2_EN_SINGLE_TAP_INT__REG BMA2X2_INT_ENABLE1_REG
505 #define BMA2X2_EN_ORIENT_INT__POS 6
506 #define BMA2X2_EN_ORIENT_INT__LEN 1
507 #define BMA2X2_EN_ORIENT_INT__MSK 0x40
508 #define BMA2X2_EN_ORIENT_INT__REG BMA2X2_INT_ENABLE1_REG
510 #define BMA2X2_EN_FLAT_INT__POS 7
511 #define BMA2X2_EN_FLAT_INT__LEN 1
512 #define BMA2X2_EN_FLAT_INT__MSK 0x80
513 #define BMA2X2_EN_FLAT_INT__REG BMA2X2_INT_ENABLE1_REG
515 #define BMA2X2_EN_HIGHG_X_INT__POS 0
516 #define BMA2X2_EN_HIGHG_X_INT__LEN 1
517 #define BMA2X2_EN_HIGHG_X_INT__MSK 0x01
518 #define BMA2X2_EN_HIGHG_X_INT__REG BMA2X2_INT_ENABLE2_REG
520 #define BMA2X2_EN_HIGHG_Y_INT__POS 1
521 #define BMA2X2_EN_HIGHG_Y_INT__LEN 1
522 #define BMA2X2_EN_HIGHG_Y_INT__MSK 0x02
523 #define BMA2X2_EN_HIGHG_Y_INT__REG BMA2X2_INT_ENABLE2_REG
525 #define BMA2X2_EN_HIGHG_Z_INT__POS 2
526 #define BMA2X2_EN_HIGHG_Z_INT__LEN 1
527 #define BMA2X2_EN_HIGHG_Z_INT__MSK 0x04
528 #define BMA2X2_EN_HIGHG_Z_INT__REG BMA2X2_INT_ENABLE2_REG
530 #define BMA2X2_EN_LOWG_INT__POS 3
531 #define BMA2X2_EN_LOWG_INT__LEN 1
532 #define BMA2X2_EN_LOWG_INT__MSK 0x08
533 #define BMA2X2_EN_LOWG_INT__REG BMA2X2_INT_ENABLE2_REG
535 #define BMA2X2_EN_NEW_DATA_INT__POS 4
536 #define BMA2X2_EN_NEW_DATA_INT__LEN 1
537 #define BMA2X2_EN_NEW_DATA_INT__MSK 0x10
538 #define BMA2X2_EN_NEW_DATA_INT__REG BMA2X2_INT_ENABLE2_REG
540 #define BMA2X2_INT_FFULL_EN_INT__POS 5
541 #define BMA2X2_INT_FFULL_EN_INT__LEN 1
542 #define BMA2X2_INT_FFULL_EN_INT__MSK 0x20
543 #define BMA2X2_INT_FFULL_EN_INT__REG BMA2X2_INT_ENABLE2_REG
545 #define BMA2X2_INT_FWM_EN_INT__POS 6
546 #define BMA2X2_INT_FWM_EN_INT__LEN 1
547 #define BMA2X2_INT_FWM_EN_INT__MSK 0x40
548 #define BMA2X2_INT_FWM_EN_INT__REG BMA2X2_INT_ENABLE2_REG
550 #define BMA2X2_INT_SLO_NO_MOT_EN_X_INT__POS 0
551 #define BMA2X2_INT_SLO_NO_MOT_EN_X_INT__LEN 1
552 #define BMA2X2_INT_SLO_NO_MOT_EN_X_INT__MSK 0x01
553 #define BMA2X2_INT_SLO_NO_MOT_EN_X_INT__REG BMA2X2_INT_SLO_NO_MOT_REG
555 #define BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__POS 1
556 #define BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__LEN 1
557 #define BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__MSK 0x02
558 #define BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__REG BMA2X2_INT_SLO_NO_MOT_REG
560 #define BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__POS 2
561 #define BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__LEN 1
562 #define BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__MSK 0x04
563 #define BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__REG BMA2X2_INT_SLO_NO_MOT_REG
565 #define BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__POS 3
566 #define BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__LEN 1
567 #define BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__MSK 0x08
568 #define BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG BMA2X2_INT_SLO_NO_MOT_REG
570 #define BMA2X2_EN_INT1_PAD_LOWG__POS 0
571 #define BMA2X2_EN_INT1_PAD_LOWG__LEN 1
572 #define BMA2X2_EN_INT1_PAD_LOWG__MSK 0x01
573 #define BMA2X2_EN_INT1_PAD_LOWG__REG BMA2X2_INT1_PAD_SEL_REG
575 #define BMA2X2_EN_INT1_PAD_HIGHG__POS 1
576 #define BMA2X2_EN_INT1_PAD_HIGHG__LEN 1
577 #define BMA2X2_EN_INT1_PAD_HIGHG__MSK 0x02
578 #define BMA2X2_EN_INT1_PAD_HIGHG__REG BMA2X2_INT1_PAD_SEL_REG
580 #define BMA2X2_EN_INT1_PAD_SLOPE__POS 2
581 #define BMA2X2_EN_INT1_PAD_SLOPE__LEN 1
582 #define BMA2X2_EN_INT1_PAD_SLOPE__MSK 0x04
583 #define BMA2X2_EN_INT1_PAD_SLOPE__REG BMA2X2_INT1_PAD_SEL_REG
585 #define BMA2X2_EN_INT1_PAD_SLO_NO_MOT__POS 3
586 #define BMA2X2_EN_INT1_PAD_SLO_NO_MOT__LEN 1
587 #define BMA2X2_EN_INT1_PAD_SLO_NO_MOT__MSK 0x08
588 #define BMA2X2_EN_INT1_PAD_SLO_NO_MOT__REG BMA2X2_INT1_PAD_SEL_REG
590 #define BMA2X2_EN_INT1_PAD_DB_TAP__POS 4
591 #define BMA2X2_EN_INT1_PAD_DB_TAP__LEN 1
592 #define BMA2X2_EN_INT1_PAD_DB_TAP__MSK 0x10
593 #define BMA2X2_EN_INT1_PAD_DB_TAP__REG BMA2X2_INT1_PAD_SEL_REG
595 #define BMA2X2_EN_INT1_PAD_SNG_TAP__POS 5
596 #define BMA2X2_EN_INT1_PAD_SNG_TAP__LEN 1
597 #define BMA2X2_EN_INT1_PAD_SNG_TAP__MSK 0x20
598 #define BMA2X2_EN_INT1_PAD_SNG_TAP__REG BMA2X2_INT1_PAD_SEL_REG
600 #define BMA2X2_EN_INT1_PAD_ORIENT__POS 6
601 #define BMA2X2_EN_INT1_PAD_ORIENT__LEN 1
602 #define BMA2X2_EN_INT1_PAD_ORIENT__MSK 0x40
603 #define BMA2X2_EN_INT1_PAD_ORIENT__REG BMA2X2_INT1_PAD_SEL_REG
605 #define BMA2X2_EN_INT1_PAD_FLAT__POS 7
606 #define BMA2X2_EN_INT1_PAD_FLAT__LEN 1
607 #define BMA2X2_EN_INT1_PAD_FLAT__MSK 0x80
608 #define BMA2X2_EN_INT1_PAD_FLAT__REG BMA2X2_INT1_PAD_SEL_REG
610 #define BMA2X2_EN_INT2_PAD_LOWG__POS 0
611 #define BMA2X2_EN_INT2_PAD_LOWG__LEN 1
612 #define BMA2X2_EN_INT2_PAD_LOWG__MSK 0x01
613 #define BMA2X2_EN_INT2_PAD_LOWG__REG BMA2X2_INT2_PAD_SEL_REG
615 #define BMA2X2_EN_INT2_PAD_HIGHG__POS 1
616 #define BMA2X2_EN_INT2_PAD_HIGHG__LEN 1
617 #define BMA2X2_EN_INT2_PAD_HIGHG__MSK 0x02
618 #define BMA2X2_EN_INT2_PAD_HIGHG__REG BMA2X2_INT2_PAD_SEL_REG
620 #define BMA2X2_EN_INT2_PAD_SLOPE__POS 2
621 #define BMA2X2_EN_INT2_PAD_SLOPE__LEN 1
622 #define BMA2X2_EN_INT2_PAD_SLOPE__MSK 0x04
623 #define BMA2X2_EN_INT2_PAD_SLOPE__REG BMA2X2_INT2_PAD_SEL_REG
625 #define BMA2X2_EN_INT2_PAD_SLO_NO_MOT__POS 3
626 #define BMA2X2_EN_INT2_PAD_SLO_NO_MOT__LEN 1
627 #define BMA2X2_EN_INT2_PAD_SLO_NO_MOT__MSK 0x08
628 #define BMA2X2_EN_INT2_PAD_SLO_NO_MOT__REG BMA2X2_INT2_PAD_SEL_REG
630 #define BMA2X2_EN_INT2_PAD_DB_TAP__POS 4
631 #define BMA2X2_EN_INT2_PAD_DB_TAP__LEN 1
632 #define BMA2X2_EN_INT2_PAD_DB_TAP__MSK 0x10
633 #define BMA2X2_EN_INT2_PAD_DB_TAP__REG BMA2X2_INT2_PAD_SEL_REG
635 #define BMA2X2_EN_INT2_PAD_SNG_TAP__POS 5
636 #define BMA2X2_EN_INT2_PAD_SNG_TAP__LEN 1
637 #define BMA2X2_EN_INT2_PAD_SNG_TAP__MSK 0x20
638 #define BMA2X2_EN_INT2_PAD_SNG_TAP__REG BMA2X2_INT2_PAD_SEL_REG
640 #define BMA2X2_EN_INT2_PAD_ORIENT__POS 6
641 #define BMA2X2_EN_INT2_PAD_ORIENT__LEN 1
642 #define BMA2X2_EN_INT2_PAD_ORIENT__MSK 0x40
643 #define BMA2X2_EN_INT2_PAD_ORIENT__REG BMA2X2_INT2_PAD_SEL_REG
645 #define BMA2X2_EN_INT2_PAD_FLAT__POS 7
646 #define BMA2X2_EN_INT2_PAD_FLAT__LEN 1
647 #define BMA2X2_EN_INT2_PAD_FLAT__MSK 0x80
648 #define BMA2X2_EN_INT2_PAD_FLAT__REG BMA2X2_INT2_PAD_SEL_REG
650 #define BMA2X2_EN_INT1_PAD_NEWDATA__POS 0
651 #define BMA2X2_EN_INT1_PAD_NEWDATA__LEN 1
652 #define BMA2X2_EN_INT1_PAD_NEWDATA__MSK 0x01
653 #define BMA2X2_EN_INT1_PAD_NEWDATA__REG BMA2X2_INT_DATA_SEL_REG
655 #define BMA2X2_EN_INT1_PAD_FWM__POS 1
656 #define BMA2X2_EN_INT1_PAD_FWM__LEN 1
657 #define BMA2X2_EN_INT1_PAD_FWM__MSK 0x02
658 #define BMA2X2_EN_INT1_PAD_FWM__REG BMA2X2_INT_DATA_SEL_REG
660 #define BMA2X2_EN_INT1_PAD_FFULL__POS 2
661 #define BMA2X2_EN_INT1_PAD_FFULL__LEN 1
662 #define BMA2X2_EN_INT1_PAD_FFULL__MSK 0x04
663 #define BMA2X2_EN_INT1_PAD_FFULL__REG BMA2X2_INT_DATA_SEL_REG
665 #define BMA2X2_EN_INT2_PAD_FFULL__POS 5
666 #define BMA2X2_EN_INT2_PAD_FFULL__LEN 1
667 #define BMA2X2_EN_INT2_PAD_FFULL__MSK 0x20
668 #define BMA2X2_EN_INT2_PAD_FFULL__REG BMA2X2_INT_DATA_SEL_REG
670 #define BMA2X2_EN_INT2_PAD_FWM__POS 6
671 #define BMA2X2_EN_INT2_PAD_FWM__LEN 1
672 #define BMA2X2_EN_INT2_PAD_FWM__MSK 0x40
673 #define BMA2X2_EN_INT2_PAD_FWM__REG BMA2X2_INT_DATA_SEL_REG
675 #define BMA2X2_EN_INT2_PAD_NEWDATA__POS 7
676 #define BMA2X2_EN_INT2_PAD_NEWDATA__LEN 1
677 #define BMA2X2_EN_INT2_PAD_NEWDATA__MSK 0x80
678 #define BMA2X2_EN_INT2_PAD_NEWDATA__REG BMA2X2_INT_DATA_SEL_REG
680 #define BMA2X2_UNFILT_INT_SRC_LOWG__POS 0
681 #define BMA2X2_UNFILT_INT_SRC_LOWG__LEN 1
682 #define BMA2X2_UNFILT_INT_SRC_LOWG__MSK 0x01
683 #define BMA2X2_UNFILT_INT_SRC_LOWG__REG BMA2X2_INT_SRC_REG
685 #define BMA2X2_UNFILT_INT_SRC_HIGHG__POS 1
686 #define BMA2X2_UNFILT_INT_SRC_HIGHG__LEN 1
687 #define BMA2X2_UNFILT_INT_SRC_HIGHG__MSK 0x02
688 #define BMA2X2_UNFILT_INT_SRC_HIGHG__REG BMA2X2_INT_SRC_REG
690 #define BMA2X2_UNFILT_INT_SRC_SLOPE__POS 2
691 #define BMA2X2_UNFILT_INT_SRC_SLOPE__LEN 1
692 #define BMA2X2_UNFILT_INT_SRC_SLOPE__MSK 0x04
693 #define BMA2X2_UNFILT_INT_SRC_SLOPE__REG BMA2X2_INT_SRC_REG
695 #define BMA2X2_UNFILT_INT_SRC_SLO_NO_MOT__POS 3
696 #define BMA2X2_UNFILT_INT_SRC_SLO_NO_MOT__LEN 1
697 #define BMA2X2_UNFILT_INT_SRC_SLO_NO_MOT__MSK 0x08
698 #define BMA2X2_UNFILT_INT_SRC_SLO_NO_MOT__REG BMA2X2_INT_SRC_REG
700 #define BMA2X2_UNFILT_INT_SRC_TAP__POS 4
701 #define BMA2X2_UNFILT_INT_SRC_TAP__LEN 1
702 #define BMA2X2_UNFILT_INT_SRC_TAP__MSK 0x10
703 #define BMA2X2_UNFILT_INT_SRC_TAP__REG BMA2X2_INT_SRC_REG
705 #define BMA2X2_UNFILT_INT_SRC_DATA__POS 5
706 #define BMA2X2_UNFILT_INT_SRC_DATA__LEN 1
707 #define BMA2X2_UNFILT_INT_SRC_DATA__MSK 0x20
708 #define BMA2X2_UNFILT_INT_SRC_DATA__REG BMA2X2_INT_SRC_REG
710 #define BMA2X2_INT1_PAD_ACTIVE_LEVEL__POS 0
711 #define BMA2X2_INT1_PAD_ACTIVE_LEVEL__LEN 1
712 #define BMA2X2_INT1_PAD_ACTIVE_LEVEL__MSK 0x01
713 #define BMA2X2_INT1_PAD_ACTIVE_LEVEL__REG BMA2X2_INT_SET_REG
715 #define BMA2X2_INT2_PAD_ACTIVE_LEVEL__POS 2
716 #define BMA2X2_INT2_PAD_ACTIVE_LEVEL__LEN 1
717 #define BMA2X2_INT2_PAD_ACTIVE_LEVEL__MSK 0x04
718 #define BMA2X2_INT2_PAD_ACTIVE_LEVEL__REG BMA2X2_INT_SET_REG
720 #define BMA2X2_INT1_PAD_OUTPUT_TYPE__POS 1
721 #define BMA2X2_INT1_PAD_OUTPUT_TYPE__LEN 1
722 #define BMA2X2_INT1_PAD_OUTPUT_TYPE__MSK 0x02
723 #define BMA2X2_INT1_PAD_OUTPUT_TYPE__REG BMA2X2_INT_SET_REG
725 #define BMA2X2_INT2_PAD_OUTPUT_TYPE__POS 3
726 #define BMA2X2_INT2_PAD_OUTPUT_TYPE__LEN 1
727 #define BMA2X2_INT2_PAD_OUTPUT_TYPE__MSK 0x08
728 #define BMA2X2_INT2_PAD_OUTPUT_TYPE__REG BMA2X2_INT_SET_REG
730 #define BMA2X2_INT_MODE_SEL__POS 0
731 #define BMA2X2_INT_MODE_SEL__LEN 4
732 #define BMA2X2_INT_MODE_SEL__MSK 0x0F
733 #define BMA2X2_INT_MODE_SEL__REG BMA2X2_INT_CTRL_REG
735 #define BMA2X2_RESET_INT__POS 7
736 #define BMA2X2_RESET_INT__LEN 1
737 #define BMA2X2_RESET_INT__MSK 0x80
738 #define BMA2X2_RESET_INT__REG BMA2X2_INT_CTRL_REG
740 #define BMA2X2_LOWG_DUR__POS 0
741 #define BMA2X2_LOWG_DUR__LEN 8
742 #define BMA2X2_LOWG_DUR__MSK 0xFF
743 #define BMA2X2_LOWG_DUR__REG BMA2X2_LOW_DURN_REG
745 #define BMA2X2_LOWG_THRES__POS 0
746 #define BMA2X2_LOWG_THRES__LEN 8
747 #define BMA2X2_LOWG_THRES__MSK 0xFF
748 #define BMA2X2_LOWG_THRES__REG BMA2X2_LOW_THRES_REG
750 #define BMA2X2_LOWG_HYST__POS 0
751 #define BMA2X2_LOWG_HYST__LEN 2
752 #define BMA2X2_LOWG_HYST__MSK 0x03
753 #define BMA2X2_LOWG_HYST__REG BMA2X2_LOW_HIGH_HYST_REG
755 #define BMA2X2_LOWG_INT_MODE__POS 2
756 #define BMA2X2_LOWG_INT_MODE__LEN 1
757 #define BMA2X2_LOWG_INT_MODE__MSK 0x04
758 #define BMA2X2_LOWG_INT_MODE__REG BMA2X2_LOW_HIGH_HYST_REG
760 #define BMA2X2_HIGHG_DUR__POS 0
761 #define BMA2X2_HIGHG_DUR__LEN 8
762 #define BMA2X2_HIGHG_DUR__MSK 0xFF
763 #define BMA2X2_HIGHG_DUR__REG BMA2X2_HIGH_DURN_REG
765 #define BMA2X2_HIGHG_THRES__POS 0
766 #define BMA2X2_HIGHG_THRES__LEN 8
767 #define BMA2X2_HIGHG_THRES__MSK 0xFF
768 #define BMA2X2_HIGHG_THRES__REG BMA2X2_HIGH_THRES_REG
770 #define BMA2X2_HIGHG_HYST__POS 6
771 #define BMA2X2_HIGHG_HYST__LEN 2
772 #define BMA2X2_HIGHG_HYST__MSK 0xC0
773 #define BMA2X2_HIGHG_HYST__REG BMA2X2_LOW_HIGH_HYST_REG
775 #define BMA2X2_SLOPE_DUR__POS 0
776 #define BMA2X2_SLOPE_DUR__LEN 2
777 #define BMA2X2_SLOPE_DUR__MSK 0x03
778 #define BMA2X2_SLOPE_DUR__REG BMA2X2_SLOPE_DURN_REG
780 #define BMA2X2_SLO_NO_MOT_DUR__POS 2
781 #define BMA2X2_SLO_NO_MOT_DUR__LEN 6
782 #define BMA2X2_SLO_NO_MOT_DUR__MSK 0xFC
783 #define BMA2X2_SLO_NO_MOT_DUR__REG BMA2X2_SLOPE_DURN_REG
785 #define BMA2X2_SLOPE_THRES__POS 0
786 #define BMA2X2_SLOPE_THRES__LEN 8
787 #define BMA2X2_SLOPE_THRES__MSK 0xFF
788 #define BMA2X2_SLOPE_THRES__REG BMA2X2_SLOPE_THRES_REG
790 #define BMA2X2_SLO_NO_MOT_THRES__POS 0
791 #define BMA2X2_SLO_NO_MOT_THRES__LEN 8
792 #define BMA2X2_SLO_NO_MOT_THRES__MSK 0xFF
793 #define BMA2X2_SLO_NO_MOT_THRES__REG BMA2X2_SLO_NO_MOT_THRES_REG
795 #define BMA2X2_TAP_DUR__POS 0
796 #define BMA2X2_TAP_DUR__LEN 3
797 #define BMA2X2_TAP_DUR__MSK 0x07
798 #define BMA2X2_TAP_DUR__REG BMA2X2_TAP_PARAM_REG
800 #define BMA2X2_TAP_SHOCK_DURN__POS 6
801 #define BMA2X2_TAP_SHOCK_DURN__LEN 1
802 #define BMA2X2_TAP_SHOCK_DURN__MSK 0x40
803 #define BMA2X2_TAP_SHOCK_DURN__REG BMA2X2_TAP_PARAM_REG
805 #define BMA2X2_ADV_TAP_INT__POS 5
806 #define BMA2X2_ADV_TAP_INT__LEN 1
807 #define BMA2X2_ADV_TAP_INT__MSK 0x20
808 #define BMA2X2_ADV_TAP_INT__REG BMA2X2_TAP_PARAM_REG
810 #define BMA2X2_TAP_QUIET_DURN__POS 7
811 #define BMA2X2_TAP_QUIET_DURN__LEN 1
812 #define BMA2X2_TAP_QUIET_DURN__MSK 0x80
813 #define BMA2X2_TAP_QUIET_DURN__REG BMA2X2_TAP_PARAM_REG
815 #define BMA2X2_TAP_THRES__POS 0
816 #define BMA2X2_TAP_THRES__LEN 5
817 #define BMA2X2_TAP_THRES__MSK 0x1F
818 #define BMA2X2_TAP_THRES__REG BMA2X2_TAP_THRES_REG
820 #define BMA2X2_TAP_SAMPLES__POS 6
821 #define BMA2X2_TAP_SAMPLES__LEN 2
822 #define BMA2X2_TAP_SAMPLES__MSK 0xC0
823 #define BMA2X2_TAP_SAMPLES__REG BMA2X2_TAP_THRES_REG
825 #define BMA2X2_ORIENT_MODE__POS 0
826 #define BMA2X2_ORIENT_MODE__LEN 2
827 #define BMA2X2_ORIENT_MODE__MSK 0x03
828 #define BMA2X2_ORIENT_MODE__REG BMA2X2_ORIENT_PARAM_REG
830 #define BMA2X2_ORIENT_BLOCK__POS 2
831 #define BMA2X2_ORIENT_BLOCK__LEN 2
832 #define BMA2X2_ORIENT_BLOCK__MSK 0x0C
833 #define BMA2X2_ORIENT_BLOCK__REG BMA2X2_ORIENT_PARAM_REG
835 #define BMA2X2_ORIENT_HYST__POS 4
836 #define BMA2X2_ORIENT_HYST__LEN 3
837 #define BMA2X2_ORIENT_HYST__MSK 0x70
838 #define BMA2X2_ORIENT_HYST__REG BMA2X2_ORIENT_PARAM_REG
840 #define BMA2X2_ORIENT_AXIS__POS 7
841 #define BMA2X2_ORIENT_AXIS__LEN 1
842 #define BMA2X2_ORIENT_AXIS__MSK 0x80
843 #define BMA2X2_ORIENT_AXIS__REG BMA2X2_THETA_BLOCK_REG
845 #define BMA2X2_ORIENT_UD_EN__POS 6
846 #define BMA2X2_ORIENT_UD_EN__LEN 1
847 #define BMA2X2_ORIENT_UD_EN__MSK 0x40
848 #define BMA2X2_ORIENT_UD_EN__REG BMA2X2_THETA_BLOCK_REG
850 #define BMA2X2_THETA_BLOCK__POS 0
851 #define BMA2X2_THETA_BLOCK__LEN 6
852 #define BMA2X2_THETA_BLOCK__MSK 0x3F
853 #define BMA2X2_THETA_BLOCK__REG BMA2X2_THETA_BLOCK_REG
855 #define BMA2X2_THETA_FLAT__POS 0
856 #define BMA2X2_THETA_FLAT__LEN 6
857 #define BMA2X2_THETA_FLAT__MSK 0x3F
858 #define BMA2X2_THETA_FLAT__REG BMA2X2_THETA_FLAT_REG
860 #define BMA2X2_FLAT_HOLD_TIME__POS 4
861 #define BMA2X2_FLAT_HOLD_TIME__LEN 2
862 #define BMA2X2_FLAT_HOLD_TIME__MSK 0x30
863 #define BMA2X2_FLAT_HOLD_TIME__REG BMA2X2_FLAT_HOLD_TIME_REG
865 #define BMA2X2_FLAT_HYS__POS 0
866 #define BMA2X2_FLAT_HYS__LEN 3
867 #define BMA2X2_FLAT_HYS__MSK 0x07
868 #define BMA2X2_FLAT_HYS__REG BMA2X2_FLAT_HOLD_TIME_REG
870 #define BMA2X2_FIFO_WML_TRIG_RETAIN__POS 0
871 #define BMA2X2_FIFO_WML_TRIG_RETAIN__LEN 6
872 #define BMA2X2_FIFO_WML_TRIG_RETAIN__MSK 0x3F
873 #define BMA2X2_FIFO_WML_TRIG_RETAIN__REG BMA2X2_FIFO_WML_TRIG
875 #define BMA2X2_EN_SELF_TEST__POS 0
876 #define BMA2X2_EN_SELF_TEST__LEN 2
877 #define BMA2X2_EN_SELF_TEST__MSK 0x03
878 #define BMA2X2_EN_SELF_TEST__REG BMA2X2_SELF_TEST_REG
880 #define BMA2X2_NEG_SELF_TEST__POS 2
881 #define BMA2X2_NEG_SELF_TEST__LEN 1
882 #define BMA2X2_NEG_SELF_TEST__MSK 0x04
883 #define BMA2X2_NEG_SELF_TEST__REG BMA2X2_SELF_TEST_REG
885 #define BMA2X2_SELF_TEST_AMP__POS 4
886 #define BMA2X2_SELF_TEST_AMP__LEN 1
887 #define BMA2X2_SELF_TEST_AMP__MSK 0x10
888 #define BMA2X2_SELF_TEST_AMP__REG BMA2X2_SELF_TEST_REG
891 #define BMA2X2_UNLOCK_EE_PROG_MODE__POS 0
892 #define BMA2X2_UNLOCK_EE_PROG_MODE__LEN 1
893 #define BMA2X2_UNLOCK_EE_PROG_MODE__MSK 0x01
894 #define BMA2X2_UNLOCK_EE_PROG_MODE__REG BMA2X2_EEPROM_CTRL_REG
896 #define BMA2X2_START_EE_PROG_TRIG__POS 1
897 #define BMA2X2_START_EE_PROG_TRIG__LEN 1
898 #define BMA2X2_START_EE_PROG_TRIG__MSK 0x02
899 #define BMA2X2_START_EE_PROG_TRIG__REG BMA2X2_EEPROM_CTRL_REG
901 #define BMA2X2_EE_PROG_READY__POS 2
902 #define BMA2X2_EE_PROG_READY__LEN 1
903 #define BMA2X2_EE_PROG_READY__MSK 0x04
904 #define BMA2X2_EE_PROG_READY__REG BMA2X2_EEPROM_CTRL_REG
906 #define BMA2X2_UPDATE_IMAGE__POS 3
907 #define BMA2X2_UPDATE_IMAGE__LEN 1
908 #define BMA2X2_UPDATE_IMAGE__MSK 0x08
909 #define BMA2X2_UPDATE_IMAGE__REG BMA2X2_EEPROM_CTRL_REG
911 #define BMA2X2_EE_REMAIN__POS 4
912 #define BMA2X2_EE_REMAIN__LEN 4
913 #define BMA2X2_EE_REMAIN__MSK 0xF0
914 #define BMA2X2_EE_REMAIN__REG BMA2X2_EEPROM_CTRL_REG
916 #define BMA2X2_EN_SPI_MODE_3__POS 0
917 #define BMA2X2_EN_SPI_MODE_3__LEN 1
918 #define BMA2X2_EN_SPI_MODE_3__MSK 0x01
919 #define BMA2X2_EN_SPI_MODE_3__REG BMA2X2_SERIAL_CTRL_REG
921 #define BMA2X2_I2C_WATCHDOG_PERIOD__POS 1
922 #define BMA2X2_I2C_WATCHDOG_PERIOD__LEN 1
923 #define BMA2X2_I2C_WATCHDOG_PERIOD__MSK 0x02
924 #define BMA2X2_I2C_WATCHDOG_PERIOD__REG BMA2X2_SERIAL_CTRL_REG
926 #define BMA2X2_EN_I2C_WATCHDOG__POS 2
927 #define BMA2X2_EN_I2C_WATCHDOG__LEN 1
928 #define BMA2X2_EN_I2C_WATCHDOG__MSK 0x04
929 #define BMA2X2_EN_I2C_WATCHDOG__REG BMA2X2_SERIAL_CTRL_REG
931 #define BMA2X2_EXT_MODE__POS 7
932 #define BMA2X2_EXT_MODE__LEN 1
933 #define BMA2X2_EXT_MODE__MSK 0x80
934 #define BMA2X2_EXT_MODE__REG BMA2X2_EXTMODE_CTRL_REG
936 #define BMA2X2_ALLOW_UPPER__POS 6
937 #define BMA2X2_ALLOW_UPPER__LEN 1
938 #define BMA2X2_ALLOW_UPPER__MSK 0x40
939 #define BMA2X2_ALLOW_UPPER__REG BMA2X2_EXTMODE_CTRL_REG
941 #define BMA2X2_MAP_2_LOWER__POS 5
942 #define BMA2X2_MAP_2_LOWER__LEN 1
943 #define BMA2X2_MAP_2_LOWER__MSK 0x20
944 #define BMA2X2_MAP_2_LOWER__REG BMA2X2_EXTMODE_CTRL_REG
946 #define BMA2X2_MAGIC_NUMBER__POS 0
947 #define BMA2X2_MAGIC_NUMBER__LEN 5
948 #define BMA2X2_MAGIC_NUMBER__MSK 0x1F
949 #define BMA2X2_MAGIC_NUMBER__REG BMA2X2_EXTMODE_CTRL_REG
951 #define BMA2X2_UNLOCK_EE_WRITE_TRIM__POS 4
952 #define BMA2X2_UNLOCK_EE_WRITE_TRIM__LEN 4
953 #define BMA2X2_UNLOCK_EE_WRITE_TRIM__MSK 0xF0
954 #define BMA2X2_UNLOCK_EE_WRITE_TRIM__REG BMA2X2_CTRL_UNLOCK_REG
956 #define BMA2X2_EN_SLOW_COMP_X__POS 0
957 #define BMA2X2_EN_SLOW_COMP_X__LEN 1
958 #define BMA2X2_EN_SLOW_COMP_X__MSK 0x01
959 #define BMA2X2_EN_SLOW_COMP_X__REG BMA2X2_OFFSET_CTRL_REG
961 #define BMA2X2_EN_SLOW_COMP_Y__POS 1
962 #define BMA2X2_EN_SLOW_COMP_Y__LEN 1
963 #define BMA2X2_EN_SLOW_COMP_Y__MSK 0x02
964 #define BMA2X2_EN_SLOW_COMP_Y__REG BMA2X2_OFFSET_CTRL_REG
966 #define BMA2X2_EN_SLOW_COMP_Z__POS 2
967 #define BMA2X2_EN_SLOW_COMP_Z__LEN 1
968 #define BMA2X2_EN_SLOW_COMP_Z__MSK 0x04
969 #define BMA2X2_EN_SLOW_COMP_Z__REG BMA2X2_OFFSET_CTRL_REG
971 #define BMA2X2_FAST_CAL_RDY_S__POS 4
972 #define BMA2X2_FAST_CAL_RDY_S__LEN 1
973 #define BMA2X2_FAST_CAL_RDY_S__MSK 0x10
974 #define BMA2X2_FAST_CAL_RDY_S__REG BMA2X2_OFFSET_CTRL_REG
976 #define BMA2X2_CAL_TRIGGER__POS 5
977 #define BMA2X2_CAL_TRIGGER__LEN 2
978 #define BMA2X2_CAL_TRIGGER__MSK 0x60
979 #define BMA2X2_CAL_TRIGGER__REG BMA2X2_OFFSET_CTRL_REG
981 #define BMA2X2_RESET_OFFSET_REGS__POS 7
982 #define BMA2X2_RESET_OFFSET_REGS__LEN 1
983 #define BMA2X2_RESET_OFFSET_REGS__MSK 0x80
984 #define BMA2X2_RESET_OFFSET_REGS__REG BMA2X2_OFFSET_CTRL_REG
986 #define BMA2X2_COMP_CUTOFF__POS 0
987 #define BMA2X2_COMP_CUTOFF__LEN 1
988 #define BMA2X2_COMP_CUTOFF__MSK 0x01
989 #define BMA2X2_COMP_CUTOFF__REG BMA2X2_OFFSET_PARAMS_REG
991 #define BMA2X2_COMP_TARGET_OFFSET_X__POS 1
992 #define BMA2X2_COMP_TARGET_OFFSET_X__LEN 2
993 #define BMA2X2_COMP_TARGET_OFFSET_X__MSK 0x06
994 #define BMA2X2_COMP_TARGET_OFFSET_X__REG BMA2X2_OFFSET_PARAMS_REG
996 #define BMA2X2_COMP_TARGET_OFFSET_Y__POS 3
997 #define BMA2X2_COMP_TARGET_OFFSET_Y__LEN 2
998 #define BMA2X2_COMP_TARGET_OFFSET_Y__MSK 0x18
999 #define BMA2X2_COMP_TARGET_OFFSET_Y__REG BMA2X2_OFFSET_PARAMS_REG
1001 #define BMA2X2_COMP_TARGET_OFFSET_Z__POS 5
1002 #define BMA2X2_COMP_TARGET_OFFSET_Z__LEN 2
1003 #define BMA2X2_COMP_TARGET_OFFSET_Z__MSK 0x60
1004 #define BMA2X2_COMP_TARGET_OFFSET_Z__REG BMA2X2_OFFSET_PARAMS_REG
1006 #define BMA2X2_FIFO_DATA_SELECT__POS 0
1007 #define BMA2X2_FIFO_DATA_SELECT__LEN 2
1008 #define BMA2X2_FIFO_DATA_SELECT__MSK 0x03
1009 #define BMA2X2_FIFO_DATA_SELECT__REG BMA2X2_FIFO_MODE_REG
1011 #define BMA2X2_FIFO_TRIGGER_SOURCE__POS 2
1012 #define BMA2X2_FIFO_TRIGGER_SOURCE__LEN 2
1013 #define BMA2X2_FIFO_TRIGGER_SOURCE__MSK 0x0C
1014 #define BMA2X2_FIFO_TRIGGER_SOURCE__REG BMA2X2_FIFO_MODE_REG
1016 #define BMA2X2_FIFO_TRIGGER_ACTION__POS 4
1017 #define BMA2X2_FIFO_TRIGGER_ACTION__LEN 2
1018 #define BMA2X2_FIFO_TRIGGER_ACTION__MSK 0x30
1019 #define BMA2X2_FIFO_TRIGGER_ACTION__REG BMA2X2_FIFO_MODE_REG
1021 #define BMA2X2_FIFO_MODE__POS 6
1022 #define BMA2X2_FIFO_MODE__LEN 2
1023 #define BMA2X2_FIFO_MODE__MSK 0xC0
1024 #define BMA2X2_FIFO_MODE__REG BMA2X2_FIFO_MODE_REG
1027 #define BMA2X2_STATUS1 0
1028 #define BMA2X2_STATUS2 1
1029 #define BMA2X2_STATUS3 2
1030 #define BMA2X2_STATUS4 3
1031 #define BMA2X2_STATUS5 4
1034 #define BMA2X2_RANGE_2G 3
1035 #define BMA2X2_RANGE_4G 5
1036 #define BMA2X2_RANGE_8G 8
1037 #define BMA2X2_RANGE_16G 12
1040 #define BMA2X2_BW_7_81HZ 0x08
1041 #define BMA2X2_BW_15_63HZ 0x09
1042 #define BMA2X2_BW_31_25HZ 0x0A
1043 #define BMA2X2_BW_62_50HZ 0x0B
1044 #define BMA2X2_BW_125HZ 0x0C
1045 #define BMA2X2_BW_250HZ 0x0D
1046 #define BMA2X2_BW_500HZ 0x0E
1047 #define BMA2X2_BW_1000HZ 0x0F
1049 #define BMA2X2_SLEEP_DUR_0_5MS 0x05
1050 #define BMA2X2_SLEEP_DUR_1MS 0x06
1051 #define BMA2X2_SLEEP_DUR_2MS 0x07
1052 #define BMA2X2_SLEEP_DUR_4MS 0x08
1053 #define BMA2X2_SLEEP_DUR_6MS 0x09
1054 #define BMA2X2_SLEEP_DUR_10MS 0x0A
1055 #define BMA2X2_SLEEP_DUR_25MS 0x0B
1056 #define BMA2X2_SLEEP_DUR_50MS 0x0C
1057 #define BMA2X2_SLEEP_DUR_100MS 0x0D
1058 #define BMA2X2_SLEEP_DUR_500MS 0x0E
1059 #define BMA2X2_SLEEP_DUR_1S 0x0F
1061 #define BMA2X2_LATCH_DUR_NON_LATCH 0x00
1062 #define BMA2X2_LATCH_DUR_250MS 0x01
1063 #define BMA2X2_LATCH_DUR_500MS 0x02
1064 #define BMA2X2_LATCH_DUR_1S 0x03
1065 #define BMA2X2_LATCH_DUR_2S 0x04
1066 #define BMA2X2_LATCH_DUR_4S 0x05
1067 #define BMA2X2_LATCH_DUR_8S 0x06
1068 #define BMA2X2_LATCH_DUR_LATCH 0x07
1069 #define BMA2X2_LATCH_DUR_NON_LATCH1 0x08
1070 #define BMA2X2_LATCH_DUR_250US 0x09
1071 #define BMA2X2_LATCH_DUR_500US 0x0A
1072 #define BMA2X2_LATCH_DUR_1MS 0x0B
1073 #define BMA2X2_LATCH_DUR_12_5MS 0x0C
1074 #define BMA2X2_LATCH_DUR_25MS 0x0D
1075 #define BMA2X2_LATCH_DUR_50MS 0x0E
1076 #define BMA2X2_LATCH_DUR_LATCH1 0x0F
1078 #define BMA2X2_MODE_NORMAL 0
1079 #define BMA2X2_MODE_LOWPOWER1 1
1080 #define BMA2X2_MODE_SUSPEND 2
1081 #define BMA2X2_MODE_DEEP_SUSPEND 3
1082 #define BMA2X2_MODE_LOWPOWER2 4
1083 #define BMA2X2_MODE_STANDBY 5
1085 #define BMA2X2_X_AXIS 0
1086 #define BMA2X2_Y_AXIS 1
1087 #define BMA2X2_Z_AXIS 2
1089 #define BMA2X2_Low_G_Interrupt 0
1090 #define BMA2X2_High_G_X_Interrupt 1
1091 #define BMA2X2_High_G_Y_Interrupt 2
1092 #define BMA2X2_High_G_Z_Interrupt 3
1093 #define BMA2X2_DATA_EN 4
1094 #define BMA2X2_Slope_X_Interrupt 5
1095 #define BMA2X2_Slope_Y_Interrupt 6
1096 #define BMA2X2_Slope_Z_Interrupt 7
1097 #define BMA2X2_Single_Tap_Interrupt 8
1098 #define BMA2X2_Double_Tap_Interrupt 9
1099 #define BMA2X2_Orient_Interrupt 10
1100 #define BMA2X2_Flat_Interrupt 11
1101 #define BMA2X2_FFULL_INTERRUPT 12
1102 #define BMA2X2_FWM_INTERRUPT 13
1104 #define BMA2X2_INT1_LOWG 0
1105 #define BMA2X2_INT2_LOWG 1
1106 #define BMA2X2_INT1_HIGHG 0
1107 #define BMA2X2_INT2_HIGHG 1
1108 #define BMA2X2_INT1_SLOPE 0
1109 #define BMA2X2_INT2_SLOPE 1
1110 #define BMA2X2_INT1_SLO_NO_MOT 0
1111 #define BMA2X2_INT2_SLO_NO_MOT 1
1112 #define BMA2X2_INT1_DTAP 0
1113 #define BMA2X2_INT2_DTAP 1
1114 #define BMA2X2_INT1_STAP 0
1115 #define BMA2X2_INT2_STAP 1
1116 #define BMA2X2_INT1_ORIENT 0
1117 #define BMA2X2_INT2_ORIENT 1
1118 #define BMA2X2_INT1_FLAT 0
1119 #define BMA2X2_INT2_FLAT 1
1120 #define BMA2X2_INT1_NDATA 0
1121 #define BMA2X2_INT2_NDATA 1
1122 #define BMA2X2_INT1_FWM 0
1123 #define BMA2X2_INT2_FWM 1
1124 #define BMA2X2_INT1_FFULL 0
1125 #define BMA2X2_INT2_FFULL 1
1127 #define BMA2X2_SRC_LOWG 0
1128 #define BMA2X2_SRC_HIGHG 1
1129 #define BMA2X2_SRC_SLOPE 2
1130 #define BMA2X2_SRC_SLO_NO_MOT 3
1131 #define BMA2X2_SRC_TAP 4
1132 #define BMA2X2_SRC_DATA 5
1134 #define BMA2X2_INT1_OUTPUT 0
1135 #define BMA2X2_INT2_OUTPUT 1
1136 #define BMA2X2_INT1_LEVEL 0
1137 #define BMA2X2_INT2_LEVEL 1
1139 #define BMA2X2_LOW_DURATION 0
1140 #define BMA2X2_HIGH_DURATION 1
1141 #define BMA2X2_SLOPE_DURATION 2
1142 #define BMA2X2_SLO_NO_MOT_DURATION 3
1144 #define BMA2X2_LOW_THRESHOLD 0
1145 #define BMA2X2_HIGH_THRESHOLD 1
1146 #define BMA2X2_SLOPE_THRESHOLD 2
1147 #define BMA2X2_SLO_NO_MOT_THRESHOLD 3
1150 #define BMA2X2_LOWG_HYST 0
1151 #define BMA2X2_HIGHG_HYST 1
1153 #define BMA2X2_ORIENT_THETA 0
1154 #define BMA2X2_FLAT_THETA 1
1156 #define BMA2X2_I2C_SELECT 0
1157 #define BMA2X2_I2C_EN 1
1159 #define BMA2X2_SLOW_COMP_X 0
1160 #define BMA2X2_SLOW_COMP_Y 1
1161 #define BMA2X2_SLOW_COMP_Z 2
1163 #define BMA2X2_CUT_OFF 0
1164 #define BMA2X2_OFFSET_TRIGGER_X 1
1165 #define BMA2X2_OFFSET_TRIGGER_Y 2
1166 #define BMA2X2_OFFSET_TRIGGER_Z 3
1168 #define BMA2X2_GP0 0
1169 #define BMA2X2_GP1 1
1171 #define BMA2X2_SLO_NO_MOT_EN_X 0
1172 #define BMA2X2_SLO_NO_MOT_EN_Y 1
1173 #define BMA2X2_SLO_NO_MOT_EN_Z 2
1174 #define BMA2X2_SLO_NO_MOT_EN_SEL 3
1176 #define BMA2X2_WAKE_UP_DUR_20MS 0
1177 #define BMA2X2_WAKE_UP_DUR_80MS 1
1178 #define BMA2X2_WAKE_UP_DUR_320MS 2
1179 #define BMA2X2_WAKE_UP_DUR_2560MS 3
1181 #define BMA2X2_SELF_TEST0_ON 1
1182 #define BMA2X2_SELF_TEST1_ON 2
1184 #define BMA2X2_EE_W_OFF 0
1185 #define BMA2X2_EE_W_ON 1
1187 #define BMA2X2_LOW_TH_IN_G(gthres, range) ((256 * gthres) / range)
1190 #define BMA2X2_HIGH_TH_IN_G(gthres, range) ((256 * gthres) / range)
1193 #define BMA2X2_LOW_HY_IN_G(ghyst, range) ((32 * ghyst) / range)
1196 #define BMA2X2_HIGH_HY_IN_G(ghyst, range) ((32 * ghyst) / range)
1199 #define BMA2X2_SLOPE_TH_IN_G(gthres, range) ((128 * gthres) / range)
1202 #define BMA2X2_GET_BITSLICE(regvar, bitname)\
1203 ((regvar & bitname##__MSK) >> bitname##__POS)
1206 #define BMA2X2_SET_BITSLICE(regvar, bitname, val)\
1207 ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
1210 #define BMA255_CHIP_ID 0XFA
1211 #define BMA250E_CHIP_ID 0XF9
1212 #define BMA222E_CHIP_ID 0XF8
1213 #define BMA280_CHIP_ID 0XFB
1215 #define BMA255_TYPE 0
1216 #define BMA250E_TYPE 1
1217 #define BMA222E_TYPE 2
1218 #define BMA280_TYPE 3
1220 #define MAX_FIFO_F_LEVEL 32
1221 #define MAX_FIFO_F_BYTES 6
1222 #define BMA_MAX_RETRY_I2C_XFER (100)
1224 static struct device *bma_device = NULL;
1225 #define CALIBRATION_FILE_PATH "/efs/calibration_data"
1227 unsigned char *sensor_name[] = { "BMA255", "BMA250E", "BMA222E", "BMA280" };
1235 struct bma2x2_data {
1236 struct i2c_client *bma2x2_client;
1239 atomic_t selftest_result;
1240 unsigned int chip_id;
1242 signed char sensor_type;
1243 struct input_dev *input;
1244 struct bma2x2acc value;
1245 struct mutex value_mutex;
1246 struct mutex enable_mutex;
1247 struct mutex mode_mutex;
1248 struct delayed_work work;
1249 struct work_struct irq_work;
1250 #ifdef CONFIG_HAS_EARLYSUSPEND
1251 struct early_suspend early_suspend;
1255 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
1256 struct bosch_sensor_specific *bst_pd;
1260 #ifdef CONFIG_HAS_EARLYSUSPEND
1261 static void bma2x2_early_suspend(struct early_suspend *h);
1262 static void bma2x2_late_resume(struct early_suspend *h);
1265 static void bma2x2_remap_sensor_data(struct bma2x2acc *val,
1266 struct bma2x2_data *client_data)
1268 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
1269 struct bosch_sensor_data bsd;
1271 if (NULL == client_data->bst_pd)
1278 bst_remap_sensor_data_dft_tab(&bsd,
1279 client_data->bst_pd->place);
1291 static int bma2x2_smbus_read_byte(struct i2c_client *client,
1292 unsigned char reg_addr, unsigned char *data)
1295 dummy = i2c_smbus_read_byte_data(client, reg_addr);
1298 *data = dummy & 0x000000ff;
1303 static int bma2x2_smbus_write_byte(struct i2c_client *client,
1304 unsigned char reg_addr, unsigned char *data)
1308 dummy = i2c_smbus_write_byte_data(client, reg_addr, *data);
1314 static int bma2x2_smbus_read_byte_block(struct i2c_client *client,
1315 unsigned char reg_addr, unsigned char *data, unsigned char len)
1318 dummy = i2c_smbus_read_i2c_block_data(client, reg_addr, len, data);
1324 static int bma_i2c_burst_read(struct i2c_client *client, u8 reg_addr,
1329 struct i2c_msg msg[] = {
1331 .addr = client->addr,
1338 .addr = client->addr,
1345 for (retry = 0; retry < BMA_MAX_RETRY_I2C_XFER; retry++) {
1346 if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
1352 if (BMA_MAX_RETRY_I2C_XFER <= retry) {
1353 printk(KERN_INFO "I2C xfer error");
1361 #ifdef BMA2X2_ENABLE_INT1
1362 static int bma2x2_set_int1_pad_sel(struct i2c_client *client, unsigned char
1367 unsigned char state;
1373 comres = bma2x2_smbus_read_byte(client,
1374 BMA2X2_EN_INT1_PAD_LOWG__REG, &data);
1375 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_LOWG,
1377 comres = bma2x2_smbus_write_byte(client,
1378 BMA2X2_EN_INT1_PAD_LOWG__REG, &data);
1381 comres = bma2x2_smbus_read_byte(client,
1382 BMA2X2_EN_INT1_PAD_HIGHG__REG, &data);
1383 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_HIGHG,
1385 comres = bma2x2_smbus_write_byte(client,
1386 BMA2X2_EN_INT1_PAD_HIGHG__REG, &data);
1389 comres = bma2x2_smbus_read_byte(client,
1390 BMA2X2_EN_INT1_PAD_SLOPE__REG, &data);
1391 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_SLOPE,
1393 comres = bma2x2_smbus_write_byte(client,
1394 BMA2X2_EN_INT1_PAD_SLOPE__REG, &data);
1397 comres = bma2x2_smbus_read_byte(client,
1398 BMA2X2_EN_INT1_PAD_DB_TAP__REG, &data);
1399 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_DB_TAP,
1401 comres = bma2x2_smbus_write_byte(client,
1402 BMA2X2_EN_INT1_PAD_DB_TAP__REG, &data);
1405 comres = bma2x2_smbus_read_byte(client,
1406 BMA2X2_EN_INT1_PAD_SNG_TAP__REG, &data);
1407 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_SNG_TAP,
1409 comres = bma2x2_smbus_write_byte(client,
1410 BMA2X2_EN_INT1_PAD_SNG_TAP__REG, &data);
1413 comres = bma2x2_smbus_read_byte(client,
1414 BMA2X2_EN_INT1_PAD_ORIENT__REG, &data);
1415 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_ORIENT,
1417 comres = bma2x2_smbus_write_byte(client,
1418 BMA2X2_EN_INT1_PAD_ORIENT__REG, &data);
1421 comres = bma2x2_smbus_read_byte(client,
1422 BMA2X2_EN_INT1_PAD_FLAT__REG, &data);
1423 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_FLAT,
1425 comres = bma2x2_smbus_write_byte(client,
1426 BMA2X2_EN_INT1_PAD_FLAT__REG, &data);
1429 comres = bma2x2_smbus_read_byte(client,
1430 BMA2X2_EN_INT1_PAD_SLO_NO_MOT__REG, &data);
1431 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT1_PAD_SLO_NO_MOT,
1433 comres = bma2x2_smbus_write_byte(client,
1434 BMA2X2_EN_INT1_PAD_SLO_NO_MOT__REG, &data);
1443 #endif /* BMA2X2_ENABLE_INT1 */
1444 #ifdef BMA2X2_ENABLE_INT2
1445 static int bma2x2_set_int2_pad_sel(struct i2c_client *client, unsigned char
1450 unsigned char state;
1456 comres = bma2x2_smbus_read_byte(client,
1457 BMA2X2_EN_INT2_PAD_LOWG__REG, &data);
1458 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_LOWG,
1460 comres = bma2x2_smbus_write_byte(client,
1461 BMA2X2_EN_INT2_PAD_LOWG__REG, &data);
1464 comres = bma2x2_smbus_read_byte(client,
1465 BMA2X2_EN_INT2_PAD_HIGHG__REG, &data);
1466 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_HIGHG,
1468 comres = bma2x2_smbus_write_byte(client,
1469 BMA2X2_EN_INT2_PAD_HIGHG__REG, &data);
1472 comres = bma2x2_smbus_read_byte(client,
1473 BMA2X2_EN_INT2_PAD_SLOPE__REG, &data);
1474 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_SLOPE,
1476 comres = bma2x2_smbus_write_byte(client,
1477 BMA2X2_EN_INT2_PAD_SLOPE__REG, &data);
1480 comres = bma2x2_smbus_read_byte(client,
1481 BMA2X2_EN_INT2_PAD_DB_TAP__REG, &data);
1482 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_DB_TAP,
1484 comres = bma2x2_smbus_write_byte(client,
1485 BMA2X2_EN_INT2_PAD_DB_TAP__REG, &data);
1488 comres = bma2x2_smbus_read_byte(client,
1489 BMA2X2_EN_INT2_PAD_SNG_TAP__REG, &data);
1490 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_SNG_TAP,
1492 comres = bma2x2_smbus_write_byte(client,
1493 BMA2X2_EN_INT2_PAD_SNG_TAP__REG, &data);
1496 comres = bma2x2_smbus_read_byte(client,
1497 BMA2X2_EN_INT2_PAD_ORIENT__REG, &data);
1498 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_ORIENT,
1500 comres = bma2x2_smbus_write_byte(client,
1501 BMA2X2_EN_INT2_PAD_ORIENT__REG, &data);
1504 comres = bma2x2_smbus_read_byte(client,
1505 BMA2X2_EN_INT2_PAD_FLAT__REG, &data);
1506 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_FLAT,
1508 comres = bma2x2_smbus_write_byte(client,
1509 BMA2X2_EN_INT2_PAD_FLAT__REG, &data);
1512 comres = bma2x2_smbus_read_byte(client,
1513 BMA2X2_EN_INT2_PAD_SLO_NO_MOT__REG, &data);
1514 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_INT2_PAD_SLO_NO_MOT,
1516 comres = bma2x2_smbus_write_byte(client,
1517 BMA2X2_EN_INT2_PAD_SLO_NO_MOT__REG, &data);
1525 #endif /* BMA2X2_ENABLE_INT2 */
1527 static int bma2x2_set_Int_Enable(struct i2c_client *client, unsigned char
1528 InterruptType , unsigned char value)
1531 unsigned char data1, data2;
1533 if ((11 < InterruptType) && (InterruptType < 16)) {
1534 switch (InterruptType) {
1536 /* slow/no motion X Interrupt */
1537 comres = bma2x2_smbus_read_byte(client,
1538 BMA2X2_INT_SLO_NO_MOT_EN_X_INT__REG, &data1);
1539 data1 = BMA2X2_SET_BITSLICE(data1,
1540 BMA2X2_INT_SLO_NO_MOT_EN_X_INT, value);
1541 comres = bma2x2_smbus_write_byte(client,
1542 BMA2X2_INT_SLO_NO_MOT_EN_X_INT__REG, &data1);
1545 /* slow/no motion Y Interrupt */
1546 comres = bma2x2_smbus_read_byte(client,
1547 BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__REG, &data1);
1548 data1 = BMA2X2_SET_BITSLICE(data1,
1549 BMA2X2_INT_SLO_NO_MOT_EN_Y_INT, value);
1550 comres = bma2x2_smbus_write_byte(client,
1551 BMA2X2_INT_SLO_NO_MOT_EN_Y_INT__REG, &data1);
1554 /* slow/no motion Z Interrupt */
1555 comres = bma2x2_smbus_read_byte(client,
1556 BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__REG, &data1);
1557 data1 = BMA2X2_SET_BITSLICE(data1,
1558 BMA2X2_INT_SLO_NO_MOT_EN_Z_INT, value);
1559 comres = bma2x2_smbus_write_byte(client,
1560 BMA2X2_INT_SLO_NO_MOT_EN_Z_INT__REG, &data1);
1563 /* slow / no motion Interrupt select */
1564 comres = bma2x2_smbus_read_byte(client,
1565 BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG, &data1);
1566 data1 = BMA2X2_SET_BITSLICE(data1,
1567 BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT, value);
1568 comres = bma2x2_smbus_write_byte(client,
1569 BMA2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG, &data1);
1576 comres = bma2x2_smbus_read_byte(client, BMA2X2_INT_ENABLE1_REG, &data1);
1577 comres = bma2x2_smbus_read_byte(client, BMA2X2_INT_ENABLE2_REG, &data2);
1580 switch (InterruptType) {
1582 /* Low G Interrupt */
1583 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_LOWG_INT, value);
1586 /* High G X Interrupt */
1588 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_X_INT,
1592 /* High G Y Interrupt */
1594 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_Y_INT,
1598 /* High G Z Interrupt */
1600 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_Z_INT,
1604 /* New Data Interrupt */
1606 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_NEW_DATA_INT,
1610 /* Slope X Interrupt */
1612 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_X_INT,
1616 /* Slope Y Interrupt */
1618 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_Y_INT,
1622 /* Slope Z Interrupt */
1624 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_Z_INT,
1628 /* Single Tap Interrupt */
1630 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SINGLE_TAP_INT,
1634 /* Double Tap Interrupt */
1636 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_DOUBLE_TAP_INT,
1640 /* Orient Interrupt */
1642 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_ORIENT_INT, value);
1645 /* Flat Interrupt */
1647 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_FLAT_INT, value);
1652 comres = bma2x2_smbus_write_byte(client, BMA2X2_INT_ENABLE1_REG,
1654 comres = bma2x2_smbus_write_byte(client, BMA2X2_INT_ENABLE2_REG,
1661 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
1662 static int bma2x2_get_interruptstatus1(struct i2c_client *client, unsigned char
1668 comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS1_REG, &data);
1675 static int bma2x2_get_HIGH_first(struct i2c_client *client, unsigned char
1676 param, unsigned char *intstatus)
1683 comres = bma2x2_smbus_read_byte(client,
1684 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1685 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_X);
1689 comres = bma2x2_smbus_read_byte(client,
1690 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1691 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_Y);
1695 comres = bma2x2_smbus_read_byte(client,
1696 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1697 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_Z);
1707 static int bma2x2_get_HIGH_sign(struct i2c_client *client, unsigned char
1713 comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1715 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_SIGN_S);
1722 static int bma2x2_get_slope_first(struct i2c_client *client, unsigned char
1723 param, unsigned char *intstatus)
1730 comres = bma2x2_smbus_read_byte(client,
1731 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1732 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_X);
1736 comres = bma2x2_smbus_read_byte(client,
1737 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1738 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_Y);
1742 comres = bma2x2_smbus_read_byte(client,
1743 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1744 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_Z);
1754 static int bma2x2_get_slope_sign(struct i2c_client *client, unsigned char
1760 comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_TAP_SLOPE_REG,
1762 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_SIGN_S);
1768 static int bma2x2_get_orient_status(struct i2c_client *client, unsigned char
1774 comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1776 data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_S);
1782 static int bma2x2_get_orient_flat_status(struct i2c_client *client, unsigned
1788 comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1790 data = BMA2X2_GET_BITSLICE(data, BMA2X2_FLAT_S);
1795 #endif /* defined(BMA2X2_ENABLE_INT1)||defined(BMA2X2_ENABLE_INT2) */
1796 static int bma2x2_set_Int_Mode(struct i2c_client *client, unsigned char Mode)
1802 comres = bma2x2_smbus_read_byte(client,
1803 BMA2X2_INT_MODE_SEL__REG, &data);
1804 data = BMA2X2_SET_BITSLICE(data, BMA2X2_INT_MODE_SEL, Mode);
1805 comres = bma2x2_smbus_write_byte(client,
1806 BMA2X2_INT_MODE_SEL__REG, &data);
1812 static int bma2x2_get_Int_Mode(struct i2c_client *client, unsigned char *Mode)
1818 comres = bma2x2_smbus_read_byte(client,
1819 BMA2X2_INT_MODE_SEL__REG, &data);
1820 data = BMA2X2_GET_BITSLICE(data, BMA2X2_INT_MODE_SEL);
1826 static int bma2x2_set_slope_duration(struct i2c_client *client, unsigned char
1833 comres = bma2x2_smbus_read_byte(client,
1834 BMA2X2_SLOPE_DUR__REG, &data);
1835 data = BMA2X2_SET_BITSLICE(data, BMA2X2_SLOPE_DUR, duration);
1836 comres = bma2x2_smbus_write_byte(client,
1837 BMA2X2_SLOPE_DUR__REG, &data);
1843 static int bma2x2_get_slope_duration(struct i2c_client *client, unsigned char
1850 comres = bma2x2_smbus_read_byte(client,
1851 BMA2X2_SLOPE_DURN_REG, &data);
1852 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_DUR);
1859 static int bma2x2_set_slope_no_mot_duration(struct i2c_client *client,
1860 unsigned char duration)
1866 comres = bma2x2_smbus_read_byte(client,
1867 BMA2x2_SLO_NO_MOT_DUR__REG, &data);
1868 data = BMA2X2_SET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR, duration);
1869 comres = bma2x2_smbus_write_byte(client,
1870 BMA2x2_SLO_NO_MOT_DUR__REG, &data);
1876 static int bma2x2_get_slope_no_mot_duration(struct i2c_client *client,
1877 unsigned char *status)
1883 comres = bma2x2_smbus_read_byte(client,
1884 BMA2x2_SLO_NO_MOT_DUR__REG, &data);
1885 data = BMA2X2_GET_BITSLICE(data, BMA2x2_SLO_NO_MOT_DUR);
1892 static int bma2x2_set_slope_threshold(struct i2c_client *client,
1893 unsigned char threshold)
1899 comres = bma2x2_smbus_write_byte(client,
1900 BMA2X2_SLOPE_THRES__REG, &data);
1905 static int bma2x2_get_slope_threshold(struct i2c_client *client,
1906 unsigned char *status)
1912 comres = bma2x2_smbus_read_byte(client,
1913 BMA2X2_SLOPE_THRES_REG, &data);
1919 static int bma2x2_set_slope_no_mot_threshold(struct i2c_client *client,
1920 unsigned char threshold)
1926 comres = bma2x2_smbus_write_byte(client,
1927 BMA2X2_SLO_NO_MOT_THRES_REG, &data);
1932 static int bma2x2_get_slope_no_mot_threshold(struct i2c_client *client,
1933 unsigned char *status)
1939 comres = bma2x2_smbus_read_byte(client,
1940 BMA2X2_SLO_NO_MOT_THRES_REG, &data);
1947 static int bma2x2_set_low_g_duration(struct i2c_client *client, unsigned char
1954 comres = bma2x2_smbus_write_byte(client, BMA2X2_LOWG_DUR__REG, &data);
1959 static int bma2x2_get_low_g_duration(struct i2c_client *client, unsigned char
1965 comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_DURN_REG, &data);
1966 data = BMA2X2_GET_BITSLICE(data, BMA2X2_LOWG_DUR);
1972 static int bma2x2_set_low_g_threshold(struct i2c_client *client, unsigned char
1979 comres = bma2x2_smbus_write_byte(client, BMA2X2_LOWG_THRES__REG, &data);
1984 static int bma2x2_get_low_g_threshold(struct i2c_client *client, unsigned char
1990 comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_THRES_REG, &data);
1991 data = BMA2X2_GET_BITSLICE(data, BMA2X2_LOWG_THRES);
1997 static int bma2x2_set_high_g_duration(struct i2c_client *client, unsigned char
2004 comres = bma2x2_smbus_write_byte(client, BMA2X2_HIGHG_DUR__REG, &data);
2009 static int bma2x2_get_high_g_duration(struct i2c_client *client, unsigned char
2015 comres = bma2x2_smbus_read_byte(client, BMA2X2_HIGH_DURN_REG, &data);
2016 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_DUR);
2022 static int bma2x2_set_high_g_threshold(struct i2c_client *client, unsigned char
2029 comres = bma2x2_smbus_write_byte(client, BMA2X2_HIGHG_THRES__REG,
2035 static int bma2x2_get_high_g_threshold(struct i2c_client *client, unsigned char
2041 comres = bma2x2_smbus_read_byte(client, BMA2X2_HIGH_THRES_REG, &data);
2042 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_THRES);
2049 static int bma2x2_set_tap_duration(struct i2c_client *client, unsigned char
2055 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_DUR__REG, &data);
2056 data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_DUR, duration);
2057 comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_DUR__REG, &data);
2062 static int bma2x2_get_tap_duration(struct i2c_client *client, unsigned char
2068 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2069 data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_DUR);
2075 static int bma2x2_set_tap_shock(struct i2c_client *client, unsigned char setval)
2080 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_SHOCK_DURN__REG,
2082 data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_SHOCK_DURN, setval);
2083 comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_SHOCK_DURN__REG,
2089 static int bma2x2_get_tap_shock(struct i2c_client *client, unsigned char
2095 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2096 data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_SHOCK_DURN);
2102 static int bma2x2_set_tap_quiet(struct i2c_client *client, unsigned char
2108 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_QUIET_DURN__REG,
2110 data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_QUIET_DURN, duration);
2111 comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_QUIET_DURN__REG,
2117 static int bma2x2_get_tap_quiet(struct i2c_client *client, unsigned char
2123 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2124 data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_QUIET_DURN);
2130 static int bma2x2_set_tap_threshold(struct i2c_client *client, unsigned char
2136 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_THRES__REG, &data);
2137 data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_THRES, threshold);
2138 comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_THRES__REG, &data);
2143 static int bma2x2_get_tap_threshold(struct i2c_client *client, unsigned char
2149 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_THRES_REG, &data);
2150 data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_THRES);
2156 static int bma2x2_set_tap_samp(struct i2c_client *client, unsigned char samp)
2161 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_SAMPLES__REG, &data);
2162 data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_SAMPLES, samp);
2163 comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_SAMPLES__REG,
2169 static int bma2x2_get_tap_samp(struct i2c_client *client, unsigned char *status)
2174 comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_THRES_REG, &data);
2175 data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_SAMPLES);
2181 static int bma2x2_set_orient_mode(struct i2c_client *client, unsigned char mode)
2186 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_MODE__REG, &data);
2187 data = BMA2X2_SET_BITSLICE(data, BMA2X2_ORIENT_MODE, mode);
2188 comres = bma2x2_smbus_write_byte(client, BMA2X2_ORIENT_MODE__REG,
2194 static int bma2x2_get_orient_mode(struct i2c_client *client, unsigned char
2200 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2201 data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_MODE);
2207 static int bma2x2_set_orient_blocking(struct i2c_client *client, unsigned char
2213 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_BLOCK__REG,
2215 data = BMA2X2_SET_BITSLICE(data, BMA2X2_ORIENT_BLOCK, samp);
2216 comres = bma2x2_smbus_write_byte(client, BMA2X2_ORIENT_BLOCK__REG,
2222 static int bma2x2_get_orient_blocking(struct i2c_client *client, unsigned char
2228 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2229 data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_BLOCK);
2235 static int bma2x2_set_orient_hyst(struct i2c_client *client, unsigned char
2241 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_HYST__REG, &data);
2242 data = BMA2X2_SET_BITSLICE(data, BMA2X2_ORIENT_HYST, orienthyst);
2243 comres = bma2x2_smbus_write_byte(client, BMA2X2_ORIENT_HYST__REG,
2249 static int bma2x2_get_orient_hyst(struct i2c_client *client, unsigned char
2255 comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2256 data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_HYST);
2261 static int bma2x2_set_theta_blocking(struct i2c_client *client, unsigned char
2267 comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_BLOCK__REG, &data);
2268 data = BMA2X2_SET_BITSLICE(data, BMA2X2_THETA_BLOCK, thetablk);
2269 comres = bma2x2_smbus_write_byte(client, BMA2X2_THETA_BLOCK__REG,
2275 static int bma2x2_get_theta_blocking(struct i2c_client *client, unsigned char
2281 comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_BLOCK_REG, &data);
2282 data = BMA2X2_GET_BITSLICE(data, BMA2X2_THETA_BLOCK);
2288 static int bma2x2_set_theta_flat(struct i2c_client *client, unsigned char
2294 comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_FLAT__REG, &data);
2295 data = BMA2X2_SET_BITSLICE(data, BMA2X2_THETA_FLAT, thetaflat);
2296 comres = bma2x2_smbus_write_byte(client, BMA2X2_THETA_FLAT__REG, &data);
2301 static int bma2x2_get_theta_flat(struct i2c_client *client, unsigned char
2307 comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_FLAT_REG, &data);
2308 data = BMA2X2_GET_BITSLICE(data, BMA2X2_THETA_FLAT);
2314 static int bma2x2_set_flat_hold_time(struct i2c_client *client, unsigned char
2320 comres = bma2x2_smbus_read_byte(client, BMA2X2_FLAT_HOLD_TIME__REG,
2322 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FLAT_HOLD_TIME, holdtime);
2323 comres = bma2x2_smbus_write_byte(client, BMA2X2_FLAT_HOLD_TIME__REG,
2329 static int bma2x2_get_flat_hold_time(struct i2c_client *client, unsigned char
2335 comres = bma2x2_smbus_read_byte(client, BMA2X2_FLAT_HOLD_TIME_REG,
2337 data = BMA2X2_GET_BITSLICE(data, BMA2X2_FLAT_HOLD_TIME);
2343 static int bma2x2_set_mode(struct i2c_client *client, unsigned char Mode)
2346 unsigned char data1, data2;
2349 comres = bma2x2_smbus_read_byte(client, BMA2X2_MODE_CTRL_REG,
2351 comres = bma2x2_smbus_read_byte(client,
2352 BMA2X2_LOW_NOISE_CTRL_REG,
2355 case BMA2X2_MODE_NORMAL:
2356 data1 = BMA2X2_SET_BITSLICE(data1,
2357 BMA2X2_MODE_CTRL, 0);
2358 data2 = BMA2X2_SET_BITSLICE(data2,
2359 BMA2X2_LOW_POWER_MODE, 0);
2360 bma2x2_smbus_write_byte(client,
2361 BMA2X2_MODE_CTRL_REG, &data1);
2363 bma2x2_smbus_write_byte(client,
2364 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2366 case BMA2X2_MODE_LOWPOWER1:
2367 data1 = BMA2X2_SET_BITSLICE(data1,
2368 BMA2X2_MODE_CTRL, 2);
2369 data2 = BMA2X2_SET_BITSLICE(data2,
2370 BMA2X2_LOW_POWER_MODE, 0);
2371 bma2x2_smbus_write_byte(client,
2372 BMA2X2_MODE_CTRL_REG, &data1);
2374 bma2x2_smbus_write_byte(client,
2375 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2377 case BMA2X2_MODE_SUSPEND:
2378 data1 = BMA2X2_SET_BITSLICE(data1,
2379 BMA2X2_MODE_CTRL, 4);
2380 data2 = BMA2X2_SET_BITSLICE(data2,
2381 BMA2X2_LOW_POWER_MODE, 0);
2382 bma2x2_smbus_write_byte(client,
2383 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2385 bma2x2_smbus_write_byte(client,
2386 BMA2X2_MODE_CTRL_REG, &data1);
2388 case BMA2X2_MODE_DEEP_SUSPEND:
2389 data1 = BMA2X2_SET_BITSLICE(data1,
2390 BMA2X2_MODE_CTRL, 1);
2391 data2 = BMA2X2_SET_BITSLICE(data2,
2392 BMA2X2_LOW_POWER_MODE, 1);
2393 bma2x2_smbus_write_byte(client,
2394 BMA2X2_MODE_CTRL_REG, &data1);
2396 bma2x2_smbus_write_byte(client,
2397 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2399 case BMA2X2_MODE_LOWPOWER2:
2400 data1 = BMA2X2_SET_BITSLICE(data1,
2401 BMA2X2_MODE_CTRL, 2);
2402 data2 = BMA2X2_SET_BITSLICE(data2,
2403 BMA2X2_LOW_POWER_MODE, 1);
2404 bma2x2_smbus_write_byte(client,
2405 BMA2X2_MODE_CTRL_REG, &data1);
2407 bma2x2_smbus_write_byte(client,
2408 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2410 case BMA2X2_MODE_STANDBY:
2411 data1 = BMA2X2_SET_BITSLICE(data1,
2412 BMA2X2_MODE_CTRL, 4);
2413 data2 = BMA2X2_SET_BITSLICE(data2,
2414 BMA2X2_LOW_POWER_MODE, 1);
2415 bma2x2_smbus_write_byte(client,
2416 BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2418 bma2x2_smbus_write_byte(client,
2419 BMA2X2_MODE_CTRL_REG, &data1);
2431 static int bma2x2_get_mode(struct i2c_client *client, unsigned char *Mode)
2434 unsigned char data1, data2;
2436 comres = bma2x2_smbus_read_byte(client, BMA2X2_MODE_CTRL_REG, &data1);
2437 comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_NOISE_CTRL_REG,
2440 data1 = (data1 & 0xE0) >> 5;
2441 data2 = (data2 & 0x40) >> 6;
2444 if ((data1 == 0x00) && (data2 == 0x00)) {
2445 *Mode = BMA2X2_MODE_NORMAL;
2447 if ((data1 == 0x02) && (data2 == 0x00)) {
2448 *Mode = BMA2X2_MODE_LOWPOWER1;
2450 if ((data1 == 0x04 || data1 == 0x06) &&
2452 *Mode = BMA2X2_MODE_SUSPEND;
2454 if (((data1 & 0x01) == 0x01)) {
2455 *Mode = BMA2X2_MODE_DEEP_SUSPEND;
2457 if ((data1 == 0x02) &&
2459 *Mode = BMA2X2_MODE_LOWPOWER2;
2461 if ((data1 == 0x04) && (data2 ==
2464 BMA2X2_MODE_STANDBY;
2467 BMA2X2_MODE_DEEP_SUSPEND;
2478 static int bma2x2_set_range(struct i2c_client *client, unsigned char Range)
2481 unsigned char data1;
2483 if ((Range == 3) || (Range == 5) || (Range == 8) || (Range == 12)) {
2484 comres = bma2x2_smbus_read_byte(client, BMA2X2_RANGE_SEL_REG,
2487 case BMA2X2_RANGE_2G:
2488 data1 = BMA2X2_SET_BITSLICE(data1,
2489 BMA2X2_RANGE_SEL, 3);
2491 case BMA2X2_RANGE_4G:
2492 data1 = BMA2X2_SET_BITSLICE(data1,
2493 BMA2X2_RANGE_SEL, 5);
2495 case BMA2X2_RANGE_8G:
2496 data1 = BMA2X2_SET_BITSLICE(data1,
2497 BMA2X2_RANGE_SEL, 8);
2499 case BMA2X2_RANGE_16G:
2500 data1 = BMA2X2_SET_BITSLICE(data1,
2501 BMA2X2_RANGE_SEL, 12);
2504 comres += bma2x2_smbus_write_byte(client, BMA2X2_RANGE_SEL_REG,
2513 static int bma2x2_get_range(struct i2c_client *client, unsigned char *Range)
2518 comres = bma2x2_smbus_read_byte(client, BMA2X2_RANGE_SEL__REG, &data);
2519 data = BMA2X2_GET_BITSLICE(data, BMA2X2_RANGE_SEL);
2526 static int bma2x2_set_bandwidth(struct i2c_client *client, unsigned char BW)
2532 if (BW > 7 && BW < 16) {
2534 case BMA2X2_BW_7_81HZ:
2535 Bandwidth = BMA2X2_BW_7_81HZ;
2537 /* 7.81 Hz 64000 uS */
2539 case BMA2X2_BW_15_63HZ:
2540 Bandwidth = BMA2X2_BW_15_63HZ;
2542 /* 15.63 Hz 32000 uS */
2544 case BMA2X2_BW_31_25HZ:
2545 Bandwidth = BMA2X2_BW_31_25HZ;
2547 /* 31.25 Hz 16000 uS */
2549 case BMA2X2_BW_62_50HZ:
2550 Bandwidth = BMA2X2_BW_62_50HZ;
2552 /* 62.50 Hz 8000 uS */
2554 case BMA2X2_BW_125HZ:
2555 Bandwidth = BMA2X2_BW_125HZ;
2557 /* 125 Hz 4000 uS */
2559 case BMA2X2_BW_250HZ:
2560 Bandwidth = BMA2X2_BW_250HZ;
2562 /* 250 Hz 2000 uS */
2564 case BMA2X2_BW_500HZ:
2565 Bandwidth = BMA2X2_BW_500HZ;
2567 /* 500 Hz 1000 uS */
2569 case BMA2X2_BW_1000HZ:
2570 Bandwidth = BMA2X2_BW_1000HZ;
2572 /* 1000 Hz 500 uS */
2575 comres = bma2x2_smbus_read_byte(client, BMA2X2_BANDWIDTH__REG,
2577 data = BMA2X2_SET_BITSLICE(data, BMA2X2_BANDWIDTH, Bandwidth);
2578 comres += bma2x2_smbus_write_byte(client, BMA2X2_BANDWIDTH__REG,
2587 static int bma2x2_get_bandwidth(struct i2c_client *client, unsigned char *BW)
2592 comres = bma2x2_smbus_read_byte(client, BMA2X2_BANDWIDTH__REG, &data);
2593 data = BMA2X2_GET_BITSLICE(data, BMA2X2_BANDWIDTH);
2599 int bma2x2_get_sleep_duration(struct i2c_client *client, unsigned char
2605 comres = bma2x2_smbus_read_byte(client,
2606 BMA2X2_SLEEP_DUR__REG, &data);
2607 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLEEP_DUR);
2613 int bma2x2_set_sleep_duration(struct i2c_client *client, unsigned char
2618 int sleep_duration = 0;
2620 if (sleep_dur > 4 && sleep_dur < 16) {
2621 switch (sleep_dur) {
2622 case BMA2X2_SLEEP_DUR_0_5MS:
2623 sleep_duration = BMA2X2_SLEEP_DUR_0_5MS;
2627 case BMA2X2_SLEEP_DUR_1MS:
2628 sleep_duration = BMA2X2_SLEEP_DUR_1MS;
2632 case BMA2X2_SLEEP_DUR_2MS:
2633 sleep_duration = BMA2X2_SLEEP_DUR_2MS;
2637 case BMA2X2_SLEEP_DUR_4MS:
2638 sleep_duration = BMA2X2_SLEEP_DUR_4MS;
2642 case BMA2X2_SLEEP_DUR_6MS:
2643 sleep_duration = BMA2X2_SLEEP_DUR_6MS;
2647 case BMA2X2_SLEEP_DUR_10MS:
2648 sleep_duration = BMA2X2_SLEEP_DUR_10MS;
2652 case BMA2X2_SLEEP_DUR_25MS:
2653 sleep_duration = BMA2X2_SLEEP_DUR_25MS;
2657 case BMA2X2_SLEEP_DUR_50MS:
2658 sleep_duration = BMA2X2_SLEEP_DUR_50MS;
2662 case BMA2X2_SLEEP_DUR_100MS:
2663 sleep_duration = BMA2X2_SLEEP_DUR_100MS;
2667 case BMA2X2_SLEEP_DUR_500MS:
2668 sleep_duration = BMA2X2_SLEEP_DUR_500MS;
2672 case BMA2X2_SLEEP_DUR_1S:
2673 sleep_duration = BMA2X2_SLEEP_DUR_1S;
2678 comres = bma2x2_smbus_read_byte(client, BMA2X2_SLEEP_DUR__REG,
2680 data = BMA2X2_SET_BITSLICE(data, BMA2X2_SLEEP_DUR,
2682 comres = bma2x2_smbus_write_byte(client, BMA2X2_SLEEP_DUR__REG,
2692 static int bma2x2_get_fifo_mode(struct i2c_client *client, unsigned char
2698 comres = bma2x2_smbus_read_byte(client, BMA2X2_FIFO_MODE__REG, &data);
2699 *fifo_mode = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_MODE);
2704 static int bma2x2_set_fifo_mode(struct i2c_client *client, unsigned char
2710 if (fifo_mode < 4) {
2711 comres = bma2x2_smbus_read_byte(client, BMA2X2_FIFO_MODE__REG,
2713 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_MODE, fifo_mode);
2714 comres = bma2x2_smbus_write_byte(client, BMA2X2_FIFO_MODE__REG,
2724 static int bma2x2_get_fifo_trig(struct i2c_client *client, unsigned char
2730 comres = bma2x2_smbus_read_byte(client,
2731 BMA2X2_FIFO_TRIGGER_ACTION__REG, &data);
2732 *fifo_trig = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_TRIGGER_ACTION);
2737 static int bma2x2_set_fifo_trig(struct i2c_client *client, unsigned char
2743 if (fifo_trig < 4) {
2744 comres = bma2x2_smbus_read_byte(client,
2745 BMA2X2_FIFO_TRIGGER_ACTION__REG, &data);
2746 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_TRIGGER_ACTION,
2748 comres = bma2x2_smbus_write_byte(client,
2749 BMA2X2_FIFO_TRIGGER_ACTION__REG, &data);
2757 static int bma2x2_get_fifo_trig_src(struct i2c_client *client, unsigned char
2763 comres = bma2x2_smbus_read_byte(client,
2764 BMA2X2_FIFO_TRIGGER_SOURCE__REG, &data);
2765 *trig_src = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_TRIGGER_SOURCE);
2771 static int bma2x2_set_fifo_trig_src(struct i2c_client *client, unsigned char
2778 comres = bma2x2_smbus_read_byte(client,
2779 BMA2X2_FIFO_TRIGGER_SOURCE__REG, &data);
2780 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_TRIGGER_SOURCE,
2782 comres = bma2x2_smbus_write_byte(client,
2783 BMA2X2_FIFO_TRIGGER_SOURCE__REG, &data);
2791 static int bma2x2_get_fifo_framecount(struct i2c_client *client, unsigned char
2797 comres = bma2x2_smbus_read_byte(client,
2798 BMA2X2_FIFO_FRAME_COUNTER_S__REG, &data);
2799 *framecount = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_FRAME_COUNTER_S);
2804 static int bma2x2_get_fifo_data_sel(struct i2c_client *client, unsigned char
2810 comres = bma2x2_smbus_read_byte(client,
2811 BMA2X2_FIFO_DATA_SELECT__REG, &data);
2812 *data_sel = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_DATA_SELECT);
2817 static int bma2x2_set_fifo_data_sel(struct i2c_client *client, unsigned char
2824 comres = bma2x2_smbus_read_byte(client,
2825 BMA2X2_FIFO_DATA_SELECT__REG,
2827 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_DATA_SELECT,
2829 comres = bma2x2_smbus_write_byte(client,
2830 BMA2X2_FIFO_DATA_SELECT__REG,
2839 static int bma2x2_get_fifo_data_out_reg(struct i2c_client *client, unsigned char
2845 comres = bma2x2_smbus_read_byte(client,
2846 BMA2X2_FIFO_DATA_OUTPUT_REG, &data);
2852 static int bma2x2_get_offset_target(struct i2c_client *client, unsigned char
2853 channel, unsigned char *offset)
2859 case BMA2X2_CUT_OFF:
2860 comres = bma2x2_smbus_read_byte(client,
2861 BMA2X2_COMP_CUTOFF__REG, &data);
2862 *offset = BMA2X2_GET_BITSLICE(data, BMA2X2_COMP_CUTOFF);
2864 case BMA2X2_OFFSET_TRIGGER_X:
2865 comres = bma2x2_smbus_read_byte(client,
2866 BMA2X2_COMP_TARGET_OFFSET_X__REG, &data);
2867 *offset = BMA2X2_GET_BITSLICE(data,
2868 BMA2X2_COMP_TARGET_OFFSET_X);
2870 case BMA2X2_OFFSET_TRIGGER_Y:
2871 comres = bma2x2_smbus_read_byte(client,
2872 BMA2X2_COMP_TARGET_OFFSET_Y__REG, &data);
2873 *offset = BMA2X2_GET_BITSLICE(data,
2874 BMA2X2_COMP_TARGET_OFFSET_Y);
2876 case BMA2X2_OFFSET_TRIGGER_Z:
2877 comres = bma2x2_smbus_read_byte(client,
2878 BMA2X2_COMP_TARGET_OFFSET_Z__REG, &data);
2879 *offset = BMA2X2_GET_BITSLICE(data,
2880 BMA2X2_COMP_TARGET_OFFSET_Z);
2890 static int bma2x2_set_offset_target(struct i2c_client *client, unsigned char
2891 channel, unsigned char offset)
2897 case BMA2X2_CUT_OFF:
2898 comres = bma2x2_smbus_read_byte(client,
2899 BMA2X2_COMP_CUTOFF__REG, &data);
2900 data = BMA2X2_SET_BITSLICE(data, BMA2X2_COMP_CUTOFF,
2902 comres = bma2x2_smbus_write_byte(client,
2903 BMA2X2_COMP_CUTOFF__REG, &data);
2905 case BMA2X2_OFFSET_TRIGGER_X:
2906 comres = bma2x2_smbus_read_byte(client,
2907 BMA2X2_COMP_TARGET_OFFSET_X__REG,
2909 data = BMA2X2_SET_BITSLICE(data,
2910 BMA2X2_COMP_TARGET_OFFSET_X,
2912 comres = bma2x2_smbus_write_byte(client,
2913 BMA2X2_COMP_TARGET_OFFSET_X__REG,
2916 case BMA2X2_OFFSET_TRIGGER_Y:
2917 comres = bma2x2_smbus_read_byte(client,
2918 BMA2X2_COMP_TARGET_OFFSET_Y__REG,
2920 data = BMA2X2_SET_BITSLICE(data,
2921 BMA2X2_COMP_TARGET_OFFSET_Y,
2923 comres = bma2x2_smbus_write_byte(client,
2924 BMA2X2_COMP_TARGET_OFFSET_Y__REG,
2927 case BMA2X2_OFFSET_TRIGGER_Z:
2928 comres = bma2x2_smbus_read_byte(client,
2929 BMA2X2_COMP_TARGET_OFFSET_Z__REG,
2931 data = BMA2X2_SET_BITSLICE(data,
2932 BMA2X2_COMP_TARGET_OFFSET_Z,
2934 comres = bma2x2_smbus_write_byte(client,
2935 BMA2X2_COMP_TARGET_OFFSET_Z__REG,
2946 static int bma2x2_get_cal_ready(struct i2c_client *client, unsigned char *calrdy
2952 comres = bma2x2_smbus_read_byte(client, BMA2X2_FAST_CAL_RDY_S__REG,
2954 data = BMA2X2_GET_BITSLICE(data, BMA2X2_FAST_CAL_RDY_S);
2960 static int bma2x2_set_cal_trigger(struct i2c_client *client, unsigned char
2966 comres = bma2x2_smbus_read_byte(client, BMA2X2_CAL_TRIGGER__REG, &data);
2967 data = BMA2X2_SET_BITSLICE(data, BMA2X2_CAL_TRIGGER, caltrigger);
2968 comres = bma2x2_smbus_write_byte(client, BMA2X2_CAL_TRIGGER__REG,
2974 static int bma2x2_write_reg(struct i2c_client *client, unsigned char addr,
2975 unsigned char *data)
2978 comres = bma2x2_smbus_write_byte(client, addr, data);
2984 static int bma2x2_set_offset_x(struct i2c_client *client, unsigned char
2991 comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_X_AXIS_REG,
2998 static int bma2x2_get_offset_x(struct i2c_client *client, unsigned char
3004 comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_X_AXIS_REG,
3011 static int bma2x2_set_offset_y(struct i2c_client *client, unsigned char
3018 comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_Y_AXIS_REG,
3024 static int bma2x2_get_offset_y(struct i2c_client *client, unsigned char
3030 comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_Y_AXIS_REG,
3037 static int bma2x2_set_offset_z(struct i2c_client *client, unsigned char
3044 comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_Z_AXIS_REG,
3050 static int bma2x2_get_offset_z(struct i2c_client *client, unsigned char
3056 comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_Z_AXIS_REG,
3064 static int bma2x2_set_selftest_st(struct i2c_client *client, unsigned char
3070 comres = bma2x2_smbus_read_byte(client, BMA2X2_EN_SELF_TEST__REG,
3072 data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_SELF_TEST, selftest);
3073 comres = bma2x2_smbus_write_byte(client, BMA2X2_EN_SELF_TEST__REG,
3079 static int bma2x2_set_selftest_stn(struct i2c_client *client, unsigned char stn)
3084 comres = bma2x2_smbus_read_byte(client, BMA2X2_NEG_SELF_TEST__REG,
3086 data = BMA2X2_SET_BITSLICE(data, BMA2X2_NEG_SELF_TEST, stn);
3087 comres = bma2x2_smbus_write_byte(client, BMA2X2_NEG_SELF_TEST__REG,
3093 static int bma2x2_set_selftest_amp(struct i2c_client *client, unsigned char amp)
3098 comres = bma2x2_smbus_read_byte(client, BMA2X2_SELF_TEST_AMP__REG,
3100 data = BMA2X2_SET_BITSLICE(data, BMA2X2_SELF_TEST_AMP, amp);
3101 comres = bma2x2_smbus_write_byte(client, BMA2X2_SELF_TEST_AMP__REG,
3107 static int bma2x2_read_accel_x(struct i2c_client *client,
3108 signed char sensor_type, short *a_x)
3111 unsigned char data[2];
3113 switch (sensor_type) {
3115 comres = bma2x2_smbus_read_byte_block(client,
3116 BMA2X2_ACC_X12_LSB__REG, data, 2);
3117 *a_x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X12_LSB)|
3118 (BMA2X2_GET_BITSLICE(data[1],
3119 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X12_LSB__LEN));
3120 *a_x = *a_x << (sizeof(short)*8-(BMA2X2_ACC_X12_LSB__LEN
3121 + BMA2X2_ACC_X_MSB__LEN));
3122 *a_x = *a_x >> (sizeof(short)*8-(BMA2X2_ACC_X12_LSB__LEN
3123 + BMA2X2_ACC_X_MSB__LEN));
3126 comres = bma2x2_smbus_read_byte_block(client,
3127 BMA2X2_ACC_X10_LSB__REG, data, 2);
3128 *a_x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X10_LSB)|
3129 (BMA2X2_GET_BITSLICE(data[1],
3130 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X10_LSB__LEN));
3131 *a_x = *a_x << (sizeof(short)*8-(BMA2X2_ACC_X10_LSB__LEN
3132 + BMA2X2_ACC_X_MSB__LEN));
3133 *a_x = *a_x >> (sizeof(short)*8-(BMA2X2_ACC_X10_LSB__LEN
3134 + BMA2X2_ACC_X_MSB__LEN));
3137 comres = bma2x2_smbus_read_byte_block(client,
3138 BMA2X2_ACC_X8_LSB__REG, data, 2);
3139 *a_x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X8_LSB)|
3140 (BMA2X2_GET_BITSLICE(data[1],
3141 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X8_LSB__LEN));
3142 *a_x = *a_x << (sizeof(short)*8-(BMA2X2_ACC_X8_LSB__LEN
3143 + BMA2X2_ACC_X_MSB__LEN));
3144 *a_x = *a_x >> (sizeof(short)*8-(BMA2X2_ACC_X8_LSB__LEN
3145 + BMA2X2_ACC_X_MSB__LEN));
3148 comres = bma2x2_smbus_read_byte_block(client,
3149 BMA2X2_ACC_X14_LSB__REG, data, 2);
3150 *a_x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X14_LSB)|
3151 (BMA2X2_GET_BITSLICE(data[1],
3152 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X14_LSB__LEN));
3153 *a_x = *a_x << (sizeof(short)*8-(BMA2X2_ACC_X14_LSB__LEN
3154 + BMA2X2_ACC_X_MSB__LEN));
3155 *a_x = *a_x >> (sizeof(short)*8-(BMA2X2_ACC_X14_LSB__LEN
3156 + BMA2X2_ACC_X_MSB__LEN));
3165 static int bma2x2_soft_reset(struct i2c_client *client)
3168 unsigned char data = BMA2X2_EN_SOFT_RESET_VALUE ;
3170 comres = bma2x2_smbus_write_byte(client, BMA2X2_EN_SOFT_RESET__REG,
3176 static int bma2x2_read_accel_y(struct i2c_client *client,
3177 signed char sensor_type, short *a_y)
3180 unsigned char data[2];
3182 switch (sensor_type) {
3184 comres = bma2x2_smbus_read_byte_block(client,
3185 BMA2X2_ACC_Y12_LSB__REG, data, 2);
3186 *a_y = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Y12_LSB)|
3187 (BMA2X2_GET_BITSLICE(data[1],
3188 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y12_LSB__LEN));
3189 *a_y = *a_y << (sizeof(short)*8-(BMA2X2_ACC_Y12_LSB__LEN
3190 + BMA2X2_ACC_Y_MSB__LEN));
3191 *a_y = *a_y >> (sizeof(short)*8-(BMA2X2_ACC_Y12_LSB__LEN
3192 + BMA2X2_ACC_Y_MSB__LEN));
3195 comres = bma2x2_smbus_read_byte_block(client,
3196 BMA2X2_ACC_Y10_LSB__REG, data, 2);
3197 *a_y = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Y10_LSB)|
3198 (BMA2X2_GET_BITSLICE(data[1],
3199 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y10_LSB__LEN));
3200 *a_y = *a_y << (sizeof(short)*8-(BMA2X2_ACC_Y10_LSB__LEN
3201 + BMA2X2_ACC_Y_MSB__LEN));
3202 *a_y = *a_y >> (sizeof(short)*8-(BMA2X2_ACC_Y10_LSB__LEN
3203 + BMA2X2_ACC_Y_MSB__LEN));
3206 comres = bma2x2_smbus_read_byte_block(client,
3207 BMA2X2_ACC_Y8_LSB__REG, data, 2);
3208 *a_y = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Y8_LSB)|
3209 (BMA2X2_GET_BITSLICE(data[1],
3210 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y8_LSB__LEN));
3211 *a_y = *a_y << (sizeof(short)*8-(BMA2X2_ACC_Y8_LSB__LEN
3212 + BMA2X2_ACC_Y_MSB__LEN));
3213 *a_y = *a_y >> (sizeof(short)*8-(BMA2X2_ACC_Y8_LSB__LEN
3214 + BMA2X2_ACC_Y_MSB__LEN));
3217 comres = bma2x2_smbus_read_byte_block(client,
3218 BMA2X2_ACC_Y14_LSB__REG, data, 2);
3219 *a_y = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Y14_LSB)|
3220 (BMA2X2_GET_BITSLICE(data[1],
3221 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y14_LSB__LEN));
3222 *a_y = *a_y << (sizeof(short)*8-(BMA2X2_ACC_Y14_LSB__LEN
3223 + BMA2X2_ACC_Y_MSB__LEN));
3224 *a_y = *a_y >> (sizeof(short)*8-(BMA2X2_ACC_Y14_LSB__LEN
3225 + BMA2X2_ACC_Y_MSB__LEN));
3234 static int bma2x2_read_accel_z(struct i2c_client *client,
3235 signed char sensor_type, short *a_z)
3238 unsigned char data[2];
3240 switch (sensor_type) {
3242 comres = bma2x2_smbus_read_byte_block(client,
3243 BMA2X2_ACC_Z12_LSB__REG, data, 2);
3244 *a_z = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Z12_LSB)|
3245 (BMA2X2_GET_BITSLICE(data[1],
3246 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z12_LSB__LEN));
3247 *a_z = *a_z << (sizeof(short)*8-(BMA2X2_ACC_Z12_LSB__LEN
3248 + BMA2X2_ACC_Z_MSB__LEN));
3249 *a_z = *a_z >> (sizeof(short)*8-(BMA2X2_ACC_Z12_LSB__LEN
3250 + BMA2X2_ACC_Z_MSB__LEN));
3253 comres = bma2x2_smbus_read_byte_block(client,
3254 BMA2X2_ACC_Z10_LSB__REG, data, 2);
3255 *a_z = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Z10_LSB)|
3256 (BMA2X2_GET_BITSLICE(data[1],
3257 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z10_LSB__LEN));
3258 *a_z = *a_z << (sizeof(short)*8-(BMA2X2_ACC_Z10_LSB__LEN
3259 + BMA2X2_ACC_Z_MSB__LEN));
3260 *a_z = *a_z >> (sizeof(short)*8-(BMA2X2_ACC_Z10_LSB__LEN
3261 + BMA2X2_ACC_Z_MSB__LEN));
3264 comres = bma2x2_smbus_read_byte_block(client,
3265 BMA2X2_ACC_Z8_LSB__REG, data, 2);
3266 *a_z = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Z8_LSB)|
3267 (BMA2X2_GET_BITSLICE(data[1],
3268 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z8_LSB__LEN));
3269 *a_z = *a_z << (sizeof(short)*8-(BMA2X2_ACC_Z8_LSB__LEN
3270 + BMA2X2_ACC_Z_MSB__LEN));
3271 *a_z = *a_z >> (sizeof(short)*8-(BMA2X2_ACC_Z8_LSB__LEN
3272 + BMA2X2_ACC_Z_MSB__LEN));
3275 comres = bma2x2_smbus_read_byte_block(client,
3276 BMA2X2_ACC_Z14_LSB__REG, data, 2);
3277 *a_z = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_Z14_LSB)|
3278 (BMA2X2_GET_BITSLICE(data[1],
3279 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z14_LSB__LEN));
3280 *a_z = *a_z << (sizeof(short)*8-(BMA2X2_ACC_Z14_LSB__LEN
3281 + BMA2X2_ACC_Z_MSB__LEN));
3282 *a_z = *a_z >> (sizeof(short)*8-(BMA2X2_ACC_Z14_LSB__LEN
3283 + BMA2X2_ACC_Z_MSB__LEN));
3293 static int bma2x2_read_temperature(struct i2c_client *client,
3294 signed char *temperature)
3299 comres = bma2x2_smbus_read_byte(client, BMA2X2_TEMPERATURE_REG, &data);
3300 *temperature = (signed char)data;
3305 static int bma2x2_open_cal(struct i2c_client *client)
3307 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3311 mm_segment_t old_fs;
3312 struct file *cal_filp = NULL;
3317 cal_filp = filp_open(CALIBRATION_FILE_PATH,
3319 if (IS_ERR(cal_filp)) {
3320 pr_err("[BMC150] %s: Can't open calibration file\n",
3323 err = PTR_ERR(cal_filp);
3327 err = cal_filp->f_op->read(cal_filp,
3329 3 * sizeof(int), &cal_filp->f_pos);
3330 if (err != 3 * sizeof(int)) {
3331 pr_err("[BMC150] %s: Can't read the cal data from file\n",
3333 filp_close(cal_filp, current->files);
3338 printk(KERN_INFO "[BMC150] %s (%d,%d,%d)",__func__, cal_data[0],cal_data[1],cal_data[2]);
3340 bma2x2_set_offset_x(bma2x2->bma2x2_client, (unsigned char)cal_data[0]);
3341 bma2x2_set_offset_y(bma2x2->bma2x2_client, (unsigned char)cal_data[1]);
3342 bma2x2_set_offset_z(bma2x2->bma2x2_client, (unsigned char)cal_data[2]);
3347 static ssize_t bma2x2_enable_int_store(struct device *dev,
3348 struct device_attribute *attr,
3349 const char *buf, size_t count)
3352 struct i2c_client *client = to_i2c_client(dev);
3353 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3355 sscanf(buf, "%d%d", &type, &value);
3357 if (bma2x2_set_Int_Enable(bma2x2->bma2x2_client, type, value) < 0)
3364 static ssize_t bma2x2_int_mode_show(struct device *dev,
3365 struct device_attribute *attr, char *buf)
3368 struct i2c_client *client = to_i2c_client(dev);
3369 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3371 if (bma2x2_get_Int_Mode(bma2x2->bma2x2_client, &data) < 0)
3372 return sprintf(buf, "Read error\n");
3374 return sprintf(buf, "%d\n", data);
3377 static ssize_t bma2x2_int_mode_store(struct device *dev,
3378 struct device_attribute *attr,
3379 const char *buf, size_t count)
3383 struct i2c_client *client = to_i2c_client(dev);
3384 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3386 error = strict_strtoul(buf, 10, &data);
3390 if (bma2x2_set_Int_Mode(bma2x2->bma2x2_client, (unsigned char)data) < 0)
3395 static ssize_t bma2x2_slope_duration_show(struct device *dev,
3396 struct device_attribute *attr, char *buf)
3399 struct i2c_client *client = to_i2c_client(dev);
3400 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3402 if (bma2x2_get_slope_duration(bma2x2->bma2x2_client, &data) < 0)
3403 return sprintf(buf, "Read error\n");
3405 return sprintf(buf, "%d\n", data);
3409 static ssize_t bma2x2_slope_duration_store(struct device *dev,
3410 struct device_attribute *attr,
3411 const char *buf, size_t count)
3415 struct i2c_client *client = to_i2c_client(dev);
3416 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3418 error = strict_strtoul(buf, 10, &data);
3422 if (bma2x2_set_slope_duration(bma2x2->bma2x2_client, (unsigned
3429 static ssize_t bma2x2_slope_no_mot_duration_show(struct device *dev,
3430 struct device_attribute *attr, char *buf)
3433 struct i2c_client *client = to_i2c_client(dev);
3434 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3436 if (bma2x2_get_slope_no_mot_duration(bma2x2->bma2x2_client, &data) < 0)
3437 return sprintf(buf, "Read error\n");
3439 return sprintf(buf, "%d\n", data);
3443 static ssize_t bma2x2_slope_no_mot_duration_store(struct device *dev,
3444 struct device_attribute *attr,
3445 const char *buf, size_t count)
3449 struct i2c_client *client = to_i2c_client(dev);
3450 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3452 error = strict_strtoul(buf, 10, &data);
3456 if (bma2x2_set_slope_no_mot_duration(bma2x2->bma2x2_client, (unsigned
3464 static ssize_t bma2x2_slope_threshold_show(struct device *dev,
3465 struct device_attribute *attr, char *buf)
3468 struct i2c_client *client = to_i2c_client(dev);
3469 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3471 if (bma2x2_get_slope_threshold(bma2x2->bma2x2_client, &data) < 0)
3472 return sprintf(buf, "Read error\n");
3474 return sprintf(buf, "%d\n", data);
3478 static ssize_t bma2x2_slope_threshold_store(struct device *dev,
3479 struct device_attribute *attr,
3480 const char *buf, size_t count)
3484 struct i2c_client *client = to_i2c_client(dev);
3485 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3487 error = strict_strtoul(buf, 10, &data);
3490 if (bma2x2_set_slope_threshold(bma2x2->bma2x2_client, (unsigned
3497 static ssize_t bma2x2_slope_no_mot_threshold_show(struct device *dev,
3498 struct device_attribute *attr, char *buf)
3501 struct i2c_client *client = to_i2c_client(dev);
3502 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3504 if (bma2x2_get_slope_no_mot_threshold(bma2x2->bma2x2_client, &data) < 0)
3505 return sprintf(buf, "Read error\n");
3507 return sprintf(buf, "%d\n", data);
3511 static ssize_t bma2x2_slope_no_mot_threshold_store(struct device *dev,
3512 struct device_attribute *attr,
3513 const char *buf, size_t count)
3517 struct i2c_client *client = to_i2c_client(dev);
3518 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3520 error = strict_strtoul(buf, 10, &data);
3523 if (bma2x2_set_slope_no_mot_threshold(bma2x2->bma2x2_client, (unsigned
3530 static ssize_t bma2x2_high_g_duration_show(struct device *dev,
3531 struct device_attribute *attr, char *buf)
3534 struct i2c_client *client = to_i2c_client(dev);
3535 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3537 if (bma2x2_get_high_g_duration(bma2x2->bma2x2_client, &data) < 0)
3538 return sprintf(buf, "Read error\n");
3540 return sprintf(buf, "%d\n", data);
3544 static ssize_t bma2x2_high_g_duration_store(struct device *dev,
3545 struct device_attribute *attr,
3546 const char *buf, size_t count)
3550 struct i2c_client *client = to_i2c_client(dev);
3551 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3553 error = strict_strtoul(buf, 10, &data);
3557 if (bma2x2_set_high_g_duration(bma2x2->bma2x2_client, (unsigned
3564 static ssize_t bma2x2_high_g_threshold_show(struct device *dev,
3565 struct device_attribute *attr, char *buf)
3568 struct i2c_client *client = to_i2c_client(dev);
3569 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3571 if (bma2x2_get_high_g_threshold(bma2x2->bma2x2_client, &data) < 0)
3572 return sprintf(buf, "Read error\n");
3574 return sprintf(buf, "%d\n", data);
3578 static ssize_t bma2x2_high_g_threshold_store(struct device *dev,
3579 struct device_attribute *attr,
3580 const char *buf, size_t count)
3584 struct i2c_client *client = to_i2c_client(dev);
3585 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3587 error = strict_strtoul(buf, 10, &data);
3590 if (bma2x2_set_high_g_threshold(bma2x2->bma2x2_client, (unsigned
3597 static ssize_t bma2x2_low_g_duration_show(struct device *dev,
3598 struct device_attribute *attr, char *buf)
3601 struct i2c_client *client = to_i2c_client(dev);
3602 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3604 if (bma2x2_get_low_g_duration(bma2x2->bma2x2_client, &data) < 0)
3605 return sprintf(buf, "Read error\n");
3607 return sprintf(buf, "%d\n", data);
3611 static ssize_t bma2x2_low_g_duration_store(struct device *dev,
3612 struct device_attribute *attr,
3613 const char *buf, size_t count)
3617 struct i2c_client *client = to_i2c_client(dev);
3618 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3620 error = strict_strtoul(buf, 10, &data);
3624 if (bma2x2_set_low_g_duration(bma2x2->bma2x2_client, (unsigned
3631 static ssize_t bma2x2_low_g_threshold_show(struct device *dev,
3632 struct device_attribute *attr, char *buf)
3635 struct i2c_client *client = to_i2c_client(dev);
3636 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3638 if (bma2x2_get_low_g_threshold(bma2x2->bma2x2_client, &data) < 0)
3639 return sprintf(buf, "Read error\n");
3641 return sprintf(buf, "%d\n", data);
3645 static ssize_t bma2x2_low_g_threshold_store(struct device *dev,
3646 struct device_attribute *attr,
3647 const char *buf, size_t count)
3651 struct i2c_client *client = to_i2c_client(dev);
3652 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3654 error = strict_strtoul(buf, 10, &data);
3657 if (bma2x2_set_low_g_threshold(bma2x2->bma2x2_client, (unsigned
3663 static ssize_t bma2x2_tap_threshold_show(struct device *dev,
3664 struct device_attribute *attr, char *buf)
3667 struct i2c_client *client = to_i2c_client(dev);
3668 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3670 if (bma2x2_get_tap_threshold(bma2x2->bma2x2_client, &data) < 0)
3671 return sprintf(buf, "Read error\n");
3673 return sprintf(buf, "%d\n", data);
3677 static ssize_t bma2x2_tap_threshold_store(struct device *dev,
3678 struct device_attribute *attr,
3679 const char *buf, size_t count)
3683 struct i2c_client *client = to_i2c_client(dev);
3684 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3686 error = strict_strtoul(buf, 10, &data);
3689 if (bma2x2_set_tap_threshold(bma2x2->bma2x2_client, (unsigned char)data)
3695 static ssize_t bma2x2_tap_duration_show(struct device *dev,
3696 struct device_attribute *attr, char *buf)
3699 struct i2c_client *client = to_i2c_client(dev);
3700 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3702 if (bma2x2_get_tap_duration(bma2x2->bma2x2_client, &data) < 0)
3703 return sprintf(buf, "Read error\n");
3705 return sprintf(buf, "%d\n", data);
3709 static ssize_t bma2x2_tap_duration_store(struct device *dev,
3710 struct device_attribute *attr,
3711 const char *buf, size_t count)
3715 struct i2c_client *client = to_i2c_client(dev);
3716 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3718 error = strict_strtoul(buf, 10, &data);
3722 if (bma2x2_set_tap_duration(bma2x2->bma2x2_client, (unsigned char)data)
3728 static ssize_t bma2x2_tap_quiet_show(struct device *dev,
3729 struct device_attribute *attr, char *buf)
3732 struct i2c_client *client = to_i2c_client(dev);
3733 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3735 if (bma2x2_get_tap_quiet(bma2x2->bma2x2_client, &data) < 0)
3736 return sprintf(buf, "Read error\n");
3738 return sprintf(buf, "%d\n", data);
3742 static ssize_t bma2x2_tap_quiet_store(struct device *dev,
3743 struct device_attribute *attr,
3744 const char *buf, size_t count)
3748 struct i2c_client *client = to_i2c_client(dev);
3749 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3751 error = strict_strtoul(buf, 10, &data);
3755 if (bma2x2_set_tap_quiet(bma2x2->bma2x2_client, (unsigned char)data) <
3762 static ssize_t bma2x2_tap_shock_show(struct device *dev,
3763 struct device_attribute *attr, char *buf)
3766 struct i2c_client *client = to_i2c_client(dev);
3767 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3769 if (bma2x2_get_tap_shock(bma2x2->bma2x2_client, &data) < 0)
3770 return sprintf(buf, "Read error\n");
3772 return sprintf(buf, "%d\n", data);
3776 static ssize_t bma2x2_tap_shock_store(struct device *dev,
3777 struct device_attribute *attr,
3778 const char *buf, size_t count)
3782 struct i2c_client *client = to_i2c_client(dev);
3783 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3785 error = strict_strtoul(buf, 10, &data);
3789 if (bma2x2_set_tap_shock(bma2x2->bma2x2_client, (unsigned char)data) <
3796 static ssize_t bma2x2_tap_samp_show(struct device *dev,
3797 struct device_attribute *attr, char *buf)
3800 struct i2c_client *client = to_i2c_client(dev);
3801 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3803 if (bma2x2_get_tap_samp(bma2x2->bma2x2_client, &data) < 0)
3804 return sprintf(buf, "Read error\n");
3806 return sprintf(buf, "%d\n", data);
3810 static ssize_t bma2x2_tap_samp_store(struct device *dev,
3811 struct device_attribute *attr,
3812 const char *buf, size_t count)
3816 struct i2c_client *client = to_i2c_client(dev);
3817 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3819 error = strict_strtoul(buf, 10, &data);
3823 if (bma2x2_set_tap_samp(bma2x2->bma2x2_client, (unsigned char)data) < 0)
3829 static ssize_t bma2x2_orient_mode_show(struct device *dev,
3830 struct device_attribute *attr, char *buf)
3833 struct i2c_client *client = to_i2c_client(dev);
3834 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3836 if (bma2x2_get_orient_mode(bma2x2->bma2x2_client, &data) < 0)
3837 return sprintf(buf, "Read error\n");
3839 return sprintf(buf, "%d\n", data);
3843 static ssize_t bma2x2_orient_mode_store(struct device *dev,
3844 struct device_attribute *attr,
3845 const char *buf, size_t count)
3849 struct i2c_client *client = to_i2c_client(dev);
3850 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3852 error = strict_strtoul(buf, 10, &data);
3856 if (bma2x2_set_orient_mode(bma2x2->bma2x2_client, (unsigned char)data) <
3863 static ssize_t bma2x2_orient_blocking_show(struct device *dev,
3864 struct device_attribute *attr, char *buf)
3867 struct i2c_client *client = to_i2c_client(dev);
3868 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3870 if (bma2x2_get_orient_blocking(bma2x2->bma2x2_client, &data) < 0)
3871 return sprintf(buf, "Read error\n");
3873 return sprintf(buf, "%d\n", data);
3877 static ssize_t bma2x2_orient_blocking_store(struct device *dev,
3878 struct device_attribute *attr,
3879 const char *buf, size_t count)
3883 struct i2c_client *client = to_i2c_client(dev);
3884 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3886 error = strict_strtoul(buf, 10, &data);
3890 if (bma2x2_set_orient_blocking(bma2x2->bma2x2_client, (unsigned
3896 static ssize_t bma2x2_orient_hyst_show(struct device *dev,
3897 struct device_attribute *attr, char *buf)
3900 struct i2c_client *client = to_i2c_client(dev);
3901 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3903 if (bma2x2_get_orient_hyst(bma2x2->bma2x2_client, &data) < 0)
3904 return sprintf(buf, "Read error\n");
3906 return sprintf(buf, "%d\n", data);
3910 static ssize_t bma2x2_orient_hyst_store(struct device *dev,
3911 struct device_attribute *attr,
3912 const char *buf, size_t count)
3916 struct i2c_client *client = to_i2c_client(dev);
3917 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3919 error = strict_strtoul(buf, 10, &data);
3923 if (bma2x2_set_orient_hyst(bma2x2->bma2x2_client, (unsigned char)data) <
3930 static ssize_t bma2x2_orient_theta_show(struct device *dev,
3931 struct device_attribute *attr, char *buf)
3934 struct i2c_client *client = to_i2c_client(dev);
3935 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3937 if (bma2x2_get_theta_blocking(bma2x2->bma2x2_client, &data) < 0)
3938 return sprintf(buf, "Read error\n");
3940 return sprintf(buf, "%d\n", data);
3944 static ssize_t bma2x2_orient_theta_store(struct device *dev,
3945 struct device_attribute *attr,
3946 const char *buf, size_t count)
3950 struct i2c_client *client = to_i2c_client(dev);
3951 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3953 error = strict_strtoul(buf, 10, &data);
3957 if (bma2x2_set_theta_blocking(bma2x2->bma2x2_client, (unsigned
3964 static ssize_t bma2x2_flat_theta_show(struct device *dev,
3965 struct device_attribute *attr, char *buf)
3968 struct i2c_client *client = to_i2c_client(dev);
3969 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3971 if (bma2x2_get_theta_flat(bma2x2->bma2x2_client, &data) < 0)
3972 return sprintf(buf, "Read error\n");
3974 return sprintf(buf, "%d\n", data);
3978 static ssize_t bma2x2_flat_theta_store(struct device *dev,
3979 struct device_attribute *attr,
3980 const char *buf, size_t count)
3984 struct i2c_client *client = to_i2c_client(dev);
3985 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3987 error = strict_strtoul(buf, 10, &data);
3991 if (bma2x2_set_theta_flat(bma2x2->bma2x2_client, (unsigned char)data) <
3997 static ssize_t bma2x2_flat_hold_time_show(struct device *dev,
3998 struct device_attribute *attr, char *buf)
4001 struct i2c_client *client = to_i2c_client(dev);
4002 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4004 if (bma2x2_get_flat_hold_time(bma2x2->bma2x2_client, &data) < 0)
4005 return sprintf(buf, "Read error\n");
4007 return sprintf(buf, "%d\n", data);
4010 static ssize_t bma2x2_selftest_show(struct device *dev,
4011 struct device_attribute *attr, char *buf)
4015 struct i2c_client *client = to_i2c_client(dev);
4016 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4018 return sprintf(buf, "%d\n", atomic_read(&bma2x2->selftest_result));
4022 static ssize_t bma2x2_softreset_store(struct device *dev,
4023 struct device_attribute *attr,
4024 const char *buf, size_t count)
4026 struct i2c_client *client = to_i2c_client(dev);
4027 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4029 if (bma2x2_soft_reset(bma2x2->bma2x2_client) < 0)
4034 static ssize_t bma2x2_selftest_store(struct device *dev,
4035 struct device_attribute *attr,
4036 const char *buf, size_t count)
4040 unsigned char clear_value = 0;
4045 unsigned long result = 0;
4046 struct i2c_client *client = to_i2c_client(dev);
4047 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4049 bma2x2_soft_reset(bma2x2->bma2x2_client);
4052 error = strict_strtoul(buf, 10, &data);
4059 bma2x2_write_reg(bma2x2->bma2x2_client, 0x32, &clear_value);
4061 if ((bma2x2->sensor_type == BMA280_TYPE) ||
4062 (bma2x2->sensor_type == BMA255_TYPE)) {
4063 /* set to 4 G range */
4064 if (bma2x2_set_range(bma2x2->bma2x2_client, 5) < 0)
4068 if ((bma2x2->sensor_type == BMA250E_TYPE) ||
4069 (bma2x2->sensor_type == BMA222E_TYPE)) {
4070 /* set to 8 G range */
4071 if (bma2x2_set_range(bma2x2->bma2x2_client, 8) < 0)
4073 if (bma2x2_set_selftest_amp(bma2x2->bma2x2_client, 1) < 0)
4077 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 1); /* 1 for x-axis*/
4078 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4081 bma2x2_read_accel_x(bma2x2->bma2x2_client,
4082 bma2x2->sensor_type, &value1);
4083 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4086 bma2x2_read_accel_x(bma2x2->bma2x2_client,
4087 bma2x2->sensor_type, &value2);
4088 diff = value1-value2;
4090 printk(KERN_INFO "diff x is %d,value1 is %d, value2 is %d\n", diff,
4093 if (bma2x2->sensor_type == BMA280_TYPE) {
4094 if (abs(diff) < 1638)
4097 if (bma2x2->sensor_type == BMA255_TYPE) {
4098 if (abs(diff) < 409)
4101 if (bma2x2->sensor_type == BMA250E_TYPE) {
4105 if (bma2x2->sensor_type == BMA222E_TYPE) {
4110 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 2); /* 2 for y-axis*/
4111 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4114 bma2x2_read_accel_y(bma2x2->bma2x2_client,
4115 bma2x2->sensor_type, &value1);
4116 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4119 bma2x2_read_accel_y(bma2x2->bma2x2_client,
4120 bma2x2->sensor_type, &value2);
4121 diff = value1-value2;
4122 printk(KERN_INFO "diff y is %d,value1 is %d, value2 is %d\n", diff,
4125 if (bma2x2->sensor_type == BMA280_TYPE) {
4126 if (abs(diff) < 1638)
4129 if (bma2x2->sensor_type == BMA255_TYPE) {
4130 if (abs(diff) < 409)
4133 if (bma2x2->sensor_type == BMA250E_TYPE) {
4137 if (bma2x2->sensor_type == BMA222E_TYPE) {
4143 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 3); /* 3 for z-axis*/
4144 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4147 bma2x2_read_accel_z(bma2x2->bma2x2_client,
4148 bma2x2->sensor_type, &value1);
4149 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4152 bma2x2_read_accel_z(bma2x2->bma2x2_client,
4153 bma2x2->sensor_type, &value2);
4154 diff = value1-value2;
4156 printk(KERN_INFO "diff z is %d,value1 is %d, value2 is %d\n", diff,
4159 if (bma2x2->sensor_type == BMA280_TYPE) {
4160 if (abs(diff) < 819)
4163 if (bma2x2->sensor_type == BMA255_TYPE) {
4164 if (abs(diff) < 204)
4167 if (bma2x2->sensor_type == BMA250E_TYPE) {
4171 if (bma2x2->sensor_type == BMA222E_TYPE) {
4176 /* self test for bma254 */
4177 if ((bma2x2->sensor_type == BMA255_TYPE) && (result > 0)) {
4179 bma2x2_soft_reset(bma2x2->bma2x2_client);
4181 bma2x2_write_reg(bma2x2->bma2x2_client, 0x32, &clear_value);
4182 /* set to 8 G range */
4183 if (bma2x2_set_range(bma2x2->bma2x2_client, 8) < 0)
4185 if (bma2x2_set_selftest_amp(bma2x2->bma2x2_client, 1) < 0)
4188 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 1); /* 1
4190 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4191 positive direction*/
4193 bma2x2_read_accel_x(bma2x2->bma2x2_client,
4194 bma2x2->sensor_type, &value1);
4195 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /*
4196 negative direction*/
4198 bma2x2_read_accel_x(bma2x2->bma2x2_client,
4199 bma2x2->sensor_type, &value2);
4200 diff = value1-value2;
4202 printk(KERN_INFO "diff x is %d,value1 is %d, value2 is %d\n",
4203 diff, value1, value2);
4204 if (abs(diff) < 204)
4207 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 2); /* 2
4209 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4210 positive direction*/
4212 bma2x2_read_accel_y(bma2x2->bma2x2_client,
4213 bma2x2->sensor_type, &value1);
4214 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /*
4215 negative direction*/
4217 bma2x2_read_accel_y(bma2x2->bma2x2_client,
4218 bma2x2->sensor_type, &value2);
4219 diff = value1-value2;
4220 printk(KERN_INFO "diff y is %d,value1 is %d, value2 is %d\n",
4221 diff, value1, value2);
4223 if (abs(diff) < 204)
4226 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 3); /* 3
4228 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4229 positive direction*/
4231 bma2x2_read_accel_z(bma2x2->bma2x2_client,
4232 bma2x2->sensor_type, &value1);
4233 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /*
4234 negative direction*/
4236 bma2x2_read_accel_z(bma2x2->bma2x2_client,
4237 bma2x2->sensor_type, &value2);
4238 diff = value1-value2;
4240 printk(KERN_INFO "diff z is %d,value1 is %d, value2 is %d\n",
4241 diff, value1, value2);
4242 if (abs(diff) < 102)
4246 atomic_set(&bma2x2->selftest_result, (unsigned int)result);
4248 bma2x2_soft_reset(bma2x2->bma2x2_client);
4250 printk(KERN_INFO "self test finished\n");
4257 static ssize_t bma2x2_flat_hold_time_store(struct device *dev,
4258 struct device_attribute *attr,
4259 const char *buf, size_t count)
4263 struct i2c_client *client = to_i2c_client(dev);
4264 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4266 error = strict_strtoul(buf, 10, &data);
4270 if (bma2x2_set_flat_hold_time(bma2x2->bma2x2_client, (unsigned
4279 static int bma2x2_read_accel_xyz(struct i2c_client *client,
4280 signed char sensor_type, struct bma2x2acc *acc)
4283 unsigned char data[6];
4284 struct bma2x2_data *client_data = i2c_get_clientdata(client);
4286 #ifdef BMA2X2_SENSOR_IDENTIFICATION_ENABLE
4287 comres = bma2x2_smbus_read_byte_block(client,
4288 BMA2X2_ACC_X12_LSB__REG, data, 6);
4289 acc->x = (data[1]<<8)|data[0];
4290 acc->y = (data[3]<<8)|data[2];
4291 acc->z = (data[5]<<8)|data[4];
4294 switch (sensor_type) {
4296 comres = bma2x2_smbus_read_byte_block(client,
4297 BMA2X2_ACC_X12_LSB__REG, data, 6);
4298 acc->x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X12_LSB)|
4299 (BMA2X2_GET_BITSLICE(data[1],
4300 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X12_LSB__LEN));
4301 acc->x = acc->x << (sizeof(short)*8-(BMA2X2_ACC_X12_LSB__LEN +
4302 BMA2X2_ACC_X_MSB__LEN));
4303 acc->x = acc->x >> (sizeof(short)*8-(BMA2X2_ACC_X12_LSB__LEN +
4304 BMA2X2_ACC_X_MSB__LEN));
4306 acc->y = BMA2X2_GET_BITSLICE(data[2], BMA2X2_ACC_Y12_LSB)|
4307 (BMA2X2_GET_BITSLICE(data[3],
4308 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y12_LSB__LEN
4310 acc->y = acc->y << (sizeof(short)*8-(BMA2X2_ACC_Y12_LSB__LEN +
4311 BMA2X2_ACC_Y_MSB__LEN));
4312 acc->y = acc->y >> (sizeof(short)*8-(BMA2X2_ACC_Y12_LSB__LEN +
4313 BMA2X2_ACC_Y_MSB__LEN));
4315 acc->z = BMA2X2_GET_BITSLICE(data[4], BMA2X2_ACC_Z12_LSB)|
4316 (BMA2X2_GET_BITSLICE(data[5],
4317 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z12_LSB__LEN));
4318 acc->z = acc->z << (sizeof(short)*8-(BMA2X2_ACC_Z12_LSB__LEN +
4319 BMA2X2_ACC_Z_MSB__LEN));
4320 acc->z = acc->z >> (sizeof(short)*8-(BMA2X2_ACC_Z12_LSB__LEN +
4321 BMA2X2_ACC_Z_MSB__LEN));
4324 comres = bma2x2_smbus_read_byte_block(client,
4325 BMA2X2_ACC_X10_LSB__REG, data, 6);
4326 acc->x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X10_LSB)|
4327 (BMA2X2_GET_BITSLICE(data[1],
4328 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X10_LSB__LEN));
4329 acc->x = acc->x << (sizeof(short)*8-(BMA2X2_ACC_X10_LSB__LEN +
4330 BMA2X2_ACC_X_MSB__LEN));
4331 acc->x = acc->x >> (sizeof(short)*8-(BMA2X2_ACC_X10_LSB__LEN +
4332 BMA2X2_ACC_X_MSB__LEN));
4334 acc->y = BMA2X2_GET_BITSLICE(data[2], BMA2X2_ACC_Y10_LSB)|
4335 (BMA2X2_GET_BITSLICE(data[3],
4336 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y10_LSB__LEN
4338 acc->y = acc->y << (sizeof(short)*8-(BMA2X2_ACC_Y10_LSB__LEN +
4339 BMA2X2_ACC_Y_MSB__LEN));
4340 acc->y = acc->y >> (sizeof(short)*8-(BMA2X2_ACC_Y10_LSB__LEN +
4341 BMA2X2_ACC_Y_MSB__LEN));
4343 acc->z = BMA2X2_GET_BITSLICE(data[4], BMA2X2_ACC_Z10_LSB)|
4344 (BMA2X2_GET_BITSLICE(data[5],
4345 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z10_LSB__LEN));
4346 acc->z = acc->z << (sizeof(short)*8-(BMA2X2_ACC_Z10_LSB__LEN +
4347 BMA2X2_ACC_Z_MSB__LEN));
4348 acc->z = acc->z >> (sizeof(short)*8-(BMA2X2_ACC_Z10_LSB__LEN +
4349 BMA2X2_ACC_Z_MSB__LEN));
4352 comres = bma2x2_smbus_read_byte_block(client,
4353 BMA2X2_ACC_X8_LSB__REG, data, 6);
4354 acc->x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X8_LSB)|
4355 (BMA2X2_GET_BITSLICE(data[1],
4356 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X8_LSB__LEN));
4357 acc->x = acc->x << (sizeof(short)*8-(BMA2X2_ACC_X8_LSB__LEN +
4358 BMA2X2_ACC_X_MSB__LEN));
4359 acc->x = acc->x >> (sizeof(short)*8-(BMA2X2_ACC_X8_LSB__LEN +
4360 BMA2X2_ACC_X_MSB__LEN));
4362 acc->y = BMA2X2_GET_BITSLICE(data[2], BMA2X2_ACC_Y8_LSB)|
4363 (BMA2X2_GET_BITSLICE(data[3],
4364 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y8_LSB__LEN
4366 acc->y = acc->y << (sizeof(short)*8-(BMA2X2_ACC_Y8_LSB__LEN +
4367 BMA2X2_ACC_Y_MSB__LEN));
4368 acc->y = acc->y >> (sizeof(short)*8-(BMA2X2_ACC_Y8_LSB__LEN +
4369 BMA2X2_ACC_Y_MSB__LEN));
4371 acc->z = BMA2X2_GET_BITSLICE(data[4], BMA2X2_ACC_Z8_LSB)|
4372 (BMA2X2_GET_BITSLICE(data[5],
4373 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z8_LSB__LEN));
4374 acc->z = acc->z << (sizeof(short)*8-(BMA2X2_ACC_Z8_LSB__LEN +
4375 BMA2X2_ACC_Z_MSB__LEN));
4376 acc->z = acc->z >> (sizeof(short)*8-(BMA2X2_ACC_Z8_LSB__LEN +
4377 BMA2X2_ACC_Z_MSB__LEN));
4380 comres = bma2x2_smbus_read_byte_block(client,
4381 BMA2X2_ACC_X14_LSB__REG, data, 6);
4382 acc->x = BMA2X2_GET_BITSLICE(data[0], BMA2X2_ACC_X14_LSB)|
4383 (BMA2X2_GET_BITSLICE(data[1],
4384 BMA2X2_ACC_X_MSB)<<(BMA2X2_ACC_X14_LSB__LEN));
4385 acc->x = acc->x << (sizeof(short)*8-(BMA2X2_ACC_X14_LSB__LEN +
4386 BMA2X2_ACC_X_MSB__LEN));
4387 acc->x = acc->x >> (sizeof(short)*8-(BMA2X2_ACC_X14_LSB__LEN +
4388 BMA2X2_ACC_X_MSB__LEN));
4390 acc->y = BMA2X2_GET_BITSLICE(data[2], BMA2X2_ACC_Y14_LSB)|
4391 (BMA2X2_GET_BITSLICE(data[3],
4392 BMA2X2_ACC_Y_MSB)<<(BMA2X2_ACC_Y14_LSB__LEN
4394 acc->y = acc->y << (sizeof(short)*8-(BMA2X2_ACC_Y14_LSB__LEN +
4395 BMA2X2_ACC_Y_MSB__LEN));
4396 acc->y = acc->y >> (sizeof(short)*8-(BMA2X2_ACC_Y14_LSB__LEN +
4397 BMA2X2_ACC_Y_MSB__LEN));
4399 acc->z = BMA2X2_GET_BITSLICE(data[4], BMA2X2_ACC_Z14_LSB)|
4400 (BMA2X2_GET_BITSLICE(data[5],
4401 BMA2X2_ACC_Z_MSB)<<(BMA2X2_ACC_Z14_LSB__LEN));
4402 acc->z = acc->z << (sizeof(short)*8-(BMA2X2_ACC_Z14_LSB__LEN +
4403 BMA2X2_ACC_Z_MSB__LEN));
4404 acc->z = acc->z >> (sizeof(short)*8-(BMA2X2_ACC_Z14_LSB__LEN +
4405 BMA2X2_ACC_Z_MSB__LEN));
4412 bma2x2_remap_sensor_data(acc, client_data);
4416 static void bma2x2_work_func(struct work_struct *work)
4418 struct bma2x2_data *bma2x2 = container_of((struct delayed_work *)work,
4419 struct bma2x2_data, work);
4420 static struct bma2x2acc acc;
4421 unsigned long delay = msecs_to_jiffies(atomic_read(&bma2x2->delay));
4423 bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4425 input_report_abs(bma2x2->input, ABS_X, acc.x);
4426 input_report_abs(bma2x2->input, ABS_Y, acc.y);
4427 input_report_abs(bma2x2->input, ABS_Z, acc.z);
4428 input_sync(bma2x2->input);
4430 mutex_lock(&bma2x2->value_mutex);
4431 bma2x2->value.x = acc.x;
4432 bma2x2->value.y = acc.y;
4433 bma2x2->value.z = acc.z;
4434 mutex_unlock(&bma2x2->value_mutex);
4436 schedule_delayed_work(&bma2x2->work, delay);
4440 static ssize_t bma2x2_register_store(struct device *dev,
4441 struct device_attribute *attr,
4442 const char *buf, size_t count)
4445 struct i2c_client *client = to_i2c_client(dev);
4446 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4448 sscanf(buf, "%d%d", &address, &value);
4449 if (bma2x2_write_reg(bma2x2->bma2x2_client, (unsigned char)address,
4450 (unsigned char *)&value) < 0)
4454 static ssize_t bma2x2_register_show(struct device *dev,
4455 struct device_attribute *attr, char *buf)
4458 struct i2c_client *client = to_i2c_client(dev);
4459 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4465 for (i = 0; i < 0x40; i++) {
4466 bma2x2_smbus_read_byte(bma2x2->bma2x2_client, i, reg+i);
4468 count += sprintf(&buf[count], "0x%x: %d\n", i, reg[i]);
4475 static ssize_t bma2x2_range_show(struct device *dev,
4476 struct device_attribute *attr, char *buf)
4479 struct i2c_client *client = to_i2c_client(dev);
4480 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4482 if (bma2x2_get_range(bma2x2->bma2x2_client, &data) < 0)
4483 return sprintf(buf, "Read error\n");
4485 return sprintf(buf, "%d\n", data);
4488 static ssize_t bma2x2_range_store(struct device *dev,
4489 struct device_attribute *attr,
4490 const char *buf, size_t count)
4494 struct i2c_client *client = to_i2c_client(dev);
4495 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4497 error = strict_strtoul(buf, 10, &data);
4500 if (bma2x2_set_range(bma2x2->bma2x2_client, (unsigned char) data) < 0)
4506 static ssize_t bma2x2_bandwidth_show(struct device *dev,
4507 struct device_attribute *attr, char *buf)
4510 struct i2c_client *client = to_i2c_client(dev);
4511 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4513 if (bma2x2_get_bandwidth(bma2x2->bma2x2_client, &data) < 0)
4514 return sprintf(buf, "Read error\n");
4516 return sprintf(buf, "%d\n", data);
4520 static ssize_t bma2x2_bandwidth_store(struct device *dev,
4521 struct device_attribute *attr,
4522 const char *buf, size_t count)
4526 struct i2c_client *client = to_i2c_client(dev);
4527 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4529 error = strict_strtoul(buf, 10, &data);
4533 if (bma2x2->sensor_type == BMA280_TYPE)
4534 if ((unsigned char) data > 14)
4537 if (bma2x2_set_bandwidth(bma2x2->bma2x2_client,
4538 (unsigned char) data) < 0)
4544 static ssize_t bma2x2_mode_show(struct device *dev,
4545 struct device_attribute *attr, char *buf)
4548 struct i2c_client *client = to_i2c_client(dev);
4549 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4551 if (bma2x2_get_mode(bma2x2->bma2x2_client, &data) < 0)
4552 return sprintf(buf, "Read error\n");
4554 return sprintf(buf, "%d\n", data);
4557 static ssize_t bma2x2_mode_store(struct device *dev,
4558 struct device_attribute *attr,
4559 const char *buf, size_t count)
4563 struct i2c_client *client = to_i2c_client(dev);
4564 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4566 error = strict_strtoul(buf, 10, &data);
4569 if (bma2x2_set_mode(bma2x2->bma2x2_client, (unsigned char) data) < 0)
4574 static ssize_t bma2x2_value_show(struct device *dev,
4575 struct device_attribute *attr, char *buf)
4577 struct input_dev *input = to_input_dev(dev);
4578 struct bma2x2_data *bma2x2 = input_get_drvdata(input);
4579 struct bma2x2acc acc_value;
4582 bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4585 /* cache of last input event */
4586 mutex_lock(&bma2x2->value_mutex);
4587 acc_value.x = bma2x2->value.x;
4588 acc_value.y = bma2x2->value.y;
4589 acc_value.z = bma2x2->value.z;
4590 mutex_unlock(&bma2x2->value_mutex);
4593 return sprintf(buf, "%d %d %d\n", acc_value.x, acc_value.y,
4597 /* raw-data for sensor test */
4598 static ssize_t bma2x2_raw_data_show(struct device *dev,
4599 struct device_attribute *attr, char *buf)
4601 struct input_dev *input = to_input_dev(dev);
4602 struct bma2x2_data *bma2x2 = input_get_drvdata(input);
4603 struct bma2x2acc acc_value;
4605 bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4608 /* cache of last input event */
4609 mutex_lock(&bma2x2->value_mutex);
4610 acc_value.x = bma2x2->value.x;
4611 acc_value.y = bma2x2->value.y;
4612 acc_value.z = bma2x2->value.z;
4613 mutex_unlock(&bma2x2->value_mutex);
4617 acc_value.x = acc_value.x >>4;
4618 acc_value.y = acc_value.y >>4;
4619 acc_value.z = acc_value.z >>4;
4621 return sprintf(buf, "%d,%d,%d\n", acc_value.x, acc_value.y,
4625 static ssize_t bma2x2_delay_show(struct device *dev,
4626 struct device_attribute *attr, char *buf)
4628 struct i2c_client *client = to_i2c_client(dev);
4629 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4631 return sprintf(buf, "%d\n", atomic_read(&bma2x2->delay));
4635 static ssize_t bma2x2_chip_id_show(struct device *dev,
4636 struct device_attribute *attr, char *buf)
4638 struct i2c_client *client = to_i2c_client(dev);
4639 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4641 return sprintf(buf, "%d\n", bma2x2->chip_id);
4646 static ssize_t bma2x2_place_show(struct device *dev,
4647 struct device_attribute *attr, char *buf)
4649 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
4650 struct i2c_client *client = to_i2c_client(dev);
4651 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4653 int place = BOSCH_SENSOR_PLACE_UNKNOWN;
4655 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
4656 if (NULL != bma2x2->bst_pd)
4657 place = bma2x2->bst_pd->place;
4660 return sprintf(buf, "%d\n", place);
4664 static ssize_t bma2x2_delay_store(struct device *dev,
4665 struct device_attribute *attr,
4666 const char *buf, size_t count)
4670 struct i2c_client *client = to_i2c_client(dev);
4671 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4673 error = strict_strtoul(buf, 10, &data);
4676 if (data > BMA2X2_MAX_DELAY)
4677 data = BMA2X2_MAX_DELAY;
4678 atomic_set(&bma2x2->delay, (unsigned int) data);
4684 static ssize_t bma2x2_enable_show(struct device *dev,
4685 struct device_attribute *attr, char *buf)
4687 struct i2c_client *client = to_i2c_client(dev);
4688 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4690 return sprintf(buf, "%d\n", atomic_read(&bma2x2->enable));
4694 static void bma2x2_set_enable(struct device *dev, int enable)
4696 struct i2c_client *client = to_i2c_client(dev);
4697 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4698 int pre_enable = atomic_read(&bma2x2->enable);
4700 mutex_lock(&bma2x2->enable_mutex);
4702 if (pre_enable == 0) {
4703 bma2x2_set_mode(bma2x2->bma2x2_client,
4704 BMA2X2_MODE_NORMAL);
4705 schedule_delayed_work(&bma2x2->work,
4706 msecs_to_jiffies(atomic_read(&bma2x2->delay)));
4707 atomic_set(&bma2x2->enable, 1);
4711 if (pre_enable == 1) {
4712 bma2x2_set_mode(bma2x2->bma2x2_client,
4713 BMA2X2_MODE_SUSPEND);
4714 cancel_delayed_work_sync(&bma2x2->work);
4715 atomic_set(&bma2x2->enable, 0);
4718 mutex_unlock(&bma2x2->enable_mutex);
4722 static ssize_t bma2x2_enable_store(struct device *dev,
4723 struct device_attribute *attr,
4724 const char *buf, size_t count)
4729 error = strict_strtoul(buf, 10, &data);
4732 if ((data == 0) || (data == 1))
4733 bma2x2_set_enable(dev, data);
4738 static ssize_t bma2x2_fast_calibration_x_show(struct device *dev,
4739 struct device_attribute *attr, char *buf)
4744 struct i2c_client *client = to_i2c_client(dev);
4745 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4747 if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 1, &data) < 0)
4748 return sprintf(buf, "Read error\n");
4750 return sprintf(buf, "%d\n", data);
4754 static ssize_t bma2x2_fast_calibration_x_store(struct device *dev,
4755 struct device_attribute *attr,
4756 const char *buf, size_t count)
4760 unsigned char timeout = 0;
4762 struct i2c_client *client = to_i2c_client(dev);
4763 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4765 error = strict_strtoul(buf, 10, &data);
4769 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 1, (unsigned
4773 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 1) < 0)
4778 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4780 /* printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4783 if (timeout == 50) {
4784 printk(KERN_INFO "get fast calibration ready error\n");
4790 printk(KERN_INFO "x axis fast calibration finished\n");
4794 static ssize_t bma2x2_fast_calibration_y_show(struct device *dev,
4795 struct device_attribute *attr, char *buf)
4800 struct i2c_client *client = to_i2c_client(dev);
4801 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4803 if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 2, &data) < 0)
4804 return sprintf(buf, "Read error\n");
4806 return sprintf(buf, "%d\n", data);
4810 static ssize_t bma2x2_fast_calibration_y_store(struct device *dev,
4811 struct device_attribute *attr,
4812 const char *buf, size_t count)
4816 unsigned char timeout = 0;
4818 struct i2c_client *client = to_i2c_client(dev);
4819 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4821 error = strict_strtoul(buf, 10, &data);
4825 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 2, (unsigned
4829 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 2) < 0)
4834 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4836 /* printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4839 if (timeout == 50) {
4840 printk(KERN_INFO "get fast calibration ready error\n");
4846 printk(KERN_INFO "y axis fast calibration finished\n");
4850 static ssize_t bma2x2_fast_calibration_z_show(struct device *dev,
4851 struct device_attribute *attr, char *buf)
4856 struct i2c_client *client = to_i2c_client(dev);
4857 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4859 if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 3, &data) < 0)
4860 return sprintf(buf, "Read error\n");
4862 return sprintf(buf, "%d\n", data);
4866 static ssize_t bma2x2_fast_calibration_z_store(struct device *dev,
4867 struct device_attribute *attr,
4868 const char *buf, size_t count)
4872 unsigned char timeout = 0;
4874 struct i2c_client *client = to_i2c_client(dev);
4875 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4877 error = strict_strtoul(buf, 10, &data);
4881 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 3, (unsigned
4885 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 3) < 0)
4890 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4892 /* printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4895 if (timeout == 50) {
4896 printk(KERN_INFO "get fast calibration ready error\n");
4902 printk(KERN_INFO "z axis fast calibration finished\n");
4905 static ssize_t accel_calibration_open(struct device *dev,
4906 struct device_attribute *attr, char *buf)
4908 struct i2c_client *client = to_i2c_client(dev);
4909 bma2x2_open_cal(client);
4914 static ssize_t bma2x2_calibration_show(struct device *dev,
4915 struct device_attribute *attr, char *buf)
4917 /*struct i2c_client *client = to_i2c_client(dev);*/
4918 /*struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);*/
4921 mm_segment_t old_fs;
4922 struct file *cal_filp = NULL;
4925 printk(KERN_INFO "[BMC150] %s\n", __func__);
4930 cal_filp = filp_open(CALIBRATION_FILE_PATH,
4932 if (IS_ERR(cal_filp)) {
4933 pr_err("[BMC150] %s: Can't open calibration file\n",
4936 err = PTR_ERR(cal_filp);
4939 err = cal_filp->f_op->read(cal_filp,
4941 3 * sizeof(int), &cal_filp->f_pos);
4942 if (err != 3 * sizeof(int)) {
4943 pr_err("[BMC150] %s: Can't read the cal data from file\n",
4945 filp_close(cal_filp, current->files);
4949 if (((cal_data[0] == 0) &&(cal_data[1] == 0) &&(cal_data[2] == 0)))
4952 printk(KERN_INFO "[BMC150] %s: result=%d, (%d,%d,%d)",__func__, result, cal_data[0],cal_data[1],cal_data[2]);
4954 return sprintf(buf, "%d %d %d %d\n", result, cal_data[0],cal_data[1],cal_data[2]);
4958 static ssize_t bma2x2_calibration_store(struct device *dev,
4959 struct device_attribute *attr,
4960 const char *buf, size_t count)
4962 struct i2c_client *client = to_i2c_client(dev);
4963 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4968 unsigned char timeout = 0;
4970 mm_segment_t old_fs;
4971 struct file *cal_filp = NULL;
4973 err = strict_strtoul(buf, 10, &data);
4975 printk(KERN_ERR "[BMC150] %s: error(%d)\n", __func__, (unsigned char) data);
4979 printk(KERN_INFO "[BMC150] %s: %d\n", __func__, (unsigned char) data);
4981 if (bma2x2_get_mode(bma2x2->bma2x2_client, &mode) < 0) {
4982 printk(KERN_ERR "[BMC150] %s: bma2x2_get_mode error\n", __func__);
4986 if (mode != BMA2X2_MODE_NORMAL) {
4987 printk(KERN_INFO "[BMC150] %s: bma2x2_get_mode %d\n", __func__, mode);
4988 bma2x2_set_mode(bma2x2->bma2x2_client, BMA2X2_MODE_NORMAL);
4992 /* check the current z value and set offset_target_z based on it */
4993 short acc_value_z = 0;
4994 unsigned char offset_target_z = 0;
4995 bma2x2_read_accel_z(bma2x2->bma2x2_client, bma2x2->sensor_type,
4997 printk(KERN_INFO "[BMC150] acc_value_z = [%d], while accel calibration\n", acc_value_z);
4999 offset_target_z = 1;
5001 offset_target_z = 2;
5003 /* x axis fast calibration */
5004 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 1, (unsigned
5008 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 1) < 0)
5014 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5016 if (timeout == 50) {
5017 printk(KERN_INFO "[BMC150] x get fast calibration ready error\n");
5022 printk(KERN_INFO "[BMC150] x axis fast calibration DONE\n");
5024 /* y axis fast calibration */
5025 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 2, (unsigned
5029 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 2) < 0)
5034 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5036 if (timeout == 50) {
5037 printk(KERN_INFO "[BMC150] y get fast calibration ready error\n");
5042 printk(KERN_INFO "[BMC150] y axis fast calibration DONE\n");
5043 /* z axis fast calibration */
5044 /* check the current z value and set offset_target_z based on it */
5045 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 3, offset_target_z) < 0)
5048 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 3) < 0)
5053 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5055 if (timeout == 50) {
5056 printk(KERN_INFO "[BMC150] z get fast calibration ready error\n");
5059 printk(KERN_INFO "[BMC150] z axis fast calibration DONE\n");
5063 bma2x2_get_offset_x(bma2x2->bma2x2_client, (unsigned char*)&cal_data[0]);
5064 bma2x2_get_offset_y(bma2x2->bma2x2_client, (unsigned char*)&cal_data[1]);
5065 bma2x2_get_offset_z(bma2x2->bma2x2_client, (unsigned char*)&cal_data[2]);
5067 printk(KERN_INFO "[BMC150] %s: (%d,%d,%d)",__func__, cal_data[0],cal_data[1],cal_data[2]);
5071 cal_filp = filp_open(CALIBRATION_FILE_PATH,
5072 O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 0666);
5073 if (IS_ERR(cal_filp)) {
5074 pr_err("[BMC150] %s: Can't open calibration file\n",
5077 err = PTR_ERR(cal_filp);
5081 err = cal_filp->f_op->write(cal_filp,
5083 3 * sizeof(int), &cal_filp->f_pos);
5084 if (err != 3 * sizeof(int)) {
5085 pr_err("[BMC150] %s: Can't write the cal data to file\n",
5089 filp_close(cal_filp, current->files);
5094 /* erase cal data */
5097 cal_filp = filp_open(CALIBRATION_FILE_PATH,
5098 O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 0666);
5099 if (IS_ERR(cal_filp)) {
5100 pr_err("[BMC150] %s: Can't open calibration file\n",
5103 err = PTR_ERR(cal_filp);
5110 err = cal_filp->f_op->write(cal_filp,
5112 3 * sizeof(int), &cal_filp->f_pos);
5113 if (err != 3 * sizeof(int)) {
5114 pr_err("[BMC150] %s: Can't write the cal data to file\n",
5118 filp_close(cal_filp, current->files);
5121 bma2x2_set_offset_x(bma2x2->bma2x2_client, (unsigned char)cal_data[0]);
5122 bma2x2_set_offset_y(bma2x2->bma2x2_client, (unsigned char)cal_data[1]);
5123 bma2x2_set_offset_z(bma2x2->bma2x2_client, (unsigned char)cal_data[2]);
5130 static ssize_t bma2x2_SleepDur_show(struct device *dev,
5131 struct device_attribute *attr, char *buf)
5134 struct i2c_client *client = to_i2c_client(dev);
5135 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5137 if (bma2x2_get_sleep_duration(bma2x2->bma2x2_client, &data) < 0)
5138 return sprintf(buf, "Read error\n");
5140 return sprintf(buf, "%d\n", data);
5144 static ssize_t bma2x2_SleepDur_store(struct device *dev,
5145 struct device_attribute *attr,
5146 const char *buf, size_t count)
5150 struct i2c_client *client = to_i2c_client(dev);
5151 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5153 error = strict_strtoul(buf, 10, &data);
5156 if (bma2x2_set_sleep_duration(bma2x2->bma2x2_client,
5157 (unsigned char) data) < 0)
5163 static ssize_t bma2x2_fifo_mode_show(struct device *dev,
5164 struct device_attribute *attr, char *buf)
5167 struct i2c_client *client = to_i2c_client(dev);
5168 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5170 if (bma2x2_get_fifo_mode(bma2x2->bma2x2_client, &data) < 0)
5171 return sprintf(buf, "Read error\n");
5173 return sprintf(buf, "%d\n", data);
5177 static ssize_t bma2x2_fifo_mode_store(struct device *dev,
5178 struct device_attribute *attr,
5179 const char *buf, size_t count)
5183 struct i2c_client *client = to_i2c_client(dev);
5184 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5186 error = strict_strtoul(buf, 10, &data);
5189 if (bma2x2_set_fifo_mode(bma2x2->bma2x2_client,
5190 (unsigned char) data) < 0)
5198 static ssize_t bma2x2_fifo_trig_show(struct device *dev,
5199 struct device_attribute *attr, char *buf)
5202 struct i2c_client *client = to_i2c_client(dev);
5203 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5205 if (bma2x2_get_fifo_trig(bma2x2->bma2x2_client, &data) < 0)
5206 return sprintf(buf, "Read error\n");
5208 return sprintf(buf, "%d\n", data);
5212 static ssize_t bma2x2_fifo_trig_store(struct device *dev,
5213 struct device_attribute *attr,
5214 const char *buf, size_t count)
5218 struct i2c_client *client = to_i2c_client(dev);
5219 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5221 error = strict_strtoul(buf, 10, &data);
5224 if (bma2x2_set_fifo_trig(bma2x2->bma2x2_client,
5225 (unsigned char) data) < 0)
5233 static ssize_t bma2x2_fifo_trig_src_show(struct device *dev,
5234 struct device_attribute *attr, char *buf)
5237 struct i2c_client *client = to_i2c_client(dev);
5238 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5240 if (bma2x2_get_fifo_trig_src(bma2x2->bma2x2_client, &data) < 0)
5241 return sprintf(buf, "Read error\n");
5243 return sprintf(buf, "%d\n", data);
5247 static ssize_t bma2x2_fifo_trig_src_store(struct device *dev,
5248 struct device_attribute *attr,
5249 const char *buf, size_t count)
5253 struct i2c_client *client = to_i2c_client(dev);
5254 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5256 error = strict_strtoul(buf, 10, &data);
5259 if (bma2x2_set_fifo_trig_src(bma2x2->bma2x2_client,
5260 (unsigned char) data) < 0)
5268 static ssize_t bma2x2_fifo_data_sel_show(struct device *dev,
5269 struct device_attribute *attr, char *buf)
5272 struct i2c_client *client = to_i2c_client(dev);
5273 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5275 if (bma2x2_get_fifo_data_sel(bma2x2->bma2x2_client, &data) < 0)
5276 return sprintf(buf, "Read error\n");
5278 return sprintf(buf, "%d\n", data);
5282 static ssize_t bma2x2_fifo_framecount_show(struct device *dev,
5283 struct device_attribute *attr, char *buf)
5286 struct i2c_client *client = to_i2c_client(dev);
5287 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5289 if (bma2x2_get_fifo_framecount(bma2x2->bma2x2_client, &data) < 0)
5290 return sprintf(buf, "Read error\n");
5292 return sprintf(buf, "%d\n", data);
5296 static ssize_t bma2x2_temperature_show(struct device *dev,
5297 struct device_attribute *attr, char *buf)
5300 struct i2c_client *client = to_i2c_client(dev);
5301 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5303 if (bma2x2_read_temperature(bma2x2->bma2x2_client, &data) < 0)
5304 return sprintf(buf, "Read error\n");
5306 return sprintf(buf, "%d\n", data);
5310 static ssize_t bma2x2_fifo_data_sel_store(struct device *dev,
5311 struct device_attribute *attr,
5312 const char *buf, size_t count)
5316 struct i2c_client *client = to_i2c_client(dev);
5317 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5319 error = strict_strtoul(buf, 10, &data);
5322 if (bma2x2_set_fifo_data_sel(bma2x2->bma2x2_client,
5323 (unsigned char) data) < 0)
5331 static ssize_t bma2x2_fifo_data_out_frame_show(struct device *dev,
5332 struct device_attribute *attr, char *buf)
5336 signed char fifo_data_out[MAX_FIFO_F_LEVEL * MAX_FIFO_F_BYTES] = {0};
5337 unsigned char f_count, f_len = 0;
5338 unsigned char fifo_datasel = 0;
5340 struct i2c_client *client = to_i2c_client(dev);
5341 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5343 if (bma2x2_get_fifo_data_sel(bma2x2->bma2x2_client, &fifo_datasel) < 0)
5344 return sprintf(buf, "Read data sel error\n");
5351 if (bma2x2_get_fifo_framecount(bma2x2->bma2x2_client, &f_count) < 0)
5352 return sprintf(buf, "Read frame count error\n");
5355 if (bma_i2c_burst_read(bma2x2->bma2x2_client,
5356 BMA2X2_FIFO_DATA_OUTPUT_REG, fifo_data_out,
5357 f_count * f_len) < 0)
5358 return sprintf(buf, "Read byte block error\n");
5361 if (bma2x2_get_fifo_data_out_reg(bma2x2->bma2x2_client, &data) < 0)
5362 return sprintf(buf, "Read error\n");
5366 len = sprintf(buf, "%lu ", jiffies);
5370 len = sprintf(buf, "%u ", f_count);
5374 len = sprintf(buf, "%u ", f_len);
5378 for (i = 0; i < f_count * f_len; i++) {
5379 len = sprintf(buf, "%d ", fifo_data_out[i]);
5391 static ssize_t bma2x2_offset_x_show(struct device *dev,
5392 struct device_attribute *attr, char *buf)
5395 struct i2c_client *client = to_i2c_client(dev);
5396 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5398 if (bma2x2_get_offset_x(bma2x2->bma2x2_client, &data) < 0)
5399 return sprintf(buf, "Read error\n");
5401 return sprintf(buf, "%d\n", data);
5405 static ssize_t bma2x2_offset_x_store(struct device *dev,
5406 struct device_attribute *attr,
5407 const char *buf, size_t count)
5411 struct i2c_client *client = to_i2c_client(dev);
5412 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5414 error = strict_strtoul(buf, 10, &data);
5418 if (bma2x2_set_offset_x(bma2x2->bma2x2_client, (unsigned
5425 static ssize_t bma2x2_offset_y_show(struct device *dev,
5426 struct device_attribute *attr, char *buf)
5429 struct i2c_client *client = to_i2c_client(dev);
5430 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5432 if (bma2x2_get_offset_y(bma2x2->bma2x2_client, &data) < 0)
5433 return sprintf(buf, "Read error\n");
5435 return sprintf(buf, "%d\n", data);
5439 static ssize_t bma2x2_offset_y_store(struct device *dev,
5440 struct device_attribute *attr,
5441 const char *buf, size_t count)
5445 struct i2c_client *client = to_i2c_client(dev);
5446 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5448 error = strict_strtoul(buf, 10, &data);
5452 if (bma2x2_set_offset_y(bma2x2->bma2x2_client, (unsigned
5459 static ssize_t bma2x2_offset_z_show(struct device *dev,
5460 struct device_attribute *attr, char *buf)
5463 struct i2c_client *client = to_i2c_client(dev);
5464 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5466 if (bma2x2_get_offset_z(bma2x2->bma2x2_client, &data) < 0)
5467 return sprintf(buf, "Read error\n");
5469 return sprintf(buf, "%d\n", data);
5473 static ssize_t bma2x2_offset_z_store(struct device *dev,
5474 struct device_attribute *attr,
5475 const char *buf, size_t count)
5479 struct i2c_client *client = to_i2c_client(dev);
5480 struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5482 error = strict_strtoul(buf, 10, &data);
5486 if (bma2x2_set_offset_z(bma2x2->bma2x2_client, (unsigned
5494 static DEVICE_ATTR(range, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5495 bma2x2_range_show, bma2x2_range_store);
5496 static DEVICE_ATTR(bandwidth, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5497 bma2x2_bandwidth_show, bma2x2_bandwidth_store);
5498 static DEVICE_ATTR(mode, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5499 bma2x2_mode_show, bma2x2_mode_store);
5500 static DEVICE_ATTR(value, S_IRUGO,
5501 bma2x2_value_show, NULL);
5502 static DEVICE_ATTR(raw_data, S_IRUGO | S_IWUSR | S_IWGRP,
5503 bma2x2_raw_data_show, NULL);
5504 static DEVICE_ATTR(delay, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5505 bma2x2_delay_show, bma2x2_delay_store);
5506 static DEVICE_ATTR(enable, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5507 bma2x2_enable_show, bma2x2_enable_store);
5508 static DEVICE_ATTR(SleepDur, S_IRUGO|S_IWUSR|S_IWGRP,
5509 bma2x2_SleepDur_show, bma2x2_SleepDur_store);
5510 static DEVICE_ATTR(fast_calibration_x, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5511 bma2x2_fast_calibration_x_show,
5512 bma2x2_fast_calibration_x_store);
5513 static DEVICE_ATTR(fast_calibration_y, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5514 bma2x2_fast_calibration_y_show,
5515 bma2x2_fast_calibration_y_store);
5516 static DEVICE_ATTR(fast_calibration_z, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5517 bma2x2_fast_calibration_z_show,
5518 bma2x2_fast_calibration_z_store);
5519 static DEVICE_ATTR(fifo_mode, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5520 bma2x2_fifo_mode_show, bma2x2_fifo_mode_store);
5521 static DEVICE_ATTR(fifo_framecount, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5522 bma2x2_fifo_framecount_show, NULL);
5523 static DEVICE_ATTR(fifo_trig, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5524 bma2x2_fifo_trig_show, bma2x2_fifo_trig_store);
5525 static DEVICE_ATTR(fifo_trig_src, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5526 bma2x2_fifo_trig_src_show, bma2x2_fifo_trig_src_store);
5527 static DEVICE_ATTR(fifo_data_sel, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5528 bma2x2_fifo_data_sel_show, bma2x2_fifo_data_sel_store);
5529 static DEVICE_ATTR(fifo_data_out_frame, S_IRUGO,
5530 bma2x2_fifo_data_out_frame_show, NULL);
5531 static DEVICE_ATTR(reg, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5532 bma2x2_register_show, bma2x2_register_store);
5533 static DEVICE_ATTR(chip_id, S_IRUGO,
5534 bma2x2_chip_id_show, NULL);
5535 static DEVICE_ATTR(offset_x, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5536 bma2x2_offset_x_show,
5537 bma2x2_offset_x_store);
5538 static DEVICE_ATTR(offset_y, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5539 bma2x2_offset_y_show,
5540 bma2x2_offset_y_store);
5541 static DEVICE_ATTR(offset_z, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5542 bma2x2_offset_z_show,
5543 bma2x2_offset_z_store);
5544 static DEVICE_ATTR(enable_int, S_IWUSR|S_IWGRP|S_IWOTH,
5545 NULL, bma2x2_enable_int_store);
5546 static DEVICE_ATTR(int_mode, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5547 bma2x2_int_mode_show, bma2x2_int_mode_store);
5548 static DEVICE_ATTR(slope_duration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5549 bma2x2_slope_duration_show, bma2x2_slope_duration_store);
5550 static DEVICE_ATTR(slope_threshold, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5551 bma2x2_slope_threshold_show, bma2x2_slope_threshold_store);
5552 static DEVICE_ATTR(slope_no_mot_duration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5553 bma2x2_slope_no_mot_duration_show,
5554 bma2x2_slope_no_mot_duration_store);
5555 static DEVICE_ATTR(slope_no_mot_threshold, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5556 bma2x2_slope_no_mot_threshold_show,
5557 bma2x2_slope_no_mot_threshold_store);
5558 static DEVICE_ATTR(high_g_duration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5559 bma2x2_high_g_duration_show, bma2x2_high_g_duration_store);
5560 static DEVICE_ATTR(high_g_threshold, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5561 bma2x2_high_g_threshold_show, bma2x2_high_g_threshold_store);
5562 static DEVICE_ATTR(low_g_duration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5563 bma2x2_low_g_duration_show, bma2x2_low_g_duration_store);
5564 static DEVICE_ATTR(low_g_threshold, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5565 bma2x2_low_g_threshold_show, bma2x2_low_g_threshold_store);
5566 static DEVICE_ATTR(tap_duration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5567 bma2x2_tap_duration_show, bma2x2_tap_duration_store);
5568 static DEVICE_ATTR(tap_threshold, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5569 bma2x2_tap_threshold_show, bma2x2_tap_threshold_store);
5570 static DEVICE_ATTR(tap_quiet, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5571 bma2x2_tap_quiet_show, bma2x2_tap_quiet_store);
5572 static DEVICE_ATTR(tap_shock, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5573 bma2x2_tap_shock_show, bma2x2_tap_shock_store);
5574 static DEVICE_ATTR(tap_samp, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5575 bma2x2_tap_samp_show, bma2x2_tap_samp_store);
5576 static DEVICE_ATTR(orient_mode, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5577 bma2x2_orient_mode_show, bma2x2_orient_mode_store);
5578 static DEVICE_ATTR(orient_blocking, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5579 bma2x2_orient_blocking_show, bma2x2_orient_blocking_store);
5580 static DEVICE_ATTR(orient_hyst, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5581 bma2x2_orient_hyst_show, bma2x2_orient_hyst_store);
5582 static DEVICE_ATTR(orient_theta, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5583 bma2x2_orient_theta_show, bma2x2_orient_theta_store);
5584 static DEVICE_ATTR(flat_theta, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5585 bma2x2_flat_theta_show, bma2x2_flat_theta_store);
5586 static DEVICE_ATTR(flat_hold_time, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5587 bma2x2_flat_hold_time_show, bma2x2_flat_hold_time_store);
5588 static DEVICE_ATTR(selftest, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5589 bma2x2_selftest_show, bma2x2_selftest_store);
5590 static DEVICE_ATTR(softreset, S_IWUSR|S_IWGRP|S_IWOTH,
5591 NULL, bma2x2_softreset_store);
5592 static DEVICE_ATTR(temperature, S_IRUGO,
5593 bma2x2_temperature_show, NULL);
5594 static DEVICE_ATTR(place, S_IRUGO,
5595 bma2x2_place_show, NULL);
5596 static DEVICE_ATTR(calibration, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
5597 bma2x2_calibration_show,
5598 bma2x2_calibration_store);
5599 static DEVICE_ATTR(accel_cal_open, S_IRUGO,
5600 accel_calibration_open,NULL);
5602 static struct attribute *bma2x2_attributes[] = {
5603 &dev_attr_range.attr,
5604 &dev_attr_bandwidth.attr,
5605 &dev_attr_mode.attr,
5606 &dev_attr_value.attr,
5607 &dev_attr_delay.attr,
5608 &dev_attr_enable.attr,
5609 &dev_attr_SleepDur.attr,
5611 &dev_attr_fast_calibration_x.attr,
5612 &dev_attr_fast_calibration_y.attr,
5613 &dev_attr_fast_calibration_z.attr,
5614 &dev_attr_fifo_mode.attr,
5615 &dev_attr_fifo_framecount.attr,
5616 &dev_attr_fifo_trig.attr,
5617 &dev_attr_fifo_trig_src.attr,
5618 &dev_attr_fifo_data_sel.attr,
5619 &dev_attr_fifo_data_out_frame.attr,
5620 &dev_attr_chip_id.attr,
5621 &dev_attr_offset_x.attr,
5622 &dev_attr_offset_y.attr,
5623 &dev_attr_offset_z.attr,
5624 &dev_attr_enable_int.attr,
5625 &dev_attr_int_mode.attr,
5626 &dev_attr_slope_duration.attr,
5627 &dev_attr_slope_threshold.attr,
5628 &dev_attr_slope_no_mot_duration.attr,
5629 &dev_attr_slope_no_mot_threshold.attr,
5630 &dev_attr_high_g_duration.attr,
5631 &dev_attr_high_g_threshold.attr,
5632 &dev_attr_low_g_duration.attr,
5633 &dev_attr_low_g_threshold.attr,
5634 &dev_attr_tap_threshold.attr,
5635 &dev_attr_tap_duration.attr,
5636 &dev_attr_tap_quiet.attr,
5637 &dev_attr_tap_shock.attr,
5638 &dev_attr_tap_samp.attr,
5639 &dev_attr_orient_mode.attr,
5640 &dev_attr_orient_blocking.attr,
5641 &dev_attr_orient_hyst.attr,
5642 &dev_attr_orient_theta.attr,
5643 &dev_attr_flat_theta.attr,
5644 &dev_attr_flat_hold_time.attr,
5645 &dev_attr_selftest.attr,
5646 &dev_attr_softreset.attr,
5647 &dev_attr_temperature.attr,
5648 &dev_attr_place.attr,
5649 &dev_attr_calibration.attr,
5653 static struct attribute_group bma2x2_attribute_group = {
5654 .attrs = bma2x2_attributes
5660 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
5661 unsigned char *orient[] = {"upward looking portrait upright", \
5662 "upward looking portrait upside-down", \
5663 "upward looking landscape left", \
5664 "upward looking landscape right", \
5665 "downward looking portrait upright", \
5666 "downward looking portrait upside-down", \
5667 "downward looking landscape left", \
5668 "downward looking landscape right"};
5670 static void bma2x2_irq_work_func(struct work_struct *work)
5672 struct bma2x2_data *bma2x2 = container_of((struct work_struct *)work,
5673 struct bma2x2_data, irq_work);
5675 unsigned char status = 0;
5677 unsigned char first_value = 0;
5678 unsigned char sign_value = 0;
5680 bma2x2_get_interruptstatus1(bma2x2->bma2x2_client, &status);
5685 printk(KERN_INFO "Low G interrupt happened\n");
5686 input_report_rel(bma2x2->input, LOW_G_INTERRUPT,
5687 LOW_G_INTERRUPT_HAPPENED);
5690 for (i = 0; i < 3; i++) {
5691 bma2x2_get_HIGH_first(bma2x2->bma2x2_client, i,
5693 if (first_value == 1) {
5695 bma2x2_get_HIGH_sign(bma2x2->bma2x2_client,
5698 if (sign_value == 1) {
5700 input_report_rel(bma2x2->input,
5702 HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED);
5704 input_report_rel(bma2x2->input,
5706 HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED);
5708 input_report_rel(bma2x2->input,
5710 HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED);
5713 input_report_rel(bma2x2->input,
5715 HIGH_G_INTERRUPT_X_HAPPENED);
5717 input_report_rel(bma2x2->input,
5719 HIGH_G_INTERRUPT_Y_HAPPENED);
5721 input_report_rel(bma2x2->input,
5723 HIGH_G_INTERRUPT_Z_HAPPENED);
5728 printk(KERN_INFO "High G interrupt happened,exis is %d,"
5729 "first is %d,sign is %d\n", i,
5730 first_value, sign_value);
5734 for (i = 0; i < 3; i++) {
5735 bma2x2_get_slope_first(bma2x2->bma2x2_client, i,
5737 if (first_value == 1) {
5739 bma2x2_get_slope_sign(bma2x2->bma2x2_client,
5742 if (sign_value == 1) {
5744 input_report_rel(bma2x2->input,
5746 SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED);
5748 input_report_rel(bma2x2->input,
5750 SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED);
5752 input_report_rel(bma2x2->input,
5754 SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED);
5757 input_report_rel(bma2x2->input,
5759 SLOPE_INTERRUPT_X_HAPPENED);
5761 input_report_rel(bma2x2->input,
5763 SLOPE_INTERRUPT_Y_HAPPENED);
5765 input_report_rel(bma2x2->input,
5767 SLOPE_INTERRUPT_Z_HAPPENED);
5772 printk(KERN_INFO "Slop interrupt happened,exis is %d,"
5773 "first is %d,sign is %d\n", i,
5774 first_value, sign_value);
5779 printk(KERN_INFO "slow/ no motion interrupt happened\n");
5780 input_report_rel(bma2x2->input, SLOW_NO_MOTION_INTERRUPT,
5781 SLOW_NO_MOTION_INTERRUPT_HAPPENED);
5785 printk(KERN_INFO "double tap interrupt happened\n");
5786 input_report_rel(bma2x2->input, DOUBLE_TAP_INTERRUPT,
5787 DOUBLE_TAP_INTERRUPT_HAPPENED);
5790 printk(KERN_INFO "single tap interrupt happened\n");
5791 input_report_rel(bma2x2->input, SINGLE_TAP_INTERRUPT,
5792 SINGLE_TAP_INTERRUPT_HAPPENED);
5795 bma2x2_get_orient_status(bma2x2->bma2x2_client,
5797 printk(KERN_INFO "orient interrupt happened,%s\n",
5798 orient[first_value]);
5799 if (first_value == 0)
5800 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5801 UPWARD_PORTRAIT_UP_INTERRUPT_HAPPENED);
5802 else if (first_value == 1)
5803 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5804 UPWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED);
5805 else if (first_value == 2)
5806 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5807 UPWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED);
5808 else if (first_value == 3)
5809 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5810 UPWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED);
5811 else if (first_value == 4)
5812 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5813 DOWNWARD_PORTRAIT_UP_INTERRUPT_HAPPENED);
5814 else if (first_value == 5)
5815 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5816 DOWNWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED);
5817 else if (first_value == 6)
5818 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5819 DOWNWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED);
5820 else if (first_value == 7)
5821 input_report_abs(bma2x2->input, ORIENT_INTERRUPT,
5822 DOWNWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED);
5825 bma2x2_get_orient_flat_status(bma2x2->bma2x2_client,
5827 printk(KERN_INFO "flat interrupt happened,flat status is %d\n",
5829 if (sign_value == 1) {
5830 input_report_abs(bma2x2->input, FLAT_INTERRUPT,
5831 FLAT_INTERRUPT_TURE_HAPPENED);
5833 input_report_abs(bma2x2->input, FLAT_INTERRUPT,
5834 FLAT_INTERRUPT_FALSE_HAPPENED);
5843 static irqreturn_t bma2x2_irq_handler(int irq, void *handle)
5847 struct bma2x2_data *data = handle;
5852 if (data->bma2x2_client == NULL)
5856 schedule_work(&data->irq_work);
5862 #endif /* defined(BMA2X2_ENABLE_INT1)||defined(BMA2X2_ENABLE_INT2) */
5866 static struct device_attribute *bma2X2_attrs[] = {
5868 &dev_attr_fast_calibration_x,
5869 &dev_attr_fast_calibration_y,
5870 &dev_attr_fast_calibration_z,
5871 &dev_attr_calibration,
5872 &dev_attr_accel_cal_open,
5876 static int bma2x2_probe(struct i2c_client *client,
5877 const struct i2c_device_id *id)
5881 unsigned char tmp_chip_id;
5882 struct bma2x2_data *data;
5883 struct input_dev *dev;
5885 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
5886 printk(KERN_INFO "i2c_check_functionality error\n");
5889 data = kzalloc(sizeof(struct bma2x2_data), GFP_KERNEL);
5895 tempvalue = i2c_smbus_read_word_data(client, BMA2X2_CHIP_ID_REG);
5896 tmp_chip_id = tempvalue&0x00ff;
5897 printk(KERN_ALERT" %s : CHIP ID vlaue of accel sensor \n",__func__);
5899 switch (tmp_chip_id) {
5900 case BMA255_CHIP_ID:
5901 data->sensor_type = BMA255_TYPE;
5903 case BMA250E_CHIP_ID:
5904 data->sensor_type = BMA250E_TYPE;
5906 case BMA222E_CHIP_ID:
5907 data->sensor_type = BMA222E_TYPE;
5909 case BMA280_CHIP_ID:
5910 data->sensor_type = BMA280_TYPE;
5913 data->sensor_type = -1;
5915 if (data->sensor_type != -1) {
5916 data->chip_id = tmp_chip_id;
5917 printk(KERN_INFO "Bosch Sensortec Device detected!\n"
5918 "%s registered I2C driver!\n",
5919 sensor_name[data->sensor_type]);
5921 printk(KERN_INFO "Bosch Sensortec Device not found"
5922 "i2c error %d\n", tempvalue);
5926 i2c_set_clientdata(client, data);
5927 data->bma2x2_client = client;
5928 mutex_init(&data->value_mutex);
5929 mutex_init(&data->mode_mutex);
5930 mutex_init(&data->enable_mutex);
5932 err = bma2x2_set_bandwidth(client, BMA2X2_BW_SET);
5934 printk(KERN_INFO "%s set bandwidth failed!\n",
5935 sensor_name[data->sensor_type]);
5938 err = bma2x2_set_range(client, BMA2X2_RANGE_SET);
5940 printk(KERN_INFO "%s set g-range failed!\n",
5941 sensor_name[data->sensor_type]);
5945 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
5946 bma2x2_set_Int_Mode(client, 1);/*latch interrupt 250ms*/
5949 #ifdef BMA2X2_ENABLE_INT1
5950 /* maps interrupt to INT1 pin */
5951 bma2x2_set_int1_pad_sel(client, PAD_LOWG);
5952 bma2x2_set_int1_pad_sel(client, PAD_HIGHG);
5953 bma2x2_set_int1_pad_sel(client, PAD_SLOP);
5954 bma2x2_set_int1_pad_sel(client, PAD_DOUBLE_TAP);
5955 bma2x2_set_int1_pad_sel(client, PAD_SINGLE_TAP);
5956 bma2x2_set_int1_pad_sel(client, PAD_ORIENT);
5957 bma2x2_set_int1_pad_sel(client, PAD_FLAT);
5958 bma2x2_set_int1_pad_sel(client, PAD_SLOW_NO_MOTION);
5961 #ifdef BMA2X2_ENABLE_INT2
5962 /* maps interrupt to INT2 pin */
5963 bma2x2_set_int2_pad_sel(client, PAD_LOWG);
5964 bma2x2_set_int2_pad_sel(client, PAD_HIGHG);
5965 bma2x2_set_int2_pad_sel(client, PAD_SLOP);
5966 bma2x2_set_int2_pad_sel(client, PAD_DOUBLE_TAP);
5967 bma2x2_set_int2_pad_sel(client, PAD_SINGLE_TAP);
5968 bma2x2_set_int2_pad_sel(client, PAD_ORIENT);
5969 bma2x2_set_int2_pad_sel(client, PAD_FLAT);
5970 bma2x2_set_int2_pad_sel(client, PAD_SLOW_NO_MOTION);
5973 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
5974 data->IRQ = client->irq;
5975 err = request_irq(data->IRQ, bma2x2_irq_handler, IRQF_TRIGGER_RISING,
5978 printk(KERN_ERR "could not request irq\n");
5980 INIT_WORK(&data->irq_work, bma2x2_irq_work_func);
5984 INIT_DELAYED_WORK(&data->work, bma2x2_work_func);
5985 atomic_set(&data->delay, BMA2X2_MAX_DELAY);
5986 atomic_set(&data->enable, 0);
5988 dev = input_allocate_device();
5991 dev->name = SENSOR_NAME;
5992 dev->id.bustype = BUS_I2C;
5994 input_set_capability(dev, EV_REL, SLOW_NO_MOTION_INTERRUPT);
5995 input_set_capability(dev, EV_REL, LOW_G_INTERRUPT);
5996 input_set_capability(dev, EV_REL, HIGH_G_INTERRUPT);
5997 input_set_capability(dev, EV_REL, SLOP_INTERRUPT);
5998 input_set_capability(dev, EV_REL, DOUBLE_TAP_INTERRUPT);
5999 input_set_capability(dev, EV_REL, SINGLE_TAP_INTERRUPT);
6000 input_set_capability(dev, EV_ABS, ORIENT_INTERRUPT);
6001 input_set_capability(dev, EV_ABS, FLAT_INTERRUPT);
6002 input_set_abs_params(dev, ABS_X, ABSMIN, ABSMAX, 0, 0);
6003 input_set_abs_params(dev, ABS_Y, ABSMIN, ABSMAX, 0, 0);
6004 input_set_abs_params(dev, ABS_Z, ABSMIN, ABSMAX, 0, 0);
6006 input_set_drvdata(dev, data);
6008 err = input_register_device(dev);
6010 input_free_device(dev);
6016 err = sysfs_create_group(&data->input->dev.kobj,
6017 &bma2x2_attribute_group);
6021 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
6022 if (NULL != client->dev.platform_data) {
6023 data->bst_pd = kzalloc(sizeof(*data->bst_pd),
6026 if (NULL != data->bst_pd) {
6027 memcpy(data->bst_pd, client->dev.platform_data,
6028 sizeof(*data->bst_pd));
6029 printk(KERN_ALERT"bma2x2 "
6030 "place of bma in %s: %d",
6032 data->bst_pd->place);
6037 #ifdef CONFIG_HAS_EARLYSUSPEND
6038 data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
6039 data->early_suspend.suspend = bma2x2_early_suspend;
6040 data->early_suspend.resume = bma2x2_late_resume;
6041 register_early_suspend(&data->early_suspend);
6044 err = sensors_register(&bma_device, data,bma2X2_attrs, "accelerometer_sensor");
6047 pr_err("%s: could not register" "accelerometer_sensor device(%d).\n", __func__, err);
6054 input_unregister_device(data->input);
6057 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
6058 if ((NULL != data) && (NULL != data->bst_pd)) {
6059 kfree(data->bst_pd);
6060 data->bst_pd = NULL;
6068 #ifdef CONFIG_HAS_EARLYSUSPEND
6069 static void bma2x2_early_suspend(struct early_suspend *h)
6071 struct bma2x2_data *data =
6072 container_of(h, struct bma2x2_data, early_suspend);
6074 mutex_lock(&data->enable_mutex);
6075 if (atomic_read(&data->enable) == 1) {
6076 bma2x2_set_mode(data->bma2x2_client, BMA2X2_MODE_SUSPEND);
6077 cancel_delayed_work_sync(&data->work);
6079 mutex_unlock(&data->enable_mutex);
6083 static void bma2x2_late_resume(struct early_suspend *h)
6085 struct bma2x2_data *data =
6086 container_of(h, struct bma2x2_data, early_suspend);
6088 mutex_lock(&data->enable_mutex);
6089 if (atomic_read(&data->enable) == 1) {
6090 bma2x2_set_mode(data->bma2x2_client, BMA2X2_MODE_NORMAL);
6091 schedule_delayed_work(&data->work,
6092 msecs_to_jiffies(atomic_read(&data->delay)));
6094 mutex_unlock(&data->enable_mutex);
6098 static int __exit bma2x2_remove(struct i2c_client *client)
6100 struct bma2x2_data *data = i2c_get_clientdata(client);
6102 bma2x2_set_enable(&client->dev, 0);
6103 #ifdef CONFIG_HAS_EARLYSUSPEND
6104 unregister_early_suspend(&data->early_suspend);
6106 sensors_unregister(bma_device, bma2X2_attrs);
6107 sysfs_remove_group(&data->input->dev.kobj, &bma2x2_attribute_group);
6108 input_unregister_device(data->input);
6110 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
6111 if (NULL != data->bst_pd) {
6112 kfree(data->bst_pd);
6113 data->bst_pd = NULL;
6123 static int bma2x2_suspend(struct i2c_client *client, pm_message_t mesg)
6125 struct bma2x2_data *data = i2c_get_clientdata(client);
6127 mutex_lock(&data->enable_mutex);
6128 if (atomic_read(&data->enable) == 1) {
6129 bma2x2_set_mode(data->bma2x2_client, BMA2X2_MODE_SUSPEND);
6130 cancel_delayed_work_sync(&data->work);
6132 mutex_unlock(&data->enable_mutex);
6137 static int bma2x2_resume(struct i2c_client *client)
6139 struct bma2x2_data *data = i2c_get_clientdata(client);
6141 mutex_lock(&data->enable_mutex);
6142 if (atomic_read(&data->enable) == 1) {
6143 bma2x2_set_mode(data->bma2x2_client, BMA2X2_MODE_NORMAL);
6144 schedule_delayed_work(&data->work,
6145 msecs_to_jiffies(atomic_read(&data->delay)));
6147 mutex_unlock(&data->enable_mutex);
6154 #define bma2x2_suspend NULL
6155 #define bma2x2_resume NULL
6157 #endif /* CONFIG_PM */
6159 static const struct i2c_device_id bma2x2_id[] = {
6164 MODULE_DEVICE_TABLE(i2c, bma2x2_id);
6166 static struct i2c_driver bma2x2_driver = {
6168 .owner = THIS_MODULE,
6169 .name = SENSOR_NAME,
6171 .suspend = bma2x2_suspend,
6172 .resume = bma2x2_resume,
6173 .id_table = bma2x2_id,
6174 .probe = bma2x2_probe,
6175 .remove = bma2x2_remove,
6179 static int __init BMA2X2_init(void)
6181 return i2c_add_driver(&bma2x2_driver);
6184 static void __exit BMA2X2_exit(void)
6186 i2c_del_driver(&bma2x2_driver);
6189 MODULE_AUTHOR("Albert Zhang <xu.zhang@bosch-sensortec.com>");
6190 MODULE_DESCRIPTION("BMA2X2 accelerometer sensor driver");
6191 MODULE_LICENSE("GPL");
6193 module_init(BMA2X2_init);
6194 module_exit(BMA2X2_exit);