|
@@ -17,6 +17,9 @@
|
|
|
#include <linux/iio/iio.h>
|
|
|
#include <linux/delay.h>
|
|
|
|
|
|
+#include <linux/iio/buffer.h>
|
|
|
+#include <linux/iio/triggered_buffer.h>
|
|
|
+#include <linux/iio/trigger_consumer.h>
|
|
|
#include "ms5611.h"
|
|
|
|
|
|
static bool ms5611_prom_is_valid(u16 *prom, size_t len)
|
|
@@ -173,6 +176,28 @@ static int ms5611_reset(struct iio_dev *indio_dev)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static irqreturn_t ms5611_trigger_handler(int irq, void *p)
|
|
|
+{
|
|
|
+ struct iio_poll_func *pf = p;
|
|
|
+ struct iio_dev *indio_dev = pf->indio_dev;
|
|
|
+ struct ms5611_state *st = iio_priv(indio_dev);
|
|
|
+ s32 buf[4]; /* s32 (pressure) + s32 (temp) + 2 * s32 (timestamp) */
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ mutex_lock(&st->lock);
|
|
|
+ ret = ms5611_read_temp_and_pressure(indio_dev, &buf[1], &buf[0]);
|
|
|
+ mutex_unlock(&st->lock);
|
|
|
+ if (ret < 0)
|
|
|
+ goto err;
|
|
|
+
|
|
|
+ iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
|
|
|
+
|
|
|
+err:
|
|
|
+ iio_trigger_notify_done(indio_dev->trig);
|
|
|
+
|
|
|
+ return IRQ_HANDLED;
|
|
|
+}
|
|
|
+
|
|
|
static int ms5611_read_raw(struct iio_dev *indio_dev,
|
|
|
struct iio_chan_spec const *chan,
|
|
|
int *val, int *val2, long mask)
|
|
@@ -218,6 +243,8 @@ static int ms5611_read_raw(struct iio_dev *indio_dev,
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
+static const unsigned long ms5611_scan_masks[] = {0x3, 0};
|
|
|
+
|
|
|
static struct ms5611_chip_info chip_info_tbl[] = {
|
|
|
[MS5611] = {
|
|
|
.temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate,
|
|
@@ -232,12 +259,27 @@ static const struct iio_chan_spec ms5611_channels[] = {
|
|
|
.type = IIO_PRESSURE,
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
|
|
|
BIT(IIO_CHAN_INFO_SCALE),
|
|
|
+ .scan_index = 0,
|
|
|
+ .scan_type = {
|
|
|
+ .sign = 's',
|
|
|
+ .realbits = 32,
|
|
|
+ .storagebits = 32,
|
|
|
+ .endianness = IIO_CPU,
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
.type = IIO_TEMP,
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
|
|
|
BIT(IIO_CHAN_INFO_SCALE),
|
|
|
- }
|
|
|
+ .scan_index = 1,
|
|
|
+ .scan_type = {
|
|
|
+ .sign = 's',
|
|
|
+ .realbits = 32,
|
|
|
+ .storagebits = 32,
|
|
|
+ .endianness = IIO_CPU,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ IIO_CHAN_SOFT_TIMESTAMP(2),
|
|
|
};
|
|
|
|
|
|
static const struct iio_info ms5611_info = {
|
|
@@ -269,15 +311,43 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type)
|
|
|
indio_dev->channels = ms5611_channels;
|
|
|
indio_dev->num_channels = ARRAY_SIZE(ms5611_channels);
|
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
|
+ indio_dev->available_scan_masks = ms5611_scan_masks;
|
|
|
|
|
|
ret = ms5611_init(indio_dev);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
|
|
|
- return devm_iio_device_register(dev, indio_dev);
|
|
|
+ ret = iio_triggered_buffer_setup(indio_dev, NULL,
|
|
|
+ ms5611_trigger_handler, NULL);
|
|
|
+ if (ret < 0) {
|
|
|
+ dev_err(dev, "iio triggered buffer setup failed\n");
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = iio_device_register(indio_dev);
|
|
|
+ if (ret < 0) {
|
|
|
+ dev_err(dev, "unable to register iio device\n");
|
|
|
+ goto err_buffer_cleanup;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+
|
|
|
+err_buffer_cleanup:
|
|
|
+ iio_triggered_buffer_cleanup(indio_dev);
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
EXPORT_SYMBOL(ms5611_probe);
|
|
|
|
|
|
+int ms5611_remove(struct iio_dev *indio_dev)
|
|
|
+{
|
|
|
+ iio_device_unregister(indio_dev);
|
|
|
+ iio_triggered_buffer_cleanup(indio_dev);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(ms5611_remove);
|
|
|
+
|
|
|
MODULE_AUTHOR("Tomasz Duszynski <tduszyns@gmail.com>");
|
|
|
MODULE_DESCRIPTION("MS5611 core driver");
|
|
|
MODULE_LICENSE("GPL v2");
|