Commit 6da3a6ce authored by Matt Ranostay's avatar Matt Ranostay Committed by Jonathan Cameron

iio: chemical: atlas-ezo-sensor: add support for O2 sensor

Add support for the Atlas EZO O2 chemical sensor which required
some refactoring of the driver and parsing of i2c transfer.

Sensor data is converted by the scaling value from percent to
IIO_CONCENTRATION.
Signed-off-by: default avatarMatt Ranostay <matt.ranostay@konsulko.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 4ffa22fd
...@@ -16,10 +16,11 @@ ...@@ -16,10 +16,11 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#define ATLAS_EZO_DRV_NAME "atlas-ezo-sensor" #define ATLAS_EZO_DRV_NAME "atlas-ezo-sensor"
#define ATLAS_CO2_INT_TIME_IN_MS 950 #define ATLAS_INT_TIME_IN_MS 950
enum { enum {
ATLAS_CO2_EZO, ATLAS_CO2_EZO,
ATLAS_O2_EZO,
}; };
struct atlas_ezo_device { struct atlas_ezo_device {
...@@ -38,31 +39,53 @@ struct atlas_ezo_data { ...@@ -38,31 +39,53 @@ struct atlas_ezo_data {
u8 buffer[8]; u8 buffer[8];
}; };
#define ATLAS_CONCENTRATION_CHANNEL(_modifier) \
{ \
.type = IIO_CONCENTRATION, \
.modified = 1,\
.channel2 = _modifier, \
.info_mask_separate = \
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
.scan_index = 0, \
.scan_type = { \
.sign = 'u', \
.realbits = 32, \
.storagebits = 32, \
.endianness = IIO_CPU, \
}, \
}
static const struct iio_chan_spec atlas_co2_ezo_channels[] = { static const struct iio_chan_spec atlas_co2_ezo_channels[] = {
{ ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2),
.type = IIO_CONCENTRATION, };
.modified = 1,
.channel2 = IIO_MOD_CO2, static const struct iio_chan_spec atlas_o2_ezo_channels[] = {
.info_mask_separate = ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2),
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
.scan_index = 0,
.scan_type = {
.sign = 'u',
.realbits = 32,
.storagebits = 32,
.endianness = IIO_CPU,
},
},
}; };
static struct atlas_ezo_device atlas_ezo_devices[] = { static struct atlas_ezo_device atlas_ezo_devices[] = {
[ATLAS_CO2_EZO] = { [ATLAS_CO2_EZO] = {
.channels = atlas_co2_ezo_channels, .channels = atlas_co2_ezo_channels,
.num_channels = 1, .num_channels = 1,
.delay = ATLAS_CO2_INT_TIME_IN_MS, .delay = ATLAS_INT_TIME_IN_MS,
}, },
[ATLAS_O2_EZO] = {
.channels = atlas_o2_ezo_channels,
.num_channels = 1,
.delay = ATLAS_INT_TIME_IN_MS,
}
}; };
static void atlas_ezo_sanitize(char *buf)
{
char *ptr = strchr(buf, '.');
if (!ptr)
return;
memmove(ptr, ptr + 1, strlen(ptr));
}
static int atlas_ezo_read_raw(struct iio_dev *indio_dev, static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int *val, int *val2, long mask) int *val, int *val2, long mask)
...@@ -96,6 +119,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, ...@@ -96,6 +119,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
return -EBUSY; return -EBUSY;
} }
/* removing floating point for fixed number representation */
atlas_ezo_sanitize(data->buffer + 2);
ret = kstrtol(data->buffer + 1, 10, &tmp); ret = kstrtol(data->buffer + 1, 10, &tmp);
*val = tmp; *val = tmp;
...@@ -105,9 +131,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev, ...@@ -105,9 +131,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
return ret ? ret : IIO_VAL_INT; return ret ? ret : IIO_VAL_INT;
} }
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 0; switch (chan->channel2) {
*val2 = 100; /* 0.0001 */ case IIO_MOD_CO2:
return IIO_VAL_INT_PLUS_MICRO; *val = 0;
*val2 = 100; /* 0.0001 */
return IIO_VAL_INT_PLUS_MICRO;
case IIO_MOD_O2:
*val = 100;
return IIO_VAL_INT;
}
return -EINVAL;
} }
return 0; return 0;
...@@ -119,12 +152,14 @@ static const struct iio_info atlas_info = { ...@@ -119,12 +152,14 @@ static const struct iio_info atlas_info = {
static const struct i2c_device_id atlas_ezo_id[] = { static const struct i2c_device_id atlas_ezo_id[] = {
{ "atlas-co2-ezo", ATLAS_CO2_EZO }, { "atlas-co2-ezo", ATLAS_CO2_EZO },
{ "atlas-o2-ezo", ATLAS_O2_EZO },
{} {}
}; };
MODULE_DEVICE_TABLE(i2c, atlas_ezo_id); MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
static const struct of_device_id atlas_ezo_dt_ids[] = { static const struct of_device_id atlas_ezo_dt_ids[] = {
{ .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, }, { .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, },
{ .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, },
{} {}
}; };
MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids); MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment