From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AA4A3590B5 for ; Tue, 6 Jan 2026 17:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767721545; cv=none; b=XKfqvEm4OJ+ZBSBvS5TnUszCXcZv9yiVtWYNhBki6pzanx6VzsQNwLfH3htcDQ4bM8XGauUCs0h0/eYg6RkLQoT2Je66T7WZMODiwoqVcXrLWkNIq8lELFjkvaap46Dfi927JLm4VSYQ185WdTBh25oxn8yIPDaXRCaKt0b0V6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767721545; c=relaxed/simple; bh=N5XDA3pHbxwIVNv4Q62stjY3z7JIMCAXVl4G72PT+rI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bEVpL+sogZvRyr+6ZY0oTJaJIJ2suLC8W8WzJCecbVsj9/4DecJMc2mjQpDr/tkbWbwcaiLXhxud0+Cps6JoJeWhVqELo5AHyz6V4G9b0ik8smfv6vflof4aSZLNe9f4G1elbCKS9WJNpHMAh5aYcCCrlXwUUuzb3WNW2pdlz3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bjbnL8Ln; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bjbnL8Ln" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7fc0c1d45a4so1051885b3a.0 for ; Tue, 06 Jan 2026 09:45:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767721543; x=1768326343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3We0aNqjHbYJgCNoEmx0vHJsTgZdujoUbsScQteKmFg=; b=bjbnL8LnsAX28BmJuHMQXXuvHJJyAEXcNwrqT6wUPqqxiQOn6cRW2k1jr1bVc/Mwz9 xagb2WA0HT1JJXFm3q9nyYw0tSAsm0OUl+09xHhZLe57r7gehTvYedQuqHDexTgr1iXQ pm55e2qDxa8kE1811zn140kXF8kXlxcGHYbOiVK5DcLgoYPtkxPFSKqekpNMeAMTpArD Qwi0FP1O9y81iyDtpZe433J5k8q1QoxJrQDAMelQ5c8R4bhO+nuJKM++UWRlBn1BI4oT M8L7pSdtLpCEwLeWPojBMPiWTYUjossQxMG5qdErjvBjYWvU/5w99a6PiP5+gNA51+Vh ZZoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767721543; x=1768326343; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3We0aNqjHbYJgCNoEmx0vHJsTgZdujoUbsScQteKmFg=; b=Fz+LE4nl4/S3uzIgESUy6IAwxn8g3IguEPL0XMVvXVLnOb15+Q3N7kvn6n9r30/trw ea7mM/30u0t4unkEo5xqw/Jaiux0EYqE3jxf9bQLPWJ9jQtkndVbxLGTPdMALJNtbKbf R5/nDynVYrqmF76gjCQWgXxyypmPZ0Jk8XzUMBjTwPQIXNG0dpnFDcy/soBwwscZrRtK dEsP1fAYH77c/XEyC0o02sf5zMkFSvfy1I4YB+UTlfAV6Dw/k+11Th0BRAukhPEYflOO SD998vjxITrg88UYpMmoPMvgrPyKSkSBJ/L2h66/UtrR7aWQgxgSfHbeIXbnQNdHJDZs mT6g== X-Forwarded-Encrypted: i=1; AJvYcCUb8Q1/L/2uKOnjlVnC3WZl1QD35jjVmEATGSBh19U+ZxmSXuMCSjqBauNwx6JHaQxoRUNEVpslO6OHQjY=@vger.kernel.org X-Gm-Message-State: AOJu0YwqaEwuguKe5Jz4p2qN8ORKmExtAYasFdGBZ5YJ2e30w0FsoVSd V/7zk73SdDfRpWdzS1sBo7JAnYtHr1KmX/jxCWJ+7w45+tdxhJt5o3qe X-Gm-Gg: AY/fxX4imEMFMkcgdEKwrSHUnS4HbADaED5/ibwm0eEP8FwSvhZpoij6QyeMoD05+MT SVI1aOp+WkYeOR9CMqZm+LrhqPb5GsOWtc6hdcoPRN7q+rJWNVAz0XiB9FdU7n1lQdqEpHle1jx QjN40/pyGn1wwwJfa5JNQspN9ra65XKH3TBDcvQKDd9VLq3Ibj7EqnLSBCYj0PD8VqNEWy+N7SL Td3v+eRGopxpRC+32UFVScvNNmI6+QmxD8V9xJRpFT59O5IgiIcoeygTChTBbUcjaPtotpNgi2a x6RK31TN06xwpc1CfgkIsO/kZo3LalAlg9IfSZCKxff6CmDGalUfX8AUSv2foN9YmNJHkPhM/eX +UwgvcA7/eec3uNkTWEEd4isD8veSJdBmLOaSW8Klo2PXawf2dhlqaMLGx72/ANCdotcb6MYZ5m DVqErre68x4KcSOnEXqwL0Afs3lAPdo6s= X-Google-Smtp-Source: AGHT+IFmLF0U9sMTkHwAs7WeIqoh1LXSWh5COrN/21DjLYpj5NfMqzMqIrcPFGwn+NtnjHym7bH7VQ== X-Received: by 2002:a05:6a00:1d06:b0:7e8:450c:61d2 with SMTP id d2e1a72fcca58-81882dde6f7mr3141538b3a.66.1767721542515; Tue, 06 Jan 2026 09:45:42 -0800 (PST) Received: from nitin-ThinkPad-T1g-Gen-8.. ([2405:201:3006:188a:8d12:f5f:47cc:6a19]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-819c52fd904sm2736818b3a.33.2026.01.06.09.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 09:45:41 -0800 (PST) From: Nitin Joshi To: hansg@kernel.org, ilpo.jarvinen@linux.intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, njoshi1@lenovo.com, Nitin Joshi , Mark Pearson Subject: [PATCH v7 1/2] platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability. Date: Wed, 7 Jan 2026 02:45:18 +0900 Message-ID: <20260106174519.6402-1-nitjoshi@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Nitin Joshi --- 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