module: Convert symbol namespace to string literal
[linux.git] / drivers / iio / accel / st_accel_core.c
blob99cb661fabb2d9cc1943fa8d0a6f3becb71126e6
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics accelerometers driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/mutex.h>
13 #include <linux/sysfs.h>
14 #include <linux/slab.h>
15 #include <linux/acpi.h>
16 #include <linux/iio/iio.h>
17 #include <linux/iio/sysfs.h>
18 #include <linux/iio/trigger.h>
20 #include <linux/iio/common/st_sensors.h>
21 #include "st_accel.h"
23 #define ST_ACCEL_NUMBER_DATA_CHANNELS 3
25 /* DEFAULT VALUE FOR SENSORS */
26 #define ST_ACCEL_DEFAULT_OUT_X_L_ADDR 0x28
27 #define ST_ACCEL_DEFAULT_OUT_Y_L_ADDR 0x2a
28 #define ST_ACCEL_DEFAULT_OUT_Z_L_ADDR 0x2c
30 /* FULLSCALE */
31 #define ST_ACCEL_FS_AVL_2G 2
32 #define ST_ACCEL_FS_AVL_4G 4
33 #define ST_ACCEL_FS_AVL_6G 6
34 #define ST_ACCEL_FS_AVL_8G 8
35 #define ST_ACCEL_FS_AVL_16G 16
36 #define ST_ACCEL_FS_AVL_100G 100
37 #define ST_ACCEL_FS_AVL_200G 200
38 #define ST_ACCEL_FS_AVL_400G 400
40 static const struct iio_mount_matrix *
41 st_accel_get_mount_matrix(const struct iio_dev *indio_dev,
42 const struct iio_chan_spec *chan)
44 struct st_sensor_data *adata = iio_priv(indio_dev);
46 return &adata->mount_matrix;
49 static const struct iio_chan_spec_ext_info st_accel_mount_matrix_ext_info[] = {
50 IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_accel_get_mount_matrix),
51 { }
54 static const struct iio_chan_spec st_accel_8bit_channels[] = {
55 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
56 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
57 ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 8, 8,
58 ST_ACCEL_DEFAULT_OUT_X_L_ADDR+1,
59 st_accel_mount_matrix_ext_info),
60 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
61 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
62 ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 8, 8,
63 ST_ACCEL_DEFAULT_OUT_Y_L_ADDR+1,
64 st_accel_mount_matrix_ext_info),
65 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
66 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
67 ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 8, 8,
68 ST_ACCEL_DEFAULT_OUT_Z_L_ADDR+1,
69 st_accel_mount_matrix_ext_info),
70 IIO_CHAN_SOFT_TIMESTAMP(3)
73 static const struct iio_chan_spec st_accel_12bit_channels[] = {
74 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
75 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
76 ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 12, 16,
77 ST_ACCEL_DEFAULT_OUT_X_L_ADDR,
78 st_accel_mount_matrix_ext_info),
79 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
80 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
81 ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 12, 16,
82 ST_ACCEL_DEFAULT_OUT_Y_L_ADDR,
83 st_accel_mount_matrix_ext_info),
84 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
85 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
86 ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 12, 16,
87 ST_ACCEL_DEFAULT_OUT_Z_L_ADDR,
88 st_accel_mount_matrix_ext_info),
89 IIO_CHAN_SOFT_TIMESTAMP(3)
92 static const struct iio_chan_spec st_accel_16bit_channels[] = {
93 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
94 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
95 ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
96 ST_ACCEL_DEFAULT_OUT_X_L_ADDR,
97 st_accel_mount_matrix_ext_info),
98 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
99 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
100 ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
101 ST_ACCEL_DEFAULT_OUT_Y_L_ADDR,
102 st_accel_mount_matrix_ext_info),
103 ST_SENSORS_LSM_CHANNELS_EXT(IIO_ACCEL,
104 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
105 ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
106 ST_ACCEL_DEFAULT_OUT_Z_L_ADDR,
107 st_accel_mount_matrix_ext_info),
108 IIO_CHAN_SOFT_TIMESTAMP(3)
111 static const struct st_sensor_settings st_accel_sensors_settings[] = {
113 .wai = 0x33,
114 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
115 .sensors_supported = {
116 [0] = LIS3DH_ACCEL_DEV_NAME,
117 [1] = LSM303DLHC_ACCEL_DEV_NAME,
118 [2] = LSM330D_ACCEL_DEV_NAME,
119 [3] = LSM330DL_ACCEL_DEV_NAME,
120 [4] = LSM330DLC_ACCEL_DEV_NAME,
121 [5] = LSM303AGR_ACCEL_DEV_NAME,
122 [6] = LIS2DH12_ACCEL_DEV_NAME,
123 [7] = LIS3DE_ACCEL_DEV_NAME,
125 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
126 .odr = {
127 .addr = 0x20,
128 .mask = 0xf0,
129 .odr_avl = {
130 { .hz = 1, .value = 0x01, },
131 { .hz = 10, .value = 0x02, },
132 { .hz = 25, .value = 0x03, },
133 { .hz = 50, .value = 0x04, },
134 { .hz = 100, .value = 0x05, },
135 { .hz = 200, .value = 0x06, },
136 { .hz = 400, .value = 0x07, },
137 { .hz = 1600, .value = 0x08, },
140 .pw = {
141 .addr = 0x20,
142 .mask = 0xf0,
143 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
145 .enable_axis = {
146 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
147 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
149 .fs = {
150 .addr = 0x23,
151 .mask = 0x30,
152 .fs_avl = {
153 [0] = {
154 .num = ST_ACCEL_FS_AVL_2G,
155 .value = 0x00,
156 .gain = IIO_G_TO_M_S_2(1000),
158 [1] = {
159 .num = ST_ACCEL_FS_AVL_4G,
160 .value = 0x01,
161 .gain = IIO_G_TO_M_S_2(2000),
163 [2] = {
164 .num = ST_ACCEL_FS_AVL_8G,
165 .value = 0x02,
166 .gain = IIO_G_TO_M_S_2(4000),
168 [3] = {
169 .num = ST_ACCEL_FS_AVL_16G,
170 .value = 0x03,
171 .gain = IIO_G_TO_M_S_2(12000),
175 .bdu = {
176 .addr = 0x23,
177 .mask = 0x80,
179 .drdy_irq = {
180 .int1 = {
181 .addr = 0x22,
182 .mask = 0x10,
184 .addr_ihl = 0x25,
185 .mask_ihl = 0x02,
186 .stat_drdy = {
187 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
188 .mask = 0x07,
191 .sim = {
192 .addr = 0x23,
193 .value = BIT(0),
195 .multi_read_bit = true,
196 .bootime = 2,
199 .wai = 0x32,
200 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
201 .sensors_supported = {
202 [0] = LIS331DLH_ACCEL_DEV_NAME,
203 [1] = LSM303DL_ACCEL_DEV_NAME,
204 [2] = LSM303DLH_ACCEL_DEV_NAME,
205 [3] = LSM303DLM_ACCEL_DEV_NAME,
207 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
208 .odr = {
209 .addr = 0x20,
210 .mask = 0x18,
211 .odr_avl = {
212 { .hz = 50, .value = 0x00, },
213 { .hz = 100, .value = 0x01, },
214 { .hz = 400, .value = 0x02, },
215 { .hz = 1000, .value = 0x03, },
218 .pw = {
219 .addr = 0x20,
220 .mask = 0xe0,
221 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
222 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
224 .enable_axis = {
225 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
226 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
228 .fs = {
229 .addr = 0x23,
230 .mask = 0x30,
231 .fs_avl = {
232 [0] = {
233 .num = ST_ACCEL_FS_AVL_2G,
234 .value = 0x00,
235 .gain = IIO_G_TO_M_S_2(1000),
237 [1] = {
238 .num = ST_ACCEL_FS_AVL_4G,
239 .value = 0x01,
240 .gain = IIO_G_TO_M_S_2(2000),
242 [2] = {
243 .num = ST_ACCEL_FS_AVL_8G,
244 .value = 0x03,
245 .gain = IIO_G_TO_M_S_2(3900),
249 .bdu = {
250 .addr = 0x23,
251 .mask = 0x80,
253 .drdy_irq = {
254 .int1 = {
255 .addr = 0x22,
256 .mask = 0x02,
257 .addr_od = 0x22,
258 .mask_od = 0x40,
260 .int2 = {
261 .addr = 0x22,
262 .mask = 0x10,
263 .addr_od = 0x22,
264 .mask_od = 0x40,
266 .addr_ihl = 0x22,
267 .mask_ihl = 0x80,
268 .stat_drdy = {
269 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
270 .mask = 0x07,
273 .sim = {
274 .addr = 0x23,
275 .value = BIT(0),
277 .multi_read_bit = true,
278 .bootime = 2,
281 .wai = 0x40,
282 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
283 .sensors_supported = {
284 [0] = LSM330_ACCEL_DEV_NAME,
286 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
287 .odr = {
288 .addr = 0x20,
289 .mask = 0xf0,
290 .odr_avl = {
291 { .hz = 3, .value = 0x01, },
292 { .hz = 6, .value = 0x02, },
293 { .hz = 12, .value = 0x03, },
294 { .hz = 25, .value = 0x04, },
295 { .hz = 50, .value = 0x05, },
296 { .hz = 100, .value = 0x06, },
297 { .hz = 200, .value = 0x07, },
298 { .hz = 400, .value = 0x08, },
299 { .hz = 800, .value = 0x09, },
300 { .hz = 1600, .value = 0x0a, },
303 .pw = {
304 .addr = 0x20,
305 .mask = 0xf0,
306 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
308 .enable_axis = {
309 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
310 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
312 .fs = {
313 .addr = 0x24,
314 .mask = 0x38,
315 .fs_avl = {
316 [0] = {
317 .num = ST_ACCEL_FS_AVL_2G,
318 .value = 0x00,
319 .gain = IIO_G_TO_M_S_2(61),
321 [1] = {
322 .num = ST_ACCEL_FS_AVL_4G,
323 .value = 0x01,
324 .gain = IIO_G_TO_M_S_2(122),
326 [2] = {
327 .num = ST_ACCEL_FS_AVL_6G,
328 .value = 0x02,
329 .gain = IIO_G_TO_M_S_2(183),
331 [3] = {
332 .num = ST_ACCEL_FS_AVL_8G,
333 .value = 0x03,
334 .gain = IIO_G_TO_M_S_2(244),
336 [4] = {
337 .num = ST_ACCEL_FS_AVL_16G,
338 .value = 0x04,
339 .gain = IIO_G_TO_M_S_2(732),
343 .bdu = {
344 .addr = 0x20,
345 .mask = 0x08,
347 .drdy_irq = {
348 .int1 = {
349 .addr = 0x23,
350 .mask = 0x80,
352 .addr_ihl = 0x23,
353 .mask_ihl = 0x40,
354 .stat_drdy = {
355 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
356 .mask = 0x07,
358 .ig1 = {
359 .en_addr = 0x23,
360 .en_mask = 0x08,
363 .sim = {
364 .addr = 0x24,
365 .value = BIT(0),
367 .multi_read_bit = false,
368 .bootime = 2,
371 .wai = 0x3a,
372 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
373 .sensors_supported = {
374 [0] = LIS3LV02DL_ACCEL_DEV_NAME,
376 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
377 .odr = {
378 .addr = 0x20,
379 .mask = 0x30, /* DF1 and DF0 */
380 .odr_avl = {
381 { .hz = 40, .value = 0x00, },
382 { .hz = 160, .value = 0x01, },
383 { .hz = 640, .value = 0x02, },
384 { .hz = 2560, .value = 0x03, },
387 .pw = {
388 .addr = 0x20,
389 .mask = 0xc0,
390 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
391 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
393 .enable_axis = {
394 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
395 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
397 .fs = {
398 .addr = 0x21,
399 .mask = 0x80,
400 .fs_avl = {
401 [0] = {
402 .num = ST_ACCEL_FS_AVL_2G,
403 .value = 0x00,
404 .gain = IIO_G_TO_M_S_2(1000),
406 [1] = {
407 .num = ST_ACCEL_FS_AVL_6G,
408 .value = 0x01,
409 .gain = IIO_G_TO_M_S_2(3000),
413 .bdu = {
414 .addr = 0x21,
415 .mask = 0x40,
418 * Data Alignment Setting - needs to be set to get
419 * left-justified data like all other sensors.
421 .das = {
422 .addr = 0x21,
423 .mask = 0x01,
425 .drdy_irq = {
426 .int1 = {
427 .addr = 0x21,
428 .mask = 0x04,
430 .stat_drdy = {
431 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
432 .mask = 0x07,
435 .sim = {
436 .addr = 0x21,
437 .value = BIT(1),
439 .multi_read_bit = true,
440 .bootime = 2, /* guess */
443 .wai = 0x3b,
444 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
445 .sensors_supported = {
446 [0] = LIS331DL_ACCEL_DEV_NAME,
447 [1] = LIS302DL_ACCEL_DEV_NAME,
449 .ch = (struct iio_chan_spec *)st_accel_8bit_channels,
450 .odr = {
451 .addr = 0x20,
452 .mask = 0x80,
453 .odr_avl = {
454 { .hz = 100, .value = 0x00, },
455 { .hz = 400, .value = 0x01, },
458 .pw = {
459 .addr = 0x20,
460 .mask = 0x40,
461 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
462 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
464 .enable_axis = {
465 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
466 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
468 .fs = {
469 .addr = 0x20,
470 .mask = 0x20,
472 * TODO: check these resulting gain settings, these are
473 * not in the datsheet
475 .fs_avl = {
476 [0] = {
477 .num = ST_ACCEL_FS_AVL_2G,
478 .value = 0x00,
479 .gain = IIO_G_TO_M_S_2(18000),
481 [1] = {
482 .num = ST_ACCEL_FS_AVL_8G,
483 .value = 0x01,
484 .gain = IIO_G_TO_M_S_2(72000),
488 .drdy_irq = {
489 .int1 = {
490 .addr = 0x22,
491 .mask = 0x04,
492 .addr_od = 0x22,
493 .mask_od = 0x40,
495 .int2 = {
496 .addr = 0x22,
497 .mask = 0x20,
498 .addr_od = 0x22,
499 .mask_od = 0x40,
501 .addr_ihl = 0x22,
502 .mask_ihl = 0x80,
503 .stat_drdy = {
504 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
505 .mask = 0x07,
508 .sim = {
509 .addr = 0x21,
510 .value = BIT(7),
512 .multi_read_bit = false,
513 .bootime = 2, /* guess */
516 .wai = 0x32,
517 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
518 .sensors_supported = {
519 [0] = H3LIS331DL_ACCEL_DEV_NAME,
520 [1] = IIS328DQ_ACCEL_DEV_NAME,
522 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
523 .odr = {
524 .addr = 0x20,
525 .mask = 0x18,
526 .odr_avl = {
527 { .hz = 50, .value = 0x00, },
528 { .hz = 100, .value = 0x01, },
529 { .hz = 400, .value = 0x02, },
530 { .hz = 1000, .value = 0x03, },
533 .pw = {
534 .addr = 0x20,
535 .mask = 0x20,
536 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
537 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
539 .enable_axis = {
540 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
541 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
543 .fs = {
544 .addr = 0x23,
545 .mask = 0x30,
546 .fs_avl = {
547 [0] = {
548 .num = ST_ACCEL_FS_AVL_100G,
549 .value = 0x00,
550 .gain = IIO_G_TO_M_S_2(49000),
552 [1] = {
553 .num = ST_ACCEL_FS_AVL_200G,
554 .value = 0x01,
555 .gain = IIO_G_TO_M_S_2(98000),
557 [2] = {
558 .num = ST_ACCEL_FS_AVL_400G,
559 .value = 0x03,
560 .gain = IIO_G_TO_M_S_2(195000),
564 .bdu = {
565 .addr = 0x23,
566 .mask = 0x80,
568 .drdy_irq = {
569 .int1 = {
570 .addr = 0x22,
571 .mask = 0x02,
573 .int2 = {
574 .addr = 0x22,
575 .mask = 0x10,
577 .addr_ihl = 0x22,
578 .mask_ihl = 0x80,
580 .sim = {
581 .addr = 0x23,
582 .value = BIT(0),
584 .multi_read_bit = true,
585 .bootime = 2,
588 /* No WAI register present */
589 .sensors_supported = {
590 [0] = LIS3L02DQ_ACCEL_DEV_NAME,
592 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
593 .odr = {
594 .addr = 0x20,
595 .mask = 0x30,
596 .odr_avl = {
597 { .hz = 280, .value = 0x00, },
598 { .hz = 560, .value = 0x01, },
599 { .hz = 1120, .value = 0x02, },
600 { .hz = 4480, .value = 0x03, },
603 .pw = {
604 .addr = 0x20,
605 .mask = 0xc0,
606 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
607 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
609 .enable_axis = {
610 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
611 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
613 .fs = {
614 .fs_avl = {
615 [0] = {
616 .num = ST_ACCEL_FS_AVL_2G,
617 .gain = IIO_G_TO_M_S_2(488),
622 * The part has a BDU bit but if set the data is never
623 * updated so don't set it.
625 .bdu = {
627 .drdy_irq = {
628 .int1 = {
629 .addr = 0x21,
630 .mask = 0x04,
632 .stat_drdy = {
633 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
634 .mask = 0x07,
637 .sim = {
638 .addr = 0x21,
639 .value = BIT(1),
641 .multi_read_bit = false,
642 .bootime = 2,
645 .wai = 0x33,
646 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
647 .sensors_supported = {
648 [0] = LNG2DM_ACCEL_DEV_NAME,
650 .ch = (struct iio_chan_spec *)st_accel_8bit_channels,
651 .odr = {
652 .addr = 0x20,
653 .mask = 0xf0,
654 .odr_avl = {
655 { .hz = 1, .value = 0x01, },
656 { .hz = 10, .value = 0x02, },
657 { .hz = 25, .value = 0x03, },
658 { .hz = 50, .value = 0x04, },
659 { .hz = 100, .value = 0x05, },
660 { .hz = 200, .value = 0x06, },
661 { .hz = 400, .value = 0x07, },
662 { .hz = 1600, .value = 0x08, },
665 .pw = {
666 .addr = 0x20,
667 .mask = 0xf0,
668 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
670 .enable_axis = {
671 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
672 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
674 .fs = {
675 .addr = 0x23,
676 .mask = 0x30,
677 .fs_avl = {
678 [0] = {
679 .num = ST_ACCEL_FS_AVL_2G,
680 .value = 0x00,
681 .gain = IIO_G_TO_M_S_2(15600),
683 [1] = {
684 .num = ST_ACCEL_FS_AVL_4G,
685 .value = 0x01,
686 .gain = IIO_G_TO_M_S_2(31200),
688 [2] = {
689 .num = ST_ACCEL_FS_AVL_8G,
690 .value = 0x02,
691 .gain = IIO_G_TO_M_S_2(62500),
693 [3] = {
694 .num = ST_ACCEL_FS_AVL_16G,
695 .value = 0x03,
696 .gain = IIO_G_TO_M_S_2(187500),
700 .drdy_irq = {
701 .int1 = {
702 .addr = 0x22,
703 .mask = 0x10,
705 .addr_ihl = 0x25,
706 .mask_ihl = 0x02,
707 .stat_drdy = {
708 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
709 .mask = 0x07,
712 .sim = {
713 .addr = 0x23,
714 .value = BIT(0),
716 .multi_read_bit = true,
717 .bootime = 2,
720 .wai = 0x44,
721 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
722 .sensors_supported = {
723 [0] = LIS2DW12_ACCEL_DEV_NAME,
725 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
726 .odr = {
727 .addr = 0x20,
728 .mask = 0xf0,
729 .odr_avl = {
730 { .hz = 1, .value = 0x01, },
731 { .hz = 12, .value = 0x02, },
732 { .hz = 25, .value = 0x03, },
733 { .hz = 50, .value = 0x04, },
734 { .hz = 100, .value = 0x05, },
735 { .hz = 200, .value = 0x06, },
738 .pw = {
739 .addr = 0x20,
740 .mask = 0xf0,
741 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
743 .fs = {
744 .addr = 0x25,
745 .mask = 0x30,
746 .fs_avl = {
747 [0] = {
748 .num = ST_ACCEL_FS_AVL_2G,
749 .value = 0x00,
750 .gain = IIO_G_TO_M_S_2(976),
752 [1] = {
753 .num = ST_ACCEL_FS_AVL_4G,
754 .value = 0x01,
755 .gain = IIO_G_TO_M_S_2(1952),
757 [2] = {
758 .num = ST_ACCEL_FS_AVL_8G,
759 .value = 0x02,
760 .gain = IIO_G_TO_M_S_2(3904),
762 [3] = {
763 .num = ST_ACCEL_FS_AVL_16G,
764 .value = 0x03,
765 .gain = IIO_G_TO_M_S_2(7808),
769 .bdu = {
770 .addr = 0x21,
771 .mask = 0x08,
773 .drdy_irq = {
774 .int1 = {
775 .addr = 0x23,
776 .mask = 0x01,
777 .addr_od = 0x22,
778 .mask_od = 0x20,
780 .int2 = {
781 .addr = 0x24,
782 .mask = 0x01,
783 .addr_od = 0x22,
784 .mask_od = 0x20,
786 .addr_ihl = 0x22,
787 .mask_ihl = 0x08,
788 .stat_drdy = {
789 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
790 .mask = 0x01,
793 .sim = {
794 .addr = 0x21,
795 .value = BIT(0),
797 .multi_read_bit = false,
798 .bootime = 2,
801 .wai = 0x11,
802 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
803 .sensors_supported = {
804 [0] = LIS3DHH_ACCEL_DEV_NAME,
806 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
807 .odr = {
808 /* just ODR = 1100Hz available */
809 .odr_avl = {
810 { .hz = 1100, .value = 0x00, },
813 .pw = {
814 .addr = 0x20,
815 .mask = 0x80,
816 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
817 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
819 .fs = {
820 .fs_avl = {
821 [0] = {
822 .num = ST_ACCEL_FS_AVL_2G,
823 .gain = IIO_G_TO_M_S_2(76),
827 .bdu = {
828 .addr = 0x20,
829 .mask = 0x01,
831 .drdy_irq = {
832 .int1 = {
833 .addr = 0x21,
834 .mask = 0x80,
835 .addr_od = 0x23,
836 .mask_od = 0x04,
838 .int2 = {
839 .addr = 0x22,
840 .mask = 0x80,
841 .addr_od = 0x23,
842 .mask_od = 0x08,
844 .stat_drdy = {
845 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
846 .mask = 0x07,
849 .multi_read_bit = false,
850 .bootime = 2,
853 .wai = 0x33,
854 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
855 .sensors_supported = {
856 [0] = LIS2DE12_ACCEL_DEV_NAME,
858 .ch = (struct iio_chan_spec *)st_accel_8bit_channels,
859 .odr = {
860 .addr = 0x20,
861 .mask = 0xf0,
862 .odr_avl = {
863 { .hz = 1, .value = 0x01, },
864 { .hz = 10, .value = 0x02, },
865 { .hz = 25, .value = 0x03, },
866 { .hz = 50, .value = 0x04, },
867 { .hz = 100, .value = 0x05, },
868 { .hz = 200, .value = 0x06, },
869 { .hz = 400, .value = 0x07, },
870 { .hz = 1620, .value = 0x08, },
871 { .hz = 5376, .value = 0x09, },
874 .pw = {
875 .addr = 0x20,
876 .mask = 0xf0,
877 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
879 .enable_axis = {
880 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
881 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
883 .fs = {
884 .addr = 0x23,
885 .mask = 0x30,
886 .fs_avl = {
887 [0] = {
888 .num = ST_ACCEL_FS_AVL_2G,
889 .value = 0x00,
890 .gain = IIO_G_TO_M_S_2(15600),
892 [1] = {
893 .num = ST_ACCEL_FS_AVL_4G,
894 .value = 0x01,
895 .gain = IIO_G_TO_M_S_2(31200),
897 [2] = {
898 .num = ST_ACCEL_FS_AVL_8G,
899 .value = 0x02,
900 .gain = IIO_G_TO_M_S_2(62500),
902 [3] = {
903 .num = ST_ACCEL_FS_AVL_16G,
904 .value = 0x03,
905 .gain = IIO_G_TO_M_S_2(187500),
909 .drdy_irq = {
910 .int1 = {
911 .addr = 0x22,
912 .mask = 0x10,
914 .addr_ihl = 0x25,
915 .mask_ihl = 0x02,
916 .stat_drdy = {
917 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
918 .mask = 0x07,
921 .sim = {
922 .addr = 0x23,
923 .value = BIT(0),
925 .multi_read_bit = true,
926 .bootime = 2,
929 .wai = 0x43,
930 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
931 .sensors_supported = {
932 [0] = LIS2DS12_ACCEL_DEV_NAME,
934 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
935 .odr = {
936 .addr = 0x20,
937 .mask = 0xf0,
938 .odr_avl = {
939 { .hz = 10, .value = 0x01, },
940 { .hz = 50, .value = 0x02, },
941 { .hz = 100, .value = 0x03, },
942 { .hz = 200, .value = 0x04, },
943 { .hz = 400, .value = 0x05, },
944 { .hz = 800, .value = 0x06, },
947 .pw = {
948 .addr = 0x20,
949 .mask = 0xf0,
950 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
952 .enable_axis = {
953 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
954 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
956 .fs = {
957 .addr = 0x20,
958 .mask = 0x0c,
959 .fs_avl = {
960 [0] = {
961 .num = ST_ACCEL_FS_AVL_2G,
962 .value = 0x00,
963 .gain = IIO_G_TO_M_S_2(61),
965 [1] = {
966 .num = ST_ACCEL_FS_AVL_4G,
967 .value = 0x02,
968 .gain = IIO_G_TO_M_S_2(122),
970 [2] = {
971 .num = ST_ACCEL_FS_AVL_8G,
972 .value = 0x03,
973 .gain = IIO_G_TO_M_S_2(244),
975 [3] = {
976 .num = ST_ACCEL_FS_AVL_16G,
977 .value = 0x01,
978 .gain = IIO_G_TO_M_S_2(488),
982 .bdu = {
983 .addr = 0x20,
984 .mask = 0x01,
986 .drdy_irq = {
987 .int1 = {
988 .addr = 0x23,
989 .mask = 0x01,
991 .int2 = {
992 .addr = 0x24,
993 .mask = 0x01,
995 .addr_ihl = 0x22,
996 .mask_ihl = 0x02,
997 .stat_drdy = {
998 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
999 .mask = 0x01,
1002 .sim = {
1003 .addr = 0x21,
1004 .value = BIT(0),
1006 .multi_read_bit = true,
1007 .bootime = 2,
1010 .wai = 0x41,
1011 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
1012 .sensors_supported = {
1013 [0] = LIS2HH12_ACCEL_DEV_NAME,
1014 [1] = LSM303C_ACCEL_DEV_NAME,
1016 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
1017 .odr = {
1018 .addr = 0x20,
1019 .mask = 0x70,
1020 .odr_avl = {
1021 { .hz = 10, .value = 0x01, },
1022 { .hz = 50, .value = 0x02, },
1023 { .hz = 100, .value = 0x03, },
1024 { .hz = 200, .value = 0x04, },
1025 { .hz = 400, .value = 0x05, },
1026 { .hz = 800, .value = 0x06, },
1029 .pw = {
1030 .addr = 0x20,
1031 .mask = 0x70,
1032 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
1034 .enable_axis = {
1035 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
1036 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
1038 .fs = {
1039 .addr = 0x23,
1040 .mask = 0x30,
1041 .fs_avl = {
1042 [0] = {
1043 .num = ST_ACCEL_FS_AVL_2G,
1044 .value = 0x00,
1045 .gain = IIO_G_TO_M_S_2(61),
1047 [1] = {
1048 .num = ST_ACCEL_FS_AVL_4G,
1049 .value = 0x02,
1050 .gain = IIO_G_TO_M_S_2(122),
1052 [2] = {
1053 .num = ST_ACCEL_FS_AVL_8G,
1054 .value = 0x03,
1055 .gain = IIO_G_TO_M_S_2(244),
1059 .bdu = {
1060 .addr = 0x20,
1061 .mask = 0x08,
1063 .drdy_irq = {
1064 .int1 = {
1065 .addr = 0x22,
1066 .mask = 0x01,
1068 .int2 = {
1069 .addr = 0x25,
1070 .mask = 0x01,
1072 .addr_ihl = 0x24,
1073 .mask_ihl = 0x02,
1074 .stat_drdy = {
1075 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
1076 .mask = 0x07,
1079 .sim = {
1080 .addr = 0x23,
1081 .value = BIT(0),
1083 .multi_read_bit = true,
1084 .bootime = 2,
1087 .wai = 0x49,
1088 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
1089 .sensors_supported = {
1090 [0] = LSM9DS0_IMU_DEV_NAME,
1091 [1] = LSM303D_IMU_DEV_NAME,
1093 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
1094 .odr = {
1095 .addr = 0x20,
1096 .mask = GENMASK(7, 4),
1097 .odr_avl = {
1098 { 3, 0x01, },
1099 { 6, 0x02, },
1100 { 12, 0x03, },
1101 { 25, 0x04, },
1102 { 50, 0x05, },
1103 { 100, 0x06, },
1104 { 200, 0x07, },
1105 { 400, 0x08, },
1106 { 800, 0x09, },
1107 { 1600, 0x0a, },
1110 .pw = {
1111 .addr = 0x20,
1112 .mask = GENMASK(7, 4),
1113 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
1115 .enable_axis = {
1116 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
1117 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
1119 .fs = {
1120 .addr = 0x21,
1121 .mask = GENMASK(5, 3),
1122 .fs_avl = {
1123 [0] = {
1124 .num = ST_ACCEL_FS_AVL_2G,
1125 .value = 0x00,
1126 .gain = IIO_G_TO_M_S_2(61),
1128 [1] = {
1129 .num = ST_ACCEL_FS_AVL_4G,
1130 .value = 0x01,
1131 .gain = IIO_G_TO_M_S_2(122),
1133 [2] = {
1134 .num = ST_ACCEL_FS_AVL_6G,
1135 .value = 0x02,
1136 .gain = IIO_G_TO_M_S_2(183),
1138 [3] = {
1139 .num = ST_ACCEL_FS_AVL_8G,
1140 .value = 0x03,
1141 .gain = IIO_G_TO_M_S_2(244),
1143 [4] = {
1144 .num = ST_ACCEL_FS_AVL_16G,
1145 .value = 0x04,
1146 .gain = IIO_G_TO_M_S_2(732),
1150 .bdu = {
1151 .addr = 0x20,
1152 .mask = BIT(3),
1154 .drdy_irq = {
1155 .int1 = {
1156 .addr = 0x22,
1157 .mask = BIT(2),
1159 .int2 = {
1160 .addr = 0x23,
1161 .mask = BIT(3),
1163 .stat_drdy = {
1164 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
1165 .mask = GENMASK(2, 0),
1168 .sim = {
1169 .addr = 0x21,
1170 .value = BIT(0),
1172 .multi_read_bit = true,
1173 .bootime = 2,
1177 * Not an ST part. Register-compatible with the LIS2DH, even
1178 * though the WAI value is different.
1180 .wai = 0x11,
1181 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
1182 .sensors_supported = {
1183 [0] = SC7A20_ACCEL_DEV_NAME,
1185 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
1186 .odr = {
1187 .addr = 0x20,
1188 .mask = 0xf0,
1189 .odr_avl = {
1190 { .hz = 1, .value = 0x01, },
1191 { .hz = 10, .value = 0x02, },
1192 { .hz = 25, .value = 0x03, },
1193 { .hz = 50, .value = 0x04, },
1194 { .hz = 100, .value = 0x05, },
1195 { .hz = 200, .value = 0x06, },
1196 { .hz = 400, .value = 0x07, },
1197 { .hz = 1600, .value = 0x08, },
1200 .pw = {
1201 .addr = 0x20,
1202 .mask = 0xf0,
1203 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
1205 .enable_axis = {
1206 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
1207 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
1209 .fs = {
1210 .addr = 0x23,
1211 .mask = 0x30,
1212 .fs_avl = {
1213 [0] = {
1214 .num = ST_ACCEL_FS_AVL_2G,
1215 .value = 0x00,
1216 .gain = IIO_G_TO_M_S_2(1000),
1218 [1] = {
1219 .num = ST_ACCEL_FS_AVL_4G,
1220 .value = 0x01,
1221 .gain = IIO_G_TO_M_S_2(2000),
1223 [2] = {
1224 .num = ST_ACCEL_FS_AVL_8G,
1225 .value = 0x02,
1226 .gain = IIO_G_TO_M_S_2(4000),
1228 [3] = {
1229 .num = ST_ACCEL_FS_AVL_16G,
1230 .value = 0x03,
1231 .gain = IIO_G_TO_M_S_2(12000),
1235 .bdu = {
1236 .addr = 0x23,
1237 .mask = 0x80,
1239 .drdy_irq = {
1240 .int1 = {
1241 .addr = 0x22,
1242 .mask = 0x10,
1244 .addr_ihl = 0x25,
1245 .mask_ihl = 0x02,
1246 .stat_drdy = {
1247 .addr = ST_SENSORS_DEFAULT_STAT_ADDR,
1248 .mask = 0x07,
1251 .sim = {
1252 .addr = 0x23,
1253 .value = BIT(0),
1255 .multi_read_bit = true,
1256 .bootime = 2,
1260 /* Default accel DRDY is available on INT1 pin */
1261 static const struct st_sensors_platform_data default_accel_pdata = {
1262 .drdy_int_pin = 1,
1265 static int st_accel_read_raw(struct iio_dev *indio_dev,
1266 struct iio_chan_spec const *ch, int *val,
1267 int *val2, long mask)
1269 int err;
1270 struct st_sensor_data *adata = iio_priv(indio_dev);
1272 switch (mask) {
1273 case IIO_CHAN_INFO_RAW:
1274 err = st_sensors_read_info_raw(indio_dev, ch, val);
1275 if (err < 0)
1276 goto read_error;
1278 return IIO_VAL_INT;
1279 case IIO_CHAN_INFO_SCALE:
1280 *val = adata->current_fullscale->gain / 1000000;
1281 *val2 = adata->current_fullscale->gain % 1000000;
1282 return IIO_VAL_INT_PLUS_MICRO;
1283 case IIO_CHAN_INFO_SAMP_FREQ:
1284 *val = adata->odr;
1285 return IIO_VAL_INT;
1286 default:
1287 return -EINVAL;
1290 read_error:
1291 return err;
1294 static int st_accel_write_raw(struct iio_dev *indio_dev,
1295 struct iio_chan_spec const *chan, int val, int val2, long mask)
1297 switch (mask) {
1298 case IIO_CHAN_INFO_SCALE: {
1299 int gain;
1301 gain = val * 1000000 + val2;
1302 return st_sensors_set_fullscale_by_gain(indio_dev, gain);
1304 case IIO_CHAN_INFO_SAMP_FREQ:
1305 if (val2)
1306 return -EINVAL;
1308 return st_sensors_set_odr(indio_dev, val);
1309 default:
1310 return -EINVAL;
1314 static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
1315 static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_accel_scale_available);
1317 static struct attribute *st_accel_attributes[] = {
1318 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
1319 &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
1320 NULL,
1323 static const struct attribute_group st_accel_attribute_group = {
1324 .attrs = st_accel_attributes,
1327 static const struct iio_info accel_info = {
1328 .attrs = &st_accel_attribute_group,
1329 .read_raw = &st_accel_read_raw,
1330 .write_raw = &st_accel_write_raw,
1331 .debugfs_reg_access = &st_sensors_debugfs_reg_access,
1334 #ifdef CONFIG_IIO_TRIGGER
1335 static const struct iio_trigger_ops st_accel_trigger_ops = {
1336 .set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE,
1337 .validate_device = st_sensors_validate_device,
1339 #define ST_ACCEL_TRIGGER_OPS (&st_accel_trigger_ops)
1340 #else
1341 #define ST_ACCEL_TRIGGER_OPS NULL
1342 #endif
1344 #ifdef CONFIG_ACPI
1345 /* Read ST-specific _ONT orientation data from ACPI and generate an
1346 * appropriate mount matrix.
1348 static int apply_acpi_orientation(struct iio_dev *indio_dev)
1350 struct st_sensor_data *adata = iio_priv(indio_dev);
1351 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1352 struct acpi_device *adev;
1353 union acpi_object *ont;
1354 union acpi_object *elements;
1355 acpi_status status;
1356 int ret = -EINVAL;
1357 unsigned int val;
1358 int i, j;
1359 int final_ont[3][3] = { { 0 }, };
1361 /* For some reason, ST's _ONT translation does not apply directly
1362 * to the data read from the sensor. Another translation must be
1363 * performed first, as described by the matrix below. Perhaps
1364 * ST required this specific translation for the first product
1365 * where the device was mounted?
1367 const int default_ont[3][3] = {
1368 { 0, 1, 0 },
1369 { -1, 0, 0 },
1370 { 0, 0, -1 },
1374 adev = ACPI_COMPANION(indio_dev->dev.parent);
1375 if (!adev)
1376 return -ENXIO;
1378 /* Read _ONT data, which should be a package of 6 integers. */
1379 status = acpi_evaluate_object(adev->handle, "_ONT", NULL, &buffer);
1380 if (status == AE_NOT_FOUND) {
1381 return -ENXIO;
1382 } else if (ACPI_FAILURE(status)) {
1383 dev_warn(&indio_dev->dev, "failed to execute _ONT: %d\n",
1384 status);
1385 return status;
1388 ont = buffer.pointer;
1389 if (ont->type != ACPI_TYPE_PACKAGE || ont->package.count != 6)
1390 goto out;
1392 /* The first 3 integers provide axis order information.
1393 * e.g. 0 1 2 would indicate normal X,Y,Z ordering.
1394 * e.g. 1 0 2 indicates that data arrives in order Y,X,Z.
1396 elements = ont->package.elements;
1397 for (i = 0; i < 3; i++) {
1398 if (elements[i].type != ACPI_TYPE_INTEGER)
1399 goto out;
1401 val = elements[i].integer.value;
1402 if (val > 2)
1403 goto out;
1405 /* Avoiding full matrix multiplication, we simply reorder the
1406 * columns in the default_ont matrix according to the
1407 * ordering provided by _ONT.
1409 final_ont[0][i] = default_ont[0][val];
1410 final_ont[1][i] = default_ont[1][val];
1411 final_ont[2][i] = default_ont[2][val];
1414 /* The final 3 integers provide sign flip information.
1415 * 0 means no change, 1 means flip.
1416 * e.g. 0 0 1 means that Z data should be sign-flipped.
1417 * This is applied after the axis reordering from above.
1419 elements += 3;
1420 for (i = 0; i < 3; i++) {
1421 if (elements[i].type != ACPI_TYPE_INTEGER)
1422 goto out;
1424 val = elements[i].integer.value;
1425 if (val != 0 && val != 1)
1426 goto out;
1427 if (!val)
1428 continue;
1430 /* Flip the values in the indicated column */
1431 final_ont[0][i] *= -1;
1432 final_ont[1][i] *= -1;
1433 final_ont[2][i] *= -1;
1436 /* Convert our integer matrix to a string-based iio_mount_matrix */
1437 for (i = 0; i < 3; i++) {
1438 for (j = 0; j < 3; j++) {
1439 int matrix_val = final_ont[i][j];
1440 char *str_value;
1442 switch (matrix_val) {
1443 case -1:
1444 str_value = "-1";
1445 break;
1446 case 0:
1447 str_value = "0";
1448 break;
1449 case 1:
1450 str_value = "1";
1451 break;
1452 default:
1453 goto out;
1455 adata->mount_matrix.rotation[i * 3 + j] = str_value;
1459 ret = 0;
1460 dev_info(&indio_dev->dev, "computed mount matrix from ACPI\n");
1462 out:
1463 kfree(buffer.pointer);
1464 if (ret)
1465 dev_dbg(&indio_dev->dev,
1466 "failed to apply ACPI orientation data: %d\n", ret);
1468 return ret;
1470 #else /* !CONFIG_ACPI */
1471 static int apply_acpi_orientation(struct iio_dev *indio_dev)
1473 return -EINVAL;
1475 #endif
1478 * st_accel_get_settings() - get sensor settings from device name
1479 * @name: device name buffer reference.
1481 * Return: valid reference on success, NULL otherwise.
1483 const struct st_sensor_settings *st_accel_get_settings(const char *name)
1485 int index = st_sensors_get_settings_index(name,
1486 st_accel_sensors_settings,
1487 ARRAY_SIZE(st_accel_sensors_settings));
1488 if (index < 0)
1489 return NULL;
1491 return &st_accel_sensors_settings[index];
1493 EXPORT_SYMBOL_NS(st_accel_get_settings, "IIO_ST_SENSORS");
1495 int st_accel_common_probe(struct iio_dev *indio_dev)
1497 struct st_sensor_data *adata = iio_priv(indio_dev);
1498 struct device *parent = indio_dev->dev.parent;
1499 struct st_sensors_platform_data *pdata = dev_get_platdata(parent);
1500 int err;
1502 indio_dev->modes = INDIO_DIRECT_MODE;
1503 indio_dev->info = &accel_info;
1505 err = st_sensors_verify_id(indio_dev);
1506 if (err < 0)
1507 return err;
1509 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
1510 indio_dev->channels = adata->sensor_settings->ch;
1511 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
1514 * First try specific ACPI methods to retrieve orientation then try the
1515 * generic function.
1517 err = apply_acpi_orientation(indio_dev);
1518 if (err) {
1519 err = iio_read_mount_matrix(parent, &adata->mount_matrix);
1520 if (err)
1521 return err;
1524 adata->current_fullscale = &adata->sensor_settings->fs.fs_avl[0];
1525 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
1527 if (!pdata)
1528 pdata = (struct st_sensors_platform_data *)&default_accel_pdata;
1530 err = st_sensors_init_sensor(indio_dev, pdata);
1531 if (err < 0)
1532 return err;
1534 err = st_accel_allocate_ring(indio_dev);
1535 if (err < 0)
1536 return err;
1538 if (adata->irq > 0) {
1539 err = st_sensors_allocate_trigger(indio_dev,
1540 ST_ACCEL_TRIGGER_OPS);
1541 if (err < 0)
1542 return err;
1545 return devm_iio_device_register(parent, indio_dev);
1547 EXPORT_SYMBOL_NS(st_accel_common_probe, "IIO_ST_SENSORS");
1549 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
1550 MODULE_DESCRIPTION("STMicroelectronics accelerometers driver");
1551 MODULE_LICENSE("GPL v2");
1552 MODULE_IMPORT_NS("IIO_ST_SENSORS");