platform/x86: dell-ddv: Rework battery temperature handling
Subsystems (2)
Armin Wolf
maintainercover platform/x86: dell-ddv: Rework battery temperature handling
This patch series reworks the handling of the battery temperature inside the dell-wmi-ddv driver.
The first patch fixes an issue inside the calculation formula for the temperature value that resulted in strange temperature values like 29.1 degrees celcius.
The second patch then simplifies the battery hook handling by using devm_battery_hook_register().
The third patch finally makes use of the new power supply extension mechanism to expose the battery temperature to userspace. The power supply extension mechanism also takes care that the temperature shows up inside the hwmon interface of the associated battery.
All patches where tested on a Dell Inspiron 3505 and appear to work.
Armin Wolf (3):
platform/x86: dell-ddv: Fix temperature calculation platform/x86: dell-ddv: Use devm_battery_hook_register platform/x86: dell-ddv: Use the power supply extension mechanism
drivers/platform/x86/dell/dell-wmi-ddv.c | 84 +++++++++++++----------- 1 file changed, 46 insertions(+), 38 deletions(-)
--
2.39.5
Armin Wolf
maintainerPATCH 1/3 platform/x86: dell-ddv: Fix temperature calculation
On the Dell Inspiron 3505 the battery temperature is always 0.1 degrees larger than the temperature show inside the OEM application.
Emulate this behaviour to avoid showing strange looking values like 29.1 degrees.
--- drivers/platform/x86/dell/dell-wmi-ddv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +4 -2
@@ -665,8 +665,10 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *attr, charif (ret <0 )return ret; -/* Use 2731 instead of 2731.5 to avoid unnecessary rounding */ -return sysfs_emit (buf,"%d\n" , value -2731 ); +/* Use 2732 instead of 2731.5 to avoid unnecessary rounding and to emulate +* the behaviour of the OEM application which seems to round down the result. +*/ +return sysfs_emit (buf,"%d\n" , value -2732 ); }static ssize_t eppid_show (struct device *dev,struct device_attribute *attr,char *buf)
--
2.39.5
Armin Wolf
maintainerPATCH 2/3 platform/x86: dell-ddv: Use devm_battery_hook_register
In reply to Armin WolfUse devm_battery_hook_register() instead of manually calling devm_add_action_or_reset() to simplify the code.
--- drivers/platform/x86/dell/dell-wmi-ddv.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +1 -10
@@ -732,13 +732,6 @@ static int dell_wmi_ddv_remove_battery(struct power_supply *battery, struct acpireturn 0 ; } -static void dell_wmi_ddv_battery_remove (void *data) -{ -struct acpi_battery_hook *hook = data; - -battery_hook_unregister (hook); -} -static int dell_wmi_ddv_battery_add (struct dell_wmi_ddv_data *data) { data->hook.name ="Dell DDV Battery Extension" ;
@@ -755,9 +748,7 @@ static int dell_wmi_ddv_battery_add(struct dell_wmi_ddv_data *data) data->eppid_attr.attr.mode =0444 ; data->eppid_attr.show = eppid_show; -battery_hook_register (&data->hook); - -return devm_add_action_or_reset (&data->wdev->dev, dell_wmi_ddv_battery_remove, &data->hook); +return devm_battery_hook_register (&data->wdev->dev, &data->hook); }static int dell_wmi_ddv_buffer_read (struct seq_file *seq,enum dell_ddv_method method)
--
2.39.5
Armin Wolf
maintainerPATCH 3/3 platform/x86: dell-ddv: Use the power supply extension mechanism
In reply to Armin WolfUse the power supply extension mechanism for registering the battery temperature properties so that they can show up in the hwmon device associated with the ACPI battery.
--- drivers/platform/x86/dell/dell-wmi-ddv.c | 75 ++++++++++++++---------- 1 file changed, 45 insertions(+), 30 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +45 -30
@@ -104,7 +104,6 @@ struct dell_wmi_ddv_sensors {struct dell_wmi_ddv_data {struct acpi_battery_hook hook; -struct device_attribute temp_attr;struct device_attribute eppid_attr;struct dell_wmi_ddv_sensors fans;struct dell_wmi_ddv_sensors temps;
@@ -651,26 +650,6 @@ static int dell_wmi_ddv_battery_index(struct acpi_device *acpi_dev, u32 *index)return kstrtou32 (uid_str,10 , index); } -static ssize_t temp_show (struct device *dev,struct device_attribute *attr,char *buf) -{ - struct dell_wmi_ddv_data *data = container_of(attr, struct dell_wmi_ddv_data, temp_attr); -u32 index, value; -int ret; - - ret =dell_wmi_ddv_battery_index (to_acpi_device (dev->parent), &index); -if (ret <0 ) -return ret; - - ret =dell_wmi_ddv_query_integer (data->wdev,DELL_DDV_BATTERY_TEMPERATURE , index, &value); -if (ret <0 ) -return ret; - -/* Use 2732 instead of 2731.5 to avoid unnecessary rounding and to emulate -* the behaviour of the OEM application which seems to round down the result. -*/ -return sysfs_emit (buf,"%d\n" , value -2732 ); -} -static ssize_t eppid_show (struct device *dev,struct device_attribute *attr,char *buf) { struct dell_wmi_ddv_data *data = container_of(attr, struct dell_wmi_ddv_data, eppid_attr);
@@ -697,6 +676,46 @@ static ssize_t eppid_show(struct device *dev, struct device_attribute *attr, chareturn ret; } +static int dell_wmi_ddv_get_property (struct power_supply *psy,const struct power_supply_ext *ext, +void *drvdata,enum power_supply_property psp, +union power_supply_propval *val) +{ +struct dell_wmi_ddv_data *data = drvdata; +u32 index, value; +int ret; + + ret =dell_wmi_ddv_battery_index (to_acpi_device (psy->dev.parent), &index); +if (ret <0 ) +return ret; + +switch (psp) { +case POWER_SUPPLY_PROP_TEMP : + ret =dell_wmi_ddv_query_integer (data->wdev,DELL_DDV_BATTERY_TEMPERATURE , index, + &value); +if (ret <0 ) +return ret; + +/* Use 2732 instead of 2731.5 to avoid unnecessary rounding and to emulate +* the behaviour of the OEM application which seems to round down the result. +*/ + val->intval = value -2732 ; +return 0 ; +default : +return -EINVAL ; + } +} + +static const enum power_supply_property dell_wmi_ddv_properties[] = { +POWER_SUPPLY_PROP_TEMP , +}; + +static const struct power_supply_ext dell_wmi_ddv_extension = { + .name =DRIVER_NAME , + .properties = dell_wmi_ddv_properties, + .num_properties =ARRAY_SIZE (dell_wmi_ddv_properties), + .get_property = dell_wmi_ddv_get_property, +}; +static int dell_wmi_ddv_add_battery (struct power_supply *battery,struct acpi_battery_hook *hook) { struct dell_wmi_ddv_data *data = container_of(hook, struct dell_wmi_ddv_data, hook);
@@ -708,13 +727,14 @@ static int dell_wmi_ddv_add_battery(struct power_supply *battery, struct acpi_baif (ret <0 )return 0 ; - ret =device_create_file (&battery->dev, &data->temp_attr); + ret =device_create_file (&battery->dev, &data->eppid_attr);if (ret <0 )return ret; - ret =device_create_file (&battery->dev, &data->eppid_attr); + ret =power_supply_register_extension (battery, &dell_wmi_ddv_extension, &data->wdev->dev, + data);if (ret <0 ) { -device_remove_file (&battery->dev, &data->temp_attr); +device_remove_file (&battery->dev, &data->eppid_attr);return ret; }
@@ -726,8 +746,8 @@ static int dell_wmi_ddv_remove_battery(struct power_supply *battery, struct acpi { struct dell_wmi_ddv_data *data = container_of(hook, struct dell_wmi_ddv_data, hook); -device_remove_file (&battery->dev, &data->temp_attr);device_remove_file (&battery->dev, &data->eppid_attr); +power_supply_unregister_extension (battery, &dell_wmi_ddv_extension);return 0 ; }
@@ -738,11 +758,6 @@ static int dell_wmi_ddv_battery_add(struct dell_wmi_ddv_data *data) data->hook.add_battery = dell_wmi_ddv_add_battery; data->hook.remove_battery = dell_wmi_ddv_remove_battery; -sysfs_attr_init (&data->temp_attr.attr); - data->temp_attr.attr.name ="temp" ; - data->temp_attr.attr.mode =0444 ; - data->temp_attr.show = temp_show; -sysfs_attr_init (&data->eppid_attr.attr); data->eppid_attr.attr.name ="eppid" ; data->eppid_attr.attr.mode =0444 ;
--
2.39.5
Hi,
Quoted 10 lines · Armin Wolf
This patch series reworks the handling of the battery temperature inside the dell-wmi-ddv driver.
The first patch fixes an issue inside the calculation formula for the temperature value that resulted in strange temperature values like 29.1 degrees celcius.
The second patch then simplifies the battery hook handling by using
devm_battery_hook_register().
Quoted 6 lines
The third patch finally makes use of the new power supply extension mechanism to expose the battery temperature to userspace. The power supply extension mechanism also takes care that the temperature shows up inside the hwmon interface of the associated battery.
All patches where tested on a Dell Inspiron 3505 and appear to work.
LGTM.
-- Sebastian
Quoted 12 lines
Armin Wolf (3):
platform/x86: dell-ddv: Fix temperature calculation platform/x86: dell-ddv: Usedevm_battery_hook_registerplatform/x86: dell-ddv: Use the power supply extension mechanismdrivers/platform/x86/dell/dell-wmi-ddv.c | 84 +++++++++++++----------- 1 file changed, 46 insertions(+), 38 deletions(-)--
2.39.5
Ilpo Järvinen
maintainerQuoted 8 lines · Armin Wolf
This patch series reworks the handling of the battery temperature inside the dell-wmi-ddv driver.
The first patch fixes an issue inside the calculation formula for the temperature value that resulted in strange temperature values like 29.1 degrees celcius.
[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
The list of commits applied:
[1/3] platform/x86: dell-ddv: Fix temperature calculation
commit: 7a248294a3145bc65eb0d8980a0a8edbb1b92db4
[2/3] platform/x86: dell-ddv: Use devm_battery_hook_register
commit: 8dc3f0161e35d6ceb12de4a70cbed593e5b0583f
[3/3] platform/x86: dell-ddv: Use the power supply extension mechanism
commit: 99923a0df7852311fa3d01eaddb430c958780143--
i.