platform/x86: thinkpad_acpi: Add support to detect hardware damage detection capability.
PATCH 1/1 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 the impacted component with status.
Initial support is available for the USB-C replaceable connector.
--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +26 -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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created. + Multiple Commands, Module Parameters ------------------------------------
drivers/platform/x86/lenovo/thinkpad_acpi.c +179 -0
197 lines not on this page · raw message
Signature · 1 line
2.43.0
Hans de Goede
maintainerHi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 42 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +15
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status.
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 10 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst +10
-0+For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created.
Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under /sys/class/ which this is not.
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Regards,
Hans
Ilpo Järvinen
maintainerQuoted 62 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +26
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created. + Multiple Commands, Module Parameters ------------------------------------drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-0@@ -11080,6 +11080,180 @@ static const struct attribute_group auxmac_attr_group = { .attrs = auxmac_attributes,
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11090
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +8
-0}; +/************************************************************************* +* 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)
Align values.
Quoted 11 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +11
-0+#define HWDD_GET_CAP 0 + +#define DAMAGE_STATUS_BIT BIT(0) +#define PORT_STATUS_OFFSET 4 +#define LID_STATUS_OFFSET 8 +#define BASE_STATUS_OFFSET 12 +#define PORT_DETAIL_OFFSET 16 + +#define PORT_POS_OFFSET 2 +#define PORT_LOC_MASK 0x3 +
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11111
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+#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
Add an empty line
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11113
Quoted 2 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +2
-0+static bool hwdd_support_available; +static bool ucdd_supported;
Add an empty line
Quoted 13 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +13
-0+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 ; +} +
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11136
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+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; +unsigned int i; + + port_status = (dmg_status >>PORT_STATUS_OFFSET ) &0xF ; + lid_status = (dmg_status >>LID_STATUS_OFFSET ) &0xF ; + base_status = (dmg_status >>BASE_STATUS_OFFSET ) &0xF ;
Define these as fields using GENMASK() and use FIELD_GET() here. Don't forget to check you also have the includes for those.
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11139
Quoted 3 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +3
-0+for (i =0 ; i <NUM_PORTS ; i++) { +if (dmg_status &BIT (i)) { +if (port_status &BIT (i)) {
Reverse the logic in these and use continue to bring down indentation level.
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11142
Quoted 3 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +3
-0+ *count +=sysfs_emit_at (buf, *count,"%s damage detected:\n" , type); + loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * i))) &0xF ; + pos_status = (loc_status >>PORT_POS_OFFSET ) &PORT_LOC_MASK ;
Extra space & use FIELD_GET().
Quoted 11 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +11
-0+ panel_status = loc_status &PORT_LOC_MASK ; + + *count +=sysfs_emit_at (buf, *count,"Location: " ); +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, " );
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11163
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+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 ;
Some checkers likely won't be happy if you're not having default: at all, even if it is unnecessary here. So add something like this:
default: WARN_ON(1); return ...;
Quoted 34 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +34
-0+ }; + +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 typc damage detection capability */ +static ssize_t hwdd_status_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +bool damage_detected = false; +unsigned int damage_status; +int err, count =0 ; + +if (ucdd_supported) { +/* Get USB TYPE-C damage status */
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11207
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+ 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; + } + +if (!damage_detected) + count = count +sysfs_emit_at (buf, count,"No damage detected\n" );
Extra space, please also use += instead.
Quoted 72 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +54
-0+ +return count; +} +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 +11313,7 @@ static const struct attribute_group *tpacpi_groups[] = { &kbdlang_attr_group, &dprc_attr_group, &auxmac_attr_group, + &hwdd_attr_group, NULL, };@@ -11752,6 +11927,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)
Signature · 1 line
i.
Hi Hans,
Thank you for reviewing this patch.
Quoted 52 lines · Hans de Goede
Hi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 46 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +19
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected:
Quoted 8 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 6 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst +6
-0+ Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created.Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under
/sys/class/which this is not.
Ack, I will modify it.
Quoted 11 lines
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Thank you for pointing this out. I am open for suggestions and will re-check regarding its use case in lenovo vantage in future.
Quoted 6 lines
Regards,
Hans
Hi Ilpo,
Thank you for reviewing the patch.
Quoted 66 lines · Ilpo Järvinen
Quoted 64 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +26
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created. + Multiple Commands, Module Parameters ------------------------------------drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-0@@ -11080,6 +11080,180 @@ static const struct attribute_group auxmac_attr_group = { .attrs = auxmac_attributes, };
Quoted 9 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11090
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +8
-0+/************************************************************************* +* 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)Align values.
Ack, i will align values like below:
#define HWDD_GET_CAP 0
#define HWDD_GET_DMG_USBC 0x80000001
#define HWDD_SUPPORT_USBC BIT(0)
#define HWDD_NOT_SUPPORTED BIT(31)
Quoted 14 lines
Quoted 14 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +14
-0+#define HWDD_GET_CAP 0 + +#define DAMAGE_STATUS_BIT BIT(0) +#define PORT_STATUS_OFFSET 4 +#define LID_STATUS_OFFSET 8 +#define BASE_STATUS_OFFSET 12 +#define PORT_DETAIL_OFFSET 16 + +#define PORT_POS_OFFSET 2 +#define PORT_LOC_MASK 0x3 + +#define PANEL_TOP 0 +#define PANEL_BASE 1 +#define PANEL_LEFT 2
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11111
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+#define PANEL_RIGHT 3 + +#define POS_LEFT 0 +#define POS_CENTER 1 +#define POS_RIGHT 2 + +#define NUM_PORTS 4Add an empty line
Ack.
Quoted 4 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11113
Quoted 3 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +2
-0+static bool hwdd_support_available; +static bool ucdd_supported;Add an empty line
Ack.
Quoted 18 lines
Quoted 18 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +17
-0+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 ; +} + +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;
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11136
Quoted 6 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +6
-0+bool damage_detected = false; +unsigned int i; + + port_status = (dmg_status >>PORT_STATUS_OFFSET ) &0xF ; + lid_status = (dmg_status >>LID_STATUS_OFFSET ) &0xF ; + base_status = (dmg_status >>BASE_STATUS_OFFSET ) &0xF ;Define these as fields using
GENMASK()and useFIELD_GET()here. Don't forget to check you also have the includes for those.
Ack. I will recheck and modify it.
Quoted 6 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11139
Quoted 4 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +3
-0+for (i =0 ; i <NUM_PORTS ; i++) { +if (dmg_status &BIT (i)) { +if (port_status &BIT (i)) {Reverse the logic in these and use continue to bring down indentation level.
Ack. I will recheck and modify it.
Quoted 5 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11142
Quoted 4 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +3
-0+ *count +=sysfs_emit_at (buf, *count,"%s damage detected:\n" , type); + loc_status = (dmg_status >> (PORT_DETAIL_OFFSET + (4 * i))) &0xF ; + pos_status = (loc_status >>PORT_POS_OFFSET ) &PORT_LOC_MASK ;Extra space & use
FIELD_GET().
Ack.
Quoted 25 lines
Quoted 12 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +11
-0+ panel_status = loc_status &PORT_LOC_MASK ; + + *count +=sysfs_emit_at (buf, *count,"Location: " ); +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, " );drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11163
Quoted 10 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +10
-0+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 ;Some checkers likely won't be happy if you're not having default: at all, even if it is unnecessary here. So add something like this:
Quoted 3 lines
default: WARN_ON(1); return ...;
Ack, I will recheck and modify it.
Quoted 37 lines
Quoted 37 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +37
-0+ }; + +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 typc damage detection capability */ +static ssize_t hwdd_status_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +bool damage_detected = false; +unsigned int damage_status; +int err, count =0 ; + +if (ucdd_supported) { +/* Get USB TYPE-C damage status */ + err =hwdd_command (HWDD_GET_DMG_USBC , &damage_status); +if (err) +return err;
Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11207
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+ +if (display_damage (buf, &count,"Type-C" , damage_status)) + damage_detected = true; + } + +if (!damage_detected) + count = count +sysfs_emit_at (buf, count,"No damage detected\n" );Extra space, please also use += instead.
Ack.
Quoted 73 lines
Quoted 73 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +54
-0+ +return count; +} +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 +11313,7 @@ static const struct attribute_group *tpacpi_groups[] = { &kbdlang_attr_group, &dprc_attr_group, &auxmac_attr_group, + &hwdd_attr_group, NULL, };@@ -11752,6 +11927,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)
Ilpo Järvinen
maintainerQuoted 81 lines · Nitin
Hi Ilpo,
Thank you for reviewing the patch.
Quoted 67 lines · Ilpo Järvinen
Quoted 65 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +14
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damagestatus.
Documentation/admin-guide/laptops/thinkpad-acpi.rst +11
-0+For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class 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
indexcc19fe520ea9..c3629bed9a8e100644drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-0@@ -11080,6 +11080,180 @@ static const struct attribute_group auxmac_attr_group = { .attrs = auxmac_attributes, }; +/************************************************************************* Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11090
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+* 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)Align values.
Quoted 6 lines
Ack, i will align values like below:
#define
HWDD_GET_CAP0
#defineHWDD_GET_DMG_USBC0x80000001
#defineHWDD_SUPPORT_USBCBIT(0)
#defineHWDD_NOT_SUPPORTEDBIT(31)
These are not aligned as values starts from different columns. Please put a tab char there in between so the values start at the same column (or varying number of tabs depending on the length of the name).
There are plenty of good examples in the code, including in this file you're modifying.
Signature · 1 line
i.
Quoted 88 lines · Ilpo Järvinen
Quoted 80 lines · Nitin
Hi Ilpo,
Thank you for reviewing the patch.
Quoted 67 lines · Ilpo Järvinen
Quoted 65 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +14
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damagestatus.
Documentation/admin-guide/laptops/thinkpad-acpi.rst +11
-0+For example: +if no damage is detected: + No damage detected +if damage detected: + Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class 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
indexcc19fe520ea9..c3629bed9a8e100644drivers/platform/x86/lenovo/thinkpad_acpi.c +0
-0@@ -11080,6 +11080,180 @@ static const struct attribute_group auxmac_attr_group = { .attrs = auxmac_attributes, }; +/************************************************************************* Quoted 8 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c static const struct attribute_group auxmac_attr_group = { · line 11090
Quoted 7 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +7
-0+* 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)Align values.
Quoted 6 lines
Ack, i will align values like below:
#define
HWDD_GET_CAP0
#defineHWDD_GET_DMG_USBC0x80000001
#defineHWDD_SUPPORT_USBCBIT(0)
#defineHWDD_NOT_SUPPORTEDBIT(31)
Quoted 6 lines
These are not aligned as values starts from different columns. Please put a tab char there in between so the values start at the same column (or varying number of tabs depending on the length of the name).
There are plenty of good examples in the code, including in this file you're modifying.
Ack, i will modify it . Thank you !
Quoted 1 line
Mark Pearson
maintainerQuoted 75 lines · Nitin
Hi Hans,
Thank you for reviewing this patch.
Quoted 52 lines · Hans de Goede
Hi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 46 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +19
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected:Quoted 8 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 6 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst +6
-0+ Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created.Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under
/sys/class/which this is not.Ack, I will modify it.
Quoted 9 lines
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Quoted 6 lines
Quoted 2 lines
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Thank you for pointing this out. I am open for suggestions and will re-check regarding its use case in lenovo vantage in future.
I'd not considered it from this perspective.
One concern is that it could be multiple devices in multiple location - so breaking it up into too many pieces becomes difficult.
What if we did:
hwdd_status - 1 or 0 if damage detected
hwdd_detail - list of damaged items with their location (could be multiple). e.g.
TYPE-C: Base, Right side, Center port
If hwdd_status is 0 then hwdd_detail would display "No damage detected"
Mark
Quoted 82 lines · Mark Pearson
Quoted 74 lines · Nitin
Hi Hans,
Thank you for reviewing this patch.
Quoted 52 lines · Hans de Goede
Hi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 46 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +19
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected:Quoted 8 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 6 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst +6
-0+ Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created.Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under
/sys/class/which this is not.Ack, I will modify it.
Quoted 8 lines
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Quoted 5 lines
Quoted 2 lines
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Thank you for pointing this out. I am open for suggestions and will re-check regarding its use case in lenovo vantage in future.
I'd not considered it from this perspective.
Quoted 7 lines
One concern is that it could be multiple devices in multiple location - so breaking it up into too many pieces becomes difficult.
What if we did:
hwdd_status- 1 or 0 if damage detected
hwdd_detail- list of damaged items with their location (could be multiple). e.g.
TYPE-C: Base, Right side, Center port
Ifhwdd_statusis 0 thenhwdd_detailwould display "No damage detected"
Thank you, Mark ! I am OK with this suggestion.
Hans / Ilpo - Any comment on this ? Thanks
Quoted 1 line
Mark
Thank you !
Nitin Joshi
Hans de Goede
maintainerHi,
Quoted 80 lines · Nitin
Quoted 78 lines · Mark Pearson
Quoted 77 lines · Nitin
Hi Hans,
Thank you for reviewing this patch.
Quoted 50 lines · Hans de Goede
Hi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 44 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>---
.../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +0
-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 failureDocumentation/admin-guide/laptops/thinkpad-acpi.rst +0
-0@@ -1576,6 +1577,31 @@ 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
+-----------------Documentation/admin-guide/laptops/thinkpad-acpi.rst +16
-0+ +sysfs attributes: hwdd_status + +Thinkpads are adding the ability to detect and report hardware damage. +Add new sysfs interface to identify the impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected:Quoted 8 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 6 lines
+ Damage detected:
+ Device: TYPE-C
+ Location: Base, Right side, Center portDocumentation/admin-guide/laptops/thinkpad-acpi.rst +3
-0+ +The property is read-only. If feature is not supported then sysfs +class is not created.Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under
/sys/class/which this is not.Ack, I will modify it.
Quoted 10 lines
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Thank you for pointing this out. I am open for suggestions and will re-check regarding its use case in lenovo vantage in future.
Quoted 8 lines
Quoted 8 lines
I'd not considered it from this perspective.
One concern is that it could be multiple devices in multiple location - so breaking it up into too many pieces becomes difficult.
What if we did:
hwdd_status- 1 or 0 if damage detected
hwdd_detail- list of damaged items with their location (could be multiple). e.g.
TYPE-C: Base, Right side, Center port
So I assume this would then output one line per damaged "item", it would be good to document this (1 line per damaged item) in the sysfs ABI docs.
Quoted 5 lines
Quoted 1 line
If
hwdd_statusis 0 thenhwdd_detailwould display "No damage detected"Thank you, Mark ! I am OK with this suggestion.
Hans / Ilpo - Any comment on this ? Thanks
Yes this sounds good to me.
Regards,
Hans
Hi,
Quoted 84 lines · Hans de Goede
Hi,
Quoted 81 lines · Nitin
Quoted 80 lines · Mark Pearson
Quoted 72 lines · Nitin
Hi Hans,
Thank you for reviewing this patch.
Quoted 50 lines · Hans de Goede
Hi,
Interesting new feature. A few small remarks on the proposed sysfs API below.
Quoted 44 lines · Nitin Joshi
Thinkpads are adding the ability to detect and report hardware damage status. Add new sysfs interface to identify the impacted component with status.
Initial support is available for the USB-C replaceable connector.Reviewed-by Mark Pearson <[email protected]>Signed-off-by Nitin Joshi<[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 26 +++ drivers/platform/x86/lenovo/thinkpad_acpi.c | 179 ++++++++++++++++++ 2 files changed, 205 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +18
-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,31 @@ 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 impacted component. +Initial support is available for the USB-C replaceable connector. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/hwdd_status + +This value displays device type and location of device with damage status. +For example: +if no damage is detected: + No damage detected +if damage detected:Quoted 8 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst percentage level, above which charging will stop. · line 1603
Quoted 6 lines
Documentation/admin-guide/laptops/thinkpad-acpi.rst +6
-0+ Damage detected: + Device: TYPE-C + Location: Base, Right side, Center port + +The property is read-only. If feature is not supported then sysfs +class is not created.Nitpick: s/class/attribute/ classes are standardized sysfs interfaces living under
/sys/class/which this is not.Ack, I will modify it.
Quoted 8 lines
Besides the nitpick I'm wondering if we do not want to make this a little bit more friendly / easy for software to parse ?
ATM this seems focused on a human directly reading the output but what if we want some sort of automation, like e.g. a Linux version of the Lenovo Vantage sw parsing this in the future?
Quoted 5 lines
Quoted 2 lines
Note I've no specific suggestions for how to make this easier to parse, this is just an observation.
Thank you for pointing this out. I am open for suggestions and will re-check regarding its use case in lenovo vantage in future.
I'd not considered it from this perspective.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
One concern is that it could be multiple devices in multiple location - so breaking it up into too many pieces becomes difficult.
What if we did:
hwdd_status- 1 or 0 if damage detected
hwdd_detail- list of damaged items with their location (could be multiple). e.g.
TYPE-C: Base, Right side, Center portSo I assume this would then output one line per damaged "item", it would be good to document this (1 line per damaged item) in the sysfs ABI docs.
yes, we will have one line per damaged "item". I will update ABI docs accordingly.
Thanks
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
If
hwdd_statusis 0 thenhwdd_detailwould display "No damage detected"Thank you, Mark ! I am OK with this suggestion.
Hans / Ilpo - Any comment on this ? Thanks
Yes this sounds good to me.
Regards,
Hans
Thanks & Regards,
Nitin