Re: [PATCH] platform/x86: thinkpad_acpi: Add sysfs to display HWDD raw
From: Ilpo Järvinen
Date: Tue Apr 28 2026 - 09:15:11 EST
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@xxxxxxxxx>
> ---
> 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");
>