1 // SPDX-License-Identifier: GPL-2.0
3 * FXOS8700 - NXP IMU (accelerometer plus magnetometer)
5 * IIO core driver for FXOS8700, with support for I2C/SPI busses
7 * TODO: Buffer, trigger, and IRQ support
9 #include <linux/module.h>
10 #include <linux/regmap.h>
11 #include <linux/bitops.h>
12 #include <linux/bitfield.h>
14 #include <linux/iio/iio.h>
15 #include <linux/iio/sysfs.h>
19 /* Register Definitions */
20 #define FXOS8700_STATUS 0x00
21 #define FXOS8700_OUT_X_MSB 0x01
22 #define FXOS8700_OUT_X_LSB 0x02
23 #define FXOS8700_OUT_Y_MSB 0x03
24 #define FXOS8700_OUT_Y_LSB 0x04
25 #define FXOS8700_OUT_Z_MSB 0x05
26 #define FXOS8700_OUT_Z_LSB 0x06
27 #define FXOS8700_F_SETUP 0x09
28 #define FXOS8700_TRIG_CFG 0x0a
29 #define FXOS8700_SYSMOD 0x0b
30 #define FXOS8700_INT_SOURCE 0x0c
31 #define FXOS8700_WHO_AM_I 0x0d
32 #define FXOS8700_XYZ_DATA_CFG 0x0e
33 #define FXOS8700_HP_FILTER_CUTOFF 0x0f
34 #define FXOS8700_PL_STATUS 0x10
35 #define FXOS8700_PL_CFG 0x11
36 #define FXOS8700_PL_COUNT 0x12
37 #define FXOS8700_PL_BF_ZCOMP 0x13
38 #define FXOS8700_PL_THS_REG 0x14
39 #define FXOS8700_A_FFMT_CFG 0x15
40 #define FXOS8700_A_FFMT_SRC 0x16
41 #define FXOS8700_A_FFMT_THS 0x17
42 #define FXOS8700_A_FFMT_COUNT 0x18
43 #define FXOS8700_TRANSIENT_CFG 0x1d
44 #define FXOS8700_TRANSIENT_SRC 0x1e
45 #define FXOS8700_TRANSIENT_THS 0x1f
46 #define FXOS8700_TRANSIENT_COUNT 0x20
47 #define FXOS8700_PULSE_CFG 0x21
48 #define FXOS8700_PULSE_SRC 0x22
49 #define FXOS8700_PULSE_THSX 0x23
50 #define FXOS8700_PULSE_THSY 0x24
51 #define FXOS8700_PULSE_THSZ 0x25
52 #define FXOS8700_PULSE_TMLT 0x26
53 #define FXOS8700_PULSE_LTCY 0x27
54 #define FXOS8700_PULSE_WIND 0x28
55 #define FXOS8700_ASLP_COUNT 0x29
56 #define FXOS8700_CTRL_REG1 0x2a
57 #define FXOS8700_CTRL_REG2 0x2b
58 #define FXOS8700_CTRL_REG3 0x2c
59 #define FXOS8700_CTRL_REG4 0x2d
60 #define FXOS8700_CTRL_REG5 0x2e
61 #define FXOS8700_OFF_X 0x2f
62 #define FXOS8700_OFF_Y 0x30
63 #define FXOS8700_OFF_Z 0x31
64 #define FXOS8700_M_DR_STATUS 0x32
65 #define FXOS8700_M_OUT_X_MSB 0x33
66 #define FXOS8700_M_OUT_X_LSB 0x34
67 #define FXOS8700_M_OUT_Y_MSB 0x35
68 #define FXOS8700_M_OUT_Y_LSB 0x36
69 #define FXOS8700_M_OUT_Z_MSB 0x37
70 #define FXOS8700_M_OUT_Z_LSB 0x38
71 #define FXOS8700_CMP_X_MSB 0x39
72 #define FXOS8700_CMP_X_LSB 0x3a
73 #define FXOS8700_CMP_Y_MSB 0x3b
74 #define FXOS8700_CMP_Y_LSB 0x3c
75 #define FXOS8700_CMP_Z_MSB 0x3d
76 #define FXOS8700_CMP_Z_LSB 0x3e
77 #define FXOS8700_M_OFF_X_MSB 0x3f
78 #define FXOS8700_M_OFF_X_LSB 0x40
79 #define FXOS8700_M_OFF_Y_MSB 0x41
80 #define FXOS8700_M_OFF_Y_LSB 0x42
81 #define FXOS8700_M_OFF_Z_MSB 0x43
82 #define FXOS8700_M_OFF_Z_LSB 0x44
83 #define FXOS8700_MAX_X_MSB 0x45
84 #define FXOS8700_MAX_X_LSB 0x46
85 #define FXOS8700_MAX_Y_MSB 0x47
86 #define FXOS8700_MAX_Y_LSB 0x48
87 #define FXOS8700_MAX_Z_MSB 0x49
88 #define FXOS8700_MAX_Z_LSB 0x4a
89 #define FXOS8700_MIN_X_MSB 0x4b
90 #define FXOS8700_MIN_X_LSB 0x4c
91 #define FXOS8700_MIN_Y_MSB 0x4d
92 #define FXOS8700_MIN_Y_LSB 0x4e
93 #define FXOS8700_MIN_Z_MSB 0x4f
94 #define FXOS8700_MIN_Z_LSB 0x50
95 #define FXOS8700_TEMP 0x51
96 #define FXOS8700_M_THS_CFG 0x52
97 #define FXOS8700_M_THS_SRC 0x53
98 #define FXOS8700_M_THS_X_MSB 0x54
99 #define FXOS8700_M_THS_X_LSB 0x55
100 #define FXOS8700_M_THS_Y_MSB 0x56
101 #define FXOS8700_M_THS_Y_LSB 0x57
102 #define FXOS8700_M_THS_Z_MSB 0x58
103 #define FXOS8700_M_THS_Z_LSB 0x59
104 #define FXOS8700_M_THS_COUNT 0x5a
105 #define FXOS8700_M_CTRL_REG1 0x5b
106 #define FXOS8700_M_CTRL_REG2 0x5c
107 #define FXOS8700_M_CTRL_REG3 0x5d
108 #define FXOS8700_M_INT_SRC 0x5e
109 #define FXOS8700_A_VECM_CFG 0x5f
110 #define FXOS8700_A_VECM_THS_MSB 0x60
111 #define FXOS8700_A_VECM_THS_LSB 0x61
112 #define FXOS8700_A_VECM_CNT 0x62
113 #define FXOS8700_A_VECM_INITX_MSB 0x63
114 #define FXOS8700_A_VECM_INITX_LSB 0x64
115 #define FXOS8700_A_VECM_INITY_MSB 0x65
116 #define FXOS8700_A_VECM_INITY_LSB 0x66
117 #define FXOS8700_A_VECM_INITZ_MSB 0x67
118 #define FXOS8700_A_VECM_INITZ_LSB 0x68
119 #define FXOS8700_M_VECM_CFG 0x69
120 #define FXOS8700_M_VECM_THS_MSB 0x6a
121 #define FXOS8700_M_VECM_THS_LSB 0x6b
122 #define FXOS8700_M_VECM_CNT 0x6c
123 #define FXOS8700_M_VECM_INITX_MSB 0x6d
124 #define FXOS8700_M_VECM_INITX_LSB 0x6e
125 #define FXOS8700_M_VECM_INITY_MSB 0x6f
126 #define FXOS8700_M_VECM_INITY_LSB 0x70
127 #define FXOS8700_M_VECM_INITZ_MSB 0x71
128 #define FXOS8700_M_VECM_INITZ_LSB 0x72
129 #define FXOS8700_A_FFMT_THS_X_MSB 0x73
130 #define FXOS8700_A_FFMT_THS_X_LSB 0x74
131 #define FXOS8700_A_FFMT_THS_Y_MSB 0x75
132 #define FXOS8700_A_FFMT_THS_Y_LSB 0x76
133 #define FXOS8700_A_FFMT_THS_Z_MSB 0x77
134 #define FXOS8700_A_FFMT_THS_Z_LSB 0x78
135 #define FXOS8700_A_TRAN_INIT_MSB 0x79
136 #define FXOS8700_A_TRAN_INIT_LSB_X 0x7a
137 #define FXOS8700_A_TRAN_INIT_LSB_Y 0x7b
138 #define FXOS8700_A_TRAN_INIT_LSB_Z 0x7d
139 #define FXOS8700_TM_NVM_LOCK 0x7e
140 #define FXOS8700_NVM_DATA0_35 0x80
141 #define FXOS8700_NVM_DATA_BNK3 0xa4
142 #define FXOS8700_NVM_DATA_BNK2 0xa5
143 #define FXOS8700_NVM_DATA_BNK1 0xa6
144 #define FXOS8700_NVM_DATA_BNK0 0xa7
146 /* Bit definitions for FXOS8700_CTRL_REG1 */
147 #define FXOS8700_CTRL_ODR_MAX 0x00
148 #define FXOS8700_CTRL_ODR_MSK GENMASK(5, 3)
150 /* Bit definitions for FXOS8700_M_CTRL_REG1 */
151 #define FXOS8700_HMS_MASK GENMASK(1, 0)
152 #define FXOS8700_OS_MASK GENMASK(4, 2)
154 /* Bit definitions for FXOS8700_M_CTRL_REG2 */
155 #define FXOS8700_MAXMIN_RST BIT(2)
156 #define FXOS8700_MAXMIN_DIS_THS BIT(3)
157 #define FXOS8700_MAXMIN_DIS BIT(4)
159 #define FXOS8700_ACTIVE 0x01
160 #define FXOS8700_ACTIVE_MIN_USLEEP 4000 /* from table 6 in datasheet */
162 #define FXOS8700_DEVICE_ID 0xC7
163 #define FXOS8700_PRE_DEVICE_ID 0xC4
164 #define FXOS8700_DATA_BUF_SIZE 3
166 struct fxos8700_data
{
167 struct regmap
*regmap
;
168 struct iio_trigger
*trig
;
169 __be16 buf
[FXOS8700_DATA_BUF_SIZE
] __aligned(IIO_DMA_MINALIGN
);
173 static const struct regmap_range read_range
[] = {
175 .range_min
= FXOS8700_STATUS
,
176 .range_max
= FXOS8700_A_FFMT_COUNT
,
178 .range_min
= FXOS8700_TRANSIENT_CFG
,
179 .range_max
= FXOS8700_A_FFMT_THS_Z_LSB
,
183 static const struct regmap_range write_range
[] = {
185 .range_min
= FXOS8700_F_SETUP
,
186 .range_max
= FXOS8700_TRIG_CFG
,
188 .range_min
= FXOS8700_XYZ_DATA_CFG
,
189 .range_max
= FXOS8700_HP_FILTER_CUTOFF
,
191 .range_min
= FXOS8700_PL_CFG
,
192 .range_max
= FXOS8700_A_FFMT_CFG
,
194 .range_min
= FXOS8700_A_FFMT_THS
,
195 .range_max
= FXOS8700_TRANSIENT_CFG
,
197 .range_min
= FXOS8700_TRANSIENT_THS
,
198 .range_max
= FXOS8700_PULSE_CFG
,
200 .range_min
= FXOS8700_PULSE_THSX
,
201 .range_max
= FXOS8700_OFF_Z
,
203 .range_min
= FXOS8700_M_OFF_X_MSB
,
204 .range_max
= FXOS8700_M_OFF_Z_LSB
,
206 .range_min
= FXOS8700_M_THS_CFG
,
207 .range_max
= FXOS8700_M_THS_CFG
,
209 .range_min
= FXOS8700_M_THS_X_MSB
,
210 .range_max
= FXOS8700_M_CTRL_REG3
,
212 .range_min
= FXOS8700_A_VECM_CFG
,
213 .range_max
= FXOS8700_A_FFMT_THS_Z_LSB
,
217 static const struct regmap_access_table driver_read_table
= {
218 .yes_ranges
= read_range
,
219 .n_yes_ranges
= ARRAY_SIZE(read_range
),
222 static const struct regmap_access_table driver_write_table
= {
223 .yes_ranges
= write_range
,
224 .n_yes_ranges
= ARRAY_SIZE(write_range
),
227 const struct regmap_config fxos8700_regmap_config
= {
230 .max_register
= FXOS8700_NVM_DATA_BNK0
,
231 .rd_table
= &driver_read_table
,
232 .wr_table
= &driver_write_table
,
234 EXPORT_SYMBOL(fxos8700_regmap_config
);
236 #define FXOS8700_CHANNEL(_type, _axis) { \
239 .channel2 = IIO_MOD_##_axis, \
240 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
241 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
242 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
245 enum fxos8700_accel_scale_bits
{
251 /* scan indexes follow DATA register order */
252 enum fxos8700_scan_axis
{
253 FXOS8700_SCAN_ACCEL_X
= 0,
254 FXOS8700_SCAN_ACCEL_Y
,
255 FXOS8700_SCAN_ACCEL_Z
,
256 FXOS8700_SCAN_MAGN_X
,
257 FXOS8700_SCAN_MAGN_Y
,
258 FXOS8700_SCAN_MAGN_Z
,
260 FXOS8700_SCAN_TIMESTAMP
,
263 enum fxos8700_sensor
{
266 FXOS8700_NUM_SENSORS
/* must be last */
269 enum fxos8700_int_pin
{
274 struct fxos8700_scale
{
279 struct fxos8700_odr
{
285 static const struct fxos8700_scale fxos8700_accel_scale
[] = {
292 * Accellerometer and magnetometer have the same ODR options, set in the
293 * CTRL_REG1 register. ODR is halved when using both sensors at once in
296 static const struct fxos8700_odr fxos8700_odr
[] = {
307 static const struct iio_chan_spec fxos8700_channels
[] = {
308 FXOS8700_CHANNEL(IIO_ACCEL
, X
),
309 FXOS8700_CHANNEL(IIO_ACCEL
, Y
),
310 FXOS8700_CHANNEL(IIO_ACCEL
, Z
),
311 FXOS8700_CHANNEL(IIO_MAGN
, X
),
312 FXOS8700_CHANNEL(IIO_MAGN
, Y
),
313 FXOS8700_CHANNEL(IIO_MAGN
, Z
),
314 IIO_CHAN_SOFT_TIMESTAMP(FXOS8700_SCAN_TIMESTAMP
),
317 static enum fxos8700_sensor
fxos8700_to_sensor(enum iio_chan_type iio_type
)
321 return FXOS8700_ACCEL
;
323 return FXOS8700_MAGN
;
329 static int fxos8700_set_active_mode(struct fxos8700_data
*data
,
330 enum fxos8700_sensor t
, bool mode
)
334 ret
= regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
, mode
);
338 usleep_range(FXOS8700_ACTIVE_MIN_USLEEP
,
339 FXOS8700_ACTIVE_MIN_USLEEP
+ 1000);
344 static int fxos8700_set_scale(struct fxos8700_data
*data
,
345 enum fxos8700_sensor t
, int uscale
)
349 static const int scale_num
= ARRAY_SIZE(fxos8700_accel_scale
);
350 struct device
*dev
= regmap_get_device(data
->regmap
);
352 if (t
== FXOS8700_MAGN
) {
353 dev_err(dev
, "Magnetometer scale is locked at 0.001Gs\n");
358 * When device is in active mode, it failed to set an ACCEL
359 * full-scale range(2g/4g/8g) in FXOS8700_XYZ_DATA_CFG.
360 * This is not align with the datasheet, but it is a fxos8700
361 * chip behavier. Set the device in standby mode before setting
362 * an ACCEL full-scale range.
364 ret
= regmap_read(data
->regmap
, FXOS8700_CTRL_REG1
, &val
);
368 active_mode
= val
& FXOS8700_ACTIVE
;
370 ret
= regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
,
371 val
& ~FXOS8700_ACTIVE
);
376 for (i
= 0; i
< scale_num
; i
++)
377 if (fxos8700_accel_scale
[i
].uscale
== uscale
)
383 ret
= regmap_write(data
->regmap
, FXOS8700_XYZ_DATA_CFG
,
384 fxos8700_accel_scale
[i
].bits
);
387 return regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
,
391 static int fxos8700_get_scale(struct fxos8700_data
*data
,
392 enum fxos8700_sensor t
, int *uscale
)
395 static const int scale_num
= ARRAY_SIZE(fxos8700_accel_scale
);
397 if (t
== FXOS8700_MAGN
) {
398 *uscale
= 1000; /* Magnetometer is locked at 0.001Gs */
402 ret
= regmap_read(data
->regmap
, FXOS8700_XYZ_DATA_CFG
, &val
);
406 for (i
= 0; i
< scale_num
; i
++) {
407 if (fxos8700_accel_scale
[i
].bits
== (val
& 0x3)) {
408 *uscale
= fxos8700_accel_scale
[i
].uscale
;
416 static int fxos8700_get_data(struct fxos8700_data
*data
, int chan_type
,
424 * Different register base addresses varies with channel types.
425 * This bug hasn't been noticed before because using an enum is
426 * really hard to read. Use an a switch statement to take over that.
430 base
= FXOS8700_OUT_X_MSB
;
433 base
= FXOS8700_M_OUT_X_MSB
;
439 /* Block read 6 bytes of device output registers to avoid data loss */
440 ret
= regmap_bulk_read(data
->regmap
, base
, data
->buf
,
445 /* Convert axis to buffer index */
446 reg
= axis
- IIO_MOD_X
;
449 * Convert to native endianness. The accel data and magn data
450 * are signed, so a forced type conversion is needed.
452 tmp
= be16_to_cpu(data
->buf
[reg
]);
455 * ACCEL output data registers contain the X-axis, Y-axis, and Z-axis
456 * 14-bit left-justified sample data and MAGN output data registers
457 * contain the X-axis, Y-axis, and Z-axis 16-bit sample data. Apply
458 * a signed 2 bits right shift to the readback raw data from ACCEL
459 * output data register and keep that from MAGN sensor as the origin.
460 * Value should be extended to 32 bit.
473 /* Convert to native endianness */
474 *val
= sign_extend32(tmp
, 15);
479 static int fxos8700_set_odr(struct fxos8700_data
*data
, enum fxos8700_sensor t
,
484 static const int odr_num
= ARRAY_SIZE(fxos8700_odr
);
486 ret
= regmap_read(data
->regmap
, FXOS8700_CTRL_REG1
, &val
);
490 active_mode
= val
& FXOS8700_ACTIVE
;
494 * The device must be in standby mode to change any of the
495 * other fields within CTRL_REG1
497 ret
= regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
,
498 val
& ~FXOS8700_ACTIVE
);
503 for (i
= 0; i
< odr_num
; i
++)
504 if (fxos8700_odr
[i
].odr
== odr
&& fxos8700_odr
[i
].uodr
== uodr
)
510 val
&= ~FXOS8700_CTRL_ODR_MSK
;
511 val
|= FIELD_PREP(FXOS8700_CTRL_ODR_MSK
, fxos8700_odr
[i
].bits
) | FXOS8700_ACTIVE
;
512 return regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
, val
);
515 static int fxos8700_get_odr(struct fxos8700_data
*data
, enum fxos8700_sensor t
,
519 static const int odr_num
= ARRAY_SIZE(fxos8700_odr
);
521 ret
= regmap_read(data
->regmap
, FXOS8700_CTRL_REG1
, &val
);
525 val
= FIELD_GET(FXOS8700_CTRL_ODR_MSK
, val
);
527 for (i
= 0; i
< odr_num
; i
++)
528 if (val
== fxos8700_odr
[i
].bits
)
534 *odr
= fxos8700_odr
[i
].odr
;
535 *uodr
= fxos8700_odr
[i
].uodr
;
540 static int fxos8700_read_raw(struct iio_dev
*indio_dev
,
541 struct iio_chan_spec
const *chan
,
542 int *val
, int *val2
, long mask
)
545 struct fxos8700_data
*data
= iio_priv(indio_dev
);
548 case IIO_CHAN_INFO_RAW
:
549 ret
= fxos8700_get_data(data
, chan
->type
, chan
->channel2
, val
);
553 case IIO_CHAN_INFO_SCALE
:
555 ret
= fxos8700_get_scale(data
, fxos8700_to_sensor(chan
->type
),
557 return ret
? ret
: IIO_VAL_INT_PLUS_MICRO
;
558 case IIO_CHAN_INFO_SAMP_FREQ
:
559 ret
= fxos8700_get_odr(data
, fxos8700_to_sensor(chan
->type
),
561 return ret
? ret
: IIO_VAL_INT_PLUS_MICRO
;
567 static int fxos8700_write_raw(struct iio_dev
*indio_dev
,
568 struct iio_chan_spec
const *chan
,
569 int val
, int val2
, long mask
)
571 struct fxos8700_data
*data
= iio_priv(indio_dev
);
574 case IIO_CHAN_INFO_SCALE
:
575 return fxos8700_set_scale(data
, fxos8700_to_sensor(chan
->type
),
577 case IIO_CHAN_INFO_SAMP_FREQ
:
578 return fxos8700_set_odr(data
, fxos8700_to_sensor(chan
->type
),
585 static IIO_CONST_ATTR(in_accel_sampling_frequency_available
,
586 "1.5625 6.25 12.5 50 100 200 400 800");
587 static IIO_CONST_ATTR(in_magn_sampling_frequency_available
,
588 "1.5625 6.25 12.5 50 100 200 400 800");
589 static IIO_CONST_ATTR(in_accel_scale_available
, "0.000244 0.000488 0.000976");
590 static IIO_CONST_ATTR(in_magn_scale_available
, "0.001000");
592 static struct attribute
*fxos8700_attrs
[] = {
593 &iio_const_attr_in_accel_sampling_frequency_available
.dev_attr
.attr
,
594 &iio_const_attr_in_magn_sampling_frequency_available
.dev_attr
.attr
,
595 &iio_const_attr_in_accel_scale_available
.dev_attr
.attr
,
596 &iio_const_attr_in_magn_scale_available
.dev_attr
.attr
,
600 static const struct attribute_group fxos8700_attrs_group
= {
601 .attrs
= fxos8700_attrs
,
604 static const struct iio_info fxos8700_info
= {
605 .read_raw
= fxos8700_read_raw
,
606 .write_raw
= fxos8700_write_raw
,
607 .attrs
= &fxos8700_attrs_group
,
610 static int fxos8700_chip_init(struct fxos8700_data
*data
, bool use_spi
)
614 struct device
*dev
= regmap_get_device(data
->regmap
);
616 ret
= regmap_read(data
->regmap
, FXOS8700_WHO_AM_I
, &val
);
618 dev_err(dev
, "Error reading chip id\n");
621 if (val
!= FXOS8700_DEVICE_ID
&& val
!= FXOS8700_PRE_DEVICE_ID
) {
622 dev_err(dev
, "Wrong chip id, got %x expected %x or %x\n",
623 val
, FXOS8700_DEVICE_ID
, FXOS8700_PRE_DEVICE_ID
);
627 ret
= fxos8700_set_active_mode(data
, FXOS8700_ACCEL
, true);
631 ret
= fxos8700_set_active_mode(data
, FXOS8700_MAGN
, true);
636 * The device must be in standby mode to change any of the other fields
639 ret
= regmap_write(data
->regmap
, FXOS8700_CTRL_REG1
, 0x00);
643 /* Set max oversample ratio (OSR) and both devices active */
644 ret
= regmap_write(data
->regmap
, FXOS8700_M_CTRL_REG1
,
645 FXOS8700_HMS_MASK
| FXOS8700_OS_MASK
);
649 /* Disable and rst min/max measurements & threshold */
650 ret
= regmap_write(data
->regmap
, FXOS8700_M_CTRL_REG2
,
651 FXOS8700_MAXMIN_RST
| FXOS8700_MAXMIN_DIS_THS
|
652 FXOS8700_MAXMIN_DIS
);
657 * Set max full-scale range (+/-8G) for ACCEL sensor in chip
658 * initialization then activate the device.
660 ret
= regmap_write(data
->regmap
, FXOS8700_XYZ_DATA_CFG
, MODE_8G
);
664 /* Max ODR (800Hz individual or 400Hz hybrid), active mode */
665 return regmap_update_bits(data
->regmap
, FXOS8700_CTRL_REG1
,
666 FXOS8700_CTRL_ODR_MSK
| FXOS8700_ACTIVE
,
667 FIELD_PREP(FXOS8700_CTRL_ODR_MSK
, FXOS8700_CTRL_ODR_MAX
) |
671 static void fxos8700_chip_uninit(void *data
)
673 struct fxos8700_data
*fxos8700_data
= data
;
675 fxos8700_set_active_mode(fxos8700_data
, FXOS8700_ACCEL
, false);
676 fxos8700_set_active_mode(fxos8700_data
, FXOS8700_MAGN
, false);
679 int fxos8700_core_probe(struct device
*dev
, struct regmap
*regmap
,
680 const char *name
, bool use_spi
)
682 struct iio_dev
*indio_dev
;
683 struct fxos8700_data
*data
;
686 indio_dev
= devm_iio_device_alloc(dev
, sizeof(*data
));
690 data
= iio_priv(indio_dev
);
691 dev_set_drvdata(dev
, indio_dev
);
692 data
->regmap
= regmap
;
694 ret
= fxos8700_chip_init(data
, use_spi
);
698 ret
= devm_add_action_or_reset(dev
, fxos8700_chip_uninit
, data
);
702 indio_dev
->channels
= fxos8700_channels
;
703 indio_dev
->num_channels
= ARRAY_SIZE(fxos8700_channels
);
704 indio_dev
->name
= name
? name
: "fxos8700";
705 indio_dev
->modes
= INDIO_DIRECT_MODE
;
706 indio_dev
->info
= &fxos8700_info
;
708 return devm_iio_device_register(dev
, indio_dev
);
710 EXPORT_SYMBOL_GPL(fxos8700_core_probe
);
712 MODULE_AUTHOR("Robert Jones <rjones@gateworks.com>");
713 MODULE_DESCRIPTION("FXOS8700 6-Axis Acc and Mag Combo Sensor driver");
714 MODULE_LICENSE("GPL v2");