1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <acpi/acpigen.h>
#include <acpi/acpigen_dptf.h>
#include <ec/google/common/dptf.h>
/*
* The Chrome EC is typically in charge of many system functions, including battery charging and
* fan PWM control. This places it in the middle of a DPTF implementation and therefore, many of
* the "helper" ACPI Methods themselves call EC Methods. Because of that, the responsibility for
* producing the corresponding AML lies here.
*/
/* DPTF Event types */
enum {
TRIP_POINTS_CHANGED_EVENT = 0x81,
THERMAL_EVENT = 0x90,
};
/* EC constants */
enum {
EC_FAN_DUTY_AUTO = 0xFF,
};
static void write_charger_PPPC(const struct device *ec)
{
acpigen_write_method_serialized("PPPC", 0);
/*
* Convert size of PPSS table to index
*
* Store (SizeOf (PPSS), Local0)
* Decrement (Local0)
*/
acpigen_write_store();
acpigen_emit_byte(SIZEOF_OP);
acpigen_emit_namestring("PPSS");
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(DECREMENT_OP);
acpigen_emit_byte(LOCAL0_OP);
/*
* Check if charging is disabled (AC removed)
*
* If (\_SB.PCI0.LPCB.EC0.ACEX () = Zero) {
* Return (Local0)
* }
*/
acpigen_write_if();
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_namestring(acpi_device_path_join(ec, "ACEX"));
acpigen_emit_byte(ZERO_OP);
acpigen_write_return_op(LOCAL0_OP);
acpigen_pop_len(); /* If */
/* Return highest power state (index 0) */
acpigen_write_return_op(ZERO_OP);
acpigen_pop_len(); /* Method */
}
static void write_charger_SPPC(const struct device *ec)
{
/*
* SPPC - Set charger current limit
* Method(SPPC, 1) {
* Store (DeRefOf (Index (DeRefOf (Index
* (PPSS, ToInteger (Arg0))), 4)), Local0)
* \_SB.PCI0.LPCB.EC0.CHGS (Local0)
* }
*/
acpigen_write_method_serialized("SPPC", 1);
/* Retrieve Control (index 4) for specified PPSS level */
acpigen_emit_byte(STORE_OP);
acpigen_emit_byte(DEREF_OP);
acpigen_emit_byte(INDEX_OP);
acpigen_emit_byte(DEREF_OP);
acpigen_emit_byte(INDEX_OP);
acpigen_emit_namestring("PPSS");
acpigen_write_to_integer(ARG0_OP, ZERO_OP);
acpigen_emit_byte(ZERO_OP); /* 3rd arg to Index */
acpigen_write_integer(4); /* Index */
acpigen_emit_byte(ZERO_OP); /* 3rd arg to Index */
acpigen_emit_byte(LOCAL0_OP);
/* Pass Control value to EC to limit charging */
acpigen_emit_namestring(acpi_device_path_join(ec, "CHGS"));
acpigen_emit_byte(LOCAL0_OP);
acpigen_pop_len(); /* Method */
}
static void write_fan_fst(const struct device *ec)
{
/* TFST is a package that is used to store data from FAND */
acpigen_write_name("TFST");
acpigen_write_package(3);
acpigen_write_integer(0); /* Revision */
acpigen_write_integer(0); /* Control */
acpigen_write_integer(0); /* Speed */
acpigen_pop_len(); /* Package */
/* _FST */
acpigen_write_method_serialized("_FST", 0);
acpigen_write_store();
acpigen_emit_namestring(acpi_device_path_join(ec, "FAND"));
acpigen_emit_byte(INDEX_OP);
acpigen_emit_namestring("TFST");
acpigen_write_integer(1);
acpigen_emit_byte(ZERO_OP); /* 3rd arg to Index */
acpigen_emit_byte(RETURN_OP);
acpigen_emit_namestring("TFST");
acpigen_pop_len(); /* Method _FST */
}
static void write_fan_fsl(const struct device *ec)
{
/* _FSL */
acpigen_write_method_serialized("_FSL", 1);
acpigen_write_store();
acpigen_emit_byte(ARG0_OP);
acpigen_emit_namestring(acpi_device_path_join(ec, "FAND"));
acpigen_pop_len(); /* Method _FSL */
}
/*
* Emit code to execute if the policy is enabled after this function is called, and also
* remember to manually add a acpigen_pop_len() afterwards!
*/
static void write_is_policy_enabled(bool enabled)
{
/*
* Local0 = SizeOf (IDSP)
* Local1 = 0
* Local2 = 0
*
* While (Local1 < Local) {
* If (IDSP[Local1] == Arg0 && Arg1 == enabled) {
* Local2 = 1
* }
* Local1++
* }
*
* If (Local2 == 1) {
* ..........
*/
/* Local0 = SizeOf (IDSP) */
acpigen_write_store();
acpigen_emit_byte(SIZEOF_OP);
acpigen_emit_namestring("IDSP");
acpigen_emit_byte(LOCAL0_OP);
/* Local1 = 0 (index variable) */
acpigen_write_store();
acpigen_write_zero();
acpigen_emit_byte(LOCAL1_OP);
/* Local2 = 0 (out variable, 1=found, 0=not found) */
acpigen_write_store();
acpigen_write_zero();
acpigen_emit_byte(LOCAL2_OP);
/*
* While (Local1 < Local0) {
*/
acpigen_emit_byte(WHILE_OP);
acpigen_write_len_f();
acpigen_emit_byte(LNOT_OP);
acpigen_emit_byte(LGREATER_OP);
acpigen_emit_byte(LOCAL1_OP);
acpigen_emit_byte(LOCAL0_OP);
/* If (IDSP[Local1] == Arg0 && Arg1 == 1) { */
acpigen_write_if();
acpigen_emit_byte(LAND_OP);
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_byte(DEREF_OP);
acpigen_emit_byte(INDEX_OP);
acpigen_emit_namestring("IDSP");
acpigen_emit_byte(LOCAL1_OP);
acpigen_emit_byte(ZERO_OP); /* 3rd arg of index - unused */
acpigen_emit_byte(ARG0_OP); /* end lequal */
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_byte(ARG1_OP);
acpigen_write_integer(enabled ? 1 : 0);
/* { Local2 = 1 } */
acpigen_write_store();
acpigen_write_one();
acpigen_emit_byte(LOCAL2_OP);
acpigen_pop_len(); /* If */
/*
* Local1++
* } # End of While
*/
acpigen_emit_byte(INCREMENT_OP);
acpigen_emit_byte(LOCAL1_OP);
acpigen_pop_len(); /* While */
/*
* If (Local2 == 1)
*/
acpigen_write_if();
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_byte(LOCAL2_OP);
acpigen_write_one();
/* caller must insert acpigen_pop_len() ! */
}
static void write_dptf_OSC(const struct device *ec)
{
char name[16];
int i;
/*
* Arg0: Buffer containing UUID
* Arg1: "Integer containing Revision ID of buffer format", but Linux passes whether
* it is enabling (1) or disabling (0) the policy in Arg1.
* Arg2: Integer containing count of entries in Arg3
* Arg3: Buffer containing list of DWORD capabilities
* Return: Buffer containing list of DWORD capabilities
*/
acpigen_write_method_serialized("_OSC", 4);
/*
* If the Passive Policy is enabled:
* 1) Disable temperature sensor trip points in the EC (replaces TINI)
* 2) Disable the charge limit in the EC (replaces TCHG.INIT)
*/
write_is_policy_enabled(true);
for (i = 0; i < DPTF_MAX_TSR; ++i) {
snprintf(name, sizeof(name), "^TSR%1d.PATD", i);
acpigen_emit_namestring(name);
}
acpigen_emit_namestring(acpi_device_path_join(ec, "CHGD"));
acpigen_pop_len(); /* If (from write_is_policy_enabled) */
/* If the Active Policy is disabled, disable DPTF fan control in the EC */
write_is_policy_enabled(false);
acpigen_write_store();
acpigen_write_integer(EC_FAN_DUTY_AUTO);
acpigen_emit_namestring(acpi_device_path_join(ec, "FAND"));
acpigen_pop_len(); /* If (from write_is_policy_enabled) */
acpigen_write_return_op(ARG3_OP);
acpigen_pop_len(); /* Method _OSC */
}
static void write_dppm_methods(const struct device *ec)
{
enum dptf_participant p;
char name[16];
int i;
acpigen_write_scope("\\_SB.DPTF");
write_dptf_OSC(ec);
/* TEVT */
if (CONFIG(EC_SUPPORTS_DPTF_TEVT)) {
acpigen_write_method("TEVT", 1);
/* Local0 = ToInteger(Arg0) */
acpigen_write_to_integer(ARG0_OP, LOCAL0_OP);
for (p = DPTF_TEMP_SENSOR_0, i = 0; p <= DPTF_TEMP_SENSOR_3; ++p, ++i) {
snprintf(name, sizeof(name), "^TSR%1d", i);
acpigen_write_if_lequal_op_int(LOCAL0_OP, i);
acpigen_notify(name, THERMAL_EVENT);
acpigen_pop_len(); /* If */
}
acpigen_pop_len(); /* Method */
}
/* TPET */
acpigen_write_method("TPET", 0);
for (p = DPTF_TEMP_SENSOR_0, i = 0; p <= DPTF_TEMP_SENSOR_3; ++p, ++i) {
snprintf(name, sizeof(name), "^TSR%1d", i);
acpigen_notify(name, TRIP_POINTS_CHANGED_EVENT);
}
acpigen_pop_len(); /* Method */
acpigen_pop_len(); /* Scope */
}
static void write_charger_methods(const struct device *ec)
{
dptf_write_scope(DPTF_CHARGER);
write_charger_PPPC(ec);
write_charger_SPPC(ec);
acpigen_pop_len(); /* Scope */
}
static void write_fan_methods(const struct device *ec)
{
dptf_write_scope(DPTF_FAN);
write_fan_fsl(ec);
write_fan_fst(ec);
acpigen_pop_len(); /* Scope */
}
static void write_thermal_methods(const struct device *ec, enum dptf_participant participant,
int tsr_index)
{
dptf_write_scope(participant);
/*
* GTSH - Amount of hysteresis inherent in temperature reading (2 degrees, in units of
* 1/10th degree K)
*/
acpigen_write_name_integer("GTSH", 20);
/* _TMP - read temperature from EC */
acpigen_write_method_serialized("_TMP", 0);
acpigen_emit_byte(RETURN_OP);
acpigen_emit_namestring(acpi_device_path_join(ec, "TSRD"));
acpigen_write_integer(tsr_index);
acpigen_pop_len(); /* Method _TMP */
/* PATC - Aux trip point count */
acpigen_write_name_integer("PATC", 2);
/* PAT0 - Set Aux trip point 0 */
acpigen_write_method_serialized("PAT0", 1);
acpigen_emit_namestring(acpi_device_path_join(ec, "PAT0"));
acpigen_write_integer(tsr_index);
acpigen_emit_byte(ARG0_OP);
acpigen_pop_len(); /* Method PAT0 */
/* PAT1 - Set Aux trip point 1 */
acpigen_write_method_serialized("PAT1", 1);
acpigen_emit_namestring(acpi_device_path_join(ec, "PAT1"));
acpigen_write_integer(tsr_index);
acpigen_emit_byte(ARG0_OP);
acpigen_pop_len(); /* Method PAT0 */
/* PATD - Disable Aux trip point */
acpigen_write_method_serialized("PATD", 0);
acpigen_emit_namestring(acpi_device_path_join(ec, "PATD"));
acpigen_write_integer(tsr_index);
acpigen_pop_len(); /* Method PAT0 */
acpigen_pop_len(); /* Scope */
}
void ec_fill_dptf_helpers(const struct device *ec)
{
enum dptf_participant p;
int i;
write_dppm_methods(ec);
write_charger_methods(ec);
write_fan_methods(ec);
for (p = DPTF_TEMP_SENSOR_0, i = 0; p <= DPTF_TEMP_SENSOR_3; ++p, ++i)
write_thermal_methods(ec, p, i);
}
|