public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw
@ 2026-04-28 12:53 Mark Pearson
  2026-04-28 13:00 ` Ilpo Järvinen
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Pearson @ 2026-04-28 12:53 UTC (permalink / raw)
  To: mpearson-lenovo
  Cc: hansg, ilpo.jarvinen, platform-driver-x86, ibm-acpi-devel,
	linux-kernel

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 sysfs entry to display the raw data.

As it shouldn't be needed in normal operation, add a hwdd_raw_enable
module parameter for when it is needed

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

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index e1cee42a1683..299cc4022e96 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -406,6 +406,7 @@ static enum {
 
 static int experimental;
 static u32 dbg_level;
+static bool hwdd_raw_enable;
 
 static struct workqueue_struct *tpacpi_wq;
 
@@ -11217,18 +11218,44 @@ static ssize_t hwdd_status_show(struct device *dev,
 
 	return sysfs_emit(buf, "0\n");
 }
+
+/* sysfs type-c damage detection raw data */
+static ssize_t hwdd_raw_show(struct device *dev,
+			     struct device_attribute *attr,
+			     char *buf)
+{
+	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;
+
+	return sysfs_emit(buf, "0x%x\n", damage_status);
+}
+
+static DEVICE_ATTR_RO(hwdd_raw);
 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,
+	&dev_attr_hwdd_raw.attr,
 	NULL
 };
 
 static umode_t hwdd_attr_is_visible(struct kobject *kobj,
 				struct attribute *attr, int n)
 {
+	/* Only display hwdd_raw if debug option has been set */
+	if (attr == &dev_attr_hwdd_raw.attr && !hwdd_raw_enable)
+		return 0;
+
 	return hwdd_support_available ? attr->mode : 0;
 }
 
@@ -11956,6 +11983,10 @@ static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
 	return -EINVAL;
 }
 
+module_param(hwdd_raw_enable, bool, 0444);
+MODULE_PARM_DESC(hwdd_raw_enable,
+		 "Enables hwdd raw output sysfs interface");
+
 module_param(experimental, int, 0444);
 MODULE_PARM_DESC(experimental,
 		 "Enables experimental features when non-zero");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw
  2026-04-28 12:53 [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw Mark Pearson
@ 2026-04-28 13:00 ` Ilpo Järvinen
  2026-04-28 13:15   ` Mark Pearson
  0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2026-04-28 13:00 UTC (permalink / raw)
  To: Mark Pearson; +Cc: Hans de Goede, platform-driver-x86, ibm-acpi-devel, LKML

On Tue, 28 Apr 2026, 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 sysfs entry to display the raw data.
> 
> As it shouldn't be needed in normal operation, add a hwdd_raw_enable
> module parameter for when it is needed

Wouldn't debugfs be more appropriate for things like this? By using it, 
you can avoid adding the module parameter as well.

-- 
 i.

> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
>  drivers/platform/x86/lenovo/thinkpad_acpi.c | 31 +++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index e1cee42a1683..299cc4022e96 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -406,6 +406,7 @@ static enum {
>  
>  static int experimental;
>  static u32 dbg_level;
> +static bool hwdd_raw_enable;
>  
>  static struct workqueue_struct *tpacpi_wq;
>  
> @@ -11217,18 +11218,44 @@ static ssize_t hwdd_status_show(struct device *dev,
>  
>  	return sysfs_emit(buf, "0\n");
>  }
> +
> +/* sysfs type-c damage detection raw data */
> +static ssize_t hwdd_raw_show(struct device *dev,
> +			     struct device_attribute *attr,
> +			     char *buf)
> +{
> +	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;
> +
> +	return sysfs_emit(buf, "0x%x\n", damage_status);
> +}
> +
> +static DEVICE_ATTR_RO(hwdd_raw);
>  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,
> +	&dev_attr_hwdd_raw.attr,
>  	NULL
>  };
>  
>  static umode_t hwdd_attr_is_visible(struct kobject *kobj,
>  				struct attribute *attr, int n)
>  {
> +	/* Only display hwdd_raw if debug option has been set */
> +	if (attr == &dev_attr_hwdd_raw.attr && !hwdd_raw_enable)
> +		return 0;
> +
>  	return hwdd_support_available ? attr->mode : 0;
>  }
>  
> @@ -11956,6 +11983,10 @@ static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
>  	return -EINVAL;
>  }
>  
> +module_param(hwdd_raw_enable, bool, 0444);
> +MODULE_PARM_DESC(hwdd_raw_enable,
> +		 "Enables hwdd raw output sysfs interface");
> +
>  module_param(experimental, int, 0444);
>  MODULE_PARM_DESC(experimental,
>  		 "Enables experimental features when non-zero");
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw
  2026-04-28 13:00 ` Ilpo Järvinen
@ 2026-04-28 13:15   ` Mark Pearson
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Pearson @ 2026-04-28 13:15 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Hans de Goede, platform-driver-x86@vger.kernel.org,
	ibm-acpi-devel, LKML

On Tue, Apr 28, 2026, at 9:00 AM, Ilpo Järvinen wrote:
> On Tue, 28 Apr 2026, 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 sysfs entry to display the raw data.
>> 
>> As it shouldn't be needed in normal operation, add a hwdd_raw_enable
>> module parameter for when it is needed
>
> Wouldn't debugfs be more appropriate for things like this? By using it, 
> you can avoid adding the module parameter as well.
>
Yeah - you're right. I was thinking of what we did on think-lmi and didn't think of that.
I'll revisit this.

Thanks for the quick review :)
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-28 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 12:53 [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw Mark Pearson
2026-04-28 13:00 ` Ilpo Järvinen
2026-04-28 13:15   ` Mark Pearson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox