* [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
@ 2026-01-06 17:45 Nitin Joshi
2026-01-06 17:45 ` [PATCH v7 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device Nitin Joshi
2026-01-12 15:34 ` [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Ilpo Järvinen
0 siblings, 2 replies; 3+ messages in thread
From: Nitin Joshi @ 2026-01-06 17:45 UTC (permalink / raw)
To: hansg, ilpo.jarvinen
Cc: platform-driver-x86, linux-kernel, njoshi1, Nitin Joshi,
Mark Pearson
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.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Nitin Joshi<nitjoshi@gmail.com>
---
Changes since v1:
-Split patch between hwdd_status and hwdd_detail
-Incorporated review comments
Changes since v2:
-Control visibility of the sysfs attribute based upon ucdd_supported
Changes since v3:
-Fix documentation build warning
Changes since v4:
-Removed extra line
Changes since v5:
-Improved code indentation
Changes since v6:
- Improved formatting for htmldocs
---
.../admin-guide/laptops/thinkpad-acpi.rst | 22 ++++
drivers/platform/x86/lenovo/thinkpad_acpi.c | 105 ++++++++++++++++++
2 files changed, 127 insertions(+)
diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
index 4ab0fef7d440..2f910ff31b37 100644
--- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst
+++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
@@ -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,27 @@ 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
------------------------------------
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index cc19fe520ea9..3702374357ab 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -11080,6 +11080,106 @@ static const struct attribute_group auxmac_attr_group = {
.attrs = auxmac_attributes,
};
+/*************************************************************************
+ * HWDD subdriver, for the Lenovo Hardware Damage Detection feature.
+ */
+
+#define HWDD_GET_DMG_USBC 0x80000001
+#define HWDD_GET_CAP 0
+#define HWDD_NOT_SUPPORTED BIT(31)
+#define HWDD_SUPPORT_USBC BIT(0)
+
+#define PORT_STATUS GENMASK(7, 4)
+#define NUM_PORTS 4
+
+static bool hwdd_support_available;
+static bool ucdd_supported;
+
+static int hwdd_command(int command, int *output)
+{
+ acpi_handle hwdd_handle;
+
+ if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "HWDD", &hwdd_handle)))
+ return -ENODEV;
+
+ if (!acpi_evalf(hwdd_handle, output, NULL, "dd", command))
+ return -EIO;
+
+ return 0;
+}
+
+/* sysfs type-c damage detection capability */
+static ssize_t hwdd_status_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ unsigned int damage_status, port_status;
+ int err, i;
+
+ if (!ucdd_supported)
+ return -ENODEV;
+
+ /* Get USB TYPE-C damage status */
+ err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
+ if (err)
+ return err;
+
+ port_status = FIELD_GET(PORT_STATUS, damage_status);
+ for (i = 0; i < NUM_PORTS; i++) {
+ if (!(damage_status & BIT(i)))
+ continue;
+ if (port_status & BIT(i))
+ return sysfs_emit(buf, "1\n");
+ }
+
+ return sysfs_emit(buf, "0\n");
+}
+static DEVICE_ATTR_RO(hwdd_status);
+
+static struct attribute *hwdd_attributes[] = {
+ &dev_attr_hwdd_status.attr,
+ NULL
+};
+
+static umode_t hwdd_attr_is_visible(struct kobject *kobj,
+ struct attribute *attr, int n)
+{
+ return hwdd_support_available ? attr->mode : 0;
+}
+
+static const struct attribute_group hwdd_attr_group = {
+ .is_visible = hwdd_attr_is_visible,
+ .attrs = hwdd_attributes,
+};
+
+static int tpacpi_hwdd_init(struct ibm_init_struct *iibm)
+{
+ int err, output;
+
+ /* Below command checks the HWDD damage capability */
+ err = hwdd_command(HWDD_GET_CAP, &output);
+ if (err)
+ return err;
+
+ if (!(output & HWDD_NOT_SUPPORTED))
+ return -ENODEV;
+
+ hwdd_support_available = true;
+
+ /*
+ * BIT(0) is assigned to check capability of damage detection is
+ * supported for USB Type-C port or not.
+ */
+ if (output & HWDD_SUPPORT_USBC)
+ ucdd_supported = true;
+
+ return err;
+}
+
+static struct ibm_struct hwdd_driver_data = {
+ .name = "hwdd",
+};
+
/* --------------------------------------------------------------------- */
static struct attribute *tpacpi_driver_attributes[] = {
@@ -11139,6 +11239,7 @@ static const struct attribute_group *tpacpi_groups[] = {
&kbdlang_attr_group,
&dprc_attr_group,
&auxmac_attr_group,
+ &hwdd_attr_group,
NULL,
};
@@ -11752,6 +11853,10 @@ static struct ibm_init_struct ibms_init[] __initdata = {
.init = auxmac_init,
.data = &auxmac_data,
},
+ {
+ .init = tpacpi_hwdd_init,
+ .data = &hwdd_driver_data,
+ },
};
static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v7 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
2026-01-06 17:45 [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Nitin Joshi
@ 2026-01-06 17:45 ` Nitin Joshi
2026-01-12 15:34 ` [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Ilpo Järvinen
1 sibling, 0 replies; 3+ messages in thread
From: Nitin Joshi @ 2026-01-06 17:45 UTC (permalink / raw)
To: hansg, ilpo.jarvinen
Cc: platform-driver-x86, linux-kernel, njoshi1, Nitin Joshi,
Mark Pearson
Add new sysfs interface to identify the impacted component with location of
device.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Nitin Joshi<nitjoshi@gmail.com>
---
Changes since v2:
-Control visibility of the sysfs attribute based upon ucdd_supported
Changes since v3:
-Fix documentation build warning
Changes since v4:
-Improved indentation and removed extra line
Changes since v5:
-Improved indentation
Changes since v6:
- Improved formatting for htmldocs
---
.../admin-guide/laptops/thinkpad-acpi.rst | 17 ++-
drivers/platform/x86/lenovo/thinkpad_acpi.c | 104 +++++++++++++++++-
2 files changed, 118 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
index 2f910ff31b37..03951ed6b628 100644
--- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst
+++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
@@ -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.
@@ -1595,6 +1595,21 @@ 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.
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 3702374357ab..95755fa1e008 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -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,6 +11124,88 @@ static int hwdd_command(int command, int *output)
return 0;
}
+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)) || !(port_status & BIT(i)))
+ continue;
+
+ *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)
+{
+ unsigned int damage_status;
+ int err, count = 0;
+
+ if (!ucdd_supported)
+ return -ENODEV;
+
+ /* 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))
+ count += sysfs_emit_at(buf, count, "No damage detected\n");
+
+ return count;
+}
+
/* sysfs type-c damage detection capability */
static ssize_t hwdd_status_show(struct device *dev,
struct device_attribute *attr,
@@ -11135,9 +11233,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
};
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
2026-01-06 17:45 [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Nitin Joshi
2026-01-06 17:45 ` [PATCH v7 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device Nitin Joshi
@ 2026-01-12 15:34 ` Ilpo Järvinen
1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2026-01-12 15:34 UTC (permalink / raw)
To: hansg, Nitin Joshi
Cc: platform-driver-x86, linux-kernel, njoshi1, Mark Pearson
On Wed, 07 Jan 2026 02:45:18 +0900, Nitin Joshi wrote:
> 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.
>
>
> [...]
Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.
The list of commits applied:
[1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
commit: f4afc36985365f2926fe5beaefbb99b97061378d
[2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
commit: c333c896ca30a1bfbd32927e3642e45f4d3cf0ac
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-12 15:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-06 17:45 [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Nitin Joshi
2026-01-06 17:45 ` [PATCH v7 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device Nitin Joshi
2026-01-12 15:34 ` [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox