1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for NXP FXAS21002C Gyroscope - Core
5 * Copyright (C) 2019 Linaro Ltd.
8 #include <linux/interrupt.h>
9 #include <linux/module.h>
10 #include <linux/of_irq.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/regmap.h>
14 #include <linux/regulator/consumer.h>
16 #include <linux/iio/events.h>
17 #include <linux/iio/iio.h>
18 #include <linux/iio/buffer.h>
19 #include <linux/iio/sysfs.h>
20 #include <linux/iio/trigger.h>
21 #include <linux/iio/trigger_consumer.h>
22 #include <linux/iio/triggered_buffer.h>
24 #include "fxas21002c.h"
26 #define FXAS21002C_CHIP_ID_1 0xD6
27 #define FXAS21002C_CHIP_ID_2 0xD7
29 enum fxas21002c_mode_state
{
30 FXAS21002C_MODE_STANDBY
,
31 FXAS21002C_MODE_READY
,
32 FXAS21002C_MODE_ACTIVE
,
35 #define FXAS21002C_STANDBY_ACTIVE_TIME_MS 62
36 #define FXAS21002C_READY_ACTIVE_TIME_MS 7
38 #define FXAS21002C_ODR_LIST_MAX 10
40 #define FXAS21002C_SCALE_FRACTIONAL 32
41 #define FXAS21002C_RANGE_LIMIT_DOUBLE 2000
43 #define FXAS21002C_AXIS_TO_REG(axis) (FXAS21002C_REG_OUT_X_MSB + ((axis) * 2))
45 static const int fxas21002c_odr_values
[] = {
46 800, 400, 200, 100, 50, 25, 12, 12
50 * These values are taken from the low-pass filter cutoff frequency calculated
51 * ODR * 0.lpf_values. So, for ODR = 800Hz with a lpf value = 0.32
52 * => LPF cutoff frequency = 800 * 0.32 = 256 Hz
54 static const int fxas21002c_lpf_values
[] = {
59 * These values are taken from the high-pass filter cutoff frequency calculated
60 * ODR * 0.0hpf_values. So, for ODR = 800Hz with a hpf value = 0.018750
61 * => HPF cutoff frequency = 800 * 0.018750 = 15 Hz
63 static const int fxas21002c_hpf_values
[] = {
64 18750, 9625, 4875, 2475
67 static const int fxas21002c_range_values
[] = {
68 4000, 2000, 1000, 500, 250
71 struct fxas21002c_data
{
73 enum fxas21002c_mode_state mode
;
74 enum fxas21002c_mode_state prev_mode
;
76 struct mutex lock
; /* serialize data access */
77 struct regmap
*regmap
;
78 struct regmap_field
*regmap_fields
[F_MAX_FIELDS
];
79 struct iio_trigger
*dready_trig
;
83 struct regulator
*vdd
;
84 struct regulator
*vddio
;
87 * DMA (thus cache coherency maintenance) requires the
88 * transfer buffers to live in their own cache lines.
90 s16 buffer
[8] ____cacheline_aligned
;
93 enum fxas21002c_channel_index
{
100 static int fxas21002c_odr_hz_from_value(struct fxas21002c_data
*data
, u8 value
)
102 int odr_value_max
= ARRAY_SIZE(fxas21002c_odr_values
) - 1;
104 value
= min_t(u8
, value
, odr_value_max
);
106 return fxas21002c_odr_values
[value
];
109 static int fxas21002c_odr_value_from_hz(struct fxas21002c_data
*data
,
112 int odr_table_size
= ARRAY_SIZE(fxas21002c_odr_values
);
115 for (i
= 0; i
< odr_table_size
; i
++)
116 if (fxas21002c_odr_values
[i
] == hz
)
122 static int fxas21002c_lpf_bw_from_value(struct fxas21002c_data
*data
, u8 value
)
124 int lpf_value_max
= ARRAY_SIZE(fxas21002c_lpf_values
) - 1;
126 value
= min_t(u8
, value
, lpf_value_max
);
128 return fxas21002c_lpf_values
[value
];
131 static int fxas21002c_lpf_value_from_bw(struct fxas21002c_data
*data
,
134 int lpf_table_size
= ARRAY_SIZE(fxas21002c_lpf_values
);
137 for (i
= 0; i
< lpf_table_size
; i
++)
138 if (fxas21002c_lpf_values
[i
] == hz
)
144 static int fxas21002c_hpf_sel_from_value(struct fxas21002c_data
*data
, u8 value
)
146 int hpf_value_max
= ARRAY_SIZE(fxas21002c_hpf_values
) - 1;
148 value
= min_t(u8
, value
, hpf_value_max
);
150 return fxas21002c_hpf_values
[value
];
153 static int fxas21002c_hpf_value_from_sel(struct fxas21002c_data
*data
,
156 int hpf_table_size
= ARRAY_SIZE(fxas21002c_hpf_values
);
159 for (i
= 0; i
< hpf_table_size
; i
++)
160 if (fxas21002c_hpf_values
[i
] == hz
)
166 static int fxas21002c_range_fs_from_value(struct fxas21002c_data
*data
,
169 int range_value_max
= ARRAY_SIZE(fxas21002c_range_values
) - 1;
170 unsigned int fs_double
;
173 /* We need to check if FS_DOUBLE is enabled to offset the value */
174 ret
= regmap_field_read(data
->regmap_fields
[F_FS_DOUBLE
], &fs_double
);
181 value
= min_t(u8
, value
, range_value_max
);
183 return fxas21002c_range_values
[value
];
186 static int fxas21002c_range_value_from_fs(struct fxas21002c_data
*data
,
189 int range_table_size
= ARRAY_SIZE(fxas21002c_range_values
);
195 for (i
= 0; i
< range_table_size
; i
++)
196 if (fxas21002c_range_values
[i
] == range
) {
204 if (range
> FXAS21002C_RANGE_LIMIT_DOUBLE
)
207 ret
= regmap_field_write(data
->regmap_fields
[F_FS_DOUBLE
], fs_double
);
214 static int fxas21002c_mode_get(struct fxas21002c_data
*data
)
220 ret
= regmap_field_read(data
->regmap_fields
[F_ACTIVE
], &active
);
224 return FXAS21002C_MODE_ACTIVE
;
226 ret
= regmap_field_read(data
->regmap_fields
[F_READY
], &ready
);
230 return FXAS21002C_MODE_READY
;
232 return FXAS21002C_MODE_STANDBY
;
235 static int fxas21002c_mode_set(struct fxas21002c_data
*data
,
236 enum fxas21002c_mode_state mode
)
240 if (mode
== data
->mode
)
243 if (mode
== FXAS21002C_MODE_READY
)
244 ret
= regmap_field_write(data
->regmap_fields
[F_READY
], 1);
246 ret
= regmap_field_write(data
->regmap_fields
[F_READY
], 0);
250 if (mode
== FXAS21002C_MODE_ACTIVE
)
251 ret
= regmap_field_write(data
->regmap_fields
[F_ACTIVE
], 1);
253 ret
= regmap_field_write(data
->regmap_fields
[F_ACTIVE
], 0);
257 /* if going to active wait the setup times */
258 if (mode
== FXAS21002C_MODE_ACTIVE
&&
259 data
->mode
== FXAS21002C_MODE_STANDBY
)
260 msleep_interruptible(FXAS21002C_STANDBY_ACTIVE_TIME_MS
);
262 if (data
->mode
== FXAS21002C_MODE_READY
)
263 msleep_interruptible(FXAS21002C_READY_ACTIVE_TIME_MS
);
265 data
->prev_mode
= data
->mode
;
271 static int fxas21002c_write(struct fxas21002c_data
*data
,
272 enum fxas21002c_fields field
, int bits
)
277 mutex_lock(&data
->lock
);
279 actual_mode
= fxas21002c_mode_get(data
);
280 if (actual_mode
< 0) {
285 ret
= fxas21002c_mode_set(data
, FXAS21002C_MODE_READY
);
289 ret
= regmap_field_write(data
->regmap_fields
[field
], bits
);
293 ret
= fxas21002c_mode_set(data
, data
->prev_mode
);
296 mutex_unlock(&data
->lock
);
301 static int fxas21002c_pm_get(struct fxas21002c_data
*data
)
303 struct device
*dev
= regmap_get_device(data
->regmap
);
306 ret
= pm_runtime_get_sync(dev
);
308 pm_runtime_put_noidle(dev
);
313 static int fxas21002c_pm_put(struct fxas21002c_data
*data
)
315 struct device
*dev
= regmap_get_device(data
->regmap
);
317 pm_runtime_mark_last_busy(dev
);
319 return pm_runtime_put_autosuspend(dev
);
322 static int fxas21002c_temp_get(struct fxas21002c_data
*data
, int *val
)
324 struct device
*dev
= regmap_get_device(data
->regmap
);
328 mutex_lock(&data
->lock
);
329 ret
= fxas21002c_pm_get(data
);
333 ret
= regmap_field_read(data
->regmap_fields
[F_TEMP
], &temp
);
335 dev_err(dev
, "failed to read temp: %d\n", ret
);
339 *val
= sign_extend32(temp
, 7);
341 ret
= fxas21002c_pm_put(data
);
348 mutex_unlock(&data
->lock
);
353 static int fxas21002c_axis_get(struct fxas21002c_data
*data
,
356 struct device
*dev
= regmap_get_device(data
->regmap
);
360 mutex_lock(&data
->lock
);
361 ret
= fxas21002c_pm_get(data
);
365 ret
= regmap_bulk_read(data
->regmap
, FXAS21002C_AXIS_TO_REG(index
),
366 &axis_be
, sizeof(axis_be
));
368 dev_err(dev
, "failed to read axis: %d: %d\n", index
, ret
);
372 *val
= sign_extend32(be16_to_cpu(axis_be
), 15);
374 ret
= fxas21002c_pm_put(data
);
381 mutex_unlock(&data
->lock
);
386 static int fxas21002c_odr_get(struct fxas21002c_data
*data
, int *odr
)
388 unsigned int odr_bits
;
391 mutex_lock(&data
->lock
);
392 ret
= regmap_field_read(data
->regmap_fields
[F_DR
], &odr_bits
);
396 *odr
= fxas21002c_odr_hz_from_value(data
, odr_bits
);
401 mutex_unlock(&data
->lock
);
406 static int fxas21002c_odr_set(struct fxas21002c_data
*data
, int odr
)
410 odr_bits
= fxas21002c_odr_value_from_hz(data
, odr
);
414 return fxas21002c_write(data
, F_DR
, odr_bits
);
417 static int fxas21002c_lpf_get(struct fxas21002c_data
*data
, int *val2
)
419 unsigned int bw_bits
;
422 mutex_lock(&data
->lock
);
423 ret
= regmap_field_read(data
->regmap_fields
[F_BW
], &bw_bits
);
427 *val2
= fxas21002c_lpf_bw_from_value(data
, bw_bits
) * 10000;
429 ret
= IIO_VAL_INT_PLUS_MICRO
;
432 mutex_unlock(&data
->lock
);
437 static int fxas21002c_lpf_set(struct fxas21002c_data
*data
, int bw
)
443 bw_bits
= fxas21002c_lpf_value_from_bw(data
, bw
);
448 * From table 33 of the device spec, for ODR = 25Hz and 12.5 value 0.08
449 * is not allowed and for ODR = 12.5 value 0.16 is also not allowed
451 ret
= fxas21002c_odr_get(data
, &odr
);
455 if ((odr
== 25 && bw_bits
> 0x01) || (odr
== 12 && bw_bits
> 0))
458 return fxas21002c_write(data
, F_BW
, bw_bits
);
461 static int fxas21002c_hpf_get(struct fxas21002c_data
*data
, int *val2
)
463 unsigned int sel_bits
;
466 mutex_lock(&data
->lock
);
467 ret
= regmap_field_read(data
->regmap_fields
[F_SEL
], &sel_bits
);
471 *val2
= fxas21002c_hpf_sel_from_value(data
, sel_bits
);
473 ret
= IIO_VAL_INT_PLUS_MICRO
;
476 mutex_unlock(&data
->lock
);
481 static int fxas21002c_hpf_set(struct fxas21002c_data
*data
, int sel
)
485 sel_bits
= fxas21002c_hpf_value_from_sel(data
, sel
);
489 return fxas21002c_write(data
, F_SEL
, sel_bits
);
492 static int fxas21002c_scale_get(struct fxas21002c_data
*data
, int *val
)
498 mutex_lock(&data
->lock
);
499 ret
= regmap_field_read(data
->regmap_fields
[F_FS
], &fs_bits
);
503 scale
= fxas21002c_range_fs_from_value(data
, fs_bits
);
512 mutex_unlock(&data
->lock
);
517 static int fxas21002c_scale_set(struct fxas21002c_data
*data
, int range
)
521 fs_bits
= fxas21002c_range_value_from_fs(data
, range
);
525 return fxas21002c_write(data
, F_FS
, fs_bits
);
528 static int fxas21002c_read_raw(struct iio_dev
*indio_dev
,
529 struct iio_chan_spec
const *chan
, int *val
,
530 int *val2
, long mask
)
532 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
536 case IIO_CHAN_INFO_RAW
:
537 switch (chan
->type
) {
539 return fxas21002c_temp_get(data
, val
);
541 return fxas21002c_axis_get(data
, chan
->scan_index
, val
);
545 case IIO_CHAN_INFO_SCALE
:
546 switch (chan
->type
) {
548 *val2
= FXAS21002C_SCALE_FRACTIONAL
;
549 ret
= fxas21002c_scale_get(data
, val
);
553 return IIO_VAL_FRACTIONAL
;
557 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
559 return fxas21002c_lpf_get(data
, val2
);
560 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY
:
562 return fxas21002c_hpf_get(data
, val2
);
563 case IIO_CHAN_INFO_SAMP_FREQ
:
565 return fxas21002c_odr_get(data
, val
);
571 static int fxas21002c_write_raw(struct iio_dev
*indio_dev
,
572 struct iio_chan_spec
const *chan
, int val
,
575 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
579 case IIO_CHAN_INFO_SAMP_FREQ
:
583 return fxas21002c_odr_set(data
, val
);
584 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
589 return fxas21002c_lpf_set(data
, val2
);
590 case IIO_CHAN_INFO_SCALE
:
591 switch (chan
->type
) {
593 range
= (((val
* 1000 + val2
/ 1000) *
594 FXAS21002C_SCALE_FRACTIONAL
) / 1000);
595 return fxas21002c_scale_set(data
, range
);
599 case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY
:
600 return fxas21002c_hpf_set(data
, val2
);
606 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("12.5 25 50 100 200 400 800");
608 static IIO_CONST_ATTR(in_anglvel_filter_low_pass_3db_frequency_available
,
611 static IIO_CONST_ATTR(in_anglvel_filter_high_pass_3db_frequency_available
,
612 "0.018750 0.009625 0.004875 0.002475");
614 static IIO_CONST_ATTR(in_anglvel_scale_available
,
615 "125.0 62.5 31.25 15.625 7.8125");
617 static struct attribute
*fxas21002c_attributes
[] = {
618 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
619 &iio_const_attr_in_anglvel_filter_low_pass_3db_frequency_available
.dev_attr
.attr
,
620 &iio_const_attr_in_anglvel_filter_high_pass_3db_frequency_available
.dev_attr
.attr
,
621 &iio_const_attr_in_anglvel_scale_available
.dev_attr
.attr
,
625 static const struct attribute_group fxas21002c_attrs_group
= {
626 .attrs
= fxas21002c_attributes
,
629 #define FXAS21002C_CHANNEL(_axis) { \
630 .type = IIO_ANGL_VEL, \
632 .channel2 = IIO_MOD_##_axis, \
633 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
634 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
635 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \
636 BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY) | \
637 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
638 .scan_index = CHANNEL_SCAN_INDEX_##_axis, \
643 .endianness = IIO_BE, \
647 static const struct iio_chan_spec fxas21002c_channels
[] = {
650 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
),
653 FXAS21002C_CHANNEL(X
),
654 FXAS21002C_CHANNEL(Y
),
655 FXAS21002C_CHANNEL(Z
),
658 static const struct iio_info fxas21002c_info
= {
659 .attrs
= &fxas21002c_attrs_group
,
660 .read_raw
= &fxas21002c_read_raw
,
661 .write_raw
= &fxas21002c_write_raw
,
664 static irqreturn_t
fxas21002c_trigger_handler(int irq
, void *p
)
666 struct iio_poll_func
*pf
= p
;
667 struct iio_dev
*indio_dev
= pf
->indio_dev
;
668 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
671 mutex_lock(&data
->lock
);
672 ret
= regmap_bulk_read(data
->regmap
, FXAS21002C_REG_OUT_X_MSB
,
673 data
->buffer
, CHANNEL_SCAN_MAX
* sizeof(s16
));
677 iio_push_to_buffers_with_timestamp(indio_dev
, data
->buffer
,
681 mutex_unlock(&data
->lock
);
683 iio_trigger_notify_done(indio_dev
->trig
);
688 static int fxas21002c_chip_init(struct fxas21002c_data
*data
)
690 struct device
*dev
= regmap_get_device(data
->regmap
);
691 unsigned int chip_id
;
694 ret
= regmap_field_read(data
->regmap_fields
[F_WHO_AM_I
], &chip_id
);
698 if (chip_id
!= FXAS21002C_CHIP_ID_1
&&
699 chip_id
!= FXAS21002C_CHIP_ID_2
) {
700 dev_err(dev
, "chip id 0x%02x is not supported\n", chip_id
);
704 data
->chip_id
= chip_id
;
706 ret
= fxas21002c_mode_set(data
, FXAS21002C_MODE_STANDBY
);
710 /* Set ODR to 200HZ as default */
711 ret
= fxas21002c_odr_set(data
, 200);
713 dev_err(dev
, "failed to set ODR: %d\n", ret
);
718 static int fxas21002c_data_rdy_trigger_set_state(struct iio_trigger
*trig
,
721 struct iio_dev
*indio_dev
= iio_trigger_get_drvdata(trig
);
722 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
724 return regmap_field_write(data
->regmap_fields
[F_INT_EN_DRDY
], state
);
727 static const struct iio_trigger_ops fxas21002c_trigger_ops
= {
728 .set_trigger_state
= &fxas21002c_data_rdy_trigger_set_state
,
731 static irqreturn_t
fxas21002c_data_rdy_handler(int irq
, void *private)
733 struct iio_dev
*indio_dev
= private;
734 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
736 data
->timestamp
= iio_get_time_ns(indio_dev
);
738 return IRQ_WAKE_THREAD
;
741 static irqreturn_t
fxas21002c_data_rdy_thread(int irq
, void *private)
743 struct iio_dev
*indio_dev
= private;
744 struct fxas21002c_data
*data
= iio_priv(indio_dev
);
745 unsigned int data_ready
;
748 ret
= regmap_field_read(data
->regmap_fields
[F_SRC_DRDY
], &data_ready
);
755 iio_trigger_poll_chained(data
->dready_trig
);
760 static int fxas21002c_trigger_probe(struct fxas21002c_data
*data
)
762 struct device
*dev
= regmap_get_device(data
->regmap
);
763 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
764 struct device_node
*np
= indio_dev
->dev
.of_node
;
765 unsigned long irq_trig
;
773 irq1
= of_irq_get_byname(np
, "INT1");
775 if (irq1
== data
->irq
) {
776 dev_info(dev
, "using interrupt line INT1\n");
777 ret
= regmap_field_write(data
->regmap_fields
[F_INT_CFG_DRDY
],
783 dev_info(dev
, "using interrupt line INT2\n");
785 irq_open_drain
= of_property_read_bool(np
, "drive-open-drain");
787 data
->dready_trig
= devm_iio_trigger_alloc(dev
, "%s-dev%d",
790 if (!data
->dready_trig
)
793 irq_trig
= irqd_get_trigger_type(irq_get_irq_data(data
->irq
));
795 if (irq_trig
== IRQF_TRIGGER_RISING
) {
796 ret
= regmap_field_write(data
->regmap_fields
[F_IPOL
], 1);
802 irq_trig
|= IRQF_SHARED
;
804 ret
= devm_request_threaded_irq(dev
, data
->irq
,
805 fxas21002c_data_rdy_handler
,
806 fxas21002c_data_rdy_thread
,
807 irq_trig
, "fxas21002c_data_ready",
812 data
->dready_trig
->dev
.parent
= dev
;
813 data
->dready_trig
->ops
= &fxas21002c_trigger_ops
;
814 iio_trigger_set_drvdata(data
->dready_trig
, indio_dev
);
816 return devm_iio_trigger_register(dev
, data
->dready_trig
);
819 static int fxas21002c_power_enable(struct fxas21002c_data
*data
)
823 ret
= regulator_enable(data
->vdd
);
827 ret
= regulator_enable(data
->vddio
);
829 regulator_disable(data
->vdd
);
836 static void fxas21002c_power_disable(struct fxas21002c_data
*data
)
838 regulator_disable(data
->vdd
);
839 regulator_disable(data
->vddio
);
842 static void fxas21002c_power_disable_action(void *_data
)
844 struct fxas21002c_data
*data
= _data
;
846 fxas21002c_power_disable(data
);
849 static int fxas21002c_regulators_get(struct fxas21002c_data
*data
)
851 struct device
*dev
= regmap_get_device(data
->regmap
);
853 data
->vdd
= devm_regulator_get(dev
->parent
, "vdd");
854 if (IS_ERR(data
->vdd
))
855 return PTR_ERR(data
->vdd
);
857 data
->vddio
= devm_regulator_get(dev
->parent
, "vddio");
859 return PTR_ERR_OR_ZERO(data
->vddio
);
862 int fxas21002c_core_probe(struct device
*dev
, struct regmap
*regmap
, int irq
,
865 struct fxas21002c_data
*data
;
866 struct iio_dev
*indio_dev
;
867 struct regmap_field
*f
;
871 indio_dev
= devm_iio_device_alloc(dev
, sizeof(*data
));
875 data
= iio_priv(indio_dev
);
876 dev_set_drvdata(dev
, indio_dev
);
878 data
->regmap
= regmap
;
880 for (i
= 0; i
< F_MAX_FIELDS
; i
++) {
881 f
= devm_regmap_field_alloc(dev
, data
->regmap
,
882 fxas21002c_reg_fields
[i
]);
886 data
->regmap_fields
[i
] = f
;
889 mutex_init(&data
->lock
);
891 ret
= fxas21002c_regulators_get(data
);
895 ret
= fxas21002c_power_enable(data
);
899 ret
= devm_add_action_or_reset(dev
, fxas21002c_power_disable_action
,
904 ret
= fxas21002c_chip_init(data
);
908 indio_dev
->dev
.parent
= dev
;
909 indio_dev
->channels
= fxas21002c_channels
;
910 indio_dev
->num_channels
= ARRAY_SIZE(fxas21002c_channels
);
911 indio_dev
->name
= name
;
912 indio_dev
->modes
= INDIO_DIRECT_MODE
;
913 indio_dev
->info
= &fxas21002c_info
;
915 ret
= fxas21002c_trigger_probe(data
);
919 ret
= devm_iio_triggered_buffer_setup(dev
, indio_dev
, NULL
,
920 fxas21002c_trigger_handler
, NULL
);
924 ret
= pm_runtime_set_active(dev
);
928 pm_runtime_enable(dev
);
929 pm_runtime_set_autosuspend_delay(dev
, 2000);
930 pm_runtime_use_autosuspend(dev
);
932 ret
= iio_device_register(indio_dev
);
939 pm_runtime_disable(dev
);
940 pm_runtime_set_suspended(dev
);
941 pm_runtime_put_noidle(dev
);
945 EXPORT_SYMBOL_GPL(fxas21002c_core_probe
);
947 void fxas21002c_core_remove(struct device
*dev
)
949 struct iio_dev
*indio_dev
= dev_get_drvdata(dev
);
951 iio_device_unregister(indio_dev
);
953 pm_runtime_disable(dev
);
954 pm_runtime_set_suspended(dev
);
955 pm_runtime_put_noidle(dev
);
957 EXPORT_SYMBOL_GPL(fxas21002c_core_remove
);
959 static int __maybe_unused
fxas21002c_suspend(struct device
*dev
)
961 struct fxas21002c_data
*data
= iio_priv(dev_get_drvdata(dev
));
963 fxas21002c_mode_set(data
, FXAS21002C_MODE_STANDBY
);
964 fxas21002c_power_disable(data
);
969 static int __maybe_unused
fxas21002c_resume(struct device
*dev
)
971 struct fxas21002c_data
*data
= iio_priv(dev_get_drvdata(dev
));
974 ret
= fxas21002c_power_enable(data
);
978 return fxas21002c_mode_set(data
, data
->prev_mode
);
981 static int __maybe_unused
fxas21002c_runtime_suspend(struct device
*dev
)
983 struct fxas21002c_data
*data
= iio_priv(dev_get_drvdata(dev
));
985 return fxas21002c_mode_set(data
, FXAS21002C_MODE_READY
);
988 static int __maybe_unused
fxas21002c_runtime_resume(struct device
*dev
)
990 struct fxas21002c_data
*data
= iio_priv(dev_get_drvdata(dev
));
992 return fxas21002c_mode_set(data
, FXAS21002C_MODE_ACTIVE
);
995 const struct dev_pm_ops fxas21002c_pm_ops
= {
996 SET_SYSTEM_SLEEP_PM_OPS(fxas21002c_suspend
, fxas21002c_resume
)
997 SET_RUNTIME_PM_OPS(fxas21002c_runtime_suspend
,
998 fxas21002c_runtime_resume
, NULL
)
1000 EXPORT_SYMBOL_GPL(fxas21002c_pm_ops
);
1002 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
1003 MODULE_LICENSE("GPL v2");
1004 MODULE_DESCRIPTION("FXAS21002C Gyro driver");