platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
PATCH v4 1/2 platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
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.
---
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
--- .../admin-guide/laptops/thinkpad-acpi.rst | 21 ++++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 106 ++++++++++++++++++ 2 files changed, 127 insertions(+)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +21 -0
@@ -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,26 @@ 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 ------------------------------------
drivers/platform/x86/lenovo/thinkpad_acpi.c +106 -0
124 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 2/2 platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
Add new sysfs interface to identify the impacted component with location of device.
---
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(-)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +12 -1
@@ -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.
drivers/platform/x86/lenovo/thinkpad_acpi.c +110 -4
138 lines not on this page · raw message
Signature · 1 line
2.43.0
Ilpo Järvinen
maintainerRe: [PATCH v4 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
Quoted 87 lines · Nitin Joshi
Add new sysfs interface to identify the impacted component with location of device.
Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>---
Changes since v2:
-Control visibility of the sysfs attribute based uponucdd_supportedChanges since v3:(quoted diff) +0
-2-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(-)Documentation/admin-guide/laptops/thinkpad-acpi.rst +12
-1@@ -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.drivers/platform/x86/lenovo/thinkpad_acpi.c +23
-3@@ -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 4static 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;
drivers/platform/x86/lenovo/thinkpad_acpi.c static int hwdd_command(int command, int *output) · line 11141
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+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?
Quoted 47 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +47
-0+ *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; +} +
drivers/platform/x86/lenovo/thinkpad_acpi.c static int hwdd_command(int command, int *output) · line 11198
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+/* 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.
Quoted 22 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +18
-0+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)
drivers/platform/x86/lenovo/thinkpad_acpi.c static ssize_t hwdd_status_show(struct device *dev, · line 11240
Quoted 5 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-1@@ -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.
Quoted 11 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +2
-0}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 };
Signature · 1 line
i.
Re: [PATCH v4 2/2] platform/x86: thinkpad_acpi: Add sysfs to display details of damaged device.
Quoted 92 lines · Ilpo Järvinen
Quoted 90 lines · Nitin Joshi
Add new sysfs interface to identify the impacted component with location of device.
Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>---
Changes since v2:
-Control visibility of the sysfs attribute based uponucdd_supportedChanges since v3:(quoted diff) +0
-2-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(-)Documentation/admin-guide/laptops/thinkpad-acpi.rst +12
-1@@ -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.drivers/platform/x86/lenovo/thinkpad_acpi.c +26
-3@@ -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 4static 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);
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static int hwdd_command(int command, int *output) · line 11141
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+ 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?
Ack , I will modify it in next version. Thanks
Quoted 51 lines
Quoted 51 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +50
-0+ *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,
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static int hwdd_command(int command, int *output) · line 11198
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+ char *buf) +{ +bool damage_detected = false; +unsigned int damage_status; +int err, count =0 ; + +Please remove the extra empty line.
Ack
Quoted 26 lines
Quoted 26 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +18
-0+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 ;
Quoted 3 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static ssize_t hwdd_status_show(struct device *dev, · line 11240
Quoted 2 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-1-return sysfs_emit (buf,"0\n" );This belongs to the previous patch.
Ack ,
Quoted 5 lines
Quoted 5 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +1
-0}static DEVICE_ATTR_RO (hwdd_status); +static DEVICE_ATTR_RO (hwdd_detail);
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static ssize_t hwdd_status_show(struct device *dev, · line 11250
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +1
-0static struct attribute *hwdd_attributes[] = { &dev_attr_hwdd_status.attr, + &dev_attr_hwdd_detail.attr,NULL };
Thanks & Regards,
Nitin Joshi