[PATCH v2] platform/x86: thinkpad_acpi: Add debugfs entry to display HWDD raw

Mark Pearson posted 1 patch 1 month, 2 weeks ago
drivers/platform/x86/lenovo/thinkpad_acpi.c | 39 +++++++++++++++++++++
1 file changed, 39 insertions(+)
[PATCH v2] platform/x86: thinkpad_acpi: Add debugfs entry to display HWDD raw
Posted by Mark Pearson 1 month, 2 weeks ago
The Lenovo diagnostics and support team have requested a mechanism
to get the raw data from the HWDD commands to support customer debug
situations.

Add a debugfs entry to display the HWDD raw data.

Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 39 +++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index e1cee42a1683..dd3e206a1295 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -38,6 +38,7 @@
 #include <linux/backlight.h>
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/freezer.h>
@@ -11217,6 +11218,26 @@ static ssize_t hwdd_status_show(struct device *dev,
 
 	return sysfs_emit(buf, "0\n");
 }
+
+/* sysfs type-c damage detection raw data - accessed via debugfs*/
+static int hwdd_raw_show(struct seq_file *m, void *v)
+{
+	unsigned int damage_status;
+	int err;
+
+	if (!ucdd_supported)
+		return -ENODEV;
+
+	/* Get USB TYPE-C damage status */
+	err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
+	if (err)
+		return err;
+
+	seq_printf(m, "HWDD: 0x%x\n", damage_status);
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(hwdd_raw);
+
 static DEVICE_ATTR_RO(hwdd_status);
 static DEVICE_ATTR_RO(hwdd_detail);
 
@@ -11504,6 +11525,20 @@ static const char * __init str_supported(int is_supported)
 }
 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
 
+static struct dentry *tpacpi_dbg;
+static void tpacpi_debugfs_init(void)
+{
+	tpacpi_dbg = debugfs_create_dir("tpacpi", NULL);
+
+	/* HWDD raw data */
+	debugfs_create_file("hwdd-raw", 0444, tpacpi_dbg, NULL, &hwdd_raw_fops);
+}
+
+static void tpacpi_debugfs_remove(void)
+{
+	debugfs_remove_recursive(tpacpi_dbg);
+}
+
 static void ibm_exit(struct ibm_struct *ibm)
 {
 	dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
@@ -12068,6 +12103,8 @@ static void thinkpad_acpi_module_exit(void)
 		remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
 	if (tpacpi_wq)
 		destroy_workqueue(tpacpi_wq);
+	if (tpacpi_dbg)
+		tpacpi_debugfs_remove();
 
 	kfree(thinkpad_id.bios_version_str);
 	kfree(thinkpad_id.ec_version_str);
@@ -12198,6 +12235,8 @@ static int __init thinkpad_acpi_module_init(void)
 		return -ENODEV;
 	}
 
+	tpacpi_debugfs_init();
+
 	dmi_id = dmi_first_match(fwbug_list);
 	if (dmi_id)
 		tp_features.quirks = dmi_id->driver_data;
-- 
2.43.0
Re: [PATCH v2] platform/x86: thinkpad_acpi: Add debugfs entry to display HWDD raw
Posted by Ilpo Järvinen 1 month ago
On Tue, 28 Apr 2026 21:51:59 -0400, Mark Pearson wrote:

> The Lenovo diagnostics and support team have requested a mechanism
> to get the raw data from the HWDD commands to support customer debug
> situations.
> 
> Add a debugfs entry to display the HWDD raw data.
> 
> 
> [...]


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/1] platform/x86: thinkpad_acpi: Add debugfs entry to display HWDD raw
      commit: 165e81354eefd5551358112773f24027aac59d5a

--
 i.
Re: [PATCH v2] platform/x86: thinkpad_acpi: Add debugfs entry to display HWDD raw
Posted by Mark Pearson 1 month, 2 weeks ago
On Tue, Apr 28, 2026, at 9:51 PM, Mark Pearson wrote:
> The Lenovo diagnostics and support team have requested a mechanism
> to get the raw data from the HWDD commands to support customer debug
> situations.
>
> Add a debugfs entry to display the HWDD raw data.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---

Apologies - in doing a minor final clean up I missed adding the changes to the entry notes :(
Let me know if I should resend the patch - but otherwise it was:

Changes in v2: Changed from sysfs entry with module parameter to using debugfs.

>  drivers/platform/x86/lenovo/thinkpad_acpi.c | 39 +++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c 
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index e1cee42a1683..dd3e206a1295 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -38,6 +38,7 @@
>  #include <linux/backlight.h>
>  #include <linux/bitfield.h>
>  #include <linux/bitops.h>
> +#include <linux/debugfs.h>
>  #include <linux/delay.h>
>  #include <linux/dmi.h>
>  #include <linux/freezer.h>
> @@ -11217,6 +11218,26 @@ static ssize_t hwdd_status_show(struct device 
> *dev,
> 
>  	return sysfs_emit(buf, "0\n");
>  }
> +
> +/* sysfs type-c damage detection raw data - accessed via debugfs*/
> +static int hwdd_raw_show(struct seq_file *m, void *v)
> +{
> +	unsigned int damage_status;
> +	int err;
> +
> +	if (!ucdd_supported)
> +		return -ENODEV;
> +
> +	/* Get USB TYPE-C damage status */
> +	err = hwdd_command(HWDD_GET_DMG_USBC, &damage_status);
> +	if (err)
> +		return err;
> +
> +	seq_printf(m, "HWDD: 0x%x\n", damage_status);
> +	return 0;
> +}
> +DEFINE_SHOW_ATTRIBUTE(hwdd_raw);
> +
>  static DEVICE_ATTR_RO(hwdd_status);
>  static DEVICE_ATTR_RO(hwdd_detail);
> 
> @@ -11504,6 +11525,20 @@ static const char * __init str_supported(int 
> is_supported)
>  }
>  #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
> 
> +static struct dentry *tpacpi_dbg;
> +static void tpacpi_debugfs_init(void)
> +{
> +	tpacpi_dbg = debugfs_create_dir("tpacpi", NULL);
> +
> +	/* HWDD raw data */
> +	debugfs_create_file("hwdd-raw", 0444, tpacpi_dbg, NULL, &hwdd_raw_fops);
> +}
> +
> +static void tpacpi_debugfs_remove(void)
> +{
> +	debugfs_remove_recursive(tpacpi_dbg);
> +}
> +
>  static void ibm_exit(struct ibm_struct *ibm)
>  {
>  	dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
> @@ -12068,6 +12103,8 @@ static void thinkpad_acpi_module_exit(void)
>  		remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
>  	if (tpacpi_wq)
>  		destroy_workqueue(tpacpi_wq);
> +	if (tpacpi_dbg)
> +		tpacpi_debugfs_remove();
> 
>  	kfree(thinkpad_id.bios_version_str);
>  	kfree(thinkpad_id.ec_version_str);
> @@ -12198,6 +12235,8 @@ static int __init thinkpad_acpi_module_init(void)
>  		return -ENODEV;
>  	}
> 
> +	tpacpi_debugfs_init();
> +
>  	dmi_id = dmi_first_match(fwbug_list);
>  	if (dmi_id)
>  		tp_features.quirks = dmi_id->driver_data;
> -- 
> 2.43.0