tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / iio / magnetometer / inv_compass / inv_yas53x_iio.h
1 /*
2 * Copyright (C) 2012 Invensense, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 */
14
15 /**
16  *  @addtogroup DRIVERS
17  *  @brief      Hardware drivers.
18  *
19  *  @{
20  *      @file  inv_yas53x_iio.h
21  *      @brief Struct definitions for the Invensense implementation
22  *              of yas53x driver.
23  */
24
25 #ifndef _INV_GYRO_H_
26 #define _INV_GYRO_H_
27
28 #include <linux/i2c.h>
29 #include <linux/kfifo.h>
30 #include <linux/miscdevice.h>
31 #include <linux/input.h>
32 #include <linux/spinlock.h>
33 #include <linux/mpu.h>
34
35 #include "iio.h"
36 #include "buffer.h"
37 #include "trigger.h"
38
39 #define YAS_MAG_MAX_FILTER_LEN                  30
40 struct yas_adaptive_filter {
41         int num;
42         int index;
43         int filter_len;
44         int filter_noise;
45         int sequence[YAS_MAG_MAX_FILTER_LEN];
46 };
47
48 struct yas_thresh_filter {
49         int threshold;
50         int last;
51 };
52
53 struct yas_filter {
54         int filter_len;
55         int filter_thresh;
56         int filter_noise[3];
57         struct yas_adaptive_filter adap_filter[3];
58         struct yas_thresh_filter thresh_filter[3];
59 };
60
61 /**
62  *  struct inv_compass_state - Driver state variables.
63  *  @plat_data:         mpu platform data from board file.
64  *  @client:            i2c client handle.
65  *  @chan_info:         channel information.
66  *  @trig:              IIO trigger.
67  *  @work:              work structure.
68  *  @delay:             delay to schedule the next work.
69  *  @overflow_bound:    bound to determine overflow.
70  *  @center:            center of the measurement.
71  *  @compass_data[3]:   compass data store.
72  *  @offset[3]:         yas530 specific data.
73  *  @base_compass_data[3]: first measure data after reset.
74  *  @first_measure_after_reset:1: flag for first measurement after reset.
75  *  @first_read_after_reset:1: flag for first read after reset.
76  *  @reset_timer: timer to accumulate overflow conditions.
77  *  @overunderflow:1:     overflow and underflow flag.
78  *  @filter: filter data structure.
79  *  @read_data:         function pointer of reading data from device.
80  *  @get_cal_data: function pointer of reading cal data.
81  */
82 struct inv_compass_state {
83         struct mpu_platform_data plat_data;
84         struct i2c_client *client;
85         struct iio_trigger  *trig;
86         struct delayed_work work;
87         s16 delay;
88         s16 overflow_bound;
89         s16 upper_bound;
90         s16 lower_bound;
91         s16 center;
92         s16 compass_data[3];
93         s8 offset[3];
94         s16 base_compass_data[3];
95         u8 first_measure_after_reset:1;
96         u8 first_read_after_reset:1;
97         u8 overunderflow:1;
98         s32 reset_timer;
99         struct yas_filter filter;
100         int (*read_data)(struct inv_compass_state *st,
101                           int *, u16 *, u16 *, u16 *, u16 *);
102         int (*get_cal_data)(struct inv_compass_state *);
103 };
104
105 /* scan element definition */
106 enum inv_mpu_scan {
107         INV_YAS53X_SCAN_MAGN_X,
108         INV_YAS53X_SCAN_MAGN_Y,
109         INV_YAS53X_SCAN_MAGN_Z,
110         INV_YAS53X_SCAN_TIMESTAMP,
111 };
112
113 #define YAS530_REGADDR_DEVICE_ID          0x80
114 #define YAS530_REGADDR_ACTUATE_INIT_COIL  0x81
115 #define YAS530_REGADDR_MEASURE_COMMAND    0x82
116 #define YAS530_REGADDR_CONFIG             0x83
117 #define YAS530_REGADDR_MEASURE_INTERVAL   0x84
118 #define YAS530_REGADDR_OFFSET_X           0x85
119 #define YAS530_REGADDR_OFFSET_Y1          0x86
120 #define YAS530_REGADDR_OFFSET_Y2          0x87
121 #define YAS530_REGADDR_TEST1              0x88
122 #define YAS530_REGADDR_TEST2              0x89
123 #define YAS530_REGADDR_CAL                0x90
124 #define YAS530_REGADDR_MEASURE_DATA       0xb0
125
126 #define YAS530_MAX_DELAY                  200
127 #define YAS530_MIN_DELAY                  5
128 #define YAS530_SCALE                      107374182L
129
130 #define YAS_YAS530_VERSION_A            0       /* YAS530  (MS-3E Aver) */
131 #define YAS_YAS530_VERSION_B            1       /* YAS530B (MS-3E Bver) */
132 #define YAS_YAS530_VERSION_A_COEF       380
133 #define YAS_YAS530_VERSION_B_COEF       550
134 #define YAS_YAS530_DATA_CENTER          2048
135 #define YAS_YAS530_DATA_OVERFLOW        4095
136 #define YAS_YAS530_CAL_DATA_SIZE        16
137
138 /*filter related defines */
139 #define YAS_MAG_DEFAULT_FILTER_NOISE_X          144 /* sd: 1200 nT */
140 #define YAS_MAG_DEFAULT_FILTER_NOISE_Y          144 /* sd: 1200 nT */
141 #define YAS_MAG_DEFAULT_FILTER_NOISE_Z          144 /* sd: 1200 nT */
142 #define YAS_MAG_DEFAULT_FILTER_LEN              20
143
144 #define YAS530_MAG_DEFAULT_FILTER_THRESH        100
145 #define YAS532_MAG_DEFAULT_FILTER_THRESH        300
146
147 #define YAS_YAS532_533_VERSION_AB       0 /* YAS532_533AB (MS-3R/3F ABver) */
148 #define YAS_YAS532_533_VERSION_AC       1 /* YAS532_533AC (MS-3R/3F ACver) */
149 #define YAS_YAS532_533_VERSION_AB_COEF  1800
150 #define YAS_YAS532_533_VERSION_AC_COEF  900
151 #define YAS_YAS532_533_DATA_CENTER      4096
152 #define YAS_YAS532_533_DATA_OVERFLOW    8190
153 #define YAS_YAS532_533_CAL_DATA_SIZE    14
154
155 #define YAS_MAG_DISTURBURNCE_THRESHOLD  1600
156 #define YAS_RESET_COIL_TIME_THRESHOLD   3000
157
158 #define INV_ERROR_COMPASS_DATA_OVERFLOW  (-1)
159 #define INV_ERROR_COMPASS_DATA_NOT_READY (-2)
160
161 int inv_yas53x_configure_ring(struct iio_dev *indio_dev);
162 void inv_yas53x_unconfigure_ring(struct iio_dev *indio_dev);
163 int inv_yas53x_probe_trigger(struct iio_dev *indio_dev);
164 void inv_yas53x_remove_trigger(struct iio_dev *indio_dev);
165 void set_yas53x_enable(struct iio_dev *indio_dev, bool enable);
166 void inv_read_yas53x_fifo(struct iio_dev *indio_dev);
167 int yas53x_read(struct inv_compass_state *st, short rawfixed[3],
168                                 s32 *overunderflow);
169 int yas53x_resume(struct inv_compass_state *st);
170
171 #endif  /* #ifndef _INV_GYRO_H_ */
172