blob: 4bffe51e11ae57de3b93628d71d41611e085df61 [file] [log] [blame]
Bosch Sensortecface5922018-08-29 08:08:53 +02001/*!
2 * @section LICENSE
3 * (C) Copyright 2011~2016 Bosch Sensortec GmbH All Rights Reserved
4 *
5 * (C) Modification Copyright 2018 Robert Bosch Kft All Rights Reserved
6 *
7 * This software program is licensed subject to the GNU General
8 * Public License (GPL).Version 2,June 1991,
9 * available at http://www.fsf.org/copyleft/gpl.html
10 *
11 * Special: Description of the Software:
12 *
13 * This software module (hereinafter called "Software") and any
14 * information on application-sheets (hereinafter called "Information") is
15 * provided free of charge for the sole purpose to support your application
16 * work.
17 *
18 * As such, the Software is merely an experimental software, not tested for
19 * safety in the field and only intended for inspiration for further development
20 * and testing. Any usage in a safety-relevant field of use (like automotive,
21 * seafaring, spacefaring, industrial plants etc.) was not intended, so there are
22 * no precautions for such usage incorporated in the Software.
23 *
24 * The Software is specifically designed for the exclusive use for Bosch
25 * Sensortec products by personnel who have special experience and training. Do
26 * not use this Software if you do not have the proper experience or training.
27 *
28 * This Software package is provided as is and without any expressed or
29 * implied warranties, including without limitation, the implied warranties of
30 * merchantability and fitness for a particular purpose.
31 *
32 * Bosch Sensortec and their representatives and agents deny any liability for
33 * the functional impairment of this Software in terms of fitness, performance
34 * and safety. Bosch Sensortec and their representatives and agents shall not be
35 * liable for any direct or indirect damages or injury, except as otherwise
36 * stipulated in mandatory applicable law.
37 * The Information provided is believed to be accurate and reliable. Bosch
38 * Sensortec assumes no responsibility for the consequences of use of such
39 * Information nor for any infringement of patents or other rights of third
40 * parties which may result from its use.
41 *
42 *------------------------------------------------------------------------------
43 * The following Product Disclaimer does not apply to the BSX4-HAL-4.1NoFusion Software
44 * which is licensed under the Apache License, Version 2.0 as stated above.
45 * http://www.apache.org/licenses/LICENSE-2.0
46 *
47 * Product Disclaimer
48 *
49 * Common:
50 *
51 * Assessment of Products Returned from Field
52 *
53 * Returned products are considered good if they fulfill the specifications /
54 * test data for 0-mileage and field listed in this document.
55 *
56 * Engineering Samples
57 *
58 * Engineering samples are marked with (e) or (E). Samples may vary from the
59 * valid technical specifications of the series product contained in this
60 * data sheet. Therefore, they are not intended or fit for resale to
61 * third parties or for use in end products. Their sole purpose is internal
62 * client testing. The testing of an engineering sample may in no way replace
63 * the testing of a series product. Bosch assumes no liability for the use
64 * of engineering samples. The purchaser shall indemnify Bosch from all claims
65 * arising from the use of engineering samples.
66 *
67 * Intended use
68 *
69 * Provided that SMI130 is used within the conditions (environment, application,
70 * installation, loads) as described in this TCD and the corresponding
71 * agreed upon documents, Bosch ensures that the product complies with
72 * the agreed properties. Agreements beyond this require
73 * the written approval by Bosch. The product is considered fit for the intended
74 * use when the product successfully has passed the tests
75 * in accordance with the TCD and agreed upon documents.
76 *
77 * It is the responsibility of the customer to ensure the proper application
78 * of the product in the overall system/vehicle.
79 *
80 * Bosch does not assume any responsibility for changes to the environment
81 * of the product that deviate from the TCD and the agreed upon documents
82 * as well as all applications not released by Bosch
83 *
84 * The resale and/or use of products are at the purchaser’s own risk and
85 * responsibility. The examination and testing of the SMI130
86 * is the sole responsibility of the purchaser.
87 *
88 * The purchaser shall indemnify Bosch from all third party claims
89 * arising from any product use not covered by the parameters of
90 * this product data sheet or not approved by Bosch and reimburse Bosch
91 * for all costs and damages in connection with such claims.
92 *
93 * The purchaser must monitor the market for the purchased products,
94 * particularly with regard to product safety, and inform Bosch without delay
95 * of all security relevant incidents.
96 *
97 * Application Examples and Hints
98 *
99 * With respect to any application examples, advice, normal values
100 * and/or any information regarding the application of the device,
101 * Bosch hereby disclaims any and all warranties and liabilities of any kind,
102 * including without limitation warranties of
103 * non-infringement of intellectual property rights or copyrights
104 * of any third party.
105 * The information given in this document shall in no event be regarded
106 * as a guarantee of conditions or characteristics. They are provided
107 * for illustrative purposes only and no evaluation regarding infringement
108 * of intellectual property rights or copyrights or regarding functionality,
109 * performance or error has been made.
110 *
111 * @filename smi130_acc.c
112 * @date 2015/11/17 10:32
113 * @Modification Date 2018/08/28 18:20
114 * @id "836294d"
115 * @version 2.1.2
116 *
117 * @brief
118 * This file contains all function implementations for the SMI_ACC2X2 in linux
119*/
120
121#ifdef CONFIG_SIG_MOTION
122#undef CONFIG_HAS_EARLYSUSPEND
123#endif
124#include <linux/module.h>
125#include <linux/init.h>
126#include <linux/i2c.h>
127#include <linux/input.h>
128#include <linux/workqueue.h>
129#include <linux/mutex.h>
130#include <linux/slab.h>
131#include <linux/mutex.h>
132#include <linux/interrupt.h>
133#include <linux/delay.h>
134#include <asm/irq.h>
135#include <linux/math64.h>
puneet597e4f12018-11-06 14:32:16 +0530136#include <linux/cpu.h>
Bosch Sensortecface5922018-08-29 08:08:53 +0200137#ifdef CONFIG_HAS_EARLYSUSPEND
138#include <linux/earlysuspend.h>
139#endif
140
141#ifdef __KERNEL__
142#include <linux/kernel.h>
143#include <linux/module.h>
144#include <linux/unistd.h>
145#include <linux/types.h>
146#include <linux/string.h>
147#else
148#include <unistd.h>
149#include <sys/types.h>
150#include <string.h>
151#endif
152
153#include "boschclass.h"
154#include "bs_log.h"
155#define DRIVER_VERSION "0.0.53.0"
156#define ACC_NAME "ACC"
Puneet Yatnal645c8f32018-12-13 12:53:44 +0530157#define SMI_ACC2X2_ENABLE_INT2 1
Bosch Sensortecface5922018-08-29 08:08:53 +0200158#define CONFIG_SMI_ACC_ENABLE_NEWDATA_INT 1
159
160#define SENSOR_NAME "smi130_acc"
161#define SMI130_ACC_USE_BASIC_I2C_FUNC 1
puneet597e4f12018-11-06 14:32:16 +0530162#define SMI130_HRTIMER 1
Bosch Sensortecface5922018-08-29 08:08:53 +0200163#define MSC_TIME 6
164#define ABSMIN -512
165#define ABSMAX 512
166#define SLOPE_THRESHOLD_VALUE 32
167#define SLOPE_DURATION_VALUE 1
168#define INTERRUPT_LATCH_MODE 13
169#define INTERRUPT_ENABLE 1
170#define INTERRUPT_DISABLE 0
171#define MAP_SLOPE_INTERRUPT 2
172#define SLOPE_X_INDEX 5
173#define SLOPE_Y_INDEX 6
174#define SLOPE_Z_INDEX 7
175#define SMI_ACC2X2_MAX_DELAY 200
176#define SMI_ACC2X2_RANGE_SET 3 /* +/- 2G */
177#define SMI_ACC2X2_BW_SET 12 /* 125HZ */
178
179#define LOW_G_INTERRUPT REL_Z
180#define HIGH_G_INTERRUPT REL_HWHEEL
181#define SLOP_INTERRUPT REL_DIAL
182#define DOUBLE_TAP_INTERRUPT REL_WHEEL
183#define SINGLE_TAP_INTERRUPT REL_MISC
184#define ORIENT_INTERRUPT ABS_PRESSURE
185#define FLAT_INTERRUPT ABS_DISTANCE
186#define SLOW_NO_MOTION_INTERRUPT REL_Y
187
188#define HIGH_G_INTERRUPT_X_HAPPENED 1
189#define HIGH_G_INTERRUPT_Y_HAPPENED 2
190#define HIGH_G_INTERRUPT_Z_HAPPENED 3
191#define HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED 4
192#define HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED 5
193#define HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED 6
194#define SLOPE_INTERRUPT_X_HAPPENED 7
195#define SLOPE_INTERRUPT_Y_HAPPENED 8
196#define SLOPE_INTERRUPT_Z_HAPPENED 9
197#define SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED 10
198#define SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED 11
199#define SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED 12
200#define DOUBLE_TAP_INTERRUPT_HAPPENED 13
201#define SINGLE_TAP_INTERRUPT_HAPPENED 14
202#define UPWARD_PORTRAIT_UP_INTERRUPT_HAPPENED 15
203#define UPWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED 16
204#define UPWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED 17
205#define UPWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED 18
206#define DOWNWARD_PORTRAIT_UP_INTERRUPT_HAPPENED 19
207#define DOWNWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED 20
208#define DOWNWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED 21
209#define DOWNWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED 22
210#define FLAT_INTERRUPT_TURE_HAPPENED 23
211#define FLAT_INTERRUPT_FALSE_HAPPENED 24
212#define LOW_G_INTERRUPT_HAPPENED 25
213#define SLOW_NO_MOTION_INTERRUPT_HAPPENED 26
214
215#define PAD_LOWG 0
216#define PAD_HIGHG 1
217#define PAD_SLOP 2
218#define PAD_DOUBLE_TAP 3
219#define PAD_SINGLE_TAP 4
220#define PAD_ORIENT 5
221#define PAD_FLAT 6
222#define PAD_SLOW_NO_MOTION 7
223
224#define SMI_ACC2X2_EEP_OFFSET 0x16
225#define SMI_ACC2X2_IMAGE_BASE 0x38
226#define SMI_ACC2X2_IMAGE_LEN 22
227
228#define SMI_ACC2X2_CHIP_ID_REG 0x00
229#define SMI_ACC2X2_VERSION_REG 0x01
230#define SMI_ACC2X2_X_AXIS_LSB_REG 0x02
231#define SMI_ACC2X2_X_AXIS_MSB_REG 0x03
232#define SMI_ACC2X2_Y_AXIS_LSB_REG 0x04
233#define SMI_ACC2X2_Y_AXIS_MSB_REG 0x05
234#define SMI_ACC2X2_Z_AXIS_LSB_REG 0x06
235#define SMI_ACC2X2_Z_AXIS_MSB_REG 0x07
236#define SMI_ACC2X2_TEMPERATURE_REG 0x08
237#define SMI_ACC2X2_STATUS1_REG 0x09
238#define SMI_ACC2X2_STATUS2_REG 0x0A
239#define SMI_ACC2X2_STATUS_TAP_SLOPE_REG 0x0B
240#define SMI_ACC2X2_STATUS_ORIENT_HIGH_REG 0x0C
241#define SMI_ACC2X2_STATUS_FIFO_REG 0x0E
242#define SMI_ACC2X2_RANGE_SEL_REG 0x0F
243#define SMI_ACC2X2_BW_SEL_REG 0x10
244#define SMI_ACC2X2_MODE_CTRL_REG 0x11
245#define SMI_ACC2X2_LOW_NOISE_CTRL_REG 0x12
246#define SMI_ACC2X2_DATA_CTRL_REG 0x13
247#define SMI_ACC2X2_RESET_REG 0x14
248#define SMI_ACC2X2_INT_ENABLE1_REG 0x16
249#define SMI_ACC2X2_INT_ENABLE2_REG 0x17
250#define SMI_ACC2X2_INT_SLO_NO_MOT_REG 0x18
251#define SMI_ACC2X2_INT1_PAD_SEL_REG 0x19
252#define SMI_ACC2X2_INT_DATA_SEL_REG 0x1A
253#define SMI_ACC2X2_INT2_PAD_SEL_REG 0x1B
254#define SMI_ACC2X2_INT_SRC_REG 0x1E
255#define SMI_ACC2X2_INT_SET_REG 0x20
256#define SMI_ACC2X2_INT_CTRL_REG 0x21
257#define SMI_ACC2X2_LOW_DURN_REG 0x22
258#define SMI_ACC2X2_LOW_THRES_REG 0x23
259#define SMI_ACC2X2_LOW_HIGH_HYST_REG 0x24
260#define SMI_ACC2X2_HIGH_DURN_REG 0x25
261#define SMI_ACC2X2_HIGH_THRES_REG 0x26
262#define SMI_ACC2X2_SLOPE_DURN_REG 0x27
263#define SMI_ACC2X2_SLOPE_THRES_REG 0x28
264#define SMI_ACC2X2_SLO_NO_MOT_THRES_REG 0x29
265#define SMI_ACC2X2_TAP_PARAM_REG 0x2A
266#define SMI_ACC2X2_TAP_THRES_REG 0x2B
267#define SMI_ACC2X2_ORIENT_PARAM_REG 0x2C
268#define SMI_ACC2X2_THETA_BLOCK_REG 0x2D
269#define SMI_ACC2X2_THETA_FLAT_REG 0x2E
270#define SMI_ACC2X2_FLAT_HOLD_TIME_REG 0x2F
271#define SMI_ACC2X2_FIFO_WML_TRIG 0x30
272#define SMI_ACC2X2_SELF_TEST_REG 0x32
273#define SMI_ACC2X2_EEPROM_CTRL_REG 0x33
274#define SMI_ACC2X2_SERIAL_CTRL_REG 0x34
275#define SMI_ACC2X2_EXTMODE_CTRL_REG 0x35
276#define SMI_ACC2X2_OFFSET_CTRL_REG 0x36
277#define SMI_ACC2X2_OFFSET_PARAMS_REG 0x37
278#define SMI_ACC2X2_OFFSET_X_AXIS_REG 0x38
279#define SMI_ACC2X2_OFFSET_Y_AXIS_REG 0x39
280#define SMI_ACC2X2_OFFSET_Z_AXIS_REG 0x3A
281#define SMI_ACC2X2_GP0_REG 0x3B
282#define SMI_ACC2X2_GP1_REG 0x3C
283#define SMI_ACC2X2_FIFO_MODE_REG 0x3E
284#define SMI_ACC2X2_FIFO_DATA_OUTPUT_REG 0x3F
285
286#define SMI_ACC2X2_CHIP_ID__POS 0
287#define SMI_ACC2X2_CHIP_ID__MSK 0xFF
288#define SMI_ACC2X2_CHIP_ID__LEN 8
289#define SMI_ACC2X2_CHIP_ID__REG SMI_ACC2X2_CHIP_ID_REG
290
291#define SMI_ACC2X2_VERSION__POS 0
292#define SMI_ACC2X2_VERSION__LEN 8
293#define SMI_ACC2X2_VERSION__MSK 0xFF
294#define SMI_ACC2X2_VERSION__REG SMI_ACC2X2_VERSION_REG
295
296#define SMI130_ACC_SLO_NO_MOT_DUR__POS 2
297#define SMI130_ACC_SLO_NO_MOT_DUR__LEN 6
298#define SMI130_ACC_SLO_NO_MOT_DUR__MSK 0xFC
299#define SMI130_ACC_SLO_NO_MOT_DUR__REG SMI_ACC2X2_SLOPE_DURN_REG
300
301#define SMI_ACC2X2_NEW_DATA_X__POS 0
302#define SMI_ACC2X2_NEW_DATA_X__LEN 1
303#define SMI_ACC2X2_NEW_DATA_X__MSK 0x01
304#define SMI_ACC2X2_NEW_DATA_X__REG SMI_ACC2X2_X_AXIS_LSB_REG
305
306#define SMI_ACC2X2_ACC_X14_LSB__POS 2
307#define SMI_ACC2X2_ACC_X14_LSB__LEN 6
308#define SMI_ACC2X2_ACC_X14_LSB__MSK 0xFC
309#define SMI_ACC2X2_ACC_X14_LSB__REG SMI_ACC2X2_X_AXIS_LSB_REG
310
311#define SMI_ACC2X2_ACC_X12_LSB__POS 4
312#define SMI_ACC2X2_ACC_X12_LSB__LEN 4
313#define SMI_ACC2X2_ACC_X12_LSB__MSK 0xF0
314#define SMI_ACC2X2_ACC_X12_LSB__REG SMI_ACC2X2_X_AXIS_LSB_REG
315
316#define SMI_ACC2X2_ACC_X10_LSB__POS 6
317#define SMI_ACC2X2_ACC_X10_LSB__LEN 2
318#define SMI_ACC2X2_ACC_X10_LSB__MSK 0xC0
319#define SMI_ACC2X2_ACC_X10_LSB__REG SMI_ACC2X2_X_AXIS_LSB_REG
320
321#define SMI_ACC2X2_ACC_X8_LSB__POS 0
322#define SMI_ACC2X2_ACC_X8_LSB__LEN 0
323#define SMI_ACC2X2_ACC_X8_LSB__MSK 0x00
324#define SMI_ACC2X2_ACC_X8_LSB__REG SMI_ACC2X2_X_AXIS_LSB_REG
325
326#define SMI_ACC2X2_ACC_X_MSB__POS 0
327#define SMI_ACC2X2_ACC_X_MSB__LEN 8
328#define SMI_ACC2X2_ACC_X_MSB__MSK 0xFF
329#define SMI_ACC2X2_ACC_X_MSB__REG SMI_ACC2X2_X_AXIS_MSB_REG
330
331#define SMI_ACC2X2_NEW_DATA_Y__POS 0
332#define SMI_ACC2X2_NEW_DATA_Y__LEN 1
333#define SMI_ACC2X2_NEW_DATA_Y__MSK 0x01
334#define SMI_ACC2X2_NEW_DATA_Y__REG SMI_ACC2X2_Y_AXIS_LSB_REG
335
336#define SMI_ACC2X2_ACC_Y14_LSB__POS 2
337#define SMI_ACC2X2_ACC_Y14_LSB__LEN 6
338#define SMI_ACC2X2_ACC_Y14_LSB__MSK 0xFC
339#define SMI_ACC2X2_ACC_Y14_LSB__REG SMI_ACC2X2_Y_AXIS_LSB_REG
340
341#define SMI_ACC2X2_ACC_Y12_LSB__POS 4
342#define SMI_ACC2X2_ACC_Y12_LSB__LEN 4
343#define SMI_ACC2X2_ACC_Y12_LSB__MSK 0xF0
344#define SMI_ACC2X2_ACC_Y12_LSB__REG SMI_ACC2X2_Y_AXIS_LSB_REG
345
346#define SMI_ACC2X2_ACC_Y10_LSB__POS 6
347#define SMI_ACC2X2_ACC_Y10_LSB__LEN 2
348#define SMI_ACC2X2_ACC_Y10_LSB__MSK 0xC0
349#define SMI_ACC2X2_ACC_Y10_LSB__REG SMI_ACC2X2_Y_AXIS_LSB_REG
350
351#define SMI_ACC2X2_ACC_Y8_LSB__POS 0
352#define SMI_ACC2X2_ACC_Y8_LSB__LEN 0
353#define SMI_ACC2X2_ACC_Y8_LSB__MSK 0x00
354#define SMI_ACC2X2_ACC_Y8_LSB__REG SMI_ACC2X2_Y_AXIS_LSB_REG
355
356#define SMI_ACC2X2_ACC_Y_MSB__POS 0
357#define SMI_ACC2X2_ACC_Y_MSB__LEN 8
358#define SMI_ACC2X2_ACC_Y_MSB__MSK 0xFF
359#define SMI_ACC2X2_ACC_Y_MSB__REG SMI_ACC2X2_Y_AXIS_MSB_REG
360
361#define SMI_ACC2X2_NEW_DATA_Z__POS 0
362#define SMI_ACC2X2_NEW_DATA_Z__LEN 1
363#define SMI_ACC2X2_NEW_DATA_Z__MSK 0x01
364#define SMI_ACC2X2_NEW_DATA_Z__REG SMI_ACC2X2_Z_AXIS_LSB_REG
365
366#define SMI_ACC2X2_ACC_Z14_LSB__POS 2
367#define SMI_ACC2X2_ACC_Z14_LSB__LEN 6
368#define SMI_ACC2X2_ACC_Z14_LSB__MSK 0xFC
369#define SMI_ACC2X2_ACC_Z14_LSB__REG SMI_ACC2X2_Z_AXIS_LSB_REG
370
371#define SMI_ACC2X2_ACC_Z12_LSB__POS 4
372#define SMI_ACC2X2_ACC_Z12_LSB__LEN 4
373#define SMI_ACC2X2_ACC_Z12_LSB__MSK 0xF0
374#define SMI_ACC2X2_ACC_Z12_LSB__REG SMI_ACC2X2_Z_AXIS_LSB_REG
375
376#define SMI_ACC2X2_ACC_Z10_LSB__POS 6
377#define SMI_ACC2X2_ACC_Z10_LSB__LEN 2
378#define SMI_ACC2X2_ACC_Z10_LSB__MSK 0xC0
379#define SMI_ACC2X2_ACC_Z10_LSB__REG SMI_ACC2X2_Z_AXIS_LSB_REG
380
381#define SMI_ACC2X2_ACC_Z8_LSB__POS 0
382#define SMI_ACC2X2_ACC_Z8_LSB__LEN 0
383#define SMI_ACC2X2_ACC_Z8_LSB__MSK 0x00
384#define SMI_ACC2X2_ACC_Z8_LSB__REG SMI_ACC2X2_Z_AXIS_LSB_REG
385
386#define SMI_ACC2X2_ACC_Z_MSB__POS 0
387#define SMI_ACC2X2_ACC_Z_MSB__LEN 8
388#define SMI_ACC2X2_ACC_Z_MSB__MSK 0xFF
389#define SMI_ACC2X2_ACC_Z_MSB__REG SMI_ACC2X2_Z_AXIS_MSB_REG
390
391#define SMI_ACC2X2_TEMPERATURE__POS 0
392#define SMI_ACC2X2_TEMPERATURE__LEN 8
393#define SMI_ACC2X2_TEMPERATURE__MSK 0xFF
394#define SMI_ACC2X2_TEMPERATURE__REG SMI_ACC2X2_TEMP_RD_REG
395
396#define SMI_ACC2X2_LOWG_INT_S__POS 0
397#define SMI_ACC2X2_LOWG_INT_S__LEN 1
398#define SMI_ACC2X2_LOWG_INT_S__MSK 0x01
399#define SMI_ACC2X2_LOWG_INT_S__REG SMI_ACC2X2_STATUS1_REG
400
401#define SMI_ACC2X2_HIGHG_INT_S__POS 1
402#define SMI_ACC2X2_HIGHG_INT_S__LEN 1
403#define SMI_ACC2X2_HIGHG_INT_S__MSK 0x02
404#define SMI_ACC2X2_HIGHG_INT_S__REG SMI_ACC2X2_STATUS1_REG
405
406#define SMI_ACC2X2_SLOPE_INT_S__POS 2
407#define SMI_ACC2X2_SLOPE_INT_S__LEN 1
408#define SMI_ACC2X2_SLOPE_INT_S__MSK 0x04
409#define SMI_ACC2X2_SLOPE_INT_S__REG SMI_ACC2X2_STATUS1_REG
410
411
412#define SMI_ACC2X2_SLO_NO_MOT_INT_S__POS 3
413#define SMI_ACC2X2_SLO_NO_MOT_INT_S__LEN 1
414#define SMI_ACC2X2_SLO_NO_MOT_INT_S__MSK 0x08
415#define SMI_ACC2X2_SLO_NO_MOT_INT_S__REG SMI_ACC2X2_STATUS1_REG
416
417#define SMI_ACC2X2_DOUBLE_TAP_INT_S__POS 4
418#define SMI_ACC2X2_DOUBLE_TAP_INT_S__LEN 1
419#define SMI_ACC2X2_DOUBLE_TAP_INT_S__MSK 0x10
420#define SMI_ACC2X2_DOUBLE_TAP_INT_S__REG SMI_ACC2X2_STATUS1_REG
421
422#define SMI_ACC2X2_SINGLE_TAP_INT_S__POS 5
423#define SMI_ACC2X2_SINGLE_TAP_INT_S__LEN 1
424#define SMI_ACC2X2_SINGLE_TAP_INT_S__MSK 0x20
425#define SMI_ACC2X2_SINGLE_TAP_INT_S__REG SMI_ACC2X2_STATUS1_REG
426
427#define SMI_ACC2X2_ORIENT_INT_S__POS 6
428#define SMI_ACC2X2_ORIENT_INT_S__LEN 1
429#define SMI_ACC2X2_ORIENT_INT_S__MSK 0x40
430#define SMI_ACC2X2_ORIENT_INT_S__REG SMI_ACC2X2_STATUS1_REG
431
432#define SMI_ACC2X2_FLAT_INT_S__POS 7
433#define SMI_ACC2X2_FLAT_INT_S__LEN 1
434#define SMI_ACC2X2_FLAT_INT_S__MSK 0x80
435#define SMI_ACC2X2_FLAT_INT_S__REG SMI_ACC2X2_STATUS1_REG
436
437#define SMI_ACC2X2_FIFO_FULL_INT_S__POS 5
438#define SMI_ACC2X2_FIFO_FULL_INT_S__LEN 1
439#define SMI_ACC2X2_FIFO_FULL_INT_S__MSK 0x20
440#define SMI_ACC2X2_FIFO_FULL_INT_S__REG SMI_ACC2X2_STATUS2_REG
441
442#define SMI_ACC2X2_FIFO_WM_INT_S__POS 6
443#define SMI_ACC2X2_FIFO_WM_INT_S__LEN 1
444#define SMI_ACC2X2_FIFO_WM_INT_S__MSK 0x40
445#define SMI_ACC2X2_FIFO_WM_INT_S__REG SMI_ACC2X2_STATUS2_REG
446
447#define SMI_ACC2X2_DATA_INT_S__POS 7
448#define SMI_ACC2X2_DATA_INT_S__LEN 1
449#define SMI_ACC2X2_DATA_INT_S__MSK 0x80
450#define SMI_ACC2X2_DATA_INT_S__REG SMI_ACC2X2_STATUS2_REG
451
452#define SMI_ACC2X2_SLOPE_FIRST_X__POS 0
453#define SMI_ACC2X2_SLOPE_FIRST_X__LEN 1
454#define SMI_ACC2X2_SLOPE_FIRST_X__MSK 0x01
455#define SMI_ACC2X2_SLOPE_FIRST_X__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
456
457#define SMI_ACC2X2_SLOPE_FIRST_Y__POS 1
458#define SMI_ACC2X2_SLOPE_FIRST_Y__LEN 1
459#define SMI_ACC2X2_SLOPE_FIRST_Y__MSK 0x02
460#define SMI_ACC2X2_SLOPE_FIRST_Y__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
461
462#define SMI_ACC2X2_SLOPE_FIRST_Z__POS 2
463#define SMI_ACC2X2_SLOPE_FIRST_Z__LEN 1
464#define SMI_ACC2X2_SLOPE_FIRST_Z__MSK 0x04
465#define SMI_ACC2X2_SLOPE_FIRST_Z__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
466
467#define SMI_ACC2X2_SLOPE_SIGN_S__POS 3
468#define SMI_ACC2X2_SLOPE_SIGN_S__LEN 1
469#define SMI_ACC2X2_SLOPE_SIGN_S__MSK 0x08
470#define SMI_ACC2X2_SLOPE_SIGN_S__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
471
472#define SMI_ACC2X2_TAP_FIRST_X__POS 4
473#define SMI_ACC2X2_TAP_FIRST_X__LEN 1
474#define SMI_ACC2X2_TAP_FIRST_X__MSK 0x10
475#define SMI_ACC2X2_TAP_FIRST_X__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
476
477#define SMI_ACC2X2_TAP_FIRST_Y__POS 5
478#define SMI_ACC2X2_TAP_FIRST_Y__LEN 1
479#define SMI_ACC2X2_TAP_FIRST_Y__MSK 0x20
480#define SMI_ACC2X2_TAP_FIRST_Y__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
481
482#define SMI_ACC2X2_TAP_FIRST_Z__POS 6
483#define SMI_ACC2X2_TAP_FIRST_Z__LEN 1
484#define SMI_ACC2X2_TAP_FIRST_Z__MSK 0x40
485#define SMI_ACC2X2_TAP_FIRST_Z__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
486
487#define SMI_ACC2X2_TAP_SIGN_S__POS 7
488#define SMI_ACC2X2_TAP_SIGN_S__LEN 1
489#define SMI_ACC2X2_TAP_SIGN_S__MSK 0x80
490#define SMI_ACC2X2_TAP_SIGN_S__REG SMI_ACC2X2_STATUS_TAP_SLOPE_REG
491
492#define SMI_ACC2X2_HIGHG_FIRST_X__POS 0
493#define SMI_ACC2X2_HIGHG_FIRST_X__LEN 1
494#define SMI_ACC2X2_HIGHG_FIRST_X__MSK 0x01
495#define SMI_ACC2X2_HIGHG_FIRST_X__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
496
497#define SMI_ACC2X2_HIGHG_FIRST_Y__POS 1
498#define SMI_ACC2X2_HIGHG_FIRST_Y__LEN 1
499#define SMI_ACC2X2_HIGHG_FIRST_Y__MSK 0x02
500#define SMI_ACC2X2_HIGHG_FIRST_Y__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
501
502#define SMI_ACC2X2_HIGHG_FIRST_Z__POS 2
503#define SMI_ACC2X2_HIGHG_FIRST_Z__LEN 1
504#define SMI_ACC2X2_HIGHG_FIRST_Z__MSK 0x04
505#define SMI_ACC2X2_HIGHG_FIRST_Z__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
506
507#define SMI_ACC2X2_HIGHG_SIGN_S__POS 3
508#define SMI_ACC2X2_HIGHG_SIGN_S__LEN 1
509#define SMI_ACC2X2_HIGHG_SIGN_S__MSK 0x08
510#define SMI_ACC2X2_HIGHG_SIGN_S__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
511
512#define SMI_ACC2X2_ORIENT_S__POS 4
513#define SMI_ACC2X2_ORIENT_S__LEN 3
514#define SMI_ACC2X2_ORIENT_S__MSK 0x70
515#define SMI_ACC2X2_ORIENT_S__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
516
517#define SMI_ACC2X2_FLAT_S__POS 7
518#define SMI_ACC2X2_FLAT_S__LEN 1
519#define SMI_ACC2X2_FLAT_S__MSK 0x80
520#define SMI_ACC2X2_FLAT_S__REG SMI_ACC2X2_STATUS_ORIENT_HIGH_REG
521
522#define SMI_ACC2X2_FIFO_FRAME_COUNTER_S__POS 0
523#define SMI_ACC2X2_FIFO_FRAME_COUNTER_S__LEN 7
524#define SMI_ACC2X2_FIFO_FRAME_COUNTER_S__MSK 0x7F
525#define SMI_ACC2X2_FIFO_FRAME_COUNTER_S__REG SMI_ACC2X2_STATUS_FIFO_REG
526
527#define SMI_ACC2X2_FIFO_OVERRUN_S__POS 7
528#define SMI_ACC2X2_FIFO_OVERRUN_S__LEN 1
529#define SMI_ACC2X2_FIFO_OVERRUN_S__MSK 0x80
530#define SMI_ACC2X2_FIFO_OVERRUN_S__REG SMI_ACC2X2_STATUS_FIFO_REG
531
532#define SMI_ACC2X2_RANGE_SEL__POS 0
533#define SMI_ACC2X2_RANGE_SEL__LEN 4
534#define SMI_ACC2X2_RANGE_SEL__MSK 0x0F
535#define SMI_ACC2X2_RANGE_SEL__REG SMI_ACC2X2_RANGE_SEL_REG
536
537#define SMI_ACC2X2_BANDWIDTH__POS 0
538#define SMI_ACC2X2_BANDWIDTH__LEN 5
539#define SMI_ACC2X2_BANDWIDTH__MSK 0x1F
540#define SMI_ACC2X2_BANDWIDTH__REG SMI_ACC2X2_BW_SEL_REG
541
542#define SMI_ACC2X2_SLEEP_DUR__POS 1
543#define SMI_ACC2X2_SLEEP_DUR__LEN 4
544#define SMI_ACC2X2_SLEEP_DUR__MSK 0x1E
545#define SMI_ACC2X2_SLEEP_DUR__REG SMI_ACC2X2_MODE_CTRL_REG
546
547#define SMI_ACC2X2_MODE_CTRL__POS 5
548#define SMI_ACC2X2_MODE_CTRL__LEN 3
549#define SMI_ACC2X2_MODE_CTRL__MSK 0xE0
550#define SMI_ACC2X2_MODE_CTRL__REG SMI_ACC2X2_MODE_CTRL_REG
551
552#define SMI_ACC2X2_DEEP_SUSPEND__POS 5
553#define SMI_ACC2X2_DEEP_SUSPEND__LEN 1
554#define SMI_ACC2X2_DEEP_SUSPEND__MSK 0x20
555#define SMI_ACC2X2_DEEP_SUSPEND__REG SMI_ACC2X2_MODE_CTRL_REG
556
557#define SMI_ACC2X2_EN_LOW_POWER__POS 6
558#define SMI_ACC2X2_EN_LOW_POWER__LEN 1
559#define SMI_ACC2X2_EN_LOW_POWER__MSK 0x40
560#define SMI_ACC2X2_EN_LOW_POWER__REG SMI_ACC2X2_MODE_CTRL_REG
561
562#define SMI_ACC2X2_EN_SUSPEND__POS 7
563#define SMI_ACC2X2_EN_SUSPEND__LEN 1
564#define SMI_ACC2X2_EN_SUSPEND__MSK 0x80
565#define SMI_ACC2X2_EN_SUSPEND__REG SMI_ACC2X2_MODE_CTRL_REG
566
567#define SMI_ACC2X2_SLEEP_TIMER__POS 5
568#define SMI_ACC2X2_SLEEP_TIMER__LEN 1
569#define SMI_ACC2X2_SLEEP_TIMER__MSK 0x20
570#define SMI_ACC2X2_SLEEP_TIMER__REG SMI_ACC2X2_LOW_NOISE_CTRL_REG
571
572#define SMI_ACC2X2_LOW_POWER_MODE__POS 6
573#define SMI_ACC2X2_LOW_POWER_MODE__LEN 1
574#define SMI_ACC2X2_LOW_POWER_MODE__MSK 0x40
575#define SMI_ACC2X2_LOW_POWER_MODE__REG SMI_ACC2X2_LOW_NOISE_CTRL_REG
576
577#define SMI_ACC2X2_EN_LOW_NOISE__POS 7
578#define SMI_ACC2X2_EN_LOW_NOISE__LEN 1
579#define SMI_ACC2X2_EN_LOW_NOISE__MSK 0x80
580#define SMI_ACC2X2_EN_LOW_NOISE__REG SMI_ACC2X2_LOW_NOISE_CTRL_REG
581
582#define SMI_ACC2X2_DIS_SHADOW_PROC__POS 6
583#define SMI_ACC2X2_DIS_SHADOW_PROC__LEN 1
584#define SMI_ACC2X2_DIS_SHADOW_PROC__MSK 0x40
585#define SMI_ACC2X2_DIS_SHADOW_PROC__REG SMI_ACC2X2_DATA_CTRL_REG
586
587#define SMI_ACC2X2_EN_DATA_HIGH_BW__POS 7
588#define SMI_ACC2X2_EN_DATA_HIGH_BW__LEN 1
589#define SMI_ACC2X2_EN_DATA_HIGH_BW__MSK 0x80
590#define SMI_ACC2X2_EN_DATA_HIGH_BW__REG SMI_ACC2X2_DATA_CTRL_REG
591
592#define SMI_ACC2X2_EN_SOFT_RESET__POS 0
593#define SMI_ACC2X2_EN_SOFT_RESET__LEN 8
594#define SMI_ACC2X2_EN_SOFT_RESET__MSK 0xFF
595#define SMI_ACC2X2_EN_SOFT_RESET__REG SMI_ACC2X2_RESET_REG
596
597#define SMI_ACC2X2_EN_SOFT_RESET_VALUE 0xB6
598
599#define SMI_ACC2X2_EN_SLOPE_X_INT__POS 0
600#define SMI_ACC2X2_EN_SLOPE_X_INT__LEN 1
601#define SMI_ACC2X2_EN_SLOPE_X_INT__MSK 0x01
602#define SMI_ACC2X2_EN_SLOPE_X_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
603
604#define SMI_ACC2X2_EN_SLOPE_Y_INT__POS 1
605#define SMI_ACC2X2_EN_SLOPE_Y_INT__LEN 1
606#define SMI_ACC2X2_EN_SLOPE_Y_INT__MSK 0x02
607#define SMI_ACC2X2_EN_SLOPE_Y_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
608
609#define SMI_ACC2X2_EN_SLOPE_Z_INT__POS 2
610#define SMI_ACC2X2_EN_SLOPE_Z_INT__LEN 1
611#define SMI_ACC2X2_EN_SLOPE_Z_INT__MSK 0x04
612#define SMI_ACC2X2_EN_SLOPE_Z_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
613
614#define SMI_ACC2X2_EN_DOUBLE_TAP_INT__POS 4
615#define SMI_ACC2X2_EN_DOUBLE_TAP_INT__LEN 1
616#define SMI_ACC2X2_EN_DOUBLE_TAP_INT__MSK 0x10
617#define SMI_ACC2X2_EN_DOUBLE_TAP_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
618
619#define SMI_ACC2X2_EN_SINGLE_TAP_INT__POS 5
620#define SMI_ACC2X2_EN_SINGLE_TAP_INT__LEN 1
621#define SMI_ACC2X2_EN_SINGLE_TAP_INT__MSK 0x20
622#define SMI_ACC2X2_EN_SINGLE_TAP_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
623
624#define SMI_ACC2X2_EN_ORIENT_INT__POS 6
625#define SMI_ACC2X2_EN_ORIENT_INT__LEN 1
626#define SMI_ACC2X2_EN_ORIENT_INT__MSK 0x40
627#define SMI_ACC2X2_EN_ORIENT_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
628
629#define SMI_ACC2X2_EN_FLAT_INT__POS 7
630#define SMI_ACC2X2_EN_FLAT_INT__LEN 1
631#define SMI_ACC2X2_EN_FLAT_INT__MSK 0x80
632#define SMI_ACC2X2_EN_FLAT_INT__REG SMI_ACC2X2_INT_ENABLE1_REG
633
634#define SMI_ACC2X2_EN_HIGHG_X_INT__POS 0
635#define SMI_ACC2X2_EN_HIGHG_X_INT__LEN 1
636#define SMI_ACC2X2_EN_HIGHG_X_INT__MSK 0x01
637#define SMI_ACC2X2_EN_HIGHG_X_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
638
639#define SMI_ACC2X2_EN_HIGHG_Y_INT__POS 1
640#define SMI_ACC2X2_EN_HIGHG_Y_INT__LEN 1
641#define SMI_ACC2X2_EN_HIGHG_Y_INT__MSK 0x02
642#define SMI_ACC2X2_EN_HIGHG_Y_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
643
644#define SMI_ACC2X2_EN_HIGHG_Z_INT__POS 2
645#define SMI_ACC2X2_EN_HIGHG_Z_INT__LEN 1
646#define SMI_ACC2X2_EN_HIGHG_Z_INT__MSK 0x04
647#define SMI_ACC2X2_EN_HIGHG_Z_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
648
649#define SMI_ACC2X2_EN_LOWG_INT__POS 3
650#define SMI_ACC2X2_EN_LOWG_INT__LEN 1
651#define SMI_ACC2X2_EN_LOWG_INT__MSK 0x08
652#define SMI_ACC2X2_EN_LOWG_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
653
654#define SMI_ACC2X2_EN_NEW_DATA_INT__POS 4
655#define SMI_ACC2X2_EN_NEW_DATA_INT__LEN 1
656#define SMI_ACC2X2_EN_NEW_DATA_INT__MSK 0x10
657#define SMI_ACC2X2_EN_NEW_DATA_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
658
659#define SMI_ACC2X2_INT_FFULL_EN_INT__POS 5
660#define SMI_ACC2X2_INT_FFULL_EN_INT__LEN 1
661#define SMI_ACC2X2_INT_FFULL_EN_INT__MSK 0x20
662#define SMI_ACC2X2_INT_FFULL_EN_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
663
664#define SMI_ACC2X2_INT_FWM_EN_INT__POS 6
665#define SMI_ACC2X2_INT_FWM_EN_INT__LEN 1
666#define SMI_ACC2X2_INT_FWM_EN_INT__MSK 0x40
667#define SMI_ACC2X2_INT_FWM_EN_INT__REG SMI_ACC2X2_INT_ENABLE2_REG
668
669#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__POS 0
670#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__LEN 1
671#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__MSK 0x01
672#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__REG SMI_ACC2X2_INT_SLO_NO_MOT_REG
673
674#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__POS 1
675#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__LEN 1
676#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__MSK 0x02
677#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__REG SMI_ACC2X2_INT_SLO_NO_MOT_REG
678
679#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__POS 2
680#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__LEN 1
681#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__MSK 0x04
682#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__REG SMI_ACC2X2_INT_SLO_NO_MOT_REG
683
684#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__POS 3
685#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__LEN 1
686#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__MSK 0x08
687#define SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG SMI_ACC2X2_INT_SLO_NO_MOT_REG
688
689#define SMI_ACC2X2_EN_INT1_PAD_LOWG__POS 0
690#define SMI_ACC2X2_EN_INT1_PAD_LOWG__LEN 1
691#define SMI_ACC2X2_EN_INT1_PAD_LOWG__MSK 0x01
692#define SMI_ACC2X2_EN_INT1_PAD_LOWG__REG SMI_ACC2X2_INT1_PAD_SEL_REG
693
694#define SMI_ACC2X2_EN_INT1_PAD_HIGHG__POS 1
695#define SMI_ACC2X2_EN_INT1_PAD_HIGHG__LEN 1
696#define SMI_ACC2X2_EN_INT1_PAD_HIGHG__MSK 0x02
697#define SMI_ACC2X2_EN_INT1_PAD_HIGHG__REG SMI_ACC2X2_INT1_PAD_SEL_REG
698
699#define SMI_ACC2X2_EN_INT1_PAD_SLOPE__POS 2
700#define SMI_ACC2X2_EN_INT1_PAD_SLOPE__LEN 1
701#define SMI_ACC2X2_EN_INT1_PAD_SLOPE__MSK 0x04
702#define SMI_ACC2X2_EN_INT1_PAD_SLOPE__REG SMI_ACC2X2_INT1_PAD_SEL_REG
703
704#define SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__POS 3
705#define SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__LEN 1
706#define SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__MSK 0x08
707#define SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__REG SMI_ACC2X2_INT1_PAD_SEL_REG
708
709#define SMI_ACC2X2_EN_INT1_PAD_DB_TAP__POS 4
710#define SMI_ACC2X2_EN_INT1_PAD_DB_TAP__LEN 1
711#define SMI_ACC2X2_EN_INT1_PAD_DB_TAP__MSK 0x10
712#define SMI_ACC2X2_EN_INT1_PAD_DB_TAP__REG SMI_ACC2X2_INT1_PAD_SEL_REG
713
714#define SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__POS 5
715#define SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__LEN 1
716#define SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__MSK 0x20
717#define SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__REG SMI_ACC2X2_INT1_PAD_SEL_REG
718
719#define SMI_ACC2X2_EN_INT1_PAD_ORIENT__POS 6
720#define SMI_ACC2X2_EN_INT1_PAD_ORIENT__LEN 1
721#define SMI_ACC2X2_EN_INT1_PAD_ORIENT__MSK 0x40
722#define SMI_ACC2X2_EN_INT1_PAD_ORIENT__REG SMI_ACC2X2_INT1_PAD_SEL_REG
723
724#define SMI_ACC2X2_EN_INT1_PAD_FLAT__POS 7
725#define SMI_ACC2X2_EN_INT1_PAD_FLAT__LEN 1
726#define SMI_ACC2X2_EN_INT1_PAD_FLAT__MSK 0x80
727#define SMI_ACC2X2_EN_INT1_PAD_FLAT__REG SMI_ACC2X2_INT1_PAD_SEL_REG
728
729#define SMI_ACC2X2_EN_INT2_PAD_LOWG__POS 0
730#define SMI_ACC2X2_EN_INT2_PAD_LOWG__LEN 1
731#define SMI_ACC2X2_EN_INT2_PAD_LOWG__MSK 0x01
732#define SMI_ACC2X2_EN_INT2_PAD_LOWG__REG SMI_ACC2X2_INT2_PAD_SEL_REG
733
734#define SMI_ACC2X2_EN_INT2_PAD_HIGHG__POS 1
735#define SMI_ACC2X2_EN_INT2_PAD_HIGHG__LEN 1
736#define SMI_ACC2X2_EN_INT2_PAD_HIGHG__MSK 0x02
737#define SMI_ACC2X2_EN_INT2_PAD_HIGHG__REG SMI_ACC2X2_INT2_PAD_SEL_REG
738
739#define SMI_ACC2X2_EN_INT2_PAD_SLOPE__POS 2
740#define SMI_ACC2X2_EN_INT2_PAD_SLOPE__LEN 1
741#define SMI_ACC2X2_EN_INT2_PAD_SLOPE__MSK 0x04
742#define SMI_ACC2X2_EN_INT2_PAD_SLOPE__REG SMI_ACC2X2_INT2_PAD_SEL_REG
743
744#define SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__POS 3
745#define SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__LEN 1
746#define SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__MSK 0x08
747#define SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__REG SMI_ACC2X2_INT2_PAD_SEL_REG
748
749#define SMI_ACC2X2_EN_INT2_PAD_DB_TAP__POS 4
750#define SMI_ACC2X2_EN_INT2_PAD_DB_TAP__LEN 1
751#define SMI_ACC2X2_EN_INT2_PAD_DB_TAP__MSK 0x10
752#define SMI_ACC2X2_EN_INT2_PAD_DB_TAP__REG SMI_ACC2X2_INT2_PAD_SEL_REG
753
754#define SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__POS 5
755#define SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__LEN 1
756#define SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__MSK 0x20
757#define SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__REG SMI_ACC2X2_INT2_PAD_SEL_REG
758
759#define SMI_ACC2X2_EN_INT2_PAD_ORIENT__POS 6
760#define SMI_ACC2X2_EN_INT2_PAD_ORIENT__LEN 1
761#define SMI_ACC2X2_EN_INT2_PAD_ORIENT__MSK 0x40
762#define SMI_ACC2X2_EN_INT2_PAD_ORIENT__REG SMI_ACC2X2_INT2_PAD_SEL_REG
763
764#define SMI_ACC2X2_EN_INT2_PAD_FLAT__POS 7
765#define SMI_ACC2X2_EN_INT2_PAD_FLAT__LEN 1
766#define SMI_ACC2X2_EN_INT2_PAD_FLAT__MSK 0x80
767#define SMI_ACC2X2_EN_INT2_PAD_FLAT__REG SMI_ACC2X2_INT2_PAD_SEL_REG
768
769#define SMI_ACC2X2_EN_INT1_PAD_NEWDATA__POS 0
770#define SMI_ACC2X2_EN_INT1_PAD_NEWDATA__LEN 1
771#define SMI_ACC2X2_EN_INT1_PAD_NEWDATA__MSK 0x01
772#define SMI_ACC2X2_EN_INT1_PAD_NEWDATA__REG SMI_ACC2X2_INT_DATA_SEL_REG
773
774#define SMI_ACC2X2_EN_INT1_PAD_FWM__POS 1
775#define SMI_ACC2X2_EN_INT1_PAD_FWM__LEN 1
776#define SMI_ACC2X2_EN_INT1_PAD_FWM__MSK 0x02
777#define SMI_ACC2X2_EN_INT1_PAD_FWM__REG SMI_ACC2X2_INT_DATA_SEL_REG
778
779#define SMI_ACC2X2_EN_INT1_PAD_FFULL__POS 2
780#define SMI_ACC2X2_EN_INT1_PAD_FFULL__LEN 1
781#define SMI_ACC2X2_EN_INT1_PAD_FFULL__MSK 0x04
782#define SMI_ACC2X2_EN_INT1_PAD_FFULL__REG SMI_ACC2X2_INT_DATA_SEL_REG
783
784#define SMI_ACC2X2_EN_INT2_PAD_FFULL__POS 5
785#define SMI_ACC2X2_EN_INT2_PAD_FFULL__LEN 1
786#define SMI_ACC2X2_EN_INT2_PAD_FFULL__MSK 0x20
787#define SMI_ACC2X2_EN_INT2_PAD_FFULL__REG SMI_ACC2X2_INT_DATA_SEL_REG
788
789#define SMI_ACC2X2_EN_INT2_PAD_FWM__POS 6
790#define SMI_ACC2X2_EN_INT2_PAD_FWM__LEN 1
791#define SMI_ACC2X2_EN_INT2_PAD_FWM__MSK 0x40
792#define SMI_ACC2X2_EN_INT2_PAD_FWM__REG SMI_ACC2X2_INT_DATA_SEL_REG
793
794#define SMI_ACC2X2_EN_INT2_PAD_NEWDATA__POS 7
795#define SMI_ACC2X2_EN_INT2_PAD_NEWDATA__LEN 1
796#define SMI_ACC2X2_EN_INT2_PAD_NEWDATA__MSK 0x80
797#define SMI_ACC2X2_EN_INT2_PAD_NEWDATA__REG SMI_ACC2X2_INT_DATA_SEL_REG
798
799#define SMI_ACC2X2_UNFILT_INT_SRC_LOWG__POS 0
800#define SMI_ACC2X2_UNFILT_INT_SRC_LOWG__LEN 1
801#define SMI_ACC2X2_UNFILT_INT_SRC_LOWG__MSK 0x01
802#define SMI_ACC2X2_UNFILT_INT_SRC_LOWG__REG SMI_ACC2X2_INT_SRC_REG
803
804#define SMI_ACC2X2_UNFILT_INT_SRC_HIGHG__POS 1
805#define SMI_ACC2X2_UNFILT_INT_SRC_HIGHG__LEN 1
806#define SMI_ACC2X2_UNFILT_INT_SRC_HIGHG__MSK 0x02
807#define SMI_ACC2X2_UNFILT_INT_SRC_HIGHG__REG SMI_ACC2X2_INT_SRC_REG
808
809#define SMI_ACC2X2_UNFILT_INT_SRC_SLOPE__POS 2
810#define SMI_ACC2X2_UNFILT_INT_SRC_SLOPE__LEN 1
811#define SMI_ACC2X2_UNFILT_INT_SRC_SLOPE__MSK 0x04
812#define SMI_ACC2X2_UNFILT_INT_SRC_SLOPE__REG SMI_ACC2X2_INT_SRC_REG
813
814#define SMI_ACC2X2_UNFILT_INT_SRC_SLO_NO_MOT__POS 3
815#define SMI_ACC2X2_UNFILT_INT_SRC_SLO_NO_MOT__LEN 1
816#define SMI_ACC2X2_UNFILT_INT_SRC_SLO_NO_MOT__MSK 0x08
817#define SMI_ACC2X2_UNFILT_INT_SRC_SLO_NO_MOT__REG SMI_ACC2X2_INT_SRC_REG
818
819#define SMI_ACC2X2_UNFILT_INT_SRC_TAP__POS 4
820#define SMI_ACC2X2_UNFILT_INT_SRC_TAP__LEN 1
821#define SMI_ACC2X2_UNFILT_INT_SRC_TAP__MSK 0x10
822#define SMI_ACC2X2_UNFILT_INT_SRC_TAP__REG SMI_ACC2X2_INT_SRC_REG
823
824#define SMI_ACC2X2_UNFILT_INT_SRC_DATA__POS 5
825#define SMI_ACC2X2_UNFILT_INT_SRC_DATA__LEN 1
826#define SMI_ACC2X2_UNFILT_INT_SRC_DATA__MSK 0x20
827#define SMI_ACC2X2_UNFILT_INT_SRC_DATA__REG SMI_ACC2X2_INT_SRC_REG
828
829#define SMI_ACC2X2_INT1_PAD_ACTIVE_LEVEL__POS 0
830#define SMI_ACC2X2_INT1_PAD_ACTIVE_LEVEL__LEN 1
831#define SMI_ACC2X2_INT1_PAD_ACTIVE_LEVEL__MSK 0x01
832#define SMI_ACC2X2_INT1_PAD_ACTIVE_LEVEL__REG SMI_ACC2X2_INT_SET_REG
833
834#define SMI_ACC2X2_INT2_PAD_ACTIVE_LEVEL__POS 2
835#define SMI_ACC2X2_INT2_PAD_ACTIVE_LEVEL__LEN 1
836#define SMI_ACC2X2_INT2_PAD_ACTIVE_LEVEL__MSK 0x04
837#define SMI_ACC2X2_INT2_PAD_ACTIVE_LEVEL__REG SMI_ACC2X2_INT_SET_REG
838
839#define SMI_ACC2X2_INT1_PAD_OUTPUT_TYPE__POS 1
840#define SMI_ACC2X2_INT1_PAD_OUTPUT_TYPE__LEN 1
841#define SMI_ACC2X2_INT1_PAD_OUTPUT_TYPE__MSK 0x02
842#define SMI_ACC2X2_INT1_PAD_OUTPUT_TYPE__REG SMI_ACC2X2_INT_SET_REG
843
844#define SMI_ACC2X2_INT2_PAD_OUTPUT_TYPE__POS 3
845#define SMI_ACC2X2_INT2_PAD_OUTPUT_TYPE__LEN 1
846#define SMI_ACC2X2_INT2_PAD_OUTPUT_TYPE__MSK 0x08
847#define SMI_ACC2X2_INT2_PAD_OUTPUT_TYPE__REG SMI_ACC2X2_INT_SET_REG
848
849#define SMI_ACC2X2_INT_MODE_SEL__POS 0
850#define SMI_ACC2X2_INT_MODE_SEL__LEN 4
851#define SMI_ACC2X2_INT_MODE_SEL__MSK 0x0F
852#define SMI_ACC2X2_INT_MODE_SEL__REG SMI_ACC2X2_INT_CTRL_REG
853
854#define SMI_ACC2X2_RESET_INT__POS 7
855#define SMI_ACC2X2_RESET_INT__LEN 1
856#define SMI_ACC2X2_RESET_INT__MSK 0x80
857#define SMI_ACC2X2_RESET_INT__REG SMI_ACC2X2_INT_CTRL_REG
858
859#define SMI_ACC2X2_LOWG_DUR__POS 0
860#define SMI_ACC2X2_LOWG_DUR__LEN 8
861#define SMI_ACC2X2_LOWG_DUR__MSK 0xFF
862#define SMI_ACC2X2_LOWG_DUR__REG SMI_ACC2X2_LOW_DURN_REG
863
864#define SMI_ACC2X2_LOWG_THRES__POS 0
865#define SMI_ACC2X2_LOWG_THRES__LEN 8
866#define SMI_ACC2X2_LOWG_THRES__MSK 0xFF
867#define SMI_ACC2X2_LOWG_THRES__REG SMI_ACC2X2_LOW_THRES_REG
868
869#define SMI_ACC2X2_LOWG_HYST__POS 0
870#define SMI_ACC2X2_LOWG_HYST__LEN 2
871#define SMI_ACC2X2_LOWG_HYST__MSK 0x03
872#define SMI_ACC2X2_LOWG_HYST__REG SMI_ACC2X2_LOW_HIGH_HYST_REG
873
874#define SMI_ACC2X2_LOWG_INT_MODE__POS 2
875#define SMI_ACC2X2_LOWG_INT_MODE__LEN 1
876#define SMI_ACC2X2_LOWG_INT_MODE__MSK 0x04
877#define SMI_ACC2X2_LOWG_INT_MODE__REG SMI_ACC2X2_LOW_HIGH_HYST_REG
878
879#define SMI_ACC2X2_HIGHG_DUR__POS 0
880#define SMI_ACC2X2_HIGHG_DUR__LEN 8
881#define SMI_ACC2X2_HIGHG_DUR__MSK 0xFF
882#define SMI_ACC2X2_HIGHG_DUR__REG SMI_ACC2X2_HIGH_DURN_REG
883
884#define SMI_ACC2X2_HIGHG_THRES__POS 0
885#define SMI_ACC2X2_HIGHG_THRES__LEN 8
886#define SMI_ACC2X2_HIGHG_THRES__MSK 0xFF
887#define SMI_ACC2X2_HIGHG_THRES__REG SMI_ACC2X2_HIGH_THRES_REG
888
889#define SMI_ACC2X2_HIGHG_HYST__POS 6
890#define SMI_ACC2X2_HIGHG_HYST__LEN 2
891#define SMI_ACC2X2_HIGHG_HYST__MSK 0xC0
892#define SMI_ACC2X2_HIGHG_HYST__REG SMI_ACC2X2_LOW_HIGH_HYST_REG
893
894#define SMI_ACC2X2_SLOPE_DUR__POS 0
895#define SMI_ACC2X2_SLOPE_DUR__LEN 2
896#define SMI_ACC2X2_SLOPE_DUR__MSK 0x03
897#define SMI_ACC2X2_SLOPE_DUR__REG SMI_ACC2X2_SLOPE_DURN_REG
898
899#define SMI_ACC2X2_SLO_NO_MOT_DUR__POS 2
900#define SMI_ACC2X2_SLO_NO_MOT_DUR__LEN 6
901#define SMI_ACC2X2_SLO_NO_MOT_DUR__MSK 0xFC
902#define SMI_ACC2X2_SLO_NO_MOT_DUR__REG SMI_ACC2X2_SLOPE_DURN_REG
903
904#define SMI_ACC2X2_SLOPE_THRES__POS 0
905#define SMI_ACC2X2_SLOPE_THRES__LEN 8
906#define SMI_ACC2X2_SLOPE_THRES__MSK 0xFF
907#define SMI_ACC2X2_SLOPE_THRES__REG SMI_ACC2X2_SLOPE_THRES_REG
908
909#define SMI_ACC2X2_SLO_NO_MOT_THRES__POS 0
910#define SMI_ACC2X2_SLO_NO_MOT_THRES__LEN 8
911#define SMI_ACC2X2_SLO_NO_MOT_THRES__MSK 0xFF
912#define SMI_ACC2X2_SLO_NO_MOT_THRES__REG SMI_ACC2X2_SLO_NO_MOT_THRES_REG
913
914#define SMI_ACC2X2_TAP_DUR__POS 0
915#define SMI_ACC2X2_TAP_DUR__LEN 3
916#define SMI_ACC2X2_TAP_DUR__MSK 0x07
917#define SMI_ACC2X2_TAP_DUR__REG SMI_ACC2X2_TAP_PARAM_REG
918
919#define SMI_ACC2X2_TAP_SHOCK_DURN__POS 6
920#define SMI_ACC2X2_TAP_SHOCK_DURN__LEN 1
921#define SMI_ACC2X2_TAP_SHOCK_DURN__MSK 0x40
922#define SMI_ACC2X2_TAP_SHOCK_DURN__REG SMI_ACC2X2_TAP_PARAM_REG
923
924#define SMI_ACC2X2_ADV_TAP_INT__POS 5
925#define SMI_ACC2X2_ADV_TAP_INT__LEN 1
926#define SMI_ACC2X2_ADV_TAP_INT__MSK 0x20
927#define SMI_ACC2X2_ADV_TAP_INT__REG SMI_ACC2X2_TAP_PARAM_REG
928
929#define SMI_ACC2X2_TAP_QUIET_DURN__POS 7
930#define SMI_ACC2X2_TAP_QUIET_DURN__LEN 1
931#define SMI_ACC2X2_TAP_QUIET_DURN__MSK 0x80
932#define SMI_ACC2X2_TAP_QUIET_DURN__REG SMI_ACC2X2_TAP_PARAM_REG
933
934#define SMI_ACC2X2_TAP_THRES__POS 0
935#define SMI_ACC2X2_TAP_THRES__LEN 5
936#define SMI_ACC2X2_TAP_THRES__MSK 0x1F
937#define SMI_ACC2X2_TAP_THRES__REG SMI_ACC2X2_TAP_THRES_REG
938
939#define SMI_ACC2X2_TAP_SAMPLES__POS 6
940#define SMI_ACC2X2_TAP_SAMPLES__LEN 2
941#define SMI_ACC2X2_TAP_SAMPLES__MSK 0xC0
942#define SMI_ACC2X2_TAP_SAMPLES__REG SMI_ACC2X2_TAP_THRES_REG
943
944#define SMI_ACC2X2_ORIENT_MODE__POS 0
945#define SMI_ACC2X2_ORIENT_MODE__LEN 2
946#define SMI_ACC2X2_ORIENT_MODE__MSK 0x03
947#define SMI_ACC2X2_ORIENT_MODE__REG SMI_ACC2X2_ORIENT_PARAM_REG
948
949#define SMI_ACC2X2_ORIENT_BLOCK__POS 2
950#define SMI_ACC2X2_ORIENT_BLOCK__LEN 2
951#define SMI_ACC2X2_ORIENT_BLOCK__MSK 0x0C
952#define SMI_ACC2X2_ORIENT_BLOCK__REG SMI_ACC2X2_ORIENT_PARAM_REG
953
954#define SMI_ACC2X2_ORIENT_HYST__POS 4
955#define SMI_ACC2X2_ORIENT_HYST__LEN 3
956#define SMI_ACC2X2_ORIENT_HYST__MSK 0x70
957#define SMI_ACC2X2_ORIENT_HYST__REG SMI_ACC2X2_ORIENT_PARAM_REG
958
959#define SMI_ACC2X2_ORIENT_AXIS__POS 7
960#define SMI_ACC2X2_ORIENT_AXIS__LEN 1
961#define SMI_ACC2X2_ORIENT_AXIS__MSK 0x80
962#define SMI_ACC2X2_ORIENT_AXIS__REG SMI_ACC2X2_THETA_BLOCK_REG
963
964#define SMI_ACC2X2_ORIENT_UD_EN__POS 6
965#define SMI_ACC2X2_ORIENT_UD_EN__LEN 1
966#define SMI_ACC2X2_ORIENT_UD_EN__MSK 0x40
967#define SMI_ACC2X2_ORIENT_UD_EN__REG SMI_ACC2X2_THETA_BLOCK_REG
968
969#define SMI_ACC2X2_THETA_BLOCK__POS 0
970#define SMI_ACC2X2_THETA_BLOCK__LEN 6
971#define SMI_ACC2X2_THETA_BLOCK__MSK 0x3F
972#define SMI_ACC2X2_THETA_BLOCK__REG SMI_ACC2X2_THETA_BLOCK_REG
973
974#define SMI_ACC2X2_THETA_FLAT__POS 0
975#define SMI_ACC2X2_THETA_FLAT__LEN 6
976#define SMI_ACC2X2_THETA_FLAT__MSK 0x3F
977#define SMI_ACC2X2_THETA_FLAT__REG SMI_ACC2X2_THETA_FLAT_REG
978
979#define SMI_ACC2X2_FLAT_HOLD_TIME__POS 4
980#define SMI_ACC2X2_FLAT_HOLD_TIME__LEN 2
981#define SMI_ACC2X2_FLAT_HOLD_TIME__MSK 0x30
982#define SMI_ACC2X2_FLAT_HOLD_TIME__REG SMI_ACC2X2_FLAT_HOLD_TIME_REG
983
984#define SMI_ACC2X2_FLAT_HYS__POS 0
985#define SMI_ACC2X2_FLAT_HYS__LEN 3
986#define SMI_ACC2X2_FLAT_HYS__MSK 0x07
987#define SMI_ACC2X2_FLAT_HYS__REG SMI_ACC2X2_FLAT_HOLD_TIME_REG
988
989#define SMI_ACC2X2_FIFO_WML_TRIG_RETAIN__POS 0
990#define SMI_ACC2X2_FIFO_WML_TRIG_RETAIN__LEN 6
991#define SMI_ACC2X2_FIFO_WML_TRIG_RETAIN__MSK 0x3F
992#define SMI_ACC2X2_FIFO_WML_TRIG_RETAIN__REG SMI_ACC2X2_FIFO_WML_TRIG
993
994#define SMI_ACC2X2_EN_SELF_TEST__POS 0
995#define SMI_ACC2X2_EN_SELF_TEST__LEN 2
996#define SMI_ACC2X2_EN_SELF_TEST__MSK 0x03
997#define SMI_ACC2X2_EN_SELF_TEST__REG SMI_ACC2X2_SELF_TEST_REG
998
999#define SMI_ACC2X2_NEG_SELF_TEST__POS 2
1000#define SMI_ACC2X2_NEG_SELF_TEST__LEN 1
1001#define SMI_ACC2X2_NEG_SELF_TEST__MSK 0x04
1002#define SMI_ACC2X2_NEG_SELF_TEST__REG SMI_ACC2X2_SELF_TEST_REG
1003
1004#define SMI_ACC2X2_SELF_TEST_AMP__POS 4
1005#define SMI_ACC2X2_SELF_TEST_AMP__LEN 1
1006#define SMI_ACC2X2_SELF_TEST_AMP__MSK 0x10
1007#define SMI_ACC2X2_SELF_TEST_AMP__REG SMI_ACC2X2_SELF_TEST_REG
1008
1009
1010#define SMI_ACC2X2_UNLOCK_EE_PROG_MODE__POS 0
1011#define SMI_ACC2X2_UNLOCK_EE_PROG_MODE__LEN 1
1012#define SMI_ACC2X2_UNLOCK_EE_PROG_MODE__MSK 0x01
1013#define SMI_ACC2X2_UNLOCK_EE_PROG_MODE__REG SMI_ACC2X2_EEPROM_CTRL_REG
1014
1015#define SMI_ACC2X2_START_EE_PROG_TRIG__POS 1
1016#define SMI_ACC2X2_START_EE_PROG_TRIG__LEN 1
1017#define SMI_ACC2X2_START_EE_PROG_TRIG__MSK 0x02
1018#define SMI_ACC2X2_START_EE_PROG_TRIG__REG SMI_ACC2X2_EEPROM_CTRL_REG
1019
1020#define SMI_ACC2X2_EE_PROG_READY__POS 2
1021#define SMI_ACC2X2_EE_PROG_READY__LEN 1
1022#define SMI_ACC2X2_EE_PROG_READY__MSK 0x04
1023#define SMI_ACC2X2_EE_PROG_READY__REG SMI_ACC2X2_EEPROM_CTRL_REG
1024
1025#define SMI_ACC2X2_UPDATE_IMAGE__POS 3
1026#define SMI_ACC2X2_UPDATE_IMAGE__LEN 1
1027#define SMI_ACC2X2_UPDATE_IMAGE__MSK 0x08
1028#define SMI_ACC2X2_UPDATE_IMAGE__REG SMI_ACC2X2_EEPROM_CTRL_REG
1029
1030#define SMI_ACC2X2_EE_REMAIN__POS 4
1031#define SMI_ACC2X2_EE_REMAIN__LEN 4
1032#define SMI_ACC2X2_EE_REMAIN__MSK 0xF0
1033#define SMI_ACC2X2_EE_REMAIN__REG SMI_ACC2X2_EEPROM_CTRL_REG
1034
1035#define SMI_ACC2X2_EN_SPI_MODE_3__POS 0
1036#define SMI_ACC2X2_EN_SPI_MODE_3__LEN 1
1037#define SMI_ACC2X2_EN_SPI_MODE_3__MSK 0x01
1038#define SMI_ACC2X2_EN_SPI_MODE_3__REG SMI_ACC2X2_SERIAL_CTRL_REG
1039
1040#define SMI_ACC2X2_I2C_WATCHDOG_PERIOD__POS 1
1041#define SMI_ACC2X2_I2C_WATCHDOG_PERIOD__LEN 1
1042#define SMI_ACC2X2_I2C_WATCHDOG_PERIOD__MSK 0x02
1043#define SMI_ACC2X2_I2C_WATCHDOG_PERIOD__REG SMI_ACC2X2_SERIAL_CTRL_REG
1044
1045#define SMI_ACC2X2_EN_I2C_WATCHDOG__POS 2
1046#define SMI_ACC2X2_EN_I2C_WATCHDOG__LEN 1
1047#define SMI_ACC2X2_EN_I2C_WATCHDOG__MSK 0x04
1048#define SMI_ACC2X2_EN_I2C_WATCHDOG__REG SMI_ACC2X2_SERIAL_CTRL_REG
1049
1050#define SMI_ACC2X2_EXT_MODE__POS 7
1051#define SMI_ACC2X2_EXT_MODE__LEN 1
1052#define SMI_ACC2X2_EXT_MODE__MSK 0x80
1053#define SMI_ACC2X2_EXT_MODE__REG SMI_ACC2X2_EXTMODE_CTRL_REG
1054
1055#define SMI_ACC2X2_ALLOW_UPPER__POS 6
1056#define SMI_ACC2X2_ALLOW_UPPER__LEN 1
1057#define SMI_ACC2X2_ALLOW_UPPER__MSK 0x40
1058#define SMI_ACC2X2_ALLOW_UPPER__REG SMI_ACC2X2_EXTMODE_CTRL_REG
1059
1060#define SMI_ACC2X2_MAP_2_LOWER__POS 5
1061#define SMI_ACC2X2_MAP_2_LOWER__LEN 1
1062#define SMI_ACC2X2_MAP_2_LOWER__MSK 0x20
1063#define SMI_ACC2X2_MAP_2_LOWER__REG SMI_ACC2X2_EXTMODE_CTRL_REG
1064
1065#define SMI_ACC2X2_MAGIC_NUMBER__POS 0
1066#define SMI_ACC2X2_MAGIC_NUMBER__LEN 5
1067#define SMI_ACC2X2_MAGIC_NUMBER__MSK 0x1F
1068#define SMI_ACC2X2_MAGIC_NUMBER__REG SMI_ACC2X2_EXTMODE_CTRL_REG
1069
1070#define SMI_ACC2X2_UNLOCK_EE_WRITE_TRIM__POS 4
1071#define SMI_ACC2X2_UNLOCK_EE_WRITE_TRIM__LEN 4
1072#define SMI_ACC2X2_UNLOCK_EE_WRITE_TRIM__MSK 0xF0
1073#define SMI_ACC2X2_UNLOCK_EE_WRITE_TRIM__REG SMI_ACC2X2_CTRL_UNLOCK_REG
1074
1075#define SMI_ACC2X2_EN_SLOW_COMP_X__POS 0
1076#define SMI_ACC2X2_EN_SLOW_COMP_X__LEN 1
1077#define SMI_ACC2X2_EN_SLOW_COMP_X__MSK 0x01
1078#define SMI_ACC2X2_EN_SLOW_COMP_X__REG SMI_ACC2X2_OFFSET_CTRL_REG
1079
1080#define SMI_ACC2X2_EN_SLOW_COMP_Y__POS 1
1081#define SMI_ACC2X2_EN_SLOW_COMP_Y__LEN 1
1082#define SMI_ACC2X2_EN_SLOW_COMP_Y__MSK 0x02
1083#define SMI_ACC2X2_EN_SLOW_COMP_Y__REG SMI_ACC2X2_OFFSET_CTRL_REG
1084
1085#define SMI_ACC2X2_EN_SLOW_COMP_Z__POS 2
1086#define SMI_ACC2X2_EN_SLOW_COMP_Z__LEN 1
1087#define SMI_ACC2X2_EN_SLOW_COMP_Z__MSK 0x04
1088#define SMI_ACC2X2_EN_SLOW_COMP_Z__REG SMI_ACC2X2_OFFSET_CTRL_REG
1089
1090#define SMI_ACC2X2_FAST_CAL_RDY_S__POS 4
1091#define SMI_ACC2X2_FAST_CAL_RDY_S__LEN 1
1092#define SMI_ACC2X2_FAST_CAL_RDY_S__MSK 0x10
1093#define SMI_ACC2X2_FAST_CAL_RDY_S__REG SMI_ACC2X2_OFFSET_CTRL_REG
1094
1095#define SMI_ACC2X2_CAL_TRIGGER__POS 5
1096#define SMI_ACC2X2_CAL_TRIGGER__LEN 2
1097#define SMI_ACC2X2_CAL_TRIGGER__MSK 0x60
1098#define SMI_ACC2X2_CAL_TRIGGER__REG SMI_ACC2X2_OFFSET_CTRL_REG
1099
1100#define SMI_ACC2X2_RESET_OFFSET_REGS__POS 7
1101#define SMI_ACC2X2_RESET_OFFSET_REGS__LEN 1
1102#define SMI_ACC2X2_RESET_OFFSET_REGS__MSK 0x80
1103#define SMI_ACC2X2_RESET_OFFSET_REGS__REG SMI_ACC2X2_OFFSET_CTRL_REG
1104
1105#define SMI_ACC2X2_COMP_CUTOFF__POS 0
1106#define SMI_ACC2X2_COMP_CUTOFF__LEN 1
1107#define SMI_ACC2X2_COMP_CUTOFF__MSK 0x01
1108#define SMI_ACC2X2_COMP_CUTOFF__REG SMI_ACC2X2_OFFSET_PARAMS_REG
1109
1110#define SMI_ACC2X2_COMP_TARGET_OFFSET_X__POS 1
1111#define SMI_ACC2X2_COMP_TARGET_OFFSET_X__LEN 2
1112#define SMI_ACC2X2_COMP_TARGET_OFFSET_X__MSK 0x06
1113#define SMI_ACC2X2_COMP_TARGET_OFFSET_X__REG SMI_ACC2X2_OFFSET_PARAMS_REG
1114
1115#define SMI_ACC2X2_COMP_TARGET_OFFSET_Y__POS 3
1116#define SMI_ACC2X2_COMP_TARGET_OFFSET_Y__LEN 2
1117#define SMI_ACC2X2_COMP_TARGET_OFFSET_Y__MSK 0x18
1118#define SMI_ACC2X2_COMP_TARGET_OFFSET_Y__REG SMI_ACC2X2_OFFSET_PARAMS_REG
1119
1120#define SMI_ACC2X2_COMP_TARGET_OFFSET_Z__POS 5
1121#define SMI_ACC2X2_COMP_TARGET_OFFSET_Z__LEN 2
1122#define SMI_ACC2X2_COMP_TARGET_OFFSET_Z__MSK 0x60
1123#define SMI_ACC2X2_COMP_TARGET_OFFSET_Z__REG SMI_ACC2X2_OFFSET_PARAMS_REG
1124
1125#define SMI_ACC2X2_FIFO_DATA_SELECT__POS 0
1126#define SMI_ACC2X2_FIFO_DATA_SELECT__LEN 2
1127#define SMI_ACC2X2_FIFO_DATA_SELECT__MSK 0x03
1128#define SMI_ACC2X2_FIFO_DATA_SELECT__REG SMI_ACC2X2_FIFO_MODE_REG
1129
1130#define SMI_ACC2X2_FIFO_TRIGGER_SOURCE__POS 2
1131#define SMI_ACC2X2_FIFO_TRIGGER_SOURCE__LEN 2
1132#define SMI_ACC2X2_FIFO_TRIGGER_SOURCE__MSK 0x0C
1133#define SMI_ACC2X2_FIFO_TRIGGER_SOURCE__REG SMI_ACC2X2_FIFO_MODE_REG
1134
1135#define SMI_ACC2X2_FIFO_TRIGGER_ACTION__POS 4
1136#define SMI_ACC2X2_FIFO_TRIGGER_ACTION__LEN 2
1137#define SMI_ACC2X2_FIFO_TRIGGER_ACTION__MSK 0x30
1138#define SMI_ACC2X2_FIFO_TRIGGER_ACTION__REG SMI_ACC2X2_FIFO_MODE_REG
1139
1140#define SMI_ACC2X2_FIFO_MODE__POS 6
1141#define SMI_ACC2X2_FIFO_MODE__LEN 2
1142#define SMI_ACC2X2_FIFO_MODE__MSK 0xC0
1143#define SMI_ACC2X2_FIFO_MODE__REG SMI_ACC2X2_FIFO_MODE_REG
1144
1145
1146#define SMI_ACC2X2_STATUS1 0
1147#define SMI_ACC2X2_STATUS2 1
1148#define SMI_ACC2X2_STATUS3 2
1149#define SMI_ACC2X2_STATUS4 3
1150#define SMI_ACC2X2_STATUS5 4
1151
1152
1153#define SMI_ACC2X2_RANGE_2G 3
1154#define SMI_ACC2X2_RANGE_4G 5
1155#define SMI_ACC2X2_RANGE_8G 8
1156#define SMI_ACC2X2_RANGE_16G 12
1157
1158
1159#define SMI_ACC2X2_BW_7_81HZ 0x08
1160#define SMI_ACC2X2_BW_15_63HZ 0x09
1161#define SMI_ACC2X2_BW_31_25HZ 0x0A
1162#define SMI_ACC2X2_BW_62_50HZ 0x0B
1163#define SMI_ACC2X2_BW_125HZ 0x0C
1164#define SMI_ACC2X2_BW_250HZ 0x0D
1165#define SMI_ACC2X2_BW_500HZ 0x0E
1166#define SMI_ACC2X2_BW_1000HZ 0x0F
1167
1168#define SMI_ACC2X2_SLEEP_DUR_0_5MS 0x05
1169#define SMI_ACC2X2_SLEEP_DUR_1MS 0x06
1170#define SMI_ACC2X2_SLEEP_DUR_2MS 0x07
1171#define SMI_ACC2X2_SLEEP_DUR_4MS 0x08
1172#define SMI_ACC2X2_SLEEP_DUR_6MS 0x09
1173#define SMI_ACC2X2_SLEEP_DUR_10MS 0x0A
1174#define SMI_ACC2X2_SLEEP_DUR_25MS 0x0B
1175#define SMI_ACC2X2_SLEEP_DUR_50MS 0x0C
1176#define SMI_ACC2X2_SLEEP_DUR_100MS 0x0D
1177#define SMI_ACC2X2_SLEEP_DUR_500MS 0x0E
1178#define SMI_ACC2X2_SLEEP_DUR_1S 0x0F
1179
1180#define SMI_ACC2X2_LATCH_DUR_NON_LATCH 0x00
1181#define SMI_ACC2X2_LATCH_DUR_250MS 0x01
1182#define SMI_ACC2X2_LATCH_DUR_500MS 0x02
1183#define SMI_ACC2X2_LATCH_DUR_1S 0x03
1184#define SMI_ACC2X2_LATCH_DUR_2S 0x04
1185#define SMI_ACC2X2_LATCH_DUR_4S 0x05
1186#define SMI_ACC2X2_LATCH_DUR_8S 0x06
1187#define SMI_ACC2X2_LATCH_DUR_LATCH 0x07
1188#define SMI_ACC2X2_LATCH_DUR_NON_LATCH1 0x08
1189#define SMI_ACC2X2_LATCH_DUR_250US 0x09
1190#define SMI_ACC2X2_LATCH_DUR_500US 0x0A
1191#define SMI_ACC2X2_LATCH_DUR_1MS 0x0B
1192#define SMI_ACC2X2_LATCH_DUR_12_5MS 0x0C
1193#define SMI_ACC2X2_LATCH_DUR_25MS 0x0D
1194#define SMI_ACC2X2_LATCH_DUR_50MS 0x0E
1195#define SMI_ACC2X2_LATCH_DUR_LATCH1 0x0F
1196
1197#define SMI_ACC2X2_MODE_NORMAL 0
1198#define SMI_ACC2X2_MODE_LOWPOWER1 1
1199#define SMI_ACC2X2_MODE_SUSPEND 2
1200#define SMI_ACC2X2_MODE_DEEP_SUSPEND 3
1201#define SMI_ACC2X2_MODE_LOWPOWER2 4
1202#define SMI_ACC2X2_MODE_STANDBY 5
1203
1204#define SMI_ACC2X2_X_AXIS 0
1205#define SMI_ACC2X2_Y_AXIS 1
1206#define SMI_ACC2X2_Z_AXIS 2
1207
1208#define SMI_ACC2X2_Low_G_Interrupt 0
1209#define SMI_ACC2X2_High_G_X_Interrupt 1
1210#define SMI_ACC2X2_High_G_Y_Interrupt 2
1211#define SMI_ACC2X2_High_G_Z_Interrupt 3
1212#define SMI_ACC2X2_DATA_EN 4
1213#define SMI_ACC2X2_Slope_X_Interrupt 5
1214#define SMI_ACC2X2_Slope_Y_Interrupt 6
1215#define SMI_ACC2X2_Slope_Z_Interrupt 7
1216#define SMI_ACC2X2_Single_Tap_Interrupt 8
1217#define SMI_ACC2X2_Double_Tap_Interrupt 9
1218#define SMI_ACC2X2_Orient_Interrupt 10
1219#define SMI_ACC2X2_Flat_Interrupt 11
1220#define SMI_ACC2X2_FFULL_INTERRUPT 12
1221#define SMI_ACC2X2_FWM_INTERRUPT 13
1222
1223#define SMI_ACC2X2_INT1_LOWG 0
1224#define SMI_ACC2X2_INT2_LOWG 1
1225#define SMI_ACC2X2_INT1_HIGHG 0
1226#define SMI_ACC2X2_INT2_HIGHG 1
1227#define SMI_ACC2X2_INT1_SLOPE 0
1228#define SMI_ACC2X2_INT2_SLOPE 1
1229#define SMI_ACC2X2_INT1_SLO_NO_MOT 0
1230#define SMI_ACC2X2_INT2_SLO_NO_MOT 1
1231#define SMI_ACC2X2_INT1_DTAP 0
1232#define SMI_ACC2X2_INT2_DTAP 1
1233#define SMI_ACC2X2_INT1_STAP 0
1234#define SMI_ACC2X2_INT2_STAP 1
1235#define SMI_ACC2X2_INT1_ORIENT 0
1236#define SMI_ACC2X2_INT2_ORIENT 1
1237#define SMI_ACC2X2_INT1_FLAT 0
1238#define SMI_ACC2X2_INT2_FLAT 1
1239#define SMI_ACC2X2_INT1_NDATA 0
1240#define SMI_ACC2X2_INT2_NDATA 1
1241#define SMI_ACC2X2_INT1_FWM 0
1242#define SMI_ACC2X2_INT2_FWM 1
1243#define SMI_ACC2X2_INT1_FFULL 0
1244#define SMI_ACC2X2_INT2_FFULL 1
1245
1246#define SMI_ACC2X2_SRC_LOWG 0
1247#define SMI_ACC2X2_SRC_HIGHG 1
1248#define SMI_ACC2X2_SRC_SLOPE 2
1249#define SMI_ACC2X2_SRC_SLO_NO_MOT 3
1250#define SMI_ACC2X2_SRC_TAP 4
1251#define SMI_ACC2X2_SRC_DATA 5
1252
1253#define SMI_ACC2X2_INT1_OUTPUT 0
1254#define SMI_ACC2X2_INT2_OUTPUT 1
1255#define SMI_ACC2X2_INT1_LEVEL 0
1256#define SMI_ACC2X2_INT2_LEVEL 1
1257
1258#define SMI_ACC2X2_LOW_DURATION 0
1259#define SMI_ACC2X2_HIGH_DURATION 1
1260#define SMI_ACC2X2_SLOPE_DURATION 2
1261#define SMI_ACC2X2_SLO_NO_MOT_DURATION 3
1262
1263#define SMI_ACC2X2_LOW_THRESHOLD 0
1264#define SMI_ACC2X2_HIGH_THRESHOLD 1
1265#define SMI_ACC2X2_SLOPE_THRESHOLD 2
1266#define SMI_ACC2X2_SLO_NO_MOT_THRESHOLD 3
1267
1268
1269#define SMI_ACC2X2_LOWG_HYST 0
1270#define SMI_ACC2X2_HIGHG_HYST 1
1271
1272#define SMI_ACC2X2_ORIENT_THETA 0
1273#define SMI_ACC2X2_FLAT_THETA 1
1274
1275#define SMI_ACC2X2_I2C_SELECT 0
1276#define SMI_ACC2X2_I2C_EN 1
1277
1278#define SMI_ACC2X2_SLOW_COMP_X 0
1279#define SMI_ACC2X2_SLOW_COMP_Y 1
1280#define SMI_ACC2X2_SLOW_COMP_Z 2
1281
1282#define SMI_ACC2X2_CUT_OFF 0
1283#define SMI_ACC2X2_OFFSET_TRIGGER_X 1
1284#define SMI_ACC2X2_OFFSET_TRIGGER_Y 2
1285#define SMI_ACC2X2_OFFSET_TRIGGER_Z 3
1286
1287#define SMI_ACC2X2_GP0 0
1288#define SMI_ACC2X2_GP1 1
1289
1290#define SMI_ACC2X2_SLO_NO_MOT_EN_X 0
1291#define SMI_ACC2X2_SLO_NO_MOT_EN_Y 1
1292#define SMI_ACC2X2_SLO_NO_MOT_EN_Z 2
1293#define SMI_ACC2X2_SLO_NO_MOT_EN_SEL 3
1294
1295#define SMI_ACC2X2_WAKE_UP_DUR_20MS 0
1296#define SMI_ACC2X2_WAKE_UP_DUR_80MS 1
1297#define SMI_ACC2X2_WAKE_UP_DUR_320MS 2
1298#define SMI_ACC2X2_WAKE_UP_DUR_2560MS 3
1299
1300#define SMI_ACC2X2_SELF_TEST0_ON 1
1301#define SMI_ACC2X2_SELF_TEST1_ON 2
1302
1303#define SMI_ACC2X2_EE_W_OFF 0
1304#define SMI_ACC2X2_EE_W_ON 1
1305
1306#define SMI_ACC2X2_LOW_TH_IN_G(gthres, range) ((256 * gthres) / range)
1307
1308
1309#define SMI_ACC2X2_HIGH_TH_IN_G(gthres, range) ((256 * gthres) / range)
1310
1311
1312#define SMI_ACC2X2_LOW_HY_IN_G(ghyst, range) ((32 * ghyst) / range)
1313
1314
1315#define SMI_ACC2X2_HIGH_HY_IN_G(ghyst, range) ((32 * ghyst) / range)
1316
1317
1318#define SMI_ACC2X2_SLOPE_TH_IN_G(gthres, range) ((128 * gthres) / range)
1319
1320
1321#define SMI_ACC2X2_GET_BITSLICE(regvar, bitname)\
1322 ((regvar & bitname##__MSK) >> bitname##__POS)
1323
1324
1325#define SMI_ACC2X2_SET_BITSLICE(regvar, bitname, val)\
1326 ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
1327
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301328#define CHECK_CHIP_ID_TIME_MAX 1
Bosch Sensortecface5922018-08-29 08:08:53 +02001329#define SMI_ACC255_CHIP_ID 0XFA
1330#define SMI_ACC250E_CHIP_ID 0XF9
1331#define SMI_ACC222E_CHIP_ID 0XF8
1332#define SMI_ACC280_CHIP_ID 0XFB
1333#define SMI_ACC355_CHIP_ID 0XEA
1334
1335#define SMI_ACC255_TYPE 0
1336#define SMI_ACC250E_TYPE 1
1337#define SMI_ACC222E_TYPE 2
1338#define SMI_ACC280_TYPE 3
1339
1340#define MAX_FIFO_F_LEVEL 32
1341#define MAX_FIFO_F_BYTES 6
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301342#define SMI_ACC_MAX_RETRY_I2C_XFER (2)
Bosch Sensortecface5922018-08-29 08:08:53 +02001343
1344#ifdef CONFIG_DOUBLE_TAP
1345#define DEFAULT_TAP_JUDGE_PERIOD 1000 /* default judge in 1 second */
1346#endif
1347
1348/*! Bosch sensor unknown place*/
1349#define BOSCH_SENSOR_PLACE_UNKNOWN (-1)
1350/*! Bosch sensor remapping table size P0~P7*/
1351#define MAX_AXIS_REMAP_TAB_SZ 8
1352
1353/* How was SMI_ACC enabled(set to operation mode) */
1354#define SMI_ACC_ENABLED_ALL 0
1355#define SMI_ACC_ENABLED_SGM 1
1356#define SMI_ACC_ENABLED_DTAP 2
1357#define SMI_ACC_ENABLED_INPUT 3
1358#define SMI_ACC_ENABLED_BSX 4
1359
1360
1361/*!
1362 * @brief:BMI058 feature
1363 * macro definition
1364*/
1365
1366#define SMI_ACC2X2_FIFO_DAT_SEL_X 1
1367#define SMI_ACC2X2_FIFO_DAT_SEL_Y 2
1368#define SMI_ACC2X2_FIFO_DAT_SEL_Z 3
1369
1370#ifdef CONFIG_SENSORS_BMI058
1371#define C_BMI058_One_U8X 1
1372#define C_BMI058_Two_U8X 2
1373#define BMI058_OFFSET_TRIGGER_X SMI_ACC2X2_OFFSET_TRIGGER_Y
1374#define BMI058_OFFSET_TRIGGER_Y SMI_ACC2X2_OFFSET_TRIGGER_X
1375
1376/*! BMI058 X AXIS OFFSET REG definition*/
1377#define BMI058_OFFSET_X_AXIS_REG SMI_ACC2X2_OFFSET_Y_AXIS_REG
1378/*! BMI058 Y AXIS OFFSET REG definition*/
1379#define BMI058_OFFSET_Y_AXIS_REG SMI_ACC2X2_OFFSET_X_AXIS_REG
1380
1381#define BMI058_FIFO_DAT_SEL_X SMI_ACC2X2_FIFO_DAT_SEL_Y
1382#define BMI058_FIFO_DAT_SEL_Y SMI_ACC2X2_FIFO_DAT_SEL_X
1383
1384/*! SMI130_ACC common slow no motion X interrupt type definition*/
1385#define SMI_ACC2X2_SLOW_NO_MOT_X_INT 12
1386/*! SMI130_ACC common slow no motion Y interrupt type definition*/
1387#define SMI_ACC2X2_SLOW_NO_MOT_Y_INT 13
1388/*! SMI130_ACC common High G X interrupt type definition*/
1389#define SMI_ACC2X2_HIGHG_X_INT 1
1390/*! SMI130_ACC common High G Y interrupt type definition*/
1391#define SMI_ACC2X2_HIGHG_Y_INT 2
1392/*! SMI130_ACC common slope X interrupt type definition*/
1393#define SMI_ACC2X2_SLOPE_X_INT 5
1394/*! SMI130_ACC common slope Y interrupt type definition*/
1395#define SMI_ACC2X2_SLOPE_Y_INT 6
1396
1397/*! this structure holds some interrupt types difference
1398**between SMI130_ACC and BMI058.
1399*/
1400struct interrupt_map_t {
1401 int x;
1402 int y;
1403};
1404/*!*Need to use SMI130_ACC Common interrupt type definition to
1405* instead of Some of BMI058 reversed Interrupt type
1406* because of HW Register.
1407* The reversed Interrupt types contain:
1408* slow_no_mot_x_int && slow_not_mot_y_int
1409* highg_x_int && highg_y_int
1410* slope_x_int && slope_y_int
1411**/
1412static const struct interrupt_map_t int_map[] = {
1413 {SMI_ACC2X2_SLOW_NO_MOT_X_INT, SMI_ACC2X2_SLOW_NO_MOT_Y_INT},
1414 {SMI_ACC2X2_HIGHG_X_INT, SMI_ACC2X2_HIGHG_Y_INT},
1415 {SMI_ACC2X2_SLOPE_X_INT, SMI_ACC2X2_SLOPE_Y_INT}
1416};
1417
1418/*! high g or slope interrupt type definition for BMI058*/
1419/*! High G interrupt of x, y, z axis happened */
1420#define HIGH_G_INTERRUPT_X HIGH_G_INTERRUPT_Y_HAPPENED
1421#define HIGH_G_INTERRUPT_Y HIGH_G_INTERRUPT_X_HAPPENED
1422#define HIGH_G_INTERRUPT_Z HIGH_G_INTERRUPT_Z_HAPPENED
1423/*! High G interrupt of x, y, z negative axis happened */
1424#define HIGH_G_INTERRUPT_X_N HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED
1425#define HIGH_G_INTERRUPT_Y_N HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED
1426#define HIGH_G_INTERRUPT_Z_N HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED
1427/*! Slope interrupt of x, y, z axis happened */
1428#define SLOPE_INTERRUPT_X SLOPE_INTERRUPT_Y_HAPPENED
1429#define SLOPE_INTERRUPT_Y SLOPE_INTERRUPT_X_HAPPENED
1430#define SLOPE_INTERRUPT_Z SLOPE_INTERRUPT_Z_HAPPENED
1431/*! Slope interrupt of x, y, z negative axis happened */
1432#define SLOPE_INTERRUPT_X_N SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED
1433#define SLOPE_INTERRUPT_Y_N SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED
1434#define SLOPE_INTERRUPT_Z_N SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED
1435
1436
1437#else
1438
1439/*! high g or slope interrupt type definition*/
1440/*! High G interrupt of x, y, z axis happened */
1441#define HIGH_G_INTERRUPT_X HIGH_G_INTERRUPT_X_HAPPENED
1442#define HIGH_G_INTERRUPT_Y HIGH_G_INTERRUPT_Y_HAPPENED
1443#define HIGH_G_INTERRUPT_Z HIGH_G_INTERRUPT_Z_HAPPENED
1444/*! High G interrupt of x, y, z negative axis happened */
1445#define HIGH_G_INTERRUPT_X_N HIGH_G_INTERRUPT_X_NEGATIVE_HAPPENED
1446#define HIGH_G_INTERRUPT_Y_N HIGH_G_INTERRUPT_Y_NEGATIVE_HAPPENED
1447#define HIGH_G_INTERRUPT_Z_N HIGH_G_INTERRUPT_Z_NEGATIVE_HAPPENED
1448/*! Slope interrupt of x, y, z axis happened */
1449#define SLOPE_INTERRUPT_X SLOPE_INTERRUPT_X_HAPPENED
1450#define SLOPE_INTERRUPT_Y SLOPE_INTERRUPT_Y_HAPPENED
1451#define SLOPE_INTERRUPT_Z SLOPE_INTERRUPT_Z_HAPPENED
1452/*! Slope interrupt of x, y, z negative axis happened */
1453#define SLOPE_INTERRUPT_X_N SLOPE_INTERRUPT_X_NEGATIVE_HAPPENED
1454#define SLOPE_INTERRUPT_Y_N SLOPE_INTERRUPT_Y_NEGATIVE_HAPPENED
1455#define SLOPE_INTERRUPT_Z_N SLOPE_INTERRUPT_Z_NEGATIVE_HAPPENED
1456
1457
1458#endif/*End of CONFIG_SENSORS_BMI058*/
1459
1460/*! A workaroud mask definition with complete resolution exists
1461* aim at writing operation FIFO_CONFIG_1, 0x3E register */
1462#define FIFO_WORKAROUNDS_MSK SMI_ACC2X2_FIFO_TRIGGER_SOURCE__MSK
1463
1464struct smi130_acc_type_map_t {
1465
1466 /*! smi130_acc sensor chip id */
1467 uint16_t chip_id;
1468
1469 /*! smi130_acc sensor type */
1470 uint16_t sensor_type;
1471
1472 /*! smi130_acc sensor name */
1473 const char *sensor_name;
1474};
1475
1476static const struct smi130_acc_type_map_t sensor_type_map[] = {
1477
1478 {SMI_ACC255_CHIP_ID, SMI_ACC255_TYPE, "SMI_ACC255/254"},
1479 {SMI_ACC355_CHIP_ID, SMI_ACC255_TYPE, "SMI_ACC355"},
1480 {SMI_ACC250E_CHIP_ID, SMI_ACC250E_TYPE, "SMI_ACC250E"},
1481 {SMI_ACC222E_CHIP_ID, SMI_ACC222E_TYPE, "SMI_ACC222E"},
1482 {SMI_ACC280_CHIP_ID, SMI_ACC280_TYPE, "SMI_ACC280"},
1483
1484};
1485
1486/*!
1487* Bst sensor common definition,
1488* please give parameters in BSP file.
1489*/
1490struct bosch_sensor_specific {
1491 char *name;
1492 /* 0 to 7 */
1493 int place;
1494 int irq;
1495 int (*irq_gpio_cfg)(void);
1496};
1497
1498
1499/*!
1500 * we use a typedef to hide the detail,
1501 * because this type might be changed
1502 */
1503struct bosch_sensor_axis_remap {
1504 /* src means which source will be mapped to target x, y, z axis */
1505 /* if an target OS axis is remapped from (-)x,
1506 * src is 0, sign_* is (-)1 */
1507 /* if an target OS axis is remapped from (-)y,
1508 * src is 1, sign_* is (-)1 */
1509 /* if an target OS axis is remapped from (-)z,
1510 * src is 2, sign_* is (-)1 */
1511 int src_x:3;
1512 int src_y:3;
1513 int src_z:3;
1514
1515 int sign_x:2;
1516 int sign_y:2;
1517 int sign_z:2;
1518};
1519
1520struct bosch_sensor_data {
1521 union {
1522 int16_t v[3];
1523 struct {
1524 int16_t x;
1525 int16_t y;
1526 int16_t z;
1527 };
1528 };
1529};
1530
Puneet Yatnalcfd94842019-04-16 12:11:05 +05301531#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
Raghava Chowdamc1e64aa2020-03-04 16:27:05 +05301532#define SMI_ACC_MAXSAMPLE 5000
Puneet Yatnalcfd94842019-04-16 12:11:05 +05301533#define G_MAX 23920640
1534struct smi_acc_sample {
1535 int xyz[3];
1536 unsigned int tsec;
1537 unsigned long long tnsec;
1538};
1539#endif
1540
Bosch Sensortecface5922018-08-29 08:08:53 +02001541struct smi130_accacc {
1542 s16 x;
1543 s16 y;
1544 s16 z;
1545};
1546
1547struct smi130_acc_data {
1548 struct i2c_client *smi130_acc_client;
1549 atomic_t delay;
1550 atomic_t enable;
1551 atomic_t selftest_result;
1552 unsigned int chip_id;
1553 unsigned int fifo_count;
1554 unsigned char fifo_datasel;
1555 unsigned char mode;
1556 signed char sensor_type;
1557 uint64_t timestamp;
1558 uint64_t fifo_time;
1559 uint64_t base_time;
1560 uint64_t acc_count;
1561 uint64_t time_odr;
1562 uint8_t debug_level;
1563 struct work_struct report_data_work;
1564 int is_timer_running;
1565 struct hrtimer timer;
1566 ktime_t work_delay_kt;
1567 struct input_dev *input;
1568
1569 struct bosch_dev *bosch_acc;
1570
1571 struct smi130_accacc value;
1572 struct mutex value_mutex;
1573 struct mutex enable_mutex;
1574 struct mutex mode_mutex;
1575 struct delayed_work work;
Bosch Sensortecface5922018-08-29 08:08:53 +02001576#ifdef CONFIG_HAS_EARLYSUSPEND
1577 struct early_suspend early_suspend;
1578#endif
1579 int16_t IRQ;
1580 struct bosch_sensor_specific *bosch_pd;
1581
1582 int smi_acc_mode_enabled;
1583 struct input_dev *dev_interrupt;
1584
1585#ifdef CONFIG_SIG_MOTION
1586 struct class *g_sensor_class;
1587 struct device *g_sensor_dev;
1588
1589 /*struct smi_acc250_platform_data *pdata;*/
1590 atomic_t en_sig_motion;
1591#endif
1592
1593#ifdef CONFIG_DOUBLE_TAP
1594 struct class *g_sensor_class_doubletap;
1595 struct device *g_sensor_dev_doubletap;
1596 atomic_t en_double_tap;
1597 unsigned char tap_times;
1598 struct mutex tap_mutex;
1599 struct timer_list tap_timer;
1600 int tap_time_period;
1601#endif
Puneet Yatnalcfd94842019-04-16 12:11:05 +05301602#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
1603 bool read_acc_boot_sample;
1604 int acc_bufsample_cnt;
1605 bool acc_buffer_smi130_samples;
Puneet Yatnalab29efa2019-08-05 13:13:31 +05301606 bool acc_enable;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05301607 struct kmem_cache *smi_acc_cachepool;
1608 struct smi_acc_sample *smi130_acc_samplist[SMI_ACC_MAXSAMPLE];
1609 int max_buffer_time;
1610 struct input_dev *accbuf_dev;
1611 int report_evt_cnt;
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05301612 struct mutex acc_sensor_buff;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05301613#endif
puneet597e4f12018-11-06 14:32:16 +05301614#ifdef SMI130_HRTIMER
1615 struct hrtimer smi130_hrtimer;
1616#endif
Bosch Sensortecface5922018-08-29 08:08:53 +02001617};
1618
puneet597e4f12018-11-06 14:32:16 +05301619#ifdef SMI130_HRTIMER
1620static void smi130_set_cpu_idle_state(bool value)
1621{
1622 cpu_idle_poll_ctrl(value);
1623}
1624static enum hrtimer_restart smi130_timer_function(struct hrtimer *timer)
1625{
1626 smi130_set_cpu_idle_state(true);
1627
1628 return HRTIMER_NORESTART;
1629}
1630static void smi130_hrtimer_reset(struct smi130_acc_data *data)
1631{
1632 hrtimer_cancel(&data->smi130_hrtimer);
1633 /*forward HRTIMER just before 1ms of irq arrival*/
1634 hrtimer_forward(&data->smi130_hrtimer, ktime_get(),
1635 ns_to_ktime(data->time_odr - 1000000));
1636 hrtimer_restart(&data->smi130_hrtimer);
1637}
1638static void smi130_hrtimer_init(struct smi130_acc_data *data)
1639{
1640 hrtimer_init(&data->smi130_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1641 data->smi130_hrtimer.function = smi130_timer_function;
1642}
1643static void smi130_hrtimer_cleanup(struct smi130_acc_data *data)
1644{
1645 hrtimer_cancel(&data->smi130_hrtimer);
1646}
1647#else
1648static void smi130_set_cpu_idle_state(bool value)
1649{
1650}
1651static void smi130_hrtimer_reset(struct smi130_acc_data *data)
1652{
1653
1654}
1655static void smi130_hrtimer_init(struct smi130_acc_data *data)
1656{
1657
1658}
1659static void smi130_hrtimer_remove(struct smi130_acc_data *data)
1660{
1661
1662}
1663#endif
1664
Bosch Sensortecface5922018-08-29 08:08:53 +02001665#ifdef CONFIG_HAS_EARLYSUSPEND
1666static void smi130_acc_early_suspend(struct early_suspend *h);
1667static void smi130_acc_late_resume(struct early_suspend *h);
1668#endif
1669
1670static int smi130_acc_set_mode(struct i2c_client *client,
1671 u8 mode, u8 enabled_mode);
1672static int smi130_acc_get_mode(struct i2c_client *client, u8 *mode);
1673static int smi130_acc_get_fifo_mode(struct i2c_client *client, u8 *fifo_mode);
1674static int smi130_acc_set_fifo_mode(struct i2c_client *client, u8 fifo_mode);
1675static int smi130_acc_normal_to_suspend(struct smi130_acc_data *smi130_acc,
1676 unsigned char data1, unsigned char data2);
1677
1678static void smi130_acc_delay(u32 msec)
1679{
1680 if (msec <= 20)
1681 usleep_range(msec * 1000, msec * 1000);
1682 else
1683 msleep(msec);
1684}
1685/*Remapping for SMI_ACC2X2*/
1686static const struct bosch_sensor_axis_remap
1687bosch_axis_remap_tab_dft[MAX_AXIS_REMAP_TAB_SZ] = {
1688 /* src_x src_y src_z sign_x sign_y sign_z */
1689 { 0, 1, 2, 1, 1, 1 }, /* P0 */
1690 { 1, 0, 2, 1, -1, 1 }, /* P1 */
1691 { 0, 1, 2, -1, -1, 1 }, /* P2 */
1692 { 1, 0, 2, -1, 1, 1 }, /* P3 */
1693
1694 { 0, 1, 2, -1, 1, -1 }, /* P4 */
1695 { 1, 0, 2, -1, -1, -1 }, /* P5 */
1696 { 0, 1, 2, 1, -1, -1 }, /* P6 */
1697 { 1, 0, 2, 1, 1, -1 }, /* P7 */
1698};
1699
1700
1701static void bosch_remap_sensor_data(struct bosch_sensor_data *data,
1702 const struct bosch_sensor_axis_remap *remap)
1703{
1704 struct bosch_sensor_data tmp;
1705
1706 tmp.x = data->v[remap->src_x] * remap->sign_x;
1707 tmp.y = data->v[remap->src_y] * remap->sign_y;
1708 tmp.z = data->v[remap->src_z] * remap->sign_z;
1709
1710 memcpy(data, &tmp, sizeof(*data));
1711}
1712
1713
1714static void bosch_remap_sensor_data_dft_tab(struct bosch_sensor_data *data,
1715 int place)
1716{
1717 /* sensor with place 0 needs not to be remapped */
1718 if ((place <= 0) || (place >= MAX_AXIS_REMAP_TAB_SZ))
1719 return;
1720
1721 bosch_remap_sensor_data(data, &bosch_axis_remap_tab_dft[place]);
1722}
1723
1724static void smi130_acc_remap_sensor_data(struct smi130_accacc *val,
1725 struct smi130_acc_data *client_data)
1726{
1727 struct bosch_sensor_data bsd;
1728 int place;
1729
1730 if ((NULL == client_data->bosch_pd) || (BOSCH_SENSOR_PLACE_UNKNOWN
1731 == client_data->bosch_pd->place))
1732 place = BOSCH_SENSOR_PLACE_UNKNOWN;
1733 else
1734 place = client_data->bosch_pd->place;
1735
1736#ifdef CONFIG_SENSORS_BMI058
1737/*x,y need to be invesed becase of HW Register for BMI058*/
1738 bsd.y = val->x;
1739 bsd.x = val->y;
1740 bsd.z = val->z;
1741#else
1742 bsd.x = val->x;
1743 bsd.y = val->y;
1744 bsd.z = val->z;
1745#endif
1746
1747 bosch_remap_sensor_data_dft_tab(&bsd, place);
1748
1749 val->x = bsd.x;
1750 val->y = bsd.y;
1751 val->z = bsd.z;
1752
1753}
1754
1755
1756static int smi130_acc_smbus_read_byte(struct i2c_client *client,
1757 unsigned char reg_addr, unsigned char *data)
1758{
1759#if !defined SMI130_ACC_USE_BASIC_I2C_FUNC
1760 s32 dummy;
1761 int len = 1;
1762 if (NULL == client)
1763 return -ENODEV;
1764
1765 while (0 != len--) {
1766#ifdef SMI130_ACC_SMBUS
1767 dummy = i2c_smbus_read_byte_data(client, reg_addr);
1768 if (dummy < 0) {
1769 PERR("i2c bus read error");
1770 return -EIO;
1771 }
1772 *data = (u8)(dummy & 0xff);
1773#else
1774 dummy = i2c_master_send(client, (char *)&reg_addr, 1);
1775 if (dummy < 0)
1776 return -EIO;
1777
1778 dummy = i2c_master_recv(client, (char *)data, 1);
1779 if (dummy < 0)
1780 return -EIO;
1781#endif
1782 reg_addr++;
1783 data++;
1784 }
1785 return 0;
1786#else
1787 int retry;
1788 int len = 1;
1789 struct i2c_msg msg[] = {
1790 {
1791 .addr = client->addr,
1792 .flags = 0,
1793 .len = 1,
1794 .buf = &reg_addr,
1795 },
1796
1797 {
1798 .addr = client->addr,
1799 .flags = I2C_M_RD,
1800 .len = len,
1801 .buf = data,
1802 },
1803 };
1804
1805 for (retry = 0; retry < SMI_ACC_MAX_RETRY_I2C_XFER; retry++) {
1806 if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
1807 break;
1808 else
1809 smi130_acc_delay(1);
1810 }
1811
1812 if (SMI_ACC_MAX_RETRY_I2C_XFER <= retry) {
1813 PERR("I2C xfer error");
1814 return -EIO;
1815 }
1816
1817 return 0;
1818#endif
1819}
1820
1821static int smi130_acc_smbus_write_byte(struct i2c_client *client,
1822 unsigned char reg_addr, unsigned char *data)
1823{
1824#if !defined SMI130_ACC_USE_BASIC_I2C_FUNC
1825 s32 dummy;
1826 int len = 1;
1827#ifndef SMI130_ACC_SMBUS
1828 u8 buffer[2];
1829#endif
1830 if (NULL == client)
1831 return -ENODEV;
1832
1833 while (0 != len--) {
1834#ifdef SMI130_ACC_SMBUS
1835 dummy = i2c_smbus_write_byte_data(client, reg_addr, *data);
1836#else
1837 buffer[0] = reg_addr;
1838 buffer[1] = *data;
1839 dummy = i2c_master_send(client, (char *)buffer, 2);
1840#endif
1841 reg_addr++;
1842 data++;
1843 if (dummy < 0) {
1844 PERR("error writing i2c bus");
1845 return -EIO;
1846 }
1847
1848 }
1849 return 0;
1850#else
1851 u8 buffer[2];
1852 int retry;
1853 int len = 1;
1854 struct i2c_msg msg[] = {
1855 {
1856 .addr = client->addr,
1857 .flags = 0,
1858 .len = 2,
1859 .buf = buffer,
1860 },
1861 };
1862 while (0 != len--) {
1863 buffer[0] = reg_addr;
1864 buffer[1] = *data;
1865 for (retry = 0; retry < SMI_ACC_MAX_RETRY_I2C_XFER; retry++) {
1866 if (i2c_transfer(client->adapter, msg,
1867 ARRAY_SIZE(msg)) > 0) {
1868 break;
1869 } else {
1870 smi130_acc_delay(1);
1871 }
1872 }
1873 if (SMI_ACC_MAX_RETRY_I2C_XFER <= retry) {
1874 PERR("I2C xfer error");
1875 return -EIO;
1876 }
1877 reg_addr++;
1878 data++;
1879 }
1880
1881 return 0;
1882#endif
1883}
1884
1885static int smi130_acc_smbus_read_byte_block(struct i2c_client *client,
1886 unsigned char reg_addr, unsigned char *data, unsigned char len)
1887{
1888 int retry;
1889
1890 struct i2c_msg msg[] = {
1891 {
1892 .addr = client->addr,
1893 .flags = 0,
1894 .len = 1,
1895 .buf = &reg_addr,
1896 },
1897
1898 {
1899 .addr = client->addr,
1900 .flags = I2C_M_RD,
1901 .len = len,
1902 .buf = data,
1903 },
1904 };
1905
1906 for (retry = 0; retry < SMI_ACC_MAX_RETRY_I2C_XFER; retry++) {
1907 if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
1908 break;
1909 else
1910 smi130_acc_delay(1);
1911 }
1912
1913 if (SMI_ACC_MAX_RETRY_I2C_XFER <= retry) {
1914 PERR("I2C xfer error");
1915 return -EIO;
1916 }
1917 return 0;
1918}
1919
1920static int smi_acc_i2c_burst_read(struct i2c_client *client, u8 reg_addr,
1921 u8 *data, u16 len)
1922{
1923 int retry;
1924
1925 struct i2c_msg msg[] = {
1926 {
1927 .addr = client->addr,
1928 .flags = 0,
1929 .len = 1,
1930 .buf = &reg_addr,
1931 },
1932
1933 {
1934 .addr = client->addr,
1935 .flags = I2C_M_RD,
1936 .len = len,
1937 .buf = data,
1938 },
1939 };
1940
1941 for (retry = 0; retry < SMI_ACC_MAX_RETRY_I2C_XFER; retry++) {
1942 if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
1943 break;
1944 else
1945 smi130_acc_delay(1);
1946 }
1947
1948 if (SMI_ACC_MAX_RETRY_I2C_XFER <= retry) {
1949 PINFO("I2C xfer error");
1950 return -EIO;
1951 }
1952
1953 return 0;
1954}
1955
1956static int smi130_acc_check_chip_id(struct i2c_client *client,
1957 struct smi130_acc_data *data)
1958{
1959 int i = 0;
1960 int err = 0;
1961 unsigned char chip_id = 0;
1962 unsigned char read_count = 0;
1963 unsigned char smi130_acc_sensor_type_count = 0;
1964
1965 smi130_acc_sensor_type_count =
1966 sizeof(sensor_type_map) / sizeof(struct smi130_acc_type_map_t);
1967
1968 while (read_count++ < CHECK_CHIP_ID_TIME_MAX) {
1969 if (smi130_acc_smbus_read_byte(client, SMI_ACC2X2_CHIP_ID_REG,
1970 &chip_id) < 0) {
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301971 PERR("Bosch Sensortec Device not found\n"
Bosch Sensortecface5922018-08-29 08:08:53 +02001972 "i2c bus read error, read chip_id:%d\n", chip_id);
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301973 err = -ENODEV;
Bosch Sensortecface5922018-08-29 08:08:53 +02001974 continue;
1975 } else {
1976 for (i = 0; i < smi130_acc_sensor_type_count; i++) {
1977 if (sensor_type_map[i].chip_id == chip_id) {
1978 data->sensor_type =
1979 sensor_type_map[i].sensor_type;
1980 data->chip_id = chip_id;
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301981 PINFO("Bosch Sensortec Device detected\n"
Bosch Sensortecface5922018-08-29 08:08:53 +02001982 " HW IC name: %s\n",
1983 sensor_type_map[i].sensor_name);
1984 return err;
1985 }
1986 }
1987 if (i < smi130_acc_sensor_type_count)
1988 return err;
1989 else {
1990 if (read_count == CHECK_CHIP_ID_TIME_MAX) {
Puneet Yatnalbd8180a2019-01-30 15:33:10 +05301991 PERR("Failed! Bosch Sensortec Device\n"
Bosch Sensortecface5922018-08-29 08:08:53 +02001992 " not found, mismatch chip_id:%d\n",
1993 chip_id);
1994 err = -ENODEV;
1995 return err;
1996 }
1997 }
1998 smi130_acc_delay(1);
1999 }
2000 }
2001 return err;
2002}
2003
2004#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
2005static int smi130_acc_set_newdata(struct i2c_client *client,
2006 unsigned char channel, unsigned char int_newdata)
2007{
2008
2009 unsigned char data = 0;
2010 int comres = 0;
2011
2012 switch (channel) {
2013 case SMI_ACC2X2_INT1_NDATA:
2014 comres = smi130_acc_smbus_read_byte(client,
2015 SMI_ACC2X2_EN_INT1_PAD_NEWDATA__REG, &data);
2016 data = SMI_ACC2X2_SET_BITSLICE(data,
2017 SMI_ACC2X2_EN_INT1_PAD_NEWDATA, int_newdata);
2018 comres = smi130_acc_smbus_write_byte(client,
2019 SMI_ACC2X2_EN_INT1_PAD_NEWDATA__REG, &data);
2020 break;
2021 case SMI_ACC2X2_INT2_NDATA:
2022 comres = smi130_acc_smbus_read_byte(client,
2023 SMI_ACC2X2_EN_INT2_PAD_NEWDATA__REG, &data);
2024 data = SMI_ACC2X2_SET_BITSLICE(data,
2025 SMI_ACC2X2_EN_INT2_PAD_NEWDATA, int_newdata);
2026 comres = smi130_acc_smbus_write_byte(client,
2027 SMI_ACC2X2_EN_INT2_PAD_NEWDATA__REG, &data);
2028 break;
2029 default:
2030 comres = -1;
2031 break;
2032 }
2033
2034 return comres;
2035
2036}
2037#endif /* CONFIG_SMI_ACC_ENABLE_NEWDATA_INT */
2038
2039#ifdef SMI_ACC2X2_ENABLE_INT1
2040static int smi130_acc_set_int1_pad_sel(struct i2c_client *client, unsigned char
2041 int1sel)
2042{
2043 int comres = 0;
2044 unsigned char data = 0;
2045 unsigned char state;
2046 state = 0x01;
2047
2048
2049 switch (int1sel) {
2050 case 0:
2051 comres = smi130_acc_smbus_read_byte(client,
2052 SMI_ACC2X2_EN_INT1_PAD_LOWG__REG, &data);
2053 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_LOWG,
2054 state);
2055 comres = smi130_acc_smbus_write_byte(client,
2056 SMI_ACC2X2_EN_INT1_PAD_LOWG__REG, &data);
2057 break;
2058 case 1:
2059 comres = smi130_acc_smbus_read_byte(client,
2060 SMI_ACC2X2_EN_INT1_PAD_HIGHG__REG, &data);
2061 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_HIGHG,
2062 state);
2063 comres = smi130_acc_smbus_write_byte(client,
2064 SMI_ACC2X2_EN_INT1_PAD_HIGHG__REG, &data);
2065 break;
2066 case 2:
2067 comres = smi130_acc_smbus_read_byte(client,
2068 SMI_ACC2X2_EN_INT1_PAD_SLOPE__REG, &data);
2069 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_SLOPE,
2070 state);
2071 comres = smi130_acc_smbus_write_byte(client,
2072 SMI_ACC2X2_EN_INT1_PAD_SLOPE__REG, &data);
2073 break;
2074 case 3:
2075 comres = smi130_acc_smbus_read_byte(client,
2076 SMI_ACC2X2_EN_INT1_PAD_DB_TAP__REG, &data);
2077 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_DB_TAP,
2078 state);
2079 comres = smi130_acc_smbus_write_byte(client,
2080 SMI_ACC2X2_EN_INT1_PAD_DB_TAP__REG, &data);
2081 break;
2082 case 4:
2083 comres = smi130_acc_smbus_read_byte(client,
2084 SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__REG, &data);
2085 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_SNG_TAP,
2086 state);
2087 comres = smi130_acc_smbus_write_byte(client,
2088 SMI_ACC2X2_EN_INT1_PAD_SNG_TAP__REG, &data);
2089 break;
2090 case 5:
2091 comres = smi130_acc_smbus_read_byte(client,
2092 SMI_ACC2X2_EN_INT1_PAD_ORIENT__REG, &data);
2093 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_ORIENT,
2094 state);
2095 comres = smi130_acc_smbus_write_byte(client,
2096 SMI_ACC2X2_EN_INT1_PAD_ORIENT__REG, &data);
2097 break;
2098 case 6:
2099 comres = smi130_acc_smbus_read_byte(client,
2100 SMI_ACC2X2_EN_INT1_PAD_FLAT__REG, &data);
2101 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_FLAT,
2102 state);
2103 comres = smi130_acc_smbus_write_byte(client,
2104 SMI_ACC2X2_EN_INT1_PAD_FLAT__REG, &data);
2105 break;
2106 case 7:
2107 comres = smi130_acc_smbus_read_byte(client,
2108 SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__REG, &data);
2109 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT,
2110 state);
2111 comres = smi130_acc_smbus_write_byte(client,
2112 SMI_ACC2X2_EN_INT1_PAD_SLO_NO_MOT__REG, &data);
2113 break;
2114
2115 default:
2116 break;
2117 }
2118
2119 return comres;
2120}
2121#endif /* SMI_ACC2X2_ENABLE_INT1 */
2122
2123#ifdef SMI_ACC2X2_ENABLE_INT2
2124static int smi130_acc_set_int2_pad_sel(struct i2c_client *client, unsigned char
2125 int2sel)
2126{
2127 int comres = 0;
2128 unsigned char data = 0;
2129 unsigned char state;
2130 state = 0x01;
2131
2132
2133 switch (int2sel) {
2134 case 0:
2135 comres = smi130_acc_smbus_read_byte(client,
2136 SMI_ACC2X2_EN_INT2_PAD_LOWG__REG, &data);
2137 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_LOWG,
2138 state);
2139 comres = smi130_acc_smbus_write_byte(client,
2140 SMI_ACC2X2_EN_INT2_PAD_LOWG__REG, &data);
2141 break;
2142 case 1:
2143 comres = smi130_acc_smbus_read_byte(client,
2144 SMI_ACC2X2_EN_INT2_PAD_HIGHG__REG, &data);
2145 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_HIGHG,
2146 state);
2147 comres = smi130_acc_smbus_write_byte(client,
2148 SMI_ACC2X2_EN_INT2_PAD_HIGHG__REG, &data);
2149 break;
2150 case 2:
2151 comres = smi130_acc_smbus_read_byte(client,
2152 SMI_ACC2X2_EN_INT2_PAD_SLOPE__REG, &data);
2153 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_SLOPE,
2154 state);
2155 comres = smi130_acc_smbus_write_byte(client,
2156 SMI_ACC2X2_EN_INT2_PAD_SLOPE__REG, &data);
2157 break;
2158 case 3:
2159 comres = smi130_acc_smbus_read_byte(client,
2160 SMI_ACC2X2_EN_INT2_PAD_DB_TAP__REG, &data);
2161 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_DB_TAP,
2162 state);
2163 comres = smi130_acc_smbus_write_byte(client,
2164 SMI_ACC2X2_EN_INT2_PAD_DB_TAP__REG, &data);
2165 break;
2166 case 4:
2167 comres = smi130_acc_smbus_read_byte(client,
2168 SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__REG, &data);
2169 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_SNG_TAP,
2170 state);
2171 comres = smi130_acc_smbus_write_byte(client,
2172 SMI_ACC2X2_EN_INT2_PAD_SNG_TAP__REG, &data);
2173 break;
2174 case 5:
2175 comres = smi130_acc_smbus_read_byte(client,
2176 SMI_ACC2X2_EN_INT2_PAD_ORIENT__REG, &data);
2177 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_ORIENT,
2178 state);
2179 comres = smi130_acc_smbus_write_byte(client,
2180 SMI_ACC2X2_EN_INT2_PAD_ORIENT__REG, &data);
2181 break;
2182 case 6:
2183 comres = smi130_acc_smbus_read_byte(client,
2184 SMI_ACC2X2_EN_INT2_PAD_FLAT__REG, &data);
2185 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_FLAT,
2186 state);
2187 comres = smi130_acc_smbus_write_byte(client,
2188 SMI_ACC2X2_EN_INT2_PAD_FLAT__REG, &data);
2189 break;
2190 case 7:
2191 comres = smi130_acc_smbus_read_byte(client,
2192 SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__REG, &data);
2193 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT,
2194 state);
2195 comres = smi130_acc_smbus_write_byte(client,
2196 SMI_ACC2X2_EN_INT2_PAD_SLO_NO_MOT__REG, &data);
2197 break;
2198 default:
2199 break;
2200 }
2201
2202 return comres;
2203}
2204#endif /* SMI_ACC2X2_ENABLE_INT2 */
2205
2206static int smi130_acc_set_Int_Enable(struct i2c_client *client, unsigned char
2207 InterruptType , unsigned char value)
2208{
2209 int comres = 0;
2210 unsigned char data1 = 0;
2211 unsigned char data2 = 0;
2212
2213 if ((11 < InterruptType) && (InterruptType < 16)) {
2214 switch (InterruptType) {
2215 case 12:
2216 /* slow/no motion X Interrupt */
2217 comres = smi130_acc_smbus_read_byte(client,
2218 SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__REG, &data1);
2219 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
2220 SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT, value);
2221 comres = smi130_acc_smbus_write_byte(client,
2222 SMI_ACC2X2_INT_SLO_NO_MOT_EN_X_INT__REG, &data1);
2223 break;
2224 case 13:
2225 /* slow/no motion Y Interrupt */
2226 comres = smi130_acc_smbus_read_byte(client,
2227 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__REG, &data1);
2228 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
2229 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT, value);
2230 comres = smi130_acc_smbus_write_byte(client,
2231 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Y_INT__REG, &data1);
2232 break;
2233 case 14:
2234 /* slow/no motion Z Interrupt */
2235 comres = smi130_acc_smbus_read_byte(client,
2236 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__REG, &data1);
2237 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
2238 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT, value);
2239 comres = smi130_acc_smbus_write_byte(client,
2240 SMI_ACC2X2_INT_SLO_NO_MOT_EN_Z_INT__REG, &data1);
2241 break;
2242 case 15:
2243 /* slow / no motion Interrupt select */
2244 comres = smi130_acc_smbus_read_byte(client,
2245 SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG, &data1);
2246 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
2247 SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT, value);
2248 comres = smi130_acc_smbus_write_byte(client,
2249 SMI_ACC2X2_INT_SLO_NO_MOT_EN_SEL_INT__REG, &data1);
2250 }
2251
2252 return comres;
2253 }
2254
2255
2256 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_INT_ENABLE1_REG, &data1);
2257 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_INT_ENABLE2_REG, &data2);
2258
2259 value = value & 1;
2260 switch (InterruptType) {
2261 case 0:
2262 /* Low G Interrupt */
2263 data2 = SMI_ACC2X2_SET_BITSLICE(data2, SMI_ACC2X2_EN_LOWG_INT, value);
2264 break;
2265
2266 case 1:
2267 /* High G X Interrupt */
2268 data2 = SMI_ACC2X2_SET_BITSLICE(data2, SMI_ACC2X2_EN_HIGHG_X_INT,
2269 value);
2270 break;
2271
2272 case 2:
2273 /* High G Y Interrupt */
2274 data2 = SMI_ACC2X2_SET_BITSLICE(data2, SMI_ACC2X2_EN_HIGHG_Y_INT,
2275 value);
2276 break;
2277
2278 case 3:
2279 /* High G Z Interrupt */
2280 data2 = SMI_ACC2X2_SET_BITSLICE(data2, SMI_ACC2X2_EN_HIGHG_Z_INT,
2281 value);
2282 break;
2283
2284 case 4:
2285 /* New Data Interrupt */
2286 data2 = SMI_ACC2X2_SET_BITSLICE(data2, SMI_ACC2X2_EN_NEW_DATA_INT,
2287 value);
2288 break;
2289
2290 case 5:
2291 /* Slope X Interrupt */
2292 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_SLOPE_X_INT,
2293 value);
2294 break;
2295
2296 case 6:
2297 /* Slope Y Interrupt */
2298 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_SLOPE_Y_INT,
2299 value);
2300 break;
2301
2302 case 7:
2303 /* Slope Z Interrupt */
2304 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_SLOPE_Z_INT,
2305 value);
2306 break;
2307
2308 case 8:
2309 /* Single Tap Interrupt */
2310 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_SINGLE_TAP_INT,
2311 value);
2312 break;
2313
2314 case 9:
2315 /* Double Tap Interrupt */
2316 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_DOUBLE_TAP_INT,
2317 value);
2318 break;
2319
2320 case 10:
2321 /* Orient Interrupt */
2322 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_ORIENT_INT, value);
2323 break;
2324
2325 case 11:
2326 /* Flat Interrupt */
2327 data1 = SMI_ACC2X2_SET_BITSLICE(data1, SMI_ACC2X2_EN_FLAT_INT, value);
2328 break;
2329
2330 default:
2331 break;
2332 }
2333 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_INT_ENABLE1_REG,
2334 &data1);
2335 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_INT_ENABLE2_REG,
2336 &data2);
2337
2338 return comres;
2339}
2340
2341
2342#if defined(SMI_ACC2X2_ENABLE_INT1) || defined(SMI_ACC2X2_ENABLE_INT2)
2343static int smi130_acc_get_interruptstatus1(struct i2c_client *client, unsigned char
2344 *intstatus)
2345{
2346 int comres = 0;
2347 unsigned char data = 0;
2348
2349 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS1_REG, &data);
2350 *intstatus = data;
2351
2352 return comres;
2353}
2354
2355#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
2356/*
2357static int smi130_acc_get_interruptstatus2(struct i2c_client *client, unsigned char
2358 *intstatus)
2359{
2360 int comres = 0;
2361 unsigned char data = 0;
2362
2363 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS2_REG, &data);
2364 *intstatus = data;
2365
2366 return comres;
2367}
2368*/
2369#endif
2370
2371static int smi130_acc_get_HIGH_first(struct i2c_client *client, unsigned char
2372 param, unsigned char *intstatus)
2373{
2374 int comres = 0;
2375 unsigned char data = 0;
2376
2377 switch (param) {
2378 case 0:
2379 comres = smi130_acc_smbus_read_byte(client,
2380 SMI_ACC2X2_STATUS_ORIENT_HIGH_REG, &data);
2381 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_FIRST_X);
2382 *intstatus = data;
2383 break;
2384 case 1:
2385 comres = smi130_acc_smbus_read_byte(client,
2386 SMI_ACC2X2_STATUS_ORIENT_HIGH_REG, &data);
2387 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_FIRST_Y);
2388 *intstatus = data;
2389 break;
2390 case 2:
2391 comres = smi130_acc_smbus_read_byte(client,
2392 SMI_ACC2X2_STATUS_ORIENT_HIGH_REG, &data);
2393 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_FIRST_Z);
2394 *intstatus = data;
2395 break;
2396 default:
2397 break;
2398 }
2399
2400 return comres;
2401}
2402
2403static int smi130_acc_get_HIGH_sign(struct i2c_client *client, unsigned char
2404 *intstatus)
2405{
2406 int comres = 0;
2407 unsigned char data = 0;
2408
2409 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS_ORIENT_HIGH_REG,
2410 &data);
2411 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_SIGN_S);
2412 *intstatus = data;
2413
2414 return comres;
2415}
2416
2417#ifndef CONFIG_SIG_MOTION
2418static int smi130_acc_get_slope_first(struct i2c_client *client, unsigned char
2419 param, unsigned char *intstatus)
2420{
2421 int comres = 0;
2422 unsigned char data = 0;
2423
2424 switch (param) {
2425 case 0:
2426 comres = smi130_acc_smbus_read_byte(client,
2427 SMI_ACC2X2_STATUS_TAP_SLOPE_REG, &data);
2428 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLOPE_FIRST_X);
2429 *intstatus = data;
2430 break;
2431 case 1:
2432 comres = smi130_acc_smbus_read_byte(client,
2433 SMI_ACC2X2_STATUS_TAP_SLOPE_REG, &data);
2434 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLOPE_FIRST_Y);
2435 *intstatus = data;
2436 break;
2437 case 2:
2438 comres = smi130_acc_smbus_read_byte(client,
2439 SMI_ACC2X2_STATUS_TAP_SLOPE_REG, &data);
2440 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLOPE_FIRST_Z);
2441 *intstatus = data;
2442 break;
2443 default:
2444 break;
2445 }
2446
2447 return comres;
2448}
2449
2450static int smi130_acc_get_slope_sign(struct i2c_client *client, unsigned char
2451 *intstatus)
2452{
2453 int comres = 0;
2454 unsigned char data = 0;
2455
2456 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS_TAP_SLOPE_REG,
2457 &data);
2458 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLOPE_SIGN_S);
2459 *intstatus = data;
2460
2461 return comres;
2462}
2463#endif
2464
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002465static int smi130_acc_get_orient_mbl_status(struct i2c_client *client, unsigned char
Bosch Sensortecface5922018-08-29 08:08:53 +02002466 *intstatus)
2467{
2468 int comres = 0;
2469 unsigned char data = 0;
2470
2471 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS_ORIENT_HIGH_REG,
2472 &data);
2473 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_ORIENT_S);
2474 *intstatus = data;
2475
2476 return comres;
2477}
2478
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002479static int smi130_acc_get_orient_mbl_flat_status(struct i2c_client *client, unsigned
Bosch Sensortecface5922018-08-29 08:08:53 +02002480 char *intstatus)
2481{
2482 int comres = 0;
2483 unsigned char data = 0;
2484
2485 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_STATUS_ORIENT_HIGH_REG,
2486 &data);
2487 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FLAT_S);
2488 *intstatus = data;
2489
2490 return comres;
2491}
2492#endif /* defined(SMI_ACC2X2_ENABLE_INT1)||defined(SMI_ACC2X2_ENABLE_INT2) */
2493
2494static int smi130_acc_set_Int_Mode(struct i2c_client *client, unsigned char Mode)
2495{
2496 int comres = 0;
2497 unsigned char data = 0;
2498
2499
2500 comres = smi130_acc_smbus_read_byte(client,
2501 SMI_ACC2X2_INT_MODE_SEL__REG, &data);
2502 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_INT_MODE_SEL, Mode);
2503 comres = smi130_acc_smbus_write_byte(client,
2504 SMI_ACC2X2_INT_MODE_SEL__REG, &data);
2505
2506
2507 return comres;
2508}
2509
2510static int smi130_acc_get_Int_Mode(struct i2c_client *client, unsigned char *Mode)
2511{
2512 int comres = 0;
2513 unsigned char data = 0;
2514
2515
2516 comres = smi130_acc_smbus_read_byte(client,
2517 SMI_ACC2X2_INT_MODE_SEL__REG, &data);
2518 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_INT_MODE_SEL);
2519 *Mode = data;
2520
2521
2522 return comres;
2523}
2524static int smi130_acc_set_slope_duration(struct i2c_client *client, unsigned char
2525 duration)
2526{
2527 int comres = 0;
2528 unsigned char data = 0;
2529
2530
2531 comres = smi130_acc_smbus_read_byte(client,
2532 SMI_ACC2X2_SLOPE_DUR__REG, &data);
2533 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_SLOPE_DUR, duration);
2534 comres = smi130_acc_smbus_write_byte(client,
2535 SMI_ACC2X2_SLOPE_DUR__REG, &data);
2536
2537 return comres;
2538}
2539
2540static int smi130_acc_get_slope_duration(struct i2c_client *client, unsigned char
2541 *status)
2542{
2543 int comres = 0;
2544 unsigned char data = 0;
2545
2546
2547 comres = smi130_acc_smbus_read_byte(client,
2548 SMI_ACC2X2_SLOPE_DURN_REG, &data);
2549 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLOPE_DUR);
2550 *status = data;
2551
2552
2553 return comres;
2554}
2555
2556static int smi130_acc_set_slope_no_mot_duration(struct i2c_client *client,
2557 unsigned char duration)
2558{
2559 int comres = 0;
2560 unsigned char data = 0;
2561
2562
2563 comres = smi130_acc_smbus_read_byte(client,
2564 SMI130_ACC_SLO_NO_MOT_DUR__REG, &data);
2565 data = SMI_ACC2X2_SET_BITSLICE(data, SMI130_ACC_SLO_NO_MOT_DUR, duration);
2566 comres = smi130_acc_smbus_write_byte(client,
2567 SMI130_ACC_SLO_NO_MOT_DUR__REG, &data);
2568
2569
2570 return comres;
2571}
2572
2573static int smi130_acc_get_slope_no_mot_duration(struct i2c_client *client,
2574 unsigned char *status)
2575{
2576 int comres = 0;
2577 unsigned char data = 0;
2578
2579
2580 comres = smi130_acc_smbus_read_byte(client,
2581 SMI130_ACC_SLO_NO_MOT_DUR__REG, &data);
2582 data = SMI_ACC2X2_GET_BITSLICE(data, SMI130_ACC_SLO_NO_MOT_DUR);
2583 *status = data;
2584
2585
2586 return comres;
2587}
2588
2589static int smi130_acc_set_slope_threshold(struct i2c_client *client,
2590 unsigned char threshold)
2591{
2592 int comres = 0;
2593 unsigned char data = 0;
2594
2595 data = threshold;
2596 comres = smi130_acc_smbus_write_byte(client,
2597 SMI_ACC2X2_SLOPE_THRES__REG, &data);
2598
2599 return comres;
2600}
2601
2602static int smi130_acc_get_slope_threshold(struct i2c_client *client,
2603 unsigned char *status)
2604{
2605 int comres = 0;
2606 unsigned char data = 0;
2607
2608
2609 comres = smi130_acc_smbus_read_byte(client,
2610 SMI_ACC2X2_SLOPE_THRES_REG, &data);
2611 *status = data;
2612
2613 return comres;
2614}
2615
2616static int smi130_acc_set_slope_no_mot_threshold(struct i2c_client *client,
2617 unsigned char threshold)
2618{
2619 int comres = 0;
2620 unsigned char data = 0;
2621
2622 data = threshold;
2623 comres = smi130_acc_smbus_write_byte(client,
2624 SMI_ACC2X2_SLO_NO_MOT_THRES_REG, &data);
2625
2626 return comres;
2627}
2628
2629static int smi130_acc_get_slope_no_mot_threshold(struct i2c_client *client,
2630 unsigned char *status)
2631{
2632 int comres = 0;
2633 unsigned char data = 0;
2634
2635
2636 comres = smi130_acc_smbus_read_byte(client,
2637 SMI_ACC2X2_SLO_NO_MOT_THRES_REG, &data);
2638 *status = data;
2639
2640 return comres;
2641}
2642
2643
2644static int smi130_acc_set_low_g_duration(struct i2c_client *client, unsigned char
2645 duration)
2646{
2647 int comres = 0;
2648 unsigned char data = 0;
2649
2650 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_LOWG_DUR__REG, &data);
2651 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_LOWG_DUR, duration);
2652 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_LOWG_DUR__REG, &data);
2653
2654 return comres;
2655}
2656
2657static int smi130_acc_get_low_g_duration(struct i2c_client *client, unsigned char
2658 *status)
2659{
2660 int comres = 0;
2661 unsigned char data = 0;
2662
2663 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_LOW_DURN_REG, &data);
2664 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_LOWG_DUR);
2665 *status = data;
2666
2667 return comres;
2668}
2669
2670static int smi130_acc_set_low_g_threshold(struct i2c_client *client, unsigned char
2671 threshold)
2672{
2673 int comres = 0;
2674 unsigned char data = 0;
2675
2676 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_LOWG_THRES__REG, &data);
2677 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_LOWG_THRES, threshold);
2678 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_LOWG_THRES__REG, &data);
2679
2680 return comres;
2681}
2682
2683static int smi130_acc_get_low_g_threshold(struct i2c_client *client, unsigned char
2684 *status)
2685{
2686 int comres = 0;
2687 unsigned char data = 0;
2688
2689 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_LOW_THRES_REG, &data);
2690 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_LOWG_THRES);
2691 *status = data;
2692
2693 return comres;
2694}
2695
2696static int smi130_acc_set_high_g_duration(struct i2c_client *client, unsigned char
2697 duration)
2698{
2699 int comres = 0;
2700 unsigned char data = 0;
2701
2702 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_HIGHG_DUR__REG, &data);
2703 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_HIGHG_DUR, duration);
2704 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_HIGHG_DUR__REG, &data);
2705
2706 return comres;
2707}
2708
2709static int smi130_acc_get_high_g_duration(struct i2c_client *client, unsigned char
2710 *status)
2711{
2712 int comres = 0;
2713 unsigned char data = 0;
2714
2715 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_HIGH_DURN_REG, &data);
2716 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_DUR);
2717 *status = data;
2718
2719 return comres;
2720}
2721
2722static int smi130_acc_set_high_g_threshold(struct i2c_client *client, unsigned char
2723 threshold)
2724{
2725 int comres = 0;
2726 unsigned char data = 0;
2727
2728 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_HIGHG_THRES__REG, &data);
2729 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_HIGHG_THRES, threshold);
2730 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_HIGHG_THRES__REG,
2731 &data);
2732
2733 return comres;
2734}
2735
2736static int smi130_acc_get_high_g_threshold(struct i2c_client *client, unsigned char
2737 *status)
2738{
2739 int comres = 0;
2740 unsigned char data = 0;
2741
2742 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_HIGH_THRES_REG, &data);
2743 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_HIGHG_THRES);
2744 *status = data;
2745
2746 return comres;
2747}
2748
2749
2750static int smi130_acc_set_tap_duration(struct i2c_client *client, unsigned char
2751 duration)
2752{
2753 int comres = 0;
2754 unsigned char data = 0;
2755
2756 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_DUR__REG, &data);
2757 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_TAP_DUR, duration);
2758 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_TAP_DUR__REG, &data);
2759
2760 return comres;
2761}
2762
2763static int smi130_acc_get_tap_duration(struct i2c_client *client, unsigned char
2764 *status)
2765{
2766 int comres = 0;
2767 unsigned char data = 0;
2768
2769 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_PARAM_REG, &data);
2770 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_TAP_DUR);
2771 *status = data;
2772
2773 return comres;
2774}
2775
2776static int smi130_acc_set_tap_shock(struct i2c_client *client, unsigned char setval)
2777{
2778 int comres = 0;
2779 unsigned char data = 0;
2780
2781 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_SHOCK_DURN__REG,
2782 &data);
2783 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_TAP_SHOCK_DURN, setval);
2784 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_TAP_SHOCK_DURN__REG,
2785 &data);
2786
2787 return comres;
2788}
2789
2790static int smi130_acc_get_tap_shock(struct i2c_client *client, unsigned char
2791 *status)
2792{
2793 int comres = 0;
2794 unsigned char data = 0;
2795
2796 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_PARAM_REG, &data);
2797 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_TAP_SHOCK_DURN);
2798 *status = data;
2799
2800 return comres;
2801}
2802
2803static int smi130_acc_set_tap_quiet(struct i2c_client *client, unsigned char
2804 duration)
2805{
2806 int comres = 0;
2807 unsigned char data = 0;
2808
2809 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_QUIET_DURN__REG,
2810 &data);
2811 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_TAP_QUIET_DURN, duration);
2812 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_TAP_QUIET_DURN__REG,
2813 &data);
2814
2815 return comres;
2816}
2817
2818static int smi130_acc_get_tap_quiet(struct i2c_client *client, unsigned char
2819 *status)
2820{
2821 int comres = 0;
2822 unsigned char data = 0;
2823
2824 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_PARAM_REG, &data);
2825 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_TAP_QUIET_DURN);
2826 *status = data;
2827
2828 return comres;
2829}
2830
2831static int smi130_acc_set_tap_threshold(struct i2c_client *client, unsigned char
2832 threshold)
2833{
2834 int comres = 0;
2835 unsigned char data = 0;
2836
2837 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_THRES__REG, &data);
2838 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_TAP_THRES, threshold);
2839 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_TAP_THRES__REG, &data);
2840
2841 return comres;
2842}
2843
2844static int smi130_acc_get_tap_threshold(struct i2c_client *client, unsigned char
2845 *status)
2846{
2847 int comres = 0;
2848 unsigned char data = 0;
2849
2850 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_THRES_REG, &data);
2851 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_TAP_THRES);
2852 *status = data;
2853
2854 return comres;
2855}
2856
2857static int smi130_acc_set_tap_samp(struct i2c_client *client, unsigned char samp)
2858{
2859 int comres = 0;
2860 unsigned char data = 0;
2861
2862 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_SAMPLES__REG, &data);
2863 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_TAP_SAMPLES, samp);
2864 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_TAP_SAMPLES__REG,
2865 &data);
2866
2867 return comres;
2868}
2869
2870static int smi130_acc_get_tap_samp(struct i2c_client *client, unsigned char *status)
2871{
2872 int comres = 0;
2873 unsigned char data = 0;
2874
2875 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TAP_THRES_REG, &data);
2876 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_TAP_SAMPLES);
2877 *status = data;
2878
2879 return comres;
2880}
2881
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002882static int smi130_acc_set_orient_mbl_mode(struct i2c_client *client, unsigned char mode)
Bosch Sensortecface5922018-08-29 08:08:53 +02002883{
2884 int comres = 0;
2885 unsigned char data = 0;
2886
2887 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_MODE__REG, &data);
2888 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_ORIENT_MODE, mode);
2889 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_ORIENT_MODE__REG,
2890 &data);
2891
2892 return comres;
2893}
2894
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002895static int smi130_acc_get_orient_mbl_mode(struct i2c_client *client, unsigned char
Bosch Sensortecface5922018-08-29 08:08:53 +02002896 *status)
2897{
2898 int comres = 0;
2899 unsigned char data = 0;
2900
2901 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_PARAM_REG, &data);
2902 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_ORIENT_MODE);
2903 *status = data;
2904
2905 return comres;
2906}
2907
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002908static int smi130_acc_set_orient_mbl_blocking(struct i2c_client *client, unsigned char
Bosch Sensortecface5922018-08-29 08:08:53 +02002909 samp)
2910{
2911 int comres = 0;
2912 unsigned char data = 0;
2913
2914 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_BLOCK__REG,
2915 &data);
2916 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_ORIENT_BLOCK, samp);
2917 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_ORIENT_BLOCK__REG,
2918 &data);
2919
2920 return comres;
2921}
2922
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002923static int smi130_acc_get_orient_mbl_blocking(struct i2c_client *client, unsigned char
Bosch Sensortecface5922018-08-29 08:08:53 +02002924 *status)
2925{
2926 int comres = 0;
2927 unsigned char data = 0;
2928
2929 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_PARAM_REG, &data);
2930 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_ORIENT_BLOCK);
2931 *status = data;
2932
2933 return comres;
2934}
2935
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002936static int smi130_acc_set_orient_mbl_hyst(struct i2c_client *client, unsigned char
2937 orient_mblhyst)
Bosch Sensortecface5922018-08-29 08:08:53 +02002938{
2939 int comres = 0;
2940 unsigned char data = 0;
2941
2942 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_HYST__REG, &data);
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002943 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_ORIENT_HYST, orient_mblhyst);
Bosch Sensortecface5922018-08-29 08:08:53 +02002944 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_ORIENT_HYST__REG,
2945 &data);
2946
2947 return comres;
2948}
2949
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02002950static int smi130_acc_get_orient_mbl_hyst(struct i2c_client *client, unsigned char
Bosch Sensortecface5922018-08-29 08:08:53 +02002951 *status)
2952{
2953 int comres = 0;
2954 unsigned char data = 0;
2955
2956 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_ORIENT_PARAM_REG, &data);
2957 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_ORIENT_HYST);
2958 *status = data;
2959
2960 return comres;
2961}
2962static int smi130_acc_set_theta_blocking(struct i2c_client *client, unsigned char
2963 thetablk)
2964{
2965 int comres = 0;
2966 unsigned char data = 0;
2967
2968 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_THETA_BLOCK__REG, &data);
2969 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_THETA_BLOCK, thetablk);
2970 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_THETA_BLOCK__REG,
2971 &data);
2972
2973 return comres;
2974}
2975
2976static int smi130_acc_get_theta_blocking(struct i2c_client *client, unsigned char
2977 *status)
2978{
2979 int comres = 0;
2980 unsigned char data = 0;
2981
2982 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_THETA_BLOCK_REG, &data);
2983 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_THETA_BLOCK);
2984 *status = data;
2985
2986 return comres;
2987}
2988
2989static int smi130_acc_set_theta_flat(struct i2c_client *client, unsigned char
2990 thetaflat)
2991{
2992 int comres = 0;
2993 unsigned char data = 0;
2994
2995 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_THETA_FLAT__REG, &data);
2996 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_THETA_FLAT, thetaflat);
2997 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_THETA_FLAT__REG, &data);
2998
2999 return comres;
3000}
3001
3002static int smi130_acc_get_theta_flat(struct i2c_client *client, unsigned char
3003 *status)
3004{
3005 int comres = 0;
3006 unsigned char data = 0;
3007
3008 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_THETA_FLAT_REG, &data);
3009 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_THETA_FLAT);
3010 *status = data;
3011
3012 return comres;
3013}
3014
3015static int smi130_acc_set_flat_hold_time(struct i2c_client *client, unsigned char
3016 holdtime)
3017{
3018 int comres = 0;
3019 unsigned char data = 0;
3020
3021 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_FLAT_HOLD_TIME__REG,
3022 &data);
3023 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_FLAT_HOLD_TIME, holdtime);
3024 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_FLAT_HOLD_TIME__REG,
3025 &data);
3026
3027 return comres;
3028}
3029
3030static int smi130_acc_get_flat_hold_time(struct i2c_client *client, unsigned char
3031 *holdtime)
3032{
3033 int comres = 0;
3034 unsigned char data = 0;
3035
3036 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_FLAT_HOLD_TIME_REG,
3037 &data);
3038 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FLAT_HOLD_TIME);
3039 *holdtime = data;
3040
3041 return comres;
3042}
3043
3044/*!
3045 * brief: smi130_acc switch from normal to suspend mode
3046 * @param[i] smi130_acc
3047 * @param[i] data1, write to PMU_LPW
3048 * @param[i] data2, write to PMU_LOW_NOSIE
3049 *
3050 * @return zero success, none-zero failed
3051 */
3052static int smi130_acc_normal_to_suspend(struct smi130_acc_data *smi130_acc,
3053 unsigned char data1, unsigned char data2)
3054{
3055 unsigned char current_fifo_mode;
3056 unsigned char current_op_mode;
3057 if (smi130_acc == NULL)
3058 return -ENODEV;
3059 /* get current op mode from mode register */
3060 if (smi130_acc_get_mode(smi130_acc->smi130_acc_client, &current_op_mode) < 0)
3061 return -EIO;
3062 /* only aimed at operatiom mode chang from normal/lpw1 mode
3063 * to suspend state.
3064 */
3065 if (current_op_mode == SMI_ACC2X2_MODE_NORMAL ||
3066 current_op_mode == SMI_ACC2X2_MODE_LOWPOWER1) {
3067 /* get current fifo mode from fifo config register */
3068 if (smi130_acc_get_fifo_mode(smi130_acc->smi130_acc_client,
3069 &current_fifo_mode) < 0)
3070 return -EIO;
3071 else {
3072 smi130_acc_smbus_write_byte(smi130_acc->smi130_acc_client,
3073 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3074 smi130_acc_smbus_write_byte(smi130_acc->smi130_acc_client,
3075 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3076 /*! Aim at fifo workarounds with FIFO_CONFIG_1 */
3077 current_fifo_mode |= FIFO_WORKAROUNDS_MSK;
3078 smi130_acc_smbus_write_byte(smi130_acc->smi130_acc_client,
3079 SMI_ACC2X2_FIFO_MODE__REG, &current_fifo_mode);
3080 smi130_acc_delay(3);
3081 return 0;
3082 }
3083 } else {
3084 smi130_acc_smbus_write_byte(smi130_acc->smi130_acc_client,
3085 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3086 smi130_acc_smbus_write_byte(smi130_acc->smi130_acc_client,
3087 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3088 smi130_acc_delay(3);
3089 return 0;
3090 }
3091
3092}
3093
3094static int smi130_acc_set_mode(struct i2c_client *client, unsigned char mode,
3095 unsigned char enabled_mode)
3096{
3097 int comres = 0;
3098 unsigned char data1 = 0;
3099 unsigned char data2 = 0;
3100 int ret = 0;
3101 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
3102
3103 mutex_lock(&smi130_acc->mode_mutex);
3104 if (SMI_ACC2X2_MODE_SUSPEND == mode) {
3105 if (enabled_mode != SMI_ACC_ENABLED_ALL) {
3106 if ((smi130_acc->smi_acc_mode_enabled &
3107 (1<<enabled_mode)) == 0) {
3108 /* sensor is already closed in this mode */
3109 mutex_unlock(&smi130_acc->mode_mutex);
3110 return 0;
3111 } else {
3112 smi130_acc->smi_acc_mode_enabled &= ~(1<<enabled_mode);
3113 }
3114 } else {
3115 /* shut down, close all and force do it*/
3116 smi130_acc->smi_acc_mode_enabled = 0;
3117 }
3118 } else if (SMI_ACC2X2_MODE_NORMAL == mode) {
3119 if ((smi130_acc->smi_acc_mode_enabled & (1<<enabled_mode)) != 0) {
3120 /* sensor is already enabled in this mode */
3121 mutex_unlock(&smi130_acc->mode_mutex);
3122 return 0;
3123 } else {
3124 smi130_acc->smi_acc_mode_enabled |= (1<<enabled_mode);
3125 }
3126 } else {
3127 /* other mode, close all and force do it*/
3128 smi130_acc->smi_acc_mode_enabled = 0;
3129 }
3130 mutex_unlock(&smi130_acc->mode_mutex);
3131
3132 if (mode < 6) {
3133 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_MODE_CTRL_REG,
3134 &data1);
3135 comres = smi130_acc_smbus_read_byte(client,
3136 SMI_ACC2X2_LOW_NOISE_CTRL_REG,
3137 &data2);
3138 switch (mode) {
3139 case SMI_ACC2X2_MODE_NORMAL:
3140 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3141 SMI_ACC2X2_MODE_CTRL, 0);
3142 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3143 SMI_ACC2X2_LOW_POWER_MODE, 0);
3144 smi130_acc_smbus_write_byte(client,
3145 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3146 smi130_acc_delay(3);
3147 smi130_acc_smbus_write_byte(client,
3148 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3149 break;
3150 case SMI_ACC2X2_MODE_LOWPOWER1:
3151 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3152 SMI_ACC2X2_MODE_CTRL, 2);
3153 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3154 SMI_ACC2X2_LOW_POWER_MODE, 0);
3155 smi130_acc_smbus_write_byte(client,
3156 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3157 smi130_acc_delay(3);
3158 smi130_acc_smbus_write_byte(client,
3159 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3160 break;
3161 case SMI_ACC2X2_MODE_SUSPEND:
3162 if (smi130_acc->smi_acc_mode_enabled != 0) {
3163 PERR("smi_acc still working");
3164 return 0;
3165 }
3166 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3167 SMI_ACC2X2_MODE_CTRL, 4);
3168 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3169 SMI_ACC2X2_LOW_POWER_MODE, 0);
3170 /*aimed at anomaly resolution when switch to suspend*/
3171 ret = smi130_acc_normal_to_suspend(smi130_acc, data1, data2);
3172 if (ret < 0)
3173 PERR("Error switching to suspend");
3174 break;
3175 case SMI_ACC2X2_MODE_DEEP_SUSPEND:
3176 if (smi130_acc->smi_acc_mode_enabled != 0) {
3177 PERR("smi_acc still working");
3178 return 0;
3179 }
3180 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3181 SMI_ACC2X2_MODE_CTRL, 1);
3182 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3183 SMI_ACC2X2_LOW_POWER_MODE, 1);
3184 smi130_acc_smbus_write_byte(client,
3185 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3186 smi130_acc_delay(3);
3187 smi130_acc_smbus_write_byte(client,
3188 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3189 break;
3190 case SMI_ACC2X2_MODE_LOWPOWER2:
3191 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3192 SMI_ACC2X2_MODE_CTRL, 2);
3193 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3194 SMI_ACC2X2_LOW_POWER_MODE, 1);
3195 smi130_acc_smbus_write_byte(client,
3196 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3197 smi130_acc_delay(3);
3198 smi130_acc_smbus_write_byte(client,
3199 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3200 break;
3201 case SMI_ACC2X2_MODE_STANDBY:
3202 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3203 SMI_ACC2X2_MODE_CTRL, 4);
3204 data2 = SMI_ACC2X2_SET_BITSLICE(data2,
3205 SMI_ACC2X2_LOW_POWER_MODE, 1);
3206 smi130_acc_smbus_write_byte(client,
3207 SMI_ACC2X2_LOW_NOISE_CTRL_REG, &data2);
3208 smi130_acc_delay(3);
3209 smi130_acc_smbus_write_byte(client,
3210 SMI_ACC2X2_MODE_CTRL_REG, &data1);
3211 break;
3212 }
3213 } else {
3214 comres = -1;
3215 }
3216
3217 return comres;
3218}
3219
3220
3221static int smi130_acc_get_mode(struct i2c_client *client, unsigned char *mode)
3222{
3223 int comres = 0;
3224 unsigned char data1 = 0;
3225 unsigned char data2 = 0;
3226
3227 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_MODE_CTRL_REG, &data1);
3228 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_LOW_NOISE_CTRL_REG,
3229 &data2);
3230
3231 data1 = (data1 & 0xE0) >> 5;
3232 data2 = (data2 & 0x40) >> 6;
3233
3234
3235 if ((data1 == 0x00) && (data2 == 0x00)) {
3236 *mode = SMI_ACC2X2_MODE_NORMAL;
3237 } else {
3238 if ((data1 == 0x02) && (data2 == 0x00)) {
3239 *mode = SMI_ACC2X2_MODE_LOWPOWER1;
3240 } else {
3241 if ((data1 == 0x04 || data1 == 0x06) &&
3242 (data2 == 0x00)) {
3243 *mode = SMI_ACC2X2_MODE_SUSPEND;
3244 } else {
3245 if (((data1 & 0x01) == 0x01)) {
3246 *mode = SMI_ACC2X2_MODE_DEEP_SUSPEND;
3247 } else {
3248 if ((data1 == 0x02) &&
3249 (data2 == 0x01)) {
3250 *mode = SMI_ACC2X2_MODE_LOWPOWER2;
3251 } else {
3252 if ((data1 == 0x04) && (data2 ==
3253 0x01)) {
3254 *mode =
3255 SMI_ACC2X2_MODE_STANDBY;
3256 } else {
3257 *mode =
3258 SMI_ACC2X2_MODE_DEEP_SUSPEND;
3259 }
3260 }
3261 }
3262 }
3263 }
3264 }
3265
3266 return comres;
3267}
3268
3269static int smi130_acc_set_range(struct i2c_client *client, unsigned char Range)
3270{
3271 int comres = 0;
3272 unsigned char data1 = 0;
3273
3274 if ((Range == 3) || (Range == 5) || (Range == 8) || (Range == 12)) {
3275 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_RANGE_SEL_REG,
3276 &data1);
3277 switch (Range) {
3278 case SMI_ACC2X2_RANGE_2G:
3279 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3280 SMI_ACC2X2_RANGE_SEL, 3);
3281 break;
3282 case SMI_ACC2X2_RANGE_4G:
3283 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3284 SMI_ACC2X2_RANGE_SEL, 5);
3285 break;
3286 case SMI_ACC2X2_RANGE_8G:
3287 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3288 SMI_ACC2X2_RANGE_SEL, 8);
3289 break;
3290 case SMI_ACC2X2_RANGE_16G:
3291 data1 = SMI_ACC2X2_SET_BITSLICE(data1,
3292 SMI_ACC2X2_RANGE_SEL, 12);
3293 break;
3294 default:
3295 break;
3296 }
3297 comres += smi130_acc_smbus_write_byte(client, SMI_ACC2X2_RANGE_SEL_REG,
3298 &data1);
3299 } else {
3300 comres = -1;
3301 }
3302
3303 return comres;
3304}
3305
3306static int smi130_acc_get_range(struct i2c_client *client, unsigned char *Range)
3307{
3308 int comres = 0;
3309 unsigned char data = 0;
3310
3311 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_RANGE_SEL__REG, &data);
3312 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_RANGE_SEL);
3313 *Range = data;
3314
3315 return comres;
3316}
3317
3318
3319static int smi130_acc_set_bandwidth(struct i2c_client *client, unsigned char BW)
3320{
3321 int comres = 0;
3322 unsigned char data = 0;
3323 int Bandwidth = 0;
3324 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
3325
3326 if (BW > 7 && BW < 16) {
3327 switch (BW) {
3328 case SMI_ACC2X2_BW_7_81HZ:
3329 Bandwidth = SMI_ACC2X2_BW_7_81HZ;
3330 smi130_acc->time_odr = 64000000;
3331
3332 /* 7.81 Hz 64000 uS */
3333 break;
3334 case SMI_ACC2X2_BW_15_63HZ:
3335 Bandwidth = SMI_ACC2X2_BW_15_63HZ;
3336 smi130_acc->time_odr = 32000000;
3337 /* 15.63 Hz 32000 uS */
3338 break;
3339 case SMI_ACC2X2_BW_31_25HZ:
3340 Bandwidth = SMI_ACC2X2_BW_31_25HZ;
3341 smi130_acc->time_odr = 16000000;
3342 /* 31.25 Hz 16000 uS */
3343 break;
3344 case SMI_ACC2X2_BW_62_50HZ:
3345 Bandwidth = SMI_ACC2X2_BW_62_50HZ;
3346 smi130_acc->time_odr = 8000000;
3347 /* 62.50 Hz 8000 uS */
3348 break;
3349 case SMI_ACC2X2_BW_125HZ:
3350 Bandwidth = SMI_ACC2X2_BW_125HZ;
3351 smi130_acc->time_odr = 4000000;
3352 /* 125 Hz 4000 uS */
3353 break;
3354 case SMI_ACC2X2_BW_250HZ:
3355 Bandwidth = SMI_ACC2X2_BW_250HZ;
3356 smi130_acc->time_odr = 2000000;
3357 /* 250 Hz 2000 uS */
3358 break;
3359 case SMI_ACC2X2_BW_500HZ:
3360 Bandwidth = SMI_ACC2X2_BW_500HZ;
3361 smi130_acc->time_odr = 1000000;
3362 /* 500 Hz 1000 uS */
3363 break;
3364 case SMI_ACC2X2_BW_1000HZ:
3365 Bandwidth = SMI_ACC2X2_BW_1000HZ;
3366 smi130_acc->time_odr = 500000;
3367 /* 1000 Hz 500 uS */
3368 break;
3369 default:
3370 break;
3371 }
3372 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_BANDWIDTH__REG,
3373 &data);
3374 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_BANDWIDTH, Bandwidth);
3375 comres += smi130_acc_smbus_write_byte(client, SMI_ACC2X2_BANDWIDTH__REG,
3376 &data);
3377 } else {
3378 comres = -1;
3379 }
3380
3381 return comres;
3382}
3383
3384static int smi130_acc_get_bandwidth(struct i2c_client *client, unsigned char *BW)
3385{
3386 int comres = 0;
3387 unsigned char data = 0;
3388
3389 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_BANDWIDTH__REG, &data);
3390 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_BANDWIDTH);
3391 *BW = data;
3392
3393 return comres;
3394}
3395
3396int smi130_acc_get_sleep_duration(struct i2c_client *client, unsigned char
3397 *sleep_dur)
3398{
3399 int comres = 0;
3400 unsigned char data = 0;
3401
3402 comres = smi130_acc_smbus_read_byte(client,
3403 SMI_ACC2X2_SLEEP_DUR__REG, &data);
3404 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_SLEEP_DUR);
3405 *sleep_dur = data;
3406
3407 return comres;
3408}
3409
3410int smi130_acc_set_sleep_duration(struct i2c_client *client, unsigned char
3411 sleep_dur)
3412{
3413 int comres = 0;
3414 unsigned char data = 0;
3415 int sleep_duration = 0;
3416
3417 if (sleep_dur > 4 && sleep_dur < 16) {
3418 switch (sleep_dur) {
3419 case SMI_ACC2X2_SLEEP_DUR_0_5MS:
3420 sleep_duration = SMI_ACC2X2_SLEEP_DUR_0_5MS;
3421
3422 /* 0.5 MS */
3423 break;
3424 case SMI_ACC2X2_SLEEP_DUR_1MS:
3425 sleep_duration = SMI_ACC2X2_SLEEP_DUR_1MS;
3426
3427 /* 1 MS */
3428 break;
3429 case SMI_ACC2X2_SLEEP_DUR_2MS:
3430 sleep_duration = SMI_ACC2X2_SLEEP_DUR_2MS;
3431
3432 /* 2 MS */
3433 break;
3434 case SMI_ACC2X2_SLEEP_DUR_4MS:
3435 sleep_duration = SMI_ACC2X2_SLEEP_DUR_4MS;
3436
3437 /* 4 MS */
3438 break;
3439 case SMI_ACC2X2_SLEEP_DUR_6MS:
3440 sleep_duration = SMI_ACC2X2_SLEEP_DUR_6MS;
3441
3442 /* 6 MS */
3443 break;
3444 case SMI_ACC2X2_SLEEP_DUR_10MS:
3445 sleep_duration = SMI_ACC2X2_SLEEP_DUR_10MS;
3446
3447 /* 10 MS */
3448 break;
3449 case SMI_ACC2X2_SLEEP_DUR_25MS:
3450 sleep_duration = SMI_ACC2X2_SLEEP_DUR_25MS;
3451
3452 /* 25 MS */
3453 break;
3454 case SMI_ACC2X2_SLEEP_DUR_50MS:
3455 sleep_duration = SMI_ACC2X2_SLEEP_DUR_50MS;
3456
3457 /* 50 MS */
3458 break;
3459 case SMI_ACC2X2_SLEEP_DUR_100MS:
3460 sleep_duration = SMI_ACC2X2_SLEEP_DUR_100MS;
3461
3462 /* 100 MS */
3463 break;
3464 case SMI_ACC2X2_SLEEP_DUR_500MS:
3465 sleep_duration = SMI_ACC2X2_SLEEP_DUR_500MS;
3466
3467 /* 500 MS */
3468 break;
3469 case SMI_ACC2X2_SLEEP_DUR_1S:
3470 sleep_duration = SMI_ACC2X2_SLEEP_DUR_1S;
3471
3472 /* 1 SECS */
3473 break;
3474 default:
3475 break;
3476 }
3477 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_SLEEP_DUR__REG,
3478 &data);
3479 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_SLEEP_DUR,
3480 sleep_duration);
3481 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_SLEEP_DUR__REG,
3482 &data);
3483 } else {
3484 comres = -1;
3485 }
3486
3487
3488 return comres;
3489}
3490
3491static int smi130_acc_get_fifo_mode(struct i2c_client *client, unsigned char
3492 *fifo_mode)
3493{
3494 int comres;
3495 unsigned char data = 0;
3496
3497 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_FIFO_MODE__REG, &data);
3498 *fifo_mode = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FIFO_MODE);
3499
3500 return comres;
3501}
3502
3503static int smi130_acc_set_fifo_mode(struct i2c_client *client, unsigned char
3504 fifo_mode)
3505{
3506 unsigned char data = 0;
3507 int comres = 0;
3508
3509 if (fifo_mode < 4) {
3510 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_FIFO_MODE__REG,
3511 &data);
3512 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_FIFO_MODE, fifo_mode);
3513 /*! Aim at fifo workarounds with FIFO_CONFIG_1 */
3514 data |= FIFO_WORKAROUNDS_MSK;
3515 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_FIFO_MODE__REG,
3516 &data);
3517 } else {
3518 comres = -1;
3519 }
3520
3521 return comres;
3522}
3523
3524static int smi130_acc_get_fifo_trig(struct i2c_client *client, unsigned char
3525 *fifo_trig)
3526{
3527 int comres;
3528 unsigned char data = 0;
3529
3530 comres = smi130_acc_smbus_read_byte(client,
3531 SMI_ACC2X2_FIFO_TRIGGER_ACTION__REG, &data);
3532 *fifo_trig = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FIFO_TRIGGER_ACTION);
3533
3534 return comres;
3535}
3536
3537static int smi130_acc_set_fifo_trig(struct i2c_client *client, unsigned char
3538 fifo_trig)
3539{
3540 unsigned char data = 0;
3541 int comres = 0;
3542
3543 if (fifo_trig < 4) {
3544 comres = smi130_acc_smbus_read_byte(client,
3545 SMI_ACC2X2_FIFO_TRIGGER_ACTION__REG, &data);
3546 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_FIFO_TRIGGER_ACTION,
3547 fifo_trig);
3548 /*! Aim at fifo workarounds with FIFO_CONFIG_1 */
3549 data |= FIFO_WORKAROUNDS_MSK;
3550 comres = smi130_acc_smbus_write_byte(client,
3551 SMI_ACC2X2_FIFO_TRIGGER_ACTION__REG, &data);
3552 } else {
3553 comres = -1;
3554 }
3555
3556 return comres;
3557}
3558
3559static int smi130_acc_get_fifo_trig_src(struct i2c_client *client, unsigned char
3560 *trig_src)
3561{
3562 int comres;
3563 unsigned char data = 0;
3564
3565 comres = smi130_acc_smbus_read_byte(client,
3566 SMI_ACC2X2_FIFO_TRIGGER_SOURCE__REG, &data);
3567 *trig_src = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FIFO_TRIGGER_SOURCE);
3568
3569 return comres;
3570}
3571
3572static int smi130_acc_set_fifo_trig_src(struct i2c_client *client, unsigned char
3573 trig_src)
3574{
3575 unsigned char data = 0;
3576 int comres = 0;
3577
3578 if (trig_src < 4) {
3579 comres = smi130_acc_smbus_read_byte(client,
3580 SMI_ACC2X2_FIFO_TRIGGER_SOURCE__REG, &data);
3581 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_FIFO_TRIGGER_SOURCE,
3582 trig_src);
3583 comres = smi130_acc_smbus_write_byte(client,
3584 SMI_ACC2X2_FIFO_TRIGGER_SOURCE__REG, &data);
3585 } else {
3586 comres = -1;
3587 }
3588
3589 return comres;
3590}
3591
3592static int smi130_acc_get_fifo_framecount(struct i2c_client *client, unsigned char
3593 *framecount)
3594{
3595 int comres = 0;
3596 unsigned char data = 0;
3597
3598 comres = smi130_acc_smbus_read_byte(client,
3599 SMI_ACC2X2_FIFO_FRAME_COUNTER_S__REG, &data);
3600 *framecount = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FIFO_FRAME_COUNTER_S);
3601
3602 return comres;
3603}
3604
3605static int smi130_acc_get_fifo_data_sel(struct i2c_client *client, unsigned char
3606 *data_sel)
3607{
3608 int comres;
3609 unsigned char data = 0;
3610
3611 comres = smi130_acc_smbus_read_byte(client,
3612 SMI_ACC2X2_FIFO_DATA_SELECT__REG, &data);
3613 *data_sel = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FIFO_DATA_SELECT);
3614
3615 return comres;
3616}
3617
3618static int smi130_acc_set_fifo_data_sel(struct i2c_client *client, unsigned char
3619 data_sel)
3620{
3621 unsigned char data = 0;
3622 int comres = 0;
3623
3624 if (data_sel < 4) {
3625 comres = smi130_acc_smbus_read_byte(client,
3626 SMI_ACC2X2_FIFO_DATA_SELECT__REG,
3627 &data);
3628 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_FIFO_DATA_SELECT,
3629 data_sel);
3630 /*! Aim at fifo workarounds with FIFO_CONFIG_1 */
3631 data |= FIFO_WORKAROUNDS_MSK;
3632 comres = smi130_acc_smbus_write_byte(client,
3633 SMI_ACC2X2_FIFO_DATA_SELECT__REG,
3634 &data);
3635 } else {
3636 comres = -1;
3637 }
3638
3639 return comres;
3640}
3641
3642
3643static int smi130_acc_get_offset_target(struct i2c_client *client, unsigned char
3644 channel, unsigned char *offset)
3645{
3646 unsigned char data = 0;
3647 int comres = 0;
3648
3649 switch (channel) {
3650 case SMI_ACC2X2_CUT_OFF:
3651 comres = smi130_acc_smbus_read_byte(client,
3652 SMI_ACC2X2_COMP_CUTOFF__REG, &data);
3653 *offset = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_COMP_CUTOFF);
3654 break;
3655 case SMI_ACC2X2_OFFSET_TRIGGER_X:
3656 comres = smi130_acc_smbus_read_byte(client,
3657 SMI_ACC2X2_COMP_TARGET_OFFSET_X__REG, &data);
3658 *offset = SMI_ACC2X2_GET_BITSLICE(data,
3659 SMI_ACC2X2_COMP_TARGET_OFFSET_X);
3660 break;
3661 case SMI_ACC2X2_OFFSET_TRIGGER_Y:
3662 comres = smi130_acc_smbus_read_byte(client,
3663 SMI_ACC2X2_COMP_TARGET_OFFSET_Y__REG, &data);
3664 *offset = SMI_ACC2X2_GET_BITSLICE(data,
3665 SMI_ACC2X2_COMP_TARGET_OFFSET_Y);
3666 break;
3667 case SMI_ACC2X2_OFFSET_TRIGGER_Z:
3668 comres = smi130_acc_smbus_read_byte(client,
3669 SMI_ACC2X2_COMP_TARGET_OFFSET_Z__REG, &data);
3670 *offset = SMI_ACC2X2_GET_BITSLICE(data,
3671 SMI_ACC2X2_COMP_TARGET_OFFSET_Z);
3672 break;
3673 default:
3674 comres = -1;
3675 break;
3676 }
3677
3678 return comres;
3679}
3680
3681static int smi130_acc_set_offset_target(struct i2c_client *client, unsigned char
3682 channel, unsigned char offset)
3683{
3684 unsigned char data = 0;
3685 int comres = 0;
3686
3687 switch (channel) {
3688 case SMI_ACC2X2_CUT_OFF:
3689 comres = smi130_acc_smbus_read_byte(client,
3690 SMI_ACC2X2_COMP_CUTOFF__REG, &data);
3691 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_COMP_CUTOFF,
3692 offset);
3693 comres = smi130_acc_smbus_write_byte(client,
3694 SMI_ACC2X2_COMP_CUTOFF__REG, &data);
3695 break;
3696 case SMI_ACC2X2_OFFSET_TRIGGER_X:
3697 comres = smi130_acc_smbus_read_byte(client,
3698 SMI_ACC2X2_COMP_TARGET_OFFSET_X__REG,
3699 &data);
3700 data = SMI_ACC2X2_SET_BITSLICE(data,
3701 SMI_ACC2X2_COMP_TARGET_OFFSET_X,
3702 offset);
3703 comres = smi130_acc_smbus_write_byte(client,
3704 SMI_ACC2X2_COMP_TARGET_OFFSET_X__REG,
3705 &data);
3706 break;
3707 case SMI_ACC2X2_OFFSET_TRIGGER_Y:
3708 comres = smi130_acc_smbus_read_byte(client,
3709 SMI_ACC2X2_COMP_TARGET_OFFSET_Y__REG,
3710 &data);
3711 data = SMI_ACC2X2_SET_BITSLICE(data,
3712 SMI_ACC2X2_COMP_TARGET_OFFSET_Y,
3713 offset);
3714 comres = smi130_acc_smbus_write_byte(client,
3715 SMI_ACC2X2_COMP_TARGET_OFFSET_Y__REG,
3716 &data);
3717 break;
3718 case SMI_ACC2X2_OFFSET_TRIGGER_Z:
3719 comres = smi130_acc_smbus_read_byte(client,
3720 SMI_ACC2X2_COMP_TARGET_OFFSET_Z__REG,
3721 &data);
3722 data = SMI_ACC2X2_SET_BITSLICE(data,
3723 SMI_ACC2X2_COMP_TARGET_OFFSET_Z,
3724 offset);
3725 comres = smi130_acc_smbus_write_byte(client,
3726 SMI_ACC2X2_COMP_TARGET_OFFSET_Z__REG,
3727 &data);
3728 break;
3729 default:
3730 comres = -1;
3731 break;
3732 }
3733
3734 return comres;
3735}
3736
3737static int smi130_acc_get_cal_ready(struct i2c_client *client,
3738 unsigned char *calrdy)
3739{
3740 int comres = 0;
3741 unsigned char data = 0;
3742
3743 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_FAST_CAL_RDY_S__REG,
3744 &data);
3745 data = SMI_ACC2X2_GET_BITSLICE(data, SMI_ACC2X2_FAST_CAL_RDY_S);
3746 *calrdy = data;
3747
3748 return comres;
3749}
3750
3751static int smi130_acc_set_cal_trigger(struct i2c_client *client, unsigned char
3752 caltrigger)
3753{
3754 int comres = 0;
3755 unsigned char data = 0;
3756
3757 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_CAL_TRIGGER__REG, &data);
3758 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_CAL_TRIGGER, caltrigger);
3759 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_CAL_TRIGGER__REG,
3760 &data);
3761
3762 return comres;
3763}
3764
3765static int smi130_acc_write_reg(struct i2c_client *client, unsigned char addr,
3766 unsigned char *data)
3767{
3768 int comres = 0;
3769 comres = smi130_acc_smbus_write_byte(client, addr, data);
3770
3771 return comres;
3772}
3773
3774
3775static int smi130_acc_set_offset_x(struct i2c_client *client, unsigned char
3776 offsetfilt)
3777{
3778 int comres = 0;
3779 unsigned char data = 0;
3780
3781 data = offsetfilt;
3782
3783#ifdef CONFIG_SENSORS_BMI058
3784 comres = smi130_acc_smbus_write_byte(client, BMI058_OFFSET_X_AXIS_REG,
3785 &data);
3786#else
3787 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_OFFSET_X_AXIS_REG,
3788 &data);
3789#endif
3790
3791 return comres;
3792}
3793
3794
3795static int smi130_acc_get_offset_x(struct i2c_client *client, unsigned char
3796 *offsetfilt)
3797{
3798 int comres = 0;
3799 unsigned char data = 0;
3800
3801#ifdef CONFIG_SENSORS_BMI058
3802 comres = smi130_acc_smbus_read_byte(client, BMI058_OFFSET_X_AXIS_REG,
3803 &data);
3804#else
3805 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_OFFSET_X_AXIS_REG,
3806 &data);
3807#endif
3808 *offsetfilt = data;
3809
3810 return comres;
3811}
3812
3813static int smi130_acc_set_offset_y(struct i2c_client *client, unsigned char
3814 offsetfilt)
3815{
3816 int comres = 0;
3817 unsigned char data = 0;
3818
3819 data = offsetfilt;
3820
3821#ifdef CONFIG_SENSORS_BMI058
3822 comres = smi130_acc_smbus_write_byte(client, BMI058_OFFSET_Y_AXIS_REG,
3823 &data);
3824#else
3825 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_OFFSET_Y_AXIS_REG,
3826 &data);
3827#endif
3828 return comres;
3829}
3830
3831static int smi130_acc_get_offset_y(struct i2c_client *client, unsigned char
3832 *offsetfilt)
3833{
3834 int comres = 0;
3835 unsigned char data = 0;
3836
3837#ifdef CONFIG_SENSORS_BMI058
3838 comres = smi130_acc_smbus_read_byte(client, BMI058_OFFSET_Y_AXIS_REG,
3839 &data);
3840#else
3841 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_OFFSET_Y_AXIS_REG,
3842 &data);
3843#endif
3844 *offsetfilt = data;
3845
3846 return comres;
3847}
3848
3849static int smi130_acc_set_offset_z(struct i2c_client *client, unsigned char
3850 offsetfilt)
3851{
3852 int comres = 0;
3853 unsigned char data = 0;
3854
3855 data = offsetfilt;
3856 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_OFFSET_Z_AXIS_REG,
3857 &data);
3858
3859 return comres;
3860}
3861
3862static int smi130_acc_get_offset_z(struct i2c_client *client, unsigned char
3863 *offsetfilt)
3864{
3865 int comres = 0;
3866 unsigned char data = 0;
3867
3868 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_OFFSET_Z_AXIS_REG,
3869 &data);
3870 *offsetfilt = data;
3871
3872 return comres;
3873}
3874
3875
3876static int smi130_acc_set_selftest_st(struct i2c_client *client, unsigned char
3877 selftest)
3878{
3879 int comres = 0;
3880 unsigned char data = 0;
3881
3882 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_EN_SELF_TEST__REG,
3883 &data);
3884 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_EN_SELF_TEST, selftest);
3885 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_EN_SELF_TEST__REG,
3886 &data);
3887
3888 return comres;
3889}
3890
3891static int smi130_acc_set_selftest_stn(struct i2c_client *client, unsigned char stn)
3892{
3893 int comres = 0;
3894 unsigned char data = 0;
3895
3896 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_NEG_SELF_TEST__REG,
3897 &data);
3898 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_NEG_SELF_TEST, stn);
3899 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_NEG_SELF_TEST__REG,
3900 &data);
3901
3902 return comres;
3903}
3904
3905static int smi130_acc_set_selftest_amp(struct i2c_client *client, unsigned char amp)
3906{
3907 int comres = 0;
3908 unsigned char data = 0;
3909
3910 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_SELF_TEST_AMP__REG,
3911 &data);
3912 data = SMI_ACC2X2_SET_BITSLICE(data, SMI_ACC2X2_SELF_TEST_AMP, amp);
3913 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_SELF_TEST_AMP__REG,
3914 &data);
3915
3916 return comres;
3917}
3918
3919static int smi130_acc_read_accel_x(struct i2c_client *client,
3920 signed char sensor_type, short *a_x)
3921{
3922 int comres = 0;
puneet597e4f12018-11-06 14:32:16 +05303923 unsigned char data[2] = {0};
Bosch Sensortecface5922018-08-29 08:08:53 +02003924
3925 switch (sensor_type) {
3926 case 0:
3927 comres = smi130_acc_smbus_read_byte_block(client,
3928 SMI_ACC2X2_ACC_X12_LSB__REG, data, 2);
3929 *a_x = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_X12_LSB)|
3930 (SMI_ACC2X2_GET_BITSLICE(data[1],
3931 SMI_ACC2X2_ACC_X_MSB)<<(SMI_ACC2X2_ACC_X12_LSB__LEN));
3932 *a_x = *a_x << (sizeof(short)*8-(SMI_ACC2X2_ACC_X12_LSB__LEN
3933 + SMI_ACC2X2_ACC_X_MSB__LEN));
3934 *a_x = *a_x >> (sizeof(short)*8-(SMI_ACC2X2_ACC_X12_LSB__LEN
3935 + SMI_ACC2X2_ACC_X_MSB__LEN));
3936 break;
3937 case 1:
3938 comres = smi130_acc_smbus_read_byte_block(client,
3939 SMI_ACC2X2_ACC_X10_LSB__REG, data, 2);
3940 *a_x = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_X10_LSB)|
3941 (SMI_ACC2X2_GET_BITSLICE(data[1],
3942 SMI_ACC2X2_ACC_X_MSB)<<(SMI_ACC2X2_ACC_X10_LSB__LEN));
3943 *a_x = *a_x << (sizeof(short)*8-(SMI_ACC2X2_ACC_X10_LSB__LEN
3944 + SMI_ACC2X2_ACC_X_MSB__LEN));
3945 *a_x = *a_x >> (sizeof(short)*8-(SMI_ACC2X2_ACC_X10_LSB__LEN
3946 + SMI_ACC2X2_ACC_X_MSB__LEN));
3947 break;
3948 case 2:
3949 comres = smi130_acc_smbus_read_byte_block(client,
3950 SMI_ACC2X2_ACC_X8_LSB__REG, data, 2);
3951 *a_x = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_X8_LSB)|
3952 (SMI_ACC2X2_GET_BITSLICE(data[1],
3953 SMI_ACC2X2_ACC_X_MSB)<<(SMI_ACC2X2_ACC_X8_LSB__LEN));
3954 *a_x = *a_x << (sizeof(short)*8-(SMI_ACC2X2_ACC_X8_LSB__LEN
3955 + SMI_ACC2X2_ACC_X_MSB__LEN));
3956 *a_x = *a_x >> (sizeof(short)*8-(SMI_ACC2X2_ACC_X8_LSB__LEN
3957 + SMI_ACC2X2_ACC_X_MSB__LEN));
3958 break;
3959 case 3:
3960 comres = smi130_acc_smbus_read_byte_block(client,
3961 SMI_ACC2X2_ACC_X14_LSB__REG, data, 2);
3962 *a_x = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_X14_LSB)|
3963 (SMI_ACC2X2_GET_BITSLICE(data[1],
3964 SMI_ACC2X2_ACC_X_MSB)<<(SMI_ACC2X2_ACC_X14_LSB__LEN));
3965 *a_x = *a_x << (sizeof(short)*8-(SMI_ACC2X2_ACC_X14_LSB__LEN
3966 + SMI_ACC2X2_ACC_X_MSB__LEN));
3967 *a_x = *a_x >> (sizeof(short)*8-(SMI_ACC2X2_ACC_X14_LSB__LEN
3968 + SMI_ACC2X2_ACC_X_MSB__LEN));
3969 break;
3970 default:
3971 break;
3972 }
3973
3974 return comres;
3975}
3976
3977static int smi130_acc_soft_reset(struct i2c_client *client)
3978{
3979 int comres = 0;
3980 unsigned char data = SMI_ACC2X2_EN_SOFT_RESET_VALUE;
3981
3982 comres = smi130_acc_smbus_write_byte(client, SMI_ACC2X2_EN_SOFT_RESET__REG,
3983 &data);
3984
3985 return comres;
3986}
3987
3988static int smi130_acc_read_accel_y(struct i2c_client *client,
3989 signed char sensor_type, short *a_y)
3990{
3991 int comres = 0;
puneet597e4f12018-11-06 14:32:16 +05303992 unsigned char data[2] = {0};
Bosch Sensortecface5922018-08-29 08:08:53 +02003993
3994 switch (sensor_type) {
3995 case 0:
3996 comres = smi130_acc_smbus_read_byte_block(client,
3997 SMI_ACC2X2_ACC_Y12_LSB__REG, data, 2);
3998 *a_y = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Y12_LSB)|
3999 (SMI_ACC2X2_GET_BITSLICE(data[1],
4000 SMI_ACC2X2_ACC_Y_MSB)<<(SMI_ACC2X2_ACC_Y12_LSB__LEN));
4001 *a_y = *a_y << (sizeof(short)*8-(SMI_ACC2X2_ACC_Y12_LSB__LEN
4002 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4003 *a_y = *a_y >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Y12_LSB__LEN
4004 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4005 break;
4006 case 1:
4007 comres = smi130_acc_smbus_read_byte_block(client,
4008 SMI_ACC2X2_ACC_Y10_LSB__REG, data, 2);
4009 *a_y = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Y10_LSB)|
4010 (SMI_ACC2X2_GET_BITSLICE(data[1],
4011 SMI_ACC2X2_ACC_Y_MSB)<<(SMI_ACC2X2_ACC_Y10_LSB__LEN));
4012 *a_y = *a_y << (sizeof(short)*8-(SMI_ACC2X2_ACC_Y10_LSB__LEN
4013 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4014 *a_y = *a_y >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Y10_LSB__LEN
4015 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4016 break;
4017 case 2:
4018 comres = smi130_acc_smbus_read_byte_block(client,
4019 SMI_ACC2X2_ACC_Y8_LSB__REG, data, 2);
4020 *a_y = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Y8_LSB)|
4021 (SMI_ACC2X2_GET_BITSLICE(data[1],
4022 SMI_ACC2X2_ACC_Y_MSB)<<(SMI_ACC2X2_ACC_Y8_LSB__LEN));
4023 *a_y = *a_y << (sizeof(short)*8-(SMI_ACC2X2_ACC_Y8_LSB__LEN
4024 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4025 *a_y = *a_y >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Y8_LSB__LEN
4026 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4027 break;
4028 case 3:
4029 comres = smi130_acc_smbus_read_byte_block(client,
4030 SMI_ACC2X2_ACC_Y14_LSB__REG, data, 2);
4031 *a_y = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Y14_LSB)|
4032 (SMI_ACC2X2_GET_BITSLICE(data[1],
4033 SMI_ACC2X2_ACC_Y_MSB)<<(SMI_ACC2X2_ACC_Y14_LSB__LEN));
4034 *a_y = *a_y << (sizeof(short)*8-(SMI_ACC2X2_ACC_Y14_LSB__LEN
4035 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4036 *a_y = *a_y >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Y14_LSB__LEN
4037 + SMI_ACC2X2_ACC_Y_MSB__LEN));
4038 break;
4039 default:
4040 break;
4041 }
4042
4043 return comres;
4044}
4045
4046static int smi130_acc_read_accel_z(struct i2c_client *client,
4047 signed char sensor_type, short *a_z)
4048{
4049 int comres = 0;
puneet597e4f12018-11-06 14:32:16 +05304050 unsigned char data[2] = {0};
Bosch Sensortecface5922018-08-29 08:08:53 +02004051
4052 switch (sensor_type) {
4053 case 0:
4054 comres = smi130_acc_smbus_read_byte_block(client,
4055 SMI_ACC2X2_ACC_Z12_LSB__REG, data, 2);
4056 *a_z = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Z12_LSB)|
4057 (SMI_ACC2X2_GET_BITSLICE(data[1],
4058 SMI_ACC2X2_ACC_Z_MSB)<<(SMI_ACC2X2_ACC_Z12_LSB__LEN));
4059 *a_z = *a_z << (sizeof(short)*8-(SMI_ACC2X2_ACC_Z12_LSB__LEN
4060 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4061 *a_z = *a_z >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Z12_LSB__LEN
4062 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4063 break;
4064 case 1:
4065 comres = smi130_acc_smbus_read_byte_block(client,
4066 SMI_ACC2X2_ACC_Z10_LSB__REG, data, 2);
4067 *a_z = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Z10_LSB)|
4068 (SMI_ACC2X2_GET_BITSLICE(data[1],
4069 SMI_ACC2X2_ACC_Z_MSB)<<(SMI_ACC2X2_ACC_Z10_LSB__LEN));
4070 *a_z = *a_z << (sizeof(short)*8-(SMI_ACC2X2_ACC_Z10_LSB__LEN
4071 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4072 *a_z = *a_z >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Z10_LSB__LEN
4073 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4074 break;
4075 case 2:
4076 comres = smi130_acc_smbus_read_byte_block(client,
4077 SMI_ACC2X2_ACC_Z8_LSB__REG, data, 2);
4078 *a_z = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Z8_LSB)|
4079 (SMI_ACC2X2_GET_BITSLICE(data[1],
4080 SMI_ACC2X2_ACC_Z_MSB)<<(SMI_ACC2X2_ACC_Z8_LSB__LEN));
4081 *a_z = *a_z << (sizeof(short)*8-(SMI_ACC2X2_ACC_Z8_LSB__LEN
4082 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4083 *a_z = *a_z >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Z8_LSB__LEN
4084 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4085 break;
4086 case 3:
4087 comres = smi130_acc_smbus_read_byte_block(client,
4088 SMI_ACC2X2_ACC_Z14_LSB__REG, data, 2);
4089 *a_z = SMI_ACC2X2_GET_BITSLICE(data[0], SMI_ACC2X2_ACC_Z14_LSB)|
4090 (SMI_ACC2X2_GET_BITSLICE(data[1],
4091 SMI_ACC2X2_ACC_Z_MSB)<<(SMI_ACC2X2_ACC_Z14_LSB__LEN));
4092 *a_z = *a_z << (sizeof(short)*8-(SMI_ACC2X2_ACC_Z14_LSB__LEN
4093 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4094 *a_z = *a_z >> (sizeof(short)*8-(SMI_ACC2X2_ACC_Z14_LSB__LEN
4095 + SMI_ACC2X2_ACC_Z_MSB__LEN));
4096 break;
4097 default:
4098 break;
4099 }
4100
4101 return comres;
4102}
4103
4104
4105static int smi130_acc_read_temperature(struct i2c_client *client,
4106 signed char *temperature)
4107{
4108 unsigned char data = 0;
4109 int comres = 0;
4110
4111 comres = smi130_acc_smbus_read_byte(client, SMI_ACC2X2_TEMPERATURE_REG, &data);
4112 *temperature = (signed char)data;
4113
4114 return comres;
4115}
4116
Puneet Yatnalcfd94842019-04-16 12:11:05 +05304117#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
4118static inline int smi130_check_acc_early_buff_enable_flag(
4119 struct smi130_acc_data *client_data)
4120{
4121 if (client_data->acc_buffer_smi130_samples == true)
4122 return 1;
4123 else
4124 return 0;
4125}
Puneet Yatnalab29efa2019-08-05 13:13:31 +05304126static void smi130_check_acc_enable_flag(struct smi130_acc_data *client_data,
4127 unsigned long data)
4128{
4129 if (data == SMI_ACC2X2_MODE_NORMAL)
4130 client_data->acc_enable = true;
4131 else
4132 client_data->acc_enable = false;
4133}
Puneet Yatnalcfd94842019-04-16 12:11:05 +05304134#else
4135static inline int smi130_check_acc_early_buff_enable_flag(
4136 struct smi130_acc_data *client_data)
4137{
4138 return 0;
4139}
Puneet Yatnalab29efa2019-08-05 13:13:31 +05304140static void smi130_check_acc_enable_flag(struct smi130_acc_data *client_data,
4141 unsigned long data)
4142{
4143
4144}
Puneet Yatnalcfd94842019-04-16 12:11:05 +05304145#endif
4146
Bosch Sensortecface5922018-08-29 08:08:53 +02004147static ssize_t smi130_acc_enable_int_store(struct device *dev,
4148 struct device_attribute *attr,
4149 const char *buf, size_t count)
4150{
4151 int type, value;
4152 struct i2c_client *client = to_i2c_client(dev);
4153 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4154#ifdef CONFIG_SENSORS_BMI058
4155 int i;
4156#endif
4157
4158 sscanf(buf, "%3d %3d", &type, &value);
4159
4160#ifdef CONFIG_SENSORS_BMI058
4161 for (i = 0; i < sizeof(int_map) / sizeof(struct interrupt_map_t); i++) {
4162 if (int_map[i].x == type) {
4163 type = int_map[i].y;
4164 break;
4165 }
4166 if (int_map[i].y == type) {
4167 type = int_map[i].x;
4168 break;
4169 }
4170 }
4171#endif
4172
4173 if (smi130_acc_set_Int_Enable(smi130_acc->smi130_acc_client, type, value) < 0)
4174 return -EINVAL;
4175
4176 return count;
4177}
4178
4179
4180static ssize_t smi130_acc_int_mode_show(struct device *dev,
4181 struct device_attribute *attr, char *buf)
4182{
4183 unsigned char data = 0;
4184 struct i2c_client *client = to_i2c_client(dev);
4185 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4186
4187 if (smi130_acc_get_Int_Mode(smi130_acc->smi130_acc_client, &data) < 0)
4188 return -EINVAL;
4189
4190 return snprintf(buf, 16, "%d\n", data);
4191}
4192
4193static ssize_t smi130_acc_int_mode_store(struct device *dev,
4194 struct device_attribute *attr,
4195 const char *buf, size_t count)
4196{
4197 unsigned long data;
4198 int error;
4199 struct i2c_client *client = to_i2c_client(dev);
4200 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4201
4202 error = kstrtoul(buf, 10, &data);
4203 if (error)
4204 return error;
4205
4206 if (smi130_acc_set_Int_Mode(smi130_acc->smi130_acc_client, (unsigned char)data) < 0)
4207 return -EINVAL;
4208
4209 return count;
4210}
4211static ssize_t smi130_acc_slope_duration_show(struct device *dev,
4212 struct device_attribute *attr, char *buf)
4213{
4214 unsigned char data = 0;
4215 struct i2c_client *client = to_i2c_client(dev);
4216 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4217
4218 if (smi130_acc_get_slope_duration(smi130_acc->smi130_acc_client, &data) < 0)
4219 return -EINVAL;
4220
4221 return snprintf(buf, 16, "%d\n", data);
4222
4223}
4224
4225static ssize_t smi130_acc_slope_duration_store(struct device *dev,
4226 struct device_attribute *attr,
4227 const char *buf, size_t count)
4228{
4229 unsigned long data;
4230 int error;
4231 struct i2c_client *client = to_i2c_client(dev);
4232 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4233
4234 error = kstrtoul(buf, 10, &data);
4235 if (error)
4236 return error;
4237
4238 if (smi130_acc_set_slope_duration(smi130_acc->smi130_acc_client, (unsigned
4239 char)data) < 0)
4240 return -EINVAL;
4241
4242 return count;
4243}
4244
4245static ssize_t smi130_acc_slope_no_mot_duration_show(struct device *dev,
4246 struct device_attribute *attr, char *buf)
4247{
4248 unsigned char data = 0;
4249 struct i2c_client *client = to_i2c_client(dev);
4250 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4251
4252 if (smi130_acc_get_slope_no_mot_duration(smi130_acc->smi130_acc_client, &data) < 0)
4253 return -EINVAL;
4254
4255 return snprintf(buf, 16, "%d\n", data);
4256
4257}
4258
4259static ssize_t smi130_acc_slope_no_mot_duration_store(struct device *dev,
4260 struct device_attribute *attr,
4261 const char *buf, size_t count)
4262{
4263 unsigned long data;
4264 int error;
4265 struct i2c_client *client = to_i2c_client(dev);
4266 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4267
4268 error = kstrtoul(buf, 10, &data);
4269 if (error)
4270 return error;
4271
4272 if (smi130_acc_set_slope_no_mot_duration(smi130_acc->smi130_acc_client, (unsigned
4273 char)data) < 0)
4274 return -EINVAL;
4275
4276 return count;
4277}
4278
4279
4280static ssize_t smi130_acc_slope_threshold_show(struct device *dev,
4281 struct device_attribute *attr, char *buf)
4282{
4283 unsigned char data = 0;
4284 struct i2c_client *client = to_i2c_client(dev);
4285 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4286
4287 if (smi130_acc_get_slope_threshold(smi130_acc->smi130_acc_client, &data) < 0)
4288 return -EINVAL;
4289
4290 return snprintf(buf, 16, "%d\n", data);
4291
4292}
4293
4294static ssize_t smi130_acc_slope_threshold_store(struct device *dev,
4295 struct device_attribute *attr,
4296 const char *buf, size_t count)
4297{
4298 unsigned long data;
4299 int error;
4300 struct i2c_client *client = to_i2c_client(dev);
4301 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4302
4303 error = kstrtoul(buf, 10, &data);
4304 if (error)
4305 return error;
4306 if (smi130_acc_set_slope_threshold(smi130_acc->smi130_acc_client, (unsigned
4307 char)data) < 0)
4308 return -EINVAL;
4309
4310 return count;
4311}
4312
4313static ssize_t smi130_acc_slope_no_mot_threshold_show(struct device *dev,
4314 struct device_attribute *attr, char *buf)
4315{
4316 unsigned char data = 0;
4317 struct i2c_client *client = to_i2c_client(dev);
4318 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4319
4320 if (smi130_acc_get_slope_no_mot_threshold(smi130_acc->smi130_acc_client, &data) < 0)
4321 return -EINVAL;
4322
4323 return snprintf(buf, 16, "%d\n", data);
4324
4325}
4326
4327static ssize_t smi130_acc_slope_no_mot_threshold_store(struct device *dev,
4328 struct device_attribute *attr,
4329 const char *buf, size_t count)
4330{
4331 unsigned long data;
4332 int error;
4333 struct i2c_client *client = to_i2c_client(dev);
4334 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4335
4336 error = kstrtoul(buf, 10, &data);
4337 if (error)
4338 return error;
4339 if (smi130_acc_set_slope_no_mot_threshold(smi130_acc->smi130_acc_client, (unsigned
4340 char)data) < 0)
4341 return -EINVAL;
4342
4343 return count;
4344}
4345
4346static ssize_t smi130_acc_high_g_duration_show(struct device *dev,
4347 struct device_attribute *attr, char *buf)
4348{
4349 unsigned char data = 0;
4350 struct i2c_client *client = to_i2c_client(dev);
4351 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4352
4353 if (smi130_acc_get_high_g_duration(smi130_acc->smi130_acc_client, &data) < 0)
4354 return -EINVAL;
4355
4356 return snprintf(buf, 16, "%d\n", data);
4357
4358}
4359
4360static ssize_t smi130_acc_high_g_duration_store(struct device *dev,
4361 struct device_attribute *attr,
4362 const char *buf, size_t count)
4363{
4364 unsigned long data;
4365 int error;
4366 struct i2c_client *client = to_i2c_client(dev);
4367 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4368
4369 error = kstrtoul(buf, 10, &data);
4370 if (error)
4371 return error;
4372
4373 if (smi130_acc_set_high_g_duration(smi130_acc->smi130_acc_client, (unsigned
4374 char)data) < 0)
4375 return -EINVAL;
4376
4377 return count;
4378}
4379
4380static ssize_t smi130_acc_high_g_threshold_show(struct device *dev,
4381 struct device_attribute *attr, char *buf)
4382{
4383 unsigned char data = 0;
4384 struct i2c_client *client = to_i2c_client(dev);
4385 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4386
4387 if (smi130_acc_get_high_g_threshold(smi130_acc->smi130_acc_client, &data) < 0)
4388 return -EINVAL;
4389
4390 return snprintf(buf, 16, "%d\n", data);
4391
4392}
4393
4394static ssize_t smi130_acc_high_g_threshold_store(struct device *dev,
4395 struct device_attribute *attr,
4396 const char *buf, size_t count)
4397{
4398 unsigned long data;
4399 int error;
4400 struct i2c_client *client = to_i2c_client(dev);
4401 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4402
4403 error = kstrtoul(buf, 10, &data);
4404 if (error)
4405 return error;
4406 if (smi130_acc_set_high_g_threshold(smi130_acc->smi130_acc_client, (unsigned
4407 char)data) < 0)
4408 return -EINVAL;
4409
4410 return count;
4411}
4412
4413static ssize_t smi130_acc_low_g_duration_show(struct device *dev,
4414 struct device_attribute *attr, char *buf)
4415{
4416 unsigned char data = 0;
4417 struct i2c_client *client = to_i2c_client(dev);
4418 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4419
4420 if (smi130_acc_get_low_g_duration(smi130_acc->smi130_acc_client, &data) < 0)
4421 return -EINVAL;
4422
4423 return snprintf(buf, 16, "%d\n", data);
4424
4425}
4426
4427static ssize_t smi130_acc_low_g_duration_store(struct device *dev,
4428 struct device_attribute *attr,
4429 const char *buf, size_t count)
4430{
4431 unsigned long data;
4432 int error;
4433 struct i2c_client *client = to_i2c_client(dev);
4434 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4435
4436 error = kstrtoul(buf, 10, &data);
4437 if (error)
4438 return error;
4439
4440 if (smi130_acc_set_low_g_duration(smi130_acc->smi130_acc_client, (unsigned
4441 char)data) < 0)
4442 return -EINVAL;
4443
4444 return count;
4445}
4446
4447static ssize_t smi130_acc_low_g_threshold_show(struct device *dev,
4448 struct device_attribute *attr, char *buf)
4449{
4450 unsigned char data = 0;
4451 struct i2c_client *client = to_i2c_client(dev);
4452 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4453
4454 if (smi130_acc_get_low_g_threshold(smi130_acc->smi130_acc_client, &data) < 0)
4455 return -EINVAL;
4456
4457 return snprintf(buf, 16, "%d\n", data);
4458
4459}
4460
4461static ssize_t smi130_acc_low_g_threshold_store(struct device *dev,
4462 struct device_attribute *attr,
4463 const char *buf, size_t count)
4464{
4465 unsigned long data;
4466 int error;
4467 struct i2c_client *client = to_i2c_client(dev);
4468 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4469
4470 error = kstrtoul(buf, 10, &data);
4471 if (error)
4472 return error;
4473 if (smi130_acc_set_low_g_threshold(smi130_acc->smi130_acc_client, (unsigned
4474 char)data) < 0)
4475 return -EINVAL;
4476
4477 return count;
4478}
4479static ssize_t smi130_acc_tap_threshold_show(struct device *dev,
4480 struct device_attribute *attr, char *buf)
4481{
4482 unsigned char data = 0;
4483 struct i2c_client *client = to_i2c_client(dev);
4484 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4485
4486 if (smi130_acc_get_tap_threshold(smi130_acc->smi130_acc_client, &data) < 0)
4487 return -EINVAL;
4488
4489 return snprintf(buf, 16, "%d\n", data);
4490
4491}
4492
4493static ssize_t smi130_acc_tap_threshold_store(struct device *dev,
4494 struct device_attribute *attr,
4495 const char *buf, size_t count)
4496{
4497 unsigned long data;
4498 int error;
4499 struct i2c_client *client = to_i2c_client(dev);
4500 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4501
4502 error = kstrtoul(buf, 10, &data);
4503 if (error)
4504 return error;
4505 if (smi130_acc_set_tap_threshold(smi130_acc->smi130_acc_client, (unsigned char)data)
4506 < 0)
4507 return -EINVAL;
4508
4509 return count;
4510}
4511static ssize_t smi130_acc_tap_duration_show(struct device *dev,
4512 struct device_attribute *attr, char *buf)
4513{
4514 unsigned char data = 0;
4515 struct i2c_client *client = to_i2c_client(dev);
4516 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4517
4518 if (smi130_acc_get_tap_duration(smi130_acc->smi130_acc_client, &data) < 0)
4519 return -EINVAL;
4520
4521 return snprintf(buf, 16, "%d\n", data);
4522
4523}
4524
4525static ssize_t smi130_acc_tap_duration_store(struct device *dev,
4526 struct device_attribute *attr,
4527 const char *buf, size_t count)
4528{
4529 unsigned long data;
4530 int error;
4531 struct i2c_client *client = to_i2c_client(dev);
4532 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4533
4534 error = kstrtoul(buf, 10, &data);
4535 if (error)
4536 return error;
4537
4538 if (smi130_acc_set_tap_duration(smi130_acc->smi130_acc_client, (unsigned char)data)
4539 < 0)
4540 return -EINVAL;
4541
4542 return count;
4543}
4544static ssize_t smi130_acc_tap_quiet_show(struct device *dev,
4545 struct device_attribute *attr, char *buf)
4546{
4547 unsigned char data = 0;
4548 struct i2c_client *client = to_i2c_client(dev);
4549 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4550
4551 if (smi130_acc_get_tap_quiet(smi130_acc->smi130_acc_client, &data) < 0)
4552 return -EINVAL;
4553
4554 return snprintf(buf, 16, "%d\n", data);
4555
4556}
4557
4558static ssize_t smi130_acc_tap_quiet_store(struct device *dev,
4559 struct device_attribute *attr,
4560 const char *buf, size_t count)
4561{
4562 unsigned long data;
4563 int error;
4564 struct i2c_client *client = to_i2c_client(dev);
4565 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4566
4567 error = kstrtoul(buf, 10, &data);
4568 if (error)
4569 return error;
4570
4571 if (smi130_acc_set_tap_quiet(smi130_acc->smi130_acc_client, (unsigned char)data) <
4572 0)
4573 return -EINVAL;
4574
4575 return count;
4576}
4577
4578static ssize_t smi130_acc_tap_shock_show(struct device *dev,
4579 struct device_attribute *attr, char *buf)
4580{
4581 unsigned char data = 0;
4582 struct i2c_client *client = to_i2c_client(dev);
4583 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4584
4585 if (smi130_acc_get_tap_shock(smi130_acc->smi130_acc_client, &data) < 0)
4586 return -EINVAL;
4587
4588 return snprintf(buf, 16, "%d\n", data);
4589
4590}
4591
4592static ssize_t smi130_acc_tap_shock_store(struct device *dev,
4593 struct device_attribute *attr,
4594 const char *buf, size_t count)
4595{
4596 unsigned long data;
4597 int error;
4598 struct i2c_client *client = to_i2c_client(dev);
4599 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4600
4601 error = kstrtoul(buf, 10, &data);
4602 if (error)
4603 return error;
4604
4605 if (smi130_acc_set_tap_shock(smi130_acc->smi130_acc_client, (unsigned char)data) <
4606 0)
4607 return -EINVAL;
4608
4609 return count;
4610}
4611
4612static ssize_t smi130_acc_tap_samp_show(struct device *dev,
4613 struct device_attribute *attr, char *buf)
4614{
4615 unsigned char data = 0;
4616 struct i2c_client *client = to_i2c_client(dev);
4617 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4618
4619 if (smi130_acc_get_tap_samp(smi130_acc->smi130_acc_client, &data) < 0)
4620 return -EINVAL;
4621
4622 return snprintf(buf, 16, "%d\n", data);
4623
4624}
4625
4626static ssize_t smi130_acc_tap_samp_store(struct device *dev,
4627 struct device_attribute *attr,
4628 const char *buf, size_t count)
4629{
4630 unsigned long data;
4631 int error;
4632 struct i2c_client *client = to_i2c_client(dev);
4633 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4634
4635 error = kstrtoul(buf, 10, &data);
4636 if (error)
4637 return error;
4638
4639 if (smi130_acc_set_tap_samp(smi130_acc->smi130_acc_client, (unsigned char)data) < 0)
4640 return -EINVAL;
4641
4642 return count;
4643}
4644
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004645static ssize_t smi130_acc_orient_mbl_mode_show(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004646 struct device_attribute *attr, char *buf)
4647{
4648 unsigned char data = 0;
4649 struct i2c_client *client = to_i2c_client(dev);
4650 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4651
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004652 if (smi130_acc_get_orient_mbl_mode(smi130_acc->smi130_acc_client, &data) < 0)
Bosch Sensortecface5922018-08-29 08:08:53 +02004653 return -EINVAL;
4654
4655 return snprintf(buf, 16, "%d\n", data);
4656
4657}
4658
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004659static ssize_t smi130_acc_orient_mbl_mode_store(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004660 struct device_attribute *attr,
4661 const char *buf, size_t count)
4662{
4663 unsigned long data;
4664 int error;
4665 struct i2c_client *client = to_i2c_client(dev);
4666 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4667
4668 error = kstrtoul(buf, 10, &data);
4669 if (error)
4670 return error;
4671
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004672 if (smi130_acc_set_orient_mbl_mode(smi130_acc->smi130_acc_client, (unsigned char)data) <
Bosch Sensortecface5922018-08-29 08:08:53 +02004673 0)
4674 return -EINVAL;
4675
4676 return count;
4677}
4678
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004679static ssize_t smi130_acc_orient_mbl_blocking_show(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004680 struct device_attribute *attr, char *buf)
4681{
4682 unsigned char data = 0;
4683 struct i2c_client *client = to_i2c_client(dev);
4684 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4685
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004686 if (smi130_acc_get_orient_mbl_blocking(smi130_acc->smi130_acc_client, &data) < 0)
Bosch Sensortecface5922018-08-29 08:08:53 +02004687 return -EINVAL;
4688
4689 return snprintf(buf, 16, "%d\n", data);
4690
4691}
4692
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004693static ssize_t smi130_acc_orient_mbl_blocking_store(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004694 struct device_attribute *attr,
4695 const char *buf, size_t count)
4696{
4697 unsigned long data;
4698 int error;
4699 struct i2c_client *client = to_i2c_client(dev);
4700 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4701
4702 error = kstrtoul(buf, 10, &data);
4703 if (error)
4704 return error;
4705
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004706 if (smi130_acc_set_orient_mbl_blocking(smi130_acc->smi130_acc_client, (unsigned
Bosch Sensortecface5922018-08-29 08:08:53 +02004707 char)data) < 0)
4708 return -EINVAL;
4709
4710 return count;
4711}
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004712static ssize_t smi130_acc_orient_mbl_hyst_show(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004713 struct device_attribute *attr, char *buf)
4714{
4715 unsigned char data = 0;
4716 struct i2c_client *client = to_i2c_client(dev);
4717 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4718
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004719 if (smi130_acc_get_orient_mbl_hyst(smi130_acc->smi130_acc_client, &data) < 0)
Bosch Sensortecface5922018-08-29 08:08:53 +02004720 return -EINVAL;
4721
4722 return snprintf(buf, 16, "%d\n", data);
4723
4724}
4725
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004726static ssize_t smi130_acc_orient_mbl_hyst_store(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004727 struct device_attribute *attr,
4728 const char *buf, size_t count)
4729{
4730 unsigned long data;
4731 int error;
4732 struct i2c_client *client = to_i2c_client(dev);
4733 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4734
4735 error = kstrtoul(buf, 10, &data);
4736 if (error)
4737 return error;
4738
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004739 if (smi130_acc_set_orient_mbl_hyst(smi130_acc->smi130_acc_client, (unsigned char)data) <
Bosch Sensortecface5922018-08-29 08:08:53 +02004740 0)
4741 return -EINVAL;
4742
4743 return count;
4744}
4745
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004746static ssize_t smi130_acc_orient_mbl_theta_show(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004747 struct device_attribute *attr, char *buf)
4748{
4749 unsigned char data = 0;
4750 struct i2c_client *client = to_i2c_client(dev);
4751 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4752
4753 if (smi130_acc_get_theta_blocking(smi130_acc->smi130_acc_client, &data) < 0)
4754 return -EINVAL;
4755
4756 return snprintf(buf, 16, "%d\n", data);
4757
4758}
4759
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02004760static ssize_t smi130_acc_orient_mbl_theta_store(struct device *dev,
Bosch Sensortecface5922018-08-29 08:08:53 +02004761 struct device_attribute *attr,
4762 const char *buf, size_t count)
4763{
4764 unsigned long data;
4765 int error;
4766 struct i2c_client *client = to_i2c_client(dev);
4767 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4768
4769 error = kstrtoul(buf, 10, &data);
4770 if (error)
4771 return error;
4772
4773 if (smi130_acc_set_theta_blocking(smi130_acc->smi130_acc_client, (unsigned
4774 char)data) < 0)
4775 return -EINVAL;
4776
4777 return count;
4778}
4779
4780static ssize_t smi130_acc_flat_theta_show(struct device *dev,
4781 struct device_attribute *attr, char *buf)
4782{
4783 unsigned char data = 0;
4784 struct i2c_client *client = to_i2c_client(dev);
4785 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4786
4787 if (smi130_acc_get_theta_flat(smi130_acc->smi130_acc_client, &data) < 0)
4788 return -EINVAL;
4789
4790 return snprintf(buf, 16, "%d\n", data);
4791
4792}
4793
4794static ssize_t smi130_acc_flat_theta_store(struct device *dev,
4795 struct device_attribute *attr,
4796 const char *buf, size_t count)
4797{
4798 unsigned long data;
4799 int error;
4800 struct i2c_client *client = to_i2c_client(dev);
4801 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4802
4803 error = kstrtoul(buf, 10, &data);
4804 if (error)
4805 return error;
4806
4807 if (smi130_acc_set_theta_flat(smi130_acc->smi130_acc_client, (unsigned char)data) <
4808 0)
4809 return -EINVAL;
4810
4811 return count;
4812}
4813static ssize_t smi130_acc_flat_hold_time_show(struct device *dev,
4814 struct device_attribute *attr, char *buf)
4815{
4816 unsigned char data = 0;
4817 struct i2c_client *client = to_i2c_client(dev);
4818 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4819
4820 if (smi130_acc_get_flat_hold_time(smi130_acc->smi130_acc_client, &data) < 0)
4821 return -EINVAL;
4822
4823 return snprintf(buf, 16, "%d\n", data);
4824
4825}
4826static ssize_t smi130_acc_selftest_show(struct device *dev,
4827 struct device_attribute *attr, char *buf)
4828{
4829
4830
4831 struct i2c_client *client = to_i2c_client(dev);
4832 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4833
4834 return snprintf(buf, 16, "%d\n", atomic_read(&smi130_acc->selftest_result));
4835
4836}
4837
4838static ssize_t smi130_acc_softreset_store(struct device *dev,
4839 struct device_attribute *attr,
4840 const char *buf, size_t count)
4841{
4842 struct i2c_client *client = to_i2c_client(dev);
4843 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4844
4845 if (smi130_acc_soft_reset(smi130_acc->smi130_acc_client) < 0)
4846 return -EINVAL;
4847
4848 return count;
4849}
4850static ssize_t smi130_acc_selftest_store(struct device *dev,
4851 struct device_attribute *attr,
4852 const char *buf, size_t count)
4853{
4854
4855 unsigned long data;
4856 unsigned char clear_value = 0;
4857 int error;
4858 short value1 = 0;
4859 short value2 = 0;
4860 short diff = 0;
4861 unsigned long result = 0;
4862 unsigned char test_result_branch = 0;
4863 struct i2c_client *client = to_i2c_client(dev);
4864 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
4865
4866 smi130_acc_soft_reset(smi130_acc->smi130_acc_client);
4867 smi130_acc_delay(5);
4868
4869 error = kstrtoul(buf, 10, &data);
4870 if (error)
4871 return error;
4872
4873 if (data != 1)
4874 return -EINVAL;
4875
4876 smi130_acc_write_reg(smi130_acc->smi130_acc_client, 0x32, &clear_value);
4877
4878 if ((smi130_acc->sensor_type == SMI_ACC280_TYPE) ||
4879 (smi130_acc->sensor_type == SMI_ACC255_TYPE)) {
4880#ifdef CONFIG_SENSORS_BMI058
4881 /*set self test amp */
4882 if (smi130_acc_set_selftest_amp(smi130_acc->smi130_acc_client, 1) < 0)
4883 return -EINVAL;
4884 /* set to 8 G range */
4885 if (smi130_acc_set_range(smi130_acc->smi130_acc_client,
4886 SMI_ACC2X2_RANGE_8G) < 0)
4887 return -EINVAL;
4888#else
4889 /* set to 4 G range */
4890 if (smi130_acc_set_range(smi130_acc->smi130_acc_client,
4891 SMI_ACC2X2_RANGE_4G) < 0)
4892 return -EINVAL;
4893#endif
4894 }
4895
4896 if ((smi130_acc->sensor_type == SMI_ACC250E_TYPE) ||
4897 (smi130_acc->sensor_type == SMI_ACC222E_TYPE)) {
4898 /* set to 8 G range */
4899 if (smi130_acc_set_range(smi130_acc->smi130_acc_client, 8) < 0)
4900 return -EINVAL;
4901 if (smi130_acc_set_selftest_amp(smi130_acc->smi130_acc_client, 1) < 0)
4902 return -EINVAL;
4903 }
4904
4905 /* 1 for x-axis(but BMI058 is 1 for y-axis )*/
4906 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 1);
4907 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0);
4908 smi130_acc_delay(10);
4909 smi130_acc_read_accel_x(smi130_acc->smi130_acc_client,
4910 smi130_acc->sensor_type, &value1);
4911 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1);
4912 smi130_acc_delay(10);
4913 smi130_acc_read_accel_x(smi130_acc->smi130_acc_client,
4914 smi130_acc->sensor_type, &value2);
4915 diff = value1-value2;
4916
4917#ifdef CONFIG_SENSORS_BMI058
4918 PINFO("diff y is %d,value1 is %d, value2 is %d\n", diff,
4919 value1, value2);
4920 test_result_branch = 2;
4921#else
4922 PINFO("diff x is %d,value1 is %d, value2 is %d\n", diff,
4923 value1, value2);
4924 test_result_branch = 1;
4925#endif
4926
4927 if (smi130_acc->sensor_type == SMI_ACC280_TYPE) {
4928#ifdef CONFIG_SENSORS_BMI058
4929 if (abs(diff) < 819)
4930 result |= test_result_branch;
4931#else
4932 if (abs(diff) < 1638)
4933 result |= test_result_branch;
4934#endif
4935 }
4936 if (smi130_acc->sensor_type == SMI_ACC255_TYPE) {
4937 if (abs(diff) < 409)
4938 result |= 1;
4939 }
4940 if (smi130_acc->sensor_type == SMI_ACC250E_TYPE) {
4941 if (abs(diff) < 51)
4942 result |= 1;
4943 }
4944 if (smi130_acc->sensor_type == SMI_ACC222E_TYPE) {
4945 if (abs(diff) < 12)
4946 result |= 1;
4947 }
4948
4949 /* 2 for y-axis but BMI058 is 1*/
4950 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 2);
4951 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0);
4952 smi130_acc_delay(10);
4953 smi130_acc_read_accel_y(smi130_acc->smi130_acc_client,
4954 smi130_acc->sensor_type, &value1);
4955 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1);
4956 smi130_acc_delay(10);
4957 smi130_acc_read_accel_y(smi130_acc->smi130_acc_client,
4958 smi130_acc->sensor_type, &value2);
4959 diff = value1-value2;
4960
4961#ifdef CONFIG_SENSORS_BMI058
4962 PINFO("diff x is %d,value1 is %d, value2 is %d\n", diff,
4963 value1, value2);
4964 test_result_branch = 1;
4965#else
4966 PINFO("diff y is %d,value1 is %d, value2 is %d\n", diff,
4967 value1, value2);
4968 test_result_branch = 2;
4969#endif
4970
4971 if (smi130_acc->sensor_type == SMI_ACC280_TYPE) {
4972#ifdef CONFIG_SENSORS_BMI058
4973 if (abs(diff) < 819)
4974 result |= test_result_branch;
4975#else
4976 if (abs(diff) < 1638)
4977 result |= test_result_branch;
4978#endif
4979 }
4980 if (smi130_acc->sensor_type == SMI_ACC255_TYPE) {
4981 if (abs(diff) < 409)
4982 result |= test_result_branch;
4983 }
4984 if (smi130_acc->sensor_type == SMI_ACC250E_TYPE) {
4985 if (abs(diff) < 51)
4986 result |= test_result_branch;
4987 }
4988 if (smi130_acc->sensor_type == SMI_ACC222E_TYPE) {
4989 if (abs(diff) < 12)
4990 result |= test_result_branch;
4991 }
4992
4993
4994 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 3); /* 3 for z-axis*/
4995 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0);
4996 smi130_acc_delay(10);
4997 smi130_acc_read_accel_z(smi130_acc->smi130_acc_client,
4998 smi130_acc->sensor_type, &value1);
4999 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1);
5000 smi130_acc_delay(10);
5001 smi130_acc_read_accel_z(smi130_acc->smi130_acc_client,
5002 smi130_acc->sensor_type, &value2);
5003 diff = value1-value2;
5004
5005 PINFO("diff z is %d,value1 is %d, value2 is %d\n", diff,
5006 value1, value2);
5007
5008 if (smi130_acc->sensor_type == SMI_ACC280_TYPE) {
5009#ifdef CONFIG_SENSORS_BMI058
5010 if (abs(diff) < 409)
5011 result |= 4;
5012#else
5013 if (abs(diff) < 819)
5014 result |= 4;
5015#endif
5016 }
5017 if (smi130_acc->sensor_type == SMI_ACC255_TYPE) {
5018 if (abs(diff) < 204)
5019 result |= 4;
5020 }
5021 if (smi130_acc->sensor_type == SMI_ACC250E_TYPE) {
5022 if (abs(diff) < 25)
5023 result |= 4;
5024 }
5025 if (smi130_acc->sensor_type == SMI_ACC222E_TYPE) {
5026 if (abs(diff) < 6)
5027 result |= 4;
5028 }
5029
5030 /* self test for smi_acc254 */
5031 if ((smi130_acc->sensor_type == SMI_ACC255_TYPE) && (result > 0)) {
5032 result = 0;
5033 smi130_acc_soft_reset(smi130_acc->smi130_acc_client);
5034 smi130_acc_delay(5);
5035 smi130_acc_write_reg(smi130_acc->smi130_acc_client, 0x32, &clear_value);
5036 /* set to 8 G range */
5037 if (smi130_acc_set_range(smi130_acc->smi130_acc_client, 8) < 0)
5038 return -EINVAL;
5039 if (smi130_acc_set_selftest_amp(smi130_acc->smi130_acc_client, 1) < 0)
5040 return -EINVAL;
5041
5042 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 1); /* 1
5043 for x-axis*/
5044 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0); /*
5045 positive direction*/
5046 smi130_acc_delay(10);
5047 smi130_acc_read_accel_x(smi130_acc->smi130_acc_client,
5048 smi130_acc->sensor_type, &value1);
5049 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1); /*
5050 negative direction*/
5051 smi130_acc_delay(10);
5052 smi130_acc_read_accel_x(smi130_acc->smi130_acc_client,
5053 smi130_acc->sensor_type, &value2);
5054 diff = value1-value2;
5055
5056 PINFO("diff x is %d,value1 is %d, value2 is %d\n",
5057 diff, value1, value2);
5058 if (abs(diff) < 204)
5059 result |= 1;
5060
5061 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 2); /* 2
5062 for y-axis*/
5063 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0); /*
5064 positive direction*/
5065 smi130_acc_delay(10);
5066 smi130_acc_read_accel_y(smi130_acc->smi130_acc_client,
5067 smi130_acc->sensor_type, &value1);
5068 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1); /*
5069 negative direction*/
5070 smi130_acc_delay(10);
5071 smi130_acc_read_accel_y(smi130_acc->smi130_acc_client,
5072 smi130_acc->sensor_type, &value2);
5073 diff = value1-value2;
5074 PINFO("diff y is %d,value1 is %d, value2 is %d\n",
5075 diff, value1, value2);
5076
5077 if (abs(diff) < 204)
5078 result |= 2;
5079
5080 smi130_acc_set_selftest_st(smi130_acc->smi130_acc_client, 3); /* 3
5081 for z-axis*/
5082 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 0); /*
5083 positive direction*/
5084 smi130_acc_delay(10);
5085 smi130_acc_read_accel_z(smi130_acc->smi130_acc_client,
5086 smi130_acc->sensor_type, &value1);
5087 smi130_acc_set_selftest_stn(smi130_acc->smi130_acc_client, 1); /*
5088 negative direction*/
5089 smi130_acc_delay(10);
5090 smi130_acc_read_accel_z(smi130_acc->smi130_acc_client,
5091 smi130_acc->sensor_type, &value2);
5092 diff = value1-value2;
5093
5094 PINFO("diff z is %d,value1 is %d, value2 is %d\n",
5095 diff, value1, value2);
5096 if (abs(diff) < 102)
5097 result |= 4;
5098 }
5099
5100 atomic_set(&smi130_acc->selftest_result, (unsigned int)result);
5101
5102 smi130_acc_soft_reset(smi130_acc->smi130_acc_client);
5103 smi130_acc_delay(5);
5104 PINFO("self test finished\n");
5105
5106 return count;
5107}
5108
5109
5110
5111static ssize_t smi130_acc_flat_hold_time_store(struct device *dev,
5112 struct device_attribute *attr,
5113 const char *buf, size_t count)
5114{
5115 unsigned long data;
5116 int error;
5117 struct i2c_client *client = to_i2c_client(dev);
5118 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5119
5120 error = kstrtoul(buf, 10, &data);
5121 if (error)
5122 return error;
5123
5124 if (smi130_acc_set_flat_hold_time(smi130_acc->smi130_acc_client, (unsigned
5125 char)data) < 0)
5126 return -EINVAL;
5127
5128 return count;
5129}
5130
5131const int smi130_acc_sensor_bitwidth[] = {
5132 12, 10, 8, 14
5133};
5134
5135static int smi130_acc_read_accel_xyz(struct i2c_client *client,
5136 signed char sensor_type, struct smi130_accacc *acc)
5137{
5138 int comres = 0;
puneet597e4f12018-11-06 14:32:16 +05305139 unsigned char data[6] = {0};
Bosch Sensortecface5922018-08-29 08:08:53 +02005140 struct smi130_acc_data *client_data = i2c_get_clientdata(client);
5141#ifndef SMI_ACC2X2_SENSOR_IDENTIFICATION_ENABLE
5142 int bitwidth;
5143#endif
5144 comres = smi130_acc_smbus_read_byte_block(client,
5145 SMI_ACC2X2_ACC_X12_LSB__REG, data, 6);
5146 if (sensor_type >= 4)
5147 return -EINVAL;
5148
5149 acc->x = (data[1]<<8)|data[0];
5150 acc->y = (data[3]<<8)|data[2];
5151 acc->z = (data[5]<<8)|data[4];
5152
5153#ifndef SMI_ACC2X2_SENSOR_IDENTIFICATION_ENABLE
5154 bitwidth = smi130_acc_sensor_bitwidth[sensor_type];
5155
5156 acc->x = (acc->x >> (16 - bitwidth));
5157 acc->y = (acc->y >> (16 - bitwidth));
5158 acc->z = (acc->z >> (16 - bitwidth));
5159#endif
5160
5161 smi130_acc_remap_sensor_data(acc, client_data);
5162 return comres;
5163}
5164
5165#ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
5166static void smi130_acc_work_func(struct work_struct *work)
5167{
5168 struct smi130_acc_data *smi130_acc = container_of((struct delayed_work *)work,
5169 struct smi130_acc_data, work);
5170 static struct smi130_accacc acc;
5171 unsigned long delay = msecs_to_jiffies(atomic_read(&smi130_acc->delay));
5172
5173 smi130_acc_read_accel_xyz(smi130_acc->smi130_acc_client, smi130_acc->sensor_type, &acc);
5174 input_report_abs(smi130_acc->input, ABS_X, acc.x);
5175 input_report_abs(smi130_acc->input, ABS_Y, acc.y);
5176 input_report_abs(smi130_acc->input, ABS_Z, acc.z);
5177 input_sync(smi130_acc->input);
5178 mutex_lock(&smi130_acc->value_mutex);
5179 smi130_acc->value = acc;
5180 mutex_unlock(&smi130_acc->value_mutex);
5181 schedule_delayed_work(&smi130_acc->work, delay);
5182}
5183#endif
5184static struct workqueue_struct *reportdata_wq;
5185
5186uint64_t smi130_acc_get_alarm_timestamp(void)
5187{
5188 uint64_t ts_ap;
5189 struct timespec tmp_time;
5190 get_monotonic_boottime(&tmp_time);
5191 ts_ap = (uint64_t)tmp_time.tv_sec * 1000000000 + tmp_time.tv_nsec;
5192 return ts_ap;
5193}
5194
5195#define ABS(x) ((x) > 0 ? (x) : -(x))
5196
5197static void smi130_acc_timer_work_fun(struct work_struct *work)
5198{
5199 struct smi130_acc_data *smi130_acc =
5200 container_of(work,
5201 struct smi130_acc_data, report_data_work);
5202 int i;
5203 unsigned char count = 0;
5204 unsigned char mode = 0;
5205 signed char fifo_data_out[MAX_FIFO_F_LEVEL * MAX_FIFO_F_BYTES] = {0};
5206 unsigned char f_len = 0;
5207 uint64_t del = 0;
5208 uint64_t time_internal = 0;
5209 int64_t drift_time = 0;
5210 static uint64_t time_odr;
5211 struct smi130_accacc acc_lsb;
5212 struct timespec ts;
5213 static uint32_t data_cnt;
5214 static uint32_t pre_data_cnt;
5215 static int64_t sample_drift_offset;
5216
5217 if (smi130_acc->fifo_datasel) {
5218 /*Select one axis data output for every fifo frame*/
5219 f_len = 2;
5220 } else {
5221 /*Select X Y Z axis data output for every fifo frame*/
5222 f_len = 6;
5223 }
5224 if (smi130_acc_get_fifo_framecount(smi130_acc->smi130_acc_client, &count) < 0) {
5225 PERR("smi130_acc_get_fifo_framecount err\n");
5226 return;
5227 }
5228 if (count == 0) {
5229 PERR("smi130_acc_get_fifo_framecount zero\n");
5230 return;
5231 }
5232 if (count > MAX_FIFO_F_LEVEL) {
5233 if (smi130_acc_get_mode(smi130_acc->smi130_acc_client, &mode) < 0) {
5234 PERR("smi130_acc_get_mode err\n");
5235 return;
5236 }
5237 if (SMI_ACC2X2_MODE_NORMAL == mode) {
5238 PERR("smi130_acc fifo_count: %d abnormal, op_mode: %d\n",
5239 count, mode);
5240 count = MAX_FIFO_F_LEVEL;
5241 } else {
5242 /*chip already suspend or shutdown*/
5243 count = 0;
5244 return;
5245 }
5246 }
5247 if (smi_acc_i2c_burst_read(smi130_acc->smi130_acc_client,
5248 SMI_ACC2X2_FIFO_DATA_OUTPUT_REG, fifo_data_out,
5249 count * f_len) < 0) {
5250 PERR("smi130_acc read fifo err\n");
5251 return;
5252 }
5253 smi130_acc->fifo_time = smi130_acc_get_alarm_timestamp();
5254 if (smi130_acc->acc_count == 0)
5255 smi130_acc->base_time = smi130_acc->timestamp =
5256 smi130_acc->fifo_time - (count-1) * smi130_acc->time_odr;
5257
5258 smi130_acc->acc_count += count;
5259 del = smi130_acc->fifo_time - smi130_acc->base_time;
5260 time_internal = div64_u64(del, smi130_acc->acc_count);
5261
5262 data_cnt++;
5263 if (data_cnt == 1)
5264 time_odr = smi130_acc->time_odr;
5265
5266 if (time_internal > time_odr) {
5267 if (time_internal - time_odr > div64_u64 (time_odr, 200))
5268 time_internal = time_odr + div64_u64(time_odr, 200);
5269 } else {
5270 if (time_odr - time_internal > div64_u64(time_odr, 200))
5271 time_internal = time_odr - div64_u64(time_odr, 200);
5272 }
5273/* please give attation for the fifo output data format*/
5274 if (f_len == 6) {
5275 /* Select X Y Z axis data output for every frame */
5276 for (i = 0; i < count; i++) {
5277 if (smi130_acc->debug_level & 0x01)
5278 printk(KERN_INFO "smi_acc time =%llu fifo_time =%llu smi_acc->count=%llu time_internal =%lld time_odr = %lld ",
5279 smi130_acc->timestamp, smi130_acc->fifo_time,
5280 smi130_acc->acc_count, time_internal, time_odr);
5281
5282 ts = ns_to_timespec(smi130_acc->timestamp);
5283 acc_lsb.x =
5284 ((unsigned char)fifo_data_out[i * f_len + 1] << 8 |
5285 (unsigned char)fifo_data_out[i * f_len + 0]);
5286 acc_lsb.y =
5287 ((unsigned char)fifo_data_out[i * f_len + 3] << 8 |
5288 (unsigned char)fifo_data_out[i * f_len + 2]);
5289 acc_lsb.z =
5290 ((unsigned char)fifo_data_out[i * f_len + 5] << 8 |
5291 (unsigned char)fifo_data_out[i * f_len + 4]);
5292#ifndef SMI_ACC2X2_SENSOR_IDENTIFICATION_ENABLE
5293 acc_lsb.x >>=
5294 (16 - smi130_acc_sensor_bitwidth[smi130_acc->sensor_type]);
5295 acc_lsb.y >>=
5296 (16 - smi130_acc_sensor_bitwidth[smi130_acc->sensor_type]);
5297 acc_lsb.z >>=
5298 (16 - smi130_acc_sensor_bitwidth[smi130_acc->sensor_type]);
5299#endif
5300 smi130_acc_remap_sensor_data(&acc_lsb, smi130_acc);
5301 input_event(smi130_acc->input, EV_MSC, MSC_TIME,
5302 ts.tv_sec);
5303 input_event(smi130_acc->input, EV_MSC, MSC_TIME,
5304 ts.tv_nsec);
5305 input_event(smi130_acc->input, EV_MSC,
5306 MSC_GESTURE, acc_lsb.x);
5307 input_event(smi130_acc->input, EV_MSC,
5308 MSC_RAW, acc_lsb.y);
5309 input_event(smi130_acc->input, EV_MSC,
5310 MSC_SCAN, acc_lsb.z);
5311 input_sync(smi130_acc->input);
5312 smi130_acc->timestamp +=
5313 time_internal - sample_drift_offset;
5314 }
5315 }
5316 drift_time = smi130_acc->timestamp - smi130_acc->fifo_time;
5317 if (data_cnt % 20 == 0) {
5318 if (ABS(drift_time) > div64_u64(time_odr, 5)) {
5319 sample_drift_offset =
5320 div64_s64(drift_time, smi130_acc->acc_count - pre_data_cnt);
5321 pre_data_cnt = smi130_acc->acc_count;
5322 time_odr = time_internal;
5323 }
5324 }
5325
5326}
5327
5328static enum hrtimer_restart reportdata_timer_fun(
5329 struct hrtimer *hrtimer)
5330{
5331 struct smi130_acc_data *client_data =
5332 container_of(hrtimer, struct smi130_acc_data, timer);
5333 int32_t delay = 0;
5334 delay = 8;
5335 queue_work(reportdata_wq, &(client_data->report_data_work));
5336 /*set delay 8ms*/
5337 client_data->work_delay_kt = ns_to_ktime(delay*1000000);
5338 hrtimer_forward(hrtimer, ktime_get(), client_data->work_delay_kt);
5339
5340 return HRTIMER_RESTART;
5341}
5342
5343static ssize_t smi130_acc_enable_timer_show(struct device *dev,
5344 struct device_attribute *attr, char *buf)
5345{
5346 struct i2c_client *client = to_i2c_client(dev);
5347 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5348
5349 return snprintf(buf, 16, "%d\n", smi130_acc->is_timer_running);
5350}
5351
5352static ssize_t smi130_acc_enable_timer_store(struct device *dev,
5353 struct device_attribute *attr,
5354 const char *buf, size_t count)
5355{
5356 unsigned long data;
5357 int error;
5358 struct i2c_client *client = to_i2c_client(dev);
5359 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5360 error = kstrtoul(buf, 10, &data);
5361 if (error)
5362 return error;
5363
5364 if (data) {
5365 if (0 == smi130_acc->is_timer_running) {
5366 hrtimer_start(&smi130_acc->timer,
5367 ns_to_ktime(1000000),
5368 HRTIMER_MODE_REL);
5369 smi130_acc->base_time = 0;
5370 smi130_acc->timestamp = 0;
5371 smi130_acc->is_timer_running = 1;
5372 }
5373 } else {
5374 if (1 == smi130_acc->is_timer_running) {
5375 hrtimer_cancel(&smi130_acc->timer);
5376 smi130_acc->is_timer_running = 0;
5377 smi130_acc->base_time = 0;
5378 smi130_acc->timestamp = 0;
5379 smi130_acc->fifo_time = 0;
5380 smi130_acc->acc_count = 0;
5381 }
5382 }
5383 return count;
5384}
5385
5386static ssize_t smi130_acc_debug_level_show(struct device *dev,
5387 struct device_attribute *attr, char *buf)
5388{
5389 int err;
5390 struct i2c_client *client = to_i2c_client(dev);
5391 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5392 err = snprintf(buf, 8, "%d\n", smi130_acc->debug_level);
5393 return err;
5394}
5395static ssize_t smi130_acc_debug_level_store(struct device *dev,
5396 struct device_attribute *attr,
5397 const char *buf, size_t count)
5398{
5399 int32_t ret = 0;
5400 unsigned long data;
5401 struct i2c_client *client = to_i2c_client(dev);
5402 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5403
5404 ret = kstrtoul(buf, 16, &data);
5405 if (ret)
5406 return ret;
5407 smi130_acc->debug_level = (uint8_t)data;
5408 return count;
5409}
5410
5411static ssize_t smi130_acc_register_store(struct device *dev,
5412 struct device_attribute *attr,
5413 const char *buf, size_t count)
5414{
5415 int address, value;
5416 struct i2c_client *client = to_i2c_client(dev);
5417 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5418
5419 sscanf(buf, "%3d %3d", &address, &value);
5420 if (smi130_acc_write_reg(smi130_acc->smi130_acc_client, (unsigned char)address,
5421 (unsigned char *)&value) < 0)
5422 return -EINVAL;
5423 return count;
5424}
5425static ssize_t smi130_acc_register_show(struct device *dev,
5426 struct device_attribute *attr, char *buf)
5427{
5428
5429 struct i2c_client *client = to_i2c_client(dev);
5430 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5431
5432 size_t count = 0;
puneet597e4f12018-11-06 14:32:16 +05305433 u8 reg[0x40] = {0};
Bosch Sensortecface5922018-08-29 08:08:53 +02005434 int i;
5435
5436 for (i = 0; i < 0x40; i++) {
5437 smi130_acc_smbus_read_byte(smi130_acc->smi130_acc_client, i, reg+i);
5438
5439 count += snprintf(&buf[count], 32, "0x%x: %d\n", i, reg[i]);
5440 }
5441 return count;
5442
5443
5444}
5445
5446static ssize_t smi130_acc_range_show(struct device *dev,
5447 struct device_attribute *attr, char *buf)
5448{
5449 unsigned char data = 0;
5450 struct i2c_client *client = to_i2c_client(dev);
5451 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5452
5453 if (smi130_acc_get_range(smi130_acc->smi130_acc_client, &data) < 0)
5454 return -EINVAL;
5455
5456 return snprintf(buf, 16, "%d\n", data);
5457}
5458
5459static ssize_t smi130_acc_range_store(struct device *dev,
5460 struct device_attribute *attr,
5461 const char *buf, size_t count)
5462{
5463 unsigned long data;
5464 int error;
5465 struct i2c_client *client = to_i2c_client(dev);
5466 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5467
Puneet Yatnalcfd94842019-04-16 12:11:05 +05305468 error = smi130_check_acc_early_buff_enable_flag(smi130_acc);
5469 if (error)
5470 return count;
5471
Bosch Sensortecface5922018-08-29 08:08:53 +02005472 error = kstrtoul(buf, 10, &data);
5473 if (error)
5474 return error;
5475 if (smi130_acc_set_range(smi130_acc->smi130_acc_client, (unsigned char) data) < 0)
5476 return -EINVAL;
5477
5478 return count;
5479}
5480
5481static ssize_t smi130_acc_bandwidth_show(struct device *dev,
5482 struct device_attribute *attr, char *buf)
5483{
5484 unsigned char data = 0;
5485 struct i2c_client *client = to_i2c_client(dev);
5486 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5487
5488 if (smi130_acc_get_bandwidth(smi130_acc->smi130_acc_client, &data) < 0)
5489 return -EINVAL;
5490
5491 return snprintf(buf, 16, "%d\n", data);
5492
5493}
5494
5495static ssize_t smi130_acc_bandwidth_store(struct device *dev,
5496 struct device_attribute *attr,
5497 const char *buf, size_t count)
5498{
5499 unsigned long data;
5500 int error;
5501 struct i2c_client *client = to_i2c_client(dev);
5502 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5503
Puneet Yatnalcfd94842019-04-16 12:11:05 +05305504 error = smi130_check_acc_early_buff_enable_flag(smi130_acc);
5505 if (error)
5506 return count;
5507
Bosch Sensortecface5922018-08-29 08:08:53 +02005508 error = kstrtoul(buf, 10, &data);
5509 if (error)
5510 return error;
5511
5512 if (smi130_acc->sensor_type == SMI_ACC280_TYPE)
5513 if ((unsigned char) data > 14)
5514 return -EINVAL;
5515
5516 if (smi130_acc_set_bandwidth(smi130_acc->smi130_acc_client,
5517 (unsigned char) data) < 0)
5518 return -EINVAL;
5519 smi130_acc->base_time = 0;
5520 smi130_acc->acc_count = 0;
5521
5522 return count;
5523}
5524
5525static ssize_t smi130_acc_mode_show(struct device *dev,
5526 struct device_attribute *attr, char *buf)
5527{
5528 unsigned char data = 0;
5529 struct i2c_client *client = to_i2c_client(dev);
5530 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5531
5532 if (smi130_acc_get_mode(smi130_acc->smi130_acc_client, &data) < 0)
5533 return -EINVAL;
5534
5535 return snprintf(buf, 32, "%d %d\n", data, smi130_acc->smi_acc_mode_enabled);
5536}
5537
5538static ssize_t smi130_acc_mode_store(struct device *dev,
5539 struct device_attribute *attr,
5540 const char *buf, size_t count)
5541{
5542 unsigned long data;
5543 int error;
5544 struct i2c_client *client = to_i2c_client(dev);
5545 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5546
Puneet Yatnalcfd94842019-04-16 12:11:05 +05305547
Bosch Sensortecface5922018-08-29 08:08:53 +02005548 error = kstrtoul(buf, 10, &data);
5549 if (error)
5550 return error;
Puneet Yatnalab29efa2019-08-05 13:13:31 +05305551
5552 smi130_check_acc_enable_flag(smi130_acc, data);
5553
5554 error = smi130_check_acc_early_buff_enable_flag(smi130_acc);
5555 if (error)
5556 return count;
5557
Bosch Sensortecface5922018-08-29 08:08:53 +02005558 if (smi130_acc_set_mode(smi130_acc->smi130_acc_client,
5559 (unsigned char) data, SMI_ACC_ENABLED_BSX) < 0)
5560 return -EINVAL;
5561
5562 return count;
5563}
5564
5565static ssize_t smi130_acc_value_cache_show(struct device *dev,
5566 struct device_attribute *attr, char *buf)
5567{
5568 struct input_dev *input = to_input_dev(dev);
5569 struct smi130_acc_data *smi130_acc = input_get_drvdata(input);
5570 struct smi130_accacc acc_value;
5571
5572 mutex_lock(&smi130_acc->value_mutex);
5573 acc_value = smi130_acc->value;
5574 mutex_unlock(&smi130_acc->value_mutex);
5575
5576 return snprintf(buf, 96, "%d %d %d\n", acc_value.x, acc_value.y,
5577 acc_value.z);
5578}
5579
5580static ssize_t smi130_acc_value_show(struct device *dev,
5581 struct device_attribute *attr, char *buf)
5582{
5583 struct input_dev *input = to_input_dev(dev);
5584 struct smi130_acc_data *smi130_acc = input_get_drvdata(input);
5585 struct smi130_accacc acc_value;
5586
5587 smi130_acc_read_accel_xyz(smi130_acc->smi130_acc_client, smi130_acc->sensor_type,
5588 &acc_value);
5589
5590 return snprintf(buf, 96, "%d %d %d\n", acc_value.x, acc_value.y,
5591 acc_value.z);
5592}
5593
5594static ssize_t smi130_acc_delay_show(struct device *dev,
5595 struct device_attribute *attr, char *buf)
5596{
5597 struct i2c_client *client = to_i2c_client(dev);
5598 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5599
5600 return snprintf(buf, 16, "%d\n", atomic_read(&smi130_acc->delay));
5601
5602}
5603
5604static ssize_t smi130_acc_chip_id_show(struct device *dev,
5605 struct device_attribute *attr, char *buf)
5606{
5607 struct i2c_client *client = to_i2c_client(dev);
5608 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5609
5610 return snprintf(buf, 16, "%u\n", smi130_acc->chip_id);
5611
5612}
5613
5614
5615static ssize_t smi130_acc_place_show(struct device *dev,
5616 struct device_attribute *attr, char *buf)
5617{
5618
5619 struct i2c_client *client = to_i2c_client(dev);
5620 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5621 int place = BOSCH_SENSOR_PLACE_UNKNOWN;
5622
5623 if (NULL != smi130_acc->bosch_pd)
5624 place = smi130_acc->bosch_pd->place;
5625
5626 return snprintf(buf, 16, "%d\n", place);
5627}
5628
5629
5630static ssize_t smi130_acc_delay_store(struct device *dev,
5631 struct device_attribute *attr,
5632 const char *buf, size_t count)
5633{
5634 unsigned long data;
5635 int error;
5636 struct i2c_client *client = to_i2c_client(dev);
5637 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5638
5639 error = kstrtoul(buf, 10, &data);
5640 if (error)
5641 return error;
5642 if (data > SMI_ACC2X2_MAX_DELAY)
5643 data = SMI_ACC2X2_MAX_DELAY;
5644 atomic_set(&smi130_acc->delay, (unsigned int) data);
5645
5646 return count;
5647}
5648
5649
5650static ssize_t smi130_acc_enable_show(struct device *dev,
5651 struct device_attribute *attr, char *buf)
5652{
5653 struct i2c_client *client = to_i2c_client(dev);
5654 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5655
5656 return snprintf(buf, 16, "%d\n", atomic_read(&smi130_acc->enable));
5657
5658}
5659
5660static void smi130_acc_set_enable(struct device *dev, int enable)
5661{
5662 struct i2c_client *client = to_i2c_client(dev);
5663 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5664 int pre_enable = atomic_read(&smi130_acc->enable);
5665
5666 mutex_lock(&smi130_acc->enable_mutex);
5667 if (enable) {
5668 if (pre_enable == 0) {
5669 smi130_acc_set_mode(smi130_acc->smi130_acc_client,
5670 SMI_ACC2X2_MODE_NORMAL, SMI_ACC_ENABLED_INPUT);
5671
5672 #ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
5673 schedule_delayed_work(&smi130_acc->work,
5674 msecs_to_jiffies(atomic_read(&smi130_acc->delay)));
5675#endif
5676 atomic_set(&smi130_acc->enable, 1);
5677 }
5678
5679 } else {
5680 if (pre_enable == 1) {
5681 smi130_acc_set_mode(smi130_acc->smi130_acc_client,
5682 SMI_ACC2X2_MODE_SUSPEND, SMI_ACC_ENABLED_INPUT);
5683
5684 #ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
5685 cancel_delayed_work_sync(&smi130_acc->work);
5686#endif
5687 atomic_set(&smi130_acc->enable, 0);
5688 }
5689 }
5690 mutex_unlock(&smi130_acc->enable_mutex);
5691
5692}
5693
5694static ssize_t smi130_acc_enable_store(struct device *dev,
5695 struct device_attribute *attr,
5696 const char *buf, size_t count)
5697{
5698 unsigned long data;
5699 int error;
5700
5701 error = kstrtoul(buf, 10, &data);
5702 if (error)
5703 return error;
5704 if ((data == 0) || (data == 1))
5705 smi130_acc_set_enable(dev, data);
5706
5707 return count;
5708}
5709static ssize_t smi130_acc_fast_calibration_x_show(struct device *dev,
5710 struct device_attribute *attr, char *buf)
5711{
5712
5713
5714 unsigned char data = 0;
5715 struct i2c_client *client = to_i2c_client(dev);
5716 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5717
5718#ifdef CONFIG_SENSORS_BMI058
5719 if (smi130_acc_get_offset_target(smi130_acc->smi130_acc_client,
5720 BMI058_OFFSET_TRIGGER_X, &data) < 0)
5721 return -EINVAL;
5722#else
5723 if (smi130_acc_get_offset_target(smi130_acc->smi130_acc_client,
5724 SMI_ACC2X2_OFFSET_TRIGGER_X, &data) < 0)
5725 return -EINVAL;
5726#endif
5727
5728 return snprintf(buf, 16, "%d\n", data);
5729
5730}
5731
5732static ssize_t smi130_acc_fast_calibration_x_store(struct device *dev,
5733 struct device_attribute *attr,
5734 const char *buf, size_t count)
5735{
5736 unsigned long data;
5737 signed char tmp;
5738 unsigned char timeout = 0;
5739 int error;
5740 struct i2c_client *client = to_i2c_client(dev);
5741 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5742
5743 error = kstrtoul(buf, 10, &data);
5744 if (error)
5745 return error;
5746
5747#ifdef CONFIG_SENSORS_BMI058
5748 if (smi130_acc_set_offset_target(smi130_acc->smi130_acc_client,
5749 BMI058_OFFSET_TRIGGER_X, (unsigned char)data) < 0)
5750 return -EINVAL;
5751#else
5752 if (smi130_acc_set_offset_target(smi130_acc->smi130_acc_client,
5753 SMI_ACC2X2_OFFSET_TRIGGER_X, (unsigned char)data) < 0)
5754 return -EINVAL;
5755#endif
5756
5757 if (smi130_acc_set_cal_trigger(smi130_acc->smi130_acc_client, 1) < 0)
5758 return -EINVAL;
5759
5760 do {
5761 smi130_acc_delay(2);
5762 smi130_acc_get_cal_ready(smi130_acc->smi130_acc_client, &tmp);
5763
5764 /*PINFO("wait 2ms cal ready flag is %d\n", tmp); */
5765 timeout++;
5766 if (timeout == 50) {
5767 PINFO("get fast calibration ready error\n");
5768 return -EINVAL;
5769 };
5770
5771 } while (tmp == 0);
5772
5773 PINFO("x axis fast calibration finished\n");
5774 return count;
5775}
5776
5777static ssize_t smi130_acc_fast_calibration_y_show(struct device *dev,
5778 struct device_attribute *attr, char *buf)
5779{
5780
5781
5782 unsigned char data = 0;
5783 struct i2c_client *client = to_i2c_client(dev);
5784 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5785
5786#ifdef CONFIG_SENSORS_BMI058
5787 if (smi130_acc_get_offset_target(smi130_acc->smi130_acc_client,
5788 BMI058_OFFSET_TRIGGER_Y, &data) < 0)
5789 return -EINVAL;
5790#else
5791 if (smi130_acc_get_offset_target(smi130_acc->smi130_acc_client,
5792 SMI_ACC2X2_OFFSET_TRIGGER_Y, &data) < 0)
5793 return -EINVAL;
5794#endif
5795
5796 return snprintf(buf, 16, "%d\n", data);
5797
5798}
5799
5800static ssize_t smi130_acc_fast_calibration_y_store(struct device *dev,
5801 struct device_attribute *attr,
5802 const char *buf, size_t count)
5803{
5804 unsigned long data;
5805 signed char tmp;
5806 unsigned char timeout = 0;
5807 int error;
5808 struct i2c_client *client = to_i2c_client(dev);
5809 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5810
5811 error = kstrtoul(buf, 10, &data);
5812 if (error)
5813 return error;
5814
5815#ifdef CONFIG_SENSORS_BMI058
5816 if (smi130_acc_set_offset_target(smi130_acc->smi130_acc_client,
5817 BMI058_OFFSET_TRIGGER_Y, (unsigned char)data) < 0)
5818 return -EINVAL;
5819#else
5820 if (smi130_acc_set_offset_target(smi130_acc->smi130_acc_client,
5821 SMI_ACC2X2_OFFSET_TRIGGER_Y, (unsigned char)data) < 0)
5822 return -EINVAL;
5823#endif
5824
5825 if (smi130_acc_set_cal_trigger(smi130_acc->smi130_acc_client, 2) < 0)
5826 return -EINVAL;
5827
5828 do {
5829 smi130_acc_delay(2);
5830 smi130_acc_get_cal_ready(smi130_acc->smi130_acc_client, &tmp);
5831
5832 /*PINFO("wait 2ms cal ready flag is %d\n", tmp);*/
5833 timeout++;
5834 if (timeout == 50) {
5835 PINFO("get fast calibration ready error\n");
5836 return -EINVAL;
5837 };
5838
5839 } while (tmp == 0);
5840
5841 PINFO("y axis fast calibration finished\n");
5842 return count;
5843}
5844
5845static ssize_t smi130_acc_fast_calibration_z_show(struct device *dev,
5846 struct device_attribute *attr, char *buf)
5847{
5848
5849
5850 unsigned char data = 0;
5851 struct i2c_client *client = to_i2c_client(dev);
5852 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5853
5854 if (smi130_acc_get_offset_target(smi130_acc->smi130_acc_client, 3, &data) < 0)
5855 return -EINVAL;
5856
5857 return snprintf(buf, 16, "%d\n", data);
5858
5859}
5860
5861static ssize_t smi130_acc_fast_calibration_z_store(struct device *dev,
5862 struct device_attribute *attr,
5863 const char *buf, size_t count)
5864{
5865 unsigned long data;
5866 signed char tmp;
5867 unsigned char timeout = 0;
5868 int error;
5869 struct i2c_client *client = to_i2c_client(dev);
5870 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5871
5872 error = kstrtoul(buf, 10, &data);
5873 if (error)
5874 return error;
5875
5876 if (smi130_acc_set_offset_target(smi130_acc->smi130_acc_client, 3, (unsigned
5877 char)data) < 0)
5878 return -EINVAL;
5879
5880 if (smi130_acc_set_cal_trigger(smi130_acc->smi130_acc_client, 3) < 0)
5881 return -EINVAL;
5882
5883 do {
5884 smi130_acc_delay(2);
5885 smi130_acc_get_cal_ready(smi130_acc->smi130_acc_client, &tmp);
5886
5887 /*PINFO("wait 2ms cal ready flag is %d\n", tmp);*/
5888 timeout++;
5889 if (timeout == 50) {
5890 PINFO("get fast calibration ready error\n");
5891 return -EINVAL;
5892 };
5893
5894 } while (tmp == 0);
5895
5896 PINFO("z axis fast calibration finished\n");
5897 return count;
5898}
5899
5900
5901static ssize_t smi130_acc_SleepDur_show(struct device *dev,
5902 struct device_attribute *attr, char *buf)
5903{
5904 unsigned char data = 0;
5905 struct i2c_client *client = to_i2c_client(dev);
5906 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5907
5908 if (smi130_acc_get_sleep_duration(smi130_acc->smi130_acc_client, &data) < 0)
5909 return -EINVAL;
5910
5911 return snprintf(buf, 16, "%d\n", data);
5912
5913}
5914
5915static ssize_t smi130_acc_SleepDur_store(struct device *dev,
5916 struct device_attribute *attr,
5917 const char *buf, size_t count)
5918{
5919 unsigned long data;
5920 int error;
5921 struct i2c_client *client = to_i2c_client(dev);
5922 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5923
5924 error = kstrtoul(buf, 10, &data);
5925 if (error)
5926 return error;
5927 if (smi130_acc_set_sleep_duration(smi130_acc->smi130_acc_client,
5928 (unsigned char) data) < 0)
5929 return -EINVAL;
5930
5931 return count;
5932}
5933
5934static ssize_t smi130_acc_fifo_mode_show(struct device *dev,
5935 struct device_attribute *attr, char *buf)
5936{
5937 unsigned char data = 0;
5938 struct i2c_client *client = to_i2c_client(dev);
5939 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5940
5941 if (smi130_acc_get_fifo_mode(smi130_acc->smi130_acc_client, &data) < 0)
5942 return -EINVAL;
5943
5944 return snprintf(buf, 16, "%d\n", data);
5945
5946}
5947
5948static ssize_t smi130_acc_fifo_mode_store(struct device *dev,
5949 struct device_attribute *attr,
5950 const char *buf, size_t count)
5951{
5952 unsigned long data;
5953 int error;
5954 struct i2c_client *client = to_i2c_client(dev);
5955 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5956
5957 error = kstrtoul(buf, 10, &data);
5958 if (error)
5959 return error;
5960 if (smi130_acc_set_fifo_mode(smi130_acc->smi130_acc_client,
5961 (unsigned char) data) < 0)
5962 return -EINVAL;
5963 return count;
5964}
5965
5966
5967
5968static ssize_t smi130_acc_fifo_trig_show(struct device *dev,
5969 struct device_attribute *attr, char *buf)
5970{
5971 unsigned char data = 0;
5972 struct i2c_client *client = to_i2c_client(dev);
5973 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5974
5975 if (smi130_acc_get_fifo_trig(smi130_acc->smi130_acc_client, &data) < 0)
5976 return -EINVAL;
5977
5978 return snprintf(buf, 16, "%d\n", data);
5979
5980}
5981
5982static ssize_t smi130_acc_fifo_trig_store(struct device *dev,
5983 struct device_attribute *attr,
5984 const char *buf, size_t count)
5985{
5986 unsigned long data;
5987 int error;
5988 struct i2c_client *client = to_i2c_client(dev);
5989 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
5990
5991 error = kstrtoul(buf, 10, &data);
5992 if (error)
5993 return error;
5994 if (smi130_acc_set_fifo_trig(smi130_acc->smi130_acc_client,
5995 (unsigned char) data) < 0)
5996 return -EINVAL;
5997
5998 return count;
5999}
6000
6001
6002
6003static ssize_t smi130_acc_fifo_trig_src_show(struct device *dev,
6004 struct device_attribute *attr, char *buf)
6005{
6006 unsigned char data = 0;
6007 struct i2c_client *client = to_i2c_client(dev);
6008 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6009
6010 if (smi130_acc_get_fifo_trig_src(smi130_acc->smi130_acc_client, &data) < 0)
6011 return -EINVAL;
6012
6013 return snprintf(buf, 16, "%d\n", data);
6014
6015}
6016
6017static ssize_t smi130_acc_fifo_trig_src_store(struct device *dev,
6018 struct device_attribute *attr,
6019 const char *buf, size_t count)
6020{
6021 unsigned long data;
6022 int error;
6023 struct i2c_client *client = to_i2c_client(dev);
6024 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6025
6026 error = kstrtoul(buf, 10, &data);
6027 if (error)
6028 return error;
6029 if (smi130_acc_set_fifo_trig_src(smi130_acc->smi130_acc_client,
6030 (unsigned char) data) < 0)
6031 return -EINVAL;
6032
6033 return count;
6034}
6035
6036
6037/*!
6038 * @brief show fifo_data_sel axis definition(Android definition, not sensor HW reg).
6039 * 0--> x, y, z axis fifo data for every frame
6040 * 1--> only x axis fifo data for every frame
6041 * 2--> only y axis fifo data for every frame
6042 * 3--> only z axis fifo data for every frame
6043 */
6044static ssize_t smi130_acc_fifo_data_sel_show(struct device *dev,
6045 struct device_attribute *attr, char *buf)
6046{
6047 unsigned char data = 0;
6048 struct i2c_client *client = to_i2c_client(dev);
6049 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6050 signed char place = BOSCH_SENSOR_PLACE_UNKNOWN;
6051 if (smi130_acc_get_fifo_data_sel(smi130_acc->smi130_acc_client, &data) < 0)
6052 return -EINVAL;
6053
6054#ifdef CONFIG_SENSORS_BMI058
6055/*Update BMI058 fifo_data_sel to the SMI130_ACC common definition*/
6056 if (BMI058_FIFO_DAT_SEL_X == data)
6057 data = SMI_ACC2X2_FIFO_DAT_SEL_X;
6058 else if (BMI058_FIFO_DAT_SEL_Y == data)
6059 data = SMI_ACC2X2_FIFO_DAT_SEL_Y;
6060#endif
6061
6062 /*remaping fifo_dat_sel if define virtual place in BSP files*/
6063 if ((NULL != smi130_acc->bosch_pd) &&
6064 (BOSCH_SENSOR_PLACE_UNKNOWN != smi130_acc->bosch_pd->place)) {
6065 place = smi130_acc->bosch_pd->place;
6066 /* sensor with place 0 needs not to be remapped */
6067 if ((place > 0) && (place < MAX_AXIS_REMAP_TAB_SZ)) {
6068 /* SMI_ACC2X2_FIFO_DAT_SEL_X: 1, Y:2, Z:3;
6069 * but bosch_axis_remap_tab_dft[i].src_x:0, y:1, z:2
6070 * so we need to +1*/
6071 if (SMI_ACC2X2_FIFO_DAT_SEL_X == data)
6072 data = bosch_axis_remap_tab_dft[place].src_x + 1;
6073 else if (SMI_ACC2X2_FIFO_DAT_SEL_Y == data)
6074 data = bosch_axis_remap_tab_dft[place].src_y + 1;
6075 }
6076 }
6077
6078 return snprintf(buf, 16, "%d\n", data);
6079
6080}
6081
6082static ssize_t smi130_acc_fifo_framecount_show(struct device *dev,
6083 struct device_attribute *attr, char *buf)
6084{
6085 unsigned char data = 0;
6086 unsigned char mode;
6087 struct i2c_client *client = to_i2c_client(dev);
6088 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6089
6090 if (smi130_acc_get_fifo_framecount(smi130_acc->smi130_acc_client, &data) < 0)
6091 return -EINVAL;
6092
6093 if (data > MAX_FIFO_F_LEVEL) {
6094
6095 if (smi130_acc_get_mode(smi130_acc->smi130_acc_client, &mode) < 0)
6096 return -EINVAL;
6097
6098 if (SMI_ACC2X2_MODE_NORMAL == mode) {
6099 PERR("smi130_acc fifo_count: %d abnormal, op_mode: %d",
6100 data, mode);
6101 data = MAX_FIFO_F_LEVEL;
6102 } else {
6103 /*chip already suspend or shutdown*/
6104 data = 0;
6105 }
6106 }
6107
6108 return snprintf(buf, 16, "%d\n", data);
6109}
6110
6111static ssize_t smi130_acc_fifo_framecount_store(struct device *dev,
6112 struct device_attribute *attr,
6113 const char *buf, size_t count)
6114{
6115 unsigned long data;
6116 int error;
6117 struct i2c_client *client = to_i2c_client(dev);
6118 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6119
6120 error = kstrtoul(buf, 10, &data);
6121 if (error)
6122 return error;
6123 smi130_acc->fifo_count = (unsigned int) data;
6124
6125 return count;
6126}
6127
6128static ssize_t smi130_acc_temperature_show(struct device *dev,
6129 struct device_attribute *attr, char *buf)
6130{
6131 unsigned char data = 0;
6132 struct i2c_client *client = to_i2c_client(dev);
6133 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6134
6135 if (smi130_acc_read_temperature(smi130_acc->smi130_acc_client, &data) < 0)
6136 return -EINVAL;
6137
6138 return snprintf(buf, 16, "%d\n", data);
6139
6140}
6141
6142/*!
6143 * @brief store fifo_data_sel axis definition(Android definition, not sensor HW reg).
6144 * 0--> x, y, z axis fifo data for every frame
6145 * 1--> only x axis fifo data for every frame
6146 * 2--> only y axis fifo data for every frame
6147 * 3--> only z axis fifo data for every frame
6148 */
6149static ssize_t smi130_acc_fifo_data_sel_store(struct device *dev,
6150 struct device_attribute *attr,
6151 const char *buf, size_t count)
6152{
6153 unsigned long data;
6154 int error;
6155 struct i2c_client *client = to_i2c_client(dev);
6156 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6157 signed char place;
6158
6159 error = kstrtoul(buf, 10, &data);
6160 if (error)
6161 return error;
6162 /*save fifo_data_sel(android definition)*/
6163 smi130_acc->fifo_datasel = (unsigned char) data;
6164
6165 /*remaping fifo_dat_sel if define virtual place*/
6166 if ((NULL != smi130_acc->bosch_pd) &&
6167 (BOSCH_SENSOR_PLACE_UNKNOWN != smi130_acc->bosch_pd->place)) {
6168 place = smi130_acc->bosch_pd->place;
6169 /* sensor with place 0 needs not to be remapped */
6170 if ((place > 0) && (place < MAX_AXIS_REMAP_TAB_SZ)) {
6171 /*Need X Y axis revesal sensor place: P1, P3, P5, P7 */
6172 /* SMI_ACC2X2_FIFO_DAT_SEL_X: 1, Y:2, Z:3;
6173 * but bosch_axis_remap_tab_dft[i].src_x:0, y:1, z:2
6174 * so we need to +1*/
6175 if (SMI_ACC2X2_FIFO_DAT_SEL_X == data)
6176 data = bosch_axis_remap_tab_dft[place].src_x + 1;
6177 else if (SMI_ACC2X2_FIFO_DAT_SEL_Y == data)
6178 data = bosch_axis_remap_tab_dft[place].src_y + 1;
6179 }
6180 }
6181#ifdef CONFIG_SENSORS_BMI058
6182 /*Update BMI058 fifo_data_sel to the SMI130_ACC common definition*/
6183 if (SMI_ACC2X2_FIFO_DAT_SEL_X == data)
6184 data = BMI058_FIFO_DAT_SEL_X;
6185 else if (SMI_ACC2X2_FIFO_DAT_SEL_Y == data)
6186 data = BMI058_FIFO_DAT_SEL_Y;
6187
6188#endif
6189 if (smi130_acc_set_fifo_data_sel(smi130_acc->smi130_acc_client,
6190 (unsigned char) data) < 0)
6191 return -EINVAL;
6192
6193 return count;
6194}
6195
6196static ssize_t smi130_acc_fifo_data_out_frame_show(struct device *dev,
6197 struct device_attribute *attr, char *buf)
6198{
6199 unsigned char f_len = 0;
6200 unsigned char count = 0;
6201 struct i2c_client *client = to_i2c_client(dev);
6202 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6203 if (smi130_acc->fifo_datasel) {
6204 /*Select one axis data output for every fifo frame*/
6205 f_len = 2;
6206 } else {
6207 /*Select X Y Z axis data output for every fifo frame*/
6208 f_len = 6;
6209 }
6210 if (smi130_acc_get_fifo_framecount(smi130_acc->smi130_acc_client, &count) < 0) {
6211 PERR("smi130_acc_get_fifo_framecount err\n");
6212 return -EINVAL;
6213 }
6214 if (count == 0)
6215 return 0;
6216 if (smi_acc_i2c_burst_read(smi130_acc->smi130_acc_client,
6217 SMI_ACC2X2_FIFO_DATA_OUTPUT_REG, buf,
6218 count * f_len) < 0)
6219 return -EINVAL;
6220
6221 return count * f_len;
6222}
6223
6224static ssize_t smi130_acc_offset_x_show(struct device *dev,
6225 struct device_attribute *attr, char *buf)
6226{
6227 unsigned char data = 0;
6228 struct i2c_client *client = to_i2c_client(dev);
6229 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6230
6231 if (smi130_acc_get_offset_x(smi130_acc->smi130_acc_client, &data) < 0)
6232 return snprintf(buf, 48, "Read error\n");
6233
6234 return snprintf(buf, 16, "%d\n", data);
6235
6236}
6237
6238static ssize_t smi130_acc_offset_x_store(struct device *dev,
6239 struct device_attribute *attr,
6240 const char *buf, size_t count)
6241{
6242 unsigned long data;
6243 int error;
6244 struct i2c_client *client = to_i2c_client(dev);
6245 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6246
6247 error = kstrtoul(buf, 10, &data);
6248 if (error)
6249 return error;
6250
6251 if (smi130_acc_set_offset_x(smi130_acc->smi130_acc_client, (unsigned
6252 char)data) < 0)
6253 return -EINVAL;
6254
6255 return count;
6256}
6257
6258static ssize_t smi130_acc_offset_y_show(struct device *dev,
6259 struct device_attribute *attr, char *buf)
6260{
6261 unsigned char data = 0;
6262 struct i2c_client *client = to_i2c_client(dev);
6263 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6264
6265 if (smi130_acc_get_offset_y(smi130_acc->smi130_acc_client, &data) < 0)
6266 return snprintf(buf, 48, "Read error\n");
6267
6268 return snprintf(buf, 16, "%d\n", data);
6269
6270}
6271
6272static ssize_t smi130_acc_offset_y_store(struct device *dev,
6273 struct device_attribute *attr,
6274 const char *buf, size_t count)
6275{
6276 unsigned long data;
6277 int error;
6278 struct i2c_client *client = to_i2c_client(dev);
6279 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6280
6281 error = kstrtoul(buf, 10, &data);
6282 if (error)
6283 return error;
6284
6285 if (smi130_acc_set_offset_y(smi130_acc->smi130_acc_client, (unsigned
6286 char)data) < 0)
6287 return -EINVAL;
6288
6289 return count;
6290}
6291
6292static ssize_t smi130_acc_offset_z_show(struct device *dev,
6293 struct device_attribute *attr, char *buf)
6294{
6295 unsigned char data = 0;
6296 struct i2c_client *client = to_i2c_client(dev);
6297 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6298
6299 if (smi130_acc_get_offset_z(smi130_acc->smi130_acc_client, &data) < 0)
6300 return snprintf(buf, 48, "Read error\n");
6301
6302 return snprintf(buf, 16, "%d\n", data);
6303
6304}
6305
6306static ssize_t smi130_acc_offset_z_store(struct device *dev,
6307 struct device_attribute *attr,
6308 const char *buf, size_t count)
6309{
6310 unsigned long data;
6311 int error;
6312 struct i2c_client *client = to_i2c_client(dev);
6313 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6314
6315 error = kstrtoul(buf, 10, &data);
6316 if (error)
6317 return error;
6318
6319 if (smi130_acc_set_offset_z(smi130_acc->smi130_acc_client, (unsigned
6320 char)data) < 0)
6321 return -EINVAL;
6322
6323 return count;
6324}
6325
6326static ssize_t smi130_acc_driver_version_show(struct device *dev
6327 , struct device_attribute *attr, char *buf)
6328{
6329 struct i2c_client *client = to_i2c_client(dev);
6330 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6331 int ret;
6332
6333 if (smi130_acc == NULL) {
6334 printk(KERN_ERR "Invalid client_data pointer");
6335 return -ENODEV;
6336 }
6337
6338 ret = snprintf(buf, 128, "Driver version: %s\n",
6339 DRIVER_VERSION);
6340 return ret;
6341}
6342
6343#ifdef CONFIG_SIG_MOTION
6344static int smi130_acc_set_en_slope_int(struct smi130_acc_data *smi130_acc,
6345 int en)
6346{
6347 int err;
6348 struct i2c_client *client = smi130_acc->smi130_acc_client;
6349
6350 if (en) {
6351 /* Set the related parameters which needs to be fine tuned by
6352 * interfaces: slope_threshold and slope_duration
6353 */
6354 /*dur: 192 samples ~= 3s*/
6355 err = smi130_acc_set_slope_duration(client, 0x0);
6356 err += smi130_acc_set_slope_threshold(client, 0x16);
6357
6358 /*Enable the interrupts*/
6359 err += smi130_acc_set_Int_Enable(client, 5, 1);/*Slope X*/
6360 err += smi130_acc_set_Int_Enable(client, 6, 1);/*Slope Y*/
6361 err += smi130_acc_set_Int_Enable(client, 7, 1);/*Slope Z*/
6362 #ifdef SMI_ACC2X2_ENABLE_INT1
6363 /* TODO: SLOPE can now only be routed to INT1 pin*/
6364 err += smi130_acc_set_int1_pad_sel(client, PAD_SLOP);
6365 #else
6366 /* err += smi130_acc_set_int2_pad_sel(client, PAD_SLOP); */
6367 #endif
6368 } else {
6369 err = smi130_acc_set_Int_Enable(client, 5, 0);/*Slope X*/
6370 err += smi130_acc_set_Int_Enable(client, 6, 0);/*Slope Y*/
6371 err += smi130_acc_set_Int_Enable(client, 7, 0);/*Slope Z*/
6372 }
6373 return err;
6374}
6375
6376static ssize_t smi130_acc_en_sig_motion_show(struct device *dev,
6377 struct device_attribute *attr, char *buf)
6378{
6379 struct i2c_client *client = to_i2c_client(dev);
6380 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6381
6382 return snprintf(buf, 16, "%d\n", atomic_read(&smi130_acc->en_sig_motion));
6383}
6384
6385static int smi130_acc_set_en_sig_motion(struct smi130_acc_data *smi130_acc,
6386 int en)
6387{
6388 int err = 0;
6389
6390 en = (en >= 1) ? 1 : 0; /* set sig motion sensor status */
6391
6392 if (atomic_read(&smi130_acc->en_sig_motion) != en) {
6393 if (en) {
6394 err = smi130_acc_set_mode(smi130_acc->smi130_acc_client,
6395 SMI_ACC2X2_MODE_NORMAL, SMI_ACC_ENABLED_SGM);
6396 err = smi130_acc_set_en_slope_int(smi130_acc, en);
6397 enable_irq_wake(smi130_acc->IRQ);
6398 } else {
6399 disable_irq_wake(smi130_acc->IRQ);
6400 err = smi130_acc_set_en_slope_int(smi130_acc, en);
6401 err = smi130_acc_set_mode(smi130_acc->smi130_acc_client,
6402 SMI_ACC2X2_MODE_SUSPEND, SMI_ACC_ENABLED_SGM);
6403 }
6404 atomic_set(&smi130_acc->en_sig_motion, en);
6405 }
6406 return err;
6407}
6408
6409static ssize_t smi130_acc_en_sig_motion_store(struct device *dev,
6410 struct device_attribute *attr,
6411 const char *buf, size_t count)
6412{
6413 unsigned long data;
6414 int error;
6415 struct i2c_client *client = to_i2c_client(dev);
6416 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6417
6418 error = kstrtoul(buf, 10, &data);
6419 if (error)
6420 return error;
6421
6422 if ((data == 0) || (data == 1))
6423 smi130_acc_set_en_sig_motion(smi130_acc, data);
6424
6425 return count;
6426}
6427#endif
6428
6429#ifdef CONFIG_DOUBLE_TAP
6430static int smi130_acc_set_en_single_tap_int(struct smi130_acc_data *smi130_acc, int en)
6431{
6432 int err;
6433 struct i2c_client *client = smi130_acc->smi130_acc_client;
6434
6435 if (en) {
6436 /* set tap interruption parameter here if needed.
6437 smi130_acc_set_tap_duration(client, 0xc0);
6438 smi130_acc_set_tap_threshold(client, 0x16);
6439 */
6440
6441 /*Enable the single tap interrupts*/
6442 err = smi130_acc_set_Int_Enable(client, 8, 1);
6443 #ifdef SMI_ACC2X2_ENABLE_INT1
6444 err += smi130_acc_set_int1_pad_sel(client, PAD_SINGLE_TAP);
6445 #else
6446 err += smi130_acc_set_int2_pad_sel(client, PAD_SINGLE_TAP);
6447 #endif
6448 } else {
6449 err = smi130_acc_set_Int_Enable(client, 8, 0);
6450 }
6451 return err;
6452}
6453
6454static ssize_t smi130_acc_tap_time_period_show(struct device *dev,
6455 struct device_attribute *attr, char *buf)
6456{
6457 struct i2c_client *client = to_i2c_client(dev);
6458 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6459
6460 return snprintf(buf, 16, "%d\n", smi130_acc->tap_time_period);
6461}
6462
6463static ssize_t smi130_acc_tap_time_period_store(struct device *dev,
6464 struct device_attribute *attr,
6465 const char *buf, size_t count)
6466{
6467 unsigned long data;
6468 int error;
6469 struct i2c_client *client = to_i2c_client(dev);
6470 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6471
6472 error = kstrtoul(buf, 10, &data);
6473 if (error)
6474 return error;
6475
6476 smi130_acc->tap_time_period = data;
6477
6478 return count;
6479}
6480
6481static ssize_t smi130_acc_en_double_tap_show(struct device *dev,
6482 struct device_attribute *attr, char *buf)
6483{
6484 struct i2c_client *client = to_i2c_client(dev);
6485 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6486
6487 return snprintf(buf, 16, "%d\n", atomic_read(&smi130_acc->en_double_tap));
6488}
6489
6490static int smi130_acc_set_en_double_tap(struct smi130_acc_data *smi130_acc,
6491 int en)
6492{
6493 int err = 0;
6494
6495 en = (en >= 1) ? 1 : 0;
6496
6497 if (atomic_read(&smi130_acc->en_double_tap) != en) {
6498 if (en) {
6499 err = smi130_acc_set_mode(smi130_acc->smi130_acc_client,
6500 SMI_ACC2X2_MODE_NORMAL, SMI_ACC_ENABLED_DTAP);
6501 err = smi130_acc_set_en_single_tap_int(smi130_acc, en);
6502 } else {
6503 err = smi130_acc_set_en_single_tap_int(smi130_acc, en);
6504 err = smi130_acc_set_mode(smi130_acc->smi130_acc_client,
6505 SMI_ACC2X2_MODE_SUSPEND, SMI_ACC_ENABLED_DTAP);
6506 }
6507 atomic_set(&smi130_acc->en_double_tap, en);
6508 }
6509 return err;
6510}
6511
6512static ssize_t smi130_acc_en_double_tap_store(struct device *dev,
6513 struct device_attribute *attr,
6514 const char *buf, size_t count)
6515{
6516 unsigned long data;
6517 int error;
6518 struct i2c_client *client = to_i2c_client(dev);
6519 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6520
6521 error = kstrtoul(buf, 10, &data);
6522 if (error)
6523 return error;
6524
6525 if ((data == 0) || (data == 1))
6526 smi130_acc_set_en_double_tap(smi130_acc, data);
6527
6528 return count;
6529}
6530
6531static void smi130_acc_tap_timeout_handle(unsigned long data)
6532{
6533 struct smi130_acc_data *smi130_acc = (struct smi130_acc_data *)data;
6534
6535 PINFO("tap interrupt handle, timeout\n");
6536 mutex_lock(&smi130_acc->tap_mutex);
6537 smi130_acc->tap_times = 0;
6538 mutex_unlock(&smi130_acc->tap_mutex);
6539
6540 /* if a single tap need to report, open the define */
6541#ifdef REPORT_SINGLE_TAP_WHEN_DOUBLE_TAP_SENSOR_ENABLED
6542 input_report_rel(smi130_acc->dev_interrupt,
6543 SINGLE_TAP_INTERRUPT,
6544 SINGLE_TAP_INTERRUPT_HAPPENED);
6545 input_sync(smi130_acc->dev_interrupt);
6546#endif
6547
6548}
6549#endif
6550
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306551#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
6552static int smi_acc_read_bootsampl(struct smi130_acc_data *client_data,
6553 unsigned long enable_read)
6554{
6555 int i = 0;
6556
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05306557 client_data->acc_buffer_smi130_samples = false;
6558
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306559 if (enable_read) {
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306560 for (i = 0; i < client_data->acc_bufsample_cnt; i++) {
6561 if (client_data->debug_level & 0x08)
6562 PINFO("acc=%d,x=%d,y=%d,z=%d,sec=%d,ns=%lld\n",
6563 i, client_data->smi130_acc_samplist[i]->xyz[0],
6564 client_data->smi130_acc_samplist[i]->xyz[1],
6565 client_data->smi130_acc_samplist[i]->xyz[2],
6566 client_data->smi130_acc_samplist[i]->tsec,
6567 client_data->smi130_acc_samplist[i]->tnsec);
6568 input_report_abs(client_data->accbuf_dev, ABS_X,
6569 client_data->smi130_acc_samplist[i]->xyz[0]);
6570 input_report_abs(client_data->accbuf_dev, ABS_Y,
6571 client_data->smi130_acc_samplist[i]->xyz[1]);
6572 input_report_abs(client_data->accbuf_dev, ABS_Z,
6573 client_data->smi130_acc_samplist[i]->xyz[2]);
6574 input_report_abs(client_data->accbuf_dev, ABS_RX,
6575 client_data->smi130_acc_samplist[i]->tsec);
6576 input_report_abs(client_data->accbuf_dev, ABS_RY,
6577 client_data->smi130_acc_samplist[i]->tnsec);
6578 input_sync(client_data->accbuf_dev);
6579 }
6580 } else {
6581 /* clean up */
6582 if (client_data->acc_bufsample_cnt != 0) {
6583 for (i = 0; i < SMI_ACC_MAXSAMPLE; i++)
6584 kmem_cache_free(client_data->smi_acc_cachepool,
6585 client_data->smi130_acc_samplist[i]);
6586 kmem_cache_destroy(client_data->smi_acc_cachepool);
6587 client_data->acc_bufsample_cnt = 0;
6588 }
6589
6590 }
6591 /*SYN_CONFIG indicates end of data*/
6592 input_event(client_data->accbuf_dev, EV_SYN, SYN_CONFIG, 0xFFFFFFFF);
6593 input_sync(client_data->accbuf_dev);
6594 if (client_data->debug_level & 0x08)
6595 PINFO("End of acc samples bufsample_cnt=%d\n",
6596 client_data->acc_bufsample_cnt);
6597 return 0;
6598}
6599static ssize_t read_acc_boot_sample_show(struct device *dev,
6600 struct device_attribute *attr,
6601 char *buf)
6602{
6603 struct i2c_client *client = to_i2c_client(dev);
6604 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6605
6606 return snprintf(buf, 16, "%u\n",
6607 smi130_acc->read_acc_boot_sample);
6608}
6609
6610static ssize_t read_acc_boot_sample_store(struct device *dev,
6611 struct device_attribute *attr,
6612 const char *buf, size_t count)
6613{
6614 int err;
6615 struct i2c_client *client = to_i2c_client(dev);
6616 struct smi130_acc_data *smi130_acc = i2c_get_clientdata(client);
6617 unsigned long enable = 0;
6618
6619 err = kstrtoul(buf, 10, &enable);
6620 if (err)
6621 return err;
6622 if (enable > 1) {
6623 PERR("Invalid value of input, input=%ld\n", enable);
6624 return -EINVAL;
6625 }
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05306626 mutex_lock(&smi130_acc->acc_sensor_buff);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306627 err = smi_acc_read_bootsampl(smi130_acc, enable);
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05306628 mutex_unlock(&smi130_acc->acc_sensor_buff);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306629 if (err)
6630 return err;
6631
6632 smi130_acc->read_acc_boot_sample = enable;
6633 return count;
6634}
6635#endif
6636
Bosch Sensortecface5922018-08-29 08:08:53 +02006637static DEVICE_ATTR(range, S_IRUGO | S_IWUSR,
6638 smi130_acc_range_show, smi130_acc_range_store);
6639static DEVICE_ATTR(bandwidth, S_IRUGO | S_IWUSR,
6640 smi130_acc_bandwidth_show, smi130_acc_bandwidth_store);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306641#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
6642static DEVICE_ATTR(read_acc_boot_sample, 0644,
6643 read_acc_boot_sample_show, read_acc_boot_sample_store);
6644#endif
Bosch Sensortecface5922018-08-29 08:08:53 +02006645static DEVICE_ATTR(op_mode, S_IRUGO | S_IWUSR,
6646 smi130_acc_mode_show, smi130_acc_mode_store);
6647static DEVICE_ATTR(value, S_IRUSR,
6648 smi130_acc_value_show, NULL);
6649static DEVICE_ATTR(value_cache, S_IRUSR,
6650 smi130_acc_value_cache_show, NULL);
6651static DEVICE_ATTR(delay, S_IRUGO | S_IWUSR,
6652 smi130_acc_delay_show, smi130_acc_delay_store);
6653static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR,
6654 smi130_acc_enable_show, smi130_acc_enable_store);
6655static DEVICE_ATTR(SleepDur, S_IRUGO | S_IWUSR,
6656 smi130_acc_SleepDur_show, smi130_acc_SleepDur_store);
6657static DEVICE_ATTR(fast_calibration_x, S_IRUGO | S_IWUSR,
6658 smi130_acc_fast_calibration_x_show,
6659 smi130_acc_fast_calibration_x_store);
6660static DEVICE_ATTR(fast_calibration_y, S_IRUGO | S_IWUSR,
6661 smi130_acc_fast_calibration_y_show,
6662 smi130_acc_fast_calibration_y_store);
6663static DEVICE_ATTR(fast_calibration_z, S_IRUGO | S_IWUSR,
6664 smi130_acc_fast_calibration_z_show,
6665 smi130_acc_fast_calibration_z_store);
6666static DEVICE_ATTR(fifo_mode, S_IRUGO | S_IWUSR,
6667 smi130_acc_fifo_mode_show, smi130_acc_fifo_mode_store);
6668static DEVICE_ATTR(fifo_framecount, S_IRUGO | S_IWUSR,
6669 smi130_acc_fifo_framecount_show, smi130_acc_fifo_framecount_store);
6670static DEVICE_ATTR(fifo_trig, S_IRUGO | S_IWUSR,
6671 smi130_acc_fifo_trig_show, smi130_acc_fifo_trig_store);
6672static DEVICE_ATTR(fifo_trig_src, S_IRUGO | S_IWUSR,
6673 smi130_acc_fifo_trig_src_show, smi130_acc_fifo_trig_src_store);
6674static DEVICE_ATTR(fifo_data_sel, S_IRUGO | S_IWUSR,
6675 smi130_acc_fifo_data_sel_show, smi130_acc_fifo_data_sel_store);
6676static DEVICE_ATTR(fifo_data_frame, S_IRUGO,
6677 smi130_acc_fifo_data_out_frame_show, NULL);
6678static DEVICE_ATTR(reg, S_IRUGO | S_IWUSR,
6679 smi130_acc_register_show, smi130_acc_register_store);
6680static DEVICE_ATTR(chip_id, S_IRUSR,
6681 smi130_acc_chip_id_show, NULL);
6682static DEVICE_ATTR(offset_x, S_IRUGO | S_IWUSR,
6683 smi130_acc_offset_x_show,
6684 smi130_acc_offset_x_store);
6685static DEVICE_ATTR(offset_y, S_IRUGO | S_IWUSR,
6686 smi130_acc_offset_y_show,
6687 smi130_acc_offset_y_store);
6688static DEVICE_ATTR(offset_z, S_IRUGO | S_IWUSR,
6689 smi130_acc_offset_z_show,
6690 smi130_acc_offset_z_store);
6691static DEVICE_ATTR(enable_int, S_IWUSR,
6692 NULL, smi130_acc_enable_int_store);
6693static DEVICE_ATTR(int_mode, S_IRUGO | S_IWUSR,
6694 smi130_acc_int_mode_show, smi130_acc_int_mode_store);
6695static DEVICE_ATTR(slope_duration, S_IRUGO | S_IWUSR,
6696 smi130_acc_slope_duration_show, smi130_acc_slope_duration_store);
6697static DEVICE_ATTR(slope_threshold, S_IRUGO | S_IWUSR,
6698 smi130_acc_slope_threshold_show, smi130_acc_slope_threshold_store);
6699static DEVICE_ATTR(slope_no_mot_duration, S_IRUGO | S_IWUSR,
6700 smi130_acc_slope_no_mot_duration_show,
6701 smi130_acc_slope_no_mot_duration_store);
6702static DEVICE_ATTR(slope_no_mot_threshold, S_IRUGO | S_IWUSR,
6703 smi130_acc_slope_no_mot_threshold_show,
6704 smi130_acc_slope_no_mot_threshold_store);
6705static DEVICE_ATTR(high_g_duration, S_IRUGO | S_IWUSR,
6706 smi130_acc_high_g_duration_show, smi130_acc_high_g_duration_store);
6707static DEVICE_ATTR(high_g_threshold, S_IRUGO | S_IWUSR,
6708 smi130_acc_high_g_threshold_show, smi130_acc_high_g_threshold_store);
6709static DEVICE_ATTR(low_g_duration, S_IRUGO | S_IWUSR,
6710 smi130_acc_low_g_duration_show, smi130_acc_low_g_duration_store);
6711static DEVICE_ATTR(low_g_threshold, S_IRUGO | S_IWUSR,
6712 smi130_acc_low_g_threshold_show, smi130_acc_low_g_threshold_store);
6713static DEVICE_ATTR(tap_duration, S_IRUGO | S_IWUSR,
6714 smi130_acc_tap_duration_show, smi130_acc_tap_duration_store);
6715static DEVICE_ATTR(tap_threshold, S_IRUGO | S_IWUSR,
6716 smi130_acc_tap_threshold_show, smi130_acc_tap_threshold_store);
6717static DEVICE_ATTR(tap_quiet, S_IRUGO | S_IWUSR,
6718 smi130_acc_tap_quiet_show, smi130_acc_tap_quiet_store);
6719static DEVICE_ATTR(tap_shock, S_IRUGO | S_IWUSR,
6720 smi130_acc_tap_shock_show, smi130_acc_tap_shock_store);
6721static DEVICE_ATTR(tap_samp, S_IRUGO | S_IWUSR,
6722 smi130_acc_tap_samp_show, smi130_acc_tap_samp_store);
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02006723static DEVICE_ATTR(orient_mbl_mode, S_IRUGO | S_IWUSR,
6724 smi130_acc_orient_mbl_mode_show, smi130_acc_orient_mbl_mode_store);
6725static DEVICE_ATTR(orient_mbl_blocking, S_IRUGO | S_IWUSR,
6726 smi130_acc_orient_mbl_blocking_show, smi130_acc_orient_mbl_blocking_store);
6727static DEVICE_ATTR(orient_mbl_hyst, S_IRUGO | S_IWUSR,
6728 smi130_acc_orient_mbl_hyst_show, smi130_acc_orient_mbl_hyst_store);
6729static DEVICE_ATTR(orient_mbl_theta, S_IRUGO | S_IWUSR,
6730 smi130_acc_orient_mbl_theta_show, smi130_acc_orient_mbl_theta_store);
Bosch Sensortecface5922018-08-29 08:08:53 +02006731static DEVICE_ATTR(flat_theta, S_IRUGO | S_IWUSR,
6732 smi130_acc_flat_theta_show, smi130_acc_flat_theta_store);
6733static DEVICE_ATTR(flat_hold_time, S_IRUGO | S_IWUSR,
6734 smi130_acc_flat_hold_time_show, smi130_acc_flat_hold_time_store);
6735static DEVICE_ATTR(selftest, S_IRUGO | S_IWUSR,
6736 smi130_acc_selftest_show, smi130_acc_selftest_store);
6737static DEVICE_ATTR(softreset, S_IWUSR,
6738 NULL, smi130_acc_softreset_store);
6739static DEVICE_ATTR(enable_timer, S_IRUGO | S_IWUSR,
6740 smi130_acc_enable_timer_show, smi130_acc_enable_timer_store);
6741static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
6742 smi130_acc_debug_level_show, smi130_acc_debug_level_store);
6743static DEVICE_ATTR(temperature, S_IRUSR,
6744 smi130_acc_temperature_show, NULL);
6745static DEVICE_ATTR(place, S_IRUSR,
6746 smi130_acc_place_show, NULL);
6747static DEVICE_ATTR(driver_version, S_IRUSR,
6748 smi130_acc_driver_version_show, NULL);
6749
6750#ifdef CONFIG_SIG_MOTION
6751static DEVICE_ATTR(en_sig_motion, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
6752 smi130_acc_en_sig_motion_show, smi130_acc_en_sig_motion_store);
6753#endif
6754#ifdef CONFIG_DOUBLE_TAP
6755static DEVICE_ATTR(tap_time_period, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
6756 smi130_acc_tap_time_period_show, smi130_acc_tap_time_period_store);
6757static DEVICE_ATTR(en_double_tap, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH,
6758 smi130_acc_en_double_tap_show, smi130_acc_en_double_tap_store);
6759#endif
6760
6761static struct attribute *smi130_acc_attributes[] = {
6762 &dev_attr_range.attr,
6763 &dev_attr_bandwidth.attr,
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306764#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
6765 &dev_attr_read_acc_boot_sample.attr,
6766#endif
Bosch Sensortecface5922018-08-29 08:08:53 +02006767 &dev_attr_op_mode.attr,
6768 &dev_attr_value.attr,
6769 &dev_attr_value_cache.attr,
6770 &dev_attr_delay.attr,
6771 &dev_attr_enable.attr,
6772 &dev_attr_SleepDur.attr,
6773 &dev_attr_reg.attr,
6774 &dev_attr_fast_calibration_x.attr,
6775 &dev_attr_fast_calibration_y.attr,
6776 &dev_attr_fast_calibration_z.attr,
6777 &dev_attr_fifo_mode.attr,
6778 &dev_attr_fifo_framecount.attr,
6779 &dev_attr_fifo_trig.attr,
6780 &dev_attr_fifo_trig_src.attr,
6781 &dev_attr_fifo_data_sel.attr,
6782 &dev_attr_fifo_data_frame.attr,
6783 &dev_attr_chip_id.attr,
6784 &dev_attr_offset_x.attr,
6785 &dev_attr_offset_y.attr,
6786 &dev_attr_offset_z.attr,
6787 &dev_attr_enable_int.attr,
6788 &dev_attr_enable_timer.attr,
6789 &dev_attr_debug_level.attr,
6790 &dev_attr_int_mode.attr,
6791 &dev_attr_slope_duration.attr,
6792 &dev_attr_slope_threshold.attr,
6793 &dev_attr_slope_no_mot_duration.attr,
6794 &dev_attr_slope_no_mot_threshold.attr,
6795 &dev_attr_high_g_duration.attr,
6796 &dev_attr_high_g_threshold.attr,
6797 &dev_attr_low_g_duration.attr,
6798 &dev_attr_low_g_threshold.attr,
6799 &dev_attr_tap_threshold.attr,
6800 &dev_attr_tap_duration.attr,
6801 &dev_attr_tap_quiet.attr,
6802 &dev_attr_tap_shock.attr,
6803 &dev_attr_tap_samp.attr,
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02006804 &dev_attr_orient_mbl_mode.attr,
6805 &dev_attr_orient_mbl_blocking.attr,
6806 &dev_attr_orient_mbl_hyst.attr,
6807 &dev_attr_orient_mbl_theta.attr,
Bosch Sensortecface5922018-08-29 08:08:53 +02006808 &dev_attr_flat_theta.attr,
6809 &dev_attr_flat_hold_time.attr,
6810 &dev_attr_selftest.attr,
6811 &dev_attr_softreset.attr,
6812 &dev_attr_temperature.attr,
6813 &dev_attr_place.attr,
6814 &dev_attr_driver_version.attr,
6815#ifdef CONFIG_SIG_MOTION
6816 &dev_attr_en_sig_motion.attr,
6817#endif
6818#ifdef CONFIG_DOUBLE_TAP
6819 &dev_attr_en_double_tap.attr,
6820#endif
6821
6822 NULL
6823};
6824
6825static struct attribute_group smi130_acc_attribute_group = {
6826 .attrs = smi130_acc_attributes
6827};
6828
6829#ifdef CONFIG_SIG_MOTION
6830static struct attribute *smi130_acc_sig_motion_attributes[] = {
6831 &dev_attr_slope_duration.attr,
6832 &dev_attr_slope_threshold.attr,
6833 &dev_attr_en_sig_motion.attr,
6834 NULL
6835};
6836static struct attribute_group smi130_acc_sig_motion_attribute_group = {
6837 .attrs = smi130_acc_sig_motion_attributes
6838};
6839#endif
6840
6841#ifdef CONFIG_DOUBLE_TAP
6842static struct attribute *smi130_acc_double_tap_attributes[] = {
6843 &dev_attr_tap_threshold.attr,
6844 &dev_attr_tap_duration.attr,
6845 &dev_attr_tap_quiet.attr,
6846 &dev_attr_tap_shock.attr,
6847 &dev_attr_tap_samp.attr,
6848 &dev_attr_tap_time_period.attr,
6849 &dev_attr_en_double_tap.attr,
6850 NULL
6851};
6852static struct attribute_group smi130_acc_double_tap_attribute_group = {
6853 .attrs = smi130_acc_double_tap_attributes
6854};
6855#endif
6856
6857
6858#if defined(SMI_ACC2X2_ENABLE_INT1) || defined(SMI_ACC2X2_ENABLE_INT2)
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02006859unsigned char *orient_mbl[] = {"upward looking portrait upright",
Bosch Sensortecface5922018-08-29 08:08:53 +02006860 "upward looking portrait upside-down",
6861 "upward looking landscape left",
6862 "upward looking landscape right",
6863 "downward looking portrait upright",
6864 "downward looking portrait upside-down",
6865 "downward looking landscape left",
6866 "downward looking landscape right"};
6867
6868
6869static void smi130_acc_high_g_interrupt_handle(struct smi130_acc_data *smi130_acc)
6870{
6871 unsigned char first_value = 0;
6872 unsigned char sign_value = 0;
6873 int i;
6874
6875 for (i = 0; i < 3; i++) {
6876 smi130_acc_get_HIGH_first(smi130_acc->smi130_acc_client, i, &first_value);
6877 if (first_value == 1) {
6878 smi130_acc_get_HIGH_sign(smi130_acc->smi130_acc_client,
6879 &sign_value);
6880 if (sign_value == 1) {
6881 if (i == 0)
6882 input_report_rel(smi130_acc->dev_interrupt,
6883 HIGH_G_INTERRUPT,
6884 HIGH_G_INTERRUPT_X_N);
6885 if (i == 1)
6886 input_report_rel(smi130_acc->dev_interrupt,
6887 HIGH_G_INTERRUPT,
6888 HIGH_G_INTERRUPT_Y_N);
6889 if (i == 2)
6890 input_report_rel(smi130_acc->dev_interrupt,
6891 HIGH_G_INTERRUPT,
6892 HIGH_G_INTERRUPT_Z_N);
6893 } else {
6894 if (i == 0)
6895 input_report_rel(smi130_acc->dev_interrupt,
6896 HIGH_G_INTERRUPT,
6897 HIGH_G_INTERRUPT_X);
6898 if (i == 1)
6899 input_report_rel(smi130_acc->dev_interrupt,
6900 HIGH_G_INTERRUPT,
6901 HIGH_G_INTERRUPT_Y);
6902 if (i == 2)
6903 input_report_rel(smi130_acc->dev_interrupt,
6904 HIGH_G_INTERRUPT,
6905 HIGH_G_INTERRUPT_Z);
6906 }
6907 }
6908
6909 PINFO("High G interrupt happened,exis is %d,\n\n"
6910 "first is %d,sign is %d\n", i,
6911 first_value, sign_value);
6912 }
6913
6914
6915}
6916
6917#ifndef CONFIG_SIG_MOTION
6918static void smi130_acc_slope_interrupt_handle(struct smi130_acc_data *smi130_acc)
6919{
6920 unsigned char first_value = 0;
6921 unsigned char sign_value = 0;
6922 int i;
6923 for (i = 0; i < 3; i++) {
6924 smi130_acc_get_slope_first(smi130_acc->smi130_acc_client, i, &first_value);
6925 if (first_value == 1) {
6926 smi130_acc_get_slope_sign(smi130_acc->smi130_acc_client,
6927 &sign_value);
6928 if (sign_value == 1) {
6929 if (i == 0)
6930 input_report_rel(smi130_acc->dev_interrupt,
6931 SLOP_INTERRUPT,
6932 SLOPE_INTERRUPT_X_N);
6933 if (i == 1)
6934 input_report_rel(smi130_acc->dev_interrupt,
6935 SLOP_INTERRUPT,
6936 SLOPE_INTERRUPT_Y_N);
6937 if (i == 2)
6938 input_report_rel(smi130_acc->dev_interrupt,
6939 SLOP_INTERRUPT,
6940 SLOPE_INTERRUPT_Z_N);
6941 } else {
6942 if (i == 0)
6943 input_report_rel(smi130_acc->dev_interrupt,
6944 SLOP_INTERRUPT,
6945 SLOPE_INTERRUPT_X);
6946 if (i == 1)
6947 input_report_rel(smi130_acc->dev_interrupt,
6948 SLOP_INTERRUPT,
6949 SLOPE_INTERRUPT_Y);
6950 if (i == 2)
6951 input_report_rel(smi130_acc->dev_interrupt,
6952 SLOP_INTERRUPT,
6953 SLOPE_INTERRUPT_Z);
6954
6955 }
6956 }
6957
6958 PINFO("Slop interrupt happened,exis is %d,\n\n"
6959 "first is %d,sign is %d\n", i,
6960 first_value, sign_value);
6961 }
6962}
6963#endif
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306964#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
6965static void store_acc_boot_sample(struct smi130_acc_data *client_data,
6966 int x, int y, int z, struct timespec ts)
6967{
6968 if (false == client_data->acc_buffer_smi130_samples)
6969 return;
6970 if (ts.tv_sec < client_data->max_buffer_time) {
6971 if (client_data->acc_bufsample_cnt < SMI_ACC_MAXSAMPLE) {
6972 client_data->smi130_acc_samplist[client_data->
6973 acc_bufsample_cnt]->xyz[0] = x;
6974 client_data->smi130_acc_samplist[client_data->
6975 acc_bufsample_cnt]->xyz[1] = y;
6976 client_data->smi130_acc_samplist[client_data->
6977 acc_bufsample_cnt]->xyz[2] = z;
6978 client_data->smi130_acc_samplist[client_data->
6979 acc_bufsample_cnt]->tsec = ts.tv_sec;
6980 client_data->smi130_acc_samplist[client_data->
6981 acc_bufsample_cnt]->tnsec = ts.tv_nsec;
6982 client_data->acc_bufsample_cnt++;
6983 }
6984 } else {
6985 PINFO("End of ACC buffering %d\n",
6986 client_data->acc_bufsample_cnt);
6987 client_data->acc_buffer_smi130_samples = false;
Puneet Yatnalab29efa2019-08-05 13:13:31 +05306988 if (client_data->acc_enable == false)
6989 smi130_acc_set_mode(client_data->smi130_acc_client,
6990 SMI_ACC2X2_MODE_SUSPEND, 1);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05306991 }
6992}
6993#else
6994static void store_acc_boot_sample(struct smi130_acc_data *client_data,
6995 int x, int y, int z, struct timespec ts)
6996{
6997}
6998#endif
6999
7000#ifdef CONFIG_ENABLE_SMI_ACC_GYRO_BUFFERING
7001static int smi130_acc_early_buff_init(struct i2c_client *client,
7002 struct smi130_acc_data *client_data)
7003{
7004 int i = 0, err = 0;
7005
7006 client_data->acc_bufsample_cnt = 0;
7007 client_data->report_evt_cnt = 5;
7008 client_data->max_buffer_time = 40;
7009
7010 client_data->smi_acc_cachepool = kmem_cache_create("acc_sensor_sample",
7011 sizeof(struct smi_acc_sample),
7012 0,
7013 SLAB_HWCACHE_ALIGN, NULL);
7014 if (!client_data->smi_acc_cachepool) {
7015 PERR("smi_acc_cachepool cache create failed\n");
7016 err = -ENOMEM;
puneet597e4f12018-11-06 14:32:16 +05307017 return 0;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307018 }
7019 for (i = 0; i < SMI_ACC_MAXSAMPLE; i++) {
7020 client_data->smi130_acc_samplist[i] =
7021 kmem_cache_alloc(client_data->smi_acc_cachepool,
7022 GFP_KERNEL);
7023 if (!client_data->smi130_acc_samplist[i]) {
7024 err = -ENOMEM;
puneet597e4f12018-11-06 14:32:16 +05307025 goto clean_exit1;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307026 }
7027 }
7028
7029 client_data->accbuf_dev = input_allocate_device();
7030 if (!client_data->accbuf_dev) {
7031 err = -ENOMEM;
7032 PERR("input device allocation failed\n");
puneet597e4f12018-11-06 14:32:16 +05307033 goto clean_exit1;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307034 }
7035 client_data->accbuf_dev->name = "smi130_accbuf";
7036 client_data->accbuf_dev->id.bustype = BUS_I2C;
7037 input_set_events_per_packet(client_data->accbuf_dev,
7038 client_data->report_evt_cnt * SMI_ACC_MAXSAMPLE);
7039 set_bit(EV_ABS, client_data->accbuf_dev->evbit);
7040 input_set_abs_params(client_data->accbuf_dev, ABS_X,
7041 -G_MAX, G_MAX, 0, 0);
7042 input_set_abs_params(client_data->accbuf_dev, ABS_Y,
7043 -G_MAX, G_MAX, 0, 0);
7044 input_set_abs_params(client_data->accbuf_dev, ABS_Z,
7045 -G_MAX, G_MAX, 0, 0);
7046 input_set_abs_params(client_data->accbuf_dev, ABS_RX,
7047 -G_MAX, G_MAX, 0, 0);
7048 input_set_abs_params(client_data->accbuf_dev, ABS_RY,
7049 -G_MAX, G_MAX, 0, 0);
7050 err = input_register_device(client_data->accbuf_dev);
7051 if (err) {
7052 PERR("unable to register input device %s\n",
7053 client_data->accbuf_dev->name);
puneet597e4f12018-11-06 14:32:16 +05307054 goto clean_exit2;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307055 }
7056
7057 client_data->acc_buffer_smi130_samples = true;
Puneet Yatnalab29efa2019-08-05 13:13:31 +05307058 client_data->acc_enable = false;
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307059
puneet597e4f12018-11-06 14:32:16 +05307060 smi130_set_cpu_idle_state(true);
7061
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05307062 mutex_init(&client_data->acc_sensor_buff);
7063
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307064 smi130_acc_set_mode(client, SMI_ACC2X2_MODE_NORMAL, 1);
7065 smi130_acc_set_bandwidth(client, SMI_ACC2X2_BW_62_50HZ);
7066 smi130_acc_set_range(client, SMI_ACC2X2_RANGE_2G);
7067
7068 return 1;
7069
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307070clean_exit2:
puneet597e4f12018-11-06 14:32:16 +05307071 input_free_device(client_data->accbuf_dev);
7072clean_exit1:
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307073 for (i = 0; i < SMI_ACC_MAXSAMPLE; i++)
7074 kmem_cache_free(client_data->smi_acc_cachepool,
7075 client_data->smi130_acc_samplist[i]);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307076 kmem_cache_destroy(client_data->smi_acc_cachepool);
7077 return 0;
7078}
7079
7080static void smi130_acc_input_cleanup(struct smi130_acc_data *client_data)
7081{
7082 int i = 0;
7083
7084 input_unregister_device(client_data->accbuf_dev);
7085 input_free_device(client_data->accbuf_dev);
7086 for (i = 0; i < SMI_ACC_MAXSAMPLE; i++)
7087 kmem_cache_free(client_data->smi_acc_cachepool,
7088 client_data->smi130_acc_samplist[i]);
7089 kmem_cache_destroy(client_data->smi_acc_cachepool);
7090}
7091#else
7092static int smi130_acc_early_buff_init(struct i2c_client *client,
7093 struct smi130_acc_data *client_data)
7094{
7095 return 1;
7096}
7097static void smi130_acc_input_cleanup(struct smi130_acc_data *client_data)
7098{
7099}
7100#endif
Bosch Sensortecface5922018-08-29 08:08:53 +02007101
puneet597e4f12018-11-06 14:32:16 +05307102static irqreturn_t smi130_acc_irq_work_func(int irq, void *handle)
Bosch Sensortecface5922018-08-29 08:08:53 +02007103{
puneet597e4f12018-11-06 14:32:16 +05307104 struct smi130_acc_data *smi130_acc = handle;
Bosch Sensortecface5922018-08-29 08:08:53 +02007105#ifdef CONFIG_DOUBLE_TAP
7106 struct i2c_client *client = smi130_acc->smi130_acc_client;
7107#endif
7108
7109 unsigned char status = 0;
7110 unsigned char first_value = 0;
7111 unsigned char sign_value = 0;
7112
7113#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7114 static struct smi130_accacc acc;
7115 struct timespec ts;
7116 /*
7117 do not use this function judge new data interrupt
7118 smi130_acc_get_interruptstatus2(smi130_acc->smi130_acc_client, &status);
7119 use the
7120 x-axis value bit new_data_x
7121 y-axis value bit new_data_y
7122 z-axis value bit new_data_z
7123 judge if this is the new data
7124 */
7125 /* PINFO("New data interrupt happened\n");*/
7126 smi130_acc_read_accel_xyz(smi130_acc->smi130_acc_client,
7127 smi130_acc->sensor_type, &acc);
7128 ts = ns_to_timespec(smi130_acc->timestamp);
7129 //if ((acc.x & SMI_ACC2X2_NEW_DATA_X__MSK) &&
7130 // (acc.y & SMI_ACC2X2_NEW_DATA_Y__MSK) &&
7131 // (acc.x & SMI_ACC2X2_NEW_DATA_Z__MSK))
7132 {
7133 input_event(smi130_acc->input, EV_MSC, MSC_TIME,
7134 ts.tv_sec);
7135 input_event(smi130_acc->input, EV_MSC, MSC_TIME,
7136 ts.tv_nsec);
7137 input_event(smi130_acc->input, EV_MSC,
7138 MSC_GESTURE, acc.x);
7139 input_event(smi130_acc->input, EV_MSC,
7140 MSC_RAW, acc.y);
7141 input_event(smi130_acc->input, EV_MSC,
7142 MSC_SCAN, acc.z);
7143 input_sync(smi130_acc->input);
7144 mutex_lock(&smi130_acc->value_mutex);
7145 smi130_acc->value = acc;
7146 mutex_unlock(&smi130_acc->value_mutex);
7147 }
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05307148 mutex_lock(&smi130_acc->acc_sensor_buff);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307149 store_acc_boot_sample(smi130_acc, acc.x, acc.y, acc.z, ts);
Puneet Yatnal3cbaa6f2020-01-08 18:09:41 +05307150 mutex_unlock(&smi130_acc->acc_sensor_buff);
Bosch Sensortecface5922018-08-29 08:08:53 +02007151
puneet597e4f12018-11-06 14:32:16 +05307152 smi130_set_cpu_idle_state(false);
7153 return IRQ_HANDLED;
7154#endif
Bosch Sensortecface5922018-08-29 08:08:53 +02007155 smi130_acc_get_interruptstatus1(smi130_acc->smi130_acc_client, &status);
Puneet Yatnal645c8f32018-12-13 12:53:44 +05307156 PDEBUG("smi130_acc_irq_work_func, status = 0x%x\n", status);
Bosch Sensortecface5922018-08-29 08:08:53 +02007157
7158#ifdef CONFIG_SIG_MOTION
7159 if (status & 0x04) {
7160 if (atomic_read(&smi130_acc->en_sig_motion) == 1) {
7161 PINFO("Significant motion interrupt happened\n");
7162 /* close sig sensor,
7163 it will be open again if APP wants */
7164 smi130_acc_set_en_sig_motion(smi130_acc, 0);
7165
7166 input_report_rel(smi130_acc->dev_interrupt,
7167 SLOP_INTERRUPT, 1);
7168 input_sync(smi130_acc->dev_interrupt);
7169 }
7170 }
7171#endif
7172
7173#ifdef CONFIG_DOUBLE_TAP
7174 if (status & 0x20) {
7175 if (atomic_read(&smi130_acc->en_double_tap) == 1) {
7176 PINFO("single tap interrupt happened\n");
7177 smi130_acc_set_Int_Enable(client, 8, 0);
7178 if (smi130_acc->tap_times == 0) {
7179 mod_timer(&smi130_acc->tap_timer, jiffies +
7180 msecs_to_jiffies(smi130_acc->tap_time_period));
7181 smi130_acc->tap_times = 1;
7182 } else {
7183 /* only double tap is judged */
7184 PINFO("double tap\n");
7185 mutex_lock(&smi130_acc->tap_mutex);
7186 smi130_acc->tap_times = 0;
7187 del_timer(&smi130_acc->tap_timer);
7188 mutex_unlock(&smi130_acc->tap_mutex);
7189 input_report_rel(smi130_acc->dev_interrupt,
7190 DOUBLE_TAP_INTERRUPT,
7191 DOUBLE_TAP_INTERRUPT_HAPPENED);
7192 input_sync(smi130_acc->dev_interrupt);
7193 }
7194 smi130_acc_set_Int_Enable(client, 8, 1);
7195 }
7196 }
7197#endif
7198
7199 switch (status) {
7200
7201 case 0x01:
7202 PINFO("Low G interrupt happened\n");
7203 input_report_rel(smi130_acc->dev_interrupt, LOW_G_INTERRUPT,
7204 LOW_G_INTERRUPT_HAPPENED);
7205 break;
7206
7207 case 0x02:
7208 smi130_acc_high_g_interrupt_handle(smi130_acc);
7209 break;
7210
7211#ifndef CONFIG_SIG_MOTION
7212 case 0x04:
7213 smi130_acc_slope_interrupt_handle(smi130_acc);
7214 break;
7215#endif
7216
7217 case 0x08:
7218 PINFO("slow/ no motion interrupt happened\n");
7219 input_report_rel(smi130_acc->dev_interrupt,
7220 SLOW_NO_MOTION_INTERRUPT,
7221 SLOW_NO_MOTION_INTERRUPT_HAPPENED);
7222 break;
7223
7224#ifndef CONFIG_DOUBLE_TAP
7225 case 0x10:
7226 PINFO("double tap interrupt happened\n");
7227 input_report_rel(smi130_acc->dev_interrupt,
7228 DOUBLE_TAP_INTERRUPT,
7229 DOUBLE_TAP_INTERRUPT_HAPPENED);
7230 break;
7231 case 0x20:
7232 PINFO("single tap interrupt happened\n");
7233 input_report_rel(smi130_acc->dev_interrupt,
7234 SINGLE_TAP_INTERRUPT,
7235 SINGLE_TAP_INTERRUPT_HAPPENED);
7236 break;
7237#endif
7238
7239 case 0x40:
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02007240 smi130_acc_get_orient_mbl_status(smi130_acc->smi130_acc_client,
Bosch Sensortecface5922018-08-29 08:08:53 +02007241 &first_value);
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02007242 PINFO("orient_mbl interrupt happened,%s\n",
7243 orient_mbl[first_value]);
Bosch Sensortecface5922018-08-29 08:08:53 +02007244 if (first_value == 0)
7245 input_report_abs(smi130_acc->dev_interrupt,
7246 ORIENT_INTERRUPT,
7247 UPWARD_PORTRAIT_UP_INTERRUPT_HAPPENED);
7248 else if (first_value == 1)
7249 input_report_abs(smi130_acc->dev_interrupt,
7250 ORIENT_INTERRUPT,
7251 UPWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED);
7252 else if (first_value == 2)
7253 input_report_abs(smi130_acc->dev_interrupt,
7254 ORIENT_INTERRUPT,
7255 UPWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED);
7256 else if (first_value == 3)
7257 input_report_abs(smi130_acc->dev_interrupt,
7258 ORIENT_INTERRUPT,
7259 UPWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED);
7260 else if (first_value == 4)
7261 input_report_abs(smi130_acc->dev_interrupt,
7262 ORIENT_INTERRUPT,
7263 DOWNWARD_PORTRAIT_UP_INTERRUPT_HAPPENED);
7264 else if (first_value == 5)
7265 input_report_abs(smi130_acc->dev_interrupt,
7266 ORIENT_INTERRUPT,
7267 DOWNWARD_PORTRAIT_DOWN_INTERRUPT_HAPPENED);
7268 else if (first_value == 6)
7269 input_report_abs(smi130_acc->dev_interrupt,
7270 ORIENT_INTERRUPT,
7271 DOWNWARD_LANDSCAPE_LEFT_INTERRUPT_HAPPENED);
7272 else if (first_value == 7)
7273 input_report_abs(smi130_acc->dev_interrupt,
7274 ORIENT_INTERRUPT,
7275 DOWNWARD_LANDSCAPE_RIGHT_INTERRUPT_HAPPENED);
7276 break;
7277 case 0x80:
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02007278 smi130_acc_get_orient_mbl_flat_status(smi130_acc->smi130_acc_client,
Bosch Sensortecface5922018-08-29 08:08:53 +02007279 &sign_value);
7280 PINFO("flat interrupt happened,flat status is %d\n",
7281 sign_value);
7282 if (sign_value == 1) {
7283 input_report_abs(smi130_acc->dev_interrupt,
7284 FLAT_INTERRUPT,
7285 FLAT_INTERRUPT_TURE_HAPPENED);
7286 } else {
7287 input_report_abs(smi130_acc->dev_interrupt,
7288 FLAT_INTERRUPT,
7289 FLAT_INTERRUPT_FALSE_HAPPENED);
7290 }
7291 break;
7292
7293 default:
7294 break;
7295 }
7296}
7297
7298static irqreturn_t smi130_acc_irq_handler(int irq, void *handle)
7299{
7300 struct smi130_acc_data *data = handle;
7301
7302 if (data == NULL)
7303 return IRQ_HANDLED;
7304 if (data->smi130_acc_client == NULL)
7305 return IRQ_HANDLED;
7306 data->timestamp = smi130_acc_get_alarm_timestamp();
puneet597e4f12018-11-06 14:32:16 +05307307 smi130_hrtimer_reset(data);
Bosch Sensortecface5922018-08-29 08:08:53 +02007308
puneet597e4f12018-11-06 14:32:16 +05307309 return IRQ_WAKE_THREAD;
Bosch Sensortecface5922018-08-29 08:08:53 +02007310}
7311#endif /* defined(SMI_ACC2X2_ENABLE_INT1)||defined(SMI_ACC2X2_ENABLE_INT2) */
7312
7313
7314static int smi130_acc_probe(struct i2c_client *client,
7315 const struct i2c_device_id *id)
7316{
7317 int err = 0;
7318 struct smi130_acc_data *data;
7319 struct input_dev *dev;
7320 struct bosch_dev *dev_acc;
7321#if defined(SMI_ACC2X2_ENABLE_INT1) || defined(SMI_ACC2X2_ENABLE_INT2)
7322 struct bosch_sensor_specific *pdata;
7323#endif
7324 struct input_dev *dev_interrupt;
7325
7326 PINFO("smi130_acc_probe start\n");
7327
7328 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
7329 PERR("i2c_check_functionality error\n");
7330 err = -EIO;
7331 goto exit;
7332 }
7333 data = kzalloc(sizeof(struct smi130_acc_data), GFP_KERNEL);
7334 if (!data) {
7335 err = -ENOMEM;
7336 goto exit;
7337 }
7338
7339 /* read and check chip id */
7340 if (smi130_acc_check_chip_id(client, data) < 0) {
7341 err = -EINVAL;
7342 goto kfree_exit;
7343 }
7344
7345 /* do soft reset */
7346 smi130_acc_delay(5);
7347 if (smi130_acc_soft_reset(client) < 0) {
7348 PERR("i2c bus write error, pls check HW connection\n");
7349 err = -EINVAL;
7350 goto kfree_exit;
7351 }
7352 smi130_acc_delay(20);
7353
7354 i2c_set_clientdata(client, data);
7355 data->smi130_acc_client = client;
7356 mutex_init(&data->value_mutex);
7357 mutex_init(&data->mode_mutex);
7358 mutex_init(&data->enable_mutex);
7359 smi130_acc_set_bandwidth(client, SMI_ACC2X2_BW_SET);
7360 smi130_acc_set_range(client, SMI_ACC2X2_RANGE_SET);
7361
7362#if defined(SMI_ACC2X2_ENABLE_INT1) || defined(SMI_ACC2X2_ENABLE_INT2)
7363
7364 pdata = client->dev.platform_data;
7365 if (pdata) {
7366 if (pdata->irq_gpio_cfg && (pdata->irq_gpio_cfg() < 0)) {
7367 PERR("IRQ GPIO conf. error %d\n",
7368 client->irq);
7369 }
7370 }
7371
7372#ifdef SMI_ACC2X2_ENABLE_INT1
7373 /* maps interrupt to INT1 pin */
7374 smi130_acc_set_int1_pad_sel(client, PAD_LOWG);
7375 smi130_acc_set_int1_pad_sel(client, PAD_HIGHG);
7376 smi130_acc_set_int1_pad_sel(client, PAD_SLOP);
7377 smi130_acc_set_int1_pad_sel(client, PAD_DOUBLE_TAP);
7378 smi130_acc_set_int1_pad_sel(client, PAD_SINGLE_TAP);
7379 smi130_acc_set_int1_pad_sel(client, PAD_ORIENT);
7380 smi130_acc_set_int1_pad_sel(client, PAD_FLAT);
7381 smi130_acc_set_int1_pad_sel(client, PAD_SLOW_NO_MOTION);
7382#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7383 smi130_acc_set_newdata(client, SMI_ACC2X2_INT1_NDATA, 1);
7384 smi130_acc_set_newdata(client, SMI_ACC2X2_INT2_NDATA, 0);
7385#endif
7386#endif
7387
7388#ifdef SMI_ACC2X2_ENABLE_INT2
7389 /* maps interrupt to INT2 pin */
7390 smi130_acc_set_int2_pad_sel(client, PAD_LOWG);
7391 smi130_acc_set_int2_pad_sel(client, PAD_HIGHG);
7392 smi130_acc_set_int2_pad_sel(client, PAD_SLOP);
7393 smi130_acc_set_int2_pad_sel(client, PAD_DOUBLE_TAP);
7394 smi130_acc_set_int2_pad_sel(client, PAD_SINGLE_TAP);
7395 smi130_acc_set_int2_pad_sel(client, PAD_ORIENT);
7396 smi130_acc_set_int2_pad_sel(client, PAD_FLAT);
7397 smi130_acc_set_int2_pad_sel(client, PAD_SLOW_NO_MOTION);
7398#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7399 smi130_acc_set_newdata(client, SMI_ACC2X2_INT1_NDATA, 0);
7400 smi130_acc_set_newdata(client, SMI_ACC2X2_INT2_NDATA, 1);
7401#endif
7402#endif
7403
7404 smi130_acc_set_Int_Mode(client, 1);/*latch interrupt 250ms*/
7405
7406 /* do not open any interrupt here */
Bosch Sensortec3a9cc292018-08-30 08:19:00 +02007407 /*10,orient_mbl
Bosch Sensortecface5922018-08-29 08:08:53 +02007408 11,flat*/
7409 /* smi130_acc_set_Int_Enable(client, 10, 1); */
7410 /* smi130_acc_set_Int_Enable(client, 11, 1); */
7411
7412#ifdef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7413 /* enable new data interrupt */
7414 smi130_acc_set_Int_Enable(client, 4, 1);
7415#endif
7416
7417#ifdef CONFIG_SIG_MOTION
7418 enable_irq_wake(data->IRQ);
7419#endif
7420 if (err)
7421 PERR("could not request irq\n");
7422
Bosch Sensortecface5922018-08-29 08:08:53 +02007423#endif
7424
7425#ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7426 INIT_DELAYED_WORK(&data->work, smi130_acc_work_func);
7427#endif
7428 atomic_set(&data->delay, SMI_ACC2X2_MAX_DELAY);
7429 atomic_set(&data->enable, 0);
7430
7431 dev = input_allocate_device();
7432 if (!dev)
7433 return -ENOMEM;
7434
7435 dev_interrupt = input_allocate_device();
7436 if (!dev_interrupt) {
7437 kfree(data);
7438 input_free_device(dev); /*free the successful dev and return*/
7439 return -ENOMEM;
7440 }
7441
7442 /* only value events reported */
7443 dev->name = SENSOR_NAME;
7444 dev->id.bustype = BUS_I2C;
7445 input_set_capability(dev, EV_ABS, ABS_MISC);
7446 input_set_abs_params(dev, ABS_X, ABSMIN, ABSMAX, 0, 0);
7447 input_set_abs_params(dev, ABS_Y, ABSMIN, ABSMAX, 0, 0);
7448 input_set_abs_params(dev, ABS_Z, ABSMIN, ABSMAX, 0, 0);
7449 input_set_capability(dev, EV_MSC, MSC_GESTURE);
7450 input_set_capability(dev, EV_MSC, MSC_RAW);
7451 input_set_capability(dev, EV_MSC, MSC_SCAN);
7452 input_set_capability(dev, EV_MSC, MSC_TIME);
7453 input_set_drvdata(dev, data);
7454 err = input_register_device(dev);
7455 if (err < 0)
7456 goto err_register_input_device;
7457
7458 /* all interrupt generated events are moved to interrupt input devices*/
7459 dev_interrupt->name = "smi_acc_interrupt";
7460 dev_interrupt->id.bustype = BUS_I2C;
7461 input_set_capability(dev_interrupt, EV_REL,
7462 SLOW_NO_MOTION_INTERRUPT);
7463 input_set_capability(dev_interrupt, EV_REL,
7464 LOW_G_INTERRUPT);
7465 input_set_capability(dev_interrupt, EV_REL,
7466 HIGH_G_INTERRUPT);
7467 input_set_capability(dev_interrupt, EV_REL,
7468 SLOP_INTERRUPT);
7469 input_set_capability(dev_interrupt, EV_REL,
7470 DOUBLE_TAP_INTERRUPT);
7471 input_set_capability(dev_interrupt, EV_REL,
7472 SINGLE_TAP_INTERRUPT);
7473 input_set_capability(dev_interrupt, EV_ABS,
7474 ORIENT_INTERRUPT);
7475 input_set_capability(dev_interrupt, EV_ABS,
7476 FLAT_INTERRUPT);
7477 input_set_drvdata(dev_interrupt, data);
7478
7479 err = input_register_device(dev_interrupt);
7480 if (err < 0)
7481 goto err_register_input_device_interrupt;
7482
7483 data->dev_interrupt = dev_interrupt;
7484 data->input = dev;
7485
7486#ifdef CONFIG_SIG_MOTION
7487 data->g_sensor_class = class_create(THIS_MODULE, "sig_sensor");
7488 if (IS_ERR(data->g_sensor_class)) {
7489 err = PTR_ERR(data->g_sensor_class);
7490 data->g_sensor_class = NULL;
7491 PERR("could not allocate g_sensor_class\n");
7492 goto err_create_class;
7493 }
7494
7495 data->g_sensor_dev = device_create(data->g_sensor_class,
7496 NULL, 0, "%s", "g_sensor");
7497 if (unlikely(IS_ERR(data->g_sensor_dev))) {
7498 err = PTR_ERR(data->g_sensor_dev);
7499 data->g_sensor_dev = NULL;
7500
7501 PERR("could not allocate g_sensor_dev\n");
7502 goto err_create_g_sensor_device;
7503 }
7504
7505 dev_set_drvdata(data->g_sensor_dev, data);
7506
7507 err = sysfs_create_group(&data->g_sensor_dev->kobj,
7508 &smi130_acc_sig_motion_attribute_group);
7509 if (err < 0)
7510 goto error_sysfs;
7511#endif
7512
7513#ifdef CONFIG_DOUBLE_TAP
7514 data->g_sensor_class_doubletap =
7515 class_create(THIS_MODULE, "dtap_sensor");
7516 if (IS_ERR(data->g_sensor_class_doubletap)) {
7517 err = PTR_ERR(data->g_sensor_class_doubletap);
7518 data->g_sensor_class_doubletap = NULL;
7519 PERR("could not allocate g_sensor_class_doubletap\n");
7520 goto err_create_class;
7521 }
7522
7523 data->g_sensor_dev_doubletap = device_create(
7524 data->g_sensor_class_doubletap,
7525 NULL, 0, "%s", "g_sensor");
7526 if (unlikely(IS_ERR(data->g_sensor_dev_doubletap))) {
7527 err = PTR_ERR(data->g_sensor_dev_doubletap);
7528 data->g_sensor_dev_doubletap = NULL;
7529
7530 PERR("could not allocate g_sensor_dev_doubletap\n");
7531 goto err_create_g_sensor_device_double_tap;
7532 }
7533
7534 dev_set_drvdata(data->g_sensor_dev_doubletap, data);
7535
7536 err = sysfs_create_group(&data->g_sensor_dev_doubletap->kobj,
7537 &smi130_acc_double_tap_attribute_group);
7538 if (err < 0)
7539 goto error_sysfs;
7540#endif
7541
7542 err = sysfs_create_group(&data->input->dev.kobj,
7543 &smi130_acc_attribute_group);
7544 if (err < 0)
7545 goto error_sysfs;
7546
7547 dev_acc = bosch_allocate_device();
7548 if (!dev_acc) {
7549 err = -ENOMEM;
7550 goto error_sysfs;
7551 }
7552 dev_acc->name = ACC_NAME;
7553
7554 bosch_set_drvdata(dev_acc, data);
7555
7556 err = bosch_register_device(dev_acc);
7557 if (err < 0)
7558 goto bosch_free_acc_exit;
7559
7560 data->bosch_acc = dev_acc;
7561 err = sysfs_create_group(&data->bosch_acc->dev.kobj,
7562 &smi130_acc_attribute_group);
7563
7564 if (err < 0)
7565 goto bosch_free_exit;
7566
7567 if (NULL != client->dev.platform_data) {
7568 data->bosch_pd = kzalloc(sizeof(*data->bosch_pd),
7569 GFP_KERNEL);
7570
7571 if (NULL != data->bosch_pd) {
7572 memcpy(data->bosch_pd, client->dev.platform_data,
7573 sizeof(*data->bosch_pd));
7574 PINFO("%s sensor driver set place: p%d",
7575 data->bosch_pd->name, data->bosch_pd->place);
7576 }
7577 }
7578
7579#ifdef CONFIG_HAS_EARLYSUSPEND
7580 data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
7581 data->early_suspend.suspend = smi130_acc_early_suspend;
7582 data->early_suspend.resume = smi130_acc_late_resume;
7583 register_early_suspend(&data->early_suspend);
7584#endif
7585 INIT_WORK(&data->report_data_work,
7586 smi130_acc_timer_work_fun);
7587 reportdata_wq = create_singlethread_workqueue("smi130_acc_wq");
7588 if (NULL == reportdata_wq)
7589 PERR("fail to create the reportdta_wq");
7590 hrtimer_init(&data->timer, CLOCK_MONOTONIC,
7591 HRTIMER_MODE_REL);
7592 data->timer.function = reportdata_timer_fun;
7593 data->work_delay_kt = ns_to_ktime(4000000);
7594 data->is_timer_running = 0;
7595 data->timestamp = 0;
7596 data->time_odr = 4000000;/*default bandwidth 125HZ*/
7597 data->smi_acc_mode_enabled = 0;
7598 data->fifo_datasel = 0;
7599 data->fifo_count = 0;
7600 data->acc_count = 0;
7601
7602#ifdef CONFIG_SIG_MOTION
7603 atomic_set(&data->en_sig_motion, 0);
7604#endif
7605#ifdef CONFIG_DOUBLE_TAP
7606 atomic_set(&data->en_double_tap, 0);
7607 data->tap_times = 0;
7608 data->tap_time_period = DEFAULT_TAP_JUDGE_PERIOD;
7609 mutex_init(&data->tap_mutex);
7610 setup_timer(&data->tap_timer, smi130_acc_tap_timeout_handle,
7611 (unsigned long)data);
7612#endif
7613 if (smi130_acc_set_mode(client, SMI_ACC2X2_MODE_SUSPEND, SMI_ACC_ENABLED_ALL) < 0)
7614 return -EINVAL;
7615 data->IRQ = client->irq;
7616 PDEBUG("data->IRQ = %d", data->IRQ);
puneet597e4f12018-11-06 14:32:16 +05307617 err = request_threaded_irq(data->IRQ, smi130_acc_irq_handler,
7618 smi130_acc_irq_work_func, IRQF_TRIGGER_RISING,
Bosch Sensortecface5922018-08-29 08:08:53 +02007619 "smi130_acc", data);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307620
puneet597e4f12018-11-06 14:32:16 +05307621 smi130_hrtimer_init(data);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307622 err = smi130_acc_early_buff_init(client, data);
7623 if (!err)
7624 goto exit;
7625
Bosch Sensortecface5922018-08-29 08:08:53 +02007626 PINFO("SMI130_ACC driver probe successfully");
7627
7628 return 0;
7629
7630bosch_free_exit:
7631 bosch_unregister_device(dev_acc);
7632
7633bosch_free_acc_exit:
7634 bosch_free_device(dev_acc);
7635
7636error_sysfs:
7637 input_unregister_device(data->input);
7638
7639#ifdef CONFIG_DOUBLE_TAP
7640err_create_g_sensor_device_double_tap:
7641 class_destroy(data->g_sensor_class_doubletap);
7642#endif
7643
7644#ifdef CONFIG_SIG_MOTION
7645err_create_g_sensor_device:
7646 class_destroy(data->g_sensor_class);
7647#endif
7648
7649#if defined(CONFIG_SIG_MOTION) || defined(CONFIG_DOUBLE_TAP)
7650err_create_class:
7651 input_unregister_device(data->dev_interrupt);
7652#endif
7653
7654err_register_input_device_interrupt:
7655 input_free_device(dev_interrupt);
7656 input_unregister_device(data->input);
7657
7658err_register_input_device:
7659 input_free_device(dev);
7660
7661kfree_exit:
7662 if ((NULL != data) && (NULL != data->bosch_pd)) {
7663 kfree(data->bosch_pd);
7664 data->bosch_pd = NULL;
7665 }
7666 kfree(data);
7667exit:
7668 return err;
7669}
7670
7671#ifdef CONFIG_HAS_EARLYSUSPEND
7672static void smi130_acc_early_suspend(struct early_suspend *h)
7673{
7674 struct smi130_acc_data *data =
7675 container_of(h, struct smi130_acc_data, early_suspend);
7676
7677 mutex_lock(&data->enable_mutex);
7678 if (atomic_read(&data->enable) == 1) {
7679 smi130_acc_set_mode(data->smi130_acc_client,
7680 SMI_ACC2X2_MODE_SUSPEND, SMI_ACC_ENABLED_INPUT);
7681#ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7682 cancel_delayed_work_sync(&data->work);
7683#endif
7684 }
7685 if (data->is_timer_running) {
7686 /*diable fifo_mode when close timer*/
7687 if (smi130_acc_set_fifo_mode(data->smi130_acc_client, 0) < 0)
7688 PERR("set fifo_mode falied");
7689 hrtimer_cancel(&data->timer);
7690 data->base_time = 0;
7691 data->timestamp = 0;
7692 data->fifo_time = 0;
7693 data->acc_count = 0;
7694 }
7695 mutex_unlock(&data->enable_mutex);
7696}
7697
7698static void smi130_acc_late_resume(struct early_suspend *h)
7699{
7700 struct smi130_acc_data *data =
7701 container_of(h, struct smi130_acc_data, early_suspend);
7702 if (NULL == data)
7703 return;
7704
7705 mutex_lock(&data->enable_mutex);
7706 if (atomic_read(&data->enable) == 1) {
7707 smi130_acc_set_mode(data->smi130_acc_client,
7708 SMI_ACC2X2_MODE_NORMAL, SMI_ACC_ENABLED_INPUT);
7709#ifndef CONFIG_SMI_ACC_ENABLE_NEWDATA_INT
7710 schedule_delayed_work(&data->work,
7711 msecs_to_jiffies(atomic_read(&data->delay)));
7712#endif
7713 }
7714 if (data->is_timer_running) {
7715 hrtimer_start(&data->timer,
7716 ns_to_ktime(data->time_odr),
7717 HRTIMER_MODE_REL);
7718 /*enable fifo_mode when init*/
7719 if (smi130_acc_set_fifo_mode(data->smi130_acc_client, 2) < 0)
7720 PERR("set fifo_mode falied");
7721 data->base_time = 0;
7722 data->timestamp = 0;
7723 data->is_timer_running = 1;
7724 data->acc_count = 0;
7725 }
7726 mutex_unlock(&data->enable_mutex);
7727}
7728#endif
7729
7730static int smi130_acc_remove(struct i2c_client *client)
7731{
7732 struct smi130_acc_data *data = i2c_get_clientdata(client);
7733
7734 if (NULL == data)
7735 return 0;
7736
puneet597e4f12018-11-06 14:32:16 +05307737 smi130_hrtimer_cleanup(data);
Puneet Yatnalcfd94842019-04-16 12:11:05 +05307738 smi130_acc_input_cleanup(data);
Bosch Sensortecface5922018-08-29 08:08:53 +02007739 smi130_acc_set_enable(&client->dev, 0);
7740#ifdef CONFIG_HAS_EARLYSUSPEND
7741 unregister_early_suspend(&data->early_suspend);
7742#endif
7743 sysfs_remove_group(&data->input->dev.kobj, &smi130_acc_attribute_group);
7744 input_unregister_device(data->input);
7745
7746 if (NULL != data->bosch_pd) {
7747 kfree(data->bosch_pd);
7748 data->bosch_pd = NULL;
7749 }
7750
7751 kfree(data);
7752 return 0;
7753}
7754
7755void smi130_acc_shutdown(struct i2c_client *client)
7756{
7757 struct smi130_acc_data *data = i2c_get_clientdata(client);
7758
7759 mutex_lock(&data->enable_mutex);
7760 smi130_acc_set_mode(data->smi130_acc_client,
7761 SMI_ACC2X2_MODE_DEEP_SUSPEND, SMI_ACC_ENABLED_ALL);
7762 mutex_unlock(&data->enable_mutex);
7763}
7764
Bosch Sensortecface5922018-08-29 08:08:53 +02007765static const struct i2c_device_id smi130_acc_id[] = {
7766 { SENSOR_NAME, 0 },
7767 { }
7768};
7769
7770MODULE_DEVICE_TABLE(i2c, smi130_acc_id);
7771static const struct of_device_id smi130_acc_of_match[] = {
7772 { .compatible = "smi130_acc", },
7773 { }
7774};
7775MODULE_DEVICE_TABLE(i2c, smi130_acc_of_match);
7776
7777static struct i2c_driver smi130_acc_driver = {
7778 .driver = {
7779 .owner = THIS_MODULE,
7780 .name = SENSOR_NAME,
7781 .of_match_table = smi130_acc_of_match,
7782 },
Bosch Sensortecface5922018-08-29 08:08:53 +02007783 .id_table = smi130_acc_id,
7784 .probe = smi130_acc_probe,
7785 .remove = smi130_acc_remove,
7786 .shutdown = smi130_acc_shutdown,
7787};
7788
7789static int __init SMI_ACC2X2_init(void)
7790{
7791 return i2c_add_driver(&smi130_acc_driver);
7792}
7793
7794static void __exit SMI_ACC2X2_exit(void)
7795{
7796 i2c_del_driver(&smi130_acc_driver);
7797}
7798
7799MODULE_AUTHOR("contact@bosch-sensortec.com");
7800MODULE_DESCRIPTION("SMI_ACC2X2 ACCELEROMETER SENSOR DRIVER");
7801MODULE_LICENSE("GPL v2");
7802
7803module_init(SMI_ACC2X2_init);
7804module_exit(SMI_ACC2X2_exit);
7805