* [PATCH] iio: Add TH06 Humidity and Temperature sensor driver
@ 2016-01-11 22:57 Cristina Moraru
2016-01-12 11:07 ` Peter Meerwald-Stadler
0 siblings, 1 reply; 4+ messages in thread
From: Cristina Moraru @ 2016-01-11 22:57 UTC (permalink / raw)
To: jic23, knaack.h, lars, pmeerw, ludovic.tancerel, mranostay,
linux-kernel, linux-iio, octavian.purdila, daniel.baluta
Cc: Cristina Moraru
Add implementation for Hoperf TH06 Humidity and Temperature
sensor driver.
Datasheet: http://www.hoperf.com/upload/sensor/TH06_Module_v01.pdf
Signed-off-by: Cristina Moraru <cristina.moraru09@gmail.com>
---
drivers/iio/humidity/Kconfig | 10 +++
drivers/iio/humidity/Makefile | 1 +
drivers/iio/humidity/th06.c | 147 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 158 insertions(+)
create mode 100644 drivers/iio/humidity/th06.c
diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig
index 6a23698..b233b16 100644
--- a/drivers/iio/humidity/Kconfig
+++ b/drivers/iio/humidity/Kconfig
@@ -55,4 +55,14 @@ config SI7020
To compile this driver as a module, choose M here: the module
will be called si7020.
+config TH06
+ tristate "TH06 humidity and temperature sensor"
+ depends on I2C
+ help
+ Say yes here to build support for the TH06 measurement of
+ relative humidity and temperature.
+
+ To compile this driver as a module, choose M here: the module
+ will be called th06.
+
endmenu
diff --git a/drivers/iio/humidity/Makefile b/drivers/iio/humidity/Makefile
index c9f089a..3667ee7 100644
--- a/drivers/iio/humidity/Makefile
+++ b/drivers/iio/humidity/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_HDC100X) += hdc100x.o
obj-$(CONFIG_HTU21) += htu21.o
obj-$(CONFIG_SI7005) += si7005.o
obj-$(CONFIG_SI7020) += si7020.o
+obj-$(CONFIG_TH06) += th06.o
diff --git a/drivers/iio/humidity/th06.c b/drivers/iio/humidity/th06.c
new file mode 100644
index 0000000..44b0d77
--- /dev/null
+++ b/drivers/iio/humidity/th06.c
@@ -0,0 +1,147 @@
+/*
+ * TH06 - I2C Humidity and Temperature Sensor
+ *
+ * Copyright (C) 2016 Cristina Moraru <cristina.moraru09@gmail.com>
+ *
+ * This file is subject to the terms and conditions of version 2 of
+ * the GNU General Public License. See the file COPYING in the main
+ * directory of this archive for more details.
+ *
+ * IIO driver for TH06 (7-bit I2C slave address 0x40)
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#define TH06_DRV_NAME "th06"
+
+#define TH06_READ_RH 0xE5
+#define TH06_READ_TEMP 0xE3
+
+struct th06_data {
+ struct i2c_client *client;
+};
+
+static const struct iio_chan_spec th06_channels[] = {
+ {
+ .type = IIO_HUMIDITYRELATIVE,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE) |
+ BIT(IIO_CHAN_INFO_OFFSET),
+ },
+ {
+ .type = IIO_TEMP,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE) |
+ BIT(IIO_CHAN_INFO_OFFSET),
+ }
+};
+
+static int th06_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan, int *val,
+ int *val2, long mask)
+{
+ struct th06_data *data = iio_priv(indio_dev);
+ int ret = -EINVAL;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ switch (chan->type) {
+ case IIO_HUMIDITYRELATIVE:
+ ret = i2c_smbus_read_word_swapped(data->client,
+ TH06_READ_RH);
+ break;
+ case IIO_TEMP:
+ ret = i2c_smbus_read_word_swapped(data->client,
+ TH06_READ_TEMP);
+ break;
+ default:
+ break;
+ }
+ if (ret < 0)
+ return ret;
+ *val = ret;
+ return IIO_VAL_INT;
+ case IIO_CHAN_INFO_SCALE:
+ switch (chan->type) {
+ case IIO_HUMIDITYRELATIVE:
+ *val = 0;
+ *val2 = 1907349;
+ break;
+ case IIO_TEMP:
+ *val = 0;
+ *val2 = 2681274;
+ break;
+ default:
+ break;
+ }
+ return IIO_VAL_INT_PLUS_NANO;
+ case IIO_CHAN_INFO_OFFSET:
+ switch (chan->type) {
+ case IIO_HUMIDITYRELATIVE:
+ *val = -6;
+ return IIO_VAL_INT;
+ case IIO_TEMP:
+ *val = -46;
+ *val2 = 850000;
+ return IIO_VAL_INT_PLUS_MICRO;
+ default:
+ break;
+ }
+ }
+ return ret;
+}
+
+
+static const struct iio_info th06_info = {
+ .driver_module = THIS_MODULE,
+ .read_raw = th06_read_raw,
+};
+
+static int th06_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct th06_data *data;
+ struct iio_dev *indio_dev;
+
+ 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;
+
+ indio_dev->dev.parent = &client->dev;
+ indio_dev->info = &th06_info;
+ indio_dev->name = TH06_DRV_NAME;
+ indio_dev->channels = th06_channels;
+ indio_dev->num_channels = ARRAY_SIZE(th06_channels);
+ indio_dev->modes = INDIO_DIRECT_MODE;
+
+ return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id th06_id[] = {
+ {"th06", 0},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, th06_id);
+
+static struct i2c_driver th06_driver = {
+ .driver = {
+ .name = TH06_DRV_NAME,
+ },
+ .probe = th06_probe,
+ .id_table = th06_id,
+};
+
+module_i2c_driver(th06_driver);
+
+MODULE_AUTHOR("Cristina Moraru <cristina.moraru09@gmail.com>");
+MODULE_DESCRIPTION("TH06 Humidity and Temperature Sensor");
+MODULE_LICENSE("GPL");
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: Add TH06 Humidity and Temperature sensor driver
2016-01-11 22:57 [PATCH] iio: Add TH06 Humidity and Temperature sensor driver Cristina Moraru
@ 2016-01-12 11:07 ` Peter Meerwald-Stadler
2016-01-12 12:12 ` Daniel Baluta
0 siblings, 1 reply; 4+ messages in thread
From: Peter Meerwald-Stadler @ 2016-01-12 11:07 UTC (permalink / raw)
To: Cristina Moraru
Cc: jic23, knaack.h, lars, ludovic.tancerel, mranostay, linux-kernel,
linux-iio, octavian.purdila, daniel.baluta
> Add implementation for Hoperf TH06 Humidity and Temperature
> sensor driver.
>
> Datasheet: http://www.hoperf.com/upload/sensor/TH06_Module_v01.pdf
I think it would be good to make to manufacturer's company name (Hoperf)
more visible in the driver; it is currently just mentioned in the commit
message; just 'TH06' is hard to google :)
maybe you could list the TODOs / unsupported features here...
the I2C register layout looks close to the si7020, maybe the chip can be
supported there without duplicating code?
minor comments below
> Signed-off-by: Cristina Moraru <cristina.moraru09@gmail.com>
> ---
> drivers/iio/humidity/Kconfig | 10 +++
> drivers/iio/humidity/Makefile | 1 +
> drivers/iio/humidity/th06.c | 147 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 158 insertions(+)
> create mode 100644 drivers/iio/humidity/th06.c
>
> diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig
> index 6a23698..b233b16 100644
> --- a/drivers/iio/humidity/Kconfig
> +++ b/drivers/iio/humidity/Kconfig
> @@ -55,4 +55,14 @@ config SI7020
> To compile this driver as a module, choose M here: the module
> will be called si7020.
>
> +config TH06
> + tristate "TH06 humidity and temperature sensor"
> + depends on I2C
> + help
> + Say yes here to build support for the TH06 measurement of
> + relative humidity and temperature.
> +
> + To compile this driver as a module, choose M here: the module
> + will be called th06.
> +
> endmenu
> diff --git a/drivers/iio/humidity/Makefile b/drivers/iio/humidity/Makefile
> index c9f089a..3667ee7 100644
> --- a/drivers/iio/humidity/Makefile
> +++ b/drivers/iio/humidity/Makefile
> @@ -7,3 +7,4 @@ obj-$(CONFIG_HDC100X) += hdc100x.o
> obj-$(CONFIG_HTU21) += htu21.o
> obj-$(CONFIG_SI7005) += si7005.o
> obj-$(CONFIG_SI7020) += si7020.o
> +obj-$(CONFIG_TH06) += th06.o
> diff --git a/drivers/iio/humidity/th06.c b/drivers/iio/humidity/th06.c
> new file mode 100644
> index 0000000..44b0d77
> --- /dev/null
> +++ b/drivers/iio/humidity/th06.c
> @@ -0,0 +1,147 @@
> +/*
> + * TH06 - I2C Humidity and Temperature Sensor
> + *
> + * Copyright (C) 2016 Cristina Moraru <cristina.moraru09@gmail.com>
> + *
> + * This file is subject to the terms and conditions of version 2 of
> + * the GNU General Public License. See the file COPYING in the main
> + * directory of this archive for more details.
> + *
> + * IIO driver for TH06 (7-bit I2C slave address 0x40)
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/i2c.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
> +
> +#define TH06_DRV_NAME "th06"
> +
> +#define TH06_READ_RH 0xE5
> +#define TH06_READ_TEMP 0xE3
> +
> +struct th06_data {
> + struct i2c_client *client;
> +};
> +
> +static const struct iio_chan_spec th06_channels[] = {
> + {
> + .type = IIO_HUMIDITYRELATIVE,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE) |
> + BIT(IIO_CHAN_INFO_OFFSET),
> + },
> + {
> + .type = IIO_TEMP,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE) |
> + BIT(IIO_CHAN_INFO_OFFSET),
> + }
> +};
> +
> +static int th06_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
> +{
> + struct th06_data *data = iio_priv(indio_dev);
> + int ret = -EINVAL;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> + switch (chan->type) {
> + case IIO_HUMIDITYRELATIVE:
> + ret = i2c_smbus_read_word_swapped(data->client,
> + TH06_READ_RH);
> + break;
> + case IIO_TEMP:
> + ret = i2c_smbus_read_word_swapped(data->client,
> + TH06_READ_TEMP);
> + break;
> + default:
> + break;
> + }
> + if (ret < 0)
> + return ret;
> + *val = ret;
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SCALE:
> + switch (chan->type) {
> + case IIO_HUMIDITYRELATIVE:
> + *val = 0;
> + *val2 = 1907349;
> + break;
> + case IIO_TEMP:
> + *val = 0;
> + *val2 = 2681274;
> + break;
> + default:
> + break;
this doesn't look right, should result in an error if this is ever called,
similar for offset below
> + }
> + return IIO_VAL_INT_PLUS_NANO;
> + case IIO_CHAN_INFO_OFFSET:
> + switch (chan->type) {
> + case IIO_HUMIDITYRELATIVE:
> + *val = -6;
> + return IIO_VAL_INT;
> + case IIO_TEMP:
> + *val = -46;
> + *val2 = 850000;
> + return IIO_VAL_INT_PLUS_MICRO;
> + default:
> + break;
> + }
> + }
> + return ret;
> +}
> +
> +
> +static const struct iio_info th06_info = {
> + .driver_module = THIS_MODULE,
> + .read_raw = th06_read_raw,
> +};
> +
> +static int th06_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct th06_data *data;
> + struct iio_dev *indio_dev;
> +
> + 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;
> +
> + indio_dev->dev.parent = &client->dev;
> + indio_dev->info = &th06_info;
> + indio_dev->name = TH06_DRV_NAME;
> + indio_dev->channels = th06_channels;
> + indio_dev->num_channels = ARRAY_SIZE(th06_channels);
> + indio_dev->modes = INDIO_DIRECT_MODE;
> +
> + return devm_iio_device_register(&client->dev, indio_dev);
> +}
> +
> +static const struct i2c_device_id th06_id[] = {
> + {"th06", 0},
> + {}
> +};
> +MODULE_DEVICE_TABLE(i2c, th06_id);
> +
> +static struct i2c_driver th06_driver = {
> + .driver = {
> + .name = TH06_DRV_NAME,
> + },
> + .probe = th06_probe,
> + .id_table = th06_id,
> +};
> +
> +module_i2c_driver(th06_driver);
> +
> +MODULE_AUTHOR("Cristina Moraru <cristina.moraru09@gmail.com>");
> +MODULE_DESCRIPTION("TH06 Humidity and Temperature Sensor");
> +MODULE_LICENSE("GPL");
>
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: Add TH06 Humidity and Temperature sensor driver
2016-01-12 11:07 ` Peter Meerwald-Stadler
@ 2016-01-12 12:12 ` Daniel Baluta
2016-01-12 12:50 ` Ondrej Zary
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Baluta @ 2016-01-12 12:12 UTC (permalink / raw)
To: Peter Meerwald-Stadler
Cc: Cristina Moraru, Jonathan Cameron, Hartmut Knaack,
Lars-Peter Clausen, Ludovic Tancerel, Matt Ranostaj,
Linux Kernel Mailing List, linux-iio, octavian.purdila,
Daniel Baluta
On Tue, Jan 12, 2016 at 1:07 PM, Peter Meerwald-Stadler
<pmeerw@pmeerw.net> wrote:
>
>> Add implementation for Hoperf TH06 Humidity and Temperature
>> sensor driver.
>>
>> Datasheet: http://www.hoperf.com/upload/sensor/TH06_Module_v01.pdf
>
> I think it would be good to make to manufacturer's company name (Hoperf)
> more visible in the driver; it is currently just mentioned in the commit
> message; just 'TH06' is hard to google :)
>
> maybe you could list the TODOs / unsupported features here...
>
> the I2C register layout looks close to the si7020, maybe the chip can be
> supported there without duplicating code?
Yes, they look pretty similar. We can give it a try to add the support
for TH06 into
already existing code for si7020.
There will be some fun with Kconfig part :). Any idea if Hoperf and
Silabs are related
companies :D.
thanks,
Daniel.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: Add TH06 Humidity and Temperature sensor driver
2016-01-12 12:12 ` Daniel Baluta
@ 2016-01-12 12:50 ` Ondrej Zary
0 siblings, 0 replies; 4+ messages in thread
From: Ondrej Zary @ 2016-01-12 12:50 UTC (permalink / raw)
To: Daniel Baluta
Cc: Peter Meerwald-Stadler, Cristina Moraru, Jonathan Cameron,
Hartmut Knaack, Lars-Peter Clausen, Ludovic Tancerel,
Matt Ranostaj, Linux Kernel Mailing List, linux-iio,
octavian.purdila
On Tuesday 12 January 2016, Daniel Baluta wrote:
> On Tue, Jan 12, 2016 at 1:07 PM, Peter Meerwald-Stadler
>
> <pmeerw@pmeerw.net> wrote:
> >> Add implementation for Hoperf TH06 Humidity and Temperature
> >> sensor driver.
> >>
> >> Datasheet: http://www.hoperf.com/upload/sensor/TH06_Module_v01.pdf
> >
> > I think it would be good to make to manufacturer's company name (Hoperf)
> > more visible in the driver; it is currently just mentioned in the commit
> > message; just 'TH06' is hard to google :)
> >
> > maybe you could list the TODOs / unsupported features here...
> >
> > the I2C register layout looks close to the si7020, maybe the chip can be
> > supported there without duplicating code?
>
> Yes, they look pretty similar. We can give it a try to add the support
> for TH06 into
> already existing code for si7020.
>
> There will be some fun with Kconfig part :). Any idea if Hoperf and
> Silabs are related
> companies :D.
Looks like TH06 is just a module with Si7020 chip. Try the "Read Electronic
ID" and "Read Firmware Revision" commands from Si7020 datasheet.
--
Ondrej Zary
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-12 12:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-11 22:57 [PATCH] iio: Add TH06 Humidity and Temperature sensor driver Cristina Moraru
2016-01-12 11:07 ` Peter Meerwald-Stadler
2016-01-12 12:12 ` Daniel Baluta
2016-01-12 12:50 ` Ondrej Zary
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.