Skip to contentSkip to conversation

platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.

PATCH Superseded Nitin Joshi 4 participants 11 messages Dec 10, 2025 – Dec 16, 2025

Subsystems (4)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.

Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify whether hardware damage is detected or not.

Initial support is available for the USB-C replaceable connector.

---
Changes since v1:
-Split patch between hwdd_status and hwdd_detail
-Incorporated review comments

---
 .../admin-guide/laptops/thinkpad-acpi.rst     |  21 ++++
 drivers/platform/x86/lenovo/thinkpad_acpi.c   | 104 ++++++++++++++++++
 2 files changed, 125 insertions(+)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +21 -0
index 4ab0fef7d440..94349e5f1298 100644
@@ -54,6 +54,7 @@ detailed description):
 	- Setting keyboard language
 	- WWAN Antenna type
 	- Auxmac
+	- Hardware damage detection capability
 
 A compatibility table by model and feature is maintained on the web
 site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1576,6 +1577,26 @@ percentage level, above which charging will stop.
 The exact semantics of the attributes may be found in
 Documentation/ABI/testing/sysfs-class-power.
 
+Hardware damage detection capability
+-----------------
+
+sysfs attributes: hwdd_status
+
+Thinkpads are adding the ability to detect and report hardware damage.
+Add new sysfs interface to identify the damaged device status.
+Initial support is available for the USB-C replaceable connector.
+
+The command to check device damaged status is::
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_status
+
+This value displays status of device damaged
+- 0 = Not Damaged
+- 1 = Damaged
+
+The property is read-only. If feature is not supported then sysfs
+attribute is not created.
+
 Multiple Commands, Module Parameters
 ------------------------------------
 
drivers/platform/x86/lenovo/thinkpad_acpi.c +104 -0

122 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/2 platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

Add new sysfs interface to identify the impacted component with location of device.

---
 .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +-
 drivers/platform/x86/lenovo/thinkpad_acpi.c   | 112 +++++++++++++++++-
 2 files changed, 121 insertions(+), 4 deletions(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +12 -1
index 94349e5f1298..3a9190ac47d0 100644
@@ -1580,7 +1580,7 @@ Documentation/ABI/testing/sysfs-class-power.
 Hardware damage detection capability
 -----------------
 
-sysfs attributes: hwdd_status
+sysfs attributes: hwdd_status, hwdd_detail
 
 Thinkpads are adding the ability to detect and report hardware damage.
 Add new sysfs interface to identify the damaged device status.
@@ -1594,6 +1594,17 @@ This value displays status of device damaged
 - 0 = Not Damaged
 - 1 = Damaged
 
+The command to check location of damaged device is::
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
+
+This value displays location of damaged device having 1 line per damaged "item".
+For example:
+if no damage is detected:
+  No damage detected
+if damage detected:
+  TYPE-C: Base, Right side, Center port
+
 The property is read-only. If feature is not supported then sysfs
 attribute is not created.
 
drivers/platform/x86/lenovo/thinkpad_acpi.c +109 -3

133 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

Quoted 148 lines · Nitin Joshi

Add new sysfs interface to identify the impacted component with location of device.

---
  .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +-
  drivers/platform/x86/lenovo/thinkpad_acpi.c   | 112 +++++++++++++++++-
  2 files changed, 121 insertions(+), 4 deletions(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +12 -1
index 94349e5f1298..3a9190ac47d0 100644
@@ -1580,7 +1580,7 @@ Documentation/ABI/testing/sysfs-class-power.
  Hardware damage detection capability
  -----------------
 
-sysfs attributes: hwdd_status
+sysfs attributes: hwdd_status, hwdd_detail
 
  Thinkpads are adding the ability to detect and report hardware damage.
  Add new sysfs interface to identify the damaged device status.
@@ -1594,6 +1594,17 @@ This value displays status of device damaged
  - 0 = Not Damaged
  - 1 = Damaged
 
+The command to check location of damaged device is::
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
+
+This value displays location of damaged device having 1 line per damaged "item".
+For example:
+if no damage is detected:
+  No damage detected
+if damage detected:
+  TYPE-C: Base, Right side, Center port
+
  The property is read-only. If feature is not supported then sysfs
  attribute is not created.
 
drivers/platform/x86/lenovo/thinkpad_acpi.c +89 -3
index 4cf365550bcb..a092d57d995d 100644
@@ -11089,8 +11089,24 @@ static const struct attribute_group auxmac_attr_group = {
  #define HWDD_NOT_SUPPORTED	BIT(31)
  #define HWDD_SUPPORT_USBC	BIT(0)
 
-#define PORT_STATUS		GENMASK(7, 4)
-#define NUM_PORTS		4
+#define PORT_STATUS     GENMASK(7, 4)
+#define LID_STATUS      GENMASK(11, 8)
+#define BASE_STATUS     GENMASK(15, 12)
+#define POS_STATUS      GENMASK(3, 2)
+#define PANEL_STATUS    GENMASK(1, 0)
+
+#define PORT_DETAIL_OFFSET	16
+
+#define PANEL_TOP	0
+#define PANEL_BASE	1
+#define PANEL_LEFT	2
+#define PANEL_RIGHT	3
+
+#define POS_LEFT	0
+#define POS_CENTER	1
+#define POS_RIGHT	2
+
+#define NUM_PORTS	4
 
  static bool hwdd_support_available;
  static bool ucdd_supported;
@@ -11108,7 +11124,95 @@ static int hwdd_command(int command, int *output)
  	return 0;
  }
 
-/* sysfs type-c damage detection capability */
+static bool display_damage(char *buf, int *count, char *type, unsigned int dmg_status)
+{
+	unsigned char lid_status, base_status, port_status;
+	unsigned char loc_status, pos_status, panel_status;
+	bool damage_detected = false;
+	int i;
+
+	port_status = FIELD_GET(PORT_STATUS, dmg_status);
+	lid_status = FIELD_GET(LID_STATUS, dmg_status);
+	base_status = FIELD_GET(BASE_STATUS, dmg_status);
+	for (i = 0; i < NUM_PORTS; i++) {
+		if (!(dmg_status & BIT(i)))
+			continue;
+
+		if (port_status & BIT(i)) {
+			*count += sysfs_emit_at(buf, *count, "%s: ", type);
+			loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * i))) & 0xF;
+			pos_status = FIELD_GET(POS_STATUS, loc_status);
+			panel_status = FIELD_GET(PANEL_STATUS, loc_status);
+
+			if (lid_status & BIT(i))
+				*count += sysfs_emit_at(buf, *count, "Lid, ");
+			if (base_status & BIT(i))
+				*count += sysfs_emit_at(buf, *count, "Base, ");
+
+			switch (pos_status) {
+			case PANEL_TOP:
+				*count += sysfs_emit_at(buf, *count, "Top, ");
+				break;
+			case PANEL_BASE:
+				*count += sysfs_emit_at(buf, *count, "Bottom, ");
+				break;
+			case PANEL_LEFT:
+				*count += sysfs_emit_at(buf, *count, "Left, ");
+				break;
+			case PANEL_RIGHT:
+				*count += sysfs_emit_at(buf, *count, "Right, ");
+				break;
+			default:
+				pr_err("Unexpected value %d in switch statement\n", pos_status);
+			};
+
+			switch (panel_status) {
+			case POS_LEFT:
+				*count += sysfs_emit_at(buf, *count, "Left port\n");
+				break;
+			case POS_CENTER:
+				*count += sysfs_emit_at(buf, *count, "Center port\n");
+				break;
+			case POS_RIGHT:
+				*count += sysfs_emit_at(buf, *count, "Right port\n");
+				break;
+			default:
+				*count += sysfs_emit_at(buf, *count, "Undefined\n");
+				break;
+			};
+			damage_detected = true;
+		}
+	}
+	return damage_detected;
+}
+
+/* sysfs type-c damage detection detail */
+static ssize_t hwdd_detail_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	bool damage_detected = false;
+	unsigned int damage_status;
+	int err, count = 0;
+

drivers/platform/x86/lenovo/thinkpad_acpi.c static int hwdd_command(int command, int *output) · line 11207

Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10 -0
+
+	if (ucdd_supported) {
+		/* Get USB TYPE-C damage status */
+		err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
+		if (err)
+			return err;
+
+		if (display_damage(buf, &count, "Type-C", damage_status))
+			damage_detected = true;
+	}

Since this is always visible aren't you missing a case for !ucdd_supported? I would think you should be returning -ENODEV.

Although arguably it would be better to control visibility of the sysfs attribute based upon ucdd_supported. You can simplify hwdd_detail_show() too then.

Quoted 23 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10 -0
+
+	if (!damage_detected)
+		count += sysfs_emit_at(buf, count, "No damage detected\n");
+
+	return count;
+}
+
+/* sysfs typc damage detection capability */
  static ssize_t hwdd_status_show(struct device *dev,
  				struct device_attribute *attr,
  				char *buf)
@@ -11134,9 +11238,11 @@ static ssize_t hwdd_status_show(struct device *dev,
  	return sysfs_emit(buf, "0\n");
  }
  static DEVICE_ATTR_RO(hwdd_status);
+static DEVICE_ATTR_RO(hwdd_detail);
 
  static struct attribute *hwdd_attributes[] = {
  	&dev_attr_hwdd_status.attr,
+	&dev_attr_hwdd_detail.attr,
  	NULL
  };
 
author
#3 lore raw

Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

Hi Mario,

Thank you for your comments.

Quoted 152 lines · Mario Limonciello
Quoted 151 lines · Nitin Joshi

Add new sysfs interface to identify the impacted component with location of device.

---
  .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +- drivers/platform/x86/lenovo/thinkpad_acpi.c   | 112 +++++++++++++++++-

  2 files changed, 121 insertions(+), 4 deletions(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
index 94349e5f1298..3a9190ac47d0 100644
@@ -1580,7 +1580,7 @@ Documentation/ABI/testing/sysfs-class-power.

  Hardware damage detection capability
  -----------------
  -sysfs attributes: hwdd_status
+sysfs attributes: hwdd_status, hwdd_detail
    Thinkpads are adding the ability to detect and report hardware damage. Add new sysfs interface to identify the damaged device status.

Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
@@ -1594,6 +1594,17 @@ This value displays status of device damaged

  - 0 = Not Damaged
  - 1 = Damaged
  +The command to check location of damaged device is::

Documentation/admin-guide/laptops/thinkpad-acpi.rst +4 -0
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
+
+This value displays location of damaged device having 1 line per 

damaged "item".

Documentation/admin-guide/laptops/thinkpad-acpi.rst +6 -0
+For example:
+if no damage is detected:
+  No damage detected
+if damage detected:
+  TYPE-C: Base, Right side, Center port
+

  The property is read-only. If feature is not supported then sysfs
  attribute is not created.
  diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c index 4cf365550bcb..a092d57d995d 100644

drivers/platform/x86/lenovo/thinkpad_acpi.c +18 -1
@@ -11089,8 +11089,24 @@ static const struct attribute_group 
 auxmac_attr_group = {
   #define HWDD_NOT_SUPPORTED    BIT(31)
   #define HWDD_SUPPORT_USBC    BIT(0)
   -#define PORT_STATUS        GENMASK(7, 4)
-#define NUM_PORTS        4
+#define PORT_STATUS     GENMASK(7, 4)
+#define LID_STATUS      GENMASK(11, 8)
+#define BASE_STATUS     GENMASK(15, 12)
+#define POS_STATUS      GENMASK(3, 2)
+#define PANEL_STATUS    GENMASK(1, 0)
+
+#define PORT_DETAIL_OFFSET    16
+
+#define PANEL_TOP    0
+#define PANEL_BASE    1
+#define PANEL_LEFT    2
+#define PANEL_RIGHT    3
+
+#define POS_LEFT    0
+#define POS_CENTER    1
+#define POS_RIGHT    2
+
+#define NUM_PORTS    4
     static bool hwdd_support_available;
   static bool ucdd_supported;
@@ -11108,7 +11124,95 @@ static int hwdd_command(int command, int 
 *output)
       return 0;
   }

  -/* sysfs type-c damage detection capability */ +static bool display_damage(char *buf, int *count, char *type, unsigned int dmg_status)

drivers/platform/x86/lenovo/thinkpad_acpi.c +16 -0
+{
+    unsigned char lid_status, base_status, port_status;
+    unsigned char loc_status, pos_status, panel_status;
+    bool damage_detected = false;
+    int i;
+
+    port_status = FIELD_GET(PORT_STATUS, dmg_status);
+    lid_status = FIELD_GET(LID_STATUS, dmg_status);
+    base_status = FIELD_GET(BASE_STATUS, dmg_status);
+    for (i = 0; i < NUM_PORTS; i++) {
+        if (!(dmg_status & BIT(i)))
+            continue;
+
+        if (port_status & BIT(i)) {
+            *count += sysfs_emit_at(buf, *count, "%s: ", type);
+            loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * 

i))) & 0xF;
+            pos_status = FIELD_GET(POS_STATUS, loc_status); +            panel_status = FIELD_GET(PANEL_STATUS, loc_status);

drivers/platform/x86/lenovo/thinkpad_acpi.c +21 -0
+
+            if (lid_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Lid, ");
+            if (base_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Base, ");
+
+            switch (pos_status) {
+            case PANEL_TOP:
+                *count += sysfs_emit_at(buf, *count, "Top, ");
+                break;
+            case PANEL_BASE:
+                *count += sysfs_emit_at(buf, *count, "Bottom, ");
+                break;
+            case PANEL_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left, ");
+                break;
+            case PANEL_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right, ");
+                break;
+            default:
+                pr_err("Unexpected value %d in switch statement\n", 

pos_status);
+            };

drivers/platform/x86/lenovo/thinkpad_acpi.c +34 -0
+
+            switch (panel_status) {
+            case POS_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left port\n");
+                break;
+            case POS_CENTER:
+                *count += sysfs_emit_at(buf, *count, "Center port\n");
+                break;
+            case POS_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right port\n");
+                break;
+            default:
+                *count += sysfs_emit_at(buf, *count, "Undefined\n");
+                break;
+            };
+            damage_detected = true;
+        }
+    }
+    return damage_detected;
+}
+
+/* sysfs type-c damage detection detail */
+static ssize_t hwdd_detail_show(struct device *dev,
+                struct device_attribute *attr,
+                char *buf)
+{
+    bool damage_detected = false;
+    unsigned int damage_status;
+    int err, count = 0;
+
+
+    if (ucdd_supported) {
+        /* Get USB TYPE-C damage status */
+        err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
Quoted 8 lines
Quoted 6 lines

+        if (err)
+            return err;
+
+        if (display_damage(buf, &count, "Type-C", damage_status)) +            damage_detected = true;
+    }

Since this is always visible aren't you missing a case for !ucdd_supported?  I would think you should be returning -ENODEV.

In actual, this condition should never occur as only USB Type-C is supported  in this ASL method but i think it's ok to add this check, if there is any benefit.

In this case, is it recommended to add such case like  !ucdd_supported?

Also, if new device id like type-a etc..  is added in future then we need to include corresponding device id supported also in this check to make sysfs visible.

Quoted 2 lines

Although arguably it would be better to control visibility of the sysfs attribute based upon ucdd_supported.  You can simplify hwdd_detail_show() too then.

If new device id is added in future then we need to add additional flag to control visibility of sysfs .

At this moment , i cant see anything obvious to be simplified in hwdd_detail_show() . Did i missed something ?

Quoted 25 lines
Quoted 22 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +8 -0
+
+    if (!damage_detected)
+        count += sysfs_emit_at(buf, count, "No damage detected\n");
+
+    return count;
+}
+
+/* sysfs typc damage detection capability */

  static ssize_t hwdd_status_show(struct device *dev, struct device_attribute *attr, char *buf)

drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -0
@@ -11134,9 +11238,11 @@ static ssize_t hwdd_status_show(struct 
 device *dev,
       return sysfs_emit(buf, "0\n");
   }
   static DEVICE_ATTR_RO(hwdd_status);
+static DEVICE_ATTR_RO(hwdd_detail);
     static struct attribute *hwdd_attributes[] = {
       &dev_attr_hwdd_status.attr,
+    &dev_attr_hwdd_detail.attr,
Quoted 2 lines

      NULL
  };

Thank you !

#4 lore raw

Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

Quoted 170 lines · Nitin

Hi Mario,

Thank you for your comments.

Quoted 152 lines · Mario Limonciello
Quoted 151 lines · Nitin Joshi

Add new sysfs interface to identify the impacted component with location of device.

---
  .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +- drivers/platform/x86/lenovo/thinkpad_acpi.c   | 112 +++++++++++++++++-

  2 files changed, 121 insertions(+), 4 deletions(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
index 94349e5f1298..3a9190ac47d0 100644
@@ -1580,7 +1580,7 @@ Documentation/ABI/testing/sysfs-class-power.

  Hardware damage detection capability
  -----------------
  -sysfs attributes: hwdd_status
+sysfs attributes: hwdd_status, hwdd_detail
    Thinkpads are adding the ability to detect and report hardware damage. Add new sysfs interface to identify the damaged device status.

Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
@@ -1594,6 +1594,17 @@ This value displays status of device damaged

  - 0 = Not Damaged
  - 1 = Damaged
  +The command to check location of damaged device is::

Documentation/admin-guide/laptops/thinkpad-acpi.rst +4 -0
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
+
+This value displays location of damaged device having 1 line per 

damaged "item".

Documentation/admin-guide/laptops/thinkpad-acpi.rst +6 -0
+For example:
+if no damage is detected:
+  No damage detected
+if damage detected:
+  TYPE-C: Base, Right side, Center port
+

  The property is read-only. If feature is not supported then sysfs
  attribute is not created.
  diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/ platform/x86/lenovo/thinkpad_acpi.c index 4cf365550bcb..a092d57d995d 100644

drivers/platform/x86/lenovo/thinkpad_acpi.c +18 -1
@@ -11089,8 +11089,24 @@ static const struct attribute_group 
 auxmac_attr_group = {
   #define HWDD_NOT_SUPPORTED    BIT(31)
   #define HWDD_SUPPORT_USBC    BIT(0)
   -#define PORT_STATUS        GENMASK(7, 4)
-#define NUM_PORTS        4
+#define PORT_STATUS     GENMASK(7, 4)
+#define LID_STATUS      GENMASK(11, 8)
+#define BASE_STATUS     GENMASK(15, 12)
+#define POS_STATUS      GENMASK(3, 2)
+#define PANEL_STATUS    GENMASK(1, 0)
+
+#define PORT_DETAIL_OFFSET    16
+
+#define PANEL_TOP    0
+#define PANEL_BASE    1
+#define PANEL_LEFT    2
+#define PANEL_RIGHT    3
+
+#define POS_LEFT    0
+#define POS_CENTER    1
+#define POS_RIGHT    2
+
+#define NUM_PORTS    4
     static bool hwdd_support_available;
   static bool ucdd_supported;
@@ -11108,7 +11124,95 @@ static int hwdd_command(int command, int 
 *output)
       return 0;
   }

  -/* sysfs type-c damage detection capability */ +static bool display_damage(char *buf, int *count, char *type, unsigned int dmg_status)

drivers/platform/x86/lenovo/thinkpad_acpi.c +16 -0
+{
+    unsigned char lid_status, base_status, port_status;
+    unsigned char loc_status, pos_status, panel_status;
+    bool damage_detected = false;
+    int i;
+
+    port_status = FIELD_GET(PORT_STATUS, dmg_status);
+    lid_status = FIELD_GET(LID_STATUS, dmg_status);
+    base_status = FIELD_GET(BASE_STATUS, dmg_status);
+    for (i = 0; i < NUM_PORTS; i++) {
+        if (!(dmg_status & BIT(i)))
+            continue;
+
+        if (port_status & BIT(i)) {
+            *count += sysfs_emit_at(buf, *count, "%s: ", type);
+            loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * 

i))) & 0xF;
+            pos_status = FIELD_GET(POS_STATUS, loc_status); +            panel_status = FIELD_GET(PANEL_STATUS, loc_status);

drivers/platform/x86/lenovo/thinkpad_acpi.c +21 -0
+
+            if (lid_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Lid, ");
+            if (base_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Base, ");
+
+            switch (pos_status) {
+            case PANEL_TOP:
+                *count += sysfs_emit_at(buf, *count, "Top, ");
+                break;
+            case PANEL_BASE:
+                *count += sysfs_emit_at(buf, *count, "Bottom, ");
+                break;
+            case PANEL_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left, ");
+                break;
+            case PANEL_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right, ");
+                break;
+            default:
+                pr_err("Unexpected value %d in switch statement\n", 

pos_status);
+            };

drivers/platform/x86/lenovo/thinkpad_acpi.c +34 -0
+
+            switch (panel_status) {
+            case POS_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left port\n");
+                break;
+            case POS_CENTER:
+                *count += sysfs_emit_at(buf, *count, "Center port\n");
+                break;
+            case POS_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right port\n");
+                break;
+            default:
+                *count += sysfs_emit_at(buf, *count, "Undefined\n");
+                break;
+            };
+            damage_detected = true;
+        }
+    }
+    return damage_detected;
+}
+
+/* sysfs type-c damage detection detail */
+static ssize_t hwdd_detail_show(struct device *dev,
+                struct device_attribute *attr,
+                char *buf)
+{
+    bool damage_detected = false;
+    unsigned int damage_status;
+    int err, count = 0;
+
+
+    if (ucdd_supported) {
+        /* Get USB TYPE-C damage status */
+        err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
Quoted 8 lines
Quoted 6 lines

+        if (err)
+            return err;
+
+        if (display_damage(buf, &count, "Type-C", damage_status)) +            damage_detected = true;
+    }

Since this is always visible aren't you missing a case for ! ucdd_supported?  I would think you should be returning -ENODEV.

In actual, this condition should never occur as only USB Type-C is supported  in this ASL method but i think it's ok to add this check, if there is any benefit.

In this case, is it recommended to add such case like  !ucdd_supported?

Quoted 8 lines

Also, if new device id like type-a etc..  is added in future then we need to include corresponding device id supported also in this check to make sysfs visible.

Quoted 2 lines

Although arguably it would be better to control visibility of the sysfs attribute based upon ucdd_supported.  You can simplify hwdd_detail_show() too then.

If new device id is added in future then we need to add additional flag to control visibility of sysfs .

At this moment , i cant see anything obvious to be simplified in hwdd_detail_show() . Did i missed something ?

Well my comment was specifically upon visibility. If you avoid attribute being visible conditional on ucdd_supported, you don't need to actually check this in *_show().

Quoted 26 lines
Quoted 26 lines
Quoted 23 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +8 -0
+
+    if (!damage_detected)
+        count += sysfs_emit_at(buf, count, "No damage detected\n");
+
+    return count;
+}
+
+/* sysfs typc damage detection capability */

  static ssize_t hwdd_status_show(struct device *dev, struct device_attribute *attr, char *buf)

drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -0
@@ -11134,9 +11238,11 @@ static ssize_t hwdd_status_show(struct 
 device *dev,
       return sysfs_emit(buf, "0\n");
   }
   static DEVICE_ATTR_RO(hwdd_status);
+static DEVICE_ATTR_RO(hwdd_detail);
     static struct attribute *hwdd_attributes[] = {
       &dev_attr_hwdd_status.attr,
+    &dev_attr_hwdd_detail.attr,
Quoted 2 lines

      NULL
  };

Thank you !

author
#5 lore raw

Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

Quoted 176 lines · Mario Limonciello
Quoted 175 lines · Nitin

Hi Mario,

Thank you for your comments.

Quoted 154 lines · Mario Limonciello
Quoted 153 lines · Nitin Joshi

Add new sysfs interface to identify the impacted component with location of device.

---
  .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +- drivers/platform/x86/lenovo/thinkpad_acpi.c   | 112
+++++++++++++++++-

  2 files changed, 121 insertions(+), 4 deletions(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
index 94349e5f1298..3a9190ac47d0 100644
@@ -1580,7 +1580,7 @@ Documentation/ABI/testing/sysfs-class-power.

  Hardware damage detection capability
  -----------------
  -sysfs attributes: hwdd_status
+sysfs attributes: hwdd_status, hwdd_detail
    Thinkpads are adding the ability to detect and report hardware damage. Add new sysfs interface to identify the damaged device status.

Documentation/admin-guide/laptops/thinkpad-acpi.rst +0 -0
@@ -1594,6 +1594,17 @@ This value displays status of device damaged

  - 0 = Not Damaged
  - 1 = Damaged
  +The command to check location of damaged device is::

Documentation/admin-guide/laptops/thinkpad-acpi.rst +4 -0
+
+        cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
+
+This value displays location of damaged device having 1 line per 

damaged "item".

Documentation/admin-guide/laptops/thinkpad-acpi.rst +6 -0
+For example:
+if no damage is detected:
+  No damage detected
+if damage detected:
+  TYPE-C: Base, Right side, Center port
+

  The property is read-only. If feature is not supported then sysfs
  attribute is not created.
  diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/ platform/x86/lenovo/thinkpad_acpi.c index 4cf365550bcb..a092d57d995d 100644

drivers/platform/x86/lenovo/thinkpad_acpi.c +18 -1
@@ -11089,8 +11089,24 @@ static const struct attribute_group 
 auxmac_attr_group = {
   #define HWDD_NOT_SUPPORTED    BIT(31)
   #define HWDD_SUPPORT_USBC    BIT(0)
   -#define PORT_STATUS        GENMASK(7, 4)
-#define NUM_PORTS        4
+#define PORT_STATUS     GENMASK(7, 4)
+#define LID_STATUS      GENMASK(11, 8)
+#define BASE_STATUS     GENMASK(15, 12)
+#define POS_STATUS      GENMASK(3, 2)
+#define PANEL_STATUS    GENMASK(1, 0)
+
+#define PORT_DETAIL_OFFSET    16
+
+#define PANEL_TOP    0
+#define PANEL_BASE    1
+#define PANEL_LEFT    2
+#define PANEL_RIGHT    3
+
+#define POS_LEFT    0
+#define POS_CENTER    1
+#define POS_RIGHT    2
+
+#define NUM_PORTS    4
     static bool hwdd_support_available;
   static bool ucdd_supported;
@@ -11108,7 +11124,95 @@ static int hwdd_command(int command, int 
 *output)
       return 0;
   }

  -/* sysfs type-c damage detection capability */ +static bool display_damage(char *buf, int *count, char *type, unsigned int dmg_status)

drivers/platform/x86/lenovo/thinkpad_acpi.c +16 -0
+{
+    unsigned char lid_status, base_status, port_status;
+    unsigned char loc_status, pos_status, panel_status;
+    bool damage_detected = false;
+    int i;
+
+    port_status = FIELD_GET(PORT_STATUS, dmg_status);
+    lid_status = FIELD_GET(LID_STATUS, dmg_status);
+    base_status = FIELD_GET(BASE_STATUS, dmg_status);
+    for (i = 0; i < NUM_PORTS; i++) {
+        if (!(dmg_status & BIT(i)))
+            continue;
+
+        if (port_status & BIT(i)) {
+            *count += sysfs_emit_at(buf, *count, "%s: ", type);
+            loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * 

i))) & 0xF;
+            pos_status = FIELD_GET(POS_STATUS, loc_status); +            panel_status = FIELD_GET(PANEL_STATUS, loc_status);

drivers/platform/x86/lenovo/thinkpad_acpi.c +21 -0
+
+            if (lid_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Lid, ");
+            if (base_status & BIT(i))
+                *count += sysfs_emit_at(buf, *count, "Base, ");
+
+            switch (pos_status) {
+            case PANEL_TOP:
+                *count += sysfs_emit_at(buf, *count, "Top, ");
+                break;
+            case PANEL_BASE:
+                *count += sysfs_emit_at(buf, *count, "Bottom, ");
+                break;
+            case PANEL_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left, ");
+                break;
+            case PANEL_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right, ");
+                break;
+            default:
+                pr_err("Unexpected value %d in switch 

statement\n", pos_status);
+            };
+
+            switch (panel_status) {
+            case POS_LEFT:
+                *count += sysfs_emit_at(buf, *count, "Left port\n"); +                break;
+            case POS_CENTER:
+                *count += sysfs_emit_at(buf, *count, "Center port\n");
+                break;
+            case POS_RIGHT:
+                *count += sysfs_emit_at(buf, *count, "Right port\n"); +                break;
+            default:
+                *count += sysfs_emit_at(buf, *count, "Undefined\n"); +                break;
+            };
+            damage_detected = true;
+        }
+    }
+    return damage_detected;

drivers/platform/x86/lenovo/thinkpad_acpi.c +15 -0
+}
+
+/* sysfs type-c damage detection detail */
+static ssize_t hwdd_detail_show(struct device *dev,
+                struct device_attribute *attr,
+                char *buf)
+{
+    bool damage_detected = false;
+    unsigned int damage_status;
+    int err, count = 0;
+
+
+    if (ucdd_supported) {
+        /* Get USB TYPE-C damage status */
+        err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
Quoted 8 lines
Quoted 6 lines

+        if (err)
+            return err;
+
+        if (display_damage(buf, &count, "Type-C", damage_status)) +            damage_detected = true;
+    }

Since this is always visible aren't you missing a case for ! ucdd_supported?  I would think you should be returning -ENODEV.

In actual, this condition should never occur as only USB Type-C is supported  in this ASL method but i think it's ok to add this check, if there is any benefit.

In this case, is it recommended to add such case like  !ucdd_supported?

Also, if new device id like type-a etc..  is added in future then we need to include corresponding device id supported also in this check to make sysfs visible.

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Although arguably it would be better to control visibility of the sysfs attribute based upon ucdd_supported.  You can simplify hwdd_detail_show() too then.

If new device id is added in future then we need to add additional flag to control visibility of sysfs .

At this moment , i cant see anything obvious to be simplified in hwdd_detail_show() . Did i missed something ?

Well my comment was specifically upon visibility. If you avoid attribute being visible conditional on ucdd_supported, you don't need to actually check this in *_show().

Ack !

 I will include case for !ucdd_supported in next version. Thank you !

Quoted 27 lines
Quoted 26 lines
Quoted 26 lines
Quoted 23 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +8 -0
+
+    if (!damage_detected)
+        count += sysfs_emit_at(buf, count, "No damage detected\n");
+
+    return count;
+}
+
+/* sysfs typc damage detection capability */

  static ssize_t hwdd_status_show(struct device *dev, struct device_attribute *attr, char *buf)

drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -0
@@ -11134,9 +11238,11 @@ static ssize_t hwdd_status_show(struct 
 device *dev,
       return sysfs_emit(buf, "0\n");
   }
   static DEVICE_ATTR_RO(hwdd_status);
+static DEVICE_ATTR_RO(hwdd_detail);
     static struct attribute *hwdd_attributes[] = {
       &dev_attr_hwdd_status.attr,
+    &dev_attr_hwdd_detail.attr,
Quoted 2 lines

      NULL
  };

Thank you !

#7 lore raw
In reply to Nitin Joshi
kernel test robot noticed the following build warnings:

Hi Nitin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc1 next-20251215]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nitin-Joshi/platform-x86-thinkpad_acpi-Add-sysfs-to-display-details-of-damaged-device/20251210-231409
base:   linus/master
patch link:    https://lore.kernel.org/r/20251210151133.7933-1-nitjoshi%40gmail.com
patch subject: [PATCH v2 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
reproduce: (https://download.01.org/0day-ci/archive/20251216/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

WARNING: No kernel-doc for file ./include/linux/pci.h
ERROR: Cannot find file ./include/linux/mod_devicetable.h
WARNING: No kernel-doc for file ./include/linux/mod_devicetable.h
ERROR: Cannot find file ./include/linux/bootconfig.h
WARNING: No kernel-doc for file ./include/linux/bootconfig.h

>> Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.
--
   Hardware damage detection capability
   ----------------- [docutils]
>> Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

vim +1581 Documentation/admin-guide/laptops/thinkpad-acpi.rst

1579
1580 Hardware damage detection capability

> 1581	-----------------

1582

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#8 lore raw

Hello ,

Quoted 16 lines · kernel test robot

Hi Nitin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc1 next-20251215]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nitin-Joshi/platform-x86-thinkpad_acpi-Add-sysfs-to-display-details-of-damaged-device/20251210-231409
base:   linus/master
patch link:    https://lore.kernel.org/r/20251210151133.7933-1-nitjoshi%40gmail.com
patch subject: [PATCH v2 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
reproduce: (https://download.01.org/0day-ci/archive/20251216/[email protected]/reproduce)
Quoted 4 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Thank you for reporting this issue and I will fix this issue .

I have already send patch v3 for this and will fix this warning in next patch version i.e v4 .

May i know, if its OK to add this Reported-by and closes tag in patch version v4 ?

Quoted 8 lines

All warnings (new ones prefixed by >>):

WARNING: No kernel-doc for file ./include/linux/pci.h
ERROR: Cannot find file ./include/linux/mod_devicetable.h
WARNING: No kernel-doc for file ./include/linux/mod_devicetable.h
ERROR: Cannot find file ./include/linux/bootconfig.h
WARNING: No kernel-doc for file ./include/linux/bootconfig.h

Quoted 5 lines
Quoted 1 line
Quoted 1 line

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

--
Hardware damage detection capability
----------------- [docutils]

Quoted 1 line
Quoted 1 line

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

Ack. Thank you !

Quoted 8 lines

vim +1581 Documentation/admin-guide/laptops/thinkpad-acpi.rst

1579
1580 Hardware damage detection capability

Quoted 1 line

1581 -----------------

1582

#6 lore raw

Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.

In reply to Nitin Joshi
kernel test robot noticed the following build warnings:

Hi Nitin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc1 next-20251216]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nitin-Joshi/platform-x86-thinkpad_acpi-Add-sysfs-to-display-details-of-damaged-device/20251210-231409
base:   linus/master
patch link:    https://lore.kernel.org/r/20251210151133.7933-2-nitjoshi%40gmail.com
patch subject: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
reproduce: (https://download.01.org/0day-ci/archive/20251216/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

Hardware damage detection capability
----------------- [docutils] Documentation/admin-guide/laptops/thinkpad-acpi.rst:1604: ERROR: Unexpected indentation. [docutils]

>> Documentation/admin-guide/laptops/thinkpad-acpi.rst:1605: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]

ERROR: Cannot find file ./include/linux/pstore_zone.h
ERROR: Cannot find file ./include/linux/pstore_zone.h
WARNING: No kernel-doc for file ./include/linux/pstore_zone.h
ERROR: Cannot find file ./include/linux/pstore_blk.h
ERROR: Cannot find file ./include/linux/pstore_blk.h

vim +1605 Documentation/admin-guide/laptops/thinkpad-acpi.rst

1598
1599 cat /sys/devices/platform/thinkpad_acpi/hwdd_detail
1600
1601 This value displays location of damaged device having 1 line per damaged "item".
1602 For example:
1603 if no damage is detected:
1604 No damage detected

> 1605	if damage detected:

1606 TYPE-C: Base, Right side, Center port
1607

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#9 lore raw
In reply to Nitin
Quoted 30 lines · Nitin

Hello ,

Quoted 20 lines · kernel test robot

Hi Nitin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc1 next-20251215]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Nitin-Joshi/platform-x86-thinkpad_acpi-Add-sysfs-to-display-details-of-damaged-device/20251210-231409
base: linus/master
patch link:
https://lore.kernel.org/r/20251210151133.7933-1-nitjoshi%40gmail.com
patch subject: [PATCH v2 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
reproduce:
(https://download.01.org/0day-ci/archive/20251216/[email protected]/reproduce)

Quoted 6 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 7 lines

Thank you for reporting this issue and I will fix this issue .

I have already send patch v3 for this and will fix this warning in next patch version i.e v4 .

May i know, if its OK to add this Reported-by and closes tag in patch version v4 ?

Hi,

Please only add those tags when you're fixing code that exists in a repo already. For new work, we don't normally add lkp report tags despite the email suggesting you to do so (I know it's a bit confusing but it's sort of same as we don't normally mention all reviewers who gave improvement suggestions either).

Quoted 26 lines
Quoted 7 lines

All warnings (new ones prefixed by >>):

WARNING: No kernel-doc for file ./include/linux/pci.h
ERROR: Cannot find file ./include/linux/mod_devicetable.h
WARNING: No kernel-doc for file ./include/linux/mod_devicetable.h
ERROR: Cannot find file ./include/linux/bootconfig.h
WARNING: No kernel-doc for file ./include/linux/bootconfig.h

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

--
Hardware damage detection capability
----------------- [docutils]

Quoted 2 lines
Quoted 2 lines

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

Ack. Thank you !

Quoted 8 lines

vim +1581 Documentation/admin-guide/laptops/thinkpad-acpi.rst

1579
1580 Hardware damage detection capability

Quoted 1 line

1581 -----------------

1582

Signature · 1 line
 i.
author
#10 lore raw
Quoted 38 lines · Ilpo Järvinen
Quoted 29 lines · Nitin

Hello ,

Quoted 20 lines · kernel test robot

Hi Nitin,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc1 next-20251215]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Nitin-Joshi/platform-x86-thinkpad_acpi-Add-sysfs-to-display-details-of-damaged-device/20251210-231409
base: linus/master
patch link:
https://lore.kernel.org/r/20251210151133.7933-1-nitjoshi%40gmail.com
patch subject: [PATCH v2 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
reproduce:
(https://download.01.org/0day-ci/archive/20251216/[email protected]/reproduce)

Quoted 6 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 7 lines

Thank you for reporting this issue and I will fix this issue .

I have already send patch v3 for this and will fix this warning in next patch version i.e v4 .

May i know, if its OK to add this Reported-by and closes tag in patch version v4 ?

Quoted 7 lines

Hi,

Please only add those tags when you're fixing code that exists in a repo already. For new work, we don't normally add lkp report tags despite the email suggesting you to do so (I know it's a bit confusing but it's sort of same as we don't normally mention all reviewers who gave improvement suggestions either).

Noted, Thank you for clarification . I will send next patch revision soon.

Thank you !

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines

All warnings (new ones prefixed by >>):

WARNING: No kernel-doc for file ./include/linux/pci.h
ERROR: Cannot find file ./include/linux/mod_devicetable.h
WARNING: No kernel-doc for file ./include/linux/mod_devicetable.h
ERROR: Cannot find file ./include/linux/bootconfig.h
WARNING: No kernel-doc for file ./include/linux/bootconfig.h

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

--
Hardware damage detection capability
----------------- [docutils]

Quoted 2 lines
Quoted 2 lines

Documentation/admin-guide/laptops/thinkpad-acpi.rst:1581: WARNING: Title underline too short.

Ack. Thank you !

Quoted 7 lines

vim +1581 Documentation/admin-guide/laptops/thinkpad-acpi.rst

1579
1580 Hardware damage detection capability

Quoted 1 line

1581 -----------------

    1582