linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] Add per channel properies support in tmp421
@ 2021-09-24  9:36 Krzysztof Adamski
  2021-09-24  9:38 ` [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding Krzysztof Adamski
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:36 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Hi,

This series adds support for defining per-channel properies (like
n-factor and label) to the TMP421 driver. It starts by adding the
missing DT binding for tmp421, in the form that was there before any of
my changes. Then I do the changes to the driver and finally adjust the
bindings to my changes.

The precedence for this case is:
[PATCH v9 2/2] hwmon: (ina3221) Read channel input source info from DT
Which can be found here:
https://lkml.org/lkml/2018/10/2/136

My patches does similar thing but to tmp422 - we need a way to define
the labels for specific channels as well as to define the n-factor (that
is board specific as it depends on the diodes used for remote sensing).
A possibility to disable unused channels seems like a good idea too.

Here comes V2. Changes compared to v1:
- renamed tmp421.yaml to ti,tmp421.yaml
- fixed sparse warnings about making function declarations static
- changed the policy for broken DT - in case of errors, the probe will
  return an error instead of continuing
- in addition to disabling the channels specified in DT, the probe
  function will also enable all the others in case they were disabled by
  some other code earlier
  NOTE: this may be a backwards incompatible change - if some channels
  were disabled by some bootloader code previously the channels would
  stay like that and now they would be enabled during probe, even if
  nothing is specified in DT. Is this what we want?
- added support for HWMON_T_ENABLE
- updated documentation
- NOTE: I haven't changed anything related to DT as the discussion has
  no clear conclusion yet.

Krzysztof Adamski (10):
  dt-bindings: hwmon: add missing tmp421 binding
  hwmon: (tmp421) introduce MAX_CHANNELS define
  hwmon: (tmp421) introduce a channel struct
  hwmon: (tmp421) add support for defining labels from DT
  hwmon: (tmp421) support disabling channels from DT
  hwmon: (tmp421) support specifying n-factor via DT
  hwmon: (tmp421) really disable channels
  hwmon: (tmp421) support HWMON_T_ENABLE
  hwmon: (tmp421) update documentation
  dt-bindings: hwmon: allow specifying channels for tmp421

 .../devicetree/bindings/hwmon/ti,tmp421.yaml  | 109 +++++++++++
 Documentation/hwmon/tmp421.rst                |  10 +
 drivers/hwmon/tmp421.c                        | 172 ++++++++++++++++--
 3 files changed, 280 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml

-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
@ 2021-09-24  9:38 ` Krzysztof Adamski
  2021-09-24 12:45   ` Rob Herring
  2021-09-24  9:39 ` [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define Krzysztof Adamski
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:38 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Add basic description of the tmp421 driver DT bindings.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 .../devicetree/bindings/hwmon/ti,tmp421.yaml  | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml b/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
new file mode 100644
index 000000000000..53940e146ee6
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/tmp421.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TMP42x/TMP44x temperature sensor
+
+maintainers:
+  - Guenter Roeck <linux@roeck-us.net>
+
+description: |
+  ±1°C Remote and Local temperature sensor
+  https://www.ti.com/lit/ds/symlink/tmp422.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,tmp421
+      - ti,tmp422
+      - ti,tmp423
+      - ti,tmp441
+      - ti,tmp442
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      sensor@4c {
+        compatible = "ti,tmp422";
+        reg = <0x4c>;
+      };
+    };
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
  2021-09-24  9:38 ` [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding Krzysztof Adamski
@ 2021-09-24  9:39 ` Krzysztof Adamski
  2021-09-24 12:05   ` Guenter Roeck
  2021-09-24  9:39 ` [PATCH v2 03/10] hwmon: (tmp421) introduce a channel struct Krzysztof Adamski
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:39 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

There are few places where the maximal number of channels is used define
the size of arrays but when raw number is used it is not clear that they
really related to this quantity.
This commit introduces MAX_CHANNELS define and uses it those places to
give some context to the number.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index ede66ea6a730..2c9ba5fe5f2a 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -29,6 +29,7 @@ static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f,
 
 enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
 
+#define MAX_CHANNELS				4
 /* The TMP421 registers */
 #define TMP421_STATUS_REG			0x08
 #define TMP421_CONFIG_REG_1			0x09
@@ -36,8 +37,8 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
 #define TMP421_MANUFACTURER_ID_REG		0xFE
 #define TMP421_DEVICE_ID_REG			0xFF
 
-static const u8 TMP421_TEMP_MSB[4]		= { 0x00, 0x01, 0x02, 0x03 };
-static const u8 TMP421_TEMP_LSB[4]		= { 0x10, 0x11, 0x12, 0x13 };
+static const u8 TMP421_TEMP_MSB[MAX_CHANNELS]	= { 0x00, 0x01, 0x02, 0x03 };
+static const u8 TMP421_TEMP_LSB[MAX_CHANNELS]	= { 0x10, 0x11, 0x12, 0x13 };
 
 /* Flags */
 #define TMP421_CONFIG_SHUTDOWN			0x40
@@ -89,7 +90,7 @@ MODULE_DEVICE_TABLE(of, tmp421_of_match);
 struct tmp421_data {
 	struct i2c_client *client;
 	struct mutex update_lock;
-	u32 temp_config[5];
+	u32 temp_config[MAX_CHANNELS + 1];
 	struct hwmon_channel_info temp_info;
 	const struct hwmon_channel_info *info[2];
 	struct hwmon_chip_info chip;
@@ -97,7 +98,7 @@ struct tmp421_data {
 	unsigned long last_updated;
 	unsigned long channels;
 	u8 config;
-	s16 temp[4];
+	s16 temp[MAX_CHANNELS];
 };
 
 static int temp_from_s16(s16 reg)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 03/10] hwmon: (tmp421) introduce a channel struct
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
  2021-09-24  9:38 ` [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding Krzysztof Adamski
  2021-09-24  9:39 ` [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define Krzysztof Adamski
@ 2021-09-24  9:39 ` Krzysztof Adamski
  2021-09-24  9:39 ` [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT Krzysztof Adamski
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:39 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

This is a preparatory change. Upcoming patches will introduce more
per-channel parameters so it's worth organizing them into a struct.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 2c9ba5fe5f2a..1068fe59df0b 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -87,6 +87,10 @@ static const struct of_device_id __maybe_unused tmp421_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tmp421_of_match);
 
+struct tmp421_channel {
+	s16 temp;
+};
+
 struct tmp421_data {
 	struct i2c_client *client;
 	struct mutex update_lock;
@@ -98,7 +102,7 @@ struct tmp421_data {
 	unsigned long last_updated;
 	unsigned long channels;
 	u8 config;
-	s16 temp[MAX_CHANNELS];
+	struct tmp421_channel channel[MAX_CHANNELS];
 };
 
 static int temp_from_s16(s16 reg)
@@ -134,9 +138,9 @@ static struct tmp421_data *tmp421_update_device(struct device *dev)
 			TMP421_CONFIG_REG_1);
 
 		for (i = 0; i < data->channels; i++) {
-			data->temp[i] = i2c_smbus_read_byte_data(client,
+			data->channel[i].temp = i2c_smbus_read_byte_data(client,
 				TMP421_TEMP_MSB[i]) << 8;
-			data->temp[i] |= i2c_smbus_read_byte_data(client,
+			data->channel[i].temp |= i2c_smbus_read_byte_data(client,
 				TMP421_TEMP_LSB[i]);
 		}
 		data->last_updated = jiffies;
@@ -156,16 +160,16 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
 	switch (attr) {
 	case hwmon_temp_input:
 		if (tmp421->config & TMP421_CONFIG_RANGE)
-			*val = temp_from_u16(tmp421->temp[channel]);
+			*val = temp_from_u16(tmp421->channel[channel].temp);
 		else
-			*val = temp_from_s16(tmp421->temp[channel]);
+			*val = temp_from_s16(tmp421->channel[channel].temp);
 		return 0;
 	case hwmon_temp_fault:
 		/*
 		 * The OPEN bit signals a fault. This is bit 0 of the temperature
 		 * register (low byte).
 		 */
-		*val = tmp421->temp[channel] & 0x01;
+		*val = tmp421->channel[channel].temp & 0x01;
 		return 0;
 	default:
 		return -EOPNOTSUPP;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (2 preceding siblings ...)
  2021-09-24  9:39 ` [PATCH v2 03/10] hwmon: (tmp421) introduce a channel struct Krzysztof Adamski
@ 2021-09-24  9:39 ` Krzysztof Adamski
  2021-09-24 12:17   ` Guenter Roeck
  2021-09-24  9:40 ` [PATCH v2 05/10] hwmon: (tmp421) support disabling channels " Krzysztof Adamski
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:39 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

tmp42x is a multichannel temperature sensor with several external
channels. Since those channels can be used to connect diodes placed
anywhere in the system, their meaning will vary depending on the
project. For this case, the hwmon framework has an idea of labels which
allows us to assign the meaning to each channel.

The similar concept is already implemented in ina3221 - the label for
each channel can be defined via device tree. See commit a9e9dd9c6de5
("hwmon: (ina3221) Read channel input source info from DT")

This patch adds support for similar feature to tmp421.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 61 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 1068fe59df0b..f9f910d60b12 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -88,6 +88,7 @@ static const struct of_device_id __maybe_unused tmp421_of_match[] = {
 MODULE_DEVICE_TABLE(of, tmp421_of_match);
 
 struct tmp421_channel {
+	const char *label;
 	s16 temp;
 };
 
@@ -177,6 +178,16 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
 
 }
 
+static int tmp421_read_string(struct device *dev, enum hwmon_sensor_types type,
+			     u32 attr, int channel, const char **str)
+{
+	struct tmp421_data *data = dev_get_drvdata(dev);
+
+	*str = data->channel[channel].label;
+
+	return 0;
+}
+
 static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
 				 u32 attr, int channel)
 {
@@ -187,6 +198,8 @@ static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
 		return 0444;
 	case hwmon_temp_input:
 		return 0444;
+	case hwmon_temp_label:
+		return 0444;
 	default:
 		return 0;
 	}
@@ -279,9 +292,53 @@ static int tmp421_detect(struct i2c_client *client,
 	return 0;
 }
 
+static int tmp421_probe_child_from_dt(struct i2c_client *client,
+				      struct device_node *child,
+				      struct tmp421_data *data)
+
+{
+	struct device *dev = &client->dev;
+	u32 i;
+	int err;
+
+	err = of_property_read_u32(child, "reg", &i);
+	if (err) {
+		dev_err(dev, "missing reg property of %pOFn\n", child);
+		return err;
+	}
+
+	if (i > MAX_CHANNELS) {
+		dev_err(dev, "invalid reg %d of %pOFn\n", i, child);
+		return -EINVAL;
+	}
+
+	of_property_read_string(child, "label", &data->channel[i].label);
+	if (data->channel[i].label)
+		data->temp_config[i] |= HWMON_T_LABEL;
+
+	return 0;
+}
+
+static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data)
+{
+	struct device *dev = &client->dev;
+	const struct device_node *np = dev->of_node;
+	struct device_node *child;
+	int err;
+
+	for_each_child_of_node(np, child) {
+		err = tmp421_probe_child_from_dt(client, child, data);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static const struct hwmon_ops tmp421_ops = {
 	.is_visible = tmp421_is_visible,
 	.read = tmp421_read,
+	.read_string = tmp421_read_string,
 };
 
 static int tmp421_probe(struct i2c_client *client)
@@ -310,6 +367,10 @@ static int tmp421_probe(struct i2c_client *client)
 	for (i = 0; i < data->channels; i++)
 		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
 
+	err = tmp421_probe_from_dt(client, data);
+	if (err)
+		return err;
+
 	data->chip.ops = &tmp421_ops;
 	data->chip.info = data->info;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 05/10] hwmon: (tmp421) support disabling channels from DT
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (3 preceding siblings ...)
  2021-09-24  9:39 ` [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT Krzysztof Adamski
@ 2021-09-24  9:40 ` Krzysztof Adamski
  2021-09-24  9:40 ` [PATCH v2 06/10] hwmon: (tmp421) support specifying n-factor via DT Krzysztof Adamski
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:40 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

The previous patch introduced per channel subnodes in DT that let us
specify some channel specific properties. This built a ground for easily
disabling individual channels of the sensor that may not be connected to
any external diode and thus are not returning any meaningful data.

This patch adds support for parsing the "status" property of channels DT
subnodes and makes sure the -ENODATA is returned when disabled channels
value is read.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index f9f910d60b12..5ff60b366be4 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -89,6 +89,7 @@ MODULE_DEVICE_TABLE(of, tmp421_of_match);
 
 struct tmp421_channel {
 	const char *label;
+	bool enabled;
 	s16 temp;
 };
 
@@ -158,6 +159,9 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
 {
 	struct tmp421_data *tmp421 = tmp421_update_device(dev);
 
+	if (!tmp421->channel[channel].enabled)
+		return -ENODATA;
+
 	switch (attr) {
 	case hwmon_temp_input:
 		if (tmp421->config & TMP421_CONFIG_RANGE)
@@ -316,6 +320,8 @@ static int tmp421_probe_child_from_dt(struct i2c_client *client,
 	if (data->channel[i].label)
 		data->temp_config[i] |= HWMON_T_LABEL;
 
+	data->channel[i].enabled = of_device_is_available(child);
+
 	return 0;
 }
 
@@ -364,8 +370,10 @@ static int tmp421_probe(struct i2c_client *client)
 	if (err)
 		return err;
 
-	for (i = 0; i < data->channels; i++)
+	for (i = 0; i < data->channels; i++) {
 		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
+		data->channel[i].enabled = true;
+	}
 
 	err = tmp421_probe_from_dt(client, data);
 	if (err)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 06/10] hwmon: (tmp421) support specifying n-factor via DT
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (4 preceding siblings ...)
  2021-09-24  9:40 ` [PATCH v2 05/10] hwmon: (tmp421) support disabling channels " Krzysztof Adamski
@ 2021-09-24  9:40 ` Krzysztof Adamski
  2021-09-24  9:42 ` [PATCH v2 07/10] hwmon: (tmp421) really disable channels Krzysztof Adamski
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:40 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Previous patches added a way to specify some channel specific parameters
in DT and n-factor is definitely one of them. This calibration mechanism
is board specific as its value depends on the diodes/transistors being
connected to the sensor and thus the DT seems like a right fit for that
information. It is very similar to the value of shunt resistor that some
drivers allows specifying in DT.

This patch adds a possibility to set n-factor for each channel via
"n-factor" DT property in each channel subnode.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 5ff60b366be4..0fa4c02f5808 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -34,6 +34,7 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
 #define TMP421_STATUS_REG			0x08
 #define TMP421_CONFIG_REG_1			0x09
 #define TMP421_CONVERSION_RATE_REG		0x0B
+#define TMP421_N_FACTOR_REG_1			0x21
 #define TMP421_MANUFACTURER_ID_REG		0xFE
 #define TMP421_DEVICE_ID_REG			0xFF
 
@@ -303,6 +304,7 @@ static int tmp421_probe_child_from_dt(struct i2c_client *client,
 {
 	struct device *dev = &client->dev;
 	u32 i;
+	s32 val;
 	int err;
 
 	err = of_property_read_u32(child, "reg", &i);
@@ -322,6 +324,20 @@ static int tmp421_probe_child_from_dt(struct i2c_client *client,
 
 	data->channel[i].enabled = of_device_is_available(child);
 
+	if (i == 0)
+		return 0; /* input 0 is internal channel */
+
+	err = of_property_read_s32(child, "n-factor", &val);
+	if (!err) {
+		if (val > 127 || val < -128) {
+			dev_err(dev, "n-factor for channel %d invalid (%d)\n",
+				i, val);
+			return -EINVAL;
+		}
+		i2c_smbus_write_byte_data(client, TMP421_N_FACTOR_REG_1 + i - 1,
+						  val);
+	}
+
 	return 0;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 07/10] hwmon: (tmp421) really disable channels
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (5 preceding siblings ...)
  2021-09-24  9:40 ` [PATCH v2 06/10] hwmon: (tmp421) support specifying n-factor via DT Krzysztof Adamski
@ 2021-09-24  9:42 ` Krzysztof Adamski
  2021-09-24 12:12   ` Guenter Roeck
  2021-09-24  9:43 ` [PATCH v2 08/10] hwmon: (tmp421) support HWMON_T_ENABLE Krzysztof Adamski
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:42 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Recent patch added possibility to disable selected channels. That would
only make sure that the ENODATA is returned for those channels but would
not configure the actual hardware.

With this patch, the config register is written to make sure the
channels are disabled also at hardware level.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 0fa4c02f5808..4934ce13afb4 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -33,6 +33,9 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
 /* The TMP421 registers */
 #define TMP421_STATUS_REG			0x08
 #define TMP421_CONFIG_REG_1			0x09
+#define TMP421_CONFIG_REG_2			0x0A
+#define TMP421_CONFIG_REG_REN(x)		(BIT(3 + (x)))
+#define TMP421_CONFIG_REG_REN_MASK		(BIT(3)|BIT(4)|BIT(5)|BIT(6))
 #define TMP421_CONVERSION_RATE_REG		0x0B
 #define TMP421_N_FACTOR_REG_1			0x21
 #define TMP421_MANUFACTURER_ID_REG		0xFE
@@ -155,6 +158,33 @@ static struct tmp421_data *tmp421_update_device(struct device *dev)
 	return data;
 }
 
+static int tmp421_enable_channels(struct tmp421_data *data)
+{
+	int err;
+	struct i2c_client *client = data->client;
+	struct device *dev = &client->dev;
+	int cfg = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_2);
+	int i;
+
+	if (cfg < 0) {
+		dev_err(dev,
+			"error reading register, can't disable channels\n");
+		return err;
+	}
+
+	cfg &= ~TMP421_CONFIG_REG_REN_MASK;
+	for (i = 0; i < data->channels; i++)
+		if (data->channel[i].enabled)
+			cfg |= TMP421_CONFIG_REG_REN(i);
+
+	err = i2c_smbus_write_byte_data(client, TMP421_CONFIG_REG_2, cfg);
+	if (err < 0)
+		dev_err(dev,
+			"error writing register, can't disable channels\n");
+
+	return err;
+}
+
 static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
 		       u32 attr, int channel, long *val)
 {
@@ -395,6 +425,10 @@ static int tmp421_probe(struct i2c_client *client)
 	if (err)
 		return err;
 
+	err = tmp421_enable_channels(data);
+	if (err)
+		return err;
+
 	data->chip.ops = &tmp421_ops;
 	data->chip.info = data->info;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 08/10] hwmon: (tmp421) support HWMON_T_ENABLE
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (6 preceding siblings ...)
  2021-09-24  9:42 ` [PATCH v2 07/10] hwmon: (tmp421) really disable channels Krzysztof Adamski
@ 2021-09-24  9:43 ` Krzysztof Adamski
  2021-09-24  9:44 ` [PATCH v2 09/10] hwmon: (tmp421) update documentation Krzysztof Adamski
  2021-09-24  9:44 ` [PATCH v2 10/10] dt-bindings: hwmon: allow specifying channels for tmp421 Krzysztof Adamski
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:43 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Since the recent patches added possibility of disabling sensor channels
via DT, it only make sense to allow controlling that from userspace via
HWMON_T_ENABLE mechanism. This patches adds support for that.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/tmp421.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 4934ce13afb4..3f3e5d6c9e3d 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -190,23 +190,28 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
 {
 	struct tmp421_data *tmp421 = tmp421_update_device(dev);
 
-	if (!tmp421->channel[channel].enabled)
-		return -ENODATA;
-
 	switch (attr) {
 	case hwmon_temp_input:
+		if (!tmp421->channel[channel].enabled)
+			return -ENODATA;
+
 		if (tmp421->config & TMP421_CONFIG_RANGE)
 			*val = temp_from_u16(tmp421->channel[channel].temp);
 		else
 			*val = temp_from_s16(tmp421->channel[channel].temp);
 		return 0;
 	case hwmon_temp_fault:
+		if (!tmp421->channel[channel].enabled)
+			return -ENODATA;
 		/*
 		 * The OPEN bit signals a fault. This is bit 0 of the temperature
 		 * register (low byte).
 		 */
 		*val = tmp421->channel[channel].temp & 0x01;
 		return 0;
+	case hwmon_temp_enable:
+		*val = tmp421->channel[channel].enabled;
+		return 0;
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -223,6 +228,24 @@ static int tmp421_read_string(struct device *dev, enum hwmon_sensor_types type,
 	return 0;
 }
 
+static int tmp421_write(struct device *dev, enum hwmon_sensor_types type,
+			u32 attr, int channel, long val)
+{
+	struct tmp421_data *data = dev_get_drvdata(dev);
+	int ret;
+
+	switch (type) {
+	case hwmon_temp:
+		data->channel[channel].enabled = val;
+		ret = tmp421_enable_channels(data);
+		break;
+	default:
+	    ret = -EOPNOTSUPP;
+	}
+
+	return ret;
+}
+
 static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
 				 u32 attr, int channel)
 {
@@ -235,6 +258,8 @@ static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
 		return 0444;
 	case hwmon_temp_label:
 		return 0444;
+	case hwmon_temp_enable:
+		return 0644;
 	default:
 		return 0;
 	}
@@ -391,6 +416,7 @@ static const struct hwmon_ops tmp421_ops = {
 	.is_visible = tmp421_is_visible,
 	.read = tmp421_read,
 	.read_string = tmp421_read_string,
+	.write = tmp421_write,
 };
 
 static int tmp421_probe(struct i2c_client *client)
@@ -417,7 +443,7 @@ static int tmp421_probe(struct i2c_client *client)
 		return err;
 
 	for (i = 0; i < data->channels; i++) {
-		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
+		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT | HWMON_T_ENABLE;
 		data->channel[i].enabled = true;
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 09/10] hwmon: (tmp421) update documentation
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (7 preceding siblings ...)
  2021-09-24  9:43 ` [PATCH v2 08/10] hwmon: (tmp421) support HWMON_T_ENABLE Krzysztof Adamski
@ 2021-09-24  9:44 ` Krzysztof Adamski
  2021-09-24  9:44 ` [PATCH v2 10/10] dt-bindings: hwmon: allow specifying channels for tmp421 Krzysztof Adamski
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:44 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Sysfs interface of the tmp421 driver was extended in the recent patches
so lets update the documentation to reflect that.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 Documentation/hwmon/tmp421.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/hwmon/tmp421.rst b/Documentation/hwmon/tmp421.rst
index ddcd5159c75d..a3002117bbd7 100644
--- a/Documentation/hwmon/tmp421.rst
+++ b/Documentation/hwmon/tmp421.rst
@@ -64,3 +64,13 @@ the temperature values via the following sysfs files:
 **temp[1-4]_input**
 
 **temp[2-4]_fault**
+
+Each sensor can be individually disabled via Devicetree or from sysfs
+via:
+
+**temp[1-4]_enable**
+
+If labels were specified in Devicetree, additional sysfs files will
+be present:
+
+**temp[1-4]_label**
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 10/10] dt-bindings: hwmon: allow specifying channels for tmp421
  2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
                   ` (8 preceding siblings ...)
  2021-09-24  9:44 ` [PATCH v2 09/10] hwmon: (tmp421) update documentation Krzysztof Adamski
@ 2021-09-24  9:44 ` Krzysztof Adamski
  9 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24  9:44 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Add binding description for the per temperature channel configuration
like labels and n-factor.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 .../devicetree/bindings/hwmon/ti,tmp421.yaml  | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml b/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
index 53940e146ee6..56085fdf1b57 100644
--- a/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
+++ b/Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
@@ -24,12 +24,49 @@ properties:
   reg:
     maxItems: 1
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
 required:
   - compatible
   - reg
 
 additionalProperties: false
 
+patternProperties:
+  "^input@([0-4])$":
+    type: object
+    description: |
+      Represents channels of the device and their specific configuration.
+
+    properties:
+      reg:
+        description: |
+          The channel number. 0 is local channel, 1-4 are remote channels
+        items:
+          minimum: 0
+          maximum: 4
+
+      label:
+        description: |
+          A descriptive name for this channel, like "ambient" or "psu".
+
+      n-factor:
+        description: |
+          The value (two's complement) to be programmed in the channel specific N correction register.
+          For remote channels only.
+        items:
+          minimum: 0
+          maximum: 1
+
+    required:
+      - reg
+
+    additionalProperties: false
+
 examples:
   - |
     i2c {
@@ -41,3 +78,32 @@ examples:
         reg = <0x4c>;
       };
     };
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      sensor@4c {
+        compatible = "ti,tmp422";
+        reg = <0x4c>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        input@0 {
+          reg = <0x0>;
+          n-factor = <0x1>;
+          label = "local";
+        };
+
+        input@1 {
+          reg = <0x1>;
+          n-factor = <0x0>;
+          label = "somelabel";
+        };
+
+        input@2 {
+          reg = <0x2>;
+          status = "disabled";
+        };
+      };
+    };
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define
  2021-09-24  9:39 ` [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define Krzysztof Adamski
@ 2021-09-24 12:05   ` Guenter Roeck
  0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2021-09-24 12:05 UTC (permalink / raw)
  To: Krzysztof Adamski
  Cc: Jean Delvare, Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

On Fri, Sep 24, 2021 at 11:39:06AM +0200, Krzysztof Adamski wrote:
> There are few places where the maximal number of channels is used define
> the size of arrays but when raw number is used it is not clear that they
> really related to this quantity.
> This commit introduces MAX_CHANNELS define and uses it those places to
> give some context to the number.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>

Applied to hwmon-next, no need to resend.

Thanks,
Guenter

> ---
>  drivers/hwmon/tmp421.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
> index ede66ea6a730..2c9ba5fe5f2a 100644
> --- a/drivers/hwmon/tmp421.c
> +++ b/drivers/hwmon/tmp421.c
> @@ -29,6 +29,7 @@ static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f,
>  
>  enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
>  
> +#define MAX_CHANNELS				4
>  /* The TMP421 registers */
>  #define TMP421_STATUS_REG			0x08
>  #define TMP421_CONFIG_REG_1			0x09
> @@ -36,8 +37,8 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
>  #define TMP421_MANUFACTURER_ID_REG		0xFE
>  #define TMP421_DEVICE_ID_REG			0xFF
>  
> -static const u8 TMP421_TEMP_MSB[4]		= { 0x00, 0x01, 0x02, 0x03 };
> -static const u8 TMP421_TEMP_LSB[4]		= { 0x10, 0x11, 0x12, 0x13 };
> +static const u8 TMP421_TEMP_MSB[MAX_CHANNELS]	= { 0x00, 0x01, 0x02, 0x03 };
> +static const u8 TMP421_TEMP_LSB[MAX_CHANNELS]	= { 0x10, 0x11, 0x12, 0x13 };
>  
>  /* Flags */
>  #define TMP421_CONFIG_SHUTDOWN			0x40
> @@ -89,7 +90,7 @@ MODULE_DEVICE_TABLE(of, tmp421_of_match);
>  struct tmp421_data {
>  	struct i2c_client *client;
>  	struct mutex update_lock;
> -	u32 temp_config[5];
> +	u32 temp_config[MAX_CHANNELS + 1];
>  	struct hwmon_channel_info temp_info;
>  	const struct hwmon_channel_info *info[2];
>  	struct hwmon_chip_info chip;
> @@ -97,7 +98,7 @@ struct tmp421_data {
>  	unsigned long last_updated;
>  	unsigned long channels;
>  	u8 config;
> -	s16 temp[4];
> +	s16 temp[MAX_CHANNELS];
>  };
>  
>  static int temp_from_s16(s16 reg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 07/10] hwmon: (tmp421) really disable channels
  2021-09-24  9:42 ` [PATCH v2 07/10] hwmon: (tmp421) really disable channels Krzysztof Adamski
@ 2021-09-24 12:12   ` Guenter Roeck
  0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2021-09-24 12:12 UTC (permalink / raw)
  To: Krzysztof Adamski
  Cc: Jean Delvare, Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

On Fri, Sep 24, 2021 at 11:42:40AM +0200, Krzysztof Adamski wrote:
> Recent patch added possibility to disable selected channels. That would
> only make sure that the ENODATA is returned for those channels but would
> not configure the actual hardware.
> 
> With this patch, the config register is written to make sure the
> channels are disabled also at hardware level.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
> ---
>  drivers/hwmon/tmp421.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
> index 0fa4c02f5808..4934ce13afb4 100644
> --- a/drivers/hwmon/tmp421.c
> +++ b/drivers/hwmon/tmp421.c
> @@ -33,6 +33,9 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
>  /* The TMP421 registers */
>  #define TMP421_STATUS_REG			0x08
>  #define TMP421_CONFIG_REG_1			0x09
> +#define TMP421_CONFIG_REG_2			0x0A
> +#define TMP421_CONFIG_REG_REN(x)		(BIT(3 + (x)))
> +#define TMP421_CONFIG_REG_REN_MASK		(BIT(3)|BIT(4)|BIT(5)|BIT(6))

GENMASK() would probably be better here.

>  #define TMP421_CONVERSION_RATE_REG		0x0B
>  #define TMP421_N_FACTOR_REG_1			0x21
>  #define TMP421_MANUFACTURER_ID_REG		0xFE
> @@ -155,6 +158,33 @@ static struct tmp421_data *tmp421_update_device(struct device *dev)
>  	return data;
>  }
>  
> +static int tmp421_enable_channels(struct tmp421_data *data)
> +{
> +	int err;
> +	struct i2c_client *client = data->client;
> +	struct device *dev = &client->dev;
> +	int cfg = i2c_smbus_read_byte_data(client, TMP421_CONFIG_REG_2);
> +	int i;
> +
> +	if (cfg < 0) {
> +		dev_err(dev,
> +			"error reading register, can't disable channels\n");

Unnecessary line break

> +		return err;

		return cfg;

> +	}
> +
> +	cfg &= ~TMP421_CONFIG_REG_REN_MASK;
> +	for (i = 0; i < data->channels; i++)
> +		if (data->channel[i].enabled)
> +			cfg |= TMP421_CONFIG_REG_REN(i);
> +
> +	err = i2c_smbus_write_byte_data(client, TMP421_CONFIG_REG_2, cfg);
> +	if (err < 0)
> +		dev_err(dev,
> +			"error writing register, can't disable channels\n");

Unnecessary line break

> +
> +	return err;
> +}
> +
>  static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
>  		       u32 attr, int channel, long *val)
>  {
> @@ -395,6 +425,10 @@ static int tmp421_probe(struct i2c_client *client)
>  	if (err)
>  		return err;
>  
> +	err = tmp421_enable_channels(data);
> +	if (err)
> +		return err;

This should really be called from tmp421_init_client(). After all, that is what
the function is for.

> +
>  	data->chip.ops = &tmp421_ops;
>  	data->chip.info = data->info;
>  

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT
  2021-09-24  9:39 ` [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT Krzysztof Adamski
@ 2021-09-24 12:17   ` Guenter Roeck
  2021-09-24 12:27     ` Krzysztof Adamski
  0 siblings, 1 reply; 17+ messages in thread
From: Guenter Roeck @ 2021-09-24 12:17 UTC (permalink / raw)
  To: Krzysztof Adamski
  Cc: Jean Delvare, Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

On Fri, Sep 24, 2021 at 11:39:49AM +0200, Krzysztof Adamski wrote:
> tmp42x is a multichannel temperature sensor with several external
> channels. Since those channels can be used to connect diodes placed
> anywhere in the system, their meaning will vary depending on the
> project. For this case, the hwmon framework has an idea of labels which
> allows us to assign the meaning to each channel.
> 
> The similar concept is already implemented in ina3221 - the label for
> each channel can be defined via device tree. See commit a9e9dd9c6de5
> ("hwmon: (ina3221) Read channel input source info from DT")
> 
> This patch adds support for similar feature to tmp421.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
> ---
>  drivers/hwmon/tmp421.c | 61 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
> index 1068fe59df0b..f9f910d60b12 100644
> --- a/drivers/hwmon/tmp421.c
> +++ b/drivers/hwmon/tmp421.c
> @@ -88,6 +88,7 @@ static const struct of_device_id __maybe_unused tmp421_of_match[] = {
>  MODULE_DEVICE_TABLE(of, tmp421_of_match);
>  
>  struct tmp421_channel {
> +	const char *label;
>  	s16 temp;
>  };
>  
> @@ -177,6 +178,16 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
>  
>  }
>  
> +static int tmp421_read_string(struct device *dev, enum hwmon_sensor_types type,
> +			     u32 attr, int channel, const char **str)
> +{
> +	struct tmp421_data *data = dev_get_drvdata(dev);
> +
> +	*str = data->channel[channel].label;
> +
> +	return 0;
> +}
> +
>  static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
>  				 u32 attr, int channel)
>  {
> @@ -187,6 +198,8 @@ static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type,
>  		return 0444;
>  	case hwmon_temp_input:
>  		return 0444;
> +	case hwmon_temp_label:
> +		return 0444;
>  	default:
>  		return 0;
>  	}
> @@ -279,9 +292,53 @@ static int tmp421_detect(struct i2c_client *client,
>  	return 0;
>  }
>  
> +static int tmp421_probe_child_from_dt(struct i2c_client *client,
> +				      struct device_node *child,
> +				      struct tmp421_data *data)
> +
> +{
> +	struct device *dev = &client->dev;
> +	u32 i;
> +	int err;
> +
> +	err = of_property_read_u32(child, "reg", &i);
> +	if (err) {
> +		dev_err(dev, "missing reg property of %pOFn\n", child);
> +		return err;
> +	}
> +
> +	if (i > MAX_CHANNELS) {
> +		dev_err(dev, "invalid reg %d of %pOFn\n", i, child);
> +		return -EINVAL;
> +	}
> +
> +	of_property_read_string(child, "label", &data->channel[i].label);
> +	if (data->channel[i].label)
> +		data->temp_config[i] |= HWMON_T_LABEL;
> +
> +	return 0;
> +}
> +
> +static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data)
> +{
> +	struct device *dev = &client->dev;
> +	const struct device_node *np = dev->of_node;
> +	struct device_node *child;
> +	int err;
> +
> +	for_each_child_of_node(np, child) {
> +		err = tmp421_probe_child_from_dt(client, child, data);
> +		if (err)
> +			return err;
> +	}

That makes me wonder: Can there ever be other (not temperature channel
related) child nodes ? Power, for example ?

Thanks,
Guenter

> +
> +	return 0;
> +}
> +
>  static const struct hwmon_ops tmp421_ops = {
>  	.is_visible = tmp421_is_visible,
>  	.read = tmp421_read,
> +	.read_string = tmp421_read_string,
>  };
>  
>  static int tmp421_probe(struct i2c_client *client)
> @@ -310,6 +367,10 @@ static int tmp421_probe(struct i2c_client *client)
>  	for (i = 0; i < data->channels; i++)
>  		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
>  
> +	err = tmp421_probe_from_dt(client, data);
> +	if (err)
> +		return err;
> +
>  	data->chip.ops = &tmp421_ops;
>  	data->chip.info = data->info;
>  

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT
  2021-09-24 12:17   ` Guenter Roeck
@ 2021-09-24 12:27     ` Krzysztof Adamski
  0 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24 12:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Jean Delvare, Rob Herring, linux-hwmon, devicetree, Przemyslaw Cencner

Dnia Fri, Sep 24, 2021 at 05:17:06AM -0700, Guenter Roeck napisał(a):
>> +static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data)
>> +{
>> +	struct device *dev = &client->dev;
>> +	const struct device_node *np = dev->of_node;
>> +	struct device_node *child;
>> +	int err;
>> +
>> +	for_each_child_of_node(np, child) {
>> +		err = tmp421_probe_child_from_dt(client, child, data);
>> +		if (err)
>> +			return err;
>> +	}
>
>That makes me wonder: Can there ever be other (not temperature channel
>related) child nodes ? Power, for example ?

For this device? Nothing that could think of that could make sense. But
we can be stricter here and skip/ignore all the nodes that are not named
input@X, if you think that is reasonable.

Krzysztof

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding
  2021-09-24  9:38 ` [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding Krzysztof Adamski
@ 2021-09-24 12:45   ` Rob Herring
  2021-09-24 12:54     ` Krzysztof Adamski
  0 siblings, 1 reply; 17+ messages in thread
From: Rob Herring @ 2021-09-24 12:45 UTC (permalink / raw)
  To: Krzysztof Adamski
  Cc: devicetree, linux-hwmon, Jean Delvare, Rob Herring,
	Guenter Roeck, Przemyslaw Cencner

On Fri, 24 Sep 2021 11:38:50 +0200, Krzysztof Adamski wrote:
> Add basic description of the tmp421 driver DT bindings.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
> ---
>  .../devicetree/bindings/hwmon/ti,tmp421.yaml  | 43 +++++++++++++++++++
>  1 file changed, 43 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml: $id: relative path/filename doesn't match actual path or filename
	expected: http://devicetree.org/schemas/hwmon/ti,tmp421.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1532139

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.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding
  2021-09-24 12:45   ` Rob Herring
@ 2021-09-24 12:54     ` Krzysztof Adamski
  0 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Adamski @ 2021-09-24 12:54 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree, linux-hwmon, Jean Delvare, Rob Herring,
	Guenter Roeck, Przemyslaw Cencner

Dnia Fri, Sep 24, 2021 at 07:45:00AM -0500, Rob Herring napisał(a):
>On Fri, 24 Sep 2021 11:38:50 +0200, Krzysztof Adamski wrote:
>> Add basic description of the tmp421 driver DT bindings.
>>
>> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
>> ---
>>  .../devicetree/bindings/hwmon/ti,tmp421.yaml  | 43 +++++++++++++++++++
>>  1 file changed, 43 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml
>>
>
>My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
>on your patch (DT_CHECKER_FLAGS is new in v5.13):
>
>yamllint warnings/errors:
>
>dtschema/dtc warnings/errors:
>./Documentation/devicetree/bindings/hwmon/ti,tmp421.yaml: $id: relative path/filename doesn't match actual path or filename
>	expected: http://devicetree.org/schemas/hwmon/ti,tmp421.yaml#
>
>doc reference errors (make refcheckdocs):
>
>See https://patchwork.ozlabs.org/patch/1532139
>
>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.
>

Hi,

Makes sense, after seeing the series of patches converting the old .txt
style binding documentation on hwmon-next, I realised the file should
not be called tmp421.yaml but ti,tmp421.yaml and I renamed it but
forgout about the $id.

I'll resubmit the fixed version soon, but I will first make sure my
system can also catch those errors too.

Krzysztof

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-09-24 12:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24  9:36 [PATCH v2 00/10] Add per channel properies support in tmp421 Krzysztof Adamski
2021-09-24  9:38 ` [PATCH v2 01/10] dt-bindings: hwmon: add missing tmp421 binding Krzysztof Adamski
2021-09-24 12:45   ` Rob Herring
2021-09-24 12:54     ` Krzysztof Adamski
2021-09-24  9:39 ` [PATCH v2 02/10] hwmon: (tmp421) introduce MAX_CHANNELS define Krzysztof Adamski
2021-09-24 12:05   ` Guenter Roeck
2021-09-24  9:39 ` [PATCH v2 03/10] hwmon: (tmp421) introduce a channel struct Krzysztof Adamski
2021-09-24  9:39 ` [PATCH v2 04/10] hwmon: (tmp421) add support for defining labels from DT Krzysztof Adamski
2021-09-24 12:17   ` Guenter Roeck
2021-09-24 12:27     ` Krzysztof Adamski
2021-09-24  9:40 ` [PATCH v2 05/10] hwmon: (tmp421) support disabling channels " Krzysztof Adamski
2021-09-24  9:40 ` [PATCH v2 06/10] hwmon: (tmp421) support specifying n-factor via DT Krzysztof Adamski
2021-09-24  9:42 ` [PATCH v2 07/10] hwmon: (tmp421) really disable channels Krzysztof Adamski
2021-09-24 12:12   ` Guenter Roeck
2021-09-24  9:43 ` [PATCH v2 08/10] hwmon: (tmp421) support HWMON_T_ENABLE Krzysztof Adamski
2021-09-24  9:44 ` [PATCH v2 09/10] hwmon: (tmp421) update documentation Krzysztof Adamski
2021-09-24  9:44 ` [PATCH v2 10/10] dt-bindings: hwmon: allow specifying channels for tmp421 Krzysztof Adamski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).