Debian Codegraph @

src/ec/google/chromeec/ec_commands.h

raw symbols SCIP
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3
4
5
6 /* Host communication command constants for Chrome EC */
7
8 #ifndef __CROS_EC_EC_COMMANDS_H
9 #define __CROS_EC_EC_COMMANDS_H
10
11 #if !defined(__ACPI__) && !defined(__KERNEL__)
12 #include <stdint.h>
13 #endif
14
15 #ifdef CHROMIUM_EC
16 /*
17 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
18 * It is used to not include macros that may cause conflicts in foreign
19 * projects (refer to crbug.com/984623).
20 */
21
22 /*
23 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
24 * generates more efficient code for accessing request/response structures on
25 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
26 */
27 #include "common.h"
28 #include "compile_time_macros.h"
29
30 #else
31 /* If BUILD_ASSERT isn't already defined, make it a no-op */
32 #ifndef BUILD_ASSERT
33 #define BUILD_ASSERT(_cond)
34 #endif /* !BUILD_ASSERT */
35 #endif /* CHROMIUM_EC */
36
37 #ifdef __KERNEL__
38 #include <linux/limits.h>
39 #else
40 /*
41 * Defines macros that may be needed but are for sure defined by the linux
42 * kernel. This section is removed when cros_ec_commands.h is generated (by
43 * util/make_linux_ec_commands_h.sh).
44 * cros_ec_commands.h looks more integrated to the kernel.
45 */
46
47 #ifndef BIT
48 #define BIT(nr) (1UL << (nr))
49 #endif
50
51 #ifndef BIT_ULL
52 #define BIT_ULL(nr) (1ULL << (nr))
53 #endif
54
55 /*
56 * When building Zephyr, this file ends up being included before Zephyr's
57 * include/sys/util.h so causes a warning there. We don't want to add an #ifdef
58 * in that file since it won't be accepted upstream. So work around it here.
59 */
60 #ifndef CONFIG_ZEPHYR
61 #ifndef GENMASK
62 #define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1))
63 #endif
64
65 #ifndef GENMASK_ULL
66 #define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1))
67 #endif
68 #endif
69
70 #endif /* __KERNEL__ */
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 /**
77 * Constant for creation of flexible array members that work in both C and
78 * C++. Flexible array members were added in C99 and are not part of the C++
79 * standard. However, clang++ supports them for C++.
80 * When compiling with gcc, flexible array members are not allowed to appear
81 * in an otherwise empty struct, so we use the GCC zero-length array
82 * extension that works with both clang/gcc/g++.
83 */
84 #if defined(__cplusplus) && defined(__clang__)
85 #define FLEXIBLE_ARRAY_MEMBER_SIZE
86 #else
87 #define FLEXIBLE_ARRAY_MEMBER_SIZE 0
88 #endif
89
90 /*
91 * Current version of this protocol
92 *
93 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
94 * determined in other ways. Remove this once the kernel code no longer
95 * depends on it.
96 */
97 #define EC_PROTO_VERSION 0x00000002
98
99 /* Command version mask */
100 #define EC_VER_MASK(version) BIT(version)
101
102 /* I/O addresses for ACPI commands */
103 #define EC_LPC_ADDR_ACPI_DATA 0x62
104 #define EC_LPC_ADDR_ACPI_CMD 0x66
105
106 /* I/O addresses for host command */
107 #define EC_LPC_ADDR_HOST_DATA 0x200
108 #define EC_LPC_ADDR_HOST_CMD 0x204
109
110 /* I/O addresses for host command args and params */
111 /* Protocol version 2 */
112 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
113 /* For version 2 params; size is EC_PROTO2_MAX_PARAM_SIZE */
114 #define EC_LPC_ADDR_HOST_PARAM 0x804
115
116 /* Protocol version 3 */
117 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
118 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
119
120 /*
121 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
122 * and they tell the kernel that so we have to think of it as two parts.
123 *
124 * Other BIOSes report only the I/O port region spanned by the Microchip
125 * MEC series EC; an attempt to address a larger region may fail.
126 */
127 #define EC_HOST_CMD_REGION0 0x800
128 #define EC_HOST_CMD_REGION1 0x880
129 #define EC_HOST_CMD_REGION_SIZE 0x80
130 #define EC_HOST_CMD_MEC_REGION_SIZE 0x8
131
132 /* EC command register bit functions */
133 #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
134 #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
135 #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
136 #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
137 #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
138 #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
139 #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
140
141 #define EC_LPC_ADDR_MEMMAP 0x900
142 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
143 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
144
145 #define EC_LPC_ADDR_MEMMAP_INDEXED_IO 0x380
146
147 /* The offset address of each type of data in mapped memory. */
148 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
149 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
150 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
151 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
152 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
153 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
154 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
155 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
156 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
157 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
158 /* Unused 0x28 - 0x2f */
159 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
160 /* Unused 0x31 - 0x33 */
161 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
162 /* Battery values are all 32 bits, unless otherwise noted. */
163 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
164 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
165 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
166 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
167 #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
168 #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
169 /* Unused 0x4f */
170 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
171 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
172 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
173 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
174 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
175 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
176 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
177 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
178 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
179 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
180 /* Unused 0x84 - 0x8f */
181 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
182 /* Unused 0x91 */
183 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
184 /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
185 /* 0x94 - 0x99: 1st Accelerometer */
186 /* 0x9a - 0x9f: 2nd Accelerometer */
187
188 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
189 #define EC_MEMMAP_GPU 0xa6 /* GPU-specific, 8 bits */
190
191 /*
192 * Bit fields for EC_MEMMAP_GPU
193 * 0:2: D-Notify level (0:D1, ... 4:D5)
194 * 3: Over temperature
195 */
196 #define EC_MEMMAP_GPU_D_NOTIFY_MASK GENMASK(2, 0)
197 #define EC_MEMMAP_GPU_OVERT_BIT BIT(3)
198
199 /* Power Participant related components */
200 #define EC_MEMMAP_PWR_SRC 0xa7 /* Power source (8-bit) */
201 /* Unused 0xa8 - 0xdf */
202
203 /*
204 * ACPI is unable to access memory mapped data at or above this offset due to
205 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
206 * which might be needed by ACPI.
207 */
208 #define EC_MEMMAP_NO_ACPI 0xe0
209
210 /* Define the format of the accelerometer mapped memory status byte. */
211 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
212 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
213 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
214
215 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
216 #define EC_TEMP_SENSOR_ENTRIES 16
217 /*
218 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
219 *
220 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
221 */
222 #define EC_TEMP_SENSOR_B_ENTRIES 8
223
224 /* Max temp sensor entries for host commands */
225 #define EC_MAX_TEMP_SENSOR_ENTRIES \
226 (EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES)
227
228 /* Special values for mapped temperature sensors */
229 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
230 #define EC_TEMP_SENSOR_ERROR 0xfe
231 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
232 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
233 /*
234 * The offset of temperature value stored in mapped memory. This allows
235 * reporting a temperature range of 200K to 454K = -73C to 181C.
236 */
237 #define EC_TEMP_SENSOR_OFFSET 200
238
239 /*
240 * Number of ALS readings at EC_MEMMAP_ALS
241 */
242 #define EC_ALS_ENTRIES 2
243
244 /*
245 * The default value a temperature sensor will return when it is present but
246 * has not been read this boot. This is a reasonable number to avoid
247 * triggering alarms on the host.
248 */
249 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
250
251 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
252 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
253
254 /* Report 0 for fan stalled so userspace applications can take
255 * an appropriate action based on this value to control the fan.
256 */
257 #define EC_FAN_SPEED_STALLED 0x0
258 /* This should be used only for ectool to support old ECs. */
259 #define EC_FAN_SPEED_STALLED_DEPRECATED 0xfffe
260
261 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
262 #define EC_BATT_FLAG_AC_PRESENT 0x01
263 #define EC_BATT_FLAG_BATT_PRESENT 0x02
264 #define EC_BATT_FLAG_DISCHARGING 0x04
265 #define EC_BATT_FLAG_CHARGING 0x08
266 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
267 /* Set if some of the static/dynamic data is invalid (or outdated). */
268 #define EC_BATT_FLAG_INVALID_DATA 0x20
269 #define EC_BATT_FLAG_CUT_OFF 0x40
270
271 /*
272 * Value written to EC_MEMMAP_BATT_DCAP, EC_MEMMAP_BATT_DVLT, EC_MEMMAP_CCNT,
273 * EC_MEMMAP_BATT_VOLT, EC_MEMMAP_BATT_RATE, EC_MEMMAP_BATT_CAP, and
274 * EC_MEMMAP_BATT_LFCC if the actual value is unknown.
275 *
276 * This corresponds with the unknown value specified by ACPI release 6.5
277 * Section 10.2.2 (and earlier versions), to match expectations of ACPI
278 * firmware.
279 */
280 #define EC_MEMMAP_BATT_UNKNOWN_VALUE (-1)
281
282 /* Switch flags at EC_MEMMAP_SWITCHES */
283 #define EC_SWITCH_LID_OPEN 0x01
284 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
285 /* Was write protect disabled; now unused. */
286 #define EC_SWITCH_IGNORE2 0x04
287 /* Was recovery requested via keyboard; now unused. */
288 #define EC_SWITCH_IGNORE1 0x08
289 /* Recovery requested via dedicated signal (from servo board) */
290 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
291 /* Was fake developer mode switch; now unused. Remove in next refactor. */
292 #define EC_SWITCH_IGNORE0 0x20
293
294 /* Host command interface flags */
295 /* Host command interface supports LPC args (LPC interface only) */
296 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
297 /* Host command interface supports version 3 protocol */
298 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
299
300 /* Wireless switch flags */
301 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
302 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
303 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
304 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
305 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
306
307 /*****************************************************************************/
308 /*
309 * ACPI commands
310 *
311 * These are valid ONLY on the ACPI command/data port.
312 */
313
314 /*
315 * ACPI Read Embedded Controller
316 *
317 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
318 *
319 * Use the following sequence:
320 *
321 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
322 * - Wait for EC_LPC_CMDR_PENDING bit to clear
323 * - Write address to EC_LPC_ADDR_ACPI_DATA
324 * - Wait for EC_LPC_CMDR_DATA bit to set
325 * - Read value from EC_LPC_ADDR_ACPI_DATA
326 */
327 #define EC_CMD_ACPI_READ 0x0080
328
329 /*
330 * ACPI Write Embedded Controller
331 *
332 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
333 *
334 * Use the following sequence:
335 *
336 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
337 * - Wait for EC_LPC_CMDR_PENDING bit to clear
338 * - Write address to EC_LPC_ADDR_ACPI_DATA
339 * - Wait for EC_LPC_CMDR_PENDING bit to clear
340 * - Write value to EC_LPC_ADDR_ACPI_DATA
341 */
342 #define EC_CMD_ACPI_WRITE 0x0081
343
344 /*
345 * ACPI Burst Enable Embedded Controller
346 *
347 * This enables burst mode on the EC to allow the host to issue several
348 * commands back-to-back. While in this mode, writes to mapped multi-byte
349 * data are locked out to ensure data consistency.
350 */
351 #define EC_CMD_ACPI_BURST_ENABLE 0x0082
352
353 /*
354 * ACPI Burst Disable Embedded Controller
355 *
356 * This disables burst mode on the EC and stops preventing EC writes to mapped
357 * multi-byte data.
358 */
359 #define EC_CMD_ACPI_BURST_DISABLE 0x0083
360
361 /*
362 * ACPI Query Embedded Controller
363 *
364 * This clears the lowest-order bit in the currently pending host events, and
365 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
366 * event 0x80000000 = 32), or 0 if no event was pending.
367 */
368 #define EC_CMD_ACPI_QUERY_EVENT 0x0084
369
370 /* Valid addresses in ACPI memory space, for read/write commands */
371
372 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
373 #define EC_ACPI_MEM_VERSION 0x00
374 /*
375 * Test location; writing value here updates test compliment byte to (0xff -
376 * value).
377 */
378 #define EC_ACPI_MEM_TEST 0x01
379 /* Test compliment; writes here are ignored. */
380 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
381
382 /* Keyboard backlight brightness percent (0 - 100) */
383 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
384 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
385 #define EC_ACPI_MEM_FAN_DUTY 0x04
386
387 /*
388 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
389 * independent thresholds attached to them. The current value of the ID
390 * register determines which sensor is affected by the THRESHOLD and COMMIT
391 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
392 * as the memory-mapped sensors. The COMMIT register applies those settings.
393 *
394 * The spec does not mandate any way to read back the threshold settings
395 * themselves, but when a threshold is crossed the AP needs a way to determine
396 * which sensor(s) are responsible. Each reading of the ID register clears and
397 * returns one sensor ID that has crossed one of its threshold (in either
398 * direction) since the last read. A value of 0xFF means "no new thresholds
399 * have tripped". Setting or enabling the thresholds for a sensor will clear
400 * the unread event count for that sensor.
401 */
402 #define EC_ACPI_MEM_TEMP_ID 0x05
403 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
404 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
405 /*
406 * Here are the bits for the COMMIT register:
407 * bit 0 selects the threshold index for the chosen sensor (0/1)
408 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
409 * Each write to the commit register affects one threshold.
410 */
411 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
412 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
413 /*
414 * Example:
415 *
416 * Set the thresholds for sensor 2 to 50 C and 60 C:
417 * write 2 to [0x05] -- select temp sensor 2
418 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
419 * write 0x2 to [0x07] -- enable threshold 0 with this value
420 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
421 * write 0x3 to [0x07] -- enable threshold 1 with this value
422 *
423 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
424 * write 2 to [0x05] -- select temp sensor 2
425 * write 0x1 to [0x07] -- disable threshold 1
426 */
427
428 /* DPTF battery charging current limit */
429 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
430
431 /* Charging limit is specified in 64 mA steps */
432 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
433 /* Value to disable DPTF battery charging limit */
434 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
435
436 /*
437 * Report device orientation
438 * Bits Definition
439 * 4 Off Body/On Body status: 0 = Off Body.
440 * 3:1 Device DPTF Profile Number (DDPN)
441 * 0 = Reserved for backward compatibility (indicates no valid
442 * profile number. Host should fall back to using TBMD).
443 * 1..7 = DPTF Profile number to indicate to host which table needs
444 * to be loaded.
445 * 0 Tablet Mode Device Indicator (TBMD)
446 */
447 #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
448 #define EC_ACPI_MEM_TBMD_SHIFT 0
449 #define EC_ACPI_MEM_TBMD_MASK 0x1
450 #define EC_ACPI_MEM_DDPN_SHIFT 1
451 #define EC_ACPI_MEM_DDPN_MASK 0x7
452 #define EC_ACPI_MEM_STTB_SHIFT 4
453 #define EC_ACPI_MEM_STTB_MASK 0x1
454
455 /*
456 * Report device features. Uses the same format as the host command, except:
457 *
458 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
459 * of features", which is of limited interest when the system is already
460 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
461 * these are supported, it defaults to 0.
462 * This allows detecting the presence of this field since older versions of
463 * the EC codebase would simply return 0xff to that unknown address. Check
464 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
465 * are valid.
466 */
467 #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
468 #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
469 #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
470 #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
471 #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
472 #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
473 #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
474 #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
475
476 #define EC_ACPI_MEM_BATTERY_INDEX 0x12
477
478 /*
479 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
480 * is enabled (1) or disabled (0).
481 * bit 0 USB port ID 0
482 * ...
483 * bit 7 USB port ID 7
484 */
485 #define EC_ACPI_MEM_USB_PORT_POWER 0x13
486
487 /*
488 * USB Retimer firmware update.
489 * Read:
490 * Result of last operation AP requested
491 * Write:
492 * bits[3:0]: USB-C port number
493 * bits[7:4]: Operation requested by AP
494 *
495 * NDA (no device attached) case:
496 * To update retimer firmware, AP needs set up TBT Alt mode.
497 * AP requests operations in this sequence:
498 * 1. Get port information about which ports support retimer firmware update.
499 * In the query result, each bit represents one port.
500 * 2. Get current MUX mode, it's NDA.
501 * 3. Suspend specified PD port's task.
502 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
503 * update firmware -> disconnect MUX -> resume PD task.
504 *
505 * DA (device attached) cases:
506 * Retimer firmware update is not supported in DA cases.
507 * 1. Get port information about which ports support retimer firmware update
508 * 2. Get current MUX mode, it's DA.
509 * 3. AP continues. No more retimer firmware update activities.
510 *
511 */
512 #define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
513
514 #define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
515 #define USB_RETIMER_FW_UPDATE_ERR 0xfe
516 #define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
517 /* Mask to clear unused MUX bits in retimer firmware update */
518 #define USB_RETIMER_FW_UPDATE_MUX_MASK \
519 (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \
520 USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \
521 USB_PD_MUX_USB4_ENABLED)
522
523 /* Retimer firmware update operations */
524 #define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
525 #define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
526 #define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
527 #define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
528 #define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
529 #define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
530 #define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
531 #define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
532
533 #define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f)
534 #define EC_ACPI_MEM_USB_RETIMER_OP(x) \
535 (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
536
537 /*
538 * Offset 0x15 is reserved for PBOK, added to coreboot in
539 * https://crrev.com/c/3840943 and proposed for inclusion here
540 * in https://crrev.com/c/3547317.
541 */
542
543 /*
544 * Get extended strings from the EC.
545 * Write:
546 * String index, or 0 to probe for EC support.
547 * Read:
548 * String bytes, following by repeating null bytes.
549 *
550 * Writing a byte (EC_ACPI_MEM_STRINGS_FIFO_ID_*) selects a string, and the
551 * following reads return the non-null bytes of the string in sequence until
552 * the end of the string is reached. After the end of the string, reads 0 until
553 * another byte is written. This interface allows ACPI firmware to read longer
554 * strings from the EC than can reasonably fit into the shared memory region.
555 *
556 * To probe for EC support, write FIFO_ID_VERSION and read will return at least
557 * one nonzero (MEM_STRINGS_FIFO_V1 for example) if MEM_STRINGS_FIFO is
558 * supported. Returned values will indicate which strings are supported. If the
559 * first byte is 0xff, the strings FIFO is unsupported.
560 */
561 #define EC_ACPI_MEM_STRINGS_FIFO 0x16
562
563 /* String index to probe EC support. */
564 #define EC_ACPI_MEM_STRINGS_FIFO_ID_VERSION 0
565 #define EC_ACPI_MEM_STRINGS_FIFO_V1 1
566 /*
567 * 0xff is the value the EC returns for unimplemented reads, indicating
568 * the current EC firmware does not implement this command.
569 */
570 #define EC_ACPI_MEM_STRINGS_FIFO_UNSUPPORTED 0xff
571
572 /*
573 * Battery model number for the selected battery. Supported since V1.
574 * Presents the same data as EC_MEMMAP_BATT_MODEL, but can provide more
575 * than 8 bytes.
576 *
577 * This and the other FIFO_ID_BATTERY strings can select one of multiple
578 * batteries by changing the value at EC_MEMMAP_BATT_INDEX. Once that index
579 * is changed, reads of these strings will return information for the
580 * corresponding battery, if present.
581 */
582 #define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MODEL 1
583 /*
584 * Battery serial number for the selected battery. Supported since V1.
585 * Presents the same data as EC_MEMMAP_BATT_SERIAL, but can provide more
586 * than 8 bytes.
587 */
588 #define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_SERIAL 2
589 /*
590 * Battery manufacturer for the selected battery. Supported since V1.
591 * Presents the same data as EC_MEMMAP_BATT_MFGR, but can provide more
592 * than 8 bytes.
593 */
594 #define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MANUFACTURER 3
595
596 /*
597 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
598 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
599 */
600 #define EC_ACPI_MEM_MAPPED_BEGIN 0x20
601 #define EC_ACPI_MEM_MAPPED_SIZE 0xe0
602
603 /* Current version of ACPI memory address space */
604 #define EC_ACPI_MEM_VERSION_CURRENT 2
605
606 /*
607 * This header file is used in coreboot both in C and ACPI code. The ACPI code
608 * is pre-processed to handle constants but the ASL compiler is unable to
609 * handle actual C code so keep it separate.
610 */
611 #ifndef __ACPI__
612
613 #ifndef __KERNEL__
614 /*
615 * Define __packed if someone hasn't beat us to it. Linux kernel style
616 * checking prefers __packed over __attribute__((packed)).
617 */
618 #ifndef __packed
619 #define __packed __attribute__((packed))
620 #endif
621
622 #ifndef __aligned
623 #define __aligned(x) __attribute__((aligned(x)))
624 #endif
625 #endif /* __KERNEL__ */
626
627 /*
628 * Attributes for EC request and response packets. Just defining __packed
629 * results in inefficient assembly code on ARM, if the structure is actually
630 * 32-bit aligned, as it should be for all buffers.
631 *
632 * Be very careful when adding these to existing structures. They will round
633 * up the structure size to the specified boundary.
634 *
635 * Also be very careful to make that if a structure is included in some other
636 * parent structure that the alignment will still be true given the packing of
637 * the parent structure. This is particularly important if the sub-structure
638 * will be passed as a pointer to another function, since that function will
639 * not know about the misalignment caused by the parent structure's packing.
640 *
641 * Also be very careful using __packed - particularly when nesting non-packed
642 * structures inside packed ones. In fact, DO NOT use __packed directly;
643 * always use one of these attributes.
644 *
645 * Once everything is annotated properly, the following search strings should
646 * not return ANY matches in this file other than right here:
647 *
648 * "__packed" - generates inefficient code; all sub-structs must also be packed
649 *
650 * "struct [^_]" - all structs should be annotated, except for structs that are
651 * members of other structs/unions (and their original declarations should be
652 * annotated).
653 */
654 #ifdef CONFIG_HOSTCMD_ALIGNED
655
656 /*
657 * Packed structures where offset and size are always aligned to 1, 2, or 4
658 * byte boundary.
659 */
660 #define __ec_align1 __packed
661 #define __ec_align2 __packed __aligned(2)
662 #define __ec_align4 __packed __aligned(4)
663
664 /*
665 * Packed structure which must be under-aligned, because its size is not a
666 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
667 * of all multi-byte fields in it, even though they are themselves aligned.
668 *
669 * In theory, we could duplicate the structure with __aligned(4) for accessing
670 * its members, but use the __packed version for sizeof().
671 */
672 #define __ec_align_size1 __packed
673
674 /*
675 * Packed structure which must be under-aligned, because its offset inside a
676 * parent structure is not a 4-byte multiple.
677 */
678 #define __ec_align_offset1 __packed
679 #define __ec_align_offset2 __packed __aligned(2)
680
681 /*
682 * Structures which are complicated enough that I'm skipping them on the first
683 * pass. They are effectively unchanged from their previous definitions.
684 *
685 * TODO(rspangler): Figure out what to do with these. It's likely necessary
686 * to work out the size and offset of each member and add explicit padding to
687 * maintain those.
688 */
689 #define __ec_todo_packed __packed
690 #define __ec_todo_unpacked
691
692 #else /* !CONFIG_HOSTCMD_ALIGNED */
693
694 /*
695 * Packed structures make no assumption about alignment, so they do inefficient
696 * byte-wise reads.
697 */
698 #define __ec_align1 __packed
699 #define __ec_align2 __packed
700 #define __ec_align4 __packed
701 #define __ec_align_size1 __packed
702 #define __ec_align_offset1 __packed
703 #define __ec_align_offset2 __packed
704 #define __ec_todo_packed __packed
705 #define __ec_todo_unpacked
706
707 #endif /* !CONFIG_HOSTCMD_ALIGNED */
708
709 /* LPC command status byte masks */
710 /* EC has written a byte in the data register and host hasn't read it yet */
711 #define EC_LPC_STATUS_TO_HOST 0x01
712 /* Host has written a command/data byte and the EC hasn't read it yet */
713 #define EC_LPC_STATUS_FROM_HOST 0x02
714 /* EC is processing a command */
715 #define EC_LPC_STATUS_PROCESSING 0x04
716 /* Last write to EC was a command, not data */
717 #define EC_LPC_STATUS_LAST_CMD 0x08
718 /* EC is in burst mode */
719 #define EC_LPC_STATUS_BURST_MODE 0x10
720 /* SCI event is pending (requesting SCI query) */
721 #define EC_LPC_STATUS_SCI_PENDING 0x20
722 /* SMI event is pending (requesting SMI query) */
723 #define EC_LPC_STATUS_SMI_PENDING 0x40
724 /* (reserved) */
725 #define EC_LPC_STATUS_RESERVED 0x80
726
727 /*
728 * EC is busy. This covers both the EC processing a command, and the host has
729 * written a new command but the EC hasn't picked it up yet.
730 */
731 #define EC_LPC_STATUS_BUSY_MASK \
732 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
733
734 /*
735 * Host command response codes (16-bit).
736 */
737 enum ec_status {
738 EC_RES_SUCCESS = 0,
739 EC_RES_INVALID_COMMAND = 1,
740 EC_RES_ERROR = 2,
741 EC_RES_INVALID_PARAM = 3,
742 EC_RES_ACCESS_DENIED = 4,
743 EC_RES_INVALID_RESPONSE = 5,
744 EC_RES_INVALID_VERSION = 6,
745 EC_RES_INVALID_CHECKSUM = 7,
746 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
747 EC_RES_UNAVAILABLE = 9, /* No response available */
748 EC_RES_TIMEOUT = 10, /* We got a timeout */
749 EC_RES_OVERFLOW = 11, /* Table / data overflow */
750 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
751 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
752 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
753 EC_RES_BUS_ERROR = 15, /* Communications bus error */
754 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
755 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
756 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
757 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
758 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
759
760 EC_RES_COUNT,
761
762 EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */
763 } __packed;
764 BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
765 #ifdef CONFIG_EC_HOST_CMD
766 /*
767 * Make sure Zephyre uses the same status codes.
768 */
769 #include <zephyr/mgmt/ec_host_cmd/ec_host_cmd.h>
770
771 BUILD_ASSERT((uint16_t)EC_RES_SUCCESS == (uint16_t)EC_HOST_CMD_SUCCESS);
772 BUILD_ASSERT((uint16_t)EC_RES_INVALID_COMMAND ==
773 (uint16_t)EC_HOST_CMD_INVALID_COMMAND);
774 BUILD_ASSERT((uint16_t)EC_RES_ERROR == (uint16_t)EC_HOST_CMD_ERROR);
775 BUILD_ASSERT((uint16_t)EC_RES_INVALID_PARAM ==
776 (uint16_t)EC_HOST_CMD_INVALID_PARAM);
777 BUILD_ASSERT((uint16_t)EC_RES_ACCESS_DENIED ==
778 (uint16_t)EC_HOST_CMD_ACCESS_DENIED);
779 BUILD_ASSERT((uint16_t)EC_RES_INVALID_RESPONSE ==
780 (uint16_t)EC_HOST_CMD_INVALID_RESPONSE);
781 BUILD_ASSERT((uint16_t)EC_RES_INVALID_VERSION ==
782 (uint16_t)EC_HOST_CMD_INVALID_VERSION);
783 BUILD_ASSERT((uint16_t)EC_RES_INVALID_CHECKSUM ==
784 (uint16_t)EC_HOST_CMD_INVALID_CHECKSUM);
785 BUILD_ASSERT((uint16_t)EC_RES_IN_PROGRESS == (uint16_t)EC_HOST_CMD_IN_PROGRESS);
786 BUILD_ASSERT((uint16_t)EC_RES_UNAVAILABLE == (uint16_t)EC_HOST_CMD_UNAVAILABLE);
787 BUILD_ASSERT((uint16_t)EC_RES_TIMEOUT == (uint16_t)EC_HOST_CMD_TIMEOUT);
788 BUILD_ASSERT((uint16_t)EC_RES_OVERFLOW == (uint16_t)EC_HOST_CMD_OVERFLOW);
789 BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER ==
790 (uint16_t)EC_HOST_CMD_INVALID_HEADER);
791 BUILD_ASSERT((uint16_t)EC_RES_REQUEST_TRUNCATED ==
792 (uint16_t)EC_HOST_CMD_REQUEST_TRUNCATED);
793 BUILD_ASSERT((uint16_t)EC_RES_RESPONSE_TOO_BIG ==
794 (uint16_t)EC_HOST_CMD_RESPONSE_TOO_BIG);
795 BUILD_ASSERT((uint16_t)EC_RES_BUS_ERROR == (uint16_t)EC_HOST_CMD_BUS_ERROR);
796 BUILD_ASSERT((uint16_t)EC_RES_BUSY == (uint16_t)EC_HOST_CMD_BUSY);
797 BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_VERSION ==
798 (uint16_t)EC_HOST_CMD_INVALID_HEADER_VERSION);
799 BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_CRC ==
800 (uint16_t)EC_HOST_CMD_INVALID_HEADER_CRC);
801 BUILD_ASSERT((uint16_t)EC_RES_INVALID_DATA_CRC ==
802 (uint16_t)EC_HOST_CMD_INVALID_DATA_CRC);
803 BUILD_ASSERT((uint16_t)EC_RES_DUP_UNAVAILABLE ==
804 (uint16_t)EC_HOST_CMD_DUP_UNAVAILABLE);
805 BUILD_ASSERT((uint16_t)EC_RES_MAX == (uint16_t)EC_HOST_CMD_MAX);
806
807 #endif
808
809 /* clang-format off */
810 #define EC_STATUS_TEXT \
811 { \
812 EC_MAP_ITEM(EC_RES_SUCCESS, SUCCESS), \
813 EC_MAP_ITEM(EC_RES_INVALID_COMMAND, INVALID_COMMAND), \
814 EC_MAP_ITEM(EC_RES_ERROR, ERROR), \
815 EC_MAP_ITEM(EC_RES_INVALID_PARAM, INVALID_PARAM), \
816 EC_MAP_ITEM(EC_RES_ACCESS_DENIED, ACCESS_DENIED), \
817 EC_MAP_ITEM(EC_RES_INVALID_RESPONSE, INVALID_RESPONSE), \
818 EC_MAP_ITEM(EC_RES_INVALID_VERSION, INVALID_VERSION), \
819 EC_MAP_ITEM(EC_RES_INVALID_CHECKSUM, INVALID_CHECKSUM), \
820 EC_MAP_ITEM(EC_RES_IN_PROGRESS, IN_PROGRESS), \
821 EC_MAP_ITEM(EC_RES_UNAVAILABLE, UNAVAILABLE), \
822 EC_MAP_ITEM(EC_RES_TIMEOUT, TIMEOUT), \
823 EC_MAP_ITEM(EC_RES_OVERFLOW, OVERFLOW), \
824 EC_MAP_ITEM(EC_RES_INVALID_HEADER, INVALID_HEADER), \
825 EC_MAP_ITEM(EC_RES_REQUEST_TRUNCATED, REQUEST_TRUNCATED), \
826 EC_MAP_ITEM(EC_RES_RESPONSE_TOO_BIG, RESPONSE_TOO_BIG), \
827 EC_MAP_ITEM(EC_RES_BUS_ERROR, BUS_ERROR), \
828 EC_MAP_ITEM(EC_RES_BUSY, BUSY), \
829 EC_MAP_ITEM(EC_RES_INVALID_HEADER_VERSION, INVALID_HEADER_VERSION), \
830 EC_MAP_ITEM(EC_RES_INVALID_HEADER_CRC, INVALID_HEADER_CRC), \
831 EC_MAP_ITEM(EC_RES_INVALID_DATA_CRC, INVALID_DATA_CRC), \
832 EC_MAP_ITEM(EC_RES_DUP_UNAVAILABLE, DUP_UNAVAILABLE), \
833 }
834 /* clang-format on */
835
836 #ifndef __cplusplus
837 #define EC_MAP_ITEM(k, v) [k] = #v
838 BUILD_ASSERT(ARRAY_SIZE(((const char *[])EC_STATUS_TEXT)) == EC_RES_COUNT);
839 #undef EC_MAP_ITEM
840 #endif
841
842 /*
843 * Host event codes. ACPI query EC command uses code 0 to mean "no event
844 * pending". We explicitly specify each value in the enum listing so they won't
845 * change if we delete/insert an item or rearrange the list (it needs to be
846 * stable across platforms, not just within a single compiled instance).
847 */
848 enum host_event_code {
849 EC_HOST_EVENT_NONE = 0,
850 EC_HOST_EVENT_LID_CLOSED = 1,
851 EC_HOST_EVENT_LID_OPEN = 2,
852 EC_HOST_EVENT_POWER_BUTTON = 3,
853 EC_HOST_EVENT_AC_CONNECTED = 4,
854 EC_HOST_EVENT_AC_DISCONNECTED = 5,
855 EC_HOST_EVENT_BATTERY_LOW = 6,
856 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
857 EC_HOST_EVENT_BATTERY = 8,
858 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
859 /* Event generated by a device attached to the EC */
860 EC_HOST_EVENT_DEVICE = 10,
861 EC_HOST_EVENT_THERMAL = 11,
862 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
863 EC_HOST_EVENT_GPU = 12,
864 EC_HOST_EVENT_KEY_PRESSED = 13,
865 /*
866 * EC has finished initializing the host interface. The host can check
867 * for this event following sending a EC_CMD_REBOOT_EC command to
868 * determine when the EC is ready to accept subsequent commands.
869 */
870 EC_HOST_EVENT_INTERFACE_READY = 14,
871 /* Keyboard recovery combo has been pressed */
872 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
873
874 /* Shutdown due to thermal overload */
875 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
876 /* Shutdown due to battery level too low */
877 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
878
879 /* Suggest that the AP throttle itself */
880 EC_HOST_EVENT_THROTTLE_START = 18,
881 /* Suggest that the AP resume normal speed */
882 EC_HOST_EVENT_THROTTLE_STOP = 19,
883
884 /* Hang detect logic detected a hang and host event timeout expired */
885 EC_HOST_EVENT_HANG_DETECT = 20,
886 /* Hang detect logic detected a hang and warm rebooted the AP */
887 EC_HOST_EVENT_HANG_REBOOT = 21,
888
889 /* PD MCU triggering host event */
890 EC_HOST_EVENT_PD_MCU = 22,
891
892 /* Battery Status flags have changed */
893 EC_HOST_EVENT_BATTERY_STATUS = 23,
894
895 /* EC encountered a panic, triggering a reset */
896 EC_HOST_EVENT_PANIC = 24,
897
898 /* Keyboard fastboot combo has been pressed */
899 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
900
901 /* EC RTC event occurred */
902 EC_HOST_EVENT_RTC = 26,
903
904 /* Emulate MKBP event */
905 EC_HOST_EVENT_MKBP = 27,
906
907 /* EC desires to change state of host-controlled USB mux */
908 EC_HOST_EVENT_USB_MUX = 28,
909
910 /*
911 * The device has changed "modes". This can be one of the following:
912 *
913 * - TABLET/LAPTOP mode
914 * - detachable base attach/detach event
915 * - on body/off body transition event
916 */
917 EC_HOST_EVENT_MODE_CHANGE = 29,
918
919 /* Keyboard recovery combo with hardware reinitialization */
920 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
921
922 /* WoV */
923 EC_HOST_EVENT_WOV = 31,
924
925 /*
926 * The high bit of the event mask is not used as a host event code. If
927 * it reads back as set, then the entire event mask should be
928 * considered invalid by the host. This can happen when reading the
929 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
930 * not initialized on the EC, or improperly configured on the host.
931 */
932 EC_HOST_EVENT_INVALID = 32,
933
934 /* Body detect (lap/desk) change event */
935 EC_HOST_EVENT_BODY_DETECT_CHANGE = 33,
936
937 /*
938 * Only 64 host events are supported. This enum uses 1-based counting so
939 * it can skip 0 (NONE), so the last legal host event number is 64.
940 */
941 };
942
943 /* Host event mask */
944 #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
945
946 /* clang-format off */
947 #define HOST_EVENT_TEXT \
948 { \
949 [EC_HOST_EVENT_NONE] = "NONE", \
950 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
951 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
952 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
953 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
954 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
955 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
956 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
957 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
958 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
959 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
960 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
961 [EC_HOST_EVENT_GPU] = "GPU", \
962 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
963 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
964 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
965 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
966 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
967 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
968 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
969 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
970 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
971 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
972 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
973 [EC_HOST_EVENT_PANIC] = "PANIC", \
974 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
975 [EC_HOST_EVENT_RTC] = "RTC", \
976 [EC_HOST_EVENT_MKBP] = "MKBP", \
977 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
978 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
979 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
980 "KEYBOARD_RECOVERY_HW_REINIT", \
981 [EC_HOST_EVENT_WOV] = "WOV", \
982 [EC_HOST_EVENT_INVALID] = "INVALID", \
983 [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \
984 }
985 /* clang-format on */
986
987 /**
988 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
989 * @flags: The host argument flags.
990 * @command_version: Command version.
991 * @data_size: The length of data.
992 * @checksum: Checksum; sum of command + flags + command_version + data_size +
993 * all params/response data bytes.
994 */
995 struct ec_lpc_host_args {
996 uint8_t flags;
997 uint8_t command_version;
998 uint8_t data_size;
999 uint8_t checksum;
1000 } __ec_align4;
1001
1002 /* Flags for ec_lpc_host_args.flags */
1003 /*
1004 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
1005 * params.
1006 *
1007 * If EC gets a command and this flag is not set, this is an old-style command.
1008 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
1009 * unknown length. EC must respond with an old-style response (that is,
1010 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
1011 */
1012 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
1013 /*
1014 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
1015 *
1016 * If EC responds to a command and this flag is not set, this is an old-style
1017 * response. Command version is 0 and response data from EC is at
1018 * EC_LPC_ADDR_OLD_PARAM with unknown length.
1019 */
1020 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
1021
1022 /*****************************************************************************/
1023 /*
1024 * Byte codes returned by EC over SPI interface.
1025 *
1026 * These can be used by the AP to debug the EC interface, and to determine
1027 * when the EC is not in a state where it will ever get around to responding
1028 * to the AP.
1029 *
1030 * Example of sequence of bytes read from EC for a current good transfer:
1031 * 1. - - AP asserts chip select (CS#)
1032 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
1033 * 3. - - EC starts handling CS# interrupt
1034 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
1035 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
1036 * bytes looking for EC_SPI_FRAME_START
1037 * 6. - - EC finishes processing and sets up response
1038 * 7. EC_SPI_FRAME_START - AP reads frame byte
1039 * 8. (response packet) - AP reads response packet
1040 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
1041 * 10 - - AP deasserts chip select
1042 * 11 - - EC processes CS# interrupt and sets up DMA for
1043 * next request
1044 *
1045 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
1046 * the following byte values:
1047 * EC_SPI_OLD_READY
1048 * EC_SPI_RX_READY
1049 * EC_SPI_RECEIVING
1050 * EC_SPI_PROCESSING
1051 *
1052 * Then the EC found an error in the request, or was not ready for the request
1053 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
1054 * because the EC is unable to tell when the AP is done sending its request.
1055 */
1056
1057 /*
1058 * Framing byte which precedes a response packet from the EC. After sending a
1059 * request, the AP will clock in bytes until it sees the framing byte, then
1060 * clock in the response packet.
1061 */
1062 #define EC_SPI_FRAME_START 0xec
1063
1064 /*
1065 * Padding bytes which are clocked out after the end of a response packet.
1066 */
1067 #define EC_SPI_PAST_END 0xed
1068
1069 /*
1070 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
1071 * that the AP will send a valid packet header (starting with
1072 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
1073 *
1074 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
1075 * CS goes low. This macro has the Most Significant Bit set to zero,
1076 * so SDO will not be driven high when CS goes low.
1077 */
1078 #define EC_SPI_RX_READY 0x78
1079
1080 /*
1081 * EC has started receiving the request from the AP, but hasn't started
1082 * processing it yet.
1083 */
1084 #define EC_SPI_RECEIVING 0xf9
1085
1086 /* EC has received the entire request from the AP and is processing it. */
1087 #define EC_SPI_PROCESSING 0xfa
1088
1089 /*
1090 * EC received bad data from the AP, such as a packet header with an invalid
1091 * length. EC will ignore all data until chip select deasserts.
1092 */
1093 #define EC_SPI_RX_BAD_DATA 0xfb
1094
1095 /*
1096 * EC received data from the AP before it was ready. That is, the AP asserted
1097 * chip select and started clocking data before the EC was ready to receive it.
1098 * EC will ignore all data until chip select deasserts.
1099 */
1100 #define EC_SPI_NOT_READY 0xfc
1101
1102 /*
1103 * EC was ready to receive a request from the AP. EC has treated the byte sent
1104 * by the AP as part of a request packet, or (for old-style ECs) is processing
1105 * a fully received packet but is not ready to respond yet.
1106 */
1107 #define EC_SPI_OLD_READY 0xfd
1108
1109 /*****************************************************************************/
1110
1111 /*
1112 * Protocol version 2 for I2C and SPI send a request this way:
1113 *
1114 * 0 EC_CMD_VERSION0 + (command version)
1115 * 1 Command number
1116 * 2 Length of params = N
1117 * 3..N+2 Params, if any
1118 * N+3 8-bit checksum of bytes 0..N+2
1119 *
1120 * The corresponding response is:
1121 *
1122 * 0 Result code (EC_RES_*)
1123 * 1 Length of params = M
1124 * 2..M+1 Params, if any
1125 * M+2 8-bit checksum of bytes 0..M+1
1126 */
1127 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
1128 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
1129 #define EC_PROTO2_REQUEST_OVERHEAD \
1130 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
1131
1132 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
1133 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
1134 #define EC_PROTO2_RESPONSE_OVERHEAD \
1135 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
1136
1137 /* Parameter length was limited by the LPC interface */
1138 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
1139
1140 /* Maximum request and response packet sizes for protocol version 2 */
1141 #define EC_PROTO2_MAX_REQUEST_SIZE \
1142 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
1143 #define EC_PROTO2_MAX_RESPONSE_SIZE \
1144 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
1145
1146 /*****************************************************************************/
1147
1148 /*
1149 * Value written to legacy command port / prefix byte to indicate protocol
1150 * 3+ structs are being used. Usage is bus-dependent.
1151 */
1152 #define EC_COMMAND_PROTOCOL_3 0xda
1153
1154 #define EC_HOST_REQUEST_VERSION 3
1155
1156 /**
1157 * struct ec_host_request - Version 3 request from host.
1158 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
1159 * receives a header with a version it doesn't know how to
1160 * parse.
1161 * @checksum: Checksum of request and data; sum of all bytes including checksum
1162 * should total to 0.
1163 * @command: Command to send (EC_CMD_...)
1164 * @command_version: Command version.
1165 * @reserved: Unused byte in current protocol version; set to 0.
1166 * @data_len: Length of data which follows this header.
1167 */
1168 struct ec_host_request {
1169 uint8_t struct_version;
1170 uint8_t checksum;
1171 uint16_t command;
1172 uint8_t command_version;
1173 uint8_t reserved;
1174 uint16_t data_len;
1175 } __ec_align4;
1176
1177 #define EC_HOST_RESPONSE_VERSION 3
1178
1179 /**
1180 * struct ec_host_response - Version 3 response from EC.
1181 * @struct_version: Struct version (=3).
1182 * @checksum: Checksum of response and data; sum of all bytes including
1183 * checksum should total to 0.
1184 * @result: EC's response to the command (separate from communication failure)
1185 * @data_len: Length of data which follows this header.
1186 * @reserved: Unused bytes in current protocol version; set to 0.
1187 */
1188 struct ec_host_response {
1189 uint8_t struct_version;
1190 uint8_t checksum;
1191 uint16_t result;
1192 uint16_t data_len;
1193 uint16_t reserved;
1194 } __ec_align4;
1195
1196 /*****************************************************************************/
1197
1198 /*
1199 * Host command protocol V4.
1200 *
1201 * Packets always start with a request or response header. They are followed
1202 * by data_len bytes of data. If the data_crc_present flag is set, the data
1203 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
1204 * polynomial.
1205 *
1206 * Host algorithm when sending a request q:
1207 *
1208 * 101) tries_left=(some value, e.g. 3);
1209 * 102) q.seq_num++
1210 * 103) q.seq_dup=0
1211 * 104) Calculate q.header_crc.
1212 * 105) Send request q to EC.
1213 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1214 *
1215 * 201) If r.struct_version != 4, go to 301.
1216 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1217 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1218 * 204) If r.seq_num != q.seq_num, go to 301.
1219 * 205) If r.seq_dup == q.seq_dup, return success.
1220 * 207) If r.seq_dup == 1, go to 301.
1221 * 208) Return error.
1222 *
1223 * 301) If --tries_left <= 0, return error.
1224 * 302) If q.seq_dup == 1, go to 105.
1225 * 303) q.seq_dup = 1
1226 * 304) Go to 104.
1227 *
1228 * EC algorithm when receiving a request q.
1229 * EC has response buffer r, error buffer e.
1230 *
1231 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1232 * and go to 301
1233 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1234 * EC_RES_INVALID_HEADER_CRC and go to 301
1235 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1236 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1237 * and go to 301.
1238 * 104) If q.seq_dup == 0, go to 201.
1239 * 105) If q.seq_num != r.seq_num, go to 201.
1240 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1241 *
1242 * 201) Process request q into response r.
1243 * 202) r.seq_num = q.seq_num
1244 * 203) r.seq_dup = q.seq_dup
1245 * 204) Calculate r.header_crc
1246 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1247 * EC_RES_DUP_UNAVAILABLE and go to 301.
1248 * 206) Send response r.
1249 *
1250 * 301) e.seq_num = q.seq_num
1251 * 302) e.seq_dup = q.seq_dup
1252 * 303) Calculate e.header_crc.
1253 * 304) Send error response e.
1254 */
1255
1256 /* Version 4 request from host */
1257 struct ec_host_request4 {
1258 /*
1259 * bits 0-3: struct_version: Structure version (=4)
1260 * bit 4: is_response: Is response (=0)
1261 * bits 5-6: seq_num: Sequence number
1262 * bit 7: seq_dup: Sequence duplicate flag
1263 */
1264 uint8_t fields0;
1265
1266 /*
1267 * bits 0-4: command_version: Command version
1268 * bits 5-6: Reserved (set 0, ignore on read)
1269 * bit 7: data_crc_present: Is data CRC present after data
1270 */
1271 uint8_t fields1;
1272
1273 /* Command code (EC_CMD_*) */
1274 uint16_t command;
1275
1276 /* Length of data which follows this header (not including data CRC) */
1277 uint16_t data_len;
1278
1279 /* Reserved (set 0, ignore on read) */
1280 uint8_t reserved;
1281
1282 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1283 uint8_t header_crc;
1284 } __ec_align4;
1285
1286 /* Version 4 response from EC */
1287 struct ec_host_response4 {
1288 /*
1289 * bits 0-3: struct_version: Structure version (=4)
1290 * bit 4: is_response: Is response (=1)
1291 * bits 5-6: seq_num: Sequence number
1292 * bit 7: seq_dup: Sequence duplicate flag
1293 */
1294 uint8_t fields0;
1295
1296 /*
1297 * bits 0-6: Reserved (set 0, ignore on read)
1298 * bit 7: data_crc_present: Is data CRC present after data
1299 */
1300 uint8_t fields1;
1301
1302 /* Result code (EC_RES_*) */
1303 uint16_t result;
1304
1305 /* Length of data which follows this header (not including data CRC) */
1306 uint16_t data_len;
1307
1308 /* Reserved (set 0, ignore on read) */
1309 uint8_t reserved;
1310
1311 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1312 uint8_t header_crc;
1313 } __ec_align4;
1314
1315 /* Fields in fields0 byte */
1316 #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1317 #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1318 #define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1319 #define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1320 #define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1321
1322 /* Fields in fields1 byte */
1323 #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1324 #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1325
1326 /*****************************************************************************/
1327 /*
1328 * Notes on commands:
1329 *
1330 * Each command is an 16-bit command value. Commands which take params or
1331 * return response data specify structures for that data. If no structure is
1332 * specified, the command does not input or output data, respectively.
1333 * Parameter/response length is implicit in the structs. Some underlying
1334 * communication protocols (I2C, SPI) may add length or checksum headers, but
1335 * those are implementation-dependent and not defined here.
1336 *
1337 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1338 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
1339 */
1340
1341 /*****************************************************************************/
1342 /* General / test commands */
1343
1344 /*
1345 * Get protocol version, used to deal with non-backward compatible protocol
1346 * changes.
1347 */
1348 #define EC_CMD_PROTO_VERSION 0x0000
1349
1350 /**
1351 * struct ec_response_proto_version - Response to the proto version command.
1352 * @version: The protocol version.
1353 */
1354 struct ec_response_proto_version {
1355 uint32_t version;
1356 } __ec_align4;
1357
1358 /*
1359 * Hello. This is a simple command to test the EC is responsive to
1360 * commands.
1361 */
1362 #define EC_CMD_HELLO 0x0001
1363
1364 /**
1365 * struct ec_params_hello - Parameters to the hello command.
1366 * @in_data: Pass anything here.
1367 */
1368 struct ec_params_hello {
1369 uint32_t in_data;
1370 } __ec_align4;
1371
1372 /**
1373 * struct ec_response_hello - Response to the hello command.
1374 * @out_data: Output will be in_data + 0x01020304.
1375 */
1376 struct ec_response_hello {
1377 uint32_t out_data;
1378 } __ec_align4;
1379
1380 /* Get version number */
1381 #define EC_CMD_GET_VERSION 0x0002
1382
1383 enum ec_image {
1384 EC_IMAGE_UNKNOWN = 0,
1385 EC_IMAGE_RO,
1386 EC_IMAGE_RW,
1387 EC_IMAGE_RW_A = EC_IMAGE_RW,
1388 EC_IMAGE_RO_B,
1389 EC_IMAGE_RW_B,
1390 };
1391
1392 /**
1393 * struct ec_response_get_version - Response to the v0 get version command.
1394 * @version_string_ro: Null-terminated RO firmware version string.
1395 * @version_string_rw: Null-terminated RW firmware version string.
1396 * @reserved: Unused bytes; was previously RW-B firmware version string.
1397 * @current_image: One of ec_image.
1398 */
1399 struct ec_response_get_version {
1400 char version_string_ro[32];
1401 char version_string_rw[32];
1402 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
1403 uint32_t current_image;
1404 } __ec_align4;
1405
1406 /**
1407 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1408 *
1409 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1410 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1411 * and adds one additional field (cros_fwid_rw).
1412 *
1413 * @version_string_ro: Null-terminated RO firmware version string.
1414 * @version_string_rw: Null-terminated RW firmware version string.
1415 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1416 * @current_image: One of ec_image.
1417 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1418 */
1419 struct ec_response_get_version_v1 {
1420 char version_string_ro[32];
1421 char version_string_rw[32];
1422 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
1423 uint32_t current_image;
1424 char cros_fwid_rw[32]; /* Added in version 1 */
1425 } __ec_align4;
1426
1427 /* Read test - OBSOLETE */
1428 #define EC_CMD_READ_TEST 0x0003
1429
1430 /*
1431 * Get build information
1432 *
1433 * Response is null-terminated string.
1434 */
1435 #define EC_CMD_GET_BUILD_INFO 0x0004
1436
1437 /* Get chip info */
1438 #define EC_CMD_GET_CHIP_INFO 0x0005
1439
1440 /**
1441 * struct ec_response_get_chip_info - Response to the get chip info command.
1442 * @vendor: Null-terminated string for chip vendor.
1443 * @name: Null-terminated string for chip name.
1444 * @revision: Null-terminated string for chip mask version.
1445 */
1446 struct ec_response_get_chip_info {
1447 char vendor[32];
1448 char name[32];
1449 char revision[32];
1450 } __ec_align4;
1451
1452 /* Get board HW version */
1453 #define EC_CMD_GET_BOARD_VERSION 0x0006
1454
1455 /**
1456 * struct ec_response_board_version - Response to the board version command.
1457 * @board_version: A monotonously incrementing number.
1458 */
1459 struct ec_response_board_version {
1460 uint16_t board_version;
1461 } __ec_align2;
1462
1463 /*
1464 * Read memory-mapped data.
1465 *
1466 * This is an alternate interface to memory-mapped data for bus protocols
1467 * which don't support direct-mapped memory - I2C, SPI, etc.
1468 *
1469 * Response is params.size bytes of data.
1470 */
1471 #define EC_CMD_READ_MEMMAP 0x0007
1472
1473 /**
1474 * struct ec_params_read_memmap - Parameters for the read memory map command.
1475 * @offset: Offset in memmap (EC_MEMMAP_*).
1476 * @size: Size to read in bytes.
1477 */
1478 struct ec_params_read_memmap {
1479 uint8_t offset;
1480 uint8_t size;
1481 } __ec_align1;
1482
1483 /* Read versions supported for a command */
1484 #define EC_CMD_GET_CMD_VERSIONS 0x0008
1485
1486 /**
1487 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1488 * @cmd: Command to check.
1489 */
1490 struct ec_params_get_cmd_versions {
1491 uint8_t cmd;
1492 } __ec_align1;
1493
1494 /**
1495 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1496 * versions (v1)
1497 * @cmd: Command to check.
1498 */
1499 struct ec_params_get_cmd_versions_v1 {
1500 uint16_t cmd;
1501 } __ec_align2;
1502
1503 /**
1504 * struct ec_response_get_cmd_version - Response to the get command versions.
1505 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1506 * a desired version.
1507 */
1508 struct ec_response_get_cmd_versions {
1509 uint32_t version_mask;
1510 } __ec_align4;
1511
1512 /*
1513 * Check EC communications status (busy). This is needed on i2c/spi but not
1514 * on lpc since it has its own out-of-band busy indicator.
1515 *
1516 * lpc must read the status from the command register. Attempting this on
1517 * lpc will overwrite the args/parameter space and corrupt its data.
1518 */
1519 #define EC_CMD_GET_COMMS_STATUS 0x0009
1520
1521 /* Avoid using ec_status which is for return values */
1522 enum ec_comms_status {
1523 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
1524 };
1525
1526 /**
1527 * struct ec_response_get_comms_status - Response to the get comms status
1528 * command.
1529 * @flags: Mask of enum ec_comms_status.
1530 */
1531 struct ec_response_get_comms_status {
1532 uint32_t flags; /* Mask of enum ec_comms_status */
1533 } __ec_align4;
1534
1535 /* Fake a variety of responses, purely for testing purposes. */
1536 #define EC_CMD_TEST_PROTOCOL 0x000A
1537
1538 /* Tell the EC what to send back to us. */
1539 struct ec_params_test_protocol {
1540 uint32_t ec_result;
1541 uint32_t ret_len;
1542 uint8_t buf[32];
1543 } __ec_align4;
1544
1545 /* Here it comes... */
1546 struct ec_response_test_protocol {
1547 uint8_t buf[32];
1548 } __ec_align4;
1549
1550 /* Get protocol information */
1551 #define EC_CMD_GET_PROTOCOL_INFO 0x000B
1552
1553 /* Flags for ec_response_get_protocol_info.flags */
1554 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
1555 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
1556
1557 /**
1558 * struct ec_response_get_protocol_info - Response to the get protocol info.
1559 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1560 * version n).
1561 * @max_request_packet_size: Maximum request packet size in bytes.
1562 * @max_response_packet_size: Maximum response packet size in bytes.
1563 * @flags: see EC_PROTOCOL_INFO_*
1564 */
1565 struct ec_response_get_protocol_info {
1566 /* Fields which exist if at least protocol version 3 supported */
1567 uint32_t protocol_versions;
1568 uint16_t max_request_packet_size;
1569 uint16_t max_response_packet_size;
1570 uint32_t flags;
1571 } __ec_align4;
1572
1573 /*****************************************************************************/
1574 /* Get/Set miscellaneous values */
1575
1576 /* The upper byte of .flags tells what to do (nothing means "get") */
1577 #define EC_GSV_SET 0x80000000
1578
1579 /*
1580 * The lower three bytes of .flags identifies the parameter, if that has
1581 * meaning for an individual command.
1582 */
1583 #define EC_GSV_PARAM_MASK 0x00ffffff
1584
1585 struct ec_params_get_set_value {
1586 uint32_t flags;
1587 uint32_t value;
1588 } __ec_align4;
1589
1590 struct ec_response_get_set_value {
1591 uint32_t flags;
1592 uint32_t value;
1593 } __ec_align4;
1594
1595 /* More than one command can use these structs to get/set parameters. */
1596 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
1597
1598 /*****************************************************************************/
1599 /* List the features supported by the firmware */
1600 #define EC_CMD_GET_FEATURES 0x000D
1601
1602 /* Supported features */
1603 enum ec_feature_code {
1604 /*
1605 * This image contains a limited set of features. Another image
1606 * in RW partition may support more features.
1607 */
1608 EC_FEATURE_LIMITED = 0,
1609 /*
1610 * Commands for probing/reading/writing/erasing the flash in the
1611 * EC are present.
1612 */
1613 EC_FEATURE_FLASH = 1,
1614 /*
1615 * Can control the fan speed directly.
1616 */
1617 EC_FEATURE_PWM_FAN = 2,
1618 /*
1619 * Can control the intensity of the keyboard backlight.
1620 */
1621 EC_FEATURE_PWM_KEYB = 3,
1622 /*
1623 * Support Google lightbar, introduced on Pixel.
1624 */
1625 EC_FEATURE_LIGHTBAR = 4,
1626 /* Control of LEDs */
1627 EC_FEATURE_LED = 5,
1628 /* Exposes an interface to control gyro and sensors.
1629 * The host goes through the EC to access these sensors.
1630 * In addition, the EC may provide composite sensors, like lid angle.
1631 */
1632 EC_FEATURE_MOTION_SENSE = 6,
1633 /* The keyboard is controlled by the EC */
1634 EC_FEATURE_KEYB = 7,
1635 /* The AP can use part of the EC flash as persistent storage. */
1636 EC_FEATURE_PSTORE = 8,
1637 /* The EC monitors BIOS port 80h, and can return POST codes. */
1638 EC_FEATURE_PORT80 = 9,
1639 /*
1640 * Thermal management: include TMP specific commands.
1641 * Higher level than direct fan control.
1642 */
1643 EC_FEATURE_THERMAL = 10,
1644 /* Can switch the screen backlight on/off */
1645 EC_FEATURE_BKLIGHT_SWITCH = 11,
1646 /* Can switch the wifi module on/off */
1647 EC_FEATURE_WIFI_SWITCH = 12,
1648 /* Monitor host events, through for example SMI or SCI */
1649 EC_FEATURE_HOST_EVENTS = 13,
1650 /* The EC exposes GPIO commands to control/monitor connected devices. */
1651 EC_FEATURE_GPIO = 14,
1652 /* The EC can send i2c messages to downstream devices. */
1653 EC_FEATURE_I2C = 15,
1654 /* Command to control charger are included */
1655 EC_FEATURE_CHARGER = 16,
1656 /* Simple battery support. */
1657 EC_FEATURE_BATTERY = 17,
1658 /*
1659 * Support Smart battery protocol
1660 * (Common Smart Battery System Interface Specification)
1661 */
1662 EC_FEATURE_SMART_BATTERY = 18,
1663 /* EC can detect when the host hangs. */
1664 EC_FEATURE_HANG_DETECT = 19,
1665 /* Report power information, for pit only */
1666 EC_FEATURE_PMU = 20,
1667 /* Another Cros EC device is present downstream of this one */
1668 EC_FEATURE_SUB_MCU = 21,
1669 /* Support USB Power delivery (PD) commands */
1670 EC_FEATURE_USB_PD = 22,
1671 /* Control USB multiplexer, for audio through USB port for instance. */
1672 EC_FEATURE_USB_MUX = 23,
1673 /* Motion Sensor code has an internal software FIFO */
1674 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1675 /* Support temporary secure vstore */
1676 EC_FEATURE_VSTORE = 25,
1677 /* EC decides on USB-C SS mux state, muxes configured by host */
1678 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1679 /* EC has RTC feature that can be controlled by host commands */
1680 EC_FEATURE_RTC = 27,
1681 /* The MCU exposes a Fingerprint sensor */
1682 EC_FEATURE_FINGERPRINT = 28,
1683 /* The MCU exposes a Touchpad */
1684 EC_FEATURE_TOUCHPAD = 29,
1685 /* The MCU has RWSIG task enabled */
1686 EC_FEATURE_RWSIG = 30,
1687 /* EC has device events support */
1688 EC_FEATURE_DEVICE_EVENT = 31,
1689 /* EC supports the unified wake masks for LPC/eSPI systems */
1690 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1691 /* EC supports 64-bit host events */
1692 EC_FEATURE_HOST_EVENT64 = 33,
1693 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1694 EC_FEATURE_EXEC_IN_RAM = 34,
1695 /* EC supports CEC commands */
1696 EC_FEATURE_CEC = 35,
1697 /* EC supports tight sensor timestamping. */
1698 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
1699 /*
1700 * EC supports tablet mode detection aligned to Chrome and allows
1701 * setting of threshold by host command using
1702 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1703 */
1704 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
1705 /*
1706 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
1707 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1708 * be sent to RO to be precise.
1709 */
1710 EC_FEATURE_EFS2 = 38,
1711 /* The MCU is a System Companion Processor (SCP). */
1712 EC_FEATURE_SCP = 39,
1713 /* The MCU is an Integrated Sensor Hub */
1714 EC_FEATURE_ISH = 40,
1715 /* New TCPMv2 TYPEC_ prefaced commands supported */
1716 EC_FEATURE_TYPEC_CMD = 41,
1717 /*
1718 * The EC will wait for direction from the AP to enter Type-C alternate
1719 * modes or USB4.
1720 */
1721 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1722 /*
1723 * The EC will wait for an acknowledge from the AP after setting the
1724 * mux.
1725 */
1726 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
1727 /*
1728 * The EC supports entering and residing in S4.
1729 */
1730 EC_FEATURE_S4_RESIDENCY = 44,
1731 /*
1732 * The EC supports the AP directing mux sets for the board.
1733 */
1734 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
1735 /*
1736 * The EC supports the AP composing VDMs for us to send.
1737 */
1738 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
1739 /*
1740 * The EC supports system safe mode panic recovery.
1741 */
1742 EC_FEATURE_SYSTEM_SAFE_MODE = 47,
1743 /*
1744 * The EC will reboot on runtime assertion failures.
1745 */
1746 EC_FEATURE_ASSERT_REBOOTS = 48,
1747 /*
1748 * The EC image is built with tokenized logging enabled.
1749 */
1750 EC_FEATURE_TOKENIZED_LOGGING = 49,
1751 /*
1752 * The EC supports triggering an STB dump.
1753 */
1754 EC_FEATURE_AMD_STB_DUMP = 50,
1755 /*
1756 * The EC supports memory dump commands.
1757 */
1758 EC_FEATURE_MEMORY_DUMP = 51,
1759 /*
1760 * The EC supports DP2.1 capability
1761 */
1762 EC_FEATURE_TYPEC_DP2_1 = 52,
1763 /*
1764 * The MCU is System Companion Processor Core 1
1765 */
1766 EC_FEATURE_SCP_C1 = 53,
1767 /*
1768 * The EC supports UCSI PPM.
1769 */
1770 EC_FEATURE_UCSI_PPM = 54,
1771 /*
1772 * The EC supports Strauss keyboard.
1773 */
1774 EC_FEATURE_STRAUSS = 55,
1775 /*
1776 * The EC supports PoE.
1777 */
1778 EC_FEATURE_POE = 56,
1779 };
1780
1781 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1782 #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1783
1784 struct ec_response_get_features {
1785 uint32_t flags[2];
1786 } __ec_align4;
1787
1788 /*****************************************************************************/
1789 /* Get the board's SKU ID from EC */
1790 #define EC_CMD_GET_SKU_ID 0x000E
1791
1792 /* Set SKU ID from AP */
1793 #define EC_CMD_SET_SKU_ID 0x000F
1794
1795 struct ec_sku_id_info {
1796 uint32_t sku_id;
1797 } __ec_align4;
1798
1799 /*****************************************************************************/
1800 /* Flash commands */
1801
1802 /* Get flash info */
1803 #define EC_CMD_FLASH_INFO 0x0010
1804 #define EC_VER_FLASH_INFO 2
1805
1806 /**
1807 * struct ec_response_flash_info - Response to the flash info command.
1808 * @flash_size: Usable flash size in bytes.
1809 * @write_block_size: Write block size. Write offset and size must be a
1810 * multiple of this.
1811 * @erase_block_size: Erase block size. Erase offset and size must be a
1812 * multiple of this.
1813 * @protect_block_size: Protection block size. Protection offset and size
1814 * must be a multiple of this.
1815 *
1816 * Version 0 returns these fields.
1817 */
1818 struct ec_response_flash_info {
1819 uint32_t flash_size;
1820 uint32_t write_block_size;
1821 uint32_t erase_block_size;
1822 uint32_t protect_block_size;
1823 } __ec_align4;
1824
1825 /*
1826 * Flags for version 1+ flash info command
1827 * EC flash erases bits to 0 instead of 1.
1828 */
1829 #define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
1830
1831 /*
1832 * Flash must be selected for read/write/erase operations to succeed. This may
1833 * be necessary on a chip where write/erase can be corrupted by other board
1834 * activity, or where the chip needs to enable some sort of programming voltage,
1835 * or where the read/write/erase operations require cleanly suspending other
1836 * chip functionality.
1837 */
1838 #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
1839
1840 /**
1841 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1842 * @flash_size: Usable flash size in bytes.
1843 * @write_block_size: Write block size. Write offset and size must be a
1844 * multiple of this.
1845 * @erase_block_size: Erase block size. Erase offset and size must be a
1846 * multiple of this.
1847 * @protect_block_size: Protection block size. Protection offset and size
1848 * must be a multiple of this.
1849 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1850 * size is exactly this and offset is a multiple of this.
1851 * For example, an EC may have a write buffer which can do
1852 * half-page operations if data is aligned, and a slower
1853 * word-at-a-time write mode.
1854 * @flags: Flags; see EC_FLASH_INFO_*
1855 *
1856 * Version 1 returns the same initial fields as version 0, with additional
1857 * fields following.
1858 *
1859 * gcc anonymous structs don't seem to get along with the __packed directive;
1860 * if they did we'd define the version 0 structure as a sub-structure of this
1861 * one.
1862 *
1863 * Version 2 supports flash banks of different sizes:
1864 * The caller specified the number of banks it has preallocated
1865 * (num_banks_desc)
1866 * The EC returns the number of banks describing the flash memory.
1867 * It adds banks descriptions up to num_banks_desc.
1868 */
1869 struct ec_response_flash_info_1 {
1870 /* Version 0 fields; see above for description */
1871 uint32_t flash_size;
1872 uint32_t write_block_size;
1873 uint32_t erase_block_size;
1874 uint32_t protect_block_size;
1875
1876 /* Version 1 adds these fields: */
1877 uint32_t write_ideal_size;
1878 uint32_t flags;
1879 } __ec_align4;
1880
1881 struct ec_params_flash_info_2 {
1882 /* Number of banks to describe */
1883 uint16_t num_banks_desc;
1884 /* Reserved; set 0; ignore on read */
1885 uint8_t reserved[2];
1886 } __ec_align4;
1887
1888 struct ec_flash_bank {
1889 /* Number of sector is in this bank. */
1890 uint16_t count;
1891 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1892 uint8_t size_exp;
1893 /* Minimal write size for the sectors in this bank */
1894 uint8_t write_size_exp;
1895 /* Erase size for the sectors in this bank */
1896 uint8_t erase_size_exp;
1897 /* Size for write protection, usually identical to erase size. */
1898 uint8_t protect_size_exp;
1899 /* Reserved; set 0; ignore on read */
1900 uint8_t reserved[2];
1901 };
1902
1903 struct ec_response_flash_info_2 {
1904 /* Total flash in the EC. */
1905 uint32_t flash_size;
1906 /* Flags; see EC_FLASH_INFO_* */
1907 uint32_t flags;
1908 /* Maximum size to use to send data to write to the EC. */
1909 uint32_t write_ideal_size;
1910 /* Number of banks present in the EC. */
1911 uint16_t num_banks_total;
1912 /* Number of banks described in banks array. */
1913 uint16_t num_banks_desc;
1914 struct ec_flash_bank banks[FLEXIBLE_ARRAY_MEMBER_SIZE];
1915 } __ec_align4;
1916
1917 /*
1918 * Read flash
1919 *
1920 * Response is params.size bytes of data.
1921 */
1922 #define EC_CMD_FLASH_READ 0x0011
1923
1924 /**
1925 * struct ec_params_flash_read - Parameters for the flash read command.
1926 * @offset: Byte offset to read.
1927 * @size: Size to read in bytes.
1928 */
1929 struct ec_params_flash_read {
1930 uint32_t offset;
1931 uint32_t size;
1932 } __ec_align4;
1933
1934 /* Write flash */
1935 #define EC_CMD_FLASH_WRITE 0x0012
1936 #define EC_VER_FLASH_WRITE 1
1937
1938 /* Version 0 of the flash command supported only 64 bytes of data */
1939 #define EC_FLASH_WRITE_VER0_SIZE 64
1940
1941 /**
1942 * struct ec_params_flash_write - Parameters for the flash write command.
1943 * @offset: Byte offset to write.
1944 * @size: Size to write in bytes.
1945 * @data: Data to write.
1946 * @data.words32: uint32_t data to write.
1947 * @data.bytes: uint8_t data to write.
1948 */
1949 struct ec_params_flash_write {
1950 uint32_t offset;
1951 uint32_t size;
1952 /* Followed by data to write. This union allows accessing an
1953 * underlying buffer as uint32s or uint8s for convenience.
1954 */
1955 union {
1956 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1957 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1958 } data;
1959 } __ec_align4;
1960 BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
1961
1962 /* Erase flash */
1963 #define EC_CMD_FLASH_ERASE 0x0013
1964
1965 /**
1966 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1967 * @offset: Byte offset to erase.
1968 * @size: Size to erase in bytes.
1969 */
1970 struct ec_params_flash_erase {
1971 uint32_t offset;
1972 uint32_t size;
1973 } __ec_align4;
1974
1975 /*
1976 * v1 add async erase:
1977 * subcommands can returns:
1978 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1979 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1980 * EC_RES_ERROR : other errors.
1981 * EC_RES_BUSY : an existing erase operation is in progress.
1982 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1983 *
1984 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1985 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1986 * the proper result.
1987 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1988 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1989 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1990 * permitted while erasing. (For instance, STM32F4).
1991 */
1992 enum ec_flash_erase_cmd {
1993 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1994 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1995 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1996 };
1997
1998 /**
1999 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
2000 * @cmd: One of ec_flash_erase_cmd.
2001 * @reserved: Pad byte; currently always contains 0.
2002 * @flag: No flags defined yet; set to 0.
2003 * @params: Same as v0 parameters.
2004 */
2005 struct ec_params_flash_erase_v1 {
2006 uint8_t cmd;
2007 uint8_t reserved;
2008 uint16_t flag;
2009 struct ec_params_flash_erase params;
2010 } __ec_align4;
2011
2012 /*
2013 * Get/set flash protection.
2014 *
2015 * If mask!=0, sets/clear the requested bits of flags. Depending on the
2016 * firmware write protect GPIO, not all flags will take effect immediately;
2017 * some flags require a subsequent hard reset to take effect. Check the
2018 * returned flags bits to see what actually happened.
2019 *
2020 * If mask=0, simply returns the current flags state.
2021 */
2022 #define EC_CMD_FLASH_PROTECT 0x0015
2023 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
2024
2025 /* Flags for flash protection */
2026 /* RO flash code protected when the EC boots */
2027 #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
2028 /*
2029 * RO flash code protected now. If this bit is set, at-boot status cannot
2030 * be changed.
2031 */
2032 #define EC_FLASH_PROTECT_RO_NOW BIT(1)
2033 /* Entire flash code protected now, until reboot. */
2034 #define EC_FLASH_PROTECT_ALL_NOW BIT(2)
2035 /* Flash write protect GPIO is asserted now */
2036 #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
2037 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
2038 #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
2039 /*
2040 * Error - flash protection is in inconsistent state. At least one bank of
2041 * flash which should be protected is not protected. Usually fixed by
2042 * re-requesting the desired flags, or by a hard reset if that fails.
2043 */
2044 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
2045 /* Entire flash code protected when the EC boots */
2046 #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
2047 /* RW flash code protected when the EC boots */
2048 #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
2049 /* RW flash code protected now. */
2050 #define EC_FLASH_PROTECT_RW_NOW BIT(8)
2051 /* Rollback information flash region protected when the EC boots */
2052 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
2053 /* Rollback information flash region protected now */
2054 #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
2055 /* Error - Unknown error */
2056 #define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
2057
2058 /**
2059 * struct ec_params_flash_protect - Parameters for the flash protect command.
2060 * @mask: Bits in flags to apply.
2061 * @flags: New flags to apply.
2062 */
2063 struct ec_params_flash_protect {
2064 uint32_t mask;
2065 uint32_t flags;
2066 } __ec_align4;
2067
2068 enum flash_protect_action {
2069 FLASH_PROTECT_ASYNC = 0,
2070 FLASH_PROTECT_GET_RESULT = 1,
2071 };
2072
2073 /* Version 2 of the command is "asynchronous". */
2074 struct ec_params_flash_protect_v2 {
2075 uint8_t action; /**< enum flash_protect_action */
2076 uint8_t reserved[3]; /**< padding for alignment */
2077 uint32_t mask;
2078 uint32_t flags;
2079 } __ec_align4;
2080
2081 /**
2082 * struct ec_response_flash_protect - Response to the flash protect command.
2083 * @flags: Current value of flash protect flags.
2084 * @valid_flags: Flags which are valid on this platform. This allows the
2085 * caller to distinguish between flags which aren't set vs. flags
2086 * which can't be set on this platform.
2087 * @writable_flags: Flags which can be changed given the current protection
2088 * state.
2089 */
2090 struct ec_response_flash_protect {
2091 uint32_t flags;
2092 uint32_t valid_flags;
2093 uint32_t writable_flags;
2094 } __ec_align4;
2095
2096 /*
2097 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
2098 * write protect. These commands may be reused with version > 0.
2099 */
2100
2101 /* Get the region offset/size */
2102 #define EC_CMD_FLASH_REGION_INFO 0x0016
2103 #define EC_VER_FLASH_REGION_INFO 1
2104
2105 enum ec_flash_region {
2106 /* Region which holds read-only EC image */
2107 EC_FLASH_REGION_RO = 0,
2108 /*
2109 * Region which holds active RW image. 'Active' is different from
2110 * 'running'. Active means 'scheduled-to-run'. Since RO image always
2111 * scheduled to run, active/non-active applies only to RW images (for
2112 * the same reason 'update' applies only to RW images. It's a state of
2113 * an image on a flash. Running image can be RO, RW_A, RW_B but active
2114 * image can only be RW_A or RW_B. In recovery mode, an active RW image
2115 * doesn't enter 'running' state but it's still active on a flash.
2116 */
2117 EC_FLASH_REGION_ACTIVE,
2118 /*
2119 * Region which should be write-protected in the factory (a superset of
2120 * EC_FLASH_REGION_RO)
2121 */
2122 EC_FLASH_REGION_WP_RO,
2123 /* Region which holds updatable (non-active) RW image */
2124 EC_FLASH_REGION_UPDATE,
2125 /* Number of regions */
2126 EC_FLASH_REGION_COUNT,
2127 };
2128 /*
2129 * 'RW' is vague if there are multiple RW images; we mean the active one,
2130 * so the old constant is deprecated.
2131 */
2132 #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
2133
2134 /**
2135 * struct ec_params_flash_region_info - Parameters for the flash region info
2136 * command.
2137 * @region: Flash region; see EC_FLASH_REGION_*
2138 */
2139 struct ec_params_flash_region_info {
2140 uint32_t region;
2141 } __ec_align4;
2142
2143 struct ec_response_flash_region_info {
2144 uint32_t offset;
2145 uint32_t size;
2146 } __ec_align4;
2147
2148 /* Get SPI flash information */
2149 #define EC_CMD_FLASH_SPI_INFO 0x0018
2150
2151 struct ec_response_flash_spi_info {
2152 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
2153 uint8_t jedec[3];
2154
2155 /* Pad byte; currently always contains 0 */
2156 uint8_t reserved0;
2157
2158 /* Manufacturer / device ID from command 0x90 */
2159 uint8_t mfr_dev_id[2];
2160
2161 /* Status registers from command 0x05 and 0x35 */
2162 uint8_t sr1, sr2;
2163 } __ec_align1;
2164
2165 /* Select flash during flash operations */
2166 #define EC_CMD_FLASH_SELECT 0x0019
2167
2168 /**
2169 * struct ec_params_flash_select - Parameters for the flash select command.
2170 * @select: 1 to select flash, 0 to deselect flash
2171 */
2172 struct ec_params_flash_select {
2173 uint8_t select;
2174 } __ec_align4;
2175
2176 /**
2177 * Request random numbers to be generated and returned.
2178 * Can be used to test the random number generator is truly random.
2179 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
2180 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
2181 */
2182 #define EC_CMD_RAND_NUM 0x001A
2183 #define EC_VER_RAND_NUM 0
2184
2185 struct ec_params_rand_num {
2186 uint16_t num_rand_bytes; /**< num random bytes to generate */
2187 } __ec_align4;
2188
2189 struct ec_response_rand_num {
2190 /**
2191 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
2192 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
2193 */
2194 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
2195 } __ec_align1;
2196 BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
2197
2198 /**
2199 * Get information about the key used to sign the RW firmware.
2200 * For more details on the fields, see "struct vb21_packed_key".
2201 */
2202 #define EC_CMD_RWSIG_INFO 0x001B
2203 #define EC_VER_RWSIG_INFO 0
2204
2205 #define VBOOT2_KEY_ID_BYTES 20
2206
2207 #ifdef CHROMIUM_EC
2208 /* Don't force external projects to depend on the vboot headers. */
2209 #include "vb21_struct.h"
2210 BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2211 #endif
2212
2213 struct ec_response_rwsig_info {
2214 /**
2215 * Signature algorithm used by the key
2216 * (enum vb2_signature_algorithm).
2217 */
2218 uint16_t sig_alg;
2219
2220 /**
2221 * Hash digest algorithm used with the key
2222 * (enum vb2_hash_algorithm).
2223 */
2224 uint16_t hash_alg;
2225
2226 /** Key version. */
2227 uint32_t key_version;
2228
2229 /** Key ID (struct vb2_id). */
2230 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2231
2232 uint8_t key_is_valid;
2233
2234 /** Alignment padding. */
2235 uint8_t reserved[3];
2236 } __ec_align4;
2237
2238 BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2239
2240 /**
2241 * Get information about the system, such as reset flags, locked state, etc.
2242 */
2243 #define EC_CMD_SYSINFO 0x001C
2244 #define EC_VER_SYSINFO 0
2245
2246 enum sysinfo_flags {
2247 SYSTEM_IS_LOCKED = BIT(0),
2248 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2249 SYSTEM_JUMP_ENABLED = BIT(2),
2250 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
2251 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2252 /*
2253 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2254 * set and cleared when the system shuts down (not when the host event
2255 * flag is cleared).
2256 */
2257 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
2258 };
2259
2260 struct ec_response_sysinfo {
2261 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
2262 uint32_t current_image; /**< enum ec_image */
2263 uint32_t flags; /**< enum sysinfo_flags */
2264 } __ec_align4;
2265
2266 /*****************************************************************************/
2267 /* PWM commands */
2268
2269 /* Get fan target RPM */
2270 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
2271
2272 struct ec_response_pwm_get_fan_rpm {
2273 uint32_t rpm;
2274 } __ec_align4;
2275
2276 /* Set target fan RPM */
2277 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
2278
2279 /* Version 0 of input params */
2280 struct ec_params_pwm_set_fan_target_rpm_v0 {
2281 uint32_t rpm;
2282 } __ec_align4;
2283
2284 /* Version 1 of input params */
2285 struct ec_params_pwm_set_fan_target_rpm_v1 {
2286 uint32_t rpm;
2287 uint8_t fan_idx;
2288 } __ec_align_size1;
2289
2290 /* Get keyboard backlight */
2291 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
2292 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
2293
2294 struct ec_response_pwm_get_keyboard_backlight {
2295 uint8_t percent;
2296 uint8_t enabled;
2297 } __ec_align1;
2298
2299 /* Set keyboard backlight */
2300 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
2301 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
2302
2303 struct ec_params_pwm_set_keyboard_backlight {
2304 uint8_t percent;
2305 } __ec_align1;
2306
2307 /* Set target fan PWM duty cycle */
2308 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
2309
2310 /* Version 0 of input params */
2311 struct ec_params_pwm_set_fan_duty_v0 {
2312 uint32_t percent;
2313 } __ec_align4;
2314
2315 /* Version 1 of input params */
2316 struct ec_params_pwm_set_fan_duty_v1 {
2317 uint32_t percent;
2318 uint8_t fan_idx;
2319 } __ec_align_size1;
2320
2321 #define EC_CMD_PWM_SET_DUTY 0x0025
2322 /* 16 bit duty cycle, 0xffff = 100% */
2323 #define EC_PWM_MAX_DUTY 0xffff
2324
2325 enum ec_pwm_type {
2326 /* All types, indexed by board-specific enum pwm_channel */
2327 EC_PWM_TYPE_GENERIC = 0,
2328 /* Keyboard backlight */
2329 EC_PWM_TYPE_KB_LIGHT,
2330 /* Display backlight */
2331 EC_PWM_TYPE_DISPLAY_LIGHT,
2332 EC_PWM_TYPE_COUNT,
2333 };
2334
2335 struct ec_params_pwm_set_duty {
2336 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2337 uint8_t pwm_type; /* ec_pwm_type */
2338 uint8_t index; /* Type-specific index, or 0 if unique */
2339 } __ec_align4;
2340
2341 #define EC_CMD_PWM_GET_DUTY 0x0026
2342
2343 struct ec_params_pwm_get_duty {
2344 uint8_t pwm_type; /* ec_pwm_type */
2345 uint8_t index; /* Type-specific index, or 0 if unique */
2346 } __ec_align1;
2347
2348 struct ec_response_pwm_get_duty {
2349 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2350 } __ec_align2;
2351
2352 #define EC_CMD_PWM_GET_FAN_DUTY 0x0027
2353
2354 struct ec_params_pwm_get_fan_duty {
2355 uint8_t fan_idx;
2356 } __ec_align1;
2357
2358 struct ec_response_pwm_get_fan_duty {
2359 uint32_t percent; /* Percentage of duty cycle, ranging from 0 ~ 100 */
2360 } __ec_align4;
2361
2362 /*****************************************************************************/
2363 /*
2364 * Lightbar commands. This looks worse than it is. Since we only use one HOST
2365 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2366 * into a subcommand. We'll make separate structs for subcommands with
2367 * different input args, so that we know how much to expect.
2368 */
2369 #define EC_CMD_LIGHTBAR_CMD 0x0028
2370
2371 struct rgb_s {
2372 uint8_t r, g, b;
2373 } __ec_todo_unpacked;
2374
2375 #define LB_BATTERY_LEVELS 4
2376
2377 /*
2378 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
2379 * host command, but the alignment is the same regardless. Keep it that way.
2380 */
2381 struct lightbar_params_v0 {
2382 /* Timing */
2383 int32_t google_ramp_up;
2384 int32_t google_ramp_down;
2385 int32_t s3s0_ramp_up;
2386 int32_t s0_tick_delay[2]; /* AC=0/1 */
2387 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2388 int32_t s0s3_ramp_down;
2389 int32_t s3_sleep_for;
2390 int32_t s3_ramp_up;
2391 int32_t s3_ramp_down;
2392
2393 /* Oscillation */
2394 uint8_t new_s0;
2395 uint8_t osc_min[2]; /* AC=0/1 */
2396 uint8_t osc_max[2]; /* AC=0/1 */
2397 uint8_t w_ofs[2]; /* AC=0/1 */
2398
2399 /* Brightness limits based on the backlight and AC. */
2400 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2401 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2402 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2403
2404 /* Battery level thresholds */
2405 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2406
2407 /* Map [AC][battery_level] to color index */
2408 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2409 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2410
2411 /* Color palette */
2412 struct rgb_s color[8]; /* 0-3 are Google colors */
2413 } __ec_todo_packed;
2414
2415 struct lightbar_params_v1 {
2416 /* Timing */
2417 int32_t google_ramp_up;
2418 int32_t google_ramp_down;
2419 int32_t s3s0_ramp_up;
2420 int32_t s0_tick_delay[2]; /* AC=0/1 */
2421 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2422 int32_t s0s3_ramp_down;
2423 int32_t s3_sleep_for;
2424 int32_t s3_ramp_up;
2425 int32_t s3_ramp_down;
2426 int32_t s5_ramp_up;
2427 int32_t s5_ramp_down;
2428 int32_t tap_tick_delay;
2429 int32_t tap_gate_delay;
2430 int32_t tap_display_time;
2431
2432 /* Tap-for-battery params */
2433 uint8_t tap_pct_red;
2434 uint8_t tap_pct_green;
2435 uint8_t tap_seg_min_on;
2436 uint8_t tap_seg_max_on;
2437 uint8_t tap_seg_osc;
2438 uint8_t tap_idx[3];
2439
2440 /* Oscillation */
2441 uint8_t osc_min[2]; /* AC=0/1 */
2442 uint8_t osc_max[2]; /* AC=0/1 */
2443 uint8_t w_ofs[2]; /* AC=0/1 */
2444
2445 /* Brightness limits based on the backlight and AC. */
2446 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2447 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2448 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2449
2450 /* Battery level thresholds */
2451 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2452
2453 /* Map [AC][battery_level] to color index */
2454 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2455 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2456
2457 /* s5: single color pulse on inhibited power-up */
2458 uint8_t s5_idx;
2459
2460 /* Color palette */
2461 struct rgb_s color[8]; /* 0-3 are Google colors */
2462 } __ec_todo_packed;
2463
2464 /* Lightbar command params v2
2465 * crbug.com/467716
2466 *
2467 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2468 * logical groups to make it more manageable ( < 120 bytes).
2469 *
2470 * NOTE: Each of these groups must be less than 120 bytes.
2471 */
2472
2473 struct lightbar_params_v2_timing {
2474 /* Timing */
2475 int32_t google_ramp_up;
2476 int32_t google_ramp_down;
2477 int32_t s3s0_ramp_up;
2478 int32_t s0_tick_delay[2]; /* AC=0/1 */
2479 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2480 int32_t s0s3_ramp_down;
2481 int32_t s3_sleep_for;
2482 int32_t s3_ramp_up;
2483 int32_t s3_ramp_down;
2484 int32_t s5_ramp_up;
2485 int32_t s5_ramp_down;
2486 int32_t tap_tick_delay;
2487 int32_t tap_gate_delay;
2488 int32_t tap_display_time;
2489 } __ec_todo_packed;
2490
2491 struct lightbar_params_v2_tap {
2492 /* Tap-for-battery params */
2493 uint8_t tap_pct_red;
2494 uint8_t tap_pct_green;
2495 uint8_t tap_seg_min_on;
2496 uint8_t tap_seg_max_on;
2497 uint8_t tap_seg_osc;
2498 uint8_t tap_idx[3];
2499 } __ec_todo_packed;
2500
2501 struct lightbar_params_v2_oscillation {
2502 /* Oscillation */
2503 uint8_t osc_min[2]; /* AC=0/1 */
2504 uint8_t osc_max[2]; /* AC=0/1 */
2505 uint8_t w_ofs[2]; /* AC=0/1 */
2506 } __ec_todo_packed;
2507
2508 struct lightbar_params_v2_brightness {
2509 /* Brightness limits based on the backlight and AC. */
2510 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2511 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2512 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2513 } __ec_todo_packed;
2514
2515 struct lightbar_params_v2_thresholds {
2516 /* Battery level thresholds */
2517 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2518 } __ec_todo_packed;
2519
2520 struct lightbar_params_v2_colors {
2521 /* Map [AC][battery_level] to color index */
2522 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2523 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2524
2525 /* s5: single color pulse on inhibited power-up */
2526 uint8_t s5_idx;
2527
2528 /* Color palette */
2529 struct rgb_s color[8]; /* 0-3 are Google colors */
2530 } __ec_todo_packed;
2531
2532 /* Lightbar program. */
2533 #define EC_LB_PROG_LEN 192
2534 struct lightbar_program {
2535 uint8_t size;
2536 uint8_t data[EC_LB_PROG_LEN];
2537 } __ec_todo_unpacked;
2538
2539 struct ec_params_lightbar {
2540 uint8_t cmd; /* Command (see enum lightbar_command) */
2541 union {
2542 /*
2543 * The following commands have no args:
2544 *
2545 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2546 * version, get_brightness, get_demo, suspend, resume,
2547 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2548 * get_params_v2_bright, get_params_v2_thlds,
2549 * get_params_v2_colors
2550 *
2551 * Don't use an empty struct, because C++ hates that.
2552 */
2553
2554 struct __ec_todo_unpacked {
2555 uint8_t num;
2556 } set_brightness, seq, demo;
2557
2558 struct __ec_todo_unpacked {
2559 uint8_t ctrl, reg, value;
2560 } reg;
2561
2562 struct __ec_todo_unpacked {
2563 uint8_t led, red, green, blue;
2564 } set_rgb;
2565
2566 struct __ec_todo_unpacked {
2567 uint8_t led;
2568 } get_rgb;
2569
2570 struct __ec_todo_unpacked {
2571 uint8_t enable;
2572 } manual_suspend_ctrl;
2573
2574 struct lightbar_params_v0 set_params_v0;
2575 struct lightbar_params_v1 set_params_v1;
2576
2577 struct lightbar_params_v2_timing set_v2par_timing;
2578 struct lightbar_params_v2_tap set_v2par_tap;
2579 struct lightbar_params_v2_oscillation set_v2par_osc;
2580 struct lightbar_params_v2_brightness set_v2par_bright;
2581 struct lightbar_params_v2_thresholds set_v2par_thlds;
2582 struct lightbar_params_v2_colors set_v2par_colors;
2583
2584 struct lightbar_program set_program;
2585 };
2586 } __ec_todo_packed;
2587
2588 struct ec_response_lightbar {
2589 union {
2590 struct __ec_todo_unpacked {
2591 struct __ec_todo_unpacked {
2592 uint8_t reg;
2593 uint8_t ic0;
2594 uint8_t ic1;
2595 } vals[23];
2596 } dump;
2597
2598 struct __ec_todo_unpacked {
2599 uint8_t num;
2600 } get_seq, get_brightness, get_demo;
2601
2602 struct lightbar_params_v0 get_params_v0;
2603 struct lightbar_params_v1 get_params_v1;
2604
2605 struct lightbar_params_v2_timing get_params_v2_timing;
2606 struct lightbar_params_v2_tap get_params_v2_tap;
2607 struct lightbar_params_v2_oscillation get_params_v2_osc;
2608 struct lightbar_params_v2_brightness get_params_v2_bright;
2609 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2610 struct lightbar_params_v2_colors get_params_v2_colors;
2611
2612 struct __ec_todo_unpacked {
2613 uint32_t num;
2614 uint32_t flags;
2615 } version;
2616
2617 struct __ec_todo_unpacked {
2618 uint8_t red, green, blue;
2619 } get_rgb;
2620
2621 /*
2622 * The following commands have no response:
2623 *
2624 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2625 * set_params_v0, set_params_v1, set_program,
2626 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2627 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2628 * set_v2par_thlds, set_v2par_colors
2629 */
2630 };
2631 } __ec_todo_packed;
2632
2633 /* Lightbar commands */
2634 enum lightbar_command {
2635 LIGHTBAR_CMD_DUMP = 0,
2636 LIGHTBAR_CMD_OFF = 1,
2637 LIGHTBAR_CMD_ON = 2,
2638 LIGHTBAR_CMD_INIT = 3,
2639 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
2640 LIGHTBAR_CMD_SEQ = 5,
2641 LIGHTBAR_CMD_REG = 6,
2642 LIGHTBAR_CMD_SET_RGB = 7,
2643 LIGHTBAR_CMD_GET_SEQ = 8,
2644 LIGHTBAR_CMD_DEMO = 9,
2645 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2646 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
2647 LIGHTBAR_CMD_VERSION = 12,
2648 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2649 LIGHTBAR_CMD_GET_RGB = 14,
2650 LIGHTBAR_CMD_GET_DEMO = 15,
2651 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2652 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
2653 LIGHTBAR_CMD_SET_PROGRAM = 18,
2654 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2655 LIGHTBAR_CMD_SUSPEND = 20,
2656 LIGHTBAR_CMD_RESUME = 21,
2657 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2658 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2659 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2660 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2661 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2662 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2663 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2664 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2665 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2666 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2667 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2668 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
2669 LIGHTBAR_NUM_CMDS,
2670 };
2671
2672 /*****************************************************************************/
2673 /* LED control commands */
2674
2675 #define EC_CMD_LED_CONTROL 0x0029
2676
2677 enum ec_led_id {
2678 /* LED to indicate battery state of charge */
2679 EC_LED_ID_BATTERY_LED = 0,
2680 /*
2681 * LED to indicate system power state (on or in suspend).
2682 * May be on power button or on C-panel.
2683 */
2684 EC_LED_ID_POWER_LED,
2685 /* LED on power adapter or its plug */
2686 EC_LED_ID_ADAPTER_LED,
2687 /* LED to indicate left side */
2688 EC_LED_ID_LEFT_LED,
2689 /* LED to indicate right side */
2690 EC_LED_ID_RIGHT_LED,
2691 /* LED to indicate recovery mode with HW_REINIT */
2692 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2693 /* LED to indicate sysrq debug mode. */
2694 EC_LED_ID_SYSRQ_DEBUG_LED,
2695 /* LED strip for advanced patterns. */
2696 EC_LED_ID_LIGHTBAR_LED,
2697
2698 EC_LED_ID_COUNT,
2699 };
2700
2701 /* LED control flags */
2702 #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2703 #define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
2704
2705 enum ec_led_colors {
2706 EC_LED_COLOR_INVALID = -1,
2707 EC_LED_COLOR_RED = 0,
2708 EC_LED_COLOR_GREEN,
2709 EC_LED_COLOR_BLUE,
2710 EC_LED_COLOR_YELLOW,
2711 EC_LED_COLOR_WHITE,
2712 EC_LED_COLOR_AMBER,
2713
2714 EC_LED_COLOR_COUNT,
2715 };
2716
2717 struct ec_params_led_control {
2718 uint8_t led_id; /* Which LED to control */
2719 uint8_t flags; /* Control flags */
2720
2721 uint8_t brightness[EC_LED_COLOR_COUNT];
2722 } __ec_align1;
2723
2724 struct ec_response_led_control {
2725 /*
2726 * Available brightness value range.
2727 *
2728 * Range 0 means color channel not present.
2729 * Range 1 means on/off control.
2730 * Other values means the LED is control by PWM.
2731 */
2732 uint8_t brightness_range[EC_LED_COLOR_COUNT];
2733 } __ec_align1;
2734
2735 /*****************************************************************************/
2736 /* Verified boot commands */
2737
2738 /*
2739 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2740 * reused for other purposes with version > 0.
2741 */
2742
2743 /* Verified boot hash command */
2744 #define EC_CMD_VBOOT_HASH 0x002A
2745
2746 struct ec_params_vboot_hash {
2747 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2748 uint8_t hash_type; /* enum ec_vboot_hash_type */
2749 uint8_t nonce_size; /* Nonce size; may be 0 */
2750 uint8_t reserved0; /* Reserved; set 0 */
2751 uint32_t offset; /* Offset in flash to hash */
2752 uint32_t size; /* Number of bytes to hash */
2753 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
2754 } __ec_align4;
2755
2756 struct ec_response_vboot_hash {
2757 uint8_t status; /* enum ec_vboot_hash_status */
2758 uint8_t hash_type; /* enum ec_vboot_hash_type */
2759 uint8_t digest_size; /* Size of hash digest in bytes */
2760 uint8_t reserved0; /* Ignore; will be 0 */
2761 uint32_t offset; /* Offset in flash which was hashed */
2762 uint32_t size; /* Number of bytes hashed */
2763 uint8_t hash_digest[64]; /* Hash digest data */
2764 } __ec_align4;
2765
2766 enum ec_vboot_hash_cmd {
2767 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2768 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2769 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2770 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
2771 };
2772
2773 enum ec_vboot_hash_type {
2774 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
2775 };
2776
2777 enum ec_vboot_hash_status {
2778 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2779 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2780 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
2781 };
2782
2783 /*
2784 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2785 * If one of these is specified, the EC will automatically update offset and
2786 * size to the correct values for the specified image (RO or RW).
2787 */
2788 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2789 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2790 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2791
2792 /*
2793 * 'RW' is vague if there are multiple RW images; we mean the active one,
2794 * so the old constant is deprecated.
2795 */
2796 #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
2797
2798 /*****************************************************************************/
2799 /*
2800 * Motion sense commands. We'll make separate structs for sub-commands with
2801 * different input args, so that we know how much to expect.
2802 */
2803 #define EC_CMD_MOTION_SENSE_CMD 0x002B
2804
2805 /* Motion sense commands */
2806 enum motionsense_command {
2807 /*
2808 * Dump command returns all motion sensor data including motion sense
2809 * module flags and individual sensor flags.
2810 */
2811 MOTIONSENSE_CMD_DUMP = 0,
2812
2813 /*
2814 * Info command returns data describing the details of a given sensor,
2815 * including enum motionsensor_type, enum motionsensor_location, and
2816 * enum motionsensor_chip.
2817 */
2818 MOTIONSENSE_CMD_INFO = 1,
2819
2820 /*
2821 * EC Rate command is a setter/getter command for the EC sampling rate
2822 * in milliseconds.
2823 * It is per sensor, the EC run sample task at the minimum of all
2824 * sensors EC_RATE.
2825 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2826 * to collect all the sensor samples.
2827 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2828 * to process of all motion sensors in milliseconds.
2829 */
2830 MOTIONSENSE_CMD_EC_RATE = 2,
2831
2832 /*
2833 * Sensor ODR command is a setter/getter command for the output data
2834 * rate of a specific motion sensor in millihertz.
2835 */
2836 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2837
2838 /*
2839 * Sensor range command is a setter/getter command for the range of
2840 * a specified motion sensor in +/-G's or +/- deg/s.
2841 */
2842 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2843
2844 /*
2845 * Setter/getter command for the keyboard wake angle. When the lid
2846 * angle is greater than this value, keyboard wake is disabled in S3,
2847 * and when the lid angle goes less than this value, keyboard wake is
2848 * enabled. Note, the lid angle measurement is an approximate,
2849 * un-calibrated value, hence the wake angle isn't exact.
2850 */
2851 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2852
2853 /*
2854 * Returns a single sensor data.
2855 */
2856 MOTIONSENSE_CMD_DATA = 6,
2857
2858 /*
2859 * Return sensor fifo info.
2860 */
2861 MOTIONSENSE_CMD_FIFO_INFO = 7,
2862
2863 /*
2864 * Insert a flush element in the fifo and return sensor fifo info.
2865 * The host can use that element to synchronize its operation.
2866 */
2867 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2868
2869 /*
2870 * Return a portion of the fifo.
2871 */
2872 MOTIONSENSE_CMD_FIFO_READ = 9,
2873
2874 /*
2875 * Perform low level calibration.
2876 * On sensors that support it, ask to do offset calibration.
2877 */
2878 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2879
2880 /*
2881 * Sensor Offset command is a setter/getter command for the offset
2882 * used for factory calibration.
2883 * The offsets can be calculated by the host, or via
2884 * PERFORM_CALIB command.
2885 */
2886 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2887
2888 /*
2889 * List available activities for a MOTION sensor.
2890 * Indicates if they are enabled or disabled.
2891 */
2892 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2893
2894 /*
2895 * Activity management
2896 * Enable/Disable activity recognition.
2897 */
2898 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2899
2900 /*
2901 * Lid Angle
2902 */
2903 MOTIONSENSE_CMD_LID_ANGLE = 14,
2904
2905 /*
2906 * Allow the FIFO to trigger interrupt via MKBP events.
2907 * By default the FIFO does not send interrupt to process the FIFO
2908 * until the AP is ready or it is coming from a wakeup sensor.
2909 */
2910 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2911
2912 /*
2913 * Spoof the readings of the sensors. The spoofed readings can be set
2914 * to arbitrary values, or will lock to the last read actual values.
2915 */
2916 MOTIONSENSE_CMD_SPOOF = 16,
2917
2918 /* Set lid angle for tablet mode detection. */
2919 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2920
2921 /*
2922 * Sensor Scale command is a setter/getter command for the calibration
2923 * scale.
2924 */
2925 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2926
2927 /*
2928 * Read the current online calibration values (if available).
2929 */
2930 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2931
2932 /*
2933 * Activity management
2934 * Retrieve current status of given activity.
2935 */
2936 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2937
2938 /* Number of motionsense sub-commands. */
2939 MOTIONSENSE_NUM_CMDS,
2940 };
2941
2942 /* List of motion sensor types. */
2943 enum motionsensor_type {
2944 MOTIONSENSE_TYPE_ACCEL = 0,
2945 MOTIONSENSE_TYPE_GYRO = 1,
2946 MOTIONSENSE_TYPE_MAG = 2,
2947 MOTIONSENSE_TYPE_PROX = 3,
2948 MOTIONSENSE_TYPE_LIGHT = 4,
2949 MOTIONSENSE_TYPE_ACTIVITY = 5,
2950 MOTIONSENSE_TYPE_BARO = 6,
2951 MOTIONSENSE_TYPE_SYNC = 7,
2952 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
2953 MOTIONSENSE_TYPE_MAX,
2954 };
2955
2956 /* List of motion sensor locations. */
2957 enum motionsensor_location {
2958 MOTIONSENSE_LOC_BASE = 0,
2959 MOTIONSENSE_LOC_LID = 1,
2960 MOTIONSENSE_LOC_CAMERA = 2,
2961 MOTIONSENSE_LOC_MAX,
2962 };
2963
2964 /* List of motion sensor chips. */
2965 enum motionsensor_chip {
2966 MOTIONSENSE_CHIP_KXCJ9 = 0,
2967 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2968 MOTIONSENSE_CHIP_BMI160 = 2,
2969 MOTIONSENSE_CHIP_SI1141 = 3,
2970 MOTIONSENSE_CHIP_SI1142 = 4,
2971 MOTIONSENSE_CHIP_SI1143 = 5,
2972 MOTIONSENSE_CHIP_KX022 = 6,
2973 MOTIONSENSE_CHIP_L3GD20H = 7,
2974 MOTIONSENSE_CHIP_BMA255 = 8,
2975 MOTIONSENSE_CHIP_BMP280 = 9,
2976 MOTIONSENSE_CHIP_OPT3001 = 10,
2977 MOTIONSENSE_CHIP_BH1730 = 11,
2978 MOTIONSENSE_CHIP_GPIO = 12,
2979 MOTIONSENSE_CHIP_LIS2DH = 13,
2980 MOTIONSENSE_CHIP_LSM6DSM = 14,
2981 MOTIONSENSE_CHIP_LIS2DE = 15,
2982 MOTIONSENSE_CHIP_LIS2MDL = 16,
2983 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2984 MOTIONSENSE_CHIP_LSM6DSO = 18,
2985 MOTIONSENSE_CHIP_LNG2DM = 19,
2986 MOTIONSENSE_CHIP_TCS3400 = 20,
2987 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2988 MOTIONSENSE_CHIP_LIS2DWL = 22,
2989 MOTIONSENSE_CHIP_LIS2DS = 23,
2990 MOTIONSENSE_CHIP_BMI260 = 24,
2991 MOTIONSENSE_CHIP_ICM426XX = 25,
2992 MOTIONSENSE_CHIP_ICM42607 = 26,
2993 MOTIONSENSE_CHIP_BMA422 = 27,
2994 MOTIONSENSE_CHIP_BMI323 = 28,
2995 MOTIONSENSE_CHIP_BMI220 = 29,
2996 MOTIONSENSE_CHIP_CM32183 = 30,
2997 MOTIONSENSE_CHIP_VEML3328 = 31,
2998 MOTIONSENSE_CHIP_MAX,
2999 };
3000
3001 /* List of orientation positions */
3002 enum motionsensor_orientation {
3003 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
3004 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
3005 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
3006 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
3007 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
3008 };
3009
3010 struct ec_response_activity_data {
3011 uint8_t activity; /* motionsensor_activity */
3012 uint8_t state;
3013 } __ec_todo_packed;
3014
3015 struct ec_response_motion_sensor_data {
3016 /* Flags for each sensor. */
3017 uint8_t flags;
3018 /* Sensor number the data comes from. */
3019 uint8_t sensor_num;
3020 /* Each sensor is up to 3-axis. */
3021 union {
3022 int16_t data[3];
3023 /* for sensors using unsigned data */
3024 uint16_t udata[3];
3025 struct __ec_todo_packed {
3026 uint16_t reserved;
3027 uint32_t timestamp;
3028 };
3029 struct __ec_todo_unpacked {
3030 struct ec_response_activity_data activity_data;
3031 int16_t add_info[2];
3032 };
3033 };
3034 } __ec_todo_packed;
3035
3036 /* Response to AP reporting calibration data for a given sensor. */
3037 struct ec_response_online_calibration_data {
3038 /** The calibration values. */
3039 int16_t data[3];
3040 };
3041
3042 /* Note: used in ec_response_get_next_data */
3043 struct ec_response_motion_sense_fifo_info {
3044 /* Size of the fifo */
3045 uint16_t size;
3046 /* Amount of space used in the fifo */
3047 uint16_t count;
3048 /* Timestamp recorded in us.
3049 * aka accurate timestamp when host event was triggered.
3050 */
3051 uint32_t timestamp;
3052 /* Total amount of vector lost */
3053 uint16_t total_lost;
3054 /* Lost events since the last fifo_info, per sensors */
3055 uint16_t lost[0];
3056 } __ec_todo_packed;
3057
3058 struct ec_response_motion_sense_fifo_data {
3059 uint32_t number_data;
3060 struct ec_response_motion_sensor_data data[0];
3061 } __ec_todo_packed;
3062
3063 /* List supported activity recognition */
3064 enum motionsensor_activity {
3065 MOTIONSENSE_ACTIVITY_RESERVED = 0,
3066 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
3067 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
3068 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
3069 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
3070 };
3071
3072 struct ec_motion_sense_activity {
3073 uint8_t sensor_num;
3074 uint8_t activity; /* one of enum motionsensor_activity */
3075 uint8_t enable; /* 1: enable, 0: disable */
3076 uint8_t reserved;
3077 uint16_t parameters[4]; /* activity dependent parameters */
3078 } __ec_todo_packed;
3079
3080 /* Module flag masks used for the dump sub-command. */
3081 #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
3082
3083 /* Sensor flag masks used for the dump sub-command. */
3084 #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
3085
3086 /*
3087 * Flush entry for synchronization.
3088 * data contains time stamp
3089 */
3090 #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
3091 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
3092 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
3093 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
3094 #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
3095
3096 #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
3097
3098 /*
3099 * Send this value for the data element to only perform a read. If you
3100 * send any other value, the EC will interpret it as data to set and will
3101 * return the actual value set.
3102 */
3103 #define EC_MOTION_SENSE_NO_VALUE -1
3104
3105 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
3106
3107 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
3108 /* Set Calibration information */
3109 #define MOTION_SENSE_SET_OFFSET BIT(0)
3110
3111 /* Default Scale value, factor 1. */
3112 #define MOTION_SENSE_DEFAULT_SCALE BIT(15)
3113
3114 #define LID_ANGLE_UNRELIABLE 500
3115
3116 enum motionsense_spoof_mode {
3117 /* Disable spoof mode. */
3118 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
3119
3120 /* Enable spoof mode, but use provided component values. */
3121 MOTIONSENSE_SPOOF_MODE_CUSTOM,
3122
3123 /* Enable spoof mode, but use the current sensor values. */
3124 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
3125
3126 /* Query the current spoof mode status for the sensor. */
3127 MOTIONSENSE_SPOOF_MODE_QUERY,
3128 };
3129
3130 struct ec_params_motion_sense {
3131 uint8_t cmd;
3132 union {
3133 /* Used for MOTIONSENSE_CMD_DUMP. */
3134 struct __ec_todo_unpacked {
3135 /*
3136 * Maximal number of sensor the host is expecting.
3137 * 0 means the host is only interested in the number
3138 * of sensors controlled by the EC.
3139 */
3140 uint8_t max_sensor_count;
3141 } dump;
3142
3143 /*
3144 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
3145 */
3146 struct __ec_todo_unpacked {
3147 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
3148 * kb_wake_angle: angle to wakeup AP.
3149 */
3150 int16_t data;
3151 } kb_wake_angle;
3152
3153 /*
3154 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
3155 */
3156 struct __ec_todo_unpacked {
3157 uint8_t sensor_num;
3158 } info, info_3, info_4, data, fifo_flush, list_activities;
3159
3160 /*
3161 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
3162 * Allow entering/exiting the calibration mode.
3163 */
3164 struct __ec_todo_unpacked {
3165 uint8_t sensor_num;
3166 uint8_t enable;
3167 } perform_calib;
3168
3169 /*
3170 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
3171 * and MOTIONSENSE_CMD_SENSOR_RANGE.
3172 */
3173 struct __ec_todo_unpacked {
3174 uint8_t sensor_num;
3175
3176 /* Rounding flag, true for round-up, false for down. */
3177 uint8_t roundup;
3178
3179 uint16_t reserved;
3180
3181 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
3182 int32_t data;
3183 } ec_rate, sensor_odr, sensor_range;
3184
3185 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
3186 struct __ec_todo_packed {
3187 uint8_t sensor_num;
3188
3189 /*
3190 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3191 * the calibration information in the EC.
3192 * If unset, just retrieve calibration information.
3193 */
3194 uint16_t flags;
3195
3196 /*
3197 * Temperature at calibration, in units of 0.01 C
3198 * 0x8000: invalid / unknown.
3199 * 0x0: 0C
3200 * 0x7fff: +327.67C
3201 */
3202 int16_t temp;
3203
3204 /*
3205 * Offset for calibration.
3206 * Unit:
3207 * Accelerometer: 1/1024 g
3208 * Gyro: 1/1024 deg/s
3209 * Compass: 1/16 uT
3210 */
3211 int16_t offset[3];
3212 } sensor_offset;
3213
3214 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3215 struct __ec_todo_packed {
3216 uint8_t sensor_num;
3217
3218 /*
3219 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3220 * the calibration information in the EC.
3221 * If unset, just retrieve calibration information.
3222 */
3223 uint16_t flags;
3224
3225 /*
3226 * Temperature at calibration, in units of 0.01 C
3227 * 0x8000: invalid / unknown.
3228 * 0x0: 0C
3229 * 0x7fff: +327.67C
3230 */
3231 int16_t temp;
3232
3233 /*
3234 * Scale for calibration:
3235 * By default scale is 1, it is encoded on 16bits:
3236 * 1 = BIT(15)
3237 * ~2 = 0xFFFF
3238 * ~0 = 0.
3239 */
3240 uint16_t scale[3];
3241 } sensor_scale;
3242
3243 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
3244 /* (no params) */
3245
3246 /* Used for MOTIONSENSE_CMD_FIFO_READ */
3247 struct __ec_todo_unpacked {
3248 /*
3249 * Number of expected vector to return.
3250 * EC may return less or 0 if none available.
3251 */
3252 uint32_t max_data_vector;
3253 } fifo_read;
3254
3255 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
3256 struct ec_motion_sense_activity set_activity;
3257
3258 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
3259 /* (no params) */
3260
3261 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3262 struct __ec_todo_unpacked {
3263 /*
3264 * 1: enable, 0 disable fifo,
3265 * EC_MOTION_SENSE_NO_VALUE return value.
3266 */
3267 int8_t enable;
3268 } fifo_int_enable;
3269
3270 /* Used for MOTIONSENSE_CMD_SPOOF */
3271 struct __ec_todo_packed {
3272 uint8_t sensor_id;
3273
3274 /* See enum motionsense_spoof_mode. */
3275 uint8_t spoof_enable;
3276
3277 /* Ignored, used for alignment. */
3278 uint8_t reserved;
3279
3280 union {
3281 /* Individual component values to spoof. */
3282 int16_t components[3];
3283
3284 /* Used when spoofing an activity */
3285 struct {
3286 /* enum motionsensor_activity */
3287 uint8_t activity_num;
3288
3289 /* spoof activity state */
3290 uint8_t activity_state;
3291 };
3292 } __ec_todo_packed;
3293 } spoof;
3294
3295 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3296 struct __ec_todo_unpacked {
3297 /*
3298 * Lid angle threshold for switching between tablet and
3299 * clamshell mode.
3300 */
3301 int16_t lid_angle;
3302
3303 /*
3304 * Hysteresis degree to prevent fluctuations between
3305 * clamshell and tablet mode if lid angle keeps
3306 * changing around the threshold. Lid motion driver will
3307 * use lid_angle + hys_degree to trigger tablet mode and
3308 * lid_angle - hys_degree to trigger clamshell mode.
3309 */
3310 int16_t hys_degree;
3311 } tablet_mode_threshold;
3312
3313 /*
3314 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3315 * Allow reading a single sensor's online calibration value.
3316 */
3317 struct __ec_todo_unpacked {
3318 uint8_t sensor_num;
3319 } online_calib_read;
3320
3321 /*
3322 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3323 */
3324 struct __ec_todo_unpacked {
3325 uint8_t sensor_num;
3326 uint8_t activity; /* enum motionsensor_activity */
3327 } get_activity;
3328 } __ec_todo_packed;
3329 } __ec_todo_packed;
3330
3331 enum motion_sense_cmd_info_flags {
3332 /* The sensor supports online calibration */
3333 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3334 };
3335
3336 struct ec_response_motion_sense {
3337 union {
3338 /* Used for MOTIONSENSE_CMD_DUMP */
3339 struct __ec_todo_unpacked {
3340 /* Flags representing the motion sensor module. */
3341 uint8_t module_flags;
3342
3343 /* Number of sensors managed directly by the EC. */
3344 uint8_t sensor_count;
3345
3346 /*
3347 * Sensor data is truncated if response_max is too small
3348 * for holding all the data.
3349 */
3350 struct ec_response_motion_sensor_data sensor[0];
3351 } dump;
3352
3353 /* Used for MOTIONSENSE_CMD_INFO. */
3354 struct __ec_todo_unpacked {
3355 /* Should be element of enum motionsensor_type. */
3356 uint8_t type;
3357
3358 /* Should be element of enum motionsensor_location. */
3359 uint8_t location;
3360
3361 /* Should be element of enum motionsensor_chip. */
3362 uint8_t chip;
3363 } info;
3364
3365 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3366 struct __ec_todo_unpacked {
3367 /* Should be element of enum motionsensor_type. */
3368 uint8_t type;
3369
3370 /* Should be element of enum motionsensor_location. */
3371 uint8_t location;
3372
3373 /* Should be element of enum motionsensor_chip. */
3374 uint8_t chip;
3375
3376 /* Minimum sensor sampling frequency */
3377 uint32_t min_frequency;
3378
3379 /* Maximum sensor sampling frequency */
3380 uint32_t max_frequency;
3381
3382 /* Max number of sensor events that could be in fifo */
3383 uint32_t fifo_max_event_count;
3384 } info_3;
3385
3386 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3387 struct __ec_align4 {
3388 /* Should be element of enum motionsensor_type. */
3389 uint8_t type;
3390
3391 /* Should be element of enum motionsensor_location. */
3392 uint8_t location;
3393
3394 /* Should be element of enum motionsensor_chip. */
3395 uint8_t chip;
3396
3397 /* Minimum sensor sampling frequency */
3398 uint32_t min_frequency;
3399
3400 /* Maximum sensor sampling frequency */
3401 uint32_t max_frequency;
3402
3403 /* Max number of sensor events that could be in fifo */
3404 uint32_t fifo_max_event_count;
3405
3406 /*
3407 * Should be elements of
3408 * enum motion_sense_cmd_info_flags
3409 */
3410 uint32_t flags;
3411 } info_4;
3412
3413 /* Used for MOTIONSENSE_CMD_DATA */
3414 struct ec_response_motion_sensor_data data;
3415
3416 /*
3417 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
3418 * MOTIONSENSE_CMD_SENSOR_RANGE,
3419 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3420 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3421 * MOTIONSENSE_CMD_SPOOF.
3422 */
3423 struct __ec_todo_unpacked {
3424 /* Current value of the parameter queried. */
3425 int32_t ret;
3426 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3427 fifo_int_enable, spoof;
3428
3429 /*
3430 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3431 * PERFORM_CALIB.
3432 */
3433 struct __ec_todo_unpacked {
3434 int16_t temp;
3435 int16_t offset[3];
3436 } sensor_offset, perform_calib;
3437
3438 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3439 struct __ec_todo_unpacked {
3440 int16_t temp;
3441 uint16_t scale[3];
3442 } sensor_scale;
3443
3444 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3445
3446 struct ec_response_motion_sense_fifo_data fifo_read;
3447
3448 struct ec_response_online_calibration_data online_calib_read;
3449
3450 struct __ec_todo_packed {
3451 uint16_t reserved;
3452 uint32_t enabled;
3453 uint32_t disabled;
3454 } list_activities;
3455
3456 /* No params for set activity */
3457
3458 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
3459 struct __ec_todo_unpacked {
3460 /*
3461 * Angle between 0 and 360 degree if available,
3462 * LID_ANGLE_UNRELIABLE otherwise.
3463 */
3464 uint16_t value;
3465 } lid_angle;
3466
3467 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3468 struct __ec_todo_unpacked {
3469 /*
3470 * Lid angle threshold for switching between tablet and
3471 * clamshell mode.
3472 */
3473 uint16_t lid_angle;
3474
3475 /* Hysteresis degree. */
3476 uint16_t hys_degree;
3477 } tablet_mode_threshold;
3478
3479 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3480 struct __ec_todo_unpacked {
3481 uint8_t state;
3482 } get_activity;
3483 };
3484 } __ec_todo_packed;
3485
3486 /*****************************************************************************/
3487 /* Force lid open command */
3488
3489 /* Make lid event always open */
3490 #define EC_CMD_FORCE_LID_OPEN 0x002C
3491
3492 struct ec_params_force_lid_open {
3493 uint8_t enabled;
3494 } __ec_align1;
3495
3496 /*****************************************************************************/
3497 /* Configure the behavior of the power button */
3498 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3499
3500 enum ec_config_power_button_flags {
3501 /* Enable/Disable power button pulses for x86 devices */
3502 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
3503 };
3504
3505 struct ec_params_config_power_button {
3506 /* See enum ec_config_power_button_flags */
3507 uint8_t flags;
3508 } __ec_align1;
3509
3510 /*****************************************************************************/
3511 /* USB charging control commands */
3512
3513 /* Set USB port charging mode */
3514 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
3515
3516 enum usb_charge_mode {
3517 /* Disable USB port. */
3518 USB_CHARGE_MODE_DISABLED,
3519 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3520 USB_CHARGE_MODE_SDP2,
3521 /* Set USB port to Charging Downstream Port, BC 1.2. */
3522 USB_CHARGE_MODE_CDP,
3523 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3524 USB_CHARGE_MODE_DCP_SHORT,
3525 /* Enable USB port (for dumb ports). */
3526 USB_CHARGE_MODE_ENABLED,
3527 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3528 USB_CHARGE_MODE_DEFAULT,
3529
3530 USB_CHARGE_MODE_COUNT,
3531 };
3532
3533 enum usb_suspend_charge {
3534 /* Enable charging in suspend */
3535 USB_ALLOW_SUSPEND_CHARGE,
3536 /* Disable charging in suspend */
3537 USB_DISALLOW_SUSPEND_CHARGE,
3538 };
3539
3540 struct ec_params_usb_charge_set_mode {
3541 uint8_t usb_port_id;
3542 uint8_t mode : 7; /* enum usb_charge_mode */
3543 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
3544 } __ec_align1;
3545
3546 /*****************************************************************************/
3547 /* Tablet mode commands */
3548
3549 /* Set tablet mode */
3550 #define EC_CMD_SET_TABLET_MODE 0x0031
3551
3552 enum tablet_mode_override {
3553 TABLET_MODE_DEFAULT,
3554 TABLET_MODE_FORCE_TABLET,
3555 TABLET_MODE_FORCE_CLAMSHELL,
3556 };
3557
3558 struct ec_params_set_tablet_mode {
3559 uint8_t tablet_mode; /* enum tablet_mode_override */
3560 } __ec_align1;
3561
3562 /*****************************************************************************/
3563 /* Persistent storage for host */
3564
3565 /* Maximum bytes that can be read/written in a single command */
3566 #define EC_PSTORE_SIZE_MAX 64
3567
3568 /* Get persistent storage info */
3569 #define EC_CMD_PSTORE_INFO 0x0040
3570
3571 struct ec_response_pstore_info {
3572 /* Persistent storage size, in bytes */
3573 uint32_t pstore_size;
3574 /* Access size; read/write offset and size must be a multiple of this */
3575 uint32_t access_size;
3576 } __ec_align4;
3577
3578 /*
3579 * Read persistent storage
3580 *
3581 * Response is params.size bytes of data.
3582 */
3583 #define EC_CMD_PSTORE_READ 0x0041
3584
3585 struct ec_params_pstore_read {
3586 uint32_t offset; /* Byte offset to read */
3587 uint32_t size; /* Size to read in bytes */
3588 } __ec_align4;
3589
3590 /* Write persistent storage */
3591 #define EC_CMD_PSTORE_WRITE 0x0042
3592
3593 struct ec_params_pstore_write {
3594 uint32_t offset; /* Byte offset to write */
3595 uint32_t size; /* Size to write in bytes */
3596 uint8_t data[EC_PSTORE_SIZE_MAX];
3597 } __ec_align4;
3598
3599 /*****************************************************************************/
3600 /* Real-time clock */
3601
3602 /* RTC params and response structures */
3603 struct ec_params_rtc {
3604 uint32_t time;
3605 } __ec_align4;
3606
3607 struct ec_response_rtc {
3608 uint32_t time;
3609 } __ec_align4;
3610
3611 /* These use ec_response_rtc */
3612 #define EC_CMD_RTC_GET_VALUE 0x0044
3613 #define EC_CMD_RTC_GET_ALARM 0x0045
3614
3615 /* These all use ec_params_rtc */
3616 #define EC_CMD_RTC_SET_VALUE 0x0046
3617 #define EC_CMD_RTC_SET_ALARM 0x0047
3618
3619 /* Pass as time param to SET_ALARM to clear the current alarm */
3620 #define EC_RTC_ALARM_CLEAR 0
3621
3622 /*****************************************************************************/
3623 /* Port80 log access */
3624
3625 /* Maximum entries that can be read/written in a single command */
3626 #define EC_PORT80_SIZE_MAX 32
3627
3628 /* Get last port80 code from previous boot */
3629 #define EC_CMD_PORT80_LAST_BOOT 0x0048
3630 #define EC_CMD_PORT80_READ 0x0048
3631
3632 enum ec_port80_subcmd {
3633 EC_PORT80_GET_INFO = 0,
3634 EC_PORT80_READ_BUFFER,
3635 };
3636
3637 struct ec_params_port80_read {
3638 uint16_t subcmd;
3639 union {
3640 struct __ec_todo_unpacked {
3641 uint32_t offset;
3642 uint32_t num_entries;
3643 } read_buffer;
3644 } __ec_todo_packed;
3645 } __ec_todo_packed;
3646
3647 struct ec_response_port80_read {
3648 union {
3649 struct __ec_todo_unpacked {
3650 uint32_t writes;
3651 uint32_t history_size;
3652 uint32_t last_boot;
3653 } get_info;
3654 struct __ec_todo_unpacked {
3655 uint16_t codes[EC_PORT80_SIZE_MAX];
3656 } data;
3657 };
3658 } __ec_todo_packed;
3659
3660 struct ec_response_port80_last_boot {
3661 uint16_t code;
3662 } __ec_align2;
3663
3664 /*****************************************************************************/
3665 /* Temporary secure storage for host verified boot use */
3666
3667 /* Number of bytes in a vstore slot */
3668 #define EC_VSTORE_SLOT_SIZE 64
3669
3670 /* Maximum number of vstore slots */
3671 #define EC_VSTORE_SLOT_MAX 32
3672
3673 /* Get persistent storage info */
3674 #define EC_CMD_VSTORE_INFO 0x0049
3675 struct ec_response_vstore_info {
3676 /* Indicates which slots are locked */
3677 uint32_t slot_locked;
3678 /* Total number of slots available */
3679 uint8_t slot_count;
3680 } __ec_align_size1;
3681
3682 /*
3683 * Read temporary secure storage
3684 *
3685 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3686 */
3687 #define EC_CMD_VSTORE_READ 0x004A
3688
3689 struct ec_params_vstore_read {
3690 uint8_t slot; /* Slot to read from */
3691 } __ec_align1;
3692
3693 struct ec_response_vstore_read {
3694 uint8_t data[EC_VSTORE_SLOT_SIZE];
3695 } __ec_align1;
3696
3697 /*
3698 * Write temporary secure storage and lock it.
3699 */
3700 #define EC_CMD_VSTORE_WRITE 0x004B
3701
3702 struct ec_params_vstore_write {
3703 uint8_t slot; /* Slot to write to */
3704 uint8_t data[EC_VSTORE_SLOT_SIZE];
3705 } __ec_align1;
3706
3707 /*****************************************************************************/
3708 /* Thermal engine commands. Note that there are two implementations. We'll
3709 * reuse the command number, but the data and behavior is incompatible.
3710 * Version 0 is what originally shipped on Link.
3711 * Version 1 separates the CPU thermal limits from the fan control.
3712 */
3713
3714 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3715 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
3716
3717 /* The version 0 structs are opaque. You have to know what they are for
3718 * the get/set commands to make any sense.
3719 */
3720
3721 /* Version 0 - set */
3722 struct ec_params_thermal_set_threshold {
3723 uint8_t sensor_type;
3724 uint8_t threshold_id;
3725 uint16_t value;
3726 } __ec_align2;
3727
3728 /* Version 0 - get */
3729 struct ec_params_thermal_get_threshold {
3730 uint8_t sensor_type;
3731 uint8_t threshold_id;
3732 } __ec_align1;
3733
3734 struct ec_response_thermal_get_threshold {
3735 uint16_t value;
3736 } __ec_align2;
3737
3738 /* The version 1 structs are visible. */
3739 enum ec_temp_thresholds {
3740 EC_TEMP_THRESH_WARN = 0,
3741 EC_TEMP_THRESH_HIGH,
3742 EC_TEMP_THRESH_HALT,
3743
3744 EC_TEMP_THRESH_COUNT,
3745 };
3746
3747 /*
3748 * Thermal configuration for one temperature sensor. Temps are in degrees K.
3749 * Zero values will be silently ignored by the thermal task.
3750 *
3751 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3752 * hysteresis.
3753 * For example,
3754 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3755 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3756 * EC will throttle ap when temperature >= 301 K, and release throttling when
3757 * temperature <= 299 K.
3758 *
3759 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3760 * For example,
3761 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3762 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3763 * EC will throttle ap when temperature >= 301 K, and release throttling when
3764 * temperature <= 294 K.
3765 *
3766 * Note that this structure is a sub-structure of
3767 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
3768 */
3769 struct ec_thermal_config {
3770 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
3771 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
3772 uint32_t temp_fan_off; /* no active cooling needed */
3773 uint32_t temp_fan_max; /* max active cooling needed */
3774 } __ec_align4;
3775
3776 /* Version 1 - get config for one sensor. */
3777 struct ec_params_thermal_get_threshold_v1 {
3778 uint32_t sensor_num;
3779 } __ec_align4;
3780 /* This returns a struct ec_thermal_config */
3781
3782 /*
3783 * Version 1 - set config for one sensor.
3784 * Use read-modify-write for best results!
3785 */
3786 struct ec_params_thermal_set_threshold_v1 {
3787 uint32_t sensor_num;
3788 struct ec_thermal_config cfg;
3789 } __ec_align4;
3790 /* This returns no data */
3791
3792 /****************************************************************************/
3793
3794 /* Set or get fan control mode */
3795 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
3796
3797 enum ec_auto_fan_ctrl_cmd {
3798 EC_AUTO_FAN_CONTROL_CMD_SET = 0,
3799 EC_AUTO_FAN_CONTROL_CMD_GET,
3800 };
3801
3802 /* Version 1 of input params */
3803 struct ec_params_auto_fan_ctrl_v1 {
3804 uint8_t fan_idx;
3805 } __ec_align1;
3806
3807 /* Version 2 of input params */
3808 struct ec_params_auto_fan_ctrl_v2 {
3809 uint8_t fan_idx;
3810 uint8_t cmd; /* enum ec_auto_fan_ctrl_cmd */
3811 uint8_t set_auto; /* only used with EC_AUTO_FAN_CONTROL_CMD_SET - bool
3812 */
3813 } __ec_align4;
3814
3815 struct ec_response_auto_fan_control {
3816 uint8_t is_auto; /* bool */
3817 } __ec_align1;
3818
3819 /* Get/Set TMP006 calibration data */
3820 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3821 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
3822
3823 /*
3824 * The original TMP006 calibration only needed four params, but now we need
3825 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3826 * the params opaque. The v1 "get" response will include the algorithm number
3827 * and how many params it requires. That way we can change the EC code without
3828 * needing to update this file. We can also use a different algorithm on each
3829 * sensor.
3830 */
3831
3832 /* This is the same struct for both v0 and v1. */
3833 struct ec_params_tmp006_get_calibration {
3834 uint8_t index;
3835 } __ec_align1;
3836
3837 /* Version 0 */
3838 struct ec_response_tmp006_get_calibration_v0 {
3839 float s0;
3840 float b0;
3841 float b1;
3842 float b2;
3843 } __ec_align4;
3844
3845 struct ec_params_tmp006_set_calibration_v0 {
3846 uint8_t index;
3847 uint8_t reserved[3];
3848 float s0;
3849 float b0;
3850 float b1;
3851 float b2;
3852 } __ec_align4;
3853
3854 /* Version 1 */
3855 struct ec_response_tmp006_get_calibration_v1 {
3856 uint8_t algorithm;
3857 uint8_t num_params;
3858 uint8_t reserved[2];
3859 float val[FLEXIBLE_ARRAY_MEMBER_SIZE];
3860 } __ec_align4;
3861
3862 struct ec_params_tmp006_set_calibration_v1 {
3863 uint8_t index;
3864 uint8_t algorithm;
3865 uint8_t num_params;
3866 uint8_t reserved;
3867 float val[FLEXIBLE_ARRAY_MEMBER_SIZE];
3868 } __ec_align4;
3869
3870 /* Read raw TMP006 data */
3871 #define EC_CMD_TMP006_GET_RAW 0x0055
3872
3873 struct ec_params_tmp006_get_raw {
3874 uint8_t index;
3875 } __ec_align1;
3876
3877 struct ec_response_tmp006_get_raw {
3878 int32_t t; /* In 1/100 K */
3879 int32_t v; /* In nV */
3880 } __ec_align4;
3881
3882 /*****************************************************************************/
3883 /* MKBP - Matrix KeyBoard Protocol */
3884
3885 /*
3886 * Read key state
3887 *
3888 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3889 * expected response size.
3890 *
3891 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3892 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3893 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
3894 */
3895 #define EC_CMD_MKBP_STATE 0x0060
3896
3897 /*
3898 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3899 */
3900 #define EC_CMD_MKBP_INFO 0x0061
3901
3902 struct ec_response_mkbp_info {
3903 uint32_t rows;
3904 uint32_t cols;
3905 /* Formerly "switches", which was 0. */
3906 uint8_t reserved;
3907 } __ec_align_size1;
3908
3909 struct ec_params_mkbp_info {
3910 uint8_t info_type;
3911 uint8_t event_type;
3912 } __ec_align1;
3913
3914 enum ec_mkbp_info_type {
3915 /*
3916 * Info about the keyboard matrix: number of rows and columns.
3917 *
3918 * Returns struct ec_response_mkbp_info.
3919 */
3920 EC_MKBP_INFO_KBD = 0,
3921
3922 /*
3923 * For buttons and switches, info about which specifically are
3924 * supported. event_type must be set to one of the values in enum
3925 * ec_mkbp_event.
3926 *
3927 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3928 * bitmask indicating which buttons or switches are present. See the
3929 * bit inidices below.
3930 */
3931 EC_MKBP_INFO_SUPPORTED = 1,
3932
3933 /*
3934 * Instantaneous state of buttons and switches.
3935 *
3936 * event_type must be set to one of the values in enum ec_mkbp_event.
3937 *
3938 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3939 * indicating the current state of the keyboard matrix.
3940 *
3941 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3942 * event state.
3943 *
3944 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3945 * state of supported buttons.
3946 *
3947 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3948 * state of supported switches.
3949 */
3950 EC_MKBP_INFO_CURRENT = 2,
3951 };
3952
3953 /* Simulate key press */
3954 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
3955
3956 struct ec_params_mkbp_simulate_key {
3957 uint8_t col;
3958 uint8_t row;
3959 uint8_t pressed;
3960 } __ec_align1;
3961
3962 /* Configure keyboard scanning */
3963 #define EC_CMD_MKBP_SET_CONFIG 0x0064
3964 #define EC_CMD_MKBP_GET_CONFIG 0x0065
3965
3966 /* flags */
3967 enum mkbp_config_flags {
3968 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3969 };
3970
3971 enum mkbp_config_valid {
3972 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3973 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3974 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3975 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3976 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3977 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3978 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
3979 };
3980
3981 /*
3982 * Configuration for our key scanning algorithm.
3983 *
3984 * Note that this is used as a sub-structure of
3985 * ec_{params/response}_mkbp_get_config.
3986 */
3987 struct ec_mkbp_config {
3988 uint32_t valid_mask; /* valid fields */
3989 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3990 uint8_t valid_flags; /* which flags are valid */
3991 uint16_t scan_period_us; /* period between start of scans */
3992 /* revert to interrupt mode after no activity for this long */
3993 uint32_t poll_timeout_us;
3994 /*
3995 * minimum post-scan relax time. Once we finish a scan we check
3996 * the time until we are due to start the next one. If this time is
3997 * shorter this field, we use this instead.
3998 */
3999 uint16_t min_post_scan_delay_us;
4000 /* delay between setting up output and waiting for it to settle */
4001 uint16_t output_settle_us;
4002 uint16_t debounce_down_us; /* time for debounce on key down */
4003 uint16_t debounce_up_us; /* time for debounce on key up */
4004 /* maximum depth to allow for fifo (0 = no keyscan output) */
4005 uint8_t fifo_max_depth;
4006 } __ec_align_size1;
4007
4008 struct ec_params_mkbp_set_config {
4009 struct ec_mkbp_config config;
4010 } __ec_align_size1;
4011
4012 struct ec_response_mkbp_get_config {
4013 struct ec_mkbp_config config;
4014 } __ec_align_size1;
4015
4016 /* Run the key scan emulation */
4017 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
4018
4019 enum ec_keyscan_seq_cmd {
4020 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
4021 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
4022 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
4023 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
4024 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
4025 };
4026
4027 enum ec_collect_flags {
4028 /*
4029 * Indicates this scan was processed by the EC. Due to timing, some
4030 * scans may be skipped.
4031 */
4032 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
4033 };
4034
4035 struct ec_collect_item {
4036 uint8_t flags; /* some flags (enum ec_collect_flags) */
4037 } __ec_align1;
4038
4039 struct ec_params_keyscan_seq_ctrl {
4040 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
4041 union {
4042 struct __ec_align1 {
4043 uint8_t active; /* still active */
4044 uint8_t num_items; /* number of items */
4045 /* Current item being presented */
4046 uint8_t cur_item;
4047 } status;
4048 struct __ec_todo_unpacked {
4049 /*
4050 * Absolute time for this scan, measured from the
4051 * start of the sequence.
4052 */
4053 uint32_t time_us;
4054 /* keyscan data */
4055 uint8_t scan[FLEXIBLE_ARRAY_MEMBER_SIZE];
4056 } add;
4057 struct __ec_align1 {
4058 uint8_t start_item; /* First item to return */
4059 uint8_t num_items; /* Number of items to return */
4060 } collect;
4061 };
4062 } __ec_todo_packed;
4063
4064 struct ec_result_keyscan_seq_ctrl {
4065 union {
4066 struct __ec_todo_unpacked {
4067 uint8_t num_items; /* Number of items */
4068 /* Data for each item */
4069 struct ec_collect_item item[FLEXIBLE_ARRAY_MEMBER_SIZE];
4070 } collect;
4071 };
4072 } __ec_todo_packed;
4073
4074 /*
4075 * Get the next pending MKBP event.
4076 *
4077 * Returns EC_RES_UNAVAILABLE if there is no event pending.
4078 *
4079 * V0: ec_response_get_next_data
4080 * V1: ec_response_get_next_data_v1. Increased key_matrix size from 13 -> 16.
4081 * V2: Added EC_MKBP_HAS_MORE_EVENTS.
4082 * V3: ec_response_get_next_data_v3. Increased key_matrix size from 16 -> 18.
4083 */
4084 #define EC_CMD_GET_NEXT_EVENT 0x0067
4085
4086 #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
4087
4088 /*
4089 * We use the most significant bit of the event type to indicate to the host
4090 * that the EC has more MKBP events available to provide.
4091 */
4092 #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
4093
4094 /* The mask to apply to get the raw event type */
4095 #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
4096
4097 enum ec_mkbp_event {
4098 /* Keyboard matrix changed. The event data is the new matrix state. */
4099 EC_MKBP_EVENT_KEY_MATRIX = 0,
4100
4101 /* New host event. The event data is 4 bytes of host event flags. */
4102 EC_MKBP_EVENT_HOST_EVENT = 1,
4103
4104 /* New Sensor FIFO data. The event data is fifo_info structure. */
4105 EC_MKBP_EVENT_SENSOR_FIFO = 2,
4106
4107 /* The state of the non-matrixed buttons have changed. */
4108 EC_MKBP_EVENT_BUTTON = 3,
4109
4110 /* The state of the switches have changed. */
4111 EC_MKBP_EVENT_SWITCH = 4,
4112
4113 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
4114 EC_MKBP_EVENT_FINGERPRINT = 5,
4115
4116 /*
4117 * Sysrq event: send emulated sysrq. The event data is sysrq,
4118 * corresponding to the key to be pressed.
4119 */
4120 EC_MKBP_EVENT_SYSRQ = 6,
4121
4122 /*
4123 * New 64-bit host event.
4124 * The event data is 8 bytes of host event flags.
4125 */
4126 EC_MKBP_EVENT_HOST_EVENT64 = 7,
4127
4128 /* Notify the AP that something happened on CEC */
4129 EC_MKBP_EVENT_CEC_EVENT = 8,
4130
4131 /* Send an incoming CEC message to the AP */
4132 EC_MKBP_EVENT_CEC_MESSAGE = 9,
4133
4134 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
4135 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
4136
4137 /* New online calibration values are available. */
4138 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
4139
4140 /* Peripheral device charger event */
4141 EC_MKBP_EVENT_PCHG = 12,
4142
4143 /* Number of MKBP events */
4144 EC_MKBP_EVENT_COUNT,
4145 };
4146 BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
4147
4148 /* clang-format off */
4149 #define EC_MKBP_EVENT_TEXT \
4150 { \
4151 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
4152 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
4153 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
4154 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
4155 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
4156 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
4157 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
4158 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
4159 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
4160 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
4161 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
4162 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
4163 [EC_MKBP_EVENT_PCHG] = "PCHG", \
4164 }
4165 /* clang-format on */
4166
4167 union __ec_align_offset1 ec_response_get_next_data {
4168 uint8_t key_matrix[13];
4169
4170 /* Unaligned */
4171 uint32_t host_event;
4172 uint64_t host_event64;
4173
4174 struct __ec_todo_unpacked {
4175 /* For aligning the fifo_info */
4176 uint8_t reserved[3];
4177 struct ec_response_motion_sense_fifo_info info;
4178 } sensor_fifo;
4179
4180 uint32_t buttons;
4181
4182 uint32_t switches;
4183
4184 uint32_t fp_events;
4185
4186 uint32_t sysrq;
4187
4188 /* CEC events from enum mkbp_cec_event */
4189 uint32_t cec_events;
4190 };
4191
4192 union __ec_align_offset1 ec_response_get_next_data_v1 {
4193 uint8_t key_matrix[16];
4194
4195 /* Unaligned */
4196 uint32_t host_event;
4197 uint64_t host_event64;
4198
4199 struct __ec_todo_unpacked {
4200 /* For aligning the fifo_info */
4201 uint8_t reserved[3];
4202 struct ec_response_motion_sense_fifo_info info;
4203 } sensor_fifo;
4204
4205 uint32_t buttons;
4206
4207 uint32_t switches;
4208
4209 uint32_t fp_events;
4210
4211 uint32_t sysrq;
4212
4213 /* CEC events from enum mkbp_cec_event */
4214 uint32_t cec_events;
4215
4216 uint8_t cec_message[16];
4217 };
4218 BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
4219
4220 union __ec_align_offset1 ec_response_get_next_data_v3 {
4221 uint8_t key_matrix[18];
4222
4223 /* Unaligned */
4224 uint32_t host_event;
4225 uint64_t host_event64;
4226
4227 struct __ec_todo_unpacked {
4228 /* For aligning the fifo_info */
4229 uint8_t reserved[3];
4230 struct ec_response_motion_sense_fifo_info info;
4231 } sensor_fifo;
4232
4233 uint32_t buttons;
4234
4235 uint32_t switches;
4236
4237 uint32_t fp_events;
4238
4239 uint32_t sysrq;
4240
4241 /* CEC events from enum mkbp_cec_event */
4242 uint32_t cec_events;
4243
4244 uint8_t cec_message[16];
4245 };
4246 BUILD_ASSERT(sizeof(union ec_response_get_next_data_v3) == 18);
4247
4248 struct ec_response_get_next_event {
4249 uint8_t event_type;
4250 /* Followed by event data if any */
4251 union ec_response_get_next_data data;
4252 } __ec_align1;
4253
4254 struct ec_response_get_next_event_v1 {
4255 uint8_t event_type;
4256 /* Followed by event data if any */
4257 union ec_response_get_next_data_v1 data;
4258 } __ec_align1;
4259
4260 struct ec_response_get_next_event_v3 {
4261 uint8_t event_type;
4262 /* Followed by event data if any */
4263 union ec_response_get_next_data_v3 data;
4264 } __ec_align1;
4265
4266 /* Bit indices for buttons and switches.*/
4267 /* Buttons */
4268 #define EC_MKBP_POWER_BUTTON 0
4269 #define EC_MKBP_VOL_UP 1
4270 #define EC_MKBP_VOL_DOWN 2
4271 #define EC_MKBP_RECOVERY 3
4272
4273 /* Switches */
4274 #define EC_MKBP_LID_OPEN 0
4275 #define EC_MKBP_TABLET_MODE 1
4276 #define EC_MKBP_BASE_ATTACHED 2
4277 #define EC_MKBP_FRONT_PROXIMITY 3
4278
4279 /* Run keyboard factory test scanning */
4280 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
4281
4282 struct ec_response_keyboard_factory_test {
4283 uint16_t shorted; /* Keyboard pins are shorted */
4284 } __ec_align2;
4285
4286 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
4287 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
4288 #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
4289 #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
4290 #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
4291 (((fpe) & 0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
4292 #define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4293 #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
4294 #define EC_MKBP_FP_MATCH_IDX(fpe) \
4295 (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
4296 #define EC_MKBP_FP_ENROLL BIT(27)
4297 #define EC_MKBP_FP_MATCH BIT(28)
4298 #define EC_MKBP_FP_FINGER_DOWN BIT(29)
4299 #define EC_MKBP_FP_FINGER_UP BIT(30)
4300 #define EC_MKBP_FP_IMAGE_READY BIT(31)
4301 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
4302 #define EC_MKBP_FP_ERR_ENROLL_OK 0
4303 #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4304 #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4305 #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4306 #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
4307 /* Can be used to detect if image was usable for enrollment or not. */
4308 #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
4309 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
4310 #define EC_MKBP_FP_ERR_MATCH_NO 0
4311 #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4312 #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
4313 #define EC_MKBP_FP_ERR_MATCH_NO_AUTH_FAIL 8
4314 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4315 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4316 #define EC_MKBP_FP_ERR_MATCH_YES 1
4317 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
4318 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4319
4320 #define EC_CMD_MKBP_WAKE_MASK 0x0069
4321 enum ec_mkbp_event_mask_action {
4322 /* Retrieve the value of a wake mask. */
4323 GET_WAKE_MASK = 0,
4324
4325 /* Set the value of a wake mask. */
4326 SET_WAKE_MASK,
4327 };
4328
4329 enum ec_mkbp_mask_type {
4330 /*
4331 * These are host events sent via MKBP.
4332 *
4333 * Some examples are:
4334 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4335 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4336 *
4337 * The only things that should be in this mask are:
4338 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4339 */
4340 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4341
4342 /*
4343 * These are MKBP events. Some examples are:
4344 *
4345 * EC_MKBP_EVENT_KEY_MATRIX
4346 * EC_MKBP_EVENT_SWITCH
4347 *
4348 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4349 */
4350 EC_MKBP_EVENT_WAKE_MASK,
4351 };
4352
4353 struct ec_params_mkbp_event_wake_mask {
4354 /* One of enum ec_mkbp_event_mask_action */
4355 uint8_t action;
4356
4357 /*
4358 * Which MKBP mask are you interested in acting upon? This is one of
4359 * ec_mkbp_mask_type.
4360 */
4361 uint8_t mask_type;
4362
4363 /* If setting a new wake mask, this contains the mask to set. */
4364 uint32_t new_wake_mask;
4365 };
4366
4367 struct ec_response_mkbp_event_wake_mask {
4368 uint32_t wake_mask;
4369 };
4370
4371 /*****************************************************************************/
4372 /* Temperature sensor commands */
4373
4374 /* Read temperature sensor info */
4375 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
4376
4377 struct ec_params_temp_sensor_get_info {
4378 uint8_t id;
4379 } __ec_align1;
4380
4381 struct ec_response_temp_sensor_get_info {
4382 char sensor_name[32];
4383 uint8_t sensor_type;
4384 } __ec_align1;
4385
4386 /*****************************************************************************/
4387
4388 /*
4389 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4390 * commands accidentally sent to the wrong interface. See the ACPI section
4391 * below.
4392 */
4393
4394 /*****************************************************************************/
4395 /* Host event commands */
4396
4397 /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
4398 /*
4399 * Host event mask params and response structures, shared by all of the host
4400 * event commands below.
4401 */
4402 struct ec_params_host_event_mask {
4403 uint32_t mask;
4404 } __ec_align4;
4405
4406 struct ec_response_host_event_mask {
4407 uint32_t mask;
4408 } __ec_align4;
4409
4410 /* These all use ec_response_host_event_mask */
4411 #define EC_CMD_HOST_EVENT_GET_B 0x0087
4412 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4413 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
4414 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
4415
4416 /* These all use ec_params_host_event_mask */
4417 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4418 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4419 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
4420 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
4421 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
4422
4423 /*
4424 * Unified host event programming interface - Should be used by newer versions
4425 * of BIOS/OS to program host events and masks
4426 *
4427 * EC returns:
4428 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4429 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
4430 */
4431
4432 struct ec_params_host_event {
4433 /* Action requested by host - one of enum ec_host_event_action. */
4434 uint8_t action;
4435
4436 /*
4437 * Mask type that the host requested the action on - one of
4438 * enum ec_host_event_mask_type.
4439 */
4440 uint8_t mask_type;
4441
4442 /* Set to 0, ignore on read */
4443 uint16_t reserved;
4444
4445 /* Value to be used in case of set operations. */
4446 uint64_t value;
4447 } __ec_align4;
4448
4449 /*
4450 * Response structure returned by EC_CMD_HOST_EVENT.
4451 * Update the value on a GET request. Set to 0 on GET/CLEAR
4452 */
4453
4454 struct ec_response_host_event {
4455 /* Mask value in case of get operation */
4456 uint64_t value;
4457 } __ec_align4;
4458
4459 enum ec_host_event_action {
4460 /*
4461 * params.value is ignored. Value of mask_type populated
4462 * in response.value
4463 */
4464 EC_HOST_EVENT_GET,
4465
4466 /* Bits in params.value are set */
4467 EC_HOST_EVENT_SET,
4468
4469 /* Bits in params.value are cleared */
4470 EC_HOST_EVENT_CLEAR,
4471 };
4472
4473 enum ec_host_event_mask_type {
4474
4475 /* Main host event copy */
4476 EC_HOST_EVENT_MAIN,
4477
4478 /* Copy B of host events */
4479 EC_HOST_EVENT_B,
4480
4481 /* SCI Mask */
4482 EC_HOST_EVENT_SCI_MASK,
4483
4484 /* SMI Mask */
4485 EC_HOST_EVENT_SMI_MASK,
4486
4487 /* Mask of events that should be always reported in hostevents */
4488 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4489
4490 /* Active wake mask */
4491 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4492
4493 /* Lazy wake mask for S0ix */
4494 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4495
4496 /* Lazy wake mask for S3 */
4497 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4498
4499 /* Lazy wake mask for S5 */
4500 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4501 };
4502
4503 #define EC_CMD_HOST_EVENT 0x00A4
4504
4505 /*****************************************************************************/
4506 /* Switch commands */
4507
4508 /* Enable/disable LCD backlight */
4509 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
4510
4511 struct ec_params_switch_enable_backlight {
4512 uint8_t enabled;
4513 } __ec_align1;
4514
4515 /* Enable/disable WLAN/Bluetooth */
4516 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
4517 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
4518
4519 /* Version 0 params; no response */
4520 struct ec_params_switch_enable_wireless_v0 {
4521 uint8_t enabled;
4522 } __ec_align1;
4523
4524 /* Version 1 params */
4525 struct ec_params_switch_enable_wireless_v1 {
4526 /* Flags to enable now */
4527 uint8_t now_flags;
4528
4529 /* Which flags to copy from now_flags */
4530 uint8_t now_mask;
4531
4532 /*
4533 * Flags to leave enabled in S3, if they're on at the S0->S3
4534 * transition. (Other flags will be disabled by the S0->S3
4535 * transition.)
4536 */
4537 uint8_t suspend_flags;
4538
4539 /* Which flags to copy from suspend_flags */
4540 uint8_t suspend_mask;
4541 } __ec_align1;
4542
4543 /* Version 1 response */
4544 struct ec_response_switch_enable_wireless_v1 {
4545 /* Flags to enable now */
4546 uint8_t now_flags;
4547
4548 /* Flags to leave enabled in S3 */
4549 uint8_t suspend_flags;
4550 } __ec_align1;
4551
4552 /*****************************************************************************/
4553 /* GPIO commands. Only available on EC if write protect has been disabled. */
4554
4555 /* Set GPIO output value */
4556 #define EC_CMD_GPIO_SET 0x0092
4557
4558 struct ec_params_gpio_set {
4559 char name[32];
4560 uint8_t val;
4561 } __ec_align1;
4562
4563 /* Get GPIO value */
4564 #define EC_CMD_GPIO_GET 0x0093
4565
4566 /* Version 0 of input params and response */
4567 struct ec_params_gpio_get {
4568 char name[32];
4569 } __ec_align1;
4570
4571 struct ec_response_gpio_get {
4572 uint8_t val;
4573 } __ec_align1;
4574
4575 /* Version 1 of input params and response */
4576 struct ec_params_gpio_get_v1 {
4577 uint8_t subcmd;
4578 union {
4579 struct __ec_align1 {
4580 char name[32];
4581 } get_value_by_name;
4582 struct __ec_align1 {
4583 uint8_t index;
4584 } get_info;
4585 };
4586 } __ec_align1;
4587
4588 struct ec_response_gpio_get_v1 {
4589 union {
4590 struct __ec_align1 {
4591 uint8_t val;
4592 } get_value_by_name, get_count;
4593 struct __ec_todo_unpacked {
4594 uint8_t val;
4595 char name[32];
4596 uint32_t flags;
4597 } get_info;
4598 };
4599 } __ec_todo_packed;
4600
4601 enum gpio_get_subcmd {
4602 EC_GPIO_GET_BY_NAME = 0,
4603 EC_GPIO_GET_COUNT = 1,
4604 EC_GPIO_GET_INFO = 2,
4605 };
4606
4607 /*****************************************************************************/
4608 /* I2C commands. Only available when flash write protect is unlocked. */
4609
4610 /*
4611 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4612 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4613 *
4614 * Use EC_CMD_I2C_PASSTHRU instead.
4615 */
4616
4617 /* Read I2C bus */
4618 #define EC_CMD_I2C_READ 0x0094
4619
4620 struct ec_params_i2c_read {
4621 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
4622 uint8_t read_size; /* Either 8 or 16. */
4623 uint8_t port;
4624 uint8_t offset;
4625 } __ec_align_size1;
4626
4627 struct ec_response_i2c_read {
4628 uint16_t data;
4629 } __ec_align2;
4630
4631 /* Write I2C bus */
4632 #define EC_CMD_I2C_WRITE 0x0095
4633
4634 struct ec_params_i2c_write {
4635 uint16_t data;
4636 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
4637 uint8_t write_size; /* Either 8 or 16. */
4638 uint8_t port;
4639 uint8_t offset;
4640 } __ec_align_size1;
4641
4642 /*****************************************************************************/
4643 /* Charge state commands. Only available when flash write protect unlocked. */
4644
4645 /* Force charge state machine to stop charging the battery or force it to
4646 * discharge the battery.
4647 */
4648 #define EC_CMD_CHARGE_CONTROL 0x0096
4649 #define EC_VER_CHARGE_CONTROL 3
4650
4651 enum ec_charge_control_mode {
4652 CHARGE_CONTROL_NORMAL = 0,
4653 CHARGE_CONTROL_IDLE,
4654 CHARGE_CONTROL_DISCHARGE,
4655 /* Add no more entry below. */
4656 CHARGE_CONTROL_COUNT,
4657 };
4658
4659 #define EC_CHARGE_MODE_TEXT \
4660 { \
4661 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4662 [CHARGE_CONTROL_IDLE] = "IDLE", \
4663 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
4664 }
4665
4666 enum ec_charge_control_cmd {
4667 EC_CHARGE_CONTROL_CMD_SET = 0,
4668 EC_CHARGE_CONTROL_CMD_GET,
4669 };
4670
4671 enum ec_charge_control_flag {
4672 EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0),
4673 };
4674
4675 struct ec_params_charge_control {
4676 uint32_t mode; /* enum charge_control_mode */
4677
4678 /* Below are the fields added in V2. */
4679 uint8_t cmd; /* enum ec_charge_control_cmd. */
4680 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
4681 /*
4682 * Lower and upper thresholds for battery sustainer. This struct isn't
4683 * named to avoid tainting foreign projects' name spaces.
4684 *
4685 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4686 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4687 * lower=-1, upper=-1.
4688 */
4689 struct {
4690 int8_t lower; /* Display SoC in percentage. */
4691 int8_t upper; /* Display SoC in percentage. */
4692 } sustain_soc;
4693 } __ec_align4;
4694
4695 /* Added in v2 */
4696 struct ec_response_charge_control {
4697 uint32_t mode; /* enum charge_control_mode */
4698 struct { /* Battery sustainer thresholds */
4699 int8_t lower;
4700 int8_t upper;
4701 } sustain_soc;
4702 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
4703 uint8_t reserved;
4704 } __ec_align4;
4705
4706 /*****************************************************************************/
4707
4708 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
4709 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
4710
4711 /*
4712 * Read data from the saved snapshot. If the subcmd parameter is
4713 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4714 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4715 * end of the previous snapshot.
4716 *
4717 * The params are only looked at in version >= 1 of this command. Prior
4718 * versions will just default to CONSOLE_READ_NEXT behavior.
4719 *
4720 * Response is null-terminated string. Empty string, if there is no more
4721 * remaining output.
4722 */
4723 #define EC_CMD_CONSOLE_READ 0x0098
4724
4725 enum ec_console_read_subcmd {
4726 CONSOLE_READ_NEXT = 0,
4727 CONSOLE_READ_RECENT,
4728 };
4729
4730 struct ec_params_console_read_v1 {
4731 uint8_t subcmd; /* enum ec_console_read_subcmd */
4732 } __ec_align1;
4733
4734 /* Print directly to EC console from host. */
4735 #define EC_CMD_CONSOLE_PRINT 0x00AC
4736
4737 /*****************************************************************************/
4738
4739 /*
4740 * Cut off battery power immediately or after the host has shut down.
4741 *
4742 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4743 * EC_RES_SUCCESS if the command was successful.
4744 * EC_RES_ERROR if the cut off command failed.
4745 */
4746 #define EC_CMD_BATTERY_CUT_OFF 0x0099
4747
4748 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
4749
4750 struct ec_params_battery_cutoff {
4751 uint8_t flags;
4752 } __ec_align1;
4753
4754 /*****************************************************************************/
4755 /* USB port mux control. */
4756
4757 /*
4758 * Switch USB mux or return to automatic switching.
4759 */
4760 #define EC_CMD_USB_MUX 0x009A
4761
4762 struct ec_params_usb_mux {
4763 uint8_t mux;
4764 } __ec_align1;
4765
4766 /*****************************************************************************/
4767 /* LDOs / FETs control. */
4768
4769 enum ec_ldo_state {
4770 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4771 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4772 };
4773
4774 /*
4775 * Switch on/off a LDO.
4776 */
4777 #define EC_CMD_LDO_SET 0x009B
4778
4779 struct ec_params_ldo_set {
4780 uint8_t index;
4781 uint8_t state;
4782 } __ec_align1;
4783
4784 /*
4785 * Get LDO state.
4786 */
4787 #define EC_CMD_LDO_GET 0x009C
4788
4789 struct ec_params_ldo_get {
4790 uint8_t index;
4791 } __ec_align1;
4792
4793 struct ec_response_ldo_get {
4794 uint8_t state;
4795 } __ec_align1;
4796
4797 /*****************************************************************************/
4798 /* Power info. */
4799
4800 /*
4801 * Get power info.
4802 *
4803 * Note: v0 of this command is deprecated
4804 */
4805 #define EC_CMD_POWER_INFO 0x009D
4806
4807 /*
4808 * v1 of EC_CMD_POWER_INFO
4809 */
4810 enum system_power_source {
4811 /*
4812 * Haven't established which power source is used yet,
4813 * or no presence signals are available
4814 */
4815 POWER_SOURCE_UNKNOWN = 0,
4816 /* System is running on battery alone */
4817 POWER_SOURCE_BATTERY = 1,
4818 /* System is running on A/C alone */
4819 POWER_SOURCE_AC = 2,
4820 /* System is running on A/C and battery */
4821 POWER_SOURCE_AC_BATTERY = 3,
4822 };
4823
4824 struct ec_response_power_info_v1 {
4825 /* enum system_power_source */
4826 uint8_t system_power_source;
4827 /* Battery state-of-charge, 0-100, 0 if not present */
4828 uint8_t battery_soc;
4829 /* AC Adapter 100% rating, Watts */
4830 uint8_t ac_adapter_100pct;
4831 /* AC Adapter 10ms rating, Watts */
4832 uint8_t ac_adapter_10ms;
4833 /* Battery 1C rating, derated */
4834 uint8_t battery_1cd;
4835 /* Rest of Platform average, Watts */
4836 uint8_t rop_avg;
4837 /* Rest of Platform peak, Watts */
4838 uint8_t rop_peak;
4839 /* Nominal charger efficiency, % */
4840 uint8_t nominal_charger_eff;
4841 /* Rest of Platform VR Average Efficiency, % */
4842 uint8_t rop_avg_eff;
4843 /* Rest of Platform VR Peak Efficiency, % */
4844 uint8_t rop_peak_eff;
4845 /* SoC VR Efficiency at Average level, % */
4846 uint8_t soc_avg_eff;
4847 /* SoC VR Efficiency at Peak level, % */
4848 uint8_t soc_peak_eff;
4849 /* Intel-specific items */
4850 struct {
4851 /* Battery's level of DBPT support: 0, 2 */
4852 uint8_t batt_dbpt_support_level;
4853 /*
4854 * Maximum peak power from battery (10ms), Watts
4855 * If DBPT is not supported, this is 0
4856 */
4857 uint8_t batt_dbpt_max_peak_power;
4858 /*
4859 * Sustained peak power from battery, Watts
4860 * If DBPT is not supported, this is 0
4861 */
4862 uint8_t batt_dbpt_sus_peak_power;
4863 } intel;
4864 } __ec_align1;
4865
4866 /*****************************************************************************/
4867 /* I2C passthru command */
4868
4869 #define EC_CMD_I2C_PASSTHRU 0x009E
4870
4871 /* Read data; if not present, message is a write */
4872 #define EC_I2C_FLAG_READ BIT(15)
4873
4874 /* Mask for address */
4875 #define EC_I2C_ADDR_MASK 0x3ff
4876
4877 #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4878 #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
4879
4880 /* Any error */
4881 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4882
4883 struct ec_params_i2c_passthru_msg {
4884 uint16_t addr_flags; /* I2C peripheral address and flags */
4885 uint16_t len; /* Number of bytes to read or write */
4886 } __ec_align2;
4887
4888 struct ec_params_i2c_passthru {
4889 uint8_t port; /* I2C port number */
4890 uint8_t num_msgs; /* Number of messages */
4891 struct ec_params_i2c_passthru_msg msg[FLEXIBLE_ARRAY_MEMBER_SIZE];
4892 /* Data to write for all messages is concatenated here */
4893 } __ec_align2;
4894
4895 struct ec_response_i2c_passthru {
4896 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4897 uint8_t num_msgs; /* Number of messages processed */
4898 /* Data read by messages concatenated here */
4899 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE];
4900 } __ec_align1;
4901
4902 /*****************************************************************************/
4903 /* AP hang detect */
4904 #define EC_CMD_HANG_DETECT 0x009F
4905
4906 #define EC_HANG_DETECT_MIN_TIMEOUT 5
4907
4908 /* EC hang detect commands */
4909 enum ec_hang_detect_cmds {
4910 /* Reload AP hang detect timer. */
4911 EC_HANG_DETECT_CMD_RELOAD = 0x0,
4912
4913 /* Stop AP hang detect timer. */
4914 EC_HANG_DETECT_CMD_CANCEL = 0x1,
4915
4916 /* Configure watchdog with given reboot timeout and
4917 * cancel currently running AP hand detect timer.
4918 */
4919 EC_HANG_DETECT_CMD_SET_TIMEOUT = 0x2,
4920
4921 /* Get last hang status - whether the AP boot was clear or not */
4922 EC_HANG_DETECT_CMD_GET_STATUS = 0x3,
4923
4924 /* Clear last hang status. Called when AP is rebooting/shutting down
4925 * gracefully.
4926 */
4927 EC_HANG_DETECT_CMD_CLEAR_STATUS = 0x4
4928 };
4929
4930 struct ec_params_hang_detect {
4931 uint16_t command; /* enum ec_hang_detect_cmds */
4932 /* Timeout in seconds before generating reboot */
4933 uint16_t reboot_timeout_sec;
4934 } __ec_align2;
4935
4936 /* Status codes that describe whether AP has boot normally or the hang has been
4937 * detected and EC has reset AP
4938 */
4939 enum ec_hang_detect_status {
4940 EC_HANG_DETECT_AP_BOOT_NORMAL = 0x0,
4941 EC_HANG_DETECT_AP_BOOT_EC_WDT = 0x1,
4942 EC_HANG_DETECT_AP_BOOT_COUNT,
4943 };
4944 struct ec_response_hang_detect {
4945 uint8_t status; /* enum ec_hang_detect_status */
4946 } __ec_align1;
4947 /*****************************************************************************/
4948 /* Commands for battery charging */
4949
4950 /*
4951 * This is the single catch-all host command to exchange data regarding the
4952 * charge state machine (v2 and up).
4953 */
4954 #define EC_CMD_CHARGE_STATE 0x00A0
4955
4956 /* Subcommands for this host command */
4957 enum charge_state_command {
4958 CHARGE_STATE_CMD_GET_STATE,
4959 CHARGE_STATE_CMD_GET_PARAM,
4960 CHARGE_STATE_CMD_SET_PARAM,
4961 CHARGE_STATE_NUM_CMDS,
4962 };
4963
4964 /*
4965 * Known param numbers are defined here. Ranges are reserved for board-specific
4966 * params, which are handled by the particular implementations.
4967 */
4968 enum charge_state_params {
4969 /* charger voltage limit */
4970 CS_PARAM_CHG_VOLTAGE,
4971
4972 /* charger current limit */
4973 CS_PARAM_CHG_CURRENT,
4974
4975 /* charger input current limit */
4976 CS_PARAM_CHG_INPUT_CURRENT,
4977
4978 /* charger-specific status */
4979 CS_PARAM_CHG_STATUS,
4980
4981 /* charger-specific options */
4982 CS_PARAM_CHG_OPTION,
4983
4984 /*
4985 * Check if power is limited due to low battery and / or a
4986 * weak external charger. READ ONLY.
4987 */
4988 CS_PARAM_LIMIT_POWER,
4989
4990 /* min value of charger voltage limit (READ ONLY) */
4991 CS_PARAM_CHG_VOLTAGE_MIN,
4992
4993 /* max value of charger voltage limit (READ ONLY) */
4994 CS_PARAM_CHG_VOLTAGE_MAX,
4995
4996 /* step value of charger voltage limit (READ ONLY) */
4997 CS_PARAM_CHG_VOLTAGE_STEP,
4998
4999 /* min value of charger current limit (READ ONLY) */
5000 CS_PARAM_CHG_CURRENT_MIN,
5001
5002 /* max value of charger current limit (READ ONLY) */
5003 CS_PARAM_CHG_CURRENT_MAX,
5004
5005 /* step value of charger current limit (READ ONLY) */
5006 CS_PARAM_CHG_CURRENT_STEP,
5007
5008 /* min value of charger input current limit (READ ONLY) */
5009 CS_PARAM_CHG_INPUT_CURRENT_MIN,
5010
5011 /* max value of charger input current limit (READ ONLY) */
5012 CS_PARAM_CHG_INPUT_CURRENT_MAX,
5013
5014 /* step value of charger input current limit (READ ONLY) */
5015 CS_PARAM_CHG_INPUT_CURRENT_STEP,
5016
5017 /* How many so far? */
5018 CS_NUM_BASE_PARAMS,
5019
5020 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
5021 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
5022 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
5023
5024 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
5025 CS_PARAM_DEBUG_MIN = 0x20000,
5026 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
5027 CS_PARAM_DEBUG_MANUAL_MODE,
5028 CS_PARAM_DEBUG_SEEMS_DEAD,
5029 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
5030 CS_PARAM_DEBUG_BATT_REMOVED, /* Deprecated */
5031 CS_PARAM_DEBUG_MANUAL_CURRENT,
5032 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
5033 CS_PARAM_DEBUG_MAX = 0x2ffff,
5034
5035 /* Other custom param ranges go here... */
5036 };
5037
5038 struct ec_params_charge_state {
5039 uint8_t cmd; /* enum charge_state_command */
5040 union {
5041 /* get_state has no args */
5042
5043 struct __ec_todo_unpacked {
5044 uint32_t param; /* enum charge_state_param */
5045 } get_param;
5046
5047 struct __ec_todo_unpacked {
5048 uint32_t param; /* param to set */
5049 uint32_t value; /* value to set */
5050 } set_param;
5051 } __ec_todo_packed;
5052 uint8_t chgnum; /* Version 1 supports chgnum */
5053 } __ec_todo_packed;
5054
5055 struct ec_response_charge_state {
5056 union {
5057 struct __ec_align4 {
5058 int ac;
5059 int chg_voltage;
5060 int chg_current;
5061 int chg_input_current;
5062 int batt_state_of_charge;
5063 } get_state;
5064
5065 struct __ec_align4 {
5066 uint32_t value;
5067 } get_param;
5068
5069 /* set_param returns no args */
5070 };
5071 } __ec_align4;
5072
5073 /*
5074 * Set maximum battery charging current.
5075 */
5076 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
5077 #define EC_VER_CHARGE_CURRENT_LIMIT 1
5078
5079 struct ec_params_current_limit {
5080 uint32_t limit; /* in mA */
5081 } __ec_align4;
5082
5083 struct ec_params_current_limit_v1 {
5084 uint32_t limit; /* in mA */
5085 /*
5086 * Battery state of charge is the minimum charge percentage at which
5087 * the battery charge current limit will apply.
5088 * When not set, the limit will apply regardless of state of charge.
5089 */
5090 uint8_t battery_soc; /* battery state of charge, 0-100 */
5091 } __ec_align4;
5092
5093 /*
5094 * Set maximum external voltage / current.
5095 */
5096 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
5097
5098 /* Command v0 is used only on Spring and is obsolete + unsupported */
5099 struct ec_params_external_power_limit_v1 {
5100 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
5101 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
5102 } __ec_align2;
5103
5104 #define EC_POWER_LIMIT_NONE 0xffff
5105
5106 /*
5107 * Set maximum voltage & current of a dedicated charge port
5108 */
5109 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
5110
5111 struct ec_params_dedicated_charger_limit {
5112 uint16_t current_lim; /* in mA */
5113 uint16_t voltage_lim; /* in mV */
5114 } __ec_align2;
5115
5116 /*
5117 * Get and set charging splashscreen variables
5118 */
5119 #define EC_CMD_CHARGESPLASH 0x00A5
5120
5121 enum ec_chargesplash_cmd {
5122 /* Get the current state variables */
5123 EC_CHARGESPLASH_GET_STATE = 0,
5124
5125 /* Indicate initialization of the display loop */
5126 EC_CHARGESPLASH_DISPLAY_READY,
5127
5128 /* Manually put the EC into the requested state */
5129 EC_CHARGESPLASH_REQUEST,
5130
5131 /* Reset all state variables */
5132 EC_CHARGESPLASH_RESET,
5133
5134 /* Manually trigger a lockout */
5135 EC_CHARGESPLASH_LOCKOUT,
5136 };
5137
5138 struct __ec_align1 ec_params_chargesplash {
5139 /* enum ec_chargesplash_cmd */
5140 uint8_t cmd;
5141 };
5142
5143 struct __ec_align1 ec_response_chargesplash {
5144 uint8_t requested;
5145 uint8_t display_initialized;
5146 uint8_t locked_out;
5147 };
5148
5149 /*****************************************************************************/
5150 /* Hibernate/Deep Sleep Commands */
5151
5152 /* Set the delay before going into hibernation. */
5153 #define EC_CMD_HIBERNATION_DELAY 0x00A8
5154
5155 struct ec_params_hibernation_delay {
5156 /*
5157 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
5158 * current settings without changing them.
5159 */
5160 uint32_t seconds;
5161 } __ec_align4;
5162
5163 struct ec_response_hibernation_delay {
5164 /*
5165 * The current time in seconds in which the system has been in the G3
5166 * state. This value is reset if the EC transitions out of G3.
5167 */
5168 uint32_t time_g3;
5169
5170 /*
5171 * The current time remaining in seconds until the EC should hibernate.
5172 * This value is also reset if the EC transitions out of G3.
5173 */
5174 uint32_t time_remaining;
5175
5176 /*
5177 * The current time in seconds that the EC should wait in G3 before
5178 * hibernating.
5179 */
5180 uint32_t hibernate_delay;
5181 } __ec_align4;
5182
5183 /* Inform the EC when entering a sleep state */
5184 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
5185
5186 enum host_sleep_event {
5187 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
5188 HOST_SLEEP_EVENT_S3_RESUME = 2,
5189 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
5190 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
5191 /* S3 suspend with additional enabled wake sources */
5192 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
5193 };
5194
5195 struct ec_params_host_sleep_event {
5196 uint8_t sleep_event;
5197 } __ec_align1;
5198
5199 /*
5200 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
5201 * transition failures
5202 */
5203 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
5204
5205 /* Disable timeout detection for this sleep transition */
5206 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
5207
5208 struct ec_params_host_sleep_event_v1 {
5209 /* The type of sleep being entered or exited. */
5210 uint8_t sleep_event;
5211
5212 /* Padding */
5213 uint8_t reserved;
5214 union {
5215 /* Parameters that apply for suspend messages. */
5216 struct {
5217 /*
5218 * The timeout in milliseconds between when this message
5219 * is received and when the EC will declare sleep
5220 * transition failure if the sleep signal is not
5221 * asserted.
5222 */
5223 uint16_t sleep_timeout_ms;
5224 } suspend_params;
5225
5226 /* No parameters for non-suspend messages. */
5227 };
5228 } __ec_align2;
5229
5230 /* A timeout occurred when this bit is set */
5231 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
5232
5233 /*
5234 * The mask defining which bits correspond to the number of sleep transitions,
5235 * as well as the maximum number of suspend line transitions that will be
5236 * reported back to the host.
5237 */
5238 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
5239
5240 struct ec_response_host_sleep_event_v1 {
5241 union {
5242 /* Response fields that apply for resume messages. */
5243 struct {
5244 /*
5245 * The number of sleep power signal transitions that
5246 * occurred since the suspend message. The high bit
5247 * indicates a timeout occurred.
5248 */
5249 uint32_t sleep_transitions;
5250 } resume_response;
5251
5252 /* No response fields for non-resume messages. */
5253 };
5254 } __ec_align4;
5255
5256 /*****************************************************************************/
5257 /* Device events */
5258 #define EC_CMD_DEVICE_EVENT 0x00AA
5259
5260 enum ec_device_event {
5261 EC_DEVICE_EVENT_TRACKPAD,
5262 EC_DEVICE_EVENT_DSP,
5263 EC_DEVICE_EVENT_WIFI,
5264 EC_DEVICE_EVENT_WLC,
5265 };
5266
5267 enum ec_device_event_param {
5268 /* Get and clear pending device events */
5269 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
5270 /* Get device event mask */
5271 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
5272 /* Set device event mask */
5273 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
5274 };
5275
5276 #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
5277
5278 struct ec_params_device_event {
5279 uint32_t event_mask;
5280 uint8_t param;
5281 } __ec_align_size1;
5282
5283 struct ec_response_device_event {
5284 uint32_t event_mask;
5285 } __ec_align4;
5286
5287 /*****************************************************************************/
5288 /* Get s0ix counter */
5289 #define EC_CMD_GET_S0IX_COUNTER 0x00AB
5290
5291 /* Flag use to reset the counter */
5292 #define EC_S0IX_COUNTER_RESET 0x1
5293
5294 struct ec_params_s0ix_cnt {
5295 /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */
5296 uint32_t flags;
5297 } __ec_align4;
5298
5299 struct ec_response_s0ix_cnt {
5300 /* Value of the s0ix_counter */
5301 uint32_t s0ix_counter;
5302 } __ec_align4;
5303
5304 /*****************************************************************************/
5305 /* Smart battery pass-through */
5306
5307 /* Get / Set 16-bit smart battery registers - OBSOLETE */
5308 #define EC_CMD_SB_READ_WORD 0x00B0
5309 #define EC_CMD_SB_WRITE_WORD 0x00B1
5310
5311 /* Get / Set string smart battery parameters
5312 * formatted as SMBUS "block". - OBSOLETE
5313 */
5314 #define EC_CMD_SB_READ_BLOCK 0x00B2
5315 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
5316
5317 /*****************************************************************************/
5318 /* Battery vendor parameters
5319 *
5320 * Get or set vendor-specific parameters in the battery. Implementations may
5321 * differ between boards or batteries. On a set operation, the response
5322 * contains the actual value set, which may be rounded or clipped from the
5323 * requested value.
5324 */
5325
5326 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
5327
5328 enum ec_battery_vendor_param_mode {
5329 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5330 BATTERY_VENDOR_PARAM_MODE_SET,
5331 };
5332
5333 struct ec_params_battery_vendor_param {
5334 uint32_t param;
5335 uint32_t value;
5336 uint8_t mode;
5337 } __ec_align_size1;
5338
5339 struct ec_response_battery_vendor_param {
5340 uint32_t value;
5341 } __ec_align4;
5342
5343 /*****************************************************************************/
5344 /*
5345 * Smart Battery Firmware Update Command - OBSOLETE
5346 */
5347 #define EC_CMD_SB_FW_UPDATE 0x00B5
5348
5349 /*
5350 * Entering Verified Boot Mode Command
5351 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5352 * Valid Modes are: normal, developer, and recovery.
5353 *
5354 * EC no longer needs to know what mode vboot has entered,
5355 * so this command is deprecated. (See chromium:1014379.)
5356 */
5357 #define EC_CMD_ENTERING_MODE 0x00B6
5358
5359 struct ec_params_entering_mode {
5360 int vboot_mode;
5361 } __ec_align4;
5362
5363 #define VBOOT_MODE_NORMAL 0
5364 #define VBOOT_MODE_DEVELOPER 1
5365 #define VBOOT_MODE_RECOVERY 2
5366
5367 /*****************************************************************************/
5368 /*
5369 * I2C passthru protection command: Protects I2C tunnels against access on
5370 * certain addresses (board-specific).
5371 */
5372 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
5373
5374 enum ec_i2c_passthru_protect_subcmd {
5375 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5376 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5377 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
5378 };
5379
5380 struct ec_params_i2c_passthru_protect {
5381 uint8_t subcmd;
5382 uint8_t port; /* I2C port number */
5383 } __ec_align1;
5384
5385 struct ec_response_i2c_passthru_protect {
5386 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
5387 } __ec_align1;
5388
5389 /*****************************************************************************/
5390 /*
5391 * HDMI CEC commands
5392 *
5393 * These commands are for sending and receiving message via HDMI CEC
5394 */
5395
5396 #define EC_CEC_MAX_PORTS 16
5397
5398 #define MAX_CEC_MSG_LEN 16
5399
5400 /*
5401 * Helper macros for packing/unpacking cec_events.
5402 * bits[27:0] : bitmask of events from enum mkbp_cec_event
5403 * bits[31:28]: port number
5404 */
5405 #define EC_MKBP_EVENT_CEC_PACK(events, port) \
5406 (((events) & GENMASK(27, 0)) | (((port) & 0xf) << 28))
5407 #define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event) & GENMASK(27, 0))
5408 #define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf)
5409
5410 /* CEC message from the AP to be written on the CEC bus */
5411 #define EC_CMD_CEC_WRITE_MSG 0x00B8
5412
5413 /**
5414 * struct ec_params_cec_write - Message to write to the CEC bus
5415 * @msg: message content to write to the CEC bus
5416 */
5417 struct ec_params_cec_write {
5418 uint8_t msg[MAX_CEC_MSG_LEN];
5419 } __ec_align1;
5420
5421 /**
5422 * struct ec_params_cec_write_v1 - Message to write to the CEC bus
5423 * @port: CEC port to write the message on
5424 * @msg_len: length of msg in bytes
5425 * @msg: message content to write to the CEC bus
5426 */
5427 struct ec_params_cec_write_v1 {
5428 uint8_t port;
5429 uint8_t msg_len;
5430 uint8_t msg[MAX_CEC_MSG_LEN];
5431 } __ec_align1;
5432
5433 /* CEC message read from a CEC bus reported back to the AP */
5434 #define EC_CMD_CEC_READ_MSG 0x00B9
5435
5436 /**
5437 * struct ec_params_cec_read - Read a message from the CEC bus
5438 * @port: CEC port to read a message on
5439 */
5440 struct ec_params_cec_read {
5441 uint8_t port;
5442 } __ec_align1;
5443
5444 /**
5445 * struct ec_response_cec_read - Message read from the CEC bus
5446 * @msg_len: length of msg in bytes
5447 * @msg: message content read from the CEC bus
5448 */
5449 struct ec_response_cec_read {
5450 uint8_t msg_len;
5451 uint8_t msg[MAX_CEC_MSG_LEN];
5452 } __ec_align1;
5453
5454 /* Set various CEC parameters */
5455 #define EC_CMD_CEC_SET 0x00BA
5456
5457 /**
5458 * struct ec_params_cec_set - CEC parameters set
5459 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5460 * @port: CEC port to set the parameter on
5461 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5462 * or 1 to enable CEC functionality, in case cmd is
5463 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5464 * address between 0 and 15 or 0xff to unregister
5465 */
5466 struct ec_params_cec_set {
5467 uint8_t cmd : 4; /* enum cec_command */
5468 uint8_t port : 4;
5469 uint8_t val;
5470 } __ec_align1;
5471
5472 /* Read various CEC parameters */
5473 #define EC_CMD_CEC_GET 0x00BB
5474
5475 /**
5476 * struct ec_params_cec_get - CEC parameters get
5477 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5478 * @port: CEC port to get the parameter on
5479 */
5480 struct ec_params_cec_get {
5481 uint8_t cmd : 4; /* enum cec_command */
5482 uint8_t port : 4;
5483 } __ec_align1;
5484
5485 /**
5486 * struct ec_response_cec_get - CEC parameters get response
5487 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5488 * disabled or 1 if CEC functionality is enabled,
5489 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5490 * configured logical address between 0 and 15 or 0xff if unregistered
5491 */
5492 struct ec_response_cec_get {
5493 uint8_t val;
5494 } __ec_align1;
5495
5496 /* Get the number of CEC ports */
5497 #define EC_CMD_CEC_PORT_COUNT 0x00C1
5498
5499 /**
5500 * struct ec_response_cec_port_count - CEC port count response
5501 * @port_count: number of CEC ports
5502 */
5503 struct ec_response_cec_port_count {
5504 uint8_t port_count;
5505 } __ec_align1;
5506
5507 /* CEC parameters command */
5508 enum cec_command {
5509 /* CEC reading, writing and events enable */
5510 CEC_CMD_ENABLE,
5511 /* CEC logical address */
5512 CEC_CMD_LOGICAL_ADDRESS,
5513 };
5514
5515 /* Events from CEC to AP */
5516 enum mkbp_cec_event {
5517 /* Outgoing message was acknowledged by a follower */
5518 EC_MKBP_CEC_SEND_OK = BIT(0),
5519 /* Outgoing message was not acknowledged */
5520 EC_MKBP_CEC_SEND_FAILED = BIT(1),
5521 /* Incoming message can be read out by AP */
5522 EC_MKBP_CEC_HAVE_DATA = BIT(2),
5523 };
5524
5525 /*****************************************************************************/
5526
5527 /* Commands for audio codec. */
5528 #define EC_CMD_EC_CODEC 0x00BC
5529
5530 enum ec_codec_subcmd {
5531 EC_CODEC_GET_CAPABILITIES = 0x0,
5532 EC_CODEC_GET_SHM_ADDR = 0x1,
5533 EC_CODEC_SET_SHM_ADDR = 0x2,
5534 EC_CODEC_SUBCMD_COUNT,
5535 };
5536
5537 enum ec_codec_cap {
5538 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5539 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5540 EC_CODEC_CAP_LAST = 32,
5541 };
5542
5543 enum ec_codec_shm_id {
5544 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5545 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5546 EC_CODEC_SHM_ID_LAST,
5547 };
5548
5549 enum ec_codec_shm_type {
5550 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5551 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
5552 };
5553
5554 struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5555 uint8_t shm_id;
5556 uint8_t reserved[3];
5557 };
5558
5559 struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5560 uint64_t phys_addr;
5561 uint32_t len;
5562 uint8_t shm_id;
5563 uint8_t reserved[3];
5564 };
5565
5566 struct __ec_align4 ec_param_ec_codec {
5567 uint8_t cmd; /* enum ec_codec_subcmd */
5568 uint8_t reserved[3];
5569
5570 union {
5571 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5572 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
5573 };
5574 };
5575
5576 struct __ec_align4 ec_response_ec_codec_get_capabilities {
5577 uint32_t capabilities;
5578 };
5579
5580 struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5581 uint64_t phys_addr;
5582 uint32_t len;
5583 uint8_t type;
5584 uint8_t reserved[3];
5585 };
5586
5587 /*****************************************************************************/
5588
5589 /* Commands for DMIC on audio codec. */
5590 #define EC_CMD_EC_CODEC_DMIC 0x00BD
5591
5592 enum ec_codec_dmic_subcmd {
5593 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5594 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5595 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5596 EC_CODEC_DMIC_SUBCMD_COUNT,
5597 };
5598
5599 enum ec_codec_dmic_channel {
5600 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5601 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5602 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5603 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5604 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5605 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5606 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5607 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5608 EC_CODEC_DMIC_CHANNEL_COUNT,
5609 };
5610
5611 struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5612 uint8_t channel; /* enum ec_codec_dmic_channel */
5613 uint8_t gain;
5614 uint8_t reserved[2];
5615 };
5616
5617 struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5618 uint8_t channel; /* enum ec_codec_dmic_channel */
5619 uint8_t reserved[3];
5620 };
5621
5622 struct __ec_align4 ec_param_ec_codec_dmic {
5623 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5624 uint8_t reserved[3];
5625
5626 union {
5627 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5628 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
5629 };
5630 };
5631
5632 struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5633 uint8_t max_gain;
5634 };
5635
5636 struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5637 uint8_t gain;
5638 };
5639
5640 /*****************************************************************************/
5641
5642 /* Commands for I2S RX on audio codec. */
5643
5644 #define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5645
5646 enum ec_codec_i2s_rx_subcmd {
5647 EC_CODEC_I2S_RX_ENABLE = 0x0,
5648 EC_CODEC_I2S_RX_DISABLE = 0x1,
5649 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5650 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5651 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
5652 EC_CODEC_I2S_RX_RESET = 0x5,
5653 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5654 };
5655
5656 enum ec_codec_i2s_rx_sample_depth {
5657 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5658 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5659 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5660 };
5661
5662 enum ec_codec_i2s_rx_daifmt {
5663 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5664 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5665 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5666 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5667 };
5668
5669 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5670 uint8_t depth;
5671 uint8_t reserved[3];
5672 };
5673
5674 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5675 uint8_t left;
5676 uint8_t right;
5677 uint8_t reserved[2];
5678 };
5679
5680 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5681 uint8_t daifmt;
5682 uint8_t reserved[3];
5683 };
5684
5685 struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5686 uint32_t bclk;
5687 };
5688
5689 struct __ec_align4 ec_param_ec_codec_i2s_rx {
5690 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5691 uint8_t reserved[3];
5692
5693 union {
5694 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5695 set_sample_depth_param;
5696 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5697 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
5698 };
5699 };
5700
5701 /*****************************************************************************/
5702 /* Commands for WoV on audio codec. */
5703
5704 #define EC_CMD_EC_CODEC_WOV 0x00BF
5705
5706 enum ec_codec_wov_subcmd {
5707 EC_CODEC_WOV_SET_LANG = 0x0,
5708 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5709 EC_CODEC_WOV_GET_LANG = 0x2,
5710 EC_CODEC_WOV_ENABLE = 0x3,
5711 EC_CODEC_WOV_DISABLE = 0x4,
5712 EC_CODEC_WOV_READ_AUDIO = 0x5,
5713 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5714 EC_CODEC_WOV_SUBCMD_COUNT,
5715 };
5716
5717 /*
5718 * @hash is SHA256 of the whole language model.
5719 * @total_len indicates the length of whole language model.
5720 * @offset is the cursor from the beginning of the model.
5721 * @buf is the packet buffer.
5722 * @len denotes how many bytes in the buf.
5723 */
5724 struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5725 uint8_t hash[32];
5726 uint32_t total_len;
5727 uint32_t offset;
5728 uint8_t buf[128];
5729 uint32_t len;
5730 };
5731
5732 struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5733 uint8_t hash[32];
5734 uint32_t total_len;
5735 };
5736
5737 struct __ec_align4 ec_param_ec_codec_wov {
5738 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5739 uint8_t reserved[3];
5740
5741 union {
5742 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5743 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
5744 };
5745 };
5746
5747 struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5748 uint8_t hash[32];
5749 };
5750
5751 struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5752 uint8_t buf[128];
5753 uint32_t len;
5754 };
5755
5756 struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5757 uint32_t offset;
5758 uint32_t len;
5759 };
5760
5761 /*****************************************************************************/
5762 /* Commands for PoE PSE controller */
5763
5764 #define EC_CMD_PSE 0x00C0
5765
5766 enum ec_pse_subcmd {
5767 EC_PSE_STATUS = 0x0,
5768 EC_PSE_ENABLE = 0x1,
5769 EC_PSE_DISABLE = 0x2,
5770 EC_PSE_SUBCMD_COUNT,
5771 };
5772
5773 struct __ec_align1 ec_params_pse {
5774 uint8_t cmd; /* enum ec_pse_subcmd */
5775 uint8_t port; /* PSE port */
5776 };
5777
5778 enum ec_pse_status {
5779 EC_PSE_STATUS_DISABLED = 0x0,
5780 EC_PSE_STATUS_ENABLED = 0x1,
5781 EC_PSE_STATUS_POWERED = 0x2,
5782 };
5783
5784 struct __ec_align1 ec_response_pse_status {
5785 uint8_t status; /* enum ec_pse_status */
5786 };
5787
5788 /*****************************************************************************/
5789 /* System commands */
5790
5791 /*
5792 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5793 * necessarily reboot the EC. Rename to "image" or something similar?
5794 */
5795 #define EC_CMD_REBOOT_EC 0x00D2
5796
5797 /* Command */
5798 enum ec_reboot_cmd {
5799 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5800 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5801 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
5802 /* (command 3 was jump to RW-B) */
5803 EC_REBOOT_COLD = 4, /* Cold-reboot */
5804 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5805 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
5806 /*
5807 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5808 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5809 */
5810 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
5811 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5812 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
5813 };
5814
5815 /* Flags for ec_params_reboot_ec.reboot_flags */
5816 #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5817 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5818 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5819 #define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
5820
5821 struct ec_params_reboot_ec {
5822 uint8_t cmd; /* enum ec_reboot_cmd */
5823 uint8_t flags; /* See EC_REBOOT_FLAG_* */
5824 } __ec_align1;
5825
5826 /*
5827 * Get information on last EC panic.
5828 *
5829 * Returns variable-length platform-dependent panic information. See panic.h
5830 * for details.
5831 */
5832 #define EC_CMD_GET_PANIC_INFO 0x00D3
5833
5834 struct ec_params_get_panic_info_v1 {
5835 /* Do not modify PANIC_DATA_FLAG_OLD_HOSTCMD when reading panic info */
5836 uint8_t preserve_old_hostcmd_flag;
5837 } __ec_align1;
5838
5839 /*****************************************************************************/
5840 /*
5841 * Special commands
5842 *
5843 * These do not follow the normal rules for commands. See each command for
5844 * details.
5845 */
5846
5847 /*
5848 * Reboot NOW
5849 *
5850 * This command will work even when the EC LPC interface is busy, because the
5851 * reboot command is processed at interrupt level. Note that when the EC
5852 * reboots, the host will reboot too, so there is no response to this command.
5853 *
5854 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5855 */
5856 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
5857
5858 /*
5859 * Resend last response (not supported on LPC).
5860 *
5861 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5862 * there was no previous command, or the previous command's response was too
5863 * big to save.
5864 */
5865 #define EC_CMD_RESEND_RESPONSE 0x00DB
5866
5867 /*
5868 * This header byte on a command indicate version 0. Any header byte less
5869 * than this means that we are talking to an old EC which doesn't support
5870 * versioning. In that case, we assume version 0.
5871 *
5872 * Header bytes greater than this indicate a later version. For example,
5873 * EC_CMD_VERSION0 + 1 means we are using version 1.
5874 *
5875 * The old EC interface must not use commands 0xdc or higher.
5876 */
5877 #define EC_CMD_VERSION0 0x00DC
5878
5879 /*
5880 * Memory Dump Commands
5881 *
5882 * Since the HOSTCMD response size is limited, depending on the
5883 * protocol, retrieving a memory dump is split into 3 commands.
5884 *
5885 * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries,
5886 * and the total dump size.
5887 * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given
5888 * memory dump entry index.
5889 * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given
5890 * address. The address and size must be within the bounds of the given
5891 * memory dump entry index. Each response is limited to the max response size
5892 * of the host protocol, so this may need to be called repeatedly to retrieve
5893 * the entire memory dump entry.
5894 *
5895 * Memory entries may overlap and may be out of order.
5896 * The host should check for overlaps to optimize transfer rate.
5897 */
5898 #define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD
5899 struct ec_response_memory_dump_get_metadata {
5900 uint16_t memory_dump_entry_count;
5901 uint32_t memory_dump_total_size;
5902 } __ec_align4;
5903
5904 #define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE
5905 struct ec_params_memory_dump_get_entry_info {
5906 uint16_t memory_dump_entry_index;
5907 } __ec_align4;
5908
5909 struct ec_response_memory_dump_get_entry_info {
5910 uint32_t address;
5911 uint32_t size;
5912 } __ec_align4;
5913
5914 #define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF
5915
5916 struct ec_params_memory_dump_read_memory {
5917 uint16_t memory_dump_entry_index;
5918 uint32_t address;
5919 uint32_t size;
5920 } __ec_align4;
5921
5922 #define EC_CMD_PANIC_LOG_INFO 0x00E0
5923
5924 /*
5925 * Parameters for configuring the panic log.
5926 * Freeze and unfreeze are mutually exclusive.
5927 */
5928 struct ec_params_panic_log_info {
5929 /* Reset panic log */
5930 uint8_t reset;
5931 /* Freeze panic log */
5932 uint8_t freeze;
5933 /* Unfreeze panic log */
5934 uint8_t unfreeze;
5935 } __ec_align1;
5936
5937 /*
5938 * Returns the panic log info before applying the configuration
5939 * in ec_params_panic_log_info.
5940 */
5941 struct ec_response_panic_log_info {
5942 uint32_t version;
5943 uint32_t capacity;
5944 uint32_t length;
5945 uint8_t valid;
5946 uint8_t frozen;
5947 } __ec_align4;
5948
5949 #define EC_CMD_PANIC_LOG_READ 0x00E1
5950
5951 /*
5952 * Read from panic log at given byte offset. Will read up to the end of the
5953 * panic log or response max. Use EC_CMD_PANIC_LOG_INFO command to freeze
5954 * the log and get the length before reading.
5955 */
5956 struct ec_params_panic_log_read {
5957 uint32_t offset;
5958 } __ec_align4;
5959
5960 /*
5961 * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into
5962 * host_cmd_handler_args.response and host_cmd_handler_args.response_size.
5963 */
5964
5965 /*****************************************************************************/
5966 /*
5967 * PD commands
5968 *
5969 * These commands are for PD MCU communication.
5970 */
5971
5972 /* EC to PD MCU exchange status command */
5973 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
5974 #define EC_VER_PD_EXCHANGE_STATUS 2
5975
5976 enum pd_charge_state {
5977 /* Don't change charge state */
5978 PD_CHARGE_NO_CHANGE = 0,
5979
5980 /* No charging allowed */
5981 PD_CHARGE_NONE,
5982
5983 /* 5V charging only */
5984 PD_CHARGE_5V,
5985
5986 /* Charge at max voltage */
5987 PD_CHARGE_MAX,
5988 };
5989
5990 /* Status of EC being sent to PD */
5991 #define EC_STATUS_HIBERNATING BIT(0)
5992
5993 struct ec_params_pd_status {
5994 /* EC status */
5995 uint8_t status;
5996
5997 /* battery state of charge */
5998 int8_t batt_soc;
5999
6000 /* charging state (from enum pd_charge_state) */
6001 uint8_t charge_state;
6002 } __ec_align1;
6003
6004 /* Status of PD being sent back to EC */
6005 #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
6006 #define PD_STATUS_IN_RW BIT(1) /* Running RW image */
6007 #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
6008 #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
6009 #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
6010 #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
6011 #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
6012 #define PD_STATUS_EC_INT_ACTIVE \
6013 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
6014 struct ec_response_pd_status {
6015 /* input current limit */
6016 uint32_t curr_lim_ma;
6017
6018 /* PD MCU status */
6019 uint16_t status;
6020
6021 /* active charging port */
6022 int8_t active_charge_port;
6023 } __ec_align_size1;
6024
6025 /* AP to PD MCU host event status command, cleared on read */
6026 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
6027
6028 /* PD MCU host event status bits */
6029 #define PD_EVENT_UPDATE_DEVICE BIT(0)
6030 #define PD_EVENT_POWER_CHANGE BIT(1)
6031 #define PD_EVENT_IDENTITY_RECEIVED BIT(2)
6032 #define PD_EVENT_DATA_SWAP BIT(3)
6033 #define PD_EVENT_TYPEC BIT(4)
6034 #define PD_EVENT_PPM BIT(5)
6035 #define PD_EVENT_INIT BIT(6)
6036
6037 struct ec_response_host_event_status {
6038 uint32_t status; /* PD MCU host event status */
6039 } __ec_align4;
6040
6041 /*
6042 * Set USB type-C port role and muxes
6043 *
6044 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
6045 *
6046 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
6047 */
6048 #define EC_CMD_USB_PD_CONTROL 0x0101
6049
6050 enum usb_pd_control_role {
6051 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
6052 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
6053 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
6054 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
6055 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
6056 USB_PD_CTRL_ROLE_FREEZE = 5,
6057 USB_PD_CTRL_ROLE_COUNT,
6058 };
6059
6060 enum usb_pd_control_mux {
6061 USB_PD_CTRL_MUX_NO_CHANGE = 0,
6062 USB_PD_CTRL_MUX_NONE = 1,
6063 USB_PD_CTRL_MUX_USB = 2,
6064 USB_PD_CTRL_MUX_DP = 3,
6065 USB_PD_CTRL_MUX_DOCK = 4,
6066 USB_PD_CTRL_MUX_AUTO = 5,
6067 USB_PD_CTRL_MUX_COUNT,
6068 };
6069
6070 enum usb_pd_control_swap {
6071 USB_PD_CTRL_SWAP_NONE = 0,
6072 USB_PD_CTRL_SWAP_DATA = 1,
6073 USB_PD_CTRL_SWAP_POWER = 2,
6074 USB_PD_CTRL_SWAP_VCONN = 3,
6075 USB_PD_CTRL_SWAP_COUNT,
6076 };
6077
6078 struct ec_params_usb_pd_control {
6079 uint8_t port;
6080 uint8_t role;
6081 uint8_t mux;
6082 uint8_t swap;
6083 } __ec_align1;
6084
6085 #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
6086 #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
6087 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
6088
6089 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
6090 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
6091 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
6092 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
6093 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
6094 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
6095 /* Partner unconstrained power */
6096 #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
6097
6098 struct ec_response_usb_pd_control {
6099 uint8_t enabled;
6100 uint8_t role;
6101 uint8_t polarity;
6102 uint8_t state;
6103 } __ec_align1;
6104
6105 struct ec_response_usb_pd_control_v1 {
6106 uint8_t enabled;
6107 uint8_t role;
6108 uint8_t polarity;
6109 char state[32];
6110 } __ec_align1;
6111
6112 /* Possible port partner connections based on CC line states */
6113 enum pd_cc_states {
6114 PD_CC_NONE = 0, /* No port partner attached */
6115
6116 /* From DFP perspective */
6117 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
6118 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
6119 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
6120 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
6121
6122 /* From UFP perspective */
6123 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
6124 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
6125 };
6126
6127 /* Active/Passive Cable */
6128 #define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
6129 /* Optical/Non-optical cable */
6130 #define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
6131 /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
6132 #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
6133 /* Active Link Uni-Direction */
6134 #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
6135 /* Retimer/Redriver cable */
6136 #define USB_PD_CTRL_RETIMER_CABLE BIT(4)
6137
6138 struct ec_response_usb_pd_control_v2 {
6139 uint8_t enabled;
6140 uint8_t role;
6141 uint8_t polarity;
6142 char state[32];
6143 uint8_t cc_state; /* enum pd_cc_states representing cc state */
6144 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
6145 uint8_t reserved; /* Reserved for future use */
6146 uint8_t control_flags; /* USB_PD_CTRL_*flags */
6147 uint8_t cable_speed; /* TBT_SS_* cable speed */
6148 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
6149 } __ec_align1;
6150
6151 #define EC_CMD_USB_PD_PORTS 0x0102
6152
6153 /* Maximum number of PD ports on a device, num_ports will be <= this */
6154 #define EC_USB_PD_MAX_PORTS 8
6155
6156 struct ec_response_usb_pd_ports {
6157 uint8_t num_ports;
6158 } __ec_align1;
6159
6160 #define EC_CMD_USB_PD_POWER_INFO 0x0103
6161
6162 #define PD_POWER_CHARGING_PORT 0xff
6163 struct ec_params_usb_pd_power_info {
6164 uint8_t port;
6165 } __ec_align1;
6166
6167 enum usb_chg_type {
6168 USB_CHG_TYPE_NONE,
6169 USB_CHG_TYPE_PD,
6170 USB_CHG_TYPE_C,
6171 USB_CHG_TYPE_PROPRIETARY,
6172 USB_CHG_TYPE_BC12_DCP,
6173 USB_CHG_TYPE_BC12_CDP,
6174 USB_CHG_TYPE_BC12_SDP,
6175 USB_CHG_TYPE_OTHER,
6176 USB_CHG_TYPE_VBUS,
6177 USB_CHG_TYPE_UNKNOWN,
6178 USB_CHG_TYPE_DEDICATED,
6179 };
6180 enum usb_power_roles {
6181 USB_PD_PORT_POWER_DISCONNECTED,
6182 USB_PD_PORT_POWER_SOURCE,
6183 USB_PD_PORT_POWER_SINK,
6184 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
6185 };
6186
6187 struct usb_chg_measures {
6188 uint16_t voltage_max;
6189 uint16_t voltage_now;
6190 uint16_t current_max;
6191 uint16_t current_lim;
6192 } __ec_align2;
6193
6194 struct ec_response_usb_pd_power_info {
6195 uint8_t role;
6196 uint8_t type;
6197 uint8_t dualrole;
6198 uint8_t reserved1;
6199 struct usb_chg_measures meas;
6200 uint32_t max_power;
6201 } __ec_align4;
6202
6203 /*
6204 * This command will return the number of USB PD charge port + the number
6205 * of dedicated port present.
6206 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
6207 */
6208 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
6209 struct ec_response_charge_port_count {
6210 uint8_t port_count;
6211 } __ec_align1;
6212
6213 /*
6214 * This command enable/disable dynamic PDO selection.
6215 */
6216 #define EC_CMD_USB_PD_DPS_CONTROL 0x0106
6217
6218 struct ec_params_usb_pd_dps_control {
6219 uint8_t enable;
6220 } __ec_align1;
6221
6222 /*
6223 * This command return the status of dynamic PDO selection.
6224 */
6225 #define EC_CMD_USB_PD_DPS_STATUS 0x0107
6226
6227 struct ec_response_usb_pd_dps_status {
6228 int32_t is_enabled;
6229 int32_t port;
6230 int32_t requested_voltage;
6231 int32_t requested_current;
6232 int32_t input_power;
6233 int32_t input_voltage;
6234 int32_t input_current;
6235 int32_t efficient_voltage;
6236 int32_t battery_voltage;
6237 int32_t max_voltage;
6238 } __ec_align4;
6239
6240 /* Write USB-PD device FW */
6241 #define EC_CMD_USB_PD_FW_UPDATE 0x0110
6242
6243 enum usb_pd_fw_update_cmds {
6244 USB_PD_FW_REBOOT,
6245 USB_PD_FW_FLASH_ERASE,
6246 USB_PD_FW_FLASH_WRITE,
6247 USB_PD_FW_ERASE_SIG,
6248 };
6249
6250 struct ec_params_usb_pd_fw_update {
6251 uint16_t dev_id;
6252 uint8_t cmd;
6253 uint8_t port;
6254
6255 /* Size to write in bytes */
6256 uint32_t size;
6257
6258 /* Followed by data to write */
6259 } __ec_align4;
6260
6261 /* Write USB-PD Accessory RW_HASH table entry */
6262 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
6263 /* RW hash is first 20 bytes of SHA-256 of RW section */
6264 #define PD_RW_HASH_SIZE 20
6265 struct ec_params_usb_pd_rw_hash_entry {
6266 uint16_t dev_id;
6267 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
6268
6269 /*
6270 * Reserved for alignment of current_image
6271 * TODO(rspangler) but it's not aligned!
6272 * Should have been reserved[2].
6273 */
6274 uint8_t reserved;
6275
6276 /* One of ec_image */
6277 uint32_t current_image;
6278 } __ec_align1;
6279
6280 /* Read USB-PD Accessory info */
6281 #define EC_CMD_USB_PD_DEV_INFO 0x0112
6282
6283 struct ec_params_usb_pd_info_request {
6284 uint8_t port;
6285 } __ec_align1;
6286
6287 /* Read USB-PD Device discovery info */
6288 #define EC_CMD_USB_PD_DISCOVERY 0x0113
6289 struct ec_params_usb_pd_discovery_entry {
6290 uint16_t vid; /* USB-IF VID */
6291 uint16_t pid; /* USB-IF PID */
6292 uint8_t ptype; /* product type (hub,periph,cable,ama) */
6293 } __ec_align_size1;
6294
6295 /* Override default charge behavior */
6296 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
6297
6298 /* Negative port parameters have special meaning */
6299 enum usb_pd_override_ports {
6300 /*
6301 * DONT_CHARGE is for all ports. Thus it's persistent across plug-in
6302 * or plug-out.
6303 */
6304 OVERRIDE_DONT_CHARGE = -2,
6305 OVERRIDE_OFF = -1,
6306 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
6307 };
6308
6309 struct ec_params_charge_port_override {
6310 int16_t override_port; /* Override port# */
6311 } __ec_align2;
6312
6313 /*
6314 * Read (and delete) one entry of PD event log.
6315 * TODO(crbug.com/751742): Make this host command more generic to accommodate
6316 * future non-PD logs that use the same internal EC event_log.
6317 */
6318 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
6319
6320 struct ec_response_pd_log {
6321 uint32_t timestamp; /* relative timestamp in milliseconds */
6322 uint8_t type; /* event type : see PD_EVENT_xx below */
6323 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
6324 uint16_t data; /* type-defined data payload */
6325 /* optional additional data payload: 0..16 bytes */
6326 uint8_t payload[FLEXIBLE_ARRAY_MEMBER_SIZE];
6327 } __ec_align4;
6328
6329 /* The timestamp is the microsecond counter shifted to get about a ms. */
6330 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
6331
6332 #define PD_LOG_SIZE_MASK 0x1f
6333 #define PD_LOG_PORT_MASK 0xe0
6334 #define PD_LOG_PORT_SHIFT 5
6335 #define PD_LOG_PORT_SIZE(port, size) \
6336 (((port) << PD_LOG_PORT_SHIFT) | ((size) & PD_LOG_SIZE_MASK))
6337 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
6338 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
6339
6340 /* PD event log : entry types */
6341 /* PD MCU events */
6342 #define PD_EVENT_MCU_BASE 0x00
6343 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
6344 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
6345 /* Reserved for custom board event */
6346 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
6347 /* PD generic accessory events */
6348 #define PD_EVENT_ACC_BASE 0x20
6349 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
6350 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
6351 /* PD power supply events */
6352 #define PD_EVENT_PS_BASE 0x40
6353 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
6354 /* PD video dongles events */
6355 #define PD_EVENT_VIDEO_BASE 0x60
6356 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
6357 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
6358 /* Returned in the "type" field, when there is no entry available */
6359 #define PD_EVENT_NO_ENTRY 0xff
6360
6361 /*
6362 * PD_EVENT_MCU_CHARGE event definition :
6363 * the payload is "struct usb_chg_measures"
6364 * the data field contains the port state flags as defined below :
6365 */
6366 /* Port partner is a dual role device */
6367 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
6368 /* Port is the pending override port */
6369 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
6370 /* Port is the override port */
6371 #define CHARGE_FLAGS_OVERRIDE BIT(13)
6372 /* Charger type */
6373 #define CHARGE_FLAGS_TYPE_SHIFT 3
6374 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
6375 /* Power delivery role */
6376 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
6377
6378 /*
6379 * PD_EVENT_PS_FAULT data field flags definition :
6380 */
6381 #define PS_FAULT_OCP 1
6382 #define PS_FAULT_FAST_OCP 2
6383 #define PS_FAULT_OVP 3
6384 #define PS_FAULT_DISCH 4
6385
6386 /*
6387 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
6388 */
6389 struct mcdp_version {
6390 uint8_t major;
6391 uint8_t minor;
6392 uint16_t build;
6393 } __ec_align4;
6394
6395 struct mcdp_info {
6396 uint8_t family[2];
6397 uint8_t chipid[2];
6398 struct mcdp_version irom;
6399 struct mcdp_version fw;
6400 } __ec_align4;
6401
6402 /* struct mcdp_info field decoding */
6403 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
6404 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
6405
6406 /* Get/Set USB-PD Alternate mode info */
6407 #define EC_CMD_USB_PD_GET_AMODE 0x0116
6408 struct ec_params_usb_pd_get_mode_request {
6409 uint16_t svid_idx; /* SVID index to get */
6410 uint8_t port; /* port */
6411 } __ec_align_size1;
6412
6413 #define VDO_MAX_SIZE 7
6414 /* Max number of VDM data objects without VDM header */
6415 #define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1)
6416
6417 struct ec_params_usb_pd_get_mode_response {
6418 uint16_t svid; /* SVID */
6419 uint16_t opos; /* Object Position */
6420 uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */
6421 } __ec_align4;
6422
6423 #define EC_CMD_USB_PD_SET_AMODE 0x0117
6424
6425 enum pd_mode_cmd {
6426 PD_EXIT_MODE = 0,
6427 PD_ENTER_MODE = 1,
6428 /* Not a command. Do NOT remove. */
6429 PD_MODE_CMD_COUNT,
6430 };
6431
6432 struct ec_params_usb_pd_set_mode_request {
6433 uint32_t cmd; /* enum pd_mode_cmd */
6434 uint16_t svid; /* SVID to set */
6435 uint8_t opos; /* Object Position */
6436 uint8_t port; /* port */
6437 } __ec_align4;
6438
6439 /* Ask the PD MCU to record a log of a requested type */
6440 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
6441
6442 struct ec_params_pd_write_log_entry {
6443 uint8_t type; /* event type : see PD_EVENT_xx above */
6444 uint8_t port; /* port#, or 0 for events unrelated to a given port */
6445 } __ec_align1;
6446
6447 /* Control USB-PD chip */
6448 #define EC_CMD_PD_CONTROL 0x0119
6449
6450 enum ec_pd_control_cmd {
6451 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6452 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6453 PD_RESET, /* Force reset the PD chip */
6454 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6455 PD_CHIP_ON, /* Power on the PD chip */
6456 };
6457
6458 struct ec_params_pd_control {
6459 uint8_t chip; /* chip id */
6460 uint8_t subcmd;
6461 } __ec_align1;
6462
6463 /* Get info about USB-C SS muxes */
6464 #define EC_CMD_USB_PD_MUX_INFO 0x011A
6465
6466 struct ec_params_usb_pd_mux_info {
6467 uint8_t port; /* USB-C port number */
6468 } __ec_align1;
6469
6470 /* Flags representing mux state */
6471 #define USB_PD_MUX_NONE 0 /* Open switch */
6472 #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6473 #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6474 #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6475 #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6476 #define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6477 #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6478 #define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6479 #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
6480 #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
6481 #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
6482
6483 /* USB-C Dock connected */
6484 #define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
6485
6486 struct ec_response_usb_pd_mux_info {
6487 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
6488 } __ec_align1;
6489
6490 #define EC_CMD_PD_CHIP_INFO 0x011B
6491
6492 struct ec_params_pd_chip_info {
6493 uint8_t port; /* USB-C port number */
6494 /*
6495 * Fetch the live chip info or hard-coded + cached chip info
6496 * 0: hardcoded value for VID/PID, cached value for FW version
6497 * 1: live chip value for VID/PID/FW Version
6498 */
6499 uint8_t live;
6500 } __ec_align1;
6501
6502 struct ec_response_pd_chip_info {
6503 uint16_t vendor_id;
6504 uint16_t product_id;
6505 uint16_t device_id;
6506 union {
6507 uint8_t fw_version_string[8];
6508 uint64_t fw_version_number;
6509 } __ec_align2;
6510 } __ec_align2;
6511
6512 struct ec_response_pd_chip_info_v1 {
6513 uint16_t vendor_id;
6514 uint16_t product_id;
6515 uint16_t device_id;
6516 union {
6517 uint8_t fw_version_string[8];
6518 uint64_t fw_version_number;
6519 } __ec_align2;
6520 union {
6521 uint8_t min_req_fw_version_string[8];
6522 uint64_t min_req_fw_version_number;
6523 } __ec_align2;
6524 } __ec_align2;
6525
6526 /** Indicates the chip should NOT receive a firmware update, if set. This is
6527 * useful when multiple ports are serviced by a single chip, to avoid
6528 * performing redundant updates. The host command implementation shall ensure
6529 * only one port out of each physical chip has FW updates active.
6530 */
6531 #define USB_PD_CHIP_INFO_FWUP_FLAG_NO_UPDATE BIT(0)
6532
6533 /** Maximum length of a project name embedded in a PDC FW image. This length
6534 * does NOT include a NUL-terminator.
6535 */
6536 #define USB_PD_CHIP_INFO_PROJECT_NAME_LEN 12
6537
6538 struct ec_response_pd_chip_info_v2 {
6539 uint16_t vendor_id;
6540 uint16_t product_id;
6541 uint16_t device_id;
6542 union {
6543 uint8_t fw_version_string[8];
6544 uint64_t fw_version_number;
6545 } __ec_align2;
6546 union {
6547 uint8_t min_req_fw_version_string[8];
6548 uint64_t min_req_fw_version_number;
6549 } __ec_align2;
6550 /** Flag to control the FW update process for this chip. */
6551 uint16_t fw_update_flags;
6552 /** Project name string associated with the chip's FW. Add an extra
6553 * byte for a NUL-terminator.
6554 */
6555 char fw_name_str[USB_PD_CHIP_INFO_PROJECT_NAME_LEN + 1];
6556 } __ec_align2;
6557
6558 /** Maximum length of a driver/chip name reported in the pd_chip_info
6559 * response
6560 */
6561 #define USB_PD_CHIP_INFO_DRIVER_NAME_LEN 24
6562
6563 struct ec_response_pd_chip_info_v3 {
6564 uint16_t vendor_id;
6565 uint16_t product_id;
6566 uint16_t device_id;
6567 union {
6568 uint8_t fw_version_string[8];
6569 uint64_t fw_version_number;
6570 } __ec_align2;
6571 union {
6572 uint8_t min_req_fw_version_string[8];
6573 uint64_t min_req_fw_version_number;
6574 } __ec_align2;
6575 /** Flag to control the FW update process for this chip. */
6576 uint16_t fw_update_flags;
6577 /** Project name string associated with the chip's FW. Add an extra
6578 * byte for a NUL-terminator.
6579 */
6580 char fw_name_str[USB_PD_CHIP_INFO_PROJECT_NAME_LEN + 1];
6581 /** Driver/chip string, plus room for a NUL-terminator */
6582 char driver_name[USB_PD_CHIP_INFO_DRIVER_NAME_LEN + 1];
6583 } __ec_align2;
6584
6585 /* Run RW signature verification and get status */
6586 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
6587
6588 struct ec_response_rwsig_check_status {
6589 uint32_t status;
6590 } __ec_align4;
6591
6592 /* For controlling RWSIG task */
6593 #define EC_CMD_RWSIG_ACTION 0x011D
6594
6595 enum rwsig_action {
6596 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6597 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
6598 };
6599
6600 struct ec_params_rwsig_action {
6601 uint32_t action;
6602 } __ec_align4;
6603
6604 /* Run verification on a slot */
6605 #define EC_CMD_EFS_VERIFY 0x011E
6606
6607 struct ec_params_efs_verify {
6608 uint8_t region; /* enum ec_flash_region */
6609 } __ec_align1;
6610
6611 /*
6612 * Retrieve info from Cros Board Info store. Response is based on the data
6613 * type. Integers return a uint32. Strings return a string, using the response
6614 * size to determine how big it is.
6615 */
6616 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
6617 /*
6618 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6619 * hardware write-protect enabled.
6620 */
6621 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
6622
6623 enum cbi_data_tag {
6624 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
6625 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6626 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
6627 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
6628 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6629 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6630 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6631 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
6632 /* Second Source Factory Cache */
6633 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6634 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
6635 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* Deprecated */
6636 CBI_TAG_COMMON_CONTROL = 11, /* Deprecated */
6637 /* struct board_batt_params */
6638 CBI_TAG_BATTERY_CONFIG = 12,
6639 /* CBI_TAG_BATTERY_CONFIG_1 ~ 15 will use 13 ~ 27. */
6640 CBI_TAG_BATTERY_CONFIG_15 = 27,
6641
6642 /* CBI_TAG_PROVISION_MATRIX_VERSION
6643 * Version of the current provision matrix
6644 */
6645 CBI_TAG_PROVISION_MATRIX_VERSION = 28, /* uint32_t bit field */
6646
6647 /* Last entry */
6648 CBI_TAG_COUNT,
6649 };
6650
6651 /*
6652 * Flags to control read operation
6653 *
6654 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6655 * write was successful without reboot.
6656 */
6657 #define CBI_GET_RELOAD BIT(0)
6658
6659 struct ec_params_get_cbi {
6660 uint32_t tag; /* enum cbi_data_tag */
6661 uint32_t flag; /* CBI_GET_* */
6662 } __ec_align4;
6663
6664 /*
6665 * Flags to control write behavior.
6666 *
6667 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6668 * useful when writing multiple fields in a row.
6669 * INIT: Need to be set when creating a new CBI from scratch. All fields
6670 * will be initialized to zero first.
6671 */
6672 #define CBI_SET_NO_SYNC BIT(0)
6673 #define CBI_SET_INIT BIT(1)
6674
6675 struct ec_params_set_cbi {
6676 uint32_t tag; /* enum cbi_data_tag */
6677 uint32_t flag; /* CBI_SET_* */
6678 uint32_t size; /* Data size */
6679 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE]; /* For string and raw data */
6680 } __ec_align1;
6681
6682 /*
6683 * Retrieve binary from CrOS Board Info primary memory source.
6684 */
6685 #define EC_CMD_CBI_BIN_READ 0x0504
6686 /*
6687 * Write binary into CrOS Board Info temporary buffer and then commit it to
6688 * permanent storage once complete. Write fails if the board has hardware
6689 * write-protect enabled.
6690 */
6691 #define EC_CMD_CBI_BIN_WRITE 0x0505
6692
6693 /*
6694 * CBI binary read/write flags
6695 * The default write behavior is to always append any data to the buffer.
6696 * If 'CLEAR' flag is set, buffer is cleared then data is appended.
6697 * If 'WRITE' flag is set, data is appended then buffer is written to memory.
6698 */
6699 #define EC_CBI_BIN_BUFFER_CLEAR BIT(0)
6700 #define EC_CBI_BIN_BUFFER_WRITE BIT(1)
6701
6702 struct ec_params_get_cbi_bin {
6703 uint32_t offset; /* Data offset */
6704 uint32_t size; /* Data size */
6705 } __ec_align4;
6706
6707 struct ec_params_set_cbi_bin {
6708 uint32_t offset; /* Data offset */
6709 uint32_t size; /* Data size */
6710 uint8_t flags; /* bit field for EC_CBI_BIN_COMMIT_FLAG_* */
6711 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE]; /* For string and raw data */
6712 } __ec_align1;
6713
6714 /*
6715 * Information about resets of the AP by the EC and the EC's own uptime.
6716 */
6717 #define EC_CMD_GET_UPTIME_INFO 0x0121
6718
6719 /* EC reset causes */
6720 #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6721 #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6722 #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6723 #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6724 #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6725 #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6726 #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6727 #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6728 #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6729 #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6730 #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6731 #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6732 #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
6733 /* Some reset flags preserved from previous boot */
6734 #define EC_RESET_FLAG_PRESERVED BIT(13)
6735 #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6736 #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6737 #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6738 #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
6739 /* AP experienced a watchdog reset */
6740 #define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6741 /* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6742 #define EC_RESET_FLAG_STAY_IN_RO BIT(19)
6743 #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6744 #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6745 #define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
6746
6747 /*
6748 * Reason codes used by the AP after a shutdown to figure out why it was reset
6749 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6750 * compatibility:
6751 * - New entries must be inserted prior to the _COUNT field
6752 * - If an existing entry is no longer in service, it must be replaced with a
6753 * RESERVED entry instead.
6754 * - The semantic meaning of an entry should not change.
6755 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6756 */
6757 enum chipset_shutdown_reason {
6758 /*
6759 * Beginning of reset reasons.
6760 */
6761 CHIPSET_RESET_BEGIN = 0,
6762 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6763 /* Custom reason defined by a board.c or baseboard.c file */
6764 CHIPSET_RESET_BOARD_CUSTOM,
6765 /* Believe that the AP has hung */
6766 CHIPSET_RESET_HANG_REBOOT,
6767 /* Reset by EC console command */
6768 CHIPSET_RESET_CONSOLE_CMD,
6769 /* Reset by EC host command */
6770 CHIPSET_RESET_HOST_CMD,
6771 /* Keyboard module reset key combination */
6772 CHIPSET_RESET_KB_SYSRESET,
6773 /* Keyboard module warm reboot */
6774 CHIPSET_RESET_KB_WARM_REBOOT,
6775 /* Debug module warm reboot */
6776 CHIPSET_RESET_DBG_WARM_REBOOT,
6777 /* I cannot self-terminate. You must lower me into the steel. */
6778 CHIPSET_RESET_AP_REQ,
6779 /* Reset as side-effect of startup sequence */
6780 CHIPSET_RESET_INIT,
6781 /* EC detected an AP watchdog event. */
6782 CHIPSET_RESET_AP_WATCHDOG,
6783
6784 CHIPSET_RESET_COUNT, /* End of reset reasons. */
6785
6786 /*
6787 * Beginning of shutdown reasons.
6788 */
6789 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6790 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6791 /* Forcing a shutdown as part of EC initialization */
6792 CHIPSET_SHUTDOWN_INIT,
6793 /* Custom reason on a per-board basis. */
6794 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6795 /* This is a reason to inhibit startup, not cause shut down. */
6796 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6797 /* A power_wait_signal is being asserted */
6798 CHIPSET_SHUTDOWN_WAIT,
6799 /* Critical battery level. */
6800 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6801 /* Because you told me to. */
6802 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6803 /* Forcing a shutdown to effect entry to G3. */
6804 CHIPSET_SHUTDOWN_G3,
6805 /* Force shutdown due to over-temperature. */
6806 CHIPSET_SHUTDOWN_THERMAL,
6807 /* Force a chipset shutdown from the power button through EC */
6808 CHIPSET_SHUTDOWN_BUTTON,
6809 /* Force a chipset shutdown, because the AP wants to. */
6810 CHIPSET_SHUTDOWN_HOST_CMD,
6811
6812 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
6813 };
6814
6815 struct ec_response_uptime_info {
6816 /*
6817 * Number of milliseconds since the last EC boot. Sysjump resets
6818 * typically do not restart the EC's time_since_boot epoch.
6819 *
6820 * WARNING: The EC's sense of time is much less accurate than the AP's
6821 * sense of time, in both phase and frequency. This timebase is similar
6822 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6823 */
6824 uint32_t time_since_ec_boot_ms;
6825
6826 /*
6827 * Number of times the AP was reset by the EC since the last EC boot.
6828 * Note that the AP may be held in reset by the EC during the initial
6829 * boot sequence, such that the very first AP boot may count as more
6830 * than one here.
6831 */
6832 uint32_t ap_resets_since_ec_boot;
6833
6834 /*
6835 * The set of flags which describe the EC's most recent reset.
6836 * See EC_RESET_FLAG_* for details.
6837 */
6838 uint32_t ec_reset_flags;
6839
6840 /* Empty log entries have both the cause and timestamp set to zero. */
6841 struct ap_reset_log_entry {
6842 /* See enum chipset_{reset,shutdown}_reason for details. */
6843 uint16_t reset_cause;
6844
6845 /* Reserved for protocol growth. */
6846 uint16_t reserved;
6847
6848 /*
6849 * The time of the reset's assertion, in milliseconds since the
6850 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6851 * Set to zero if the log entry is empty.
6852 */
6853 uint32_t reset_time_ms;
6854 } recent_ap_reset[4];
6855 } __ec_align4;
6856
6857 /*
6858 * Add entropy to the device secret (stored in the rollback region).
6859 *
6860 * Depending on the chip, the operation may take a long time (e.g. to erase
6861 * flash), so the commands are asynchronous.
6862 */
6863 #define EC_CMD_ADD_ENTROPY 0x0122
6864
6865 enum add_entropy_action {
6866 /* Add entropy to the current secret. */
6867 ADD_ENTROPY_ASYNC = 0,
6868 /*
6869 * Add entropy, and also make sure that the previous secret is erased.
6870 * (this can be implemented by adding entropy multiple times until
6871 * all rolback blocks have been overwritten).
6872 */
6873 ADD_ENTROPY_RESET_ASYNC = 1,
6874 /* Read back result from the previous operation. */
6875 ADD_ENTROPY_GET_RESULT = 2,
6876 };
6877
6878 struct ec_params_rollback_add_entropy {
6879 uint8_t action;
6880 } __ec_align1;
6881
6882 /*
6883 * Perform a single read of a given ADC channel.
6884 */
6885 #define EC_CMD_ADC_READ 0x0123
6886
6887 struct ec_params_adc_read {
6888 uint8_t adc_channel;
6889 } __ec_align1;
6890
6891 struct ec_response_adc_read {
6892 int32_t adc_value;
6893 } __ec_align4;
6894
6895 /*
6896 * Read back rollback info
6897 */
6898 #define EC_CMD_ROLLBACK_INFO 0x0124
6899
6900 struct ec_response_rollback_info {
6901 int32_t id; /* Incrementing number to indicate which region to use. */
6902 int32_t rollback_min_version;
6903 int32_t rw_rollback_version;
6904 } __ec_align4;
6905
6906 /* Issue AP reset */
6907 #define EC_CMD_AP_RESET 0x0125
6908
6909 /*****************************************************************************/
6910 /* Locate peripheral chips
6911 *
6912 * Return values:
6913 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6914 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6915 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6916 */
6917 #define EC_CMD_LOCATE_CHIP 0x0126
6918
6919 enum ec_chip_type {
6920 EC_CHIP_TYPE_CBI_EEPROM = 0,
6921 EC_CHIP_TYPE_TCPC = 1,
6922 EC_CHIP_TYPE_PDC = 2,
6923 EC_CHIP_TYPE_COUNT,
6924 EC_CHIP_TYPE_MAX = 0xFF,
6925 };
6926
6927 enum ec_bus_type {
6928 EC_BUS_TYPE_I2C = 0,
6929 EC_BUS_TYPE_EMBEDDED = 1,
6930 EC_BUS_TYPE_COUNT,
6931 EC_BUS_TYPE_MAX = 0xFF,
6932 };
6933
6934 struct ec_i2c_info {
6935 uint16_t port; /* Physical port for device */
6936 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
6937 };
6938
6939 struct ec_params_locate_chip {
6940 uint8_t type; /* enum ec_chip_type */
6941 uint8_t index; /* Specifies one instance of chip type */
6942 /* Used for type specific parameters in future */
6943 union {
6944 uint16_t reserved;
6945 };
6946 } __ec_align2;
6947
6948 struct ec_response_locate_chip {
6949 uint8_t bus_type; /* enum ec_bus_type */
6950 uint8_t reserved; /* Aligning the following union to 2 bytes */
6951 union {
6952 struct ec_i2c_info i2c_info;
6953 };
6954 } __ec_align2;
6955
6956 /*
6957 * Reboot AP on G3
6958 *
6959 * This command is used for validation purpose, where the AP needs to be
6960 * returned back to S0 state from G3 state without using the servo to trigger
6961 * wake events.
6962 * - With command version 0:
6963 * AP reboots immediately from G3
6964 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6965 * - With command version 1:
6966 * AP reboots after the user specified delay
6967 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
6968 */
6969 #define EC_CMD_REBOOT_AP_ON_G3 0x0127
6970
6971 struct ec_params_reboot_ap_on_g3_v1 {
6972 /* configurable delay in seconds in G3 state */
6973 uint32_t reboot_ap_at_g3_delay;
6974 } __ec_align4;
6975
6976 /*****************************************************************************/
6977 /* Get PD port capabilities
6978 *
6979 * Returns the following static *capabilities* of the given port:
6980 * 1) Power role: source, sink, or dual. It is not anticipated that
6981 * future CrOS devices would ever be only a source, so the options are
6982 * sink or dual.
6983 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6984 * believe any CrOS device would support Try.SNK, so this would be source
6985 * or none).
6986 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6987 * for CrOS devices.
6988 */
6989 #define EC_CMD_GET_PD_PORT_CAPS 0x0128
6990
6991 enum ec_pd_power_role_caps {
6992 EC_PD_POWER_ROLE_SOURCE = 0,
6993 EC_PD_POWER_ROLE_SINK = 1,
6994 EC_PD_POWER_ROLE_DUAL = 2,
6995 };
6996
6997 enum ec_pd_try_power_role_caps {
6998 EC_PD_TRY_POWER_ROLE_NONE = 0,
6999 EC_PD_TRY_POWER_ROLE_SINK = 1,
7000 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
7001 };
7002
7003 enum ec_pd_data_role_caps {
7004 EC_PD_DATA_ROLE_DFP = 0,
7005 EC_PD_DATA_ROLE_UFP = 1,
7006 EC_PD_DATA_ROLE_DUAL = 2,
7007 };
7008
7009 /* From: power_manager/power_supply_properties.proto */
7010 enum ec_pd_port_location {
7011 /* The location of the port is unknown, or there's only one port. */
7012 EC_PD_PORT_LOCATION_UNKNOWN = 0,
7013
7014 /*
7015 * Various positions on the device. The first word describes the side of
7016 * the device where the port is located while the second clarifies the
7017 * position. For example, LEFT_BACK means the farthest-back port on the
7018 * left side, while BACK_LEFT means the leftmost port on the back of the
7019 * device.
7020 */
7021 EC_PD_PORT_LOCATION_LEFT = 1,
7022 EC_PD_PORT_LOCATION_RIGHT = 2,
7023 EC_PD_PORT_LOCATION_BACK = 3,
7024 EC_PD_PORT_LOCATION_FRONT = 4,
7025 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
7026 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
7027 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
7028 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
7029 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
7030 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
7031 };
7032
7033 struct ec_params_get_pd_port_caps {
7034 uint8_t port; /* Which port to interrogate */
7035 } __ec_align1;
7036
7037 struct ec_response_get_pd_port_caps {
7038 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
7039 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
7040 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
7041 uint8_t pd_port_location; /* enum ec_pd_port_location */
7042 } __ec_align1;
7043
7044 /*****************************************************************************/
7045 /*
7046 * Button press simulation
7047 *
7048 * This command is used to simulate a button press.
7049 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
7050 * Time duration for which button needs to be pressed is an optional parameter.
7051 *
7052 * NOTE: This is only available on unlocked devices for testing purposes only.
7053 */
7054 #define EC_CMD_BUTTON 0x0129
7055
7056 struct ec_params_button {
7057 /* Button mask aligned to enum keyboard_button_type */
7058 uint32_t btn_mask;
7059
7060 /* Duration in milliseconds button needs to be pressed */
7061 uint32_t press_ms;
7062 } __ec_align1;
7063
7064 enum keyboard_button_type {
7065 KEYBOARD_BUTTON_POWER = 0,
7066 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
7067 KEYBOARD_BUTTON_VOLUME_UP = 2,
7068 KEYBOARD_BUTTON_RECOVERY = 3,
7069 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
7070 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
7071 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
7072 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
7073 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
7074 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
7075 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
7076 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
7077
7078 KEYBOARD_BUTTON_COUNT,
7079 };
7080
7081 /*****************************************************************************/
7082 /*
7083 * "Get the Keyboard Config". An EC implementing this command is expected to be
7084 * vivaldi capable, i.e. can send action codes for the top row keys.
7085 * Additionally, capability to send function codes for the same keys is
7086 * optional and acceptable.
7087 *
7088 * Note: If the top row can generate both function and action codes by
7089 * using a dedicated Fn key, it does not matter whether the key sends
7090 * "function" or "action" codes by default. In both cases, the response
7091 * for this command will look the same.
7092 */
7093 #define EC_CMD_GET_KEYBD_CONFIG 0x012A
7094
7095 /* Possible values for the top row keys */
7096 enum action_key {
7097 TK_ABSENT = 0,
7098 TK_BACK = 1,
7099 TK_FORWARD = 2,
7100 TK_REFRESH = 3,
7101 TK_FULLSCREEN = 4,
7102 TK_OVERVIEW = 5,
7103 TK_BRIGHTNESS_DOWN = 6,
7104 TK_BRIGHTNESS_UP = 7,
7105 TK_VOL_MUTE = 8,
7106 TK_VOL_DOWN = 9,
7107 TK_VOL_UP = 10,
7108 TK_SNAPSHOT = 11,
7109 TK_PRIVACY_SCRN_TOGGLE = 12,
7110 TK_KBD_BKLIGHT_DOWN = 13,
7111 TK_KBD_BKLIGHT_UP = 14,
7112 TK_PLAY_PAUSE = 15,
7113 TK_NEXT_TRACK = 16,
7114 TK_PREV_TRACK = 17,
7115 TK_KBD_BKLIGHT_TOGGLE = 18,
7116 TK_MICMUTE = 19,
7117 TK_MENU = 20,
7118 TK_DICTATE = 21,
7119 TK_ACCESSIBILITY = 22,
7120 TK_DONOTDISTURB = 23,
7121
7122 TK_COUNT
7123 };
7124
7125 /*
7126 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
7127 * If this needs to change, please create a new version of the command.
7128 */
7129 #define MAX_TOP_ROW_KEYS 15
7130 #define MIN_TOP_ROW_KEYS 10
7131
7132 /*
7133 * Is the keyboard capable of sending function keys *in addition to*
7134 * action keys. This is possible for e.g. if the keyboard has a
7135 * dedicated Fn key.
7136 */
7137 #define KEYBD_CAP_FUNCTION_KEYS BIT(0)
7138 /*
7139 * Whether the keyboard has a dedicated numeric keyboard.
7140 */
7141 #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
7142 /*
7143 * Whether the keyboard has a screenlock key.
7144 */
7145 #define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
7146
7147 /*
7148 * Whether the keyboard has an assistant key.
7149 */
7150 #define KEYBD_CAP_ASSISTANT_KEY BIT(3)
7151
7152 struct ec_response_keybd_config {
7153 /*
7154 * Number of top row keys, excluding Esc and Screenlock.
7155 * If this is 0, all Vivaldi keyboard code is disabled.
7156 * (i.e. does not expose any tables to the kernel).
7157 */
7158 uint8_t num_top_row_keys;
7159
7160 /*
7161 * The action keys in the top row, in order from left to right.
7162 * The values are filled from enum action_key. Esc and Screenlock
7163 * keys are not considered part of top row keys.
7164 */
7165 uint8_t action_keys[MAX_TOP_ROW_KEYS];
7166
7167 /* Capability flags */
7168 uint8_t capabilities;
7169
7170 } __ec_align1;
7171
7172 /*
7173 * Configure smart discharge
7174 */
7175 #define EC_CMD_SMART_DISCHARGE 0x012B
7176
7177 #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
7178
7179 /* Discharge rates when the system is in cutoff or hibernation. */
7180 struct discharge_rate {
7181 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
7182 uint16_t hibern; /* Discharge rate (uA) in hibernation */
7183 };
7184
7185 struct smart_discharge_zone {
7186 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
7187 int cutoff;
7188 /* When the capacity (mAh) is below this, EC stays up. */
7189 int stayup;
7190 };
7191
7192 struct ec_params_smart_discharge {
7193 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
7194 /*
7195 * Desired hours for the battery to survive before reaching 0%. Set to
7196 * zero to disable smart discharging. That is, the system hibernates as
7197 * soon as the G3 idle timer expires.
7198 */
7199 uint16_t hours_to_zero;
7200 /* Set both to zero to keep the current rates. */
7201 struct discharge_rate drate;
7202 };
7203
7204 struct ec_response_smart_discharge {
7205 uint16_t hours_to_zero;
7206 struct discharge_rate drate;
7207 struct smart_discharge_zone dzone;
7208 };
7209
7210 /*****************************************************************************/
7211 /* Voltage regulator controls */
7212
7213 /*
7214 * Get basic info of voltage regulator for given index.
7215 *
7216 * Returns the regulator name and supported voltage list in mV.
7217 */
7218 #define EC_CMD_REGULATOR_GET_INFO 0x012C
7219
7220 /* Maximum length of regulator name */
7221 #define EC_REGULATOR_NAME_MAX_LEN 16
7222
7223 /* Maximum length of the supported voltage list. */
7224 #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
7225
7226 struct ec_params_regulator_get_info {
7227 uint32_t index;
7228 } __ec_align4;
7229
7230 struct ec_response_regulator_get_info {
7231 char name[EC_REGULATOR_NAME_MAX_LEN];
7232 uint16_t num_voltages;
7233 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
7234 } __ec_align2;
7235
7236 /*
7237 * Configure the regulator as enabled / disabled.
7238 */
7239 #define EC_CMD_REGULATOR_ENABLE 0x012D
7240
7241 struct ec_params_regulator_enable {
7242 uint32_t index;
7243 uint8_t enable;
7244 } __ec_align4;
7245
7246 /*
7247 * Query if the regulator is enabled.
7248 *
7249 * Returns 1 if the regulator is enabled, 0 if not.
7250 */
7251 #define EC_CMD_REGULATOR_IS_ENABLED 0x012E
7252
7253 struct ec_params_regulator_is_enabled {
7254 uint32_t index;
7255 } __ec_align4;
7256
7257 struct ec_response_regulator_is_enabled {
7258 uint8_t enabled;
7259 } __ec_align1;
7260
7261 /*
7262 * Set voltage for the voltage regulator within the range specified.
7263 *
7264 * The driver should select the voltage in range closest to min_mv.
7265 *
7266 * Also note that this might be called before the regulator is enabled, and the
7267 * setting should be in effect after the regulator is enabled.
7268 */
7269 #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
7270
7271 struct ec_params_regulator_set_voltage {
7272 uint32_t index;
7273 uint32_t min_mv;
7274 uint32_t max_mv;
7275 } __ec_align4;
7276
7277 /*
7278 * Get the currently configured voltage for the voltage regulator.
7279 *
7280 * Note that this might be called before the regulator is enabled, and this
7281 * should return the configured output voltage if the regulator is enabled.
7282 */
7283 #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
7284
7285 struct ec_params_regulator_get_voltage {
7286 uint32_t index;
7287 } __ec_align4;
7288
7289 struct ec_response_regulator_get_voltage {
7290 uint32_t voltage_mv;
7291 } __ec_align4;
7292
7293 /*
7294 * Gather all discovery information for the given port and partner type.
7295 *
7296 * Note that if discovery has not yet completed, only the currently completed
7297 * responses will be filled in. If the discovery data structures are changed
7298 * in the process of the command running, BUSY will be returned.
7299 *
7300 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
7301 * contain, while the number of SVIDs here is selected to fit within the PROTO2
7302 * maximum parameter size.
7303 */
7304 #define EC_CMD_TYPEC_DISCOVERY 0x0131
7305
7306 enum typec_partner_type {
7307 TYPEC_PARTNER_SOP = 0,
7308 TYPEC_PARTNER_SOP_PRIME = 1,
7309 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
7310 };
7311
7312 struct ec_params_typec_discovery {
7313 uint8_t port;
7314 uint8_t partner_type; /* enum typec_partner_type */
7315 } __ec_align1;
7316
7317 struct svid_mode_info {
7318 uint16_t svid;
7319 uint16_t mode_count; /* Number of modes partner sent */
7320 uint32_t mode_vdo[VDO_MAX_OBJECTS];
7321 };
7322
7323 struct ec_response_typec_discovery {
7324 uint8_t identity_count; /* Number of identity VDOs partner sent */
7325 uint8_t svid_count; /* Number of SVIDs partner sent */
7326 uint16_t reserved;
7327 uint32_t discovery_vdo[VDO_MAX_OBJECTS];
7328 struct svid_mode_info svids[FLEXIBLE_ARRAY_MEMBER_SIZE];
7329 } __ec_align1;
7330
7331 /* USB Type-C commands for AP-controlled device policy. */
7332 #define EC_CMD_TYPEC_CONTROL 0x0132
7333
7334 enum typec_control_command {
7335 TYPEC_CONTROL_COMMAND_EXIT_MODES,
7336 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
7337 TYPEC_CONTROL_COMMAND_ENTER_MODE,
7338 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
7339 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
7340 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
7341 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
7342 };
7343
7344 /* Modes (USB or alternate) that a type-C port may enter. */
7345 enum typec_mode {
7346 TYPEC_MODE_DP,
7347 TYPEC_MODE_TBT,
7348 TYPEC_MODE_USB4,
7349 };
7350
7351 /* Replies the AP may specify to the TBT EnterMode command as a UFP */
7352 enum typec_tbt_ufp_reply {
7353 TYPEC_TBT_UFP_REPLY_NAK,
7354 TYPEC_TBT_UFP_REPLY_ACK,
7355 };
7356
7357 #define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
7358
7359 struct typec_usb_mux_set {
7360 /* Index of the mux to set in the chain */
7361 uint8_t mux_index;
7362
7363 /* USB_PD_MUX_*-encoded USB mux state to set */
7364 uint8_t mux_flags;
7365 } __ec_align1;
7366
7367 struct typec_vdm_req {
7368 /* VDM data, including VDM header */
7369 uint32_t vdm_data[VDO_MAX_SIZE];
7370 /* Number of 32-bit fields filled in */
7371 uint8_t vdm_data_objects;
7372 /* Partner to address - see enum typec_partner_type */
7373 uint8_t partner_type;
7374 } __ec_align1;
7375
7376 struct ec_params_typec_control {
7377 uint8_t port;
7378 uint8_t command; /* enum typec_control_command */
7379 uint16_t reserved;
7380
7381 /*
7382 * This section will be interpreted based on |command|. Define a
7383 * placeholder structure to avoid having to increase the size and bump
7384 * the command version when adding new sub-commands.
7385 */
7386 union {
7387 /* Used for CLEAR_EVENTS */
7388 uint32_t clear_events_mask;
7389 /* Used for ENTER_MODE - enum typec_mode */
7390 uint8_t mode_to_enter;
7391 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
7392 uint8_t tbt_ufp_reply;
7393 /* Used for USB_MUX_SET */
7394 struct typec_usb_mux_set mux_params;
7395 /* Used for BIST_SHARE_MODE */
7396 uint8_t bist_share_mode;
7397 /* Used for VMD_REQ */
7398 struct typec_vdm_req vdm_req_params;
7399 uint8_t placeholder[128];
7400 };
7401 } __ec_align1;
7402
7403 /*
7404 * Gather all status information for a port.
7405 *
7406 * Note: this covers many of the return fields from the deprecated
7407 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
7408 * discovery data. The "enum pd_cc_states" is defined with the deprecated
7409 * EC_CMD_USB_PD_CONTROL command.
7410 *
7411 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
7412 */
7413 #define EC_CMD_TYPEC_STATUS 0x0133
7414
7415 /*
7416 * Power role.
7417 *
7418 * Note this is also used for PD header creation, and values align to those in
7419 * the Power Delivery Specification Revision 3.0 (See
7420 * 6.2.1.1.4 Port Power Role).
7421 */
7422 enum pd_power_role {
7423 PD_ROLE_SINK = 0,
7424 PD_ROLE_SOURCE = 1,
7425 };
7426
7427 /*
7428 * Data role.
7429 *
7430 * Note this is also used for PD header creation, and the first two values
7431 * align to those in the Power Delivery Specification Revision 3.0 (See
7432 * 6.2.1.1.6 Port Data Role).
7433 */
7434 enum pd_data_role {
7435 PD_ROLE_UFP = 0,
7436 PD_ROLE_DFP = 1,
7437 PD_ROLE_DISCONNECTED = 2,
7438 };
7439
7440 enum pd_vconn_role {
7441 PD_ROLE_VCONN_OFF = 0,
7442 PD_ROLE_VCONN_SRC = 1,
7443 };
7444
7445 /*
7446 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
7447 * regardless of whether a debug accessory is connected.
7448 */
7449 enum tcpc_cc_polarity {
7450 /*
7451 * _CCx: is used to indicate the polarity while not connected to
7452 * a Debug Accessory. Only one CC line will assert a resistor and
7453 * the other will be open.
7454 */
7455 POLARITY_CC1 = 0,
7456 POLARITY_CC2 = 1,
7457
7458 /*
7459 * _CCx_DTS is used to indicate the polarity while connected to a
7460 * SRC Debug Accessory. Assert resistors on both lines.
7461 */
7462 POLARITY_CC1_DTS = 2,
7463 POLARITY_CC2_DTS = 3,
7464
7465 /*
7466 * The current TCPC code relies on these specific POLARITY values.
7467 * Adding in a check to verify if the list grows for any reason
7468 * that this will give a hint that other places need to be
7469 * adjusted.
7470 */
7471 POLARITY_COUNT,
7472 };
7473
7474 #define MODE_DP_PIN_A BIT(0)
7475 #define MODE_DP_PIN_B BIT(1)
7476 #define MODE_DP_PIN_C BIT(2)
7477 #define MODE_DP_PIN_D BIT(3)
7478 #define MODE_DP_PIN_E BIT(4)
7479 #define MODE_DP_PIN_F BIT(5)
7480 #define MODE_DP_PIN_ALL GENMASK(5, 0)
7481
7482 #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
7483 #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
7484 #define PD_STATUS_EVENT_HARD_RESET BIT(2)
7485 #define PD_STATUS_EVENT_DISCONNECTED BIT(3)
7486 #define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
7487 #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
7488 #define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
7489 #define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
7490 #define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
7491 #define PD_STATUS_EVENT_COUNT 9
7492
7493 /*
7494 * Encode and decode for BCD revision response
7495 *
7496 * Note: the major revision set is written assuming that the value given is the
7497 * Specification Revision from the PD header, which currently only maps to PD
7498 * 1.0-3.0 with the major revision being one greater than the binary value.
7499 */
7500 #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
7501 #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
7502 #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
7503
7504 /*
7505 * Encode revision from partner RMDO
7506 *
7507 * Unlike the specification revision given in the PD header, specification and
7508 * version information returned in the revision message data object (RMDO) is
7509 * not offset.
7510 */
7511 #define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
7512 #define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
7513 #define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
7514 #define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
7515
7516 /*
7517 * Decode helpers for Source and Sink Capability PDOs
7518 *
7519 * Note: The Power Delivery Specification should be considered the ultimate
7520 * source of truth on the decoding of these PDOs
7521 */
7522 #define PDO_TYPE_FIXED (0 << 30)
7523 #define PDO_TYPE_BATTERY (1 << 30)
7524 #define PDO_TYPE_VARIABLE (2 << 30)
7525 #define PDO_TYPE_AUGMENTED (3 << 30)
7526 #define PDO_TYPE_MASK (3 << 30)
7527
7528 /*
7529 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
7530 *
7531 * <31:30> : Fixed Supply
7532 * <29> : Dual-Role Power
7533 * <28> : SNK/SRC dependent
7534 * <27> : Unconstrained Power
7535 * <26> : USB Communications Capable
7536 * <25> : Dual-Role Data
7537 * <24:20> : SNK/SRC dependent
7538 * <19:10> : Voltage in 50mV Units
7539 * <9:0> : Maximum Current in 10mA units
7540 */
7541 #define PDO_FIXED_DUAL_ROLE BIT(29)
7542 #define PDO_FIXED_UNCONSTRAINED BIT(27)
7543 #define PDO_FIXED_COMM_CAP BIT(26)
7544 #define PDO_FIXED_DATA_SWAP BIT(25)
7545 #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
7546 #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7547 #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
7548
7549 /*
7550 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7551 *
7552 * <31:30> : Battery
7553 * <29:20> : Maximum Voltage in 50mV units
7554 * <19:10> : Minimum Voltage in 50mV units
7555 * <9:0> : Maximum Allowable Power in 250mW units
7556 */
7557 #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7558 #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7559 #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
7560
7561 /*
7562 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7563 *
7564 * <31:30> : Variable Supply (non-Battery)
7565 * <29:20> : Maximum Voltage in 50mV units
7566 * <19:10> : Minimum Voltage in 50mV units
7567 * <9:0> : Operational Current in 10mA units
7568 */
7569 #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7570 #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7571 #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
7572
7573 /*
7574 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7575 *
7576 * Note this type is reserved in PD 2.0, and only one type of APDO is
7577 * supported as of the cited version.
7578 *
7579 * <31:30> : Augmented Power Data Object
7580 * <29:28> : Programmable Power Supply
7581 * <27> : PPS Power Limited
7582 * <26:25> : Reserved
7583 * <24:17> : Maximum Voltage in 100mV increments
7584 * <16> : Reserved
7585 * <15:8> : Minimum Voltage in 100mV increments
7586 * <7> : Reserved
7587 * <6:0> : Maximum Current in 50mA increments
7588 */
7589 #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7590 #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7591 #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
7592
7593 struct ec_params_typec_status {
7594 uint8_t port;
7595 } __ec_align1;
7596
7597 /*
7598 * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1.
7599 * If you need to support old ECs who speak only v0, use
7600 * ec_response_typec_status_v0 instead. They're binary-compatible.
7601 */
7602 struct ec_response_typec_status /* DEPRECATED */ {
7603 uint8_t pd_enabled; /* PD communication enabled - bool */
7604 uint8_t dev_connected; /* Device connected - bool */
7605 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7606 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7607
7608 uint8_t power_role; /* enum pd_power_role */
7609 uint8_t data_role; /* enum pd_data_role */
7610 uint8_t vconn_role; /* enum pd_vconn_role */
7611 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7612
7613 uint8_t polarity; /* enum tcpc_cc_polarity */
7614 uint8_t cc_state; /* enum pd_cc_states */
7615 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7616 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7617
7618 char tc_state[32]; /* TC state name */
7619
7620 uint32_t events; /* PD_STATUS_EVENT bitmask */
7621
7622 /*
7623 * BCD PD revisions for partners
7624 *
7625 * The format has the PD major revision in the upper nibble, and the PD
7626 * minor revision in the next nibble. The following two nibbles hold the
7627 * major and minor specification version. If a partner does not support
7628 * the Revision message, only the major revision will be given.
7629 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7630 *
7631 * PD revision/version will be 0 if no PD device is connected.
7632 */
7633 uint16_t sop_revision;
7634 uint16_t sop_prime_revision;
7635
7636 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7637
7638 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7639 } __ec_align1;
7640
7641 struct cros_ec_typec_status {
7642 uint8_t pd_enabled; /* PD communication enabled - bool */
7643 uint8_t dev_connected; /* Device connected - bool */
7644 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7645 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7646
7647 uint8_t power_role; /* enum pd_power_role */
7648 uint8_t data_role; /* enum pd_data_role */
7649 uint8_t vconn_role; /* enum pd_vconn_role */
7650 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7651
7652 uint8_t polarity; /* enum tcpc_cc_polarity */
7653 uint8_t cc_state; /* enum pd_cc_states */
7654 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7655 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7656
7657 char tc_state[32]; /* TC state name */
7658
7659 uint32_t events; /* PD_STATUS_EVENT bitmask */
7660
7661 /*
7662 * BCD PD revisions for partners
7663 *
7664 * The format has the PD major revision in the upper nibble, and the PD
7665 * minor revision in the next nibble. The following two nibbles hold the
7666 * major and minor specification version. If a partner does not support
7667 * the Revision message, only the major revision will be given.
7668 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7669 *
7670 * PD revision/version will be 0 if no PD device is connected.
7671 */
7672 uint16_t sop_revision;
7673 uint16_t sop_prime_revision;
7674 } __ec_align1;
7675
7676 struct ec_response_typec_status_v0 {
7677 struct cros_ec_typec_status typec_status;
7678 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7679 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7680 } __ec_align1;
7681
7682 struct ec_response_typec_status_v1 {
7683 struct cros_ec_typec_status typec_status;
7684 uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */
7685 uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */
7686 } __ec_align1;
7687
7688 /**
7689 * Get the number of peripheral charge ports
7690 */
7691 #define EC_CMD_PCHG_COUNT 0x0134
7692
7693 #define EC_PCHG_MAX_PORTS 8
7694
7695 struct ec_response_pchg_count {
7696 uint8_t port_count;
7697 } __ec_align1;
7698
7699 /**
7700 * Get the status of a peripheral charge port
7701 */
7702 #define EC_CMD_PCHG 0x0135
7703
7704 /* For v1 and v2 */
7705 struct ec_params_pchg {
7706 uint8_t port;
7707 } __ec_align1;
7708
7709 struct ec_params_pchg_v3 {
7710 uint8_t port;
7711 /* Below are new in v3. */
7712 uint8_t reserved1;
7713 uint8_t reserved2;
7714 uint8_t reserved3;
7715 /* Errors acked by the host (thus to be cleared) */
7716 uint32_t error;
7717 } __ec_align1;
7718
7719 /* For v1 */
7720 struct ec_response_pchg {
7721 uint32_t error; /* enum pchg_error */
7722 uint8_t state; /* enum pchg_state state */
7723 uint8_t battery_percentage;
7724 uint8_t unused0;
7725 uint8_t unused1;
7726 /* Fields added in version 1 */
7727 uint32_t fw_version;
7728 uint32_t dropped_event_count;
7729 } __ec_align4;
7730
7731 /* For v2 and v3 */
7732 struct ec_response_pchg_v2 {
7733 uint32_t error; /* enum pchg_error */
7734 uint8_t state; /* enum pchg_state state */
7735 uint8_t battery_percentage;
7736 uint8_t unused0;
7737 uint8_t unused1;
7738 /* Fields added in version 1 */
7739 uint32_t fw_version;
7740 uint32_t dropped_event_count;
7741 /* Fields added in version 2 */
7742 uint32_t dropped_host_event_count;
7743 } __ec_align4;
7744
7745 enum pchg_state {
7746 /* Charger is reset and not initialized. */
7747 PCHG_STATE_RESET = 0,
7748 /* Charger is initialized or disabled. */
7749 PCHG_STATE_INITIALIZED,
7750 /* Charger is enabled and ready to detect a device. */
7751 PCHG_STATE_ENABLED,
7752 /* Device is in proximity. */
7753 PCHG_STATE_DETECTED,
7754 /* Device is being charged. */
7755 PCHG_STATE_CHARGING,
7756 /* Device is fully charged. It implies DETECTED (& not charging). */
7757 PCHG_STATE_FULL,
7758 /* In download (a.k.a. firmware update) mode */
7759 PCHG_STATE_DOWNLOAD,
7760 /* In download mode. Ready for receiving data. */
7761 PCHG_STATE_DOWNLOADING,
7762 /* Device is ready for data communication. */
7763 PCHG_STATE_CONNECTED,
7764 /* Charger is in Built-In Self Test mode. */
7765 PCHG_STATE_BIST,
7766 /* Put no more entry below */
7767 PCHG_STATE_COUNT,
7768 };
7769
7770 /* clang-format off */
7771 #define EC_PCHG_STATE_TEXT \
7772 { \
7773 [PCHG_STATE_RESET] = "RESET", \
7774 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7775 [PCHG_STATE_ENABLED] = "ENABLED", \
7776 [PCHG_STATE_DETECTED] = "DETECTED", \
7777 [PCHG_STATE_CHARGING] = "CHARGING", \
7778 [PCHG_STATE_FULL] = "FULL", \
7779 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7780 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7781 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7782 [PCHG_STATE_BIST] = "BIST", \
7783 }
7784 /* clang-format on */
7785
7786 /**
7787 * Update firmware of peripheral chip
7788 */
7789 #define EC_CMD_PCHG_UPDATE 0x0136
7790
7791 /* Port number is encoded in bit[28:31]. */
7792 #define EC_MKBP_PCHG_PORT_SHIFT 28
7793 /* Utility macros for converting MKBP event <-> port number. */
7794 #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7795 #define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
7796 /* Utility macro for extracting event bits. */
7797 #define EC_MKBP_PCHG_EVENT_MASK(e) \
7798 ((e) & GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
7799
7800 #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7801 #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7802 #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7803 #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7804 #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
7805
7806 enum ec_pchg_update_cmd {
7807 /* Reset chip to normal mode. */
7808 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7809 /* Reset and put a chip in update (a.k.a. download) mode. */
7810 EC_PCHG_UPDATE_CMD_OPEN,
7811 /* Write a block of data containing FW image. */
7812 EC_PCHG_UPDATE_CMD_WRITE,
7813 /* Close update session. */
7814 EC_PCHG_UPDATE_CMD_CLOSE,
7815 /* Reset chip (without mode change). */
7816 EC_PCHG_UPDATE_CMD_RESET,
7817 /* Enable pass-through mode. */
7818 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
7819 /* End of commands */
7820 EC_PCHG_UPDATE_CMD_COUNT,
7821 };
7822
7823 struct ec_params_pchg_update {
7824 /* PCHG port number */
7825 uint8_t port;
7826 /* enum ec_pchg_update_cmd */
7827 uint8_t cmd;
7828 /* Padding */
7829 uint8_t reserved0;
7830 uint8_t reserved1;
7831 /* Version of new firmware */
7832 uint32_t version;
7833 /* CRC32 of new firmware */
7834 uint32_t crc32;
7835 /* Address in chip memory where <data> is written to */
7836 uint32_t addr;
7837 /* Size of <data> */
7838 uint32_t size;
7839 /* Partial data of new firmware */
7840 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE];
7841 } __ec_align4;
7842
7843 BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7844 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
7845
7846 struct ec_response_pchg_update {
7847 /* Block size */
7848 uint32_t block_size;
7849 } __ec_align4;
7850
7851 #define EC_CMD_DISPLAY_SOC 0x0137
7852
7853 struct ec_response_display_soc {
7854 /* Display charge in 10ths of a % (1000=100.0%) */
7855 int16_t display_soc;
7856 /* Full factor in 10ths of a % (1000=100.0%) */
7857 int16_t full_factor;
7858 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7859 int16_t shutdown_soc;
7860 } __ec_align2;
7861
7862 #define EC_CMD_SET_BASE_STATE 0x0138
7863
7864 struct ec_params_set_base_state {
7865 uint8_t cmd; /* enum ec_set_base_state_cmd */
7866 } __ec_align1;
7867
7868 enum ec_set_base_state_cmd {
7869 EC_SET_BASE_STATE_DETACH = 0,
7870 EC_SET_BASE_STATE_ATTACH,
7871 EC_SET_BASE_STATE_RESET,
7872 };
7873
7874 #define EC_CMD_I2C_CONTROL 0x0139
7875
7876 /* Subcommands for I2C control */
7877
7878 enum ec_i2c_control_command {
7879 EC_I2C_CONTROL_GET_SPEED,
7880 EC_I2C_CONTROL_SET_SPEED,
7881 };
7882
7883 #define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7884
7885 struct ec_params_i2c_control {
7886 uint8_t port; /* I2C port number */
7887 uint8_t cmd; /* enum ec_i2c_control_command */
7888 union {
7889 uint16_t speed_khz;
7890 } cmd_params;
7891 } __ec_align_size1;
7892
7893 struct ec_response_i2c_control {
7894 union {
7895 uint16_t speed_khz;
7896 } cmd_response;
7897 } __ec_align_size1;
7898
7899 #define EC_CMD_RGBKBD_SET_COLOR 0x013A
7900 #define EC_CMD_RGBKBD 0x013B
7901
7902 #define EC_RGBKBD_MAX_KEY_COUNT 128
7903 #define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7904 #define EC_RGBKBD_MAX_SCALE 0xFF
7905
7906 enum rgbkbd_state {
7907 /* RGB keyboard is reset and not initialized. */
7908 RGBKBD_STATE_RESET = 0,
7909 /* RGB keyboard is initialized but not enabled. */
7910 RGBKBD_STATE_INITIALIZED,
7911 /* RGB keyboard is disabled. */
7912 RGBKBD_STATE_DISABLED,
7913 /* RGB keyboard is enabled and ready to receive a command. */
7914 RGBKBD_STATE_ENABLED,
7915
7916 /* Put no more entry below */
7917 RGBKBD_STATE_COUNT,
7918 };
7919
7920 enum ec_rgbkbd_subcmd {
7921 EC_RGBKBD_SUBCMD_CLEAR = 1,
7922 EC_RGBKBD_SUBCMD_DEMO = 2,
7923 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
7924 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
7925 EC_RGBKBD_SUBCMD_COUNT
7926 };
7927
7928 enum ec_rgbkbd_demo {
7929 EC_RGBKBD_DEMO_OFF = 0,
7930 EC_RGBKBD_DEMO_FLOW = 1,
7931 EC_RGBKBD_DEMO_DOT = 2,
7932 EC_RGBKBD_DEMO_COUNT,
7933 };
7934
7935 BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7936
7937 enum ec_rgbkbd_type {
7938 EC_RGBKBD_TYPE_UNKNOWN = 0,
7939 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7940 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7941 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7942 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7943 EC_RGBKBD_TYPE_COUNT,
7944 };
7945
7946 struct ec_rgbkbd_set_scale {
7947 uint8_t key;
7948 struct rgb_s scale;
7949 };
7950
7951 struct ec_params_rgbkbd {
7952 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
7953 union {
7954 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7955 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
7956 struct ec_rgbkbd_set_scale set_scale;
7957 };
7958 } __ec_align1;
7959
7960 struct ec_response_rgbkbd {
7961 /*
7962 * RGBKBD type supported by the device.
7963 */
7964
7965 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7966 } __ec_align1;
7967
7968 struct ec_params_rgbkbd_set_color {
7969 /* Specifies the starting key ID whose color is being changed. */
7970 uint8_t start_key;
7971 /* Specifies # of elements in <color>. */
7972 uint8_t length;
7973 /* RGB color data array of length up to MAX_KEY_COUNT. */
7974 struct rgb_s color[FLEXIBLE_ARRAY_MEMBER_SIZE];
7975 } __ec_align1;
7976
7977 /*
7978 * Gather the response to the most recent VDM REQ from the AP, as well
7979 * as popping the oldest VDM:Attention from the DPM queue
7980 */
7981 #define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7982
7983 struct ec_params_typec_vdm_response {
7984 uint8_t port;
7985 } __ec_align1;
7986
7987 struct ec_response_typec_vdm_response {
7988 /* Number of 32-bit fields filled in */
7989 uint8_t vdm_data_objects;
7990 /* Partner to address - see enum typec_partner_type */
7991 uint8_t partner_type;
7992 /* enum ec_status describing VDM response */
7993 uint16_t vdm_response_err;
7994 /* VDM data, including VDM header */
7995 uint32_t vdm_response[VDO_MAX_SIZE];
7996 /* Number of 32-bit Attention fields filled in */
7997 uint8_t vdm_attention_objects;
7998 /* Number of remaining messages to consume */
7999 uint8_t vdm_attention_left;
8000 /* Reserved */
8001 uint16_t reserved1;
8002 /* VDM:Attention contents */
8003 uint32_t vdm_attention[2];
8004 } __ec_align1;
8005
8006 /*
8007 * Get an active battery config from the EC.
8008 */
8009 #define EC_CMD_BATTERY_CONFIG 0x013D
8010
8011 /* Version of struct batt_conf_header and its internals. */
8012 #define EC_BATTERY_CONFIG_STRUCT_VERSION 0x00
8013
8014 /* Number of writes needed to invoke battery cutoff command */
8015 #define SHIP_MODE_WRITES 2
8016
8017 struct ship_mode_info {
8018 uint8_t reg_addr;
8019 uint8_t reserved;
8020 uint16_t reg_data[SHIP_MODE_WRITES];
8021 } __packed __aligned(2);
8022
8023 struct sleep_mode_info {
8024 uint8_t reg_addr;
8025 uint8_t reserved;
8026 uint16_t reg_data;
8027 } __packed __aligned(2);
8028
8029 struct fet_info {
8030 uint8_t reg_addr;
8031 uint8_t reserved;
8032 uint16_t reg_mask;
8033 uint16_t disconnect_val;
8034 uint16_t cfet_mask; /* CHG FET status mask */
8035 uint16_t cfet_off_val;
8036 } __packed __aligned(2);
8037
8038 enum fuel_gauge_flags {
8039 /*
8040 * Write Block Support. If enabled, we use a i2c write block command
8041 * instead of a 16-bit write. The effective difference is the i2c
8042 * transaction will prefix the length (2).
8043 */
8044 FUEL_GAUGE_FLAG_WRITE_BLOCK = BIT(0),
8045 /* Sleep command support. fuel_gauge_info.sleep_mode must be defined. */
8046 FUEL_GAUGE_FLAG_SLEEP_MODE = BIT(1),
8047 /*
8048 * Manufacturer access command support. If enabled, FET status is read
8049 * from the OperationStatus (0x54) register using the
8050 * ManufacturerBlockAccess (0x44).
8051 */
8052 FUEL_GAUGE_FLAG_MFGACC = BIT(2),
8053 /*
8054 * SMB block protocol support in manufacturer access command. If
8055 * enabled, FET status is read from the OperationStatus (0x54) register
8056 * using the ManufacturerBlockAccess (0x44).
8057 */
8058 FUEL_GAUGE_FLAG_MFGACC_SMB_BLOCK = BIT(3),
8059 };
8060
8061 struct fuel_gauge_info {
8062 uint32_t flags;
8063 uint32_t board_flags;
8064 struct ship_mode_info ship_mode;
8065 struct sleep_mode_info sleep_mode;
8066 struct fet_info fet;
8067 } __packed __aligned(4);
8068
8069 /* Battery constants */
8070 struct battery_info {
8071 /* Operation voltage in mV */
8072 uint16_t voltage_max;
8073 uint16_t voltage_normal;
8074 uint16_t voltage_min;
8075 /* (TODO(chromium:756700): add desired_charging_current */
8076 /**
8077 * Pre-charge to fast charge threshold in mV,
8078 * default to voltage_min if not specified.
8079 * This option is only available on isl923x and rt946x.
8080 */
8081 uint16_t precharge_voltage;
8082 /* Pre-charge current in mA */
8083 uint16_t precharge_current;
8084 /* Working temperature ranges in degrees C */
8085 int8_t start_charging_min_c;
8086 int8_t start_charging_max_c;
8087 int8_t charging_min_c;
8088 int8_t charging_max_c;
8089 int8_t discharging_min_c;
8090 int8_t discharging_max_c;
8091 /* Used only if CONFIG_BATTERY_VENDOR_PARAM is defined. */
8092 uint8_t vendor_param_start;
8093 uint8_t reserved;
8094 } __packed __aligned(2);
8095
8096 /*
8097 * The 'config' of a battery.
8098 */
8099 struct board_batt_params {
8100 struct fuel_gauge_info fuel_gauge;
8101 struct battery_info batt_info;
8102 } __packed __aligned(4);
8103
8104 /*
8105 * The SBS defines a string object as a block of chars, 32 byte maximum, where
8106 * the first byte indicates the number of chars in the block (excluding the
8107 * first byte).
8108 *
8109 * Thus, the actual string length (i.e. the value strlen returns) is limited to
8110 * 31 (=SBS_MAX_STR_SIZE).
8111 *
8112 * SBS_MAX_STR_OBJ_SIZE can be used as the size of a buffer for an SBS string
8113 * object but also as a buffer for a c-lang string because the null terminating
8114 * char also takes one byte.
8115 */
8116 #define SBS_MAX_STR_SIZE 31
8117 #define SBS_MAX_STR_OBJ_SIZE (SBS_MAX_STR_SIZE + 1)
8118
8119 /*
8120 * Header describing a battery config stored in CBI. Only struct_version has
8121 * size and position independent of struct_version. The rest varies as
8122 * struct_version changes.
8123 *
8124 * Version 0
8125 * Layout:
8126 * +-------------+
8127 * | header |
8128 * +-------------+
8129 * | | ^
8130 * | manuf_name | | manuf_name_size
8131 * | | v
8132 * +-------------+
8133 * | device_name | ^
8134 * | | | device_name_size
8135 * | | v
8136 * +-------------+
8137 * | config | ^
8138 * | | |
8139 * | | | cbi data size
8140 * | | | - (header_size+manuf_name_size+device_name_size)
8141 * | | |
8142 * | | v
8143 * +-------------+
8144 * Note:
8145 * - manuf_name and device_name are not null-terminated.
8146 * - The config isn't aligned. It should be copied to struct board_batt_params
8147 * before its contents are accessed.
8148 */
8149 struct batt_conf_header {
8150 /* Version independent field. It's always here as a uint8_t. */
8151 uint8_t struct_version;
8152 /* Version 0 members */
8153 uint8_t manuf_name_size;
8154 uint8_t device_name_size;
8155 uint8_t reserved;
8156 /* manuf_name, device_name, board_batt_params follow after this. */
8157 } __packed;
8158
8159 #define BATT_CONF_MAX_SIZE \
8160 (sizeof(struct batt_conf_header) + SBS_MAX_STR_OBJ_SIZE * 2 + \
8161 sizeof(struct board_batt_params))
8162
8163 /*
8164 * Record the current AP firmware state. This is used to help testing, such as
8165 * with FAFT (Fully-Automated Firmware Test), which likes to know which firmware
8166 * screen is currently displayed.
8167 */
8168
8169 #define EC_CMD_AP_FW_STATE 0x013E
8170
8171 struct ec_params_ap_fw_state {
8172 /*
8173 * Value which indicates the state. This is not decoded by the EC, so
8174 * its meaning is entirely outside this code base.
8175 */
8176 uint32_t state;
8177 } __ec_align1;
8178
8179 /*
8180 * UCSI OPM-PPM commands
8181 *
8182 * These commands are used for communication between OPM and PPM.
8183 * Only UCSI3.0 is tested.
8184 */
8185
8186 #define EC_CMD_UCSI_PPM_SET 0x0140
8187
8188 /* The data size is stored in the host command protocol header. */
8189 struct ec_params_ucsi_ppm_set {
8190 uint16_t offset;
8191 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE];
8192 } __ec_align2;
8193
8194 #define EC_CMD_UCSI_PPM_GET 0x0141
8195
8196 /* For 'GET' sub-commands, data will be returned as a raw payload. */
8197 struct ec_params_ucsi_ppm_get {
8198 uint16_t offset;
8199 uint8_t size;
8200 } __ec_align2;
8201
8202 #define EC_CMD_SET_ALARM_SLP_S0_DBG 0x0142
8203
8204 /* RTC params and response structures */
8205 struct ec_params_set_alarm_slp_s0_dbg {
8206 uint32_t time;
8207 } __ec_align2;
8208
8209 /*
8210 * Control PDC tracing.
8211 * EC_PDC_TRACE_MSG_PORT_NONE disable tracing
8212 * EC_PDC_TRACE_MSG_PORT_ALL enable tracing on all ports
8213 * else, enable tracing on a specific port.
8214 */
8215
8216 #define EC_CMD_PDC_TRACE_MSG_ENABLE 0x0143
8217
8218 #define EC_PDC_TRACE_MSG_PORT_NONE 0xff
8219 #define EC_PDC_TRACE_MSG_PORT_ALL 0xfe
8220
8221 struct ec_params_pdc_trace_msg_enable {
8222 uint8_t port;
8223 };
8224
8225 struct ec_response_pdc_trace_msg_enable {
8226 /* Previous port value. */
8227 uint8_t port;
8228 uint8_t reserved;
8229 /* Number of free bytes in FIFO. */
8230 uint16_t fifo_free;
8231 /* Running total of dropped messages (may wrap). */
8232 uint32_t dropped_count;
8233 } __ec_align4;
8234
8235 /*
8236 * Fetch multiple PDC trace entries.
8237 *
8238 * If no entries are available, pl_size is 0.
8239 * At most MAX_HC_PDC_TRACE_MSG_GET_PAYLOAD bytes worth of entries
8240 * are returned. Only whole entries are returned.
8241 */
8242
8243 #define EC_CMD_PDC_TRACE_MSG_GET_ENTRIES 0x0144
8244 #define MAX_HC_PDC_TRACE_MSG_GET_PAYLOAD 240
8245
8246 struct ec_response_pdc_trace_msg_get_entries {
8247 /* Total bytes of payload. */
8248 uint16_t pl_size;
8249 /* Packed array of pdc_trace_msg_entry structs. */
8250 uint8_t payload[FLEXIBLE_ARRAY_MEMBER_SIZE];
8251 };
8252
8253 enum pdc_trace_msg_direction {
8254 PDC_TRACE_MSG_DIR_IN = 0,
8255 PDC_TRACE_MSG_DIR_OUT = 1,
8256 };
8257
8258 struct pdc_trace_msg_entry {
8259 /*
8260 * Timestamp - least significant 32 bits of EC epoch time
8261 * (microseconds, will wrap around).
8262 */
8263 uint32_t time32_us;
8264 /* Entry sequence number (wraps around). */
8265 uint16_t seq_num;
8266 /* Port number associated with this entry. */
8267 uint8_t port_num;
8268 /* Direction of message (enum pdc_trace_msg_direction) */
8269 uint8_t direction;
8270 /* Format of pdc_data (PDC chip identifier). */
8271 uint8_t msg_type;
8272 /* Bytes in pdc_data. */
8273 uint8_t pdc_data_size;
8274 /* Captured PDC message. */
8275 uint8_t pdc_data[FLEXIBLE_ARRAY_MEMBER_SIZE];
8276 } __ec_align1;
8277
8278 /* Enable/disable Ethernet POE power */
8279 #define EC_CMD_SWITCH_ENABLE_POE 0x0145
8280
8281 struct ec_params_switch_enable_poe {
8282 uint8_t enabled;
8283 } __ec_align1;
8284
8285 /*****************************************************************************/
8286 /* The command range 0x200-0x2FF is reserved for Rotor. */
8287
8288 /*****************************************************************************/
8289 /*
8290 * Reserve a range of host commands for the CR51 firmware.
8291 */
8292 #define EC_CMD_CR51_BASE 0x0300
8293 #define EC_CMD_CR51_LAST 0x03FF
8294
8295 /*****************************************************************************/
8296 /* Fingerprint MCU commands: range 0x0400-0x040x */
8297
8298 /*
8299 * Fingerprint SPI sensor passthru command
8300 *
8301 * This command was used for prototyping and it's now deprecated.
8302 */
8303 #define EC_CMD_FP_PASSTHRU 0x0400
8304
8305 #define EC_FP_FLAG_NOT_COMPLETE 0x1
8306
8307 struct ec_params_fp_passthru {
8308 uint16_t len; /* Number of bytes to write then read */
8309 uint16_t flags; /* EC_FP_FLAG_xxx */
8310 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE]; /* Data to send */
8311 } __ec_align2;
8312
8313 /* Configure the Fingerprint MCU behavior */
8314 #define EC_CMD_FP_MODE 0x0402
8315
8316 /* Put the sensor in its lowest power mode */
8317 #define FP_MODE_DEEPSLEEP BIT(0)
8318 /* Wait to see a finger on the sensor */
8319 #define FP_MODE_FINGER_DOWN BIT(1)
8320 /* Poll until the finger has left the sensor */
8321 #define FP_MODE_FINGER_UP BIT(2)
8322 /* Capture the current finger image */
8323 #define FP_MODE_CAPTURE BIT(3)
8324 /* Finger enrollment session on-going */
8325 #define FP_MODE_ENROLL_SESSION BIT(4)
8326 /* Enroll the current finger image */
8327 #define FP_MODE_ENROLL_IMAGE BIT(5)
8328 /* Try to match the current finger image */
8329 #define FP_MODE_MATCH BIT(6)
8330 /* Reset and re-initialize the sensor. */
8331 #define FP_MODE_RESET_SENSOR BIT(7)
8332 /* Sensor maintenance for dead pixels. */
8333 #define FP_MODE_SENSOR_MAINTENANCE BIT(8)
8334 /* special value: don't change anything just read back current mode */
8335 #define FP_MODE_DONT_CHANGE BIT(31)
8336
8337 #define FP_VALID_MODES \
8338 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
8339 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
8340 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
8341 FP_MODE_DONT_CHANGE)
8342
8343 #define FP_MODES_WITH_AUTHENTICATION (FP_MODE_ENROLL_SESSION | FP_MODE_MATCH)
8344
8345 /* Capture types defined in bits [30..26] */
8346 #define FP_MODE_CAPTURE_TYPE_SHIFT 26
8347 #define FP_MODE_CAPTURE_TYPE_MASK (0x1F << FP_MODE_CAPTURE_TYPE_SHIFT)
8348 /**
8349 * enum fp_capture_type - Specifies the "mode" when capturing images.
8350 *
8351 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
8352 * image (produces 'frame_size' bytes)
8353 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
8354 * bpp bits)
8355 * @FP_CAPTURE_DEFECT_PXL_TEST: Capture for check defect pixel test
8356 * @FP_CAPTURE_ABNORMAL_TEST: Capture for check abnormal pixel test
8357 * @FP_CAPTURE_NOISE_TEST: Capture for check noise test
8358 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
8359 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
8360 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
8361 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
8362 * @FP_CAPTURE_TYPE_MAX: End of enum
8363 *
8364 * @note This enum must remain ordered, if you add new values you must ensure
8365 * that FP_CAPTURE_TYPE_MAX is still the last one.
8366 */
8367 enum fp_capture_type {
8368 FP_CAPTURE_VENDOR_FORMAT = 0,
8369 FP_CAPTURE_DEFECT_PXL_TEST = 1,
8370 FP_CAPTURE_ABNORMAL_TEST = 2,
8371 FP_CAPTURE_NOISE_TEST = 3,
8372 FP_CAPTURE_SIMPLE_IMAGE = 4,
8373 FP_CAPTURE_PATTERN0 = 8,
8374 FP_CAPTURE_PATTERN1 = 12,
8375 FP_CAPTURE_QUALITY_TEST = 16,
8376 FP_CAPTURE_RESET_TEST = 20,
8377 FP_CAPTURE_TYPE_MAX,
8378 };
8379
8380 /* The maximum number of capture types in enum fp_capture_type */
8381 #define FP_MAX_CAPTURE_TYPES 9
8382
8383 /* Extracts the capture type from the sensor 'mode' word */
8384 #define FP_CAPTURE_TYPE(mode) \
8385 (enum fp_capture_type)(((mode) & FP_MODE_CAPTURE_TYPE_MASK) >> \
8386 FP_MODE_CAPTURE_TYPE_SHIFT)
8387
8388 #define FP_MAC_LENGTH 32
8389
8390 struct ec_params_fp_mode {
8391 uint32_t mode; /* as defined by FP_MODE_ constants */
8392 } __ec_align4;
8393
8394 struct ec_params_fp_mode_v1 {
8395 uint32_t mode; /* as defined by FP_MODE_ constants */
8396 uint8_t mac[FP_MAC_LENGTH];
8397 } __ec_align4;
8398
8399 struct ec_response_fp_mode {
8400 uint32_t mode; /* as defined by FP_MODE_ constants */
8401 } __ec_align4;
8402
8403 /* Retrieve Fingerprint sensor information */
8404 #define EC_CMD_FP_INFO 0x0403
8405
8406 /* Mask for dead pixels */
8407 #define FP_ERROR_DEAD_PIXELS_MASK 0x3FF
8408 /* Maximum number of dead pixels */
8409 #define FP_ERROR_DEAD_PIXELS_MAX (FP_ERROR_DEAD_PIXELS_MASK - 1)
8410 /* Number of dead pixels detected on the last maintenance */
8411 #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & FP_ERROR_DEAD_PIXELS_MASK)
8412 /* Unknown number of dead pixels detected on the last maintenance */
8413 #define FP_ERROR_DEAD_PIXELS_UNKNOWN (FP_ERROR_DEAD_PIXELS_MASK)
8414 /* No interrupt from the sensor */
8415 #define FP_ERROR_NO_IRQ BIT(12)
8416 /* SPI communication error */
8417 #define FP_ERROR_SPI_COMM BIT(13)
8418 /* Invalid sensor Hardware ID */
8419 #define FP_ERROR_BAD_HWID BIT(14)
8420 /* Sensor initialization failed */
8421 #define FP_ERROR_INIT_FAIL BIT(15)
8422
8423 struct ec_response_fp_info_v0 {
8424 /* Sensor identification */
8425 uint32_t vendor_id;
8426 uint32_t product_id;
8427 uint32_t model_id;
8428 uint32_t version;
8429 /* Image frame characteristics */
8430 uint32_t frame_size;
8431 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
8432 uint16_t width;
8433 uint16_t height;
8434 uint16_t bpp;
8435 uint16_t errors; /* see FP_ERROR_ flags above */
8436 } __ec_align4;
8437
8438 struct ec_response_fp_info {
8439 /* Sensor identification */
8440 uint32_t vendor_id;
8441 uint32_t product_id;
8442 uint32_t model_id;
8443 uint32_t version;
8444 /* Image frame characteristics */
8445 uint32_t frame_size;
8446 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
8447 uint16_t width;
8448 uint16_t height;
8449 uint16_t bpp;
8450 uint16_t errors; /* see FP_ERROR_ flags above */
8451 /* Template/finger current information */
8452 uint32_t template_size; /* max template size in bytes */
8453 uint16_t template_max; /* maximum number of fingers/templates */
8454 uint16_t template_valid; /* number of valid fingers/templates */
8455 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
8456 uint32_t template_version; /* version of the template format */
8457 } __ec_align4;
8458
8459 struct fp_sensor_info {
8460 /* Sensor identification */
8461 uint32_t vendor_id;
8462 uint32_t product_id;
8463 uint32_t model_id;
8464 uint32_t version;
8465 uint16_t num_capture_types; /* number of image capture types */
8466 uint16_t errors; /* see FP_ERROR_ flags above */
8467 } __ec_align4;
8468 BUILD_ASSERT(sizeof(struct fp_sensor_info) == 20);
8469
8470 struct fp_template_info {
8471 /* Template/finger current information */
8472 uint32_t template_size; /* max template size in bytes */
8473 uint16_t template_max; /* maximum number of fingers/templates */
8474 uint16_t template_valid; /* number of valid fingers/templates */
8475 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
8476 uint32_t template_version; /* version of the template format */
8477 } __ec_align4;
8478 BUILD_ASSERT(sizeof(struct fp_template_info) == 16);
8479
8480 struct fp_image_frame_params {
8481 /* Image frame characteristics */
8482 uint32_t frame_size;
8483 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
8484 uint16_t width;
8485 uint16_t height;
8486 uint16_t bpp;
8487 /** Type of image capture from enum fp_capture_type. */
8488 uint8_t fp_capture_type;
8489 uint8_t reserved; /**< padding for alignment */
8490 } __ec_align4;
8491 BUILD_ASSERT(sizeof(struct fp_image_frame_params) == 16);
8492
8493 struct ec_response_fp_info_v2 {
8494 /* Sensor identification */
8495 struct fp_sensor_info sensor_info;
8496 /* Template/finger current information */
8497 struct fp_template_info template_info;
8498 /* fingerprint image frame parameters */
8499 struct fp_image_frame_params
8500 image_frame_params[FLEXIBLE_ARRAY_MEMBER_SIZE];
8501 } __ec_align4;
8502 BUILD_ASSERT(sizeof(struct ec_response_fp_info_v2) == 36);
8503
8504 /* Get the last captured finger frame or a template content */
8505 #define EC_CMD_FP_FRAME 0x0404
8506
8507 /* constants defining the 'offset' field which also contains the frame index */
8508 #define FP_FRAME_INDEX_SHIFT 28
8509 /* Frame buffer where the captured image is stored */
8510 #define FP_FRAME_INDEX_RAW_IMAGE 0
8511 /* First frame buffer holding a template */
8512 #define FP_FRAME_INDEX_TEMPLATE 1
8513 #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
8514 #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
8515
8516 /* Version of the format of the encrypted templates. */
8517 #define FP_TEMPLATE_FORMAT_VERSION 4
8518
8519 /* Constants for encryption parameters */
8520 #define FP_CONTEXT_NONCE_BYTES 12
8521 #define FP_CONTEXT_USERID_BYTES 32
8522 #define FP_CONTEXT_USERID_WORDS (FP_CONTEXT_USERID_BYTES / sizeof(uint32_t))
8523 #define FP_CONTEXT_TAG_BYTES 16
8524 #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
8525 #define FP_CONTEXT_TPM_BYTES 32
8526
8527 /* Constants for positive match parameters. */
8528 #define FP_POSITIVE_MATCH_SALT_BYTES 16
8529
8530 struct ec_fp_template_encryption_metadata {
8531 /*
8532 * Version of the structure format (N=3).
8533 */
8534 uint16_t struct_version;
8535 /* Reserved bytes, set to 0. */
8536 uint16_t reserved;
8537 /*
8538 * The salt is *only* ever used for key derivation. The nonce is unique,
8539 * a different one is used for every message.
8540 */
8541 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
8542 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
8543 uint8_t tag[FP_CONTEXT_TAG_BYTES];
8544 };
8545
8546 struct ec_params_fp_frame {
8547 /*
8548 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
8549 * in the high nibble, and the real offset within the frame in
8550 * FP_FRAME_OFFSET_MASK.
8551 */
8552 uint32_t offset;
8553 uint32_t size;
8554 } __ec_align4;
8555
8556 /* Load a template into the MCU */
8557 #define EC_CMD_FP_TEMPLATE 0x0405
8558
8559 /* Flag in the 'size' field indicating that the full template has been sent */
8560 #define FP_TEMPLATE_COMMIT 0x80000000
8561
8562 struct ec_params_fp_template {
8563 uint32_t offset;
8564 uint32_t size;
8565 uint8_t data[FLEXIBLE_ARRAY_MEMBER_SIZE];
8566 } __ec_align4;
8567
8568 /* Clear the current fingerprint user context and set a new one */
8569 #define EC_CMD_FP_CONTEXT 0x0406
8570
8571 struct ec_params_fp_context {
8572 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8573 } __ec_align4;
8574
8575 enum fp_context_action {
8576 FP_CONTEXT_ASYNC = 0,
8577 FP_CONTEXT_GET_RESULT = 1,
8578 };
8579
8580 /* Version 1 of the command is "asynchronous". */
8581 struct ec_params_fp_context_v1 {
8582 uint8_t action; /**< enum fp_context_action */
8583 uint8_t reserved[3]; /**< padding for alignment */
8584 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8585 } __ec_align4;
8586
8587 #define EC_CMD_FP_STATS 0x0407
8588
8589 #define FPSTATS_CAPTURE_INV BIT(0)
8590 #define FPSTATS_MATCHING_INV BIT(1)
8591
8592 struct ec_response_fp_stats {
8593 uint32_t capture_time_us;
8594 uint32_t matching_time_us;
8595 uint32_t overall_time_us;
8596 struct {
8597 uint32_t lo;
8598 uint32_t hi;
8599 } overall_t0;
8600 uint8_t timestamps_invalid;
8601 int8_t template_matched;
8602 } __ec_align2;
8603
8604 #define EC_CMD_FP_SEED 0x0408
8605 struct ec_params_fp_seed {
8606 /*
8607 * Version of the structure format (N=3).
8608 */
8609 uint16_t struct_version;
8610 /* Reserved bytes, set to 0. */
8611 uint16_t reserved;
8612 /* Seed from the TPM. */
8613 uint8_t seed[FP_CONTEXT_TPM_BYTES];
8614 } __ec_align4;
8615
8616 #define EC_CMD_FP_ENC_STATUS 0x0409
8617
8618 /* FP TPM seed has been set or not */
8619 #define FP_ENC_STATUS_SEED_SET BIT(0)
8620 /* Session was established or not */
8621 #define FP_CONTEXT_STATUS_SESSION_ESTABLISHED BIT(1)
8622 /* FP session_nonce had been set or not*/
8623 #define FP_CONTEXT_SESSION_NONCE_SET BIT(2)
8624 /* FP user_id had been set or not*/
8625 #define FP_CONTEXT_USER_ID_SET BIT(3)
8626 /* The operation authentication challenge was generated */
8627 #define FP_AUTH_CHALLENGE_SET BIT(4)
8628
8629 struct ec_response_fp_encryption_status {
8630 /* Used bits in encryption engine status */
8631 uint32_t valid_flags;
8632 /* Encryption engine status */
8633 uint32_t status;
8634 } __ec_align4;
8635
8636 #define EC_CMD_FP_READ_MATCH_SECRET 0x040A
8637 struct ec_params_fp_read_match_secret {
8638 uint16_t fgr;
8639 } __ec_align4;
8640
8641 /* The positive match secret has the length of the SHA256 digest. */
8642 #define FP_POSITIVE_MATCH_SECRET_BYTES 32
8643 struct ec_response_fp_read_match_secret {
8644 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8645 } __ec_align4;
8646
8647 #define FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN 32
8648
8649 struct fp_elliptic_curve_public_key {
8650 uint8_t x[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8651 uint8_t y[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8652 } __ec_align4;
8653
8654 #define FP_AES_KEY_ENC_METADATA_VERSION 1
8655 #define FP_AES_KEY_NONCE_BYTES 12
8656 #define FP_AES_KEY_ENCRYPTION_SALT_BYTES 16
8657 #define FP_AES_KEY_TAG_BYTES 16
8658
8659 struct fp_auth_command_encryption_metadata {
8660 /* Version of the structure format */
8661 uint16_t struct_version;
8662 /* Reserved bytes, set to 0. */
8663 uint16_t reserved;
8664 /*
8665 * The salt is *only* ever used for key derivation. The nonce is unique,
8666 * a different one is used for every message.
8667 */
8668 uint8_t nonce[FP_AES_KEY_NONCE_BYTES];
8669 uint8_t encryption_salt[FP_AES_KEY_ENCRYPTION_SALT_BYTES];
8670 uint8_t tag[FP_AES_KEY_TAG_BYTES];
8671 } __ec_align4;
8672
8673 #define FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN 32
8674 #define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8675
8676 struct fp_encrypted_private_key {
8677 struct fp_auth_command_encryption_metadata info;
8678 uint8_t data[FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN];
8679 } __ec_align4;
8680
8681 #define EC_CMD_FP_ESTABLISH_PAIRING_KEY_KEYGEN 0x0410
8682
8683 struct ec_response_fp_establish_pairing_key_keygen {
8684 struct fp_elliptic_curve_public_key pubkey;
8685 } __ec_align4;
8686
8687 #define FP_PAIRING_KEY_LEN 32
8688
8689 struct ec_fp_encrypted_pairing_key {
8690 struct fp_auth_command_encryption_metadata info;
8691 uint8_t data[FP_PAIRING_KEY_LEN];
8692 } __ec_align4;
8693
8694 #define EC_CMD_FP_ESTABLISH_PAIRING_KEY_WRAP 0x0411
8695
8696 struct ec_params_fp_establish_pairing_key_wrap {
8697 struct fp_elliptic_curve_public_key peers_pubkey;
8698 } __ec_align4;
8699
8700 struct ec_response_fp_establish_pairing_key_wrap {
8701 struct ec_fp_encrypted_pairing_key encrypted_pairing_key;
8702 } __ec_align4;
8703
8704 #define EC_CMD_FP_LOAD_PAIRING_KEY 0x0412
8705
8706 typedef struct ec_response_fp_establish_pairing_key_wrap
8707 ec_params_fp_load_pairing_key;
8708
8709 #define FP_CK_SESSION_NONCE_LEN 32
8710
8711 #define EC_CMD_FP_GENERATE_NONCE 0x0413
8712 struct ec_response_fp_generate_nonce {
8713 uint8_t nonce[FP_CK_SESSION_NONCE_LEN];
8714 } __ec_align4;
8715
8716 #define EC_CMD_FP_ESTABLISH_SESSION 0x0414
8717 struct ec_params_fp_establish_session {
8718 uint8_t peer_nonce[FP_CK_SESSION_NONCE_LEN];
8719 uint8_t enc_tpm_seed[FP_CONTEXT_TPM_BYTES];
8720 uint8_t nonce[FP_AES_KEY_NONCE_BYTES];
8721 uint8_t tag[FP_AES_KEY_TAG_BYTES];
8722 } __ec_align4;
8723
8724 #define FP_CHALLENGE_SIZE 32
8725
8726 #define EC_CMD_FP_GENERATE_CHALLENGE 0x0415
8727 struct ec_response_fp_generate_challenge {
8728 uint8_t challenge[FP_CHALLENGE_SIZE];
8729 } __ec_align4;
8730
8731 #define EC_CMD_FP_CONFIRM_TEMPLATE 0x0416
8732 struct ec_params_fp_confirm_template {
8733 uint8_t mac[FP_MAC_LENGTH];
8734 } __ec_align4;
8735
8736 #define EC_CMD_FP_SIGN_MATCH 0x0417
8737 struct ec_params_fp_sign_match {
8738 uint8_t challenge[FP_CHALLENGE_SIZE];
8739 } __ec_align4;
8740
8741 struct ec_response_fp_sign_match {
8742 uint8_t signature[FP_MAC_LENGTH];
8743 } __ec_align4;
8744
8745 /*****************************************************************************/
8746 /* Touchpad MCU commands: range 0x0500-0x05FF */
8747
8748 /* Perform touchpad self test */
8749 #define EC_CMD_TP_SELF_TEST 0x0500
8750
8751 /* Get number of frame types, and the size of each type */
8752 #define EC_CMD_TP_FRAME_INFO 0x0501
8753
8754 struct ec_response_tp_frame_info {
8755 uint32_t n_frames;
8756 uint32_t frame_sizes[FLEXIBLE_ARRAY_MEMBER_SIZE];
8757 } __ec_align4;
8758
8759 /* Create a snapshot of current frame readings */
8760 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
8761
8762 /* Read the frame */
8763 #define EC_CMD_TP_FRAME_GET 0x0503
8764
8765 struct ec_params_tp_frame_get {
8766 uint32_t frame_index;
8767 uint32_t offset;
8768 uint32_t size;
8769 } __ec_align4;
8770
8771 /*****************************************************************************/
8772 /* EC-EC communication commands: range 0x0600-0x06FF */
8773
8774 #define EC_COMM_TEXT_MAX 8
8775
8776 /*
8777 * Get battery static information, i.e. information that never changes, or
8778 * very infrequently.
8779 */
8780 #define EC_CMD_BATTERY_GET_STATIC 0x0600
8781
8782 /**
8783 * struct ec_params_battery_static_info - Battery static info parameters
8784 * @index: Battery index.
8785 */
8786 struct ec_params_battery_static_info {
8787 uint8_t index;
8788 } __ec_align_size1;
8789
8790 /**
8791 * struct ec_response_battery_static_info - Battery static info response
8792 * @design_capacity: Battery Design Capacity (mAh)
8793 * @design_voltage: Battery Design Voltage (mV)
8794 * @manufacturer: Battery Manufacturer String
8795 * @model: Battery Model Number String
8796 * @serial: Battery Serial Number String
8797 * @type: Battery Type String
8798 * @cycle_count: Battery Cycle Count
8799 */
8800 struct ec_response_battery_static_info {
8801 uint16_t design_capacity;
8802 uint16_t design_voltage;
8803 char manufacturer[EC_COMM_TEXT_MAX];
8804 char model[EC_COMM_TEXT_MAX];
8805 char serial[EC_COMM_TEXT_MAX];
8806 char type[EC_COMM_TEXT_MAX];
8807 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
8808 uint32_t cycle_count;
8809 } __ec_align4;
8810
8811 /**
8812 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
8813 * Equivalent to struct ec_response_battery_static_info, but with longer
8814 * strings.
8815 * @design_capacity: battery design capacity (in mAh)
8816 * @design_voltage: battery design voltage (in mV)
8817 * @cycle_count: battery cycle count
8818 * @manufacturer_ext: battery manufacturer string
8819 * @model_ext: battery model string
8820 * @serial_ext: battery serial number string
8821 * @type_ext: battery type string
8822 */
8823 struct ec_response_battery_static_info_v1 {
8824 uint16_t design_capacity;
8825 uint16_t design_voltage;
8826 uint32_t cycle_count;
8827 char manufacturer_ext[12];
8828 char model_ext[12];
8829 char serial_ext[12];
8830 char type_ext[12];
8831 } __ec_align4;
8832
8833 /**
8834 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
8835 *
8836 * Equivalent to struct ec_response_battery_static_info, but with strings
8837 * further lengthened (relative to v1) to accommodate the maximum string length
8838 * permitted by the Smart Battery Data Specification revision 1.1 and fields
8839 * renamed to better match that specification.
8840 *
8841 * @design_capacity: battery design capacity (in mAh)
8842 * @design_voltage: battery design voltage (in mV)
8843 * @cycle_count: battery cycle count
8844 * @manufacturer: battery manufacturer string
8845 * @device_name: battery model string
8846 * @serial: battery serial number string
8847 * @chemistry: battery type string
8848 */
8849 struct ec_response_battery_static_info_v2 {
8850 uint16_t design_capacity;
8851 uint16_t design_voltage;
8852 uint32_t cycle_count;
8853 char manufacturer[SBS_MAX_STR_OBJ_SIZE];
8854 char device_name[SBS_MAX_STR_OBJ_SIZE];
8855 char serial[SBS_MAX_STR_OBJ_SIZE];
8856 char chemistry[SBS_MAX_STR_OBJ_SIZE];
8857 } __ec_align4;
8858
8859 /*
8860 * Get battery dynamic information, i.e. information that is likely to change
8861 * every time it is read.
8862 */
8863 #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
8864
8865 /**
8866 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
8867 * @index: Battery index.
8868 */
8869 struct ec_params_battery_dynamic_info {
8870 uint8_t index;
8871 } __ec_align_size1;
8872
8873 /**
8874 * struct ec_response_battery_dynamic_info - Battery dynamic info response
8875 * @actual_voltage: Battery voltage (mV)
8876 * @actual_current: Battery current (mA); negative=discharging
8877 * @remaining_capacity: Remaining capacity (mAh)
8878 * @full_capacity: Capacity (mAh, might change occasionally)
8879 * @flags: Flags, see EC_BATT_FLAG_*
8880 * @desired_voltage: Charging voltage desired by battery (mV)
8881 * @desired_current: Charging current desired by battery (mA)
8882 */
8883 struct ec_response_battery_dynamic_info {
8884 int16_t actual_voltage;
8885 int16_t actual_current;
8886 int16_t remaining_capacity;
8887 int16_t full_capacity;
8888 int16_t flags;
8889 int16_t desired_voltage;
8890 int16_t desired_current;
8891 } __ec_align2;
8892
8893 /*
8894 * Control charger chip. Used to control charger chip on the peripheral.
8895 */
8896 #define EC_CMD_CHARGER_CONTROL 0x0602
8897
8898 /**
8899 * struct ec_params_charger_control - Charger control parameters
8900 * @max_current: Charger current (mA). Positive to allow base to draw up to
8901 * max_current and (possibly) charge battery, negative to request current
8902 * from base (OTG).
8903 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
8904 * >= 0.
8905 * @allow_charging: Allow base battery charging (only makes sense if
8906 * max_current > 0).
8907 */
8908 struct ec_params_charger_control {
8909 int16_t max_current;
8910 uint16_t otg_voltage;
8911 uint8_t allow_charging;
8912 } __ec_align_size1;
8913
8914 /* Get ACK from the USB-C SS muxes */
8915 #define EC_CMD_USB_PD_MUX_ACK 0x0603
8916
8917 struct ec_params_usb_pd_mux_ack {
8918 uint8_t port; /* USB-C port number */
8919 } __ec_align1;
8920
8921 /* Get boot time */
8922 #define EC_CMD_GET_BOOT_TIME 0x0604
8923
8924 enum boot_time_param {
8925 ARAIL = 0,
8926 RSMRST,
8927 ESPIRST,
8928 PLTRST_LOW,
8929 PLTRST_HIGH,
8930 EC_CUR_TIME,
8931 RESET_CNT,
8932 };
8933
8934 struct ec_response_get_boot_time {
8935 uint64_t timestamp[RESET_CNT];
8936 uint16_t cnt;
8937 } __ec_align4;
8938
8939 /* Issue AP shutdown */
8940 #define EC_CMD_AP_SHUTDOWN 0x0605
8941
8942 /*****************************************************************************/
8943 /*
8944 * Reserve a range of host commands for board-specific, experimental, or
8945 * special purpose features. These can be (re)used without updating this file.
8946 *
8947 * CAUTION: Don't go nuts with this. Shipping products should document ALL
8948 * their EC commands for easier development, testing, debugging, and support.
8949 *
8950 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
8951 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
8952 *
8953 * In your experimental code, you may want to do something like this:
8954 *
8955 * #define EC_CMD_MAGIC_FOO 0x0000
8956 * #define EC_CMD_MAGIC_BAR 0x0001
8957 * #define EC_CMD_MAGIC_HEY 0x0002
8958 *
8959 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
8960 * EC_VER_MASK(0);
8961 *
8962 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
8963 * EC_VER_MASK(0);
8964 *
8965 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
8966 * EC_VER_MASK(0);
8967 */
8968 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
8969 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
8970
8971 /*
8972 * Given the private host command offset, calculate the true private host
8973 * command value.
8974 */
8975 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
8976 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
8977
8978 /*****************************************************************************/
8979 /*
8980 * Passthru commands
8981 *
8982 * Some platforms have sub-processors chained to each other. For example.
8983 *
8984 * AP <--> EC <--> PD MCU
8985 *
8986 * The top 2 bits of the command number are used to indicate which device the
8987 * command is intended for. Device 0 is always the device receiving the
8988 * command; other device mapping is board-specific.
8989 *
8990 * When a device receives a command to be passed to a sub-processor, it passes
8991 * it on with the device number set back to 0. This allows the sub-processor
8992 * to remain blissfully unaware of whether the command originated on the next
8993 * device up the chain, or was passed through from the AP.
8994 *
8995 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
8996 * AP sends command 0x4002 to the EC
8997 * EC sends command 0x0002 to the PD MCU
8998 * EC forwards PD MCU response back to the AP
8999 */
9000
9001 /* Offset and max command number for sub-device n */
9002 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
9003 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
9004
9005 /*****************************************************************************/
9006 /*
9007 * Deprecated constants. These constants have been renamed for clarity. The
9008 * meaning and size has not changed. Programs that use the old names should
9009 * switch to the new names soon, as the old names may not be carried forward
9010 * forever.
9011 */
9012 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
9013 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
9014 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
9015
9016 #endif /* !__ACPI__ */
9017
9018 #ifdef __cplusplus
9019 }
9020 #endif
9021
9022 #endif /* __CROS_EC_EC_COMMANDS_H */