Skip to content

Commit 99923a0

Browse files
Wer-Wolfij-intel
authored andcommitted
platform/x86: dell-ddv: Use the power supply extension mechanism
Use 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. Signed-off-by: Armin Wolf <[email protected]> Reviewed-by: Sebastian Reichel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 8dc3f01 commit 99923a0

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

drivers/platform/x86/dell/dell-wmi-ddv.c

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ struct dell_wmi_ddv_sensors {
104104

105105
struct dell_wmi_ddv_data {
106106
struct acpi_battery_hook hook;
107-
struct device_attribute temp_attr;
108107
struct device_attribute eppid_attr;
109108
struct dell_wmi_ddv_sensors fans;
110109
struct dell_wmi_ddv_sensors temps;
@@ -651,26 +650,6 @@ static int dell_wmi_ddv_battery_index(struct acpi_device *acpi_dev, u32 *index)
651650
return kstrtou32(uid_str, 10, index);
652651
}
653652

654-
static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char *buf)
655-
{
656-
struct dell_wmi_ddv_data *data = container_of(attr, struct dell_wmi_ddv_data, temp_attr);
657-
u32 index, value;
658-
int ret;
659-
660-
ret = dell_wmi_ddv_battery_index(to_acpi_device(dev->parent), &index);
661-
if (ret < 0)
662-
return ret;
663-
664-
ret = dell_wmi_ddv_query_integer(data->wdev, DELL_DDV_BATTERY_TEMPERATURE, index, &value);
665-
if (ret < 0)
666-
return ret;
667-
668-
/* Use 2732 instead of 2731.5 to avoid unnecessary rounding and to emulate
669-
* the behaviour of the OEM application which seems to round down the result.
670-
*/
671-
return sysfs_emit(buf, "%d\n", value - 2732);
672-
}
673-
674653
static ssize_t eppid_show(struct device *dev, struct device_attribute *attr, char *buf)
675654
{
676655
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, cha
697676
return ret;
698677
}
699678

679+
static int dell_wmi_ddv_get_property(struct power_supply *psy, const struct power_supply_ext *ext,
680+
void *drvdata, enum power_supply_property psp,
681+
union power_supply_propval *val)
682+
{
683+
struct dell_wmi_ddv_data *data = drvdata;
684+
u32 index, value;
685+
int ret;
686+
687+
ret = dell_wmi_ddv_battery_index(to_acpi_device(psy->dev.parent), &index);
688+
if (ret < 0)
689+
return ret;
690+
691+
switch (psp) {
692+
case POWER_SUPPLY_PROP_TEMP:
693+
ret = dell_wmi_ddv_query_integer(data->wdev, DELL_DDV_BATTERY_TEMPERATURE, index,
694+
&value);
695+
if (ret < 0)
696+
return ret;
697+
698+
/* Use 2732 instead of 2731.5 to avoid unnecessary rounding and to emulate
699+
* the behaviour of the OEM application which seems to round down the result.
700+
*/
701+
val->intval = value - 2732;
702+
return 0;
703+
default:
704+
return -EINVAL;
705+
}
706+
}
707+
708+
static const enum power_supply_property dell_wmi_ddv_properties[] = {
709+
POWER_SUPPLY_PROP_TEMP,
710+
};
711+
712+
static const struct power_supply_ext dell_wmi_ddv_extension = {
713+
.name = DRIVER_NAME,
714+
.properties = dell_wmi_ddv_properties,
715+
.num_properties = ARRAY_SIZE(dell_wmi_ddv_properties),
716+
.get_property = dell_wmi_ddv_get_property,
717+
};
718+
700719
static int dell_wmi_ddv_add_battery(struct power_supply *battery, struct acpi_battery_hook *hook)
701720
{
702721
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_ba
708727
if (ret < 0)
709728
return 0;
710729

711-
ret = device_create_file(&battery->dev, &data->temp_attr);
730+
ret = device_create_file(&battery->dev, &data->eppid_attr);
712731
if (ret < 0)
713732
return ret;
714733

715-
ret = device_create_file(&battery->dev, &data->eppid_attr);
734+
ret = power_supply_register_extension(battery, &dell_wmi_ddv_extension, &data->wdev->dev,
735+
data);
716736
if (ret < 0) {
717-
device_remove_file(&battery->dev, &data->temp_attr);
737+
device_remove_file(&battery->dev, &data->eppid_attr);
718738

719739
return ret;
720740
}
@@ -726,8 +746,8 @@ static int dell_wmi_ddv_remove_battery(struct power_supply *battery, struct acpi
726746
{
727747
struct dell_wmi_ddv_data *data = container_of(hook, struct dell_wmi_ddv_data, hook);
728748

729-
device_remove_file(&battery->dev, &data->temp_attr);
730749
device_remove_file(&battery->dev, &data->eppid_attr);
750+
power_supply_unregister_extension(battery, &dell_wmi_ddv_extension);
731751

732752
return 0;
733753
}
@@ -738,11 +758,6 @@ static int dell_wmi_ddv_battery_add(struct dell_wmi_ddv_data *data)
738758
data->hook.add_battery = dell_wmi_ddv_add_battery;
739759
data->hook.remove_battery = dell_wmi_ddv_remove_battery;
740760

741-
sysfs_attr_init(&data->temp_attr.attr);
742-
data->temp_attr.attr.name = "temp";
743-
data->temp_attr.attr.mode = 0444;
744-
data->temp_attr.show = temp_show;
745-
746761
sysfs_attr_init(&data->eppid_attr.attr);
747762
data->eppid_attr.attr.name = "eppid";
748763
data->eppid_attr.attr.mode = 0444;

0 commit comments

Comments
 (0)