Skip to contentSkip to conversation

dt-bindings: hwmon: ti,tmp401: Add channel nodes with label property

PATCH In review Bruno Thomsen 3 participants 5 messages Nov 18 – Nov 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dt-bindings: hwmon: ti,tmp401: Add channel nodes with label property

TMP401, TMP411, TMP431 and TMP435 have one local and one remote temperature channel; TMP432 has two remote channels. The local channel measures the board where the chip sits and a remote channel measures whatever diode is wired to it, so only the board design says what each channel is.

kam,am335x-emperor-mini fits a TMP431 in place of the NXP SA56004 on kam,am335x-emperor, at the same I2C address. On both boards the local channel measures the baseboard and the remote channel the FPGA's thermal diode. national,lm90.yaml already lets the SA56004 name its channels through channel nodes with a label property; add the same nodes to ti,tmp401 so the TMP431 channels get the same names.

---
v1: https://lore.kernel.org/linux-hwmon/[email protected]/

Changes in v2:
- Rewrite commit message around the board that needs per-channel labels, rather than referring to other bindings. (Krzysztof)
- Quote '#address-cells' and '#size-cells' consistently with the patternProperties key. (Krzysztof)
- Drop the new example and extend the existing ti,tmp431 example with the channel nodes instead. (Krzysztof)
- Reword subject: the patch adds channel nodes, not just a property.
- Rebase on the new "#thermal-sensor-cells" property, which moved the patternProperties context.

The "kam,am335x-emperor" device tree series that consumes this is at
https://lore.kernel.org/linux-devicetree/[email protected]/
Its v2 adds "kam,am335x-emperor-mini", which uses these channel nodes.

---
 .../devicetree/bindings/hwmon/ti,tmp401.yaml  | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
Documentation/devicetree/bindings/hwmon/ti,tmp401.yaml +48 -0
index f283b567d5b6..b162bf8c043a 100644
@@ -30,6 +30,12 @@ properties:
   reg:
     maxItems: 1
 
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
   ti,extended-range-enable:
     description:
       When set, this sensor measures over extended temperature range.
@@ -53,6 +59,26 @@ properties:
   "#thermal-sensor-cells":
     const: 1
 
+patternProperties:
+  "^channel@([0-2])$":
+    type: object
+    description: Represents channels of the device and their specific configuration.
+
+    properties:
+      reg:
+        description: The channel number. 0 is local channel, 1-2 are remote channels.
+        items:
+          minimum: 0
+          maximum: 2
+
+      label:
+        description: A descriptive name for this channel, like "ambient" or "psu".
+
+    required:
+      - reg
+
+    additionalProperties: false
+
 allOf:
   - if:
       properties:
@@ -75,6 +101,16 @@ allOf:
       properties:
         ti,beta-compensation: false
 
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              const: ti,tmp432
+    then:
+      properties:
+        channel@2: false
+
 required:
   - compatible
   - reg
@@ -103,5 +139,17 @@ examples:
         ti,extended-range-enable;
         ti,n-factor = <0x3b>;
         ti,beta-compensation = <0x7>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0x0>;
+          label = "mainboard";
+        };
+
+        channel@1 {
+          reg = <0x1>;
+          label = "fpga";
+        };
       };
     };

base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4

Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 2/2 hwmon: (tmp401) add channel label support

Read the optional per-channel label from the device tree and expose it through tempX_label, so user space can select a temperature sensor by the name the board gives it instead of hardcoding a sysfs index.

The channel index comes from the child node reg property. Reject a reg value that the detected chip does not implement, since only TMP432 has a second remote channel; accepting it would add a tempX_label with no matching tempX_input.

This mirrors what lm90 already does.

---
Changes in v2:
- Fix continuation-line alignment in tmp401_read_string() reported by checkpatch --strict.
- Expand commit message: the channel index comes from the child node reg property, and a reg value the detected chip does not implement is rejected so no tempX_label is created without a tempX_input.
- Skip child nodes not named "channel", as lm90 and tmp421 do.

---
 drivers/hwmon/tmp401.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/hwmon/tmp401.c +36 -0
index 2fceeacdc88c..7b645d982c9a 100644
@@ -117,6 +117,7 @@ struct tmp401_data {
 	struct hwmon_channel_info temp_info;
 	const struct hwmon_channel_info *info[3];
 	struct hwmon_chip_info chip;
+	const char *channel_label[4];
 };
 
 /* regmap */
@@ -467,6 +468,16 @@ static int tmp401_read(struct device *dev, enum hwmon_sensor_types type,
 	}
 }
 
+static int tmp401_read_string(struct device *dev, enum hwmon_sensor_types type,
+			      u32 attr, int channel, const char **str)
+{
+	struct tmp401_data *data = dev_get_drvdata(dev);
+
+	*str = data->channel_label[channel];
+
+	return 0;
+}
+
 static int tmp401_write(struct device *dev, enum hwmon_sensor_types type,
 			u32 attr, int channel, long val)
 {
@@ -502,6 +513,7 @@ static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type,
 		case hwmon_temp_fault:
 		case hwmon_temp_lowest:
 		case hwmon_temp_highest:
+		case hwmon_temp_label:
 			return 0444;
 		case hwmon_temp_min:
 		case hwmon_temp_max:
@@ -521,6 +533,7 @@ static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type,
 static const struct hwmon_ops tmp401_ops = {
 	.is_visible = tmp401_is_visible,
 	.read = tmp401_read,
+	.read_string = tmp401_read_string,
 	.write = tmp401_write,
 };
 
@@ -531,6 +544,7 @@ static int tmp401_init_client(struct tmp401_data *data)
 	struct regmap *regmap = data->regmap;
 	u32 config, config_orig;
 	int ret;
+	u32 ch;
 	u32 val = 0;
 	s32 nfactor = 0;
 
@@ -590,6 +604,28 @@ static int tmp401_init_client(struct tmp401_data *data)
 			return ret;
 	}
 
+	for_each_child_of_node_scoped(data->client->dev.of_node, child) {
+		if (!of_node_name_eq(child, "channel"))
+			continue;
+		ret = of_property_read_u32(child, "reg", &ch);
+		if (ret) {
+			dev_err(&data->client->dev, "missing reg property of %pOFn\n", child);
+			return ret;
+		}
+		if (ch >= ARRAY_SIZE(data->temp_channel_config) ||
+		    !data->temp_channel_config[ch]) {
+			dev_err(&data->client->dev, "invalid reg %u of %pOFn\n", ch, child);
+			return -EINVAL;
+		}
+		ret = of_property_read_string(child, "label", &data->channel_label[ch]);
+		if (ret == -ENODATA || ret == -EILSEQ) {
+			dev_err(&data->client->dev, "invalid label property in %pOFn\n", child);
+			return ret;
+		}
+		if (data->channel_label[ch])
+			data->temp_channel_config[ch] |= HWMON_T_LABEL;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 2/2] hwmon: (tmp401) add channel label support

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

Read the optional per-channel label from the device tree and expose it through tempX_label, so user space can select a temperature sensor by the name the board gives it instead of hardcoding a sysfs index.

Quoted 8 lines

The channel index comes from the child node reg property. Reject a reg value that the detected chip does not implement, since only TMP432 has a second remote channel; accepting it would add a tempX_label with no matching tempX_input.

This mirrors what lm90 already does.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] hwmon: (tmp401) add channel label support

In reply to Bruno Thomsen
Quoted 4 lines · Bruno Thomsen

Read the optional per-channel label from the device tree and expose it through tempX_label, so user space can select a temperature sensor by the name the board gives it instead of hardcoding a sysfs index.

Quoted 8 lines

The channel index comes from the child node reg property. Reject a reg value that the detected chip does not implement, since only TMP432 has a second remote channel; accepting it would add a tempX_label with no matching tempX_input.

This mirrors what lm90 already does.

For my reference:

Quoted 94 lines

---
Changes in v2:
- Fix continuation-line alignment in tmp401_read_string() reported by checkpatch --strict.
- Expand commit message: the channel index comes from the child node reg property, and a reg value the detected chip does not implement is rejected so no tempX_label is created without a tempX_input.
- Skip child nodes not named "channel", as lm90 and tmp421 do.

---
  drivers/hwmon/tmp401.c | 36 ++++++++++++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)
drivers/hwmon/tmp401.c +36 -0
index 2fceeacdc88c..7b645d982c9a 100644
@@ -117,6 +117,7 @@ struct tmp401_data {
  	struct hwmon_channel_info temp_info;
  	const struct hwmon_channel_info *info[3];
  	struct hwmon_chip_info chip;
+	const char *channel_label[4];
  };
 
  /* regmap */
@@ -467,6 +468,16 @@ static int tmp401_read(struct device *dev, enum hwmon_sensor_types type,
  	}
  }
 
+static int tmp401_read_string(struct device *dev, enum hwmon_sensor_types type,
+			      u32 attr, int channel, const char **str)
+{
+	struct tmp401_data *data = dev_get_drvdata(dev);
+
+	*str = data->channel_label[channel];
+
+	return 0;
+}
+
  static int tmp401_write(struct device *dev, enum hwmon_sensor_types type,
  			u32 attr, int channel, long val)
  {
@@ -502,6 +513,7 @@ static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type,
  		case hwmon_temp_fault:
  		case hwmon_temp_lowest:
  		case hwmon_temp_highest:
+		case hwmon_temp_label:
  			return 0444;
  		case hwmon_temp_min:
  		case hwmon_temp_max:
@@ -521,6 +533,7 @@ static umode_t tmp401_is_visible(const void *data, enum hwmon_sensor_types type,
  static const struct hwmon_ops tmp401_ops = {
  	.is_visible = tmp401_is_visible,
  	.read = tmp401_read,
+	.read_string = tmp401_read_string,
  	.write = tmp401_write,
  };
 
@@ -531,6 +544,7 @@ static int tmp401_init_client(struct tmp401_data *data)
  	struct regmap *regmap = data->regmap;
  	u32 config, config_orig;
  	int ret;
+	u32 ch;
  	u32 val = 0;
  	s32 nfactor = 0;
 
@@ -590,6 +604,28 @@ static int tmp401_init_client(struct tmp401_data *data)
  			return ret;
  	}
 
+	for_each_child_of_node_scoped(data->client->dev.of_node, child) {
+		if (!of_node_name_eq(child, "channel"))
+			continue;
+		ret = of_property_read_u32(child, "reg", &ch);
+		if (ret) {
+			dev_err(&data->client->dev, "missing reg property of %pOFn\n", child);
+			return ret;
+		}
+		if (ch >= ARRAY_SIZE(data->temp_channel_config) ||
+		    !data->temp_channel_config[ch]) {
+			dev_err(&data->client->dev, "invalid reg %u of %pOFn\n", ch, child);
+			return -EINVAL;
+		}
+		ret = of_property_read_string(child, "label", &data->channel_label[ch]);
+		if (ret == -ENODATA || ret == -EILSEQ) {
+			dev_err(&data->client->dev, "invalid label property in %pOFn\n", child);
+			return ret;
+		}
+		if (data->channel_label[ch])
+			data->temp_channel_config[ch] |= HWMON_T_LABEL;
+	}
+
  	return 0;
  }
 
#4 lore raw
In reply to Bruno Thomsen
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

TMP401, TMP411, TMP431 and TMP435 have one local and one remote temperature channel; TMP432 has two remote channels. The local channel measures the board where the chip sits and a remote channel measures whatever diode is wired to it, so only the board design says what each channel is.

Quoted 8 lines

kam,am335x-emperor-mini fits a TMP431 in place of the NXP SA56004 on kam,am335x-emperor, at the same I2C address. On both boards the local channel measures the baseboard and the remote channel the FPGA's thermal diode. national,lm90.yaml already lets the SA56004 name its channels through channel nodes with a label property; add the same nodes to ti,tmp401 so the TMP431 channels get the same names.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1