1
2
3
4
5
6
7
8
9
10
11
12#ifndef ST_LSM6DSX_H
13#define ST_LSM6DSX_H
14
15#include <linux/device.h>
16
17#define ST_LSM6DS3_DEV_NAME "lsm6ds3"
18#define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
19#define ST_LSM6DSL_DEV_NAME "lsm6dsl"
20#define ST_LSM6DSM_DEV_NAME "lsm6dsm"
21#define ST_ISM330DLC_DEV_NAME "ism330dlc"
22
23enum st_lsm6dsx_hw_id {
24 ST_LSM6DS3_ID,
25 ST_LSM6DS3H_ID,
26 ST_LSM6DSL_ID,
27 ST_LSM6DSM_ID,
28 ST_ISM330DLC_ID,
29 ST_LSM6DSX_MAX_ID,
30};
31
32#define ST_LSM6DSX_BUFF_SIZE 400
33#define ST_LSM6DSX_CHAN_SIZE 2
34#define ST_LSM6DSX_SAMPLE_SIZE 6
35#define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
36 ST_LSM6DSX_SAMPLE_SIZE)
37#define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
38
39struct st_lsm6dsx_reg {
40 u8 addr;
41 u8 mask;
42};
43
44
45
46
47
48
49
50struct st_lsm6dsx_fifo_ops {
51 struct {
52 u8 addr;
53 u16 mask;
54 } fifo_th;
55 struct {
56 u8 addr;
57 u16 mask;
58 } fifo_diff;
59 u8 th_wl;
60};
61
62
63
64
65
66
67
68
69struct st_lsm6dsx_hw_ts_settings {
70 struct st_lsm6dsx_reg timer_en;
71 struct st_lsm6dsx_reg hr_timer;
72 struct st_lsm6dsx_reg fifo_en;
73 struct st_lsm6dsx_reg decimator;
74};
75
76
77
78
79
80
81
82
83
84
85struct st_lsm6dsx_settings {
86 u8 wai;
87 u16 max_fifo_size;
88 enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
89 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
90 struct st_lsm6dsx_fifo_ops fifo_ops;
91 struct st_lsm6dsx_hw_ts_settings ts_settings;
92};
93
94enum st_lsm6dsx_sensor_id {
95 ST_LSM6DSX_ID_ACC,
96 ST_LSM6DSX_ID_GYRO,
97 ST_LSM6DSX_ID_MAX,
98};
99
100enum st_lsm6dsx_fifo_mode {
101 ST_LSM6DSX_FIFO_BYPASS = 0x0,
102 ST_LSM6DSX_FIFO_CONT = 0x6,
103};
104
105
106
107
108
109
110
111
112
113
114
115
116
117struct st_lsm6dsx_sensor {
118 char name[32];
119 enum st_lsm6dsx_sensor_id id;
120 struct st_lsm6dsx_hw *hw;
121
122 u32 gain;
123 u16 odr;
124
125 u16 watermark;
126 u8 sip;
127 u8 decimator;
128 s64 ts_ref;
129};
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146struct st_lsm6dsx_hw {
147 struct device *dev;
148 struct regmap *regmap;
149 int irq;
150
151 struct mutex fifo_lock;
152 struct mutex conf_lock;
153
154 enum st_lsm6dsx_fifo_mode fifo_mode;
155 u8 enable_mask;
156 u8 ts_sip;
157 u8 sip;
158
159 u8 *buff;
160
161 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
162
163 const struct st_lsm6dsx_settings *settings;
164};
165
166extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
167
168int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
169 struct regmap *regmap);
170int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor);
171int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor);
172int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
173int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
174 u16 watermark);
175int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
176int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
177 enum st_lsm6dsx_fifo_mode fifo_mode);
178
179#endif
180