1 /* Copyright (c) 2018 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
6 /* Host communication command constants for Chrome EC */
8 #ifndef __CROS_EC_COMMANDS_H
9 #define __CROS_EC_COMMANDS_H
14 * request: CMD [ P0 P1 P2 ... Pn S ]
15 * response: ERR [ P0 P1 P2 ... Pn S ]
17 * where the bytes are defined as follow :
18 * - CMD is the command code. (defined by EC_CMD_ constants)
19 * - ERR is the error code. (defined by EC_RES_ constants)
20 * - Px is the optional payload.
21 * it is not sent if the error code is not success.
22 * (defined by ec_params_ and ec_response_ structures)
23 * - S is the checksum which is the sum of all payload bytes.
25 * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
26 * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
27 * On I2C, all bytes are sent serially in the same message.
31 * Current version of this protocol
33 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
34 * determined in other ways. Remove this once the kernel code no longer
37 #define EC_PROTO_VERSION 0x00000002
39 /* Command version mask */
40 #define EC_VER_MASK(version) (1UL << (version))
42 /* I/O addresses for ACPI commands */
43 #define EC_LPC_ADDR_ACPI_DATA 0x62
44 #define EC_LPC_ADDR_ACPI_CMD 0x66
46 /* I/O addresses for host command */
47 #define EC_LPC_ADDR_HOST_DATA 0x200
48 #define EC_LPC_ADDR_HOST_CMD 0x204
50 /* I/O addresses for host command args and params */
51 /* Protocol version 2 */
52 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
53 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
54 * EC_PROTO2_MAX_PARAM_SIZE */
55 /* Protocol version 3 */
56 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
57 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
59 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
60 * and they tell the kernel that so we have to think of it as two parts. */
61 #define EC_HOST_CMD_REGION0 0x800
62 #define EC_HOST_CMD_REGION1 0x880
63 #define EC_HOST_CMD_REGION_SIZE 0x80
65 /* EC command register bit functions */
66 #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
67 #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
68 #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
69 #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
70 #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
71 #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
72 #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
74 /* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource */
75 #define MEC_EMI_BASE 0x800
76 #define MEC_EMI_SIZE 8
78 #define EC_LPC_ADDR_MEMMAP 0x900
79 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
80 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
82 /* The offset address of each type of data in mapped memory. */
83 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
84 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
85 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
86 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
87 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
88 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
89 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
90 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
91 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
92 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
93 /* Unused 0x28 - 0x2f */
94 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
95 /* Unused 0x31 - 0x33 */
96 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
97 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
98 /* Battery values are all 32 bits */
99 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
100 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
101 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
102 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
103 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
104 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
105 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
106 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
107 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
108 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
109 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
110 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
111 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
112 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
113 /* Unused 0x84 - 0x8f */
114 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
116 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
117 /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
118 /* 0x94 - 0x99: 1st Accelerometer */
119 /* 0x9a - 0x9f: 2nd Accelerometer */
120 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
121 /* Unused 0xa6 - 0xdf */
124 * ACPI is unable to access memory mapped data at or above this offset due to
125 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
126 * which might be needed by ACPI.
128 #define EC_MEMMAP_NO_ACPI 0xe0
130 /* Define the format of the accelerometer mapped memory status byte. */
131 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
132 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
133 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
135 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
136 #define EC_TEMP_SENSOR_ENTRIES 16
138 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
140 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
142 #define EC_TEMP_SENSOR_B_ENTRIES 8
144 /* Special values for mapped temperature sensors */
145 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
146 #define EC_TEMP_SENSOR_ERROR 0xfe
147 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
148 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
150 * The offset of temperature value stored in mapped memory. This allows
151 * reporting a temperature range of 200K to 454K = -73C to 181C.
153 #define EC_TEMP_SENSOR_OFFSET 200
156 * Number of ALS readings at EC_MEMMAP_ALS
158 #define EC_ALS_ENTRIES 2
161 * The default value a temperature sensor will return when it is present but
162 * has not been read this boot. This is a reasonable number to avoid
163 * triggering alarms on the host.
165 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
167 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
168 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
169 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
171 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
172 #define EC_BATT_FLAG_AC_PRESENT 0x01
173 #define EC_BATT_FLAG_BATT_PRESENT 0x02
174 #define EC_BATT_FLAG_DISCHARGING 0x04
175 #define EC_BATT_FLAG_CHARGING 0x08
176 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
178 /* Switch flags at EC_MEMMAP_SWITCHES */
179 #define EC_SWITCH_LID_OPEN 0x01
180 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
181 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
182 /* Was recovery requested via keyboard; now unused. */
183 #define EC_SWITCH_IGNORE1 0x08
184 /* Recovery requested via dedicated signal (from servo board) */
185 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
186 /* Was fake developer mode switch; now unused. Remove in next refactor. */
187 #define EC_SWITCH_IGNORE0 0x20
189 /* Host command interface flags */
190 /* Host command interface supports LPC args (LPC interface only) */
191 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
192 /* Host command interface supports version 3 protocol */
193 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
195 /* Wireless switch flags */
196 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
197 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
198 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
199 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
200 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
202 /*****************************************************************************/
206 * These are valid ONLY on the ACPI command/data port.
210 * ACPI Read Embedded Controller
212 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
214 * Use the following sequence:
216 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
217 * - Wait for EC_LPC_CMDR_PENDING bit to clear
218 * - Write address to EC_LPC_ADDR_ACPI_DATA
219 * - Wait for EC_LPC_CMDR_DATA bit to set
220 * - Read value from EC_LPC_ADDR_ACPI_DATA
222 #define EC_CMD_ACPI_READ 0x0080
225 * ACPI Write Embedded Controller
227 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
229 * Use the following sequence:
231 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
232 * - Wait for EC_LPC_CMDR_PENDING bit to clear
233 * - Write address to EC_LPC_ADDR_ACPI_DATA
234 * - Wait for EC_LPC_CMDR_PENDING bit to clear
235 * - Write value to EC_LPC_ADDR_ACPI_DATA
237 #define EC_CMD_ACPI_WRITE 0x0081
240 * ACPI Burst Enable Embedded Controller
242 * This enables burst mode on the EC to allow the host to issue several
243 * commands back-to-back. While in this mode, writes to mapped multi-byte
244 * data are locked out to ensure data consistency.
246 #define EC_CMD_ACPI_BURST_ENABLE 0x0082
249 * ACPI Burst Disable Embedded Controller
251 * This disables burst mode on the EC and stops preventing EC writes to mapped
254 #define EC_CMD_ACPI_BURST_DISABLE 0x0083
257 * ACPI Query Embedded Controller
259 * This clears the lowest-order bit in the currently pending host events, and
260 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
261 * event 0x80000000 = 32), or 0 if no event was pending.
263 #define EC_CMD_ACPI_QUERY_EVENT 0x0084
265 /* Valid addresses in ACPI memory space, for read/write commands */
267 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
268 #define EC_ACPI_MEM_VERSION 0x00
270 * Test location; writing value here updates test compliment byte to (0xff -
273 #define EC_ACPI_MEM_TEST 0x01
274 /* Test compliment; writes here are ignored. */
275 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
277 /* Keyboard backlight brightness percent (0 - 100) */
278 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
279 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
280 #define EC_ACPI_MEM_FAN_DUTY 0x04
283 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
284 * independent thresholds attached to them. The current value of the ID
285 * register determines which sensor is affected by the THRESHOLD and COMMIT
286 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
287 * as the memory-mapped sensors. The COMMIT register applies those settings.
289 * The spec does not mandate any way to read back the threshold settings
290 * themselves, but when a threshold is crossed the AP needs a way to determine
291 * which sensor(s) are responsible. Each reading of the ID register clears and
292 * returns one sensor ID that has crossed one of its threshold (in either
293 * direction) since the last read. A value of 0xFF means "no new thresholds
294 * have tripped". Setting or enabling the thresholds for a sensor will clear
295 * the unread event count for that sensor.
297 #define EC_ACPI_MEM_TEMP_ID 0x05
298 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
299 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
301 * Here are the bits for the COMMIT register:
302 * bit 0 selects the threshold index for the chosen sensor (0/1)
303 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
304 * Each write to the commit register affects one threshold.
306 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
307 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
311 * Set the thresholds for sensor 2 to 50 C and 60 C:
312 * write 2 to [0x05] -- select temp sensor 2
313 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
314 * write 0x2 to [0x07] -- enable threshold 0 with this value
315 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
316 * write 0x3 to [0x07] -- enable threshold 1 with this value
318 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
319 * write 2 to [0x05] -- select temp sensor 2
320 * write 0x1 to [0x07] -- disable threshold 1
323 /* DPTF battery charging current limit */
324 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
326 /* Charging limit is specified in 64 mA steps */
327 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
328 /* Value to disable DPTF battery charging limit */
329 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
332 * Report device orientation
333 * bit 0 device is tablet mode
335 #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
336 #define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
339 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
340 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
342 #define EC_ACPI_MEM_MAPPED_BEGIN 0x20
343 #define EC_ACPI_MEM_MAPPED_SIZE 0xe0
345 /* Current version of ACPI memory address space */
346 #define EC_ACPI_MEM_VERSION_CURRENT 2
350 * This header file is used in coreboot both in C and ACPI code. The ACPI code
351 * is pre-processed to handle constants but the ASL compiler is unable to
352 * handle actual C code so keep it separate.
357 * Define __packed if someone hasn't beat us to it. Linux kernel style
358 * checking prefers __packed over __attribute__((packed)).
361 #define __packed __attribute__((packed))
365 #define __aligned(x) __attribute__((aligned(x)))
369 * Attributes for EC request and response packets. Just defining __packed
370 * results in inefficient assembly code on ARM, if the structure is actually
371 * 32-bit aligned, as it should be for all buffers.
373 * Be very careful when adding these to existing structures. They will round
374 * up the structure size to the specified boundary.
376 * Also be very careful to make that if a structure is included in some other
377 * parent structure that the alignment will still be true given the packing of
378 * the parent structure. This is particularly important if the sub-structure
379 * will be passed as a pointer to another function, since that function will
380 * not know about the misaligment caused by the parent structure's packing.
382 * Also be very careful using __packed - particularly when nesting non-packed
383 * structures inside packed ones. In fact, DO NOT use __packed directly;
384 * always use one of these attributes.
386 * Once everything is annotated properly, the following search strings should
387 * not return ANY matches in this file other than right here:
389 * "__packed" - generates inefficient code; all sub-structs must also be packed
391 * "struct [^_]" - all structs should be annotated, except for structs that are
392 * members of other structs/unions (and their original declarations should be
395 #ifdef CONFIG_HOSTCMD_ALIGNED
398 * Packed structures where offset and size are always aligned to 1, 2, or 4
401 #define __ec_align1 __packed
402 #define __ec_align2 __packed __aligned(2)
403 #define __ec_align4 __packed __aligned(4)
406 * Packed structure which must be under-aligned, because its size is not a
407 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
408 * of all multi-byte fields in it, even though they are themselves aligned.
410 * In theory, we could duplicate the structure with __aligned(4) for accessing
411 * its members, but use the __packed version for sizeof().
413 #define __ec_align_size1 __packed
416 * Packed structure which must be under-aligned, because its offset inside a
417 * parent structure is not a 4-byte multiple.
419 #define __ec_align_offset1 __packed
420 #define __ec_align_offset2 __packed __aligned(2)
423 * Structures which are complicated enough that I'm skipping them on the first
424 * pass. They are effectively unchanged from their previous definitions.
426 * TODO(rspangler): Figure out what to do with these. It's likely necessary
427 * to work out the size and offset of each member and add explicit padding to
430 #define __ec_todo_packed __packed
431 #define __ec_todo_unpacked
433 #else /* !CONFIG_HOSTCMD_ALIGNED */
436 * Packed structures make no assumption about alignment, so they do inefficient
439 #define __ec_align1 __packed
440 #define __ec_align2 __packed
441 #define __ec_align4 __packed
442 #define __ec_align_size1 __packed
443 #define __ec_align_offset1 __packed
444 #define __ec_align_offset2 __packed
445 #define __ec_todo_packed __packed
446 #define __ec_todo_unpacked
448 #endif /* !CONFIG_HOSTCMD_ALIGNED */
450 /* LPC command status byte masks */
451 /* EC has written a byte in the data register and host hasn't read it yet */
452 #define EC_LPC_STATUS_TO_HOST 0x01
453 /* Host has written a command/data byte and the EC hasn't read it yet */
454 #define EC_LPC_STATUS_FROM_HOST 0x02
455 /* EC is processing a command */
456 #define EC_LPC_STATUS_PROCESSING 0x04
457 /* Last write to EC was a command, not data */
458 #define EC_LPC_STATUS_LAST_CMD 0x08
459 /* EC is in burst mode */
460 #define EC_LPC_STATUS_BURST_MODE 0x10
461 /* SCI event is pending (requesting SCI query) */
462 #define EC_LPC_STATUS_SCI_PENDING 0x20
463 /* SMI event is pending (requesting SMI query) */
464 #define EC_LPC_STATUS_SMI_PENDING 0x40
466 #define EC_LPC_STATUS_RESERVED 0x80
469 * EC is busy. This covers both the EC processing a command, and the host has
470 * written a new command but the EC hasn't picked it up yet.
472 #define EC_LPC_STATUS_BUSY_MASK \
473 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
475 /* Host command response codes (16-bit). Note that response codes should be
476 * stored in a uint16_t rather than directly in a value of this type.
480 EC_RES_INVALID_COMMAND = 1,
482 EC_RES_INVALID_PARAM = 3,
483 EC_RES_ACCESS_DENIED = 4,
484 EC_RES_INVALID_RESPONSE = 5,
485 EC_RES_INVALID_VERSION = 6,
486 EC_RES_INVALID_CHECKSUM = 7,
487 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
488 EC_RES_UNAVAILABLE = 9, /* No response available */
489 EC_RES_TIMEOUT = 10, /* We got a timeout */
490 EC_RES_OVERFLOW = 11, /* Table / data overflow */
491 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
492 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
493 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
494 EC_RES_BUS_ERROR = 15, /* Communications bus error */
495 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
499 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
500 * EC command uses code 0 to mean "no event pending". We explicitly specify
501 * each value in the enum listing so they won't change if we delete/insert an
502 * item or rearrange the list (it needs to be stable across platforms, not
503 * just within a single compiled instance).
505 enum host_event_code {
506 EC_HOST_EVENT_LID_CLOSED = 1,
507 EC_HOST_EVENT_LID_OPEN = 2,
508 EC_HOST_EVENT_POWER_BUTTON = 3,
509 EC_HOST_EVENT_AC_CONNECTED = 4,
510 EC_HOST_EVENT_AC_DISCONNECTED = 5,
511 EC_HOST_EVENT_BATTERY_LOW = 6,
512 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
513 EC_HOST_EVENT_BATTERY = 8,
514 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
515 /* Event generated by a device attached to the EC */
516 EC_HOST_EVENT_DEVICE = 10,
517 EC_HOST_EVENT_THERMAL = 11,
518 EC_HOST_EVENT_USB_CHARGER = 12,
519 EC_HOST_EVENT_KEY_PRESSED = 13,
521 * EC has finished initializing the host interface. The host can check
522 * for this event following sending a EC_CMD_REBOOT_EC command to
523 * determine when the EC is ready to accept subsequent commands.
525 EC_HOST_EVENT_INTERFACE_READY = 14,
526 /* Keyboard recovery combo has been pressed */
527 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
529 /* Shutdown due to thermal overload */
530 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
531 /* Shutdown due to battery level too low */
532 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
534 /* Suggest that the AP throttle itself */
535 EC_HOST_EVENT_THROTTLE_START = 18,
536 /* Suggest that the AP resume normal speed */
537 EC_HOST_EVENT_THROTTLE_STOP = 19,
539 /* Hang detect logic detected a hang and host event timeout expired */
540 EC_HOST_EVENT_HANG_DETECT = 20,
541 /* Hang detect logic detected a hang and warm rebooted the AP */
542 EC_HOST_EVENT_HANG_REBOOT = 21,
544 /* PD MCU triggering host event */
545 EC_HOST_EVENT_PD_MCU = 22,
547 /* Battery Status flags have changed */
548 EC_HOST_EVENT_BATTERY_STATUS = 23,
550 /* EC encountered a panic, triggering a reset */
551 EC_HOST_EVENT_PANIC = 24,
553 /* Keyboard fastboot combo has been pressed */
554 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
556 /* EC RTC event occurred */
557 EC_HOST_EVENT_RTC = 26,
559 /* Emulate MKBP event */
560 EC_HOST_EVENT_MKBP = 27,
562 /* EC desires to change state of host-controlled USB mux */
563 EC_HOST_EVENT_USB_MUX = 28,
565 /* TABLET/LAPTOP mode event*/
566 EC_HOST_EVENT_MODE_CHANGE = 29,
568 /* Keyboard recovery combo with hardware reinitialization */
569 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
572 * Reserve this last bit to indicate that at least one bit in a
573 * secondary host event word is set. See crbug.com/633646.
575 EC_HOST_EVENT_EXTENDED = 31,
578 * The high bit of the event mask is not used as a host event code. If
579 * it reads back as set, then the entire event mask should be
580 * considered invalid by the host. This can happen when reading the
581 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
582 * not initialized on the EC, or improperly configured on the host.
584 EC_HOST_EVENT_INVALID = 32
586 /* Host event mask */
587 #define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
589 /* Arguments at EC_LPC_ADDR_HOST_ARGS */
590 struct __ec_align4 ec_lpc_host_args {
592 uint8_t command_version;
595 * Checksum; sum of command + flags + command_version + data_size +
596 * all params/response data bytes.
601 /* Flags for ec_lpc_host_args.flags */
603 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
606 * If EC gets a command and this flag is not set, this is an old-style command.
607 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
608 * unknown length. EC must respond with an old-style response (that is,
609 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
611 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
613 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
615 * If EC responds to a command and this flag is not set, this is an old-style
616 * response. Command version is 0 and response data from EC is at
617 * EC_LPC_ADDR_OLD_PARAM with unknown length.
619 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
621 /*****************************************************************************/
623 * Byte codes returned by EC over SPI interface.
625 * These can be used by the AP to debug the EC interface, and to determine
626 * when the EC is not in a state where it will ever get around to responding
629 * Example of sequence of bytes read from EC for a current good transfer:
630 * 1. - - AP asserts chip select (CS#)
631 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
632 * 3. - - EC starts handling CS# interrupt
633 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
634 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
635 * bytes looking for EC_SPI_FRAME_START
636 * 6. - - EC finishes processing and sets up response
637 * 7. EC_SPI_FRAME_START - AP reads frame byte
638 * 8. (response packet) - AP reads response packet
639 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
640 * 10 - - AP deasserts chip select
641 * 11 - - EC processes CS# interrupt and sets up DMA for
644 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
645 * the following byte values:
651 * Then the EC found an error in the request, or was not ready for the request
652 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
653 * because the EC is unable to tell when the AP is done sending its request.
657 * Framing byte which precedes a response packet from the EC. After sending a
658 * request, the AP will clock in bytes until it sees the framing byte, then
659 * clock in the response packet.
661 #define EC_SPI_FRAME_START 0xec
664 * Padding bytes which are clocked out after the end of a response packet.
666 #define EC_SPI_PAST_END 0xed
669 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
670 * that the AP will send a valid packet header (starting with
671 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
673 #define EC_SPI_RX_READY 0xf8
676 * EC has started receiving the request from the AP, but hasn't started
679 #define EC_SPI_RECEIVING 0xf9
681 /* EC has received the entire request from the AP and is processing it. */
682 #define EC_SPI_PROCESSING 0xfa
685 * EC received bad data from the AP, such as a packet header with an invalid
686 * length. EC will ignore all data until chip select deasserts.
688 #define EC_SPI_RX_BAD_DATA 0xfb
691 * EC received data from the AP before it was ready. That is, the AP asserted
692 * chip select and started clocking data before the EC was ready to receive it.
693 * EC will ignore all data until chip select deasserts.
695 #define EC_SPI_NOT_READY 0xfc
698 * EC was ready to receive a request from the AP. EC has treated the byte sent
699 * by the AP as part of a request packet, or (for old-style ECs) is processing
700 * a fully received packet but is not ready to respond yet.
702 #define EC_SPI_OLD_READY 0xfd
704 /*****************************************************************************/
707 * Protocol version 2 for I2C and SPI send a request this way:
709 * 0 EC_CMD_VERSION0 + (command version)
711 * 2 Length of params = N
712 * 3..N+2 Params, if any
713 * N+3 8-bit checksum of bytes 0..N+2
715 * The corresponding response is:
717 * 0 Result code (EC_RES_*)
718 * 1 Length of params = M
719 * 2..M+1 Params, if any
720 * M+2 8-bit checksum of bytes 0..M+1
722 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
723 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
724 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
725 EC_PROTO2_REQUEST_TRAILER_BYTES)
727 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
728 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
729 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
730 EC_PROTO2_RESPONSE_TRAILER_BYTES)
732 /* Parameter length was limited by the LPC interface */
733 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
735 /* Maximum request and response packet sizes for protocol version 2 */
736 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
737 EC_PROTO2_MAX_PARAM_SIZE)
738 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
739 EC_PROTO2_MAX_PARAM_SIZE)
741 /*****************************************************************************/
744 * Value written to legacy command port / prefix byte to indicate protocol
745 * 3+ structs are being used. Usage is bus-dependent.
747 #define EC_COMMAND_PROTOCOL_3 0xda
749 #define EC_HOST_REQUEST_VERSION 3
751 /* Version 3 request from host */
752 struct __ec_align4 ec_host_request {
753 /* Structure version (=3)
755 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
756 * version it doesn't know how to parse.
758 uint8_t struct_version;
761 * Checksum of request and data; sum of all bytes including checksum
769 /* Command version */
770 uint8_t command_version;
772 /* Unused byte in current protocol version; set to 0 */
775 /* Length of data which follows this header */
779 #define EC_HOST_RESPONSE_VERSION 3
781 /* Version 3 response from EC */
782 struct __ec_align4 ec_host_response {
783 /* Structure version (=3) */
784 uint8_t struct_version;
787 * Checksum of response and data; sum of all bytes including checksum
792 /* Result code (EC_RES_*) */
795 /* Length of data which follows this header */
798 /* Unused bytes in current protocol version; set to 0 */
802 /*****************************************************************************/
806 * Each command is an 16-bit command value. Commands which take params or
807 * return response data specify structures for that data. If no structure is
808 * specified, the command does not input or output data, respectively.
809 * Parameter/response length is implicit in the structs. Some underlying
810 * communication protocols (I2C, SPI) may add length or checksum headers, but
811 * those are implementation-dependent and not defined here.
813 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
814 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
817 /*****************************************************************************/
818 /* General / test commands */
821 * Get protocol version, used to deal with non-backward compatible protocol
824 #define EC_CMD_PROTO_VERSION 0x0000
826 struct __ec_align4 ec_response_proto_version {
831 * Hello. This is a simple command to test the EC is responsive to
834 #define EC_CMD_HELLO 0x0001
836 struct __ec_align4 ec_params_hello {
837 uint32_t in_data; /* Pass anything here */
840 struct __ec_align4 ec_response_hello {
841 uint32_t out_data; /* Output will be in_data + 0x01020304 */
844 /* Get version number */
845 #define EC_CMD_GET_VERSION 0x0002
847 enum ec_current_image {
848 EC_IMAGE_UNKNOWN = 0,
853 struct __ec_align4 ec_response_get_version {
854 /* Null-terminated version strings for RO, RW */
855 char version_string_ro[32];
856 char version_string_rw[32];
857 char reserved[32]; /* Was previously RW-B string */
858 uint32_t current_image; /* One of ec_current_image */
862 #define EC_CMD_READ_TEST 0x0003
864 struct __ec_align4 ec_params_read_test {
865 uint32_t offset; /* Starting value for read buffer */
866 uint32_t size; /* Size to read in bytes */
869 struct __ec_align4 ec_response_read_test {
874 * Get build information
876 * Response is null-terminated string.
878 #define EC_CMD_GET_BUILD_INFO 0x0004
881 #define EC_CMD_GET_CHIP_INFO 0x0005
883 struct __ec_align4 ec_response_get_chip_info {
884 /* Null-terminated strings */
887 char revision[32]; /* Mask version */
890 /* Get board HW version */
891 #define EC_CMD_GET_BOARD_VERSION 0x0006
893 struct __ec_align2 ec_response_board_version {
894 uint16_t board_version; /* A monotonously incrementing number. */
898 * Read memory-mapped data.
900 * This is an alternate interface to memory-mapped data for bus protocols
901 * which don't support direct-mapped memory - I2C, SPI, etc.
903 * Response is params.size bytes of data.
905 #define EC_CMD_READ_MEMMAP 0x0007
907 struct __ec_align1 ec_params_read_memmap {
908 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
909 uint8_t size; /* Size to read in bytes */
912 /* Read versions supported for a command */
913 #define EC_CMD_GET_CMD_VERSIONS 0x0008
915 struct __ec_align1 ec_params_get_cmd_versions {
916 uint8_t cmd; /* Command to check */
919 struct __ec_align2 ec_params_get_cmd_versions_v1 {
920 uint16_t cmd; /* Command to check */
923 struct __ec_align4 ec_response_get_cmd_versions {
925 * Mask of supported versions; use EC_VER_MASK() to compare with a
928 uint32_t version_mask;
932 * Check EC communications status (busy). This is needed on i2c/spi but not
933 * on lpc since it has its own out-of-band busy indicator.
935 * lpc must read the status from the command register. Attempting this on
936 * lpc will overwrite the args/parameter space and corrupt its data.
938 #define EC_CMD_GET_COMMS_STATUS 0x0009
940 /* Avoid using ec_status which is for return values */
941 enum ec_comms_status {
942 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
945 struct __ec_align4 ec_response_get_comms_status {
946 uint32_t flags; /* Mask of enum ec_comms_status */
949 /* Fake a variety of responses, purely for testing purposes. */
950 #define EC_CMD_TEST_PROTOCOL 0x000A
952 /* Tell the EC what to send back to us. */
953 struct __ec_align4 ec_params_test_protocol {
959 /* Here it comes... */
960 struct __ec_align4 ec_response_test_protocol {
964 /* Get protocol information */
965 #define EC_CMD_GET_PROTOCOL_INFO 0x000B
967 /* Flags for ec_response_get_protocol_info.flags */
968 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
969 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
971 struct __ec_align4 ec_response_get_protocol_info {
972 /* Fields which exist if at least protocol version 3 supported */
974 /* Bitmask of protocol versions supported (1 << n means version n)*/
975 uint32_t protocol_versions;
977 /* Maximum request packet size, in bytes */
978 uint16_t max_request_packet_size;
980 /* Maximum response packet size, in bytes */
981 uint16_t max_response_packet_size;
983 /* Flags; see EC_PROTOCOL_INFO_* */
988 /*****************************************************************************/
989 /* Get/Set miscellaneous values */
991 /* The upper byte of .flags tells what to do (nothing means "get") */
992 #define EC_GSV_SET 0x80000000
994 /* The lower three bytes of .flags identifies the parameter, if that has
995 meaning for an individual command. */
996 #define EC_GSV_PARAM_MASK 0x00ffffff
998 struct __ec_align4 ec_params_get_set_value {
1003 struct __ec_align4 ec_response_get_set_value {
1008 /* More than one command can use these structs to get/set parameters. */
1009 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
1011 /*****************************************************************************/
1012 /* List the features supported by the firmware */
1013 #define EC_CMD_GET_FEATURES 0x000D
1015 /* Supported features */
1016 enum ec_feature_code {
1018 * This image contains a limited set of features. Another image
1019 * in RW partition may support more features.
1021 EC_FEATURE_LIMITED = 0,
1023 * Commands for probing/reading/writing/erasing the flash in the
1026 EC_FEATURE_FLASH = 1,
1028 * Can control the fan speed directly.
1030 EC_FEATURE_PWM_FAN = 2,
1032 * Can control the intensity of the keyboard backlight.
1034 EC_FEATURE_PWM_KEYB = 3,
1036 * Support Google lightbar, introduced on Pixel.
1038 EC_FEATURE_LIGHTBAR = 4,
1039 /* Control of LEDs */
1041 /* Exposes an interface to control gyro and sensors.
1042 * The host goes through the EC to access these sensors.
1043 * In addition, the EC may provide composite sensors, like lid angle.
1045 EC_FEATURE_MOTION_SENSE = 6,
1046 /* The keyboard is controlled by the EC */
1047 EC_FEATURE_KEYB = 7,
1048 /* The AP can use part of the EC flash as persistent storage. */
1049 EC_FEATURE_PSTORE = 8,
1050 /* The EC monitors BIOS port 80h, and can return POST codes. */
1051 EC_FEATURE_PORT80 = 9,
1053 * Thermal management: include TMP specific commands.
1054 * Higher level than direct fan control.
1056 EC_FEATURE_THERMAL = 10,
1057 /* Can switch the screen backlight on/off */
1058 EC_FEATURE_BKLIGHT_SWITCH = 11,
1059 /* Can switch the wifi module on/off */
1060 EC_FEATURE_WIFI_SWITCH = 12,
1061 /* Monitor host events, through for example SMI or SCI */
1062 EC_FEATURE_HOST_EVENTS = 13,
1063 /* The EC exposes GPIO commands to control/monitor connected devices. */
1064 EC_FEATURE_GPIO = 14,
1065 /* The EC can send i2c messages to downstream devices. */
1066 EC_FEATURE_I2C = 15,
1067 /* Command to control charger are included */
1068 EC_FEATURE_CHARGER = 16,
1069 /* Simple battery support. */
1070 EC_FEATURE_BATTERY = 17,
1072 * Support Smart battery protocol
1073 * (Common Smart Battery System Interface Specification)
1075 EC_FEATURE_SMART_BATTERY = 18,
1076 /* EC can detect when the host hangs. */
1077 EC_FEATURE_HANG_DETECT = 19,
1078 /* Report power information, for pit only */
1079 EC_FEATURE_PMU = 20,
1080 /* Another Cros EC device is present downstream of this one */
1081 EC_FEATURE_SUB_MCU = 21,
1082 /* Support USB Power delivery (PD) commands */
1083 EC_FEATURE_USB_PD = 22,
1084 /* Control USB multiplexer, for audio through USB port for instance. */
1085 EC_FEATURE_USB_MUX = 23,
1086 /* Motion Sensor code has an internal software FIFO */
1087 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1088 /* Support temporary secure vstore */
1089 EC_FEATURE_VSTORE = 25,
1090 /* EC decides on USB-C SS mux state, muxes configured by host */
1091 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1092 /* EC has RTC feature that can be controlled by host commands */
1093 EC_FEATURE_RTC = 27,
1094 /* The MCU exposes a Fingerprint sensor */
1095 EC_FEATURE_FINGERPRINT = 28,
1096 /* The MCU exposes a Touchpad */
1097 EC_FEATURE_TOUCHPAD = 29,
1098 /* The MCU has RWSIG task enabled */
1099 EC_FEATURE_RWSIG = 30,
1100 /* EC has device events support */
1101 EC_FEATURE_DEVICE_EVENT = 31,
1102 /* EC supports the unified wake masks for LPC/eSPI systems */
1103 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1106 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1107 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
1108 struct __ec_align4 ec_response_get_features {
1112 /*****************************************************************************/
1113 /* Get the board's SKU ID from EC */
1114 #define EC_CMD_GET_SKU_ID 0x000E
1116 /* Set SKU ID from AP */
1117 #define EC_CMD_SET_SKU_ID 0x000F
1119 struct __ec_align4 ec_sku_id_info {
1123 /*****************************************************************************/
1124 /* Flash commands */
1126 /* Get flash info */
1127 #define EC_CMD_FLASH_INFO 0x0010
1128 #define EC_VER_FLASH_INFO 2
1130 /* Version 0 returns these fields */
1131 struct __ec_align4 ec_response_flash_info {
1132 /* Usable flash size, in bytes */
1133 uint32_t flash_size;
1135 * Write block size. Write offset and size must be a multiple
1138 uint32_t write_block_size;
1140 * Erase block size. Erase offset and size must be a multiple
1143 uint32_t erase_block_size;
1145 * Protection block size. Protection offset and size must be a
1148 uint32_t protect_block_size;
1151 /* Flags for version 1+ flash info command */
1152 /* EC flash erases bits to 0 instead of 1 */
1153 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1155 /* Flash must be selected for read/write/erase operations to succeed. This may
1156 * be necessary on a chip where write/erase can be corrupted by other board
1157 * activity, or where the chip needs to enable some sort of programming voltage,
1158 * or where the read/write/erase operations require cleanly suspending other
1159 * chip functionality. */
1160 #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1163 * Version 1 returns the same initial fields as version 0, with additional
1166 * gcc anonymous structs don't seem to get along with the __packed directive;
1167 * if they did we'd define the version 0 structure as a sub-structure of this
1170 * Version 2 supports flash banks of different sizes:
1171 * The caller specified the number of banks it has preallocated
1173 * The EC returns the number of banks describing the flash memory.
1174 * It adds banks descriptions up to num_banks_desc.
1176 struct __ec_align4 ec_response_flash_info_1 {
1177 /* Version 0 fields; see above for description */
1178 uint32_t flash_size;
1179 uint32_t write_block_size;
1180 uint32_t erase_block_size;
1181 uint32_t protect_block_size;
1183 /* Version 1 adds these fields: */
1185 * Ideal write size in bytes. Writes will be fastest if size is
1186 * exactly this and offset is a multiple of this. For example, an EC
1187 * may have a write buffer which can do half-page operations if data is
1188 * aligned, and a slower word-at-a-time write mode.
1190 uint32_t write_ideal_size;
1192 /* Flags; see EC_FLASH_INFO_* */
1196 struct __ec_align4 ec_params_flash_info_2 {
1197 /* Number of banks to describe */
1198 uint16_t num_banks_desc;
1199 /* Reserved; set 0; ignore on read */
1200 uint8_t reserved[2];
1203 struct ec_flash_bank {
1204 /* Number of sector is in this bank. */
1206 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1208 /* Minimal write size for the sectors in this bank */
1209 uint8_t write_size_exp;
1210 /* Erase size for the sectors in this bank */
1211 uint8_t erase_size_exp;
1212 /* Size for write protection, usually identical to erase size. */
1213 uint8_t protect_size_exp;
1214 /* Reserved; set 0; ignore on read */
1215 uint8_t reserved[2];
1218 struct __ec_align4 ec_response_flash_info_2 {
1219 /* Total flash in the EC. */
1220 uint32_t flash_size;
1221 /* Flags; see EC_FLASH_INFO_* */
1223 /* Maximum size to use to send data to write to the EC. */
1224 uint32_t write_ideal_size;
1225 /* Number of banks present in the EC. */
1226 uint16_t num_banks_total;
1227 /* Number of banks described in banks array. */
1228 uint16_t num_banks_desc;
1229 struct ec_flash_bank banks[0];
1235 * Response is params.size bytes of data.
1237 #define EC_CMD_FLASH_READ 0x0011
1239 struct __ec_align4 ec_params_flash_read {
1240 uint32_t offset; /* Byte offset to read */
1241 uint32_t size; /* Size to read in bytes */
1245 #define EC_CMD_FLASH_WRITE 0x0012
1246 #define EC_VER_FLASH_WRITE 1
1248 /* Version 0 of the flash command supported only 64 bytes of data */
1249 #define EC_FLASH_WRITE_VER0_SIZE 64
1251 struct __ec_align4 ec_params_flash_write {
1252 uint32_t offset; /* Byte offset to write */
1253 uint32_t size; /* Size to write in bytes */
1254 /* Followed by data to write */
1258 #define EC_CMD_FLASH_ERASE 0x0013
1261 struct __ec_align4 ec_params_flash_erase {
1262 uint32_t offset; /* Byte offset to erase */
1263 uint32_t size; /* Size to erase in bytes */
1267 #define EC_VER_FLASH_WRITE 1
1268 /* v1 add async erase:
1269 * subcommands can returns:
1270 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1271 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1272 * EC_RES_ERROR : other errors.
1273 * EC_RES_BUSY : an existing erase operation is in progress.
1274 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1276 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1277 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1278 * the proper result.
1279 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1280 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1281 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1282 * permitted while erasing. (For instance, STM32F4).
1284 enum ec_flash_erase_cmd {
1285 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1286 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1287 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1290 struct __ec_align4 ec_params_flash_erase_v1 {
1291 /* One of ec_flash_erase_cmd. */
1293 /* Pad byte; currently always contains 0 */
1295 /* No flags defined yet; set to 0 */
1297 /* Same as v0 parameters. */
1298 struct ec_params_flash_erase params;
1302 * Get/set flash protection.
1304 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1305 * firmware write protect GPIO, not all flags will take effect immediately;
1306 * some flags require a subsequent hard reset to take effect. Check the
1307 * returned flags bits to see what actually happened.
1309 * If mask=0, simply returns the current flags state.
1311 #define EC_CMD_FLASH_PROTECT 0x0015
1312 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1314 /* Flags for flash protection */
1315 /* RO flash code protected when the EC boots */
1316 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1318 * RO flash code protected now. If this bit is set, at-boot status cannot
1321 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1322 /* Entire flash code protected now, until reboot. */
1323 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1324 /* Flash write protect GPIO is asserted now */
1325 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1326 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1327 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1329 * Error - flash protection is in inconsistent state. At least one bank of
1330 * flash which should be protected is not protected. Usually fixed by
1331 * re-requesting the desired flags, or by a hard reset if that fails.
1333 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1334 /* Entire flash code protected when the EC boots */
1335 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1336 /* RW flash code protected when the EC boots */
1337 #define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1338 /* RW flash code protected now. */
1339 #define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1340 /* Rollback information flash region protected when the EC boots */
1341 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1342 /* Rollback information flash region protected now */
1343 #define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
1345 struct __ec_align4 ec_params_flash_protect {
1346 uint32_t mask; /* Bits in flags to apply */
1347 uint32_t flags; /* New flags to apply */
1350 struct __ec_align4 ec_response_flash_protect {
1351 /* Current value of flash protect flags */
1354 * Flags which are valid on this platform. This allows the caller
1355 * to distinguish between flags which aren't set vs. flags which can't
1356 * be set on this platform.
1358 uint32_t valid_flags;
1359 /* Flags which can be changed given the current protection state */
1360 uint32_t writable_flags;
1364 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1365 * write protect. These commands may be reused with version > 0.
1368 /* Get the region offset/size */
1369 #define EC_CMD_FLASH_REGION_INFO 0x0016
1370 #define EC_VER_FLASH_REGION_INFO 1
1372 enum ec_flash_region {
1373 /* Region which holds read-only EC image */
1374 EC_FLASH_REGION_RO = 0,
1375 /* Region which holds active rewritable EC image */
1376 EC_FLASH_REGION_ACTIVE,
1378 * Region which should be write-protected in the factory (a superset of
1379 * EC_FLASH_REGION_RO)
1381 EC_FLASH_REGION_WP_RO,
1382 /* Region which holds updatable image */
1383 EC_FLASH_REGION_UPDATE,
1384 /* Number of regions */
1385 EC_FLASH_REGION_COUNT,
1388 struct __ec_align4 ec_params_flash_region_info {
1389 uint32_t region; /* enum ec_flash_region */
1392 struct __ec_align4 ec_response_flash_region_info {
1397 /* Read/write VbNvContext */
1398 #define EC_CMD_VBNV_CONTEXT 0x0017
1399 #define EC_VER_VBNV_CONTEXT 1
1400 #define EC_VBNV_BLOCK_SIZE 16
1401 #define EC_VBNV_BLOCK_SIZE_V2 64
1403 enum ec_vbnvcontext_op {
1404 EC_VBNV_CONTEXT_OP_READ,
1405 EC_VBNV_CONTEXT_OP_WRITE,
1408 struct __ec_align4 ec_params_vbnvcontext {
1410 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1413 struct __ec_align4 ec_response_vbnvcontext {
1414 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1418 /* Get SPI flash information */
1419 #define EC_CMD_FLASH_SPI_INFO 0x0018
1421 struct __ec_align1 ec_response_flash_spi_info {
1422 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1425 /* Pad byte; currently always contains 0 */
1428 /* Manufacturer / device ID from command 0x90 */
1429 uint8_t mfr_dev_id[2];
1431 /* Status registers from command 0x05 and 0x35 */
1436 /* Select flash during flash operations */
1437 #define EC_CMD_FLASH_SELECT 0x0019
1439 struct __ec_align4 ec_params_flash_select {
1440 /* 1 to select flash, 0 to deselect flash */
1444 /*****************************************************************************/
1447 /* Get fan target RPM */
1448 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1450 struct __ec_align4 ec_response_pwm_get_fan_rpm {
1454 /* Set target fan RPM */
1455 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1457 /* Version 0 of input params */
1458 struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
1462 /* Version 1 of input params */
1463 struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
1468 /* Get keyboard backlight */
1469 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1470 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1472 struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
1477 /* Set keyboard backlight */
1478 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1479 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1481 struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
1485 /* Set target fan PWM duty cycle */
1486 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1488 /* Version 0 of input params */
1489 struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
1493 /* Version 1 of input params */
1494 struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
1499 #define EC_CMD_PWM_SET_DUTY 0x0025
1500 /* 16 bit duty cycle, 0xffff = 100% */
1501 #define EC_PWM_MAX_DUTY 0xffff
1504 /* All types, indexed by board-specific enum pwm_channel */
1505 EC_PWM_TYPE_GENERIC = 0,
1506 /* Keyboard backlight */
1507 EC_PWM_TYPE_KB_LIGHT,
1508 /* Display backlight */
1509 EC_PWM_TYPE_DISPLAY_LIGHT,
1513 struct __ec_align4 ec_params_pwm_set_duty {
1514 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1515 uint8_t pwm_type; /* ec_pwm_type */
1516 uint8_t index; /* Type-specific index, or 0 if unique */
1519 #define EC_CMD_PWM_GET_DUTY 0x0026
1521 struct __ec_align1 ec_params_pwm_get_duty {
1522 uint8_t pwm_type; /* ec_pwm_type */
1523 uint8_t index; /* Type-specific index, or 0 if unique */
1526 struct __ec_align2 ec_response_pwm_get_duty {
1527 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1530 /*****************************************************************************/
1532 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1533 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1534 * into a subcommand. We'll make separate structs for subcommands with
1535 * different input args, so that we know how much to expect.
1537 #define EC_CMD_LIGHTBAR_CMD 0x0028
1539 struct __ec_todo_unpacked rgb_s {
1543 #define LB_BATTERY_LEVELS 4
1544 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1545 * host command, but the alignment is the same regardless. Keep it that way.
1547 struct __ec_todo_packed lightbar_params_v0 {
1549 int32_t google_ramp_up;
1550 int32_t google_ramp_down;
1551 int32_t s3s0_ramp_up;
1552 int32_t s0_tick_delay[2]; /* AC=0/1 */
1553 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1554 int32_t s0s3_ramp_down;
1555 int32_t s3_sleep_for;
1557 int32_t s3_ramp_down;
1561 uint8_t osc_min[2]; /* AC=0/1 */
1562 uint8_t osc_max[2]; /* AC=0/1 */
1563 uint8_t w_ofs[2]; /* AC=0/1 */
1565 /* Brightness limits based on the backlight and AC. */
1566 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1567 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1568 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1570 /* Battery level thresholds */
1571 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1573 /* Map [AC][battery_level] to color index */
1574 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1575 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1578 struct rgb_s color[8]; /* 0-3 are Google colors */
1581 struct __ec_todo_packed lightbar_params_v1 {
1583 int32_t google_ramp_up;
1584 int32_t google_ramp_down;
1585 int32_t s3s0_ramp_up;
1586 int32_t s0_tick_delay[2]; /* AC=0/1 */
1587 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1588 int32_t s0s3_ramp_down;
1589 int32_t s3_sleep_for;
1591 int32_t s3_ramp_down;
1593 int32_t s5_ramp_down;
1594 int32_t tap_tick_delay;
1595 int32_t tap_gate_delay;
1596 int32_t tap_display_time;
1598 /* Tap-for-battery params */
1599 uint8_t tap_pct_red;
1600 uint8_t tap_pct_green;
1601 uint8_t tap_seg_min_on;
1602 uint8_t tap_seg_max_on;
1603 uint8_t tap_seg_osc;
1607 uint8_t osc_min[2]; /* AC=0/1 */
1608 uint8_t osc_max[2]; /* AC=0/1 */
1609 uint8_t w_ofs[2]; /* AC=0/1 */
1611 /* Brightness limits based on the backlight and AC. */
1612 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1613 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1614 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1616 /* Battery level thresholds */
1617 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1619 /* Map [AC][battery_level] to color index */
1620 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1621 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1623 /* s5: single color pulse on inhibited power-up */
1627 struct rgb_s color[8]; /* 0-3 are Google colors */
1630 /* Lightbar command params v2
1633 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1634 * logical groups to make it more manageable ( < 120 bytes).
1636 * NOTE: Each of these groups must be less than 120 bytes.
1639 struct __ec_todo_packed lightbar_params_v2_timing {
1641 int32_t google_ramp_up;
1642 int32_t google_ramp_down;
1643 int32_t s3s0_ramp_up;
1644 int32_t s0_tick_delay[2]; /* AC=0/1 */
1645 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1646 int32_t s0s3_ramp_down;
1647 int32_t s3_sleep_for;
1649 int32_t s3_ramp_down;
1651 int32_t s5_ramp_down;
1652 int32_t tap_tick_delay;
1653 int32_t tap_gate_delay;
1654 int32_t tap_display_time;
1657 struct __ec_todo_packed lightbar_params_v2_tap {
1658 /* Tap-for-battery params */
1659 uint8_t tap_pct_red;
1660 uint8_t tap_pct_green;
1661 uint8_t tap_seg_min_on;
1662 uint8_t tap_seg_max_on;
1663 uint8_t tap_seg_osc;
1667 struct __ec_todo_packed lightbar_params_v2_oscillation {
1669 uint8_t osc_min[2]; /* AC=0/1 */
1670 uint8_t osc_max[2]; /* AC=0/1 */
1671 uint8_t w_ofs[2]; /* AC=0/1 */
1674 struct __ec_todo_packed lightbar_params_v2_brightness {
1675 /* Brightness limits based on the backlight and AC. */
1676 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1677 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1678 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1681 struct __ec_todo_packed lightbar_params_v2_thresholds {
1682 /* Battery level thresholds */
1683 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1686 struct __ec_todo_packed lightbar_params_v2_colors {
1687 /* Map [AC][battery_level] to color index */
1688 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1689 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1691 /* s5: single color pulse on inhibited power-up */
1695 struct rgb_s color[8]; /* 0-3 are Google colors */
1698 /* Lightbyte program. */
1699 #define EC_LB_PROG_LEN 192
1700 struct __ec_todo_unpacked lightbar_program {
1702 uint8_t data[EC_LB_PROG_LEN];
1705 struct __ec_todo_packed ec_params_lightbar {
1706 uint8_t cmd; /* Command (see enum lightbar_command) */
1708 struct __ec_todo_unpacked {
1710 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1711 version, get_brightness, get_demo, suspend, resume,
1712 get_params_v2_timing, get_params_v2_tap,
1713 get_params_v2_osc, get_params_v2_bright,
1714 get_params_v2_thlds, get_params_v2_colors;
1716 struct __ec_todo_unpacked {
1718 } set_brightness, seq, demo;
1720 struct __ec_todo_unpacked {
1721 uint8_t ctrl, reg, value;
1724 struct __ec_todo_unpacked {
1725 uint8_t led, red, green, blue;
1728 struct __ec_todo_unpacked {
1732 struct __ec_todo_unpacked {
1734 } manual_suspend_ctrl;
1736 struct lightbar_params_v0 set_params_v0;
1737 struct lightbar_params_v1 set_params_v1;
1739 struct lightbar_params_v2_timing set_v2par_timing;
1740 struct lightbar_params_v2_tap set_v2par_tap;
1741 struct lightbar_params_v2_oscillation set_v2par_osc;
1742 struct lightbar_params_v2_brightness set_v2par_bright;
1743 struct lightbar_params_v2_thresholds set_v2par_thlds;
1744 struct lightbar_params_v2_colors set_v2par_colors;
1746 struct lightbar_program set_program;
1750 struct __ec_todo_packed ec_response_lightbar {
1752 struct __ec_todo_unpacked {
1753 struct __ec_todo_unpacked {
1760 struct __ec_todo_unpacked {
1762 } get_seq, get_brightness, get_demo;
1764 struct lightbar_params_v0 get_params_v0;
1765 struct lightbar_params_v1 get_params_v1;
1768 struct lightbar_params_v2_timing get_params_v2_timing;
1769 struct lightbar_params_v2_tap get_params_v2_tap;
1770 struct lightbar_params_v2_oscillation get_params_v2_osc;
1771 struct lightbar_params_v2_brightness get_params_v2_bright;
1772 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1773 struct lightbar_params_v2_colors get_params_v2_colors;
1775 struct __ec_todo_unpacked {
1780 struct __ec_todo_unpacked {
1781 uint8_t red, green, blue;
1784 struct __ec_todo_unpacked {
1785 /* no return params */
1786 } off, on, init, set_brightness, seq, reg, set_rgb,
1787 demo, set_params_v0, set_params_v1,
1788 set_program, manual_suspend_ctrl, suspend, resume,
1789 set_v2par_timing, set_v2par_tap,
1790 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1795 /* Lightbar commands */
1796 enum lightbar_command {
1797 LIGHTBAR_CMD_DUMP = 0,
1798 LIGHTBAR_CMD_OFF = 1,
1799 LIGHTBAR_CMD_ON = 2,
1800 LIGHTBAR_CMD_INIT = 3,
1801 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1802 LIGHTBAR_CMD_SEQ = 5,
1803 LIGHTBAR_CMD_REG = 6,
1804 LIGHTBAR_CMD_SET_RGB = 7,
1805 LIGHTBAR_CMD_GET_SEQ = 8,
1806 LIGHTBAR_CMD_DEMO = 9,
1807 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1808 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1809 LIGHTBAR_CMD_VERSION = 12,
1810 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1811 LIGHTBAR_CMD_GET_RGB = 14,
1812 LIGHTBAR_CMD_GET_DEMO = 15,
1813 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1814 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1815 LIGHTBAR_CMD_SET_PROGRAM = 18,
1816 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1817 LIGHTBAR_CMD_SUSPEND = 20,
1818 LIGHTBAR_CMD_RESUME = 21,
1819 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1820 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1821 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1822 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1823 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1824 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1825 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1826 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1827 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1828 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1829 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1830 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
1834 /*****************************************************************************/
1835 /* LED control commands */
1837 #define EC_CMD_LED_CONTROL 0x0029
1840 /* LED to indicate battery state of charge */
1841 EC_LED_ID_BATTERY_LED = 0,
1843 * LED to indicate system power state (on or in suspend).
1844 * May be on power button or on C-panel.
1846 EC_LED_ID_POWER_LED,
1847 /* LED on power adapter or its plug */
1848 EC_LED_ID_ADAPTER_LED,
1849 /* LED to indicate left side */
1851 /* LED to indicate right side */
1852 EC_LED_ID_RIGHT_LED,
1853 /* LED to indicate recovery mode with HW_REINIT */
1854 EC_LED_ID_RECOVERY_HW_REINIT_LED,
1855 /* LED to indicate sysrq debug mode. */
1856 EC_LED_ID_SYSRQ_DEBUG_LED,
1861 /* LED control flags */
1862 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1863 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1865 enum ec_led_colors {
1866 EC_LED_COLOR_RED = 0,
1869 EC_LED_COLOR_YELLOW,
1876 struct __ec_align1 ec_params_led_control {
1877 uint8_t led_id; /* Which LED to control */
1878 uint8_t flags; /* Control flags */
1880 uint8_t brightness[EC_LED_COLOR_COUNT];
1883 struct __ec_align1 ec_response_led_control {
1885 * Available brightness value range.
1887 * Range 0 means color channel not present.
1888 * Range 1 means on/off control.
1889 * Other values means the LED is control by PWM.
1891 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1894 /*****************************************************************************/
1895 /* Verified boot commands */
1898 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1899 * reused for other purposes with version > 0.
1902 /* Verified boot hash command */
1903 #define EC_CMD_VBOOT_HASH 0x002A
1905 struct __ec_align4 ec_params_vboot_hash {
1906 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1907 uint8_t hash_type; /* enum ec_vboot_hash_type */
1908 uint8_t nonce_size; /* Nonce size; may be 0 */
1909 uint8_t reserved0; /* Reserved; set 0 */
1910 uint32_t offset; /* Offset in flash to hash */
1911 uint32_t size; /* Number of bytes to hash */
1912 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1915 struct __ec_align4 ec_response_vboot_hash {
1916 uint8_t status; /* enum ec_vboot_hash_status */
1917 uint8_t hash_type; /* enum ec_vboot_hash_type */
1918 uint8_t digest_size; /* Size of hash digest in bytes */
1919 uint8_t reserved0; /* Ignore; will be 0 */
1920 uint32_t offset; /* Offset in flash which was hashed */
1921 uint32_t size; /* Number of bytes hashed */
1922 uint8_t hash_digest[64]; /* Hash digest data */
1925 enum ec_vboot_hash_cmd {
1926 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1927 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1928 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1929 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1932 enum ec_vboot_hash_type {
1933 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1936 enum ec_vboot_hash_status {
1937 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1938 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1939 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1943 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1944 * If one of these is specified, the EC will automatically update offset and
1945 * size to the correct values for the specified image (RO or RW).
1947 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1948 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
1949 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
1951 /*****************************************************************************/
1953 * Motion sense commands. We'll make separate structs for sub-commands with
1954 * different input args, so that we know how much to expect.
1956 #define EC_CMD_MOTION_SENSE_CMD 0x002B
1958 /* Motion sense commands */
1959 enum motionsense_command {
1961 * Dump command returns all motion sensor data including motion sense
1962 * module flags and individual sensor flags.
1964 MOTIONSENSE_CMD_DUMP = 0,
1967 * Info command returns data describing the details of a given sensor,
1968 * including enum motionsensor_type, enum motionsensor_location, and
1969 * enum motionsensor_chip.
1971 MOTIONSENSE_CMD_INFO = 1,
1974 * EC Rate command is a setter/getter command for the EC sampling rate
1976 * It is per sensor, the EC run sample task at the minimum of all
1978 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1979 * to collect all the sensor samples.
1980 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1981 * to process of all motion sensors in milliseconds.
1983 MOTIONSENSE_CMD_EC_RATE = 2,
1986 * Sensor ODR command is a setter/getter command for the output data
1987 * rate of a specific motion sensor in millihertz.
1989 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1992 * Sensor range command is a setter/getter command for the range of
1993 * a specified motion sensor in +/-G's or +/- deg/s.
1995 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1998 * Setter/getter command for the keyboard wake angle. When the lid
1999 * angle is greater than this value, keyboard wake is disabled in S3,
2000 * and when the lid angle goes less than this value, keyboard wake is
2001 * enabled. Note, the lid angle measurement is an approximate,
2002 * un-calibrated value, hence the wake angle isn't exact.
2004 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2007 * Returns a single sensor data.
2009 MOTIONSENSE_CMD_DATA = 6,
2012 * Return sensor fifo info.
2014 MOTIONSENSE_CMD_FIFO_INFO = 7,
2017 * Insert a flush element in the fifo and return sensor fifo info.
2018 * The host can use that element to synchronize its operation.
2020 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2023 * Return a portion of the fifo.
2025 MOTIONSENSE_CMD_FIFO_READ = 9,
2028 * Perform low level calibration.
2029 * On sensors that support it, ask to do offset calibration.
2031 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2034 * Sensor Offset command is a setter/getter command for the offset
2035 * used for calibration.
2036 * The offsets can be calculated by the host, or via
2037 * PERFORM_CALIB command.
2039 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2042 * List available activities for a MOTION sensor.
2043 * Indicates if they are enabled or disabled.
2045 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2048 * Activity management
2049 * Enable/Disable activity recognition.
2051 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2056 MOTIONSENSE_CMD_LID_ANGLE = 14,
2059 * Allow the FIFO to trigger interrupt via MKBP events.
2060 * By default the FIFO does not send interrupt to process the FIFO
2061 * until the AP is ready or it is coming from a wakeup sensor.
2063 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2066 * Spoof the readings of the sensors. The spoofed readings can be set
2067 * to arbitrary values, or will lock to the last read actual values.
2069 MOTIONSENSE_CMD_SPOOF = 16,
2071 /* Number of motionsense sub-commands. */
2072 MOTIONSENSE_NUM_CMDS
2075 /* List of motion sensor types. */
2076 enum motionsensor_type {
2077 MOTIONSENSE_TYPE_ACCEL = 0,
2078 MOTIONSENSE_TYPE_GYRO = 1,
2079 MOTIONSENSE_TYPE_MAG = 2,
2080 MOTIONSENSE_TYPE_PROX = 3,
2081 MOTIONSENSE_TYPE_LIGHT = 4,
2082 MOTIONSENSE_TYPE_ACTIVITY = 5,
2083 MOTIONSENSE_TYPE_BARO = 6,
2084 MOTIONSENSE_TYPE_MAX,
2087 /* List of motion sensor locations. */
2088 enum motionsensor_location {
2089 MOTIONSENSE_LOC_BASE = 0,
2090 MOTIONSENSE_LOC_LID = 1,
2091 MOTIONSENSE_LOC_MAX,
2094 /* List of motion sensor chips. */
2095 enum motionsensor_chip {
2096 MOTIONSENSE_CHIP_KXCJ9 = 0,
2097 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2098 MOTIONSENSE_CHIP_BMI160 = 2,
2099 MOTIONSENSE_CHIP_SI1141 = 3,
2100 MOTIONSENSE_CHIP_SI1142 = 4,
2101 MOTIONSENSE_CHIP_SI1143 = 5,
2102 MOTIONSENSE_CHIP_KX022 = 6,
2103 MOTIONSENSE_CHIP_L3GD20H = 7,
2104 MOTIONSENSE_CHIP_BMA255 = 8,
2105 MOTIONSENSE_CHIP_BMP280 = 9,
2106 MOTIONSENSE_CHIP_OPT3001 = 10,
2109 struct __ec_todo_packed ec_response_motion_sensor_data {
2110 /* Flags for each sensor. */
2112 /* sensor number the data comes from */
2114 /* Each sensor is up to 3-axis. */
2117 struct __ec_todo_packed {
2121 struct __ec_todo_unpacked {
2122 uint8_t activity; /* motionsensor_activity */
2124 int16_t add_info[2];
2129 /* Note: used in ec_response_get_next_data */
2130 struct __ec_todo_packed ec_response_motion_sense_fifo_info {
2131 /* Size of the fifo */
2133 /* Amount of space used in the fifo */
2135 /* Timestamp recorded in us */
2137 /* Total amount of vector lost */
2138 uint16_t total_lost;
2139 /* Lost events since the last fifo_info, per sensors */
2143 struct __ec_todo_packed ec_response_motion_sense_fifo_data {
2144 uint32_t number_data;
2145 struct ec_response_motion_sensor_data data[0];
2148 /* List supported activity recognition */
2149 enum motionsensor_activity {
2150 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2151 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2152 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2155 struct __ec_todo_unpacked ec_motion_sense_activity {
2157 uint8_t activity; /* one of enum motionsensor_activity */
2158 uint8_t enable; /* 1: enable, 0: disable */
2160 uint16_t parameters[3]; /* activity dependent parameters */
2163 /* Module flag masks used for the dump sub-command. */
2164 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2166 /* Sensor flag masks used for the dump sub-command. */
2167 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2170 * Flush entry for synchronization.
2171 * data contains time stamp
2173 #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2174 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2175 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
2176 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
2179 * Send this value for the data element to only perform a read. If you
2180 * send any other value, the EC will interpret it as data to set and will
2181 * return the actual value set.
2183 #define EC_MOTION_SENSE_NO_VALUE -1
2185 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2187 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2188 /* Set Calibration information */
2189 #define MOTION_SENSE_SET_OFFSET 1
2191 #define LID_ANGLE_UNRELIABLE 500
2193 enum motionsense_spoof_mode {
2194 /* Disable spoof mode. */
2195 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2197 /* Enable spoof mode, but use provided component values. */
2198 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2200 /* Enable spoof mode, but use the current sensor values. */
2201 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2203 /* Query the current spoof mode status for the sensor. */
2204 MOTIONSENSE_SPOOF_MODE_QUERY,
2207 struct __ec_todo_packed ec_params_motion_sense {
2210 /* Used for MOTIONSENSE_CMD_DUMP */
2211 struct __ec_todo_unpacked {
2213 * Maximal number of sensor the host is expecting.
2214 * 0 means the host is only interested in the number
2215 * of sensors controlled by the EC.
2217 uint8_t max_sensor_count;
2221 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2223 struct __ec_todo_unpacked {
2224 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2225 * kb_wake_angle: angle to wakup AP.
2230 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2231 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
2232 struct __ec_todo_unpacked {
2234 } info, info_3, data, fifo_flush, perform_calib,
2238 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2239 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2241 struct __ec_todo_unpacked {
2244 /* Rounding flag, true for round-up, false for down. */
2249 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2251 } ec_rate, sensor_odr, sensor_range;
2253 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2254 struct __ec_todo_packed {
2258 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2259 * the calibration information in the EC.
2260 * If unset, just retrieve calibration information.
2265 * Temperature at calibration, in units of 0.01 C
2266 * 0x8000: invalid / unknown.
2273 * Offset for calibration.
2275 * Accelerometer: 1/1024 g
2276 * Gyro: 1/1024 deg/s
2282 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
2283 struct __ec_todo_unpacked {
2286 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2287 struct __ec_todo_unpacked {
2289 * Number of expected vector to return.
2290 * EC may return less or 0 if none available.
2292 uint32_t max_data_vector;
2295 struct ec_motion_sense_activity set_activity;
2297 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2298 struct __ec_todo_unpacked {
2301 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2302 struct __ec_todo_unpacked {
2304 * 1: enable, 0 disable fifo,
2305 * EC_MOTION_SENSE_NO_VALUE return value.
2310 /* Used for MOTIONSENSE_CMD_SPOOF */
2311 struct __ec_todo_packed {
2314 /* See enum motionsense_spoof_mode. */
2315 uint8_t spoof_enable;
2317 /* Ignored, used for alignment. */
2320 /* Individual component values to spoof. */
2321 int16_t components[3];
2326 struct __ec_todo_packed ec_response_motion_sense {
2328 /* Used for MOTIONSENSE_CMD_DUMP */
2329 struct __ec_todo_unpacked {
2330 /* Flags representing the motion sensor module. */
2331 uint8_t module_flags;
2333 /* Number of sensors managed directly by the EC */
2334 uint8_t sensor_count;
2337 * sensor data is truncated if response_max is too small
2338 * for holding all the data.
2340 struct ec_response_motion_sensor_data sensor[0];
2343 /* Used for MOTIONSENSE_CMD_INFO. */
2344 struct __ec_todo_unpacked {
2345 /* Should be element of enum motionsensor_type. */
2348 /* Should be element of enum motionsensor_location. */
2351 /* Should be element of enum motionsensor_chip. */
2355 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2356 struct __ec_todo_unpacked {
2357 /* Should be element of enum motionsensor_type. */
2360 /* Should be element of enum motionsensor_location. */
2363 /* Should be element of enum motionsensor_chip. */
2366 /* Minimum sensor sampling frequency */
2367 uint32_t min_frequency;
2369 /* Maximum sensor sampling frequency */
2370 uint32_t max_frequency;
2372 /* Max number of sensor events that could be in fifo */
2373 uint32_t fifo_max_event_count;
2376 /* Used for MOTIONSENSE_CMD_DATA */
2377 struct ec_response_motion_sensor_data data;
2380 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2381 * MOTIONSENSE_CMD_SENSOR_RANGE,
2382 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2383 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2384 * MOTIONSENSE_CMD_SPOOF.
2386 struct __ec_todo_unpacked {
2387 /* Current value of the parameter queried. */
2389 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2390 fifo_int_enable, spoof;
2392 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2393 struct __ec_todo_unpacked {
2396 } sensor_offset, perform_calib;
2398 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2400 struct ec_response_motion_sense_fifo_data fifo_read;
2402 struct __ec_todo_packed {
2408 struct __ec_todo_unpacked {
2411 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2412 struct __ec_todo_unpacked {
2414 * Angle between 0 and 360 degree if available,
2415 * LID_ANGLE_UNRELIABLE otherwise.
2422 /*****************************************************************************/
2423 /* Force lid open command */
2425 /* Make lid event always open */
2426 #define EC_CMD_FORCE_LID_OPEN 0x002C
2428 struct __ec_align1 ec_params_force_lid_open {
2432 /*****************************************************************************/
2433 /* Configure the behavior of the power button */
2434 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2436 enum ec_config_power_button_flags {
2437 /* Enable/Disable power button pulses for x86 devices */
2438 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2441 struct __ec_align1 ec_params_config_power_button {
2442 /* See enum ec_config_power_button_flags */
2446 /*****************************************************************************/
2447 /* USB charging control commands */
2449 /* Set USB port charging mode */
2450 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2452 struct __ec_align1 ec_params_usb_charge_set_mode {
2453 uint8_t usb_port_id;
2457 /*****************************************************************************/
2458 /* Persistent storage for host */
2460 /* Maximum bytes that can be read/written in a single command */
2461 #define EC_PSTORE_SIZE_MAX 64
2463 /* Get persistent storage info */
2464 #define EC_CMD_PSTORE_INFO 0x0040
2466 struct __ec_align4 ec_response_pstore_info {
2467 /* Persistent storage size, in bytes */
2468 uint32_t pstore_size;
2469 /* Access size; read/write offset and size must be a multiple of this */
2470 uint32_t access_size;
2474 * Read persistent storage
2476 * Response is params.size bytes of data.
2478 #define EC_CMD_PSTORE_READ 0x0041
2480 struct __ec_align4 ec_params_pstore_read {
2481 uint32_t offset; /* Byte offset to read */
2482 uint32_t size; /* Size to read in bytes */
2485 /* Write persistent storage */
2486 #define EC_CMD_PSTORE_WRITE 0x0042
2488 struct __ec_align4 ec_params_pstore_write {
2489 uint32_t offset; /* Byte offset to write */
2490 uint32_t size; /* Size to write in bytes */
2491 uint8_t data[EC_PSTORE_SIZE_MAX];
2494 /*****************************************************************************/
2495 /* Real-time clock */
2497 /* RTC params and response structures */
2498 struct __ec_align4 ec_params_rtc {
2502 struct __ec_align4 ec_response_rtc {
2506 /* These use ec_response_rtc */
2507 #define EC_CMD_RTC_GET_VALUE 0x0044
2508 #define EC_CMD_RTC_GET_ALARM 0x0045
2510 /* These all use ec_params_rtc */
2511 #define EC_CMD_RTC_SET_VALUE 0x0046
2512 #define EC_CMD_RTC_SET_ALARM 0x0047
2514 /* Pass as time param to SET_ALARM to clear the current alarm */
2515 #define EC_RTC_ALARM_CLEAR 0
2517 /*****************************************************************************/
2518 /* Port80 log access */
2520 /* Maximum entries that can be read/written in a single command */
2521 #define EC_PORT80_SIZE_MAX 32
2523 /* Get last port80 code from previous boot */
2524 #define EC_CMD_PORT80_LAST_BOOT 0x0048
2525 #define EC_CMD_PORT80_READ 0x0048
2527 enum ec_port80_subcmd {
2528 EC_PORT80_GET_INFO = 0,
2529 EC_PORT80_READ_BUFFER,
2532 struct __ec_todo_packed ec_params_port80_read {
2535 struct __ec_todo_unpacked {
2537 uint32_t num_entries;
2542 struct __ec_todo_packed ec_response_port80_read {
2544 struct __ec_todo_unpacked {
2546 uint32_t history_size;
2549 struct __ec_todo_unpacked {
2550 uint16_t codes[EC_PORT80_SIZE_MAX];
2555 struct __ec_align2 ec_response_port80_last_boot {
2559 /*****************************************************************************/
2560 /* Temporary secure storage for host verified boot use */
2562 /* Number of bytes in a vstore slot */
2563 #define EC_VSTORE_SLOT_SIZE 64
2565 /* Maximum number of vstore slots */
2566 #define EC_VSTORE_SLOT_MAX 32
2568 /* Get persistent storage info */
2569 #define EC_CMD_VSTORE_INFO 0x0049
2570 struct __ec_align_size1 ec_response_vstore_info {
2571 /* Indicates which slots are locked */
2572 uint32_t slot_locked;
2573 /* Total number of slots available */
2578 * Read temporary secure storage
2580 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2582 #define EC_CMD_VSTORE_READ 0x004A
2584 struct __ec_align1 ec_params_vstore_read {
2585 uint8_t slot; /* Slot to read from */
2588 struct __ec_align1 ec_response_vstore_read {
2589 uint8_t data[EC_VSTORE_SLOT_SIZE];
2593 * Write temporary secure storage and lock it.
2595 #define EC_CMD_VSTORE_WRITE 0x004B
2597 struct __ec_align1 ec_params_vstore_write {
2598 uint8_t slot; /* Slot to write to */
2599 uint8_t data[EC_VSTORE_SLOT_SIZE];
2602 /*****************************************************************************/
2603 /* Thermal engine commands. Note that there are two implementations. We'll
2604 * reuse the command number, but the data and behavior is incompatible.
2605 * Version 0 is what originally shipped on Link.
2606 * Version 1 separates the CPU thermal limits from the fan control.
2609 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2610 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
2612 /* The version 0 structs are opaque. You have to know what they are for
2613 * the get/set commands to make any sense.
2616 /* Version 0 - set */
2617 struct __ec_align2 ec_params_thermal_set_threshold {
2618 uint8_t sensor_type;
2619 uint8_t threshold_id;
2623 /* Version 0 - get */
2624 struct __ec_align1 ec_params_thermal_get_threshold {
2625 uint8_t sensor_type;
2626 uint8_t threshold_id;
2629 struct __ec_align2 ec_response_thermal_get_threshold {
2634 /* The version 1 structs are visible. */
2635 enum ec_temp_thresholds {
2636 EC_TEMP_THRESH_WARN = 0,
2637 EC_TEMP_THRESH_HIGH,
2638 EC_TEMP_THRESH_HALT,
2640 EC_TEMP_THRESH_COUNT
2644 * Thermal configuration for one temperature sensor. Temps are in degrees K.
2645 * Zero values will be silently ignored by the thermal task.
2647 * Note that this structure is a sub-structure of
2648 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
2650 struct __ec_align4 ec_thermal_config {
2651 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2652 uint32_t temp_fan_off; /* no active cooling needed */
2653 uint32_t temp_fan_max; /* max active cooling needed */
2656 /* Version 1 - get config for one sensor. */
2657 struct __ec_align4 ec_params_thermal_get_threshold_v1 {
2658 uint32_t sensor_num;
2660 /* This returns a struct ec_thermal_config */
2662 /* Version 1 - set config for one sensor.
2663 * Use read-modify-write for best results! */
2664 struct __ec_align4 ec_params_thermal_set_threshold_v1 {
2665 uint32_t sensor_num;
2666 struct ec_thermal_config cfg;
2668 /* This returns no data */
2670 /****************************************************************************/
2672 /* Toggle automatic fan control */
2673 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
2675 /* Version 1 of input params */
2676 struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
2680 /* Get/Set TMP006 calibration data */
2681 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2682 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
2685 * The original TMP006 calibration only needed four params, but now we need
2686 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2687 * the params opaque. The v1 "get" response will include the algorithm number
2688 * and how many params it requires. That way we can change the EC code without
2689 * needing to update this file. We can also use a different algorithm on each
2693 /* This is the same struct for both v0 and v1. */
2694 struct __ec_align1 ec_params_tmp006_get_calibration {
2699 struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
2706 struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
2708 uint8_t reserved[3];
2716 struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
2719 uint8_t reserved[2];
2723 struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
2732 /* Read raw TMP006 data */
2733 #define EC_CMD_TMP006_GET_RAW 0x0055
2735 struct __ec_align1 ec_params_tmp006_get_raw {
2739 struct __ec_align4 ec_response_tmp006_get_raw {
2740 int32_t t; /* In 1/100 K */
2741 int32_t v; /* In nV */
2744 /*****************************************************************************/
2745 /* MKBP - Matrix KeyBoard Protocol */
2750 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2751 * expected response size.
2753 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2754 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2755 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2757 #define EC_CMD_MKBP_STATE 0x0060
2760 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2762 #define EC_CMD_MKBP_INFO 0x0061
2764 struct __ec_align_size1 ec_response_mkbp_info {
2767 /* Formerly "switches", which was 0. */
2771 struct __ec_align1 ec_params_mkbp_info {
2776 enum ec_mkbp_info_type {
2778 * Info about the keyboard matrix: number of rows and columns.
2780 * Returns struct ec_response_mkbp_info.
2782 EC_MKBP_INFO_KBD = 0,
2785 * For buttons and switches, info about which specifically are
2786 * supported. event_type must be set to one of the values in enum
2789 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2790 * bitmask indicating which buttons or switches are present. See the
2791 * bit inidices below.
2793 EC_MKBP_INFO_SUPPORTED = 1,
2796 * Instantaneous state of buttons and switches.
2798 * event_type must be set to one of the values in enum ec_mkbp_event.
2800 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2801 * indicating the current state of the keyboard matrix.
2803 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2806 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2807 * state of supported buttons.
2809 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2810 * state of supported switches.
2812 EC_MKBP_INFO_CURRENT = 2,
2815 /* Simulate key press */
2816 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2818 struct __ec_align1 ec_params_mkbp_simulate_key {
2824 /* Configure keyboard scanning */
2825 #define EC_CMD_MKBP_SET_CONFIG 0x0064
2826 #define EC_CMD_MKBP_GET_CONFIG 0x0065
2829 enum mkbp_config_flags {
2830 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2833 enum mkbp_config_valid {
2834 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2835 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2836 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2837 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2838 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2839 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2840 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2844 * Configuration for our key scanning algorithm.
2846 * Note that this is used as a sub-structure of
2847 * ec_{params/response}_mkbp_get_config.
2849 struct __ec_align_size1 ec_mkbp_config {
2850 uint32_t valid_mask; /* valid fields */
2851 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2852 uint8_t valid_flags; /* which flags are valid */
2853 uint16_t scan_period_us; /* period between start of scans */
2854 /* revert to interrupt mode after no activity for this long */
2855 uint32_t poll_timeout_us;
2857 * minimum post-scan relax time. Once we finish a scan we check
2858 * the time until we are due to start the next one. If this time is
2859 * shorter this field, we use this instead.
2861 uint16_t min_post_scan_delay_us;
2862 /* delay between setting up output and waiting for it to settle */
2863 uint16_t output_settle_us;
2864 uint16_t debounce_down_us; /* time for debounce on key down */
2865 uint16_t debounce_up_us; /* time for debounce on key up */
2866 /* maximum depth to allow for fifo (0 = no keyscan output) */
2867 uint8_t fifo_max_depth;
2870 struct __ec_align_size1 ec_params_mkbp_set_config {
2871 struct ec_mkbp_config config;
2874 struct __ec_align_size1 ec_response_mkbp_get_config {
2875 struct ec_mkbp_config config;
2878 /* Run the key scan emulation */
2879 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2881 enum ec_keyscan_seq_cmd {
2882 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2883 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2884 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2885 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2886 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2889 enum ec_collect_flags {
2891 * Indicates this scan was processed by the EC. Due to timing, some
2892 * scans may be skipped.
2894 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2897 struct __ec_align1 ec_collect_item {
2898 uint8_t flags; /* some flags (enum ec_collect_flags) */
2901 struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
2902 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2904 struct __ec_align1 {
2905 uint8_t active; /* still active */
2906 uint8_t num_items; /* number of items */
2907 /* Current item being presented */
2910 struct __ec_todo_unpacked {
2912 * Absolute time for this scan, measured from the
2913 * start of the sequence.
2916 uint8_t scan[0]; /* keyscan data */
2918 struct __ec_align1 {
2919 uint8_t start_item; /* First item to return */
2920 uint8_t num_items; /* Number of items to return */
2925 struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
2927 struct __ec_todo_unpacked {
2928 uint8_t num_items; /* Number of items */
2929 /* Data for each item */
2930 struct ec_collect_item item[0];
2936 * Get the next pending MKBP event.
2938 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2940 #define EC_CMD_GET_NEXT_EVENT 0x0067
2942 enum ec_mkbp_event {
2943 /* Keyboard matrix changed. The event data is the new matrix state. */
2944 EC_MKBP_EVENT_KEY_MATRIX = 0,
2946 /* New host event. The event data is 4 bytes of host event flags. */
2947 EC_MKBP_EVENT_HOST_EVENT = 1,
2949 /* New Sensor FIFO data. The event data is fifo_info structure. */
2950 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2952 /* The state of the non-matrixed buttons have changed. */
2953 EC_MKBP_EVENT_BUTTON = 3,
2955 /* The state of the switches have changed. */
2956 EC_MKBP_EVENT_SWITCH = 4,
2958 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2959 EC_MKBP_EVENT_FINGERPRINT = 5,
2962 * Sysrq event: send emulated sysrq. The event data is sysrq,
2963 * corresponding to the key to be pressed.
2965 EC_MKBP_EVENT_SYSRQ = 6,
2967 /* Number of MKBP events */
2968 EC_MKBP_EVENT_COUNT,
2971 union __ec_align_offset1 ec_response_get_next_data {
2972 uint8_t key_matrix[13];
2975 uint32_t host_event;
2977 struct __ec_todo_unpacked {
2978 /* For aligning the fifo_info */
2979 uint8_t reserved[3];
2980 struct ec_response_motion_sense_fifo_info info;
2992 struct __ec_align1 ec_response_get_next_event {
2994 /* Followed by event data if any */
2995 union ec_response_get_next_data data;
2998 /* Bit indices for buttons and switches.*/
3000 #define EC_MKBP_POWER_BUTTON 0
3001 #define EC_MKBP_VOL_UP 1
3002 #define EC_MKBP_VOL_DOWN 2
3003 #define EC_MKBP_RECOVERY 3
3006 #define EC_MKBP_LID_OPEN 0
3007 #define EC_MKBP_TABLET_MODE 1
3009 /* Run keyboard factory test scanning */
3010 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3012 struct __ec_align2 ec_response_keyboard_factory_test {
3013 uint16_t shorted; /* Keyboard pins are shorted */
3016 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3017 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3018 #define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3019 #define EC_MKBP_FP_FINGER_UP (1 << 30)
3020 #define EC_MKBP_FP_IMAGE_READY (1 << 31)
3022 /*****************************************************************************/
3023 /* Temperature sensor commands */
3025 /* Read temperature sensor info */
3026 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
3028 struct __ec_align1 ec_params_temp_sensor_get_info {
3032 struct __ec_align1 ec_response_temp_sensor_get_info {
3033 char sensor_name[32];
3034 uint8_t sensor_type;
3037 /*****************************************************************************/
3040 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3041 * commands accidentally sent to the wrong interface. See the ACPI section
3045 /*****************************************************************************/
3046 /* Host event commands */
3049 /* Obsolete. New implementation should use EC_CMD_PROGRAM_HOST_EVENT instead */
3051 * Host event mask params and response structures, shared by all of the host
3052 * event commands below.
3054 struct __ec_align4 ec_params_host_event_mask {
3058 struct __ec_align4 ec_response_host_event_mask {
3062 /* These all use ec_response_host_event_mask */
3063 #define EC_CMD_HOST_EVENT_GET_B 0x0087
3064 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3065 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3066 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
3068 /* These all use ec_params_host_event_mask */
3069 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3070 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3071 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
3072 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3073 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3076 * Unified host event programming interface - Should be used by newer versions
3077 * of BIOS/OS to program host events and masks
3080 struct __ec_align4 ec_params_host_event {
3082 /* Action requested by host - one of enum ec_host_event_action. */
3086 * Mask type that the host requested the action on - one of
3087 * enum ec_host_event_mask_type.
3091 /* Set to 0, ignore on read */
3094 /* Value to be used in case of set operations. */
3099 * Response structure returned by EC_CMD_HOST_EVENT.
3100 * Update the value on a GET request. Set to 0 on GET/CLEAR
3103 struct __ec_align4 ec_response_host_event {
3105 /* Mask value in case of get operation */
3109 enum ec_host_event_action {
3111 * params.value is ignored. Value of mask_type populated
3116 /* Bits in params.value are set */
3119 /* Bits in params.value are cleared */
3120 EC_HOST_EVENT_CLEAR,
3123 enum ec_host_event_mask_type {
3125 /* Main host event copy */
3128 /* Copy B of host events */
3132 EC_HOST_EVENT_SCI_MASK,
3135 EC_HOST_EVENT_SMI_MASK,
3137 /* Mask of events that should be always reported in hostevents */
3138 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3140 /* Active wake mask */
3141 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3143 /* Lazy wake mask for S0ix */
3144 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3146 /* Lazy wake mask for S3 */
3147 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3149 /* Lazy wake mask for S5 */
3150 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3153 #define EC_CMD_HOST_EVENT 0x00A4
3155 /*****************************************************************************/
3156 /* Switch commands */
3158 /* Enable/disable LCD backlight */
3159 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
3161 struct __ec_align1 ec_params_switch_enable_backlight {
3165 /* Enable/disable WLAN/Bluetooth */
3166 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
3167 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
3169 /* Version 0 params; no response */
3170 struct __ec_align1 ec_params_switch_enable_wireless_v0 {
3174 /* Version 1 params */
3175 struct __ec_align1 ec_params_switch_enable_wireless_v1 {
3176 /* Flags to enable now */
3179 /* Which flags to copy from now_flags */
3183 * Flags to leave enabled in S3, if they're on at the S0->S3
3184 * transition. (Other flags will be disabled by the S0->S3
3187 uint8_t suspend_flags;
3189 /* Which flags to copy from suspend_flags */
3190 uint8_t suspend_mask;
3193 /* Version 1 response */
3194 struct __ec_align1 ec_response_switch_enable_wireless_v1 {
3195 /* Flags to enable now */
3198 /* Flags to leave enabled in S3 */
3199 uint8_t suspend_flags;
3202 /*****************************************************************************/
3203 /* GPIO commands. Only available on EC if write protect has been disabled. */
3205 /* Set GPIO output value */
3206 #define EC_CMD_GPIO_SET 0x0092
3208 struct __ec_align1 ec_params_gpio_set {
3213 /* Get GPIO value */
3214 #define EC_CMD_GPIO_GET 0x0093
3216 /* Version 0 of input params and response */
3217 struct __ec_align1 ec_params_gpio_get {
3221 struct __ec_align1 ec_response_gpio_get {
3225 /* Version 1 of input params and response */
3226 struct __ec_align1 ec_params_gpio_get_v1 {
3229 struct __ec_align1 {
3231 } get_value_by_name;
3232 struct __ec_align1 {
3238 struct __ec_todo_packed ec_response_gpio_get_v1 {
3240 struct __ec_align1 {
3242 } get_value_by_name, get_count;
3243 struct __ec_todo_unpacked {
3251 enum gpio_get_subcmd {
3252 EC_GPIO_GET_BY_NAME = 0,
3253 EC_GPIO_GET_COUNT = 1,
3254 EC_GPIO_GET_INFO = 2,
3257 /*****************************************************************************/
3258 /* I2C commands. Only available when flash write protect is unlocked. */
3261 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3262 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3264 * Use EC_CMD_I2C_PASSTHRU instead.
3268 #define EC_CMD_I2C_READ 0x0094
3270 struct __ec_align_size1 ec_params_i2c_read {
3271 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3272 uint8_t read_size; /* Either 8 or 16. */
3277 struct __ec_align2 ec_response_i2c_read {
3282 #define EC_CMD_I2C_WRITE 0x0095
3284 struct __ec_align_size1 ec_params_i2c_write {
3286 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3287 uint8_t write_size; /* Either 8 or 16. */
3292 /*****************************************************************************/
3293 /* Charge state commands. Only available when flash write protect unlocked. */
3295 /* Force charge state machine to stop charging the battery or force it to
3296 * discharge the battery.
3298 #define EC_CMD_CHARGE_CONTROL 0x0096
3299 #define EC_VER_CHARGE_CONTROL 1
3301 enum ec_charge_control_mode {
3302 CHARGE_CONTROL_NORMAL = 0,
3303 CHARGE_CONTROL_IDLE,
3304 CHARGE_CONTROL_DISCHARGE,
3307 struct __ec_align4 ec_params_charge_control {
3308 uint32_t mode; /* enum charge_control_mode */
3311 /*****************************************************************************/
3312 /* Console commands. Only available when flash write protect is unlocked. */
3314 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
3315 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
3318 * Read data from the saved snapshot. If the subcmd parameter is
3319 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3320 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3321 * end of the previous snapshot.
3323 * The params are only looked at in version >= 1 of this command. Prior
3324 * versions will just default to CONSOLE_READ_NEXT behavior.
3326 * Response is null-terminated string. Empty string, if there is no more
3329 #define EC_CMD_CONSOLE_READ 0x0098
3331 enum ec_console_read_subcmd {
3332 CONSOLE_READ_NEXT = 0,
3336 struct __ec_align1 ec_params_console_read_v1 {
3337 uint8_t subcmd; /* enum ec_console_read_subcmd */
3340 /*****************************************************************************/
3343 * Cut off battery power immediately or after the host has shut down.
3345 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3346 * EC_RES_SUCCESS if the command was successful.
3347 * EC_RES_ERROR if the cut off command failed.
3349 #define EC_CMD_BATTERY_CUT_OFF 0x0099
3351 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3353 struct __ec_align1 ec_params_battery_cutoff {
3357 /*****************************************************************************/
3358 /* USB port mux control. */
3361 * Switch USB mux or return to automatic switching.
3363 #define EC_CMD_USB_MUX 0x009A
3365 struct __ec_align1 ec_params_usb_mux {
3369 /*****************************************************************************/
3370 /* LDOs / FETs control. */
3373 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3374 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3378 * Switch on/off a LDO.
3380 #define EC_CMD_LDO_SET 0x009B
3382 struct __ec_align1 ec_params_ldo_set {
3390 #define EC_CMD_LDO_GET 0x009C
3392 struct __ec_align1 ec_params_ldo_get {
3396 struct __ec_align1 ec_response_ldo_get {
3400 /*****************************************************************************/
3406 #define EC_CMD_POWER_INFO 0x009D
3408 struct __ec_align4 ec_response_power_info {
3409 uint32_t usb_dev_type;
3410 uint16_t voltage_ac;
3411 uint16_t voltage_system;
3412 uint16_t current_system;
3413 uint16_t usb_current_limit;
3416 /*****************************************************************************/
3417 /* I2C passthru command */
3419 #define EC_CMD_I2C_PASSTHRU 0x009E
3421 /* Read data; if not present, message is a write */
3422 #define EC_I2C_FLAG_READ (1 << 15)
3424 /* Mask for address */
3425 #define EC_I2C_ADDR_MASK 0x3ff
3427 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3428 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3431 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3433 struct __ec_align2 ec_params_i2c_passthru_msg {
3434 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3435 uint16_t len; /* Number of bytes to read or write */
3438 struct __ec_align2 ec_params_i2c_passthru {
3439 uint8_t port; /* I2C port number */
3440 uint8_t num_msgs; /* Number of messages */
3441 struct ec_params_i2c_passthru_msg msg[];
3442 /* Data to write for all messages is concatenated here */
3445 struct __ec_align1 ec_response_i2c_passthru {
3446 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3447 uint8_t num_msgs; /* Number of messages processed */
3448 uint8_t data[]; /* Data read by messages concatenated here */
3451 /*****************************************************************************/
3452 /* Power button hang detect */
3454 #define EC_CMD_HANG_DETECT 0x009F
3456 /* Reasons to start hang detection timer */
3457 /* Power button pressed */
3458 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3461 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3464 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
3466 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
3467 #define EC_HANG_START_ON_RESUME (1 << 3)
3469 /* Reasons to cancel hang detection */
3471 /* Power button released */
3472 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3474 /* Any host command from AP received */
3475 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3477 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3478 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3481 * If this flag is set, all the other fields are ignored, and the hang detect
3482 * timer is started. This provides the AP a way to start the hang timer
3483 * without reconfiguring any of the other hang detect settings. Note that
3484 * you must previously have configured the timeouts.
3486 #define EC_HANG_START_NOW (1 << 30)
3489 * If this flag is set, all the other fields are ignored (including
3490 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3491 * without reconfiguring any of the other hang detect settings.
3493 #define EC_HANG_STOP_NOW (1 << 31)
3495 struct __ec_align4 ec_params_hang_detect {
3496 /* Flags; see EC_HANG_* */
3499 /* Timeout in msec before generating host event, if enabled */
3500 uint16_t host_event_timeout_msec;
3502 /* Timeout in msec before generating warm reboot, if enabled */
3503 uint16_t warm_reboot_timeout_msec;
3506 /*****************************************************************************/
3507 /* Commands for battery charging */
3510 * This is the single catch-all host command to exchange data regarding the
3511 * charge state machine (v2 and up).
3513 #define EC_CMD_CHARGE_STATE 0x00A0
3515 /* Subcommands for this host command */
3516 enum charge_state_command {
3517 CHARGE_STATE_CMD_GET_STATE,
3518 CHARGE_STATE_CMD_GET_PARAM,
3519 CHARGE_STATE_CMD_SET_PARAM,
3520 CHARGE_STATE_NUM_CMDS
3524 * Known param numbers are defined here. Ranges are reserved for board-specific
3525 * params, which are handled by the particular implementations.
3527 enum charge_state_params {
3528 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3529 CS_PARAM_CHG_CURRENT, /* charger current limit */
3530 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3531 CS_PARAM_CHG_STATUS, /* charger-specific status */
3532 CS_PARAM_CHG_OPTION, /* charger-specific options */
3533 CS_PARAM_LIMIT_POWER, /*
3534 * Check if power is limited due to
3535 * low battery and / or a weak external
3536 * charger. READ ONLY.
3538 /* How many so far? */
3541 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3542 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3543 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3545 /* Other custom param ranges go here... */
3548 struct __ec_todo_packed ec_params_charge_state {
3549 uint8_t cmd; /* enum charge_state_command */
3551 struct __ec_align1 {
3555 struct __ec_todo_unpacked {
3556 uint32_t param; /* enum charge_state_param */
3559 struct __ec_todo_unpacked {
3560 uint32_t param; /* param to set */
3561 uint32_t value; /* value to set */
3566 struct __ec_align4 ec_response_charge_state {
3568 struct __ec_align4 {
3572 int chg_input_current;
3573 int batt_state_of_charge;
3576 struct __ec_align4 {
3579 struct __ec_align4 {
3580 /* no return values */
3587 * Set maximum battery charging current.
3589 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
3591 struct __ec_align4 ec_params_current_limit {
3592 uint32_t limit; /* in mA */
3596 * Set maximum external voltage / current.
3598 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
3600 /* Command v0 is used only on Spring and is obsolete + unsupported */
3601 struct __ec_align2 ec_params_external_power_limit_v1 {
3602 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3603 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
3606 #define EC_POWER_LIMIT_NONE 0xffff
3609 * Set maximum voltage & current of a dedicated charge port
3611 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3613 struct __ec_align2 ec_params_dedicated_charger_limit {
3614 uint16_t current_lim; /* in mA */
3615 uint16_t voltage_lim; /* in mV */
3618 /*****************************************************************************/
3619 /* Hibernate/Deep Sleep Commands */
3621 /* Set the delay before going into hibernation. */
3622 #define EC_CMD_HIBERNATION_DELAY 0x00A8
3624 struct __ec_align4 ec_params_hibernation_delay {
3626 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3627 * current settings without changing them.
3632 struct __ec_align4 ec_response_hibernation_delay {
3634 * The current time in seconds in which the system has been in the G3
3635 * state. This value is reset if the EC transitions out of G3.
3640 * The current time remaining in seconds until the EC should hibernate.
3641 * This value is also reset if the EC transitions out of G3.
3643 uint32_t time_remaining;
3646 * The current time in seconds that the EC should wait in G3 before
3649 uint32_t hibernate_delay;
3652 /* Inform the EC when entering a sleep state */
3653 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3655 enum host_sleep_event {
3656 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3657 HOST_SLEEP_EVENT_S3_RESUME = 2,
3658 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3659 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3662 struct __ec_align1 ec_params_host_sleep_event {
3663 uint8_t sleep_event;
3666 /*****************************************************************************/
3668 #define EC_CMD_DEVICE_EVENT 0x00AA
3670 enum ec_device_event {
3671 EC_DEVICE_EVENT_TRACKPAD,
3672 EC_DEVICE_EVENT_DSP,
3673 EC_DEVICE_EVENT_WIFI,
3676 enum ec_device_event_param {
3677 /* Get and clear pending device events */
3678 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3679 /* Get device event mask */
3680 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3681 /* Set device event mask */
3682 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3685 #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3687 struct __ec_align_size1 ec_params_device_event {
3688 uint32_t event_mask;
3692 struct __ec_align4 ec_response_device_event {
3693 uint32_t event_mask;
3696 /*****************************************************************************/
3697 /* Smart battery pass-through */
3699 /* Get / Set 16-bit smart battery registers */
3700 #define EC_CMD_SB_READ_WORD 0x00B0
3701 #define EC_CMD_SB_WRITE_WORD 0x00B1
3703 /* Get / Set string smart battery parameters
3704 * formatted as SMBUS "block".
3706 #define EC_CMD_SB_READ_BLOCK 0x00B2
3707 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
3709 struct __ec_align1 ec_params_sb_rd {
3713 struct __ec_align2 ec_response_sb_rd_word {
3717 struct __ec_align1 ec_params_sb_wr_word {
3722 struct __ec_align1 ec_response_sb_rd_block {
3726 struct __ec_align1 ec_params_sb_wr_block {
3731 /*****************************************************************************/
3732 /* Battery vendor parameters
3734 * Get or set vendor-specific parameters in the battery. Implementations may
3735 * differ between boards or batteries. On a set operation, the response
3736 * contains the actual value set, which may be rounded or clipped from the
3740 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
3742 enum ec_battery_vendor_param_mode {
3743 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3744 BATTERY_VENDOR_PARAM_MODE_SET,
3747 struct __ec_align_size1 ec_params_battery_vendor_param {
3753 struct __ec_align4 ec_response_battery_vendor_param {
3757 /*****************************************************************************/
3759 * Smart Battery Firmware Update Commands
3761 #define EC_CMD_SB_FW_UPDATE 0x00B5
3763 enum ec_sb_fw_update_subcmd {
3764 EC_SB_FW_UPDATE_PREPARE = 0x0,
3765 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3766 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3767 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3768 EC_SB_FW_UPDATE_END = 0x4,
3769 EC_SB_FW_UPDATE_STATUS = 0x5,
3770 EC_SB_FW_UPDATE_PROTECT = 0x6,
3771 EC_SB_FW_UPDATE_MAX = 0x7,
3774 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3775 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3776 #define SB_FW_UPDATE_CMD_INFO_SIZE 8
3778 struct __ec_align4 ec_sb_fw_update_header {
3779 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3780 uint16_t fw_id; /* firmware id */
3783 struct __ec_align4 ec_params_sb_fw_update {
3784 struct ec_sb_fw_update_header hdr;
3786 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3787 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3788 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3789 /* EC_SB_FW_UPDATE_END = 0x4 */
3790 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3791 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
3792 struct __ec_align4 {
3796 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
3797 struct __ec_align4 {
3798 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3803 struct __ec_align1 ec_response_sb_fw_update {
3805 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3806 struct __ec_align1 {
3807 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3810 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3811 struct __ec_align1 {
3812 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3818 * Entering Verified Boot Mode Command
3819 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3820 * Valid Modes are: normal, developer, and recovery.
3822 #define EC_CMD_ENTERING_MODE 0x00B6
3824 struct __ec_align4 ec_params_entering_mode {
3828 #define VBOOT_MODE_NORMAL 0
3829 #define VBOOT_MODE_DEVELOPER 1
3830 #define VBOOT_MODE_RECOVERY 2
3832 /*****************************************************************************/
3834 * I2C passthru protection command: Protects I2C tunnels against access on
3835 * certain addresses (board-specific).
3837 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
3839 enum ec_i2c_passthru_protect_subcmd {
3840 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3841 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3844 struct __ec_align1 ec_params_i2c_passthru_protect {
3846 uint8_t port; /* I2C port number */
3849 struct __ec_align1 ec_response_i2c_passthru_protect {
3850 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
3853 /*****************************************************************************/
3854 /* System commands */
3857 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3858 * necessarily reboot the EC. Rename to "image" or something similar?
3860 #define EC_CMD_REBOOT_EC 0x00D2
3863 enum ec_reboot_cmd {
3864 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
3865 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3866 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
3867 /* (command 3 was jump to RW-B) */
3868 EC_REBOOT_COLD = 4, /* Cold-reboot */
3869 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3870 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
3871 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
3874 /* Flags for ec_params_reboot_ec.reboot_flags */
3875 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
3876 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
3877 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2) /* Switch RW slot */
3879 struct __ec_align1 ec_params_reboot_ec {
3880 uint8_t cmd; /* enum ec_reboot_cmd */
3881 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3885 * Get information on last EC panic.
3887 * Returns variable-length platform-dependent panic information. See panic.h
3890 #define EC_CMD_GET_PANIC_INFO 0x00D3
3892 /*****************************************************************************/
3896 * These do not follow the normal rules for commands. See each command for
3903 * This command will work even when the EC LPC interface is busy, because the
3904 * reboot command is processed at interrupt level. Note that when the EC
3905 * reboots, the host will reboot too, so there is no response to this command.
3907 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3909 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3912 * Resend last response (not supported on LPC).
3914 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3915 * there was no previous command, or the previous command's response was too
3918 #define EC_CMD_RESEND_RESPONSE 0x00DB
3921 * This header byte on a command indicate version 0. Any header byte less
3922 * than this means that we are talking to an old EC which doesn't support
3923 * versioning. In that case, we assume version 0.
3925 * Header bytes greater than this indicate a later version. For example,
3926 * EC_CMD_VERSION0 + 1 means we are using version 1.
3928 * The old EC interface must not use commands 0xdc or higher.
3930 #define EC_CMD_VERSION0 0x00DC
3932 /*****************************************************************************/
3936 * These commands are for PD MCU communication.
3939 /* EC to PD MCU exchange status command */
3940 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
3941 #define EC_VER_PD_EXCHANGE_STATUS 2
3943 enum pd_charge_state {
3944 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3945 PD_CHARGE_NONE, /* No charging allowed */
3946 PD_CHARGE_5V, /* 5V charging only */
3947 PD_CHARGE_MAX /* Charge at max voltage */
3950 /* Status of EC being sent to PD */
3951 #define EC_STATUS_HIBERNATING (1 << 0)
3953 struct __ec_align1 ec_params_pd_status {
3954 uint8_t status; /* EC status */
3955 int8_t batt_soc; /* battery state of charge */
3956 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
3959 /* Status of PD being sent back to EC */
3960 #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3961 #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3962 #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
3963 #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3964 #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3965 #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3966 #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3967 #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3968 PD_STATUS_TCPC_ALERT_1 | \
3969 PD_STATUS_HOST_EVENT)
3970 struct __ec_align_size1 ec_response_pd_status {
3971 uint32_t curr_lim_ma; /* input current limit */
3972 uint16_t status; /* PD MCU status */
3973 int8_t active_charge_port; /* active charging port */
3976 /* AP to PD MCU host event status command, cleared on read */
3977 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
3979 /* PD MCU host event status bits */
3980 #define PD_EVENT_UPDATE_DEVICE (1 << 0)
3981 #define PD_EVENT_POWER_CHANGE (1 << 1)
3982 #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
3983 #define PD_EVENT_DATA_SWAP (1 << 3)
3984 struct __ec_align4 ec_response_host_event_status {
3985 uint32_t status; /* PD MCU host event status */
3988 /* Set USB type-C port role and muxes */
3989 #define EC_CMD_USB_PD_CONTROL 0x0101
3991 enum usb_pd_control_role {
3992 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3993 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3994 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3995 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3996 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3997 USB_PD_CTRL_ROLE_COUNT
4000 enum usb_pd_control_mux {
4001 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4002 USB_PD_CTRL_MUX_NONE = 1,
4003 USB_PD_CTRL_MUX_USB = 2,
4004 USB_PD_CTRL_MUX_DP = 3,
4005 USB_PD_CTRL_MUX_DOCK = 4,
4006 USB_PD_CTRL_MUX_AUTO = 5,
4007 USB_PD_CTRL_MUX_COUNT
4010 enum usb_pd_control_swap {
4011 USB_PD_CTRL_SWAP_NONE = 0,
4012 USB_PD_CTRL_SWAP_DATA = 1,
4013 USB_PD_CTRL_SWAP_POWER = 2,
4014 USB_PD_CTRL_SWAP_VCONN = 3,
4015 USB_PD_CTRL_SWAP_COUNT
4018 struct __ec_align1 ec_params_usb_pd_control {
4025 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
4026 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
4027 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4029 #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
4030 #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
4031 #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
4032 #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
4033 #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
4034 #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
4035 #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
4037 struct __ec_align1 ec_response_usb_pd_control {
4044 struct __ec_align1 ec_response_usb_pd_control_v1 {
4051 #define EC_CMD_USB_PD_PORTS 0x0102
4053 /* Maximum number of PD ports on a device, num_ports will be <= this */
4054 #define EC_USB_PD_MAX_PORTS 8
4056 struct __ec_align1 ec_response_usb_pd_ports {
4060 #define EC_CMD_USB_PD_POWER_INFO 0x0103
4062 #define PD_POWER_CHARGING_PORT 0xff
4063 struct __ec_align1 ec_params_usb_pd_power_info {
4071 USB_CHG_TYPE_PROPRIETARY,
4072 USB_CHG_TYPE_BC12_DCP,
4073 USB_CHG_TYPE_BC12_CDP,
4074 USB_CHG_TYPE_BC12_SDP,
4077 USB_CHG_TYPE_UNKNOWN,
4079 enum usb_power_roles {
4080 USB_PD_PORT_POWER_DISCONNECTED,
4081 USB_PD_PORT_POWER_SOURCE,
4082 USB_PD_PORT_POWER_SINK,
4083 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4086 struct __ec_align2 usb_chg_measures {
4087 uint16_t voltage_max;
4088 uint16_t voltage_now;
4089 uint16_t current_max;
4090 uint16_t current_lim;
4093 struct __ec_align4 ec_response_usb_pd_power_info {
4098 struct usb_chg_measures meas;
4102 /* Write USB-PD device FW */
4103 #define EC_CMD_USB_PD_FW_UPDATE 0x0110
4105 enum usb_pd_fw_update_cmds {
4107 USB_PD_FW_FLASH_ERASE,
4108 USB_PD_FW_FLASH_WRITE,
4109 USB_PD_FW_ERASE_SIG,
4112 struct __ec_align4 ec_params_usb_pd_fw_update {
4116 uint32_t size; /* Size to write in bytes */
4117 /* Followed by data to write */
4120 /* Write USB-PD Accessory RW_HASH table entry */
4121 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4122 /* RW hash is first 20 bytes of SHA-256 of RW section */
4123 #define PD_RW_HASH_SIZE 20
4124 struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
4126 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4127 uint8_t reserved; /* For alignment of current_image
4128 * TODO(rspangler) but it's not aligned!
4129 * Should have been reserved[2]. */
4130 uint32_t current_image; /* One of ec_current_image */
4133 /* Read USB-PD Accessory info */
4134 #define EC_CMD_USB_PD_DEV_INFO 0x0112
4136 struct __ec_align1 ec_params_usb_pd_info_request {
4140 /* Read USB-PD Device discovery info */
4141 #define EC_CMD_USB_PD_DISCOVERY 0x0113
4142 struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
4143 uint16_t vid; /* USB-IF VID */
4144 uint16_t pid; /* USB-IF PID */
4145 uint8_t ptype; /* product type (hub,periph,cable,ama) */
4148 /* Override default charge behavior */
4149 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
4151 /* Negative port parameters have special meaning */
4152 enum usb_pd_override_ports {
4153 OVERRIDE_DONT_CHARGE = -2,
4155 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4158 struct __ec_align2 ec_params_charge_port_override {
4159 int16_t override_port; /* Override port# */
4162 /* Read (and delete) one entry of PD event log */
4163 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4165 struct __ec_align4 ec_response_pd_log {
4166 uint32_t timestamp; /* relative timestamp in milliseconds */
4167 uint8_t type; /* event type : see PD_EVENT_xx below */
4168 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4169 uint16_t data; /* type-defined data payload */
4170 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
4174 /* The timestamp is the microsecond counter shifted to get about a ms. */
4175 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4177 #define PD_LOG_SIZE_MASK 0x1f
4178 #define PD_LOG_PORT_MASK 0xe0
4179 #define PD_LOG_PORT_SHIFT 5
4180 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4181 ((size) & PD_LOG_SIZE_MASK))
4182 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4183 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4185 /* PD event log : entry types */
4187 #define PD_EVENT_MCU_BASE 0x00
4188 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4189 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4190 /* Reserved for custom board event */
4191 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4192 /* PD generic accessory events */
4193 #define PD_EVENT_ACC_BASE 0x20
4194 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4195 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4196 /* PD power supply events */
4197 #define PD_EVENT_PS_BASE 0x40
4198 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4199 /* PD video dongles events */
4200 #define PD_EVENT_VIDEO_BASE 0x60
4201 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4202 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4203 /* Returned in the "type" field, when there is no entry available */
4204 #define PD_EVENT_NO_ENTRY 0xff
4207 * PD_EVENT_MCU_CHARGE event definition :
4208 * the payload is "struct usb_chg_measures"
4209 * the data field contains the port state flags as defined below :
4211 /* Port partner is a dual role device */
4212 #define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4213 /* Port is the pending override port */
4214 #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4215 /* Port is the override port */
4216 #define CHARGE_FLAGS_OVERRIDE (1 << 13)
4218 #define CHARGE_FLAGS_TYPE_SHIFT 3
4219 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4220 /* Power delivery role */
4221 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4224 * PD_EVENT_PS_FAULT data field flags definition :
4226 #define PS_FAULT_OCP 1
4227 #define PS_FAULT_FAST_OCP 2
4228 #define PS_FAULT_OVP 3
4229 #define PS_FAULT_DISCH 4
4232 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4234 struct __ec_align4 mcdp_version {
4240 struct __ec_align4 mcdp_info {
4243 struct mcdp_version irom;
4244 struct mcdp_version fw;
4247 /* struct mcdp_info field decoding */
4248 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4249 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4251 /* Get/Set USB-PD Alternate mode info */
4252 #define EC_CMD_USB_PD_GET_AMODE 0x0116
4253 struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
4254 uint16_t svid_idx; /* SVID index to get */
4255 uint8_t port; /* port */
4258 struct __ec_align4 ec_params_usb_pd_get_mode_response {
4259 uint16_t svid; /* SVID */
4260 uint16_t opos; /* Object Position */
4261 uint32_t vdo[6]; /* Mode VDOs */
4264 #define EC_CMD_USB_PD_SET_AMODE 0x0117
4269 /* Not a command. Do NOT remove. */
4273 struct __ec_align4 ec_params_usb_pd_set_mode_request {
4274 uint32_t cmd; /* enum pd_mode_cmd */
4275 uint16_t svid; /* SVID to set */
4276 uint8_t opos; /* Object Position */
4277 uint8_t port; /* port */
4280 /* Ask the PD MCU to record a log of a requested type */
4281 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
4283 struct __ec_align1 ec_params_pd_write_log_entry {
4284 uint8_t type; /* event type : see PD_EVENT_xx above */
4285 uint8_t port; /* port#, or 0 for events unrelated to a given port */
4289 /* Control USB-PD chip */
4290 #define EC_CMD_PD_CONTROL 0x0119
4292 enum ec_pd_control_cmd {
4293 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4294 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4295 PD_RESET, /* Force reset the PD chip */
4296 PD_CONTROL_DISABLE /* Disable further calls to this command */
4299 struct __ec_align1 ec_params_pd_control {
4300 uint8_t chip; /* chip id (should be 0) */
4304 /* Get info about USB-C SS muxes */
4305 #define EC_CMD_USB_PD_MUX_INFO 0x011A
4307 struct __ec_align1 ec_params_usb_pd_mux_info {
4308 uint8_t port; /* USB-C port number */
4311 /* Flags representing mux state */
4312 #define USB_PD_MUX_USB_ENABLED (1 << 0)
4313 #define USB_PD_MUX_DP_ENABLED (1 << 1)
4314 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4315 #define USB_PD_MUX_HPD_IRQ (1 << 3)
4317 struct __ec_align1 ec_response_usb_pd_mux_info {
4318 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4321 #define EC_CMD_PD_CHIP_INFO 0x011B
4323 struct __ec_align1 ec_params_pd_chip_info {
4324 uint8_t port; /* USB-C port number */
4325 uint8_t renew; /* Force renewal */
4328 struct __ec_align2 ec_response_pd_chip_info {
4330 uint16_t product_id;
4333 uint8_t fw_version_string[8];
4334 uint64_t fw_version_number;
4338 /* Run RW signature verification and get status */
4339 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4341 struct __ec_align4 ec_response_rwsig_check_status {
4345 /* For controlling RWSIG task */
4346 #define EC_CMD_RWSIG_ACTION 0x011D
4349 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4350 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4353 struct __ec_align4 ec_params_rwsig_action {
4357 /* Run verification on a slot */
4358 #define EC_CMD_EFS_VERIFY 0x011E
4360 struct __ec_align1 ec_params_efs_verify {
4361 uint8_t region; /* enum ec_flash_region */
4365 * Retrieve info from Cros Board Info store. Response is based on the data
4366 * type. Integers return a uint32. Strings return a string, using the response
4367 * size to determine how big it is.
4369 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
4371 * Write info into Cros Board Info on EEPROM. Write fails if the board has
4372 * hardware write-protect enabled.
4374 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
4377 CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
4378 CBI_TAG_OEM_ID = 1, /* uint8_t */
4379 CBI_TAG_SKU_ID = 2, /* uint8_t */
4384 * Flags to control read operation
4386 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
4387 * write was successful without reboot.
4389 #define CBI_GET_RELOAD (1 << 0)
4391 struct __ec_align4 ec_params_get_cbi {
4392 uint32_t type; /* enum cbi_data_tag */
4393 uint32_t flag; /* CBI_GET_* */
4397 * Flags to control write behavior.
4399 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
4400 * useful when writing multiple fields in a row.
4401 * INIT: Needs to be set when creating a new CBI from scratch. All fields
4402 * will be initialized to zero first.
4404 #define CBI_SET_NO_SYNC (1 << 0)
4405 #define CBI_SET_INIT (1 << 1)
4407 struct __ec_align1 ec_params_set_cbi {
4408 uint32_t tag; /* enum cbi_data_tag */
4409 uint32_t flag; /* CBI_SET_* */
4410 uint32_t size; /* Data size */
4411 uint8_t data[]; /* For string and raw data */
4414 /*****************************************************************************/
4415 /* The command range 0x200-0x2FF is reserved for Rotor. */
4417 /*****************************************************************************/
4419 * Reserve a range of host commands for the CR51 firmware.
4421 #define EC_CMD_CR51_BASE 0x0300
4422 #define EC_CMD_CR51_LAST 0x03FF
4424 /*****************************************************************************/
4425 /* Fingerprint MCU commands: range 0x0400-0x040x */
4427 /* Fingerprint SPI sensor passthru command: prototyping ONLY */
4428 #define EC_CMD_FP_PASSTHRU 0x0400
4430 #define EC_FP_FLAG_NOT_COMPLETE 0x1
4432 struct __ec_align2 ec_params_fp_passthru {
4433 uint16_t len; /* Number of bytes to write then read */
4434 uint16_t flags; /* EC_FP_FLAG_xxx */
4435 uint8_t data[]; /* Data to send */
4438 /* Fingerprint sensor configuration command: prototyping ONLY */
4439 #define EC_CMD_FP_SENSOR_CONFIG 0x0401
4441 #define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4443 struct __ec_align2 ec_params_fp_sensor_config {
4444 uint8_t count; /* Number of setup registers */
4446 * the value to send to each of the 'count' setup registers
4447 * is stored in the 'data' array for 'len' bytes just after
4450 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4454 /* Configure the Fingerprint MCU behavior */
4455 #define EC_CMD_FP_MODE 0x0402
4457 /* Put the sensor in its lowest power mode */
4458 #define FP_MODE_DEEPSLEEP (1<<0)
4459 /* Wait to see a finger on the sensor */
4460 #define FP_MODE_FINGER_DOWN (1<<1)
4461 /* Poll until the finger has left the sensor */
4462 #define FP_MODE_FINGER_UP (1<<2)
4463 /* Capture the current finger image */
4464 #define FP_MODE_CAPTURE (1<<3)
4465 /* special value: don't change anything just read back current mode */
4466 #define FP_MODE_DONT_CHANGE (1<<31)
4468 struct __ec_align4 ec_params_fp_mode {
4469 uint32_t mode; /* as defined by FP_MODE_ constants */
4473 struct __ec_align4 ec_response_fp_mode {
4474 uint32_t mode; /* as defined by FP_MODE_ constants */
4478 /* Retrieve Fingerprint sensor information */
4479 #define EC_CMD_FP_INFO 0x0403
4481 struct __ec_align2 ec_response_fp_info {
4482 /* Sensor identification */
4484 uint32_t product_id;
4487 /* Image frame characteristics */
4488 uint32_t frame_size;
4489 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4495 /* Get the last captured finger frame: TODO: will be AES-encrypted */
4496 #define EC_CMD_FP_FRAME 0x0404
4498 struct __ec_align4 ec_params_fp_frame {
4503 /*****************************************************************************/
4504 /* Touchpad MCU commands: range 0x0500-0x05FF */
4506 /* Perform touchpad self test */
4507 #define EC_CMD_TP_SELF_TEST 0x0500
4509 /* Get number of frame types, and the size of each type */
4510 #define EC_CMD_TP_FRAME_INFO 0x0501
4512 struct __ec_align4 ec_response_tp_frame_info {
4514 uint32_t frame_sizes[0];
4517 /* Create a snapshot of current frame readings */
4518 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4520 /* Read the frame */
4521 #define EC_CMD_TP_FRAME_GET 0x0503
4523 struct __ec_align4 ec_params_tp_frame_get {
4524 uint32_t frame_index;
4529 /*****************************************************************************/
4531 * Reserve a range of host commands for board-specific, experimental, or
4532 * special purpose features. These can be (re)used without updating this file.
4534 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4535 * their EC commands for easier development, testing, debugging, and support.
4537 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4538 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4540 * In your experimental code, you may want to do something like this:
4542 * #define EC_CMD_MAGIC_FOO 0x0000
4543 * #define EC_CMD_MAGIC_BAR 0x0001
4544 * #define EC_CMD_MAGIC_HEY 0x0002
4546 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4549 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4552 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4555 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4556 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4559 * Given the private host command offset, calculate the true private host
4562 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4563 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4565 /*****************************************************************************/
4569 * Some platforms have sub-processors chained to each other. For example.
4571 * AP <--> EC <--> PD MCU
4573 * The top 2 bits of the command number are used to indicate which device the
4574 * command is intended for. Device 0 is always the device receiving the
4575 * command; other device mapping is board-specific.
4577 * When a device receives a command to be passed to a sub-processor, it passes
4578 * it on with the device number set back to 0. This allows the sub-processor
4579 * to remain blissfully unaware of whether the command originated on the next
4580 * device up the chain, or was passed through from the AP.
4582 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4583 * AP sends command 0x4002 to the EC
4584 * EC sends command 0x0002 to the PD MCU
4585 * EC forwards PD MCU response back to the AP
4588 /* Offset and max command number for sub-device n */
4589 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4590 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4592 /*****************************************************************************/
4594 * Deprecated constants. These constants have been renamed for clarity. The
4595 * meaning and size has not changed. Programs that use the old names should
4596 * switch to the new names soon, as the old names may not be carried forward
4599 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4600 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4601 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4603 #endif /* !__ACPI__ && !__KERNEL__ */
4605 #endif /* __CROS_EC_COMMANDS_H */