This source file includes following definitions.
- st_sensors_allocate_trigger
- st_sensors_deallocate_trigger
- st_sensors_of_name_probe
1
2
3
4
5
6
7
8
9
10 #ifndef ST_SENSORS_H
11 #define ST_SENSORS_H
12
13 #include <linux/i2c.h>
14 #include <linux/spi/spi.h>
15 #include <linux/irqreturn.h>
16 #include <linux/iio/trigger.h>
17 #include <linux/bitops.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/regmap.h>
20
21 #include <linux/platform_data/st_sensors_pdata.h>
22
23
24
25
26
27 #define ST_SENSORS_MAX_BUFFER_SIZE (ALIGN(2 * 3, sizeof(s64)) + \
28 sizeof(s64))
29
30 #define ST_SENSORS_ODR_LIST_MAX 10
31 #define ST_SENSORS_FULLSCALE_AVL_MAX 10
32
33 #define ST_SENSORS_NUMBER_ALL_CHANNELS 4
34 #define ST_SENSORS_ENABLE_ALL_AXIS 0x07
35 #define ST_SENSORS_SCAN_X 0
36 #define ST_SENSORS_SCAN_Y 1
37 #define ST_SENSORS_SCAN_Z 2
38 #define ST_SENSORS_DEFAULT_POWER_ON_VALUE 0x01
39 #define ST_SENSORS_DEFAULT_POWER_OFF_VALUE 0x00
40 #define ST_SENSORS_DEFAULT_WAI_ADDRESS 0x0f
41 #define ST_SENSORS_DEFAULT_AXIS_ADDR 0x20
42 #define ST_SENSORS_DEFAULT_AXIS_MASK 0x07
43 #define ST_SENSORS_DEFAULT_AXIS_N_BIT 3
44 #define ST_SENSORS_DEFAULT_STAT_ADDR 0x27
45
46 #define ST_SENSORS_MAX_NAME 17
47 #define ST_SENSORS_MAX_4WAI 8
48
49 #define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \
50 ch2, s, endian, rbits, sbits, addr) \
51 { \
52 .type = device_type, \
53 .modified = mod, \
54 .info_mask_separate = mask, \
55 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
56 .scan_index = index, \
57 .channel2 = ch2, \
58 .address = addr, \
59 .scan_type = { \
60 .sign = s, \
61 .realbits = rbits, \
62 .shift = sbits - rbits, \
63 .storagebits = sbits, \
64 .endianness = endian, \
65 }, \
66 }
67
68 #define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \
69 IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \
70 st_sensors_sysfs_sampling_frequency_avail)
71
72 #define ST_SENSORS_DEV_ATTR_SCALE_AVAIL(name) \
73 IIO_DEVICE_ATTR(name, S_IRUGO, \
74 st_sensors_sysfs_scale_avail, NULL , 0);
75
76 struct st_sensor_odr_avl {
77 unsigned int hz;
78 u8 value;
79 };
80
81 struct st_sensor_odr {
82 u8 addr;
83 u8 mask;
84 struct st_sensor_odr_avl odr_avl[ST_SENSORS_ODR_LIST_MAX];
85 };
86
87 struct st_sensor_power {
88 u8 addr;
89 u8 mask;
90 u8 value_off;
91 u8 value_on;
92 };
93
94 struct st_sensor_axis {
95 u8 addr;
96 u8 mask;
97 };
98
99 struct st_sensor_fullscale_avl {
100 unsigned int num;
101 u8 value;
102 unsigned int gain;
103 unsigned int gain2;
104 };
105
106 struct st_sensor_fullscale {
107 u8 addr;
108 u8 mask;
109 struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
110 };
111
112 struct st_sensor_sim {
113 u8 addr;
114 u8 value;
115 };
116
117
118
119
120
121
122 struct st_sensor_bdu {
123 u8 addr;
124 u8 mask;
125 };
126
127
128
129
130
131
132 struct st_sensor_das {
133 u8 addr;
134 u8 mask;
135 };
136
137
138
139
140
141
142
143
144 struct st_sensor_int_drdy {
145 u8 addr;
146 u8 mask;
147 u8 addr_od;
148 u8 mask_od;
149 };
150
151
152
153
154
155
156
157
158
159
160
161
162 struct st_sensor_data_ready_irq {
163 struct st_sensor_int_drdy int1;
164 struct st_sensor_int_drdy int2;
165 u8 addr_ihl;
166 u8 mask_ihl;
167 struct {
168 u8 addr;
169 u8 mask;
170 } stat_drdy;
171 struct {
172 u8 en_addr;
173 u8 en_mask;
174 } ig1;
175 };
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 struct st_sensor_settings {
195 u8 wai;
196 u8 wai_addr;
197 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
198 struct iio_chan_spec *ch;
199 int num_ch;
200 struct st_sensor_odr odr;
201 struct st_sensor_power pw;
202 struct st_sensor_axis enable_axis;
203 struct st_sensor_fullscale fs;
204 struct st_sensor_bdu bdu;
205 struct st_sensor_das das;
206 struct st_sensor_data_ready_irq drdy_irq;
207 struct st_sensor_sim sim;
208 bool multi_read_bit;
209 unsigned int bootime;
210 };
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232 struct st_sensor_data {
233 struct device *dev;
234 struct iio_trigger *trig;
235 struct iio_mount_matrix *mount_matrix;
236 struct st_sensor_settings *sensor_settings;
237 struct st_sensor_fullscale_avl *current_fullscale;
238 struct regulator *vdd;
239 struct regulator *vdd_io;
240 struct regmap *regmap;
241
242 bool enabled;
243
244 unsigned int odr;
245 unsigned int num_data_channels;
246
247 u8 drdy_int_pin;
248 bool int_pin_open_drain;
249 int irq;
250
251 bool edge_irq;
252 bool hw_irq_trigger;
253 s64 hw_timestamp;
254
255 char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
256 };
257
258 #ifdef CONFIG_IIO_BUFFER
259 irqreturn_t st_sensors_trigger_handler(int irq, void *p);
260 #endif
261
262 #ifdef CONFIG_IIO_TRIGGER
263 int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
264 const struct iio_trigger_ops *trigger_ops);
265
266 void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
267 int st_sensors_validate_device(struct iio_trigger *trig,
268 struct iio_dev *indio_dev);
269 #else
270 static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
271 const struct iio_trigger_ops *trigger_ops)
272 {
273 return 0;
274 }
275 static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
276 {
277 return;
278 }
279 #define st_sensors_validate_device NULL
280 #endif
281
282 int st_sensors_init_sensor(struct iio_dev *indio_dev,
283 struct st_sensors_platform_data *pdata);
284
285 int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
286
287 int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
288
289 int st_sensors_power_enable(struct iio_dev *indio_dev);
290
291 void st_sensors_power_disable(struct iio_dev *indio_dev);
292
293 int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
294 unsigned reg, unsigned writeval,
295 unsigned *readval);
296
297 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
298
299 int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);
300
301 int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale);
302
303 int st_sensors_read_info_raw(struct iio_dev *indio_dev,
304 struct iio_chan_spec const *ch, int *val);
305
306 int st_sensors_get_settings_index(const char *name,
307 const struct st_sensor_settings *list,
308 const int list_length);
309
310 int st_sensors_verify_id(struct iio_dev *indio_dev);
311
312 ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
313 struct device_attribute *attr, char *buf);
314
315 ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
316 struct device_attribute *attr, char *buf);
317
318 #ifdef CONFIG_OF
319 void st_sensors_of_name_probe(struct device *dev,
320 const struct of_device_id *match,
321 char *name, int len);
322 #else
323 static inline void st_sensors_of_name_probe(struct device *dev,
324 const struct of_device_id *match,
325 char *name, int len)
326 {
327 }
328 #endif
329
330 #endif