iio: temperature: add support for tmp117
cover iio: temperature: add support for tmp117
Add the dt-bindings and the driver for tmp117 sensor.
Puranjay Mohan (2):
dt-bindings: iio: temperature: Add DT bindings for TMP117
iio: temperature: add driver support for ti tmp117
.../bindings/iio/temperature/ti,tmp117.yaml | 40 ++++ drivers/iio/temperature/Kconfig | 11 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 196 ++++++++++++++++++ 4 files changed, 248 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml create mode 100644 drivers/iio/temperature/tmp117.c
Signature · 1 line
2.30.1
PATCH 1/2 dt-bindings: iio: temperature: Add DT bindings for TMP117
Add devicetree binding document for TMP117, a digital temperature sensor.
--- .../bindings/iio/temperature/ti,tmp117.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2021 Puranjay Mohan. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bindings/iio/temperature/ti,tmp117.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI TMP117 - Digital temperature sensor with integrated NV memory + +maintainers: Puranjay Mohan <[email protected]> + +description: | + datasheet- https://www.ti.com/lit/gpn/tmp1 + ----------------------------- + | ADD0 | Device Address| + ----------------------------- + | Ground | 0x48 | + | V+ | 0x49 | + | SDA | 0x4A | + | SCL | 0x4B | + ----------------------------- +properties: + compatible: + enum: + - ti,tmp117 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +examples: + | + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>; + }; +
Signature · 1 line
2.30.1
Rob Herring
maintainerRe: [PATCH 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117
Quoted 8 lines · Puranjay Mohan
Add devicetree binding document for TMP117, a digital temperature sensor.
Signed-off-by Puranjay Mohan <[email protected]>--- .../bindings/iio/temperature/ti,tmp117.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:./Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml:14:1: [error] syntax error: found character '\t' that cannot start any token (syntax)
dtschema/dtc warnings/errors:
make[1]: *** Deleting file 'Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dts'
Traceback (most recent call last):
File "/usr/local/bin/dt-extract-example", line 45, in <module>
binding = yaml.load(open(args.yamlfile, encoding='utf-8').read())
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/main.py", line 343, in load
return constructor.get_single_data()
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
node = self.composer.get_single_node()
File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 731, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: while scanning a block scalar
in "<unicode string>", line 12, column 14
found a tab character where an indentation space is expected
in "<unicode string>", line 14, column 1
make[1]: *** [Documentation/devicetree/bindings/Makefile:20: Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dts] Error 1 make[1]: *** Waiting for unfinished jobs...../Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml: while scanning a block scalar
in "<unicode string>", line 12, column 14
found a tab character where an indentation space is expected
in "<unicode string>", line 14, column 1
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml: ignoring, error parsing file
warning: no schema found in file: ./Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml
make: *** [Makefile:1380: dt_binding_check] Error 2
See https://patchwork.ozlabs.org/patch/1456032
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
PATCH 2/2 iio: temperature: add driver support for ti tmp117
In reply to Puranjay MohanTMP117 is a Digital temperature sensor with integrated NV memory.
Add support for tmp117 driver in iio subsystem.
Datasheet:-https://www.ti.com/lit/gpn/tmp117
--- drivers/iio/temperature/Kconfig | 11 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 196 +++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 drivers/iio/temperature/tmp117.c
drivers/iio/temperature/Kconfig +11 -0
@@ -86,6 +86,17 @@ config TMP007 This driver can also be built as a module. If so, the module will be called tmp007. +config TMP117 + tristate "TMP117 Digital temperature sensor with integrated NV memory" + depends on I2C + help + If you say yes here you get support for the Texas Instruments + TMP117 Digital temperature sensor with integrated NV memory. + + This driver can also be built as a module. If so, the module will + be called tmp117. + + config TSYS01 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" depends on I2C
drivers/iio/temperature/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TMP007) += tmp007.o +obj-$(CONFIG_TMP117) += tmp117.o obj-$(CONFIG_TSYS01) += tsys01.o obj-$(CONFIG_TSYS02D) += tsys02d.o obj-$(CONFIG_LTC2983) += ltc2983.o
drivers/iio/temperature/tmp117.c new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH 2/2] iio: temperature: add driver support for ti tmp117
Quoted 7 lines · Puranjay Mohan
TMP117 is a Digital temperature sensor with integrated NV memory.
Add support for tmp117 driver in iio subsystem.
Datasheet:-https://www.ti.com/lit/gpn/tmp117
Signed-off-by Puranjay Mohan <[email protected]>
Hi,
Thanks for the patch, this looks really good. I have a couple of small comments inline.
And one general comment. What you have implemented as IIO_CHAN_INFO_OFFSET should be IIO_CHAN_INFO_CALIBBIAS, since it is an offset for calibration. The IIO_CHAN_INFO_OFFSET property on the other hand is used to describe how to convert from raw data to SI units.
Quoted 59 lines
--- drivers/iio/temperature/Kconfig | 11 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 196 +++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+)create mode 100644
drivers/iio/temperature/tmp117.cdrivers/iio/temperature/Kconfig +11
-0@@ -86,6 +86,17 @@ config TMP007 This driver can also be built as a module. If so, the module will be called tmp007. +config TMP117 + tristate "TMP117 Digital temperature sensor with integrated NV memory" + depends on I2C + help + If you say yes here you get support for the Texas Instruments + TMP117 Digital temperature sensor with integrated NV memory. + + This driver can also be built as a module. If so, the module will + be called tmp117. + + config TSYS01 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" depends on I2Cdrivers/iio/temperature/Makefile +1
-0@@ -10,6 +10,7 @@ obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TMP007) += tmp007.o +obj-$(CONFIG_TMP117) += tmp117.o obj-$(CONFIG_TSYS01) += tsys01.o obj-$(CONFIG_TSYS02D) += tsys02d.o obj-$(CONFIG_LTC2983) += ltc2983.odrivers/iio/temperature/tmp117.c new file +12
-0@@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* tmp117.c - Digital temperature sensor with integrated NV memory +* +* Copyright (c) 2021 Puranjay Mohan <[email protected]> +* +* Driver for the Texas Instruments TMP117 Temperature Sensor +* +* (7-bit I2C slave address (0x48 - 0x4B), changeable via ADD pins) +* +* Note: This driver assumes that the sensor has been calibrated beforehand. +*/
drivers/iio/temperature/tmp117.c line 22
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+ +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/delay.h> +#include <linux/module.h> +#include <linux/pm.h> +#include <linux/bitops.h> +#include <linux/of.h> +#include <linux/irq.h> +#include <linux/interrupt.h>
interrupt.h is for consumers, irq.h is for providers. Since this driver is only a interrupt consumer you only need irq.h.
I believe bitops.h and delay.h are also not needed by this driver.
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +4
-0+ +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/events.h>
drivers/iio/temperature/tmp117.c line 36
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+ +#define TMP117_REG_TEMP 0x0 +#define TMP117_REG_CFGR 0x1 +#define TMP117_REG_HIGH_LIM 0x2 +#define TMP117_REG_LOW_LIM 0x3 +#define TMP117_REG_EEPROM_UL 0x4 +#define TMP117_REG_EEPROM1 0x5 +#define TMP117_REG_EEPROM2 0x6 +#define TMP117_REG_EEPROM3 0x7 +#define TMP117_REG_TEMP_OFFSET 0x7
You got register 0x7 twice here.
Quoted 6 lines
drivers/iio/temperature/tmp117.c new file +6
-0+#define TMP117_REG_EEPROM4 0x8 +#define TMP117_REG_DEVICE_ID 0xF + +#define TMP117_RESOLUTION 78125/* in tens of uCelsius*/ +#define TMP117_RESOLUTION_DIV 10000000 +
drivers/iio/temperature/tmp117.c line 52
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+#define TMP117_DEVICE_ID 0x0117 + +struct tmp117_data { +struct i2c_client *client; +struct mutex lock; +}; + +static int tmp117_read_reg (struct tmp117_data *data,u8 reg) +{ +
Being pedantic: the newline at the top here and also in write_reg are not needed.
Quoted 11 lines
drivers/iio/temperature/tmp117.c new file +11
-0+return i2c_smbus_read_word_swapped (data->client, reg); +} + +static int tmp117_write_reg (struct tmp117_data *data,u8 reg,int val) +{ + +return i2c_smbus_write_word_swapped (data->client, reg, val); +} + +static int tmp117_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val,
drivers/iio/temperature/tmp117.c line 73
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+ int *val2, long mask) +{ +struct tmp117_data *data =iio_priv (indio_dev); +u16 tmp, off; + +switch (mask) { +case IIO_CHAN_INFO_PROCESSED : + tmp =tmp117_read_reg (data,TMP117_REG_TEMP ); + *val = ((int16_t )tmp * (int32_t )TMP117_RESOLUTION ) /10000000 ; + *val2 = ((int16_t )tmp * (int32_t )TMP117_RESOLUTION ) %10000000 ;
Since this is a linear transform it would be better to report RAW measurements and then provide the scale attribute for conversion,.
Quoted 65 lines
drivers/iio/temperature/tmp117.c new file +65
-0+return IIO_VAL_INT_PLUS_MICRO ; + +case IIO_CHAN_INFO_OFFSET : + off =tmp117_read_reg (data,TMP117_REG_TEMP_OFFSET ); + *val = ((int16_t )off * (int32_t )TMP117_RESOLUTION ) /10000000 ; + *val2 = ((int16_t )off * (int32_t )TMP117_RESOLUTION ) %10000000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +default : +return -EINVAL ; + } +} + +static int tmp117_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *channel,int val, +int val2,long mask) +{ +struct tmp117_data *data =iio_priv (indio_dev); +u16 off; + +switch (mask) { +case IIO_CHAN_INFO_OFFSET : + off = ((val *10000000 ) + (val2 *10 )) + / (int32_t )TMP117_RESOLUTION ; +return tmp117_write_reg (data,TMP117_REG_TEMP_OFFSET , off); + +default : +return -EINVAL ; + } +} + +static const struct iio_chan_spec tmp117_channels[] = { + { + .type =IIO_TEMP , + .info_mask_separate =BIT (IIO_CHAN_INFO_PROCESSED ) | +BIT (IIO_CHAN_INFO_OFFSET ), + }, +}; + +static const struct iio_info tmp117_info = { + .read_raw = tmp117_read_raw, + .write_raw = tmp117_write_raw, +}; + +static bool tmp117_identify (struct i2c_client *client) +{ +int dev_id; + + dev_id =i2c_smbus_read_word_swapped (client,TMP117_REG_DEVICE_ID ); +if (dev_id <0 ) +return false; + +return (dev_id ==TMP117_DEVICE_ID ); +} + +static int tmp117_probe (struct i2c_client *client, +const struct i2c_device_id *tmp117_id) +{ +struct tmp117_data *data; +struct iio_dev *indio_dev; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_WORD_DATA )) +return -EOPNOTSUPP ; + +if (!tmp117_identify (client)) {
drivers/iio/temperature/tmp117.c line 148
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+dev_err (&client->dev,"TMP117 not found\n" ); +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);
If you remove the remove() callback the i2c_set_clientdata() here can also be removed.
drivers/iio/temperature/tmp117.c line 152
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +4
-0+ data->client = client; +mutex_init (&data->lock); + + indio_dev->dev.parent = &client->dev;
The parent assignment is no longer needed in the latest upstream kernel since it happens in devm_iio_device_alloc().
drivers/iio/temperature/tmp117.c line 160
Quoted 8 lines
drivers/iio/temperature/tmp117.c new file +8
-0+ indio_dev->name ="tmp117" ; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &tmp117_info; + + indio_dev->channels = tmp117_channels; + indio_dev->num_channels =ARRAY_SIZE (tmp117_channels); + +return iio_device_register (indio_dev);
devm_iio_device_register(...) and then you can remove the the remove() callback.
Quoted 3 lines
drivers/iio/temperature/tmp117.c new file +2
-0+} +