linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor
@ 2020-06-09 19:41 Matt Ranostay
  2020-06-09 19:41 ` [PATCH 1/3] iio: add IIO_MOD_O2 modifier Matt Ranostay
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Matt Ranostay @ 2020-06-09 19:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay

Add support for Alas EZO O2 sensor, rework driver to allow this to be done, and
added IIO_MOD_O2 modifier.

Matt Ranostay (3):
  iio: add IIO_MOD_O2 modifier
  dt-bindings: iio: chemical: add O2 EZO module documentation
  iio: chemical: atlas-ezo-sensor: add support for O2 sensor

 Documentation/ABI/testing/sysfs-bus-iio       |  2 +
 .../bindings/iio/chemical/atlas,sensor.yaml   |  2 +
 drivers/iio/chemical/atlas-ezo-sensor.c       | 74 ++++++++++++++-----
 drivers/iio/industrialio-core.c               |  1 +
 include/uapi/linux/iio/types.h                |  1 +
 tools/iio/iio_event_monitor.c                 |  2 +
 6 files changed, 63 insertions(+), 19 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] iio: add IIO_MOD_O2 modifier
  2020-06-09 19:41 [PATCH 0/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
@ 2020-06-09 19:41 ` Matt Ranostay
  2020-06-09 19:41 ` [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation Matt Ranostay
  2020-06-09 19:41 ` [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
  2 siblings, 0 replies; 7+ messages in thread
From: Matt Ranostay @ 2020-06-09 19:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay

Add modifier IIO_MOD_O2 for O2 concentration reporting

Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 Documentation/ABI/testing/sysfs-bus-iio | 2 ++
 drivers/iio/industrialio-core.c         | 1 +
 include/uapi/linux/iio/types.h          | 1 +
 tools/iio/iio_event_monitor.c           | 2 ++
 4 files changed, 6 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index d3e53a6d8331..5166d905a830 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1564,6 +1564,8 @@ What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_ethanol_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_ethanol_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_h2_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_h2_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_o2_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_o2_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw
 What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw
 KernelVersion:	4.3
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 1527f01a44f1..983dba7725a4 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -130,6 +130,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_PM2P5] = "pm2p5",
 	[IIO_MOD_PM4] = "pm4",
 	[IIO_MOD_PM10] = "pm10",
+	[IIO_MOD_O2] = "o2",
 };
 
 /* relies on pairs of these shared then separate */
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index fdd81affca4b..48c13147c0a8 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -94,6 +94,7 @@ enum iio_modifier {
 	IIO_MOD_PM10,
 	IIO_MOD_ETHANOL,
 	IIO_MOD_H2,
+	IIO_MOD_O2,
 };
 
 enum iio_event_type {
diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index f115d166c985..bb03859db89d 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -119,6 +119,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_PM2P5] = "pm2p5",
 	[IIO_MOD_PM4] = "pm4",
 	[IIO_MOD_PM10] = "pm10",
+	[IIO_MOD_O2] = "o2",
 };
 
 static bool event_is_known(struct iio_event_data *event)
@@ -211,6 +212,7 @@ static bool event_is_known(struct iio_event_data *event)
 	case IIO_MOD_PM2P5:
 	case IIO_MOD_PM4:
 	case IIO_MOD_PM10:
+	case IIO_MOD_O2:
 		break;
 	default:
 		return false;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation
  2020-06-09 19:41 [PATCH 0/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
  2020-06-09 19:41 ` [PATCH 1/3] iio: add IIO_MOD_O2 modifier Matt Ranostay
@ 2020-06-09 19:41 ` Matt Ranostay
  2020-06-17 22:05   ` Rob Herring
  2020-06-09 19:41 ` [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
  2 siblings, 1 reply; 7+ messages in thread
From: Matt Ranostay @ 2020-06-09 19:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay, devicetree

Cc: devicetree@vger.kernel.org
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 .../devicetree/bindings/iio/chemical/atlas,sensor.yaml          | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/chemical/atlas,sensor.yaml b/Documentation/devicetree/bindings/iio/chemical/atlas,sensor.yaml
index 69e8931e0ae8..46496dc250f2 100644
--- a/Documentation/devicetree/bindings/iio/chemical/atlas,sensor.yaml
+++ b/Documentation/devicetree/bindings/iio/chemical/atlas,sensor.yaml
@@ -19,6 +19,7 @@ description: |
     http://www.atlas-scientific.com/_files/_datasheets/_oem/pH_oem_datasheet.pdf
     http://www.atlas-scientific.com/_files/_datasheets/_oem/RTD_oem_datasheet.pdf
     http://www.atlas-scientific.com/_files/_datasheets/_probe/EZO_CO2_Datasheet.pdf
+    https://www.atlas-scientific.com/files/EZO_O2_datasheet.pdf
 
 properties:
   compatible:
@@ -29,6 +30,7 @@ properties:
       - atlas,ph-sm
       - atlas,rtd-sm
       - atlas,co2-ezo
+      - atlas,o2-ezo
 
   reg:
      maxItems: 1
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor
  2020-06-09 19:41 [PATCH 0/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
  2020-06-09 19:41 ` [PATCH 1/3] iio: add IIO_MOD_O2 modifier Matt Ranostay
  2020-06-09 19:41 ` [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation Matt Ranostay
@ 2020-06-09 19:41 ` Matt Ranostay
  2020-06-14 13:39   ` Jonathan Cameron
  2 siblings, 1 reply; 7+ messages in thread
From: Matt Ranostay @ 2020-06-09 19:41 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay

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: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/chemical/atlas-ezo-sensor.c | 74 ++++++++++++++++++-------
 1 file changed, 55 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c
index a94eb8a6bf32..94188c84e65f 100644
--- a/drivers/iio/chemical/atlas-ezo-sensor.c
+++ b/drivers/iio/chemical/atlas-ezo-sensor.c
@@ -16,10 +16,11 @@
 #include <linux/iio/iio.h>
 
 #define ATLAS_EZO_DRV_NAME		"atlas-ezo-sensor"
-#define ATLAS_CO2_INT_TIME_IN_MS	950
+#define ATLAS_INT_TIME_IN_MS		950
 
 enum {
 	ATLAS_CO2_EZO,
+	ATLAS_O2_EZO,
 };
 
 struct atlas_ezo_device {
@@ -38,31 +39,54 @@ struct atlas_ezo_data {
 	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[] = {
-	{
-		.type = IIO_CONCENTRATION,
-		.modified = 1,
-		.channel2 = IIO_MOD_CO2,
-		.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,
-		},
-	},
+	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2),
+};
+
+static const struct iio_chan_spec atlas_o2_ezo_channels[] = {
+	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2),
 };
 
 static struct atlas_ezo_device atlas_ezo_devices[] = {
 	[ATLAS_CO2_EZO] = {
 		.channels = atlas_co2_ezo_channels,
 		.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;
+
+	for (; *ptr; ptr++)
+		*ptr = *(ptr + 1);
+}
+
 static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
 			  struct iio_chan_spec const *chan,
 			  int *val, int *val2, long mask)
@@ -96,6 +120,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
 			return -EBUSY;
 		}
 
+		/* removing floating point for fixed number representation */
+		atlas_ezo_sanitize(data->buffer + 2);
+
 		ret = kstrtol(data->buffer + 1, 10, &tmp);
 
 		*val = tmp;
@@ -105,9 +132,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
 		return ret ? ret : IIO_VAL_INT;
 	}
 	case IIO_CHAN_INFO_SCALE:
-		*val = 0;
-		*val2 = 100; /* 0.0001 */
-		return IIO_VAL_INT_PLUS_MICRO;
+		switch (chan->channel2) {
+		case IIO_MOD_CO2:
+			*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;
@@ -119,12 +153,14 @@ static const struct iio_info atlas_info = {
 
 static const struct i2c_device_id atlas_ezo_id[] = {
 	{ "atlas-co2-ezo", ATLAS_CO2_EZO },
+	{ "atlas-o2-ezo", ATLAS_O2_EZO },
 	{}
 };
 MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
 
 static const struct of_device_id atlas_ezo_dt_ids[] = {
 	{ .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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor
  2020-06-09 19:41 ` [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
@ 2020-06-14 13:39   ` Jonathan Cameron
  2020-06-14 20:24     ` Matt Ranostay
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2020-06-14 13:39 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: linux-iio

On Tue,  9 Jun 2020 12:41:17 -0700
Matt Ranostay <matt.ranostay@konsulko.com> wrote:

> 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: Matt Ranostay <matt.ranostay@konsulko.com>
Hohum.  I could just apply this series today (looks good) but
given you just fixed that missing strings problem, that will make
for a messy merge for Greg when I send this via togreg and the
fix via fixes-togreg.

As such I'm going to sit on this one until that fix ends up in my
upstream then pick this up.

Do remind me if I seem to have lost it though once that's true!

Thanks,

Jonathan

> ---
>  drivers/iio/chemical/atlas-ezo-sensor.c | 74 ++++++++++++++++++-------
>  1 file changed, 55 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c
> index a94eb8a6bf32..94188c84e65f 100644
> --- a/drivers/iio/chemical/atlas-ezo-sensor.c
> +++ b/drivers/iio/chemical/atlas-ezo-sensor.c
> @@ -16,10 +16,11 @@
>  #include <linux/iio/iio.h>
>  
>  #define ATLAS_EZO_DRV_NAME		"atlas-ezo-sensor"
> -#define ATLAS_CO2_INT_TIME_IN_MS	950
> +#define ATLAS_INT_TIME_IN_MS		950
>  
>  enum {
>  	ATLAS_CO2_EZO,
> +	ATLAS_O2_EZO,
>  };
>  
>  struct atlas_ezo_device {
> @@ -38,31 +39,54 @@ struct atlas_ezo_data {
>  	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[] = {
> -	{
> -		.type = IIO_CONCENTRATION,
> -		.modified = 1,
> -		.channel2 = IIO_MOD_CO2,
> -		.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,
> -		},
> -	},
> +	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2),
> +};
> +
> +static const struct iio_chan_spec atlas_o2_ezo_channels[] = {
> +	ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2),
>  };
>  
>  static struct atlas_ezo_device atlas_ezo_devices[] = {
>  	[ATLAS_CO2_EZO] = {
>  		.channels = atlas_co2_ezo_channels,
>  		.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;
> +
> +	for (; *ptr; ptr++)
> +		*ptr = *(ptr + 1);
> +}
> +
>  static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
>  			  struct iio_chan_spec const *chan,
>  			  int *val, int *val2, long mask)
> @@ -96,6 +120,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
>  			return -EBUSY;
>  		}
>  
> +		/* removing floating point for fixed number representation */
> +		atlas_ezo_sanitize(data->buffer + 2);
> +
>  		ret = kstrtol(data->buffer + 1, 10, &tmp);
>  
>  		*val = tmp;
> @@ -105,9 +132,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
>  		return ret ? ret : IIO_VAL_INT;
>  	}
>  	case IIO_CHAN_INFO_SCALE:
> -		*val = 0;
> -		*val2 = 100; /* 0.0001 */
> -		return IIO_VAL_INT_PLUS_MICRO;
> +		switch (chan->channel2) {
> +		case IIO_MOD_CO2:
> +			*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;
> @@ -119,12 +153,14 @@ static const struct iio_info atlas_info = {
>  
>  static const struct i2c_device_id atlas_ezo_id[] = {
>  	{ "atlas-co2-ezo", ATLAS_CO2_EZO },
> +	{ "atlas-o2-ezo", ATLAS_O2_EZO },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
>  
>  static const struct of_device_id atlas_ezo_dt_ids[] = {
>  	{ .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);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor
  2020-06-14 13:39   ` Jonathan Cameron
@ 2020-06-14 20:24     ` Matt Ranostay
  0 siblings, 0 replies; 7+ messages in thread
From: Matt Ranostay @ 2020-06-14 20:24 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: open list:IIO SUBSYSTEM AND DRIVERS

On Sun, Jun 14, 2020 at 6:39 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue,  9 Jun 2020 12:41:17 -0700
> Matt Ranostay <matt.ranostay@konsulko.com> wrote:
>
> > 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: Matt Ranostay <matt.ranostay@konsulko.com>
> Hohum.  I could just apply this series today (looks good) but
> given you just fixed that missing strings problem, that will make
> for a messy merge for Greg when I send this via togreg and the
> fix via fixes-togreg.
>
> As such I'm going to sit on this one until that fix ends up in my
> upstream then pick this up.
>
> Do remind me if I seem to have lost it though once that's true!

Will do!

- Matt

>
> Thanks,
>
> Jonathan
>
> > ---
> >  drivers/iio/chemical/atlas-ezo-sensor.c | 74 ++++++++++++++++++-------
> >  1 file changed, 55 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c
> > index a94eb8a6bf32..94188c84e65f 100644
> > --- a/drivers/iio/chemical/atlas-ezo-sensor.c
> > +++ b/drivers/iio/chemical/atlas-ezo-sensor.c
> > @@ -16,10 +16,11 @@
> >  #include <linux/iio/iio.h>
> >
> >  #define ATLAS_EZO_DRV_NAME           "atlas-ezo-sensor"
> > -#define ATLAS_CO2_INT_TIME_IN_MS     950
> > +#define ATLAS_INT_TIME_IN_MS         950
> >
> >  enum {
> >       ATLAS_CO2_EZO,
> > +     ATLAS_O2_EZO,
> >  };
> >
> >  struct atlas_ezo_device {
> > @@ -38,31 +39,54 @@ struct atlas_ezo_data {
> >       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[] = {
> > -     {
> > -             .type = IIO_CONCENTRATION,
> > -             .modified = 1,
> > -             .channel2 = IIO_MOD_CO2,
> > -             .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,
> > -             },
> > -     },
> > +     ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_CO2),
> > +};
> > +
> > +static const struct iio_chan_spec atlas_o2_ezo_channels[] = {
> > +     ATLAS_CONCENTRATION_CHANNEL(IIO_MOD_O2),
> >  };
> >
> >  static struct atlas_ezo_device atlas_ezo_devices[] = {
> >       [ATLAS_CO2_EZO] = {
> >               .channels = atlas_co2_ezo_channels,
> >               .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;
> > +
> > +     for (; *ptr; ptr++)
> > +             *ptr = *(ptr + 1);
> > +}
> > +
> >  static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
> >                         struct iio_chan_spec const *chan,
> >                         int *val, int *val2, long mask)
> > @@ -96,6 +120,9 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
> >                       return -EBUSY;
> >               }
> >
> > +             /* removing floating point for fixed number representation */
> > +             atlas_ezo_sanitize(data->buffer + 2);
> > +
> >               ret = kstrtol(data->buffer + 1, 10, &tmp);
> >
> >               *val = tmp;
> > @@ -105,9 +132,16 @@ static int atlas_ezo_read_raw(struct iio_dev *indio_dev,
> >               return ret ? ret : IIO_VAL_INT;
> >       }
> >       case IIO_CHAN_INFO_SCALE:
> > -             *val = 0;
> > -             *val2 = 100; /* 0.0001 */
> > -             return IIO_VAL_INT_PLUS_MICRO;
> > +             switch (chan->channel2) {
> > +             case IIO_MOD_CO2:
> > +                     *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;
> > @@ -119,12 +153,14 @@ static const struct iio_info atlas_info = {
> >
> >  static const struct i2c_device_id atlas_ezo_id[] = {
> >       { "atlas-co2-ezo", ATLAS_CO2_EZO },
> > +     { "atlas-o2-ezo", ATLAS_O2_EZO },
> >       {}
> >  };
> >  MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
> >
> >  static const struct of_device_id atlas_ezo_dt_ids[] = {
> >       { .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);
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation
  2020-06-09 19:41 ` [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation Matt Ranostay
@ 2020-06-17 22:05   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2020-06-17 22:05 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: devicetree, jic23, linux-iio

On Tue, 09 Jun 2020 12:41:16 -0700, Matt Ranostay wrote:
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
> ---
>  .../devicetree/bindings/iio/chemical/atlas,sensor.yaml          | 2 ++
>  1 file changed, 2 insertions(+)
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-17 22:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 19:41 [PATCH 0/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
2020-06-09 19:41 ` [PATCH 1/3] iio: add IIO_MOD_O2 modifier Matt Ranostay
2020-06-09 19:41 ` [PATCH 2/3] dt-bindings: iio: chemical: add O2 EZO module documentation Matt Ranostay
2020-06-17 22:05   ` Rob Herring
2020-06-09 19:41 ` [PATCH 3/3] iio: chemical: atlas-ezo-sensor: add support for O2 sensor Matt Ranostay
2020-06-14 13:39   ` Jonathan Cameron
2020-06-14 20:24     ` Matt Ranostay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).