Skip to contentSkip to conversation

dt-bindings: hwmon: add tmp464.yaml

PATCH Superseded Guenter Roeck 2 participants 8 messages Feb 18, 2022 – Feb 22, 2022

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v5 1/2 dt-bindings: hwmon: add tmp464.yaml

From: Agathe Porte <[email protected]>

Add basic description of the tmp464 driver DT bindings.

---
v5:
- Dropped ti,n-factor from channel@0 example. Added additional channel to examples to show positive ti,n-factor property.

v4:
- No changes

v3:
- Addedd support for TMP468.
- Changed number of channels from 0..3 (which was wrong anyway) to 0..8.
- Changed value range for ti,n-factor to int8, with an example for a negative value.
- Added myself as driver maintainer.

 .../devicetree/bindings/hwmon/ti,tmp464.yaml  | 114 ++++++++++++++++++
 MAINTAINERS                                   |   7 ++
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml
Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml new file +114 -0
new file mode 100644
index 000000000000..14f6a3412b8c
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/ti,tmp464.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TMP464 and TMP468 temperature sensors
+
+maintainers:
+  - Agathe Porte <[email protected]>
+
+description: |
+  ±0.0625°C Remote and Local temperature sensor
+  https://www.ti.com/lit/ds/symlink/tmp464.pdf
+  https://www.ti.com/lit/ds/symlink/tmp468.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,tmp464
+      - ti,tmp468
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+patternProperties:
+  "^channel@([0-8])$":
+    type: object
+    description: |
+      Represents channels of the device and their specific configuration.
+
+    properties:
+      reg:
+        description: |
+          The channel number. 0 is local channel, 1-8 are remote channels.
+        items:
+          minimum: 0
+          maximum: 8
+
+      label:
+        description: |
+          A descriptive name for this channel, like "ambient" or "psu".
+
+      ti,n-factor:
+        description: |
+          The value (two's complement) to be programmed in the channel specific N correction register.
+          For remote channels only.
+        $ref: /schemas/types.yaml#/definitions/int8
+        items:
+          minimum: -128
+          maximum: 127
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      sensor@4b {
+        compatible = "ti,tmp464";
+        reg = <0x4b>;
+      };
+    };
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      sensor@4b {
+        compatible = "ti,tmp464";
+        reg = <0x4b>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0x0>;
+          label = "local";
+        };
+
+        channel@1 {
+          reg = <0x1>;
+          ti,n-factor = /bits/ 8 <(-10)>;
+          label = "external";
+        };
+
+        channel@2 {
+          reg = <0x2>;
+          ti,n-factor = /bits/ 8 <0x10>;
+          label = "somelabel";
+        };
+
+        channel@3 {
+          reg = <0x3>;
+          status = "disabled";
+        };
+      };
+    };
MAINTAINERS +7 -0
index fca970a46e77..f51bc7c7e439 100644
@@ -19489,6 +19489,13 @@ S:	Maintained
 F:	Documentation/hwmon/tmp401.rst
 F:	drivers/hwmon/tmp401.c
 
+TMP464 HARDWARE MONITOR DRIVER
+M:	Agathe Porte <[email protected]>
+M:	Guenter Roeck <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml
+
 TMP513 HARDWARE MONITOR DRIVER
 M:	Eric Tremblay <[email protected]>
 L:	[email protected]
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH v5 2/2 hwmon: Add driver for Texas Instruments TMP464 and TMP468

Add support for Texas Instruments TMP464 and TMP468 temperature sensor ICs.

TI's TMP464 is an I2C temperature sensor chip. This chip is similar to TI's TMP421 chip, but with 16bit-wide registers (instead of 8bit-wide registers). The chip has one local sensor and four remote sensors. TMP468 is similar to TMP464 but has one local and eight remote sensors.

Originally-from: Agathe Porte <[email protected]>

Cc Agathe Porte <[email protected]>
Cc Krzysztof Adamski <[email protected]>

---
v5:
- Dropped unused variable

v4:
- Fixed reading n-factor information from devicetree
[Use of_property_read_u8 instead of of_property_read_s32 to read the
property value, and write n-factor value into the upper 8 bit of the n-factor register]
- Fixed displaying label attributes

v3:
- Added support for TMP468
- Added support for various limits, temperature hysteresis, alarm attributes, and update interval
- Use regmap instead of local caching
- Use static chip configuration
- Unlock check if needed when loading driver, and lock it when unloading it
- Call tmp464_init_client() before calling tmp464_probe_from_dt() since the latter changes registers, which requires the chip to be unlocked.
- Restore configuration register when unloading driver
- ti,n-factor is optional, so don't fail if the property is not present

Notes:
- Tested with real TMP468. Module tested for TMP464. Devicetree code tested with rudimentary qemu implementation.

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/tmp464.rst |  73 ++++
 MAINTAINERS                    |   2 +
 drivers/hwmon/Kconfig          |  11 +
 drivers/hwmon/Makefile         |   1 +
 drivers/hwmon/tmp464.c         | 689 +++++++++++++++++++++++++++++++++
 6 files changed, 777 insertions(+)
 create mode 100644 Documentation/hwmon/tmp464.rst
 create mode 100644 drivers/hwmon/tmp464.c
Documentation/hwmon/index.rst +1 -0
index df20022c741f..37590db85e65 100644
@@ -193,6 +193,7 @@ Hardware Monitoring Kernel Drivers
    tmp108
    tmp401
    tmp421
+   tmp464
    tmp513
    tps23861
    tps40422
Documentation/hwmon/tmp464.rst new file +73 -0

73 lines not on this page · raw message

MAINTAINERS +2 -0
index f51bc7c7e439..9b51bf5ca3b8 100644
@@ -19495,6 +19495,8 @@ M:	Guenter Roeck <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml
+F:	Documentation/hwmon/tmp464.rst
+F:	drivers/hwmon/tmp464.c
 
 TMP513 HARDWARE MONITOR DRIVER
 M:	Eric Tremblay <[email protected]>
drivers/hwmon/Kconfig +11 -0
index 8df25f1079ba..b84932fd0c13 100644
@@ -1979,6 +1979,17 @@ config SENSORS_TMP421
 	  This driver can also be built as a module. If so, the module
 	  will be called tmp421.
 
+config SENSORS_TMP464
+	tristate "Texas Instruments TMP464 and compatible"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  If you say yes here you get support for Texas Instruments TMP464
+	  and TMP468 temperature sensor chips.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called tmp464.
+
 config SENSORS_TMP513
 	tristate "Texas Instruments TMP513 and compatibles"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index 185f946d698b..a1f2d6686227 100644
@@ -194,6 +194,7 @@ obj-$(CONFIG_SENSORS_TMP103)	+= tmp103.o
 obj-$(CONFIG_SENSORS_TMP108)	+= tmp108.o
 obj-$(CONFIG_SENSORS_TMP401)	+= tmp401.o
 obj-$(CONFIG_SENSORS_TMP421)	+= tmp421.o
+obj-$(CONFIG_SENSORS_TMP464)	+= tmp464.o
 obj-$(CONFIG_SENSORS_TMP513)	+= tmp513.o
 obj-$(CONFIG_SENSORS_VEXPRESS)	+= vexpress-hwmon.o
 obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o
drivers/hwmon/tmp464.c new file +689 -0

689 lines not on this page · raw message

Signature · 1 line
2.35.1
#2 lore raw
In reply to Guenter Roeck

Dnia Fri, Feb 18, 2022 at 07:09:07AM -0800, Guenter Roeck napisał(a):

Quoted 86 lines

From: Agathe Porte <[email protected]>

Add basic description of the tmp464 driver DT bindings.

---
v5:
- Dropped ti,n-factor from channel@0 example. Added additional channel to examples to show positive ti,n-factor property.

v4:
- No changes

v3:
- Addedd support for TMP468.
- Changed number of channels from 0..3 (which was wrong anyway) to 0..8.
- Changed value range for ti,n-factor to int8, with an example for a negative value.
- Added myself as driver maintainer.

.../devicetree/bindings/hwmon/ti,tmp464.yaml | 114 ++++++++++++++++++
MAINTAINERS | 7 ++

2 files changed, 121 insertions(+)

create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml

Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml new file +53 -0
new file mode 100644
index 000000000000..14f6a3412b8c
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/ti,tmp464.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TMP464 and TMP468 temperature sensors
+
+maintainers:
+  - Agathe Porte <[email protected]>
+
+description: |
+  ±0.0625°C Remote and Local temperature sensor
+  https://www.ti.com/lit/ds/symlink/tmp464.pdf
+  https://www.ti.com/lit/ds/symlink/tmp468.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,tmp464
+      - ti,tmp468
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+patternProperties:
+  "^channel@([0-8])$":
+    type: object
+    description: |
+      Represents channels of the device and their specific configuration.
+
+    properties:
+      reg:
+        description: |
+          The channel number. 0 is local channel, 1-8 are remote channels.
+        items:
+          minimum: 0
+          maximum: 8
+
+      label:
+        description: |

Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml new file +10 -0
+          A descriptive name for this channel, like "ambient" or "psu".
+
+      ti,n-factor:
+        description: |
+          The value (two's complement) to be programmed in the channel specific N correction register.
+          For remote channels only.
+        $ref: /schemas/types.yaml#/definitions/int8
+        items:
+          minimum: -128
+          maximum: 127

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

Krzysztof

author maintainer
#3 lore raw
Quoted 96 lines · Krzysztof Adamski

Dnia Fri, Feb 18, 2022 at 07:09:07AM -0800, Guenter Roeck napisał(a):

Quoted 95 lines

From: Agathe Porte <[email protected]>

Add basic description of the tmp464 driver DT bindings.

---
v5:
- Dropped ti,n-factor from channel@0 example. Added additional channel to examples to show positive ti,n-factor property.

v4:
- No changes

v3:
- Addedd support for TMP468.
- Changed number of channels from 0..3 (which was wrong anyway) to 0..8.
- Changed value range for ti,n-factor to int8, with an example for a negative value.
- Added myself as driver maintainer.

.../devicetree/bindings/hwmon/ti,tmp464.yaml  | 114 ++++++++++++++++++ MAINTAINERS                                   |   7 ++

2 files changed, 121 insertions(+)

create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml

Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml new file +62 -0
new file mode 100644
index 000000000000..14f6a3412b8c
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/ti,tmp464.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TMP464 and TMP468 temperature sensors
+
+maintainers:
+  - Agathe Porte <[email protected]>
+
+description: |
+  ±0.0625°C Remote and Local temperature sensor
+  https://www.ti.com/lit/ds/symlink/tmp464.pdf
+  https://www.ti.com/lit/ds/symlink/tmp468.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,tmp464
+      - ti,tmp468
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+patternProperties:
+  "^channel@([0-8])$":
+    type: object
+    description: |
+      Represents channels of the device and their specific configuration.
+
+    properties:
+      reg:
+        description: |
+          The channel number. 0 is local channel, 1-8 are remote channels.
+        items:
+          minimum: 0
+          maximum: 8
+
+      label:
+        description: |
+          A descriptive name for this channel, like "ambient" or "psu".
+
+      ti,n-factor:
+        description: |
+          The value (two's complement) to be programmed in the channel specific N correction register.
+          For remote channels only.
+        $ref: /schemas/types.yaml#/definitions/int8
+        items:
+          minimum: -128
Quoted 9 lines

Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml line 63

Quoted 1 line
Documentation/devicetree/bindings/hwmon/ti,tmp464.yaml new file +1 -0
+          maximum: 127

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

I seem to recall from that discussion that there was supposedly no way to express negative numbers in devicetree. Obviously that is incorrect. In addition to that, I strongly suspect that the tmp421 code as written does not work. Its value range is specified as 0..255, but it is read with

	err = of_property_read_s32(child, "ti,n-factor", &val);
and range checked with
	if (val > 127 || val < -128) {
                dev_err(dev, "n-factor for channel %d invalid (%d)\n",
                       i, val);
                return -EINVAL;
        }

That just looks wrong. Either the value range is 0..255 and checked as 0 .. 255, or it is -128 .. 127 and must be both checked and specified accordingly. This made me look into the code and I found how negative numbers are supposed to be handled.

We can go either way, but whatever it is should be correct and be confirmed to work. Rob, any thoughts ?

Guenter

#4 lore raw

Dnia Mon, Feb 21, 2022 at 08:16:15AM -0800, Guenter Roeck napisał(a):

Quoted 10 lines
Quoted 7 lines

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

I seem to recall from that discussion that there was supposedly no way to express negative numbers in devicetree. Obviously that is incorrect.

Well, I would still argue it *is* correct. DT only support unsigned numbers and, really, only 32 or 64 bit. See the chapter 2.2.4 Properties in:
https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf

Devicetree also supports array of bytes, and this is how we get the /bits/ magic but this is just a syntactic suggar. The same is true about negative values. Just decompile your compiled DTB and you will see. To put it in other words - DTS does support negative values, DTB don't.j

Quoted 10 lines

In addition to that, I strongly suspect that the tmp421 code as written does not work. Its value range is specified as 0..255, but it is read with

	err = of_property_read_s32(child, "ti,n-factor", &val);
and range checked with
	if (val > 127 || val < -128) {
               dev_err(dev, "n-factor for channel %d invalid (%d)\n",
                      i, val);
               return -EINVAL;
       }
Quoted 4 lines

That just looks wrong. Either the value range is 0..255 and checked as 0 .. 255, or it is -128 .. 127 and must be both checked and specified accordingly. This made me look into the code and I found how negative numbers are supposed to be handled.

It worked for me when I tested that. I could redo the test, if you are unsure. The code also looks good to me. I wasn't convinced for this format in yaml but after the whole discussion we had, we settled on that, with Robs blessing :)

Here's the actual discussion where all this was considered:
https://patchwork.kernel.org/project/linux-hwmon/patch/3ff7b4cc57dab2073fa091072366c1e524631729.1632984254.git.krzysztof.adamski@nokia.com/

I'm not saying the way we do this for tmp421 is better or even right, all I say is that it would make sense to be consistent and not redo this discussion every time we have this problem.

Krzysztof

author maintainer
#5 lore raw
Quoted 37 lines · Krzysztof Adamski

Dnia Mon, Feb 21, 2022 at 08:16:15AM -0800, Guenter Roeck napisał(a):

Quoted 10 lines
Quoted 7 lines

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

I seem to recall from that discussion that there was supposedly no way to express negative numbers in devicetree. Obviously that is incorrect.

Well, I would still argue it *is* correct. DT only support unsigned numbers and, really, only 32 or 64 bit. See the chapter 2.2.4 Properties in:
https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf

Devicetree also supports array of bytes, and this is how we get the /bits/ magic but this is just a syntactic suggar. The same is true about negative values. Just decompile your compiled DTB and you will see. To put it in other words - DTS does support negative values, DTB don't.j

Quoted 10 lines

In addition to that, I strongly suspect that the tmp421 code as written does not work. Its value range is specified as 0..255, but it is read with err = of_property_read_s32(child, "ti,n-factor", &val); and range checked with
    if (val > 127 || val < -128) {
               dev_err(dev, "n-factor for channel %d invalid (%d)\n", i, val);
               return -EINVAL;
       }

Quoted 4 lines

That just looks wrong. Either the value range is 0..255 and checked as 0 .. 255, or it is -128 .. 127 and must be both checked and specified accordingly. This made me look into the code and I found how negative numbers are supposed to be handled.

Quoted 5 lines

It worked for me when I tested that. I could redo the test, if you are unsure. The code also looks good to me. I wasn't convinced for this format in yaml but after the whole discussion we had, we settled on that, with Robs blessing :)

It is hard for me to believe that you can enter, say, 255 into the dts file and of_property_read_s32() reads it as -1. If so, of_property_read_s32() could never support values of 128 and above, which seems unlikely.

Now, I can imagine that one can enter 0xffffffff and of_property_read_s32() returns -1, but that isn't what is documented for tmp421.

Guenter

Quoted 8 lines

Here's the actual discussion where all this was considered:
https://patchwork.kernel.org/project/linux-hwmon/patch/3ff7b4cc57dab2073fa091072366c1e524631729.1632984254.git.krzysztof.adamski@nokia.com/

I'm not saying the way we do this for tmp421 is better or even right, all I say is that it would make sense to be consistent and not redo this discussion every time we have this problem.

Krzysztof

#6 lore raw

Dnia Mon, Feb 21, 2022 at 02:11:17PM -0800, Guenter Roeck napisał(a):

Quoted 44 lines · Krzysztof Adamski
Quoted 37 lines

Dnia Mon, Feb 21, 2022 at 08:16:15AM -0800, Guenter Roeck napisał(a):

Quoted 10 lines
Quoted 7 lines

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

I seem to recall from that discussion that there was supposedly no way to express negative numbers in devicetree. Obviously that is incorrect.

Well, I would still argue it *is* correct. DT only support unsigned numbers and, really, only 32 or 64 bit. See the chapter 2.2.4 Properties in:
https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf

Devicetree also supports array of bytes, and this is how we get the /bits/ magic but this is just a syntactic suggar. The same is true about negative values. Just decompile your compiled DTB and you will see. To put it in other words - DTS does support negative values, DTB don't.j

Quoted 10 lines

In addition to that, I strongly suspect that the tmp421 code as written does not work. Its value range is specified as 0..255, but it is read with err = of_property_read_s32(child, "ti,n-factor", &val); and range checked with
    if (val > 127 || val < -128) {
               dev_err(dev, "n-factor for channel %d invalid (%d)\n", i, val);
               return -EINVAL;
       }

Quoted 4 lines

That just looks wrong. Either the value range is 0..255 and checked as 0 .. 255, or it is -128 .. 127 and must be both checked and specified accordingly. This made me look into the code and I found how negative numbers are supposed to be handled.

Quoted 5 lines

It worked for me when I tested that. I could redo the test, if you are unsure. The code also looks good to me. I wasn't convinced for this format in yaml but after the whole discussion we had, we settled on that, with Robs blessing :)

Quoted 7 lines

It is hard for me to believe that you can enter, say, 255 into the dts file and of_property_read_s32() reads it as -1. If so, of_property_read_s32() could never support values of 128 and above, which seems unlikely.

Now, I can imagine that one can enter 0xffffffff and of_property_read_s32() returns -1, but that isn't what is documented for tmp421.

Yes, you are correct, you have to enter either <(-1)> or <0xffffffff> (which is the same thing). I was quite confused on how to specify that in DT bindings and apparently maybe we did not understand each other well enough back when the patch was submitted. The code and the description is correct, though, so the question is how to properly set "minimum" and "maximum" value.

I think I should at least update the example of tmp421 in the binding to use <(-1)> notation to make it obvious that it works this way. But I guess we need Rob to help us understand how this should be specified.

In any case, if you drop usage of /bits 8/ and keep the property naitive 32 bit, both tmp421 and tmp464 bindings will be compatible with each other.

@Rob, if I want a property ti,n-factor be in in range from <(-128)> to <127>, so that we can use of_property_read_s32() and then use just one byte of that, how to specify that in yaml file? For TMP421, we currently have:

ti,n-factor:
description: |
The value (two's complement) to be programmed in the channel specific N correction register. For remote channels only.
$ref: /schemas/types.yaml#/definitions/uint32
items:

     minimum: 0
     maximum: 255

which is confusing.

Guenter is proposing to use
$ref: /schemas/types.yaml#/definitions/int8
items:
minimum: -128
maximum: 127

and of_property_read_u8() for the same property on another driver, so usage of /bits/ 8 is required. Which approach is better in your opinion?

Krzysztof

Krzysztof

author maintainer
#7 lore raw
Quoted 53 lines · Krzysztof Adamski

Dnia Mon, Feb 21, 2022 at 02:11:17PM -0800, Guenter Roeck napisał(a):

Quoted 44 lines · Krzysztof Adamski
Quoted 37 lines

Dnia Mon, Feb 21, 2022 at 08:16:15AM -0800, Guenter Roeck napisał(a):

Quoted 10 lines
Quoted 7 lines

I still thing we should have the same format here and in tmp421, for consistency. If use the same property name, "ti,n-factor" but on tmp421 you have use 32bit value while here you have to use 8bit (which is weird in DT, BTW), it might be confusing.
Back when we did this for TMP421, there was some discussion and we settled on this approach, why do it differently now?

I seem to recall from that discussion that there was supposedly no way to express negative numbers in devicetree. Obviously that is incorrect.

Well, I would still argue it *is* correct. DT only support unsigned numbers and, really, only 32 or 64 bit. See the chapter 2.2.4 Properties in:
https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf

Devicetree also supports array of bytes, and this is how we get the /bits/ magic but this is just a syntactic suggar. The same is true about negative values. Just decompile your compiled DTB and you will see. To put it in other words - DTS does support negative values, DTB don't.j

Quoted 10 lines

In addition to that, I strongly suspect that the tmp421 code as written does not work. Its value range is specified as 0..255, but it is read with err = of_property_read_s32(child, "ti,n-factor", &val); and range checked with
    if (val > 127 || val < -128) {
               dev_err(dev, "n-factor for channel %d invalid (%d)\n", i, val);
               return -EINVAL;
       }

Quoted 4 lines

That just looks wrong. Either the value range is 0..255 and checked as 0 .. 255, or it is -128 .. 127 and must be both checked and specified accordingly. This made me look into the code and I found how negative numbers are supposed to be handled.

Quoted 5 lines

It worked for me when I tested that. I could redo the test, if you are unsure. The code also looks good to me. I wasn't convinced for this format in yaml but after the whole discussion we had, we settled on that, with Robs blessing :)

Quoted 7 lines

It is hard for me to believe that you can enter, say, 255 into the dts file and of_property_read_s32() reads it as -1. If so, of_property_read_s32() could never support values of 128 and above, which seems unlikely.

Now, I can imagine that one can enter 0xffffffff and of_property_read_s32() returns -1, but that isn't what is documented for tmp421.

Quoted 5 lines

Yes, you are correct, you have to enter either <(-1)> or <0xffffffff> (which is the same thing). I was quite confused on how to specify that in DT bindings and apparently maybe we did not understand each other well enough back when the patch was submitted. The code and the description is correct, though, so the question is how to properly set

Here is where we disagree. The bindings say:

    items:
      minimum: 0
      maximum: 255

Based on this, the following devicetree configuration should be correct.

        tmp423a@4c {
                compatible = "ti,tmp423";
                reg = <0x4c>;
		#address-cells = <1>;
                #size-cells = <0>;
 
                channel@1 {
                    reg = <1>;
                    ti,n-factor = <255>;
                };
        };

However, it results in:

tmp421 4-004c: n-factor for channel 1 invalid (255)
tmp421: probe of 4-004c failed with error -22

Either the range is 0 ... 255 and we need to accept 0 ... 255, or the range is -128 ... 127 and we need to accept -128 ... 127.

Quoted 26 lines

"minimum" and "maximum" value.

I think I should at least update the example of tmp421 in the binding to use <(-1)> notation to make it obvious that it works this way. But I guess we need Rob to help us understand how this should be specified.

In any case, if you drop usage of /bits 8/ and keep the property naitive 32 bit, both tmp421 and tmp464 bindings will be compatible with each other.

@Rob, if I want a property ti,n-factor be in in range from <(-128)> to <127>, so that we can use of_property_read_s32() and then use just one byte of that, how to specify that in yaml file? For TMP421, we currently have:

ti,n-factor:
description: |
The value (two's complement) to be programmed in the channel specific N correction register. For remote channels only.
$ref: /schemas/types.yaml#/definitions/uint32
items:

     minimum: 0
     maximum: 255

which is confusing.

Quoted 9 lines

Guenter is proposing to use
$ref: /schemas/types.yaml#/definitions/int8
items:

   minimum: -128
   maximum: 127

and of_property_read_u8() for the same property on another driver, so usage of /bits/ 8 is required. Which approach is better in your opinion?

I could declare the property as int32, use of_property_read_s32, and validate the range in the driver. However, the range still needs to match the documentation.

Guenter