platform/x86: dell: Add new dell-wmi-ddv driver
Subsystems (8)
Armin Wolf
maintainerv2 cover platform/x86: dell: Add new dell-wmi-ddv driver
This patch series adds a new driver for a WMI interface found in many newer Dell machines. This interface allows to read battery properties like temperature and the ePPID (Dell-specific), while also providing fan and thermal sensor information.
The interface does support multiple batteries which are indentified by an "index", which appears to be the battery ACPI UID. Since the interface also appears to omit any bounts checking of the index, the ACPI battery hook mechanism is used to discover batteries.
Since the information returned when querying fan/thermal sensor information is currently unknown, a debugfs entry is created to allow for easier reverse engineering. The interface is likely to be replaced by a proper hwmon interface in the future.
Since the driver can potentially be instantiated multiple times, the ACPI battery hook mechanism had to be extended.
The first patch passes a pointer to the battery hook to the hook callbacks, so that they can access instance-specific data with container_of().
The second patch finally adds the new driver. It was called dell-wmi-ddv since the interface is called "DDV" by Dell software, likely meaning "Dell Data Vault".
The driver was tested, together with the changes made to the ACPI battery driver, on a Dell Inspiron 3505. Other drivers already using the battery hook mechanism where changed as well, but could only be compile-tested due to missing hardware.
---
Changes in v2:
- Significantly lower the amount of changes being made to the acpi battery driver
- drop unnecessary ABI description of the temp attribute
- return 0 when a unsupported battery is found to avoid being unloaded
Armin Wolf (2):
ACPI: battery: Pass battery hook pointer to hook callbacks platform/x86: dell: Add new dell-wmi-ddv driver
.../ABI/testing/debugfs-dell-wmi-ddv | 21 + .../ABI/testing/sysfs-platform-dell-wmi-ddv | 7 + MAINTAINERS | 7 + drivers/acpi/battery.c | 8 +- drivers/platform/x86/asus-wmi.c | 4 +- drivers/platform/x86/dell/Kconfig | 13 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-wmi-ddv.c | 361 ++++++++++++++++++ drivers/platform/x86/huawei-wmi.c | 4 +- drivers/platform/x86/lg-laptop.c | 4 +- drivers/platform/x86/system76_acpi.c | 4 +- drivers/platform/x86/thinkpad_acpi.c | 4 +- drivers/platform/x86/toshiba_acpi.c | 4 +- drivers/platform/x86/wmi.c | 1 + include/acpi/battery.h | 4 +- 15 files changed, 429 insertions(+), 18 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-dell-wmi-ddv create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv create mode 100644 drivers/platform/x86/dell/dell-wmi-ddv.c
--
2.30.2
Armin Wolf
maintainerPATCH v2 1/2 ACPI: battery: Pass battery hook pointer to hook callbacks
Right now, is impossible for battery hook callbacks to access instance-specific data, forcing most drivers to provide some sort of global state. This however is difficult for drivers which can be instantiated multiple times and/or are hotplug-capable.
Pass a pointer to the batetry hook to those callbacks for usage with container_of().
--- drivers/acpi/battery.c | 8 ++++---- drivers/platform/x86/asus-wmi.c | 4 ++-- drivers/platform/x86/huawei-wmi.c | 4 ++-- drivers/platform/x86/lg-laptop.c | 4 ++-- drivers/platform/x86/system76_acpi.c | 4 ++-- drivers/platform/x86/thinkpad_acpi.c | 4 ++-- drivers/platform/x86/toshiba_acpi.c | 4 ++-- include/acpi/battery.h | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-)
drivers/acpi/battery.c +4 -4
@@ -696,7 +696,7 @@ static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)if (lock)mutex_lock (&hook_mutex);list_for_each_entry (battery, &acpi_battery_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }list_del (&hook->list);if (lock)
@@ -724,7 +724,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)* its attributes. */ list_for_each_entry (battery, &acpi_battery_list, list) { -if (hook->add_battery (battery->bat)) { +if (hook->add_battery (battery->bat, hook)) {/* * If a add-battery returns non-zero, * the registration of the extension has failed,
@@ -762,7 +762,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)* during the battery module initialization. */ list_for_each_entry_safe (hook_node, tmp, &battery_hook_list, list) { -if (hook_node->add_battery (battery->bat)) { +if (hook_node->add_battery (battery->bat, hook_node)) {/* * The notification of the extensions has failed, to * prevent further errors we will unload the extension.
@@ -785,7 +785,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery)* custom attributes from the battery. */ list_for_each_entry (hook, &battery_hook_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }/* Then, just remove the battery from the list */ list_del (&battery->list);
drivers/platform/x86/asus-wmi.c +2 -2
@@ -882,7 +882,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device,static DEVICE_ATTR_RW (charge_control_end_threshold); -static int asus_wmi_battery_add (struct power_supply *battery) +static int asus_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {/* The WMI method does not provide a way to specific a battery, so we * just assume it is the first battery.
@@ -909,7 +909,7 @@ static int asus_wmi_battery_add(struct power_supply *battery)return 0 ; } -static int asus_wmi_battery_remove (struct power_supply *battery) +static int asus_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);
drivers/platform/x86/huawei-wmi.c +2 -2
@@ -468,7 +468,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (charge_control_thresholds); -static int huawei_wmi_battery_add (struct power_supply *battery) +static int huawei_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int err =0 ;
@@ -483,7 +483,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery)return err; } -static int huawei_wmi_battery_remove (struct power_supply *battery) +static int huawei_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_start_threshold);device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);
drivers/platform/x86/lg-laptop.c +2 -2
@@ -546,7 +546,7 @@ static DEVICE_ATTR_RW(fn_lock);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (battery_care_limit); -static int lg_battery_add (struct power_supply *battery) +static int lg_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (device_create_file (&battery->dev, &dev_attr_charge_control_end_threshold))
@@ -555,7 +555,7 @@ static int lg_battery_add(struct power_supply *battery)return 0 ; } -static int lg_battery_remove (struct power_supply *battery) +static int lg_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);
drivers/platform/x86/system76_acpi.c +2 -2
@@ -254,7 +254,7 @@ static struct attribute *system76_battery_attrs[] = {ATTRIBUTE_GROUPS (system76_battery); -static int system76_battery_add (struct power_supply *battery) +static int system76_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {// System76 EC only supports 1 battery if (strcmp (battery->desc->name,"BAT0" ) !=0 )
@@ -266,7 +266,7 @@ static int system76_battery_add(struct power_supply *battery)return 0 ; } -static int system76_battery_remove (struct power_supply *battery) +static int system76_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, system76_battery_groups);return 0 ;
drivers/platform/x86/thinkpad_acpi.c +2 -2
@@ -9897,7 +9897,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery);/* ACPI battery hooking */ -static int tpacpi_battery_add (struct power_supply *battery) +static int tpacpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int batteryid =tpacpi_battery_get_id (battery->desc->name);
@@ -9908,7 +9908,7 @@ static int tpacpi_battery_add(struct power_supply *battery)return 0 ; } -static int tpacpi_battery_remove (struct power_supply *battery) +static int tpacpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, tpacpi_battery_groups);return 0 ;
drivers/platform/x86/toshiba_acpi.c +2 -2
@@ -3113,7 +3113,7 @@ static struct attribute *toshiba_acpi_battery_attrs[] = {ATTRIBUTE_GROUPS (toshiba_acpi_battery); -static int toshiba_acpi_battery_add (struct power_supply *battery) +static int toshiba_acpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (toshiba_acpi ==NULL ) {pr_err ("Init order issue\n" );
@@ -3126,7 +3126,7 @@ static int toshiba_acpi_battery_add(struct power_supply *battery)return 0 ; } -static int toshiba_acpi_battery_remove (struct power_supply *battery) +static int toshiba_acpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, toshiba_acpi_battery_groups);return 0 ;
include/acpi/battery.h +2 -2
@@ -12,8 +12,8 @@struct acpi_battery_hook {const char *name; -int (*add_battery)(struct power_supply *battery); -int (*remove_battery)(struct power_supply *battery); +int (*add_battery)(struct power_supply *battery,struct acpi_battery_hook *hook); +int (*remove_battery)(struct power_supply *battery,struct acpi_battery_hook *hook);struct list_head list; };
--
2.30.2
Re: [PATCH v2 1/2] ACPI: battery: Pass battery hook pointer to hook callbacks
Quoted 11 lines · Armin Wolf
Right now, is impossible for battery hook callbacks to access instance-specific data, forcing most drivers to provide some sort of global state. This however is difficult for drivers which can be instantiated multiple times and/or are hotplug-capable.
Pass a pointer to the batetry hook to those callbacks for usage with
container_of().Signed-off-by Armin Wolf <[email protected]>
Quoted 201 lines
--- drivers/acpi/battery.c | 8 ++++---- drivers/platform/x86/asus-wmi.c | 4 ++-- drivers/platform/x86/huawei-wmi.c | 4 ++-- drivers/platform/x86/lg-laptop.c | 4 ++-- drivers/platform/x86/system76_acpi.c | 4 ++-- drivers/platform/x86/thinkpad_acpi.c | 4 ++-- drivers/platform/x86/toshiba_acpi.c | 4 ++-- include/acpi/battery.h | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-)drivers/acpi/battery.c +4
-4@@ -696,7 +696,7 @@ static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)if (lock)mutex_lock (&hook_mutex);list_for_each_entry (battery, &acpi_battery_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }list_del (&hook->list);if (lock)@@ -724,7 +724,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)* its attributes. */ list_for_each_entry (battery, &acpi_battery_list, list) { -if (hook->add_battery (battery->bat)) { +if (hook->add_battery (battery->bat, hook)) {/* * If a add-battery returns non-zero, * the registration of the extension has failed, @@ -762,7 +762,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)* during the battery module initialization. */ list_for_each_entry_safe (hook_node, tmp, &battery_hook_list, list) { -if (hook_node->add_battery (battery->bat)) { +if (hook_node->add_battery (battery->bat, hook_node)) {/* * The notification of the extensions has failed, to * prevent further errors we will unload the extension. @@ -785,7 +785,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery)* custom attributes from the battery. */ list_for_each_entry (hook, &battery_hook_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }/* Then, just remove the battery from the list */ list_del (&battery->list);drivers/platform/x86/asus-wmi.c +2
-2@@ -882,7 +882,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device,static DEVICE_ATTR_RW (charge_control_end_threshold); -static int asus_wmi_battery_add (struct power_supply *battery) +static int asus_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {/* The WMI method does not provide a way to specific a battery, so we * just assume it is the first battery. @@ -909,7 +909,7 @@ static int asus_wmi_battery_add(struct power_supply *battery)return 0 ; } -static int asus_wmi_battery_remove (struct power_supply *battery) +static int asus_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/huawei-wmi.c +2
-2@@ -468,7 +468,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (charge_control_thresholds); -static int huawei_wmi_battery_add (struct power_supply *battery) +static int huawei_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int err =0 ;@@ -483,7 +483,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery)return err; } -static int huawei_wmi_battery_remove (struct power_supply *battery) +static int huawei_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_start_threshold);device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/lg-laptop.c +2
-2@@ -546,7 +546,7 @@ static DEVICE_ATTR_RW(fn_lock);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (battery_care_limit); -static int lg_battery_add (struct power_supply *battery) +static int lg_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (device_create_file (&battery->dev, &dev_attr_charge_control_end_threshold))@@ -555,7 +555,7 @@ static int lg_battery_add(struct power_supply *battery)return 0 ; } -static int lg_battery_remove (struct power_supply *battery) +static int lg_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/system76_acpi.c +2
-2@@ -254,7 +254,7 @@ static struct attribute *system76_battery_attrs[] = {ATTRIBUTE_GROUPS (system76_battery); -static int system76_battery_add (struct power_supply *battery) +static int system76_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {// System76 EC only supports 1 battery if (strcmp (battery->desc->name,"BAT0" ) !=0 )@@ -266,7 +266,7 @@ static int system76_battery_add(struct power_supply *battery)return 0 ; } -static int system76_battery_remove (struct power_supply *battery) +static int system76_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, system76_battery_groups);return 0 ;drivers/platform/x86/thinkpad_acpi.c +2
-2@@ -9897,7 +9897,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery);/* ACPI battery hooking */ -static int tpacpi_battery_add (struct power_supply *battery) +static int tpacpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int batteryid =tpacpi_battery_get_id (battery->desc->name);@@ -9908,7 +9908,7 @@ static int tpacpi_battery_add(struct power_supply *battery)return 0 ; } -static int tpacpi_battery_remove (struct power_supply *battery) +static int tpacpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, tpacpi_battery_groups);return 0 ;drivers/platform/x86/toshiba_acpi.c +2
-2@@ -3113,7 +3113,7 @@ static struct attribute *toshiba_acpi_battery_attrs[] = {ATTRIBUTE_GROUPS (toshiba_acpi_battery); -static int toshiba_acpi_battery_add (struct power_supply *battery) +static int toshiba_acpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (toshiba_acpi ==NULL ) {pr_err ("Init order issue\n" );@@ -3126,7 +3126,7 @@ static int toshiba_acpi_battery_add(struct power_supply *battery)return 0 ; } -static int toshiba_acpi_battery_remove (struct power_supply *battery) +static int toshiba_acpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, toshiba_acpi_battery_groups);return 0 ;include/acpi/battery.h +2
-3@@ -12,8 +12,8 @@struct acpi_battery_hook {const char *name; -int (*add_battery)(struct power_supply *battery); -int (*remove_battery)(struct power_supply *battery); +int (*add_battery)(struct power_supply *battery,struct acpi_battery_hook *hook); +int (*remove_battery)(struct power_supply *battery,struct acpi_battery_hook *hook);struct list_head list; }; --2.30.2
Re: [PATCH v2 1/2] ACPI: battery: Pass battery hook pointer to hook callbacks
In reply to Armin WolfHi,
Quoted 10 lines · Armin Wolf
Right now, is impossible for battery hook callbacks to access instance-specific data, forcing most drivers to provide some sort of global state. This however is difficult for drivers which can be instantiated multiple times and/or are hotplug-capable.
Pass a pointer to the batetry hook to those callbacks for usage with
container_of().Signed-off-by Armin Wolf <[email protected]>
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 201 lines
--- drivers/acpi/battery.c | 8 ++++---- drivers/platform/x86/asus-wmi.c | 4 ++-- drivers/platform/x86/huawei-wmi.c | 4 ++-- drivers/platform/x86/lg-laptop.c | 4 ++-- drivers/platform/x86/system76_acpi.c | 4 ++-- drivers/platform/x86/thinkpad_acpi.c | 4 ++-- drivers/platform/x86/toshiba_acpi.c | 4 ++-- include/acpi/battery.h | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-)drivers/acpi/battery.c +4
-4@@ -696,7 +696,7 @@ static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock)if (lock)mutex_lock (&hook_mutex);list_for_each_entry (battery, &acpi_battery_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }list_del (&hook->list);if (lock)@@ -724,7 +724,7 @@ void battery_hook_register(struct acpi_battery_hook *hook)* its attributes. */ list_for_each_entry (battery, &acpi_battery_list, list) { -if (hook->add_battery (battery->bat)) { +if (hook->add_battery (battery->bat, hook)) {/* * If a add-battery returns non-zero, * the registration of the extension has failed, @@ -762,7 +762,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery)* during the battery module initialization. */ list_for_each_entry_safe (hook_node, tmp, &battery_hook_list, list) { -if (hook_node->add_battery (battery->bat)) { +if (hook_node->add_battery (battery->bat, hook_node)) {/* * The notification of the extensions has failed, to * prevent further errors we will unload the extension. @@ -785,7 +785,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery)* custom attributes from the battery. */ list_for_each_entry (hook, &battery_hook_list, list) { - hook->remove_battery (battery->bat); + hook->remove_battery (battery->bat, hook); }/* Then, just remove the battery from the list */ list_del (&battery->list);drivers/platform/x86/asus-wmi.c +2
-2@@ -882,7 +882,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device,static DEVICE_ATTR_RW (charge_control_end_threshold); -static int asus_wmi_battery_add (struct power_supply *battery) +static int asus_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {/* The WMI method does not provide a way to specific a battery, so we * just assume it is the first battery. @@ -909,7 +909,7 @@ static int asus_wmi_battery_add(struct power_supply *battery)return 0 ; } -static int asus_wmi_battery_remove (struct power_supply *battery) +static int asus_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/huawei-wmi.c +2
-2@@ -468,7 +468,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (charge_control_thresholds); -static int huawei_wmi_battery_add (struct power_supply *battery) +static int huawei_wmi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int err =0 ;@@ -483,7 +483,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery)return err; } -static int huawei_wmi_battery_remove (struct power_supply *battery) +static int huawei_wmi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_start_threshold);device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/lg-laptop.c +2
-2@@ -546,7 +546,7 @@ static DEVICE_ATTR_RW(fn_lock);static DEVICE_ATTR_RW (charge_control_end_threshold);static DEVICE_ATTR_RW (battery_care_limit); -static int lg_battery_add (struct power_supply *battery) +static int lg_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (device_create_file (&battery->dev, &dev_attr_charge_control_end_threshold))@@ -555,7 +555,7 @@ static int lg_battery_add(struct power_supply *battery)return 0 ; } -static int lg_battery_remove (struct power_supply *battery) +static int lg_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_file (&battery->dev, &dev_attr_charge_control_end_threshold);drivers/platform/x86/system76_acpi.c +2
-2@@ -254,7 +254,7 @@ static struct attribute *system76_battery_attrs[] = {ATTRIBUTE_GROUPS (system76_battery); -static int system76_battery_add (struct power_supply *battery) +static int system76_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {// System76 EC only supports 1 battery if (strcmp (battery->desc->name,"BAT0" ) !=0 )@@ -266,7 +266,7 @@ static int system76_battery_add(struct power_supply *battery)return 0 ; } -static int system76_battery_remove (struct power_supply *battery) +static int system76_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, system76_battery_groups);return 0 ;drivers/platform/x86/thinkpad_acpi.c +2
-2@@ -9897,7 +9897,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery);/* ACPI battery hooking */ -static int tpacpi_battery_add (struct power_supply *battery) +static int tpacpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {int batteryid =tpacpi_battery_get_id (battery->desc->name);@@ -9908,7 +9908,7 @@ static int tpacpi_battery_add(struct power_supply *battery)return 0 ; } -static int tpacpi_battery_remove (struct power_supply *battery) +static int tpacpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, tpacpi_battery_groups);return 0 ;drivers/platform/x86/toshiba_acpi.c +2
-2@@ -3113,7 +3113,7 @@ static struct attribute *toshiba_acpi_battery_attrs[] = {ATTRIBUTE_GROUPS (toshiba_acpi_battery); -static int toshiba_acpi_battery_add (struct power_supply *battery) +static int toshiba_acpi_battery_add (struct power_supply *battery,struct acpi_battery_hook *hook) {if (toshiba_acpi ==NULL ) {pr_err ("Init order issue\n" );@@ -3126,7 +3126,7 @@ static int toshiba_acpi_battery_add(struct power_supply *battery)return 0 ; } -static int toshiba_acpi_battery_remove (struct power_supply *battery) +static int toshiba_acpi_battery_remove (struct power_supply *battery,struct acpi_battery_hook *hook) {device_remove_groups (&battery->dev, toshiba_acpi_battery_groups);return 0 ;include/acpi/battery.h +2
-3@@ -12,8 +12,8 @@struct acpi_battery_hook {const char *name; -int (*add_battery)(struct power_supply *battery); -int (*remove_battery)(struct power_supply *battery); +int (*add_battery)(struct power_supply *battery,struct acpi_battery_hook *hook); +int (*remove_battery)(struct power_supply *battery,struct acpi_battery_hook *hook);struct list_head list; }; --2.30.2
Armin Wolf
maintainerPATCH v2 2/2 platform/x86: dell: Add new dell-wmi-ddv driver
In reply to Armin WolfThe dell-wmi-ddv driver adds support for reading the current temperature and ePPID of ACPI batteries on supported Dell machines.
Since the WMI interface used by this driver does not do any input validation and thus cannot be used for probing, the driver depends on the ACPI battery extension machanism to discover batteries.
The driver also supports a debugfs interface for retrieving buffers containing fan and thermal sensor information. Since the meaing of the content of those buffers is currently unknown, the interface is meant for reverse-engineering and will likely be replaced with an hwmon interface once the meaning has been understood.
The driver was tested on a Dell Inspiron 3505.
--- .../ABI/testing/debugfs-dell-wmi-ddv | 21 + .../ABI/testing/sysfs-platform-dell-wmi-ddv | 7 + MAINTAINERS | 7 + drivers/platform/x86/dell/Kconfig | 13 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-wmi-ddv.c | 361 ++++++++++++++++++ drivers/platform/x86/wmi.c | 1 + 7 files changed, 411 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-dell-wmi-ddv create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv create mode 100644 drivers/platform/x86/dell/dell-wmi-ddv.c
Documentation/ABI/testing/debugfs-dell-wmi-ddv new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/kernel/debug/dell-wmi-ddv-<wmi_device_name>/fan_sensor_information +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf <[email protected]> +Description: + This file contains the contents of the fan sensor information buffer, + which contains fan sensor entries and a terminating character (0xFF). + + Each fan sensor entry consists of three bytes with an unknown meaning, + interested people may use this file for reverse-engineering. + +What: /sys/kernel/debug/dell-wmi-ddv-<wmi_device_name>/thermal_sensor_information +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf <[email protected]> +Description: + This file contains the contents of the thermal sensor information buffer, + which contains thermal sensor entries and a terminating character (0xFF). + + Each thermal sensor entry consists of five bytes with an unknown meaning, + interested people may use this file for reverse-engineering.
Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/class/power_supply/<battery_name>/eppid +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf <[email protected]> +Description: + Reports the Dell ePPID (electronic Dell Piece Part Identification) + of the ACPI battery.
MAINTAINERS +7 -0
@@ -5821,6 +5821,13 @@ L: [email protected] S: Maintained F: drivers/platform/x86/dell/dell-wmi-descriptor.c +DELL WMI DDV DRIVER +M: Armin Wolf <[email protected]> +S: Maintained +F: Documentation/ABI/testing/debugfs-dell-wmi-ddv +F: Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv +F: drivers/platform/x86/dell/dell-wmi-ddv.c + DELL WMI SYSMAN DRIVER M: Divya Bharathi <[email protected]> M: Prasanth Ksr <[email protected]>
drivers/platform/x86/dell/Kconfig +13 -0
@@ -189,6 +189,19 @@ config DELL_WMI_DESCRIPTOR default n depends on ACPI_WMI +config DELL_WMI_DDV + tristate "Dell WMI sensors Support" + default m + depends on ACPI_BATTERY + depends on ACPI_WMI + help + This option adds support for WMI-based sensors like + battery temperature sensors found on some Dell notebooks. + It also supports reading of the battery ePPID. + + To compile this drivers as a module, choose M here: the module will + be called dell-wmi-ddv. + config DELL_WMI_LED tristate "External LED on Dell Business Netbooks" default m
drivers/platform/x86/dell/Makefile +1 -0
@@ -19,5 +19,6 @@ dell-wmi-objs := dell-wmi-base.o dell-wmi-$(CONFIG_DELL_WMI_PRIVACY) += dell-wmi-privacy.o obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o +obj-$(CONFIG_DELL_WMI_DDV) += dell-wmi-ddv.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/
drivers/platform/x86/dell/dell-wmi-ddv.c new file +361 -0
361 lines not on this page · raw message
drivers/platform/x86/wmi.c +1 -0
@@ -108,6 +108,7 @@ MODULE_DEVICE_TABLE(acpi, wmi_device_ids);/* allow duplicate GUIDs as these device drivers use struct wmi_driver */ static const char *const allow_duplicates[] = {"05901221-D566-11D1-B2F0-00A0C9062910" ,/* wmi-bmof */ +"8A42EA14-4F2A-FD45-6422-0087F7A7E608" ,/* dell-wmi-ddv */ NULL };
--
2.30.2
Quoted 17 lines · Armin Wolf
The dell-wmi-ddv driver adds support for reading the current temperature and ePPID of ACPI batteries on supported Dell machines.
Since the WMI interface used by this driver does not do any input validation and thus cannot be used for probing, the driver depends on the ACPI battery extension machanism to discover batteries.
The driver also supports a debugfs interface for retrieving buffers containing fan and thermal sensor information. Since the meaing of the content of those buffers is currently unknown, the interface is meant for reverse-engineering and will likely be replaced with an hwmon interface once the meaning has been understood.
The driver was tested on a Dell Inspiron 3505.
...
drivers/platform/x86/dell/Kconfig config DELL_WMI_DESCRIPTOR · line 194
Quoted 4 lines
drivers/platform/x86/dell/Kconfig +3
-0+config DELL_WMI_DDV + tristate "Dell WMI sensors Support" + default m
Why? (Imagine I have Dell, but old machine)
(And yes, I see that other Kconfig options are using it, but we shall avoid
cargo cult and each default choice like this has to be explained at least.)
...
Quoted 1 line
+ *
dell-wmi-ddv.c-- Linux driver for WMI sensor information on Dell notebooks.
Please, remove file name from the file. This will be an additional burden in the future in case it will be renamed.
...
Quoted 1 line
+#include <
acpi/battery.h>
Is it required to be the first? Otherwise it seems ACPI specific to me and the general rule is to put inclusions from generic towards custom. I.o.w. can you move it after linux/wmi.h with a blank line in between?
Quoted 12 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +12
-0+#include <linux/acpi.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/kstrtox.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/limits.h> +#include <linux/power_supply.h> +#include <linux/seq_file.h> +#include <linux/sysfs.h> +#include <linux/wmi.h>
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 55
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+struct dell_wmi_ddv_data { +struct acpi_battery_hook hook; +struct device_attribute temp_attr, eppid_attr;
It's hard to read and easy to miss that the data type has two members here. Please, put one member per one line.
Quoted 2 lines
(quoted diff) +2
-0+ struct wmi_device *wdev; +};
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 80
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+if (obj->type != type) { +kfree (obj); +return -EIO ;
EINVAL?
Quoted 1 line
(quoted diff) +1
-0+ }
...
Review
Quoted 1 line
(quoted diff) +1
-0+ kfree(obj);
I'm wondering what is the best to use in the drivers:
1) kfree()
2) acpi_os_free()
3) ACPI_FREE()
?
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 159
Quoted 7 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +6
-0+static int dell_wmi_ddv_battery_index (struct acpi_device *acpi_dev,u32 *index) +{ +const char *uid_str =acpi_device_uid (acpi_dev); + +if (!uid_str) +return -ENODEV ;
It will be better for maintaining to have
const char *uid_str...; uid_str = ... if (!uid_str) ...
Quoted 2 lines
(quoted diff) +2
-0+ return kstrtou32(uid_str, 10, index); +}
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 212
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+/* Return 0 instead of error to avoid being unloaded */ + ret =dell_wmi_ddv_battery_index (to_acpi_device (battery->dev.parent), &index); +if (ret <0 ) +return 0 ;
How index is used?
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 223
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +10
-0+ ret =device_create_file (&battery->dev, &data->temp_attr); +if (ret <0 ) +return ret; + + ret =device_create_file (&battery->dev, &data->eppid_attr); +if (ret <0 ) { +device_remove_file (&battery->dev, &data->temp_attr); + +return ret; + }
Why dev_groups member can't be utilized?
...
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)
Strictly speaking this should return int (see below).
drivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +13
-0+{ +struct dentry *entry; +char name[64 ]; + +scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);
return devm...
This is not related to debugfs and there is no rule to avoid checking error codes from devm_add_action_or_reset().
Quoted 1 line
+}
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+static struct wmi_driver dell_wmi_ddv_driver = { + .driver = { + .name =DRIVER_NAME ,
I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+ }, + .id_table = dell_wmi_ddv_id_table, + .probe = dell_wmi_ddv_probe, +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 19 lines · Andy Shevchenko
Quoted 9 lines · Armin Wolf
The dell-wmi-ddv driver adds support for reading the current temperature and ePPID of ACPI batteries on supported Dell machines.
Since the WMI interface used by this driver does not do any input validation and thus cannot be used for probing, the driver depends on the ACPI battery extension machanism to discover batteries.
Quoted 8 lines
The driver also supports a debugfs interface for retrieving buffers containing fan and thermal sensor information. Since the meaing of the content of those buffers is currently unknown, the interface is meant for reverse-engineering and will likely be replaced with an hwmon interface once the meaning has been understood.
The driver was tested on a Dell Inspiron 3505.
Quoted 8 lines
...
drivers/platform/x86/dell/Kconfig config DELL_WMI_DESCRIPTOR · line 194
Quoted 4 lines
drivers/platform/x86/dell/Kconfig +3
-0+config DELL_WMI_DDV + tristate "Dell WMI sensors Support" + default mWhy? (Imagine I have Dell, but old machine)
Then you can select N if you really want to.
Quoted 2 lines
(And yes, I see that other
Kconfigoptions are using it, but we shall avoid
cargo cult and each default choice like this has to be explained at least.)
This has been discussed during the review of v1 already.
There are quite a few dell modules and the choice has been made to put these all behind a dell platform drivers options and then default all the individual modules to 'm'.
Quoted 52 lines
...
Quoted 1 line
+ *
dell-wmi-ddv.c-- Linux driver for WMI sensor information on Dell notebooks.Please, remove file name from the file. This will be an additional burden in the future in case it will be renamed.
...
Quoted 1 line
+#include <
acpi/battery.h>Is it required to be the first? Otherwise it seems ACPI specific to me and the general rule is to put inclusions from generic towards custom. I.o.w. can you move it after
linux/wmi.hwith a blank line in between?Quoted 12 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +12
-0+#include <linux/acpi.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/kstrtox.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/limits.h> +#include <linux/power_supply.h> +#include <linux/seq_file.h> +#include <linux/sysfs.h> +#include <linux/wmi.h> ...
drivers/platform/x86/dell/dell-wmi-ddv.c line 55
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+struct dell_wmi_ddv_data { +struct acpi_battery_hook hook; +struct device_attribute temp_attr, eppid_attr;It's hard to read and easy to miss that the data type has two members here. Please, put one member per one line.
Quoted 2 lines
(quoted diff) +2
-0+ struct wmi_device *wdev; +};...
drivers/platform/x86/dell/dell-wmi-ddv.c line 80
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+if (obj->type != type) { +kfree (obj); +return -EIO ;EINVAL?
Quoted 1 line
(quoted diff) +1
-0+ }...
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ kfree(obj);I'm wondering what is the best to use in the drivers:
1)kfree()
2)acpi_os_free()
3)ACPI_FREE()?
Most ACPI driver code I know of just uses kfree() the other 2 are more ACPI-core / ACPICA internal helpers.
Quoted 24 lines
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 159
Quoted 7 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +6
-0+static int dell_wmi_ddv_battery_index (struct acpi_device *acpi_dev,u32 *index) +{ +const char *uid_str =acpi_device_uid (acpi_dev); + +if (!uid_str) +return -ENODEV ;It will be better for maintaining to have
const char *uid_str...; uid_str = ... if (!uid_str) ...Quoted 2 lines
(quoted diff) +2
-0+ return kstrtou32(uid_str, 10, index); +}...
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 212
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+/* Return 0 instead of error to avoid being unloaded */ + ret =dell_wmi_ddv_battery_index (to_acpi_device (battery->dev.parent), &index); +if (ret <0 ) +return 0 ;How index is used?
index is used in the registered sysfs attr show functions, so if this fails then the sysfs attr should not be registered.
Quoted 15 lines
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 223
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +10
-0+ ret =device_create_file (&battery->dev, &data->temp_attr); +if (ret <0 ) +return ret; + + ret =device_create_file (&battery->dev, &data->eppid_attr); +if (ret <0 ) { +device_remove_file (&battery->dev, &data->temp_attr); + +return ret; + }Why
dev_groupsmember can't be utilized?
Because this is an extension to the ACPI battery driver, IOW this adds extra attributes to the power-supply-class device registered by the ACPI battery driver. Note that the device in this case is managed by the power-supply-class code, so there is no access to dev_groups even in the ACPI battery code.
Quoted 37 lines
...
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
drivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +13
-0+{ +struct dentry *entry; +char name[64 ]; + +scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().Quoted 1 line
+}
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+static struct wmi_driver dell_wmi_ddv_driver = { + .driver = { + .name =DRIVER_NAME ,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
Quoted 5 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 356
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+ }, + .id_table = dell_wmi_ddv_id_table, + .probe = dell_wmi_ddv_probe, +};
Regards,
Hans
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Tue, Sep 27, 2022 at 10:45:21PM +0200, Armin Wolf wrote:
...
Quoted 6 lines
Quoted 3 lines
drivers/platform/x86/dell/Kconfig config DELL_WMI_DESCRIPTOR · line 194
Quoted 1 line
drivers/platform/x86/dell/Kconfig +1
-0+ default mWhy? (Imagine I have Dell, but old machine)
Then you can select N if you really want to.
Quoted 8 lines
Quoted 2 lines
(And yes, I see that other
Kconfigoptions are using it, but we shall avoid
cargo cult and each default choice like this has to be explained at least.)This has been discussed during the review of v1 already.
There are quite a few dell modules and the choice has been made to put these all behind a dell platform drivers options and then default all the individual modules to 'm'.
Okay, thanks for pointing out that this was discussed. I was not aware.
...
Quoted 11 lines
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ kfree(obj);I'm wondering what is the best to use in the drivers:
1)kfree()
2)acpi_os_free()
3)ACPI_FREE()?
Most ACPI driver code I know of just uses
kfree()the other 2 are more ACPI-core / ACPICA internal helpers.
To me 2) would look more consistent, esp. in case if it is extended in the future.
...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+ ret =device_create_file (&battery->dev, &data->temp_attr); +if (ret <0 ) +return ret; +Quoted 8 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 223
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +6
-0+ ret =device_create_file (&battery->dev, &data->eppid_attr); +if (ret <0 ) { +device_remove_file (&battery->dev, &data->temp_attr); + +return ret; + }Why
dev_groupsmember can't be utilized?
Quoted 5 lines
Because this is an extension to the ACPI battery driver, IOW this adds extra attributes to the power-supply-class device registered by the ACPI battery driver. Note that the device in this case is managed by the power-supply-class code, so there is no access to
dev_groupseven in the ACPI battery code.
Ah, I see now, so we extend the attributes of the 3rd party driver here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Armin Wolf
maintainerAm 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 61 lines · Armin Wolf
Quoted 17 lines
The dell-wmi-ddv driver adds support for reading the current temperature and ePPID of ACPI batteries on supported Dell machines.
Since the WMI interface used by this driver does not do any input validation and thus cannot be used for probing, the driver depends on the ACPI battery extension machanism to discover batteries.
The driver also supports a debugfs interface for retrieving buffers containing fan and thermal sensor information. Since the meaing of the content of those buffers is currently unknown, the interface is meant for reverse-engineering and will likely be replaced with an hwmon interface once the meaning has been understood.
The driver was tested on a Dell Inspiron 3505.
...
drivers/platform/x86/dell/Kconfig config DELL_WMI_DESCRIPTOR · line 194
Quoted 3 lines
drivers/platform/x86/dell/Kconfig +3
-0+config DELL_WMI_DDV + tristate "Dell WMI sensors Support" + default mWhy? (Imagine I have Dell, but old machine)
(And yes, I see that other
Kconfigoptions are using it, but we shall avoid
cargo cult and each default choice like this has to be explained at least.)...
Quoted 1 line
+ *
dell-wmi-ddv.c-- Linux driver for WMI sensor information on Dell notebooks.Please, remove file name from the file. This will be an additional burden in the future in case it will be renamed.
...
Quoted 1 line
+#include <
acpi/battery.h>Is it required to be the first? Otherwise it seems ACPI specific to me and the general rule is to put inclusions from generic towards custom. I.o.w. can you move it after
linux/wmi.hwith a blank line in between?Quoted 12 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +12
-0+#include <linux/acpi.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/kstrtox.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/limits.h> +#include <linux/power_supply.h> +#include <linux/seq_file.h> +#include <linux/sysfs.h> +#include <linux/wmi.h> ...
drivers/platform/x86/dell/dell-wmi-ddv.c line 55
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+struct dell_wmi_ddv_data { +struct acpi_battery_hook hook; +struct device_attribute temp_attr, eppid_attr;It's hard to read and easy to miss that the data type has two members here. Please, put one member per one line.
Quoted 8 lines
Quoted 2 lines
(quoted diff) +2
-0+ struct wmi_device *wdev; +};...
drivers/platform/x86/dell/dell-wmi-ddv.c line 80
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+if (obj->type != type) { +kfree (obj); +return -EIO ;EINVAL?
In my opinion, EINVAL should be returned if the parameters are invalid. In this case however, the error comes from the wmi device returning invalid data, which would be represented better with EIO.
Quoted 71 lines
Quoted 1 line
(quoted diff) +1
-0+ }...
Review
Quoted 1 line
(quoted diff) +1
-0+ kfree(obj);I'm wondering what is the best to use in the drivers:
1)kfree()
2)acpi_os_free()
3)ACPI_FREE()?
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 159
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +6
-0+static int dell_wmi_ddv_battery_index (struct acpi_device *acpi_dev,u32 *index) +{ +const char *uid_str =acpi_device_uid (acpi_dev); + +if (!uid_str) +return -ENODEV ;It will be better for maintaining to have
const char *uid_str...; uid_str = ... if (!uid_str) ...Quoted 2 lines
(quoted diff) +2
-0+ return kstrtou32(uid_str, 10, index); +}...
drivers/platform/x86/dell/dell-wmi-ddv.c line 212
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+/* Return 0 instead of error to avoid being unloaded */ + ret =dell_wmi_ddv_battery_index (to_acpi_device (battery->dev.parent), &index); +if (ret <0 ) +return 0 ;How index is used?
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 223
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +10
-0+ ret =device_create_file (&battery->dev, &data->temp_attr); +if (ret <0 ) +return ret; + + ret =device_create_file (&battery->dev, &data->eppid_attr); +if (ret <0 ) { +device_remove_file (&battery->dev, &data->temp_attr); + +return ret; + }Why
dev_groupsmember can't be utilized?...
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
drivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +13
-0+{ +struct dentry *entry; +char name[64 ]; + +scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
Quoted 3 lines
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().
According to the documentation of debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value of dell_wmi_ddv_debugfs_init() would be ignored when called, which means that returning an error would serve no purpose. Additionally, devm_add_action_or_reset() automatically executes the cleanup function if devres registration fails, so we do not have to care about that.
Quoted 8 lines
Quoted 1 line
+}
...
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +3
-0+static struct wmi_driver dell_wmi_ddv_driver = { + .driver = { + .name =DRIVER_NAME ,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both.
Armin Wolf
Quoted 4 lines
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+ }, + .id_table = dell_wmi_ddv_id_table, + .probe = dell_wmi_ddv_probe, +};
Quoted 2 lines · Armin Wolf
Am 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 1 line · Armin Wolf
...
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
drivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +13
-0+{ +struct dentry *entry; +char name[64 ]; + +scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
Quoted 8 lines
Quoted 3 lines
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().According to the documentation of
debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value ofdell_wmi_ddv_debugfs_init()would be ignored when called, which means that returning an error would serve no purpose. Additionally,devm_add_action_or_reset()automatically executes the cleanup function if devres registration fails, so we do not have to care about that.
The problem with your code that if devm_ call fails and you ain't stop probing the remove-insert module (or unbind-bind) cycle will fail, because of existing (leaked) debugfs dentries.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+}
That said, you must check error code of devm_ call above. This is a potential leak of resources right now in the code.
...
Quoted 6 lines
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 1 line
drivers/platform/x86/dell/dell-wmi-ddv.c new file +1
-0+ .name = DRIVER_NAME,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both.
Which is exactly what we must prevent developer to do. If changing debugfs it mustn't change the driver name, because the latter is ABI, while the former is not.
I think now you got my point.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 33 lines · Andy Shevchenko
Quoted 2 lines · Armin Wolf
Am 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 1 line · Armin Wolf
...
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
drivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +13
-0+{ +struct dentry *entry; +char name[64 ]; + +scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
Quoted 8 lines
Quoted 3 lines
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().According to the documentation of
debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value ofdell_wmi_ddv_debugfs_init()would be ignored when called, which means that returning an error would serve no purpose. Additionally,devm_add_action_or_reset()automatically executes the cleanup function if devres registration fails, so we do not have to care about that.
Quoted 3 lines
The problem with your code that if
devm_call fails and you ain't stop probing the remove-insert module (or unbind-bind) cycle will fail, because of existing (leaked) debugfs dentries.
No it won't if the devm_ call fails then it will directly call the passed in handler so in this case we can simply continue without debugfs entries (which will have been removed by the handler). The directly calling of the action handler on failure is the whole difference between devm_add_action() and devm_add_action_or_reset()
So using it this way in the case of a debugfs init function is fine.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 1 line
drivers/platform/x86/dell/dell-wmi-ddv.c new file +1
-0+ .name = DRIVER_NAME,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both.
Which is exactly what we must prevent developer to do. If changing debugfs it mustn't change the driver name, because the latter is ABI, while the former is not.
Arguably both are not really ABI. Drivers have been renamed in the past without issues for userspace.
Regards,
Hans
Armin Wolf
maintainerAm 29.09.22 um 15:12 schrieb Hans de Goede:
Quoted 56 lines
Hi,
Quoted 27 lines · Andy Shevchenko
Quoted 2 lines · Armin Wolf
Am 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 1 line · Armin Wolf
...
Quoted 22 lines
Quoted 22 lines
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+{ +struct dentry *entry; +char name[64 ]; +Fujitsu Academydrivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +9
-0+scnprintf (name,ARRAY_SIZE (name),"%s-%s" ,DRIVER_NAME ,dev_name (&wdev->dev)); + entry =debugfs_create_dir (name,NULL ); + +debugfs_create_devm_seqfile (&wdev->dev,"fan_sensor_information" , entry, + dell_wmi_ddv_fan_read); +debugfs_create_devm_seqfile (&wdev->dev,"thermal_sensor_information" , entry, + dell_wmi_ddv_temp_read); + +devm_add_action_or_reset (&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().Quoted 8 lines
Quoted 5 lines
According to the documentation of
debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value ofdell_wmi_ddv_debugfs_init()would be ignored when called, which means that returning an error would serve no purpose. Additionally,devm_add_action_or_reset()automatically executes the cleanup function if devres registration fails, so we do not have to care about that.The problem with your code that if
devm_call fails and you ain't stop probing the remove-insert module (or unbind-bind) cycle will fail, because of existing (leaked) debugfs dentries.No it won't if the
devm_call fails then it will directly call the passed in handler so in this case we can simply continue without debugfs entries (which will have been removed by the handler). The directly calling of the action handler on failure is the whole difference betweendevm_add_action()anddevm_add_action_or_reset()So using it this way in the case of a debugfs init function is fine.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
drivers/platform/x86/dell/dell-wmi-ddv.c line 352
Quoted 1 line
drivers/platform/x86/dell/dell-wmi-ddv.c new file +1
-0+ .name = DRIVER_NAME,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both.
Which is exactly what we must prevent developer to do. If changing debugfs it mustn't change the driver name, because the latter is ABI, while the former is not.
Quoted 7 lines
Arguably both are not really ABI. Drivers have been renamed in the past without issues for userspace.
Regards,
Hans
What is the current status of this patch set? If necessary, i can submit an v3 patch set which includes the patch regarding the minor style fixes. I also tested the driver on my Dell Insprion 3505 for some time, so i can proof it works.
Armin Wolf
Hi Armin, Rafael,
Quoted 58 lines · Armin Wolf
Am 29.09.22 um 15:12 schrieb Hans de Goede:
Quoted 56 lines
Hi,
Quoted 27 lines · Andy Shevchenko
Quoted 2 lines · Armin Wolf
Am 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 1 line · Armin Wolf
...
Quoted 22 lines
Quoted 22 lines
Quoted 1 line
+static void
dell_wmi_ddv_debugfs_init(struct wmi_device *wdev)Strictly speaking this should return int (see below).
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +4
-0+{ + struct dentry *entry; + char name[64]; +Fujitsu Academydrivers/platform/x86/dell/dell-wmi-ddv.c line 315
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-ddv.c new file +9
-0+ scnprintf(name, ARRAY_SIZE(name), "%s-%s", DRIVER_NAME, dev_name(&wdev->dev)); + entry = debugfs_create_dir(name, NULL); + + debugfs_create_devm_seqfile(&wdev->dev, "fan_sensor_information", entry, + dell_wmi_ddv_fan_read); + debugfs_create_devm_seqfile(&wdev->dev, "thermal_sensor_information", entry, + dell_wmi_ddv_temp_read); + + devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_debugfs_remove, entry);return devm...
This is not related to debugfs and there is no rule to avoid checking error codes from
devm_add_action_or_reset().Quoted 8 lines
Quoted 5 lines
According to the documentation of
debugfs_create_dir(), drivers should work fine if debugfs initialization fails. Thus the the return value ofdell_wmi_ddv_debugfs_init()would be ignored when called, which means that returning an error would serve no purpose. Additionally,devm_add_action_or_reset()automatically executes the cleanup function if devres registration fails, so we do not have to care about that.The problem with your code that if
devm_call fails and you ain't stop probing the remove-insert module (or unbind-bind) cycle will fail, because of existing (leaked) debugfs dentries.No it won't if the
devm_call fails then it will directly call the passed in handler so in this case we can simply continue without debugfs entries (which will have been removed by the handler). The directly calling of the action handler on failure is the whole difference betweendevm_add_action()anddevm_add_action_or_reset()So using it this way in the case of a debugfs init function is fine.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ .name =
DRIVER_NAME,I would use explicit literal since this is a (semi-) ABI, and having it as a define feels not fully right.
The driver name is used in two places (init and debugfs), so having a define for it avoids problems in case someone forgets to change both.
Which is exactly what we must prevent developer to do. If changing debugfs it mustn't change the driver name, because the latter is ABI, while the former is not.
Quoted 8 lines
Quoted 7 lines
Arguably both are not really ABI. Drivers have been renamed in the past without issues for userspace.
Regards,
Hans
What is the current status of this patch set?
I indicated to Rafael (ACPI subsys maintainer) that I consider this ready for merging and tried to coordinate this with Rafael, but that email seems to have fallen through the cracks, likely due to it being pretty close to the 6.1 merge window. So lets try again:
Rafael, from my pov this patch-set is ready for merging, since 2/2 depends on "[PATCH v2 1/2] ACPI: battery: Pass battery hook pointer to hook callbacks" we need to coordinate this.
Since even patch 1/2 mostly touches files under drivers/platform/x86 I would prefer to merge this through the pdx86 tree, may I have your ack for this ?
Quoted 3 lines
If necessary, i can submit an v3 patch set which includes the
patch regarding the minor style fixes. I also tested the driver on my Dell Insprion 3505 for some time, so i can proof it works.
I can squash the follow up patch into 2/2 when merging this myself. From my pov no action is needed from you on this at this moment on time. But it is good that you send a friendly ping about this :)
Regards,
Hans
Quoted 2 lines · Armin Wolf
Am 28.09.22 um 12:47 schrieb Andy Shevchenko:
Quoted 1 line · Armin Wolf
Side note: When answering to emails, please remove unrelated context, do not make this the answering party problem.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 39 lines · Armin Wolf
This patch series adds a new driver for a WMI interface found in many newer Dell machines. This interface allows to read battery properties like temperature and the ePPID (Dell-specific), while also providing fan and thermal sensor information.
The interface does support multiple batteries which are indentified by an "index", which appears to be the battery ACPI UID. Since the interface also appears to omit any bounts checking of the index, the ACPI battery hook mechanism is used to discover batteries.
Since the information returned when querying fan/thermal sensor information is currently unknown, a debugfs entry is created to allow for easier reverse engineering. The interface is likely to be replaced by a proper hwmon interface in the future.
Since the driver can potentially be instantiated multiple times, the ACPI battery hook mechanism had to be extended.
The first patch passes a pointer to the battery hook to the hook callbacks, so that they can access instance-specific data with
container_of().The second patch finally adds the new driver. It was called dell-wmi-ddv since the interface is called "DDV" by Dell software, likely meaning "Dell Data Vault".
The driver was tested, together with the changes made to the ACPI battery driver, on a Dell Inspiron 3505. Other drivers already using the battery hook mechanism where changed as well, but could only be compile-tested due to missing hardware.
---
Changes in v2:
- Significantly lower the amount of changes being made to the acpi battery driver
- drop unnecessary ABI description of the temp attribute
- return 0 when a unsupported battery is found to avoid being unloaded
Quoted 3 lines
Armin Wolf (2):
ACPI: battery: Pass battery hook pointer to hook callbacks platform/x86: dell: Add new dell-wmi-ddv driver
Thanks.
The new version looks good to me:
for the series.
Rafael, from my POV this can be merged through either your tree or mine. Feel free to merge this through your tree, or please give your Ack for merging through mine (assuming you are ok with the changes of course).
Regards,
Hans
Quoted 48 lines · Hans de Goede
Quoted 39 lines · Armin Wolf
This patch series adds a new driver for a WMI interface found in many newer Dell machines. This interface allows to read battery properties like temperature and the ePPID (Dell-specific), while also providing fan and thermal sensor information.
The interface does support multiple batteries which are indentified by an "index", which appears to be the battery ACPI UID. Since the interface also appears to omit any bounts checking of the index, the ACPI battery hook mechanism is used to discover batteries.
Since the information returned when querying fan/thermal sensor information is currently unknown, a debugfs entry is created to allow for easier reverse engineering. The interface is likely to be replaced by a proper hwmon interface in the future.
Since the driver can potentially be instantiated multiple times, the ACPI battery hook mechanism had to be extended.
The first patch passes a pointer to the battery hook to the hook callbacks, so that they can access instance-specific data with
container_of().The second patch finally adds the new driver. It was called dell-wmi-ddv since the interface is called "DDV" by Dell software, likely meaning "Dell Data Vault".
The driver was tested, together with the changes made to the ACPI battery driver, on a Dell Inspiron 3505. Other drivers already using the battery hook mechanism where changed as well, but could only be compile-tested due to missing hardware.
---
Changes in v2:
- Significantly lower the amount of changes being made to the acpi battery driver
- drop unnecessary ABI description of the temp attribute
- return 0 when a unsupported battery is found to avoid being unloadedQuoted 3 lines
Armin Wolf (2):
ACPI: battery: Pass battery hook pointer to hook callbacks platform/x86: dell: Add new dell-wmi-ddv driverThanks.
The new version looks good to me:
Quoted 8 lines
Reviewed-by Hans de Goede <[email protected]>for the series.
Rafael, from my POV this can be merged through either your tree or mine. Feel free to merge this through your tree, or please give your Ack for merging through mine (assuming you are ok with the changes of course).
I gave some comments, but it's up to you if they have to be addressed now or as a follow up.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 53 lines · Andy Shevchenko
Quoted 52 lines · Hans de Goede
Quoted 39 lines · Armin Wolf
This patch series adds a new driver for a WMI interface found in many newer Dell machines. This interface allows to read battery properties like temperature and the ePPID (Dell-specific), while also providing fan and thermal sensor information.
The interface does support multiple batteries which are indentified by an "index", which appears to be the battery ACPI UID. Since the interface also appears to omit any bounts checking of the index, the ACPI battery hook mechanism is used to discover batteries.
Since the information returned when querying fan/thermal sensor information is currently unknown, a debugfs entry is created to allow for easier reverse engineering. The interface is likely to be replaced by a proper hwmon interface in the future.
Since the driver can potentially be instantiated multiple times, the ACPI battery hook mechanism had to be extended.
The first patch passes a pointer to the battery hook to the hook callbacks, so that they can access instance-specific data with
container_of().The second patch finally adds the new driver. It was called dell-wmi-ddv since the interface is called "DDV" by Dell software, likely meaning "Dell Data Vault".
The driver was tested, together with the changes made to the ACPI battery driver, on a Dell Inspiron 3505. Other drivers already using the battery hook mechanism where changed as well, but could only be compile-tested due to missing hardware.
---
Changes in v2:
- Significantly lower the amount of changes being made to the acpi battery driver
- drop unnecessary ABI description of the temp attribute
- return 0 when a unsupported battery is found to avoid being unloadedQuoted 3 lines
Armin Wolf (2):
ACPI: battery: Pass battery hook pointer to hook callbacks platform/x86: dell: Add new dell-wmi-ddv driverThanks.
The new version looks good to me:
Reviewed-by Hans de Goede <[email protected]>for the series.
Quoted 7 lines
Quoted 4 lines
Rafael, from my POV this can be merged through either your tree or mine. Feel free to merge this through your tree, or please give your Ack for merging through mine (assuming you are ok with the changes of course).
I gave some comments, but it's up to you if they have to be addressed now or as a follow up.
I have answered a couple of your comments.
What remains is very small / trivial. So IMHO this can go in as is and then a follow-up patch can be done to address your remaining comments. Armin, can you do a follow-up patch addressing Andy's remaining comments please?
I guess it also depends on Rafael and if Rafael is ok with taking this for 6.1 or if this is going to be 6.2 material.
If this is going to be delayed till 6.2, then we can squash in the follow-up patch while merging.
Regards,
Hans