Skip to contentSkip to conversation

Add driver support for ESWIN EIC7700 PVT controller

PATCH Superseded [email protected] 4 participants 14 messages Apr 30 – May 13

Subsystems (2)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add driver support for ESWIN EIC7700 PVT controller

From: Huan He <[email protected]>

Add support for the ESWIN EIC7700 PVT (Voltage, Temperature) sensor

Features:
The driver supports monitoring of voltage and temperature parameters through the hardware monitoring subsystem. It provides an access to the sampled Temperature and Voltage.

Test:
Tested this patch on the SiFive HiFive Premier P550 (which uses the ESWIN EIC7700 SoC).

Updates:

Changes in v4:
- Update eswin,eic7700-pvt.yaml
- Delete reviewed-by tag of Conor Dooley, because the label enum constraint is introduced
- Update eic7700-pvt.c and eic7700-pvt.h
- Remove the unused LVT/ULVT/SVT process-monitoring channels
- Remove the probe-time power check since the PVT block is always powered on EIC7700 and the extra verification is unnecessary
- Stop requesting the interrupt as shared and use the dedicated PVT IRQ only
- Reorder probe initialization so the interface is initialized before the clock is disabled, avoiding register accesses with the clock gated
- Fix runtime PM reference handling on error paths by balancing pm_runtime_get_noresume() with pm_runtime_put_noidle()
- Add pm_runtime_put_noidle() handling for failed pm_runtime_get_sync() calls in hwmon read/write paths
- Switch the PM callback registration from pm_sleep_ptr() to pm_ptr()

Changes in v3:
- Update eswin,eic7700-pvt.yaml
- Remove redundant label property description and use 'label: true' to reference the definition in hwmon-common.yaml
- Replace 'additionalProperties: false' with 'unevaluatedProperties: false'
- Remove the description for '#thermal-sensor-cells'
- Update eic7700-pvt.c and eic7700-pvt.h
- Fix clock reference count imbalance with Runtime PM:
Replace devm_clk_get_enabled() with devm_clk_get() and manually manage clock enable/disable to avoid double-disable in remove() when Runtime PM is active. Clock is now enabled only during probe for eic7700_pvt_check_pwr(), then disabled before enabling Runtime PM, which takes full control of the clock thereafter
- Add detailed comment explaining the spurious interrupt risk in eic7700_pvt_check_pwr()
- Replace wait_for_completion_interruptible() with wait_for_completion_timeout() to prevent infinite wait

Changes in v2:
- Update eswin,eic7700-pvt.yaml
- Reference the hwmon-common.yaml file
- Remove the clock-names and reset-names properties
- Move additionalProperties: false after the required block
- Remove one example node to avoid redundancy
- Update eic7700-pvt.c and eic7700-pvt.h
- Remove unused sensor macros (PVT_SENSOR_FIRST, PVT_SENSOR_LAST, PVT_SENSORS_NUM)
- Drop the unnecessary hwmon-sysfs.h header
- Replace dynamic sensor info allocation with a static array and unify sensor labels
- Remove unused hwmon_temp_type attribute
- Eliminate redundant validation checks
- Remove mutex and related locking, relying on hwmon core serialization
- Replace per-sensor caches and completions with a single data cache and completion object
- Remove pvt->sensor tracking. ISR no longer depends on the currently selected sensor
- Move devm_add_action() registration after init_completion() for safer cleanup, and update cleanup function (pvt_clear_data)
- Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_exclusive_deasserted()
- Replace eic7700_pvt_remove() with eic7700_pvt_disable_pm_runtime() and move it after PM runtime enable to avoid resource leaks on probe failure and remove clock disable and reset assert from eic7700_pvt_disable_pm_runtime() as it is already handled by devm_* framework
- Remove redundant clock presence check in runtime_resume

- Link to v1: https://lore.kernel.org/all/[email protected]/

Huan He (2):
dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor
hwmon: Add Eswin EIC7700 PVT sensor driver

 .../bindings/hwmon/eswin,eic7700-pvt.yaml     |  68 ++
 drivers/hwmon/Kconfig                         |  12 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/eic7700-pvt.c                   | 591 ++++++++++++++++++
 drivers/hwmon/eic7700-pvt.h                   |  99 +++
 5 files changed, 771 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml
 create mode 100644 drivers/hwmon/eic7700-pvt.c
 create mode 100644 drivers/hwmon/eic7700-pvt.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/2 dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

From: Huan He <[email protected]>

Add device tree binding documentation for ESWIN EIC7700 Process, Voltage and Temperature sensor.

The EIC7700 SoC integrates two PVT instances for monitoring SoC and DDR power domains respectively.

---
 .../bindings/hwmon/eswin,eic7700-pvt.yaml     | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +68 -0
new file mode 100644
index 000000000000..ba89b829ee94
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/eswin,eic7700-pvt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ESWIN EIC7700 PVT Sensor
+
+maintainers:
+  - Yulin Lu <[email protected]>
+  - Huan He <[email protected]>
+
+description:
+  ESWIN EIC7700 SoC integrates embedded process, voltage and temperature
+  sensors to monitor the internal SoC environment. The system includes two
+  PVT sensor instances. The PVT0 monitors the main SoC power domain. The
+  PVT1 sensor monitors the DDR core power domain.
+
+allOf:
+  - $ref: /schemas/hwmon/hwmon-common.yaml#
+
+properties:
+  compatible:
+    const: eswin,eic7700-pvt
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  label:
+    enum:
+      - pvt0
+      - pvt1
+
+  resets:
+    maxItems: 1
+
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - interrupts
+  - label
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    pvt@50b00000 {
+      compatible = "eswin,eic7700-pvt";
+      reg = <0x50b00000 0x10000>;
+      clocks = <&clocks 244>;
+      interrupts = <349>;
+      interrupt-parent = <&plic>;
+      label = "pvt0";
+      resets = <&reset 111>;
+      #thermal-sensor-cells = <0>;
+    };
+...
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The 'label' property is required and restricted to an enum, misusing it for hardware instance…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The 'label' property is required and restricted to an enum, misusing it for hardware instance identification.
- [Medium] The '#thermal-sensor-cells' property is defined but omitted from the 'required' list.
--

commit 5a5ed34d17ea4e88cd80b5a8e96e21dcc65e9f11
Author: Huan He <[email protected]>

dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

This commit adds the device tree binding documentation for the Eswin EIC7700 Process, Voltage and Temperature sensor. The SoC integrates two PVT instances for monitoring the main SoC and DDR power domains.

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +0 -0
new file mode 100644
index 0000000000000..ba89b829ee947

[ ... ]

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +7 -0
+  interrupts:
+    maxItems: 1
+
+  label:
+    enum:
+      - pvt0
+      - pvt1

Is it appropriate to restrict the standard label property to a strict enum and require it?

The devicetree specification generally defines label as an optional, human-readable string. Should the hardware instances be differentiated by their reg addresses, aliases, or dedicated properties instead of imposing a strict enum on a standard free-form string?

Quoted 4 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +4 -0
+
+  resets:
+    maxItems: 1
+

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 52

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - interrupts
+  - label
+  - resets

Should #thermal-sensor-cells be included in this required list?

Since the device acts as a thermal sensor provider, omitting its cell-count property allows incomplete device tree nodes to silently pass schema validation. This might lead to runtime failures or misconfigurations when dependent thermal zones attempt to reference the sensor.

[ ... ]

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

Re: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

Hi Sashiko,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 31 lines

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The 'label' property is required and restricted to an enum, misusing it for hardware instance identification.
- [Medium] The '#thermal-sensor-cells' property is defined but omitted from the 'required' list.
--

commit 5a5ed34d17ea4e88cd80b5a8e96e21dcc65e9f11
Author: Huan He <[email protected]>

dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

This commit adds the device tree binding documentation for the Eswin EIC7700 Process, Voltage and Temperature sensor. The SoC integrates two PVT instances for monitoring the main SoC and DDR power domains.

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +0 -0
new file mode 100644
index 0000000000000..ba89b829ee947

[ ... ]

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +7 -0
+  interrupts:
+    maxItems: 1
+
+  label:
+    enum:
+      - pvt0
+      - pvt1
Quoted 7 lines

Is it appropriate to restrict the standard label property to a strict enum and require it?

The devicetree specification generally defines label as an optional, human-readable string. Should the hardware instances be differentiated by their reg addresses, aliases, or dedicated properties instead of imposing a strict enum on a standard free-form string?

I am planning to update the next revision as follows. Would this be acceptable?

YAML:
-  label:
-    enum:
-      - pvt0
-      - pvt1
+  label: true

required:
  - compatible
  - reg
  - clocks
  - interrupts
- - label

Driver:
 static int eic7700_pvt_create_hwmon(struct pvt_hwmon *pvt)
 {
-   struct device *dev = pvt->dev;
-   struct device_node *np = dev->of_node;
-   const char *node_label;
-   int type;
-   const char *names[2] = {"soc_pvt", "ddr_pvt"};
-
-   if (of_property_read_string(np, "label", &node_label)) {
-       dev_err(dev, "Missing 'label' property in DTS node\n");
-       return -EINVAL;
-   }
-
-   if (strcmp(node_label, "pvt0") == 0) {
-       type = 0;
-   } else if (strcmp(node_label, "pvt1") == 0) {
-       type = 1;
-   } else {
-       dev_err(pvt->dev, "Unsupported label: %s\n", node_label);
-       return -EINVAL;
-   }
+   const char *name = "pvt";
+
+   of_property_read_string(pvt->dev->of_node, "label", &name);

-   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, names[type],
+   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, name, pvt, &pvt_hwmon_info,
                              NULL);

Quoted 18 lines
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +4 -0
+
+  resets:
+    maxItems: 1
+

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 52

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - interrupts
+  - label
+  - resets

Should #thermal-sensor-cells be included in this required list?

Quoted 4 lines

Since the device acts as a thermal sensor provider, omitting its cell-count property allows incomplete device tree nodes to silently pass schema validation. This might lead to runtime failures or misconfigurations when dependent thermal zones attempt to reference the sensor.

I will add "#thermal-sensor-cells" to the required list in the next revision.

Best regards,
Huan He

#4 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

In reply to [email protected]

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 5 lines · On Thu, Apr 30, 2026 at 02:44:44PM +0800, [email protected] wrote:
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +5 -0
+
+  label:
+    enum:
+      - pvt0
+      - pvt1

No, label is user-visible name. Can be whatever user decides.

Please read writing bindings - instance IDs are not allowed.

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+
+  resets:
+    maxItems: 1
+
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 58

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  - clocks
+  - interrupts
+  - label
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    pvt@50b00000 {

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel sources for similar cases or you can grow the spec (via pull request to DT spec repo).

Best regards,
Krzysztof

author
#5 lore raw

Re: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

Hi Krzysztof,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 10 lines · On Thu, Apr 30, 2026 at 02:44:44PM +0800, [email protected] wrote:

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +5 -0
+
+  label:
+    enum:
+      - pvt0
+      - pvt1

No, label is user-visible name. Can be whatever user decides.

Please read writing bindings - instance IDs are not allowed.

Thanks for the clarification.
I am planning to update the next revision as follows. Would this be acceptable?

YAML:
-  label:
-    enum:
-      - pvt0
-      - pvt1
+  label: true

required:
  - compatible
  - reg
  - clocks
  - interrupts
- - label

Driver:
 static int eic7700_pvt_create_hwmon(struct pvt_hwmon *pvt)
 {
-   struct device *dev = pvt->dev;
-   struct device_node *np = dev->of_node;
-   const char *node_label;
-   int type;
-   const char *names[2] = {"soc_pvt", "ddr_pvt"};
-
-   if (of_property_read_string(np, "label", &node_label)) {
-       dev_err(dev, "Missing 'label' property in DTS node\n");
-       return -EINVAL;
-   }
-
-   if (strcmp(node_label, "pvt0") == 0) {
-       type = 0;
-   } else if (strcmp(node_label, "pvt1") == 0) {
-       type = 1;
-   } else {
-       dev_err(pvt->dev, "Unsupported label: %s\n", node_label);
-       return -EINVAL;
-   }
+   const char *name = "pvt";
+
+   of_property_read_string(pvt->dev->of_node, "label", &name);

-   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, names[type],
+   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, name, pvt, &pvt_hwmon_info,
                              NULL);

Quoted 23 lines
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+
+  resets:
+    maxItems: 1
+
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 58

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  - clocks
+  - interrupts
+  - label
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    pvt@50b00000 {
Quoted 6 lines

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel sources for similar cases or you can grow the spec (via pull request to DT spec repo).

I will update the example node name from "pvt@..." to the generic "sensor@...". Is this acceptable?

Best regards,
Huan He

maintainer
#6 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

Quoted 54 lines · Huan He

Hi Krzysztof,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 10 lines · On Thu, Apr 30, 2026 at 02:44:44PM +0800, [email protected] wrote:

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +5 -0
+
+  label:
+    enum:
+      - pvt0
+      - pvt1

No, label is user-visible name. Can be whatever user decides.

Please read writing bindings - instance IDs are not allowed.

Thanks for the clarification.
I am planning to update the next revision as follows. Would this be acceptable?

YAML:
-  label:
-    enum:
-      - pvt0
-      - pvt1
+  label: true

required:
  - compatible
  - reg
  - clocks
  - interrupts
- - label

Driver:
 static int eic7700_pvt_create_hwmon(struct pvt_hwmon *pvt) {
-   struct device *dev = pvt->dev;
-   struct device_node *np = dev->of_node;
-   const char *node_label;
-   int type;
-   const char *names[2] = {"soc_pvt", "ddr_pvt"};

(quoted diff) +0 -12
-
-   if (of_property_read_string(np, "label", &node_label)) {
-       dev_err(dev, "Missing 'label' property in DTS node\n");
-       return -EINVAL;
-   }
-
-   if (strcmp(node_label, "pvt0") == 0) {
-       type = 0;
-   } else if (strcmp(node_label, "pvt1") == 0) {
-       type = 1;
-   } else {
-       dev_err(pvt->dev, "Unsupported label: %s\n", node_label);

Review

Quoted 10 lines
(quoted diff) +4 -3
-       return -EINVAL;
-   }
+   const char *name = "pvt";
+
+   of_property_read_string(pvt->dev->of_node, "label", &name);
 
-   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, names[type],
+   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, name,
                               pvt, &pvt_hwmon_info,
                               NULL);

This would try to register a free-text name for the hwmon device, which would be unacceptable.

There are lots of multi-channel devices out there. None of them have those problems. Why do you insist in free-text names instead of using, say, "reg" to distinguish the channels ?

Guenter

Quoted 35 lines
Quoted 23 lines
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+
+  resets:
+    maxItems: 1
+
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 58

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  - clocks
+  - interrupts
+  - label
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    pvt@50b00000 {
Quoted 6 lines

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel sources for similar cases or you can grow the spec (via pull request to DT spec repo).

I will update the example node name from "pvt@..." to the generic "sensor@...". Is this acceptable?

Best regards,
Huan He

author
#7 lore raw

Re: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

Hi Guenter,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 70 lines · Huan He
Quoted 54 lines

Hi Krzysztof,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 10 lines · On Thu, Apr 30, 2026 at 02:44:44PM +0800, [email protected] wrote:

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 38

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +5 -0
+
+  label:
+    enum:
+      - pvt0
+      - pvt1

No, label is user-visible name. Can be whatever user decides.

Please read writing bindings - instance IDs are not allowed.

Thanks for the clarification.
I am planning to update the next revision as follows. Would this be acceptable?

YAML:
-  label:
-    enum:
-      - pvt0
-      - pvt1
+  label: true

required:
  - compatible
  - reg
  - clocks
  - interrupts
- - label

Driver:
 static int eic7700_pvt_create_hwmon(struct pvt_hwmon *pvt) {
-   struct device *dev = pvt->dev;
-   struct device_node *np = dev->of_node;
-   const char *node_label;
-   int type;
-   const char *names[2] = {"soc_pvt", "ddr_pvt"};

(quoted diff) +0 -12
-
-   if (of_property_read_string(np, "label", &node_label)) {
-       dev_err(dev, "Missing 'label' property in DTS node\n");
-       return -EINVAL;
-   }
-
-   if (strcmp(node_label, "pvt0") == 0) {
-       type = 0;
-   } else if (strcmp(node_label, "pvt1") == 0) {
-       type = 1;
-   } else {
-       dev_err(pvt->dev, "Unsupported label: %s\n", node_label);

Review

Quoted 10 lines
(quoted diff) +4 -3
-       return -EINVAL;
-   }
+   const char *name = "pvt";
+
+   of_property_read_string(pvt->dev->of_node, "label", &name);
 
-   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, names[type],
+   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, name,
                               pvt, &pvt_hwmon_info,
                               NULL);

This would try to register a free-text name for the hwmon device, which would be unacceptable.

Quoted 3 lines

There are lots of multi-channel devices out there. None of them have those problems. Why do you insist in free-text names instead of using, say, "reg" to distinguish the channels ?

Thanks for the clarification.

In the next revision, I will register the hwmon device with the fixed name "pvt".

Best regards,
Huan He

#8 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor

In reply to Huan He
Quoted 11 lines · Huan He

Hi Krzysztof,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 7 lines · On Thu, Apr 30, 2026 at 02:44:44PM +0800, [email protected] wrote:
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +5 -0
+
+  label:
+    enum:
+      - pvt0
+      - pvt1
Quoted 7 lines
Quoted 3 lines

No, label is user-visible name. Can be whatever user decides.

Please read writing bindings - instance IDs are not allowed.

Thanks for the clarification.
I am planning to update the next revision as follows. Would this be acceptable?

From DT ABI point of view, that would be fine, but as Guenter pointed out - it is not correct for hwmon.

Quoted 76 lines

YAML:
-  label:
-    enum:
-      - pvt0
-      - pvt1
+  label: true

required:
  - compatible
  - reg
  - clocks
  - interrupts
- - label

Driver:
 static int eic7700_pvt_create_hwmon(struct pvt_hwmon *pvt) {
-   struct device *dev = pvt->dev;
-   struct device_node *np = dev->of_node;
-   const char *node_label;
-   int type;
-   const char *names[2] = {"soc_pvt", "ddr_pvt"};

(quoted diff) +3 -14
-
-   if (of_property_read_string(np, "label", &node_label)) {
-       dev_err(dev, "Missing 'label' property in DTS node\n");
-       return -EINVAL;
-   }
-
-   if (strcmp(node_label, "pvt0") == 0) {
-       type = 0;
-   } else if (strcmp(node_label, "pvt1") == 0) {
-       type = 1;
-   } else {
-       dev_err(pvt->dev, "Unsupported label: %s\n", node_label);
-       return -EINVAL;
-   }
+   const char *name = "pvt";
+
+   of_property_read_string(pvt->dev->of_node, "label", &name);


-   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, names[type],
+   pvt->hwmon = devm_hwmon_device_register_with_info(pvt->dev, name, pvt, &pvt_hwmon_info,
                              NULL);

Quoted 23 lines
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+
+  resets:
+    maxItems: 1
+
+  '#thermal-sensor-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml line 58

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml new file +10 -0
+  - clocks
+  - interrupts
+  - label
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    pvt@50b00000 {
Quoted 6 lines

Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel sources for similar cases or you can grow the spec (via pull request to DT spec repo).

Quoted 2 lines

I will update the example node name from "pvt@..." to the generic "sensor@...". Is this acceptable?

Yes, assuming this is some sort of sensor.

Best regards,
Krzysztof

#9 lore raw

PATCH v4 2/2 hwmon: Add Eswin EIC7700 PVT sensor driver

In reply to [email protected]

From: Huan He <[email protected]>

Add support for ESWIN EIC7700 Voltage and Temperature sensor. The driver supports temperature and voltage monitoring with polynomial conversion, and provides sysfs interface for sensor data access.

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

---
 drivers/hwmon/Kconfig       |  12 +
 drivers/hwmon/Makefile      |   1 +
 drivers/hwmon/eic7700-pvt.c | 591 ++++++++++++++++++++++++++++++++++++
 drivers/hwmon/eic7700-pvt.h |  99 ++++++
 4 files changed, 703 insertions(+)
 create mode 100644 drivers/hwmon/eic7700-pvt.c
 create mode 100644 drivers/hwmon/eic7700-pvt.h
drivers/hwmon/Kconfig +12 -0
index 14e4cea48acc..1a69dfe7bdc1 100644
@@ -2033,6 +2033,18 @@ config SENSORS_DME1737
 	  This driver can also be built as a module. If so, the module
 	  will be called dme1737.
 
+config SENSORS_EIC7700_PVT
+	tristate "Eswin EIC7700 Process, Voltage, Temperature sensor driver"
+	depends on ARCH_ESWIN || COMPILE_TEST
+	depends on HWMON
+	select POLYNOMIAL
+	help
+	  If you say yes here you get support for Eswin EIC7700 PVT sensor
+	  embedded into the SoC.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called eic7700-pvt.
+
 config SENSORS_EMC1403
 	tristate "SMSC EMC1403/23 thermal sensor"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index 4788996aa137..3f8c347e3758 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
 obj-$(CONFIG_SENSORS_DRIVETEMP)	+= drivetemp.o
 obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
+obj-$(CONFIG_SENSORS_EIC7700_PVT) += eic7700-pvt.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
 obj-$(CONFIG_SENSORS_EMC2305)	+= emc2305.o
drivers/hwmon/eic7700-pvt.c new file +591 -0

591 lines not on this page · raw message

drivers/hwmon/eic7700-pvt.h new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH v4 2/2] hwmon: Add Eswin EIC7700 PVT sensor driver

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] Hardware access with disabled clock when CONFIG_PM=n - [High] Resource leak and hardware powered…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Hardware access with disabled clock when CONFIG_PM=n
- [High] Resource leak and hardware powered on during driver unbind
- [High] System suspend state desynchronization causes potential crashes
- [High] Unclocked hardware access in the interrupt handler
- [Medium] Missing synchronization on timeout path causes race condition and stale data
- [Medium] Unvalidated sysfs input and hwmon ABI violation for temp_offset
- [Low] Mismatch between commit message and implemented voltage channels
--

commit 226d2b003d7fbabad9b8abaf9c71cf6fdf386a91
Author: Huan He <[email protected]>

hwmon: Add Eswin EIC7700 PVT sensor driver

Add support for ESWIN EIC7700 Voltage and Temperature sensor. The driver supports temperature and voltage monitoring with polynomial conversion, and provides sysfs interface for sensor data access.

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

Quoted 2 lines

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

This isn't a bug, but the commit message states there are four voltage sensors, while the driver implementation only exposes a single voltage channel. Could the commit message be updated to match the implementation?

Quoted 5 lines
drivers/hwmon/eic7700-pvt.c new file +0 -0
new file mode 100644
index 0000000000000..d9d6a035defeb

[ ... ]

drivers/hwmon/eic7700-pvt.c line 120

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static irqreturn_t eic7700_pvt_hard_isr(int irq, void *data)
+{
+	struct pvt_hwmon *pvt = data;
+	u32 val;
+
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+	/*
+	 * Read the data, update the cache and notify a waiter of this event.
+	 */
+	val = readl(pvt->regs + PVT_DATA);

Could this cause a bus fault if a spurious or delayed interrupt fires while the device is in the RPM_SUSPENDED state?

When the device is suspended, the hardware clock is gated. Accessing registers without checking the PM runtime state could lead to a crash. Should this use pm_runtime_get_if_active() to protect against accessing unclocked hardware?

[ ... ]

Quoted 24 lines
drivers/hwmon/eic7700-pvt.c new file +24 -0
+static int eic7700_pvt_read_data(struct pvt_hwmon *pvt,
+				 enum pvt_sensor_type type, long *val)
+{
+	unsigned long timeout;
+	u32 data;
+	int ret;
+
+	/*
+	 * Wait for PVT conversion to complete and update the data cache. The
+	 * data read procedure is following: set the requested PVT sensor mode,
+	 * enable conversion, wait until conversion is finished, then disable
+	 * conversion and IRQ, and read the cached data.
+	 */
+	reinit_completion(&pvt->conversion);
+
+	eic7700_pvt_set_mode(pvt, pvt_info[type].mode);
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, PVT_ENA_EN);
+
+	/*
+	 * Wait with timeout since in case if the sensor is suddenly powered
+	 * down the request won't be completed and the caller will hang up on
+	 * this procedure until the power is back up again. Multiply the
+	 * timeout by the factor of two to prevent a false timeout.
+	 */

drivers/hwmon/eic7700-pvt.c line 160

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout));
+	ret = wait_for_completion_timeout(&pvt->conversion, timeout);
+
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, 0);
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+
+	data = READ_ONCE(pvt->data_cache);
+
+	if (!ret)
+		return -ETIMEDOUT;

If the timeout expires, could an interrupt still be in flight?

If so, a subsequent read request would call reinit_completion(), and the delayed interrupt handler could execute, complete the new request prematurely, and cause the read to return stale data.

Does the timeout path need to call synchronize_irq() to ensure no interrupt handler is running before returning?

[ ... ]

drivers/hwmon/eic7700-pvt.c line 225

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static int eic7700_pvt_write_trim(struct pvt_hwmon *pvt, long val)
+{
+	/*
+	 * Update PVT trim register safely while the controller is temporarily
+	 * disabled.
+	 */
+	eic7700_pvt_set_trim(pvt, val);
+
+	return 0;
+}

Does this code validate the user input before writing it to the hardware?

Writing a negative value could truncate to 0xFFFFFFFF and overwrite reserved bits in the register. Additionally, the hwmon ABI specifies that temp_offset should be in millidegrees Celsius, but this writes the raw value directly to the register without scaling.

[ ... ]

drivers/hwmon/eic7700-pvt.c line 443

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+static void eic7700_pvt_disable_pm_runtime(void *data)
+{
+	struct pvt_hwmon *pvt = data;
+
+	pm_runtime_dont_use_autosuspend(pvt->dev);
+	pm_runtime_disable(pvt->dev);
+}

Can this leak the clock reference and leave the hardware powered on if the device is unbound?

Because pm_runtime_put_autosuspend() is used after reads, the device remains active for a 3-second window. If the module is removed during this window, pm_runtime_disable() will cancel the pending suspend but it does not suspend a device that is currently RPM_ACTIVE.

Should this cleanup action explicitly suspend the device if it is active?

[ ... ]

Quoted 2 lines
drivers/hwmon/eic7700-pvt.c new file +2 -0
+static int eic7700_pvt_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/hwmon/eic7700-pvt.c line 481

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+	ret = eic7700_pvt_init_iface(pvt);
+	if (ret) {
+		clk_disable_unprepare(pvt->clk);
+		return ret;
+	}
+
+	clk_disable_unprepare(pvt->clk);

Is this driver intended to be built when CONFIG_PM is disabled?

If CONFIG_PM is disabled, pm_runtime_get_sync() in the hwmon read function is a no-op that returns 1. Because the clock is explicitly disabled at the end of probe() and relies entirely on PM runtime to re-enable it, a read operation will access the hardware registers while the clock is gated, leading to an external abort or system hang.

Also, eic7700_pvt_suspend() checks !pm_runtime_status_suspended(dev), which is always false when CONFIG_PM=n, causing it to erroneously call clk_disable_unprepare() on an already disabled clock.

[ ... ]

Quoted 4 lines
drivers/hwmon/eic7700-pvt.c new file +4 -0
+static int __maybe_unused eic7700_pvt_suspend(struct device *dev)
+{
+	int ret = 0;
+

drivers/hwmon/eic7700-pvt.c line 549

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	if (!pm_runtime_status_suspended(dev)) {
+		ret = eic7700_pvt_runtime_suspend(dev);
+		if (ret) {
+			dev_err(dev, "Failed to suspend: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}

Does calling eic7700_pvt_runtime_suspend() directly leave the PM runtime state desynchronized?

This manually gates the clock if the device is active, but it fails to update the device's PM runtime status. The PM core still considers the device to be RPM_ACTIVE.

If a kernel thread calls pm_runtime_get_sync() before late suspend, it will see the state as active, return immediately without re-enabling the clock, and crash when accessing registers.

Should this use pm_runtime_force_suspend() and pm_runtime_force_resume() to safely maintain state consistency?

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

Re: Re: [PATCH v4 2/2] hwmon: Add Eswin EIC7700 PVT sensor driver

Hi Sashiko, Guenter,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 23 lines

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Hardware access with disabled clock when CONFIG_PM=n
- [High] Resource leak and hardware powered on during driver unbind
- [High] System suspend state desynchronization causes potential crashes
- [High] Unclocked hardware access in the interrupt handler
- [Medium] Missing synchronization on timeout path causes race condition and stale data
- [Medium] Unvalidated sysfs input and hwmon ABI violation for temp_offset
- [Low] Mismatch between commit message and implemented voltage channels
--

commit 226d2b003d7fbabad9b8abaf9c71cf6fdf386a91
Author: Huan He <[email protected]>

hwmon: Add Eswin EIC7700 PVT sensor driver

Add support for ESWIN EIC7700 Voltage and Temperature sensor. The driver supports temperature and voltage monitoring with polynomial conversion, and provides sysfs interface for sensor data access.

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

Quoted 6 lines
Quoted 2 lines

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

This isn't a bug, but the commit message states there are four voltage sensors, while the driver implementation only exposes a single voltage channel. Could the commit message be updated to match the implementation?

I will update the commit message accordingly.

The current driver only exposes one temperature channel and one voltage channel, so the commit text will be changed to match the implementation.

Quoted 21 lines
Quoted 6 lines
drivers/hwmon/eic7700-pvt.c new file +0 -0
new file mode 100644
index 0000000000000..d9d6a035defeb

[ ... ]

drivers/hwmon/eic7700-pvt.c line 120

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static irqreturn_t eic7700_pvt_hard_isr(int irq, void *data)
+{
+	struct pvt_hwmon *pvt = data;
+	u32 val;
+
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+	/*
+	 * Read the data, update the cache and notify a waiter of this event.
+	 */
+	val = readl(pvt->regs + PVT_DATA);

Could this cause a bus fault if a spurious or delayed interrupt fires while the device is in the RPM_SUSPENDED state?

Quoted 3 lines

When the device is suspended, the hardware clock is gated. Accessing registers without checking the PM runtime state could lead to a crash. Should this use pm_runtime_get_if_active() to protect against accessing unclocked hardware?

Yes, this is a valid concern.

If a delayed or spurious interrupt fires while the device is runtime-suspended, the handler may otherwise touch registers after the clock has been gated.

I will update the ISR to guard register accesses with pm_runtime_get_if_active() and only access the hardware when the device is runtime active. The temporary PM reference will be dropped with pm_runtime_put_noidle() on the handled path.

The ISR will be changed along these lines:
+   int active;
+   if (IS_ENABLED(CONFIG_PM)) {
+       active = pm_runtime_get_if_active(pvt->dev);
+       if (active <= 0)
+           return IRQ_NONE;
+   }

    ... access registers ...

+   if (IS_ENABLED(CONFIG_PM))
+       pm_runtime_put_noidle(pvt->dev);

Quoted 39 lines

[ ... ]

Quoted 24 lines
drivers/hwmon/eic7700-pvt.c new file +24 -0
+static int eic7700_pvt_read_data(struct pvt_hwmon *pvt,
+				 enum pvt_sensor_type type, long *val)
+{
+	unsigned long timeout;
+	u32 data;
+	int ret;
+
+	/*
+	 * Wait for PVT conversion to complete and update the data cache. The
+	 * data read procedure is following: set the requested PVT sensor mode,
+	 * enable conversion, wait until conversion is finished, then disable
+	 * conversion and IRQ, and read the cached data.
+	 */
+	reinit_completion(&pvt->conversion);
+
+	eic7700_pvt_set_mode(pvt, pvt_info[type].mode);
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, PVT_ENA_EN);
+
+	/*
+	 * Wait with timeout since in case if the sensor is suddenly powered
+	 * down the request won't be completed and the caller will hang up on
+	 * this procedure until the power is back up again. Multiply the
+	 * timeout by the factor of two to prevent a false timeout.
+	 */

drivers/hwmon/eic7700-pvt.c line 160

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout));
+	ret = wait_for_completion_timeout(&pvt->conversion, timeout);
+
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, 0);
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+
+	data = READ_ONCE(pvt->data_cache);
+
+	if (!ret)
+		return -ETIMEDOUT;

If the timeout expires, could an interrupt still be in flight?

Quoted 6 lines

If so, a subsequent read request would call reinit_completion(), and the delayed interrupt handler could execute, complete the new request prematurely, and cause the read to return stale data.

Does the timeout path need to call synchronize_irq() to ensure no interrupt handler is running before returning?

If a timeout occurs, a delayed interrupt may still be in flight and could complete the next conversion request after reinit_completion().

I will add synchronize_irq() on the timeout path so that any in-flight handler has completed before returning.

The eic7700_pvt_read_data() function will be changed along these lines:

    eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);

+   if (!ret)
+       synchronize_irq(pvt->irq);
+
    data = READ_ONCE(pvt->data_cache);

Quoted 15 lines

[ ... ]

drivers/hwmon/eic7700-pvt.c line 225

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static int eic7700_pvt_write_trim(struct pvt_hwmon *pvt, long val)
+{
+	/*
+	 * Update PVT trim register safely while the controller is temporarily
+	 * disabled.
+	 */
+	eic7700_pvt_set_trim(pvt, val);
+
+	return 0;
+}

Does this code validate the user input before writing it to the hardware?

Quoted 4 lines

Writing a negative value could truncate to 0xFFFFFFFF and overwrite reserved bits in the register. Additionally, the hwmon ABI specifies that temp_offset should be in millidegrees Celsius, but this writes the raw value directly to the register without scaling.

Agreed.

The current temp_offset implementation exposes the raw PVT trim register directly, which does not match the hwmon ABI requirement for millidegree Celsius units.

I will remove the temp_offset attribute in the next revision instead of exposing an ABI-incompatible raw hardware value.

Quoted 13 lines

[ ... ]

drivers/hwmon/eic7700-pvt.c line 443

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+static void eic7700_pvt_disable_pm_runtime(void *data)
+{
+	struct pvt_hwmon *pvt = data;
+
+	pm_runtime_dont_use_autosuspend(pvt->dev);
+	pm_runtime_disable(pvt->dev);
+}

Can this leak the clock reference and leave the hardware powered on if the device is unbound?

Quoted 6 lines

Because pm_runtime_put_autosuspend() is used after reads, the device remains active for a 3-second window. If the module is removed during this window, pm_runtime_disable() will cancel the pending suspend but it does not suspend a device that is currently RPM_ACTIVE.

Should this cleanup action explicitly suspend the device if it is active?

pm_runtime_disable() alone does not guarantee that an RPM_ACTIVE device is runtime-suspended during driver unbind, so the clock may remain enabled if the driver is removed inside the autosuspend window.

I will fix this by forcing the device into runtime suspend before disabling runtime PM in the cleanup path.

The eic7700_pvt_disable_pm_runtime() function will be changed along these lines:

    pm_runtime_dont_use_autosuspend(pvt->dev);
+   pm_runtime_force_suspend(pvt->dev);
    pm_runtime_disable(pvt->dev);

Quoted 15 lines

[ ... ]

Quoted 2 lines
drivers/hwmon/eic7700-pvt.c new file +2 -0
+static int eic7700_pvt_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/hwmon/eic7700-pvt.c line 481

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+	ret = eic7700_pvt_init_iface(pvt);
+	if (ret) {
+		clk_disable_unprepare(pvt->clk);
+		return ret;
+	}
+
+	clk_disable_unprepare(pvt->clk);

Is this driver intended to be built when CONFIG_PM is disabled?

Quoted 5 lines

If CONFIG_PM is disabled, pm_runtime_get_sync() in the hwmon read function is a no-op that returns 1. Because the clock is explicitly disabled at the end of probe() and relies entirely on PM runtime to re-enable it, a read operation will access the hardware registers while the clock is gated, leading to an external abort or system hang.

With CONFIG_PM disabled, pm_runtime_get_sync() becomes a stub and the runtime PM callbacks are never invoked, while probe() currently gates the clock at the end. As a result, later hwmon register accesses may touch the hardware with the clock disabled.

I will fix this by keeping the clock enabled permanently when CONFIG_PM=n and gating it only during driver cleanup.

The eic7700_pvt_probe() function will be changed along these lines:

ret = devm_add_action_or_reset(dev, eic7700_pvt_disable_pm_runtime, pvt); if (ret)
    return ret;

pm_runtime_put_autosuspend(dev);

+   if (!IS_ENABLED(CONFIG_PM)) {
+       ret = clk_prepare_enable(pvt->clk);
+       if (ret)
+           return dev_err_probe(&pdev->dev, ret,
+                        "Failed to enable clock\n");
+   }

In eic7700_pvt_disable_pm_runtime:

    pm_runtime_disable(pvt->dev);
+   if (!IS_ENABLED(CONFIG_PM))
+       clk_disable_unprepare(pvt->clk);

Quoted 4 lines

Also, eic7700_pvt_suspend() checks !pm_runtime_status_suspended(dev), which is always false when CONFIG_PM=n, causing it to erroneously call clk_disable_unprepare() on an already disabled clock.

This part is not applicable with CONFIG_PM=n.

The driver uses pm_ptr(&eic7700_pvt_pm_ops), so with CONFIG_PM disabled the PM callback pointer is NULL and eic7700_pvt_suspend() is not executed by the PM core. Therefore there is no real double clk_disable_unprepare() from that path.

Quoted 24 lines

[ ... ]

Quoted 4 lines
drivers/hwmon/eic7700-pvt.c new file +4 -0
+static int __maybe_unused eic7700_pvt_suspend(struct device *dev)
+{
+	int ret = 0;
+

drivers/hwmon/eic7700-pvt.c line 549

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	if (!pm_runtime_status_suspended(dev)) {
+		ret = eic7700_pvt_runtime_suspend(dev);
+		if (ret) {
+			dev_err(dev, "Failed to suspend: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}

Does calling eic7700_pvt_runtime_suspend() directly leave the PM runtime state desynchronized?

This manually gates the clock if the device is active, but it fails to update the device's PM runtime status. The PM core still considers the device to be RPM_ACTIVE.

Quoted 6 lines

If a kernel thread calls pm_runtime_get_sync() before late suspend, it will see the state as active, return immediately without re-enabling the clock, and crash when accessing registers.

Should this use pm_runtime_force_suspend() and pm_runtime_force_resume() to safely maintain state consistency?

Calling the driver's runtime suspend/resume callbacks directly from the system sleep callbacks does not update the PM core state, so the runtime PM status can become inconsistent with the actual clock state.

I will switch the system sleep callbacks to pm_runtime_force_suspend() and pm_runtime_force_resume() in the next revision.

eic7700_pvt_pm_ops will be changed along these lines:

-   SYSTEM_SLEEP_PM_OPS(eic7700_pvt_suspend, eic7700_pvt_resume)
+   SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)

Best regards,
Huan He

With CONFIG_PM disabled, pm_runtime_get_sync() becomes a stub and the runtime PM callbacks are never invoked, while probe() currently gates the clock at the end. As a result, later hwmon register accesses may touch the hardware with the clock disabled.

I will fix this by keeping the clock enabled permanently when CONFIG_PM=n and gating it only during driver cleanup.

ret = devm_add_action_or_reset(dev, eic7700_pvt_disable_pm_runtime, pvt); if (ret)
    return ret;

pm_runtime_put_autosuspend(dev);

+   if (!IS_ENABLED(CONFIG_PM)) {
+       ret = clk_prepare_enable(pvt->clk);
+       if (ret)
+           return dev_err_probe(&pdev->dev, ret,
+                        "Failed to enable clock\n");
+   }
In eic7700_pvt_disable_pm_runtime:

    pm_runtime_disable(pvt->dev);
+   if (!IS_ENABLED(CONFIG_PM))
+       clk_disable_unprepare(pvt->clk);

With CONFIG_PM disabled, pm_runtime_get_sync() becomes a stub and the runtime PM callbacks are never invoked, while probe() currently gates the clock at the end. As a result, later hwmon register accesses may touch the hardware with the clock disabled.

I will fix this by keeping the clock enabled permanently when CONFIG_PM=n and gating it only during driver cleanup.

ret = devm_add_action_or_reset(dev, eic7700_pvt_disable_pm_runtime, pvt); if (ret)
    return ret;

pm_runtime_put_autosuspend(dev);

+   if (!IS_ENABLED(CONFIG_PM)) {
+       ret = clk_prepare_enable(pvt->clk);
+       if (ret)
+           return dev_err_probe(&pdev->dev, ret,
+                        "Failed to enable clock\n");
+   }
In eic7700_pvt_disable_pm_runtime:

    pm_runtime_disable(pvt->dev);
+   if (!IS_ENABLED(CONFIG_PM))
+       clk_disable_unprepare(pvt->clk);

With CONFIG_PM disabled, pm_runtime_get_sync() becomes a stub and the runtime PM callbacks are never invoked, while probe() currently gates the clock at the end. As a result, later hwmon register accesses may touch the hardware with the clock disabled.

I will fix this by keeping the clock enabled permanently when CONFIG_PM=n and gating it only during driver cleanup.

ret = devm_add_action_or_reset(dev, eic7700_pvt_disable_pm_runtime, pvt); if (ret)
    return ret;

pm_runtime_put_autosuspend(dev);

+   if (!IS_ENABLED(CONFIG_PM)) {
+       ret = clk_prepare_enable(pvt->clk);
+       if (ret)
+           return dev_err_probe(&pdev->dev, ret,
+                        "Failed to enable clock\n");
+   }
In eic7700_pvt_disable_pm_runtime:

    pm_runtime_disable(pvt->dev);
+   if (!IS_ENABLED(CONFIG_PM))
+       clk_disable_unprepare(pvt->clk);

author
#12 lore raw

Re: Re: Re: [PATCH v4 2/2] hwmon: Add Eswin EIC7700 PVT sensor driver

Hi Sashiko, Guenter,

Thank you very much for your detailed review. We appreciate the feedback.

Quoted 23 lines

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Hardware access with disabled clock when CONFIG_PM=n
- [High] Resource leak and hardware powered on during driver unbind
- [High] System suspend state desynchronization causes potential crashes
- [High] Unclocked hardware access in the interrupt handler
- [Medium] Missing synchronization on timeout path causes race condition and stale data
- [Medium] Unvalidated sysfs input and hwmon ABI violation for temp_offset
- [Low] Mismatch between commit message and implemented voltage channels
--

commit 226d2b003d7fbabad9b8abaf9c71cf6fdf386a91
Author: Huan He <[email protected]>

hwmon: Add Eswin EIC7700 PVT sensor driver

Add support for ESWIN EIC7700 Voltage and Temperature sensor. The driver supports temperature and voltage monitoring with polynomial conversion, and provides sysfs interface for sensor data access.

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

Quoted 6 lines
Quoted 2 lines

The PVT IP contains one temperature sensor and four voltage sensors for process variation monitoring.

This isn't a bug, but the commit message states there are four voltage sensors, while the driver implementation only exposes a single voltage channel. Could the commit message be updated to match the implementation?

I will update the commit message accordingly.

The current driver only exposes one temperature channel and one voltage channel, so the commit text will be changed to match the implementation.

Quoted 21 lines
Quoted 6 lines
drivers/hwmon/eic7700-pvt.c new file +0 -0
new file mode 100644
index 0000000000000..d9d6a035defeb

[ ... ]

drivers/hwmon/eic7700-pvt.c line 120

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static irqreturn_t eic7700_pvt_hard_isr(int irq, void *data)
+{
+	struct pvt_hwmon *pvt = data;
+	u32 val;
+
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+	/*
+	 * Read the data, update the cache and notify a waiter of this event.
+	 */
+	val = readl(pvt->regs + PVT_DATA);

Could this cause a bus fault if a spurious or delayed interrupt fires while the device is in the RPM_SUSPENDED state?

Quoted 3 lines

When the device is suspended, the hardware clock is gated. Accessing registers without checking the PM runtime state could lead to a crash. Should this use pm_runtime_get_if_active() to protect against accessing unclocked hardware?

Yes, this is a valid concern.

If a delayed or spurious interrupt fires while the device is runtime-suspended, the handler may otherwise touch registers after the clock has been gated.

I will update the ISR to guard register accesses with pm_runtime_get_if_active() and only access the hardware when the device is runtime active. The temporary PM reference will be dropped with pm_runtime_put_noidle() on the handled path.

The ISR will be changed along these lines:
+   int active;
+   if (IS_ENABLED(CONFIG_PM)) {
+       active = pm_runtime_get_if_active(pvt->dev);
+       if (active <= 0)
+           return IRQ_NONE;
+   }

    ... access registers ...

+   if (IS_ENABLED(CONFIG_PM))
+       pm_runtime_put_noidle(pvt->dev);

Quoted 39 lines

[ ... ]

Quoted 24 lines
drivers/hwmon/eic7700-pvt.c new file +24 -0
+static int eic7700_pvt_read_data(struct pvt_hwmon *pvt,
+				 enum pvt_sensor_type type, long *val)
+{
+	unsigned long timeout;
+	u32 data;
+	int ret;
+
+	/*
+	 * Wait for PVT conversion to complete and update the data cache. The
+	 * data read procedure is following: set the requested PVT sensor mode,
+	 * enable conversion, wait until conversion is finished, then disable
+	 * conversion and IRQ, and read the cached data.
+	 */
+	reinit_completion(&pvt->conversion);
+
+	eic7700_pvt_set_mode(pvt, pvt_info[type].mode);
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, PVT_ENA_EN);
+
+	/*
+	 * Wait with timeout since in case if the sensor is suddenly powered
+	 * down the request won't be completed and the caller will hang up on
+	 * this procedure until the power is back up again. Multiply the
+	 * timeout by the factor of two to prevent a false timeout.
+	 */

drivers/hwmon/eic7700-pvt.c line 160

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	timeout = 2 * usecs_to_jiffies(ktime_to_us(pvt->timeout));
+	ret = wait_for_completion_timeout(&pvt->conversion, timeout);
+
+	eic7700_pvt_update(pvt->regs + PVT_ENA, PVT_ENA_EN, 0);
+	eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);
+
+	data = READ_ONCE(pvt->data_cache);
+
+	if (!ret)
+		return -ETIMEDOUT;

If the timeout expires, could an interrupt still be in flight?

Quoted 6 lines

If so, a subsequent read request would call reinit_completion(), and the delayed interrupt handler could execute, complete the new request prematurely, and cause the read to return stale data.

Does the timeout path need to call synchronize_irq() to ensure no interrupt handler is running before returning?

If a timeout occurs, a delayed interrupt may still be in flight and could complete the next conversion request after reinit_completion().

I will add synchronize_irq() on the timeout path so that any in-flight handler has completed before returning.

The eic7700_pvt_read_data() function will be changed along these lines:

    eic7700_pvt_update(pvt->regs + PVT_INT, PVT_INT_CLR, PVT_INT_CLR);

+   if (!ret)
+       synchronize_irq(pvt->irq);
+
    data = READ_ONCE(pvt->data_cache);

Quoted 15 lines

[ ... ]

drivers/hwmon/eic7700-pvt.c line 225

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+static int eic7700_pvt_write_trim(struct pvt_hwmon *pvt, long val)
+{
+	/*
+	 * Update PVT trim register safely while the controller is temporarily
+	 * disabled.
+	 */
+	eic7700_pvt_set_trim(pvt, val);
+
+	return 0;
+}

Does this code validate the user input before writing it to the hardware?

Quoted 4 lines

Writing a negative value could truncate to 0xFFFFFFFF and overwrite reserved bits in the register. Additionally, the hwmon ABI specifies that temp_offset should be in millidegrees Celsius, but this writes the raw value directly to the register without scaling.

Agreed.

The current temp_offset implementation exposes the raw PVT trim register directly, which does not match the hwmon ABI requirement for millidegree Celsius units.

I will remove the temp_offset attribute in the next revision instead of exposing an ABI-incompatible raw hardware value.

Quoted 13 lines

[ ... ]

drivers/hwmon/eic7700-pvt.c line 443

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+static void eic7700_pvt_disable_pm_runtime(void *data)
+{
+	struct pvt_hwmon *pvt = data;
+
+	pm_runtime_dont_use_autosuspend(pvt->dev);
+	pm_runtime_disable(pvt->dev);
+}

Can this leak the clock reference and leave the hardware powered on if the device is unbound?

Quoted 6 lines

Because pm_runtime_put_autosuspend() is used after reads, the device remains active for a 3-second window. If the module is removed during this window, pm_runtime_disable() will cancel the pending suspend but it does not suspend a device that is currently RPM_ACTIVE.

Should this cleanup action explicitly suspend the device if it is active?

pm_runtime_disable() alone does not guarantee that an RPM_ACTIVE device is runtime-suspended during driver unbind, so the clock may remain enabled if the driver is removed inside the autosuspend window.

I will fix this by forcing the device into runtime suspend before disabling runtime PM in the cleanup path.

The eic7700_pvt_disable_pm_runtime() function will be changed along these lines:

    pm_runtime_dont_use_autosuspend(pvt->dev);
+   pm_runtime_force_suspend(pvt->dev);
    pm_runtime_disable(pvt->dev);

Quoted 15 lines

[ ... ]

Quoted 2 lines
drivers/hwmon/eic7700-pvt.c new file +2 -0
+static int eic7700_pvt_probe(struct platform_device *pdev)
+{

[ ... ]

drivers/hwmon/eic7700-pvt.c line 481

Quoted 7 lines
drivers/hwmon/eic7700-pvt.c new file +7 -0
+	ret = eic7700_pvt_init_iface(pvt);
+	if (ret) {
+		clk_disable_unprepare(pvt->clk);
+		return ret;
+	}
+
+	clk_disable_unprepare(pvt->clk);

Is this driver intended to be built when CONFIG_PM is disabled?

Quoted 5 lines

If CONFIG_PM is disabled, pm_runtime_get_sync() in the hwmon read function is a no-op that returns 1. Because the clock is explicitly disabled at the end of probe() and relies entirely on PM runtime to re-enable it, a read operation will access the hardware registers while the clock is gated, leading to an external abort or system hang.

With CONFIG_PM disabled, pm_runtime_get_sync() becomes a stub and the runtime PM callbacks are never invoked, while probe() currently gates the clock at the end. As a result, later hwmon register accesses may touch the hardware with the clock disabled.

I will fix this by keeping the clock enabled permanently when CONFIG_PM=n and gating it only during driver cleanup.

The eic7700_pvt_probe() function will be changed along these lines:

ret = devm_add_action_or_reset(dev, eic7700_pvt_disable_pm_runtime, pvt); if (ret)
    return ret;

pm_runtime_put_autosuspend(dev);

+   if (!IS_ENABLED(CONFIG_PM)) {
+       ret = clk_prepare_enable(pvt->clk);
+       if (ret)
+           return dev_err_probe(&pdev->dev, ret,
+                        "Failed to enable clock\n");
+   }

In eic7700_pvt_disable_pm_runtime:

    pm_runtime_disable(pvt->dev);
+   if (!IS_ENABLED(CONFIG_PM))
+       clk_disable_unprepare(pvt->clk);

Quoted 4 lines

Also, eic7700_pvt_suspend() checks !pm_runtime_status_suspended(dev), which is always false when CONFIG_PM=n, causing it to erroneously call clk_disable_unprepare() on an already disabled clock.

This part is not applicable with CONFIG_PM=n.

The driver uses pm_ptr(&eic7700_pvt_pm_ops), so with CONFIG_PM disabled the PM callback pointer is NULL and eic7700_pvt_suspend() is not executed by the PM core. Therefore there is no real double clk_disable_unprepare() from that path.

Quoted 24 lines

[ ... ]

Quoted 4 lines
drivers/hwmon/eic7700-pvt.c new file +4 -0
+static int __maybe_unused eic7700_pvt_suspend(struct device *dev)
+{
+	int ret = 0;
+

drivers/hwmon/eic7700-pvt.c line 549

Quoted 10 lines
drivers/hwmon/eic7700-pvt.c new file +10 -0
+	if (!pm_runtime_status_suspended(dev)) {
+		ret = eic7700_pvt_runtime_suspend(dev);
+		if (ret) {
+			dev_err(dev, "Failed to suspend: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}

Does calling eic7700_pvt_runtime_suspend() directly leave the PM runtime state desynchronized?

This manually gates the clock if the device is active, but it fails to update the device's PM runtime status. The PM core still considers the device to be RPM_ACTIVE.

Quoted 6 lines

If a kernel thread calls pm_runtime_get_sync() before late suspend, it will see the state as active, return immediately without re-enabling the clock, and crash when accessing registers.

Should this use pm_runtime_force_suspend() and pm_runtime_force_resume() to safely maintain state consistency?

Calling the driver's runtime suspend/resume callbacks directly from the system sleep callbacks does not update the PM core state, so the runtime PM status can become inconsistent with the actual clock state.

I will switch the system sleep callbacks to pm_runtime_force_suspend() and pm_runtime_force_resume() in the next revision.

eic7700_pvt_pm_ops will be changed along these lines:

-   SYSTEM_SLEEP_PM_OPS(eic7700_pvt_suspend, eic7700_pvt_resume)
+   SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)

Best regards,
Huan He

maintainer
#13 lore raw
In reply to [email protected]
Quoted 9 lines · On 4/29/26 23:41, [email protected] wrote:

From: Huan He <[email protected]>

Add support for the ESWIN EIC7700 PVT (Voltage, Temperature) sensor

Features:
The driver supports monitoring of voltage and temperature parameters through the hardware monitoring subsystem. It provides an access to the sampled Temperature and Voltage.

Please either address the issues reported by Sashiko, or explain why they are invalid.

Thanks,
Guenter

Quoted 90 lines

Test:
Tested this patch on the SiFive HiFive Premier P550 (which uses the ESWIN EIC7700 SoC).

Updates:

Changes in v4:
- Update eswin,eic7700-pvt.yaml
- Delete reviewed-by tag of Conor Dooley, because the label enum constraint is introduced
- Update eic7700-pvt.c and eic7700-pvt.h
- Remove the unused LVT/ULVT/SVT process-monitoring channels
- Remove the probe-time power check since the PVT block is always powered on EIC7700 and the extra verification is unnecessary
- Stop requesting the interrupt as shared and use the dedicated PVT IRQ only
- Reorder probe initialization so the interface is initialized before the clock is disabled, avoiding register accesses with the clock gated
- Fix runtime PM reference handling on error paths by balancing pm_runtime_get_noresume() with pm_runtime_put_noidle()
- Add pm_runtime_put_noidle() handling for failed pm_runtime_get_sync() calls in hwmon read/write paths
- Switch the PM callback registration from pm_sleep_ptr() to pm_ptr()

Changes in v3:
- Update eswin,eic7700-pvt.yaml
- Remove redundant label property description and use 'label: true' to reference the definition in hwmon-common.yaml
- Replace 'additionalProperties: false' with 'unevaluatedProperties: false'
- Remove the description for '#thermal-sensor-cells'
- Update eic7700-pvt.c and eic7700-pvt.h
- Fix clock reference count imbalance with Runtime PM:
Replace devm_clk_get_enabled() with devm_clk_get() and manually manage clock enable/disable to avoid double-disable in remove() when Runtime PM is active. Clock is now enabled only during probe for eic7700_pvt_check_pwr(), then disabled before enabling Runtime PM, which takes full control of the clock thereafter
- Add detailed comment explaining the spurious interrupt risk in eic7700_pvt_check_pwr()
- Replace wait_for_completion_interruptible() with wait_for_completion_timeout() to prevent infinite wait

Changes in v2:
- Update eswin,eic7700-pvt.yaml
- Reference the hwmon-common.yaml file
- Remove the clock-names and reset-names properties
- Move additionalProperties: false after the required block
- Remove one example node to avoid redundancy
- Update eic7700-pvt.c and eic7700-pvt.h
- Remove unused sensor macros (PVT_SENSOR_FIRST, PVT_SENSOR_LAST, PVT_SENSORS_NUM)
- Drop the unnecessary hwmon-sysfs.h header
- Replace dynamic sensor info allocation with a static array and unify sensor labels
- Remove unused hwmon_temp_type attribute
- Eliminate redundant validation checks
- Remove mutex and related locking, relying on hwmon core serialization
- Replace per-sensor caches and completions with a single data cache and completion object
- Remove pvt->sensor tracking. ISR no longer depends on the currently selected sensor
- Move devm_add_action() registration after init_completion() for safer cleanup, and update cleanup function (pvt_clear_data)
- Replace devm_reset_control_get_optional_exclusive() with devm_reset_control_get_exclusive_deasserted()
- Replace eic7700_pvt_remove() with eic7700_pvt_disable_pm_runtime() and move it after PM runtime enable to avoid resource leaks on probe failure and remove clock disable and reset assert from eic7700_pvt_disable_pm_runtime() as it is already handled by devm_* framework
- Remove redundant clock presence check in runtime_resume

- Link to v1: https://lore.kernel.org/all/[email protected]/

Huan He (2):
dt-bindings: hwmon: Add Eswin EIC7700 PVT sensor
hwmon: Add Eswin EIC7700 PVT sensor driver

  .../bindings/hwmon/eswin,eic7700-pvt.yaml     |  68 ++
  drivers/hwmon/Kconfig                         |  12 +
  drivers/hwmon/Makefile                        |   1 +
  drivers/hwmon/eic7700-pvt.c                   | 591 ++++++++++++++++++
  drivers/hwmon/eic7700-pvt.h                   |  99 +++
  5 files changed, 771 insertions(+)

create mode 100644 Documentation/devicetree/bindings/hwmon/eswin,eic7700-pvt.yaml create mode 100644 drivers/hwmon/eic7700-pvt.c
create mode 100644 drivers/hwmon/eic7700-pvt.h