1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Host communication command constants for ChromeOS EC
5 * Copyright (C) 2012 Google, Inc
7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
11 /* Host communication command constants for Chrome EC */
13 #ifndef __CROS_EC_COMMANDS_H
14 #define __CROS_EC_COMMANDS_H
19 #define BUILD_ASSERT(_cond)
22 * Current version of this protocol
24 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
25 * determined in other ways. Remove this once the kernel code no longer
28 #define EC_PROTO_VERSION 0x00000002
30 /* Command version mask */
31 #define EC_VER_MASK(version) BIT(version)
33 /* I/O addresses for ACPI commands */
34 #define EC_LPC_ADDR_ACPI_DATA 0x62
35 #define EC_LPC_ADDR_ACPI_CMD 0x66
37 /* I/O addresses for host command */
38 #define EC_LPC_ADDR_HOST_DATA 0x200
39 #define EC_LPC_ADDR_HOST_CMD 0x204
41 /* I/O addresses for host command args and params */
42 /* Protocol version 2 */
43 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
44 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
45 * EC_PROTO2_MAX_PARAM_SIZE
47 /* Protocol version 3 */
48 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
49 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
52 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
53 * and they tell the kernel that so we have to think of it as two parts.
55 #define EC_HOST_CMD_REGION0 0x800
56 #define EC_HOST_CMD_REGION1 0x880
57 #define EC_HOST_CMD_REGION_SIZE 0x80
59 /* EC command register bit functions */
60 #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
61 #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
62 #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
63 #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
64 #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
65 #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
66 #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
68 #define EC_LPC_ADDR_MEMMAP 0x900
69 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
70 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
72 /* The offset address of each type of data in mapped memory. */
73 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
74 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
75 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
76 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
77 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
78 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
79 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
80 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
81 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
82 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
83 /* Unused 0x28 - 0x2f */
84 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
85 /* Unused 0x31 - 0x33 */
86 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
87 /* Battery values are all 32 bits, unless otherwise noted. */
88 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
89 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
90 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
91 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
92 #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
93 #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
95 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
96 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
97 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
98 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
99 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
100 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
101 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
102 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
103 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
104 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
105 /* Unused 0x84 - 0x8f */
106 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
108 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
109 /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
110 /* 0x94 - 0x99: 1st Accelerometer */
111 /* 0x9a - 0x9f: 2nd Accelerometer */
112 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
113 /* Unused 0xa6 - 0xdf */
116 * ACPI is unable to access memory mapped data at or above this offset due to
117 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
118 * which might be needed by ACPI.
120 #define EC_MEMMAP_NO_ACPI 0xe0
122 /* Define the format of the accelerometer mapped memory status byte. */
123 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
124 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
125 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
127 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
128 #define EC_TEMP_SENSOR_ENTRIES 16
130 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
132 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
134 #define EC_TEMP_SENSOR_B_ENTRIES 8
136 /* Special values for mapped temperature sensors */
137 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
138 #define EC_TEMP_SENSOR_ERROR 0xfe
139 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
140 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
142 * The offset of temperature value stored in mapped memory. This allows
143 * reporting a temperature range of 200K to 454K = -73C to 181C.
145 #define EC_TEMP_SENSOR_OFFSET 200
148 * Number of ALS readings at EC_MEMMAP_ALS
150 #define EC_ALS_ENTRIES 2
153 * The default value a temperature sensor will return when it is present but
154 * has not been read this boot. This is a reasonable number to avoid
155 * triggering alarms on the host.
157 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
159 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
160 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
161 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
163 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
164 #define EC_BATT_FLAG_AC_PRESENT 0x01
165 #define EC_BATT_FLAG_BATT_PRESENT 0x02
166 #define EC_BATT_FLAG_DISCHARGING 0x04
167 #define EC_BATT_FLAG_CHARGING 0x08
168 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
169 /* Set if some of the static/dynamic data is invalid (or outdated). */
170 #define EC_BATT_FLAG_INVALID_DATA 0x20
172 /* Switch flags at EC_MEMMAP_SWITCHES */
173 #define EC_SWITCH_LID_OPEN 0x01
174 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
175 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
176 /* Was recovery requested via keyboard; now unused. */
177 #define EC_SWITCH_IGNORE1 0x08
178 /* Recovery requested via dedicated signal (from servo board) */
179 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
180 /* Was fake developer mode switch; now unused. Remove in next refactor. */
181 #define EC_SWITCH_IGNORE0 0x20
183 /* Host command interface flags */
184 /* Host command interface supports LPC args (LPC interface only) */
185 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
186 /* Host command interface supports version 3 protocol */
187 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
189 /* Wireless switch flags */
190 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
191 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
192 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
193 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
194 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
196 /*****************************************************************************/
200 * These are valid ONLY on the ACPI command/data port.
204 * ACPI Read Embedded Controller
206 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
208 * Use the following sequence:
210 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
211 * - Wait for EC_LPC_CMDR_PENDING bit to clear
212 * - Write address to EC_LPC_ADDR_ACPI_DATA
213 * - Wait for EC_LPC_CMDR_DATA bit to set
214 * - Read value from EC_LPC_ADDR_ACPI_DATA
216 #define EC_CMD_ACPI_READ 0x0080
219 * ACPI Write Embedded Controller
221 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
223 * Use the following sequence:
225 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
226 * - Wait for EC_LPC_CMDR_PENDING bit to clear
227 * - Write address to EC_LPC_ADDR_ACPI_DATA
228 * - Wait for EC_LPC_CMDR_PENDING bit to clear
229 * - Write value to EC_LPC_ADDR_ACPI_DATA
231 #define EC_CMD_ACPI_WRITE 0x0081
234 * ACPI Burst Enable Embedded Controller
236 * This enables burst mode on the EC to allow the host to issue several
237 * commands back-to-back. While in this mode, writes to mapped multi-byte
238 * data are locked out to ensure data consistency.
240 #define EC_CMD_ACPI_BURST_ENABLE 0x0082
243 * ACPI Burst Disable Embedded Controller
245 * This disables burst mode on the EC and stops preventing EC writes to mapped
248 #define EC_CMD_ACPI_BURST_DISABLE 0x0083
251 * ACPI Query Embedded Controller
253 * This clears the lowest-order bit in the currently pending host events, and
254 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
255 * event 0x80000000 = 32), or 0 if no event was pending.
257 #define EC_CMD_ACPI_QUERY_EVENT 0x0084
259 /* Valid addresses in ACPI memory space, for read/write commands */
261 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
262 #define EC_ACPI_MEM_VERSION 0x00
264 * Test location; writing value here updates test compliment byte to (0xff -
267 #define EC_ACPI_MEM_TEST 0x01
268 /* Test compliment; writes here are ignored. */
269 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
271 /* Keyboard backlight brightness percent (0 - 100) */
272 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
273 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
274 #define EC_ACPI_MEM_FAN_DUTY 0x04
277 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
278 * independent thresholds attached to them. The current value of the ID
279 * register determines which sensor is affected by the THRESHOLD and COMMIT
280 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
281 * as the memory-mapped sensors. The COMMIT register applies those settings.
283 * The spec does not mandate any way to read back the threshold settings
284 * themselves, but when a threshold is crossed the AP needs a way to determine
285 * which sensor(s) are responsible. Each reading of the ID register clears and
286 * returns one sensor ID that has crossed one of its threshold (in either
287 * direction) since the last read. A value of 0xFF means "no new thresholds
288 * have tripped". Setting or enabling the thresholds for a sensor will clear
289 * the unread event count for that sensor.
291 #define EC_ACPI_MEM_TEMP_ID 0x05
292 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
293 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
295 * Here are the bits for the COMMIT register:
296 * bit 0 selects the threshold index for the chosen sensor (0/1)
297 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
298 * Each write to the commit register affects one threshold.
300 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
301 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
305 * Set the thresholds for sensor 2 to 50 C and 60 C:
306 * write 2 to [0x05] -- select temp sensor 2
307 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
308 * write 0x2 to [0x07] -- enable threshold 0 with this value
309 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
310 * write 0x3 to [0x07] -- enable threshold 1 with this value
312 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
313 * write 2 to [0x05] -- select temp sensor 2
314 * write 0x1 to [0x07] -- disable threshold 1
317 /* DPTF battery charging current limit */
318 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
320 /* Charging limit is specified in 64 mA steps */
321 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
322 /* Value to disable DPTF battery charging limit */
323 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
326 * Report device orientation
328 * 3:1 Device DPTF Profile Number (DDPN)
329 * 0 = Reserved for backward compatibility (indicates no valid
330 * profile number. Host should fall back to using TBMD).
331 * 1..7 = DPTF Profile number to indicate to host which table needs
333 * 0 Tablet Mode Device Indicator (TBMD)
335 #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
336 #define EC_ACPI_MEM_TBMD_SHIFT 0
337 #define EC_ACPI_MEM_TBMD_MASK 0x1
338 #define EC_ACPI_MEM_DDPN_SHIFT 1
339 #define EC_ACPI_MEM_DDPN_MASK 0x7
342 * Report device features. Uses the same format as the host command, except:
344 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
345 * of features", which is of limited interest when the system is already
346 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
347 * these are supported, it defaults to 0.
348 * This allows detecting the presence of this field since older versions of
349 * the EC codebase would simply return 0xff to that unknown address. Check
350 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
353 #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
354 #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
355 #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
356 #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
357 #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
358 #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
359 #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
360 #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
362 #define EC_ACPI_MEM_BATTERY_INDEX 0x12
365 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
366 * is enabled (1) or disabled (0).
367 * bit 0 USB port ID 0
369 * bit 7 USB port ID 7
371 #define EC_ACPI_MEM_USB_PORT_POWER 0x13
374 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
375 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
377 #define EC_ACPI_MEM_MAPPED_BEGIN 0x20
378 #define EC_ACPI_MEM_MAPPED_SIZE 0xe0
380 /* Current version of ACPI memory address space */
381 #define EC_ACPI_MEM_VERSION_CURRENT 2
385 * This header file is used in coreboot both in C and ACPI code. The ACPI code
386 * is pre-processed to handle constants but the ASL compiler is unable to
387 * handle actual C code so keep it separate.
392 * Attributes for EC request and response packets. Just defining __packed
393 * results in inefficient assembly code on ARM, if the structure is actually
394 * 32-bit aligned, as it should be for all buffers.
396 * Be very careful when adding these to existing structures. They will round
397 * up the structure size to the specified boundary.
399 * Also be very careful to make that if a structure is included in some other
400 * parent structure that the alignment will still be true given the packing of
401 * the parent structure. This is particularly important if the sub-structure
402 * will be passed as a pointer to another function, since that function will
403 * not know about the misaligment caused by the parent structure's packing.
405 * Also be very careful using __packed - particularly when nesting non-packed
406 * structures inside packed ones. In fact, DO NOT use __packed directly;
407 * always use one of these attributes.
409 * Once everything is annotated properly, the following search strings should
410 * not return ANY matches in this file other than right here:
412 * "__packed" - generates inefficient code; all sub-structs must also be packed
414 * "struct [^_]" - all structs should be annotated, except for structs that are
415 * members of other structs/unions (and their original declarations should be
420 * Packed structures make no assumption about alignment, so they do inefficient
423 #define __ec_align1 __packed
424 #define __ec_align2 __packed
425 #define __ec_align4 __packed
426 #define __ec_align_size1 __packed
427 #define __ec_align_offset1 __packed
428 #define __ec_align_offset2 __packed
429 #define __ec_todo_packed __packed
430 #define __ec_todo_unpacked
433 /* LPC command status byte masks */
434 /* EC has written a byte in the data register and host hasn't read it yet */
435 #define EC_LPC_STATUS_TO_HOST 0x01
436 /* Host has written a command/data byte and the EC hasn't read it yet */
437 #define EC_LPC_STATUS_FROM_HOST 0x02
438 /* EC is processing a command */
439 #define EC_LPC_STATUS_PROCESSING 0x04
440 /* Last write to EC was a command, not data */
441 #define EC_LPC_STATUS_LAST_CMD 0x08
442 /* EC is in burst mode */
443 #define EC_LPC_STATUS_BURST_MODE 0x10
444 /* SCI event is pending (requesting SCI query) */
445 #define EC_LPC_STATUS_SCI_PENDING 0x20
446 /* SMI event is pending (requesting SMI query) */
447 #define EC_LPC_STATUS_SMI_PENDING 0x40
449 #define EC_LPC_STATUS_RESERVED 0x80
452 * EC is busy. This covers both the EC processing a command, and the host has
453 * written a new command but the EC hasn't picked it up yet.
455 #define EC_LPC_STATUS_BUSY_MASK \
456 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
459 * Host command response codes (16-bit). Note that response codes should be
460 * stored in a uint16_t rather than directly in a value of this type.
464 EC_RES_INVALID_COMMAND = 1,
466 EC_RES_INVALID_PARAM = 3,
467 EC_RES_ACCESS_DENIED = 4,
468 EC_RES_INVALID_RESPONSE = 5,
469 EC_RES_INVALID_VERSION = 6,
470 EC_RES_INVALID_CHECKSUM = 7,
471 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
472 EC_RES_UNAVAILABLE = 9, /* No response available */
473 EC_RES_TIMEOUT = 10, /* We got a timeout */
474 EC_RES_OVERFLOW = 11, /* Table / data overflow */
475 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
476 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
477 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
478 EC_RES_BUS_ERROR = 15, /* Communications bus error */
479 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
480 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
481 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
482 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
483 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
487 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
488 * EC command uses code 0 to mean "no event pending". We explicitly specify
489 * each value in the enum listing so they won't change if we delete/insert an
490 * item or rearrange the list (it needs to be stable across platforms, not
491 * just within a single compiled instance).
493 enum host_event_code {
494 EC_HOST_EVENT_LID_CLOSED = 1,
495 EC_HOST_EVENT_LID_OPEN = 2,
496 EC_HOST_EVENT_POWER_BUTTON = 3,
497 EC_HOST_EVENT_AC_CONNECTED = 4,
498 EC_HOST_EVENT_AC_DISCONNECTED = 5,
499 EC_HOST_EVENT_BATTERY_LOW = 6,
500 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
501 EC_HOST_EVENT_BATTERY = 8,
502 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
503 /* Event generated by a device attached to the EC */
504 EC_HOST_EVENT_DEVICE = 10,
505 EC_HOST_EVENT_THERMAL = 11,
506 EC_HOST_EVENT_USB_CHARGER = 12,
507 EC_HOST_EVENT_KEY_PRESSED = 13,
509 * EC has finished initializing the host interface. The host can check
510 * for this event following sending a EC_CMD_REBOOT_EC command to
511 * determine when the EC is ready to accept subsequent commands.
513 EC_HOST_EVENT_INTERFACE_READY = 14,
514 /* Keyboard recovery combo has been pressed */
515 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
517 /* Shutdown due to thermal overload */
518 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
519 /* Shutdown due to battery level too low */
520 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
522 /* Suggest that the AP throttle itself */
523 EC_HOST_EVENT_THROTTLE_START = 18,
524 /* Suggest that the AP resume normal speed */
525 EC_HOST_EVENT_THROTTLE_STOP = 19,
527 /* Hang detect logic detected a hang and host event timeout expired */
528 EC_HOST_EVENT_HANG_DETECT = 20,
529 /* Hang detect logic detected a hang and warm rebooted the AP */
530 EC_HOST_EVENT_HANG_REBOOT = 21,
532 /* PD MCU triggering host event */
533 EC_HOST_EVENT_PD_MCU = 22,
535 /* Battery Status flags have changed */
536 EC_HOST_EVENT_BATTERY_STATUS = 23,
538 /* EC encountered a panic, triggering a reset */
539 EC_HOST_EVENT_PANIC = 24,
541 /* Keyboard fastboot combo has been pressed */
542 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
544 /* EC RTC event occurred */
545 EC_HOST_EVENT_RTC = 26,
547 /* Emulate MKBP event */
548 EC_HOST_EVENT_MKBP = 27,
550 /* EC desires to change state of host-controlled USB mux */
551 EC_HOST_EVENT_USB_MUX = 28,
553 /* TABLET/LAPTOP mode or detachable base attach/detach event */
554 EC_HOST_EVENT_MODE_CHANGE = 29,
556 /* Keyboard recovery combo with hardware reinitialization */
557 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
560 * The high bit of the event mask is not used as a host event code. If
561 * it reads back as set, then the entire event mask should be
562 * considered invalid by the host. This can happen when reading the
563 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
564 * not initialized on the EC, or improperly configured on the host.
566 EC_HOST_EVENT_INVALID = 32
568 /* Host event mask */
569 #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
572 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
573 * @flags: The host argument flags.
574 * @command_version: Command version.
575 * @data_size: The length of data.
576 * @checksum: Checksum; sum of command + flags + command_version + data_size +
577 * all params/response data bytes.
579 struct ec_lpc_host_args {
581 uint8_t command_version;
586 /* Flags for ec_lpc_host_args.flags */
588 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
591 * If EC gets a command and this flag is not set, this is an old-style command.
592 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
593 * unknown length. EC must respond with an old-style response (that is,
594 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
596 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
598 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
600 * If EC responds to a command and this flag is not set, this is an old-style
601 * response. Command version is 0 and response data from EC is at
602 * EC_LPC_ADDR_OLD_PARAM with unknown length.
604 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
606 /*****************************************************************************/
608 * Byte codes returned by EC over SPI interface.
610 * These can be used by the AP to debug the EC interface, and to determine
611 * when the EC is not in a state where it will ever get around to responding
614 * Example of sequence of bytes read from EC for a current good transfer:
615 * 1. - - AP asserts chip select (CS#)
616 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
617 * 3. - - EC starts handling CS# interrupt
618 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
619 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
620 * bytes looking for EC_SPI_FRAME_START
621 * 6. - - EC finishes processing and sets up response
622 * 7. EC_SPI_FRAME_START - AP reads frame byte
623 * 8. (response packet) - AP reads response packet
624 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
625 * 10 - - AP deasserts chip select
626 * 11 - - EC processes CS# interrupt and sets up DMA for
629 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
630 * the following byte values:
636 * Then the EC found an error in the request, or was not ready for the request
637 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
638 * because the EC is unable to tell when the AP is done sending its request.
642 * Framing byte which precedes a response packet from the EC. After sending a
643 * request, the AP will clock in bytes until it sees the framing byte, then
644 * clock in the response packet.
646 #define EC_SPI_FRAME_START 0xec
649 * Padding bytes which are clocked out after the end of a response packet.
651 #define EC_SPI_PAST_END 0xed
654 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
655 * that the AP will send a valid packet header (starting with
656 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
658 #define EC_SPI_RX_READY 0xf8
661 * EC has started receiving the request from the AP, but hasn't started
664 #define EC_SPI_RECEIVING 0xf9
666 /* EC has received the entire request from the AP and is processing it. */
667 #define EC_SPI_PROCESSING 0xfa
670 * EC received bad data from the AP, such as a packet header with an invalid
671 * length. EC will ignore all data until chip select deasserts.
673 #define EC_SPI_RX_BAD_DATA 0xfb
676 * EC received data from the AP before it was ready. That is, the AP asserted
677 * chip select and started clocking data before the EC was ready to receive it.
678 * EC will ignore all data until chip select deasserts.
680 #define EC_SPI_NOT_READY 0xfc
683 * EC was ready to receive a request from the AP. EC has treated the byte sent
684 * by the AP as part of a request packet, or (for old-style ECs) is processing
685 * a fully received packet but is not ready to respond yet.
687 #define EC_SPI_OLD_READY 0xfd
689 /*****************************************************************************/
692 * Protocol version 2 for I2C and SPI send a request this way:
694 * 0 EC_CMD_VERSION0 + (command version)
696 * 2 Length of params = N
697 * 3..N+2 Params, if any
698 * N+3 8-bit checksum of bytes 0..N+2
700 * The corresponding response is:
702 * 0 Result code (EC_RES_*)
703 * 1 Length of params = M
704 * 2..M+1 Params, if any
705 * M+2 8-bit checksum of bytes 0..M+1
707 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
708 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
709 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
710 EC_PROTO2_REQUEST_TRAILER_BYTES)
712 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
713 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
714 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
715 EC_PROTO2_RESPONSE_TRAILER_BYTES)
717 /* Parameter length was limited by the LPC interface */
718 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
720 /* Maximum request and response packet sizes for protocol version 2 */
721 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
722 EC_PROTO2_MAX_PARAM_SIZE)
723 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
724 EC_PROTO2_MAX_PARAM_SIZE)
726 /*****************************************************************************/
729 * Value written to legacy command port / prefix byte to indicate protocol
730 * 3+ structs are being used. Usage is bus-dependent.
732 #define EC_COMMAND_PROTOCOL_3 0xda
734 #define EC_HOST_REQUEST_VERSION 3
737 * struct ec_host_request - Version 3 request from host.
738 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
739 * receives a header with a version it doesn't know how to
741 * @checksum: Checksum of request and data; sum of all bytes including checksum
743 * @command: Command to send (EC_CMD_...)
744 * @command_version: Command version.
745 * @reserved: Unused byte in current protocol version; set to 0.
746 * @data_len: Length of data which follows this header.
748 struct ec_host_request {
749 uint8_t struct_version;
752 uint8_t command_version;
757 #define EC_HOST_RESPONSE_VERSION 3
760 * struct ec_host_response - Version 3 response from EC.
761 * @struct_version: Struct version (=3).
762 * @checksum: Checksum of response and data; sum of all bytes including
763 * checksum should total to 0.
764 * @result: EC's response to the command (separate from communication failure)
765 * @data_len: Length of data which follows this header.
766 * @reserved: Unused bytes in current protocol version; set to 0.
768 struct ec_host_response {
769 uint8_t struct_version;
776 /*****************************************************************************/
779 * Host command protocol V4.
781 * Packets always start with a request or response header. They are followed
782 * by data_len bytes of data. If the data_crc_present flag is set, the data
783 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
786 * Host algorithm when sending a request q:
788 * 101) tries_left=(some value, e.g. 3);
791 * 104) Calculate q.header_crc.
792 * 105) Send request q to EC.
793 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
795 * 201) If r.struct_version != 4, go to 301.
796 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
797 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
798 * 204) If r.seq_num != q.seq_num, go to 301.
799 * 205) If r.seq_dup == q.seq_dup, return success.
800 * 207) If r.seq_dup == 1, go to 301.
803 * 301) If --tries_left <= 0, return error.
804 * 302) If q.seq_dup == 1, go to 105.
808 * EC algorithm when receiving a request q.
809 * EC has response buffer r, error buffer e.
811 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
813 * 102) If q.header_crc mismatches calculated CRC, set e.result =
814 * EC_RES_INVALID_HEADER_CRC and go to 301
815 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
816 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
818 * 104) If q.seq_dup == 0, go to 201.
819 * 105) If q.seq_num != r.seq_num, go to 201.
820 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
822 * 201) Process request q into response r.
823 * 202) r.seq_num = q.seq_num
824 * 203) r.seq_dup = q.seq_dup
825 * 204) Calculate r.header_crc
826 * 205) If r.data_len > 0 and data is no longer available, set e.result =
827 * EC_RES_DUP_UNAVAILABLE and go to 301.
828 * 206) Send response r.
830 * 301) e.seq_num = q.seq_num
831 * 302) e.seq_dup = q.seq_dup
832 * 303) Calculate e.header_crc.
833 * 304) Send error response e.
836 /* Version 4 request from host */
837 struct ec_host_request4 {
839 * bits 0-3: struct_version: Structure version (=4)
840 * bit 4: is_response: Is response (=0)
841 * bits 5-6: seq_num: Sequence number
842 * bit 7: seq_dup: Sequence duplicate flag
847 * bits 0-4: command_version: Command version
848 * bits 5-6: Reserved (set 0, ignore on read)
849 * bit 7: data_crc_present: Is data CRC present after data
853 /* Command code (EC_CMD_*) */
856 /* Length of data which follows this header (not including data CRC) */
859 /* Reserved (set 0, ignore on read) */
862 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
866 /* Version 4 response from EC */
867 struct ec_host_response4 {
869 * bits 0-3: struct_version: Structure version (=4)
870 * bit 4: is_response: Is response (=1)
871 * bits 5-6: seq_num: Sequence number
872 * bit 7: seq_dup: Sequence duplicate flag
877 * bits 0-6: Reserved (set 0, ignore on read)
878 * bit 7: data_crc_present: Is data CRC present after data
882 /* Result code (EC_RES_*) */
885 /* Length of data which follows this header (not including data CRC) */
888 /* Reserved (set 0, ignore on read) */
891 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
895 /* Fields in fields0 byte */
896 #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
897 #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
898 #define EC_PACKET4_0_SEQ_NUM_SHIFT 5
899 #define EC_PACKET4_0_SEQ_NUM_MASK 0x60
900 #define EC_PACKET4_0_SEQ_DUP_MASK 0x80
902 /* Fields in fields1 byte */
903 #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
904 #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
906 /*****************************************************************************/
910 * Each command is an 16-bit command value. Commands which take params or
911 * return response data specify structures for that data. If no structure is
912 * specified, the command does not input or output data, respectively.
913 * Parameter/response length is implicit in the structs. Some underlying
914 * communication protocols (I2C, SPI) may add length or checksum headers, but
915 * those are implementation-dependent and not defined here.
917 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
918 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
921 /*****************************************************************************/
922 /* General / test commands */
925 * Get protocol version, used to deal with non-backward compatible protocol
928 #define EC_CMD_PROTO_VERSION 0x0000
931 * struct ec_response_proto_version - Response to the proto version command.
932 * @version: The protocol version.
934 struct ec_response_proto_version {
939 * Hello. This is a simple command to test the EC is responsive to
942 #define EC_CMD_HELLO 0x0001
945 * struct ec_params_hello - Parameters to the hello command.
946 * @in_data: Pass anything here.
948 struct ec_params_hello {
953 * struct ec_response_hello - Response to the hello command.
954 * @out_data: Output will be in_data + 0x01020304.
956 struct ec_response_hello {
960 /* Get version number */
961 #define EC_CMD_GET_VERSION 0x0002
963 enum ec_current_image {
964 EC_IMAGE_UNKNOWN = 0,
970 * struct ec_response_get_version - Response to the get version command.
971 * @version_string_ro: Null-terminated RO firmware version string.
972 * @version_string_rw: Null-terminated RW firmware version string.
973 * @reserved: Unused bytes; was previously RW-B firmware version string.
974 * @current_image: One of ec_current_image.
976 struct ec_response_get_version {
977 char version_string_ro[32];
978 char version_string_rw[32];
980 uint32_t current_image;
984 #define EC_CMD_READ_TEST 0x0003
987 * struct ec_params_read_test - Parameters for the read test command.
988 * @offset: Starting value for read buffer.
989 * @size: Size to read in bytes.
991 struct ec_params_read_test {
997 * struct ec_response_read_test - Response to the read test command.
998 * @data: Data returned by the read test command.
1000 struct ec_response_read_test {
1005 * Get build information
1007 * Response is null-terminated string.
1009 #define EC_CMD_GET_BUILD_INFO 0x0004
1012 #define EC_CMD_GET_CHIP_INFO 0x0005
1015 * struct ec_response_get_chip_info - Response to the get chip info command.
1016 * @vendor: Null-terminated string for chip vendor.
1017 * @name: Null-terminated string for chip name.
1018 * @revision: Null-terminated string for chip mask version.
1020 struct ec_response_get_chip_info {
1026 /* Get board HW version */
1027 #define EC_CMD_GET_BOARD_VERSION 0x0006
1030 * struct ec_response_board_version - Response to the board version command.
1031 * @board_version: A monotonously incrementing number.
1033 struct ec_response_board_version {
1034 uint16_t board_version;
1038 * Read memory-mapped data.
1040 * This is an alternate interface to memory-mapped data for bus protocols
1041 * which don't support direct-mapped memory - I2C, SPI, etc.
1043 * Response is params.size bytes of data.
1045 #define EC_CMD_READ_MEMMAP 0x0007
1048 * struct ec_params_read_memmap - Parameters for the read memory map command.
1049 * @offset: Offset in memmap (EC_MEMMAP_*).
1050 * @size: Size to read in bytes.
1052 struct ec_params_read_memmap {
1057 /* Read versions supported for a command */
1058 #define EC_CMD_GET_CMD_VERSIONS 0x0008
1061 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1062 * @cmd: Command to check.
1064 struct ec_params_get_cmd_versions {
1069 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1071 * @cmd: Command to check.
1073 struct ec_params_get_cmd_versions_v1 {
1078 * struct ec_response_get_cmd_version - Response to the get command versions.
1079 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1080 * a desired version.
1082 struct ec_response_get_cmd_versions {
1083 uint32_t version_mask;
1087 * Check EC communications status (busy). This is needed on i2c/spi but not
1088 * on lpc since it has its own out-of-band busy indicator.
1090 * lpc must read the status from the command register. Attempting this on
1091 * lpc will overwrite the args/parameter space and corrupt its data.
1093 #define EC_CMD_GET_COMMS_STATUS 0x0009
1095 /* Avoid using ec_status which is for return values */
1096 enum ec_comms_status {
1097 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
1101 * struct ec_response_get_comms_status - Response to the get comms status
1103 * @flags: Mask of enum ec_comms_status.
1105 struct ec_response_get_comms_status {
1106 uint32_t flags; /* Mask of enum ec_comms_status */
1109 /* Fake a variety of responses, purely for testing purposes. */
1110 #define EC_CMD_TEST_PROTOCOL 0x000A
1112 /* Tell the EC what to send back to us. */
1113 struct ec_params_test_protocol {
1119 /* Here it comes... */
1120 struct ec_response_test_protocol {
1124 /* Get protocol information */
1125 #define EC_CMD_GET_PROTOCOL_INFO 0x000B
1127 /* Flags for ec_response_get_protocol_info.flags */
1128 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
1129 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
1132 * struct ec_response_get_protocol_info - Response to the get protocol info.
1133 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1135 * @max_request_packet_size: Maximum request packet size in bytes.
1136 * @max_response_packet_size: Maximum response packet size in bytes.
1137 * @flags: see EC_PROTOCOL_INFO_*
1139 struct ec_response_get_protocol_info {
1140 /* Fields which exist if at least protocol version 3 supported */
1141 uint32_t protocol_versions;
1142 uint16_t max_request_packet_size;
1143 uint16_t max_response_packet_size;
1148 /*****************************************************************************/
1149 /* Get/Set miscellaneous values */
1151 /* The upper byte of .flags tells what to do (nothing means "get") */
1152 #define EC_GSV_SET 0x80000000
1155 * The lower three bytes of .flags identifies the parameter, if that has
1156 * meaning for an individual command.
1158 #define EC_GSV_PARAM_MASK 0x00ffffff
1160 struct ec_params_get_set_value {
1165 struct ec_response_get_set_value {
1170 /* More than one command can use these structs to get/set parameters. */
1171 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
1173 /*****************************************************************************/
1174 /* List the features supported by the firmware */
1175 #define EC_CMD_GET_FEATURES 0x000D
1177 /* Supported features */
1178 enum ec_feature_code {
1180 * This image contains a limited set of features. Another image
1181 * in RW partition may support more features.
1183 EC_FEATURE_LIMITED = 0,
1185 * Commands for probing/reading/writing/erasing the flash in the
1188 EC_FEATURE_FLASH = 1,
1190 * Can control the fan speed directly.
1192 EC_FEATURE_PWM_FAN = 2,
1194 * Can control the intensity of the keyboard backlight.
1196 EC_FEATURE_PWM_KEYB = 3,
1198 * Support Google lightbar, introduced on Pixel.
1200 EC_FEATURE_LIGHTBAR = 4,
1201 /* Control of LEDs */
1203 /* Exposes an interface to control gyro and sensors.
1204 * The host goes through the EC to access these sensors.
1205 * In addition, the EC may provide composite sensors, like lid angle.
1207 EC_FEATURE_MOTION_SENSE = 6,
1208 /* The keyboard is controlled by the EC */
1209 EC_FEATURE_KEYB = 7,
1210 /* The AP can use part of the EC flash as persistent storage. */
1211 EC_FEATURE_PSTORE = 8,
1212 /* The EC monitors BIOS port 80h, and can return POST codes. */
1213 EC_FEATURE_PORT80 = 9,
1215 * Thermal management: include TMP specific commands.
1216 * Higher level than direct fan control.
1218 EC_FEATURE_THERMAL = 10,
1219 /* Can switch the screen backlight on/off */
1220 EC_FEATURE_BKLIGHT_SWITCH = 11,
1221 /* Can switch the wifi module on/off */
1222 EC_FEATURE_WIFI_SWITCH = 12,
1223 /* Monitor host events, through for example SMI or SCI */
1224 EC_FEATURE_HOST_EVENTS = 13,
1225 /* The EC exposes GPIO commands to control/monitor connected devices. */
1226 EC_FEATURE_GPIO = 14,
1227 /* The EC can send i2c messages to downstream devices. */
1228 EC_FEATURE_I2C = 15,
1229 /* Command to control charger are included */
1230 EC_FEATURE_CHARGER = 16,
1231 /* Simple battery support. */
1232 EC_FEATURE_BATTERY = 17,
1234 * Support Smart battery protocol
1235 * (Common Smart Battery System Interface Specification)
1237 EC_FEATURE_SMART_BATTERY = 18,
1238 /* EC can detect when the host hangs. */
1239 EC_FEATURE_HANG_DETECT = 19,
1240 /* Report power information, for pit only */
1241 EC_FEATURE_PMU = 20,
1242 /* Another Cros EC device is present downstream of this one */
1243 EC_FEATURE_SUB_MCU = 21,
1244 /* Support USB Power delivery (PD) commands */
1245 EC_FEATURE_USB_PD = 22,
1246 /* Control USB multiplexer, for audio through USB port for instance. */
1247 EC_FEATURE_USB_MUX = 23,
1248 /* Motion Sensor code has an internal software FIFO */
1249 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1250 /* Support temporary secure vstore */
1251 EC_FEATURE_VSTORE = 25,
1252 /* EC decides on USB-C SS mux state, muxes configured by host */
1253 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1254 /* EC has RTC feature that can be controlled by host commands */
1255 EC_FEATURE_RTC = 27,
1256 /* The MCU exposes a Fingerprint sensor */
1257 EC_FEATURE_FINGERPRINT = 28,
1258 /* The MCU exposes a Touchpad */
1259 EC_FEATURE_TOUCHPAD = 29,
1260 /* The MCU has RWSIG task enabled */
1261 EC_FEATURE_RWSIG = 30,
1262 /* EC has device events support */
1263 EC_FEATURE_DEVICE_EVENT = 31,
1264 /* EC supports the unified wake masks for LPC/eSPI systems */
1265 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1266 /* EC supports 64-bit host events */
1267 EC_FEATURE_HOST_EVENT64 = 33,
1268 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1269 EC_FEATURE_EXEC_IN_RAM = 34,
1270 /* EC supports CEC commands */
1271 EC_FEATURE_CEC = 35,
1272 /* EC supports tight sensor timestamping. */
1273 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
1275 * EC supports tablet mode detection aligned to Chrome and allows
1276 * setting of threshold by host command using
1277 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1279 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
1280 /* EC supports audio codec. */
1281 EC_FEATURE_AUDIO_CODEC = 38,
1282 /* The MCU is a System Companion Processor (SCP). */
1283 EC_FEATURE_SCP = 39,
1284 /* The MCU is an Integrated Sensor Hub */
1285 EC_FEATURE_ISH = 40,
1288 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1289 #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1291 struct ec_response_get_features {
1295 /*****************************************************************************/
1296 /* Get the board's SKU ID from EC */
1297 #define EC_CMD_GET_SKU_ID 0x000E
1299 /* Set SKU ID from AP */
1300 #define EC_CMD_SET_SKU_ID 0x000F
1302 struct ec_sku_id_info {
1306 /*****************************************************************************/
1307 /* Flash commands */
1309 /* Get flash info */
1310 #define EC_CMD_FLASH_INFO 0x0010
1311 #define EC_VER_FLASH_INFO 2
1314 * struct ec_response_flash_info - Response to the flash info command.
1315 * @flash_size: Usable flash size in bytes.
1316 * @write_block_size: Write block size. Write offset and size must be a
1318 * @erase_block_size: Erase block size. Erase offset and size must be a
1320 * @protect_block_size: Protection block size. Protection offset and size
1321 * must be a multiple of this.
1323 * Version 0 returns these fields.
1325 struct ec_response_flash_info {
1326 uint32_t flash_size;
1327 uint32_t write_block_size;
1328 uint32_t erase_block_size;
1329 uint32_t protect_block_size;
1333 * Flags for version 1+ flash info command
1334 * EC flash erases bits to 0 instead of 1.
1336 #define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
1339 * Flash must be selected for read/write/erase operations to succeed. This may
1340 * be necessary on a chip where write/erase can be corrupted by other board
1341 * activity, or where the chip needs to enable some sort of programming voltage,
1342 * or where the read/write/erase operations require cleanly suspending other
1343 * chip functionality.
1345 #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
1348 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1349 * @flash_size: Usable flash size in bytes.
1350 * @write_block_size: Write block size. Write offset and size must be a
1352 * @erase_block_size: Erase block size. Erase offset and size must be a
1354 * @protect_block_size: Protection block size. Protection offset and size
1355 * must be a multiple of this.
1356 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1357 * size is exactly this and offset is a multiple of this.
1358 * For example, an EC may have a write buffer which can do
1359 * half-page operations if data is aligned, and a slower
1360 * word-at-a-time write mode.
1361 * @flags: Flags; see EC_FLASH_INFO_*
1363 * Version 1 returns the same initial fields as version 0, with additional
1366 * gcc anonymous structs don't seem to get along with the __packed directive;
1367 * if they did we'd define the version 0 structure as a sub-structure of this
1370 * Version 2 supports flash banks of different sizes:
1371 * The caller specified the number of banks it has preallocated
1373 * The EC returns the number of banks describing the flash memory.
1374 * It adds banks descriptions up to num_banks_desc.
1376 struct ec_response_flash_info_1 {
1377 /* Version 0 fields; see above for description */
1378 uint32_t flash_size;
1379 uint32_t write_block_size;
1380 uint32_t erase_block_size;
1381 uint32_t protect_block_size;
1383 /* Version 1 adds these fields: */
1384 uint32_t write_ideal_size;
1388 struct ec_params_flash_info_2 {
1389 /* Number of banks to describe */
1390 uint16_t num_banks_desc;
1391 /* Reserved; set 0; ignore on read */
1392 uint8_t reserved[2];
1395 struct ec_flash_bank {
1396 /* Number of sector is in this bank. */
1398 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1400 /* Minimal write size for the sectors in this bank */
1401 uint8_t write_size_exp;
1402 /* Erase size for the sectors in this bank */
1403 uint8_t erase_size_exp;
1404 /* Size for write protection, usually identical to erase size. */
1405 uint8_t protect_size_exp;
1406 /* Reserved; set 0; ignore on read */
1407 uint8_t reserved[2];
1410 struct ec_response_flash_info_2 {
1411 /* Total flash in the EC. */
1412 uint32_t flash_size;
1413 /* Flags; see EC_FLASH_INFO_* */
1415 /* Maximum size to use to send data to write to the EC. */
1416 uint32_t write_ideal_size;
1417 /* Number of banks present in the EC. */
1418 uint16_t num_banks_total;
1419 /* Number of banks described in banks array. */
1420 uint16_t num_banks_desc;
1421 struct ec_flash_bank banks[0];
1427 * Response is params.size bytes of data.
1429 #define EC_CMD_FLASH_READ 0x0011
1432 * struct ec_params_flash_read - Parameters for the flash read command.
1433 * @offset: Byte offset to read.
1434 * @size: Size to read in bytes.
1436 struct ec_params_flash_read {
1442 #define EC_CMD_FLASH_WRITE 0x0012
1443 #define EC_VER_FLASH_WRITE 1
1445 /* Version 0 of the flash command supported only 64 bytes of data */
1446 #define EC_FLASH_WRITE_VER0_SIZE 64
1449 * struct ec_params_flash_write - Parameters for the flash write command.
1450 * @offset: Byte offset to write.
1451 * @size: Size to write in bytes.
1453 struct ec_params_flash_write {
1456 /* Followed by data to write */
1460 #define EC_CMD_FLASH_ERASE 0x0013
1463 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1464 * @offset: Byte offset to erase.
1465 * @size: Size to erase in bytes.
1467 struct ec_params_flash_erase {
1473 * v1 add async erase:
1474 * subcommands can returns:
1475 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1476 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1477 * EC_RES_ERROR : other errors.
1478 * EC_RES_BUSY : an existing erase operation is in progress.
1479 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1481 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1482 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1483 * the proper result.
1484 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1485 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1486 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1487 * permitted while erasing. (For instance, STM32F4).
1489 enum ec_flash_erase_cmd {
1490 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1491 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1492 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1496 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1497 * @cmd: One of ec_flash_erase_cmd.
1498 * @reserved: Pad byte; currently always contains 0.
1499 * @flag: No flags defined yet; set to 0.
1500 * @params: Same as v0 parameters.
1502 struct ec_params_flash_erase_v1 {
1506 struct ec_params_flash_erase params;
1510 * Get/set flash protection.
1512 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1513 * firmware write protect GPIO, not all flags will take effect immediately;
1514 * some flags require a subsequent hard reset to take effect. Check the
1515 * returned flags bits to see what actually happened.
1517 * If mask=0, simply returns the current flags state.
1519 #define EC_CMD_FLASH_PROTECT 0x0015
1520 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1522 /* Flags for flash protection */
1523 /* RO flash code protected when the EC boots */
1524 #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
1526 * RO flash code protected now. If this bit is set, at-boot status cannot
1529 #define EC_FLASH_PROTECT_RO_NOW BIT(1)
1530 /* Entire flash code protected now, until reboot. */
1531 #define EC_FLASH_PROTECT_ALL_NOW BIT(2)
1532 /* Flash write protect GPIO is asserted now */
1533 #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
1534 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1535 #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
1537 * Error - flash protection is in inconsistent state. At least one bank of
1538 * flash which should be protected is not protected. Usually fixed by
1539 * re-requesting the desired flags, or by a hard reset if that fails.
1541 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
1542 /* Entire flash code protected when the EC boots */
1543 #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
1544 /* RW flash code protected when the EC boots */
1545 #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
1546 /* RW flash code protected now. */
1547 #define EC_FLASH_PROTECT_RW_NOW BIT(8)
1548 /* Rollback information flash region protected when the EC boots */
1549 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
1550 /* Rollback information flash region protected now */
1551 #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
1555 * struct ec_params_flash_protect - Parameters for the flash protect command.
1556 * @mask: Bits in flags to apply.
1557 * @flags: New flags to apply.
1559 struct ec_params_flash_protect {
1565 * struct ec_response_flash_protect - Response to the flash protect command.
1566 * @flags: Current value of flash protect flags.
1567 * @valid_flags: Flags which are valid on this platform. This allows the
1568 * caller to distinguish between flags which aren't set vs. flags
1569 * which can't be set on this platform.
1570 * @writable_flags: Flags which can be changed given the current protection
1573 struct ec_response_flash_protect {
1575 uint32_t valid_flags;
1576 uint32_t writable_flags;
1580 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1581 * write protect. These commands may be reused with version > 0.
1584 /* Get the region offset/size */
1585 #define EC_CMD_FLASH_REGION_INFO 0x0016
1586 #define EC_VER_FLASH_REGION_INFO 1
1588 enum ec_flash_region {
1589 /* Region which holds read-only EC image */
1590 EC_FLASH_REGION_RO = 0,
1592 * Region which holds active RW image. 'Active' is different from
1593 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1594 * scheduled to run, active/non-active applies only to RW images (for
1595 * the same reason 'update' applies only to RW images. It's a state of
1596 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1597 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1598 * doesn't enter 'running' state but it's still active on a flash.
1600 EC_FLASH_REGION_ACTIVE,
1602 * Region which should be write-protected in the factory (a superset of
1603 * EC_FLASH_REGION_RO)
1605 EC_FLASH_REGION_WP_RO,
1606 /* Region which holds updatable (non-active) RW image */
1607 EC_FLASH_REGION_UPDATE,
1608 /* Number of regions */
1609 EC_FLASH_REGION_COUNT,
1612 * 'RW' is vague if there are multiple RW images; we mean the active one,
1613 * so the old constant is deprecated.
1615 #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
1618 * struct ec_params_flash_region_info - Parameters for the flash region info
1620 * @region: Flash region; see EC_FLASH_REGION_*
1622 struct ec_params_flash_region_info {
1626 struct ec_response_flash_region_info {
1631 /* Read/write VbNvContext */
1632 #define EC_CMD_VBNV_CONTEXT 0x0017
1633 #define EC_VER_VBNV_CONTEXT 1
1634 #define EC_VBNV_BLOCK_SIZE 16
1636 enum ec_vbnvcontext_op {
1637 EC_VBNV_CONTEXT_OP_READ,
1638 EC_VBNV_CONTEXT_OP_WRITE,
1641 struct ec_params_vbnvcontext {
1643 uint8_t block[EC_VBNV_BLOCK_SIZE];
1646 struct ec_response_vbnvcontext {
1647 uint8_t block[EC_VBNV_BLOCK_SIZE];
1651 /* Get SPI flash information */
1652 #define EC_CMD_FLASH_SPI_INFO 0x0018
1654 struct ec_response_flash_spi_info {
1655 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1658 /* Pad byte; currently always contains 0 */
1661 /* Manufacturer / device ID from command 0x90 */
1662 uint8_t mfr_dev_id[2];
1664 /* Status registers from command 0x05 and 0x35 */
1669 /* Select flash during flash operations */
1670 #define EC_CMD_FLASH_SELECT 0x0019
1673 * struct ec_params_flash_select - Parameters for the flash select command.
1674 * @select: 1 to select flash, 0 to deselect flash
1676 struct ec_params_flash_select {
1681 /*****************************************************************************/
1684 /* Get fan target RPM */
1685 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1687 struct ec_response_pwm_get_fan_rpm {
1691 /* Set target fan RPM */
1692 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1694 /* Version 0 of input params */
1695 struct ec_params_pwm_set_fan_target_rpm_v0 {
1699 /* Version 1 of input params */
1700 struct ec_params_pwm_set_fan_target_rpm_v1 {
1705 /* Get keyboard backlight */
1706 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1707 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1709 struct ec_response_pwm_get_keyboard_backlight {
1714 /* Set keyboard backlight */
1715 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1716 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1718 struct ec_params_pwm_set_keyboard_backlight {
1722 /* Set target fan PWM duty cycle */
1723 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1725 /* Version 0 of input params */
1726 struct ec_params_pwm_set_fan_duty_v0 {
1730 /* Version 1 of input params */
1731 struct ec_params_pwm_set_fan_duty_v1 {
1736 #define EC_CMD_PWM_SET_DUTY 0x0025
1737 /* 16 bit duty cycle, 0xffff = 100% */
1738 #define EC_PWM_MAX_DUTY 0xffff
1741 /* All types, indexed by board-specific enum pwm_channel */
1742 EC_PWM_TYPE_GENERIC = 0,
1743 /* Keyboard backlight */
1744 EC_PWM_TYPE_KB_LIGHT,
1745 /* Display backlight */
1746 EC_PWM_TYPE_DISPLAY_LIGHT,
1750 struct ec_params_pwm_set_duty {
1751 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1752 uint8_t pwm_type; /* ec_pwm_type */
1753 uint8_t index; /* Type-specific index, or 0 if unique */
1756 #define EC_CMD_PWM_GET_DUTY 0x0026
1758 struct ec_params_pwm_get_duty {
1759 uint8_t pwm_type; /* ec_pwm_type */
1760 uint8_t index; /* Type-specific index, or 0 if unique */
1763 struct ec_response_pwm_get_duty {
1764 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1767 /*****************************************************************************/
1769 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1770 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1771 * into a subcommand. We'll make separate structs for subcommands with
1772 * different input args, so that we know how much to expect.
1774 #define EC_CMD_LIGHTBAR_CMD 0x0028
1778 } __ec_todo_unpacked;
1780 #define LB_BATTERY_LEVELS 4
1783 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1784 * host command, but the alignment is the same regardless. Keep it that way.
1786 struct lightbar_params_v0 {
1788 int32_t google_ramp_up;
1789 int32_t google_ramp_down;
1790 int32_t s3s0_ramp_up;
1791 int32_t s0_tick_delay[2]; /* AC=0/1 */
1792 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1793 int32_t s0s3_ramp_down;
1794 int32_t s3_sleep_for;
1796 int32_t s3_ramp_down;
1800 uint8_t osc_min[2]; /* AC=0/1 */
1801 uint8_t osc_max[2]; /* AC=0/1 */
1802 uint8_t w_ofs[2]; /* AC=0/1 */
1804 /* Brightness limits based on the backlight and AC. */
1805 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1806 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1807 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1809 /* Battery level thresholds */
1810 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1812 /* Map [AC][battery_level] to color index */
1813 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1814 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1817 struct rgb_s color[8]; /* 0-3 are Google colors */
1820 struct lightbar_params_v1 {
1822 int32_t google_ramp_up;
1823 int32_t google_ramp_down;
1824 int32_t s3s0_ramp_up;
1825 int32_t s0_tick_delay[2]; /* AC=0/1 */
1826 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1827 int32_t s0s3_ramp_down;
1828 int32_t s3_sleep_for;
1830 int32_t s3_ramp_down;
1832 int32_t s5_ramp_down;
1833 int32_t tap_tick_delay;
1834 int32_t tap_gate_delay;
1835 int32_t tap_display_time;
1837 /* Tap-for-battery params */
1838 uint8_t tap_pct_red;
1839 uint8_t tap_pct_green;
1840 uint8_t tap_seg_min_on;
1841 uint8_t tap_seg_max_on;
1842 uint8_t tap_seg_osc;
1846 uint8_t osc_min[2]; /* AC=0/1 */
1847 uint8_t osc_max[2]; /* AC=0/1 */
1848 uint8_t w_ofs[2]; /* AC=0/1 */
1850 /* Brightness limits based on the backlight and AC. */
1851 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1852 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1853 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1855 /* Battery level thresholds */
1856 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1858 /* Map [AC][battery_level] to color index */
1859 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1860 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1862 /* s5: single color pulse on inhibited power-up */
1866 struct rgb_s color[8]; /* 0-3 are Google colors */
1869 /* Lightbar command params v2
1872 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1873 * logical groups to make it more manageable ( < 120 bytes).
1875 * NOTE: Each of these groups must be less than 120 bytes.
1878 struct lightbar_params_v2_timing {
1880 int32_t google_ramp_up;
1881 int32_t google_ramp_down;
1882 int32_t s3s0_ramp_up;
1883 int32_t s0_tick_delay[2]; /* AC=0/1 */
1884 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1885 int32_t s0s3_ramp_down;
1886 int32_t s3_sleep_for;
1888 int32_t s3_ramp_down;
1890 int32_t s5_ramp_down;
1891 int32_t tap_tick_delay;
1892 int32_t tap_gate_delay;
1893 int32_t tap_display_time;
1896 struct lightbar_params_v2_tap {
1897 /* Tap-for-battery params */
1898 uint8_t tap_pct_red;
1899 uint8_t tap_pct_green;
1900 uint8_t tap_seg_min_on;
1901 uint8_t tap_seg_max_on;
1902 uint8_t tap_seg_osc;
1906 struct lightbar_params_v2_oscillation {
1908 uint8_t osc_min[2]; /* AC=0/1 */
1909 uint8_t osc_max[2]; /* AC=0/1 */
1910 uint8_t w_ofs[2]; /* AC=0/1 */
1913 struct lightbar_params_v2_brightness {
1914 /* Brightness limits based on the backlight and AC. */
1915 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1916 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1917 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1920 struct lightbar_params_v2_thresholds {
1921 /* Battery level thresholds */
1922 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1925 struct lightbar_params_v2_colors {
1926 /* Map [AC][battery_level] to color index */
1927 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1928 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1930 /* s5: single color pulse on inhibited power-up */
1934 struct rgb_s color[8]; /* 0-3 are Google colors */
1937 /* Lightbar program. */
1938 #define EC_LB_PROG_LEN 192
1939 struct lightbar_program {
1941 uint8_t data[EC_LB_PROG_LEN];
1942 } __ec_todo_unpacked;
1944 struct ec_params_lightbar {
1945 uint8_t cmd; /* Command (see enum lightbar_command) */
1948 * The following commands have no args:
1950 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1951 * version, get_brightness, get_demo, suspend, resume,
1952 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
1953 * get_params_v2_bright, get_params_v2_thlds,
1954 * get_params_v2_colors
1956 * Don't use an empty struct, because C++ hates that.
1959 struct __ec_todo_unpacked {
1961 } set_brightness, seq, demo;
1963 struct __ec_todo_unpacked {
1964 uint8_t ctrl, reg, value;
1967 struct __ec_todo_unpacked {
1968 uint8_t led, red, green, blue;
1971 struct __ec_todo_unpacked {
1975 struct __ec_todo_unpacked {
1977 } manual_suspend_ctrl;
1979 struct lightbar_params_v0 set_params_v0;
1980 struct lightbar_params_v1 set_params_v1;
1982 struct lightbar_params_v2_timing set_v2par_timing;
1983 struct lightbar_params_v2_tap set_v2par_tap;
1984 struct lightbar_params_v2_oscillation set_v2par_osc;
1985 struct lightbar_params_v2_brightness set_v2par_bright;
1986 struct lightbar_params_v2_thresholds set_v2par_thlds;
1987 struct lightbar_params_v2_colors set_v2par_colors;
1989 struct lightbar_program set_program;
1993 struct ec_response_lightbar {
1995 struct __ec_todo_unpacked {
1996 struct __ec_todo_unpacked {
2003 struct __ec_todo_unpacked {
2005 } get_seq, get_brightness, get_demo;
2007 struct lightbar_params_v0 get_params_v0;
2008 struct lightbar_params_v1 get_params_v1;
2011 struct lightbar_params_v2_timing get_params_v2_timing;
2012 struct lightbar_params_v2_tap get_params_v2_tap;
2013 struct lightbar_params_v2_oscillation get_params_v2_osc;
2014 struct lightbar_params_v2_brightness get_params_v2_bright;
2015 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2016 struct lightbar_params_v2_colors get_params_v2_colors;
2018 struct __ec_todo_unpacked {
2023 struct __ec_todo_unpacked {
2024 uint8_t red, green, blue;
2028 * The following commands have no response:
2030 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2031 * set_params_v0, set_params_v1, set_program,
2032 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2033 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2034 * set_v2par_thlds, set_v2par_colors
2039 /* Lightbar commands */
2040 enum lightbar_command {
2041 LIGHTBAR_CMD_DUMP = 0,
2042 LIGHTBAR_CMD_OFF = 1,
2043 LIGHTBAR_CMD_ON = 2,
2044 LIGHTBAR_CMD_INIT = 3,
2045 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
2046 LIGHTBAR_CMD_SEQ = 5,
2047 LIGHTBAR_CMD_REG = 6,
2048 LIGHTBAR_CMD_SET_RGB = 7,
2049 LIGHTBAR_CMD_GET_SEQ = 8,
2050 LIGHTBAR_CMD_DEMO = 9,
2051 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2052 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
2053 LIGHTBAR_CMD_VERSION = 12,
2054 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2055 LIGHTBAR_CMD_GET_RGB = 14,
2056 LIGHTBAR_CMD_GET_DEMO = 15,
2057 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2058 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
2059 LIGHTBAR_CMD_SET_PROGRAM = 18,
2060 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2061 LIGHTBAR_CMD_SUSPEND = 20,
2062 LIGHTBAR_CMD_RESUME = 21,
2063 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2064 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2065 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2066 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2067 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2068 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2069 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2070 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2071 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2072 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2073 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2074 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
2078 /*****************************************************************************/
2079 /* LED control commands */
2081 #define EC_CMD_LED_CONTROL 0x0029
2084 /* LED to indicate battery state of charge */
2085 EC_LED_ID_BATTERY_LED = 0,
2087 * LED to indicate system power state (on or in suspend).
2088 * May be on power button or on C-panel.
2090 EC_LED_ID_POWER_LED,
2091 /* LED on power adapter or its plug */
2092 EC_LED_ID_ADAPTER_LED,
2093 /* LED to indicate left side */
2095 /* LED to indicate right side */
2096 EC_LED_ID_RIGHT_LED,
2097 /* LED to indicate recovery mode with HW_REINIT */
2098 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2099 /* LED to indicate sysrq debug mode. */
2100 EC_LED_ID_SYSRQ_DEBUG_LED,
2105 /* LED control flags */
2106 #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2107 #define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
2109 enum ec_led_colors {
2110 EC_LED_COLOR_RED = 0,
2113 EC_LED_COLOR_YELLOW,
2120 struct ec_params_led_control {
2121 uint8_t led_id; /* Which LED to control */
2122 uint8_t flags; /* Control flags */
2124 uint8_t brightness[EC_LED_COLOR_COUNT];
2127 struct ec_response_led_control {
2129 * Available brightness value range.
2131 * Range 0 means color channel not present.
2132 * Range 1 means on/off control.
2133 * Other values means the LED is control by PWM.
2135 uint8_t brightness_range[EC_LED_COLOR_COUNT];
2138 /*****************************************************************************/
2139 /* Verified boot commands */
2142 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2143 * reused for other purposes with version > 0.
2146 /* Verified boot hash command */
2147 #define EC_CMD_VBOOT_HASH 0x002A
2149 struct ec_params_vboot_hash {
2150 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2151 uint8_t hash_type; /* enum ec_vboot_hash_type */
2152 uint8_t nonce_size; /* Nonce size; may be 0 */
2153 uint8_t reserved0; /* Reserved; set 0 */
2154 uint32_t offset; /* Offset in flash to hash */
2155 uint32_t size; /* Number of bytes to hash */
2156 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
2159 struct ec_response_vboot_hash {
2160 uint8_t status; /* enum ec_vboot_hash_status */
2161 uint8_t hash_type; /* enum ec_vboot_hash_type */
2162 uint8_t digest_size; /* Size of hash digest in bytes */
2163 uint8_t reserved0; /* Ignore; will be 0 */
2164 uint32_t offset; /* Offset in flash which was hashed */
2165 uint32_t size; /* Number of bytes hashed */
2166 uint8_t hash_digest[64]; /* Hash digest data */
2169 enum ec_vboot_hash_cmd {
2170 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2171 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2172 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2173 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
2176 enum ec_vboot_hash_type {
2177 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
2180 enum ec_vboot_hash_status {
2181 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2182 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2183 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
2187 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2188 * If one of these is specified, the EC will automatically update offset and
2189 * size to the correct values for the specified image (RO or RW).
2191 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2192 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2193 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2196 * 'RW' is vague if there are multiple RW images; we mean the active one,
2197 * so the old constant is deprecated.
2199 #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
2201 /*****************************************************************************/
2203 * Motion sense commands. We'll make separate structs for sub-commands with
2204 * different input args, so that we know how much to expect.
2206 #define EC_CMD_MOTION_SENSE_CMD 0x002B
2208 /* Motion sense commands */
2209 enum motionsense_command {
2211 * Dump command returns all motion sensor data including motion sense
2212 * module flags and individual sensor flags.
2214 MOTIONSENSE_CMD_DUMP = 0,
2217 * Info command returns data describing the details of a given sensor,
2218 * including enum motionsensor_type, enum motionsensor_location, and
2219 * enum motionsensor_chip.
2221 MOTIONSENSE_CMD_INFO = 1,
2224 * EC Rate command is a setter/getter command for the EC sampling rate
2226 * It is per sensor, the EC run sample task at the minimum of all
2228 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2229 * to collect all the sensor samples.
2230 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2231 * to process of all motion sensors in milliseconds.
2233 MOTIONSENSE_CMD_EC_RATE = 2,
2236 * Sensor ODR command is a setter/getter command for the output data
2237 * rate of a specific motion sensor in millihertz.
2239 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2242 * Sensor range command is a setter/getter command for the range of
2243 * a specified motion sensor in +/-G's or +/- deg/s.
2245 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2248 * Setter/getter command for the keyboard wake angle. When the lid
2249 * angle is greater than this value, keyboard wake is disabled in S3,
2250 * and when the lid angle goes less than this value, keyboard wake is
2251 * enabled. Note, the lid angle measurement is an approximate,
2252 * un-calibrated value, hence the wake angle isn't exact.
2254 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2257 * Returns a single sensor data.
2259 MOTIONSENSE_CMD_DATA = 6,
2262 * Return sensor fifo info.
2264 MOTIONSENSE_CMD_FIFO_INFO = 7,
2267 * Insert a flush element in the fifo and return sensor fifo info.
2268 * The host can use that element to synchronize its operation.
2270 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2273 * Return a portion of the fifo.
2275 MOTIONSENSE_CMD_FIFO_READ = 9,
2278 * Perform low level calibration.
2279 * On sensors that support it, ask to do offset calibration.
2281 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2284 * Sensor Offset command is a setter/getter command for the offset
2285 * used for calibration.
2286 * The offsets can be calculated by the host, or via
2287 * PERFORM_CALIB command.
2289 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2292 * List available activities for a MOTION sensor.
2293 * Indicates if they are enabled or disabled.
2295 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2298 * Activity management
2299 * Enable/Disable activity recognition.
2301 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2306 MOTIONSENSE_CMD_LID_ANGLE = 14,
2309 * Allow the FIFO to trigger interrupt via MKBP events.
2310 * By default the FIFO does not send interrupt to process the FIFO
2311 * until the AP is ready or it is coming from a wakeup sensor.
2313 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2316 * Spoof the readings of the sensors. The spoofed readings can be set
2317 * to arbitrary values, or will lock to the last read actual values.
2319 MOTIONSENSE_CMD_SPOOF = 16,
2321 /* Set lid angle for tablet mode detection. */
2322 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2325 * Sensor Scale command is a setter/getter command for the calibration
2328 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2330 /* Number of motionsense sub-commands. */
2331 MOTIONSENSE_NUM_CMDS
2334 /* List of motion sensor types. */
2335 enum motionsensor_type {
2336 MOTIONSENSE_TYPE_ACCEL = 0,
2337 MOTIONSENSE_TYPE_GYRO = 1,
2338 MOTIONSENSE_TYPE_MAG = 2,
2339 MOTIONSENSE_TYPE_PROX = 3,
2340 MOTIONSENSE_TYPE_LIGHT = 4,
2341 MOTIONSENSE_TYPE_ACTIVITY = 5,
2342 MOTIONSENSE_TYPE_BARO = 6,
2343 MOTIONSENSE_TYPE_SYNC = 7,
2344 MOTIONSENSE_TYPE_MAX,
2347 /* List of motion sensor locations. */
2348 enum motionsensor_location {
2349 MOTIONSENSE_LOC_BASE = 0,
2350 MOTIONSENSE_LOC_LID = 1,
2351 MOTIONSENSE_LOC_CAMERA = 2,
2352 MOTIONSENSE_LOC_MAX,
2355 /* List of motion sensor chips. */
2356 enum motionsensor_chip {
2357 MOTIONSENSE_CHIP_KXCJ9 = 0,
2358 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2359 MOTIONSENSE_CHIP_BMI160 = 2,
2360 MOTIONSENSE_CHIP_SI1141 = 3,
2361 MOTIONSENSE_CHIP_SI1142 = 4,
2362 MOTIONSENSE_CHIP_SI1143 = 5,
2363 MOTIONSENSE_CHIP_KX022 = 6,
2364 MOTIONSENSE_CHIP_L3GD20H = 7,
2365 MOTIONSENSE_CHIP_BMA255 = 8,
2366 MOTIONSENSE_CHIP_BMP280 = 9,
2367 MOTIONSENSE_CHIP_OPT3001 = 10,
2368 MOTIONSENSE_CHIP_BH1730 = 11,
2369 MOTIONSENSE_CHIP_GPIO = 12,
2370 MOTIONSENSE_CHIP_LIS2DH = 13,
2371 MOTIONSENSE_CHIP_LSM6DSM = 14,
2372 MOTIONSENSE_CHIP_LIS2DE = 15,
2373 MOTIONSENSE_CHIP_LIS2MDL = 16,
2374 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2375 MOTIONSENSE_CHIP_LSM6DSO = 18,
2376 MOTIONSENSE_CHIP_LNG2DM = 19,
2377 MOTIONSENSE_CHIP_MAX,
2380 /* List of orientation positions */
2381 enum motionsensor_orientation {
2382 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2383 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2384 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2385 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2386 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
2389 struct ec_response_motion_sensor_data {
2390 /* Flags for each sensor. */
2392 /* Sensor number the data comes from. */
2394 /* Each sensor is up to 3-axis. */
2397 struct __ec_todo_packed {
2401 struct __ec_todo_unpacked {
2402 uint8_t activity; /* motionsensor_activity */
2404 int16_t add_info[2];
2409 /* Note: used in ec_response_get_next_data */
2410 struct ec_response_motion_sense_fifo_info {
2411 /* Size of the fifo */
2413 /* Amount of space used in the fifo */
2415 /* Timestamp recorded in us.
2416 * aka accurate timestamp when host event was triggered.
2419 /* Total amount of vector lost */
2420 uint16_t total_lost;
2421 /* Lost events since the last fifo_info, per sensors */
2425 struct ec_response_motion_sense_fifo_data {
2426 uint32_t number_data;
2427 struct ec_response_motion_sensor_data data[0];
2430 /* List supported activity recognition */
2431 enum motionsensor_activity {
2432 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2433 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2434 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2435 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
2438 struct ec_motion_sense_activity {
2440 uint8_t activity; /* one of enum motionsensor_activity */
2441 uint8_t enable; /* 1: enable, 0: disable */
2443 uint16_t parameters[3]; /* activity dependent parameters */
2444 } __ec_todo_unpacked;
2446 /* Module flag masks used for the dump sub-command. */
2447 #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
2449 /* Sensor flag masks used for the dump sub-command. */
2450 #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
2453 * Flush entry for synchronization.
2454 * data contains time stamp
2456 #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2457 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2458 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2459 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2460 #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
2463 * Send this value for the data element to only perform a read. If you
2464 * send any other value, the EC will interpret it as data to set and will
2465 * return the actual value set.
2467 #define EC_MOTION_SENSE_NO_VALUE -1
2469 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2471 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2472 /* Set Calibration information */
2473 #define MOTION_SENSE_SET_OFFSET BIT(0)
2475 /* Default Scale value, factor 1. */
2476 #define MOTION_SENSE_DEFAULT_SCALE BIT(15)
2478 #define LID_ANGLE_UNRELIABLE 500
2480 enum motionsense_spoof_mode {
2481 /* Disable spoof mode. */
2482 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2484 /* Enable spoof mode, but use provided component values. */
2485 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2487 /* Enable spoof mode, but use the current sensor values. */
2488 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2490 /* Query the current spoof mode status for the sensor. */
2491 MOTIONSENSE_SPOOF_MODE_QUERY,
2494 struct ec_params_motion_sense {
2497 /* Used for MOTIONSENSE_CMD_DUMP. */
2498 struct __ec_todo_unpacked {
2500 * Maximal number of sensor the host is expecting.
2501 * 0 means the host is only interested in the number
2502 * of sensors controlled by the EC.
2504 uint8_t max_sensor_count;
2508 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2510 struct __ec_todo_unpacked {
2511 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2512 * kb_wake_angle: angle to wakup AP.
2518 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2519 * and MOTIONSENSE_CMD_PERFORM_CALIB.
2521 struct __ec_todo_unpacked {
2523 } info, info_3, data, fifo_flush, perform_calib,
2527 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2528 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2530 struct __ec_todo_unpacked {
2533 /* Rounding flag, true for round-up, false for down. */
2538 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2540 } ec_rate, sensor_odr, sensor_range;
2542 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2543 struct __ec_todo_packed {
2547 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2548 * the calibration information in the EC.
2549 * If unset, just retrieve calibration information.
2554 * Temperature at calibration, in units of 0.01 C
2555 * 0x8000: invalid / unknown.
2562 * Offset for calibration.
2564 * Accelerometer: 1/1024 g
2565 * Gyro: 1/1024 deg/s
2571 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2572 struct __ec_todo_packed {
2576 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2577 * the calibration information in the EC.
2578 * If unset, just retrieve calibration information.
2583 * Temperature at calibration, in units of 0.01 C
2584 * 0x8000: invalid / unknown.
2591 * Scale for calibration:
2592 * By default scale is 1, it is encoded on 16bits:
2601 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
2604 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2605 struct __ec_todo_unpacked {
2607 * Number of expected vector to return.
2608 * EC may return less or 0 if none available.
2610 uint32_t max_data_vector;
2613 struct ec_motion_sense_activity set_activity;
2615 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2618 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2619 struct __ec_todo_unpacked {
2621 * 1: enable, 0 disable fifo,
2622 * EC_MOTION_SENSE_NO_VALUE return value.
2627 /* Used for MOTIONSENSE_CMD_SPOOF */
2628 struct __ec_todo_packed {
2631 /* See enum motionsense_spoof_mode. */
2632 uint8_t spoof_enable;
2634 /* Ignored, used for alignment. */
2637 /* Individual component values to spoof. */
2638 int16_t components[3];
2641 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2642 struct __ec_todo_unpacked {
2644 * Lid angle threshold for switching between tablet and
2650 * Hysteresis degree to prevent fluctuations between
2651 * clamshell and tablet mode if lid angle keeps
2652 * changing around the threshold. Lid motion driver will
2653 * use lid_angle + hys_degree to trigger tablet mode and
2654 * lid_angle - hys_degree to trigger clamshell mode.
2657 } tablet_mode_threshold;
2661 struct ec_response_motion_sense {
2663 /* Used for MOTIONSENSE_CMD_DUMP */
2664 struct __ec_todo_unpacked {
2665 /* Flags representing the motion sensor module. */
2666 uint8_t module_flags;
2668 /* Number of sensors managed directly by the EC. */
2669 uint8_t sensor_count;
2672 * Sensor data is truncated if response_max is too small
2673 * for holding all the data.
2675 struct ec_response_motion_sensor_data sensor[0];
2678 /* Used for MOTIONSENSE_CMD_INFO. */
2679 struct __ec_todo_unpacked {
2680 /* Should be element of enum motionsensor_type. */
2683 /* Should be element of enum motionsensor_location. */
2686 /* Should be element of enum motionsensor_chip. */
2690 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2691 struct __ec_todo_unpacked {
2692 /* Should be element of enum motionsensor_type. */
2695 /* Should be element of enum motionsensor_location. */
2698 /* Should be element of enum motionsensor_chip. */
2701 /* Minimum sensor sampling frequency */
2702 uint32_t min_frequency;
2704 /* Maximum sensor sampling frequency */
2705 uint32_t max_frequency;
2707 /* Max number of sensor events that could be in fifo */
2708 uint32_t fifo_max_event_count;
2711 /* Used for MOTIONSENSE_CMD_DATA */
2712 struct ec_response_motion_sensor_data data;
2715 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2716 * MOTIONSENSE_CMD_SENSOR_RANGE,
2717 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2718 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2719 * MOTIONSENSE_CMD_SPOOF.
2721 struct __ec_todo_unpacked {
2722 /* Current value of the parameter queried. */
2724 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2725 fifo_int_enable, spoof;
2728 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2731 struct __ec_todo_unpacked {
2734 } sensor_offset, perform_calib;
2736 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2737 struct __ec_todo_unpacked {
2742 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2744 struct ec_response_motion_sense_fifo_data fifo_read;
2746 struct __ec_todo_packed {
2752 /* No params for set activity */
2754 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2755 struct __ec_todo_unpacked {
2757 * Angle between 0 and 360 degree if available,
2758 * LID_ANGLE_UNRELIABLE otherwise.
2763 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2764 struct __ec_todo_unpacked {
2766 * Lid angle threshold for switching between tablet and
2771 /* Hysteresis degree. */
2772 uint16_t hys_degree;
2773 } tablet_mode_threshold;
2778 /*****************************************************************************/
2779 /* Force lid open command */
2781 /* Make lid event always open */
2782 #define EC_CMD_FORCE_LID_OPEN 0x002C
2784 struct ec_params_force_lid_open {
2788 /*****************************************************************************/
2789 /* Configure the behavior of the power button */
2790 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2792 enum ec_config_power_button_flags {
2793 /* Enable/Disable power button pulses for x86 devices */
2794 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
2797 struct ec_params_config_power_button {
2798 /* See enum ec_config_power_button_flags */
2802 /*****************************************************************************/
2803 /* USB charging control commands */
2805 /* Set USB port charging mode */
2806 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2808 struct ec_params_usb_charge_set_mode {
2809 uint8_t usb_port_id;
2811 uint8_t inhibit_charge:1;
2814 /*****************************************************************************/
2815 /* Persistent storage for host */
2817 /* Maximum bytes that can be read/written in a single command */
2818 #define EC_PSTORE_SIZE_MAX 64
2820 /* Get persistent storage info */
2821 #define EC_CMD_PSTORE_INFO 0x0040
2823 struct ec_response_pstore_info {
2824 /* Persistent storage size, in bytes */
2825 uint32_t pstore_size;
2826 /* Access size; read/write offset and size must be a multiple of this */
2827 uint32_t access_size;
2831 * Read persistent storage
2833 * Response is params.size bytes of data.
2835 #define EC_CMD_PSTORE_READ 0x0041
2837 struct ec_params_pstore_read {
2838 uint32_t offset; /* Byte offset to read */
2839 uint32_t size; /* Size to read in bytes */
2842 /* Write persistent storage */
2843 #define EC_CMD_PSTORE_WRITE 0x0042
2845 struct ec_params_pstore_write {
2846 uint32_t offset; /* Byte offset to write */
2847 uint32_t size; /* Size to write in bytes */
2848 uint8_t data[EC_PSTORE_SIZE_MAX];
2851 /*****************************************************************************/
2852 /* Real-time clock */
2854 /* RTC params and response structures */
2855 struct ec_params_rtc {
2859 struct ec_response_rtc {
2863 /* These use ec_response_rtc */
2864 #define EC_CMD_RTC_GET_VALUE 0x0044
2865 #define EC_CMD_RTC_GET_ALARM 0x0045
2867 /* These all use ec_params_rtc */
2868 #define EC_CMD_RTC_SET_VALUE 0x0046
2869 #define EC_CMD_RTC_SET_ALARM 0x0047
2871 /* Pass as time param to SET_ALARM to clear the current alarm */
2872 #define EC_RTC_ALARM_CLEAR 0
2874 /*****************************************************************************/
2875 /* Port80 log access */
2877 /* Maximum entries that can be read/written in a single command */
2878 #define EC_PORT80_SIZE_MAX 32
2880 /* Get last port80 code from previous boot */
2881 #define EC_CMD_PORT80_LAST_BOOT 0x0048
2882 #define EC_CMD_PORT80_READ 0x0048
2884 enum ec_port80_subcmd {
2885 EC_PORT80_GET_INFO = 0,
2886 EC_PORT80_READ_BUFFER,
2889 struct ec_params_port80_read {
2892 struct __ec_todo_unpacked {
2894 uint32_t num_entries;
2899 struct ec_response_port80_read {
2901 struct __ec_todo_unpacked {
2903 uint32_t history_size;
2906 struct __ec_todo_unpacked {
2907 uint16_t codes[EC_PORT80_SIZE_MAX];
2912 struct ec_response_port80_last_boot {
2916 /*****************************************************************************/
2917 /* Temporary secure storage for host verified boot use */
2919 /* Number of bytes in a vstore slot */
2920 #define EC_VSTORE_SLOT_SIZE 64
2922 /* Maximum number of vstore slots */
2923 #define EC_VSTORE_SLOT_MAX 32
2925 /* Get persistent storage info */
2926 #define EC_CMD_VSTORE_INFO 0x0049
2927 struct ec_response_vstore_info {
2928 /* Indicates which slots are locked */
2929 uint32_t slot_locked;
2930 /* Total number of slots available */
2935 * Read temporary secure storage
2937 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2939 #define EC_CMD_VSTORE_READ 0x004A
2941 struct ec_params_vstore_read {
2942 uint8_t slot; /* Slot to read from */
2945 struct ec_response_vstore_read {
2946 uint8_t data[EC_VSTORE_SLOT_SIZE];
2950 * Write temporary secure storage and lock it.
2952 #define EC_CMD_VSTORE_WRITE 0x004B
2954 struct ec_params_vstore_write {
2955 uint8_t slot; /* Slot to write to */
2956 uint8_t data[EC_VSTORE_SLOT_SIZE];
2959 /*****************************************************************************/
2960 /* Thermal engine commands. Note that there are two implementations. We'll
2961 * reuse the command number, but the data and behavior is incompatible.
2962 * Version 0 is what originally shipped on Link.
2963 * Version 1 separates the CPU thermal limits from the fan control.
2966 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2967 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
2969 /* The version 0 structs are opaque. You have to know what they are for
2970 * the get/set commands to make any sense.
2973 /* Version 0 - set */
2974 struct ec_params_thermal_set_threshold {
2975 uint8_t sensor_type;
2976 uint8_t threshold_id;
2980 /* Version 0 - get */
2981 struct ec_params_thermal_get_threshold {
2982 uint8_t sensor_type;
2983 uint8_t threshold_id;
2986 struct ec_response_thermal_get_threshold {
2991 /* The version 1 structs are visible. */
2992 enum ec_temp_thresholds {
2993 EC_TEMP_THRESH_WARN = 0,
2994 EC_TEMP_THRESH_HIGH,
2995 EC_TEMP_THRESH_HALT,
2997 EC_TEMP_THRESH_COUNT
3001 * Thermal configuration for one temperature sensor. Temps are in degrees K.
3002 * Zero values will be silently ignored by the thermal task.
3004 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3007 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3008 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3009 * EC will throttle ap when temperature >= 301 K, and release throttling when
3010 * temperature <= 299 K.
3012 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3014 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3015 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3016 * EC will throttle ap when temperature >= 301 K, and release throttling when
3017 * temperature <= 294 K.
3019 * Note that this structure is a sub-structure of
3020 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
3022 struct ec_thermal_config {
3023 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
3024 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
3025 uint32_t temp_fan_off; /* no active cooling needed */
3026 uint32_t temp_fan_max; /* max active cooling needed */
3029 /* Version 1 - get config for one sensor. */
3030 struct ec_params_thermal_get_threshold_v1 {
3031 uint32_t sensor_num;
3033 /* This returns a struct ec_thermal_config */
3036 * Version 1 - set config for one sensor.
3037 * Use read-modify-write for best results!
3039 struct ec_params_thermal_set_threshold_v1 {
3040 uint32_t sensor_num;
3041 struct ec_thermal_config cfg;
3043 /* This returns no data */
3045 /****************************************************************************/
3047 /* Toggle automatic fan control */
3048 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
3050 /* Version 1 of input params */
3051 struct ec_params_auto_fan_ctrl_v1 {
3055 /* Get/Set TMP006 calibration data */
3056 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3057 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
3060 * The original TMP006 calibration only needed four params, but now we need
3061 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3062 * the params opaque. The v1 "get" response will include the algorithm number
3063 * and how many params it requires. That way we can change the EC code without
3064 * needing to update this file. We can also use a different algorithm on each
3068 /* This is the same struct for both v0 and v1. */
3069 struct ec_params_tmp006_get_calibration {
3074 struct ec_response_tmp006_get_calibration_v0 {
3081 struct ec_params_tmp006_set_calibration_v0 {
3083 uint8_t reserved[3];
3091 struct ec_response_tmp006_get_calibration_v1 {
3094 uint8_t reserved[2];
3098 struct ec_params_tmp006_set_calibration_v1 {
3107 /* Read raw TMP006 data */
3108 #define EC_CMD_TMP006_GET_RAW 0x0055
3110 struct ec_params_tmp006_get_raw {
3114 struct ec_response_tmp006_get_raw {
3115 int32_t t; /* In 1/100 K */
3116 int32_t v; /* In nV */
3119 /*****************************************************************************/
3120 /* MKBP - Matrix KeyBoard Protocol */
3125 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3126 * expected response size.
3128 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3129 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3130 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
3132 #define EC_CMD_MKBP_STATE 0x0060
3135 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3137 #define EC_CMD_MKBP_INFO 0x0061
3139 struct ec_response_mkbp_info {
3142 /* Formerly "switches", which was 0. */
3146 struct ec_params_mkbp_info {
3151 enum ec_mkbp_info_type {
3153 * Info about the keyboard matrix: number of rows and columns.
3155 * Returns struct ec_response_mkbp_info.
3157 EC_MKBP_INFO_KBD = 0,
3160 * For buttons and switches, info about which specifically are
3161 * supported. event_type must be set to one of the values in enum
3164 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3165 * bitmask indicating which buttons or switches are present. See the
3166 * bit inidices below.
3168 EC_MKBP_INFO_SUPPORTED = 1,
3171 * Instantaneous state of buttons and switches.
3173 * event_type must be set to one of the values in enum ec_mkbp_event.
3175 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3176 * indicating the current state of the keyboard matrix.
3178 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3181 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3182 * state of supported buttons.
3184 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3185 * state of supported switches.
3187 EC_MKBP_INFO_CURRENT = 2,
3190 /* Simulate key press */
3191 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
3193 struct ec_params_mkbp_simulate_key {
3199 #define EC_CMD_GET_KEYBOARD_ID 0x0063
3201 struct ec_response_keyboard_id {
3202 uint32_t keyboard_id;
3206 KEYBOARD_ID_UNSUPPORTED = 0,
3207 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3210 /* Configure keyboard scanning */
3211 #define EC_CMD_MKBP_SET_CONFIG 0x0064
3212 #define EC_CMD_MKBP_GET_CONFIG 0x0065
3215 enum mkbp_config_flags {
3216 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3219 enum mkbp_config_valid {
3220 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3221 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3222 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3223 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3224 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3225 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3226 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
3230 * Configuration for our key scanning algorithm.
3232 * Note that this is used as a sub-structure of
3233 * ec_{params/response}_mkbp_get_config.
3235 struct ec_mkbp_config {
3236 uint32_t valid_mask; /* valid fields */
3237 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3238 uint8_t valid_flags; /* which flags are valid */
3239 uint16_t scan_period_us; /* period between start of scans */
3240 /* revert to interrupt mode after no activity for this long */
3241 uint32_t poll_timeout_us;
3243 * minimum post-scan relax time. Once we finish a scan we check
3244 * the time until we are due to start the next one. If this time is
3245 * shorter this field, we use this instead.
3247 uint16_t min_post_scan_delay_us;
3248 /* delay between setting up output and waiting for it to settle */
3249 uint16_t output_settle_us;
3250 uint16_t debounce_down_us; /* time for debounce on key down */
3251 uint16_t debounce_up_us; /* time for debounce on key up */
3252 /* maximum depth to allow for fifo (0 = no keyscan output) */
3253 uint8_t fifo_max_depth;
3256 struct ec_params_mkbp_set_config {
3257 struct ec_mkbp_config config;
3260 struct ec_response_mkbp_get_config {
3261 struct ec_mkbp_config config;
3264 /* Run the key scan emulation */
3265 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
3267 enum ec_keyscan_seq_cmd {
3268 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3269 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3270 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3271 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3272 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3275 enum ec_collect_flags {
3277 * Indicates this scan was processed by the EC. Due to timing, some
3278 * scans may be skipped.
3280 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
3283 struct ec_collect_item {
3284 uint8_t flags; /* some flags (enum ec_collect_flags) */
3287 struct ec_params_keyscan_seq_ctrl {
3288 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3290 struct __ec_align1 {
3291 uint8_t active; /* still active */
3292 uint8_t num_items; /* number of items */
3293 /* Current item being presented */
3296 struct __ec_todo_unpacked {
3298 * Absolute time for this scan, measured from the
3299 * start of the sequence.
3302 uint8_t scan[0]; /* keyscan data */
3304 struct __ec_align1 {
3305 uint8_t start_item; /* First item to return */
3306 uint8_t num_items; /* Number of items to return */
3311 struct ec_result_keyscan_seq_ctrl {
3313 struct __ec_todo_unpacked {
3314 uint8_t num_items; /* Number of items */
3315 /* Data for each item */
3316 struct ec_collect_item item[0];
3322 * Get the next pending MKBP event.
3324 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3326 #define EC_CMD_GET_NEXT_EVENT 0x0067
3328 #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3331 * We use the most significant bit of the event type to indicate to the host
3332 * that the EC has more MKBP events available to provide.
3334 #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3336 /* The mask to apply to get the raw event type */
3337 #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3339 enum ec_mkbp_event {
3340 /* Keyboard matrix changed. The event data is the new matrix state. */
3341 EC_MKBP_EVENT_KEY_MATRIX = 0,
3343 /* New host event. The event data is 4 bytes of host event flags. */
3344 EC_MKBP_EVENT_HOST_EVENT = 1,
3346 /* New Sensor FIFO data. The event data is fifo_info structure. */
3347 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3349 /* The state of the non-matrixed buttons have changed. */
3350 EC_MKBP_EVENT_BUTTON = 3,
3352 /* The state of the switches have changed. */
3353 EC_MKBP_EVENT_SWITCH = 4,
3355 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3356 EC_MKBP_EVENT_FINGERPRINT = 5,
3359 * Sysrq event: send emulated sysrq. The event data is sysrq,
3360 * corresponding to the key to be pressed.
3362 EC_MKBP_EVENT_SYSRQ = 6,
3365 * New 64-bit host event.
3366 * The event data is 8 bytes of host event flags.
3368 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3370 /* Notify the AP that something happened on CEC */
3371 EC_MKBP_EVENT_CEC_EVENT = 8,
3373 /* Send an incoming CEC message to the AP */
3374 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3376 /* Number of MKBP events */
3377 EC_MKBP_EVENT_COUNT,
3379 BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
3381 union __ec_align_offset1 ec_response_get_next_data {
3382 uint8_t key_matrix[13];
3385 uint32_t host_event;
3386 uint64_t host_event64;
3388 struct __ec_todo_unpacked {
3389 /* For aligning the fifo_info */
3390 uint8_t reserved[3];
3391 struct ec_response_motion_sense_fifo_info info;
3402 /* CEC events from enum mkbp_cec_event */
3403 uint32_t cec_events;
3406 union __ec_align_offset1 ec_response_get_next_data_v1 {
3407 uint8_t key_matrix[16];
3410 uint32_t host_event;
3411 uint64_t host_event64;
3413 struct __ec_todo_unpacked {
3414 /* For aligning the fifo_info */
3415 uint8_t reserved[3];
3416 struct ec_response_motion_sense_fifo_info info;
3427 /* CEC events from enum mkbp_cec_event */
3428 uint32_t cec_events;
3430 uint8_t cec_message[16];
3432 BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
3434 struct ec_response_get_next_event {
3436 /* Followed by event data if any */
3437 union ec_response_get_next_data data;
3440 struct ec_response_get_next_event_v1 {
3442 /* Followed by event data if any */
3443 union ec_response_get_next_data_v1 data;
3446 /* Bit indices for buttons and switches.*/
3448 #define EC_MKBP_POWER_BUTTON 0
3449 #define EC_MKBP_VOL_UP 1
3450 #define EC_MKBP_VOL_DOWN 2
3451 #define EC_MKBP_RECOVERY 3
3454 #define EC_MKBP_LID_OPEN 0
3455 #define EC_MKBP_TABLET_MODE 1
3456 #define EC_MKBP_BASE_ATTACHED 2
3458 /* Run keyboard factory test scanning */
3459 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3461 struct ec_response_keyboard_factory_test {
3462 uint16_t shorted; /* Keyboard pins are shorted */
3465 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3466 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3467 #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3468 #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3469 #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3470 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3471 #define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3472 #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3473 #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3474 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
3475 #define EC_MKBP_FP_ENROLL BIT(27)
3476 #define EC_MKBP_FP_MATCH BIT(28)
3477 #define EC_MKBP_FP_FINGER_DOWN BIT(29)
3478 #define EC_MKBP_FP_FINGER_UP BIT(30)
3479 #define EC_MKBP_FP_IMAGE_READY BIT(31)
3480 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3481 #define EC_MKBP_FP_ERR_ENROLL_OK 0
3482 #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3483 #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3484 #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3485 #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3486 /* Can be used to detect if image was usable for enrollment or not. */
3487 #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3488 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3489 #define EC_MKBP_FP_ERR_MATCH_NO 0
3490 #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
3491 #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
3492 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3493 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3494 #define EC_MKBP_FP_ERR_MATCH_YES 1
3495 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3496 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3499 /*****************************************************************************/
3500 /* Temperature sensor commands */
3502 /* Read temperature sensor info */
3503 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
3505 struct ec_params_temp_sensor_get_info {
3509 struct ec_response_temp_sensor_get_info {
3510 char sensor_name[32];
3511 uint8_t sensor_type;
3514 /*****************************************************************************/
3517 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3518 * commands accidentally sent to the wrong interface. See the ACPI section
3522 /*****************************************************************************/
3523 /* Host event commands */
3526 /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
3528 * Host event mask params and response structures, shared by all of the host
3529 * event commands below.
3531 struct ec_params_host_event_mask {
3535 struct ec_response_host_event_mask {
3539 /* These all use ec_response_host_event_mask */
3540 #define EC_CMD_HOST_EVENT_GET_B 0x0087
3541 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3542 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3543 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
3545 /* These all use ec_params_host_event_mask */
3546 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3547 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3548 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
3549 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3550 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3553 * Unified host event programming interface - Should be used by newer versions
3554 * of BIOS/OS to program host events and masks
3557 struct ec_params_host_event {
3559 /* Action requested by host - one of enum ec_host_event_action. */
3563 * Mask type that the host requested the action on - one of
3564 * enum ec_host_event_mask_type.
3568 /* Set to 0, ignore on read */
3571 /* Value to be used in case of set operations. */
3576 * Response structure returned by EC_CMD_HOST_EVENT.
3577 * Update the value on a GET request. Set to 0 on GET/CLEAR
3580 struct ec_response_host_event {
3582 /* Mask value in case of get operation */
3586 enum ec_host_event_action {
3588 * params.value is ignored. Value of mask_type populated
3593 /* Bits in params.value are set */
3596 /* Bits in params.value are cleared */
3597 EC_HOST_EVENT_CLEAR,
3600 enum ec_host_event_mask_type {
3602 /* Main host event copy */
3605 /* Copy B of host events */
3609 EC_HOST_EVENT_SCI_MASK,
3612 EC_HOST_EVENT_SMI_MASK,
3614 /* Mask of events that should be always reported in hostevents */
3615 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3617 /* Active wake mask */
3618 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3620 /* Lazy wake mask for S0ix */
3621 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3623 /* Lazy wake mask for S3 */
3624 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3626 /* Lazy wake mask for S5 */
3627 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3630 #define EC_CMD_HOST_EVENT 0x00A4
3632 /*****************************************************************************/
3633 /* Switch commands */
3635 /* Enable/disable LCD backlight */
3636 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
3638 struct ec_params_switch_enable_backlight {
3642 /* Enable/disable WLAN/Bluetooth */
3643 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
3644 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
3646 /* Version 0 params; no response */
3647 struct ec_params_switch_enable_wireless_v0 {
3651 /* Version 1 params */
3652 struct ec_params_switch_enable_wireless_v1 {
3653 /* Flags to enable now */
3656 /* Which flags to copy from now_flags */
3660 * Flags to leave enabled in S3, if they're on at the S0->S3
3661 * transition. (Other flags will be disabled by the S0->S3
3664 uint8_t suspend_flags;
3666 /* Which flags to copy from suspend_flags */
3667 uint8_t suspend_mask;
3670 /* Version 1 response */
3671 struct ec_response_switch_enable_wireless_v1 {
3672 /* Flags to enable now */
3675 /* Flags to leave enabled in S3 */
3676 uint8_t suspend_flags;
3679 /*****************************************************************************/
3680 /* GPIO commands. Only available on EC if write protect has been disabled. */
3682 /* Set GPIO output value */
3683 #define EC_CMD_GPIO_SET 0x0092
3685 struct ec_params_gpio_set {
3690 /* Get GPIO value */
3691 #define EC_CMD_GPIO_GET 0x0093
3693 /* Version 0 of input params and response */
3694 struct ec_params_gpio_get {
3698 struct ec_response_gpio_get {
3702 /* Version 1 of input params and response */
3703 struct ec_params_gpio_get_v1 {
3706 struct __ec_align1 {
3708 } get_value_by_name;
3709 struct __ec_align1 {
3715 struct ec_response_gpio_get_v1 {
3717 struct __ec_align1 {
3719 } get_value_by_name, get_count;
3720 struct __ec_todo_unpacked {
3728 enum gpio_get_subcmd {
3729 EC_GPIO_GET_BY_NAME = 0,
3730 EC_GPIO_GET_COUNT = 1,
3731 EC_GPIO_GET_INFO = 2,
3734 /*****************************************************************************/
3735 /* I2C commands. Only available when flash write protect is unlocked. */
3738 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3739 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3741 * Use EC_CMD_I2C_PASSTHRU instead.
3745 #define EC_CMD_I2C_READ 0x0094
3747 struct ec_params_i2c_read {
3748 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3749 uint8_t read_size; /* Either 8 or 16. */
3754 struct ec_response_i2c_read {
3759 #define EC_CMD_I2C_WRITE 0x0095
3761 struct ec_params_i2c_write {
3763 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3764 uint8_t write_size; /* Either 8 or 16. */
3769 /*****************************************************************************/
3770 /* Charge state commands. Only available when flash write protect unlocked. */
3772 /* Force charge state machine to stop charging the battery or force it to
3773 * discharge the battery.
3775 #define EC_CMD_CHARGE_CONTROL 0x0096
3776 #define EC_VER_CHARGE_CONTROL 1
3778 enum ec_charge_control_mode {
3779 CHARGE_CONTROL_NORMAL = 0,
3780 CHARGE_CONTROL_IDLE,
3781 CHARGE_CONTROL_DISCHARGE,
3784 struct ec_params_charge_control {
3785 uint32_t mode; /* enum charge_control_mode */
3788 /*****************************************************************************/
3790 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
3791 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
3794 * Read data from the saved snapshot. If the subcmd parameter is
3795 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3796 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3797 * end of the previous snapshot.
3799 * The params are only looked at in version >= 1 of this command. Prior
3800 * versions will just default to CONSOLE_READ_NEXT behavior.
3802 * Response is null-terminated string. Empty string, if there is no more
3805 #define EC_CMD_CONSOLE_READ 0x0098
3807 enum ec_console_read_subcmd {
3808 CONSOLE_READ_NEXT = 0,
3812 struct ec_params_console_read_v1 {
3813 uint8_t subcmd; /* enum ec_console_read_subcmd */
3816 /*****************************************************************************/
3819 * Cut off battery power immediately or after the host has shut down.
3821 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3822 * EC_RES_SUCCESS if the command was successful.
3823 * EC_RES_ERROR if the cut off command failed.
3825 #define EC_CMD_BATTERY_CUT_OFF 0x0099
3827 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
3829 struct ec_params_battery_cutoff {
3833 /*****************************************************************************/
3834 /* USB port mux control. */
3837 * Switch USB mux or return to automatic switching.
3839 #define EC_CMD_USB_MUX 0x009A
3841 struct ec_params_usb_mux {
3845 /*****************************************************************************/
3846 /* LDOs / FETs control. */
3849 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3850 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3854 * Switch on/off a LDO.
3856 #define EC_CMD_LDO_SET 0x009B
3858 struct ec_params_ldo_set {
3866 #define EC_CMD_LDO_GET 0x009C
3868 struct ec_params_ldo_get {
3872 struct ec_response_ldo_get {
3876 /*****************************************************************************/
3882 #define EC_CMD_POWER_INFO 0x009D
3884 struct ec_response_power_info {
3885 uint32_t usb_dev_type;
3886 uint16_t voltage_ac;
3887 uint16_t voltage_system;
3888 uint16_t current_system;
3889 uint16_t usb_current_limit;
3892 /*****************************************************************************/
3893 /* I2C passthru command */
3895 #define EC_CMD_I2C_PASSTHRU 0x009E
3897 /* Read data; if not present, message is a write */
3898 #define EC_I2C_FLAG_READ BIT(15)
3900 /* Mask for address */
3901 #define EC_I2C_ADDR_MASK 0x3ff
3903 #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
3904 #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
3907 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3909 struct ec_params_i2c_passthru_msg {
3910 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3911 uint16_t len; /* Number of bytes to read or write */
3914 struct ec_params_i2c_passthru {
3915 uint8_t port; /* I2C port number */
3916 uint8_t num_msgs; /* Number of messages */
3917 struct ec_params_i2c_passthru_msg msg[];
3918 /* Data to write for all messages is concatenated here */
3921 struct ec_response_i2c_passthru {
3922 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3923 uint8_t num_msgs; /* Number of messages processed */
3924 uint8_t data[]; /* Data read by messages concatenated here */
3927 /*****************************************************************************/
3928 /* Power button hang detect */
3930 #define EC_CMD_HANG_DETECT 0x009F
3932 /* Reasons to start hang detection timer */
3933 /* Power button pressed */
3934 #define EC_HANG_START_ON_POWER_PRESS BIT(0)
3937 #define EC_HANG_START_ON_LID_CLOSE BIT(1)
3940 #define EC_HANG_START_ON_LID_OPEN BIT(2)
3942 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
3943 #define EC_HANG_START_ON_RESUME BIT(3)
3945 /* Reasons to cancel hang detection */
3947 /* Power button released */
3948 #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
3950 /* Any host command from AP received */
3951 #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
3953 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3954 #define EC_HANG_STOP_ON_SUSPEND BIT(10)
3957 * If this flag is set, all the other fields are ignored, and the hang detect
3958 * timer is started. This provides the AP a way to start the hang timer
3959 * without reconfiguring any of the other hang detect settings. Note that
3960 * you must previously have configured the timeouts.
3962 #define EC_HANG_START_NOW BIT(30)
3965 * If this flag is set, all the other fields are ignored (including
3966 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3967 * without reconfiguring any of the other hang detect settings.
3969 #define EC_HANG_STOP_NOW BIT(31)
3971 struct ec_params_hang_detect {
3972 /* Flags; see EC_HANG_* */
3975 /* Timeout in msec before generating host event, if enabled */
3976 uint16_t host_event_timeout_msec;
3978 /* Timeout in msec before generating warm reboot, if enabled */
3979 uint16_t warm_reboot_timeout_msec;
3982 /*****************************************************************************/
3983 /* Commands for battery charging */
3986 * This is the single catch-all host command to exchange data regarding the
3987 * charge state machine (v2 and up).
3989 #define EC_CMD_CHARGE_STATE 0x00A0
3991 /* Subcommands for this host command */
3992 enum charge_state_command {
3993 CHARGE_STATE_CMD_GET_STATE,
3994 CHARGE_STATE_CMD_GET_PARAM,
3995 CHARGE_STATE_CMD_SET_PARAM,
3996 CHARGE_STATE_NUM_CMDS
4000 * Known param numbers are defined here. Ranges are reserved for board-specific
4001 * params, which are handled by the particular implementations.
4003 enum charge_state_params {
4004 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4005 CS_PARAM_CHG_CURRENT, /* charger current limit */
4006 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4007 CS_PARAM_CHG_STATUS, /* charger-specific status */
4008 CS_PARAM_CHG_OPTION, /* charger-specific options */
4009 CS_PARAM_LIMIT_POWER, /*
4010 * Check if power is limited due to
4011 * low battery and / or a weak external
4012 * charger. READ ONLY.
4014 /* How many so far? */
4017 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4018 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4019 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4021 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4022 CS_PARAM_DEBUG_MIN = 0x20000,
4023 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4024 CS_PARAM_DEBUG_MANUAL_MODE,
4025 CS_PARAM_DEBUG_SEEMS_DEAD,
4026 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4027 CS_PARAM_DEBUG_BATT_REMOVED,
4028 CS_PARAM_DEBUG_MANUAL_CURRENT,
4029 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4030 CS_PARAM_DEBUG_MAX = 0x2ffff,
4032 /* Other custom param ranges go here... */
4035 struct ec_params_charge_state {
4036 uint8_t cmd; /* enum charge_state_command */
4038 /* get_state has no args */
4040 struct __ec_todo_unpacked {
4041 uint32_t param; /* enum charge_state_param */
4044 struct __ec_todo_unpacked {
4045 uint32_t param; /* param to set */
4046 uint32_t value; /* value to set */
4051 struct ec_response_charge_state {
4053 struct __ec_align4 {
4057 int chg_input_current;
4058 int batt_state_of_charge;
4061 struct __ec_align4 {
4065 /* set_param returns no args */
4071 * Set maximum battery charging current.
4073 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
4075 struct ec_params_current_limit {
4076 uint32_t limit; /* in mA */
4080 * Set maximum external voltage / current.
4082 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
4084 /* Command v0 is used only on Spring and is obsolete + unsupported */
4085 struct ec_params_external_power_limit_v1 {
4086 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4087 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
4090 #define EC_POWER_LIMIT_NONE 0xffff
4093 * Set maximum voltage & current of a dedicated charge port
4095 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4097 struct ec_params_dedicated_charger_limit {
4098 uint16_t current_lim; /* in mA */
4099 uint16_t voltage_lim; /* in mV */
4102 /*****************************************************************************/
4103 /* Hibernate/Deep Sleep Commands */
4105 /* Set the delay before going into hibernation. */
4106 #define EC_CMD_HIBERNATION_DELAY 0x00A8
4108 struct ec_params_hibernation_delay {
4110 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4111 * current settings without changing them.
4116 struct ec_response_hibernation_delay {
4118 * The current time in seconds in which the system has been in the G3
4119 * state. This value is reset if the EC transitions out of G3.
4124 * The current time remaining in seconds until the EC should hibernate.
4125 * This value is also reset if the EC transitions out of G3.
4127 uint32_t time_remaining;
4130 * The current time in seconds that the EC should wait in G3 before
4133 uint32_t hibernate_delay;
4136 /* Inform the EC when entering a sleep state */
4137 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4139 enum host_sleep_event {
4140 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4141 HOST_SLEEP_EVENT_S3_RESUME = 2,
4142 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
4143 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4144 /* S3 suspend with additional enabled wake sources */
4145 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
4148 struct ec_params_host_sleep_event {
4149 uint8_t sleep_event;
4153 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4154 * transition failures
4156 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4158 /* Disable timeout detection for this sleep transition */
4159 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4161 struct ec_params_host_sleep_event_v1 {
4162 /* The type of sleep being entered or exited. */
4163 uint8_t sleep_event;
4168 /* Parameters that apply for suspend messages. */
4171 * The timeout in milliseconds between when this message
4172 * is received and when the EC will declare sleep
4173 * transition failure if the sleep signal is not
4176 uint16_t sleep_timeout_ms;
4179 /* No parameters for non-suspend messages. */
4183 /* A timeout occurred when this bit is set */
4184 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4187 * The mask defining which bits correspond to the number of sleep transitions,
4188 * as well as the maximum number of suspend line transitions that will be
4189 * reported back to the host.
4191 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4193 struct ec_response_host_sleep_event_v1 {
4195 /* Response fields that apply for resume messages. */
4198 * The number of sleep power signal transitions that
4199 * occurred since the suspend message. The high bit
4200 * indicates a timeout occurred.
4202 uint32_t sleep_transitions;
4205 /* No response fields for non-resume messages. */
4209 /*****************************************************************************/
4211 #define EC_CMD_DEVICE_EVENT 0x00AA
4213 enum ec_device_event {
4214 EC_DEVICE_EVENT_TRACKPAD,
4215 EC_DEVICE_EVENT_DSP,
4216 EC_DEVICE_EVENT_WIFI,
4219 enum ec_device_event_param {
4220 /* Get and clear pending device events */
4221 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4222 /* Get device event mask */
4223 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4224 /* Set device event mask */
4225 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4228 #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
4230 struct ec_params_device_event {
4231 uint32_t event_mask;
4235 struct ec_response_device_event {
4236 uint32_t event_mask;
4239 /*****************************************************************************/
4240 /* Smart battery pass-through */
4242 /* Get / Set 16-bit smart battery registers */
4243 #define EC_CMD_SB_READ_WORD 0x00B0
4244 #define EC_CMD_SB_WRITE_WORD 0x00B1
4246 /* Get / Set string smart battery parameters
4247 * formatted as SMBUS "block".
4249 #define EC_CMD_SB_READ_BLOCK 0x00B2
4250 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
4252 struct ec_params_sb_rd {
4256 struct ec_response_sb_rd_word {
4260 struct ec_params_sb_wr_word {
4265 struct ec_response_sb_rd_block {
4269 struct ec_params_sb_wr_block {
4274 /*****************************************************************************/
4275 /* Battery vendor parameters
4277 * Get or set vendor-specific parameters in the battery. Implementations may
4278 * differ between boards or batteries. On a set operation, the response
4279 * contains the actual value set, which may be rounded or clipped from the
4283 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
4285 enum ec_battery_vendor_param_mode {
4286 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4287 BATTERY_VENDOR_PARAM_MODE_SET,
4290 struct ec_params_battery_vendor_param {
4296 struct ec_response_battery_vendor_param {
4300 /*****************************************************************************/
4302 * Smart Battery Firmware Update Commands
4304 #define EC_CMD_SB_FW_UPDATE 0x00B5
4306 enum ec_sb_fw_update_subcmd {
4307 EC_SB_FW_UPDATE_PREPARE = 0x0,
4308 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4309 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4310 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4311 EC_SB_FW_UPDATE_END = 0x4,
4312 EC_SB_FW_UPDATE_STATUS = 0x5,
4313 EC_SB_FW_UPDATE_PROTECT = 0x6,
4314 EC_SB_FW_UPDATE_MAX = 0x7,
4317 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4318 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4319 #define SB_FW_UPDATE_CMD_INFO_SIZE 8
4321 struct ec_sb_fw_update_header {
4322 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4323 uint16_t fw_id; /* firmware id */
4326 struct ec_params_sb_fw_update {
4327 struct ec_sb_fw_update_header hdr;
4329 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4330 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4331 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4332 /* EC_SB_FW_UPDATE_END = 0x4 */
4333 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4334 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
4335 /* Those have no args */
4337 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
4338 struct __ec_align4 {
4339 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4344 struct ec_response_sb_fw_update {
4346 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4347 struct __ec_align1 {
4348 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4351 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4352 struct __ec_align1 {
4353 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4359 * Entering Verified Boot Mode Command
4360 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4361 * Valid Modes are: normal, developer, and recovery.
4363 #define EC_CMD_ENTERING_MODE 0x00B6
4365 struct ec_params_entering_mode {
4369 #define VBOOT_MODE_NORMAL 0
4370 #define VBOOT_MODE_DEVELOPER 1
4371 #define VBOOT_MODE_RECOVERY 2
4373 /*****************************************************************************/
4375 * I2C passthru protection command: Protects I2C tunnels against access on
4376 * certain addresses (board-specific).
4378 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
4380 enum ec_i2c_passthru_protect_subcmd {
4381 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
4382 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
4385 struct ec_params_i2c_passthru_protect {
4387 uint8_t port; /* I2C port number */
4390 struct ec_response_i2c_passthru_protect {
4391 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
4395 /*****************************************************************************/
4399 * These commands are for sending and receiving message via HDMI CEC
4402 #define MAX_CEC_MSG_LEN 16
4404 /* CEC message from the AP to be written on the CEC bus */
4405 #define EC_CMD_CEC_WRITE_MSG 0x00B8
4408 * struct ec_params_cec_write - Message to write to the CEC bus
4409 * @msg: message content to write to the CEC bus
4411 struct ec_params_cec_write {
4412 uint8_t msg[MAX_CEC_MSG_LEN];
4415 /* Set various CEC parameters */
4416 #define EC_CMD_CEC_SET 0x00BA
4419 * struct ec_params_cec_set - CEC parameters set
4420 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4421 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4422 * or 1 to enable CEC functionality, in case cmd is
4423 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4424 * address between 0 and 15 or 0xff to unregister
4426 struct ec_params_cec_set {
4427 uint8_t cmd; /* enum cec_command */
4431 /* Read various CEC parameters */
4432 #define EC_CMD_CEC_GET 0x00BB
4435 * struct ec_params_cec_get - CEC parameters get
4436 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4438 struct ec_params_cec_get {
4439 uint8_t cmd; /* enum cec_command */
4443 * struct ec_response_cec_get - CEC parameters get response
4444 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4445 * disabled or 1 if CEC functionality is enabled,
4446 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4447 * configured logical address between 0 and 15 or 0xff if unregistered
4449 struct ec_response_cec_get {
4453 /* CEC parameters command */
4455 /* CEC reading, writing and events enable */
4457 /* CEC logical address */
4458 CEC_CMD_LOGICAL_ADDRESS,
4461 /* Events from CEC to AP */
4462 enum mkbp_cec_event {
4463 /* Outgoing message was acknowledged by a follower */
4464 EC_MKBP_CEC_SEND_OK = BIT(0),
4465 /* Outgoing message was not acknowledged */
4466 EC_MKBP_CEC_SEND_FAILED = BIT(1),
4469 /*****************************************************************************/
4471 /* Commands for I2S recording on audio codec. */
4473 #define EC_CMD_CODEC_I2S 0x00BC
4474 #define EC_WOV_I2S_SAMPLE_RATE 48000
4476 enum ec_codec_i2s_subcmd {
4477 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
4478 EC_CODEC_SET_GAIN = 0x1,
4479 EC_CODEC_GET_GAIN = 0x2,
4480 EC_CODEC_I2S_ENABLE = 0x3,
4481 EC_CODEC_I2S_SET_CONFIG = 0x4,
4482 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
4483 EC_CODEC_I2S_SET_BCLK = 0x6,
4484 EC_CODEC_I2S_SUBCMD_COUNT = 0x7,
4487 enum ec_sample_depth_value {
4488 EC_CODEC_SAMPLE_DEPTH_16 = 0,
4489 EC_CODEC_SAMPLE_DEPTH_24 = 1,
4492 enum ec_i2s_config {
4494 EC_DAI_FMT_RIGHT_J = 1,
4495 EC_DAI_FMT_LEFT_J = 2,
4496 EC_DAI_FMT_PCM_A = 3,
4497 EC_DAI_FMT_PCM_B = 4,
4498 EC_DAI_FMT_PCM_TDM = 5,
4502 * For subcommand EC_CODEC_GET_GAIN.
4504 struct __ec_align1 ec_codec_i2s_gain {
4509 struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
4510 int16_t ch0_delay; /* 0 to 496 */
4511 int16_t ch1_delay; /* -1 to 496 */
4512 uint8_t adjacent_to_ch0;
4513 uint8_t adjacent_to_ch1;
4516 struct __ec_todo_packed ec_param_codec_i2s {
4517 /* enum ec_codec_i2s_subcmd */
4521 * EC_CODEC_SET_SAMPLE_DEPTH
4522 * Value should be one of ec_sample_depth_value.
4528 * Value should be 0~43 for both channels.
4530 struct ec_codec_i2s_gain gain;
4533 * EC_CODEC_I2S_ENABLE
4534 * 1 to enable, 0 to disable.
4539 * EC_CODEC_I2S_SET_CONFIG
4540 * Value should be one of ec_i2s_config.
4545 * EC_CODEC_I2S_SET_TDM_CONFIG
4546 * Value should be one of ec_i2s_config.
4548 struct ec_param_codec_i2s_tdm tdm_param;
4551 * EC_CODEC_I2S_SET_BCLK
4558 /*****************************************************************************/
4559 /* System commands */
4562 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
4563 * necessarily reboot the EC. Rename to "image" or something similar?
4565 #define EC_CMD_REBOOT_EC 0x00D2
4568 enum ec_reboot_cmd {
4569 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
4570 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
4571 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
4572 /* (command 3 was jump to RW-B) */
4573 EC_REBOOT_COLD = 4, /* Cold-reboot */
4574 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
4575 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
4576 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
4579 /* Flags for ec_params_reboot_ec.reboot_flags */
4580 #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
4581 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
4582 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
4584 struct ec_params_reboot_ec {
4585 uint8_t cmd; /* enum ec_reboot_cmd */
4586 uint8_t flags; /* See EC_REBOOT_FLAG_* */
4590 * Get information on last EC panic.
4592 * Returns variable-length platform-dependent panic information. See panic.h
4595 #define EC_CMD_GET_PANIC_INFO 0x00D3
4597 /*****************************************************************************/
4601 * These do not follow the normal rules for commands. See each command for
4608 * This command will work even when the EC LPC interface is busy, because the
4609 * reboot command is processed at interrupt level. Note that when the EC
4610 * reboots, the host will reboot too, so there is no response to this command.
4612 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
4614 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
4617 * Resend last response (not supported on LPC).
4619 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
4620 * there was no previous command, or the previous command's response was too
4623 #define EC_CMD_RESEND_RESPONSE 0x00DB
4626 * This header byte on a command indicate version 0. Any header byte less
4627 * than this means that we are talking to an old EC which doesn't support
4628 * versioning. In that case, we assume version 0.
4630 * Header bytes greater than this indicate a later version. For example,
4631 * EC_CMD_VERSION0 + 1 means we are using version 1.
4633 * The old EC interface must not use commands 0xdc or higher.
4635 #define EC_CMD_VERSION0 0x00DC
4637 /*****************************************************************************/
4641 * These commands are for PD MCU communication.
4644 /* EC to PD MCU exchange status command */
4645 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
4646 #define EC_VER_PD_EXCHANGE_STATUS 2
4648 enum pd_charge_state {
4649 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4650 PD_CHARGE_NONE, /* No charging allowed */
4651 PD_CHARGE_5V, /* 5V charging only */
4652 PD_CHARGE_MAX /* Charge at max voltage */
4655 /* Status of EC being sent to PD */
4656 #define EC_STATUS_HIBERNATING BIT(0)
4658 struct ec_params_pd_status {
4659 uint8_t status; /* EC status */
4660 int8_t batt_soc; /* battery state of charge */
4661 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
4664 /* Status of PD being sent back to EC */
4665 #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
4666 #define PD_STATUS_IN_RW BIT(1) /* Running RW image */
4667 #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
4668 #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
4669 #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
4670 #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
4671 #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
4672 #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4673 PD_STATUS_TCPC_ALERT_1 | \
4674 PD_STATUS_HOST_EVENT)
4675 struct ec_response_pd_status {
4676 uint32_t curr_lim_ma; /* input current limit */
4677 uint16_t status; /* PD MCU status */
4678 int8_t active_charge_port; /* active charging port */
4681 /* AP to PD MCU host event status command, cleared on read */
4682 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4684 /* PD MCU host event status bits */
4685 #define PD_EVENT_UPDATE_DEVICE BIT(0)
4686 #define PD_EVENT_POWER_CHANGE BIT(1)
4687 #define PD_EVENT_IDENTITY_RECEIVED BIT(2)
4688 #define PD_EVENT_DATA_SWAP BIT(3)
4689 struct ec_response_host_event_status {
4690 uint32_t status; /* PD MCU host event status */
4693 /* Set USB type-C port role and muxes */
4694 #define EC_CMD_USB_PD_CONTROL 0x0101
4696 enum usb_pd_control_role {
4697 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
4698 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
4699 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4700 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4701 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4702 USB_PD_CTRL_ROLE_FREEZE = 5,
4703 USB_PD_CTRL_ROLE_COUNT
4706 enum usb_pd_control_mux {
4707 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4708 USB_PD_CTRL_MUX_NONE = 1,
4709 USB_PD_CTRL_MUX_USB = 2,
4710 USB_PD_CTRL_MUX_DP = 3,
4711 USB_PD_CTRL_MUX_DOCK = 4,
4712 USB_PD_CTRL_MUX_AUTO = 5,
4713 USB_PD_CTRL_MUX_COUNT
4716 enum usb_pd_control_swap {
4717 USB_PD_CTRL_SWAP_NONE = 0,
4718 USB_PD_CTRL_SWAP_DATA = 1,
4719 USB_PD_CTRL_SWAP_POWER = 2,
4720 USB_PD_CTRL_SWAP_VCONN = 3,
4721 USB_PD_CTRL_SWAP_COUNT
4724 struct ec_params_usb_pd_control {
4731 #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
4732 #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
4733 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
4735 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
4736 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
4737 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
4738 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
4739 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
4740 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
4741 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
4743 struct ec_response_usb_pd_control {
4750 struct ec_response_usb_pd_control_v1 {
4757 /* Values representing usbc PD CC state */
4758 #define USBC_PD_CC_NONE 0 /* No accessory connected */
4759 #define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */
4760 #define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */
4761 #define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */
4762 #define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */
4763 #define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */
4765 struct ec_response_usb_pd_control_v2 {
4770 uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
4771 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
4772 /* CL:1500994 Current cable type */
4773 uint8_t reserved_cable_type;
4776 #define EC_CMD_USB_PD_PORTS 0x0102
4778 /* Maximum number of PD ports on a device, num_ports will be <= this */
4779 #define EC_USB_PD_MAX_PORTS 8
4781 struct ec_response_usb_pd_ports {
4785 #define EC_CMD_USB_PD_POWER_INFO 0x0103
4787 #define PD_POWER_CHARGING_PORT 0xff
4788 struct ec_params_usb_pd_power_info {
4796 USB_CHG_TYPE_PROPRIETARY,
4797 USB_CHG_TYPE_BC12_DCP,
4798 USB_CHG_TYPE_BC12_CDP,
4799 USB_CHG_TYPE_BC12_SDP,
4802 USB_CHG_TYPE_UNKNOWN,
4803 USB_CHG_TYPE_DEDICATED,
4805 enum usb_power_roles {
4806 USB_PD_PORT_POWER_DISCONNECTED,
4807 USB_PD_PORT_POWER_SOURCE,
4808 USB_PD_PORT_POWER_SINK,
4809 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4812 struct usb_chg_measures {
4813 uint16_t voltage_max;
4814 uint16_t voltage_now;
4815 uint16_t current_max;
4816 uint16_t current_lim;
4819 struct ec_response_usb_pd_power_info {
4824 struct usb_chg_measures meas;
4830 * This command will return the number of USB PD charge port + the number
4831 * of dedicated port present.
4832 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
4834 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
4835 struct ec_response_charge_port_count {
4839 /* Write USB-PD device FW */
4840 #define EC_CMD_USB_PD_FW_UPDATE 0x0110
4842 enum usb_pd_fw_update_cmds {
4844 USB_PD_FW_FLASH_ERASE,
4845 USB_PD_FW_FLASH_WRITE,
4846 USB_PD_FW_ERASE_SIG,
4849 struct ec_params_usb_pd_fw_update {
4853 uint32_t size; /* Size to write in bytes */
4854 /* Followed by data to write */
4857 /* Write USB-PD Accessory RW_HASH table entry */
4858 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4859 /* RW hash is first 20 bytes of SHA-256 of RW section */
4860 #define PD_RW_HASH_SIZE 20
4861 struct ec_params_usb_pd_rw_hash_entry {
4863 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4864 uint8_t reserved; /*
4865 * For alignment of current_image
4866 * TODO(rspangler) but it's not aligned!
4867 * Should have been reserved[2].
4869 uint32_t current_image; /* One of ec_current_image */
4872 /* Read USB-PD Accessory info */
4873 #define EC_CMD_USB_PD_DEV_INFO 0x0112
4875 struct ec_params_usb_pd_info_request {
4879 /* Read USB-PD Device discovery info */
4880 #define EC_CMD_USB_PD_DISCOVERY 0x0113
4881 struct ec_params_usb_pd_discovery_entry {
4882 uint16_t vid; /* USB-IF VID */
4883 uint16_t pid; /* USB-IF PID */
4884 uint8_t ptype; /* product type (hub,periph,cable,ama) */
4887 /* Override default charge behavior */
4888 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
4890 /* Negative port parameters have special meaning */
4891 enum usb_pd_override_ports {
4892 OVERRIDE_DONT_CHARGE = -2,
4894 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4897 struct ec_params_charge_port_override {
4898 int16_t override_port; /* Override port# */
4902 * Read (and delete) one entry of PD event log.
4903 * TODO(crbug.com/751742): Make this host command more generic to accommodate
4904 * future non-PD logs that use the same internal EC event_log.
4906 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4908 struct ec_response_pd_log {
4909 uint32_t timestamp; /* relative timestamp in milliseconds */
4910 uint8_t type; /* event type : see PD_EVENT_xx below */
4911 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4912 uint16_t data; /* type-defined data payload */
4913 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
4916 /* The timestamp is the microsecond counter shifted to get about a ms. */
4917 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4919 #define PD_LOG_SIZE_MASK 0x1f
4920 #define PD_LOG_PORT_MASK 0xe0
4921 #define PD_LOG_PORT_SHIFT 5
4922 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4923 ((size) & PD_LOG_SIZE_MASK))
4924 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4925 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4927 /* PD event log : entry types */
4929 #define PD_EVENT_MCU_BASE 0x00
4930 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4931 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4932 /* Reserved for custom board event */
4933 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4934 /* PD generic accessory events */
4935 #define PD_EVENT_ACC_BASE 0x20
4936 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4937 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4938 /* PD power supply events */
4939 #define PD_EVENT_PS_BASE 0x40
4940 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4941 /* PD video dongles events */
4942 #define PD_EVENT_VIDEO_BASE 0x60
4943 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4944 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4945 /* Returned in the "type" field, when there is no entry available */
4946 #define PD_EVENT_NO_ENTRY 0xff
4949 * PD_EVENT_MCU_CHARGE event definition :
4950 * the payload is "struct usb_chg_measures"
4951 * the data field contains the port state flags as defined below :
4953 /* Port partner is a dual role device */
4954 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
4955 /* Port is the pending override port */
4956 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
4957 /* Port is the override port */
4958 #define CHARGE_FLAGS_OVERRIDE BIT(13)
4960 #define CHARGE_FLAGS_TYPE_SHIFT 3
4961 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4962 /* Power delivery role */
4963 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4966 * PD_EVENT_PS_FAULT data field flags definition :
4968 #define PS_FAULT_OCP 1
4969 #define PS_FAULT_FAST_OCP 2
4970 #define PS_FAULT_OVP 3
4971 #define PS_FAULT_DISCH 4
4974 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4976 struct mcdp_version {
4985 struct mcdp_version irom;
4986 struct mcdp_version fw;
4989 /* struct mcdp_info field decoding */
4990 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4991 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4993 /* Get/Set USB-PD Alternate mode info */
4994 #define EC_CMD_USB_PD_GET_AMODE 0x0116
4995 struct ec_params_usb_pd_get_mode_request {
4996 uint16_t svid_idx; /* SVID index to get */
4997 uint8_t port; /* port */
5000 struct ec_params_usb_pd_get_mode_response {
5001 uint16_t svid; /* SVID */
5002 uint16_t opos; /* Object Position */
5003 uint32_t vdo[6]; /* Mode VDOs */
5006 #define EC_CMD_USB_PD_SET_AMODE 0x0117
5011 /* Not a command. Do NOT remove. */
5015 struct ec_params_usb_pd_set_mode_request {
5016 uint32_t cmd; /* enum pd_mode_cmd */
5017 uint16_t svid; /* SVID to set */
5018 uint8_t opos; /* Object Position */
5019 uint8_t port; /* port */
5022 /* Ask the PD MCU to record a log of a requested type */
5023 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
5025 struct ec_params_pd_write_log_entry {
5026 uint8_t type; /* event type : see PD_EVENT_xx above */
5027 uint8_t port; /* port#, or 0 for events unrelated to a given port */
5031 /* Control USB-PD chip */
5032 #define EC_CMD_PD_CONTROL 0x0119
5034 enum ec_pd_control_cmd {
5035 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5036 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5037 PD_RESET, /* Force reset the PD chip */
5038 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5039 PD_CHIP_ON, /* Power on the PD chip */
5042 struct ec_params_pd_control {
5043 uint8_t chip; /* chip id */
5047 /* Get info about USB-C SS muxes */
5048 #define EC_CMD_USB_PD_MUX_INFO 0x011A
5050 struct ec_params_usb_pd_mux_info {
5051 uint8_t port; /* USB-C port number */
5054 /* Flags representing mux state */
5055 #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5056 #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5057 #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5058 #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5059 #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5061 struct ec_response_usb_pd_mux_info {
5062 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
5065 #define EC_CMD_PD_CHIP_INFO 0x011B
5067 struct ec_params_pd_chip_info {
5068 uint8_t port; /* USB-C port number */
5069 uint8_t renew; /* Force renewal */
5072 struct ec_response_pd_chip_info {
5074 uint16_t product_id;
5077 uint8_t fw_version_string[8];
5078 uint64_t fw_version_number;
5082 struct ec_response_pd_chip_info_v1 {
5084 uint16_t product_id;
5087 uint8_t fw_version_string[8];
5088 uint64_t fw_version_number;
5091 uint8_t min_req_fw_version_string[8];
5092 uint64_t min_req_fw_version_number;
5096 /* Run RW signature verification and get status */
5097 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5099 struct ec_response_rwsig_check_status {
5103 /* For controlling RWSIG task */
5104 #define EC_CMD_RWSIG_ACTION 0x011D
5107 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5108 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5111 struct ec_params_rwsig_action {
5115 /* Run verification on a slot */
5116 #define EC_CMD_EFS_VERIFY 0x011E
5118 struct ec_params_efs_verify {
5119 uint8_t region; /* enum ec_flash_region */
5123 * Retrieve info from Cros Board Info store. Response is based on the data
5124 * type. Integers return a uint32. Strings return a string, using the response
5125 * size to determine how big it is.
5127 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5129 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5130 * hardware write-protect enabled.
5132 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5135 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5136 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5137 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
5138 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
5139 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
5140 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
5145 * Flags to control read operation
5147 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5148 * write was successful without reboot.
5150 #define CBI_GET_RELOAD BIT(0)
5152 struct ec_params_get_cbi {
5153 uint32_t tag; /* enum cbi_data_tag */
5154 uint32_t flag; /* CBI_GET_* */
5158 * Flags to control write behavior.
5160 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5161 * useful when writing multiple fields in a row.
5162 * INIT: Need to be set when creating a new CBI from scratch. All fields
5163 * will be initialized to zero first.
5165 #define CBI_SET_NO_SYNC BIT(0)
5166 #define CBI_SET_INIT BIT(1)
5168 struct ec_params_set_cbi {
5169 uint32_t tag; /* enum cbi_data_tag */
5170 uint32_t flag; /* CBI_SET_* */
5171 uint32_t size; /* Data size */
5172 uint8_t data[]; /* For string and raw data */
5176 * Information about resets of the AP by the EC and the EC's own uptime.
5178 #define EC_CMD_GET_UPTIME_INFO 0x0121
5180 struct ec_response_uptime_info {
5182 * Number of milliseconds since the last EC boot. Sysjump resets
5183 * typically do not restart the EC's time_since_boot epoch.
5185 * WARNING: The EC's sense of time is much less accurate than the AP's
5186 * sense of time, in both phase and frequency. This timebase is similar
5187 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5189 uint32_t time_since_ec_boot_ms;
5192 * Number of times the AP was reset by the EC since the last EC boot.
5193 * Note that the AP may be held in reset by the EC during the initial
5194 * boot sequence, such that the very first AP boot may count as more
5197 uint32_t ap_resets_since_ec_boot;
5200 * The set of flags which describe the EC's most recent reset. See
5201 * include/system.h RESET_FLAG_* for details.
5203 uint32_t ec_reset_flags;
5205 /* Empty log entries have both the cause and timestamp set to zero. */
5206 struct ap_reset_log_entry {
5208 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5211 uint16_t reset_cause;
5213 /* Reserved for protocol growth. */
5217 * The time of the reset's assertion, in milliseconds since the
5218 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5219 * Set to zero if the log entry is empty.
5221 uint32_t reset_time_ms;
5222 } recent_ap_reset[4];
5226 * Add entropy to the device secret (stored in the rollback region).
5228 * Depending on the chip, the operation may take a long time (e.g. to erase
5229 * flash), so the commands are asynchronous.
5231 #define EC_CMD_ADD_ENTROPY 0x0122
5233 enum add_entropy_action {
5234 /* Add entropy to the current secret. */
5235 ADD_ENTROPY_ASYNC = 0,
5237 * Add entropy, and also make sure that the previous secret is erased.
5238 * (this can be implemented by adding entropy multiple times until
5239 * all rolback blocks have been overwritten).
5241 ADD_ENTROPY_RESET_ASYNC = 1,
5242 /* Read back result from the previous operation. */
5243 ADD_ENTROPY_GET_RESULT = 2,
5246 struct ec_params_rollback_add_entropy {
5251 * Perform a single read of a given ADC channel.
5253 #define EC_CMD_ADC_READ 0x0123
5255 struct ec_params_adc_read {
5256 uint8_t adc_channel;
5259 struct ec_response_adc_read {
5264 * Read back rollback info
5266 #define EC_CMD_ROLLBACK_INFO 0x0124
5268 struct ec_response_rollback_info {
5269 int32_t id; /* Incrementing number to indicate which region to use. */
5270 int32_t rollback_min_version;
5271 int32_t rw_rollback_version;
5275 /* Issue AP reset */
5276 #define EC_CMD_AP_RESET 0x0125
5278 /*****************************************************************************/
5279 /* The command range 0x200-0x2FF is reserved for Rotor. */
5281 /*****************************************************************************/
5283 * Reserve a range of host commands for the CR51 firmware.
5285 #define EC_CMD_CR51_BASE 0x0300
5286 #define EC_CMD_CR51_LAST 0x03FF
5288 /*****************************************************************************/
5289 /* Fingerprint MCU commands: range 0x0400-0x040x */
5291 /* Fingerprint SPI sensor passthru command: prototyping ONLY */
5292 #define EC_CMD_FP_PASSTHRU 0x0400
5294 #define EC_FP_FLAG_NOT_COMPLETE 0x1
5296 struct ec_params_fp_passthru {
5297 uint16_t len; /* Number of bytes to write then read */
5298 uint16_t flags; /* EC_FP_FLAG_xxx */
5299 uint8_t data[]; /* Data to send */
5302 /* Configure the Fingerprint MCU behavior */
5303 #define EC_CMD_FP_MODE 0x0402
5305 /* Put the sensor in its lowest power mode */
5306 #define FP_MODE_DEEPSLEEP BIT(0)
5307 /* Wait to see a finger on the sensor */
5308 #define FP_MODE_FINGER_DOWN BIT(1)
5309 /* Poll until the finger has left the sensor */
5310 #define FP_MODE_FINGER_UP BIT(2)
5311 /* Capture the current finger image */
5312 #define FP_MODE_CAPTURE BIT(3)
5313 /* Finger enrollment session on-going */
5314 #define FP_MODE_ENROLL_SESSION BIT(4)
5315 /* Enroll the current finger image */
5316 #define FP_MODE_ENROLL_IMAGE BIT(5)
5317 /* Try to match the current finger image */
5318 #define FP_MODE_MATCH BIT(6)
5319 /* Reset and re-initialize the sensor. */
5320 #define FP_MODE_RESET_SENSOR BIT(7)
5321 /* special value: don't change anything just read back current mode */
5322 #define FP_MODE_DONT_CHANGE BIT(31)
5324 #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
5325 FP_MODE_FINGER_DOWN | \
5326 FP_MODE_FINGER_UP | \
5328 FP_MODE_ENROLL_SESSION | \
5329 FP_MODE_ENROLL_IMAGE | \
5331 FP_MODE_RESET_SENSOR | \
5332 FP_MODE_DONT_CHANGE)
5334 /* Capture types defined in bits [30..28] */
5335 #define FP_MODE_CAPTURE_TYPE_SHIFT 28
5336 #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
5338 * This enum must remain ordered, if you add new values you must ensure that
5339 * FP_CAPTURE_TYPE_MAX is still the last one.
5341 enum fp_capture_type {
5342 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
5343 FP_CAPTURE_VENDOR_FORMAT = 0,
5344 /* Simple raw image capture (produces width x height x bpp bits) */
5345 FP_CAPTURE_SIMPLE_IMAGE = 1,
5346 /* Self test pattern (e.g. checkerboard) */
5347 FP_CAPTURE_PATTERN0 = 2,
5348 /* Self test pattern (e.g. inverted checkerboard) */
5349 FP_CAPTURE_PATTERN1 = 3,
5350 /* Capture for Quality test with fixed contrast */
5351 FP_CAPTURE_QUALITY_TEST = 4,
5352 /* Capture for pixel reset value test */
5353 FP_CAPTURE_RESET_TEST = 5,
5354 FP_CAPTURE_TYPE_MAX,
5356 /* Extracts the capture type from the sensor 'mode' word */
5357 #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
5358 >> FP_MODE_CAPTURE_TYPE_SHIFT)
5360 struct ec_params_fp_mode {
5361 uint32_t mode; /* as defined by FP_MODE_ constants */
5364 struct ec_response_fp_mode {
5365 uint32_t mode; /* as defined by FP_MODE_ constants */
5368 /* Retrieve Fingerprint sensor information */
5369 #define EC_CMD_FP_INFO 0x0403
5371 /* Number of dead pixels detected on the last maintenance */
5372 #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
5373 /* Unknown number of dead pixels detected on the last maintenance */
5374 #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
5375 /* No interrupt from the sensor */
5376 #define FP_ERROR_NO_IRQ BIT(12)
5377 /* SPI communication error */
5378 #define FP_ERROR_SPI_COMM BIT(13)
5379 /* Invalid sensor Hardware ID */
5380 #define FP_ERROR_BAD_HWID BIT(14)
5381 /* Sensor initialization failed */
5382 #define FP_ERROR_INIT_FAIL BIT(15)
5384 struct ec_response_fp_info_v0 {
5385 /* Sensor identification */
5387 uint32_t product_id;
5390 /* Image frame characteristics */
5391 uint32_t frame_size;
5392 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5396 uint16_t errors; /* see FP_ERROR_ flags above */
5399 struct ec_response_fp_info {
5400 /* Sensor identification */
5402 uint32_t product_id;
5405 /* Image frame characteristics */
5406 uint32_t frame_size;
5407 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5411 uint16_t errors; /* see FP_ERROR_ flags above */
5412 /* Template/finger current information */
5413 uint32_t template_size; /* max template size in bytes */
5414 uint16_t template_max; /* maximum number of fingers/templates */
5415 uint16_t template_valid; /* number of valid fingers/templates */
5416 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
5417 uint32_t template_version; /* version of the template format */
5420 /* Get the last captured finger frame or a template content */
5421 #define EC_CMD_FP_FRAME 0x0404
5423 /* constants defining the 'offset' field which also contains the frame index */
5424 #define FP_FRAME_INDEX_SHIFT 28
5425 /* Frame buffer where the captured image is stored */
5426 #define FP_FRAME_INDEX_RAW_IMAGE 0
5427 /* First frame buffer holding a template */
5428 #define FP_FRAME_INDEX_TEMPLATE 1
5429 #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
5430 #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
5432 /* Version of the format of the encrypted templates. */
5433 #define FP_TEMPLATE_FORMAT_VERSION 3
5435 /* Constants for encryption parameters */
5436 #define FP_CONTEXT_NONCE_BYTES 12
5437 #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
5438 #define FP_CONTEXT_TAG_BYTES 16
5439 #define FP_CONTEXT_SALT_BYTES 16
5440 #define FP_CONTEXT_TPM_BYTES 32
5442 struct ec_fp_template_encryption_metadata {
5444 * Version of the structure format (N=3).
5446 uint16_t struct_version;
5447 /* Reserved bytes, set to 0. */
5450 * The salt is *only* ever used for key derivation. The nonce is unique,
5451 * a different one is used for every message.
5453 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
5454 uint8_t salt[FP_CONTEXT_SALT_BYTES];
5455 uint8_t tag[FP_CONTEXT_TAG_BYTES];
5458 struct ec_params_fp_frame {
5460 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
5461 * in the high nibble, and the real offset within the frame in
5462 * FP_FRAME_OFFSET_MASK.
5468 /* Load a template into the MCU */
5469 #define EC_CMD_FP_TEMPLATE 0x0405
5471 /* Flag in the 'size' field indicating that the full template has been sent */
5472 #define FP_TEMPLATE_COMMIT 0x80000000
5474 struct ec_params_fp_template {
5480 /* Clear the current fingerprint user context and set a new one */
5481 #define EC_CMD_FP_CONTEXT 0x0406
5483 struct ec_params_fp_context {
5484 uint32_t userid[FP_CONTEXT_USERID_WORDS];
5487 #define EC_CMD_FP_STATS 0x0407
5489 #define FPSTATS_CAPTURE_INV BIT(0)
5490 #define FPSTATS_MATCHING_INV BIT(1)
5492 struct ec_response_fp_stats {
5493 uint32_t capture_time_us;
5494 uint32_t matching_time_us;
5495 uint32_t overall_time_us;
5500 uint8_t timestamps_invalid;
5501 int8_t template_matched;
5504 #define EC_CMD_FP_SEED 0x0408
5505 struct ec_params_fp_seed {
5507 * Version of the structure format (N=3).
5509 uint16_t struct_version;
5510 /* Reserved bytes, set to 0. */
5512 /* Seed from the TPM. */
5513 uint8_t seed[FP_CONTEXT_TPM_BYTES];
5516 #define EC_CMD_FP_ENC_STATUS 0x0409
5518 /* FP TPM seed has been set or not */
5519 #define FP_ENC_STATUS_SEED_SET BIT(0)
5521 struct ec_response_fp_encryption_status {
5522 /* Used bits in encryption engine status */
5523 uint32_t valid_flags;
5524 /* Encryption engine status */
5528 /*****************************************************************************/
5529 /* Touchpad MCU commands: range 0x0500-0x05FF */
5531 /* Perform touchpad self test */
5532 #define EC_CMD_TP_SELF_TEST 0x0500
5534 /* Get number of frame types, and the size of each type */
5535 #define EC_CMD_TP_FRAME_INFO 0x0501
5537 struct ec_response_tp_frame_info {
5539 uint32_t frame_sizes[0];
5542 /* Create a snapshot of current frame readings */
5543 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
5545 /* Read the frame */
5546 #define EC_CMD_TP_FRAME_GET 0x0503
5548 struct ec_params_tp_frame_get {
5549 uint32_t frame_index;
5554 /*****************************************************************************/
5555 /* EC-EC communication commands: range 0x0600-0x06FF */
5557 #define EC_COMM_TEXT_MAX 8
5560 * Get battery static information, i.e. information that never changes, or
5561 * very infrequently.
5563 #define EC_CMD_BATTERY_GET_STATIC 0x0600
5566 * struct ec_params_battery_static_info - Battery static info parameters
5567 * @index: Battery index.
5569 struct ec_params_battery_static_info {
5574 * struct ec_response_battery_static_info - Battery static info response
5575 * @design_capacity: Battery Design Capacity (mAh)
5576 * @design_voltage: Battery Design Voltage (mV)
5577 * @manufacturer: Battery Manufacturer String
5578 * @model: Battery Model Number String
5579 * @serial: Battery Serial Number String
5580 * @type: Battery Type String
5581 * @cycle_count: Battery Cycle Count
5583 struct ec_response_battery_static_info {
5584 uint16_t design_capacity;
5585 uint16_t design_voltage;
5586 char manufacturer[EC_COMM_TEXT_MAX];
5587 char model[EC_COMM_TEXT_MAX];
5588 char serial[EC_COMM_TEXT_MAX];
5589 char type[EC_COMM_TEXT_MAX];
5590 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
5591 uint32_t cycle_count;
5595 * Get battery dynamic information, i.e. information that is likely to change
5596 * every time it is read.
5598 #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
5601 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
5602 * @index: Battery index.
5604 struct ec_params_battery_dynamic_info {
5609 * struct ec_response_battery_dynamic_info - Battery dynamic info response
5610 * @actual_voltage: Battery voltage (mV)
5611 * @actual_current: Battery current (mA); negative=discharging
5612 * @remaining_capacity: Remaining capacity (mAh)
5613 * @full_capacity: Capacity (mAh, might change occasionally)
5614 * @flags: Flags, see EC_BATT_FLAG_*
5615 * @desired_voltage: Charging voltage desired by battery (mV)
5616 * @desired_current: Charging current desired by battery (mA)
5618 struct ec_response_battery_dynamic_info {
5619 int16_t actual_voltage;
5620 int16_t actual_current;
5621 int16_t remaining_capacity;
5622 int16_t full_capacity;
5624 int16_t desired_voltage;
5625 int16_t desired_current;
5629 * Control charger chip. Used to control charger chip on the slave.
5631 #define EC_CMD_CHARGER_CONTROL 0x0602
5634 * struct ec_params_charger_control - Charger control parameters
5635 * @max_current: Charger current (mA). Positive to allow base to draw up to
5636 * max_current and (possibly) charge battery, negative to request current
5638 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
5640 * @allow_charging: Allow base battery charging (only makes sense if
5643 struct ec_params_charger_control {
5644 int16_t max_current;
5645 uint16_t otg_voltage;
5646 uint8_t allow_charging;
5649 /*****************************************************************************/
5651 * Reserve a range of host commands for board-specific, experimental, or
5652 * special purpose features. These can be (re)used without updating this file.
5654 * CAUTION: Don't go nuts with this. Shipping products should document ALL
5655 * their EC commands for easier development, testing, debugging, and support.
5657 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
5658 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
5660 * In your experimental code, you may want to do something like this:
5662 * #define EC_CMD_MAGIC_FOO 0x0000
5663 * #define EC_CMD_MAGIC_BAR 0x0001
5664 * #define EC_CMD_MAGIC_HEY 0x0002
5666 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
5669 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
5672 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
5675 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
5676 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
5679 * Given the private host command offset, calculate the true private host
5682 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
5683 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
5685 /*****************************************************************************/
5689 * Some platforms have sub-processors chained to each other. For example.
5691 * AP <--> EC <--> PD MCU
5693 * The top 2 bits of the command number are used to indicate which device the
5694 * command is intended for. Device 0 is always the device receiving the
5695 * command; other device mapping is board-specific.
5697 * When a device receives a command to be passed to a sub-processor, it passes
5698 * it on with the device number set back to 0. This allows the sub-processor
5699 * to remain blissfully unaware of whether the command originated on the next
5700 * device up the chain, or was passed through from the AP.
5702 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
5703 * AP sends command 0x4002 to the EC
5704 * EC sends command 0x0002 to the PD MCU
5705 * EC forwards PD MCU response back to the AP
5708 /* Offset and max command number for sub-device n */
5709 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
5710 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
5712 /*****************************************************************************/
5714 * Deprecated constants. These constants have been renamed for clarity. The
5715 * meaning and size has not changed. Programs that use the old names should
5716 * switch to the new names soon, as the old names may not be carried forward
5719 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
5720 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
5721 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
5725 #endif /* __CROS_EC_COMMANDS_H */