This source file includes following definitions.
- st_lsm6dsx_update_bits_locked
- st_lsm6dsx_read_locked
- st_lsm6dsx_write_locked
1
2
3
4
5
6
7
8
9
10
11 #ifndef ST_LSM6DSX_H
12 #define ST_LSM6DSX_H
13
14 #include <linux/device.h>
15
16 #define ST_LSM6DS3_DEV_NAME "lsm6ds3"
17 #define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
18 #define ST_LSM6DSL_DEV_NAME "lsm6dsl"
19 #define ST_LSM6DSM_DEV_NAME "lsm6dsm"
20 #define ST_ISM330DLC_DEV_NAME "ism330dlc"
21 #define ST_LSM6DSO_DEV_NAME "lsm6dso"
22 #define ST_ASM330LHH_DEV_NAME "asm330lhh"
23 #define ST_LSM6DSOX_DEV_NAME "lsm6dsox"
24 #define ST_LSM6DSR_DEV_NAME "lsm6dsr"
25 #define ST_LSM6DS3TRC_DEV_NAME "lsm6ds3tr-c"
26 #define ST_ISM330DHCX_DEV_NAME "ism330dhcx"
27 #define ST_LSM9DS1_DEV_NAME "lsm9ds1-imu"
28
29 enum st_lsm6dsx_hw_id {
30 ST_LSM6DS3_ID,
31 ST_LSM6DS3H_ID,
32 ST_LSM6DSL_ID,
33 ST_LSM6DSM_ID,
34 ST_ISM330DLC_ID,
35 ST_LSM6DSO_ID,
36 ST_ASM330LHH_ID,
37 ST_LSM6DSOX_ID,
38 ST_LSM6DSR_ID,
39 ST_LSM6DS3TRC_ID,
40 ST_ISM330DHCX_ID,
41 ST_LSM9DS1_ID,
42 ST_LSM6DSX_MAX_ID,
43 };
44
45 #define ST_LSM6DSX_BUFF_SIZE 512
46 #define ST_LSM6DSX_CHAN_SIZE 2
47 #define ST_LSM6DSX_SAMPLE_SIZE 6
48 #define ST_LSM6DSX_TAG_SIZE 1
49 #define ST_LSM6DSX_TAGGED_SAMPLE_SIZE (ST_LSM6DSX_SAMPLE_SIZE + \
50 ST_LSM6DSX_TAG_SIZE)
51 #define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
52 ST_LSM6DSX_SAMPLE_SIZE)
53 #define ST_LSM6DSX_MAX_TAGGED_WORD_LEN ((32 / ST_LSM6DSX_TAGGED_SAMPLE_SIZE) \
54 * ST_LSM6DSX_TAGGED_SAMPLE_SIZE)
55 #define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
56
57 #define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \
58 { \
59 .type = chan_type, \
60 .address = addr, \
61 .modified = 1, \
62 .channel2 = mod, \
63 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
64 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
65 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
66 .scan_index = scan_idx, \
67 .scan_type = { \
68 .sign = 's', \
69 .realbits = 16, \
70 .storagebits = 16, \
71 .endianness = IIO_LE, \
72 }, \
73 }
74
75 struct st_lsm6dsx_reg {
76 u8 addr;
77 u8 mask;
78 };
79
80 struct st_lsm6dsx_sensor;
81 struct st_lsm6dsx_hw;
82
83 struct st_lsm6dsx_odr {
84 u16 hz;
85 u8 val;
86 };
87
88 #define ST_LSM6DSX_ODR_LIST_SIZE 6
89 struct st_lsm6dsx_odr_table_entry {
90 struct st_lsm6dsx_reg reg;
91 struct st_lsm6dsx_odr odr_avl[ST_LSM6DSX_ODR_LIST_SIZE];
92 };
93
94 struct st_lsm6dsx_fs {
95 u32 gain;
96 u8 val;
97 };
98
99 #define ST_LSM6DSX_FS_LIST_SIZE 4
100 struct st_lsm6dsx_fs_table_entry {
101 struct st_lsm6dsx_reg reg;
102
103 struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
104 int fs_len;
105 };
106
107
108
109
110
111
112
113
114
115 struct st_lsm6dsx_fifo_ops {
116 int (*update_fifo)(struct st_lsm6dsx_sensor *sensor, bool enable);
117 int (*read_fifo)(struct st_lsm6dsx_hw *hw);
118 struct {
119 u8 addr;
120 u16 mask;
121 } fifo_th;
122 struct {
123 u8 addr;
124 u16 mask;
125 } fifo_diff;
126 u8 th_wl;
127 };
128
129
130
131
132
133
134
135
136 struct st_lsm6dsx_hw_ts_settings {
137 struct st_lsm6dsx_reg timer_en;
138 struct st_lsm6dsx_reg hr_timer;
139 struct st_lsm6dsx_reg fifo_en;
140 struct st_lsm6dsx_reg decimator;
141 };
142
143
144
145
146
147
148
149
150
151
152
153
154
155 struct st_lsm6dsx_shub_settings {
156 struct st_lsm6dsx_reg page_mux;
157 struct st_lsm6dsx_reg master_en;
158 struct st_lsm6dsx_reg pullup_en;
159 struct st_lsm6dsx_reg aux_sens;
160 struct st_lsm6dsx_reg wr_once;
161 u8 shub_out;
162 u8 slv0_addr;
163 u8 dw_slv0_addr;
164 u8 batch_en;
165 };
166
167 enum st_lsm6dsx_ext_sensor_id {
168 ST_LSM6DSX_ID_MAGN,
169 };
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 struct st_lsm6dsx_ext_dev_settings {
185 u8 i2c_addr[2];
186 struct {
187 u8 addr;
188 u8 val;
189 } wai;
190 enum st_lsm6dsx_ext_sensor_id id;
191 struct st_lsm6dsx_odr_table_entry odr_table;
192 struct st_lsm6dsx_fs_table_entry fs_table;
193 struct st_lsm6dsx_reg temp_comp;
194 struct {
195 struct st_lsm6dsx_reg reg;
196 u8 off_val;
197 u8 on_val;
198 } pwr_table;
199 struct st_lsm6dsx_reg off_canc;
200 struct st_lsm6dsx_reg bdu;
201 struct {
202 u8 addr;
203 u8 len;
204 } out;
205 };
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 struct st_lsm6dsx_settings {
225 u8 wai;
226 u8 int1_addr;
227 u8 int2_addr;
228 u8 reset_addr;
229 u16 max_fifo_size;
230 struct {
231 enum st_lsm6dsx_hw_id hw_id;
232 const char *name;
233 } id[ST_LSM6DSX_MAX_ID];
234 struct {
235 const struct iio_chan_spec *chan;
236 int len;
237 } channels[2];
238 struct st_lsm6dsx_odr_table_entry odr_table[2];
239 struct st_lsm6dsx_fs_table_entry fs_table[2];
240 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
241 struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
242 struct st_lsm6dsx_fifo_ops fifo_ops;
243 struct st_lsm6dsx_hw_ts_settings ts_settings;
244 struct st_lsm6dsx_shub_settings shub_settings;
245 };
246
247 enum st_lsm6dsx_sensor_id {
248 ST_LSM6DSX_ID_GYRO,
249 ST_LSM6DSX_ID_ACC,
250 ST_LSM6DSX_ID_EXT0,
251 ST_LSM6DSX_ID_EXT1,
252 ST_LSM6DSX_ID_EXT2,
253 ST_LSM6DSX_ID_MAX,
254 };
255
256 enum st_lsm6dsx_fifo_mode {
257 ST_LSM6DSX_FIFO_BYPASS = 0x0,
258 ST_LSM6DSX_FIFO_CONT = 0x6,
259 };
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 struct st_lsm6dsx_sensor {
275 char name[32];
276 enum st_lsm6dsx_sensor_id id;
277 struct st_lsm6dsx_hw *hw;
278
279 u32 gain;
280 u16 odr;
281
282 u16 watermark;
283 u8 sip;
284 u8 decimator;
285 s64 ts_ref;
286
287 struct {
288 const struct st_lsm6dsx_ext_dev_settings *settings;
289 u8 addr;
290 } ext_info;
291 };
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310 struct st_lsm6dsx_hw {
311 struct device *dev;
312 struct regmap *regmap;
313 int irq;
314
315 struct mutex fifo_lock;
316 struct mutex conf_lock;
317 struct mutex page_lock;
318
319 enum st_lsm6dsx_fifo_mode fifo_mode;
320 u8 suspend_mask;
321 u8 enable_mask;
322 u8 ts_sip;
323 u8 sip;
324
325 u8 *buff;
326
327 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
328
329 const struct st_lsm6dsx_settings *settings;
330 };
331
332 static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
333 extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
334
335 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
336 struct regmap *regmap);
337 int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
338 bool enable);
339 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
340 int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val);
341 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
342 u16 watermark);
343 int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable);
344 int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
345 int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
346 enum st_lsm6dsx_fifo_mode fifo_mode);
347 int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
348 int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw);
349 int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val);
350 int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name);
351 int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable);
352 int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable);
353
354 static inline int
355 st_lsm6dsx_update_bits_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
356 unsigned int mask, unsigned int val)
357 {
358 int err;
359
360 mutex_lock(&hw->page_lock);
361 err = regmap_update_bits(hw->regmap, addr, mask, val);
362 mutex_unlock(&hw->page_lock);
363
364 return err;
365 }
366
367 static inline int
368 st_lsm6dsx_read_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
369 void *val, unsigned int len)
370 {
371 int err;
372
373 mutex_lock(&hw->page_lock);
374 err = regmap_bulk_read(hw->regmap, addr, val, len);
375 mutex_unlock(&hw->page_lock);
376
377 return err;
378 }
379
380 static inline int
381 st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
382 unsigned int val)
383 {
384 int err;
385
386 mutex_lock(&hw->page_lock);
387 err = regmap_write(hw->regmap, addr, val);
388 mutex_unlock(&hw->page_lock);
389
390 return err;
391 }
392
393 #endif