Skip to content

Commit 7b52b20

Browse files
spandruvadarafaeljw
authored andcommitted
ACPI: DPTF: Add battery participant driver
This driver adds support for Dynamic Platform and Thermal Framework battery participant device support. These attributes are presented via sysfs interface under the platform device for the battery participant: $ls /sys/bus/platform/devices/INT3532:00/dptf_battery current_discharge_capbility_ma max_platform_power_mw no_load_voltage_mv high_freq_impedance_mohm max_steady_state_power_mw Refer to the documentation at Documentation/ABI/testing/sysfs-platform-dptf for details. Here the implementation reuses existing dptf-power.c as the motivation and processing is same. It also shares one ACPI method. Here this change is using participant type, "PTYP" method to identify and do different processing. By using participant type, create/delete either "dptf_power" or "dptf_battery" attribute group and send notifications. The particpant type for for the battery participant is 0x0C. ACPI methods description: PMAX (Intel(R) Dynamic Tuning Platform Max Power Supplied by Battery): This object evaluates to the maximum platform power that can be supported by the battery in milli watts. PBSS (Intel(R) Dynamic Tuning Power Battery Steady State): This object returns the max sustained power for battery in milli watts. RBHF (Intel(R) Dynamic Tuning High Frequency Impedance): This object returns high frequency impedance value that can be obtained from battery fuel gauge. VBNL (Intel(R) Dynamic Tuning No-Load Voltage) This object returns battery instantaneous no-load voltage that can be obtained from battery fuel gauge in milli volts CMPP (Intel(R) Dynamic Tuning Current Discharge Capability) This object returns battery discharge current capability obtained from battery fuel gauge milli amps. Notifications: 0x80: PMAX change. Used to notify Intel(R)Dynamic Tuning Battery participant driver when the PMAX has changed by 250mw. 0x83: PBSS change. Used to notify Intel(R) Dynamic Tuning Battery participant driver when the power source has changed. 0x85: RBHF change. Used to notify Intel(R)Dynamic Tuning Battery participant driver when the RBHF has changed over a threshold by 5mOhm. 0x86: Battery Capability change. Used to notify Intel(R)Dynamic Tuning Battery participant driver when the battery capability has changed. Signed-off-by: Srinivas Pandruvada <[email protected]> [ rjw: Subject ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 668ce99 commit 7b52b20

File tree

2 files changed

+110
-10
lines changed

2 files changed

+110
-10
lines changed

Documentation/ABI/testing/sysfs-platform-dptf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,41 @@ KernelVersion: v5.8
5454
5555
Description:
5656
(WO) Confirm embedded controller about a prochot notification.
57+
58+
What: /sys/bus/platform/devices/INT3532:00/dptf_battery/max_platform_power_mw
59+
Date: June, 2020
60+
KernelVersion: v5.8
61+
62+
Description:
63+
(RO) The maximum platform power that can be supported by the battery in milli watts.
64+
65+
What: /sys/bus/platform/devices/INT3532:00/dptf_battery/max_steady_state_power_mw
66+
Date: June, 2020
67+
KernelVersion: v5.8
68+
69+
Description:
70+
(RO) The maximum sustained power for battery in milli watts.
71+
72+
What: /sys/bus/platform/devices/INT3532:00/dptf_battery/high_freq_impedance_mohm
73+
Date: June, 2020
74+
KernelVersion: v5.8
75+
76+
Description:
77+
(RO) The high frequency impedance value that can be obtained from battery
78+
fuel gauge in milli Ohms.
79+
80+
What: /sys/bus/platform/devices/INT3532:00/dptf_battery/no_load_voltage_mv
81+
Date: June, 2020
82+
KernelVersion: v5.8
83+
84+
Description:
85+
(RO) The no-load voltage that can be obtained from battery fuel gauge in
86+
milli volts.
87+
88+
What: /sys/bus/platform/devices/INT3532:00/dptf_battery/current_discharge_capbility_ma
89+
Date: June, 2020
90+
KernelVersion: v5.8
91+
92+
Description:
93+
(RO) The battery discharge current capability obtained from battery fuel gauge in
94+
milli Amps.

drivers/acpi/dptf/dptf_power.c

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
#include <linux/platform_device.h>
1111

1212
/*
13-
* Presentation of attributes which are defined for INT3407. They are:
13+
* Presentation of attributes which are defined for INT3407 and INT3532.
14+
* They are:
1415
* PMAX : Maximum platform powe
1516
* PSRC : Platform power source
1617
* ARTG : Adapter rating
1718
* CTYP : Charger type
1819
* PBSS : Battery steady power
1920
* PROP : Rest of worst case platform Power
21+
* PBSS : Power Battery Steady State
22+
* PBSS : Power Battery Steady State
23+
* RBHF : High Frequency Impedance
24+
* VBNL : Instantaneous No-Load Voltage
25+
* CMPP : Current Discharge Capability
2026
*/
2127
#define DPTF_POWER_SHOW(name, object) \
2228
static ssize_t name##_show(struct device *dev,\
@@ -41,13 +47,21 @@ DPTF_POWER_SHOW(adapter_rating_mw, ARTG)
4147
DPTF_POWER_SHOW(battery_steady_power_mw, PBSS)
4248
DPTF_POWER_SHOW(charger_type, CTYP)
4349
DPTF_POWER_SHOW(rest_of_platform_power_mw, PROP)
50+
DPTF_POWER_SHOW(max_steady_state_power_mw, PBSS)
51+
DPTF_POWER_SHOW(high_freq_impedance_mohm, RBHF)
52+
DPTF_POWER_SHOW(no_load_voltage_mv, VBNL)
53+
DPTF_POWER_SHOW(current_discharge_capbility_ma, CMPP);
4454

4555
static DEVICE_ATTR_RO(max_platform_power_mw);
4656
static DEVICE_ATTR_RO(platform_power_source);
4757
static DEVICE_ATTR_RO(adapter_rating_mw);
4858
static DEVICE_ATTR_RO(battery_steady_power_mw);
4959
static DEVICE_ATTR_RO(charger_type);
5060
static DEVICE_ATTR_RO(rest_of_platform_power_mw);
61+
static DEVICE_ATTR_RO(max_steady_state_power_mw);
62+
static DEVICE_ATTR_RO(high_freq_impedance_mohm);
63+
static DEVICE_ATTR_RO(no_load_voltage_mv);
64+
static DEVICE_ATTR_RO(current_discharge_capbility_ma);
5165

5266
static ssize_t prochot_confirm_store(struct device *dev,
5367
struct device_attribute *attr,
@@ -85,8 +99,38 @@ static const struct attribute_group dptf_power_attribute_group = {
8599
.name = "dptf_power"
86100
};
87101

102+
static struct attribute *dptf_battery_attrs[] = {
103+
&dev_attr_max_platform_power_mw.attr,
104+
&dev_attr_max_steady_state_power_mw.attr,
105+
&dev_attr_high_freq_impedance_mohm.attr,
106+
&dev_attr_no_load_voltage_mv.attr,
107+
&dev_attr_current_discharge_capbility_ma.attr,
108+
NULL
109+
};
110+
111+
static const struct attribute_group dptf_battery_attribute_group = {
112+
.attrs = dptf_battery_attrs,
113+
.name = "dptf_battery"
114+
};
115+
116+
#define MAX_POWER_CHANGED 0x80
88117
#define POWER_STATE_CHANGED 0x81
118+
#define STEADY_STATE_POWER_CHANGED 0x83
89119
#define POWER_PROP_CHANGE_EVENT 0x84
120+
#define IMPEDANCED_CHNGED 0x85
121+
#define VOLTAGE_CURRENT_CHANGED 0x86
122+
123+
static long long dptf_participant_type(acpi_handle handle)
124+
{
125+
unsigned long long ptype;
126+
acpi_status status;
127+
128+
status = acpi_evaluate_integer(handle, "PTYP", NULL, &ptype);
129+
if (ACPI_FAILURE(status))
130+
return -ENODEV;
131+
132+
return ptype;
133+
}
90134

91135
static void dptf_power_notify(acpi_handle handle, u32 event, void *data)
92136
{
@@ -100,6 +144,15 @@ static void dptf_power_notify(acpi_handle handle, u32 event, void *data)
100144
case POWER_PROP_CHANGE_EVENT:
101145
attr = "rest_of_platform_power_mw";
102146
break;
147+
case MAX_POWER_CHANGED:
148+
attr = "max_platform_power_mw";
149+
break;
150+
case STEADY_STATE_POWER_CHANGED:
151+
attr = "max_steady_state_power_mw";
152+
break;
153+
case VOLTAGE_CURRENT_CHANGED:
154+
attr = "no_load_voltage_mv";
155+
break;
103156
default:
104157
dev_err(&pdev->dev, "Unsupported event [0x%x]\n", event);
105158
return;
@@ -109,25 +162,29 @@ static void dptf_power_notify(acpi_handle handle, u32 event, void *data)
109162
* Notify that an attribute is changed, so that user space can read
110163
* again.
111164
*/
112-
sysfs_notify(&pdev->dev.kobj, "dptf_power", attr);
165+
if (dptf_participant_type(handle) == 0x0CULL)
166+
sysfs_notify(&pdev->dev.kobj, "dptf_battery", attr);
167+
else
168+
sysfs_notify(&pdev->dev.kobj, "dptf_power", attr);
113169
}
114170

115171
static int dptf_power_add(struct platform_device *pdev)
116172
{
173+
const struct attribute_group *attr_group;
117174
struct acpi_device *acpi_dev;
118-
acpi_status status;
119175
unsigned long long ptype;
120176
int result;
121177

122178
acpi_dev = ACPI_COMPANION(&(pdev->dev));
123179
if (!acpi_dev)
124180
return -ENODEV;
125181

126-
status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
127-
if (ACPI_FAILURE(status))
128-
return -ENODEV;
129-
130-
if (ptype != 0x11)
182+
ptype = dptf_participant_type(acpi_dev->handle);
183+
if (ptype == 0x11)
184+
attr_group = &dptf_power_attribute_group;
185+
else if (ptype == 0x0C)
186+
attr_group = &dptf_battery_attribute_group;
187+
else
131188
return -ENODEV;
132189

133190
result = acpi_install_notify_handler(acpi_dev->handle,
@@ -138,7 +195,7 @@ static int dptf_power_add(struct platform_device *pdev)
138195
return result;
139196

140197
result = sysfs_create_group(&pdev->dev.kobj,
141-
&dptf_power_attribute_group);
198+
attr_group);
142199
if (result) {
143200
acpi_remove_notify_handler(acpi_dev->handle,
144201
ACPI_DEVICE_NOTIFY,
@@ -158,13 +215,18 @@ static int dptf_power_remove(struct platform_device *pdev)
158215
acpi_remove_notify_handler(acpi_dev->handle,
159216
ACPI_DEVICE_NOTIFY,
160217
dptf_power_notify);
161-
sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
218+
219+
if (dptf_participant_type(acpi_dev->handle) == 0x0CULL)
220+
sysfs_remove_group(&pdev->dev.kobj, &dptf_battery_attribute_group);
221+
else
222+
sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
162223

163224
return 0;
164225
}
165226

166227
static const struct acpi_device_id int3407_device_ids[] = {
167228
{"INT3407", 0},
229+
{"INT3532", 0},
168230
{"INTC1047", 0},
169231
{"", 0},
170232
};

0 commit comments

Comments
 (0)