Skip to content

Commit 668ce99

Browse files
spandruvadarafaeljw
authored andcommitted
ACPI: DPTF: Additional sysfs attributes for power participant driver
Add two additional attributes to the existing power participant driver: rest_of_platform_power_mw: (RO) Shows the rest of worst case platform power in mW outside of S0C. This will help in power distribution to SoC and rest of the system. For example on a test system, this value is 2.5W with a 15W TDP SoC. Based on the adapter rating (adapter_rating_mw), user space software can decide on proper power allocation to SoC to improve short term performance via powercap/RAPL interface. prochot_confirm: (WO) Confirm EC about a prochot notification. Also userspace is notified via sysfs_notify(), whenever power source or rest of the platform power is changed. So user space can use poll() system call on those attributes. The ACPI methods used in this patch are as follows: PROP This object evaluates to the rest of worst case platform power in mW. Bits: 23:0 Worst case rest of platform power in mW. PBOK PBOK is a method designed to provide a mechanism for OSPM to change power setting before EC can de-assert a PROCHOT from a device. The EC may receive several PROCHOTs, so it has a sequence number attached to PSRC (read via existing attribute "platform_power_source"). Once OSPM takes action for a PSRC change notification, it can call PBOK method to confirm with the sequence number. Bits: 3:0 Power Delivery State Change Sequence number 30 Reserved 31 0 – Not OK to de-assert PROCHOT 1 – OK to de-assert PROCHOT PSRC (Platform Power Source): Not new in this patch but for documentation for new bits This object evaluates to an integer that represents the system power source as well as the power delivery state change sequence number. Bits: 3:0 The current power source as an integer for AC, DC, USB, Wireless. 0 = DC, 1 = AC, 2 = USB, 3 = Wireless Charging 7:4 Power Delivery State Change Sequence Number. Default value is 0 Notifications: 0x81: (Power State Change) Used to notify when the power source has changed. 0x84: (PROP change) Used to notify when the platform rest of power has changed. Signed-off-by: Srinivas Pandruvada <[email protected]> [ rjw: Subject, minor ABI documentation edit ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 9cb1fd0 commit 668ce99

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

Documentation/ABI/testing/sysfs-platform-dptf

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,30 @@ KernelVersion: v4.10
2727
2828
Description:
2929
(RO) Display the platform power source
30-
0x00 = DC
31-
0x01 = AC
32-
0x02 = USB
33-
0x03 = Wireless Charger
30+
bits[3:0] Current power source
31+
0x00 = DC
32+
0x01 = AC
33+
0x02 = USB
34+
0x03 = Wireless Charger
35+
bits[7:4] Power source sequence number
3436

3537
What: /sys/bus/platform/devices/INT3407:00/dptf_power/battery_steady_power
3638
Date: Jul, 2016
3739
KernelVersion: v4.10
3840
3941
Description:
4042
(RO) The maximum sustained power for battery in milliwatts.
43+
44+
What: /sys/bus/platform/devices/INT3407:00/dptf_power/rest_of_platform_power_mw
45+
Date: June, 2020
46+
KernelVersion: v5.8
47+
48+
Description:
49+
(RO) Shows the rest (outside of SoC) of worst-case platform power.
50+
51+
What: /sys/bus/platform/devices/INT3407:00/dptf_power/prochot_confirm
52+
Date: June, 2020
53+
KernelVersion: v5.8
54+
55+
Description:
56+
(WO) Confirm embedded controller about a prochot notification.

drivers/acpi/dptf/dptf_power.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* ARTG : Adapter rating
1717
* CTYP : Charger type
1818
* PBSS : Battery steady power
19+
* PROP : Rest of worst case platform Power
1920
*/
2021
#define DPTF_POWER_SHOW(name, object) \
2122
static ssize_t name##_show(struct device *dev,\
@@ -39,19 +40,43 @@ DPTF_POWER_SHOW(platform_power_source, PSRC)
3940
DPTF_POWER_SHOW(adapter_rating_mw, ARTG)
4041
DPTF_POWER_SHOW(battery_steady_power_mw, PBSS)
4142
DPTF_POWER_SHOW(charger_type, CTYP)
43+
DPTF_POWER_SHOW(rest_of_platform_power_mw, PROP)
4244

4345
static DEVICE_ATTR_RO(max_platform_power_mw);
4446
static DEVICE_ATTR_RO(platform_power_source);
4547
static DEVICE_ATTR_RO(adapter_rating_mw);
4648
static DEVICE_ATTR_RO(battery_steady_power_mw);
4749
static DEVICE_ATTR_RO(charger_type);
50+
static DEVICE_ATTR_RO(rest_of_platform_power_mw);
51+
52+
static ssize_t prochot_confirm_store(struct device *dev,
53+
struct device_attribute *attr,
54+
const char *buf, size_t count)
55+
{
56+
struct acpi_device *acpi_dev = dev_get_drvdata(dev);
57+
acpi_status status;
58+
int seq_no;
59+
60+
if (kstrtouint(buf, 0, &seq_no) < 0)
61+
return -EINVAL;
62+
63+
status = acpi_execute_simple_method(acpi_dev->handle, "PBOK", seq_no);
64+
if (ACPI_SUCCESS(status))
65+
return count;
66+
67+
return -EINVAL;
68+
}
69+
70+
static DEVICE_ATTR_WO(prochot_confirm);
4871

4972
static struct attribute *dptf_power_attrs[] = {
5073
&dev_attr_max_platform_power_mw.attr,
5174
&dev_attr_platform_power_source.attr,
5275
&dev_attr_adapter_rating_mw.attr,
5376
&dev_attr_battery_steady_power_mw.attr,
5477
&dev_attr_charger_type.attr,
78+
&dev_attr_rest_of_platform_power_mw.attr,
79+
&dev_attr_prochot_confirm.attr,
5580
NULL
5681
};
5782

@@ -60,6 +85,33 @@ static const struct attribute_group dptf_power_attribute_group = {
6085
.name = "dptf_power"
6186
};
6287

88+
#define POWER_STATE_CHANGED 0x81
89+
#define POWER_PROP_CHANGE_EVENT 0x84
90+
91+
static void dptf_power_notify(acpi_handle handle, u32 event, void *data)
92+
{
93+
struct platform_device *pdev = data;
94+
char *attr;
95+
96+
switch (event) {
97+
case POWER_STATE_CHANGED:
98+
attr = "platform_power_source";
99+
break;
100+
case POWER_PROP_CHANGE_EVENT:
101+
attr = "rest_of_platform_power_mw";
102+
break;
103+
default:
104+
dev_err(&pdev->dev, "Unsupported event [0x%x]\n", event);
105+
return;
106+
}
107+
108+
/*
109+
* Notify that an attribute is changed, so that user space can read
110+
* again.
111+
*/
112+
sysfs_notify(&pdev->dev.kobj, "dptf_power", attr);
113+
}
114+
63115
static int dptf_power_add(struct platform_device *pdev)
64116
{
65117
struct acpi_device *acpi_dev;
@@ -78,10 +130,21 @@ static int dptf_power_add(struct platform_device *pdev)
78130
if (ptype != 0x11)
79131
return -ENODEV;
80132

133+
result = acpi_install_notify_handler(acpi_dev->handle,
134+
ACPI_DEVICE_NOTIFY,
135+
dptf_power_notify,
136+
(void *)pdev);
137+
if (result)
138+
return result;
139+
81140
result = sysfs_create_group(&pdev->dev.kobj,
82141
&dptf_power_attribute_group);
83-
if (result)
142+
if (result) {
143+
acpi_remove_notify_handler(acpi_dev->handle,
144+
ACPI_DEVICE_NOTIFY,
145+
dptf_power_notify);
84146
return result;
147+
}
85148

86149
platform_set_drvdata(pdev, acpi_dev);
87150

@@ -90,7 +153,11 @@ static int dptf_power_add(struct platform_device *pdev)
90153

91154
static int dptf_power_remove(struct platform_device *pdev)
92155
{
156+
struct acpi_device *acpi_dev = platform_get_drvdata(pdev);
93157

158+
acpi_remove_notify_handler(acpi_dev->handle,
159+
ACPI_DEVICE_NOTIFY,
160+
dptf_power_notify);
94161
sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
95162

96163
return 0;

0 commit comments

Comments
 (0)