]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/iio/imu/nvi_mpu/nvi_icm.c
eb2c4a59c5347fdb9d81e3436b80b386774627a6
[sojka/nv-tegra/linux-3.10.git] / drivers / iio / imu / nvi_mpu / nvi_icm.c
1 /* Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
2  *
3  * This software is licensed under the terms of the GNU General Public
4  * License version 2, as published by the Free Software Foundation, and
5  * may be copied, distributed, and modified under those terms.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/time.h>
15 #include <linux/delay.h>
16 #include "nvi.h"
17 #include "nvi_dmp_icm.h"
18
19 #define BYTES_PER_SENSOR                6
20 /* full scale and LPF setting */
21 #define ICM_SELFTEST_GYRO_FS            ((0 << 3) | 1)
22 #define ICM_SELFTEST_ACCEL_FS           ((7 << 3) | 1)
23 /* register settings */
24 #define ICM_SELFTEST_GYRO_SMPLRT_DIV    10
25 #define ICM_SELFTEST_GYRO_AVGCFG        3
26 #define ICM_SELFTEST_ACCEL_SMPLRT_DIV   10
27 #define ICM_SELFTEST_ACCEL_DEC3_CFG     2
28 #define ICM_SELFTEST_GYRO_SENS          (32768 / 250)
29 #define BIT_ACCEL_CTEN                  0x1C
30 #define BIT_GYRO_CTEN                   0x38
31 /* wait time before collecting data */
32 #define ICM_MAX_PACKETS                 20
33 #define ICM_SELFTEST_WAIT_TIME          (ICM_MAX_PACKETS * 10)
34 #define ICM_GYRO_ENGINE_UP_TIME         50
35 #define ICM_ST_STABLE_TIME              20
36 #define ICM_GYRO_SCALE                  131
37 #define ICM_ST_PRECISION                1000
38 #define ICM_ST_ACCEL_FS_MG              2000UL
39 #define ICM_ST_SCALE                    32768
40 #define ICM_ST_TRY_TIMES                2
41 #define ICM_ST_SAMPLES                  200
42 #define ICM_ACCEL_ST_SHIFT_DELTA_MIN    500
43 #define ICM_ACCEL_ST_SHIFT_DELTA_MAX    1500
44 #define ICM_GYRO_CT_SHIFT_DELTA         500
45 /* Gyro Offset Max Value (dps) */
46 #define ICM_GYRO_OFFSET_MAX             20
47 /* Gyro Self Test Absolute Limits ST_AL (dps) */
48 #define ICM_GYRO_ST_AL                  60
49 /* Accel Self Test Absolute Limits ST_AL (mg) */
50 #define ICM_ACCEL_ST_AL_MIN ((225 * ICM_ST_SCALE \
51                               / ICM_ST_ACCEL_FS_MG) * ICM_ST_PRECISION)
52 #define ICM_ACCEL_ST_AL_MAX ((675 * ICM_ST_SCALE \
53                               / ICM_ST_ACCEL_FS_MG) * ICM_ST_PRECISION)
54
55
56 static const u16 icm_st_tb[256] = {
57         2620, 2646, 2672, 2699, 2726, 2753, 2781, 2808,
58         2837, 2865, 2894, 2923, 2952, 2981, 3011, 3041,
59         3072, 3102, 3133, 3165, 3196, 3228, 3261, 3293,
60         3326, 3359, 3393, 3427, 3461, 3496, 3531, 3566,
61         3602, 3638, 3674, 3711, 3748, 3786, 3823, 3862,
62         3900, 3939, 3979, 4019, 4059, 4099, 4140, 4182,
63         4224, 4266, 4308, 4352, 4395, 4439, 4483, 4528,
64         4574, 4619, 4665, 4712, 4759, 4807, 4855, 4903,
65         4953, 5002, 5052, 5103, 5154, 5205, 5257, 5310,
66         5363, 5417, 5471, 5525, 5581, 5636, 5693, 5750,
67         5807, 5865, 5924, 5983, 6043, 6104, 6165, 6226,
68         6289, 6351, 6415, 6479, 6544, 6609, 6675, 6742,
69         6810, 6878, 6946, 7016, 7086, 7157, 7229, 7301,
70         7374, 7448, 7522, 7597, 7673, 7750, 7828, 7906,
71         7985, 8065, 8145, 8227, 8309, 8392, 8476, 8561,
72         8647, 8733, 8820, 8909, 8998, 9088, 9178, 9270,
73         9363, 9457, 9551, 9647, 9743, 9841, 9939, 10038,
74         10139, 10240, 10343, 10446, 10550, 10656, 10763, 10870,
75         10979, 11089, 11200, 11312, 11425, 11539, 11654, 11771,
76         11889, 12008, 12128, 12249, 12371, 12495, 12620, 12746,
77         12874, 13002, 13132, 13264, 13396, 13530, 13666, 13802,
78         13940, 14080, 14221, 14363, 14506, 14652, 14798, 14946,
79         15096, 15247, 15399, 15553, 15709, 15866, 16024, 16184,
80         16346, 16510, 16675, 16842, 17010, 17180, 17352, 17526,
81         17701, 17878, 18057, 18237, 18420, 18604, 18790, 18978,
82         19167, 19359, 19553, 19748, 19946, 20145, 20347, 20550,
83         20756, 20963, 21173, 21385, 21598, 21814, 22033, 22253,
84         22475, 22700, 22927, 23156, 23388, 23622, 23858, 24097,
85         24338, 24581, 24827, 25075, 25326, 25579, 25835, 26093,
86         26354, 26618, 26884, 27153, 27424, 27699, 27976, 28255,
87         28538, 28823, 29112, 29403, 29697, 29994, 30294, 30597,
88         30903, 31212, 31524, 31839, 32157, 32479, 32804
89 };
90
91 /**
92 * inv_icm_st_gyr_chk() - check gyro self test.
93 *  this function returns zero as success. A non-zero return
94 *  value indicates failure in self test.
95 *  @*st: main data structure.
96 *  @*reg_avg: average value of normal test.
97 *  @*st_avg: average value of self test
98 */
99 static int inv_icm_st_gyr_chk(struct nvi_state *st, int *reg_avg, int *st_avg)
100 {
101         u8 *regs;
102         int ret = 0;
103         int otp_value_zero = 0;
104         int st_shift_prod[AXIS_N];
105         int st_shift_cust[AXIS_N];
106         int i;
107
108         regs = &st->st_data[DEV_GYR][0];
109         if (st->sts & NVI_DBG_SPEW_MSG)
110                 dev_info(&st->i2c->dev, "%s data: %02x %02x %02x\n",
111                          __func__, regs[0], regs[1], regs[2]);
112         for (i = 0; i < AXIS_N; i++) {
113                 if (regs[i] != 0) {
114                         st_shift_prod[i] = icm_st_tb[regs[i] - 1];
115                 } else {
116                         st_shift_prod[i] = 0;
117                         otp_value_zero = 1;
118                 }
119         }
120         if (st->sts & NVI_DBG_SPEW_MSG)
121                 dev_info(&st->i2c->dev,
122                          "%s st_shift_prod: %+d %+d %+d\n", __func__,
123                          st_shift_prod[0], st_shift_prod[1], st_shift_prod[2]);
124         for (i = 0; i < AXIS_N; i++) {
125                 st_shift_cust[i] = st_avg[i] - reg_avg[i];
126                 if (!otp_value_zero) {
127                         /* Self Test Pass/Fail Criteria A */
128                         if (st_shift_cust[i] < (ICM_GYRO_CT_SHIFT_DELTA *
129                                                 st_shift_prod[i])) {
130                                 ret = 1;
131                                 if (st->sts & NVI_DBG_SPEW_MSG)
132                                         dev_info(&st->i2c->dev,
133                                                  "%s FAIL A axis %d\n",
134                                                  __func__, i);
135                         }
136                 } else {
137                         /* Self Test Pass/Fail Criteria B */
138                         if (st_shift_cust[i] < (ICM_GYRO_ST_AL *
139                                                 ICM_SELFTEST_GYRO_SENS *
140                                                 ICM_ST_PRECISION)) {
141                                 ret = 1;
142                                 if (st->sts & NVI_DBG_SPEW_MSG)
143                                         dev_info(&st->i2c->dev,
144                                                  "%s FAIL B axis %d\n",
145                                                  __func__, i);
146                         }
147                 }
148         }
149
150         if (st->sts & NVI_DBG_SPEW_MSG)
151                 dev_info(&st->i2c->dev, "%s st_shift_cust: %+d %+d %+d\n",
152                          __func__,
153                          st_shift_cust[0], st_shift_cust[1], st_shift_cust[2]);
154         if (ret == 0) {
155                 /* Self Test Pass/Fail Criteria C */
156                 for (i = 0; i < AXIS_N; i++) {
157                         if (abs(reg_avg[i]) > (ICM_GYRO_OFFSET_MAX *
158                                                ICM_SELFTEST_GYRO_SENS *
159                                                ICM_ST_PRECISION)) {
160                                 ret = 1;
161                                 if (st->sts & NVI_DBG_SPEW_MSG)
162                                         dev_info(&st->i2c->dev,
163                                                  "%s FAIL C axis %d\n",
164                                                  __func__, i);
165                         }
166                 }
167         }
168
169         return ret;
170 }
171
172 /**
173 * inv_icm_st_acc_chk() - check accel self test.
174 *  this function returns zero as success. A non-zero return
175 *  value indicates failure in self test.
176 *  @*st: main data structure.
177 *  @*reg_avg: average value of normal test.
178 *  @*st_avg: average value of self test
179 */
180 static int inv_icm_st_acc_chk(struct nvi_state *st, int *reg_avg, int *st_avg)
181 {
182         u8 *regs;
183         int i;
184         int st_shift_prod[AXIS_N];
185         int st_shift_cust[AXIS_N];
186         int otp_value_zero = 0;
187         int ret = 0;
188
189         regs = &st->st_data[DEV_ACC][0];
190         if (st->sts & NVI_DBG_SPEW_MSG)
191                 dev_info(&st->i2c->dev, "%s data: %02x %02x %02x\n",
192                          __func__, regs[0], regs[1], regs[2]);
193         for (i = 0; i < AXIS_N; i++) {
194                 if (regs[i] != 0) {
195                         st_shift_prod[i] = icm_st_tb[regs[i] - 1];
196                 } else {
197                         st_shift_prod[i] = 0;
198                         otp_value_zero = 1;
199                 }
200         }
201
202         if (st->sts & NVI_DBG_SPEW_MSG)
203                 dev_info(&st->i2c->dev,
204                          "%s st_shift_prod: %+d %+d %+d\n", __func__,
205                          st_shift_prod[0], st_shift_prod[1], st_shift_prod[2]);
206         if (!otp_value_zero) {
207                 /* Self Test Pass/Fail Criteria A */
208                 for (i = 0; i < AXIS_N; i++) {
209                         st_shift_cust[i] = st_avg[i] - reg_avg[i];
210                         if (st_shift_cust[i] < (ICM_ACCEL_ST_SHIFT_DELTA_MIN *
211                                                 st_shift_prod[i])) {
212                                 ret = 1;
213                                 if (st->sts & NVI_DBG_SPEW_MSG)
214                                         dev_info(&st->i2c->dev,
215                                                  "%s FAIL A (min) axis %d\n",
216                                                  __func__, i);
217                         }
218                         if (st_shift_cust[i] > (ICM_ACCEL_ST_SHIFT_DELTA_MAX *
219                                                 st_shift_prod[i])) {
220                                 ret = 1;
221                                 if (st->sts & NVI_DBG_SPEW_MSG)
222                                         dev_info(&st->i2c->dev,
223                                                  "%s FAIL A (max) axis %d\n",
224                                                  __func__, i);
225                         }
226                 }
227         } else {
228                 /* Self Test Pass/Fail Criteria B */
229                 for (i = 0; i < AXIS_N; i++) {
230                         st_shift_cust[i] = abs(st_avg[i] - reg_avg[i]);
231                         if ((st_shift_cust[i] < ICM_ACCEL_ST_AL_MIN) ||
232                                     (st_shift_cust[i] > ICM_ACCEL_ST_AL_MAX)) {
233                                 ret = 1;
234                                 if (st->sts & NVI_DBG_SPEW_MSG)
235                                         dev_info(&st->i2c->dev,
236                                                  "%s FAIL B axis %d\n",
237                                                  __func__, i);
238                         }
239                 }
240         }
241
242         if (st->sts & NVI_DBG_SPEW_MSG)
243                 dev_info(&st->i2c->dev, "%s st_shift_cust: %+d %+d %+d\n",
244                          __func__,
245                          st_shift_cust[0], st_shift_cust[1], st_shift_cust[2]);
246         return ret;
247 }
248
249 static int inv_icm_st_setup(struct nvi_state *st)
250 {
251         int axis;
252         int ret;
253
254         /* Wake up and stop sensors */
255         ret = nvi_pm_wr(st, __func__, INV_CLK_PLL, BIT_PWR_PRESSURE_STBY |
256                         BIT_PWR_ACCEL_STBY | BIT_PWR_GYRO_STBY, 0);
257         /* Perform a soft-reset of the chip
258          * This will clear any prior states in the chip
259          */
260         ret |= nvi_wr_pm1(st, __func__, BIT_H_RESET);
261         if (ret)
262                 return ret;
263
264         msleep(POWER_UP_TIME);
265         /* Wake up */
266         ret = nvi_wr_pm1(st, __func__, INV_CLK_PLL);
267         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->user_ctrl, BIT_FIFO_EN,
268                             __func__, &st->rc.user_ctrl);
269         /* Configure FIFO */
270         ret |= nvi_wr_fifo_cfg(st, -1);
271         /* Set cycle mode */
272         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->lp_config, 0x70,
273                             __func__, &st->rc.lp_config);
274         /* Configure FSR and DLPF */
275         ret |= nvi_i2c_write_rc(st, &st->hal->reg->smplrt[DEV_GYR],
276                                 ICM_SELFTEST_GYRO_SMPLRT_DIV, __func__,
277                                 (u8 *)&st->rc.smplrt[DEV_GYR], true);
278         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->gyro_config1,
279                              ICM_SELFTEST_GYRO_FS,
280                              __func__, &st->rc.gyro_config1);
281         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->gyro_config2,
282                              ICM_SELFTEST_GYRO_AVGCFG,
283                              __func__, &st->rc.gyro_config2);
284         ret |= nvi_i2c_write_rc(st, &st->hal->reg->smplrt[DEV_ACC],
285                                 ICM_SELFTEST_ACCEL_SMPLRT_DIV, __func__,
286                                 (u8 *)&st->rc.smplrt[DEV_ACC], true);
287         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->accel_config,
288                              ICM_SELFTEST_ACCEL_FS,
289                              __func__, &st->rc.accel_config);
290         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->accel_config2,
291                              ICM_SELFTEST_ACCEL_DEC3_CFG,
292                              __func__, &st->rc.accel_config2);
293         if (ret)
294                 return ret;
295
296         /* Read selftest values */
297         for (axis = 0; axis < AXIS_N; axis++)
298                 ret |= nvi_i2c_rd(st, &st->hal->reg->self_test_g[axis],
299                                   &st->st_data[DEV_GYR][axis]);
300
301         for (axis = 0; axis < AXIS_N; axis++)
302                 ret |= nvi_i2c_rd(st, &st->hal->reg->self_test_a[axis],
303                                   &st->st_data[DEV_ACC][axis]);
304
305         ret |= nvi_pm_wr(st, __func__, INV_CLK_PLL,
306                          BIT_PWR_PRESSURE_STBY, 0x70);
307         if (ret)
308                 return ret;
309
310         msleep(ICM_GYRO_ENGINE_UP_TIME);
311         return ret;
312 }
313
314 static int inv_icm_st_rd(struct nvi_state *st, int dev,
315                          int *sum_result, int *s)
316 {
317         u16 fifo_count;
318         s16 vals[AXIS_N];
319         u8 d[ICM_MAX_PACKETS * BYTES_PER_SENSOR];
320         int packet_count;
321         int i;
322         int j;
323         int t;
324         int ret;
325
326         ret = nvi_i2c_write_rc(st, &st->hal->reg->fifo_en, 0,
327                                __func__, (u8 *)&st->rc.fifo_en, false);
328         /* Reset FIFO */
329         ret |= nvi_i2c_wr(st, &st->hal->reg->fifo_rst,
330                           0x1F, __func__);
331         ret |= nvi_i2c_wr(st, &st->hal->reg->fifo_rst,
332                           0x1E, __func__);
333         if (ret)
334                 return ret;
335
336         while (*s < ICM_ST_SAMPLES) {
337                 ret = nvi_i2c_write_rc(st, &st->hal->reg->fifo_en,
338                                        st->hal->dev[dev]->fifo_en_msk,
339                                        __func__, (u8 *)&st->rc.fifo_en, false);
340                 if (ret)
341                         return ret;
342
343                 msleep(ICM_SELFTEST_WAIT_TIME);
344                 ret = nvi_i2c_write_rc(st, &st->hal->reg->fifo_en, 0,
345                                        __func__, (u8 *)&st->rc.fifo_en, false);
346                 if (ret)
347                         return ret;
348
349                 ret = nvi_i2c_rd(st, &st->hal->reg->fifo_count_h, d);
350                 if (ret)
351                         return ret;
352
353                 fifo_count = be16_to_cpup((__be16 *)(&d[0]));
354                 if (st->sts & NVI_DBG_SPEW_MSG)
355                         dev_info(&st->i2c->dev, "%s fifo_count=%d\n",
356                                  __func__, fifo_count);
357                 if (ICM_MAX_PACKETS * BYTES_PER_SENSOR < fifo_count) {
358                         ret = nvi_i2c_r(st, st->hal->reg->fifo_rw.bank,
359                                         st->hal->reg->fifo_rw.reg,
360                                         ICM_MAX_PACKETS * BYTES_PER_SENSOR, d);
361                         packet_count = ICM_MAX_PACKETS;
362                 } else {
363                         ret = nvi_i2c_r(st, st->hal->reg->fifo_rw.bank,
364                                         st->hal->reg->fifo_rw.reg,
365                                         fifo_count, d);
366                         packet_count = fifo_count / BYTES_PER_SENSOR;
367                 }
368                 if (ret)
369                         return ret;
370
371                 i = 0;
372                 while (i < packet_count) {
373                         for (j = 0; j < AXIS_N; j++) {
374                                 t = 2 * j + i * BYTES_PER_SENSOR;
375                                 vals[j] = (s16)be16_to_cpup((__be16 *)(&d[t]));
376                                 sum_result[j] += vals[j];
377                         }
378                         if (st->sts & NVI_DBG_SPEW_MSG)
379                                 dev_info(&st->i2c->dev,
380                                          "%s %s %d: %+d %+d %+d\n",
381                                          __func__, st->snsr[dev].cfg.name,
382                                          *s, vals[0], vals[1], vals[2]);
383                         (*s)++;
384                         i++;
385                 }
386         }
387
388         return 0;
389 }
390
391 /*
392  *  inv_icm_st_acc_do() - do the actual test of self testing
393  */
394 static int inv_icm_st_acc_do(struct nvi_state *st,
395                              int *accel_result, int *accel_st_result)
396 {
397         int accel_s;
398         int i;
399         int j;
400         int ret;
401
402         for (i = 0; i < AXIS_N; i++) {
403                 accel_result[i] = 0;
404                 accel_st_result[i] = 0;
405         }
406         accel_s = 0;
407         ret = inv_icm_st_rd(st, DEV_ACC, accel_result, &accel_s);
408         if (ret || accel_s <= 0)
409                 return -1;
410
411         for (j = 0; j < AXIS_N; j++) {
412                 accel_result[j] = accel_result[j] / accel_s;
413                 accel_result[j] *= ICM_ST_PRECISION;
414         }
415         /* Set Self-Test Bit */
416         ret = nvi_i2c_wr_rc(st, &st->hal->reg->accel_config2,
417                             BIT_ACCEL_CTEN | ICM_SELFTEST_ACCEL_DEC3_CFG,
418                             __func__, &st->rc.accel_config2);
419         if (ret)
420                 return ret;
421
422         msleep(ICM_ST_STABLE_TIME);
423         accel_s = 0;
424         ret = inv_icm_st_rd(st, DEV_ACC, accel_st_result, &accel_s);
425         if (ret || accel_s <= 0)
426                 return -1;
427
428         for (j = 0; j < AXIS_N; j++) {
429                 accel_st_result[j] = accel_st_result[j] / accel_s;
430                 accel_st_result[j] *= ICM_ST_PRECISION;
431         }
432         if (st->sts & NVI_DBG_SPEW_MSG)
433                 dev_info(&st->i2c->dev, "%s %d, %d, %d\n", __func__,
434                          accel_result[0], accel_result[1], accel_result[2]);
435
436         return 0;
437 }
438
439 /*
440  *  inv_icm_st_gyr_do() - do the actual test of self testing
441  */
442 static int inv_icm_st_gyr_do(struct nvi_state *st,
443                              int *gyro_result, int *gyro_st_result)
444 {
445         int gyro_s;
446         int i;
447         int j;
448         int ret;
449
450         for (i = 0; i < AXIS_N; i++) {
451                 gyro_result[i] = 0;
452                 gyro_st_result[i] = 0;
453         }
454         gyro_s = 0;
455         ret = inv_icm_st_rd(st, DEV_GYR, gyro_result, &gyro_s);
456         if (ret || gyro_s <= 0)
457                 return -1;
458
459         for (j = 0; j < AXIS_N; j++) {
460                 gyro_result[j] = gyro_result[j] / gyro_s;
461                 gyro_result[j] *= ICM_ST_PRECISION;
462         }
463         /* Set Self-Test Bit */
464         ret = nvi_i2c_wr_rc(st, &st->hal->reg->gyro_config2,
465                             BIT_GYRO_CTEN | ICM_SELFTEST_GYRO_AVGCFG,
466                             __func__, &st->rc.gyro_config2);
467         if (ret)
468                 return ret;
469
470         msleep(ICM_ST_STABLE_TIME);
471         gyro_s = 0;
472         ret = inv_icm_st_rd(st, DEV_GYR, gyro_st_result, &gyro_s);
473         if (ret || gyro_s <= 0)
474                 return -1;
475
476         for (j = 0; j < AXIS_N; j++) {
477                 gyro_st_result[j] = gyro_st_result[j] / gyro_s;
478                 gyro_st_result[j] *= ICM_ST_PRECISION;
479         }
480         if (st->sts & NVI_DBG_SPEW_MSG)
481                 dev_info(&st->i2c->dev, "%s %d, %d, %d\n", __func__,
482                          gyro_result[0], gyro_result[1], gyro_result[2]);
483         return 0;
484 }
485
486 static int inv_st_gyr_icm(struct nvi_state *st)
487 {
488         int ret;
489         int gyr_bias_st[AXIS_N];
490         int gyr_bias_regular[AXIS_N];
491         int test_times;
492         int i;
493         char gyro_result;
494
495         ret = inv_icm_st_setup(st);
496         if (ret)
497                 return ret;
498
499         test_times = ICM_ST_TRY_TIMES;
500         while (test_times > 0) {
501                 ret = inv_icm_st_gyr_do(st, gyr_bias_regular, gyr_bias_st);
502                 if (ret == -EAGAIN)
503                         test_times--;
504                 else
505                         test_times = 0;
506         }
507         if (ret)
508                 return ret;
509
510         if (st->sts & NVI_DBG_SPEW_MSG) {
511                 dev_info(&st->i2c->dev, "%s gyro bias_regular: %+d %+d %+d\n",
512                          __func__, gyr_bias_regular[0], gyr_bias_regular[1],
513                          gyr_bias_regular[2]);
514                 dev_info(&st->i2c->dev, "%s gyro bias_st: %+d %+d %+d\n",
515                          __func__, gyr_bias_st[0], gyr_bias_st[1],
516                          gyr_bias_st[2]);
517         }
518         for (i = 0; i < AXIS_N; i++)
519                 st->bias[DEV_GYR][i] = (gyr_bias_regular[i] /
520                                         ICM_ST_PRECISION);
521         gyro_result = inv_icm_st_gyr_chk(st, gyr_bias_regular, gyr_bias_st);
522         if (st->sts & NVI_DBG_SPEW_MSG)
523                 dev_info(&st->i2c->dev, "%s gyro_result %hhd\n",
524                          __func__, gyro_result);
525
526         return gyro_result;
527 }
528
529 static int inv_st_acc_icm(struct nvi_state *st)
530 {
531         int ret;
532         int acc_bias_st[AXIS_N];
533         int acc_bias_regular[AXIS_N];
534         int test_times;
535         int i;
536         char accel_result;
537
538         ret = inv_icm_st_setup(st);
539         if (ret)
540                 return ret;
541
542         test_times = ICM_ST_TRY_TIMES;
543         while (test_times > 0) {
544                 ret = inv_icm_st_acc_do(st, acc_bias_regular, acc_bias_st);
545                 if (ret == -EAGAIN)
546                         test_times--;
547                 else
548                         break;
549         }
550         if (ret)
551                 return ret;
552
553         if (st->sts & NVI_DBG_SPEW_MSG) {
554                 dev_info(&st->i2c->dev, "%s acc_bias_regular: %+d %+d %+d\n",
555                          __func__, acc_bias_regular[0],
556                          acc_bias_regular[1], acc_bias_regular[2]);
557                 dev_info(&st->i2c->dev, "%s acc_bias_st: %+d %+d %+d\n",
558                          __func__, acc_bias_st[0], acc_bias_st[1],
559                          acc_bias_st[2]);
560         }
561         for (i = 0; i < AXIS_N; i++)
562                 st->bias[DEV_ACC][i] = (acc_bias_regular[i] /
563                                         ICM_ST_PRECISION);
564         accel_result = inv_icm_st_acc_chk(st, acc_bias_regular, acc_bias_st);
565         if (st->sts & NVI_DBG_SPEW_MSG)
566                 dev_info(&st->i2c->dev, "%s accel_result %hhd\n",
567                          __func__, accel_result);
568         return accel_result;
569 }
570
571 static int nvi_pm_icm(struct nvi_state *st, u8 pm1, u8 pm2, u8 lp)
572 {
573         int ret;
574
575         ret = nvi_i2c_wr_rc(st, &st->hal->reg->lp_config, 0x70,
576                             __func__, &st->rc.lp_config);
577         /* the DMP changes pm2 so we can't use the cache */
578         ret |= nvi_i2c_wr(st, &st->hal->reg->pm2, pm2, __func__);
579         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->pm1, pm1,
580                              __func__, &st->rc.pm1);
581         return ret;
582 }
583
584 static int nvi_en_gyr_icm(struct nvi_state *st)
585 {
586         u8 val;
587         int i;
588         int ret = 0;
589
590         st->snsr[DEV_GYR].buf_n = 6;
591         for (i = 0; i < AXIS_N; i++)
592                 ret |= nvi_wr_gyro_offset(st, i,
593                                           (u16)(st->rom_offset[DEV_GYR][i] +
594                                                 st->dev_offset[DEV_GYR][i]));
595         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->gyro_config2, 0,
596                              __func__, &st->rc.gyro_config2);
597         val = (st->snsr[DEV_GYR].usr_cfg << 1) | 0x01;
598         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->gyro_config1, val,
599                              __func__, &st->rc.gyro_config1);
600         return ret;
601 }
602
603 static int nvi_en_acc_icm(struct nvi_state *st)
604 {
605         u8 val;
606         int i;
607         int ret = 0;
608
609         st->snsr[DEV_ACC].buf_n = 6;
610         st->snsr[DEV_ACC].buf_shft = 0;
611         for (i = 0; i < AXIS_N; i++)
612                 ret |= nvi_wr_accel_offset(st, i,
613                                            (u16)(st->rom_offset[DEV_ACC][i] +
614                                           (st->dev_offset[DEV_ACC][i] << 1)));
615         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->accel_config2, 0,
616                              __func__, &st->rc.accel_config2);
617         val = (st->snsr[DEV_ACC].usr_cfg << 1);
618         ret |= nvi_i2c_wr_rc(st, &st->hal->reg->accel_config, val,
619                              __func__, &st->rc.accel_config);
620         return ret;
621 }
622
623 static int nvi_init_icm(struct nvi_state *st)
624 {
625         u8 val;
626         s8 t;
627         unsigned int src;
628         int ret;
629
630         st->snsr[DEV_ACC].cfg.thresh_hi = 0; /* no ACC LP on ICM */
631         st->snsr[DEV_SM].cfg.thresh_lo = ICM_SMD_THLD_INIT;
632         st->snsr[DEV_SM].cfg.thresh_hi = ICM_SMD_THLD_N_INIT;
633         st->snsr[DEV_SM].cfg.delay_us_min = ICM_SMD_TIMER_INIT;
634         st->snsr[DEV_SM].cfg.delay_us_max = ICM_SMD_TIMER2_INIT;
635         st->snsr[DEV_SM].cfg.report_n = ICM_SMD_RESET_INIT;
636         ret = nvi_i2c_rd(st, &st->hal->reg->tbc_pll, &val);
637         if (ret)
638                 return ret;
639
640         t = abs(val & 0x7F);
641         if (val & 0x80)
642                 t = -t;
643         st->src[SRC_GYR].base_t = NSEC_PER_SEC - t * 769903 + ((t * 769903) /
644                                                                1270) * t;
645         st->src[SRC_ACC].base_t = NSEC_PER_SEC;
646         st->src[SRC_AUX].base_t = NSEC_PER_SEC;
647         for (src = 0; src < st->hal->src_n; src++)
648                 st->src[src].base_t /= ICM_BASE_SAMPLE_RATE;
649
650         /* calculate the period_us_max */
651         st->src[SRC_GYR].period_us_max = (st->src[SRC_GYR].base_t *
652                                           0xFF) / 1000;
653         /* WAR: limit SRC_ACC to SRC_GYR since same period required by WAR */
654         st->src[SRC_ACC].period_us_max = st->src[SRC_GYR].period_us_max;
655         st->src[SRC_AUX].period_us_max = st->hal->src[SRC_AUX].period_us_max;
656         for (src = 0; src < st->hal->src_n; src++)
657                 st->src[src].period_us_min = st->hal->src[src].period_us_min;
658
659         nvi_en_gyr_icm(st);
660         nvi_en_acc_icm(st);
661         return 0;
662 }
663
664 struct nvi_fn nvi_fn_icm = {
665         .pm                             = nvi_pm_icm,
666         .init                           = nvi_init_icm,
667         .st_acc                         = inv_st_acc_icm,
668         .st_gyr                         = inv_st_gyr_icm,
669         .en_acc                         = nvi_en_acc_icm,
670         .en_gyr                         = nvi_en_gyr_icm,
671 };
672
673
674 static int nvi_src(struct nvi_state *st, unsigned int src)
675 {
676         unsigned int rate;
677         int ret;
678
679         rate = (st->src[src].period_us_req * 1000) / st->src[src].base_t;
680         if (rate)
681                 rate--;
682         ret = nvi_i2c_write_rc(st, &st->hal->reg->smplrt[src], rate,
683                                __func__, (u8 *)&st->rc.smplrt[src], true);
684         if (!ret)
685                 st->src[src].period_us_src = ((rate + 1) *
686                                               st->src[src].base_t) / 1000;
687         if (st->sts & (NVS_STS_SPEW_MSG | NVI_DBG_SPEW_MSG))
688                 dev_info(&st->i2c->dev,
689                          "%s src[%u] period_req=%u period_src=%u err=%d\n",
690                          __func__, src, st->src[src].period_us_req,
691                          st->src[src].period_us_src, ret);
692         return ret;
693 }
694
695 static int nvi_src_gyr(struct nvi_state *st)
696 {
697         return nvi_src(st, SRC_GYR);
698 }
699
700 static int nvi_src_acc(struct nvi_state *st)
701 {
702         return nvi_src(st, SRC_ACC);
703 }
704
705 static unsigned int nvi_aux_period_us[] = {
706         29127111,
707         14563556,
708         7281778,
709         3640889,
710         1820444,
711         910222,
712         455111,
713         227556,
714         113778,
715         56889,
716         28444,
717         14222,
718 };
719
720 static int nvi_src_aux(struct nvi_state *st)
721 {
722         u8 val;
723         unsigned int i;
724         int ret;
725
726         for (i = 0; i < ARRAY_SIZE(nvi_aux_period_us); i++) {
727                 if (st->src[SRC_AUX].period_us_req >= nvi_aux_period_us[i])
728                         break;
729         }
730         if (i >= ARRAY_SIZE(nvi_aux_period_us))
731                 i = ARRAY_SIZE(nvi_aux_period_us) - 1;
732         val = 0x0F - i;
733         ret = nvi_i2c_wr_rc(st, &st->hal->reg->i2c_mst_odr_config, val,
734                             __func__, &st->rc.i2c_mst_odr_config);
735         if (!ret) {
736                 st->src[SRC_AUX].period_us_src = nvi_aux_period_us[i];
737                 ret = nvi_aux_delay(st, __func__);
738         }
739         if (st->sts & (NVS_STS_SPEW_MSG | NVI_DBG_SPEW_MSG))
740                 dev_info(&st->i2c->dev, "%s src[SRC_AUX]: period=%u err=%d\n",
741                          __func__, st->src[SRC_AUX].period_us_req, ret);
742         return ret;
743 }
744
745 static const struct nvi_hal_src src[] = {
746         [SRC_GYR]                       {
747                 .dev_msk                = (1 << DEV_GYR) | (1 << DEV_GYU),
748                 .period_us_min          = 10000,
749                 .period_us_max          = 200000,
750                 .fn_period              = nvi_src_gyr,
751         },
752         [SRC_ACC]                       {
753                 .dev_msk                = (1 << DEV_ACC),
754                 .period_us_min          = 10000,
755                 .period_us_max          = 200000,
756                 .fn_period              = nvi_src_acc,
757         },
758         [SRC_AUX]                       {
759                 .dev_msk                = (1 << DEV_AUX),
760                 .period_us_min          = 14222,
761                 .period_us_max          = 29127111,
762                 .fn_period              = nvi_src_aux,
763         },
764 };
765
766 static int nvi_fifo_devs[] = {
767         DEV_GYR,
768         DEV_ACC,
769         -1,
770         DEV_AUX,
771 };
772
773 static const unsigned long nvi_lp_dly_us_tbl[] = {
774         4096000,/* 4096ms */
775         2048000,/* 2048ms */
776         1024000,/* 1024ms */
777         512000, /* 512ms */
778         256000, /* 256ms */
779         128000, /* 128ms */
780         64000,  /* 64ms */
781         32000,  /* 32ms */
782         16000,  /* 16ms */
783         8000,   /* 8ms */
784         4000,   /* 4ms */
785         /* 2000, 2ms */
786 };
787
788 static struct nvi_rr nvi_rr_acc[] = {
789         /* all accelerometer values are in g's  fval = NVS_FLOAT_NANO */
790         {
791                 .max_range              = {
792                         .ival           = 19,
793                         .fval           = 613300000,
794                 },
795                 .resolution             = {
796                         .ival           = 0,
797                         .fval           = 598550,
798                 },
799         },
800         {
801                 .max_range              = {
802                         .ival           = 39,
803                         .fval           = 226600000,
804                 },
805                 .resolution             = {
806                         .ival           = 0,
807                         .fval           = 1197101,
808                 },
809         },
810         {
811                 .max_range              = {
812                         .ival           = 78,
813                         .fval           = 453200000,
814                 },
815                 .resolution             = {
816                         .ival           = 0,
817                         .fval           = 2394202,
818                 },
819         },
820         {
821                 .max_range              = {
822                         .ival           = 156,
823                         .fval           = 906400000,
824                 },
825                 .resolution             = {
826                         .ival           = 0,
827                         .fval           = 4788403,
828                 },
829         },
830 };
831
832 static struct nvi_rr nvi_rr_gyr[] = {
833         /* rad / sec  fval = NVS_FLOAT_NANO */
834         {
835                 .max_range              = {
836                         .ival           = 4,
837                         .fval           = 363323130,
838                 },
839                 .resolution             = {
840                         .ival           = 0,
841                         .fval           = 133231,
842                 },
843         },
844         {
845                 .max_range              = {
846                         .ival           = 8,
847                         .fval           = 726646260,
848                 },
849                 .resolution             = {
850                         .ival           = 0,
851                         .fval           = 266462,
852                 },
853         },
854         {
855                 .max_range              = {
856                         .ival           = 17,
857                         .fval           = 453292520,
858                 },
859                 .resolution             = {
860                         .ival           = 0,
861                         .fval           = 532113,
862                 },
863         },
864         {
865                 .max_range              = {
866                         .ival           = 34,
867                         .fval           = 906585040,
868                 },
869                 .resolution             = {
870                         .ival           = 0,
871                         .fval           = 1064225,
872                 },
873         },
874 };
875
876 static struct nvi_rr nvi_rr_tmp[] = {
877         {
878                 .max_range              = {
879                         .ival           = 125,
880                         .fval           = 0,
881                 },
882                 .resolution             = {
883                         .ival           = 1,
884                         .fval           = 0,
885                 },
886         },
887 };
888
889 static struct nvi_rr nvi_rr_dmp[] = {
890         {
891                 .max_range              = {
892                         .ival           = 1,
893                         .fval           = 0,
894                 },
895                 .resolution             = {
896                         .ival           = 1,
897                         .fval           = 0,
898                 },
899         },
900 };
901
902 static const struct nvi_hal_dev nvi_hal_acc = {
903         .version                        = 3,
904         .src                            = SRC_ACC,
905         .rr_0n                          = ARRAY_SIZE(nvi_rr_acc) - 1,
906         .rr                             = nvi_rr_acc,
907         .milliamp                       = {
908                 .ival                   = 0,
909                 .fval                   = 500000000, /* NVS_FLOAT_NANO */
910         },
911         .fifo_en_msk                    = 0x1000,
912         .fifo                           = 1,
913         .fifo_data_n                    = 6,
914 };
915
916 static const struct nvi_hal_dev nvi_hal_gyr = {
917         .version                        = 3,
918         .src                            = SRC_GYR,
919         .rr_0n                          = ARRAY_SIZE(nvi_rr_gyr) - 1,
920         .rr                             = nvi_rr_gyr,
921         .milliamp                       = {
922                 .ival                   = 3,
923                 .fval                   = 700000000, /* NVS_FLOAT_NANO */
924         },
925         .fifo_en_msk                    = 0x0E00,
926         .fifo                           = 0,
927         .fifo_data_n                    = 6,
928 };
929
930 static const struct nvi_hal_dev nvi_hal_tmp = {
931         .version                        = 2,
932         .src                            = -1,
933         .rr_0n                          = ARRAY_SIZE(nvi_rr_tmp) - 1,
934         .rr                             = nvi_rr_tmp,
935         .scale                          = {
936                 .ival                   = 0,
937                 .fval                   = 334082700, /* NVS_FLOAT_NANO */
938         },
939         .offset                         = {
940                 .ival                   = 0,
941                 .fval                   = 137625600, /* NVS_FLOAT_NANO */
942         },
943         .milliamp                       = {
944                 .ival                   = 3,
945                 .fval                   = 700000000, /* NVS_FLOAT_NANO */
946         },
947 };
948
949 static const struct nvi_hal_dev nvi_hal_aux = {
950         .src                            = SRC_AUX,
951         .fifo_en_msk                    = 0x000F,
952 };
953
954 static const struct nvi_hal_dev nvi_hal_dmp = {
955         .version                        = 1,
956         .src                            = SRC_GYR,
957         .rr_0n                          = ARRAY_SIZE(nvi_rr_dmp) - 1,
958         .rr                             = nvi_rr_dmp,
959         .milliamp                       = {
960                 .ival                   = 0,
961                 .fval                   = 500000, /* NVS_FLOAT_MICRO */
962         },
963 };
964
965
966 static const struct nvi_hal_reg nvi_hal_reg_icm = {
967 /* register bank 0 */
968         .lp_config                      = {
969                 .bank                   = 0,
970                 .reg                    = 0x05,
971                 .dflt                   = 0x70,
972         },
973         .i2c_mst_status                 = {
974                 .bank                   = 0,
975                 .reg                    = 0x17,
976         },
977         .int_pin_cfg                    = {
978                 .bank                   = 0,
979                 .reg                    = 0x0F,
980         },
981         .int_enable                     = {
982                 .bank                   = 0,
983                 .reg                    = 0x10,
984                 .len                    = 4,
985         },
986         .int_dmp                        = {
987                 .bank                   = 0,
988                 .reg                    = 0x18,
989         },
990         .int_status                     = {
991                 .bank                   = 0,
992                 .reg                    = 0x19,
993                 .len                    = 4,
994         },
995         .out_h[DEV_ACC]         = {
996                 .bank                   = 0,
997                 .reg                    = 0x2D,
998         },
999         .out_h[DEV_GYR]         = {
1000                 .bank                   = 0,
1001                 .reg                    = 0x33,
1002         },
1003         .out_h[DEV_TMP]         = {
1004                 .bank                   = 0,
1005                 .reg                    = 0x39,
1006         },
1007         .ext_sens_data_00               = {
1008                 .bank                   = 0,
1009                 .reg                    = 0x3B,
1010         },
1011         .signal_path_reset              = {
1012                 .bank                   = 0,
1013                 .reg                    = 0x04,
1014         },
1015         .user_ctrl                      = {
1016                 .bank                   = 0,
1017                 .reg                    = 0x03,
1018         },
1019         .pm1                            = {
1020                 .bank                   = 0,
1021                 .reg                    = 0x06,
1022                 .dflt                   = 0x01,
1023         },
1024         .pm2                            = {
1025                 .bank                   = 0,
1026                 .reg                    = 0x07,
1027                 .dflt                   = 0x40,
1028         },
1029         .fifo_en                        = {
1030                 .bank                   = 0,
1031                 .reg                    = 0x66,
1032                 .len                    = 2,
1033         },
1034         .fifo_rst                       = {
1035                 .bank                   = 0,
1036                 .reg                    = 0x68,
1037         },
1038         .fifo_sz                        = {
1039                 .bank                   = 0,
1040                 .reg                    = 0x6E,
1041         },
1042         .fifo_count_h                   = {
1043                 .bank                   = 0,
1044                 .reg                    = 0x70,
1045                 .len                    = 2,
1046         },
1047         .fifo_rw                        = {
1048                 .bank                   = 0,
1049                 .reg                    = 0x72,
1050         },
1051         .fifo_cfg                       = {
1052                 .bank                   = 0,
1053                 .reg                    = 0x76,
1054         },
1055         .who_am_i                       = {
1056                 .bank                   = 0,
1057                 .reg                    = 0x00,
1058         },
1059         .mem_addr                       = {
1060                 .bank                   = 0,
1061                 .reg                    = 0x7C,
1062         },
1063         .mem_rw                         = {
1064                 .bank                   = 0,
1065                 .reg                    = 0x7D,
1066         },
1067         .mem_bank                       = {
1068                 .bank                   = 0,
1069                 .reg                    = 0x7E,
1070         },
1071         .reg_bank                       = {
1072                 .bank                   = 0,
1073                 .reg                    = 0x7F,
1074         },
1075 /* register bank 1 */
1076         .self_test_g[AXIS_X]            = {
1077                 .bank                   = 1,
1078                 .reg                    = 0x02,
1079         },
1080         .self_test_g[AXIS_Y]            = {
1081                 .bank                   = 1,
1082                 .reg                    = 0x03,
1083         },
1084         .self_test_g[AXIS_Z]            = {
1085                 .bank                   = 1,
1086                 .reg                    = 0x04,
1087         },
1088         .self_test_a[AXIS_X]    = {
1089                 .bank                   = 1,
1090                 .reg                    = 0x0E,
1091         },
1092         .self_test_a[AXIS_Y]    = {
1093                 .bank                   = 1,
1094                 .reg                    = 0x0F,
1095         },
1096         .self_test_a[AXIS_Z]    = {
1097                 .bank                   = 1,
1098                 .reg                    = 0x10,
1099         },
1100         .a_offset_h[AXIS_X]             = {
1101                 .bank                   = 1,
1102                 .reg                    = 0x14,
1103                 .len                    = 2,
1104         },
1105         .a_offset_h[AXIS_Y]             = {
1106                 .bank                   = 1,
1107                 .reg                    = 0x17,
1108                 .len                    = 2,
1109         },
1110         .a_offset_h[AXIS_Z]             = {
1111                 .bank                   = 1,
1112                 .reg                    = 0x1A,
1113                 .len                    = 2,
1114         },
1115         .tbc_pll                        = {
1116                 .bank                   = 1,
1117                 .reg                    = 0x28,
1118         },
1119         .tbc_rcosc                      = {
1120                 .bank                   = 1,
1121                 .reg                    = 0x29,
1122         },
1123 /* register bank 2 */
1124         .smplrt[SRC_GYR]                = {
1125                 .bank                   = 2,
1126                 .reg                    = 0x00,
1127         },
1128         .gyro_config1                   = {
1129                 .bank                   = 2,
1130                 .reg                    = 0x01,
1131                 .dflt                   = 0x01,
1132         },
1133         .gyro_config2                   = {
1134                 .bank                   = 2,
1135                 .reg                    = 0x02,
1136         },
1137         .g_offset_h[AXIS_X]             = {
1138                 .bank                   = 2,
1139                 .reg                    = 0x03,
1140                 .len                    = 2,
1141         },
1142         .g_offset_h[AXIS_Y]             = {
1143                 .bank                   = 2,
1144                 .reg                    = 0x05,
1145                 .len                    = 2,
1146         },
1147         .g_offset_h[AXIS_Z]             = {
1148                 .bank                   = 2,
1149                 .reg                    = 0x07,
1150                 .len                    = 2,
1151         },
1152         .smplrt[SRC_ACC]                = {
1153                 .bank                   = 2,
1154                 .reg                    = 0x10,
1155                 .len                    = 2,
1156         },
1157         .accel_config                   = {
1158                 .bank                   = 2,
1159                 .reg                    = 0x14,
1160         },
1161         .accel_config2                  = {
1162                 .bank                   = 2,
1163                 .reg                    = 0x15,
1164         },
1165         .fw_start                       = {
1166                 .bank                   = 2,
1167                 .reg                    = 0x50,
1168                 .len                    = 2,
1169         },
1170 /* register bank 3 */
1171         .i2c_mst_odr_config             = {
1172                 .bank                   = 3,
1173                 .reg                    = 0x00,
1174         },
1175         .i2c_mst_ctrl                   = {
1176                 .bank                   = 3,
1177                 .reg                    = 0x01,
1178         },
1179         .i2c_mst_delay_ctrl             = {
1180                 .bank                   = 3,
1181                 .reg                    = 0x02,
1182         },
1183         .i2c_slv_addr[0]                = {
1184                 .bank                   = 3,
1185                 .reg                    = 0x03,
1186         },
1187         .i2c_slv_addr[1]                = {
1188                 .bank                   = 3,
1189                 .reg                    = 0x07,
1190         },
1191         .i2c_slv_addr[2]                = {
1192                 .bank                   = 3,
1193                 .reg                    = 0x0B,
1194         },
1195         .i2c_slv_addr[3]                = {
1196                 .bank                   = 3,
1197                 .reg                    = 0x0F,
1198         },
1199         .i2c_slv_addr[4]                = {
1200                 .bank                   = 3,
1201                 .reg                    = 0x13,
1202         },
1203         .i2c_slv_reg[0]                 = {
1204                 .bank                   = 3,
1205                 .reg                    = 0x04,
1206         },
1207         .i2c_slv_reg[1]                 = {
1208                 .bank                   = 3,
1209                 .reg                    = 0x08,
1210         },
1211         .i2c_slv_reg[2]                 = {
1212                 .bank                   = 3,
1213                 .reg                    = 0x0C,
1214         },
1215         .i2c_slv_reg[3]                 = {
1216                 .bank                   = 3,
1217                 .reg                    = 0x10,
1218         },
1219         .i2c_slv_reg[4]                 = {
1220                 .bank                   = 3,
1221                 .reg                    = 0x14,
1222         },
1223         .i2c_slv_ctrl[0]                = {
1224                 .bank                   = 3,
1225                 .reg                    = 0x05,
1226         },
1227         .i2c_slv_ctrl[1]                = {
1228                 .bank                   = 3,
1229                 .reg                    = 0x09,
1230         },
1231         .i2c_slv_ctrl[2]                = {
1232                 .bank                   = 3,
1233                 .reg                    = 0x0D,
1234         },
1235         .i2c_slv_ctrl[3]                = {
1236                 .bank                   = 3,
1237                 .reg                    = 0x11,
1238         },
1239         .i2c_slv4_ctrl                  = {
1240                 .bank                   = 3,
1241                 .reg                    = 0x15,
1242         },
1243         .i2c_slv_do[0]                  = {
1244                 .bank                   = 3,
1245                 .reg                    = 0x06,
1246         },
1247         .i2c_slv_do[1]                  = {
1248                 .bank                   = 3,
1249                 .reg                    = 0x0A,
1250         },
1251         .i2c_slv_do[2]                  = {
1252                 .bank                   = 3,
1253                 .reg                    = 0x0E,
1254         },
1255         .i2c_slv_do[3]                  = {
1256                 .bank                   = 3,
1257                 .reg                    = 0x12,
1258         },
1259         .i2c_slv_do[4]                  = {
1260                 .bank                   = 3,
1261                 .reg                    = 0x16,
1262         },
1263         .i2c_slv4_di                    = {
1264                 .bank                   = 3,
1265                 .reg                    = 0x17,
1266         },
1267 };
1268
1269 static const struct nvi_hal_bit nvi_hal_bit_icm = {
1270         .dmp_int_sm                     = 2,
1271         .dmp_int_stp                    = 3,
1272         .int_i2c_mst                    = 0,
1273         .int_dmp                        = 1,
1274         .int_pll_rdy                    = 2,
1275         .int_wom                        = 3,
1276         .int_wof                        = 7,
1277         .int_data_rdy_0                 = 8,
1278         .int_data_rdy_1                 = 9,
1279         .int_data_rdy_2                 = 10,
1280         .int_data_rdy_3                 = 11,
1281         .int_fifo_ovrflw_0              = 16,
1282         .int_fifo_ovrflw_1              = 17,
1283         .int_fifo_ovrflw_2              = 18,
1284         .int_fifo_ovrflw_3              = 19,
1285         .int_fifo_wm_0                  = 24,
1286         .int_fifo_wm_1                  = 25,
1287         .int_fifo_wm_2                  = 26,
1288         .int_fifo_wm_3                  = 27,
1289         .slv_fifo_en[0]                 = 0,
1290         .slv_fifo_en[1]                 = 1,
1291         .slv_fifo_en[2]                 = 2,
1292         .slv_fifo_en[3]                 = 3,
1293 };
1294
1295 const struct nvi_hal nvi_hal_20628 = {
1296         .regs_n                         = 128,
1297         .reg_bank_n                     = 4,
1298         .src                            = src,
1299         .src_n                          = ARRAY_SIZE(src),
1300         .fifo_dev                       = nvi_fifo_devs,
1301         .fifo_n                         = ARRAY_SIZE(nvi_fifo_devs),
1302         .lp_tbl                         = nvi_lp_dly_us_tbl,
1303         .lp_tbl_n                       = ARRAY_SIZE(nvi_lp_dly_us_tbl),
1304         .dev[DEV_ACC]                   = &nvi_hal_acc,
1305         .dev[DEV_GYR]                   = &nvi_hal_gyr,
1306         .dev[DEV_TMP]                   = &nvi_hal_tmp,
1307         .dev[DEV_SM]                    = &nvi_hal_dmp,
1308         .dev[DEV_STP]                   = &nvi_hal_dmp,
1309         .dev[DEV_QTN]                   = &nvi_hal_dmp,
1310         .dev[DEV_GMR]                   = &nvi_hal_dmp,
1311         .dev[DEV_GYU]                   = &nvi_hal_gyr,
1312         .dev[DEV_AUX]                   = &nvi_hal_aux,
1313         .reg                            = &nvi_hal_reg_icm,
1314         .bit                            = &nvi_hal_bit_icm,
1315         .fn                             = &nvi_fn_icm,
1316         .dmp                            = &nvi_dmp_icm,
1317 };
1318 EXPORT_SYMBOL(nvi_hal_20628);
1319