mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Nitin Joshi <nitjoshi@gmail.com>
Cc: hansg@kernel.org, ilpo.jarvinen@linux.intel.com,
	 platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,  njoshi1@lenovo.com,
	Mark Pearson <mpearson-lenovo@squebb.ca>
Subject: Re: [PATCH v4 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
Date: Tue, 16 Dec 2025 14:14:42 +0200 (EET)	[thread overview]
Message-ID: <42c66ffc-8e36-c595-25bd-e58335087ba3@linux.intel.com> (raw)
In-Reply-To: <20251216120454.41076-2-nitjoshi@gmail.com>

On Tue, 16 Dec 2025, Nitin Joshi wrote:

> 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
> ---
>  .../admin-guide/laptops/thinkpad-acpi.rst     |  13 +-
>  drivers/platform/x86/lenovo/thinkpad_acpi.c   | 114 +++++++++++++++++-
>  2 files changed, 122 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
> index 2db05f718b11..3a37b14863a8 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.
> @@ -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.
>  
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index b0f7dc0bd531..0dc6d7e07213 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,7 +11124,96 @@ 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)) {

Could this too be using reverse logic to reduce indentation level?

> +			*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;
> +
> +

Please remove the extra empty line.

> +	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;
> +	} else
> +		return -ENODEV;
> +
> +	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)
> @@ -11132,13 +11237,14 @@ static ssize_t hwdd_status_show(struct device *dev,
>  	} else
>  		return -ENODEV;
>  
> -
>  	return sysfs_emit(buf, "0\n");

This belongs to the previous patch.

>  }
>  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
>  };
>  
> 

-- 
 i.


  reply	other threads:[~2025-12-16 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16 12:04 [PATCH v4 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability Nitin Joshi
2025-12-16 12:04 ` [PATCH v4 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device Nitin Joshi
2025-12-16 12:14   ` Ilpo Järvinen [this message]
2025-12-17  2:20     ` Nitin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42c66ffc-8e36-c595-25bd-e58335087ba3@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=nitjoshi@gmail.com \
    --cc=njoshi1@lenovo.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome