upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / staging / iio / gyro / k3g.h
1 /*
2  *  k3g.h -  ST Microelectronics three-axis gyroscope sensor 
3  
4  *  Copyright (c) 2010 Samsung Eletronics
5  *  Donggeun Kim <dg77.kim@samsung.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #ifndef _K3G_H_
13 #define _K3G_H_
14
15 #define K3G_WHO_AM_I                    0x0f
16 #define K3G_CTRL_REG1                   0x20
17 #define K3G_CTRL_REG2                   0x21
18 #define K3G_CTRL_REG3                   0x22
19 #define K3G_CTRL_REG4                   0x23
20 #define K3G_CTRL_REG5                   0x24
21 #define K3G_REFERENCE                   0x25
22 #define K3G_OUT_TEMP                    0x26
23 #define K3G_STATUS_REG                  0x27
24 #define K3G_OUT_X_L                     0x28
25 #define K3G_OUT_X_H                     0x29
26 #define K3G_OUT_Y_L                     0x2a
27 #define K3G_OUT_Y_H                     0x2b
28 #define K3G_OUT_Z_L                     0x2c
29 #define K3G_OUT_Z_H                     0x2d
30 #define K3G_FIFO_CTRL_REG               0x2e
31 #define K3G_FIFO_SRC_REG                0x2f
32 #define K3G_INT1_CFG_REG                0x30
33 #define K3G_INT1_SRC_REG                0x31
34 #define K3G_INT1_THS_XH                 0x32
35 #define K3G_INT1_THS_XL                 0x33
36 #define K3G_INT1_THS_YH                 0x34
37 #define K3G_INT1_THS_YL                 0x35
38 #define K3G_INT1_THS_ZH                 0x36
39 #define K3G_INT1_THS_ZL                 0x37
40 #define K3G_INT1_DURATION_REG           0x38
41
42 #define K3G_MULTI_OUT_X_L               0xa8
43
44 #define K3G_DATA_RATE_SHIFT             6
45 #define K3G_DATA_RATE_105HZ             ((0x0) << K3G_DATA_RATE_SHIFT)
46 #define K3G_DATA_RATE_210HZ             ((0x1) << K3G_DATA_RATE_SHIFT)
47 #define K3G_DATA_RATE_420HZ             ((0x2) << K3G_DATA_RATE_SHIFT)
48 #define K3G_DATA_RATE_840HZ             ((0x3) << K3G_DATA_RATE_SHIFT)
49 #define K3G_BANDWIDTH_SHIFT             4
50 #define K3G_BANDWIDTH_MASK              ((0x3) << K3G_BANDWIDTH_SHIFT)
51 #define K3G_POWERDOWN_SHIFT             3
52 #define K3G_POWERDOWN_POWER_DOWN        ((0x0) << K3G_POWERDOWN_SHIFT)
53 #define K3G_POWERDOWN_NORMAL            ((0x1) << K3G_POWERDOWN_SHIFT)
54 #define K3G_POWERDOWN_MASK              ((0x1) << K3G_POWERDOWN_SHIFT)
55 #define K3G_Z_EN_SHIFT                  2
56 #define K3G_Z_EN                        ((0x1) << K3G_Z_EN_SHIFT)
57 #define K3G_Y_EN_SHIFT                  1
58 #define K3G_Y_EN                        ((0x1) << K3G_Y_EN_SHIFT)
59 #define K3G_X_EN_SHIFT                  0
60 #define K3G_X_EN                        ((0x1) << K3G_X_EN_SHIFT)
61
62 #define K3G_HIGH_PASS_FILTER_SHIFT                              4
63 #define K3G_HIGH_PASS_FILTER_NORMAL_MODE_RESET_READING  ((0x0) << K3G_HIGH_PASS_FILTER_SHIFT)
64 #define K3G_HIGH_PASS_FILTER_REFERENCE_SIGNAL           ((0x1) << K3G_HIGH_PASS_FILTER_SHIFT)
65 #define K3G_HIGH_PASS_FILTER_NORMAL_MODE                ((0x2) << K3G_HIGH_PASS_FILTER_SHIFT)
66 #define K3G_HIGH_PASS_FILTER_AUTORESET_ON_INTERRUPT     ((0x3) << K3G_HIGH_PASS_FILTER_SHIFT)
67 #define K3G_HIGH_PASS_FILTER_CUTOFF_FREQ_SHIFT                  0
68 #define K3G_HIGH_PASS_FILTER_CUTOFF_FREQ_MASK                   ((0xf) << K3G_HIGH_PASS_FILTER_CUTOFF_FREQ_SHIFT)
69
70 #define K3G_INT1_EN_SHIFT                       7
71 #define K3G_INT1_EN                             ((0x1) << K3G_INT1_EN_SHIFT)
72 #define K3G_INT1_BOOT_SHIFT                     6
73 #define K3G_INT1_BOOT                           ((0x1) << K3G_INT1_BOOT_SHIFT)
74 #define K3G_INT1_ACTIVE_SHIFT                   5
75 #define K3G_INT1_ACTIVE_HIGH                    ((0x0) << K3G_INT1_ACTIVE_SHIFT)
76 #define K3G_INT1_ACTIVE_LOW                     ((0x1) << K3G_INT1_ACTIVE_SHIFT)
77 #define K3G_INT_PUSH_PULL_OPEN_DRAIN_SHIFT      4
78 #define K3G_INT_PUSH_PULL                       ((0x0) << K3G_INT_PUSH_PULL_OPEN_DRAIN_SHIFT)
79 #define K3G_INT_OPEN_DRAIN                      ((0x1) << K3G_INT_PUSH_PULL_OPEN_DRAIN_SHIFT)
80 #define K3G_INT2_SRC_SHIFT                      0
81 #define K3G_INT2_SRC_MASK                       ((0x0f) << K3G_INT2_SRC_SHIFT)
82 #define K3G_INT2_DATA_READY_SHIFT               3
83 #define K3G_INT2_DATA_READY                     ((0x1) << K3G_INT2_DATA_READY_SHIFT)
84 #define K3G_INT2_WATERMARK_SHIFT                2
85 #define K3G_INT2_WATERMARK                      ((0x1) << K3G_INT2_WATERMARK_SHIFT)
86 #define K3G_INT2_OVERRUN_SHIFT                  1
87 #define K3G_INT2_OVERRUN                        ((0x1) << K3G_INT2_OVERRUN_SHIFT)
88 #define K3G_INT2_EMPTY_SHIFT                    0
89 #define K3G_INT2_EMPTY                          ((0x1) << K3G_INT2_EMPTY_SHIFT)
90
91 #define K3G_BLOCK_DATA_UPDATE_SHIFT             7
92 #define K3G_BLOCK_DATA_UPDATE                   ((0x1) << K3G_BLOCK_DATA_UPDATE_SHIFT)
93 #define K3G_BIG_LITTLE_ENDIAN_SHIFT             6
94 #define K3G_BIG_ENDIAN                          ((0x0) << K3G_BIG_LITTLE_ENDIAN_SHIFT)
95 #define K3G_LITTLE_ENDIAN                       ((0x1) << K3G_BIG_LITTLE_ENDIAN_SHIFT)
96 #define K3G_FULL_SCALE_SHIFT                    4
97 #define K3G_FULL_SCALE_250DPS                   ((0x0) << K3G_FULL_SCALE_SHIFT)
98 #define K3G_FULL_SCALE_500DPS                   ((0x1) << K3G_FULL_SCALE_SHIFT)
99 #define K3G_FULL_SCALE_2000DPS                  ((0x2) << K3G_FULL_SCALE_SHIFT)
100 #define K3G_SELF_TEST_SHIFT                     1
101 #define K3G_SELF_TESET_NORMAL                   ((0x0) << K3G_SELF_TEST_SHIFT)
102 #define K3G_SELF_TESET_0                        ((0x1) << K3G_SELF_TEST_SHIFT)
103 #define K3G_SELF_TESET_1                        ((0x3) << K3G_SELF_TEST_SHIFT)
104 #define K3G_SPI_MODE_SHIFT                      0
105 #define K3G_SPI_FOUR_WIRE                       ((0x0) << K3G_SPI_MODE_SHIFT)
106 #define K3G_SPI_THREE_WIRE                      ((0x1) << K3G_SPI_MODE_SHIFT)
107
108 #define K3G_REBOOT_SHIFT                        7
109 #define K3G_REBOOT                              ((0x1) << K3G_REBOOT_SHIFT)
110 #define K3G_FIFO_EN_SHIFT                       6
111 #define K3G_FIFO_EN                             ((0x1) << K3G_FIFO_EN_SHIFT)
112 #define K3G_HIGH_PASS_FILTER_EN_SHIFT           4
113 #define K3G_HIGH_PASS_FILTER_EN                 ((0x1) << K3G_HIGH_PASS_FILTER_EN_SHIFT)
114 #define K3G_INT1_SELECTION_SHIFT                2
115 #define K3G_INT1_SELECTION                      ((0x3) << K3G_INT1_SELECTION_SHIFT)
116 #define K3G_OUT_SELECTION_SHIFT                 0
117 #define K3G_OUT_SELECTION                       ((0x3) << K3G_OUT_SELECTION_SHIFT)
118
119 #define K3G_ZYX_OVERRUN_SHIFT                   7
120 #define K3G_ZYX_OVERRUN                         ((0x1) << K3G_ZYX_OVERRUN_SHIFT)
121 #define K3G_Z_OVERRUN_SHIFT                     6
122 #define K3G_Z_OVERRUN                           ((0x1) << K3G_Z_OVERRUN_SHIFT)
123 #define K3G_Y_OVERRUN_SHIFT                     5
124 #define K3G_Y_OVERRUN                           ((0x1) << K3G_Y_OVERRUN_SHIFT)
125 #define K3G_X_OVERRUN_SHIFT                     4
126 #define K3G_X_OVERRUN                           ((0x1) << K3G_X_OVERRUN_SHIFT)
127 #define K3G_ZYX_DATA_AVAILABLE_SHIFT            3
128 #define K3G_ZYX_DATA_AVAILABEL                  ((0x1) << K3G_ZYX_DATA_AVAILABLE_SHIFT)
129 #define K3G_Z_DATA_AVAILABLE_SHIFT              2
130 #define K3G_Z_DATA_AVAILABLE                    ((0x1) << K3G_Z_DATA_AVAILABLE_SHIFT)
131 #define K3G_Y_DATA_AVAILABLE_SHIFT              1
132 #define K3G_Y_DATA_AVAILABLE                    ((0x1) << K3G_Y_DATA_AVAILABLE_SHIFT)
133 #define K3G_X_DATA_AVAILABLE_SHIFT              0
134 #define K3G_X_DATA_AVAILABLE                    ((0x1) << K3G_X_DATA_AVAILABLE_SHIFT)
135
136 #define K3G_FIFO_MODE_SHIFT                     5
137 #define K3G_FIFO_BYPASS_MODE                    ((0x0) << K3G_FIFO_MODE_SHIFT)
138 #define K3G_FIFO_FIFO_MODE                      ((0x1) << K3G_FIFO_MODE_SHIFT)
139 #define K3G_FIFO_STREAM_MODE                    ((0x2) << K3G_FIFO_MODE_SHIFT)
140 #define K3G_FIFO_STREAM_TO_FIFO_MODE            ((0x3) << K3G_FIFO_MODE_SHIFT)
141 #define K3G_FIFO_BYPASS_TO_STREAM_MODE          ((0x4) << K3G_FIFO_MODE_SHIFT)
142 #define K3G_FIFO_MODE_MASK                      ((0x7) << K3G_FIFO_MODE_SHIFT)
143 #define K3G_WATERMARK_THRES_SHIFT               0
144 #define K3G_WATERMARK_THRES_MASK                ((0x1f) << K3G_WATERMARK_THRES_SHIFT)
145
146 #define K3G_WATERMARK_SHIFT                     7
147 #define K3G_WATERMARK                           ((0x1) << K3G_WATERMARK_SHIFT)
148 #define K3G_OVERRUN_SHIFT                       6
149 #define K3G_OVERRUN                             ((0x1) << K3G_OVERRUN_SHIFT)
150 #define K3G_EMPTY_SHIFT                         5
151 #define K3G_EMPTY                               ((0x1) << K3G_EMPTY_SHIFT)
152 #define K3G_FIFO_STORED_SHIFT                   0
153 #define K3G_FIFO_STORED_MASK                    ((0x1f) << K3G_FIFO_STORED_SHIFT)
154
155 #define K3G_AND_OR_COMBINATION_SHIFT            7
156 #define K3G_OR_COMBINATION                      ((0x0) << K3G_AND_OR_COMBINATION_SHIFT)
157 #define K3G_AND_COMBINATION                     ((0x1) << K3G_AND_OR_COMBINATION_SHIFT)
158 #define K3G_LATCH_INTERRUPT_SHIFT               6
159 #define K3G_INTERRUPT_NO_LATCHED                ((0x0) << K3G_LATCH_INTERRUPT_SHIFT)
160 #define K3G_INTERRUPT_LATCHED                   ((0x1) << K3G_LATCH_INTERRUPT_SHIFT)
161 #define K3G_Z_HIGH_INT_EN_SHIFT                 5
162 #define K3G_Z_HIGH_INT_EN                       ((0x1) << K3G_Z_HIGH_INT_EN_SHIFT)
163 #define K3G_Z_LOW_INT_EN_SHIFT                  4
164 #define K3G_Z_LOW_INT_EN                        ((0x1) << K3G_Z_LOW_INT_EN_SHIFT)
165 #define K3G_Y_HIGH_INT_EN_SHIFT                 3
166 #define K3G_Y_HIGH_INT_EN                       ((0x1) << K3G_Y_HIGH_INT_EN_SHIFT)
167 #define K3G_Y_LOW_INT_EN_SHIFT                  2
168 #define K3G_Y_LOW_INT_EN                        ((0x1) << K3G_Y_LOW_INT_EN_SHIFT)
169 #define K3G_X_HIGH_INT_EN_SHIFT                 1
170 #define K3G_X_HIGH_INT_EN                       ((0x1) << K3G_X_HIGH_INT_EN_SHIFT)
171 #define K3G_X_LOW_INT_EN_SHIFT                  0
172 #define K3G_X_LOW_INT_EN                        ((0x1) << K3G_X_LOW_INT_EN_SHIFT)
173
174 #define K3G_INTERRUPT_ACTIVE_SHIFT              6
175 #define K3G_INTERRUPT_ACTIVE                    ((0x1) << K3G_INTERRUPT_ACTIVE_SHIFT)
176 #define K3G_Z_HIGH_SHIFT                        5
177 #define K3G_Z_HIGH                              ((0x1) << K3G_Z_HIGH_SHIFT)
178 #define K3G_Z_LOW_SHIFT                         4
179 #define K3G_Z_LOW                               ((0x1) << K3G_Z_LOW_SHIFT)
180 #define K3G_Y_HIGH_SHIFT                        3
181 #define K3G_Y_HIGH                              ((0x1) << K3G_Y_HIGH_SHIFT)
182 #define K3G_Y_LOW_SHIFT                         2
183 #define K3G_Y_LOW                               ((0x1) << K3G_Y_LOW_SHIFT)
184 #define K3G_X_HIGH_SHIFT                        1
185 #define K3G_X_HIGH                              ((0x1) << K3G_X_HIGH_SHIFT)
186 #define K3G_X_LOW_SHIFT                         0
187 #define K3G_X_LOW                               ((0x1) << K3G_X_LOW_SHIFT)
188
189 #define K3G_INT1_WAIT_EN_SHIFT                  7
190 #define K3G_INT1_WAIT_EN                        ((0x1) << K3G_INT1_WAIT_EN_SHIFT)
191 #define K3G_INT1_DURATION_SHIFT                 0
192 #define K3G_INT1_DURATION_MASK                  ((0x7f) << K3G_INT1_DURATION_SHIFT)
193
194 #define K3G_TEMP_SHIFT                          0
195 #define K3G_TEMP_MASK                           ((0xff) << K3G_TEMP_SHIFT)
196
197 #define K3G_DEV_ID                              0xd3
198
199 struct k3g_platform_data {
200         int irq2;
201         u8 data_rate;
202         u8 bandwidth;
203         u8 powerdown;
204         u8 zen;
205         u8 yen;
206         u8 xen;
207         u8 hpmode;
208         u8 hpcf;
209         u8 int1_enable;
210         u8 int1_boot;
211         u8 int1_hl_active;
212         u8 int_pp_od;
213         u8 int2_src;
214         u8 block_data_update;
215         u8 endian;
216         u8 fullscale;
217         u8 selftest;
218         u8 spi_mode;
219         u8 reboot;
220         u8 fifo_enable;
221         u8 hp_enable;
222         u8 int1_sel;
223         u8 out_sel;
224         u8 fifo_mode;
225         u8 fifo_threshold;
226         u8 int1_combination;
227         u8 int1_latch;
228         u8 int1_z_high_enable;
229         u8 int1_z_low_enable;
230         u8 int1_y_high_enable;
231         u8 int1_y_low_enable;
232         u8 int1_x_high_enable;
233         u8 int1_x_low_enable;
234         u8 int1_wait_enable;
235         u8 int1_wait_duration;
236         u16 int1_z_threshold;
237         u16 int1_y_threshold;
238         u16 int1_x_threshold;
239 };
240
241 struct k3g_chip {
242         struct i2c_client               *client;
243         struct iio_dev                  *indio_dev;
244         struct work_struct              work_thresh;
245         struct work_struct              work_fifo;
246         struct iio_trigger              *trig;
247         s64                             last_timestamp;
248         struct mutex                    lock;
249         struct mutex                    ring_lock;
250         struct k3g_platform_data        *pdata;
251 };
252
253 int k3g_set_8bit_value(struct k3g_chip *chip, u8 val,
254                        u8 *cached_value, u8 shift, u8 mask, u8 reg);
255 int k3g_get_raw_value(struct k3g_chip *chip, int reg);
256 int k3g_get_8bit_value(struct k3g_chip *chip, u8 shift, u8 mask, u8 reg);
257
258 int k3g_configure_ring(struct iio_dev *indio_dev);
259 void k3g_unconfigure_ring(struct iio_dev *indio_dev);
260
261 void k3g_register_ring_funcs(struct iio_dev *indio_dev);
262 void k3g_ring_int_process(int val, struct iio_ring_buffer *ring);
263
264 #endif