diff --git a/Documentation/ABI/testing/sysfs-class-power-surface b/Documentation/ABI/testing/sysfs-class-power-surface index 79cde4dcf2f5e..176533cd33f69 100644 --- a/Documentation/ABI/testing/sysfs-class-power-surface +++ b/Documentation/ABI/testing/sysfs-class-power-surface @@ -13,3 +13,108 @@ Description: Valid values: In micro-Wh or micro-Ah, depending on the power unit of the battery + +What: /sys/class/power_supply//dptf/max_platform_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Maximum peak power the battery can deliver, in mW (DPTF PMAX). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/max_steady_state_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Maximum sustained power the battery can deliver, in mW (DPTF PBSS). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/high_freq_impedance_mohm +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + High-frequency impedance of the battery, in mOhm (DPTF RBHF). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/no_load_voltage_mv +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + No-load voltage of the battery, in mV (DPTF VBNL). + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/available_input_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power available to the platform from the connected power sources, + in mW, as reported by the embedded controller. + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/rest_of_platform_power_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power of the rest of the platform, in mW (DPTF PROP), as reported + by the embedded controller. + + The embedded controller provides this value for platform power + management (DPTF) and updates it when the power source changes + and on resume from suspend. + The attribute is only present on devices whose embedded + controller is known to provide the data. + + Access: Read + +What: /sys/class/power_supply//dptf/adapter_rating_mw +Date: November 2026 +KernelVersion: 7.4 +Contact: Lars Schellhas van Kisfeld +Description: + Power rating of the connected adapter, in mW (DPTF ARTG), as + reported by the embedded controller. Reading it fails with + ENODATA while no rating is known. The attribute is only present + on devices whose embedded controller is known to provide the + value. + + Access: Read diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c index ef87965fcc930..fbe183e5280eb 100644 --- a/drivers/platform/surface/surface_aggregator_registry.c +++ b/drivers/platform/surface/surface_aggregator_registry.c @@ -51,6 +51,12 @@ static const struct software_node ssam_node_hub_base = { .parent = &ssam_node_root, }; +/* Property of the battery and AC adapter devices of an EC with DPTF support. */ +static const struct property_entry ssam_node_has_dptf[] = { + PROPERTY_ENTRY_BOOL("has_dptf"), + { } +}; + /* AC adapter. */ static const struct software_node ssam_node_bat_ac = { .name = "ssam:01:02:01:01:01", @@ -67,6 +73,25 @@ static const struct software_node ssam_node_bat_main = { static const struct software_node ssam_node_bat_sb3base = { .name = "ssam:01:02:02:01:00", .parent = &ssam_node_hub_base, + .properties = ssam_node_has_dptf, +}; + +/* + * AC adapter and primary battery of devices whose EC answers the DPTF + * requests (battery data, adapter rating). Sending these requests to an EC + * that does not support them runs into a timeout, so the drivers only send + * them if the device has the "has_dptf" property. + */ +static const struct software_node ssam_node_bat_ac_dptf = { + .name = "ssam:01:02:01:01:01", + .parent = &ssam_node_root, + .properties = ssam_node_has_dptf, +}; + +static const struct software_node ssam_node_bat_main_dptf = { + .name = "ssam:01:02:01:01:00", + .parent = &ssam_node_root, + .properties = ssam_node_has_dptf, }; /* Platform profile / performance-mode device without a fan. */ @@ -237,8 +262,8 @@ static const struct software_node *ssam_node_group_gen5[] = { static const struct software_node *ssam_node_group_sb3[] = { &ssam_node_root, &ssam_node_hub_base, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_bat_sb3base, &ssam_node_tmp_perf_profile, &ssam_node_bas_dtx, @@ -249,7 +274,7 @@ static const struct software_node *ssam_node_group_sb3[] = { NULL, }; -/* Devices for Surface Laptop 3 and 4. */ +/* Devices for Surface Laptop 3 (13", Intel), without DPTF. */ static const struct software_node *ssam_node_group_sl3[] = { &ssam_node_root, &ssam_node_bat_ac, @@ -261,11 +286,23 @@ static const struct software_node *ssam_node_group_sl3[] = { NULL, }; +/* Devices for Surface Laptop 3 (15", AMD) and 4 (13", Intel; 15", AMD), with DPTF. */ +static const struct software_node *ssam_node_group_sl3_dptf[] = { + &ssam_node_root, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile, + &ssam_node_hid_main_keyboard, + &ssam_node_hid_main_touchpad, + &ssam_node_hid_main_iid5, + NULL, +}; + /* Devices for Surface Laptop 5. */ static const struct software_node *ssam_node_group_sl5[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -279,8 +316,8 @@ static const struct software_node *ssam_node_group_sl5[] = { /* Devices for Surface Laptop 6. */ static const struct software_node *ssam_node_group_sl6[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -305,8 +342,8 @@ static const struct software_node *ssam_node_group_sl7[] = { /* Devices for Surface Laptop Studio 1. */ static const struct software_node *ssam_node_group_sls1[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, &ssam_node_pos_tablet_switch, &ssam_node_hid_sam_keyboard, @@ -321,8 +358,8 @@ static const struct software_node *ssam_node_group_sls1[] = { /* Devices for Surface Laptop Studio 2. */ static const struct software_node *ssam_node_group_sls2[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile_with_fan, &ssam_node_tmp_sensors, &ssam_node_fan_speed, @@ -337,13 +374,13 @@ static const struct software_node *ssam_node_group_sls2[] = { /* Devices for Surface Laptop Go. */ static const struct software_node *ssam_node_group_slg1[] = { &ssam_node_root, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, NULL, }; -/* Devices for Surface Pro 7 and Surface Pro 7+. */ +/* Devices for Surface Pro 7, without DPTF. */ static const struct software_node *ssam_node_group_sp7[] = { &ssam_node_root, &ssam_node_bat_ac, @@ -352,12 +389,21 @@ static const struct software_node *ssam_node_group_sp7[] = { NULL, }; +/* Devices for Surface Pro 7+, with DPTF. */ +static const struct software_node *ssam_node_group_sp7_dptf[] = { + &ssam_node_root, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile, + NULL, +}; + /* Devices for Surface Pro 8 */ static const struct software_node *ssam_node_group_sp8[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_perf_profile, &ssam_node_kip_tablet_switch, &ssam_node_hid_kip_keyboard, @@ -369,7 +415,7 @@ static const struct software_node *ssam_node_group_sp8[] = { NULL, }; -/* Devices for Surface Pro 9, 10 and 11 (Intel/x86) */ +/* Devices for Surface Pro 12 (Intel/x86), without DPTF. */ static const struct software_node *ssam_node_group_sp9[] = { &ssam_node_root, &ssam_node_hub_kip, @@ -388,12 +434,31 @@ static const struct software_node *ssam_node_group_sp9[] = { NULL, }; +/* Devices for Surface Pro 9, 10 and 11 (Intel/x86), with DPTF. */ +static const struct software_node *ssam_node_group_sp9_dptf[] = { + &ssam_node_root, + &ssam_node_hub_kip, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, + &ssam_node_tmp_perf_profile_with_fan, + &ssam_node_tmp_sensors, + &ssam_node_fan_speed, + &ssam_node_pos_tablet_switch, + &ssam_node_hid_kip_keyboard, + &ssam_node_hid_kip_penstash, + &ssam_node_hid_kip_touchpad, + &ssam_node_hid_kip_fwupd, + &ssam_node_hid_sam_sensors, + &ssam_node_hid_sam_ucm_ucsi, + NULL, +}; + /* Devices for Surface Pro 9 5G (ARM/QCOM) */ static const struct software_node *ssam_node_group_sp9_5g[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_sensors, &ssam_node_hid_kip_keyboard, &ssam_node_hid_kip_penstash, @@ -408,8 +473,8 @@ static const struct software_node *ssam_node_group_sp9_5g[] = { static const struct software_node *ssam_node_group_sp11[] = { &ssam_node_root, &ssam_node_hub_kip, - &ssam_node_bat_ac, - &ssam_node_bat_main, + &ssam_node_bat_ac_dptf, + &ssam_node_bat_main_dptf, &ssam_node_tmp_sensors, &ssam_node_hid_kip_keyboard, &ssam_node_hid_kip_penstash, @@ -446,19 +511,19 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = { { "MSHW0116", (unsigned long)ssam_node_group_sp7 }, /* Surface Pro 7+ */ - { "MSHW0119", (unsigned long)ssam_node_group_sp7 }, + { "MSHW0119", (unsigned long)ssam_node_group_sp7_dptf }, /* Surface Pro 8 */ { "MSHW0263", (unsigned long)ssam_node_group_sp8 }, /* Surface Pro 9 */ - { "MSHW0343", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0343", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 10 */ - { "MSHW0510", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0510", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 11 */ - { "MSHW0583", (unsigned long)ssam_node_group_sp9 }, + { "MSHW0583", (unsigned long)ssam_node_group_sp9_dptf }, /* Surface Pro 12 (Intel) */ { "MSHW0743", (unsigned long)ssam_node_group_sp9 }, @@ -479,10 +544,10 @@ static const struct acpi_device_id ssam_platform_hub_acpi_match[] = { { "MSHW0114", (unsigned long)ssam_node_group_sl3 }, /* Surface Laptop 3 (15", AMD) and 4 (15", AMD) */ - { "MSHW0110", (unsigned long)ssam_node_group_sl3 }, + { "MSHW0110", (unsigned long)ssam_node_group_sl3_dptf }, /* Surface Laptop 4 (13", Intel) */ - { "MSHW0250", (unsigned long)ssam_node_group_sl3 }, + { "MSHW0250", (unsigned long)ssam_node_group_sl3_dptf }, /* Surface Laptop 5 */ { "MSHW0350", (unsigned long)ssam_node_group_sl5 }, diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c index 1273b6082311d..a3176c34dac1d 100644 --- a/drivers/power/supply/surface_battery.c +++ b/drivers/power/supply/surface_battery.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,26 @@ struct spwr_bst { static_assert(sizeof(struct spwr_bst) == 16); +/* + * Battery data for platform power management (DPTF), command 0x53. The EC + * also sends it as an event when the power source changes. The field names + * follow the DPTF battery participant (see drivers/acpi/dptf/dptf_power.c). + */ +struct spwr_dptf { + __u8 version; + __le32 max_platform_power; /* mW, peak power the battery can deliver (PMAX) */ + __le32 max_steady_state_power; /* mW, sustained battery power (PBSS) */ + __le16 high_freq_impedance; /* mOhm (RBHF) */ + __le16 no_load_voltage; /* mV (VBNL) */ + __le32 available_input_power; /* mW, power available from all sources */ + __le32 rest_of_platform_power; /* mW (PROP) */ +} __packed; + +static_assert(sizeof(struct spwr_dptf) == 21); + +/* The only DPTF data version seen on devices so far (Surface Book 3). */ +#define SPWR_DPTF_VERSION 1 + #define SPWR_BIX_REVISION 0 #define SPWR_BATTERY_VALUE_UNKNOWN 0xffffffff @@ -102,6 +123,12 @@ SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bst, struct spwr_bst, { .command_id = 0x03, }); +/* Get battery data for platform power management (DPTF). */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_dptf, struct spwr_dptf, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x53, +}); + /* Set battery trip point (_BTP). */ SSAM_DEFINE_SYNC_REQUEST_CL_W(ssam_bat_set_btp, __le32, { .target_category = SSAM_SSH_TC_BAT, @@ -134,6 +161,10 @@ struct spwr_battery_device { struct spwr_bix bix; struct spwr_bst bst; u32 alarm; + + bool has_dptf; /* the device supports the DPTF request (device property) */ + bool dptf_version_warned; + struct spwr_dptf dptf; }; @@ -196,6 +227,47 @@ static int spwr_battery_load_bst(struct spwr_battery_device *bat) return ssam_retry(ssam_bat_get_bst, bat->sdev, &bat->bst); } +static void spwr_battery_check_dptf_version(struct spwr_battery_device *bat) +{ + lockdep_assert_held(&bat->lock); + + if (bat->dptf.version == SPWR_DPTF_VERSION || bat->dptf_version_warned) + return; + + bat->dptf_version_warned = true; + dev_warn(&bat->sdev->dev, "unexpected DPTF data version %u, the values may be wrong\n", + bat->dptf.version); +} + +static int spwr_battery_load_dptf_unlocked(struct spwr_battery_device *bat) +{ + int status; + + lockdep_assert_held(&bat->lock); + + status = ssam_retry(ssam_bat_get_dptf, bat->sdev, &bat->dptf); + if (!status) + spwr_battery_check_dptf_version(bat); + + return status; +} + +/* Reload the DPTF data, which can go stale while the driver is not notified. */ +static void spwr_battery_reload_dptf(struct spwr_battery_device *bat) +{ + int status; + + if (!bat->has_dptf) + return; + + mutex_lock(&bat->lock); + status = spwr_battery_load_dptf_unlocked(bat); + mutex_unlock(&bat->lock); + + if (status) + dev_warn(&bat->sdev->dev, "failed to update DPTF data: %d\n", status); +} + static int spwr_battery_set_alarm_unlocked(struct spwr_battery_device *bat, u32 value) { __le32 value_le = cpu_to_le32(value); @@ -340,6 +412,23 @@ static int spwr_battery_recheck_status(struct spwr_battery_device *bat) return status; } +static int spwr_battery_update_dptf(struct spwr_battery_device *bat, const struct ssam_event *event) +{ + if (!bat->has_dptf) + return 0; + + if (event->length < sizeof(bat->dptf)) + return -EPROTO; + + mutex_lock(&bat->lock); + memcpy(&bat->dptf, event->data, sizeof(bat->dptf)); + spwr_battery_check_dptf_version(bat); + mutex_unlock(&bat->lock); + + power_supply_changed(bat->psy); + return 0; +} + static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_event *event) { struct spwr_battery_device *bat = container_of(nf, struct spwr_battery_device, notif); @@ -376,10 +465,7 @@ static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_eve break; case SAM_EVENT_CID_BAT_DPTF: - /* - * TODO: Implement support for DPTF event. - */ - status = 0; + status = spwr_battery_update_dptf(bat, event); break; default: @@ -397,6 +483,9 @@ static void spwr_battery_update_bst_workfn(struct work_struct *work) bat = container_of(dwork, struct spwr_battery_device, update_work); + /* The EC does not send the DPTF event for every power source change. */ + spwr_battery_reload_dptf(bat); + status = spwr_battery_update_bst(bat, false); if (status) { dev_err(&bat->sdev->dev, "failed to update battery state: %d\n", status); @@ -713,7 +802,62 @@ static struct attribute *spwr_battery_attrs[] = { &dev_attr_alarm.attr, NULL, }; -ATTRIBUTE_GROUPS(spwr_battery); + +static const struct attribute_group spwr_battery_group = { + .attrs = spwr_battery_attrs, +}; + +/* -- DPTF attributes. ------------------------------------------------------ */ + +#define SPWR_DPTF_SHOW(_name, _field, _get) \ +static ssize_t _name##_show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + struct spwr_battery_device *bat = power_supply_get_drvdata(dev_to_psy(dev)); \ + u32 value; \ + \ + mutex_lock(&bat->lock); \ + value = _get(&bat->dptf._field); \ + mutex_unlock(&bat->lock); \ + \ + return sysfs_emit(buf, "%u\n", value); \ +} \ +static DEVICE_ATTR_RO(_name) + +SPWR_DPTF_SHOW(max_platform_power_mw, max_platform_power, get_unaligned_le32); +SPWR_DPTF_SHOW(max_steady_state_power_mw, max_steady_state_power, get_unaligned_le32); +SPWR_DPTF_SHOW(high_freq_impedance_mohm, high_freq_impedance, get_unaligned_le16); +SPWR_DPTF_SHOW(no_load_voltage_mv, no_load_voltage, get_unaligned_le16); +SPWR_DPTF_SHOW(available_input_power_mw, available_input_power, get_unaligned_le32); +SPWR_DPTF_SHOW(rest_of_platform_power_mw, rest_of_platform_power, get_unaligned_le32); + +static struct attribute *spwr_dptf_attrs[] = { + &dev_attr_max_platform_power_mw.attr, + &dev_attr_max_steady_state_power_mw.attr, + &dev_attr_high_freq_impedance_mohm.attr, + &dev_attr_no_load_voltage_mv.attr, + &dev_attr_available_input_power_mw.attr, + &dev_attr_rest_of_platform_power_mw.attr, + NULL, +}; + +static umode_t spwr_dptf_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct spwr_battery_device *bat = power_supply_get_drvdata(dev_to_psy(kobj_to_dev(kobj))); + + return bat->has_dptf ? attr->mode : 0; +} + +static const struct attribute_group spwr_dptf_group = { + .name = "dptf", + .attrs = spwr_dptf_attrs, + .is_visible = spwr_dptf_is_visible, +}; + +static const struct attribute_group *spwr_battery_groups[] = { + &spwr_battery_group, + &spwr_dptf_group, + NULL, +}; /* -- Device setup. --------------------------------------------------------- */ @@ -755,6 +899,12 @@ static int spwr_battery_register(struct spwr_battery_device *bat) if ((le32_to_cpu(sta) & SAM_BATTERY_STA_OK) != SAM_BATTERY_STA_OK) return -ENODEV; + /* + * The EC does not answer the DPTF request if it does not support it, + * so only send it if the device is marked as supporting it. + */ + bat->has_dptf = device_property_read_bool(&bat->sdev->dev, "has_dptf"); + /* Satisfy lockdep although we are in an exclusive context here. */ mutex_lock(&bat->lock); @@ -764,6 +914,14 @@ static int spwr_battery_register(struct spwr_battery_device *bat) return status; } + if (bat->has_dptf) { + status = spwr_battery_load_dptf_unlocked(bat); + if (status) { + dev_warn(&bat->sdev->dev, "failed to load DPTF data: %d\n", status); + bat->has_dptf = false; + } + } + if (spwr_battery_present(bat)) { u32 cap_warn = get_unaligned_le32(&bat->bix.design_cap_warn); @@ -810,7 +968,12 @@ static int spwr_battery_register(struct spwr_battery_device *bat) static int __maybe_unused surface_battery_resume(struct device *dev) { - return spwr_battery_recheck_full(dev_get_drvdata(dev)); + struct spwr_battery_device *bat = dev_get_drvdata(dev); + + /* The power source can have changed while suspended. */ + spwr_battery_reload_dptf(bat); + + return spwr_battery_recheck_full(bat); } static SIMPLE_DEV_PM_OPS(surface_battery_pm_ops, NULL, surface_battery_resume); diff --git a/drivers/power/supply/surface_charger.c b/drivers/power/supply/surface_charger.c index d4bba6b417947..e397a0c9887d3 100644 --- a/drivers/power/supply/surface_charger.c +++ b/drivers/power/supply/surface_charger.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,15 @@ SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_psrc, __le32, { }); +/* Get the power rating of the connected adapter (DPTF ARTG), in mW. */ +SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_artg, __le32, { + .target_category = SSAM_SSH_TC_BAT, + .command_id = 0x0f, +}); + +/* ARTG value while no rating is known (e.g. no adapter connected). */ +#define SPWR_AC_ARTG_UNKNOWN 0x80000000 + /* -- Device structures. ---------------------------------------------------- */ struct spwr_psy_properties { @@ -59,6 +69,7 @@ struct spwr_ac_device { struct mutex lock; /* Guards access to state below. */ __le32 state; + bool has_artg; /* the device supports the ARTG request (device property) */ }; @@ -164,6 +175,48 @@ static int spwr_ac_get_property(struct power_supply *psy, enum power_supply_prop } +/* -- DPTF attributes. ------------------------------------------------------ */ + +static ssize_t adapter_rating_mw_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct spwr_ac_device *ac = power_supply_get_drvdata(dev_to_psy(dev)); + __le32 artg; + int status; + + status = ssam_retry(ssam_bat_get_artg, ac->sdev, &artg); + if (status) + return status; + + if (le32_to_cpu(artg) == SPWR_AC_ARTG_UNKNOWN) + return -ENODATA; + + return sysfs_emit(buf, "%u\n", le32_to_cpu(artg)); +} +static DEVICE_ATTR_RO(adapter_rating_mw); + +static struct attribute *spwr_ac_dptf_attrs[] = { + &dev_attr_adapter_rating_mw.attr, + NULL, +}; + +static umode_t spwr_ac_dptf_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct spwr_ac_device *ac = power_supply_get_drvdata(dev_to_psy(kobj_to_dev(kobj))); + + return ac->has_artg ? attr->mode : 0; +} + +static const struct attribute_group spwr_ac_dptf_group = { + .name = "dptf", + .attrs = spwr_ac_dptf_attrs, + .is_visible = spwr_ac_dptf_is_visible, +}; + +static const struct attribute_group *spwr_ac_groups[] = { + &spwr_ac_dptf_group, + NULL, +}; + /* -- Device setup. --------------------------------------------------------- */ static char *battery_supplied_to[] = { @@ -208,7 +261,14 @@ static int spwr_ac_register(struct spwr_ac_device *ac) if ((le32_to_cpu(sta) & SAM_BATTERY_STA_OK) != SAM_BATTERY_STA_OK) return -ENODEV; + /* + * An EC that does not support the ARTG request does not answer it, so + * only send it on devices marked as supporting it. + */ + ac->has_artg = device_property_read_bool(&ac->sdev->dev, "has_dptf"); + psy_cfg.drv_data = ac; + psy_cfg.attr_grp = spwr_ac_groups; psy_cfg.supplied_to = battery_supplied_to; psy_cfg.num_supplicants = ARRAY_SIZE(battery_supplied_to);