Skip to contentSkip to conversation

hwmon: Add support for currX_emergency and inX_emergency attributes

PATCH Superseded Guenter Roeck 2 participants 2 messages Jul 22

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: Add support for currX_emergency and inX_emergency attributes

Some hardware monitoring chips support three alarm levels for current and voltage measurements. Add support for currX_emergency and inX_emergency attributes to support such chips.

Cc Manaf Meethalavalappu Pallikunhi <[email protected]>

---
RFT: Waiting for an actual chip driver using the new attributes.

 Documentation/ABI/testing/sysfs-class-hwmon | 26 +++++++++++++++++++++
 Documentation/hwmon/sysfs-interface.rst     |  6 +++++
 drivers/hwmon/hwmon.c                       |  2 ++
 include/linux/hwmon.h                       |  4 ++++
 4 files changed, 38 insertions(+)
Documentation/ABI/testing/sysfs-class-hwmon +26 -0
index b185bdfc7186..42fd89305101 100644
@@ -81,6 +81,18 @@ Description:
 		take drastic action such as power down or reset. At the very
 		least, it should report a fault.
 
+What:		/sys/class/hwmon/hwmonX/inY_emergency
+Description:
+		Voltage emergency max value.
+
+		Unit: millivolt
+
+		RW
+
+		If voltage reaches or exceeds this limit, the system is expected
+		to take drastic action such as immediate power down or reset.
+		At the very least, it should report a fault.
+
 What:		/sys/class/hwmon/hwmonX/inY_input
 Description:
 		Voltage input value.
@@ -647,6 +659,20 @@ Description:
 
 		RW
 
+What:		/sys/class/hwmon/hwmonX/currY_emergency
+Description:
+		Current emergency high value.
+
+		Unit: milliampere
+
+		RW
+
+		If a current reaches or exceeds this limit, the system is
+		expected to take drastic action such as immediate power down
+		or reset. At the very least, it should report a fault.
+
+What:		/sys/class/hwmon/hwmonX/inY_input
+
 What:		/sys/class/hwmon/hwmonX/currY_input
 Description:
 		Current input value
Documentation/hwmon/sysfs-interface.rst +6 -0
index 94e1bbce172a..e8f2a12793af 100644
@@ -127,6 +127,9 @@ Voltages
 `in[0-*]_crit`
 		Voltage critical max value.
 
+`in[0-*]_emergency`
+		Voltage emergency max value.
+
 `in[0-*]_input`
 		Voltage input value.
 
@@ -332,6 +335,9 @@ Currents
 `curr[1-*]_crit`
 		Current critical high value.
 
+`curr[1-*]_emergency`
+		Current emergency high value.
+
 `curr[1-*]_input`
 		Current input value.
 
drivers/hwmon/hwmon.c +2 -0
index 55a9a3ddd4aa..a07bfe7ac7db 100644
@@ -621,6 +621,7 @@ static const char * const hwmon_in_attr_templates[] = {
 	[hwmon_in_max] = "in%d_max",
 	[hwmon_in_lcrit] = "in%d_lcrit",
 	[hwmon_in_crit] = "in%d_crit",
+	[hwmon_in_emergency] = "in%d_emergency",
 	[hwmon_in_average] = "in%d_average",
 	[hwmon_in_lowest] = "in%d_lowest",
 	[hwmon_in_highest] = "in%d_highest",
@@ -644,6 +645,7 @@ static const char * const hwmon_curr_attr_templates[] = {
 	[hwmon_curr_max] = "curr%d_max",
 	[hwmon_curr_lcrit] = "curr%d_lcrit",
 	[hwmon_curr_crit] = "curr%d_crit",
+	[hwmon_curr_emergency] = "curr%d_emergency",
 	[hwmon_curr_average] = "curr%d_average",
 	[hwmon_curr_lowest] = "curr%d_lowest",
 	[hwmon_curr_highest] = "curr%d_highest",
include/linux/hwmon.h +4 -0
index 77a6f2bffcba..2cd433966723 100644
@@ -134,6 +134,7 @@ enum hwmon_in_attributes {
 	hwmon_in_max,
 	hwmon_in_lcrit,
 	hwmon_in_crit,
+	hwmon_in_emergency,
 	hwmon_in_average,
 	hwmon_in_lowest,
 	hwmon_in_highest,
@@ -156,6 +157,7 @@ enum hwmon_in_attributes {
 #define HWMON_I_MAX		BIT(hwmon_in_max)
 #define HWMON_I_LCRIT		BIT(hwmon_in_lcrit)
 #define HWMON_I_CRIT		BIT(hwmon_in_crit)
+#define HWMON_I_EMERGENCY	BIT(hwmon_in_emergency)
 #define HWMON_I_AVERAGE		BIT(hwmon_in_average)
 #define HWMON_I_LOWEST		BIT(hwmon_in_lowest)
 #define HWMON_I_HIGHEST		BIT(hwmon_in_highest)
@@ -178,6 +180,7 @@ enum hwmon_curr_attributes {
 	hwmon_curr_max,
 	hwmon_curr_lcrit,
 	hwmon_curr_crit,
+	hwmon_curr_emergency,
 	hwmon_curr_average,
 	hwmon_curr_lowest,
 	hwmon_curr_highest,
@@ -199,6 +202,7 @@ enum hwmon_curr_attributes {
 #define HWMON_C_MAX		BIT(hwmon_curr_max)
 #define HWMON_C_LCRIT		BIT(hwmon_curr_lcrit)
 #define HWMON_C_CRIT		BIT(hwmon_curr_crit)
+#define HWMON_C_EMERGENCY	BIT(hwmon_curr_emergency)
 #define HWMON_C_AVERAGE		BIT(hwmon_curr_average)
 #define HWMON_C_LOWEST		BIT(hwmon_curr_lowest)
 #define HWMON_C_HIGHEST		BIT(hwmon_curr_highest)
Signature · 1 line
2.45.2
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Missing `_alarm` attributes for new emergency limits. - [Low] Orphaned duplicate `inY_input`…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing _alarm attributes for new emergency limits.
- [Low] Orphaned duplicate inY_input entry in sysfs ABI documentation.
--

--- Patch [1]: [RFT PATCH] hwmon: Add support for currX_emergency and inX_emergency attributes --- commit d42d90a3ffe54304e60c7c4aa212e4dd46adefe6
Author: Guenter Roeck <[email protected]>

hwmon: Add support for currX_emergency and inX_emergency attributes

This commit introduces support for currX_emergency and inX_emergency attributes in the hardware monitoring subsystem. It updates the sysfs ABI documentation and adds the new attributes to the hwmon core templates and enums.

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-hwmon +0 -0
index b185bdfc7186a..42fd89305101a 100644

[ ... ]

Quoted 11 lines
Documentation/ABI/testing/sysfs-class-hwmon +7 -0
@@ -647,6 +659,20 @@ Description:
 
 		RW
 
+What:		/sys/class/hwmon/hwmonX/currY_emergency
+Description:
+		Current emergency high value.
+
+		Unit: milliampere
+
+		RW

Documentation/ABI/testing/sysfs-class-hwmon Description: · line 678

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-hwmon +7 -0
+
+		If a current reaches or exceeds this limit, the system is
+		expected to take drastic action such as immediate power down
+		or reset. At the very least, it should report a fault.
+
+What:		/sys/class/hwmon/hwmonX/inY_input
+
 What:		/sys/class/hwmon/hwmonX/currY_input
 Description:
 		Current input value

[Severity: Low]
This isn't a bug, but should this What: /sys/class/hwmon/hwmonX/inY_input line be here?

It appears to be an orphaned duplicate entry.

Quoted 4 lines
drivers/hwmon/hwmon.c +0 -0
index 55a9a3ddd4aac..a07bfe7ac7dbf 100644

[ ... ]

drivers/hwmon/hwmon.c static const char * const hwmon_in_attr_templates[] = { · line 627

Quoted 8 lines
drivers/hwmon/hwmon.c +1 -0
@@ -621,6 +621,7 @@ static const char * const hwmon_in_attr_templates[] = {
 	[hwmon_in_max] = "in%d_max",
 	[hwmon_in_lcrit] = "in%d_lcrit",
 	[hwmon_in_crit] = "in%d_crit",
+	[hwmon_in_emergency] = "in%d_emergency",
 	[hwmon_in_average] = "in%d_average",
 	[hwmon_in_lowest] = "in%d_lowest",
 	[hwmon_in_highest] = "in%d_highest",

[Severity: Medium]
Are we missing the string definition for in%d_emergency_alarm here?

Without hwmon_in_emergency_alarm in the hwmon_in_attr_templates array, drivers will not be able to use the hwmon_device_register_with_info API to expose the voltage emergency alarm status.

[ ... ]

drivers/hwmon/hwmon.c static const char * const hwmon_curr_attr_templates[] = { · line 651

Quoted 8 lines
drivers/hwmon/hwmon.c +1 -0
@@ -644,6 +645,7 @@ static const char * const hwmon_curr_attr_templates[] = {
 	[hwmon_curr_max] = "curr%d_max",
 	[hwmon_curr_lcrit] = "curr%d_lcrit",
 	[hwmon_curr_crit] = "curr%d_crit",
+	[hwmon_curr_emergency] = "curr%d_emergency",
 	[hwmon_curr_average] = "curr%d_average",
 	[hwmon_curr_lowest] = "curr%d_lowest",
 	[hwmon_curr_highest] = "curr%d_highest",

[Severity: Medium]
Similarly, does hwmon_curr_attr_templates also need a string definition for curr%d_emergency_alarm?

include/linux/hwmon.h enum hwmon_in_attributes { · line 140

Quoted 12 lines
include/linux/hwmon.h +1 -0
index 77a6f2bffcba7..2cd433966723e 100644
@@ -134,6 +134,7 @@ enum hwmon_in_attributes {
 	hwmon_in_max,
 	hwmon_in_lcrit,
 	hwmon_in_crit,
+	hwmon_in_emergency,
 	hwmon_in_average,
 	hwmon_in_lowest,
 	hwmon_in_highest,

[Severity: Medium]
Should hwmon_in_emergency_alarm be declared in enum hwmon_in_attributes alongside the other voltage alarm attributes to complete the API feature?

[ ... ]

include/linux/hwmon.h enum hwmon_curr_attributes { · line 186

Quoted 8 lines
include/linux/hwmon.h +1 -0
@@ -178,6 +180,7 @@ enum hwmon_curr_attributes {
 	hwmon_curr_max,
 	hwmon_curr_lcrit,
 	hwmon_curr_crit,
+	hwmon_curr_emergency,
 	hwmon_curr_average,
 	hwmon_curr_lowest,
 	hwmon_curr_highest,

[Severity: Medium]
Does enum hwmon_curr_attributes also need hwmon_curr_emergency_alarm declared to allow exporting current emergency alarm statuses?

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