All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/4] iio: new chemical sensor framework and channel types
@ 2015-09-14  3:26 ` Matt Ranostay
  0 siblings, 0 replies; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree, Matt Ranostay

Changes from v4:
* Add IIO_MOD_CO2 and IIO_MOD_VOC modifiers
* Updated IIO_RESISTANCE and IIO_CONCENTRATION documentation
* Moved the decimal point shifting to the scale value versus the reading

Matt Ranostay (4):
  iio: chemical: Add IIO_CONCENTRATION channel type
  iio: resistance: add IIO_RESISTANCE channel type
  devicetree: add SGX Sensortech vendor id
  iio: chemical: add SGX VZ89x VOC sensor support

 Documentation/ABI/testing/sysfs-bus-iio            |  19 ++
 .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
 .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 drivers/iio/Kconfig                                |   1 +
 drivers/iio/Makefile                               |   1 +
 drivers/iio/chemical/Kconfig                       |  15 ++
 drivers/iio/chemical/Makefile                      |   6 +
 drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
 drivers/iio/industrialio-core.c                    |   4 +
 include/uapi/linux/iio/types.h                     |   4 +
 11 files changed, 296 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
 create mode 100644 drivers/iio/chemical/Kconfig
 create mode 100644 drivers/iio/chemical/Makefile
 create mode 100644 drivers/iio/chemical/vz89x.c

-- 
1.9.1


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

* [PATCH v5 0/4] iio: new chemical sensor framework and channel types
@ 2015-09-14  3:26 ` Matt Ranostay
  0 siblings, 0 replies; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A, lars-Qo5EllUWu/uELgA04lAiVw,
	pmeerw-jW+XmwGofnusTnJN9+BGXg
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Matt Ranostay

Changes from v4:
* Add IIO_MOD_CO2 and IIO_MOD_VOC modifiers
* Updated IIO_RESISTANCE and IIO_CONCENTRATION documentation
* Moved the decimal point shifting to the scale value versus the reading

Matt Ranostay (4):
  iio: chemical: Add IIO_CONCENTRATION channel type
  iio: resistance: add IIO_RESISTANCE channel type
  devicetree: add SGX Sensortech vendor id
  iio: chemical: add SGX VZ89x VOC sensor support

 Documentation/ABI/testing/sysfs-bus-iio            |  19 ++
 .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
 .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 drivers/iio/Kconfig                                |   1 +
 drivers/iio/Makefile                               |   1 +
 drivers/iio/chemical/Kconfig                       |  15 ++
 drivers/iio/chemical/Makefile                      |   6 +
 drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
 drivers/iio/industrialio-core.c                    |   4 +
 include/uapi/linux/iio/types.h                     |   4 +
 11 files changed, 296 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
 create mode 100644 drivers/iio/chemical/Kconfig
 create mode 100644 drivers/iio/chemical/Makefile
 create mode 100644 drivers/iio/chemical/vz89x.c

-- 
1.9.1

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

* [PATCH v5 1/4] iio: chemical: Add IIO_CONCENTRATION channel type
  2015-09-14  3:26 ` Matt Ranostay
  (?)
@ 2015-09-14  3:26 ` Matt Ranostay
  2015-09-20 18:55     ` Jonathan Cameron
  -1 siblings, 1 reply; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree, Matt Ranostay

There are air quality sensors that report data back in parts per million
of VOC (Volatile Organic Compounds) which are usually indexed from CO2
or another common pollutant.

This patchset adds an IIO_CONCENTRATION type that returns a percentage
of substance because no other channels types fit this use case.
Modifiers for IIO_MOD_CO2 and IIO_MOD_VOC gas types are defined.

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 Documentation/ABI/testing/sysfs-bus-iio | 11 +++++++++++
 drivers/iio/industrialio-core.c         |  3 +++
 include/uapi/linux/iio/types.h          |  3 +++
 3 files changed, 17 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 42d360f..682c070 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1459,3 +1459,14 @@ Description:
 		measurements and return the average value as output data. Each
 		value resulted from <type>[_name]_oversampling_ratio measurements
 		is considered as one sample for <type>[_name]_sampling_frequency.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_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
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Raw (unscaled no offset etc.) percentage reading of a substance.
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index b3fcc2c..8eb6064 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -75,6 +75,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_ENERGY] = "energy",
 	[IIO_DISTANCE] = "distance",
 	[IIO_VELOCITY] = "velocity",
+	[IIO_CONCENTRATION] = "concentration",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -111,6 +112,8 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
 	[IIO_MOD_I] = "i",
 	[IIO_MOD_Q] = "q",
+	[IIO_MOD_CO2] = "co2",
+	[IIO_MOD_VOC] = "voc",
 };
 
 /* 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 2f8b117..1e4c4e3 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -35,6 +35,7 @@ enum iio_chan_type {
 	IIO_ENERGY,
 	IIO_DISTANCE,
 	IIO_VELOCITY,
+	IIO_CONCENTRATION,
 };
 
 enum iio_modifier {
@@ -72,6 +73,8 @@ enum iio_modifier {
 	IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
 	IIO_MOD_I,
 	IIO_MOD_Q,
+	IIO_MOD_CO2,
+	IIO_MOD_VOC,
 };
 
 enum iio_event_type {
-- 
1.9.1


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

* [PATCH v5 2/4] iio: resistance: add IIO_RESISTANCE channel type
  2015-09-14  3:26 ` Matt Ranostay
  (?)
  (?)
@ 2015-09-14  3:26 ` Matt Ranostay
  2015-09-20 18:55     ` Jonathan Cameron
  -1 siblings, 1 reply; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 Documentation/ABI/testing/sysfs-bus-iio | 8 ++++++++
 drivers/iio/industrialio-core.c         | 1 +
 include/uapi/linux/iio/types.h          | 1 +
 3 files changed, 10 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index 682c070..a91af51 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1470,3 +1470,11 @@ KernelVersion:	4.3
 Contact:	linux-iio@vger.kernel.org
 Description:
 		Raw (unscaled no offset etc.) percentage reading of a substance.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_resistance_raw
+What:		/sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
+KernelVersion:	4.3
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Raw (unscaled no offset etc.) resistance reading that can be processed
+		into an ohm value.
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 8eb6064..80439a6 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -76,6 +76,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_DISTANCE] = "distance",
 	[IIO_VELOCITY] = "velocity",
 	[IIO_CONCENTRATION] = "concentration",
+	[IIO_RESISTANCE] = "resistance",
 };
 
 static const char * const iio_modifier_names[] = {
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index 1e4c4e3..7c63bd6 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -36,6 +36,7 @@ enum iio_chan_type {
 	IIO_DISTANCE,
 	IIO_VELOCITY,
 	IIO_CONCENTRATION,
+	IIO_RESISTANCE,
 };
 
 enum iio_modifier {
-- 
1.9.1


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

* [PATCH v5 3/4] devicetree: add SGX Sensortech vendor id
  2015-09-14  3:26 ` Matt Ranostay
                   ` (2 preceding siblings ...)
  (?)
@ 2015-09-14  3:26 ` Matt Ranostay
  2015-09-20 18:58   ` Jonathan Cameron
  -1 siblings, 1 reply; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index ac5f0c3..281e8f0 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -191,6 +191,7 @@ sbs	Smart Battery System
 schindler	Schindler
 seagate	Seagate Technology PLC
 semtech	Semtech Corporation
+sgx	SGX Sensortech
 sharp	Sharp Corporation
 sil	Silicon Image
 silabs	Silicon Laboratories
-- 
1.9.1


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

* [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-14  3:26 ` Matt Ranostay
                   ` (3 preceding siblings ...)
  (?)
@ 2015-09-14  3:26 ` Matt Ranostay
  2015-09-14  8:35   ` Peter Meerwald
  -1 siblings, 1 reply; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14  3:26 UTC (permalink / raw)
  To: jic23, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree, Matt Ranostay

Add support for VZ89X sensors VOC and CO2 reporting channels in
percentage which can be converted to part per million.

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
 .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
 drivers/iio/Kconfig                                |   1 +
 drivers/iio/Makefile                               |   1 +
 drivers/iio/chemical/Kconfig                       |  15 ++
 drivers/iio/chemical/Makefile                      |   6 +
 drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
 7 files changed, 268 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
 create mode 100644 drivers/iio/chemical/Kconfig
 create mode 100644 drivers/iio/chemical/Makefile
 create mode 100644 drivers/iio/chemical/vz89x.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
new file mode 100644
index 0000000..c0c1ea9
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
@@ -0,0 +1,7 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
+Date:		September 2015
+KernelVersion:	4.3
+Contact:	Matt Ranostay <mranostay@gmail.com>
+Description:
+		Get the raw calibration VOC value from the sensor.
+		This value has little application outside of calibration.
diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
index d77d412..a550216 100644
--- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
@@ -88,6 +88,7 @@ ricoh,rs5c372b		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 ricoh,rv5c386		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 ricoh,rv5c387a		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 samsung,24ad0xd1	S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
+sgx,vz89x		SGX Sensortech VZ89X Sensors
 sii,s35390a		2-wire CMOS real-time clock
 skyworks,sky81452	Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
 st-micro,24c256		i2c serial eeprom  (24cxx)
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 4011eff..9664e9c 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
 source "drivers/iio/accel/Kconfig"
 source "drivers/iio/adc/Kconfig"
 source "drivers/iio/amplifiers/Kconfig"
+source "drivers/iio/chemical/Kconfig"
 source "drivers/iio/common/Kconfig"
 source "drivers/iio/dac/Kconfig"
 source "drivers/iio/frequency/Kconfig"
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 698afc2..2288684 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
 obj-y += accel/
 obj-y += adc/
 obj-y += amplifiers/
+obj-y += chemical/
 obj-y += common/
 obj-y += dac/
 obj-y += gyro/
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
new file mode 100644
index 0000000..04906af
--- /dev/null
+++ b/drivers/iio/chemical/Kconfig
@@ -0,0 +1,15 @@
+#
+# Chemical sensors
+#
+
+menu "Indoor Air Quality sensors"
+
+config VZ89X
+	tristate "SGX Sensortech MiCS VZ89X VOC sensor"
+	depends on I2C
+	help
+	  Say Y here to build I2C interface support for the SGX
+	  Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
+	  sensors
+
+endmenu
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
new file mode 100644
index 0000000..7292f2d
--- /dev/null
+++ b/drivers/iio/chemical/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for IIO chemical sensors
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_VZ89X)		+= vz89x.o
diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
new file mode 100644
index 0000000..b454200
--- /dev/null
+++ b/drivers/iio/chemical/vz89x.c
@@ -0,0 +1,237 @@
+/*
+ * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
+ *
+ * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#define VZ89X_REG_MEASUREMENT		0x09
+#define VZ89X_REG_MEASUREMENT_SIZE	6
+
+#define VZ89X_VOC_CO2_IDX		0
+#define VZ89X_VOC_SHORT_IDX		1
+#define VZ89X_VOC_TVOC_IDX		2
+#define VZ89X_VOC_RESISTANCE_IDX	3
+
+struct vz89x_data {
+	struct i2c_client *client;
+	struct mutex lock;
+	unsigned long last_update;
+
+	u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
+};
+
+static const struct iio_chan_spec vz89x_channels[] = {
+	{
+		.type = IIO_CONCENTRATION,
+		.channel2 = IIO_MOD_CO2,
+		.modified = 1,
+		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
+		.address = VZ89X_VOC_CO2_IDX,
+	},
+	{
+		.type = IIO_CONCENTRATION,
+		.channel2 = IIO_MOD_VOC,
+		.modified = 1,
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.address = VZ89X_VOC_SHORT_IDX,
+		.extend_name = "short",
+	},
+	{
+		.type = IIO_CONCENTRATION,
+		.channel2 = IIO_MOD_VOC,
+		.modified = 1,
+		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
+		.address = VZ89X_VOC_TVOC_IDX,
+	},
+	{
+		.type = IIO_RESISTANCE,
+		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+		.address = VZ89X_VOC_RESISTANCE_IDX,
+	},
+};
+
+static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
+static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
+
+static struct attribute *vz89x_attributes[] = {
+	&iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
+	&iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group vz89x_attrs_group = {
+	.attrs = vz89x_attributes,
+};
+
+static int vz89x_get_measurement(struct vz89x_data *data)
+{
+	int ret;
+	int i;
+
+	/* sensor can only be polled once a second max per datasheet */
+	if (!time_after(jiffies, data->last_update + HZ))
+		return 0;
+
+	ret = i2c_smbus_write_word_data(data->client,
+					VZ89X_REG_MEASUREMENT, 0);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
+		ret = i2c_smbus_read_byte(data->client);
+		if (ret < 0)
+			return ret;
+		data->buffer[i] = ret;
+	}
+
+	data->last_update = jiffies;
+
+	return 0;
+}
+
+static int vz89x_get_resistance_reading(struct vz89x_data *data)
+{
+	u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
+
+	return buf[0] | (buf[1] << 8) | (buf[2] << 16);
+}
+
+static int vz89x_read_raw(struct iio_dev *indio_dev,
+			  struct iio_chan_spec const *chan, int *val,
+			  int *val2, long mask)
+{
+	struct vz89x_data *data = iio_priv(indio_dev);
+	int ret = -EINVAL;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		mutex_lock(&data->lock);
+		ret = vz89x_get_measurement(data);
+		mutex_unlock(&data->lock);
+
+		if (ret)
+			return ret;
+
+		switch (chan->address) {
+		case VZ89X_VOC_CO2_IDX:
+		case VZ89X_VOC_SHORT_IDX:
+		case VZ89X_VOC_TVOC_IDX:
+			*val = data->buffer[chan->address];
+			return IIO_VAL_INT;
+		case VZ89X_VOC_RESISTANCE_IDX:
+			*val = vz89x_get_resistance_reading(data);
+			return IIO_VAL_INT;
+		default:
+			return -EINVAL;
+		}
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		switch (chan->type) {
+		case IIO_RESISTANCE:
+			*val = 10;
+			return IIO_VAL_INT;
+		default:
+			return -EINVAL;
+		}
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		switch (chan->address) {
+		case VZ89X_VOC_CO2_IDX:
+			*val = 44;
+			*val2 = 250000;
+			return IIO_VAL_INT_PLUS_MICRO;
+		case VZ89X_VOC_TVOC_IDX:
+			*val = -13;
+			return IIO_VAL_INT;
+		default:
+			return -EINVAL;
+		}
+	}
+
+	return ret;
+}
+
+static const struct iio_info vz89x_info = {
+	.attrs		= &vz89x_attrs_group,
+	.read_raw	= vz89x_read_raw,
+	.driver_module	= THIS_MODULE,
+};
+
+static int vz89x_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct iio_dev *indio_dev;
+	struct vz89x_data *data;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
+				     I2C_FUNC_SMBUS_BYTE))
+		return -ENODEV;
+
+	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	i2c_set_clientdata(client, indio_dev);
+	data->client = client;
+	data->last_update = jiffies - HZ;
+	mutex_init(&data->lock);
+
+	indio_dev->dev.parent = &client->dev;
+	indio_dev->info = &vz89x_info,
+	indio_dev->name = dev_name(&client->dev);
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	indio_dev->channels = vz89x_channels;
+	indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
+
+	return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id vz89x_id[] = {
+	{ "vz89x", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, vz89x_id);
+
+static const struct of_device_id vz89x_dt_ids[] = {
+	{ .compatible = "sgx,vz89x" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
+
+static struct i2c_driver vz89x_driver = {
+	.driver = {
+		.name	= "vz89x",
+		.of_match_table = of_match_ptr(vz89x_dt_ids),
+	},
+	.probe = vz89x_probe,
+	.id_table = vz89x_id,
+};
+module_i2c_driver(vz89x_driver);
+
+MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
+MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
+MODULE_LICENSE("GPL v2");
-- 
1.9.1


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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-14  3:26 ` [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support Matt Ranostay
@ 2015-09-14  8:35   ` Peter Meerwald
  2015-09-14 15:22     ` Matt Ranostay
                       ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Peter Meerwald @ 2015-09-14  8:35 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: jic23, lars, linux-iio


> Add support for VZ89X sensors VOC and CO2 reporting channels in
> percentage which can be converted to part per million.

can you make the proper changes for _CONCENTRATION etc. also for 
tools/iio/iio_event_monitor.c?

and comment below
 
> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
> ---
>  .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>  .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>  drivers/iio/Kconfig                                |   1 +
>  drivers/iio/Makefile                               |   1 +
>  drivers/iio/chemical/Kconfig                       |  15 ++
>  drivers/iio/chemical/Makefile                      |   6 +
>  drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>  7 files changed, 268 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>  create mode 100644 drivers/iio/chemical/Kconfig
>  create mode 100644 drivers/iio/chemical/Makefile
>  create mode 100644 drivers/iio/chemical/vz89x.c
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
> new file mode 100644
> index 0000000..c0c1ea9
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
> @@ -0,0 +1,7 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
> +Date:		September 2015
> +KernelVersion:	4.3
> +Contact:	Matt Ranostay <mranostay@gmail.com>
> +Description:
> +		Get the raw calibration VOC value from the sensor.
> +		This value has little application outside of calibration.
> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> index d77d412..a550216 100644
> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
> @@ -88,6 +88,7 @@ ricoh,rs5c372b		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>  ricoh,rv5c386		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>  ricoh,rv5c387a		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>  samsung,24ad0xd1	S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
> +sgx,vz89x		SGX Sensortech VZ89X Sensors
>  sii,s35390a		2-wire CMOS real-time clock
>  skyworks,sky81452	Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>  st-micro,24c256		i2c serial eeprom  (24cxx)
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index 4011eff..9664e9c 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>  source "drivers/iio/accel/Kconfig"
>  source "drivers/iio/adc/Kconfig"
>  source "drivers/iio/amplifiers/Kconfig"
> +source "drivers/iio/chemical/Kconfig"
>  source "drivers/iio/common/Kconfig"
>  source "drivers/iio/dac/Kconfig"
>  source "drivers/iio/frequency/Kconfig"
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index 698afc2..2288684 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>  obj-y += accel/
>  obj-y += adc/
>  obj-y += amplifiers/
> +obj-y += chemical/
>  obj-y += common/
>  obj-y += dac/
>  obj-y += gyro/
> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
> new file mode 100644
> index 0000000..04906af
> --- /dev/null
> +++ b/drivers/iio/chemical/Kconfig
> @@ -0,0 +1,15 @@
> +#
> +# Chemical sensors
> +#
> +
> +menu "Indoor Air Quality sensors"

the comment above says 'Chemical sensors', the menu item 'Indoor Air 
Quality sensors' -- I guess an outdoor sensor would fit here as well...

> +
> +config VZ89X
> +	tristate "SGX Sensortech MiCS VZ89X VOC sensor"
> +	depends on I2C
> +	help
> +	  Say Y here to build I2C interface support for the SGX
> +	  Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
> +	  sensors
> +
> +endmenu
> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
> new file mode 100644
> index 0000000..7292f2d
> --- /dev/null
> +++ b/drivers/iio/chemical/Makefile
> @@ -0,0 +1,6 @@
> +#
> +# Makefile for IIO chemical sensors
> +#
> +
> +# When adding new entries keep the list in alphabetical order
> +obj-$(CONFIG_VZ89X)		+= vz89x.o
> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
> new file mode 100644
> index 0000000..b454200
> --- /dev/null
> +++ b/drivers/iio/chemical/vz89x.c
> @@ -0,0 +1,237 @@
> +/*
> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
> + *
> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/init.h>
> +#include <linux/i2c.h>
> +
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +
> +#define VZ89X_REG_MEASUREMENT		0x09
> +#define VZ89X_REG_MEASUREMENT_SIZE	6
> +
> +#define VZ89X_VOC_CO2_IDX		0
> +#define VZ89X_VOC_SHORT_IDX		1
> +#define VZ89X_VOC_TVOC_IDX		2
> +#define VZ89X_VOC_RESISTANCE_IDX	3
> +
> +struct vz89x_data {
> +	struct i2c_client *client;
> +	struct mutex lock;
> +	unsigned long last_update;
> +
> +	u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
> +};
> +
> +static const struct iio_chan_spec vz89x_channels[] = {
> +	{
> +		.type = IIO_CONCENTRATION,
> +		.channel2 = IIO_MOD_CO2,
> +		.modified = 1,
> +		.info_mask_separate =
> +			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
> +		.address = VZ89X_VOC_CO2_IDX,
> +	},
> +	{
> +		.type = IIO_CONCENTRATION,
> +		.channel2 = IIO_MOD_VOC,
> +		.modified = 1,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +		.address = VZ89X_VOC_SHORT_IDX,
> +		.extend_name = "short",
> +	},
> +	{
> +		.type = IIO_CONCENTRATION,
> +		.channel2 = IIO_MOD_VOC,
> +		.modified = 1,
> +		.info_mask_separate =
> +			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
> +		.address = VZ89X_VOC_TVOC_IDX,
> +	},
> +	{
> +		.type = IIO_RESISTANCE,
> +		.info_mask_separate =
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +		.address = VZ89X_VOC_RESISTANCE_IDX,
> +	},
> +};
> +
> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
> +
> +static struct attribute *vz89x_attributes[] = {
> +	&iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
> +	&iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group vz89x_attrs_group = {
> +	.attrs = vz89x_attributes,
> +};
> +
> +static int vz89x_get_measurement(struct vz89x_data *data)
> +{
> +	int ret;
> +	int i;
> +
> +	/* sensor can only be polled once a second max per datasheet */
> +	if (!time_after(jiffies, data->last_update + HZ))
> +		return 0;
> +
> +	ret = i2c_smbus_write_word_data(data->client,
> +					VZ89X_REG_MEASUREMENT, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
> +		ret = i2c_smbus_read_byte(data->client);
> +		if (ret < 0)
> +			return ret;
> +		data->buffer[i] = ret;
> +	}
> +
> +	data->last_update = jiffies;
> +
> +	return 0;
> +}
> +
> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
> +{
> +	u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
> +
> +	return buf[0] | (buf[1] << 8) | (buf[2] << 16);
> +}
> +
> +static int vz89x_read_raw(struct iio_dev *indio_dev,
> +			  struct iio_chan_spec const *chan, int *val,
> +			  int *val2, long mask)
> +{
> +	struct vz89x_data *data = iio_priv(indio_dev);
> +	int ret = -EINVAL;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		mutex_lock(&data->lock);
> +		ret = vz89x_get_measurement(data);
> +		mutex_unlock(&data->lock);
> +
> +		if (ret)
> +			return ret;
> +
> +		switch (chan->address) {
> +		case VZ89X_VOC_CO2_IDX:
> +		case VZ89X_VOC_SHORT_IDX:
> +		case VZ89X_VOC_TVOC_IDX:
> +			*val = data->buffer[chan->address];
> +			return IIO_VAL_INT;
> +		case VZ89X_VOC_RESISTANCE_IDX:
> +			*val = vz89x_get_resistance_reading(data);
> +			return IIO_VAL_INT;
> +		default:
> +			return -EINVAL;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_SCALE:
> +		switch (chan->type) {
> +		case IIO_RESISTANCE:
> +			*val = 10;
> +			return IIO_VAL_INT;
> +		default:
> +			return -EINVAL;
> +		}
> +		break;
> +	case IIO_CHAN_INFO_OFFSET:
> +		switch (chan->address) {
> +		case VZ89X_VOC_CO2_IDX:
> +			*val = 44;
> +			*val2 = 250000;
> +			return IIO_VAL_INT_PLUS_MICRO;
> +		case VZ89X_VOC_TVOC_IDX:
> +			*val = -13;
> +			return IIO_VAL_INT;
> +		default:
> +			return -EINVAL;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
> +static const struct iio_info vz89x_info = {
> +	.attrs		= &vz89x_attrs_group,
> +	.read_raw	= vz89x_read_raw,
> +	.driver_module	= THIS_MODULE,
> +};
> +
> +static int vz89x_probe(struct i2c_client *client,
> +		       const struct i2c_device_id *id)
> +{
> +	struct iio_dev *indio_dev;
> +	struct vz89x_data *data;
> +
> +	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
> +				     I2C_FUNC_SMBUS_BYTE))
> +		return -ENODEV;
> +
> +	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	data = iio_priv(indio_dev);
> +	i2c_set_clientdata(client, indio_dev);
> +	data->client = client;
> +	data->last_update = jiffies - HZ;
> +	mutex_init(&data->lock);
> +
> +	indio_dev->dev.parent = &client->dev;
> +	indio_dev->info = &vz89x_info,
> +	indio_dev->name = dev_name(&client->dev);
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +
> +	indio_dev->channels = vz89x_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
> +
> +	return devm_iio_device_register(&client->dev, indio_dev);
> +}
> +
> +static const struct i2c_device_id vz89x_id[] = {
> +	{ "vz89x", 0 },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
> +
> +static const struct of_device_id vz89x_dt_ids[] = {
> +	{ .compatible = "sgx,vz89x" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
> +
> +static struct i2c_driver vz89x_driver = {
> +	.driver = {
> +		.name	= "vz89x",
> +		.of_match_table = of_match_ptr(vz89x_dt_ids),
> +	},
> +	.probe = vz89x_probe,
> +	.id_table = vz89x_id,
> +};
> +module_i2c_driver(vz89x_driver);
> +
> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
> +MODULE_LICENSE("GPL v2");
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)

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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-14  8:35   ` Peter Meerwald
@ 2015-09-14 15:22     ` Matt Ranostay
  2015-09-15  2:55     ` Matt Ranostay
  2015-09-20 19:02     ` Jonathan Cameron
  2 siblings, 0 replies; 17+ messages in thread
From: Matt Ranostay @ 2015-09-14 15:22 UTC (permalink / raw)
  To: Peter Meerwald; +Cc: jic23, lars, linux-iio



> On Sep 14, 2015, at 01:35, Peter Meerwald <pmeerw@pmeerw.net> wrote:
> 
> 
>> Add support for VZ89X sensors VOC and CO2 reporting channels in
>> percentage which can be converted to part per million.
> 
> can you make the proper changes for _CONCENTRATION etc. also for 
> tools/iio/iio_event_monitor.c?
> 
> and comment below
> 
>> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
>> ---
>> .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>> .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>> drivers/iio/Kconfig                                |   1 +
>> drivers/iio/Makefile                               |   1 +
>> drivers/iio/chemical/Kconfig                       |  15 ++
>> drivers/iio/chemical/Makefile                      |   6 +
>> drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>> 7 files changed, 268 insertions(+)
>> create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> create mode 100644 drivers/iio/chemical/Kconfig
>> create mode 100644 drivers/iio/chemical/Makefile
>> create mode 100644 drivers/iio/chemical/vz89x.c
>> 
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> new file mode 100644
>> index 0000000..c0c1ea9
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> @@ -0,0 +1,7 @@
>> +What:        /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
>> +Date:        September 2015
>> +KernelVersion:    4.3
>> +Contact:    Matt Ranostay <mranostay@gmail.com>
>> +Description:
>> +        Get the raw calibration VOC value from the sensor.
>> +        This value has little application outside of calibration.
>> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> index d77d412..a550216 100644
>> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> @@ -88,6 +88,7 @@ ricoh,rs5c372b        I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>> ricoh,rv5c386        I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>> ricoh,rv5c387a        I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>> samsung,24ad0xd1    S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
>> +sgx,vz89x        SGX Sensortech VZ89X Sensors
>> sii,s35390a        2-wire CMOS real-time clock
>> skyworks,sky81452    Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>> st-micro,24c256        i2c serial eeprom  (24cxx)
>> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
>> index 4011eff..9664e9c 100644
>> --- a/drivers/iio/Kconfig
>> +++ b/drivers/iio/Kconfig
>> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>> source "drivers/iio/accel/Kconfig"
>> source "drivers/iio/adc/Kconfig"
>> source "drivers/iio/amplifiers/Kconfig"
>> +source "drivers/iio/chemical/Kconfig"
>> source "drivers/iio/common/Kconfig"
>> source "drivers/iio/dac/Kconfig"
>> source "drivers/iio/frequency/Kconfig"
>> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
>> index 698afc2..2288684 100644
>> --- a/drivers/iio/Makefile
>> +++ b/drivers/iio/Makefile
>> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>> obj-y += accel/
>> obj-y += adc/
>> obj-y += amplifiers/
>> +obj-y += chemical/
>> obj-y += common/
>> obj-y += dac/
>> obj-y += gyro/
>> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
>> new file mode 100644
>> index 0000000..04906af
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Kconfig
>> @@ -0,0 +1,15 @@
>> +#
>> +# Chemical sensors
>> +#
>> +
>> +menu "Indoor Air Quality sensors"
> 
> the comment above says 'Chemical sensors', the menu item 'Indoor Air 
> Quality sensors' -- I guess an outdoor sensor would fit here as well...
Yeah I don't really care what the menu item is named.   Any thoughts on just Chemical Sensors ?
> 
>> +
>> +config VZ89X
>> +    tristate "SGX Sensortech MiCS VZ89X VOC sensor"
>> +    depends on I2C
>> +    help
>> +      Say Y here to build I2C interface support for the SGX
>> +      Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
>> +      sensors
>> +
>> +endmenu
>> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
>> new file mode 100644
>> index 0000000..7292f2d
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Makefile
>> @@ -0,0 +1,6 @@
>> +#
>> +# Makefile for IIO chemical sensors
>> +#
>> +
>> +# When adding new entries keep the list in alphabetical order
>> +obj-$(CONFIG_VZ89X)        += vz89x.o
>> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
>> new file mode 100644
>> index 0000000..b454200
>> --- /dev/null
>> +++ b/drivers/iio/chemical/vz89x.c
>> @@ -0,0 +1,237 @@
>> +/*
>> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
>> + *
>> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/init.h>
>> +#include <linux/i2c.h>
>> +
>> +#include <linux/iio/iio.h>
>> +#include <linux/iio/sysfs.h>
>> +
>> +#define VZ89X_REG_MEASUREMENT        0x09
>> +#define VZ89X_REG_MEASUREMENT_SIZE    6
>> +
>> +#define VZ89X_VOC_CO2_IDX        0
>> +#define VZ89X_VOC_SHORT_IDX        1
>> +#define VZ89X_VOC_TVOC_IDX        2
>> +#define VZ89X_VOC_RESISTANCE_IDX    3
>> +
>> +struct vz89x_data {
>> +    struct i2c_client *client;
>> +    struct mutex lock;
>> +    unsigned long last_update;
>> +
>> +    u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
>> +};
>> +
>> +static const struct iio_chan_spec vz89x_channels[] = {
>> +    {
>> +        .type = IIO_CONCENTRATION,
>> +        .channel2 = IIO_MOD_CO2,
>> +        .modified = 1,
>> +        .info_mask_separate =
>> +            BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +        .address = VZ89X_VOC_CO2_IDX,
>> +    },
>> +    {
>> +        .type = IIO_CONCENTRATION,
>> +        .channel2 = IIO_MOD_VOC,
>> +        .modified = 1,
>> +        .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>> +        .address = VZ89X_VOC_SHORT_IDX,
>> +        .extend_name = "short",
>> +    },
>> +    {
>> +        .type = IIO_CONCENTRATION,
>> +        .channel2 = IIO_MOD_VOC,
>> +        .modified = 1,
>> +        .info_mask_separate =
>> +            BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +        .address = VZ89X_VOC_TVOC_IDX,
>> +    },
>> +    {
>> +        .type = IIO_RESISTANCE,
>> +        .info_mask_separate =
>> +            BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>> +        .address = VZ89X_VOC_RESISTANCE_IDX,
>> +    },
>> +};
>> +
>> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
>> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
>> +
>> +static struct attribute *vz89x_attributes[] = {
>> +    &iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
>> +    &iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
>> +    NULL,
>> +};
>> +
>> +static const struct attribute_group vz89x_attrs_group = {
>> +    .attrs = vz89x_attributes,
>> +};
>> +
>> +static int vz89x_get_measurement(struct vz89x_data *data)
>> +{
>> +    int ret;
>> +    int i;
>> +
>> +    /* sensor can only be polled once a second max per datasheet */
>> +    if (!time_after(jiffies, data->last_update + HZ))
>> +        return 0;
>> +
>> +    ret = i2c_smbus_write_word_data(data->client,
>> +                    VZ89X_REG_MEASUREMENT, 0);
>> +    if (ret < 0)
>> +        return ret;
>> +
>> +    for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
>> +        ret = i2c_smbus_read_byte(data->client);
>> +        if (ret < 0)
>> +            return ret;
>> +        data->buffer[i] = ret;
>> +    }
>> +
>> +    data->last_update = jiffies;
>> +
>> +    return 0;
>> +}
>> +
>> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
>> +{
>> +    u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
>> +
>> +    return buf[0] | (buf[1] << 8) | (buf[2] << 16);
>> +}
>> +
>> +static int vz89x_read_raw(struct iio_dev *indio_dev,
>> +              struct iio_chan_spec const *chan, int *val,
>> +              int *val2, long mask)
>> +{
>> +    struct vz89x_data *data = iio_priv(indio_dev);
>> +    int ret = -EINVAL;
>> +
>> +    switch (mask) {
>> +    case IIO_CHAN_INFO_RAW:
>> +        mutex_lock(&data->lock);
>> +        ret = vz89x_get_measurement(data);
>> +        mutex_unlock(&data->lock);
>> +
>> +        if (ret)
>> +            return ret;
>> +
>> +        switch (chan->address) {
>> +        case VZ89X_VOC_CO2_IDX:
>> +        case VZ89X_VOC_SHORT_IDX:
>> +        case VZ89X_VOC_TVOC_IDX:
>> +            *val = data->buffer[chan->address];
>> +            return IIO_VAL_INT;
>> +        case VZ89X_VOC_RESISTANCE_IDX:
>> +            *val = vz89x_get_resistance_reading(data);
>> +            return IIO_VAL_INT;
>> +        default:
>> +            return -EINVAL;
>> +        }
>> +        break;
>> +    case IIO_CHAN_INFO_SCALE:
>> +        switch (chan->type) {
>> +        case IIO_RESISTANCE:
>> +            *val = 10;
>> +            return IIO_VAL_INT;
>> +        default:
>> +            return -EINVAL;
>> +        }
>> +        break;
>> +    case IIO_CHAN_INFO_OFFSET:
>> +        switch (chan->address) {
>> +        case VZ89X_VOC_CO2_IDX:
>> +            *val = 44;
>> +            *val2 = 250000;
>> +            return IIO_VAL_INT_PLUS_MICRO;
>> +        case VZ89X_VOC_TVOC_IDX:
>> +            *val = -13;
>> +            return IIO_VAL_INT;
>> +        default:
>> +            return -EINVAL;
>> +        }
>> +    }
>> +
>> +    return ret;
>> +}
>> +
>> +static const struct iio_info vz89x_info = {
>> +    .attrs        = &vz89x_attrs_group,
>> +    .read_raw    = vz89x_read_raw,
>> +    .driver_module    = THIS_MODULE,
>> +};
>> +
>> +static int vz89x_probe(struct i2c_client *client,
>> +               const struct i2c_device_id *id)
>> +{
>> +    struct iio_dev *indio_dev;
>> +    struct vz89x_data *data;
>> +
>> +    if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
>> +                     I2C_FUNC_SMBUS_BYTE))
>> +        return -ENODEV;
>> +
>> +    indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>> +    if (!indio_dev)
>> +        return -ENOMEM;
>> +
>> +    data = iio_priv(indio_dev);
>> +    i2c_set_clientdata(client, indio_dev);
>> +    data->client = client;
>> +    data->last_update = jiffies - HZ;
>> +    mutex_init(&data->lock);
>> +
>> +    indio_dev->dev.parent = &client->dev;
>> +    indio_dev->info = &vz89x_info,
>> +    indio_dev->name = dev_name(&client->dev);
>> +    indio_dev->modes = INDIO_DIRECT_MODE;
>> +
>> +    indio_dev->channels = vz89x_channels;
>> +    indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
>> +
>> +    return devm_iio_device_register(&client->dev, indio_dev);
>> +}
>> +
>> +static const struct i2c_device_id vz89x_id[] = {
>> +    { "vz89x", 0 },
>> +    { }
>> +};
>> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
>> +
>> +static const struct of_device_id vz89x_dt_ids[] = {
>> +    { .compatible = "sgx,vz89x" },
>> +    { }
>> +};
>> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
>> +
>> +static struct i2c_driver vz89x_driver = {
>> +    .driver = {
>> +        .name    = "vz89x",
>> +        .of_match_table = of_match_ptr(vz89x_dt_ids),
>> +    },
>> +    .probe = vz89x_probe,
>> +    .id_table = vz89x_id,
>> +};
>> +module_i2c_driver(vz89x_driver);
>> +
>> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
>> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
>> +MODULE_LICENSE("GPL v2");
> 
> -- 
> 
> Peter Meerwald
> +43-664-2444418 (mobile)

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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-14  8:35   ` Peter Meerwald
  2015-09-14 15:22     ` Matt Ranostay
@ 2015-09-15  2:55     ` Matt Ranostay
  2015-09-20 19:02     ` Jonathan Cameron
  2 siblings, 0 replies; 17+ messages in thread
From: Matt Ranostay @ 2015-09-15  2:55 UTC (permalink / raw)
  To: Peter Meerwald; +Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio

On Mon, Sep 14, 2015 at 1:35 AM, Peter Meerwald <pmeerw@pmeerw.net> wrote:
>
>> Add support for VZ89X sensors VOC and CO2 reporting channels in
>> percentage which can be converted to part per million.
>
> can you make the proper changes for _CONCENTRATION etc. also for
> tools/iio/iio_event_monitor.c?

should this include modifiers?
>
> and comment below
>
>> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
>> ---
>>  .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>>  .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>>  drivers/iio/Kconfig                                |   1 +
>>  drivers/iio/Makefile                               |   1 +
>>  drivers/iio/chemical/Kconfig                       |  15 ++
>>  drivers/iio/chemical/Makefile                      |   6 +
>>  drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>>  7 files changed, 268 insertions(+)
>>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>  create mode 100644 drivers/iio/chemical/Kconfig
>>  create mode 100644 drivers/iio/chemical/Makefile
>>  create mode 100644 drivers/iio/chemical/vz89x.c
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> new file mode 100644
>> index 0000000..c0c1ea9
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> @@ -0,0 +1,7 @@
>> +What:                /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
>> +Date:                September 2015
>> +KernelVersion:       4.3
>> +Contact:     Matt Ranostay <mranostay@gmail.com>
>> +Description:
>> +             Get the raw calibration VOC value from the sensor.
>> +             This value has little application outside of calibration.
>> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> index d77d412..a550216 100644
>> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> @@ -88,6 +88,7 @@ ricoh,rs5c372b              I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  ricoh,rv5c386                I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  ricoh,rv5c387a               I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  samsung,24ad0xd1     S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
>> +sgx,vz89x            SGX Sensortech VZ89X Sensors
>>  sii,s35390a          2-wire CMOS real-time clock
>>  skyworks,sky81452    Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>>  st-micro,24c256              i2c serial eeprom  (24cxx)
>> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
>> index 4011eff..9664e9c 100644
>> --- a/drivers/iio/Kconfig
>> +++ b/drivers/iio/Kconfig
>> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>>  source "drivers/iio/accel/Kconfig"
>>  source "drivers/iio/adc/Kconfig"
>>  source "drivers/iio/amplifiers/Kconfig"
>> +source "drivers/iio/chemical/Kconfig"
>>  source "drivers/iio/common/Kconfig"
>>  source "drivers/iio/dac/Kconfig"
>>  source "drivers/iio/frequency/Kconfig"
>> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
>> index 698afc2..2288684 100644
>> --- a/drivers/iio/Makefile
>> +++ b/drivers/iio/Makefile
>> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>>  obj-y += accel/
>>  obj-y += adc/
>>  obj-y += amplifiers/
>> +obj-y += chemical/
>>  obj-y += common/
>>  obj-y += dac/
>>  obj-y += gyro/
>> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
>> new file mode 100644
>> index 0000000..04906af
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Kconfig
>> @@ -0,0 +1,15 @@
>> +#
>> +# Chemical sensors
>> +#
>> +
>> +menu "Indoor Air Quality sensors"
>
> the comment above says 'Chemical sensors', the menu item 'Indoor Air
> Quality sensors' -- I guess an outdoor sensor would fit here as well...
>
>> +
>> +config VZ89X
>> +     tristate "SGX Sensortech MiCS VZ89X VOC sensor"
>> +     depends on I2C
>> +     help
>> +       Say Y here to build I2C interface support for the SGX
>> +       Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
>> +       sensors
>> +
>> +endmenu
>> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
>> new file mode 100644
>> index 0000000..7292f2d
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Makefile
>> @@ -0,0 +1,6 @@
>> +#
>> +# Makefile for IIO chemical sensors
>> +#
>> +
>> +# When adding new entries keep the list in alphabetical order
>> +obj-$(CONFIG_VZ89X)          += vz89x.o
>> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
>> new file mode 100644
>> index 0000000..b454200
>> --- /dev/null
>> +++ b/drivers/iio/chemical/vz89x.c
>> @@ -0,0 +1,237 @@
>> +/*
>> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
>> + *
>> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/init.h>
>> +#include <linux/i2c.h>
>> +
>> +#include <linux/iio/iio.h>
>> +#include <linux/iio/sysfs.h>
>> +
>> +#define VZ89X_REG_MEASUREMENT                0x09
>> +#define VZ89X_REG_MEASUREMENT_SIZE   6
>> +
>> +#define VZ89X_VOC_CO2_IDX            0
>> +#define VZ89X_VOC_SHORT_IDX          1
>> +#define VZ89X_VOC_TVOC_IDX           2
>> +#define VZ89X_VOC_RESISTANCE_IDX     3
>> +
>> +struct vz89x_data {
>> +     struct i2c_client *client;
>> +     struct mutex lock;
>> +     unsigned long last_update;
>> +
>> +     u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
>> +};
>> +
>> +static const struct iio_chan_spec vz89x_channels[] = {
>> +     {
>> +             .type = IIO_CONCENTRATION,
>> +             .channel2 = IIO_MOD_CO2,
>> +             .modified = 1,
>> +             .info_mask_separate =
>> +                     BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +             .address = VZ89X_VOC_CO2_IDX,
>> +     },
>> +     {
>> +             .type = IIO_CONCENTRATION,
>> +             .channel2 = IIO_MOD_VOC,
>> +             .modified = 1,
>> +             .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>> +             .address = VZ89X_VOC_SHORT_IDX,
>> +             .extend_name = "short",
>> +     },
>> +     {
>> +             .type = IIO_CONCENTRATION,
>> +             .channel2 = IIO_MOD_VOC,
>> +             .modified = 1,
>> +             .info_mask_separate =
>> +                     BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +             .address = VZ89X_VOC_TVOC_IDX,
>> +     },
>> +     {
>> +             .type = IIO_RESISTANCE,
>> +             .info_mask_separate =
>> +                     BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>> +             .address = VZ89X_VOC_RESISTANCE_IDX,
>> +     },
>> +};
>> +
>> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
>> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
>> +
>> +static struct attribute *vz89x_attributes[] = {
>> +     &iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
>> +     &iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
>> +     NULL,
>> +};
>> +
>> +static const struct attribute_group vz89x_attrs_group = {
>> +     .attrs = vz89x_attributes,
>> +};
>> +
>> +static int vz89x_get_measurement(struct vz89x_data *data)
>> +{
>> +     int ret;
>> +     int i;
>> +
>> +     /* sensor can only be polled once a second max per datasheet */
>> +     if (!time_after(jiffies, data->last_update + HZ))
>> +             return 0;
>> +
>> +     ret = i2c_smbus_write_word_data(data->client,
>> +                                     VZ89X_REG_MEASUREMENT, 0);
>> +     if (ret < 0)
>> +             return ret;
>> +
>> +     for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
>> +             ret = i2c_smbus_read_byte(data->client);
>> +             if (ret < 0)
>> +                     return ret;
>> +             data->buffer[i] = ret;
>> +     }
>> +
>> +     data->last_update = jiffies;
>> +
>> +     return 0;
>> +}
>> +
>> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
>> +{
>> +     u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
>> +
>> +     return buf[0] | (buf[1] << 8) | (buf[2] << 16);
>> +}
>> +
>> +static int vz89x_read_raw(struct iio_dev *indio_dev,
>> +                       struct iio_chan_spec const *chan, int *val,
>> +                       int *val2, long mask)
>> +{
>> +     struct vz89x_data *data = iio_priv(indio_dev);
>> +     int ret = -EINVAL;
>> +
>> +     switch (mask) {
>> +     case IIO_CHAN_INFO_RAW:
>> +             mutex_lock(&data->lock);
>> +             ret = vz89x_get_measurement(data);
>> +             mutex_unlock(&data->lock);
>> +
>> +             if (ret)
>> +                     return ret;
>> +
>> +             switch (chan->address) {
>> +             case VZ89X_VOC_CO2_IDX:
>> +             case VZ89X_VOC_SHORT_IDX:
>> +             case VZ89X_VOC_TVOC_IDX:
>> +                     *val = data->buffer[chan->address];
>> +                     return IIO_VAL_INT;
>> +             case VZ89X_VOC_RESISTANCE_IDX:
>> +                     *val = vz89x_get_resistance_reading(data);
>> +                     return IIO_VAL_INT;
>> +             default:
>> +                     return -EINVAL;
>> +             }
>> +             break;
>> +     case IIO_CHAN_INFO_SCALE:
>> +             switch (chan->type) {
>> +             case IIO_RESISTANCE:
>> +                     *val = 10;
>> +                     return IIO_VAL_INT;
>> +             default:
>> +                     return -EINVAL;
>> +             }
>> +             break;
>> +     case IIO_CHAN_INFO_OFFSET:
>> +             switch (chan->address) {
>> +             case VZ89X_VOC_CO2_IDX:
>> +                     *val = 44;
>> +                     *val2 = 250000;
>> +                     return IIO_VAL_INT_PLUS_MICRO;
>> +             case VZ89X_VOC_TVOC_IDX:
>> +                     *val = -13;
>> +                     return IIO_VAL_INT;
>> +             default:
>> +                     return -EINVAL;
>> +             }
>> +     }
>> +
>> +     return ret;
>> +}
>> +
>> +static const struct iio_info vz89x_info = {
>> +     .attrs          = &vz89x_attrs_group,
>> +     .read_raw       = vz89x_read_raw,
>> +     .driver_module  = THIS_MODULE,
>> +};
>> +
>> +static int vz89x_probe(struct i2c_client *client,
>> +                    const struct i2c_device_id *id)
>> +{
>> +     struct iio_dev *indio_dev;
>> +     struct vz89x_data *data;
>> +
>> +     if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
>> +                                  I2C_FUNC_SMBUS_BYTE))
>> +             return -ENODEV;
>> +
>> +     indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>> +     if (!indio_dev)
>> +             return -ENOMEM;
>> +
>> +     data = iio_priv(indio_dev);
>> +     i2c_set_clientdata(client, indio_dev);
>> +     data->client = client;
>> +     data->last_update = jiffies - HZ;
>> +     mutex_init(&data->lock);
>> +
>> +     indio_dev->dev.parent = &client->dev;
>> +     indio_dev->info = &vz89x_info,
>> +     indio_dev->name = dev_name(&client->dev);
>> +     indio_dev->modes = INDIO_DIRECT_MODE;
>> +
>> +     indio_dev->channels = vz89x_channels;
>> +     indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
>> +
>> +     return devm_iio_device_register(&client->dev, indio_dev);
>> +}
>> +
>> +static const struct i2c_device_id vz89x_id[] = {
>> +     { "vz89x", 0 },
>> +     { }
>> +};
>> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
>> +
>> +static const struct of_device_id vz89x_dt_ids[] = {
>> +     { .compatible = "sgx,vz89x" },
>> +     { }
>> +};
>> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
>> +
>> +static struct i2c_driver vz89x_driver = {
>> +     .driver = {
>> +             .name   = "vz89x",
>> +             .of_match_table = of_match_ptr(vz89x_dt_ids),
>> +     },
>> +     .probe = vz89x_probe,
>> +     .id_table = vz89x_id,
>> +};
>> +module_i2c_driver(vz89x_driver);
>> +
>> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
>> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
>> +MODULE_LICENSE("GPL v2");
>>
>
> --
>
> Peter Meerwald
> +43-664-2444418 (mobile)

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

* Re: [PATCH v5 1/4] iio: chemical: Add IIO_CONCENTRATION channel type
@ 2015-09-20 18:55     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 18:55 UTC (permalink / raw)
  To: Matt Ranostay, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree

On 14/09/15 04:26, Matt Ranostay wrote:
> There are air quality sensors that report data back in parts per million
> of VOC (Volatile Organic Compounds) which are usually indexed from CO2
> or another common pollutant.
> 
> This patchset adds an IIO_CONCENTRATION type that returns a percentage
> of substance because no other channels types fit this use case.
> Modifiers for IIO_MOD_CO2 and IIO_MOD_VOC gas types are defined.
> 
> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
Applied to the togreg branch of iio.git - initially pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 11 +++++++++++
>  drivers/iio/industrialio-core.c         |  3 +++
>  include/uapi/linux/iio/types.h          |  3 +++
>  3 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 42d360f..682c070 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1459,3 +1459,14 @@ Description:
>  		measurements and return the average value as output data. Each
>  		value resulted from <type>[_name]_oversampling_ratio measurements
>  		is considered as one sample for <type>[_name]_sampling_frequency.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_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
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Raw (unscaled no offset etc.) percentage reading of a substance.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index b3fcc2c..8eb6064 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -75,6 +75,7 @@ static const char * const iio_chan_type_name_spec[] = {
>  	[IIO_ENERGY] = "energy",
>  	[IIO_DISTANCE] = "distance",
>  	[IIO_VELOCITY] = "velocity",
> +	[IIO_CONCENTRATION] = "concentration",
>  };
>  
>  static const char * const iio_modifier_names[] = {
> @@ -111,6 +112,8 @@ static const char * const iio_modifier_names[] = {
>  	[IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
>  	[IIO_MOD_I] = "i",
>  	[IIO_MOD_Q] = "q",
> +	[IIO_MOD_CO2] = "co2",
> +	[IIO_MOD_VOC] = "voc",
>  };
>  
>  /* 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 2f8b117..1e4c4e3 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -35,6 +35,7 @@ enum iio_chan_type {
>  	IIO_ENERGY,
>  	IIO_DISTANCE,
>  	IIO_VELOCITY,
> +	IIO_CONCENTRATION,
>  };
>  
>  enum iio_modifier {
> @@ -72,6 +73,8 @@ enum iio_modifier {
>  	IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
>  	IIO_MOD_I,
>  	IIO_MOD_Q,
> +	IIO_MOD_CO2,
> +	IIO_MOD_VOC,
>  };
>  
>  enum iio_event_type {
> 


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

* Re: [PATCH v5 1/4] iio: chemical: Add IIO_CONCENTRATION channel type
@ 2015-09-20 18:55     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 18:55 UTC (permalink / raw)
  To: Matt Ranostay, lars-Qo5EllUWu/uELgA04lAiVw,
	pmeerw-jW+XmwGofnusTnJN9+BGXg
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 14/09/15 04:26, Matt Ranostay wrote:
> There are air quality sensors that report data back in parts per million
> of VOC (Volatile Organic Compounds) which are usually indexed from CO2
> or another common pollutant.
> 
> This patchset adds an IIO_CONCENTRATION type that returns a percentage
> of substance because no other channels types fit this use case.
> Modifiers for IIO_MOD_CO2 and IIO_MOD_VOC gas types are defined.
> 
> Signed-off-by: Matt Ranostay <mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied to the togreg branch of iio.git - initially pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 11 +++++++++++
>  drivers/iio/industrialio-core.c         |  3 +++
>  include/uapi/linux/iio/types.h          |  3 +++
>  3 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 42d360f..682c070 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1459,3 +1459,14 @@ Description:
>  		measurements and return the average value as output data. Each
>  		value resulted from <type>[_name]_oversampling_ratio measurements
>  		is considered as one sample for <type>[_name]_sampling_frequency.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_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
> +Contact:	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> +Description:
> +		Raw (unscaled no offset etc.) percentage reading of a substance.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index b3fcc2c..8eb6064 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -75,6 +75,7 @@ static const char * const iio_chan_type_name_spec[] = {
>  	[IIO_ENERGY] = "energy",
>  	[IIO_DISTANCE] = "distance",
>  	[IIO_VELOCITY] = "velocity",
> +	[IIO_CONCENTRATION] = "concentration",
>  };
>  
>  static const char * const iio_modifier_names[] = {
> @@ -111,6 +112,8 @@ static const char * const iio_modifier_names[] = {
>  	[IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
>  	[IIO_MOD_I] = "i",
>  	[IIO_MOD_Q] = "q",
> +	[IIO_MOD_CO2] = "co2",
> +	[IIO_MOD_VOC] = "voc",
>  };
>  
>  /* 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 2f8b117..1e4c4e3 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -35,6 +35,7 @@ enum iio_chan_type {
>  	IIO_ENERGY,
>  	IIO_DISTANCE,
>  	IIO_VELOCITY,
> +	IIO_CONCENTRATION,
>  };
>  
>  enum iio_modifier {
> @@ -72,6 +73,8 @@ enum iio_modifier {
>  	IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
>  	IIO_MOD_I,
>  	IIO_MOD_Q,
> +	IIO_MOD_CO2,
> +	IIO_MOD_VOC,
>  };
>  
>  enum iio_event_type {
> 

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

* Re: [PATCH v5 2/4] iio: resistance: add IIO_RESISTANCE channel type
@ 2015-09-20 18:55     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 18:55 UTC (permalink / raw)
  To: Matt Ranostay, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree

On 14/09/15 04:26, Matt Ranostay wrote:
> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
Applied to the togreg branch of iio.git - initially pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan
> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 8 ++++++++
>  drivers/iio/industrialio-core.c         | 1 +
>  include/uapi/linux/iio/types.h          | 1 +
>  3 files changed, 10 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 682c070..a91af51 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1470,3 +1470,11 @@ KernelVersion:	4.3
>  Contact:	linux-iio@vger.kernel.org
>  Description:
>  		Raw (unscaled no offset etc.) percentage reading of a substance.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_resistance_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
> +KernelVersion:	4.3
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Raw (unscaled no offset etc.) resistance reading that can be processed
> +		into an ohm value.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 8eb6064..80439a6 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -76,6 +76,7 @@ static const char * const iio_chan_type_name_spec[] = {
>  	[IIO_DISTANCE] = "distance",
>  	[IIO_VELOCITY] = "velocity",
>  	[IIO_CONCENTRATION] = "concentration",
> +	[IIO_RESISTANCE] = "resistance",
>  };
>  
>  static const char * const iio_modifier_names[] = {
> diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
> index 1e4c4e3..7c63bd6 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -36,6 +36,7 @@ enum iio_chan_type {
>  	IIO_DISTANCE,
>  	IIO_VELOCITY,
>  	IIO_CONCENTRATION,
> +	IIO_RESISTANCE,
>  };
>  
>  enum iio_modifier {
> 


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

* Re: [PATCH v5 2/4] iio: resistance: add IIO_RESISTANCE channel type
@ 2015-09-20 18:55     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 18:55 UTC (permalink / raw)
  To: Matt Ranostay, lars-Qo5EllUWu/uELgA04lAiVw,
	pmeerw-jW+XmwGofnusTnJN9+BGXg
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On 14/09/15 04:26, Matt Ranostay wrote:
> Signed-off-by: Matt Ranostay <mranostay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied to the togreg branch of iio.git - initially pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan
> ---
>  Documentation/ABI/testing/sysfs-bus-iio | 8 ++++++++
>  drivers/iio/industrialio-core.c         | 1 +
>  include/uapi/linux/iio/types.h          | 1 +
>  3 files changed, 10 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
> index 682c070..a91af51 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio
> +++ b/Documentation/ABI/testing/sysfs-bus-iio
> @@ -1470,3 +1470,11 @@ KernelVersion:	4.3
>  Contact:	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>  Description:
>  		Raw (unscaled no offset etc.) percentage reading of a substance.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_resistance_raw
> +What:		/sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
> +KernelVersion:	4.3
> +Contact:	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> +Description:
> +		Raw (unscaled no offset etc.) resistance reading that can be processed
> +		into an ohm value.
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 8eb6064..80439a6 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -76,6 +76,7 @@ static const char * const iio_chan_type_name_spec[] = {
>  	[IIO_DISTANCE] = "distance",
>  	[IIO_VELOCITY] = "velocity",
>  	[IIO_CONCENTRATION] = "concentration",
> +	[IIO_RESISTANCE] = "resistance",
>  };
>  
>  static const char * const iio_modifier_names[] = {
> diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
> index 1e4c4e3..7c63bd6 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -36,6 +36,7 @@ enum iio_chan_type {
>  	IIO_DISTANCE,
>  	IIO_VELOCITY,
>  	IIO_CONCENTRATION,
> +	IIO_RESISTANCE,
>  };
>  
>  enum iio_modifier {
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v5 3/4] devicetree: add SGX Sensortech vendor id
  2015-09-14  3:26 ` [PATCH v5 3/4] devicetree: add SGX Sensortech vendor id Matt Ranostay
@ 2015-09-20 18:58   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 18:58 UTC (permalink / raw)
  To: Matt Ranostay, lars, pmeerw; +Cc: linux-iio, linux-kernel, devicetree

On 14/09/15 04:26, Matt Ranostay wrote:
> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
Applied. Note there was fuzz in my tree as I am lagging mainline
somewhat.  However it is pretty obvious how to fix up merge
issues in this file so lets not worry about that ;)

Jonathan
> ---
>  Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
> index ac5f0c3..281e8f0 100644
> --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
> +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
> @@ -191,6 +191,7 @@ sbs	Smart Battery System
>  schindler	Schindler
>  seagate	Seagate Technology PLC
>  semtech	Semtech Corporation
> +sgx	SGX Sensortech
>  sharp	Sharp Corporation
>  sil	Silicon Image
>  silabs	Silicon Laboratories
> 


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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-14  8:35   ` Peter Meerwald
  2015-09-14 15:22     ` Matt Ranostay
  2015-09-15  2:55     ` Matt Ranostay
@ 2015-09-20 19:02     ` Jonathan Cameron
  2015-09-23  3:42       ` Matt Ranostay
  2 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron @ 2015-09-20 19:02 UTC (permalink / raw)
  To: Peter Meerwald, Matt Ranostay; +Cc: lars, linux-iio

On 14/09/15 09:35, Peter Meerwald wrote:
> 
>> Add support for VZ89X sensors VOC and CO2 reporting channels in
>> percentage which can be converted to part per million.
> 
> can you make the proper changes for _CONCENTRATION etc. also for 
> tools/iio/iio_event_monitor.c?
Rather than going through another complete version of this series,
would you mind doing that as a follow up patch?

> 
> and comment below
I've fixed this up as chemical sensors when applying.
>  
>> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
>> ---
>>  .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>>  .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>>  drivers/iio/Kconfig                                |   1 +
>>  drivers/iio/Makefile                               |   1 +
>>  drivers/iio/chemical/Kconfig                       |  15 ++
>>  drivers/iio/chemical/Makefile                      |   6 +
>>  drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>>  7 files changed, 268 insertions(+)
>>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>  create mode 100644 drivers/iio/chemical/Kconfig
>>  create mode 100644 drivers/iio/chemical/Makefile
>>  create mode 100644 drivers/iio/chemical/vz89x.c
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> new file mode 100644
>> index 0000000..c0c1ea9
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>> @@ -0,0 +1,7 @@
>> +What:		/sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
>> +Date:		September 2015
>> +KernelVersion:	4.3
>> +Contact:	Matt Ranostay <mranostay@gmail.com>
>> +Description:
>> +		Get the raw calibration VOC value from the sensor.
>> +		This value has little application outside of calibration.
>> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> index d77d412..a550216 100644
>> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>> @@ -88,6 +88,7 @@ ricoh,rs5c372b		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  ricoh,rv5c386		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  ricoh,rv5c387a		I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>  samsung,24ad0xd1	S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
>> +sgx,vz89x		SGX Sensortech VZ89X Sensors
>>  sii,s35390a		2-wire CMOS real-time clock
>>  skyworks,sky81452	Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>>  st-micro,24c256		i2c serial eeprom  (24cxx)
>> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
>> index 4011eff..9664e9c 100644
>> --- a/drivers/iio/Kconfig
>> +++ b/drivers/iio/Kconfig
>> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>>  source "drivers/iio/accel/Kconfig"
>>  source "drivers/iio/adc/Kconfig"
>>  source "drivers/iio/amplifiers/Kconfig"
>> +source "drivers/iio/chemical/Kconfig"
>>  source "drivers/iio/common/Kconfig"
>>  source "drivers/iio/dac/Kconfig"
>>  source "drivers/iio/frequency/Kconfig"
>> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
>> index 698afc2..2288684 100644
>> --- a/drivers/iio/Makefile
>> +++ b/drivers/iio/Makefile
>> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>>  obj-y += accel/
>>  obj-y += adc/
>>  obj-y += amplifiers/
>> +obj-y += chemical/
>>  obj-y += common/
>>  obj-y += dac/
>>  obj-y += gyro/
>> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
>> new file mode 100644
>> index 0000000..04906af
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Kconfig
>> @@ -0,0 +1,15 @@
>> +#
>> +# Chemical sensors
>> +#
>> +
>> +menu "Indoor Air Quality sensors"
> 
> the comment above says 'Chemical sensors', the menu item 'Indoor Air 
> Quality sensors' -- I guess an outdoor sensor would fit here as well...
Lets just go with Chemical sensors.
> 
>> +
>> +config VZ89X
>> +	tristate "SGX Sensortech MiCS VZ89X VOC sensor"
>> +	depends on I2C
>> +	help
>> +	  Say Y here to build I2C interface support for the SGX
>> +	  Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
>> +	  sensors
>> +
>> +endmenu
>> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
>> new file mode 100644
>> index 0000000..7292f2d
>> --- /dev/null
>> +++ b/drivers/iio/chemical/Makefile
>> @@ -0,0 +1,6 @@
>> +#
>> +# Makefile for IIO chemical sensors
>> +#
>> +
>> +# When adding new entries keep the list in alphabetical order
>> +obj-$(CONFIG_VZ89X)		+= vz89x.o
>> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
>> new file mode 100644
>> index 0000000..b454200
>> --- /dev/null
>> +++ b/drivers/iio/chemical/vz89x.c
>> @@ -0,0 +1,237 @@
>> +/*
>> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
>> + *
>> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>> +
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/init.h>
>> +#include <linux/i2c.h>
>> +
>> +#include <linux/iio/iio.h>
>> +#include <linux/iio/sysfs.h>
>> +
>> +#define VZ89X_REG_MEASUREMENT		0x09
>> +#define VZ89X_REG_MEASUREMENT_SIZE	6
>> +
>> +#define VZ89X_VOC_CO2_IDX		0
>> +#define VZ89X_VOC_SHORT_IDX		1
>> +#define VZ89X_VOC_TVOC_IDX		2
>> +#define VZ89X_VOC_RESISTANCE_IDX	3
>> +
>> +struct vz89x_data {
>> +	struct i2c_client *client;
>> +	struct mutex lock;
>> +	unsigned long last_update;
>> +
>> +	u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
>> +};
>> +
>> +static const struct iio_chan_spec vz89x_channels[] = {
>> +	{
>> +		.type = IIO_CONCENTRATION,
>> +		.channel2 = IIO_MOD_CO2,
>> +		.modified = 1,
>> +		.info_mask_separate =
>> +			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +		.address = VZ89X_VOC_CO2_IDX,
>> +	},
>> +	{
>> +		.type = IIO_CONCENTRATION,
>> +		.channel2 = IIO_MOD_VOC,
>> +		.modified = 1,
>> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>> +		.address = VZ89X_VOC_SHORT_IDX,
>> +		.extend_name = "short",
>> +	},
>> +	{
>> +		.type = IIO_CONCENTRATION,
>> +		.channel2 = IIO_MOD_VOC,
>> +		.modified = 1,
>> +		.info_mask_separate =
>> +			BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>> +		.address = VZ89X_VOC_TVOC_IDX,
>> +	},
>> +	{
>> +		.type = IIO_RESISTANCE,
>> +		.info_mask_separate =
>> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>> +		.address = VZ89X_VOC_RESISTANCE_IDX,
>> +	},
>> +};
>> +
>> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
>> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
>> +
>> +static struct attribute *vz89x_attributes[] = {
>> +	&iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
>> +	&iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
>> +	NULL,
>> +};
>> +
>> +static const struct attribute_group vz89x_attrs_group = {
>> +	.attrs = vz89x_attributes,
>> +};
>> +
>> +static int vz89x_get_measurement(struct vz89x_data *data)
>> +{
>> +	int ret;
>> +	int i;
>> +
>> +	/* sensor can only be polled once a second max per datasheet */
>> +	if (!time_after(jiffies, data->last_update + HZ))
>> +		return 0;
>> +
>> +	ret = i2c_smbus_write_word_data(data->client,
>> +					VZ89X_REG_MEASUREMENT, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
>> +		ret = i2c_smbus_read_byte(data->client);
>> +		if (ret < 0)
>> +			return ret;
>> +		data->buffer[i] = ret;
>> +	}
>> +
>> +	data->last_update = jiffies;
>> +
>> +	return 0;
>> +}
>> +
>> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
>> +{
>> +	u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
>> +
>> +	return buf[0] | (buf[1] << 8) | (buf[2] << 16);
>> +}
>> +
>> +static int vz89x_read_raw(struct iio_dev *indio_dev,
>> +			  struct iio_chan_spec const *chan, int *val,
>> +			  int *val2, long mask)
>> +{
>> +	struct vz89x_data *data = iio_priv(indio_dev);
>> +	int ret = -EINVAL;
>> +
>> +	switch (mask) {
>> +	case IIO_CHAN_INFO_RAW:
>> +		mutex_lock(&data->lock);
>> +		ret = vz89x_get_measurement(data);
>> +		mutex_unlock(&data->lock);
>> +
>> +		if (ret)
>> +			return ret;
>> +
>> +		switch (chan->address) {
>> +		case VZ89X_VOC_CO2_IDX:
>> +		case VZ89X_VOC_SHORT_IDX:
>> +		case VZ89X_VOC_TVOC_IDX:
>> +			*val = data->buffer[chan->address];
>> +			return IIO_VAL_INT;
>> +		case VZ89X_VOC_RESISTANCE_IDX:
>> +			*val = vz89x_get_resistance_reading(data);
>> +			return IIO_VAL_INT;
>> +		default:
>> +			return -EINVAL;
>> +		}
>> +		break;
>> +	case IIO_CHAN_INFO_SCALE:
>> +		switch (chan->type) {
>> +		case IIO_RESISTANCE:
>> +			*val = 10;
>> +			return IIO_VAL_INT;
>> +		default:
>> +			return -EINVAL;
>> +		}
>> +		break;
>> +	case IIO_CHAN_INFO_OFFSET:
>> +		switch (chan->address) {
>> +		case VZ89X_VOC_CO2_IDX:
>> +			*val = 44;
>> +			*val2 = 250000;
>> +			return IIO_VAL_INT_PLUS_MICRO;
>> +		case VZ89X_VOC_TVOC_IDX:
>> +			*val = -13;
>> +			return IIO_VAL_INT;
>> +		default:
>> +			return -EINVAL;
>> +		}
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>> +static const struct iio_info vz89x_info = {
>> +	.attrs		= &vz89x_attrs_group,
>> +	.read_raw	= vz89x_read_raw,
>> +	.driver_module	= THIS_MODULE,
>> +};
>> +
>> +static int vz89x_probe(struct i2c_client *client,
>> +		       const struct i2c_device_id *id)
>> +{
>> +	struct iio_dev *indio_dev;
>> +	struct vz89x_data *data;
>> +
>> +	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
>> +				     I2C_FUNC_SMBUS_BYTE))
>> +		return -ENODEV;
>> +
>> +	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>> +	if (!indio_dev)
>> +		return -ENOMEM;
>> +
>> +	data = iio_priv(indio_dev);
>> +	i2c_set_clientdata(client, indio_dev);
>> +	data->client = client;
>> +	data->last_update = jiffies - HZ;
>> +	mutex_init(&data->lock);
>> +
>> +	indio_dev->dev.parent = &client->dev;
>> +	indio_dev->info = &vz89x_info,
>> +	indio_dev->name = dev_name(&client->dev);
>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>> +
>> +	indio_dev->channels = vz89x_channels;
>> +	indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
>> +
>> +	return devm_iio_device_register(&client->dev, indio_dev);
>> +}
>> +
>> +static const struct i2c_device_id vz89x_id[] = {
>> +	{ "vz89x", 0 },
>> +	{ }
>> +};
>> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
>> +
>> +static const struct of_device_id vz89x_dt_ids[] = {
>> +	{ .compatible = "sgx,vz89x" },
>> +	{ }
>> +};
>> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
>> +
>> +static struct i2c_driver vz89x_driver = {
>> +	.driver = {
>> +		.name	= "vz89x",
>> +		.of_match_table = of_match_ptr(vz89x_dt_ids),
>> +	},
>> +	.probe = vz89x_probe,
>> +	.id_table = vz89x_id,
>> +};
>> +module_i2c_driver(vz89x_driver);
>> +
>> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
>> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
>> +MODULE_LICENSE("GPL v2");
>>
> 


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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-20 19:02     ` Jonathan Cameron
@ 2015-09-23  3:42       ` Matt Ranostay
  2015-09-23  3:46         ` Matt Ranostay
  0 siblings, 1 reply; 17+ messages in thread
From: Matt Ranostay @ 2015-09-23  3:42 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Peter Meerwald, Lars-Peter Clausen, linux-iio

On Sun, Sep 20, 2015 at 12:02 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 14/09/15 09:35, Peter Meerwald wrote:
>>
>>> Add support for VZ89X sensors VOC and CO2 reporting channels in
>>> percentage which can be converted to part per million.
>>
>> can you make the proper changes for _CONCENTRATION etc. also for
>> tools/iio/iio_event_monitor.c?
> Rather than going through another complete version of this series,
> would you mind doing that as a follow up patch?
I'll do it as a follow on unless see below....  should IIO_RESISTANCE
to iio_event_monitor.c be added as well?


>
>>
>> and comment below
> I've fixed this up as chemical sensors when applying.

Actually have found a HW bug that affects one in like 1000 reads. Need
to submit one more series to workaround it.... so should I add the
previous to the next version?

>>
>>> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
>>> ---
>>>  .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>>>  .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>>>  drivers/iio/Kconfig                                |   1 +
>>>  drivers/iio/Makefile                               |   1 +
>>>  drivers/iio/chemical/Kconfig                       |  15 ++
>>>  drivers/iio/chemical/Makefile                      |   6 +
>>>  drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>>>  7 files changed, 268 insertions(+)
>>>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>>  create mode 100644 drivers/iio/chemical/Kconfig
>>>  create mode 100644 drivers/iio/chemical/Makefile
>>>  create mode 100644 drivers/iio/chemical/vz89x.c
>>>
>>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>> new file mode 100644
>>> index 0000000..c0c1ea9
>>> --- /dev/null
>>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>> @@ -0,0 +1,7 @@
>>> +What:               /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
>>> +Date:               September 2015
>>> +KernelVersion:      4.3
>>> +Contact:    Matt Ranostay <mranostay@gmail.com>
>>> +Description:
>>> +            Get the raw calibration VOC value from the sensor.
>>> +            This value has little application outside of calibration.
>>> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>> index d77d412..a550216 100644
>>> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>> @@ -88,6 +88,7 @@ ricoh,rs5c372b             I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>  ricoh,rv5c386               I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>  ricoh,rv5c387a              I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>  samsung,24ad0xd1    S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
>>> +sgx,vz89x           SGX Sensortech VZ89X Sensors
>>>  sii,s35390a         2-wire CMOS real-time clock
>>>  skyworks,sky81452   Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>>>  st-micro,24c256             i2c serial eeprom  (24cxx)
>>> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
>>> index 4011eff..9664e9c 100644
>>> --- a/drivers/iio/Kconfig
>>> +++ b/drivers/iio/Kconfig
>>> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>>>  source "drivers/iio/accel/Kconfig"
>>>  source "drivers/iio/adc/Kconfig"
>>>  source "drivers/iio/amplifiers/Kconfig"
>>> +source "drivers/iio/chemical/Kconfig"
>>>  source "drivers/iio/common/Kconfig"
>>>  source "drivers/iio/dac/Kconfig"
>>>  source "drivers/iio/frequency/Kconfig"
>>> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
>>> index 698afc2..2288684 100644
>>> --- a/drivers/iio/Makefile
>>> +++ b/drivers/iio/Makefile
>>> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>>>  obj-y += accel/
>>>  obj-y += adc/
>>>  obj-y += amplifiers/
>>> +obj-y += chemical/
>>>  obj-y += common/
>>>  obj-y += dac/
>>>  obj-y += gyro/
>>> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
>>> new file mode 100644
>>> index 0000000..04906af
>>> --- /dev/null
>>> +++ b/drivers/iio/chemical/Kconfig
>>> @@ -0,0 +1,15 @@
>>> +#
>>> +# Chemical sensors
>>> +#
>>> +
>>> +menu "Indoor Air Quality sensors"
>>
>> the comment above says 'Chemical sensors', the menu item 'Indoor Air
>> Quality sensors' -- I guess an outdoor sensor would fit here as well...
> Lets just go with Chemical sensors.



>>
>>> +
>>> +config VZ89X
>>> +    tristate "SGX Sensortech MiCS VZ89X VOC sensor"
>>> +    depends on I2C
>>> +    help
>>> +      Say Y here to build I2C interface support for the SGX
>>> +      Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
>>> +      sensors
>>> +
>>> +endmenu
>>> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
>>> new file mode 100644
>>> index 0000000..7292f2d
>>> --- /dev/null
>>> +++ b/drivers/iio/chemical/Makefile
>>> @@ -0,0 +1,6 @@
>>> +#
>>> +# Makefile for IIO chemical sensors
>>> +#
>>> +
>>> +# When adding new entries keep the list in alphabetical order
>>> +obj-$(CONFIG_VZ89X)         += vz89x.o
>>> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
>>> new file mode 100644
>>> index 0000000..b454200
>>> --- /dev/null
>>> +++ b/drivers/iio/chemical/vz89x.c
>>> @@ -0,0 +1,237 @@
>>> +/*
>>> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
>>> + *
>>> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License as published by
>>> + * the Free Software Foundation; either version 2 of the License, or
>>> + * (at your option) any later version.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + */
>>> +
>>> +#include <linux/module.h>
>>> +#include <linux/mutex.h>
>>> +#include <linux/init.h>
>>> +#include <linux/i2c.h>
>>> +
>>> +#include <linux/iio/iio.h>
>>> +#include <linux/iio/sysfs.h>
>>> +
>>> +#define VZ89X_REG_MEASUREMENT               0x09
>>> +#define VZ89X_REG_MEASUREMENT_SIZE  6
>>> +
>>> +#define VZ89X_VOC_CO2_IDX           0
>>> +#define VZ89X_VOC_SHORT_IDX         1
>>> +#define VZ89X_VOC_TVOC_IDX          2
>>> +#define VZ89X_VOC_RESISTANCE_IDX    3
>>> +
>>> +struct vz89x_data {
>>> +    struct i2c_client *client;
>>> +    struct mutex lock;
>>> +    unsigned long last_update;
>>> +
>>> +    u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
>>> +};
>>> +
>>> +static const struct iio_chan_spec vz89x_channels[] = {
>>> +    {
>>> +            .type = IIO_CONCENTRATION,
>>> +            .channel2 = IIO_MOD_CO2,
>>> +            .modified = 1,
>>> +            .info_mask_separate =
>>> +                    BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>>> +            .address = VZ89X_VOC_CO2_IDX,
>>> +    },
>>> +    {
>>> +            .type = IIO_CONCENTRATION,
>>> +            .channel2 = IIO_MOD_VOC,
>>> +            .modified = 1,
>>> +            .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>>> +            .address = VZ89X_VOC_SHORT_IDX,
>>> +            .extend_name = "short",
>>> +    },
>>> +    {
>>> +            .type = IIO_CONCENTRATION,
>>> +            .channel2 = IIO_MOD_VOC,
>>> +            .modified = 1,
>>> +            .info_mask_separate =
>>> +                    BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>>> +            .address = VZ89X_VOC_TVOC_IDX,
>>> +    },
>>> +    {
>>> +            .type = IIO_RESISTANCE,
>>> +            .info_mask_separate =
>>> +                    BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>>> +            .address = VZ89X_VOC_RESISTANCE_IDX,
>>> +    },
>>> +};
>>> +
>>> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
>>> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
>>> +
>>> +static struct attribute *vz89x_attributes[] = {
>>> +    &iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
>>> +    &iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
>>> +    NULL,
>>> +};
>>> +
>>> +static const struct attribute_group vz89x_attrs_group = {
>>> +    .attrs = vz89x_attributes,
>>> +};
>>> +
>>> +static int vz89x_get_measurement(struct vz89x_data *data)
>>> +{
>>> +    int ret;
>>> +    int i;
>>> +
>>> +    /* sensor can only be polled once a second max per datasheet */
>>> +    if (!time_after(jiffies, data->last_update + HZ))
>>> +            return 0;
>>> +
>>> +    ret = i2c_smbus_write_word_data(data->client,
>>> +                                    VZ89X_REG_MEASUREMENT, 0);
>>> +    if (ret < 0)
>>> +            return ret;
>>> +
>>> +    for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
>>> +            ret = i2c_smbus_read_byte(data->client);
>>> +            if (ret < 0)
>>> +                    return ret;
>>> +            data->buffer[i] = ret;
>>> +    }
>>> +
>>> +    data->last_update = jiffies;
>>> +
>>> +    return 0;
>>> +}
>>> +
>>> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
>>> +{
>>> +    u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
>>> +
>>> +    return buf[0] | (buf[1] << 8) | (buf[2] << 16);
>>> +}
>>> +
>>> +static int vz89x_read_raw(struct iio_dev *indio_dev,
>>> +                      struct iio_chan_spec const *chan, int *val,
>>> +                      int *val2, long mask)
>>> +{
>>> +    struct vz89x_data *data = iio_priv(indio_dev);
>>> +    int ret = -EINVAL;
>>> +
>>> +    switch (mask) {
>>> +    case IIO_CHAN_INFO_RAW:
>>> +            mutex_lock(&data->lock);
>>> +            ret = vz89x_get_measurement(data);
>>> +            mutex_unlock(&data->lock);
>>> +
>>> +            if (ret)
>>> +                    return ret;
>>> +
>>> +            switch (chan->address) {
>>> +            case VZ89X_VOC_CO2_IDX:
>>> +            case VZ89X_VOC_SHORT_IDX:
>>> +            case VZ89X_VOC_TVOC_IDX:
>>> +                    *val = data->buffer[chan->address];
>>> +                    return IIO_VAL_INT;
>>> +            case VZ89X_VOC_RESISTANCE_IDX:
>>> +                    *val = vz89x_get_resistance_reading(data);
>>> +                    return IIO_VAL_INT;
>>> +            default:
>>> +                    return -EINVAL;
>>> +            }
>>> +            break;
>>> +    case IIO_CHAN_INFO_SCALE:
>>> +            switch (chan->type) {
>>> +            case IIO_RESISTANCE:
>>> +                    *val = 10;
>>> +                    return IIO_VAL_INT;
>>> +            default:
>>> +                    return -EINVAL;
>>> +            }
>>> +            break;
>>> +    case IIO_CHAN_INFO_OFFSET:
>>> +            switch (chan->address) {
>>> +            case VZ89X_VOC_CO2_IDX:
>>> +                    *val = 44;
>>> +                    *val2 = 250000;
>>> +                    return IIO_VAL_INT_PLUS_MICRO;
>>> +            case VZ89X_VOC_TVOC_IDX:
>>> +                    *val = -13;
>>> +                    return IIO_VAL_INT;
>>> +            default:
>>> +                    return -EINVAL;
>>> +            }
>>> +    }
>>> +
>>> +    return ret;
>>> +}
>>> +
>>> +static const struct iio_info vz89x_info = {
>>> +    .attrs          = &vz89x_attrs_group,
>>> +    .read_raw       = vz89x_read_raw,
>>> +    .driver_module  = THIS_MODULE,
>>> +};
>>> +
>>> +static int vz89x_probe(struct i2c_client *client,
>>> +                   const struct i2c_device_id *id)
>>> +{
>>> +    struct iio_dev *indio_dev;
>>> +    struct vz89x_data *data;
>>> +
>>> +    if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
>>> +                                 I2C_FUNC_SMBUS_BYTE))
>>> +            return -ENODEV;
>>> +
>>> +    indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>>> +    if (!indio_dev)
>>> +            return -ENOMEM;
>>> +
>>> +    data = iio_priv(indio_dev);
>>> +    i2c_set_clientdata(client, indio_dev);
>>> +    data->client = client;
>>> +    data->last_update = jiffies - HZ;
>>> +    mutex_init(&data->lock);
>>> +
>>> +    indio_dev->dev.parent = &client->dev;
>>> +    indio_dev->info = &vz89x_info,
>>> +    indio_dev->name = dev_name(&client->dev);
>>> +    indio_dev->modes = INDIO_DIRECT_MODE;
>>> +
>>> +    indio_dev->channels = vz89x_channels;
>>> +    indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
>>> +
>>> +    return devm_iio_device_register(&client->dev, indio_dev);
>>> +}
>>> +
>>> +static const struct i2c_device_id vz89x_id[] = {
>>> +    { "vz89x", 0 },
>>> +    { }
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
>>> +
>>> +static const struct of_device_id vz89x_dt_ids[] = {
>>> +    { .compatible = "sgx,vz89x" },
>>> +    { }
>>> +};
>>> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
>>> +
>>> +static struct i2c_driver vz89x_driver = {
>>> +    .driver = {
>>> +            .name   = "vz89x",
>>> +            .of_match_table = of_match_ptr(vz89x_dt_ids),
>>> +    },
>>> +    .probe = vz89x_probe,
>>> +    .id_table = vz89x_id,
>>> +};
>>> +module_i2c_driver(vz89x_driver);
>>> +
>>> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
>>> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
>>> +MODULE_LICENSE("GPL v2");
>>>
>>
>

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

* Re: [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support
  2015-09-23  3:42       ` Matt Ranostay
@ 2015-09-23  3:46         ` Matt Ranostay
  0 siblings, 0 replies; 17+ messages in thread
From: Matt Ranostay @ 2015-09-23  3:46 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Peter Meerwald, Lars-Peter Clausen, linux-iio

Heh didn't see the part of it getting applied. I can submit the HW
workaround in the follow up along with the iio event changes :)

On Tue, Sep 22, 2015 at 8:42 PM, Matt Ranostay <mranostay@gmail.com> wrote:
> On Sun, Sep 20, 2015 at 12:02 PM, Jonathan Cameron <jic23@kernel.org> wrote:
>> On 14/09/15 09:35, Peter Meerwald wrote:
>>>
>>>> Add support for VZ89X sensors VOC and CO2 reporting channels in
>>>> percentage which can be converted to part per million.
>>>
>>> can you make the proper changes for _CONCENTRATION etc. also for
>>> tools/iio/iio_event_monitor.c?
>> Rather than going through another complete version of this series,
>> would you mind doing that as a follow up patch?
> I'll do it as a follow on unless see below....  should IIO_RESISTANCE
> to iio_event_monitor.c be added as well?
>
>
>>
>>>
>>> and comment below
>> I've fixed this up as chemical sensors when applying.
>
> Actually have found a HW bug that affects one in like 1000 reads. Need
> to submit one more series to workaround it.... so should I add the
> previous to the next version?
>
>>>
>>>> Signed-off-by: Matt Ranostay <mranostay@gmail.com>
>>>> ---
>>>>  .../ABI/testing/sysfs-bus-iio-chemical-vz89x       |   7 +
>>>>  .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
>>>>  drivers/iio/Kconfig                                |   1 +
>>>>  drivers/iio/Makefile                               |   1 +
>>>>  drivers/iio/chemical/Kconfig                       |  15 ++
>>>>  drivers/iio/chemical/Makefile                      |   6 +
>>>>  drivers/iio/chemical/vz89x.c                       | 237 +++++++++++++++++++++
>>>>  7 files changed, 268 insertions(+)
>>>>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>>>  create mode 100644 drivers/iio/chemical/Kconfig
>>>>  create mode 100644 drivers/iio/chemical/Makefile
>>>>  create mode 100644 drivers/iio/chemical/vz89x.c
>>>>
>>>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>>> new file mode 100644
>>>> index 0000000..c0c1ea9
>>>> --- /dev/null
>>>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
>>>> @@ -0,0 +1,7 @@
>>>> +What:               /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
>>>> +Date:               September 2015
>>>> +KernelVersion:      4.3
>>>> +Contact:    Matt Ranostay <mranostay@gmail.com>
>>>> +Description:
>>>> +            Get the raw calibration VOC value from the sensor.
>>>> +            This value has little application outside of calibration.
>>>> diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>>> index d77d412..a550216 100644
>>>> --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>>> +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
>>>> @@ -88,6 +88,7 @@ ricoh,rs5c372b             I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>>  ricoh,rv5c386               I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>>  ricoh,rv5c387a              I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
>>>>  samsung,24ad0xd1    S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
>>>> +sgx,vz89x           SGX Sensortech VZ89X Sensors
>>>>  sii,s35390a         2-wire CMOS real-time clock
>>>>  skyworks,sky81452   Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
>>>>  st-micro,24c256             i2c serial eeprom  (24cxx)
>>>> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
>>>> index 4011eff..9664e9c 100644
>>>> --- a/drivers/iio/Kconfig
>>>> +++ b/drivers/iio/Kconfig
>>>> @@ -61,6 +61,7 @@ config IIO_CONSUMERS_PER_TRIGGER
>>>>  source "drivers/iio/accel/Kconfig"
>>>>  source "drivers/iio/adc/Kconfig"
>>>>  source "drivers/iio/amplifiers/Kconfig"
>>>> +source "drivers/iio/chemical/Kconfig"
>>>>  source "drivers/iio/common/Kconfig"
>>>>  source "drivers/iio/dac/Kconfig"
>>>>  source "drivers/iio/frequency/Kconfig"
>>>> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
>>>> index 698afc2..2288684 100644
>>>> --- a/drivers/iio/Makefile
>>>> +++ b/drivers/iio/Makefile
>>>> @@ -14,6 +14,7 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>>>>  obj-y += accel/
>>>>  obj-y += adc/
>>>>  obj-y += amplifiers/
>>>> +obj-y += chemical/
>>>>  obj-y += common/
>>>>  obj-y += dac/
>>>>  obj-y += gyro/
>>>> diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
>>>> new file mode 100644
>>>> index 0000000..04906af
>>>> --- /dev/null
>>>> +++ b/drivers/iio/chemical/Kconfig
>>>> @@ -0,0 +1,15 @@
>>>> +#
>>>> +# Chemical sensors
>>>> +#
>>>> +
>>>> +menu "Indoor Air Quality sensors"
>>>
>>> the comment above says 'Chemical sensors', the menu item 'Indoor Air
>>> Quality sensors' -- I guess an outdoor sensor would fit here as well...
>> Lets just go with Chemical sensors.
>
>
>
>>>
>>>> +
>>>> +config VZ89X
>>>> +    tristate "SGX Sensortech MiCS VZ89X VOC sensor"
>>>> +    depends on I2C
>>>> +    help
>>>> +      Say Y here to build I2C interface support for the SGX
>>>> +      Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
>>>> +      sensors
>>>> +
>>>> +endmenu
>>>> diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
>>>> new file mode 100644
>>>> index 0000000..7292f2d
>>>> --- /dev/null
>>>> +++ b/drivers/iio/chemical/Makefile
>>>> @@ -0,0 +1,6 @@
>>>> +#
>>>> +# Makefile for IIO chemical sensors
>>>> +#
>>>> +
>>>> +# When adding new entries keep the list in alphabetical order
>>>> +obj-$(CONFIG_VZ89X)         += vz89x.o
>>>> diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
>>>> new file mode 100644
>>>> index 0000000..b454200
>>>> --- /dev/null
>>>> +++ b/drivers/iio/chemical/vz89x.c
>>>> @@ -0,0 +1,237 @@
>>>> +/*
>>>> + * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
>>>> + *
>>>> + * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
>>>> + *
>>>> + * This program is free software; you can redistribute it and/or modify
>>>> + * it under the terms of the GNU General Public License as published by
>>>> + * the Free Software Foundation; either version 2 of the License, or
>>>> + * (at your option) any later version.
>>>> + *
>>>> + * This program is distributed in the hope that it will be useful,
>>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>>> + * GNU General Public License for more details.
>>>> + *
>>>> + */
>>>> +
>>>> +#include <linux/module.h>
>>>> +#include <linux/mutex.h>
>>>> +#include <linux/init.h>
>>>> +#include <linux/i2c.h>
>>>> +
>>>> +#include <linux/iio/iio.h>
>>>> +#include <linux/iio/sysfs.h>
>>>> +
>>>> +#define VZ89X_REG_MEASUREMENT               0x09
>>>> +#define VZ89X_REG_MEASUREMENT_SIZE  6
>>>> +
>>>> +#define VZ89X_VOC_CO2_IDX           0
>>>> +#define VZ89X_VOC_SHORT_IDX         1
>>>> +#define VZ89X_VOC_TVOC_IDX          2
>>>> +#define VZ89X_VOC_RESISTANCE_IDX    3
>>>> +
>>>> +struct vz89x_data {
>>>> +    struct i2c_client *client;
>>>> +    struct mutex lock;
>>>> +    unsigned long last_update;
>>>> +
>>>> +    u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
>>>> +};
>>>> +
>>>> +static const struct iio_chan_spec vz89x_channels[] = {
>>>> +    {
>>>> +            .type = IIO_CONCENTRATION,
>>>> +            .channel2 = IIO_MOD_CO2,
>>>> +            .modified = 1,
>>>> +            .info_mask_separate =
>>>> +                    BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>>>> +            .address = VZ89X_VOC_CO2_IDX,
>>>> +    },
>>>> +    {
>>>> +            .type = IIO_CONCENTRATION,
>>>> +            .channel2 = IIO_MOD_VOC,
>>>> +            .modified = 1,
>>>> +            .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>>>> +            .address = VZ89X_VOC_SHORT_IDX,
>>>> +            .extend_name = "short",
>>>> +    },
>>>> +    {
>>>> +            .type = IIO_CONCENTRATION,
>>>> +            .channel2 = IIO_MOD_VOC,
>>>> +            .modified = 1,
>>>> +            .info_mask_separate =
>>>> +                    BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
>>>> +            .address = VZ89X_VOC_TVOC_IDX,
>>>> +    },
>>>> +    {
>>>> +            .type = IIO_RESISTANCE,
>>>> +            .info_mask_separate =
>>>> +                    BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>>>> +            .address = VZ89X_VOC_RESISTANCE_IDX,
>>>> +    },
>>>> +};
>>>> +
>>>> +static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
>>>> +static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
>>>> +
>>>> +static struct attribute *vz89x_attributes[] = {
>>>> +    &iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
>>>> +    &iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
>>>> +    NULL,
>>>> +};
>>>> +
>>>> +static const struct attribute_group vz89x_attrs_group = {
>>>> +    .attrs = vz89x_attributes,
>>>> +};
>>>> +
>>>> +static int vz89x_get_measurement(struct vz89x_data *data)
>>>> +{
>>>> +    int ret;
>>>> +    int i;
>>>> +
>>>> +    /* sensor can only be polled once a second max per datasheet */
>>>> +    if (!time_after(jiffies, data->last_update + HZ))
>>>> +            return 0;
>>>> +
>>>> +    ret = i2c_smbus_write_word_data(data->client,
>>>> +                                    VZ89X_REG_MEASUREMENT, 0);
>>>> +    if (ret < 0)
>>>> +            return ret;
>>>> +
>>>> +    for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
>>>> +            ret = i2c_smbus_read_byte(data->client);
>>>> +            if (ret < 0)
>>>> +                    return ret;
>>>> +            data->buffer[i] = ret;
>>>> +    }
>>>> +
>>>> +    data->last_update = jiffies;
>>>> +
>>>> +    return 0;
>>>> +}
>>>> +
>>>> +static int vz89x_get_resistance_reading(struct vz89x_data *data)
>>>> +{
>>>> +    u8 *buf = &data->buffer[VZ89X_VOC_TVOC_IDX];
>>>> +
>>>> +    return buf[0] | (buf[1] << 8) | (buf[2] << 16);
>>>> +}
>>>> +
>>>> +static int vz89x_read_raw(struct iio_dev *indio_dev,
>>>> +                      struct iio_chan_spec const *chan, int *val,
>>>> +                      int *val2, long mask)
>>>> +{
>>>> +    struct vz89x_data *data = iio_priv(indio_dev);
>>>> +    int ret = -EINVAL;
>>>> +
>>>> +    switch (mask) {
>>>> +    case IIO_CHAN_INFO_RAW:
>>>> +            mutex_lock(&data->lock);
>>>> +            ret = vz89x_get_measurement(data);
>>>> +            mutex_unlock(&data->lock);
>>>> +
>>>> +            if (ret)
>>>> +                    return ret;
>>>> +
>>>> +            switch (chan->address) {
>>>> +            case VZ89X_VOC_CO2_IDX:
>>>> +            case VZ89X_VOC_SHORT_IDX:
>>>> +            case VZ89X_VOC_TVOC_IDX:
>>>> +                    *val = data->buffer[chan->address];
>>>> +                    return IIO_VAL_INT;
>>>> +            case VZ89X_VOC_RESISTANCE_IDX:
>>>> +                    *val = vz89x_get_resistance_reading(data);
>>>> +                    return IIO_VAL_INT;
>>>> +            default:
>>>> +                    return -EINVAL;
>>>> +            }
>>>> +            break;
>>>> +    case IIO_CHAN_INFO_SCALE:
>>>> +            switch (chan->type) {
>>>> +            case IIO_RESISTANCE:
>>>> +                    *val = 10;
>>>> +                    return IIO_VAL_INT;
>>>> +            default:
>>>> +                    return -EINVAL;
>>>> +            }
>>>> +            break;
>>>> +    case IIO_CHAN_INFO_OFFSET:
>>>> +            switch (chan->address) {
>>>> +            case VZ89X_VOC_CO2_IDX:
>>>> +                    *val = 44;
>>>> +                    *val2 = 250000;
>>>> +                    return IIO_VAL_INT_PLUS_MICRO;
>>>> +            case VZ89X_VOC_TVOC_IDX:
>>>> +                    *val = -13;
>>>> +                    return IIO_VAL_INT;
>>>> +            default:
>>>> +                    return -EINVAL;
>>>> +            }
>>>> +    }
>>>> +
>>>> +    return ret;
>>>> +}
>>>> +
>>>> +static const struct iio_info vz89x_info = {
>>>> +    .attrs          = &vz89x_attrs_group,
>>>> +    .read_raw       = vz89x_read_raw,
>>>> +    .driver_module  = THIS_MODULE,
>>>> +};
>>>> +
>>>> +static int vz89x_probe(struct i2c_client *client,
>>>> +                   const struct i2c_device_id *id)
>>>> +{
>>>> +    struct iio_dev *indio_dev;
>>>> +    struct vz89x_data *data;
>>>> +
>>>> +    if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
>>>> +                                 I2C_FUNC_SMBUS_BYTE))
>>>> +            return -ENODEV;
>>>> +
>>>> +    indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>>>> +    if (!indio_dev)
>>>> +            return -ENOMEM;
>>>> +
>>>> +    data = iio_priv(indio_dev);
>>>> +    i2c_set_clientdata(client, indio_dev);
>>>> +    data->client = client;
>>>> +    data->last_update = jiffies - HZ;
>>>> +    mutex_init(&data->lock);
>>>> +
>>>> +    indio_dev->dev.parent = &client->dev;
>>>> +    indio_dev->info = &vz89x_info,
>>>> +    indio_dev->name = dev_name(&client->dev);
>>>> +    indio_dev->modes = INDIO_DIRECT_MODE;
>>>> +
>>>> +    indio_dev->channels = vz89x_channels;
>>>> +    indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
>>>> +
>>>> +    return devm_iio_device_register(&client->dev, indio_dev);
>>>> +}
>>>> +
>>>> +static const struct i2c_device_id vz89x_id[] = {
>>>> +    { "vz89x", 0 },
>>>> +    { }
>>>> +};
>>>> +MODULE_DEVICE_TABLE(i2c, vz89x_id);
>>>> +
>>>> +static const struct of_device_id vz89x_dt_ids[] = {
>>>> +    { .compatible = "sgx,vz89x" },
>>>> +    { }
>>>> +};
>>>> +MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
>>>> +
>>>> +static struct i2c_driver vz89x_driver = {
>>>> +    .driver = {
>>>> +            .name   = "vz89x",
>>>> +            .of_match_table = of_match_ptr(vz89x_dt_ids),
>>>> +    },
>>>> +    .probe = vz89x_probe,
>>>> +    .id_table = vz89x_id,
>>>> +};
>>>> +module_i2c_driver(vz89x_driver);
>>>> +
>>>> +MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
>>>> +MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
>>>> +MODULE_LICENSE("GPL v2");
>>>>
>>>
>>

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

end of thread, other threads:[~2015-09-23  3:46 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-14  3:26 [PATCH v5 0/4] iio: new chemical sensor framework and channel types Matt Ranostay
2015-09-14  3:26 ` Matt Ranostay
2015-09-14  3:26 ` [PATCH v5 1/4] iio: chemical: Add IIO_CONCENTRATION channel type Matt Ranostay
2015-09-20 18:55   ` Jonathan Cameron
2015-09-20 18:55     ` Jonathan Cameron
2015-09-14  3:26 ` [PATCH v5 2/4] iio: resistance: add IIO_RESISTANCE " Matt Ranostay
2015-09-20 18:55   ` Jonathan Cameron
2015-09-20 18:55     ` Jonathan Cameron
2015-09-14  3:26 ` [PATCH v5 3/4] devicetree: add SGX Sensortech vendor id Matt Ranostay
2015-09-20 18:58   ` Jonathan Cameron
2015-09-14  3:26 ` [PATCH v5 4/4] iio: chemical: add SGX VZ89x VOC sensor support Matt Ranostay
2015-09-14  8:35   ` Peter Meerwald
2015-09-14 15:22     ` Matt Ranostay
2015-09-15  2:55     ` Matt Ranostay
2015-09-20 19:02     ` Jonathan Cameron
2015-09-23  3:42       ` Matt Ranostay
2015-09-23  3:46         ` Matt Ranostay

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.