2 * Murata ZPA2326 pressure and temperature sensor IIO driver
4 * Copyright (c) 2016 Parrot S.A.
6 * Author: Gregor Boirie <gregor.boirie@parrot.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * DOC: ZPA2326 theory of operations
21 * This driver supports %INDIO_DIRECT_MODE and %INDIO_BUFFER_TRIGGERED IIO
23 * A internal hardware trigger is also implemented to dispatch registered IIO
24 * trigger consumers upon "sample ready" interrupts.
26 * ZPA2326 hardware supports 2 sampling mode: one shot and continuous.
28 * A complete one shot sampling cycle gets device out of low power mode,
29 * performs pressure and temperature measurements, then automatically switches
30 * back to low power mode. It is meant for on demand sampling with optimal power
31 * saving at the cost of lower sampling rate and higher software overhead.
32 * This is a natural candidate for IIO read_raw hook implementation
33 * (%INDIO_DIRECT_MODE). It is also used for triggered buffering support to
34 * ensure explicit synchronization with external trigger events
35 * (%INDIO_BUFFER_TRIGGERED).
37 * The continuous mode works according to a periodic hardware measurement
38 * process continuously pushing samples into an internal hardware FIFO (for
39 * pressure samples only). Measurement cycle completion may be signaled by a
40 * "sample ready" interrupt.
41 * Typical software sequence of operations :
42 * - get device out of low power mode,
43 * - setup hardware sampling period,
44 * - at end of period, upon data ready interrupt: pop pressure samples out of
45 * hardware FIFO and fetch temperature sample
46 * - when no longer needed, stop sampling process by putting device into
48 * This mode is used to implement %INDIO_BUFFER_TRIGGERED mode if device tree
49 * declares a valid interrupt line. In this case, the internal hardware trigger
52 * Note that hardware sampling frequency is taken into account only when
53 * internal hardware trigger is attached as the highest sampling rate seems to
54 * be the most energy efficient.
57 * preset pressure threshold crossing / IIO events ;
58 * differential pressure sampling ;
59 * hardware samples averaging.
62 #include <linux/module.h>
63 #include <linux/kernel.h>
64 #include <linux/delay.h>
65 #include <linux/interrupt.h>
66 #include <linux/regulator/consumer.h>
67 #include <linux/pm_runtime.h>
68 #include <linux/regmap.h>
69 #include <linux/iio/iio.h>
70 #include <linux/iio/sysfs.h>
71 #include <linux/iio/buffer.h>
72 #include <linux/iio/trigger.h>
73 #include <linux/iio/trigger_consumer.h>
74 #include <linux/iio/triggered_buffer.h>
77 /* 200 ms should be enough for the longest conversion time in one-shot mode. */
78 #define ZPA2326_CONVERSION_JIFFIES (HZ / 5)
80 /* There should be a 1 ms delay (Tpup) after getting out of reset. */
81 #define ZPA2326_TPUP_USEC_MIN (1000)
82 #define ZPA2326_TPUP_USEC_MAX (2000)
85 * struct zpa2326_frequency - Hardware sampling frequency descriptor
86 * @hz : Frequency in Hertz.
87 * @odr: Output Data Rate word as expected by %ZPA2326_CTRL_REG3_REG.
89 struct zpa2326_frequency
{
95 * Keep these in strict ascending order: last array entry is expected to
96 * correspond to the highest sampling frequency.
98 static const struct zpa2326_frequency zpa2326_sampling_frequencies
[] = {
99 { .hz
= 1, .odr
= 1 << ZPA2326_CTRL_REG3_ODR_SHIFT
},
100 { .hz
= 5, .odr
= 5 << ZPA2326_CTRL_REG3_ODR_SHIFT
},
101 { .hz
= 11, .odr
= 6 << ZPA2326_CTRL_REG3_ODR_SHIFT
},
102 { .hz
= 23, .odr
= 7 << ZPA2326_CTRL_REG3_ODR_SHIFT
},
105 /* Return the highest hardware sampling frequency available. */
106 static const struct zpa2326_frequency
*zpa2326_highest_frequency(void)
108 return &zpa2326_sampling_frequencies
[
109 ARRAY_SIZE(zpa2326_sampling_frequencies
) - 1];
113 * struct zpa_private - Per-device internal private state
114 * @timestamp: Buffered samples ready datum.
115 * @regmap: Underlying I2C / SPI bus adapter used to abstract slave register
117 * @result: Allows sampling logic to get completion status of operations
118 * that interrupt handlers perform asynchronously.
119 * @data_ready: Interrupt handler uses this to wake user context up at sampling
120 * operation completion.
121 * @trigger: Optional hardware / interrupt driven trigger used to notify
122 * external devices a new sample is ready.
123 * @waken: Flag indicating whether or not device has just been powered on.
124 * @irq: Optional interrupt line: negative or zero if not declared into
125 * DT, in which case sampling logic keeps polling status register
126 * to detect completion.
127 * @frequency: Current hardware sampling frequency.
128 * @vref: Power / voltage reference.
129 * @vdd: Power supply.
131 struct zpa2326_private
{
133 struct regmap
*regmap
;
135 struct completion data_ready
;
136 struct iio_trigger
*trigger
;
139 const struct zpa2326_frequency
*frequency
;
140 struct regulator
*vref
;
141 struct regulator
*vdd
;
144 #define zpa2326_err(_idev, _format, _arg...) \
145 dev_err(_idev->dev.parent, _format, ##_arg)
147 #define zpa2326_warn(_idev, _format, _arg...) \
148 dev_warn(_idev->dev.parent, _format, ##_arg)
151 #define zpa2326_dbg(_idev, _format, _arg...) \
152 dev_dbg(_idev->dev.parent, _format, ##_arg)
154 #define zpa2326_dbg(_idev, _format, _arg...)
157 bool zpa2326_isreg_writeable(struct device
*dev
, unsigned int reg
)
160 case ZPA2326_REF_P_XL_REG
:
161 case ZPA2326_REF_P_L_REG
:
162 case ZPA2326_REF_P_H_REG
:
163 case ZPA2326_RES_CONF_REG
:
164 case ZPA2326_CTRL_REG0_REG
:
165 case ZPA2326_CTRL_REG1_REG
:
166 case ZPA2326_CTRL_REG2_REG
:
167 case ZPA2326_CTRL_REG3_REG
:
168 case ZPA2326_THS_P_LOW_REG
:
169 case ZPA2326_THS_P_HIGH_REG
:
176 EXPORT_SYMBOL_GPL(zpa2326_isreg_writeable
);
178 bool zpa2326_isreg_readable(struct device
*dev
, unsigned int reg
)
181 case ZPA2326_REF_P_XL_REG
:
182 case ZPA2326_REF_P_L_REG
:
183 case ZPA2326_REF_P_H_REG
:
184 case ZPA2326_DEVICE_ID_REG
:
185 case ZPA2326_RES_CONF_REG
:
186 case ZPA2326_CTRL_REG0_REG
:
187 case ZPA2326_CTRL_REG1_REG
:
188 case ZPA2326_CTRL_REG2_REG
:
189 case ZPA2326_CTRL_REG3_REG
:
190 case ZPA2326_INT_SOURCE_REG
:
191 case ZPA2326_THS_P_LOW_REG
:
192 case ZPA2326_THS_P_HIGH_REG
:
193 case ZPA2326_STATUS_REG
:
194 case ZPA2326_PRESS_OUT_XL_REG
:
195 case ZPA2326_PRESS_OUT_L_REG
:
196 case ZPA2326_PRESS_OUT_H_REG
:
197 case ZPA2326_TEMP_OUT_L_REG
:
198 case ZPA2326_TEMP_OUT_H_REG
:
205 EXPORT_SYMBOL_GPL(zpa2326_isreg_readable
);
207 bool zpa2326_isreg_precious(struct device
*dev
, unsigned int reg
)
210 case ZPA2326_INT_SOURCE_REG
:
211 case ZPA2326_PRESS_OUT_H_REG
:
218 EXPORT_SYMBOL_GPL(zpa2326_isreg_precious
);
221 * zpa2326_enable_device() - Enable device, i.e. get out of low power mode.
222 * @indio_dev: The IIO device associated with the hardware to enable.
224 * Required to access complete register space and to perform any sampling
225 * or control operations.
227 * Return: Zero when successful, a negative error code otherwise.
229 static int zpa2326_enable_device(const struct iio_dev
*indio_dev
)
233 err
= regmap_write(((struct zpa2326_private
*)
234 iio_priv(indio_dev
))->regmap
,
235 ZPA2326_CTRL_REG0_REG
, ZPA2326_CTRL_REG0_ENABLE
);
237 zpa2326_err(indio_dev
, "failed to enable device (%d)", err
);
241 zpa2326_dbg(indio_dev
, "enabled");
247 * zpa2326_sleep() - Disable device, i.e. switch to low power mode.
248 * @indio_dev: The IIO device associated with the hardware to disable.
250 * Only %ZPA2326_DEVICE_ID_REG and %ZPA2326_CTRL_REG0_REG registers may be
251 * accessed once device is in the disabled state.
253 * Return: Zero when successful, a negative error code otherwise.
255 static int zpa2326_sleep(const struct iio_dev
*indio_dev
)
259 err
= regmap_write(((struct zpa2326_private
*)
260 iio_priv(indio_dev
))->regmap
,
261 ZPA2326_CTRL_REG0_REG
, 0);
263 zpa2326_err(indio_dev
, "failed to sleep (%d)", err
);
267 zpa2326_dbg(indio_dev
, "sleeping");
273 * zpa2326_reset_device() - Reset device to default hardware state.
274 * @indio_dev: The IIO device associated with the hardware to reset.
276 * Disable sampling and empty hardware FIFO.
277 * Device must be enabled before reset, i.e. not in low power mode.
279 * Return: Zero when successful, a negative error code otherwise.
281 static int zpa2326_reset_device(const struct iio_dev
*indio_dev
)
285 err
= regmap_write(((struct zpa2326_private
*)
286 iio_priv(indio_dev
))->regmap
,
287 ZPA2326_CTRL_REG2_REG
, ZPA2326_CTRL_REG2_SWRESET
);
289 zpa2326_err(indio_dev
, "failed to reset device (%d)", err
);
293 usleep_range(ZPA2326_TPUP_USEC_MIN
, ZPA2326_TPUP_USEC_MAX
);
295 zpa2326_dbg(indio_dev
, "reset");
301 * zpa2326_start_oneshot() - Start a single sampling cycle, i.e. in one shot
303 * @indio_dev: The IIO device associated with the sampling hardware.
305 * Device must have been previously enabled and configured for one shot mode.
306 * Device will be switched back to low power mode at end of cycle.
308 * Return: Zero when successful, a negative error code otherwise.
310 static int zpa2326_start_oneshot(const struct iio_dev
*indio_dev
)
314 err
= regmap_write(((struct zpa2326_private
*)
315 iio_priv(indio_dev
))->regmap
,
316 ZPA2326_CTRL_REG0_REG
,
317 ZPA2326_CTRL_REG0_ENABLE
|
318 ZPA2326_CTRL_REG0_ONE_SHOT
);
320 zpa2326_err(indio_dev
, "failed to start one shot cycle (%d)",
325 zpa2326_dbg(indio_dev
, "one shot cycle started");
331 * zpa2326_power_on() - Power on device to allow subsequent configuration.
332 * @indio_dev: The IIO device associated with the sampling hardware.
333 * @private: Internal private state related to @indio_dev.
335 * Sampling will be disabled, preventing strange things from happening in our
336 * back. Hardware FIFO content will be cleared.
337 * When successful, device will be left in the enabled state to allow further
340 * Return: Zero when successful, a negative error code otherwise.
342 static int zpa2326_power_on(const struct iio_dev
*indio_dev
,
343 const struct zpa2326_private
*private)
347 err
= regulator_enable(private->vref
);
351 err
= regulator_enable(private->vdd
);
355 zpa2326_dbg(indio_dev
, "powered on");
357 err
= zpa2326_enable_device(indio_dev
);
361 err
= zpa2326_reset_device(indio_dev
);
368 zpa2326_sleep(indio_dev
);
370 regulator_disable(private->vdd
);
372 regulator_disable(private->vref
);
374 zpa2326_dbg(indio_dev
, "powered off");
380 * zpa2326_power_off() - Power off device, i.e. disable attached power
382 * @indio_dev: The IIO device associated with the sampling hardware.
383 * @private: Internal private state related to @indio_dev.
385 * Return: Zero when successful, a negative error code otherwise.
387 static void zpa2326_power_off(const struct iio_dev
*indio_dev
,
388 const struct zpa2326_private
*private)
390 regulator_disable(private->vdd
);
391 regulator_disable(private->vref
);
393 zpa2326_dbg(indio_dev
, "powered off");
397 * zpa2326_config_oneshot() - Setup device for one shot / on demand mode.
398 * @indio_dev: The IIO device associated with the sampling hardware.
399 * @irq: Optional interrupt line the hardware uses to notify new data
400 * samples are ready. Negative or zero values indicate no interrupts
401 * are available, meaning polling is required.
403 * Output Data Rate is configured for the highest possible rate so that
404 * conversion time and power consumption are reduced to a minimum.
405 * Note that hardware internal averaging machinery (not implemented in this
406 * driver) is not applicable in this mode.
408 * Device must have been previously enabled before calling
409 * zpa2326_config_oneshot().
411 * Return: Zero when successful, a negative error code otherwise.
413 static int zpa2326_config_oneshot(const struct iio_dev
*indio_dev
,
416 struct regmap
*regs
= ((struct zpa2326_private
*)
417 iio_priv(indio_dev
))->regmap
;
418 const struct zpa2326_frequency
*freq
= zpa2326_highest_frequency();
421 /* Setup highest available Output Data Rate for one shot mode. */
422 err
= regmap_write(regs
, ZPA2326_CTRL_REG3_REG
, freq
->odr
);
427 /* Request interrupt when new sample is available. */
428 err
= regmap_write(regs
, ZPA2326_CTRL_REG1_REG
,
429 (u8
)~ZPA2326_CTRL_REG1_MASK_DATA_READY
);
432 dev_err(indio_dev
->dev
.parent
,
433 "failed to setup one shot mode (%d)", err
);
438 zpa2326_dbg(indio_dev
, "one shot mode setup @%dHz", freq
->hz
);
444 * zpa2326_clear_fifo() - Clear remaining entries in hardware FIFO.
445 * @indio_dev: The IIO device associated with the sampling hardware.
446 * @min_count: Number of samples present within hardware FIFO.
448 * @min_count argument is a hint corresponding to the known minimum number of
449 * samples currently living in the FIFO. This allows to reduce the number of bus
450 * accesses by skipping status register read operation as long as we know for
451 * sure there are still entries left.
453 * Return: Zero when successful, a negative error code otherwise.
455 static int zpa2326_clear_fifo(const struct iio_dev
*indio_dev
,
456 unsigned int min_count
)
458 struct regmap
*regs
= ((struct zpa2326_private
*)
459 iio_priv(indio_dev
))->regmap
;
465 * No hint: read status register to determine whether FIFO is
468 err
= regmap_read(regs
, ZPA2326_STATUS_REG
, &val
);
473 if (val
& ZPA2326_STATUS_FIFO_E
)
474 /* Fifo is empty: nothing to trash. */
481 * A single fetch from pressure MSB register is enough to pop
482 * values out of FIFO.
484 err
= regmap_read(regs
, ZPA2326_PRESS_OUT_H_REG
, &val
);
490 * We know for sure there are at least min_count entries
491 * left in FIFO. Skip status register read.
497 err
= regmap_read(regs
, ZPA2326_STATUS_REG
, &val
);
501 } while (!(val
& ZPA2326_STATUS_FIFO_E
));
503 zpa2326_dbg(indio_dev
, "FIFO cleared");
508 zpa2326_err(indio_dev
, "failed to clear FIFO (%d)", err
);
514 * zpa2326_dequeue_pressure() - Retrieve the most recent pressure sample from
516 * @indio_dev: The IIO device associated with the sampling hardware.
517 * @pressure: Sampled pressure output.
519 * Note that ZPA2326 hardware FIFO stores pressure samples only.
521 * Return: Zero when successful, a negative error code otherwise.
523 static int zpa2326_dequeue_pressure(const struct iio_dev
*indio_dev
,
526 struct regmap
*regs
= ((struct zpa2326_private
*)
527 iio_priv(indio_dev
))->regmap
;
532 err
= regmap_read(regs
, ZPA2326_STATUS_REG
, &val
);
538 if (val
& ZPA2326_STATUS_P_OR
) {
540 * Fifo overrun : first sample dequeued from FIFO is the
543 zpa2326_warn(indio_dev
, "FIFO overflow");
545 err
= regmap_bulk_read(regs
, ZPA2326_PRESS_OUT_XL_REG
, pressure
,
550 #define ZPA2326_FIFO_DEPTH (16U)
551 /* Hardware FIFO may hold no more than 16 pressure samples. */
552 return zpa2326_clear_fifo(indio_dev
, ZPA2326_FIFO_DEPTH
- 1);
556 * Fifo has not overflown : retrieve newest sample. We need to pop
557 * values out until FIFO is empty : last fetched pressure is the newest.
558 * In nominal cases, we should find a single queued sample only.
561 err
= regmap_bulk_read(regs
, ZPA2326_PRESS_OUT_XL_REG
, pressure
,
566 err
= regmap_read(regs
, ZPA2326_STATUS_REG
, &val
);
571 } while (!(val
& ZPA2326_STATUS_FIFO_E
));
575 * Samples were pushed by hardware during previous rounds but we
576 * didn't consume them fast enough: inform user.
578 zpa2326_dbg(indio_dev
, "cleared %d FIFO entries", cleared
);
584 * zpa2326_fill_sample_buffer() - Enqueue new channel samples to IIO buffer.
585 * @indio_dev: The IIO device associated with the sampling hardware.
586 * @private: Internal private state related to @indio_dev.
588 * Return: Zero when successful, a negative error code otherwise.
590 static int zpa2326_fill_sample_buffer(struct iio_dev
*indio_dev
,
591 const struct zpa2326_private
*private)
600 if (test_bit(0, indio_dev
->active_scan_mask
)) {
601 /* Get current pressure from hardware FIFO. */
602 err
= zpa2326_dequeue_pressure(indio_dev
, &sample
.pressure
);
604 zpa2326_warn(indio_dev
, "failed to fetch pressure (%d)",
610 if (test_bit(1, indio_dev
->active_scan_mask
)) {
611 /* Get current temperature. */
612 err
= regmap_bulk_read(private->regmap
, ZPA2326_TEMP_OUT_L_REG
,
613 &sample
.temperature
, 2);
615 zpa2326_warn(indio_dev
,
616 "failed to fetch temperature (%d)", err
);
622 * Now push samples using timestamp stored either :
623 * - by hardware interrupt handler if interrupt is available: see
624 * zpa2326_handle_irq(),
625 * - or oneshot completion polling machinery : see
626 * zpa2326_trigger_handler().
628 zpa2326_dbg(indio_dev
, "filling raw samples buffer");
630 iio_push_to_buffers_with_timestamp(indio_dev
, &sample
,
637 static int zpa2326_runtime_suspend(struct device
*parent
)
639 const struct iio_dev
*indio_dev
= dev_get_drvdata(parent
);
641 if (pm_runtime_autosuspend_expiration(parent
))
642 /* Userspace changed autosuspend delay. */
645 zpa2326_power_off(indio_dev
, iio_priv(indio_dev
));
650 static int zpa2326_runtime_resume(struct device
*parent
)
652 const struct iio_dev
*indio_dev
= dev_get_drvdata(parent
);
654 return zpa2326_power_on(indio_dev
, iio_priv(indio_dev
));
657 const struct dev_pm_ops zpa2326_pm_ops
= {
658 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend
,
659 pm_runtime_force_resume
)
660 SET_RUNTIME_PM_OPS(zpa2326_runtime_suspend
, zpa2326_runtime_resume
,
663 EXPORT_SYMBOL_GPL(zpa2326_pm_ops
);
666 * zpa2326_resume() - Request the PM layer to power supply the device.
667 * @indio_dev: The IIO device associated with the sampling hardware.
670 * < 0 - a negative error code meaning failure ;
671 * 0 - success, device has just been powered up ;
672 * 1 - success, device was already powered.
674 static int zpa2326_resume(const struct iio_dev
*indio_dev
)
678 err
= pm_runtime_get_sync(indio_dev
->dev
.parent
);
684 * Device was already power supplied: get it out of low power
685 * mode and inform caller.
687 zpa2326_enable_device(indio_dev
);
691 /* Inform caller device has just been brought back to life. */
696 * zpa2326_suspend() - Schedule a power down using autosuspend feature of PM
698 * @indio_dev: The IIO device associated with the sampling hardware.
700 * Device is switched to low power mode at first to save power even when
701 * attached regulator is a "dummy" one.
703 static void zpa2326_suspend(struct iio_dev
*indio_dev
)
705 struct device
*parent
= indio_dev
->dev
.parent
;
707 zpa2326_sleep(indio_dev
);
709 pm_runtime_mark_last_busy(parent
);
710 pm_runtime_put_autosuspend(parent
);
713 static void zpa2326_init_runtime(struct device
*parent
)
715 pm_runtime_get_noresume(parent
);
716 pm_runtime_set_active(parent
);
717 pm_runtime_enable(parent
);
718 pm_runtime_set_autosuspend_delay(parent
, 1000);
719 pm_runtime_use_autosuspend(parent
);
720 pm_runtime_mark_last_busy(parent
);
721 pm_runtime_put_autosuspend(parent
);
724 static void zpa2326_fini_runtime(struct device
*parent
)
726 pm_runtime_disable(parent
);
727 pm_runtime_set_suspended(parent
);
729 #else /* !CONFIG_PM */
730 static int zpa2326_resume(const struct iio_dev
*indio_dev
)
732 zpa2326_enable_device(indio_dev
);
737 static void zpa2326_suspend(struct iio_dev
*indio_dev
)
739 zpa2326_sleep(indio_dev
);
742 #define zpa2326_init_runtime(_parent)
743 #define zpa2326_fini_runtime(_parent)
744 #endif /* !CONFIG_PM */
747 * zpa2326_handle_irq() - Process hardware interrupts.
748 * @irq: Interrupt line the hardware uses to notify new data has arrived.
749 * @data: The IIO device associated with the sampling hardware.
751 * Timestamp buffered samples as soon as possible then schedule threaded bottom
754 * Return: Always successful.
756 static irqreturn_t
zpa2326_handle_irq(int irq
, void *data
)
758 struct iio_dev
*indio_dev
= (struct iio_dev
*)data
;
760 if (iio_buffer_enabled(indio_dev
)) {
761 /* Timestamping needed for buffered sampling only. */
762 ((struct zpa2326_private
*)
763 iio_priv(indio_dev
))->timestamp
= iio_get_time_ns(indio_dev
);
766 return IRQ_WAKE_THREAD
;
770 * zpa2326_handle_threaded_irq() - Interrupt bottom-half handler.
771 * @irq: Interrupt line the hardware uses to notify new data has arrived.
772 * @data: The IIO device associated with the sampling hardware.
774 * Mainly ensures interrupt is caused by a real "new sample available"
775 * condition. This relies upon the ability to perform blocking / sleeping bus
776 * accesses to slave's registers. This is why zpa2326_handle_threaded_irq() is
777 * called from within a thread, i.e. not called from hard interrupt context.
779 * When device is using its own internal hardware trigger in continuous sampling
780 * mode, data are available into hardware FIFO once interrupt has occurred. All
781 * we have to do is to dispatch the trigger, which in turn will fetch data and
784 * When not using its own internal hardware trigger, the device has been
785 * configured in one-shot mode either by an external trigger or the IIO read_raw
786 * hook. This means one of the latter is currently waiting for sampling
787 * completion, in which case we must simply wake it up.
789 * See zpa2326_trigger_handler().
792 * %IRQ_NONE - no consistent interrupt happened ;
793 * %IRQ_HANDLED - there was new samples available.
795 static irqreturn_t
zpa2326_handle_threaded_irq(int irq
, void *data
)
797 struct iio_dev
*indio_dev
= (struct iio_dev
*)data
;
798 struct zpa2326_private
*priv
= iio_priv(indio_dev
);
801 irqreturn_t ret
= IRQ_NONE
;
804 * Are we using our own internal trigger in triggered buffer mode, i.e.,
805 * currently working in continuous sampling mode ?
807 cont
= (iio_buffer_enabled(indio_dev
) &&
808 iio_trigger_using_own(indio_dev
));
811 * Device works according to a level interrupt scheme: reading interrupt
812 * status de-asserts interrupt line.
814 priv
->result
= regmap_read(priv
->regmap
, ZPA2326_INT_SOURCE_REG
, &val
);
815 if (priv
->result
< 0) {
822 /* Data ready is the only interrupt source we requested. */
823 if (!(val
& ZPA2326_INT_SOURCE_DATA_READY
)) {
825 * Interrupt happened but no new sample available: likely caused
826 * by spurious interrupts, in which case, returning IRQ_NONE
827 * allows to benefit from the generic spurious interrupts
830 zpa2326_warn(indio_dev
, "unexpected interrupt status %02x",
836 priv
->result
= -ENODATA
;
840 /* New sample available: dispatch internal trigger consumers. */
841 iio_trigger_poll_chained(priv
->trigger
);
845 * Internal hardware trigger has been scheduled above : it will
846 * fetch data on its own.
854 * Wake up direct or externaly triggered buffer mode waiters: see
855 * zpa2326_sample_oneshot() and zpa2326_trigger_handler().
857 complete(&priv
->data_ready
);
863 * zpa2326_wait_oneshot_completion() - Wait for oneshot data ready interrupt.
864 * @indio_dev: The IIO device associated with the sampling hardware.
865 * @private: Internal private state related to @indio_dev.
867 * Return: Zero when successful, a negative error code otherwise.
869 static int zpa2326_wait_oneshot_completion(const struct iio_dev
*indio_dev
,
870 struct zpa2326_private
*private)
876 zpa2326_dbg(indio_dev
, "waiting for one shot completion interrupt");
878 timeout
= wait_for_completion_interruptible_timeout(
879 &private->data_ready
, ZPA2326_CONVERSION_JIFFIES
);
882 * Interrupt handler completed before timeout: return operation
885 return private->result
;
887 /* Clear all interrupts just to be sure. */
888 regmap_read(private->regmap
, ZPA2326_INT_SOURCE_REG
, &val
);
892 zpa2326_warn(indio_dev
, "no one shot interrupt occurred (%ld)",
895 } else if (timeout
< 0) {
896 zpa2326_warn(indio_dev
,
897 "wait for one shot interrupt cancelled");
904 static int zpa2326_init_managed_irq(struct device
*parent
,
905 struct iio_dev
*indio_dev
,
906 struct zpa2326_private
*private,
915 * Platform declared no interrupt line: device will be polled
916 * for data availability.
918 dev_info(parent
, "no interrupt found, running in polling mode");
922 init_completion(&private->data_ready
);
924 /* Request handler to be scheduled into threaded interrupt context. */
925 err
= devm_request_threaded_irq(parent
, irq
, zpa2326_handle_irq
,
926 zpa2326_handle_threaded_irq
,
927 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
928 dev_name(parent
), indio_dev
);
930 dev_err(parent
, "failed to request interrupt %d (%d)", irq
,
935 dev_info(parent
, "using interrupt %d", irq
);
941 * zpa2326_poll_oneshot_completion() - Actively poll for one shot data ready.
942 * @indio_dev: The IIO device associated with the sampling hardware.
944 * Loop over registers content to detect end of sampling cycle. Used when DT
945 * declared no valid interrupt lines.
947 * Return: Zero when successful, a negative error code otherwise.
949 static int zpa2326_poll_oneshot_completion(const struct iio_dev
*indio_dev
)
951 unsigned long tmout
= jiffies
+ ZPA2326_CONVERSION_JIFFIES
;
952 struct regmap
*regs
= ((struct zpa2326_private
*)
953 iio_priv(indio_dev
))->regmap
;
957 zpa2326_dbg(indio_dev
, "polling for one shot completion");
960 * At least, 100 ms is needed for the device to complete its one-shot
963 if (msleep_interruptible(100))
966 /* Poll for conversion completion in hardware. */
968 err
= regmap_read(regs
, ZPA2326_CTRL_REG0_REG
, &val
);
972 if (!(val
& ZPA2326_CTRL_REG0_ONE_SHOT
))
973 /* One-shot bit self clears at conversion end. */
976 if (time_after(jiffies
, tmout
)) {
977 /* Prevent from waiting forever : let's time out. */
982 usleep_range(10000, 20000);
986 * In oneshot mode, pressure sample availability guarantees that
987 * temperature conversion has also completed : just check pressure
988 * status bit to keep things simple.
990 err
= regmap_read(regs
, ZPA2326_STATUS_REG
, &val
);
994 if (!(val
& ZPA2326_STATUS_P_DA
)) {
995 /* No sample available. */
1003 zpa2326_warn(indio_dev
, "failed to poll one shot completion (%d)", err
);
1009 * zpa2326_fetch_raw_sample() - Retrieve a raw sample and convert it to CPU
1011 * @indio_dev: The IIO device associated with the sampling hardware.
1012 * @type: Type of measurement / channel to fetch from.
1013 * @value: Sample output.
1015 * Return: Zero when successful, a negative error code otherwise.
1017 static int zpa2326_fetch_raw_sample(const struct iio_dev
*indio_dev
,
1018 enum iio_chan_type type
,
1021 struct regmap
*regs
= ((struct zpa2326_private
*)
1022 iio_priv(indio_dev
))->regmap
;
1027 zpa2326_dbg(indio_dev
, "fetching raw pressure sample");
1029 err
= regmap_bulk_read(regs
, ZPA2326_PRESS_OUT_XL_REG
, value
,
1032 zpa2326_warn(indio_dev
, "failed to fetch pressure (%d)",
1037 /* Pressure is a 24 bits wide little-endian unsigned int. */
1038 *value
= (((u8
*)value
)[2] << 16) | (((u8
*)value
)[1] << 8) |
1044 zpa2326_dbg(indio_dev
, "fetching raw temperature sample");
1046 err
= regmap_bulk_read(regs
, ZPA2326_TEMP_OUT_L_REG
, value
, 2);
1048 zpa2326_warn(indio_dev
,
1049 "failed to fetch temperature (%d)", err
);
1053 /* Temperature is a 16 bits wide little-endian signed int. */
1054 *value
= (int)le16_to_cpup((__le16
*)value
);
1064 * zpa2326_sample_oneshot() - Perform a complete one shot sampling cycle.
1065 * @indio_dev: The IIO device associated with the sampling hardware.
1066 * @type: Type of measurement / channel to fetch from.
1067 * @value: Sample output.
1069 * Return: Zero when successful, a negative error code otherwise.
1071 static int zpa2326_sample_oneshot(struct iio_dev
*indio_dev
,
1072 enum iio_chan_type type
,
1076 struct zpa2326_private
*priv
;
1078 ret
= iio_device_claim_direct_mode(indio_dev
);
1082 ret
= zpa2326_resume(indio_dev
);
1086 priv
= iio_priv(indio_dev
);
1090 * We were already power supplied. Just clear hardware FIFO to
1091 * get rid of samples acquired during previous rounds (if any).
1092 * Sampling operation always generates both temperature and
1093 * pressure samples. The latter are always enqueued into
1094 * hardware FIFO. This may lead to situations were pressure
1095 * samples still sit into FIFO when previous cycle(s) fetched
1096 * temperature data only.
1097 * Hence, we need to clear hardware FIFO content to prevent from
1098 * getting outdated values at the end of current cycle.
1100 if (type
== IIO_PRESSURE
) {
1101 ret
= zpa2326_clear_fifo(indio_dev
, 0);
1107 * We have just been power supplied, i.e. device is in default
1108 * "out of reset" state, meaning we need to reconfigure it
1111 ret
= zpa2326_config_oneshot(indio_dev
, priv
->irq
);
1116 /* Start a sampling cycle in oneshot mode. */
1117 ret
= zpa2326_start_oneshot(indio_dev
);
1121 /* Wait for sampling cycle to complete. */
1123 ret
= zpa2326_wait_oneshot_completion(indio_dev
, priv
);
1125 ret
= zpa2326_poll_oneshot_completion(indio_dev
);
1130 /* Retrieve raw sample value and convert it to CPU endianness. */
1131 ret
= zpa2326_fetch_raw_sample(indio_dev
, type
, value
);
1134 zpa2326_suspend(indio_dev
);
1136 iio_device_release_direct_mode(indio_dev
);
1142 * zpa2326_trigger_handler() - Perform an IIO buffered sampling round in one
1144 * @irq: The software interrupt assigned to @data
1145 * @data: The IIO poll function dispatched by external trigger our device is
1148 * Bottom-half handler called by the IIO trigger to which our device is
1149 * currently attached. Allows us to synchronize this device buffered sampling
1150 * either with external events (such as timer expiration, external device sample
1151 * ready, etc...) or with its own interrupt (internal hardware trigger).
1153 * When using an external trigger, basically run the same sequence of operations
1154 * as for zpa2326_sample_oneshot() with the following hereafter. Hardware FIFO
1155 * is not cleared since already done at buffering enable time and samples
1156 * dequeueing always retrieves the most recent value.
1158 * Otherwise, when internal hardware trigger has dispatched us, just fetch data
1159 * from hardware FIFO.
1161 * Fetched data will pushed unprocessed to IIO buffer since samples conversion
1162 * is delegated to userspace in buffered mode (endianness, etc...).
1165 * %IRQ_NONE - no consistent interrupt happened ;
1166 * %IRQ_HANDLED - there was new samples available.
1168 static irqreturn_t
zpa2326_trigger_handler(int irq
, void *data
)
1170 struct iio_dev
*indio_dev
= ((struct iio_poll_func
*)
1172 struct zpa2326_private
*priv
= iio_priv(indio_dev
);
1176 * We have been dispatched, meaning we are in triggered buffer mode.
1177 * Using our own internal trigger implies we are currently in continuous
1178 * hardware sampling mode.
1180 cont
= iio_trigger_using_own(indio_dev
);
1183 /* On demand sampling : start a one shot cycle. */
1184 if (zpa2326_start_oneshot(indio_dev
))
1187 /* Wait for sampling cycle to complete. */
1188 if (priv
->irq
<= 0) {
1189 /* No interrupt available: poll for completion. */
1190 if (zpa2326_poll_oneshot_completion(indio_dev
))
1193 /* Only timestamp sample once it is ready. */
1194 priv
->timestamp
= iio_get_time_ns(indio_dev
);
1196 /* Interrupt handlers will timestamp for us. */
1197 if (zpa2326_wait_oneshot_completion(indio_dev
, priv
))
1202 /* Enqueue to IIO buffer / userspace. */
1203 zpa2326_fill_sample_buffer(indio_dev
, priv
);
1207 /* Don't switch to low power if sampling continuously. */
1208 zpa2326_sleep(indio_dev
);
1210 /* Inform attached trigger we are done. */
1211 iio_trigger_notify_done(indio_dev
->trig
);
1217 * zpa2326_preenable_buffer() - Prepare device for configuring triggered
1220 * @indio_dev: The IIO device associated with the sampling hardware.
1222 * Basically power up device.
1223 * Called with IIO device's lock held.
1225 * Return: Zero when successful, a negative error code otherwise.
1227 static int zpa2326_preenable_buffer(struct iio_dev
*indio_dev
)
1229 int ret
= zpa2326_resume(indio_dev
);
1234 /* Tell zpa2326_postenable_buffer() if we have just been powered on. */
1235 ((struct zpa2326_private
*)
1236 iio_priv(indio_dev
))->waken
= iio_priv(indio_dev
);
1242 * zpa2326_postenable_buffer() - Configure device for triggered sampling.
1243 * @indio_dev: The IIO device associated with the sampling hardware.
1245 * Basically setup one-shot mode if plugging external trigger.
1246 * Otherwise, let internal trigger configure continuous sampling :
1247 * see zpa2326_set_trigger_state().
1249 * If an error is returned, IIO layer will call our postdisable hook for us,
1250 * i.e. no need to explicitly power device off here.
1251 * Called with IIO device's lock held.
1253 * Called with IIO device's lock held.
1255 * Return: Zero when successful, a negative error code otherwise.
1257 static int zpa2326_postenable_buffer(struct iio_dev
*indio_dev
)
1259 const struct zpa2326_private
*priv
= iio_priv(indio_dev
);
1264 * We were already power supplied. Just clear hardware FIFO to
1265 * get rid of samples acquired during previous rounds (if any).
1267 err
= zpa2326_clear_fifo(indio_dev
, 0);
1272 if (!iio_trigger_using_own(indio_dev
) && priv
->waken
) {
1274 * We are using an external trigger and we have just been
1275 * powered up: reconfigure one-shot mode.
1277 err
= zpa2326_config_oneshot(indio_dev
, priv
->irq
);
1282 /* Plug our own trigger event handler. */
1283 err
= iio_triggered_buffer_postenable(indio_dev
);
1290 zpa2326_err(indio_dev
, "failed to enable buffering (%d)", err
);
1295 static int zpa2326_postdisable_buffer(struct iio_dev
*indio_dev
)
1297 zpa2326_suspend(indio_dev
);
1302 static const struct iio_buffer_setup_ops zpa2326_buffer_setup_ops
= {
1303 .preenable
= zpa2326_preenable_buffer
,
1304 .postenable
= zpa2326_postenable_buffer
,
1305 .predisable
= iio_triggered_buffer_predisable
,
1306 .postdisable
= zpa2326_postdisable_buffer
1310 * zpa2326_set_trigger_state() - Start / stop continuous sampling.
1311 * @trig: The trigger being attached to IIO device associated with the sampling
1313 * @state: Tell whether to start (true) or stop (false)
1315 * Basically enable / disable hardware continuous sampling mode.
1317 * Called with IIO device's lock held at postenable() or predisable() time.
1319 * Return: Zero when successful, a negative error code otherwise.
1321 static int zpa2326_set_trigger_state(struct iio_trigger
*trig
, bool state
)
1323 const struct iio_dev
*indio_dev
= dev_get_drvdata(
1325 const struct zpa2326_private
*priv
= iio_priv(indio_dev
);
1330 * Switch trigger off : in case of failure, interrupt is left
1331 * disabled in order to prevent handler from accessing released
1337 * As device is working in continuous mode, handlers may be
1338 * accessing resources we are currently freeing...
1339 * Prevent this by disabling interrupt handlers and ensure
1340 * the device will generate no more interrupts unless explicitly
1341 * required to, i.e. by restoring back to default one shot mode.
1343 disable_irq(priv
->irq
);
1346 * Disable continuous sampling mode to restore settings for
1347 * one shot / direct sampling operations.
1349 err
= regmap_write(priv
->regmap
, ZPA2326_CTRL_REG3_REG
,
1350 zpa2326_highest_frequency()->odr
);
1355 * Now that device won't generate interrupts on its own,
1356 * acknowledge any currently active interrupts (may happen on
1357 * rare occasions while stopping continuous mode).
1359 err
= regmap_read(priv
->regmap
, ZPA2326_INT_SOURCE_REG
, &val
);
1364 * Re-enable interrupts only if we can guarantee the device will
1365 * generate no more interrupts to prevent handlers from
1366 * accessing released resources.
1368 enable_irq(priv
->irq
);
1370 zpa2326_dbg(indio_dev
, "continuous mode stopped");
1373 * Switch trigger on : start continuous sampling at required
1378 /* Enable interrupt if getting out of reset. */
1379 err
= regmap_write(priv
->regmap
, ZPA2326_CTRL_REG1_REG
,
1381 ~ZPA2326_CTRL_REG1_MASK_DATA_READY
);
1386 /* Enable continuous sampling at specified frequency. */
1387 err
= regmap_write(priv
->regmap
, ZPA2326_CTRL_REG3_REG
,
1388 ZPA2326_CTRL_REG3_ENABLE_MEAS
|
1389 priv
->frequency
->odr
);
1393 zpa2326_dbg(indio_dev
, "continuous mode setup @%dHz",
1394 priv
->frequency
->hz
);
1400 static const struct iio_trigger_ops zpa2326_trigger_ops
= {
1401 .owner
= THIS_MODULE
,
1402 .set_trigger_state
= zpa2326_set_trigger_state
,
1406 * zpa2326_init_trigger() - Create an interrupt driven / hardware trigger
1407 * allowing to notify external devices a new sample is
1409 * @parent: Hardware sampling device @indio_dev is a child of.
1410 * @indio_dev: The IIO device associated with the sampling hardware.
1411 * @private: Internal private state related to @indio_dev.
1412 * @irq: Optional interrupt line the hardware uses to notify new data
1413 * samples are ready. Negative or zero values indicate no interrupts
1414 * are available, meaning polling is required.
1416 * Only relevant when DT declares a valid interrupt line.
1418 * Return: Zero when successful, a negative error code otherwise.
1420 static int zpa2326_init_managed_trigger(struct device
*parent
,
1421 struct iio_dev
*indio_dev
,
1422 struct zpa2326_private
*private,
1425 struct iio_trigger
*trigger
;
1431 trigger
= devm_iio_trigger_alloc(parent
, "%s-dev%d",
1432 indio_dev
->name
, indio_dev
->id
);
1437 trigger
->dev
.parent
= parent
;
1438 trigger
->ops
= &zpa2326_trigger_ops
;
1440 private->trigger
= trigger
;
1442 /* Register to triggers space. */
1443 ret
= devm_iio_trigger_register(parent
, trigger
);
1445 dev_err(parent
, "failed to register hardware trigger (%d)",
1451 static int zpa2326_get_frequency(const struct iio_dev
*indio_dev
)
1453 return ((struct zpa2326_private
*)iio_priv(indio_dev
))->frequency
->hz
;
1456 static int zpa2326_set_frequency(struct iio_dev
*indio_dev
, int hz
)
1458 struct zpa2326_private
*priv
= iio_priv(indio_dev
);
1462 /* Check if requested frequency is supported. */
1463 for (freq
= 0; freq
< ARRAY_SIZE(zpa2326_sampling_frequencies
); freq
++)
1464 if (zpa2326_sampling_frequencies
[freq
].hz
== hz
)
1466 if (freq
== ARRAY_SIZE(zpa2326_sampling_frequencies
))
1469 /* Don't allow changing frequency if buffered sampling is ongoing. */
1470 err
= iio_device_claim_direct_mode(indio_dev
);
1474 priv
->frequency
= &zpa2326_sampling_frequencies
[freq
];
1476 iio_device_release_direct_mode(indio_dev
);
1481 /* Expose supported hardware sampling frequencies (Hz) through sysfs. */
1482 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("1 5 11 23");
1484 static struct attribute
*zpa2326_attributes
[] = {
1485 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
1489 static const struct attribute_group zpa2326_attribute_group
= {
1490 .attrs
= zpa2326_attributes
,
1493 static int zpa2326_read_raw(struct iio_dev
*indio_dev
,
1494 struct iio_chan_spec
const *chan
,
1500 case IIO_CHAN_INFO_RAW
:
1501 return zpa2326_sample_oneshot(indio_dev
, chan
->type
, val
);
1503 case IIO_CHAN_INFO_SCALE
:
1504 switch (chan
->type
) {
1507 * Pressure resolution is 1/64 Pascal. Scale to kPascal
1508 * as required by IIO ABI.
1512 return IIO_VAL_FRACTIONAL
;
1516 * Temperature follows the equation:
1517 * Temp[degC] = Tempcode * 0.00649 - 176.83
1519 * Tempcode is composed the raw sampled 16 bits.
1521 * Hence, to produce a temperature in milli-degrees
1522 * Celsius according to IIO ABI, we need to apply the
1523 * following equation to raw samples:
1524 * Temp[milli degC] = (Tempcode + Offset) * Scale
1526 * Offset = -176.83 / 0.00649
1527 * Scale = 0.00649 * 1000
1531 return IIO_VAL_INT_PLUS_MICRO
;
1537 case IIO_CHAN_INFO_OFFSET
:
1538 switch (chan
->type
) {
1542 return IIO_VAL_FRACTIONAL
;
1548 case IIO_CHAN_INFO_SAMP_FREQ
:
1549 *val
= zpa2326_get_frequency(indio_dev
);
1557 static int zpa2326_write_raw(struct iio_dev
*indio_dev
,
1558 const struct iio_chan_spec
*chan
,
1563 if ((mask
!= IIO_CHAN_INFO_SAMP_FREQ
) || val2
)
1566 return zpa2326_set_frequency(indio_dev
, val
);
1569 static const struct iio_chan_spec zpa2326_channels
[] = {
1571 .type
= IIO_PRESSURE
,
1577 .endianness
= IIO_LE
,
1579 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
1580 BIT(IIO_CHAN_INFO_SCALE
),
1581 .info_mask_shared_by_all
= BIT(IIO_CHAN_INFO_SAMP_FREQ
),
1590 .endianness
= IIO_LE
,
1592 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
) |
1593 BIT(IIO_CHAN_INFO_SCALE
) |
1594 BIT(IIO_CHAN_INFO_OFFSET
),
1595 .info_mask_shared_by_all
= BIT(IIO_CHAN_INFO_SAMP_FREQ
),
1597 [2] = IIO_CHAN_SOFT_TIMESTAMP(2),
1600 static const struct iio_info zpa2326_info
= {
1601 .driver_module
= THIS_MODULE
,
1602 .attrs
= &zpa2326_attribute_group
,
1603 .read_raw
= zpa2326_read_raw
,
1604 .write_raw
= zpa2326_write_raw
,
1607 static struct iio_dev
*zpa2326_create_managed_iiodev(struct device
*device
,
1609 struct regmap
*regmap
)
1611 struct iio_dev
*indio_dev
;
1613 /* Allocate space to hold IIO device internal state. */
1614 indio_dev
= devm_iio_device_alloc(device
,
1615 sizeof(struct zpa2326_private
));
1619 /* Setup for userspace synchronous on demand sampling. */
1620 indio_dev
->modes
= INDIO_DIRECT_MODE
;
1621 indio_dev
->dev
.parent
= device
;
1622 indio_dev
->channels
= zpa2326_channels
;
1623 indio_dev
->num_channels
= ARRAY_SIZE(zpa2326_channels
);
1624 indio_dev
->name
= name
;
1625 indio_dev
->info
= &zpa2326_info
;
1630 int zpa2326_probe(struct device
*parent
,
1634 struct regmap
*regmap
)
1636 struct iio_dev
*indio_dev
;
1637 struct zpa2326_private
*priv
;
1641 indio_dev
= zpa2326_create_managed_iiodev(parent
, name
, regmap
);
1645 priv
= iio_priv(indio_dev
);
1647 priv
->vref
= devm_regulator_get(parent
, "vref");
1648 if (IS_ERR(priv
->vref
))
1649 return PTR_ERR(priv
->vref
);
1651 priv
->vdd
= devm_regulator_get(parent
, "vdd");
1652 if (IS_ERR(priv
->vdd
))
1653 return PTR_ERR(priv
->vdd
);
1655 /* Set default hardware sampling frequency to highest rate supported. */
1656 priv
->frequency
= zpa2326_highest_frequency();
1659 * Plug device's underlying bus abstraction : this MUST be set before
1660 * registering interrupt handlers since an interrupt might happen if
1661 * power up sequence is not properly applied.
1663 priv
->regmap
= regmap
;
1665 err
= devm_iio_triggered_buffer_setup(parent
, indio_dev
, NULL
,
1666 zpa2326_trigger_handler
,
1667 &zpa2326_buffer_setup_ops
);
1671 err
= zpa2326_init_managed_trigger(parent
, indio_dev
, priv
, irq
);
1675 err
= zpa2326_init_managed_irq(parent
, indio_dev
, priv
, irq
);
1679 /* Power up to check device ID and perform initial hardware setup. */
1680 err
= zpa2326_power_on(indio_dev
, priv
);
1684 /* Read id register to check we are talking to the right slave. */
1685 err
= regmap_read(regmap
, ZPA2326_DEVICE_ID_REG
, &id
);
1690 dev_err(parent
, "found device with unexpected id %02x", id
);
1695 err
= zpa2326_config_oneshot(indio_dev
, irq
);
1699 /* Setup done : go sleeping. Device will be awaken upon user request. */
1700 err
= zpa2326_sleep(indio_dev
);
1704 dev_set_drvdata(parent
, indio_dev
);
1706 zpa2326_init_runtime(parent
);
1708 err
= iio_device_register(indio_dev
);
1710 zpa2326_fini_runtime(parent
);
1717 /* Put to sleep just in case power regulators are "dummy" ones. */
1718 zpa2326_sleep(indio_dev
);
1720 zpa2326_power_off(indio_dev
, priv
);
1724 EXPORT_SYMBOL_GPL(zpa2326_probe
);
1726 void zpa2326_remove(const struct device
*parent
)
1728 struct iio_dev
*indio_dev
= dev_get_drvdata(parent
);
1730 iio_device_unregister(indio_dev
);
1731 zpa2326_fini_runtime(indio_dev
->dev
.parent
);
1732 zpa2326_sleep(indio_dev
);
1733 zpa2326_power_off(indio_dev
, iio_priv(indio_dev
));
1735 EXPORT_SYMBOL_GPL(zpa2326_remove
);
1737 MODULE_AUTHOR("Gregor Boirie <gregor.boirie@parrot.com>");
1738 MODULE_DESCRIPTION("Core driver for Murata ZPA2326 pressure sensor");
1739 MODULE_LICENSE("GPL v2");