iio: temperature: add support for tmp117
v2 cover iio: temperature: add support for tmp117
Add the dt-bindings and the driver for tmp117 sensor.
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 | 34 ++++ MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/tmp117.c | 179 ++++++++++++++++++ 5 files changed, 231 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 v2 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 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +34 -0
@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0 +%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: + - | + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>; + };
Signature · 1 line
2.30.1
Rob Herring
maintainerRe: [PATCH v2 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 | 34 +++++++++++++++++++ 1 file changed, 34 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:
dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dts:21.13-26: Warning (reg_format): /example-0/tmp117@48:reg: property has invalid length (4 bytes) (#address-cells == 1, #size-cells == 1) Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: Warning (pci_device_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: Warning (simple_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: Warning (spi_bus_reg): Failed prerequisite 'reg_format' /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/iio/temperature/ti,tmp117.example.dt.yaml: example-0: tmp117@48:reg:0: [72] is too short
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
See https://patchwork.ozlabs.org/patch/1460920
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.
Rob Herring
maintainerRe: [PATCH v2 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117
In reply to Puranjay MohanQuoted 1 line · Puranjay Mohan
Add devicetree binding document for TMP117, a digital temperature sensor.
Please run checkpatch.pl and fix trailing WS.
Quoted 18 lines
Signed-off-by Puranjay Mohan <[email protected]>--- .../bindings/iio/temperature/ti,tmp117.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yamlDocumentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +5
-0@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/iio/temperature/ti,tmp117.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#"
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml line 15
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +10
-0+ +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]>"
Don't need quotes.
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml line 20
Quoted 5 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +5
-0+ +properties: + compatible: + enum: + - "ti,tmp117"
Don't need quotes.
Blank line here.
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml line 22
Quoted 2 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +2
-0+ reg: + maxItems: 1
blank line here.
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml line 33
Quoted 11 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +11
-0+required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>;
You could just add to trivial-devices.yaml.
Quoted 4 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +1
-0+ };Signature · 1 line
2.30.1
Jonathan Cameron
maintainerRe: [PATCH v2 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117
In reply to Puranjay MohanQuoted 38 lines · On Thu, 1 Apr 2021 14:46:47 +0530 Puranjay Mohan <[email protected]> wrote:
Add devicetree binding document for TMP117, a digital temperature sensor.
Signed-off-by Puranjay Mohan <[email protected]>--- .../bindings/iio/temperature/ti,tmp117.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yamlDocumentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +24
-0@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0 +%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
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml line 34
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/ti,tmp117.yaml new file +10
-0+ - reg + +additionalProperties: false + +examples: + - | + tmp117@48 { + compatible = "ti,tmp117"; + reg = <0x48>; + };
For the example embed it in an appropriate i2c description e.g.
i2c {
#address-cells = <1>;
#size-cells = <0>;
tmp117@48 {
compatible = "ti,tmp117";
reg = <0x48>;
};
};PATCH v2 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 | 179 +++++++++++++++++++++++++++++++ 4 files changed, 197 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 +179 -0
179 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Quoted 4 lines · Puranjay Mohan
TMP117 is a Digital temperature sensor with integrated NV memory.
Add support for tmp117 driver in iio subsystem.
+ blank line
Quoted 1 line
Datasheet:-https://www.ti.com/lit/gpn/tmp117
Make it a tag, i.e. remove the following blank line and use a space after colon.
Quoted 2 lines
Signed-off-by Puranjay Mohan <[email protected]>
...
Quoted 2 lines
+/*
+ *tmp117.c- Digital temperature sensor with integrated NV memory
It's useless and provokes an unneeded churn when having a file name inside the file.
Please, drop it for good.
Quoted 6 lines
+ *
+ * Copyright (c) 2021 Puranjay Mohan <[email protected]>
+ *
+ * Driver for the Texas Instruments TMP117 Temperature Sensor+ *
Redundant blank line.
Quoted 4 lines
+ * (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 16
Quoted 3 lines
drivers/iio/temperature/tmp117.c new file +3
-0+#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/module.h>
Missed:
bitops.h //sign_extend32()
types.h // s32
Quoted 2 lines
(quoted diff) +2
-0+ +#include <linux/iio/iio.h>
...
drivers/iio/temperature/tmp117.c line 36
Quoted 3 lines
drivers/iio/temperature/tmp117.c new file +3
-0+struct tmp117_data { +struct i2c_client *client; +};
Doesn't make any sense to have a separate structure for just one pointer member. Use that pointer directly.
...
drivers/iio/temperature/tmp117.c line 60
Quoted 7 lines
drivers/iio/temperature/tmp117.c new file +7
-0+case IIO_CHAN_INFO_CALIBBIAS : + ret =i2c_smbus_read_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET ); +if (ret <0 ) +return ret; + *val = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + /10000 ;
One line
drivers/iio/temperature/tmp117.c line 62
Quoted 2 lines
drivers/iio/temperature/tmp117.c new file +2
-0+ *val2 = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + %10000 ;
One line.
I'll be honest, I do not like these explicit castings at all. Can you revisit and try to refactor that you won't need them?
For example, I can't understand how ret can be higher than 16 bit since we checked on negative values beforehand.
drivers/iio/temperature/tmp117.c line 71
Quoted 9 lines
drivers/iio/temperature/tmp117.c new file +9
-0+return IIO_VAL_INT_PLUS_MICRO ; + +case IIO_CHAN_INFO_SCALE : +/* Conversion from 10s of uC to mC +* as IIO reports temperature in mC +*/ + *val =TMP117_RESOLUTION_10UC /10000 ; + *val2 = (TMP117_RESOLUTION_10UC %10000 ) *100 ; +return IIO_VAL_INT_PLUS_MICRO ;
You use 10000 many times, can you give it an appropriate name (via #define)?
...
drivers/iio/temperature/tmp117.c line 87
Quoted 5 lines
drivers/iio/temperature/tmp117.c new file +3
-0+s16 off; +case IIO_CHAN_INFO_CALIBBIAS : + off = (s16 )val;
Redundant explicit casting.
Quoted 2 lines
drivers/iio/temperature/tmp117.c new file +2
-0+return i2c_smbus_write_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET , off);
...
drivers/iio/temperature/tmp117.c line 157
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +3
-0+static const struct of_device_id tmp117_of_match[] = { + { .compatible ="ti,tmp117" , }, + { },
No need to comma in terminator line(s).
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Quoted 9 lines · Andy Shevchenko
[...]
drivers/iio/temperature/tmp117.c line 71
Quoted 7 lines
drivers/iio/temperature/tmp117.c new file +7
-0+case IIO_CHAN_INFO_SCALE : +/* Conversion from 10s of uC to mC +* as IIO reports temperature in mC +*/ + *val =TMP117_RESOLUTION_10UC /10000 ; + *val2 = (TMP117_RESOLUTION_10UC %10000 ) *100 ; +return IIO_VAL_INT_PLUS_MICRO ;You use 10000 many times, can you give it an appropriate name (via #define)?
#define TENTHOUSAND 10000 ;)
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Quoted 10 lines · Lars-Peter Clausen
Quoted 8 lines · Andy Shevchenko
[...]
Quoted 7 lines
drivers/iio/temperature/tmp117.c new file +7
-0+case IIO_CHAN_INFO_SCALE : +/* Conversion from 10s of uC to mC +* as IIO reports temperature in mC +*/ + *val =TMP117_RESOLUTION_10UC /10000 ; + *val2 = (TMP117_RESOLUTION_10UC %10000 ) *100 ; +return IIO_VAL_INT_PLUS_MICRO ;
Quoted 2 lines
Quoted 1 line
You use 10000 many times, can you give it an appropriate name (via #define)?
#define TENTHOUSAND 10000 ;)
Actually, besides April fool's day, this can have a value if 1000 is defined as mC _PER_uC or so.
Oh, wait. We have it already.
#define MILLIDEGREE_PER_DEGREE 1000
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
In reply to Puranjay MohanQuoted 6 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/tmp117Signed-off-by Puranjay Mohan <[email protected]>
Nice and clean driver. Just some comments about the CALIBBIAS.
Quoted 2 lines
[...]
+#defineTMP117_RESOLUTION_10UC78125
Isn't the unit here 100 uC?
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-0+#define TMP117_DEVICE_ID 0x0117 + +struct tmp117_data { +struct i2c_client *client; +}; + +static int tmp117_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *channel,int *val, +int *val2,long mask) +{
drivers/iio/temperature/tmp117.c line 62
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +9
-0+case IIO_CHAN_INFO_CALIBBIAS : + ret =i2c_smbus_read_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET ); +if (ret <0 ) +return ret; + *val = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + /10000 ; + *val2 = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + %10000 ;
If I understand this right CALBBIAS is written in one unit, but read in another unit. E.g. if you do echo 100 > ..._calibbias and then cat ..._calibbias you'd read a different value back.
I think that would be quite unexpected behavior. The unit should be the same. Here in the read function you can just return the register value. Just make sure to properly sign extend like for the RAW property.
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +3
-0+return IIO_VAL_INT_PLUS_MICRO ; +} +
drivers/iio/temperature/tmp117.c line 87
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +10
-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 = (s16 )val;
This should have some input validation to avoid writing bogus values to the register when the value is out of range. You can either reject out of range values or clamp them into the valid range (using the clamp() macro).
Quoted 8 lines
drivers/iio/temperature/tmp117.c new file +8
-0+return i2c_smbus_write_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET , off); + +default : +return -EINVAL ; + } +} +
[...]
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Quoted 7 lines · Lars-Peter Clausen
Quoted 5 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
Quoted 7 lines
Quoted 1 line
Signed-off-by Puranjay Mohan <[email protected]>Nice and clean driver. Just some comments about the CALIBBIAS.
Quoted 2 lines
[...]
+#defineTMP117_RESOLUTION_10UC78125Isn't the unit here 100 uC?
it is 7.8125 milli degrees_C so 78125 x 10^-4 milli degrees_C which is 78125 x 10^-4 x 10^3 micro degrees_C
so it becomes 78125 x 10^-1 micro degrees_C = 78125 10_microdegrees_C. Did it in detail so I remember it in the future. I guess you thought it as 0.78125 millidegrees_C?
Quoted 16 lines
Quoted 16 lines
drivers/iio/temperature/tmp117.c new file +15
-0+#define TMP117_DEVICE_ID 0x0117 + +struct tmp117_data { +struct i2c_client *client; +}; + +static int tmp117_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *channel,int *val, +int *val2,long mask) +{ +case IIO_CHAN_INFO_CALIBBIAS : + ret =i2c_smbus_read_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET ); +if (ret <0 ) +return ret;
Quoted 9 lines
drivers/iio/temperature/tmp117.c line 62
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +4
-0+ *val = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + /10000 ; + *val2 = ((int16_t )ret * (int32_t )TMP117_RESOLUTION_10UC ) + %10000 ;If I understand this right CALBBIAS is written in one unit, but read in another unit. E.g. if you do
echo 100 > ..._calibbiasand thencat ..._calibbiasyou'd read a different value back.
yes, reading it will return the value in milli degrees_C. but to write it should be in the register format according to the datasheet.
Quoted 2 lines
I think that would be quite unexpected behavior. The unit should be the same. Here in the read function you can just return the register value.
Okay, if you feel that would be right then I will do it.
Quoted 12 lines
Just make sure to properly sign extend like for the RAW property.
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +9
-0+return IIO_VAL_INT_PLUS_MICRO ; +} + +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;
Quoted 8 lines
drivers/iio/temperature/tmp117.c line 87
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +4
-0+ +switch (mask) { +case IIO_CHAN_INFO_CALIBBIAS : + off = (s16 )val;This should have some input validation to avoid writing bogus values to the register when the value is out of range. You can either reject out of range values or clamp them into the valid range (using the
clamp()macro).
the maximum value which this register takes is 0xffff, so it should get clamped automatically when casting to s16?
I might be wrong here.
Quoted 9 lines
Quoted 8 lines
drivers/iio/temperature/tmp117.c new file +8
-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
Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Quoted 10 lines · Puranjay Mohan
Quoted 9 lines · Lars-Peter Clausen
Quoted 6 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/tmp117Signed-off-by Puranjay Mohan <[email protected]>Nice and clean driver. Just some comments about the CALIBBIAS.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
[...]
+#defineTMP117_RESOLUTION_10UC78125Isn't the unit here 100 uC?
it is 7.8125 milli
degrees_Cso 78125 x 10^-4 millidegrees_Cwhich is 78125 x 10^-4 x 10^3 microdegrees_C
so it becomes 78125 x 10^-1 microdegrees_C= 78125 10_microdegrees_C. Did it in detail so I remember it in the future. I guess you thought it as 0.78125millidegrees_C?
Ah, I get it, it is a tenth micro degree, not tens of micro degrees, sorry got confused.
Quoted 5 lines
[...]
Quoted 2 lines
I think that would be quite unexpected behavior. The unit should be the same. Here in the read function you can just return the register value.
Okay, if you feel that would be right then I will do it.
Yea, I think reading and writing in different units would be a bit confusing.
Quoted 20 lines
Quoted 12 lines
Just make sure to properly sign extend like for the RAW property.
Quoted 10 lines
drivers/iio/temperature/tmp117.c new file +9
-0+return IIO_VAL_INT_PLUS_MICRO ; +} + +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;Quoted 8 lines
drivers/iio/temperature/tmp117.c line 87
Quoted 4 lines
drivers/iio/temperature/tmp117.c new file +4
-0+ +switch (mask) { +case IIO_CHAN_INFO_CALIBBIAS : + off = (s16 )val;This should have some input validation to avoid writing bogus values to the register when the value is out of range. You can either reject out of range values or clamp them into the valid range (using the
clamp()macro).
Quoted 3 lines
the maximum value which this register takes is
0xffff, so it should get clamped automatically when casting to s16?
I might be wrong here.
Casting will truncate the upper bits. So something like 0x12345 gets turned into 0x2345.
Quoted 12 lines
Quoted 10 lines
Quoted 9 lines
drivers/iio/temperature/tmp117.c new file +8
-0+return i2c_smbus_write_word_swapped (data->client, +TMP117_REG_TEMP_OFFSET , off); + +default : +return -EINVAL ; + } +} +[...]