ARM: mali400: r5p2_rel0: fix Makefile & Kconfig
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / sensor / bma2x2_driver.c
1 /*  Date: 2013/06/17 22:13:00
2  *  Revision: 1.7.2
3  */
4
5 /*
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
8
9  * (C) Copyright 2011 Bosch Sensortec GmbH
10  * All Rights Reserved
11  */
12
13
14 /* file BMA2X2.c
15    brief This file contains all function implementations for the BMA2X2 in linux
16
17 */
18
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>
29 #include <linux/fs.h>
30 #include <linux/uaccess.h>
31 #ifdef CONFIG_HAS_EARLYSUSPEND
32 #include <linux/earlysuspend.h>
33 #endif
34 #include <linux/sensors_core.h>
35 #include <linux/bst_sensor_common.h>
36
37
38 #define SENSOR_NAME                     "bma2x2"
39 #define ABSMIN                          -512
40 #define ABSMAX                          512
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  */
53
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
62
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
89
90
91 #define PAD_LOWG                                        0
92 #define PAD_HIGHG                                       1
93 #define PAD_SLOP                                        2
94 #define PAD_DOUBLE_TAP                                  3
95 #define PAD_SINGLE_TAP                                  4
96 #define PAD_ORIENT                                      5
97 #define PAD_FLAT                                        6
98 #define PAD_SLOW_NO_MOTION                              7
99
100
101 #define BMA2X2_EEP_OFFSET                       0x16
102 #define BMA2X2_IMAGE_BASE                       0x38
103 #define BMA2X2_IMAGE_LEN                        22
104
105
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
163
164
165
166
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
171
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
176
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
181
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
186
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
191
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
196
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
201
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
206
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
211
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
216
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
221
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
226
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
231
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
236
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
241
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
246
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
251
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
256
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
261
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
266
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
271
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
276
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
281
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
286
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
291
292
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
297
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
302
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
307
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
312
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
317
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
322
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
327
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
332
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
337
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
342
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
347
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
352
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
357
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
362
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
367
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
372
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
377
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
382
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
387
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
392
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
397
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
402
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
407
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
412
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
417
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
422
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
427
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
432
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
437
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
442
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
447
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
452
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
457
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
462
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
467
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
472
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
477
478 #define BMA2X2_EN_SOFT_RESET_VALUE        0xB6
479
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
484
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
489
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
494
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
499
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
504
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
509
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
514
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
519
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
524
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
529
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
534
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
539
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
544
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
549
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
554
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
559
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
564
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
569
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
574
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
579
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
584
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
589
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
594
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
599
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
604
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
609
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
614
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
619
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
624
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
629
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
634
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
639
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
644
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
649
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
654
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
659
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
664
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
669
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
674
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
679
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
684
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
689
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
694
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
699
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
704
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
709
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
714
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
719
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
724
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
729
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
734
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
739
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
744
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
749
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
754
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
759
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
764
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
769
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
774
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
779
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
784
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
789
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
794
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
799
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
804
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
809
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
814
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
819
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
824
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
829
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
834
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
839
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
844
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
849
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
854
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
859
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
864
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
869
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
874
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
879
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
884
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
889
890
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
895
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
900
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
905
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
910
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
915
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
920
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
925
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
930
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
935
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
940
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
945
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
950
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
955
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
960
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
965
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
970
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
975
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
980
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
985
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
990
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
995
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
1000
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
1005
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
1010
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
1015
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
1020
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
1025
1026
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
1032
1033
1034 #define BMA2X2_RANGE_2G                 3
1035 #define BMA2X2_RANGE_4G                 5
1036 #define BMA2X2_RANGE_8G                 8
1037 #define BMA2X2_RANGE_16G                12
1038
1039
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
1048
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
1060
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
1077
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
1084
1085 #define BMA2X2_X_AXIS           0
1086 #define BMA2X2_Y_AXIS           1
1087 #define BMA2X2_Z_AXIS           2
1088
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
1103
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
1126
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
1133
1134 #define BMA2X2_INT1_OUTPUT      0
1135 #define BMA2X2_INT2_OUTPUT      1
1136 #define BMA2X2_INT1_LEVEL       0
1137 #define BMA2X2_INT2_LEVEL       1
1138
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
1143
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
1148
1149
1150 #define BMA2X2_LOWG_HYST                0
1151 #define BMA2X2_HIGHG_HYST               1
1152
1153 #define BMA2X2_ORIENT_THETA             0
1154 #define BMA2X2_FLAT_THETA               1
1155
1156 #define BMA2X2_I2C_SELECT               0
1157 #define BMA2X2_I2C_EN                   1
1158
1159 #define BMA2X2_SLOW_COMP_X              0
1160 #define BMA2X2_SLOW_COMP_Y              1
1161 #define BMA2X2_SLOW_COMP_Z              2
1162
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
1167
1168 #define BMA2X2_GP0                      0
1169 #define BMA2X2_GP1                      1
1170
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
1175
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
1180
1181 #define BMA2X2_SELF_TEST0_ON            1
1182 #define BMA2X2_SELF_TEST1_ON            2
1183
1184 #define BMA2X2_EE_W_OFF                 0
1185 #define BMA2X2_EE_W_ON                  1
1186
1187 #define BMA2X2_LOW_TH_IN_G(gthres, range)           ((256 * gthres) / range)
1188
1189
1190 #define BMA2X2_HIGH_TH_IN_G(gthres, range)          ((256 * gthres) / range)
1191
1192
1193 #define BMA2X2_LOW_HY_IN_G(ghyst, range)            ((32 * ghyst) / range)
1194
1195
1196 #define BMA2X2_HIGH_HY_IN_G(ghyst, range)           ((32 * ghyst) / range)
1197
1198
1199 #define BMA2X2_SLOPE_TH_IN_G(gthres, range)    ((128 * gthres) / range)
1200
1201
1202 #define BMA2X2_GET_BITSLICE(regvar, bitname)\
1203         ((regvar & bitname##__MSK) >> bitname##__POS)
1204
1205
1206 #define BMA2X2_SET_BITSLICE(regvar, bitname, val)\
1207         ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
1208
1209
1210 #define BMA255_CHIP_ID 0XFA
1211 #define BMA250E_CHIP_ID 0XF9
1212 #define BMA222E_CHIP_ID 0XF8
1213 #define BMA280_CHIP_ID 0XFB
1214
1215 #define BMA255_TYPE 0
1216 #define BMA250E_TYPE 1
1217 #define BMA222E_TYPE 2
1218 #define BMA280_TYPE 3
1219
1220 #define MAX_FIFO_F_LEVEL 32
1221 #define MAX_FIFO_F_BYTES 6
1222 #define BMA_MAX_RETRY_I2C_XFER (100)
1223
1224 static struct device *bma_device = NULL;
1225 #define CALIBRATION_FILE_PATH   "/efs/calibration_data"
1226
1227 unsigned char *sensor_name[] = { "BMA255", "BMA250E", "BMA222E", "BMA280" };
1228
1229 struct bma2x2acc {
1230         s16     x,
1231                 y,
1232                 z;
1233 } ;
1234
1235 struct bma2x2_data {
1236         struct i2c_client *bma2x2_client;
1237         atomic_t delay;
1238         atomic_t enable;
1239         atomic_t selftest_result;
1240         unsigned int chip_id;
1241         unsigned char mode;
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;
1252 #endif
1253         int IRQ;
1254
1255 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
1256         struct bosch_sensor_specific *bst_pd;
1257 #endif
1258 };
1259
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);
1263 #endif
1264
1265 static void bma2x2_remap_sensor_data(struct bma2x2acc *val,
1266                 struct bma2x2_data *client_data)
1267 {
1268 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
1269         struct bosch_sensor_data bsd;
1270
1271         if (NULL == client_data->bst_pd)
1272                 return;
1273
1274         bsd.x = val->x;
1275         bsd.y = val->y;
1276         bsd.z = val->z;
1277
1278         bst_remap_sensor_data_dft_tab(&bsd,
1279                         client_data->bst_pd->place);
1280
1281         val->x = bsd.x;
1282         val->y = bsd.y;
1283         val->z = bsd.z;
1284 #else
1285         (void)val;
1286         (void)client_data;
1287 #endif
1288 }
1289
1290
1291 static int bma2x2_smbus_read_byte(struct i2c_client *client,
1292                 unsigned char reg_addr, unsigned char *data)
1293 {
1294         s32 dummy;
1295         dummy = i2c_smbus_read_byte_data(client, reg_addr);
1296         if (dummy < 0)
1297                 return -1;
1298         *data = dummy & 0x000000ff;
1299
1300         return 0;
1301 }
1302
1303 static int bma2x2_smbus_write_byte(struct i2c_client *client,
1304                 unsigned char reg_addr, unsigned char *data)
1305 {
1306         s32 dummy;
1307
1308         dummy = i2c_smbus_write_byte_data(client, reg_addr, *data);
1309         if (dummy < 0)
1310                 return -1;
1311         return 0;
1312 }
1313
1314 static int bma2x2_smbus_read_byte_block(struct i2c_client *client,
1315                 unsigned char reg_addr, unsigned char *data, unsigned char len)
1316 {
1317         s32 dummy;
1318         dummy = i2c_smbus_read_i2c_block_data(client, reg_addr, len, data);
1319         if (dummy < 0)
1320                 return -1;
1321         return 0;
1322 }
1323
1324 static int bma_i2c_burst_read(struct i2c_client *client, u8 reg_addr,
1325                 u8 *data, u16 len)
1326 {
1327         int retry;
1328
1329         struct i2c_msg msg[] = {
1330                 {
1331                  .addr = client->addr,
1332                  .flags = 0,
1333                  .len = 1,
1334                  .buf = &reg_addr,
1335                 },
1336
1337                 {
1338                  .addr = client->addr,
1339                  .flags = I2C_M_RD,
1340                  .len = len,
1341                  .buf = data,
1342                  },
1343         };
1344
1345         for (retry = 0; retry < BMA_MAX_RETRY_I2C_XFER; retry++) {
1346                 if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
1347                         break;
1348                 else
1349                         mdelay(1);
1350         }
1351
1352         if (BMA_MAX_RETRY_I2C_XFER <= retry) {
1353                 printk(KERN_INFO "I2C xfer error");
1354                 return -EIO;
1355         }
1356
1357         return 0;
1358 }
1359
1360
1361 #ifdef BMA2X2_ENABLE_INT1
1362 static int bma2x2_set_int1_pad_sel(struct i2c_client *client, unsigned char
1363                 int1sel)
1364 {
1365         int comres = 0;
1366         unsigned char data;
1367         unsigned char state;
1368         state = 0x01;
1369
1370
1371         switch (int1sel) {
1372         case 0:
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,
1376                                 state);
1377                 comres = bma2x2_smbus_write_byte(client,
1378                                 BMA2X2_EN_INT1_PAD_LOWG__REG, &data);
1379                 break;
1380         case 1:
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,
1384                                 state);
1385                 comres = bma2x2_smbus_write_byte(client,
1386                                 BMA2X2_EN_INT1_PAD_HIGHG__REG, &data);
1387                 break;
1388         case 2:
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,
1392                                 state);
1393                 comres = bma2x2_smbus_write_byte(client,
1394                                 BMA2X2_EN_INT1_PAD_SLOPE__REG, &data);
1395                 break;
1396         case 3:
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,
1400                                 state);
1401                 comres = bma2x2_smbus_write_byte(client,
1402                                 BMA2X2_EN_INT1_PAD_DB_TAP__REG, &data);
1403                 break;
1404         case 4:
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,
1408                                 state);
1409                 comres = bma2x2_smbus_write_byte(client,
1410                                 BMA2X2_EN_INT1_PAD_SNG_TAP__REG, &data);
1411                 break;
1412         case 5:
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,
1416                                 state);
1417                 comres = bma2x2_smbus_write_byte(client,
1418                                 BMA2X2_EN_INT1_PAD_ORIENT__REG, &data);
1419                 break;
1420         case 6:
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,
1424                                 state);
1425                 comres = bma2x2_smbus_write_byte(client,
1426                                 BMA2X2_EN_INT1_PAD_FLAT__REG, &data);
1427                 break;
1428         case 7:
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,
1432                                 state);
1433                 comres = bma2x2_smbus_write_byte(client,
1434                                 BMA2X2_EN_INT1_PAD_SLO_NO_MOT__REG, &data);
1435                 break;
1436
1437         default:
1438                 break;
1439         }
1440
1441         return comres;
1442 }
1443 #endif /* BMA2X2_ENABLE_INT1 */
1444 #ifdef BMA2X2_ENABLE_INT2
1445 static int bma2x2_set_int2_pad_sel(struct i2c_client *client, unsigned char
1446                 int2sel)
1447 {
1448         int comres = 0;
1449         unsigned char data;
1450         unsigned char state;
1451         state = 0x01;
1452
1453
1454         switch (int2sel) {
1455         case 0:
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,
1459                                 state);
1460                 comres = bma2x2_smbus_write_byte(client,
1461                                 BMA2X2_EN_INT2_PAD_LOWG__REG, &data);
1462                 break;
1463         case 1:
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,
1467                                 state);
1468                 comres = bma2x2_smbus_write_byte(client,
1469                                 BMA2X2_EN_INT2_PAD_HIGHG__REG, &data);
1470                 break;
1471         case 2:
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,
1475                                 state);
1476                 comres = bma2x2_smbus_write_byte(client,
1477                                 BMA2X2_EN_INT2_PAD_SLOPE__REG, &data);
1478                 break;
1479         case 3:
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,
1483                                 state);
1484                 comres = bma2x2_smbus_write_byte(client,
1485                                 BMA2X2_EN_INT2_PAD_DB_TAP__REG, &data);
1486                 break;
1487         case 4:
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,
1491                                 state);
1492                 comres = bma2x2_smbus_write_byte(client,
1493                                 BMA2X2_EN_INT2_PAD_SNG_TAP__REG, &data);
1494                 break;
1495         case 5:
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,
1499                                 state);
1500                 comres = bma2x2_smbus_write_byte(client,
1501                                 BMA2X2_EN_INT2_PAD_ORIENT__REG, &data);
1502                 break;
1503         case 6:
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,
1507                                 state);
1508                 comres = bma2x2_smbus_write_byte(client,
1509                                 BMA2X2_EN_INT2_PAD_FLAT__REG, &data);
1510                 break;
1511         case 7:
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,
1515                                 state);
1516                 comres = bma2x2_smbus_write_byte(client,
1517                                 BMA2X2_EN_INT2_PAD_SLO_NO_MOT__REG, &data);
1518                 break;
1519         default:
1520                 break;
1521         }
1522
1523         return comres;
1524 }
1525 #endif /* BMA2X2_ENABLE_INT2 */
1526
1527 static int bma2x2_set_Int_Enable(struct i2c_client *client, unsigned char
1528                 InterruptType , unsigned char value)
1529 {
1530         int comres = 0;
1531         unsigned char data1, data2;
1532
1533         if ((11 < InterruptType) && (InterruptType < 16)) {
1534                 switch (InterruptType) {
1535                 case 12:
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);
1543                         break;
1544                 case 13:
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);
1552                         break;
1553                 case 14:
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);
1561                         break;
1562                 case 15:
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);
1570                 }
1571
1572         return comres;
1573         }
1574
1575
1576         comres = bma2x2_smbus_read_byte(client, BMA2X2_INT_ENABLE1_REG, &data1);
1577         comres = bma2x2_smbus_read_byte(client, BMA2X2_INT_ENABLE2_REG, &data2);
1578
1579         value = value & 1;
1580         switch (InterruptType) {
1581         case 0:
1582                 /* Low G Interrupt  */
1583                 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_LOWG_INT, value);
1584                 break;
1585         case 1:
1586                 /* High G X Interrupt */
1587
1588                 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_X_INT,
1589                                 value);
1590                 break;
1591         case 2:
1592                 /* High G Y Interrupt */
1593
1594                 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_Y_INT,
1595                                 value);
1596                 break;
1597         case 3:
1598                 /* High G Z Interrupt */
1599
1600                 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_HIGHG_Z_INT,
1601                                 value);
1602                 break;
1603         case 4:
1604                 /* New Data Interrupt  */
1605
1606                 data2 = BMA2X2_SET_BITSLICE(data2, BMA2X2_EN_NEW_DATA_INT,
1607                                 value);
1608                 break;
1609         case 5:
1610                 /* Slope X Interrupt */
1611
1612                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_X_INT,
1613                                 value);
1614                 break;
1615         case 6:
1616                 /* Slope Y Interrupt */
1617
1618                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_Y_INT,
1619                                 value);
1620                 break;
1621         case 7:
1622                 /* Slope Z Interrupt */
1623
1624                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SLOPE_Z_INT,
1625                                 value);
1626                 break;
1627         case 8:
1628                 /* Single Tap Interrupt */
1629
1630                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_SINGLE_TAP_INT,
1631                                 value);
1632                 break;
1633         case 9:
1634                 /* Double Tap Interrupt */
1635
1636                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_DOUBLE_TAP_INT,
1637                                 value);
1638                 break;
1639         case 10:
1640                 /* Orient Interrupt  */
1641
1642                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_ORIENT_INT, value);
1643                 break;
1644         case 11:
1645                 /* Flat Interrupt */
1646
1647                 data1 = BMA2X2_SET_BITSLICE(data1, BMA2X2_EN_FLAT_INT, value);
1648                 break;
1649         default:
1650                 break;
1651         }
1652         comres = bma2x2_smbus_write_byte(client, BMA2X2_INT_ENABLE1_REG,
1653                         &data1);
1654         comres = bma2x2_smbus_write_byte(client, BMA2X2_INT_ENABLE2_REG,
1655                         &data2);
1656
1657         return comres;
1658 }
1659
1660
1661 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
1662 static int bma2x2_get_interruptstatus1(struct i2c_client *client, unsigned char
1663                 *intstatus)
1664 {
1665         int comres = 0;
1666         unsigned char data;
1667
1668         comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS1_REG, &data);
1669         *intstatus = data;
1670
1671         return comres;
1672 }
1673
1674
1675 static int bma2x2_get_HIGH_first(struct i2c_client *client, unsigned char
1676                                                 param, unsigned char *intstatus)
1677 {
1678         int comres = 0;
1679         unsigned char data;
1680
1681         switch (param) {
1682         case 0:
1683                 comres = bma2x2_smbus_read_byte(client,
1684                                 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1685                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_X);
1686                 *intstatus = data;
1687                 break;
1688         case 1:
1689                 comres = bma2x2_smbus_read_byte(client,
1690                                 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1691                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_Y);
1692                 *intstatus = data;
1693                 break;
1694         case 2:
1695                 comres = bma2x2_smbus_read_byte(client,
1696                                 BMA2X2_STATUS_ORIENT_HIGH_REG, &data);
1697                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_FIRST_Z);
1698                 *intstatus = data;
1699                 break;
1700         default:
1701                 break;
1702         }
1703
1704         return comres;
1705 }
1706
1707 static int bma2x2_get_HIGH_sign(struct i2c_client *client, unsigned char
1708                 *intstatus)
1709 {
1710         int comres = 0;
1711         unsigned char data;
1712
1713         comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1714                         &data);
1715         data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_SIGN_S);
1716         *intstatus = data;
1717
1718         return comres;
1719 }
1720
1721
1722 static int bma2x2_get_slope_first(struct i2c_client *client, unsigned char
1723         param, unsigned char *intstatus)
1724 {
1725         int comres = 0;
1726         unsigned char data;
1727
1728         switch (param) {
1729         case 0:
1730                 comres = bma2x2_smbus_read_byte(client,
1731                                 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1732                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_X);
1733                 *intstatus = data;
1734                 break;
1735         case 1:
1736                 comres = bma2x2_smbus_read_byte(client,
1737                                 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1738                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_Y);
1739                 *intstatus = data;
1740                 break;
1741         case 2:
1742                 comres = bma2x2_smbus_read_byte(client,
1743                                 BMA2X2_STATUS_TAP_SLOPE_REG, &data);
1744                 data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_FIRST_Z);
1745                 *intstatus = data;
1746                 break;
1747         default:
1748                 break;
1749         }
1750
1751         return comres;
1752 }
1753
1754 static int bma2x2_get_slope_sign(struct i2c_client *client, unsigned char
1755                 *intstatus)
1756 {
1757         int comres = 0;
1758         unsigned char data;
1759
1760         comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_TAP_SLOPE_REG,
1761                         &data);
1762         data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_SIGN_S);
1763         *intstatus = data;
1764
1765         return comres;
1766 }
1767
1768 static int bma2x2_get_orient_status(struct i2c_client *client, unsigned char
1769                 *intstatus)
1770 {
1771         int comres = 0;
1772         unsigned char data;
1773
1774         comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1775                         &data);
1776         data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_S);
1777         *intstatus = data;
1778
1779         return comres;
1780 }
1781
1782 static int bma2x2_get_orient_flat_status(struct i2c_client *client, unsigned
1783                 char *intstatus)
1784 {
1785         int comres = 0;
1786         unsigned char data;
1787
1788         comres = bma2x2_smbus_read_byte(client, BMA2X2_STATUS_ORIENT_HIGH_REG,
1789                         &data);
1790         data = BMA2X2_GET_BITSLICE(data, BMA2X2_FLAT_S);
1791         *intstatus = data;
1792
1793         return comres;
1794 }
1795 #endif /* defined(BMA2X2_ENABLE_INT1)||defined(BMA2X2_ENABLE_INT2) */
1796 static int bma2x2_set_Int_Mode(struct i2c_client *client, unsigned char Mode)
1797 {
1798         int comres = 0;
1799         unsigned char data;
1800
1801
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);
1807
1808
1809         return comres;
1810 }
1811
1812 static int bma2x2_get_Int_Mode(struct i2c_client *client, unsigned char *Mode)
1813 {
1814         int comres = 0;
1815         unsigned char data;
1816
1817
1818         comres = bma2x2_smbus_read_byte(client,
1819                         BMA2X2_INT_MODE_SEL__REG, &data);
1820         data  = BMA2X2_GET_BITSLICE(data, BMA2X2_INT_MODE_SEL);
1821         *Mode = data;
1822
1823
1824         return comres;
1825 }
1826 static int bma2x2_set_slope_duration(struct i2c_client *client, unsigned char
1827                 duration)
1828 {
1829         int comres = 0;
1830         unsigned char data;
1831
1832
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);
1838
1839
1840         return comres;
1841 }
1842
1843 static int bma2x2_get_slope_duration(struct i2c_client *client, unsigned char
1844                 *status)
1845 {
1846         int comres = 0;
1847         unsigned char data;
1848
1849
1850         comres = bma2x2_smbus_read_byte(client,
1851                         BMA2X2_SLOPE_DURN_REG, &data);
1852         data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLOPE_DUR);
1853         *status = data;
1854
1855
1856         return comres;
1857 }
1858
1859 static int bma2x2_set_slope_no_mot_duration(struct i2c_client *client,
1860                         unsigned char duration)
1861 {
1862         int comres = 0;
1863         unsigned char data;
1864
1865
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);
1871
1872
1873         return comres;
1874 }
1875
1876 static int bma2x2_get_slope_no_mot_duration(struct i2c_client *client,
1877                         unsigned char *status)
1878 {
1879         int comres = 0;
1880         unsigned char data;
1881
1882
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);
1886         *status = data;
1887
1888
1889         return comres;
1890 }
1891
1892 static int bma2x2_set_slope_threshold(struct i2c_client *client,
1893                 unsigned char threshold)
1894 {
1895         int comres = 0;
1896         unsigned char data;
1897
1898         data = threshold;
1899         comres = bma2x2_smbus_write_byte(client,
1900                         BMA2X2_SLOPE_THRES__REG, &data);
1901
1902         return comres;
1903 }
1904
1905 static int bma2x2_get_slope_threshold(struct i2c_client *client,
1906                 unsigned char *status)
1907 {
1908         int comres = 0;
1909         unsigned char data;
1910
1911
1912         comres = bma2x2_smbus_read_byte(client,
1913                         BMA2X2_SLOPE_THRES_REG, &data);
1914         *status = data;
1915
1916         return comres;
1917 }
1918
1919 static int bma2x2_set_slope_no_mot_threshold(struct i2c_client *client,
1920                 unsigned char threshold)
1921 {
1922         int comres = 0;
1923         unsigned char data;
1924
1925         data = threshold;
1926         comres = bma2x2_smbus_write_byte(client,
1927                         BMA2X2_SLO_NO_MOT_THRES_REG, &data);
1928
1929         return comres;
1930 }
1931
1932 static int bma2x2_get_slope_no_mot_threshold(struct i2c_client *client,
1933                 unsigned char *status)
1934 {
1935         int comres = 0;
1936         unsigned char data;
1937
1938
1939         comres = bma2x2_smbus_read_byte(client,
1940                         BMA2X2_SLO_NO_MOT_THRES_REG, &data);
1941         *status = data;
1942
1943         return comres;
1944 }
1945
1946
1947 static int bma2x2_set_low_g_duration(struct i2c_client *client, unsigned char
1948                 duration)
1949 {
1950         int comres = 0;
1951         unsigned char data;
1952
1953         data = duration;
1954         comres = bma2x2_smbus_write_byte(client, BMA2X2_LOWG_DUR__REG, &data);
1955
1956         return comres;
1957 }
1958
1959 static int bma2x2_get_low_g_duration(struct i2c_client *client, unsigned char
1960                 *status)
1961 {
1962         int comres = 0;
1963         unsigned char data;
1964
1965         comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_DURN_REG, &data);
1966         data = BMA2X2_GET_BITSLICE(data, BMA2X2_LOWG_DUR);
1967         *status = data;
1968
1969         return comres;
1970 }
1971
1972 static int bma2x2_set_low_g_threshold(struct i2c_client *client, unsigned char
1973                 threshold)
1974 {
1975         int comres = 0;
1976         unsigned char data;
1977
1978         data = threshold;
1979         comres = bma2x2_smbus_write_byte(client, BMA2X2_LOWG_THRES__REG, &data);
1980
1981         return comres;
1982 }
1983
1984 static int bma2x2_get_low_g_threshold(struct i2c_client *client, unsigned char
1985                 *status)
1986 {
1987         int comres = 0;
1988         unsigned char data;
1989
1990         comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_THRES_REG, &data);
1991         data = BMA2X2_GET_BITSLICE(data, BMA2X2_LOWG_THRES);
1992         *status = data;
1993
1994         return comres;
1995 }
1996
1997 static int bma2x2_set_high_g_duration(struct i2c_client *client, unsigned char
1998                 duration)
1999 {
2000         int comres = 0;
2001         unsigned char data;
2002
2003         data = duration;
2004         comres = bma2x2_smbus_write_byte(client, BMA2X2_HIGHG_DUR__REG, &data);
2005
2006         return comres;
2007 }
2008
2009 static int bma2x2_get_high_g_duration(struct i2c_client *client, unsigned char
2010                 *status)
2011 {
2012         int comres = 0;
2013         unsigned char data;
2014
2015         comres = bma2x2_smbus_read_byte(client, BMA2X2_HIGH_DURN_REG, &data);
2016         data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_DUR);
2017         *status = data;
2018
2019         return comres;
2020 }
2021
2022 static int bma2x2_set_high_g_threshold(struct i2c_client *client, unsigned char
2023                 threshold)
2024 {
2025         int comres = 0;
2026         unsigned char data;
2027
2028         data = threshold;
2029         comres = bma2x2_smbus_write_byte(client, BMA2X2_HIGHG_THRES__REG,
2030                         &data);
2031
2032         return comres;
2033 }
2034
2035 static int bma2x2_get_high_g_threshold(struct i2c_client *client, unsigned char
2036                 *status)
2037 {
2038         int comres = 0;
2039         unsigned char data;
2040
2041         comres = bma2x2_smbus_read_byte(client, BMA2X2_HIGH_THRES_REG, &data);
2042         data = BMA2X2_GET_BITSLICE(data, BMA2X2_HIGHG_THRES);
2043         *status = data;
2044
2045         return comres;
2046 }
2047
2048
2049 static int bma2x2_set_tap_duration(struct i2c_client *client, unsigned char
2050                 duration)
2051 {
2052         int comres = 0;
2053         unsigned char data;
2054
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);
2058
2059         return comres;
2060 }
2061
2062 static int bma2x2_get_tap_duration(struct i2c_client *client, unsigned char
2063                 *status)
2064 {
2065         int comres = 0;
2066         unsigned char data;
2067
2068         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2069         data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_DUR);
2070         *status = data;
2071
2072         return comres;
2073 }
2074
2075 static int bma2x2_set_tap_shock(struct i2c_client *client, unsigned char setval)
2076 {
2077         int comres = 0;
2078         unsigned char data;
2079
2080         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_SHOCK_DURN__REG,
2081                         &data);
2082         data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_SHOCK_DURN, setval);
2083         comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_SHOCK_DURN__REG,
2084                         &data);
2085
2086         return comres;
2087 }
2088
2089 static int bma2x2_get_tap_shock(struct i2c_client *client, unsigned char
2090                 *status)
2091 {
2092         int comres = 0;
2093         unsigned char data;
2094
2095         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2096         data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_SHOCK_DURN);
2097         *status = data;
2098
2099         return comres;
2100 }
2101
2102 static int bma2x2_set_tap_quiet(struct i2c_client *client, unsigned char
2103                 duration)
2104 {
2105         int comres = 0;
2106         unsigned char data;
2107
2108         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_QUIET_DURN__REG,
2109                         &data);
2110         data = BMA2X2_SET_BITSLICE(data, BMA2X2_TAP_QUIET_DURN, duration);
2111         comres = bma2x2_smbus_write_byte(client, BMA2X2_TAP_QUIET_DURN__REG,
2112                         &data);
2113
2114         return comres;
2115 }
2116
2117 static int bma2x2_get_tap_quiet(struct i2c_client *client, unsigned char
2118                 *status)
2119 {
2120         int comres = 0;
2121         unsigned char data;
2122
2123         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_PARAM_REG, &data);
2124         data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_QUIET_DURN);
2125         *status = data;
2126
2127         return comres;
2128 }
2129
2130 static int bma2x2_set_tap_threshold(struct i2c_client *client, unsigned char
2131                 threshold)
2132 {
2133         int comres = 0;
2134         unsigned char data;
2135
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);
2139
2140         return comres;
2141 }
2142
2143 static int bma2x2_get_tap_threshold(struct i2c_client *client, unsigned char
2144                 *status)
2145 {
2146         int comres = 0;
2147         unsigned char data;
2148
2149         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_THRES_REG, &data);
2150         data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_THRES);
2151         *status = data;
2152
2153         return comres;
2154 }
2155
2156 static int bma2x2_set_tap_samp(struct i2c_client *client, unsigned char samp)
2157 {
2158         int comres = 0;
2159         unsigned char data;
2160
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,
2164                         &data);
2165
2166         return comres;
2167 }
2168
2169 static int bma2x2_get_tap_samp(struct i2c_client *client, unsigned char *status)
2170 {
2171         int comres = 0;
2172         unsigned char data;
2173
2174         comres = bma2x2_smbus_read_byte(client, BMA2X2_TAP_THRES_REG, &data);
2175         data = BMA2X2_GET_BITSLICE(data, BMA2X2_TAP_SAMPLES);
2176         *status = data;
2177
2178         return comres;
2179 }
2180
2181 static int bma2x2_set_orient_mode(struct i2c_client *client, unsigned char mode)
2182 {
2183         int comres = 0;
2184         unsigned char data;
2185
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,
2189                         &data);
2190
2191         return comres;
2192 }
2193
2194 static int bma2x2_get_orient_mode(struct i2c_client *client, unsigned char
2195                 *status)
2196 {
2197         int comres = 0;
2198         unsigned char data;
2199
2200         comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2201         data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_MODE);
2202         *status = data;
2203
2204         return comres;
2205 }
2206
2207 static int bma2x2_set_orient_blocking(struct i2c_client *client, unsigned char
2208                 samp)
2209 {
2210         int comres = 0;
2211         unsigned char data;
2212
2213         comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_BLOCK__REG,
2214                         &data);
2215         data = BMA2X2_SET_BITSLICE(data, BMA2X2_ORIENT_BLOCK, samp);
2216         comres = bma2x2_smbus_write_byte(client, BMA2X2_ORIENT_BLOCK__REG,
2217                         &data);
2218
2219         return comres;
2220 }
2221
2222 static int bma2x2_get_orient_blocking(struct i2c_client *client, unsigned char
2223                 *status)
2224 {
2225         int comres = 0;
2226         unsigned char data;
2227
2228         comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2229         data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_BLOCK);
2230         *status = data;
2231
2232         return comres;
2233 }
2234
2235 static int bma2x2_set_orient_hyst(struct i2c_client *client, unsigned char
2236                 orienthyst)
2237 {
2238         int comres = 0;
2239         unsigned char data;
2240
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,
2244                         &data);
2245
2246         return comres;
2247 }
2248
2249 static int bma2x2_get_orient_hyst(struct i2c_client *client, unsigned char
2250                 *status)
2251 {
2252         int comres = 0;
2253         unsigned char data;
2254
2255         comres = bma2x2_smbus_read_byte(client, BMA2X2_ORIENT_PARAM_REG, &data);
2256         data = BMA2X2_GET_BITSLICE(data, BMA2X2_ORIENT_HYST);
2257         *status = data;
2258
2259         return comres;
2260 }
2261 static int bma2x2_set_theta_blocking(struct i2c_client *client, unsigned char
2262                 thetablk)
2263 {
2264         int comres = 0;
2265         unsigned char data;
2266
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,
2270                         &data);
2271
2272         return comres;
2273 }
2274
2275 static int bma2x2_get_theta_blocking(struct i2c_client *client, unsigned char
2276                 *status)
2277 {
2278         int comres = 0;
2279         unsigned char data;
2280
2281         comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_BLOCK_REG, &data);
2282         data = BMA2X2_GET_BITSLICE(data, BMA2X2_THETA_BLOCK);
2283         *status = data;
2284
2285         return comres;
2286 }
2287
2288 static int bma2x2_set_theta_flat(struct i2c_client *client, unsigned char
2289                 thetaflat)
2290 {
2291         int comres = 0;
2292         unsigned char data;
2293
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);
2297
2298         return comres;
2299 }
2300
2301 static int bma2x2_get_theta_flat(struct i2c_client *client, unsigned char
2302                 *status)
2303 {
2304         int comres = 0 ;
2305         unsigned char data;
2306
2307         comres = bma2x2_smbus_read_byte(client, BMA2X2_THETA_FLAT_REG, &data);
2308         data = BMA2X2_GET_BITSLICE(data, BMA2X2_THETA_FLAT);
2309         *status = data;
2310
2311         return comres;
2312 }
2313
2314 static int bma2x2_set_flat_hold_time(struct i2c_client *client, unsigned char
2315                 holdtime)
2316 {
2317         int comres = 0;
2318         unsigned char data;
2319
2320         comres = bma2x2_smbus_read_byte(client, BMA2X2_FLAT_HOLD_TIME__REG,
2321                         &data);
2322         data = BMA2X2_SET_BITSLICE(data, BMA2X2_FLAT_HOLD_TIME, holdtime);
2323         comres = bma2x2_smbus_write_byte(client, BMA2X2_FLAT_HOLD_TIME__REG,
2324                         &data);
2325
2326         return comres;
2327 }
2328
2329 static int bma2x2_get_flat_hold_time(struct i2c_client *client, unsigned char
2330                 *holdtime)
2331 {
2332         int comres = 0;
2333         unsigned char data;
2334
2335         comres = bma2x2_smbus_read_byte(client, BMA2X2_FLAT_HOLD_TIME_REG,
2336                         &data);
2337         data  = BMA2X2_GET_BITSLICE(data, BMA2X2_FLAT_HOLD_TIME);
2338         *holdtime = data ;
2339
2340         return comres;
2341 }
2342
2343 static int bma2x2_set_mode(struct i2c_client *client, unsigned char Mode)
2344 {
2345         int comres = 0;
2346         unsigned char data1, data2;
2347
2348         if (Mode < 6) {
2349                 comres = bma2x2_smbus_read_byte(client, BMA2X2_MODE_CTRL_REG,
2350                                 &data1);
2351                 comres = bma2x2_smbus_read_byte(client,
2352                                 BMA2X2_LOW_NOISE_CTRL_REG,
2353                                 &data2);
2354                 switch (Mode) {
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);
2362                                 mdelay(1);
2363                                 bma2x2_smbus_write_byte(client,
2364                                         BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2365                                 break;
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);
2373                                 mdelay(1);
2374                                 bma2x2_smbus_write_byte(client,
2375                                         BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2376                                 break;
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);
2384                                 mdelay(1);
2385                                 bma2x2_smbus_write_byte(client,
2386                                         BMA2X2_MODE_CTRL_REG, &data1);
2387                                 break;
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);
2395                                 mdelay(1);
2396                                 bma2x2_smbus_write_byte(client,
2397                                         BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2398                                 break;
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);
2406                                 mdelay(1);
2407                                 bma2x2_smbus_write_byte(client,
2408                                         BMA2X2_LOW_NOISE_CTRL_REG, &data2);
2409                                 break;
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);
2417                                 mdelay(1);
2418                                 bma2x2_smbus_write_byte(client,
2419                                                 BMA2X2_MODE_CTRL_REG, &data1);
2420                 break;
2421                 }
2422         } else {
2423                 comres = -1 ;
2424         }
2425
2426
2427         return comres;
2428 }
2429
2430
2431 static int bma2x2_get_mode(struct i2c_client *client, unsigned char *Mode)
2432 {
2433         int comres = 0;
2434         unsigned char data1, data2;
2435
2436         comres = bma2x2_smbus_read_byte(client, BMA2X2_MODE_CTRL_REG, &data1);
2437         comres = bma2x2_smbus_read_byte(client, BMA2X2_LOW_NOISE_CTRL_REG,
2438                         &data2);
2439
2440         data1  = (data1 & 0xE0) >> 5;
2441         data2  = (data2 & 0x40) >> 6;
2442
2443
2444         if ((data1 == 0x00) && (data2 == 0x00)) {
2445                 *Mode  = BMA2X2_MODE_NORMAL;
2446         } else {
2447                 if ((data1 == 0x02) && (data2 == 0x00)) {
2448                         *Mode  = BMA2X2_MODE_LOWPOWER1;
2449                 } else {
2450                         if ((data1 == 0x04 || data1 == 0x06) &&
2451                                                 (data2 == 0x00)) {
2452                                 *Mode  = BMA2X2_MODE_SUSPEND;
2453                         } else {
2454                                 if (((data1 & 0x01) == 0x01)) {
2455                                         *Mode  = BMA2X2_MODE_DEEP_SUSPEND;
2456                                 } else {
2457                                         if ((data1 == 0x02) &&
2458                                                         (data2 == 0x01)) {
2459                                                 *Mode  = BMA2X2_MODE_LOWPOWER2;
2460                                         } else {
2461                                                 if ((data1 == 0x04) && (data2 ==
2462                                                                         0x01)) {
2463                                                         *Mode  =
2464                                                         BMA2X2_MODE_STANDBY;
2465                                                 } else {
2466                                                         *Mode =
2467                                                 BMA2X2_MODE_DEEP_SUSPEND;
2468                                                 }
2469                                         }
2470                                 }
2471                         }
2472                 }
2473         }
2474
2475         return comres;
2476 }
2477
2478 static int bma2x2_set_range(struct i2c_client *client, unsigned char Range)
2479 {
2480         int comres = 0 ;
2481         unsigned char data1;
2482
2483         if ((Range == 3) || (Range == 5) || (Range == 8) || (Range == 12)) {
2484                 comres = bma2x2_smbus_read_byte(client, BMA2X2_RANGE_SEL_REG,
2485                                 &data1);
2486                 switch (Range) {
2487                 case BMA2X2_RANGE_2G:
2488                         data1  = BMA2X2_SET_BITSLICE(data1,
2489                                         BMA2X2_RANGE_SEL, 3);
2490                         break;
2491                 case BMA2X2_RANGE_4G:
2492                         data1  = BMA2X2_SET_BITSLICE(data1,
2493                                         BMA2X2_RANGE_SEL, 5);
2494                         break;
2495                 case BMA2X2_RANGE_8G:
2496                         data1  = BMA2X2_SET_BITSLICE(data1,
2497                                         BMA2X2_RANGE_SEL, 8);
2498                         break;
2499                 case BMA2X2_RANGE_16G:
2500                         data1  = BMA2X2_SET_BITSLICE(data1,
2501                                         BMA2X2_RANGE_SEL, 12);
2502                         break;
2503                 }
2504                 comres += bma2x2_smbus_write_byte(client, BMA2X2_RANGE_SEL_REG,
2505                                 &data1);
2506         } else {
2507                 comres = -1 ;
2508         }
2509
2510         return comres;
2511 }
2512
2513 static int bma2x2_get_range(struct i2c_client *client, unsigned char *Range)
2514 {
2515         int comres = 0;
2516         unsigned char data;
2517
2518         comres = bma2x2_smbus_read_byte(client, BMA2X2_RANGE_SEL__REG, &data);
2519         data = BMA2X2_GET_BITSLICE(data, BMA2X2_RANGE_SEL);
2520         *Range = data;
2521
2522         return comres;
2523 }
2524
2525
2526 static int bma2x2_set_bandwidth(struct i2c_client *client, unsigned char BW)
2527 {
2528         int comres = 0;
2529         unsigned char data;
2530         int Bandwidth = 0;
2531
2532         if (BW > 7 && BW < 16) {
2533                 switch (BW) {
2534                 case BMA2X2_BW_7_81HZ:
2535                         Bandwidth = BMA2X2_BW_7_81HZ;
2536
2537                         /*  7.81 Hz      64000 uS   */
2538                         break;
2539                 case BMA2X2_BW_15_63HZ:
2540                         Bandwidth = BMA2X2_BW_15_63HZ;
2541
2542                         /*  15.63 Hz     32000 uS   */
2543                         break;
2544                 case BMA2X2_BW_31_25HZ:
2545                         Bandwidth = BMA2X2_BW_31_25HZ;
2546
2547                         /*  31.25 Hz     16000 uS   */
2548                         break;
2549                 case BMA2X2_BW_62_50HZ:
2550                         Bandwidth = BMA2X2_BW_62_50HZ;
2551
2552                         /*  62.50 Hz     8000 uS   */
2553                         break;
2554                 case BMA2X2_BW_125HZ:
2555                         Bandwidth = BMA2X2_BW_125HZ;
2556
2557                         /*  125 Hz       4000 uS   */
2558                         break;
2559                 case BMA2X2_BW_250HZ:
2560                         Bandwidth = BMA2X2_BW_250HZ;
2561
2562                         /*  250 Hz       2000 uS   */
2563                         break;
2564                 case BMA2X2_BW_500HZ:
2565                         Bandwidth = BMA2X2_BW_500HZ;
2566
2567                         /*  500 Hz       1000 uS   */
2568                         break;
2569                 case BMA2X2_BW_1000HZ:
2570                         Bandwidth = BMA2X2_BW_1000HZ;
2571
2572                         /*  1000 Hz      500 uS   */
2573                         break;
2574                 }
2575                 comres = bma2x2_smbus_read_byte(client, BMA2X2_BANDWIDTH__REG,
2576                                 &data);
2577                 data = BMA2X2_SET_BITSLICE(data, BMA2X2_BANDWIDTH, Bandwidth);
2578                 comres += bma2x2_smbus_write_byte(client, BMA2X2_BANDWIDTH__REG,
2579                                 &data);
2580         } else {
2581                 comres = -1 ;
2582         }
2583
2584         return comres;
2585 }
2586
2587 static int bma2x2_get_bandwidth(struct i2c_client *client, unsigned char *BW)
2588 {
2589         int comres = 0;
2590         unsigned char data;
2591
2592         comres = bma2x2_smbus_read_byte(client, BMA2X2_BANDWIDTH__REG, &data);
2593         data = BMA2X2_GET_BITSLICE(data, BMA2X2_BANDWIDTH);
2594         *BW = data ;
2595
2596         return comres;
2597 }
2598
2599 int bma2x2_get_sleep_duration(struct i2c_client *client, unsigned char
2600                 *sleep_dur)
2601 {
2602         int comres = 0;
2603         unsigned char data;
2604
2605         comres = bma2x2_smbus_read_byte(client,
2606                         BMA2X2_SLEEP_DUR__REG, &data);
2607         data = BMA2X2_GET_BITSLICE(data, BMA2X2_SLEEP_DUR);
2608         *sleep_dur = data;
2609
2610         return comres;
2611 }
2612
2613 int bma2x2_set_sleep_duration(struct i2c_client *client, unsigned char
2614                 sleep_dur)
2615 {
2616         int comres = 0;
2617         unsigned char data;
2618         int sleep_duration = 0;
2619
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;
2624
2625                         /*  0.5 MS   */
2626                         break;
2627                 case BMA2X2_SLEEP_DUR_1MS:
2628                         sleep_duration = BMA2X2_SLEEP_DUR_1MS;
2629
2630                         /*  1 MS  */
2631                         break;
2632                 case BMA2X2_SLEEP_DUR_2MS:
2633                         sleep_duration = BMA2X2_SLEEP_DUR_2MS;
2634
2635                         /*  2 MS  */
2636                         break;
2637                 case BMA2X2_SLEEP_DUR_4MS:
2638                         sleep_duration = BMA2X2_SLEEP_DUR_4MS;
2639
2640                         /*  4 MS   */
2641                         break;
2642                 case BMA2X2_SLEEP_DUR_6MS:
2643                         sleep_duration = BMA2X2_SLEEP_DUR_6MS;
2644
2645                         /*  6 MS  */
2646                         break;
2647                 case BMA2X2_SLEEP_DUR_10MS:
2648                         sleep_duration = BMA2X2_SLEEP_DUR_10MS;
2649
2650                         /*  10 MS  */
2651                         break;
2652                 case BMA2X2_SLEEP_DUR_25MS:
2653                         sleep_duration = BMA2X2_SLEEP_DUR_25MS;
2654
2655                         /*  25 MS  */
2656                         break;
2657                 case BMA2X2_SLEEP_DUR_50MS:
2658                         sleep_duration = BMA2X2_SLEEP_DUR_50MS;
2659
2660                         /*  50 MS   */
2661                         break;
2662                 case BMA2X2_SLEEP_DUR_100MS:
2663                         sleep_duration = BMA2X2_SLEEP_DUR_100MS;
2664
2665                         /*  100 MS  */
2666                         break;
2667                 case BMA2X2_SLEEP_DUR_500MS:
2668                         sleep_duration = BMA2X2_SLEEP_DUR_500MS;
2669
2670                         /*  500 MS   */
2671                         break;
2672                 case BMA2X2_SLEEP_DUR_1S:
2673                         sleep_duration = BMA2X2_SLEEP_DUR_1S;
2674
2675                         /*  1 SECS   */
2676                         break;
2677                 }
2678                 comres = bma2x2_smbus_read_byte(client, BMA2X2_SLEEP_DUR__REG,
2679                                 &data);
2680                 data = BMA2X2_SET_BITSLICE(data, BMA2X2_SLEEP_DUR,
2681                                 sleep_duration);
2682                 comres = bma2x2_smbus_write_byte(client, BMA2X2_SLEEP_DUR__REG,
2683                                 &data);
2684         } else {
2685                 comres = -1 ;
2686         }
2687
2688
2689         return comres;
2690 }
2691
2692 static int bma2x2_get_fifo_mode(struct i2c_client *client, unsigned char
2693                 *fifo_mode)
2694 {
2695         int comres;
2696         unsigned char data;
2697
2698         comres = bma2x2_smbus_read_byte(client, BMA2X2_FIFO_MODE__REG, &data);
2699         *fifo_mode = BMA2X2_GET_BITSLICE(data, BMA2X2_FIFO_MODE);
2700
2701         return comres;
2702 }
2703
2704 static int bma2x2_set_fifo_mode(struct i2c_client *client, unsigned char
2705                 fifo_mode)
2706 {
2707         unsigned char data;
2708         int comres = 0;
2709
2710         if (fifo_mode < 4) {
2711                 comres = bma2x2_smbus_read_byte(client, BMA2X2_FIFO_MODE__REG,
2712                                 &data);
2713                 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_MODE, fifo_mode);
2714                 comres = bma2x2_smbus_write_byte(client, BMA2X2_FIFO_MODE__REG,
2715                                 &data);
2716         } else {
2717                 comres = -1 ;
2718         }
2719
2720         return comres;
2721 }
2722
2723
2724 static int bma2x2_get_fifo_trig(struct i2c_client *client, unsigned char
2725                 *fifo_trig)
2726 {
2727         int comres;
2728         unsigned char data;
2729
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);
2733
2734         return comres;
2735 }
2736
2737 static int bma2x2_set_fifo_trig(struct i2c_client *client, unsigned char
2738                 fifo_trig)
2739 {
2740         unsigned char data;
2741         int comres = 0;
2742
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,
2747                                 fifo_trig);
2748                 comres = bma2x2_smbus_write_byte(client,
2749                                 BMA2X2_FIFO_TRIGGER_ACTION__REG, &data);
2750         } else {
2751                 comres = -1 ;
2752         }
2753
2754         return comres;
2755 }
2756
2757 static int bma2x2_get_fifo_trig_src(struct i2c_client *client, unsigned char
2758                 *trig_src)
2759 {
2760         int comres;
2761         unsigned char data;
2762
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);
2766
2767         return comres;
2768 }
2769
2770
2771 static int bma2x2_set_fifo_trig_src(struct i2c_client *client, unsigned char
2772                 trig_src)
2773 {
2774         unsigned char data;
2775         int comres = 0;
2776
2777         if (trig_src < 4) {
2778                 comres = bma2x2_smbus_read_byte(client,
2779                                 BMA2X2_FIFO_TRIGGER_SOURCE__REG, &data);
2780                 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_TRIGGER_SOURCE,
2781                                 trig_src);
2782                 comres = bma2x2_smbus_write_byte(client,
2783                                 BMA2X2_FIFO_TRIGGER_SOURCE__REG, &data);
2784         } else {
2785                 comres = -1 ;
2786         }
2787
2788         return comres;
2789 }
2790
2791 static int bma2x2_get_fifo_framecount(struct i2c_client *client, unsigned char
2792                          *framecount)
2793 {
2794         int comres = 0;
2795         unsigned char data;
2796
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);
2800
2801         return comres;
2802 }
2803
2804 static int bma2x2_get_fifo_data_sel(struct i2c_client *client, unsigned char
2805                 *data_sel)
2806 {
2807         int comres;
2808         unsigned char data;
2809
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);
2813
2814         return comres;
2815 }
2816
2817 static int bma2x2_set_fifo_data_sel(struct i2c_client *client, unsigned char
2818                 data_sel)
2819 {
2820         unsigned char data;
2821         int comres = 0;
2822
2823         if (data_sel < 4) {
2824                 comres = bma2x2_smbus_read_byte(client,
2825                                 BMA2X2_FIFO_DATA_SELECT__REG,
2826                                 &data);
2827                 data = BMA2X2_SET_BITSLICE(data, BMA2X2_FIFO_DATA_SELECT,
2828                                 data_sel);
2829                 comres = bma2x2_smbus_write_byte(client,
2830                                 BMA2X2_FIFO_DATA_SELECT__REG,
2831                                 &data);
2832         } else {
2833                 comres = -1 ;
2834         }
2835
2836         return comres;
2837 }
2838
2839 static int bma2x2_get_fifo_data_out_reg(struct i2c_client *client, unsigned char
2840                 *out_reg)
2841 {
2842         unsigned char data;
2843         int comres = 0;
2844
2845         comres = bma2x2_smbus_read_byte(client,
2846                                 BMA2X2_FIFO_DATA_OUTPUT_REG, &data);
2847         *out_reg = data;
2848
2849         return comres;
2850 }
2851
2852 static int bma2x2_get_offset_target(struct i2c_client *client, unsigned char
2853                 channel, unsigned char *offset)
2854 {
2855         unsigned char data;
2856         int comres = 0;
2857
2858         switch (channel) {
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);
2863                 break;
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);
2869                 break;
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);
2875                 break;
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);
2881                 break;
2882         default:
2883                 comres = -1;
2884                 break;
2885         }
2886
2887         return comres;
2888 }
2889
2890 static int bma2x2_set_offset_target(struct i2c_client *client, unsigned char
2891                 channel, unsigned char offset)
2892 {
2893         unsigned char data;
2894         int comres = 0;
2895
2896         switch (channel) {
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,
2901                                 offset);
2902                 comres = bma2x2_smbus_write_byte(client,
2903                                 BMA2X2_COMP_CUTOFF__REG, &data);
2904                 break;
2905         case BMA2X2_OFFSET_TRIGGER_X:
2906                 comres = bma2x2_smbus_read_byte(client,
2907                                 BMA2X2_COMP_TARGET_OFFSET_X__REG,
2908                                 &data);
2909                 data = BMA2X2_SET_BITSLICE(data,
2910                                 BMA2X2_COMP_TARGET_OFFSET_X,
2911                                 offset);
2912                 comres = bma2x2_smbus_write_byte(client,
2913                                 BMA2X2_COMP_TARGET_OFFSET_X__REG,
2914                                 &data);
2915                 break;
2916         case BMA2X2_OFFSET_TRIGGER_Y:
2917                 comres = bma2x2_smbus_read_byte(client,
2918                                 BMA2X2_COMP_TARGET_OFFSET_Y__REG,
2919                                 &data);
2920                 data = BMA2X2_SET_BITSLICE(data,
2921                                 BMA2X2_COMP_TARGET_OFFSET_Y,
2922                                 offset);
2923                 comres = bma2x2_smbus_write_byte(client,
2924                                 BMA2X2_COMP_TARGET_OFFSET_Y__REG,
2925                                 &data);
2926                 break;
2927         case BMA2X2_OFFSET_TRIGGER_Z:
2928                 comres = bma2x2_smbus_read_byte(client,
2929                                 BMA2X2_COMP_TARGET_OFFSET_Z__REG,
2930                                 &data);
2931                 data = BMA2X2_SET_BITSLICE(data,
2932                                 BMA2X2_COMP_TARGET_OFFSET_Z,
2933                                 offset);
2934                 comres = bma2x2_smbus_write_byte(client,
2935                                 BMA2X2_COMP_TARGET_OFFSET_Z__REG,
2936                                 &data);
2937                 break;
2938         default:
2939                 comres = -1;
2940                 break;
2941         }
2942
2943         return comres;
2944 }
2945
2946 static int bma2x2_get_cal_ready(struct i2c_client *client, unsigned char *calrdy
2947                 )
2948 {
2949         int comres = 0 ;
2950         unsigned char data;
2951
2952         comres = bma2x2_smbus_read_byte(client, BMA2X2_FAST_CAL_RDY_S__REG,
2953                         &data);
2954         data = BMA2X2_GET_BITSLICE(data, BMA2X2_FAST_CAL_RDY_S);
2955         *calrdy = data;
2956
2957         return comres;
2958 }
2959
2960 static int bma2x2_set_cal_trigger(struct i2c_client *client, unsigned char
2961                 caltrigger)
2962 {
2963         int comres = 0;
2964         unsigned char data;
2965
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,
2969                         &data);
2970
2971         return comres;
2972 }
2973
2974 static int bma2x2_write_reg(struct i2c_client *client, unsigned char addr,
2975                 unsigned char *data)
2976 {
2977         int comres = 0 ;
2978         comres = bma2x2_smbus_write_byte(client, addr, data);
2979
2980         return comres;
2981 }
2982
2983
2984 static int bma2x2_set_offset_x(struct i2c_client *client, unsigned char
2985                 offsetfilt)
2986 {
2987         int comres = 0;
2988         unsigned char data;
2989
2990         data =  offsetfilt;
2991         comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_X_AXIS_REG,
2992                                                 &data);
2993
2994         return comres;
2995 }
2996
2997
2998 static int bma2x2_get_offset_x(struct i2c_client *client, unsigned char
2999                                                 *offsetfilt)
3000 {
3001         int comres = 0;
3002         unsigned char data;
3003
3004         comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_X_AXIS_REG,
3005                                                 &data);
3006         *offsetfilt = data;
3007
3008         return comres;
3009 }
3010
3011 static int bma2x2_set_offset_y(struct i2c_client *client, unsigned char
3012                                                 offsetfilt)
3013 {
3014         int comres = 0;
3015         unsigned char data;
3016
3017         data =  offsetfilt;
3018         comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_Y_AXIS_REG,
3019                                                 &data);
3020
3021         return comres;
3022 }
3023
3024 static int bma2x2_get_offset_y(struct i2c_client *client, unsigned char
3025                                                 *offsetfilt)
3026 {
3027         int comres = 0;
3028         unsigned char data;
3029
3030         comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_Y_AXIS_REG,
3031                                                 &data);
3032         *offsetfilt = data;
3033
3034         return comres;
3035 }
3036
3037 static int bma2x2_set_offset_z(struct i2c_client *client, unsigned char
3038                                                 offsetfilt)
3039 {
3040         int comres = 0;
3041         unsigned char data;
3042
3043         data =  offsetfilt;
3044         comres = bma2x2_smbus_write_byte(client, BMA2X2_OFFSET_Z_AXIS_REG,
3045                                                 &data);
3046
3047         return comres;
3048 }
3049
3050 static int bma2x2_get_offset_z(struct i2c_client *client, unsigned char
3051                                                 *offsetfilt)
3052 {
3053         int comres = 0;
3054         unsigned char data;
3055
3056         comres = bma2x2_smbus_read_byte(client, BMA2X2_OFFSET_Z_AXIS_REG,
3057                                                 &data);
3058         *offsetfilt = data;
3059
3060         return comres;
3061 }
3062
3063
3064 static int bma2x2_set_selftest_st(struct i2c_client *client, unsigned char
3065                 selftest)
3066 {
3067         int comres = 0;
3068         unsigned char data;
3069
3070         comres = bma2x2_smbus_read_byte(client, BMA2X2_EN_SELF_TEST__REG,
3071                         &data);
3072         data = BMA2X2_SET_BITSLICE(data, BMA2X2_EN_SELF_TEST, selftest);
3073         comres = bma2x2_smbus_write_byte(client, BMA2X2_EN_SELF_TEST__REG,
3074                         &data);
3075
3076         return comres;
3077 }
3078
3079 static int bma2x2_set_selftest_stn(struct i2c_client *client, unsigned char stn)
3080 {
3081         int comres = 0;
3082         unsigned char data;
3083
3084         comres = bma2x2_smbus_read_byte(client, BMA2X2_NEG_SELF_TEST__REG,
3085                         &data);
3086         data = BMA2X2_SET_BITSLICE(data, BMA2X2_NEG_SELF_TEST, stn);
3087         comres = bma2x2_smbus_write_byte(client, BMA2X2_NEG_SELF_TEST__REG,
3088                         &data);
3089
3090         return comres;
3091 }
3092
3093 static int bma2x2_set_selftest_amp(struct i2c_client *client, unsigned char amp)
3094 {
3095         int comres = 0;
3096         unsigned char data;
3097
3098         comres = bma2x2_smbus_read_byte(client, BMA2X2_SELF_TEST_AMP__REG,
3099                         &data);
3100         data = BMA2X2_SET_BITSLICE(data, BMA2X2_SELF_TEST_AMP, amp);
3101         comres = bma2x2_smbus_write_byte(client, BMA2X2_SELF_TEST_AMP__REG,
3102                         &data);
3103
3104         return comres;
3105 }
3106
3107 static int bma2x2_read_accel_x(struct i2c_client *client,
3108                                 signed char sensor_type, short *a_x)
3109 {
3110         int comres = 0;
3111         unsigned char data[2];
3112
3113         switch (sensor_type) {
3114         case 0:
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));
3124                 break;
3125         case 1:
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));
3135                 break;
3136         case 2:
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));
3146                 break;
3147         case 3:
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));
3157                 break;
3158         default:
3159                 break;
3160         }
3161
3162         return comres;
3163 }
3164
3165 static int bma2x2_soft_reset(struct i2c_client *client)
3166 {
3167         int comres = 0;
3168         unsigned char data = BMA2X2_EN_SOFT_RESET_VALUE ;
3169
3170         comres = bma2x2_smbus_write_byte(client, BMA2X2_EN_SOFT_RESET__REG,
3171                                         &data);
3172
3173         return comres;
3174 }
3175
3176 static int bma2x2_read_accel_y(struct i2c_client *client,
3177                                 signed char sensor_type, short *a_y)
3178 {
3179         int comres = 0;
3180         unsigned char data[2];
3181
3182         switch (sensor_type) {
3183         case 0:
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));
3193                 break;
3194         case 1:
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));
3204                 break;
3205         case 2:
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));
3215                 break;
3216         case 3:
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));
3226                 break;
3227         default:
3228                 break;
3229         }
3230
3231         return comres;
3232 }
3233
3234 static int bma2x2_read_accel_z(struct i2c_client *client,
3235                                 signed char sensor_type, short *a_z)
3236 {
3237         int comres = 0;
3238         unsigned char data[2];
3239
3240         switch (sensor_type) {
3241         case 0:
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));
3251                 break;
3252         case 1:
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));
3262                 break;
3263         case 2:
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));
3273                 break;
3274         case 3:
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));
3284                 break;
3285         default:
3286                 break;
3287         }
3288
3289         return comres;
3290 }
3291
3292
3293 static int bma2x2_read_temperature(struct i2c_client *client,
3294                                         signed char *temperature)
3295 {
3296         unsigned char data;
3297         int comres = 0;
3298
3299         comres = bma2x2_smbus_read_byte(client, BMA2X2_TEMPERATURE_REG, &data);
3300         *temperature = (signed char)data;
3301
3302         return comres;
3303 }
3304
3305 static int bma2x2_open_cal(struct i2c_client *client)
3306 {
3307         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3308
3309         int cal_data[3];
3310         int err;
3311         mm_segment_t old_fs;
3312         struct file *cal_filp = NULL;
3313
3314         old_fs = get_fs();
3315         set_fs(KERNEL_DS);
3316
3317         cal_filp = filp_open(CALIBRATION_FILE_PATH,
3318                 O_RDONLY, 0666);
3319         if (IS_ERR(cal_filp)) {
3320                 pr_err("[BMC150] %s: Can't open calibration file\n",
3321                         __func__);
3322                 set_fs(old_fs);
3323                 err = PTR_ERR(cal_filp);
3324                 return err;
3325         }
3326
3327         err = cal_filp->f_op->read(cal_filp,
3328                 (char *)cal_data,
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",
3332                         __func__);
3333                 filp_close(cal_filp, current->files);
3334                 set_fs(old_fs);
3335                 return -EIO;
3336         }
3337
3338         printk(KERN_INFO "[BMC150] %s (%d,%d,%d)",__func__, cal_data[0],cal_data[1],cal_data[2]);
3339
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]);
3343
3344         return 0;
3345
3346 }
3347 static ssize_t bma2x2_enable_int_store(struct device *dev,
3348                 struct device_attribute *attr,
3349                 const char *buf, size_t count)
3350 {
3351         int type, value;
3352         struct i2c_client *client = to_i2c_client(dev);
3353         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3354
3355         sscanf(buf, "%d%d", &type, &value);
3356
3357         if (bma2x2_set_Int_Enable(bma2x2->bma2x2_client, type, value) < 0)
3358                 return -EINVAL;
3359
3360         return count;
3361 }
3362
3363
3364 static ssize_t bma2x2_int_mode_show(struct device *dev,
3365                 struct device_attribute *attr, char *buf)
3366 {
3367         unsigned char data;
3368         struct i2c_client *client = to_i2c_client(dev);
3369         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3370
3371         if (bma2x2_get_Int_Mode(bma2x2->bma2x2_client, &data) < 0)
3372                 return sprintf(buf, "Read error\n");
3373
3374         return sprintf(buf, "%d\n", data);
3375 }
3376
3377 static ssize_t bma2x2_int_mode_store(struct device *dev,
3378                 struct device_attribute *attr,
3379                 const char *buf, size_t count)
3380 {
3381         unsigned long data;
3382         int error;
3383         struct i2c_client *client = to_i2c_client(dev);
3384         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3385
3386         error = strict_strtoul(buf, 10, &data);
3387         if (error)
3388                 return error;
3389
3390         if (bma2x2_set_Int_Mode(bma2x2->bma2x2_client, (unsigned char)data) < 0)
3391                 return -EINVAL;
3392
3393         return count;
3394 }
3395 static ssize_t bma2x2_slope_duration_show(struct device *dev,
3396                 struct device_attribute *attr, char *buf)
3397 {
3398         unsigned char data;
3399         struct i2c_client *client = to_i2c_client(dev);
3400         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3401
3402         if (bma2x2_get_slope_duration(bma2x2->bma2x2_client, &data) < 0)
3403                 return sprintf(buf, "Read error\n");
3404
3405         return sprintf(buf, "%d\n", data);
3406
3407 }
3408
3409 static ssize_t bma2x2_slope_duration_store(struct device *dev,
3410                 struct device_attribute *attr,
3411                 const char *buf, size_t count)
3412 {
3413         unsigned long data;
3414         int error;
3415         struct i2c_client *client = to_i2c_client(dev);
3416         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3417
3418         error = strict_strtoul(buf, 10, &data);
3419         if (error)
3420                 return error;
3421
3422         if (bma2x2_set_slope_duration(bma2x2->bma2x2_client, (unsigned
3423                                         char)data) < 0)
3424                 return -EINVAL;
3425
3426         return count;
3427 }
3428
3429 static ssize_t bma2x2_slope_no_mot_duration_show(struct device *dev,
3430                 struct device_attribute *attr, char *buf)
3431 {
3432         unsigned char data;
3433         struct i2c_client *client = to_i2c_client(dev);
3434         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3435
3436         if (bma2x2_get_slope_no_mot_duration(bma2x2->bma2x2_client, &data) < 0)
3437                 return sprintf(buf, "Read error\n");
3438
3439         return sprintf(buf, "%d\n", data);
3440
3441 }
3442
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)
3446 {
3447         unsigned long data;
3448         int error;
3449         struct i2c_client *client = to_i2c_client(dev);
3450         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3451
3452         error = strict_strtoul(buf, 10, &data);
3453         if (error)
3454                 return error;
3455
3456         if (bma2x2_set_slope_no_mot_duration(bma2x2->bma2x2_client, (unsigned
3457                                         char)data) < 0)
3458                 return -EINVAL;
3459
3460         return count;
3461 }
3462
3463
3464 static ssize_t bma2x2_slope_threshold_show(struct device *dev,
3465                 struct device_attribute *attr, char *buf)
3466 {
3467         unsigned char data;
3468         struct i2c_client *client = to_i2c_client(dev);
3469         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3470
3471         if (bma2x2_get_slope_threshold(bma2x2->bma2x2_client, &data) < 0)
3472                 return sprintf(buf, "Read error\n");
3473
3474         return sprintf(buf, "%d\n", data);
3475
3476 }
3477
3478 static ssize_t bma2x2_slope_threshold_store(struct device *dev,
3479                 struct device_attribute *attr,
3480                 const char *buf, size_t count)
3481 {
3482         unsigned long data;
3483         int error;
3484         struct i2c_client *client = to_i2c_client(dev);
3485         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3486
3487         error = strict_strtoul(buf, 10, &data);
3488         if (error)
3489                 return error;
3490         if (bma2x2_set_slope_threshold(bma2x2->bma2x2_client, (unsigned
3491                                         char)data) < 0)
3492                 return -EINVAL;
3493
3494         return count;
3495 }
3496
3497 static ssize_t bma2x2_slope_no_mot_threshold_show(struct device *dev,
3498                 struct device_attribute *attr, char *buf)
3499 {
3500         unsigned char data;
3501         struct i2c_client *client = to_i2c_client(dev);
3502         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3503
3504         if (bma2x2_get_slope_no_mot_threshold(bma2x2->bma2x2_client, &data) < 0)
3505                 return sprintf(buf, "Read error\n");
3506
3507         return sprintf(buf, "%d\n", data);
3508
3509 }
3510
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)
3514 {
3515         unsigned long data;
3516         int error;
3517         struct i2c_client *client = to_i2c_client(dev);
3518         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3519
3520         error = strict_strtoul(buf, 10, &data);
3521         if (error)
3522                 return error;
3523         if (bma2x2_set_slope_no_mot_threshold(bma2x2->bma2x2_client, (unsigned
3524                                         char)data) < 0)
3525                 return -EINVAL;
3526
3527         return count;
3528 }
3529
3530 static ssize_t bma2x2_high_g_duration_show(struct device *dev,
3531                 struct device_attribute *attr, char *buf)
3532 {
3533         unsigned char data;
3534         struct i2c_client *client = to_i2c_client(dev);
3535         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3536
3537         if (bma2x2_get_high_g_duration(bma2x2->bma2x2_client, &data) < 0)
3538                 return sprintf(buf, "Read error\n");
3539
3540         return sprintf(buf, "%d\n", data);
3541
3542 }
3543
3544 static ssize_t bma2x2_high_g_duration_store(struct device *dev,
3545                 struct device_attribute *attr,
3546                 const char *buf, size_t count)
3547 {
3548         unsigned long data;
3549         int error;
3550         struct i2c_client *client = to_i2c_client(dev);
3551         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3552
3553         error = strict_strtoul(buf, 10, &data);
3554         if (error)
3555                 return error;
3556
3557         if (bma2x2_set_high_g_duration(bma2x2->bma2x2_client, (unsigned
3558                                         char)data) < 0)
3559                 return -EINVAL;
3560
3561         return count;
3562 }
3563
3564 static ssize_t bma2x2_high_g_threshold_show(struct device *dev,
3565                 struct device_attribute *attr, char *buf)
3566 {
3567         unsigned char data;
3568         struct i2c_client *client = to_i2c_client(dev);
3569         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3570
3571         if (bma2x2_get_high_g_threshold(bma2x2->bma2x2_client, &data) < 0)
3572                 return sprintf(buf, "Read error\n");
3573
3574         return sprintf(buf, "%d\n", data);
3575
3576 }
3577
3578 static ssize_t bma2x2_high_g_threshold_store(struct device *dev,
3579                 struct device_attribute *attr,
3580                 const char *buf, size_t count)
3581 {
3582         unsigned long data;
3583         int error;
3584         struct i2c_client *client = to_i2c_client(dev);
3585         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3586
3587         error = strict_strtoul(buf, 10, &data);
3588         if (error)
3589                 return error;
3590         if (bma2x2_set_high_g_threshold(bma2x2->bma2x2_client, (unsigned
3591                                         char)data) < 0)
3592                 return -EINVAL;
3593
3594         return count;
3595 }
3596
3597 static ssize_t bma2x2_low_g_duration_show(struct device *dev,
3598                 struct device_attribute *attr, char *buf)
3599 {
3600         unsigned char data;
3601         struct i2c_client *client = to_i2c_client(dev);
3602         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3603
3604         if (bma2x2_get_low_g_duration(bma2x2->bma2x2_client, &data) < 0)
3605                 return sprintf(buf, "Read error\n");
3606
3607         return sprintf(buf, "%d\n", data);
3608
3609 }
3610
3611 static ssize_t bma2x2_low_g_duration_store(struct device *dev,
3612                 struct device_attribute *attr,
3613                 const char *buf, size_t count)
3614 {
3615         unsigned long data;
3616         int error;
3617         struct i2c_client *client = to_i2c_client(dev);
3618         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3619
3620         error = strict_strtoul(buf, 10, &data);
3621         if (error)
3622                 return error;
3623
3624         if (bma2x2_set_low_g_duration(bma2x2->bma2x2_client, (unsigned
3625                                         char)data) < 0)
3626                 return -EINVAL;
3627
3628         return count;
3629 }
3630
3631 static ssize_t bma2x2_low_g_threshold_show(struct device *dev,
3632                 struct device_attribute *attr, char *buf)
3633 {
3634         unsigned char data;
3635         struct i2c_client *client = to_i2c_client(dev);
3636         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3637
3638         if (bma2x2_get_low_g_threshold(bma2x2->bma2x2_client, &data) < 0)
3639                 return sprintf(buf, "Read error\n");
3640
3641         return sprintf(buf, "%d\n", data);
3642
3643 }
3644
3645 static ssize_t bma2x2_low_g_threshold_store(struct device *dev,
3646                 struct device_attribute *attr,
3647                 const char *buf, size_t count)
3648 {
3649         unsigned long data;
3650         int error;
3651         struct i2c_client *client = to_i2c_client(dev);
3652         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3653
3654         error = strict_strtoul(buf, 10, &data);
3655         if (error)
3656                 return error;
3657         if (bma2x2_set_low_g_threshold(bma2x2->bma2x2_client, (unsigned
3658                                         char)data) < 0)
3659                 return -EINVAL;
3660
3661         return count;
3662 }
3663 static ssize_t bma2x2_tap_threshold_show(struct device *dev,
3664                 struct device_attribute *attr, char *buf)
3665 {
3666         unsigned char data;
3667         struct i2c_client *client = to_i2c_client(dev);
3668         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3669
3670         if (bma2x2_get_tap_threshold(bma2x2->bma2x2_client, &data) < 0)
3671                 return sprintf(buf, "Read error\n");
3672
3673         return sprintf(buf, "%d\n", data);
3674
3675 }
3676
3677 static ssize_t bma2x2_tap_threshold_store(struct device *dev,
3678                 struct device_attribute *attr,
3679                 const char *buf, size_t count)
3680 {
3681         unsigned long data;
3682         int error;
3683         struct i2c_client *client = to_i2c_client(dev);
3684         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3685
3686         error = strict_strtoul(buf, 10, &data);
3687         if (error)
3688                 return error;
3689         if (bma2x2_set_tap_threshold(bma2x2->bma2x2_client, (unsigned char)data)
3690                         < 0)
3691                 return -EINVAL;
3692
3693         return count;
3694 }
3695 static ssize_t bma2x2_tap_duration_show(struct device *dev,
3696                 struct device_attribute *attr, char *buf)
3697 {
3698         unsigned char data;
3699         struct i2c_client *client = to_i2c_client(dev);
3700         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3701
3702         if (bma2x2_get_tap_duration(bma2x2->bma2x2_client, &data) < 0)
3703                 return sprintf(buf, "Read error\n");
3704
3705         return sprintf(buf, "%d\n", data);
3706
3707 }
3708
3709 static ssize_t bma2x2_tap_duration_store(struct device *dev,
3710                 struct device_attribute *attr,
3711                 const char *buf, size_t count)
3712 {
3713         unsigned long data;
3714         int error;
3715         struct i2c_client *client = to_i2c_client(dev);
3716         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3717
3718         error = strict_strtoul(buf, 10, &data);
3719         if (error)
3720                 return error;
3721
3722         if (bma2x2_set_tap_duration(bma2x2->bma2x2_client, (unsigned char)data)
3723                         < 0)
3724                 return -EINVAL;
3725
3726         return count;
3727 }
3728 static ssize_t bma2x2_tap_quiet_show(struct device *dev,
3729                 struct device_attribute *attr, char *buf)
3730 {
3731         unsigned char data;
3732         struct i2c_client *client = to_i2c_client(dev);
3733         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3734
3735         if (bma2x2_get_tap_quiet(bma2x2->bma2x2_client, &data) < 0)
3736                 return sprintf(buf, "Read error\n");
3737
3738         return sprintf(buf, "%d\n", data);
3739
3740 }
3741
3742 static ssize_t bma2x2_tap_quiet_store(struct device *dev,
3743                 struct device_attribute *attr,
3744                 const char *buf, size_t count)
3745 {
3746         unsigned long data;
3747         int error;
3748         struct i2c_client *client = to_i2c_client(dev);
3749         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3750
3751         error = strict_strtoul(buf, 10, &data);
3752         if (error)
3753                 return error;
3754
3755         if (bma2x2_set_tap_quiet(bma2x2->bma2x2_client, (unsigned char)data) <
3756                         0)
3757                 return -EINVAL;
3758
3759         return count;
3760 }
3761
3762 static ssize_t bma2x2_tap_shock_show(struct device *dev,
3763                 struct device_attribute *attr, char *buf)
3764 {
3765         unsigned char data;
3766         struct i2c_client *client = to_i2c_client(dev);
3767         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3768
3769         if (bma2x2_get_tap_shock(bma2x2->bma2x2_client, &data) < 0)
3770                 return sprintf(buf, "Read error\n");
3771
3772         return sprintf(buf, "%d\n", data);
3773
3774 }
3775
3776 static ssize_t bma2x2_tap_shock_store(struct device *dev,
3777                 struct device_attribute *attr,
3778                 const char *buf, size_t count)
3779 {
3780         unsigned long data;
3781         int error;
3782         struct i2c_client *client = to_i2c_client(dev);
3783         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3784
3785         error = strict_strtoul(buf, 10, &data);
3786         if (error)
3787                 return error;
3788
3789         if (bma2x2_set_tap_shock(bma2x2->bma2x2_client, (unsigned char)data) <
3790                         0)
3791                 return -EINVAL;
3792
3793         return count;
3794 }
3795
3796 static ssize_t bma2x2_tap_samp_show(struct device *dev,
3797                 struct device_attribute *attr, char *buf)
3798 {
3799         unsigned char data;
3800         struct i2c_client *client = to_i2c_client(dev);
3801         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3802
3803         if (bma2x2_get_tap_samp(bma2x2->bma2x2_client, &data) < 0)
3804                 return sprintf(buf, "Read error\n");
3805
3806         return sprintf(buf, "%d\n", data);
3807
3808 }
3809
3810 static ssize_t bma2x2_tap_samp_store(struct device *dev,
3811                 struct device_attribute *attr,
3812                 const char *buf, size_t count)
3813 {
3814         unsigned long data;
3815         int error;
3816         struct i2c_client *client = to_i2c_client(dev);
3817         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3818
3819         error = strict_strtoul(buf, 10, &data);
3820         if (error)
3821                 return error;
3822
3823         if (bma2x2_set_tap_samp(bma2x2->bma2x2_client, (unsigned char)data) < 0)
3824                 return -EINVAL;
3825
3826         return count;
3827 }
3828
3829 static ssize_t bma2x2_orient_mode_show(struct device *dev,
3830                 struct device_attribute *attr, char *buf)
3831 {
3832         unsigned char data;
3833         struct i2c_client *client = to_i2c_client(dev);
3834         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3835
3836         if (bma2x2_get_orient_mode(bma2x2->bma2x2_client, &data) < 0)
3837                 return sprintf(buf, "Read error\n");
3838
3839         return sprintf(buf, "%d\n", data);
3840
3841 }
3842
3843 static ssize_t bma2x2_orient_mode_store(struct device *dev,
3844                 struct device_attribute *attr,
3845                 const char *buf, size_t count)
3846 {
3847         unsigned long data;
3848         int error;
3849         struct i2c_client *client = to_i2c_client(dev);
3850         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3851
3852         error = strict_strtoul(buf, 10, &data);
3853         if (error)
3854                 return error;
3855
3856         if (bma2x2_set_orient_mode(bma2x2->bma2x2_client, (unsigned char)data) <
3857                         0)
3858                 return -EINVAL;
3859
3860         return count;
3861 }
3862
3863 static ssize_t bma2x2_orient_blocking_show(struct device *dev,
3864                 struct device_attribute *attr, char *buf)
3865 {
3866         unsigned char data;
3867         struct i2c_client *client = to_i2c_client(dev);
3868         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3869
3870         if (bma2x2_get_orient_blocking(bma2x2->bma2x2_client, &data) < 0)
3871                 return sprintf(buf, "Read error\n");
3872
3873         return sprintf(buf, "%d\n", data);
3874
3875 }
3876
3877 static ssize_t bma2x2_orient_blocking_store(struct device *dev,
3878                 struct device_attribute *attr,
3879                 const char *buf, size_t count)
3880 {
3881         unsigned long data;
3882         int error;
3883         struct i2c_client *client = to_i2c_client(dev);
3884         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3885
3886         error = strict_strtoul(buf, 10, &data);
3887         if (error)
3888                 return error;
3889
3890         if (bma2x2_set_orient_blocking(bma2x2->bma2x2_client, (unsigned
3891                                         char)data) < 0)
3892                 return -EINVAL;
3893
3894         return count;
3895 }
3896 static ssize_t bma2x2_orient_hyst_show(struct device *dev,
3897                 struct device_attribute *attr, char *buf)
3898 {
3899         unsigned char data;
3900         struct i2c_client *client = to_i2c_client(dev);
3901         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3902
3903         if (bma2x2_get_orient_hyst(bma2x2->bma2x2_client, &data) < 0)
3904                 return sprintf(buf, "Read error\n");
3905
3906         return sprintf(buf, "%d\n", data);
3907
3908 }
3909
3910 static ssize_t bma2x2_orient_hyst_store(struct device *dev,
3911                 struct device_attribute *attr,
3912                 const char *buf, size_t count)
3913 {
3914         unsigned long data;
3915         int error;
3916         struct i2c_client *client = to_i2c_client(dev);
3917         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3918
3919         error = strict_strtoul(buf, 10, &data);
3920         if (error)
3921                 return error;
3922
3923         if (bma2x2_set_orient_hyst(bma2x2->bma2x2_client, (unsigned char)data) <
3924                         0)
3925                 return -EINVAL;
3926
3927         return count;
3928 }
3929
3930 static ssize_t bma2x2_orient_theta_show(struct device *dev,
3931                 struct device_attribute *attr, char *buf)
3932 {
3933         unsigned char data;
3934         struct i2c_client *client = to_i2c_client(dev);
3935         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3936
3937         if (bma2x2_get_theta_blocking(bma2x2->bma2x2_client, &data) < 0)
3938                 return sprintf(buf, "Read error\n");
3939
3940         return sprintf(buf, "%d\n", data);
3941
3942 }
3943
3944 static ssize_t bma2x2_orient_theta_store(struct device *dev,
3945                 struct device_attribute *attr,
3946                 const char *buf, size_t count)
3947 {
3948         unsigned long data;
3949         int error;
3950         struct i2c_client *client = to_i2c_client(dev);
3951         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3952
3953         error = strict_strtoul(buf, 10, &data);
3954         if (error)
3955                 return error;
3956
3957         if (bma2x2_set_theta_blocking(bma2x2->bma2x2_client, (unsigned
3958                                         char)data) < 0)
3959                 return -EINVAL;
3960
3961         return count;
3962 }
3963
3964 static ssize_t bma2x2_flat_theta_show(struct device *dev,
3965                 struct device_attribute *attr, char *buf)
3966 {
3967         unsigned char data;
3968         struct i2c_client *client = to_i2c_client(dev);
3969         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3970
3971         if (bma2x2_get_theta_flat(bma2x2->bma2x2_client, &data) < 0)
3972                 return sprintf(buf, "Read error\n");
3973
3974         return sprintf(buf, "%d\n", data);
3975
3976 }
3977
3978 static ssize_t bma2x2_flat_theta_store(struct device *dev,
3979                 struct device_attribute *attr,
3980                 const char *buf, size_t count)
3981 {
3982         unsigned long data;
3983         int error;
3984         struct i2c_client *client = to_i2c_client(dev);
3985         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
3986
3987         error = strict_strtoul(buf, 10, &data);
3988         if (error)
3989                 return error;
3990
3991         if (bma2x2_set_theta_flat(bma2x2->bma2x2_client, (unsigned char)data) <
3992                         0)
3993                 return -EINVAL;
3994
3995         return count;
3996 }
3997 static ssize_t bma2x2_flat_hold_time_show(struct device *dev,
3998                 struct device_attribute *attr, char *buf)
3999 {
4000         unsigned char data;
4001         struct i2c_client *client = to_i2c_client(dev);
4002         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4003
4004         if (bma2x2_get_flat_hold_time(bma2x2->bma2x2_client, &data) < 0)
4005                 return sprintf(buf, "Read error\n");
4006
4007         return sprintf(buf, "%d\n", data);
4008
4009 }
4010 static ssize_t bma2x2_selftest_show(struct device *dev,
4011                 struct device_attribute *attr, char *buf)
4012 {
4013
4014
4015         struct i2c_client *client = to_i2c_client(dev);
4016         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4017
4018         return sprintf(buf, "%d\n", atomic_read(&bma2x2->selftest_result));
4019
4020 }
4021
4022 static ssize_t bma2x2_softreset_store(struct device *dev,
4023                 struct device_attribute *attr,
4024                 const char *buf, size_t count)
4025 {
4026         struct i2c_client *client = to_i2c_client(dev);
4027         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4028
4029         if (bma2x2_soft_reset(bma2x2->bma2x2_client) < 0)
4030                 return -EINVAL;
4031
4032         return count;
4033 }
4034 static ssize_t bma2x2_selftest_store(struct device *dev,
4035                 struct device_attribute *attr,
4036                 const char *buf, size_t count)
4037 {
4038
4039         unsigned long data;
4040         unsigned char clear_value = 0;
4041         int error;
4042         short value1 = 0;
4043         short value2 = 0;
4044         short diff = 0;
4045         unsigned long result = 0;
4046         struct i2c_client *client = to_i2c_client(dev);
4047         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4048
4049         bma2x2_soft_reset(bma2x2->bma2x2_client);
4050         mdelay(5);
4051
4052         error = strict_strtoul(buf, 10, &data);
4053         if (error)
4054                 return error;
4055
4056         if (data != 1)
4057                 return -EINVAL;
4058
4059         bma2x2_write_reg(bma2x2->bma2x2_client, 0x32, &clear_value);
4060
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)
4065                         return -EINVAL;
4066         }
4067
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)
4072                         return -EINVAL;
4073                 if (bma2x2_set_selftest_amp(bma2x2->bma2x2_client, 1) < 0)
4074                         return -EINVAL;
4075         }
4076
4077         bma2x2_set_selftest_st(bma2x2->bma2x2_client, 1); /* 1 for x-axis*/
4078         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4079                                                               direction*/
4080         mdelay(10);
4081         bma2x2_read_accel_x(bma2x2->bma2x2_client,
4082                                         bma2x2->sensor_type, &value1);
4083         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4084                                                               direction*/
4085         mdelay(10);
4086         bma2x2_read_accel_x(bma2x2->bma2x2_client,
4087                                         bma2x2->sensor_type, &value2);
4088         diff = value1-value2;
4089
4090         printk(KERN_INFO "diff x is %d,value1 is %d, value2 is %d\n", diff,
4091                         value1, value2);
4092
4093         if (bma2x2->sensor_type == BMA280_TYPE) {
4094                 if (abs(diff) < 1638)
4095                         result |= 1;
4096         }
4097         if (bma2x2->sensor_type == BMA255_TYPE) {
4098                 if (abs(diff) < 409)
4099                         result |= 1;
4100         }
4101         if (bma2x2->sensor_type == BMA250E_TYPE) {
4102                 if (abs(diff) < 51)
4103                         result |= 1;
4104         }
4105         if (bma2x2->sensor_type == BMA222E_TYPE) {
4106                 if (abs(diff) < 12)
4107                         result |= 1;
4108         }
4109
4110         bma2x2_set_selftest_st(bma2x2->bma2x2_client, 2); /* 2 for y-axis*/
4111         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4112                                                               direction*/
4113         mdelay(10);
4114         bma2x2_read_accel_y(bma2x2->bma2x2_client,
4115                                         bma2x2->sensor_type, &value1);
4116         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4117                                                               direction*/
4118         mdelay(10);
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,
4123                         value1, value2);
4124
4125         if (bma2x2->sensor_type == BMA280_TYPE) {
4126                 if (abs(diff) < 1638)
4127                         result |= 2;
4128         }
4129         if (bma2x2->sensor_type == BMA255_TYPE) {
4130                 if (abs(diff) < 409)
4131                         result |= 2;
4132         }
4133         if (bma2x2->sensor_type == BMA250E_TYPE) {
4134                 if (abs(diff) < 51)
4135                         result |= 2;
4136         }
4137         if (bma2x2->sensor_type == BMA222E_TYPE) {
4138                 if (abs(diff) < 12)
4139                         result |= 2;
4140         }
4141
4142
4143         bma2x2_set_selftest_st(bma2x2->bma2x2_client, 3); /* 3 for z-axis*/
4144         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /* positive
4145                                                               direction*/
4146         mdelay(10);
4147         bma2x2_read_accel_z(bma2x2->bma2x2_client,
4148                                         bma2x2->sensor_type, &value1);
4149         bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 1); /* negative
4150                                                               direction*/
4151         mdelay(10);
4152         bma2x2_read_accel_z(bma2x2->bma2x2_client,
4153                                         bma2x2->sensor_type, &value2);
4154         diff = value1-value2;
4155
4156         printk(KERN_INFO "diff z is %d,value1 is %d, value2 is %d\n", diff,
4157                         value1, value2);
4158
4159         if (bma2x2->sensor_type == BMA280_TYPE) {
4160                 if (abs(diff) < 819)
4161                         result |= 4;
4162         }
4163         if (bma2x2->sensor_type == BMA255_TYPE) {
4164                 if (abs(diff) < 204)
4165                         result |= 4;
4166         }
4167         if (bma2x2->sensor_type == BMA250E_TYPE) {
4168                 if (abs(diff) < 25)
4169                         result |= 4;
4170         }
4171         if (bma2x2->sensor_type == BMA222E_TYPE) {
4172                 if (abs(diff) < 6)
4173                         result |= 4;
4174         }
4175
4176         /* self test for bma254 */
4177         if ((bma2x2->sensor_type == BMA255_TYPE) && (result > 0)) {
4178                 result = 0;
4179                 bma2x2_soft_reset(bma2x2->bma2x2_client);
4180                 mdelay(5);
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)
4184                         return -EINVAL;
4185                 if (bma2x2_set_selftest_amp(bma2x2->bma2x2_client, 1) < 0)
4186                         return -EINVAL;
4187
4188                 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 1); /* 1
4189                                                                 for x-axis*/
4190                 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4191                                                         positive direction*/
4192                 mdelay(10);
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*/
4197                 mdelay(10);
4198                 bma2x2_read_accel_x(bma2x2->bma2x2_client,
4199                                                 bma2x2->sensor_type, &value2);
4200                 diff = value1-value2;
4201
4202                 printk(KERN_INFO "diff x is %d,value1 is %d, value2 is %d\n",
4203                                                 diff, value1, value2);
4204                 if (abs(diff) < 204)
4205                         result |= 1;
4206
4207                 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 2); /* 2
4208                                                                 for y-axis*/
4209                 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4210                                                         positive direction*/
4211                 mdelay(10);
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*/
4216                 mdelay(10);
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);
4222
4223                 if (abs(diff) < 204)
4224                         result |= 2;
4225
4226                 bma2x2_set_selftest_st(bma2x2->bma2x2_client, 3); /* 3
4227                                                                 for z-axis*/
4228                 bma2x2_set_selftest_stn(bma2x2->bma2x2_client, 0); /*
4229                                                         positive direction*/
4230                 mdelay(10);
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*/
4235                 mdelay(10);
4236                 bma2x2_read_accel_z(bma2x2->bma2x2_client,
4237                                                 bma2x2->sensor_type, &value2);
4238                 diff = value1-value2;
4239
4240                 printk(KERN_INFO "diff z is %d,value1 is %d, value2 is %d\n",
4241                                                 diff, value1, value2);
4242                 if (abs(diff) < 102)
4243                         result |= 4;
4244         }
4245
4246         atomic_set(&bma2x2->selftest_result, (unsigned int)result);
4247
4248         bma2x2_soft_reset(bma2x2->bma2x2_client);
4249         mdelay(5);
4250         printk(KERN_INFO "self test finished\n");
4251
4252         return count;
4253 }
4254
4255
4256
4257 static ssize_t bma2x2_flat_hold_time_store(struct device *dev,
4258                 struct device_attribute *attr,
4259                 const char *buf, size_t count)
4260 {
4261         unsigned long data;
4262         int error;
4263         struct i2c_client *client = to_i2c_client(dev);
4264         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4265
4266         error = strict_strtoul(buf, 10, &data);
4267         if (error)
4268                 return error;
4269
4270         if (bma2x2_set_flat_hold_time(bma2x2->bma2x2_client, (unsigned
4271                                         char)data) < 0)
4272                 return -EINVAL;
4273
4274         return count;
4275 }
4276
4277
4278
4279 static int bma2x2_read_accel_xyz(struct i2c_client *client,
4280                 signed char sensor_type, struct bma2x2acc *acc)
4281 {
4282         int comres = 0;
4283         unsigned char data[6];
4284         struct bma2x2_data *client_data = i2c_get_clientdata(client);
4285
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];
4292
4293 #else
4294         switch (sensor_type) {
4295         case 0:
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));
4305
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
4309                                                                         ));
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));
4314
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));
4322                 break;
4323         case 1:
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));
4333
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
4337                                                                         ));
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));
4342
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));
4350                 break;
4351         case 2:
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));
4361
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
4365                                                                         ));
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));
4370
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));
4378                 break;
4379         case 3:
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));
4389
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
4393                                                                         ));
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));
4398
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));
4406                 break;
4407         default:
4408                 break;
4409         }
4410 #endif
4411
4412         bma2x2_remap_sensor_data(acc, client_data);
4413         return comres;
4414 }
4415
4416 static void bma2x2_work_func(struct work_struct *work)
4417 {
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));
4422
4423         bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4424                                                                          &acc);
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);
4429
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);
4435
4436         schedule_delayed_work(&bma2x2->work, delay);
4437 }
4438
4439
4440 static ssize_t bma2x2_register_store(struct device *dev,
4441                 struct device_attribute *attr,
4442                 const char *buf, size_t count)
4443 {
4444         int address, value;
4445         struct i2c_client *client = to_i2c_client(dev);
4446         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4447
4448         sscanf(buf, "%d%d", &address, &value);
4449         if (bma2x2_write_reg(bma2x2->bma2x2_client, (unsigned char)address,
4450                                 (unsigned char *)&value) < 0)
4451                 return -EINVAL;
4452         return count;
4453 }
4454 static ssize_t bma2x2_register_show(struct device *dev,
4455                 struct device_attribute *attr, char *buf)
4456 {
4457
4458         struct i2c_client *client = to_i2c_client(dev);
4459         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4460
4461         size_t count = 0;
4462         u8 reg[0x40];
4463         int i;
4464
4465         for (i = 0; i < 0x40; i++) {
4466                 bma2x2_smbus_read_byte(bma2x2->bma2x2_client, i, reg+i);
4467
4468                 count += sprintf(&buf[count], "0x%x: %d\n", i, reg[i]);
4469         }
4470         return count;
4471
4472
4473 }
4474
4475 static ssize_t bma2x2_range_show(struct device *dev,
4476                 struct device_attribute *attr, char *buf)
4477 {
4478         unsigned char data;
4479         struct i2c_client *client = to_i2c_client(dev);
4480         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4481
4482         if (bma2x2_get_range(bma2x2->bma2x2_client, &data) < 0)
4483                 return sprintf(buf, "Read error\n");
4484
4485         return sprintf(buf, "%d\n", data);
4486 }
4487
4488 static ssize_t bma2x2_range_store(struct device *dev,
4489                 struct device_attribute *attr,
4490                 const char *buf, size_t count)
4491 {
4492         unsigned long data;
4493         int error;
4494         struct i2c_client *client = to_i2c_client(dev);
4495         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4496
4497         error = strict_strtoul(buf, 10, &data);
4498         if (error)
4499                 return error;
4500         if (bma2x2_set_range(bma2x2->bma2x2_client, (unsigned char) data) < 0)
4501                 return -EINVAL;
4502
4503         return count;
4504 }
4505
4506 static ssize_t bma2x2_bandwidth_show(struct device *dev,
4507                 struct device_attribute *attr, char *buf)
4508 {
4509         unsigned char data;
4510         struct i2c_client *client = to_i2c_client(dev);
4511         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4512
4513         if (bma2x2_get_bandwidth(bma2x2->bma2x2_client, &data) < 0)
4514                 return sprintf(buf, "Read error\n");
4515
4516         return sprintf(buf, "%d\n", data);
4517
4518 }
4519
4520 static ssize_t bma2x2_bandwidth_store(struct device *dev,
4521                 struct device_attribute *attr,
4522                 const char *buf, size_t count)
4523 {
4524         unsigned long data;
4525         int error;
4526         struct i2c_client *client = to_i2c_client(dev);
4527         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4528
4529         error = strict_strtoul(buf, 10, &data);
4530         if (error)
4531                 return error;
4532
4533         if (bma2x2->sensor_type == BMA280_TYPE)
4534                 if ((unsigned char) data > 14)
4535                         return -EINVAL;
4536
4537         if (bma2x2_set_bandwidth(bma2x2->bma2x2_client,
4538                                 (unsigned char) data) < 0)
4539                 return -EINVAL;
4540
4541         return count;
4542 }
4543
4544 static ssize_t bma2x2_mode_show(struct device *dev,
4545                 struct device_attribute *attr, char *buf)
4546 {
4547         unsigned char data;
4548         struct i2c_client *client = to_i2c_client(dev);
4549         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4550
4551         if (bma2x2_get_mode(bma2x2->bma2x2_client, &data) < 0)
4552                 return sprintf(buf, "Read error\n");
4553
4554         return sprintf(buf, "%d\n", data);
4555 }
4556
4557 static ssize_t bma2x2_mode_store(struct device *dev,
4558                 struct device_attribute *attr,
4559                 const char *buf, size_t count)
4560 {
4561         unsigned long data;
4562         int error;
4563         struct i2c_client *client = to_i2c_client(dev);
4564         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4565
4566         error = strict_strtoul(buf, 10, &data);
4567         if (error)
4568                 return error;
4569         if (bma2x2_set_mode(bma2x2->bma2x2_client, (unsigned char) data) < 0)
4570                 return -EINVAL;
4571
4572         return count;
4573 }
4574 static ssize_t bma2x2_value_show(struct device *dev,
4575                 struct device_attribute *attr, char *buf)
4576 {
4577         struct input_dev *input = to_input_dev(dev);
4578         struct bma2x2_data *bma2x2 = input_get_drvdata(input);
4579         struct bma2x2acc acc_value;
4580
4581 #if 0
4582         bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4583                                                                 &acc_value);
4584 #else
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);
4591 #endif
4592
4593         return sprintf(buf, "%d %d %d\n", acc_value.x, acc_value.y,
4594                         acc_value.z);
4595 }
4596
4597 /* raw-data for sensor test */
4598 static ssize_t bma2x2_raw_data_show(struct device *dev,
4599                 struct device_attribute *attr, char *buf)
4600 {
4601         struct input_dev *input = to_input_dev(dev);
4602         struct bma2x2_data *bma2x2 = input_get_drvdata(input);
4603         struct bma2x2acc acc_value;
4604 #if 0
4605         bma2x2_read_accel_xyz(bma2x2->bma2x2_client, bma2x2->sensor_type,
4606                                                                 &acc_value);
4607 #else
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);
4614
4615 #endif
4616
4617         acc_value.x = acc_value.x >>4;
4618         acc_value.y = acc_value.y >>4;
4619         acc_value.z = acc_value.z >>4;
4620
4621         return sprintf(buf, "%d,%d,%d\n", acc_value.x, acc_value.y,
4622                         acc_value.z);
4623 }
4624
4625 static ssize_t bma2x2_delay_show(struct device *dev,
4626                 struct device_attribute *attr, char *buf)
4627 {
4628         struct i2c_client *client = to_i2c_client(dev);
4629         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4630
4631         return sprintf(buf, "%d\n", atomic_read(&bma2x2->delay));
4632
4633 }
4634
4635 static ssize_t bma2x2_chip_id_show(struct device *dev,
4636                 struct device_attribute *attr, char *buf)
4637 {
4638         struct i2c_client *client = to_i2c_client(dev);
4639         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4640
4641         return sprintf(buf, "%d\n", bma2x2->chip_id);
4642
4643 }
4644
4645
4646 static ssize_t bma2x2_place_show(struct device *dev,
4647                 struct device_attribute *attr, char *buf)
4648 {
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);
4652 #endif
4653         int place = BOSCH_SENSOR_PLACE_UNKNOWN;
4654
4655 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
4656         if (NULL != bma2x2->bst_pd)
4657                 place = bma2x2->bst_pd->place;
4658 #endif
4659
4660         return sprintf(buf, "%d\n", place);
4661 }
4662
4663
4664 static ssize_t bma2x2_delay_store(struct device *dev,
4665                 struct device_attribute *attr,
4666                 const char *buf, size_t count)
4667 {
4668         unsigned long data;
4669         int error;
4670         struct i2c_client *client = to_i2c_client(dev);
4671         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4672
4673         error = strict_strtoul(buf, 10, &data);
4674         if (error)
4675                 return error;
4676         if (data > BMA2X2_MAX_DELAY)
4677                 data = BMA2X2_MAX_DELAY;
4678         atomic_set(&bma2x2->delay, (unsigned int) data);
4679
4680         return count;
4681 }
4682
4683
4684 static ssize_t bma2x2_enable_show(struct device *dev,
4685                 struct device_attribute *attr, char *buf)
4686 {
4687         struct i2c_client *client = to_i2c_client(dev);
4688         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4689
4690         return sprintf(buf, "%d\n", atomic_read(&bma2x2->enable));
4691
4692 }
4693
4694 static void bma2x2_set_enable(struct device *dev, int enable)
4695 {
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);
4699
4700         mutex_lock(&bma2x2->enable_mutex);
4701         if (enable) {
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);
4708                 }
4709
4710         } else {
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);
4716                 }
4717         }
4718         mutex_unlock(&bma2x2->enable_mutex);
4719
4720 }
4721
4722 static ssize_t bma2x2_enable_store(struct device *dev,
4723                 struct device_attribute *attr,
4724                 const char *buf, size_t count)
4725 {
4726         unsigned long data;
4727         int error;
4728
4729         error = strict_strtoul(buf, 10, &data);
4730         if (error)
4731                 return error;
4732         if ((data == 0) || (data == 1))
4733                 bma2x2_set_enable(dev, data);
4734
4735
4736         return count;
4737 }
4738 static ssize_t bma2x2_fast_calibration_x_show(struct device *dev,
4739                 struct device_attribute *attr, char *buf)
4740 {
4741
4742
4743         unsigned char data;
4744         struct i2c_client *client = to_i2c_client(dev);
4745         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4746
4747         if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 1, &data) < 0)
4748                 return sprintf(buf, "Read error\n");
4749
4750         return sprintf(buf, "%d\n", data);
4751
4752 }
4753
4754 static ssize_t bma2x2_fast_calibration_x_store(struct device *dev,
4755                 struct device_attribute *attr,
4756                 const char *buf, size_t count)
4757 {
4758         unsigned long data;
4759         signed char tmp;
4760         unsigned char timeout = 0;
4761         int error;
4762         struct i2c_client *client = to_i2c_client(dev);
4763         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4764
4765         error = strict_strtoul(buf, 10, &data);
4766         if (error)
4767                 return error;
4768
4769         if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 1, (unsigned
4770                                         char)data) < 0)
4771                 return -EINVAL;
4772
4773         if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 1) < 0)
4774                 return -EINVAL;
4775
4776         do {
4777                 mdelay(2);
4778                 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4779
4780 /*              printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4781  */
4782                 timeout++;
4783                 if (timeout == 50) {
4784                         printk(KERN_INFO "get fast calibration ready error\n");
4785                         return -EINVAL;
4786                 };
4787
4788         } while (tmp == 0);
4789
4790         printk(KERN_INFO "x axis fast calibration finished\n");
4791         return count;
4792 }
4793
4794 static ssize_t bma2x2_fast_calibration_y_show(struct device *dev,
4795                 struct device_attribute *attr, char *buf)
4796 {
4797
4798
4799         unsigned char data;
4800         struct i2c_client *client = to_i2c_client(dev);
4801         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4802
4803         if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 2, &data) < 0)
4804                 return sprintf(buf, "Read error\n");
4805
4806         return sprintf(buf, "%d\n", data);
4807
4808 }
4809
4810 static ssize_t bma2x2_fast_calibration_y_store(struct device *dev,
4811                 struct device_attribute *attr,
4812                 const char *buf, size_t count)
4813 {
4814         unsigned long data;
4815         signed char tmp;
4816         unsigned char timeout = 0;
4817         int error;
4818         struct i2c_client *client = to_i2c_client(dev);
4819         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4820
4821         error = strict_strtoul(buf, 10, &data);
4822         if (error)
4823                 return error;
4824
4825         if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 2, (unsigned
4826                                         char)data) < 0)
4827                 return -EINVAL;
4828
4829         if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 2) < 0)
4830                 return -EINVAL;
4831
4832         do {
4833                 mdelay(2);
4834                 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4835
4836 /*              printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4837  */
4838                 timeout++;
4839                 if (timeout == 50) {
4840                         printk(KERN_INFO "get fast calibration ready error\n");
4841                         return -EINVAL;
4842                 };
4843
4844         } while (tmp == 0);
4845
4846         printk(KERN_INFO "y axis fast calibration finished\n");
4847         return count;
4848 }
4849
4850 static ssize_t bma2x2_fast_calibration_z_show(struct device *dev,
4851                 struct device_attribute *attr, char *buf)
4852 {
4853
4854
4855         unsigned char data;
4856         struct i2c_client *client = to_i2c_client(dev);
4857         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4858
4859         if (bma2x2_get_offset_target(bma2x2->bma2x2_client, 3, &data) < 0)
4860                 return sprintf(buf, "Read error\n");
4861
4862         return sprintf(buf, "%d\n", data);
4863
4864 }
4865
4866 static ssize_t bma2x2_fast_calibration_z_store(struct device *dev,
4867                 struct device_attribute *attr,
4868                 const char *buf, size_t count)
4869 {
4870         unsigned long data;
4871         signed char tmp;
4872         unsigned char timeout = 0;
4873         int error;
4874         struct i2c_client *client = to_i2c_client(dev);
4875         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4876
4877         error = strict_strtoul(buf, 10, &data);
4878         if (error)
4879                 return error;
4880
4881         if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 3, (unsigned
4882                                         char)data) < 0)
4883                 return -EINVAL;
4884
4885         if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 3) < 0)
4886                 return -EINVAL;
4887
4888         do {
4889                 mdelay(2);
4890                 bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
4891
4892 /*              printk(KERN_INFO "wait 2ms cal ready flag is %d\n", tmp);
4893  */
4894                 timeout++;
4895                 if (timeout == 50) {
4896                         printk(KERN_INFO "get fast calibration ready error\n");
4897                         return -EINVAL;
4898                 };
4899
4900         } while (tmp == 0);
4901
4902         printk(KERN_INFO "z axis fast calibration finished\n");
4903         return count;
4904 }
4905 static ssize_t accel_calibration_open(struct device *dev,
4906                 struct device_attribute *attr, char *buf)
4907 {
4908         struct i2c_client *client = to_i2c_client(dev);
4909         bma2x2_open_cal(client);
4910         return 1;
4911 }
4912
4913
4914 static ssize_t bma2x2_calibration_show(struct device *dev,
4915                 struct device_attribute *attr, char *buf)
4916 {
4917         /*struct i2c_client *client = to_i2c_client(dev);*/
4918         /*struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);*/
4919         int cal_data[3];
4920         int err;
4921         mm_segment_t old_fs;
4922         struct file *cal_filp = NULL;
4923         int result = 1;
4924
4925         printk(KERN_INFO "[BMC150] %s\n", __func__);  
4926
4927         old_fs = get_fs();
4928         set_fs(KERNEL_DS);
4929
4930         cal_filp = filp_open(CALIBRATION_FILE_PATH,
4931                 O_RDONLY, 0666);
4932         if (IS_ERR(cal_filp)) {
4933                 pr_err("[BMC150] %s: Can't open calibration file\n",
4934                         __func__);
4935                 set_fs(old_fs);
4936                 err = PTR_ERR(cal_filp);
4937                 return err;
4938         }
4939         err = cal_filp->f_op->read(cal_filp,
4940                 (char *)cal_data,
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",
4944                         __func__);
4945                 filp_close(cal_filp, current->files);
4946                 set_fs(old_fs);
4947                 return -EIO;
4948         }
4949         if (((cal_data[0] == 0) &&(cal_data[1] == 0) &&(cal_data[2] == 0)))
4950                 result = 0;
4951
4952         printk(KERN_INFO "[BMC150] %s: result=%d, (%d,%d,%d)",__func__, result, cal_data[0],cal_data[1],cal_data[2]);
4953     
4954         return sprintf(buf, "%d %d %d %d\n", result, cal_data[0],cal_data[1],cal_data[2]);
4955
4956 }
4957
4958 static ssize_t bma2x2_calibration_store(struct device *dev,
4959                 struct device_attribute *attr,
4960                 const char *buf, size_t count)
4961 {
4962         struct i2c_client *client = to_i2c_client(dev);
4963         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
4964         int cal_data[3];
4965         unsigned long data;
4966         unsigned char mode;    
4967         signed char tmp;
4968         unsigned char timeout = 0;
4969         int err;
4970         mm_segment_t old_fs;
4971         struct file *cal_filp = NULL;
4972
4973         err = strict_strtoul(buf, 10, &data);
4974         if (err) {
4975             printk(KERN_ERR "[BMC150] %s: error(%d)\n", __func__, (unsigned char) data);
4976             return err;
4977         }
4978
4979         printk(KERN_INFO "[BMC150] %s: %d\n", __func__, (unsigned char) data);  
4980
4981         if (bma2x2_get_mode(bma2x2->bma2x2_client, &mode) < 0) {
4982             printk(KERN_ERR "[BMC150] %s: bma2x2_get_mode error\n", __func__);  
4983             return -EINVAL;
4984         }
4985     
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);
4989         }
4990        
4991         if(data){
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,
4996                                                                          &acc_value_z);
4997                 printk(KERN_INFO "[BMC150] acc_value_z = [%d], while accel calibration\n", acc_value_z);
4998                 if(acc_value_z > 0)
4999                         offset_target_z = 1;
5000                 else
5001                         offset_target_z = 2;
5002
5003                 /* x axis fast calibration */
5004                 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 1, (unsigned
5005                                                 char)0) < 0)
5006                         return -EINVAL;
5007
5008                 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 1) < 0)
5009                         return -EINVAL;
5010                 
5011
5012                 do {
5013                         mdelay(50);
5014                         bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5015                         timeout++;
5016                         if (timeout == 50) {
5017                                 printk(KERN_INFO "[BMC150] x get fast calibration ready error\n");
5018                                 return -EINVAL;
5019                         };
5020                 } while (tmp == 0);
5021                 
5022                 printk(KERN_INFO "[BMC150] x axis fast calibration DONE\n");
5023
5024                 /* y axis fast calibration */
5025                 if (bma2x2_set_offset_target(bma2x2->bma2x2_client, 2, (unsigned
5026                                                 char)0) < 0)
5027                         return -EINVAL;
5028         
5029                 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 2) < 0)
5030                         return -EINVAL;
5031         
5032                 do {
5033                         mdelay(50);
5034                         bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5035                         timeout++;
5036                         if (timeout == 50) {
5037                                 printk(KERN_INFO "[BMC150] y get fast calibration ready error\n");
5038                                 return -EINVAL;
5039                         };
5040                 } while (tmp == 0);
5041                 
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)
5046                         return -EINVAL;
5047
5048                 if (bma2x2_set_cal_trigger(bma2x2->bma2x2_client, 3) < 0)
5049                         return -EINVAL;
5050
5051                 do {
5052                         mdelay(50);
5053                         bma2x2_get_cal_ready(bma2x2->bma2x2_client, &tmp);
5054                         timeout++;
5055                         if (timeout == 50) {
5056                                 printk(KERN_INFO "[BMC150] z get fast calibration ready error\n");
5057                                 return -EINVAL;
5058                         };
5059                         printk(KERN_INFO "[BMC150] z axis fast calibration DONE\n");
5060                 } while (tmp == 0);
5061
5062                 /* calibration */
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]);
5066         
5067                 printk(KERN_INFO "[BMC150] %s: (%d,%d,%d)",__func__, cal_data[0],cal_data[1],cal_data[2]);
5068
5069                 old_fs = get_fs();
5070                 set_fs(KERNEL_DS);
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",
5075                                 __func__);
5076                         set_fs(old_fs);
5077                         err = PTR_ERR(cal_filp);
5078                         return err;
5079                 }
5080
5081                 err = cal_filp->f_op->write(cal_filp,
5082                         (char *)cal_data,
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",
5086                                 __func__);
5087                         err = -EIO;
5088                 }
5089                 filp_close(cal_filp, current->files);
5090                 set_fs(old_fs);
5091         }
5092         else
5093         {
5094                 /* erase cal data */
5095                 old_fs = get_fs();
5096                 set_fs(KERNEL_DS);
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",
5101                                 __func__);
5102                         set_fs(old_fs);
5103                         err = PTR_ERR(cal_filp);
5104                         return err;
5105                 }
5106                 cal_data[0] = 0;
5107                 cal_data[1] = 0;
5108                 cal_data[2] = 0;
5109
5110                 err = cal_filp->f_op->write(cal_filp,
5111                         (char *)cal_data,
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",
5115                                 __func__);
5116                         err = -EIO;
5117                 }
5118                 filp_close(cal_filp, current->files);
5119                 set_fs(old_fs);
5120
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]);         
5124         }
5125
5126         return count;
5127 }
5128
5129
5130 static ssize_t bma2x2_SleepDur_show(struct device *dev,
5131                 struct device_attribute *attr, char *buf)
5132 {
5133         unsigned char data;
5134         struct i2c_client *client = to_i2c_client(dev);
5135         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5136
5137         if (bma2x2_get_sleep_duration(bma2x2->bma2x2_client, &data) < 0)
5138                 return sprintf(buf, "Read error\n");
5139
5140         return sprintf(buf, "%d\n", data);
5141
5142 }
5143
5144 static ssize_t bma2x2_SleepDur_store(struct device *dev,
5145                 struct device_attribute *attr,
5146                 const char *buf, size_t count)
5147 {
5148         unsigned long data;
5149         int error;
5150         struct i2c_client *client = to_i2c_client(dev);
5151         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5152
5153         error = strict_strtoul(buf, 10, &data);
5154         if (error)
5155                 return error;
5156         if (bma2x2_set_sleep_duration(bma2x2->bma2x2_client,
5157                                 (unsigned char) data) < 0)
5158                 return -EINVAL;
5159
5160         return count;
5161 }
5162
5163 static ssize_t bma2x2_fifo_mode_show(struct device *dev,
5164                 struct device_attribute *attr, char *buf)
5165 {
5166         unsigned char data;
5167         struct i2c_client *client = to_i2c_client(dev);
5168         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5169
5170         if (bma2x2_get_fifo_mode(bma2x2->bma2x2_client, &data) < 0)
5171                 return sprintf(buf, "Read error\n");
5172
5173         return sprintf(buf, "%d\n", data);
5174
5175 }
5176
5177 static ssize_t bma2x2_fifo_mode_store(struct device *dev,
5178                 struct device_attribute *attr,
5179                 const char *buf, size_t count)
5180 {
5181         unsigned long data;
5182         int error;
5183         struct i2c_client *client = to_i2c_client(dev);
5184         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5185
5186         error = strict_strtoul(buf, 10, &data);
5187         if (error)
5188                 return error;
5189         if (bma2x2_set_fifo_mode(bma2x2->bma2x2_client,
5190                                 (unsigned char) data) < 0)
5191                 return -EINVAL;
5192
5193         return count;
5194 }
5195
5196
5197
5198 static ssize_t bma2x2_fifo_trig_show(struct device *dev,
5199                 struct device_attribute *attr, char *buf)
5200 {
5201         unsigned char data;
5202         struct i2c_client *client = to_i2c_client(dev);
5203         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5204
5205         if (bma2x2_get_fifo_trig(bma2x2->bma2x2_client, &data) < 0)
5206                 return sprintf(buf, "Read error\n");
5207
5208         return sprintf(buf, "%d\n", data);
5209
5210 }
5211
5212 static ssize_t bma2x2_fifo_trig_store(struct device *dev,
5213                 struct device_attribute *attr,
5214                 const char *buf, size_t count)
5215 {
5216         unsigned long data;
5217         int error;
5218         struct i2c_client *client = to_i2c_client(dev);
5219         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5220
5221         error = strict_strtoul(buf, 10, &data);
5222         if (error)
5223                 return error;
5224         if (bma2x2_set_fifo_trig(bma2x2->bma2x2_client,
5225                                 (unsigned char) data) < 0)
5226                 return -EINVAL;
5227
5228         return count;
5229 }
5230
5231
5232
5233 static ssize_t bma2x2_fifo_trig_src_show(struct device *dev,
5234                 struct device_attribute *attr, char *buf)
5235 {
5236         unsigned char data;
5237         struct i2c_client *client = to_i2c_client(dev);
5238         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5239
5240         if (bma2x2_get_fifo_trig_src(bma2x2->bma2x2_client, &data) < 0)
5241                 return sprintf(buf, "Read error\n");
5242
5243         return sprintf(buf, "%d\n", data);
5244
5245 }
5246
5247 static ssize_t bma2x2_fifo_trig_src_store(struct device *dev,
5248                 struct device_attribute *attr,
5249                 const char *buf, size_t count)
5250 {
5251         unsigned long data;
5252         int error;
5253         struct i2c_client *client = to_i2c_client(dev);
5254         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5255
5256         error = strict_strtoul(buf, 10, &data);
5257         if (error)
5258                 return error;
5259         if (bma2x2_set_fifo_trig_src(bma2x2->bma2x2_client,
5260                                 (unsigned char) data) < 0)
5261                 return -EINVAL;
5262
5263         return count;
5264 }
5265
5266
5267
5268 static ssize_t bma2x2_fifo_data_sel_show(struct device *dev,
5269                 struct device_attribute *attr, char *buf)
5270 {
5271         unsigned char data;
5272         struct i2c_client *client = to_i2c_client(dev);
5273         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5274
5275         if (bma2x2_get_fifo_data_sel(bma2x2->bma2x2_client, &data) < 0)
5276                 return sprintf(buf, "Read error\n");
5277
5278         return sprintf(buf, "%d\n", data);
5279
5280 }
5281
5282 static ssize_t bma2x2_fifo_framecount_show(struct device *dev,
5283                 struct device_attribute *attr, char *buf)
5284 {
5285         unsigned char data;
5286         struct i2c_client *client = to_i2c_client(dev);
5287         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5288
5289         if (bma2x2_get_fifo_framecount(bma2x2->bma2x2_client, &data) < 0)
5290                 return sprintf(buf, "Read error\n");
5291
5292         return sprintf(buf, "%d\n", data);
5293
5294 }
5295
5296 static ssize_t bma2x2_temperature_show(struct device *dev,
5297                 struct device_attribute *attr, char *buf)
5298 {
5299         unsigned char data;
5300         struct i2c_client *client = to_i2c_client(dev);
5301         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5302
5303         if (bma2x2_read_temperature(bma2x2->bma2x2_client, &data) < 0)
5304                 return sprintf(buf, "Read error\n");
5305
5306         return sprintf(buf, "%d\n", data);
5307
5308 }
5309
5310 static ssize_t bma2x2_fifo_data_sel_store(struct device *dev,
5311                 struct device_attribute *attr,
5312                 const char *buf, size_t count)
5313 {
5314         unsigned long data;
5315         int error;
5316         struct i2c_client *client = to_i2c_client(dev);
5317         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5318
5319         error = strict_strtoul(buf, 10, &data);
5320         if (error)
5321                 return error;
5322         if (bma2x2_set_fifo_data_sel(bma2x2->bma2x2_client,
5323                                 (unsigned char) data) < 0)
5324                 return -EINVAL;
5325
5326         return count;
5327 }
5328
5329
5330
5331 static ssize_t bma2x2_fifo_data_out_frame_show(struct device *dev,
5332                 struct device_attribute *attr, char *buf)
5333 {
5334         unsigned char data;
5335         int err, i, len;
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;
5339
5340         struct i2c_client *client = to_i2c_client(dev);
5341         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5342
5343         if (bma2x2_get_fifo_data_sel(bma2x2->bma2x2_client, &fifo_datasel) < 0)
5344                 return sprintf(buf, "Read data sel error\n");
5345
5346         if (fifo_datasel)
5347                 f_len = 2;
5348         else
5349                 f_len = 6;
5350
5351         if (bma2x2_get_fifo_framecount(bma2x2->bma2x2_client, &f_count) < 0)
5352                 return sprintf(buf, "Read frame count error\n");
5353
5354
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");
5359
5360
5361         if (bma2x2_get_fifo_data_out_reg(bma2x2->bma2x2_client, &data) < 0)
5362                 return sprintf(buf, "Read error\n");
5363
5364         err = 0;
5365
5366         len = sprintf(buf, "%lu ", jiffies);
5367         buf += len;
5368         err += len;
5369
5370         len = sprintf(buf, "%u ", f_count);
5371         buf += len;
5372         err += len;
5373
5374         len = sprintf(buf, "%u ", f_len);
5375         buf += len;
5376         err += len;
5377
5378         for (i = 0; i < f_count * f_len; i++)   {
5379                 len = sprintf(buf, "%d ", fifo_data_out[i]);
5380                 buf += len;
5381                 err += len;
5382         }
5383
5384         return err;
5385
5386 }
5387
5388
5389
5390
5391 static ssize_t bma2x2_offset_x_show(struct device *dev,
5392                 struct device_attribute *attr, char *buf)
5393 {
5394         unsigned char data;
5395         struct i2c_client *client = to_i2c_client(dev);
5396         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5397
5398         if (bma2x2_get_offset_x(bma2x2->bma2x2_client, &data) < 0)
5399                 return sprintf(buf, "Read error\n");
5400
5401         return sprintf(buf, "%d\n", data);
5402
5403 }
5404
5405 static ssize_t bma2x2_offset_x_store(struct device *dev,
5406                 struct device_attribute *attr,
5407                 const char *buf, size_t count)
5408 {
5409         unsigned long data;
5410         int error;
5411         struct i2c_client *client = to_i2c_client(dev);
5412         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5413
5414         error = strict_strtoul(buf, 10, &data);
5415         if (error)
5416                 return error;
5417
5418         if (bma2x2_set_offset_x(bma2x2->bma2x2_client, (unsigned
5419                                         char)data) < 0)
5420                 return -EINVAL;
5421
5422         return count;
5423 }
5424
5425 static ssize_t bma2x2_offset_y_show(struct device *dev,
5426                 struct device_attribute *attr, char *buf)
5427 {
5428         unsigned char data;
5429         struct i2c_client *client = to_i2c_client(dev);
5430         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5431
5432         if (bma2x2_get_offset_y(bma2x2->bma2x2_client, &data) < 0)
5433                 return sprintf(buf, "Read error\n");
5434
5435         return sprintf(buf, "%d\n", data);
5436
5437 }
5438
5439 static ssize_t bma2x2_offset_y_store(struct device *dev,
5440                 struct device_attribute *attr,
5441                 const char *buf, size_t count)
5442 {
5443         unsigned long data;
5444         int error;
5445         struct i2c_client *client = to_i2c_client(dev);
5446         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5447
5448         error = strict_strtoul(buf, 10, &data);
5449         if (error)
5450                 return error;
5451
5452         if (bma2x2_set_offset_y(bma2x2->bma2x2_client, (unsigned
5453                                         char)data) < 0)
5454                 return -EINVAL;
5455
5456         return count;
5457 }
5458
5459 static ssize_t bma2x2_offset_z_show(struct device *dev,
5460                 struct device_attribute *attr, char *buf)
5461 {
5462         unsigned char data;
5463         struct i2c_client *client = to_i2c_client(dev);
5464         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5465
5466         if (bma2x2_get_offset_z(bma2x2->bma2x2_client, &data) < 0)
5467                 return sprintf(buf, "Read error\n");
5468
5469         return sprintf(buf, "%d\n", data);
5470
5471 }
5472
5473 static ssize_t bma2x2_offset_z_store(struct device *dev,
5474                 struct device_attribute *attr,
5475                 const char *buf, size_t count)
5476 {
5477         unsigned long data;
5478         int error;
5479         struct i2c_client *client = to_i2c_client(dev);
5480         struct bma2x2_data *bma2x2 = i2c_get_clientdata(client);
5481
5482         error = strict_strtoul(buf, 10, &data);
5483         if (error)
5484                 return error;
5485
5486         if (bma2x2_set_offset_z(bma2x2->bma2x2_client, (unsigned
5487                                         char)data) < 0)
5488                 return -EINVAL;
5489
5490         return count;
5491 }
5492
5493
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);
5601
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,
5610         &dev_attr_reg.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,
5650         NULL
5651 };
5652
5653 static struct attribute_group bma2x2_attribute_group = {
5654         .attrs = bma2x2_attributes
5655 };
5656
5657
5658
5659
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"};
5669
5670 static void bma2x2_irq_work_func(struct work_struct *work)
5671 {
5672         struct bma2x2_data *bma2x2 = container_of((struct work_struct *)work,
5673                         struct bma2x2_data, irq_work);
5674
5675         unsigned char status = 0;
5676         unsigned char i;
5677         unsigned char first_value = 0;
5678         unsigned char sign_value = 0;
5679
5680         bma2x2_get_interruptstatus1(bma2x2->bma2x2_client, &status);
5681
5682         switch (status) {
5683
5684         case 0x01:
5685                 printk(KERN_INFO "Low G interrupt happened\n");
5686                 input_report_rel(bma2x2->input, LOW_G_INTERRUPT,
5687                                 LOW_G_INTERRUPT_HAPPENED);
5688                 break;
5689         case 0x02:
5690                 for (i = 0; i < 3; i++) {
5691                         bma2x2_get_HIGH_first(bma2x2->bma2x2_client, i,
5692                                            &first_value);
5693                         if (first_value == 1) {
5694
5695                                 bma2x2_get_HIGH_sign(bma2x2->bma2x2_client,
5696                                                    &sign_value);
5697
5698                                 if (sign_value == 1) {
5699                                         if (i == 0)
5700                                                 input_report_rel(bma2x2->input,
5701                                                 HIGH_G_INTERRUPT,
5702                                         HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED);
5703                                         if (i == 1)
5704                                                 input_report_rel(bma2x2->input,
5705                                                 HIGH_G_INTERRUPT,
5706                                         HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED);
5707                                         if (i == 2)
5708                                                 input_report_rel(bma2x2->input,
5709                                                 HIGH_G_INTERRUPT,
5710                                         HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED);
5711                                 } else {
5712                                         if (i == 0)
5713                                                 input_report_rel(bma2x2->input,
5714                                                 HIGH_G_INTERRUPT,
5715                                         HIGH_G_INTERRUPT_X_HAPPENED);
5716                                         if (i == 1)
5717                                                 input_report_rel(bma2x2->input,
5718                                                 HIGH_G_INTERRUPT,
5719                                         HIGH_G_INTERRUPT_Y_HAPPENED);
5720                                         if (i == 2)
5721                                                 input_report_rel(bma2x2->input,
5722                                                 HIGH_G_INTERRUPT,
5723                                         HIGH_G_INTERRUPT_Z_HAPPENED);
5724
5725                                 }
5726                            }
5727
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);
5731                 }
5732                    break;
5733         case 0x04:
5734                 for (i = 0; i < 3; i++) {
5735                         bma2x2_get_slope_first(bma2x2->bma2x2_client, i,
5736                                            &first_value);
5737                         if (first_value == 1) {
5738
5739                                 bma2x2_get_slope_sign(bma2x2->bma2x2_client,
5740                                                    &sign_value);
5741
5742                                 if (sign_value == 1) {
5743                                         if (i == 0)
5744                                                 input_report_rel(bma2x2->input,
5745                                                 SLOP_INTERRUPT,
5746                                         SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED);
5747                                         else if (i == 1)
5748                                                 input_report_rel(bma2x2->input,
5749                                                 SLOP_INTERRUPT,
5750                                         SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED);
5751                                         else if (i == 2)
5752                                                 input_report_rel(bma2x2->input,
5753                                                 SLOP_INTERRUPT,
5754                                         SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED);
5755                                 } else {
5756                                         if (i == 0)
5757                                                 input_report_rel(bma2x2->input,
5758                                                                 SLOP_INTERRUPT,
5759                                                 SLOPE_INTERRUPT_X_HAPPENED);
5760                                         else if (i == 1)
5761                                                 input_report_rel(bma2x2->input,
5762                                                                 SLOP_INTERRUPT,
5763                                                 SLOPE_INTERRUPT_Y_HAPPENED);
5764                                         else if (i == 2)
5765                                                 input_report_rel(bma2x2->input,
5766                                                                 SLOP_INTERRUPT,
5767                                                 SLOPE_INTERRUPT_Z_HAPPENED);
5768
5769                                 }
5770                         }
5771
5772                         printk(KERN_INFO "Slop interrupt happened,exis is %d,"
5773                                         "first is %d,sign is %d\n", i,
5774                                         first_value, sign_value);
5775                 }
5776                 break;
5777
5778         case 0x08:
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);
5782                 break;
5783
5784         case 0x10:
5785                 printk(KERN_INFO "double tap interrupt happened\n");
5786                 input_report_rel(bma2x2->input, DOUBLE_TAP_INTERRUPT,
5787                                         DOUBLE_TAP_INTERRUPT_HAPPENED);
5788                 break;
5789         case 0x20:
5790                 printk(KERN_INFO "single tap interrupt happened\n");
5791                 input_report_rel(bma2x2->input, SINGLE_TAP_INTERRUPT,
5792                                         SINGLE_TAP_INTERRUPT_HAPPENED);
5793                 break;
5794         case 0x40:
5795                 bma2x2_get_orient_status(bma2x2->bma2x2_client,
5796                                     &first_value);
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);
5823                 break;
5824         case 0x80:
5825                 bma2x2_get_orient_flat_status(bma2x2->bma2x2_client,
5826                                     &sign_value);
5827                 printk(KERN_INFO "flat interrupt happened,flat status is %d\n",
5828                                     sign_value);
5829                 if (sign_value == 1) {
5830                         input_report_abs(bma2x2->input, FLAT_INTERRUPT,
5831                                 FLAT_INTERRUPT_TURE_HAPPENED);
5832                 } else {
5833                         input_report_abs(bma2x2->input, FLAT_INTERRUPT,
5834                                 FLAT_INTERRUPT_FALSE_HAPPENED);
5835                 }
5836                 break;
5837         default:
5838                 break;
5839         }
5840
5841 }
5842
5843 static irqreturn_t bma2x2_irq_handler(int irq, void *handle)
5844 {
5845
5846
5847         struct bma2x2_data *data = handle;
5848
5849
5850         if (data == NULL)
5851                 return IRQ_HANDLED;
5852         if (data->bma2x2_client == NULL)
5853                 return IRQ_HANDLED;
5854
5855
5856         schedule_work(&data->irq_work);
5857
5858         return IRQ_HANDLED;
5859
5860
5861 }
5862 #endif /* defined(BMA2X2_ENABLE_INT1)||defined(BMA2X2_ENABLE_INT2) */
5863
5864
5865
5866 static struct device_attribute *bma2X2_attrs[] = {
5867                 &dev_attr_raw_data,
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,
5873                 NULL,
5874  };
5875         
5876 static int bma2x2_probe(struct i2c_client *client,
5877                 const struct i2c_device_id *id)
5878 {
5879         int err = 0;
5880         int tempvalue;
5881         unsigned char tmp_chip_id;
5882         struct bma2x2_data *data;
5883         struct input_dev *dev;
5884         
5885         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
5886                 printk(KERN_INFO "i2c_check_functionality error\n");
5887                 goto exit;
5888         }
5889         data = kzalloc(sizeof(struct bma2x2_data), GFP_KERNEL);
5890         if (!data) {
5891                 err = -ENOMEM;
5892                 goto exit;
5893         }
5894         /* read chip id */
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__);
5898
5899         switch (tmp_chip_id) {
5900         case BMA255_CHIP_ID:
5901                 data->sensor_type = BMA255_TYPE;
5902                 break;
5903         case BMA250E_CHIP_ID:
5904                 data->sensor_type = BMA250E_TYPE;
5905                 break;
5906         case BMA222E_CHIP_ID:
5907                 data->sensor_type = BMA222E_TYPE;
5908                 break;
5909         case BMA280_CHIP_ID:
5910                 data->sensor_type = BMA280_TYPE;
5911                 break;
5912         default:
5913                 data->sensor_type = -1;
5914         }
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]);
5920         } else{
5921                 printk(KERN_INFO "Bosch Sensortec Device not found"
5922                                 "i2c error %d\n", tempvalue);
5923                 err = -ENODEV;
5924                 goto kfree_exit;
5925         }
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);
5931
5932         err = bma2x2_set_bandwidth(client, BMA2X2_BW_SET);
5933         if (err < 0){
5934                 printk(KERN_INFO "%s set bandwidth failed!\n",
5935                         sensor_name[data->sensor_type]);
5936         }
5937
5938         err = bma2x2_set_range(client, BMA2X2_RANGE_SET);
5939         if (err < 0){
5940                 printk(KERN_INFO "%s set g-range failed!\n",
5941                         sensor_name[data->sensor_type]);
5942         }
5943
5944
5945 #if defined(BMA2X2_ENABLE_INT1) || defined(BMA2X2_ENABLE_INT2)
5946         bma2x2_set_Int_Mode(client, 1);/*latch interrupt 250ms*/
5947 #endif
5948
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);
5959 #endif
5960
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);
5971 #endif
5972
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,
5976                         "bma2x2", data);
5977         if (err)
5978                 printk(KERN_ERR "could not request irq\n");
5979
5980         INIT_WORK(&data->irq_work, bma2x2_irq_work_func);
5981 #endif
5982
5983
5984         INIT_DELAYED_WORK(&data->work, bma2x2_work_func);
5985         atomic_set(&data->delay, BMA2X2_MAX_DELAY);
5986         atomic_set(&data->enable, 0);
5987
5988         dev = input_allocate_device();
5989         if (!dev)
5990                 return -ENOMEM;
5991         dev->name = SENSOR_NAME;
5992         dev->id.bustype = BUS_I2C;
5993
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);
6005
6006         input_set_drvdata(dev, data);
6007
6008         err = input_register_device(dev);
6009         if (err < 0) {
6010                 input_free_device(dev);
6011                 goto kfree_exit;
6012         }
6013
6014         data->input = dev;
6015
6016         err = sysfs_create_group(&data->input->dev.kobj,
6017                         &bma2x2_attribute_group);
6018         if (err < 0)
6019                 goto error_sysfs;
6020
6021 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
6022         if (NULL != client->dev.platform_data) {
6023                 data->bst_pd = kzalloc(sizeof(*data->bst_pd),
6024                                 GFP_KERNEL);
6025
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",
6031                                         data->bst_pd->name,
6032                                         data->bst_pd->place);
6033                 }
6034         }
6035 #endif
6036
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);
6042 #endif
6043         
6044         err = sensors_register(&bma_device, data,bma2X2_attrs, "accelerometer_sensor");
6045     if (err < 0 )
6046         {
6047                 pr_err("%s: could not register" "accelerometer_sensor  device(%d).\n", __func__, err);
6048                 goto error_sysfs;
6049         }
6050         
6051         return 0;
6052
6053 error_sysfs:
6054         input_unregister_device(data->input);
6055
6056 kfree_exit:
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;
6061         }
6062 #endif
6063         kfree(data);
6064 exit:
6065         return err;
6066 }
6067
6068 #ifdef CONFIG_HAS_EARLYSUSPEND
6069 static void bma2x2_early_suspend(struct early_suspend *h)
6070 {
6071         struct bma2x2_data *data =
6072                 container_of(h, struct bma2x2_data, early_suspend);
6073
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);
6078         }
6079         mutex_unlock(&data->enable_mutex);
6080 }
6081
6082
6083 static void bma2x2_late_resume(struct early_suspend *h)
6084 {
6085         struct bma2x2_data *data =
6086                 container_of(h, struct bma2x2_data, early_suspend);
6087
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)));
6093         }
6094         mutex_unlock(&data->enable_mutex);
6095 }
6096 #endif
6097
6098 static int __exit bma2x2_remove(struct i2c_client *client)
6099 {
6100         struct bma2x2_data *data = i2c_get_clientdata(client);
6101
6102         bma2x2_set_enable(&client->dev, 0);
6103 #ifdef CONFIG_HAS_EARLYSUSPEND
6104         unregister_early_suspend(&data->early_suspend);
6105 #endif
6106         sensors_unregister(bma_device, bma2X2_attrs);
6107         sysfs_remove_group(&data->input->dev.kobj, &bma2x2_attribute_group);
6108         input_unregister_device(data->input);
6109
6110 #ifdef CONFIG_BMA_USE_PLATFORM_DATA
6111         if (NULL != data->bst_pd) {
6112                 kfree(data->bst_pd);
6113                 data->bst_pd = NULL;
6114         }
6115 #endif
6116
6117         kfree(data);
6118
6119         return 0;
6120 }
6121 #ifdef CONFIG_PM
6122
6123 static int bma2x2_suspend(struct i2c_client *client, pm_message_t mesg)
6124 {
6125         struct bma2x2_data *data = i2c_get_clientdata(client);
6126
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);
6131         }
6132         mutex_unlock(&data->enable_mutex);
6133
6134         return 0;
6135 }
6136
6137 static int bma2x2_resume(struct i2c_client *client)
6138 {
6139         struct bma2x2_data *data = i2c_get_clientdata(client);
6140
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)));
6146         }
6147         mutex_unlock(&data->enable_mutex);
6148
6149         return 0;
6150 }
6151
6152 #else
6153
6154 #define bma2x2_suspend          NULL
6155 #define bma2x2_resume           NULL
6156
6157 #endif /* CONFIG_PM */
6158
6159 static const struct i2c_device_id bma2x2_id[] = {
6160         { SENSOR_NAME, 0 },
6161         { }
6162 };
6163
6164 MODULE_DEVICE_TABLE(i2c, bma2x2_id);
6165
6166 static struct i2c_driver bma2x2_driver = {
6167         .driver = {
6168                 .owner  = THIS_MODULE,
6169                 .name   = SENSOR_NAME,
6170         },
6171         .suspend        = bma2x2_suspend,
6172         .resume         = bma2x2_resume,
6173         .id_table       = bma2x2_id,
6174         .probe          = bma2x2_probe,
6175         .remove         = bma2x2_remove,
6176
6177 };
6178
6179 static int __init BMA2X2_init(void)
6180 {
6181         return i2c_add_driver(&bma2x2_driver);
6182 }
6183
6184 static void __exit BMA2X2_exit(void)
6185 {
6186         i2c_del_driver(&bma2x2_driver);
6187 }
6188
6189 MODULE_AUTHOR("Albert Zhang <xu.zhang@bosch-sensortec.com>");
6190 MODULE_DESCRIPTION("BMA2X2 accelerometer sensor driver");
6191 MODULE_LICENSE("GPL");
6192
6193 module_init(BMA2X2_init);
6194 module_exit(BMA2X2_exit);