iio: temperature: add support for tmp117
v3 cover iio: temperature: add support for tmp117
Add the dt-bindings and the driver for tmp117 sensor.
Changes since v2:
1. Made Calibbias read and write in same units.
2. Add missing includes.
3. Clamp the values before writing to calibbias.
4. Add i2c description to dt-binding example.
5. Remove explicit casting at different places. Changes since v1:
1. Remove unused headers
2. Add error checking in i2c read/write.
3. Correct DT bindings.
4. Correct implementation to return tmp in milli celcius.
5. Remove unused mutex lock.
6. Modify MAINTAINERS.
Changes since v0:
1. Correct Yaml syntax.
2. Change IIO_CHAN_INFO_OFFSET to IIO_CHAN_INFO_CALIBBIAS.
3. Implement IIO_CHAN_INFO_SCALE.
4. Use devm_iio_device_register().
5. Remove unused headers like delay.h
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 | 41 ++++ MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 182 ++++++++++++++++++ 5 files changed, 241 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 v3 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 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +41 -0
@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/iio/temperature/ti,tmp117.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: "TI TMP117 - Digital temperature sensor with integrated NV memory" + +description: | + TI TMP117 - Digital temperature sensor with integrated NV memory that supports + I2C interface. + https://www.ti.com/lit/gpn/tmp1 + +maintainers: + - Puranjay Mohan <[email protected]> + +properties: + compatible: + enum: + - ti,tmp117 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>; + }; + };
Signature · 1 line
2.30.1
PATCH v3 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
--- MAINTAINERS | 7 ++ drivers/iio/temperature/Kconfig | 10 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 182 +++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 drivers/iio/temperature/tmp117.c
MAINTAINERS +7 -0
@@ -16666,6 +16666,13 @@ F: include/dt-bindings/soc/ti,sci_pm_domain.h F: include/linux/soc/ti/ti_sci_inta_msi.h F: include/linux/soc/ti/ti_sci_protocol.h +TEXAS INSTRUMENTS' TMP117 TEMPERATURE SENSOR DRIVER +M: Puranjay Mohan <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml +F: drivers/iio/temperature/tmp117.c + THANKO'S RAREMONO AM/FM/SW RADIO RECEIVER USB DRIVER M: Hans Verkuil <[email protected]> L: [email protected]
drivers/iio/temperature/Kconfig +10 -0
@@ -97,6 +97,16 @@ 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
@@ -12,5 +12,6 @@ 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
drivers/iio/temperature/tmp117.c new file +182 -0
182 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH v3 2/2] iio: temperature: add driver support for ti tmp117
drivers/iio/temperature/tmp117.c line 90
Quoted 12 lines · Puranjay Mohan
drivers/iio/temperature/tmp117.c new file +12
-0+ +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); +s16 off; + +switch (mask) { +case IIO_CHAN_INFO_CALIBBIAS : + off =clamp (val,-32768 ,32767 ); +if (off == data->calibbias)
data->calibbias is only set in probe() and always 0. I'm not sure we need to cache the value. Reading it back from the device seems fine.
Quoted 9 lines
drivers/iio/temperature/tmp117.c new file +9
-0+return 0 ; +return i2c_smbus_write_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET , off); + +default : +return -EINVAL ; + } +} +
Re: [PATCH v3 2/2] iio: temperature: add driver support for ti tmp117
Quoted 17 lines · Lars-Peter Clausen
drivers/iio/temperature/tmp117.c line 90
Quoted 12 lines · Puranjay Mohan
drivers/iio/temperature/tmp117.c new file +12
-0+ +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); +s16 off; + +switch (mask) { +case IIO_CHAN_INFO_CALIBBIAS : + off =clamp (val,-32768 ,32767 ); +if (off == data->calibbias)
data->calibbiasis only set inprobe()and always 0. I'm not sure we need to cache the value. Reading it back from the device seems fine.
I forgot to update it, thanks for finding the bug. Actually, I wanted to update the calibbias register only if a different value is being written.
If the same value is written to the device repeatedly then we can save some I2C writes using this.
and while reading the calibbias, it is read from the device only. I will fix the bug in the next revision.
Quoted 11 lines
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +9
-0+return 0 ; +return i2c_smbus_write_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET , off); + +default : +return -EINVAL ; + } +} +
Signature · 5 lines
Thanks and Regards Yours Truly, Puranjay Mohan