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,
1104 /* EC supports 64-bit host events */
1105 EC_FEATURE_HOST_EVENT64 = 33,
1106 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1107 EC_FEATURE_EXEC_IN_RAM = 34,
1108 /* EC supports CEC commands */
1109 EC_FEATURE_CEC = 35,
1110 /* EC supports tight sensor timestamping. */
1111 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
1113 * EC supports tablet mode detection aligned to Chrome and allows
1114 * setting of threshold by host command using
1115 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1117 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
1119 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
1120 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1121 * be sent to RO to be precise.
1123 EC_FEATURE_EFS2 = 38,
1124 /* The MCU is a System Companion Processor (SCP). */
1125 EC_FEATURE_SCP = 39,
1126 /* The MCU is an Integrated Sensor Hub */
1127 EC_FEATURE_ISH = 40,
1128 /* New TCPMv2 TYPEC_ prefaced commands supported */
1129 EC_FEATURE_TYPEC_CMD = 41,
1131 * The EC will wait for direction from the AP to enter Type-C alternate
1134 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1136 * The EC will wait for an acknowledge from the AP after setting the
1139 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
1142 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1143 #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1145 struct ec_response_get_features {
1149 /*****************************************************************************/
1150 /* Get the board's SKU ID from EC */
1151 #define EC_CMD_GET_SKU_ID 0x000E
1153 /* Set SKU ID from AP */
1154 #define EC_CMD_SET_SKU_ID 0x000F
1156 struct __ec_align4 ec_sku_id_info {
1160 /*****************************************************************************/
1161 /* Flash commands */
1163 /* Get flash info */
1164 #define EC_CMD_FLASH_INFO 0x0010
1165 #define EC_VER_FLASH_INFO 2
1167 /* Version 0 returns these fields */
1168 struct __ec_align4 ec_response_flash_info {
1169 /* Usable flash size, in bytes */
1170 uint32_t flash_size;
1172 * Write block size. Write offset and size must be a multiple
1175 uint32_t write_block_size;
1177 * Erase block size. Erase offset and size must be a multiple
1180 uint32_t erase_block_size;
1182 * Protection block size. Protection offset and size must be a
1185 uint32_t protect_block_size;
1188 /* Flags for version 1+ flash info command */
1189 /* EC flash erases bits to 0 instead of 1 */
1190 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1192 /* Flash must be selected for read/write/erase operations to succeed. This may
1193 * be necessary on a chip where write/erase can be corrupted by other board
1194 * activity, or where the chip needs to enable some sort of programming voltage,
1195 * or where the read/write/erase operations require cleanly suspending other
1196 * chip functionality. */
1197 #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1200 * Version 1 returns the same initial fields as version 0, with additional
1203 * gcc anonymous structs don't seem to get along with the __packed directive;
1204 * if they did we'd define the version 0 structure as a sub-structure of this
1207 * Version 2 supports flash banks of different sizes:
1208 * The caller specified the number of banks it has preallocated
1210 * The EC returns the number of banks describing the flash memory.
1211 * It adds banks descriptions up to num_banks_desc.
1213 struct __ec_align4 ec_response_flash_info_1 {
1214 /* Version 0 fields; see above for description */
1215 uint32_t flash_size;
1216 uint32_t write_block_size;
1217 uint32_t erase_block_size;
1218 uint32_t protect_block_size;
1220 /* Version 1 adds these fields: */
1222 * Ideal write size in bytes. Writes will be fastest if size is
1223 * exactly this and offset is a multiple of this. For example, an EC
1224 * may have a write buffer which can do half-page operations if data is
1225 * aligned, and a slower word-at-a-time write mode.
1227 uint32_t write_ideal_size;
1229 /* Flags; see EC_FLASH_INFO_* */
1233 struct __ec_align4 ec_params_flash_info_2 {
1234 /* Number of banks to describe */
1235 uint16_t num_banks_desc;
1236 /* Reserved; set 0; ignore on read */
1237 uint8_t reserved[2];
1240 struct ec_flash_bank {
1241 /* Number of sector is in this bank. */
1243 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1245 /* Minimal write size for the sectors in this bank */
1246 uint8_t write_size_exp;
1247 /* Erase size for the sectors in this bank */
1248 uint8_t erase_size_exp;
1249 /* Size for write protection, usually identical to erase size. */
1250 uint8_t protect_size_exp;
1251 /* Reserved; set 0; ignore on read */
1252 uint8_t reserved[2];
1255 struct __ec_align4 ec_response_flash_info_2 {
1256 /* Total flash in the EC. */
1257 uint32_t flash_size;
1258 /* Flags; see EC_FLASH_INFO_* */
1260 /* Maximum size to use to send data to write to the EC. */
1261 uint32_t write_ideal_size;
1262 /* Number of banks present in the EC. */
1263 uint16_t num_banks_total;
1264 /* Number of banks described in banks array. */
1265 uint16_t num_banks_desc;
1266 struct ec_flash_bank banks[0];
1272 * Response is params.size bytes of data.
1274 #define EC_CMD_FLASH_READ 0x0011
1276 struct __ec_align4 ec_params_flash_read {
1277 uint32_t offset; /* Byte offset to read */
1278 uint32_t size; /* Size to read in bytes */
1282 #define EC_CMD_FLASH_WRITE 0x0012
1283 #define EC_VER_FLASH_WRITE 1
1285 /* Version 0 of the flash command supported only 64 bytes of data */
1286 #define EC_FLASH_WRITE_VER0_SIZE 64
1288 struct __ec_align4 ec_params_flash_write {
1289 uint32_t offset; /* Byte offset to write */
1290 uint32_t size; /* Size to write in bytes */
1291 /* Followed by data to write */
1295 #define EC_CMD_FLASH_ERASE 0x0013
1298 struct __ec_align4 ec_params_flash_erase {
1299 uint32_t offset; /* Byte offset to erase */
1300 uint32_t size; /* Size to erase in bytes */
1304 #define EC_VER_FLASH_WRITE 1
1305 /* v1 add async erase:
1306 * subcommands can returns:
1307 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1308 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1309 * EC_RES_ERROR : other errors.
1310 * EC_RES_BUSY : an existing erase operation is in progress.
1311 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1313 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1314 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1315 * the proper result.
1316 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1317 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1318 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1319 * permitted while erasing. (For instance, STM32F4).
1321 enum ec_flash_erase_cmd {
1322 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1323 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1324 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1327 struct __ec_align4 ec_params_flash_erase_v1 {
1328 /* One of ec_flash_erase_cmd. */
1330 /* Pad byte; currently always contains 0 */
1332 /* No flags defined yet; set to 0 */
1334 /* Same as v0 parameters. */
1335 struct ec_params_flash_erase params;
1339 * Get/set flash protection.
1341 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1342 * firmware write protect GPIO, not all flags will take effect immediately;
1343 * some flags require a subsequent hard reset to take effect. Check the
1344 * returned flags bits to see what actually happened.
1346 * If mask=0, simply returns the current flags state.
1348 #define EC_CMD_FLASH_PROTECT 0x0015
1349 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1351 /* Flags for flash protection */
1352 /* RO flash code protected when the EC boots */
1353 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1355 * RO flash code protected now. If this bit is set, at-boot status cannot
1358 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1359 /* Entire flash code protected now, until reboot. */
1360 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1361 /* Flash write protect GPIO is asserted now */
1362 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1363 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1364 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1366 * Error - flash protection is in inconsistent state. At least one bank of
1367 * flash which should be protected is not protected. Usually fixed by
1368 * re-requesting the desired flags, or by a hard reset if that fails.
1370 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1371 /* Entire flash code protected when the EC boots */
1372 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1373 /* RW flash code protected when the EC boots */
1374 #define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1375 /* RW flash code protected now. */
1376 #define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1377 /* Rollback information flash region protected when the EC boots */
1378 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1379 /* Rollback information flash region protected now */
1380 #define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
1382 struct __ec_align4 ec_params_flash_protect {
1383 uint32_t mask; /* Bits in flags to apply */
1384 uint32_t flags; /* New flags to apply */
1387 struct __ec_align4 ec_response_flash_protect {
1388 /* Current value of flash protect flags */
1391 * Flags which are valid on this platform. This allows the caller
1392 * to distinguish between flags which aren't set vs. flags which can't
1393 * be set on this platform.
1395 uint32_t valid_flags;
1396 /* Flags which can be changed given the current protection state */
1397 uint32_t writable_flags;
1401 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1402 * write protect. These commands may be reused with version > 0.
1405 /* Get the region offset/size */
1406 #define EC_CMD_FLASH_REGION_INFO 0x0016
1407 #define EC_VER_FLASH_REGION_INFO 1
1409 enum ec_flash_region {
1410 /* Region which holds read-only EC image */
1411 EC_FLASH_REGION_RO = 0,
1412 /* Region which holds active rewritable EC image */
1413 EC_FLASH_REGION_ACTIVE,
1415 * Region which should be write-protected in the factory (a superset of
1416 * EC_FLASH_REGION_RO)
1418 EC_FLASH_REGION_WP_RO,
1419 /* Region which holds updatable image */
1420 EC_FLASH_REGION_UPDATE,
1421 /* Number of regions */
1422 EC_FLASH_REGION_COUNT,
1425 struct __ec_align4 ec_params_flash_region_info {
1426 uint32_t region; /* enum ec_flash_region */
1429 struct __ec_align4 ec_response_flash_region_info {
1434 /* Read/write VbNvContext */
1435 #define EC_CMD_VBNV_CONTEXT 0x0017
1436 #define EC_VER_VBNV_CONTEXT 1
1437 #define EC_VBNV_BLOCK_SIZE 16
1438 #define EC_VBNV_BLOCK_SIZE_V2 64
1440 enum ec_vbnvcontext_op {
1441 EC_VBNV_CONTEXT_OP_READ,
1442 EC_VBNV_CONTEXT_OP_WRITE,
1445 struct __ec_align4 ec_params_vbnvcontext {
1447 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1450 struct __ec_align4 ec_response_vbnvcontext {
1451 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1455 /* Get SPI flash information */
1456 #define EC_CMD_FLASH_SPI_INFO 0x0018
1458 struct __ec_align1 ec_response_flash_spi_info {
1459 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1462 /* Pad byte; currently always contains 0 */
1465 /* Manufacturer / device ID from command 0x90 */
1466 uint8_t mfr_dev_id[2];
1468 /* Status registers from command 0x05 and 0x35 */
1473 /* Select flash during flash operations */
1474 #define EC_CMD_FLASH_SELECT 0x0019
1476 struct __ec_align4 ec_params_flash_select {
1477 /* 1 to select flash, 0 to deselect flash */
1481 /*****************************************************************************/
1484 /* Get fan target RPM */
1485 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1487 struct __ec_align4 ec_response_pwm_get_fan_rpm {
1491 /* Set target fan RPM */
1492 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1494 /* Version 0 of input params */
1495 struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
1499 /* Version 1 of input params */
1500 struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
1505 /* Get keyboard backlight */
1506 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1507 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1509 struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
1514 /* Set keyboard backlight */
1515 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1516 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1518 struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
1522 /* Set target fan PWM duty cycle */
1523 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1525 /* Version 0 of input params */
1526 struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
1530 /* Version 1 of input params */
1531 struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
1536 #define EC_CMD_PWM_SET_DUTY 0x0025
1537 /* 16 bit duty cycle, 0xffff = 100% */
1538 #define EC_PWM_MAX_DUTY 0xffff
1541 /* All types, indexed by board-specific enum pwm_channel */
1542 EC_PWM_TYPE_GENERIC = 0,
1543 /* Keyboard backlight */
1544 EC_PWM_TYPE_KB_LIGHT,
1545 /* Display backlight */
1546 EC_PWM_TYPE_DISPLAY_LIGHT,
1550 struct __ec_align4 ec_params_pwm_set_duty {
1551 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1552 uint8_t pwm_type; /* ec_pwm_type */
1553 uint8_t index; /* Type-specific index, or 0 if unique */
1556 #define EC_CMD_PWM_GET_DUTY 0x0026
1558 struct __ec_align1 ec_params_pwm_get_duty {
1559 uint8_t pwm_type; /* ec_pwm_type */
1560 uint8_t index; /* Type-specific index, or 0 if unique */
1563 struct __ec_align2 ec_response_pwm_get_duty {
1564 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1567 /*****************************************************************************/
1569 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1570 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1571 * into a subcommand. We'll make separate structs for subcommands with
1572 * different input args, so that we know how much to expect.
1574 #define EC_CMD_LIGHTBAR_CMD 0x0028
1576 struct __ec_todo_unpacked rgb_s {
1580 #define LB_BATTERY_LEVELS 4
1581 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1582 * host command, but the alignment is the same regardless. Keep it that way.
1584 struct __ec_todo_packed lightbar_params_v0 {
1586 int32_t google_ramp_up;
1587 int32_t google_ramp_down;
1588 int32_t s3s0_ramp_up;
1589 int32_t s0_tick_delay[2]; /* AC=0/1 */
1590 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1591 int32_t s0s3_ramp_down;
1592 int32_t s3_sleep_for;
1594 int32_t s3_ramp_down;
1598 uint8_t osc_min[2]; /* AC=0/1 */
1599 uint8_t osc_max[2]; /* AC=0/1 */
1600 uint8_t w_ofs[2]; /* AC=0/1 */
1602 /* Brightness limits based on the backlight and AC. */
1603 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1604 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1605 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1607 /* Battery level thresholds */
1608 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1610 /* Map [AC][battery_level] to color index */
1611 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1612 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1615 struct rgb_s color[8]; /* 0-3 are Google colors */
1618 struct __ec_todo_packed lightbar_params_v1 {
1620 int32_t google_ramp_up;
1621 int32_t google_ramp_down;
1622 int32_t s3s0_ramp_up;
1623 int32_t s0_tick_delay[2]; /* AC=0/1 */
1624 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1625 int32_t s0s3_ramp_down;
1626 int32_t s3_sleep_for;
1628 int32_t s3_ramp_down;
1630 int32_t s5_ramp_down;
1631 int32_t tap_tick_delay;
1632 int32_t tap_gate_delay;
1633 int32_t tap_display_time;
1635 /* Tap-for-battery params */
1636 uint8_t tap_pct_red;
1637 uint8_t tap_pct_green;
1638 uint8_t tap_seg_min_on;
1639 uint8_t tap_seg_max_on;
1640 uint8_t tap_seg_osc;
1644 uint8_t osc_min[2]; /* AC=0/1 */
1645 uint8_t osc_max[2]; /* AC=0/1 */
1646 uint8_t w_ofs[2]; /* AC=0/1 */
1648 /* Brightness limits based on the backlight and AC. */
1649 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1650 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1651 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1653 /* Battery level thresholds */
1654 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1656 /* Map [AC][battery_level] to color index */
1657 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1658 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1660 /* s5: single color pulse on inhibited power-up */
1664 struct rgb_s color[8]; /* 0-3 are Google colors */
1667 /* Lightbar command params v2
1670 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1671 * logical groups to make it more manageable ( < 120 bytes).
1673 * NOTE: Each of these groups must be less than 120 bytes.
1676 struct __ec_todo_packed lightbar_params_v2_timing {
1678 int32_t google_ramp_up;
1679 int32_t google_ramp_down;
1680 int32_t s3s0_ramp_up;
1681 int32_t s0_tick_delay[2]; /* AC=0/1 */
1682 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1683 int32_t s0s3_ramp_down;
1684 int32_t s3_sleep_for;
1686 int32_t s3_ramp_down;
1688 int32_t s5_ramp_down;
1689 int32_t tap_tick_delay;
1690 int32_t tap_gate_delay;
1691 int32_t tap_display_time;
1694 struct __ec_todo_packed lightbar_params_v2_tap {
1695 /* Tap-for-battery params */
1696 uint8_t tap_pct_red;
1697 uint8_t tap_pct_green;
1698 uint8_t tap_seg_min_on;
1699 uint8_t tap_seg_max_on;
1700 uint8_t tap_seg_osc;
1704 struct __ec_todo_packed lightbar_params_v2_oscillation {
1706 uint8_t osc_min[2]; /* AC=0/1 */
1707 uint8_t osc_max[2]; /* AC=0/1 */
1708 uint8_t w_ofs[2]; /* AC=0/1 */
1711 struct __ec_todo_packed lightbar_params_v2_brightness {
1712 /* Brightness limits based on the backlight and AC. */
1713 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1714 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1715 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1718 struct __ec_todo_packed lightbar_params_v2_thresholds {
1719 /* Battery level thresholds */
1720 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1723 struct __ec_todo_packed lightbar_params_v2_colors {
1724 /* Map [AC][battery_level] to color index */
1725 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1726 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1728 /* s5: single color pulse on inhibited power-up */
1732 struct rgb_s color[8]; /* 0-3 are Google colors */
1735 /* Lightbyte program. */
1736 #define EC_LB_PROG_LEN 192
1737 struct __ec_todo_unpacked lightbar_program {
1739 uint8_t data[EC_LB_PROG_LEN];
1742 struct __ec_todo_packed ec_params_lightbar {
1743 uint8_t cmd; /* Command (see enum lightbar_command) */
1745 struct __ec_todo_unpacked {
1747 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1748 version, get_brightness, get_demo, suspend, resume,
1749 get_params_v2_timing, get_params_v2_tap,
1750 get_params_v2_osc, get_params_v2_bright,
1751 get_params_v2_thlds, get_params_v2_colors;
1753 struct __ec_todo_unpacked {
1755 } set_brightness, seq, demo;
1757 struct __ec_todo_unpacked {
1758 uint8_t ctrl, reg, value;
1761 struct __ec_todo_unpacked {
1762 uint8_t led, red, green, blue;
1765 struct __ec_todo_unpacked {
1769 struct __ec_todo_unpacked {
1771 } manual_suspend_ctrl;
1773 struct lightbar_params_v0 set_params_v0;
1774 struct lightbar_params_v1 set_params_v1;
1776 struct lightbar_params_v2_timing set_v2par_timing;
1777 struct lightbar_params_v2_tap set_v2par_tap;
1778 struct lightbar_params_v2_oscillation set_v2par_osc;
1779 struct lightbar_params_v2_brightness set_v2par_bright;
1780 struct lightbar_params_v2_thresholds set_v2par_thlds;
1781 struct lightbar_params_v2_colors set_v2par_colors;
1783 struct lightbar_program set_program;
1787 struct __ec_todo_packed ec_response_lightbar {
1789 struct __ec_todo_unpacked {
1790 struct __ec_todo_unpacked {
1797 struct __ec_todo_unpacked {
1799 } get_seq, get_brightness, get_demo;
1801 struct lightbar_params_v0 get_params_v0;
1802 struct lightbar_params_v1 get_params_v1;
1805 struct lightbar_params_v2_timing get_params_v2_timing;
1806 struct lightbar_params_v2_tap get_params_v2_tap;
1807 struct lightbar_params_v2_oscillation get_params_v2_osc;
1808 struct lightbar_params_v2_brightness get_params_v2_bright;
1809 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1810 struct lightbar_params_v2_colors get_params_v2_colors;
1812 struct __ec_todo_unpacked {
1817 struct __ec_todo_unpacked {
1818 uint8_t red, green, blue;
1821 struct __ec_todo_unpacked {
1822 /* no return params */
1823 } off, on, init, set_brightness, seq, reg, set_rgb,
1824 demo, set_params_v0, set_params_v1,
1825 set_program, manual_suspend_ctrl, suspend, resume,
1826 set_v2par_timing, set_v2par_tap,
1827 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1832 /* Lightbar commands */
1833 enum lightbar_command {
1834 LIGHTBAR_CMD_DUMP = 0,
1835 LIGHTBAR_CMD_OFF = 1,
1836 LIGHTBAR_CMD_ON = 2,
1837 LIGHTBAR_CMD_INIT = 3,
1838 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1839 LIGHTBAR_CMD_SEQ = 5,
1840 LIGHTBAR_CMD_REG = 6,
1841 LIGHTBAR_CMD_SET_RGB = 7,
1842 LIGHTBAR_CMD_GET_SEQ = 8,
1843 LIGHTBAR_CMD_DEMO = 9,
1844 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1845 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1846 LIGHTBAR_CMD_VERSION = 12,
1847 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1848 LIGHTBAR_CMD_GET_RGB = 14,
1849 LIGHTBAR_CMD_GET_DEMO = 15,
1850 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1851 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1852 LIGHTBAR_CMD_SET_PROGRAM = 18,
1853 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1854 LIGHTBAR_CMD_SUSPEND = 20,
1855 LIGHTBAR_CMD_RESUME = 21,
1856 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1857 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1858 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1859 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1860 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1861 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1862 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1863 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1864 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1865 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1866 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1867 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
1871 /*****************************************************************************/
1872 /* LED control commands */
1874 #define EC_CMD_LED_CONTROL 0x0029
1877 /* LED to indicate battery state of charge */
1878 EC_LED_ID_BATTERY_LED = 0,
1880 * LED to indicate system power state (on or in suspend).
1881 * May be on power button or on C-panel.
1883 EC_LED_ID_POWER_LED,
1884 /* LED on power adapter or its plug */
1885 EC_LED_ID_ADAPTER_LED,
1886 /* LED to indicate left side */
1888 /* LED to indicate right side */
1889 EC_LED_ID_RIGHT_LED,
1890 /* LED to indicate recovery mode with HW_REINIT */
1891 EC_LED_ID_RECOVERY_HW_REINIT_LED,
1892 /* LED to indicate sysrq debug mode. */
1893 EC_LED_ID_SYSRQ_DEBUG_LED,
1898 /* LED control flags */
1899 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1900 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1902 enum ec_led_colors {
1903 EC_LED_COLOR_RED = 0,
1906 EC_LED_COLOR_YELLOW,
1913 struct __ec_align1 ec_params_led_control {
1914 uint8_t led_id; /* Which LED to control */
1915 uint8_t flags; /* Control flags */
1917 uint8_t brightness[EC_LED_COLOR_COUNT];
1920 struct __ec_align1 ec_response_led_control {
1922 * Available brightness value range.
1924 * Range 0 means color channel not present.
1925 * Range 1 means on/off control.
1926 * Other values means the LED is control by PWM.
1928 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1931 /*****************************************************************************/
1932 /* Verified boot commands */
1935 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1936 * reused for other purposes with version > 0.
1939 /* Verified boot hash command */
1940 #define EC_CMD_VBOOT_HASH 0x002A
1942 struct __ec_align4 ec_params_vboot_hash {
1943 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1944 uint8_t hash_type; /* enum ec_vboot_hash_type */
1945 uint8_t nonce_size; /* Nonce size; may be 0 */
1946 uint8_t reserved0; /* Reserved; set 0 */
1947 uint32_t offset; /* Offset in flash to hash */
1948 uint32_t size; /* Number of bytes to hash */
1949 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1952 struct __ec_align4 ec_response_vboot_hash {
1953 uint8_t status; /* enum ec_vboot_hash_status */
1954 uint8_t hash_type; /* enum ec_vboot_hash_type */
1955 uint8_t digest_size; /* Size of hash digest in bytes */
1956 uint8_t reserved0; /* Ignore; will be 0 */
1957 uint32_t offset; /* Offset in flash which was hashed */
1958 uint32_t size; /* Number of bytes hashed */
1959 uint8_t hash_digest[64]; /* Hash digest data */
1962 enum ec_vboot_hash_cmd {
1963 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1964 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1965 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1966 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1969 enum ec_vboot_hash_type {
1970 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1973 enum ec_vboot_hash_status {
1974 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1975 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1976 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1980 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1981 * If one of these is specified, the EC will automatically update offset and
1982 * size to the correct values for the specified image (RO or RW).
1984 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1985 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
1986 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
1988 /*****************************************************************************/
1990 * Motion sense commands. We'll make separate structs for sub-commands with
1991 * different input args, so that we know how much to expect.
1993 #define EC_CMD_MOTION_SENSE_CMD 0x002B
1995 /* Motion sense commands */
1996 enum motionsense_command {
1998 * Dump command returns all motion sensor data including motion sense
1999 * module flags and individual sensor flags.
2001 MOTIONSENSE_CMD_DUMP = 0,
2004 * Info command returns data describing the details of a given sensor,
2005 * including enum motionsensor_type, enum motionsensor_location, and
2006 * enum motionsensor_chip.
2008 MOTIONSENSE_CMD_INFO = 1,
2011 * EC Rate command is a setter/getter command for the EC sampling rate
2013 * It is per sensor, the EC run sample task at the minimum of all
2015 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2016 * to collect all the sensor samples.
2017 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2018 * to process of all motion sensors in milliseconds.
2020 MOTIONSENSE_CMD_EC_RATE = 2,
2023 * Sensor ODR command is a setter/getter command for the output data
2024 * rate of a specific motion sensor in millihertz.
2026 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2029 * Sensor range command is a setter/getter command for the range of
2030 * a specified motion sensor in +/-G's or +/- deg/s.
2032 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2035 * Setter/getter command for the keyboard wake angle. When the lid
2036 * angle is greater than this value, keyboard wake is disabled in S3,
2037 * and when the lid angle goes less than this value, keyboard wake is
2038 * enabled. Note, the lid angle measurement is an approximate,
2039 * un-calibrated value, hence the wake angle isn't exact.
2041 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2044 * Returns a single sensor data.
2046 MOTIONSENSE_CMD_DATA = 6,
2049 * Return sensor fifo info.
2051 MOTIONSENSE_CMD_FIFO_INFO = 7,
2054 * Insert a flush element in the fifo and return sensor fifo info.
2055 * The host can use that element to synchronize its operation.
2057 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2060 * Return a portion of the fifo.
2062 MOTIONSENSE_CMD_FIFO_READ = 9,
2065 * Perform low level calibration.
2066 * On sensors that support it, ask to do offset calibration.
2068 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2071 * Sensor Offset command is a setter/getter command for the offset
2072 * used for calibration.
2073 * The offsets can be calculated by the host, or via
2074 * PERFORM_CALIB command.
2076 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2079 * List available activities for a MOTION sensor.
2080 * Indicates if they are enabled or disabled.
2082 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2085 * Activity management
2086 * Enable/Disable activity recognition.
2088 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2093 MOTIONSENSE_CMD_LID_ANGLE = 14,
2096 * Allow the FIFO to trigger interrupt via MKBP events.
2097 * By default the FIFO does not send interrupt to process the FIFO
2098 * until the AP is ready or it is coming from a wakeup sensor.
2100 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2103 * Spoof the readings of the sensors. The spoofed readings can be set
2104 * to arbitrary values, or will lock to the last read actual values.
2106 MOTIONSENSE_CMD_SPOOF = 16,
2108 /* Number of motionsense sub-commands. */
2109 MOTIONSENSE_NUM_CMDS
2112 /* List of motion sensor types. */
2113 enum motionsensor_type {
2114 MOTIONSENSE_TYPE_ACCEL = 0,
2115 MOTIONSENSE_TYPE_GYRO = 1,
2116 MOTIONSENSE_TYPE_MAG = 2,
2117 MOTIONSENSE_TYPE_PROX = 3,
2118 MOTIONSENSE_TYPE_LIGHT = 4,
2119 MOTIONSENSE_TYPE_ACTIVITY = 5,
2120 MOTIONSENSE_TYPE_BARO = 6,
2121 MOTIONSENSE_TYPE_MAX,
2124 /* List of motion sensor locations. */
2125 enum motionsensor_location {
2126 MOTIONSENSE_LOC_BASE = 0,
2127 MOTIONSENSE_LOC_LID = 1,
2128 MOTIONSENSE_LOC_MAX,
2131 /* List of motion sensor chips. */
2132 enum motionsensor_chip {
2133 MOTIONSENSE_CHIP_KXCJ9 = 0,
2134 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2135 MOTIONSENSE_CHIP_BMI160 = 2,
2136 MOTIONSENSE_CHIP_SI1141 = 3,
2137 MOTIONSENSE_CHIP_SI1142 = 4,
2138 MOTIONSENSE_CHIP_SI1143 = 5,
2139 MOTIONSENSE_CHIP_KX022 = 6,
2140 MOTIONSENSE_CHIP_L3GD20H = 7,
2141 MOTIONSENSE_CHIP_BMA255 = 8,
2142 MOTIONSENSE_CHIP_BMP280 = 9,
2143 MOTIONSENSE_CHIP_OPT3001 = 10,
2146 struct __ec_todo_packed ec_response_motion_sensor_data {
2147 /* Flags for each sensor. */
2149 /* sensor number the data comes from */
2151 /* Each sensor is up to 3-axis. */
2154 struct __ec_todo_packed {
2158 struct __ec_todo_unpacked {
2159 uint8_t activity; /* motionsensor_activity */
2161 int16_t add_info[2];
2166 /* Note: used in ec_response_get_next_data */
2167 struct __ec_todo_packed ec_response_motion_sense_fifo_info {
2168 /* Size of the fifo */
2170 /* Amount of space used in the fifo */
2172 /* Timestamp recorded in us */
2174 /* Total amount of vector lost */
2175 uint16_t total_lost;
2176 /* Lost events since the last fifo_info, per sensors */
2180 struct __ec_todo_packed ec_response_motion_sense_fifo_data {
2181 uint32_t number_data;
2182 struct ec_response_motion_sensor_data data[0];
2185 /* List supported activity recognition */
2186 enum motionsensor_activity {
2187 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2188 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2189 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2192 struct __ec_todo_unpacked ec_motion_sense_activity {
2194 uint8_t activity; /* one of enum motionsensor_activity */
2195 uint8_t enable; /* 1: enable, 0: disable */
2197 uint16_t parameters[3]; /* activity dependent parameters */
2200 /* Module flag masks used for the dump sub-command. */
2201 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2203 /* Sensor flag masks used for the dump sub-command. */
2204 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2207 * Flush entry for synchronization.
2208 * data contains time stamp
2210 #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2211 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2212 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
2213 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
2216 * Send this value for the data element to only perform a read. If you
2217 * send any other value, the EC will interpret it as data to set and will
2218 * return the actual value set.
2220 #define EC_MOTION_SENSE_NO_VALUE -1
2222 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2224 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2225 /* Set Calibration information */
2226 #define MOTION_SENSE_SET_OFFSET 1
2228 #define LID_ANGLE_UNRELIABLE 500
2230 enum motionsense_spoof_mode {
2231 /* Disable spoof mode. */
2232 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2234 /* Enable spoof mode, but use provided component values. */
2235 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2237 /* Enable spoof mode, but use the current sensor values. */
2238 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2240 /* Query the current spoof mode status for the sensor. */
2241 MOTIONSENSE_SPOOF_MODE_QUERY,
2244 struct __ec_todo_packed ec_params_motion_sense {
2247 /* Used for MOTIONSENSE_CMD_DUMP */
2248 struct __ec_todo_unpacked {
2250 * Maximal number of sensor the host is expecting.
2251 * 0 means the host is only interested in the number
2252 * of sensors controlled by the EC.
2254 uint8_t max_sensor_count;
2258 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2260 struct __ec_todo_unpacked {
2261 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2262 * kb_wake_angle: angle to wakup AP.
2267 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2268 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
2269 struct __ec_todo_unpacked {
2271 } info, info_3, data, fifo_flush, perform_calib,
2275 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2276 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2278 struct __ec_todo_unpacked {
2281 /* Rounding flag, true for round-up, false for down. */
2286 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2288 } ec_rate, sensor_odr, sensor_range;
2290 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2291 struct __ec_todo_packed {
2295 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2296 * the calibration information in the EC.
2297 * If unset, just retrieve calibration information.
2302 * Temperature at calibration, in units of 0.01 C
2303 * 0x8000: invalid / unknown.
2310 * Offset for calibration.
2312 * Accelerometer: 1/1024 g
2313 * Gyro: 1/1024 deg/s
2319 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
2320 struct __ec_todo_unpacked {
2323 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2324 struct __ec_todo_unpacked {
2326 * Number of expected vector to return.
2327 * EC may return less or 0 if none available.
2329 uint32_t max_data_vector;
2332 struct ec_motion_sense_activity set_activity;
2334 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2335 struct __ec_todo_unpacked {
2338 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2339 struct __ec_todo_unpacked {
2341 * 1: enable, 0 disable fifo,
2342 * EC_MOTION_SENSE_NO_VALUE return value.
2347 /* Used for MOTIONSENSE_CMD_SPOOF */
2348 struct __ec_todo_packed {
2351 /* See enum motionsense_spoof_mode. */
2352 uint8_t spoof_enable;
2354 /* Ignored, used for alignment. */
2357 /* Individual component values to spoof. */
2358 int16_t components[3];
2363 struct __ec_todo_packed ec_response_motion_sense {
2365 /* Used for MOTIONSENSE_CMD_DUMP */
2366 struct __ec_todo_unpacked {
2367 /* Flags representing the motion sensor module. */
2368 uint8_t module_flags;
2370 /* Number of sensors managed directly by the EC */
2371 uint8_t sensor_count;
2374 * sensor data is truncated if response_max is too small
2375 * for holding all the data.
2377 struct ec_response_motion_sensor_data sensor[0];
2380 /* Used for MOTIONSENSE_CMD_INFO. */
2381 struct __ec_todo_unpacked {
2382 /* Should be element of enum motionsensor_type. */
2385 /* Should be element of enum motionsensor_location. */
2388 /* Should be element of enum motionsensor_chip. */
2392 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2393 struct __ec_todo_unpacked {
2394 /* Should be element of enum motionsensor_type. */
2397 /* Should be element of enum motionsensor_location. */
2400 /* Should be element of enum motionsensor_chip. */
2403 /* Minimum sensor sampling frequency */
2404 uint32_t min_frequency;
2406 /* Maximum sensor sampling frequency */
2407 uint32_t max_frequency;
2409 /* Max number of sensor events that could be in fifo */
2410 uint32_t fifo_max_event_count;
2413 /* Used for MOTIONSENSE_CMD_DATA */
2414 struct ec_response_motion_sensor_data data;
2417 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2418 * MOTIONSENSE_CMD_SENSOR_RANGE,
2419 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2420 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2421 * MOTIONSENSE_CMD_SPOOF.
2423 struct __ec_todo_unpacked {
2424 /* Current value of the parameter queried. */
2426 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2427 fifo_int_enable, spoof;
2429 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2430 struct __ec_todo_unpacked {
2433 } sensor_offset, perform_calib;
2435 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2437 struct ec_response_motion_sense_fifo_data fifo_read;
2439 struct __ec_todo_packed {
2445 struct __ec_todo_unpacked {
2448 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2449 struct __ec_todo_unpacked {
2451 * Angle between 0 and 360 degree if available,
2452 * LID_ANGLE_UNRELIABLE otherwise.
2459 /*****************************************************************************/
2460 /* Force lid open command */
2462 /* Make lid event always open */
2463 #define EC_CMD_FORCE_LID_OPEN 0x002C
2465 struct __ec_align1 ec_params_force_lid_open {
2469 /*****************************************************************************/
2470 /* Configure the behavior of the power button */
2471 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2473 enum ec_config_power_button_flags {
2474 /* Enable/Disable power button pulses for x86 devices */
2475 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2478 struct __ec_align1 ec_params_config_power_button {
2479 /* See enum ec_config_power_button_flags */
2483 /*****************************************************************************/
2484 /* USB charging control commands */
2486 /* Set USB port charging mode */
2487 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2489 struct __ec_align1 ec_params_usb_charge_set_mode {
2490 uint8_t usb_port_id;
2494 /*****************************************************************************/
2495 /* Persistent storage for host */
2497 /* Maximum bytes that can be read/written in a single command */
2498 #define EC_PSTORE_SIZE_MAX 64
2500 /* Get persistent storage info */
2501 #define EC_CMD_PSTORE_INFO 0x0040
2503 struct __ec_align4 ec_response_pstore_info {
2504 /* Persistent storage size, in bytes */
2505 uint32_t pstore_size;
2506 /* Access size; read/write offset and size must be a multiple of this */
2507 uint32_t access_size;
2511 * Read persistent storage
2513 * Response is params.size bytes of data.
2515 #define EC_CMD_PSTORE_READ 0x0041
2517 struct __ec_align4 ec_params_pstore_read {
2518 uint32_t offset; /* Byte offset to read */
2519 uint32_t size; /* Size to read in bytes */
2522 /* Write persistent storage */
2523 #define EC_CMD_PSTORE_WRITE 0x0042
2525 struct __ec_align4 ec_params_pstore_write {
2526 uint32_t offset; /* Byte offset to write */
2527 uint32_t size; /* Size to write in bytes */
2528 uint8_t data[EC_PSTORE_SIZE_MAX];
2531 /*****************************************************************************/
2532 /* Real-time clock */
2534 /* RTC params and response structures */
2535 struct __ec_align4 ec_params_rtc {
2539 struct __ec_align4 ec_response_rtc {
2543 /* These use ec_response_rtc */
2544 #define EC_CMD_RTC_GET_VALUE 0x0044
2545 #define EC_CMD_RTC_GET_ALARM 0x0045
2547 /* These all use ec_params_rtc */
2548 #define EC_CMD_RTC_SET_VALUE 0x0046
2549 #define EC_CMD_RTC_SET_ALARM 0x0047
2551 /* Pass as time param to SET_ALARM to clear the current alarm */
2552 #define EC_RTC_ALARM_CLEAR 0
2554 /*****************************************************************************/
2555 /* Port80 log access */
2557 /* Maximum entries that can be read/written in a single command */
2558 #define EC_PORT80_SIZE_MAX 32
2560 /* Get last port80 code from previous boot */
2561 #define EC_CMD_PORT80_LAST_BOOT 0x0048
2562 #define EC_CMD_PORT80_READ 0x0048
2564 enum ec_port80_subcmd {
2565 EC_PORT80_GET_INFO = 0,
2566 EC_PORT80_READ_BUFFER,
2569 struct __ec_todo_packed ec_params_port80_read {
2572 struct __ec_todo_unpacked {
2574 uint32_t num_entries;
2579 struct __ec_todo_packed ec_response_port80_read {
2581 struct __ec_todo_unpacked {
2583 uint32_t history_size;
2586 struct __ec_todo_unpacked {
2587 uint16_t codes[EC_PORT80_SIZE_MAX];
2592 struct __ec_align2 ec_response_port80_last_boot {
2596 /*****************************************************************************/
2597 /* Temporary secure storage for host verified boot use */
2599 /* Number of bytes in a vstore slot */
2600 #define EC_VSTORE_SLOT_SIZE 64
2602 /* Maximum number of vstore slots */
2603 #define EC_VSTORE_SLOT_MAX 32
2605 /* Get persistent storage info */
2606 #define EC_CMD_VSTORE_INFO 0x0049
2607 struct __ec_align_size1 ec_response_vstore_info {
2608 /* Indicates which slots are locked */
2609 uint32_t slot_locked;
2610 /* Total number of slots available */
2615 * Read temporary secure storage
2617 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2619 #define EC_CMD_VSTORE_READ 0x004A
2621 struct __ec_align1 ec_params_vstore_read {
2622 uint8_t slot; /* Slot to read from */
2625 struct __ec_align1 ec_response_vstore_read {
2626 uint8_t data[EC_VSTORE_SLOT_SIZE];
2630 * Write temporary secure storage and lock it.
2632 #define EC_CMD_VSTORE_WRITE 0x004B
2634 struct __ec_align1 ec_params_vstore_write {
2635 uint8_t slot; /* Slot to write to */
2636 uint8_t data[EC_VSTORE_SLOT_SIZE];
2639 /*****************************************************************************/
2640 /* Thermal engine commands. Note that there are two implementations. We'll
2641 * reuse the command number, but the data and behavior is incompatible.
2642 * Version 0 is what originally shipped on Link.
2643 * Version 1 separates the CPU thermal limits from the fan control.
2646 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2647 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
2649 /* The version 0 structs are opaque. You have to know what they are for
2650 * the get/set commands to make any sense.
2653 /* Version 0 - set */
2654 struct __ec_align2 ec_params_thermal_set_threshold {
2655 uint8_t sensor_type;
2656 uint8_t threshold_id;
2660 /* Version 0 - get */
2661 struct __ec_align1 ec_params_thermal_get_threshold {
2662 uint8_t sensor_type;
2663 uint8_t threshold_id;
2666 struct __ec_align2 ec_response_thermal_get_threshold {
2671 /* The version 1 structs are visible. */
2672 enum ec_temp_thresholds {
2673 EC_TEMP_THRESH_WARN = 0,
2674 EC_TEMP_THRESH_HIGH,
2675 EC_TEMP_THRESH_HALT,
2677 EC_TEMP_THRESH_COUNT
2681 * Thermal configuration for one temperature sensor. Temps are in degrees K.
2682 * Zero values will be silently ignored by the thermal task.
2684 * Note that this structure is a sub-structure of
2685 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
2687 struct __ec_align4 ec_thermal_config {
2688 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2689 uint32_t temp_fan_off; /* no active cooling needed */
2690 uint32_t temp_fan_max; /* max active cooling needed */
2693 /* Version 1 - get config for one sensor. */
2694 struct __ec_align4 ec_params_thermal_get_threshold_v1 {
2695 uint32_t sensor_num;
2697 /* This returns a struct ec_thermal_config */
2699 /* Version 1 - set config for one sensor.
2700 * Use read-modify-write for best results! */
2701 struct __ec_align4 ec_params_thermal_set_threshold_v1 {
2702 uint32_t sensor_num;
2703 struct ec_thermal_config cfg;
2705 /* This returns no data */
2707 /****************************************************************************/
2709 /* Toggle automatic fan control */
2710 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
2712 /* Version 1 of input params */
2713 struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
2717 /* Get/Set TMP006 calibration data */
2718 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2719 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
2722 * The original TMP006 calibration only needed four params, but now we need
2723 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2724 * the params opaque. The v1 "get" response will include the algorithm number
2725 * and how many params it requires. That way we can change the EC code without
2726 * needing to update this file. We can also use a different algorithm on each
2730 /* This is the same struct for both v0 and v1. */
2731 struct __ec_align1 ec_params_tmp006_get_calibration {
2736 struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
2743 struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
2745 uint8_t reserved[3];
2753 struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
2756 uint8_t reserved[2];
2760 struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
2769 /* Read raw TMP006 data */
2770 #define EC_CMD_TMP006_GET_RAW 0x0055
2772 struct __ec_align1 ec_params_tmp006_get_raw {
2776 struct __ec_align4 ec_response_tmp006_get_raw {
2777 int32_t t; /* In 1/100 K */
2778 int32_t v; /* In nV */
2781 /*****************************************************************************/
2782 /* MKBP - Matrix KeyBoard Protocol */
2787 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2788 * expected response size.
2790 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2791 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2792 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2794 #define EC_CMD_MKBP_STATE 0x0060
2797 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2799 #define EC_CMD_MKBP_INFO 0x0061
2801 struct __ec_align_size1 ec_response_mkbp_info {
2804 /* Formerly "switches", which was 0. */
2808 struct __ec_align1 ec_params_mkbp_info {
2813 enum ec_mkbp_info_type {
2815 * Info about the keyboard matrix: number of rows and columns.
2817 * Returns struct ec_response_mkbp_info.
2819 EC_MKBP_INFO_KBD = 0,
2822 * For buttons and switches, info about which specifically are
2823 * supported. event_type must be set to one of the values in enum
2826 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2827 * bitmask indicating which buttons or switches are present. See the
2828 * bit inidices below.
2830 EC_MKBP_INFO_SUPPORTED = 1,
2833 * Instantaneous state of buttons and switches.
2835 * event_type must be set to one of the values in enum ec_mkbp_event.
2837 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2838 * indicating the current state of the keyboard matrix.
2840 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2843 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2844 * state of supported buttons.
2846 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2847 * state of supported switches.
2849 EC_MKBP_INFO_CURRENT = 2,
2852 /* Simulate key press */
2853 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2855 struct __ec_align1 ec_params_mkbp_simulate_key {
2861 /* Configure keyboard scanning */
2862 #define EC_CMD_MKBP_SET_CONFIG 0x0064
2863 #define EC_CMD_MKBP_GET_CONFIG 0x0065
2866 enum mkbp_config_flags {
2867 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2870 enum mkbp_config_valid {
2871 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2872 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2873 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2874 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2875 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2876 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2877 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2881 * Configuration for our key scanning algorithm.
2883 * Note that this is used as a sub-structure of
2884 * ec_{params/response}_mkbp_get_config.
2886 struct __ec_align_size1 ec_mkbp_config {
2887 uint32_t valid_mask; /* valid fields */
2888 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2889 uint8_t valid_flags; /* which flags are valid */
2890 uint16_t scan_period_us; /* period between start of scans */
2891 /* revert to interrupt mode after no activity for this long */
2892 uint32_t poll_timeout_us;
2894 * minimum post-scan relax time. Once we finish a scan we check
2895 * the time until we are due to start the next one. If this time is
2896 * shorter this field, we use this instead.
2898 uint16_t min_post_scan_delay_us;
2899 /* delay between setting up output and waiting for it to settle */
2900 uint16_t output_settle_us;
2901 uint16_t debounce_down_us; /* time for debounce on key down */
2902 uint16_t debounce_up_us; /* time for debounce on key up */
2903 /* maximum depth to allow for fifo (0 = no keyscan output) */
2904 uint8_t fifo_max_depth;
2907 struct __ec_align_size1 ec_params_mkbp_set_config {
2908 struct ec_mkbp_config config;
2911 struct __ec_align_size1 ec_response_mkbp_get_config {
2912 struct ec_mkbp_config config;
2915 /* Run the key scan emulation */
2916 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2918 enum ec_keyscan_seq_cmd {
2919 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2920 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2921 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2922 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2923 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2926 enum ec_collect_flags {
2928 * Indicates this scan was processed by the EC. Due to timing, some
2929 * scans may be skipped.
2931 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2934 struct __ec_align1 ec_collect_item {
2935 uint8_t flags; /* some flags (enum ec_collect_flags) */
2938 struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
2939 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2941 struct __ec_align1 {
2942 uint8_t active; /* still active */
2943 uint8_t num_items; /* number of items */
2944 /* Current item being presented */
2947 struct __ec_todo_unpacked {
2949 * Absolute time for this scan, measured from the
2950 * start of the sequence.
2953 uint8_t scan[0]; /* keyscan data */
2955 struct __ec_align1 {
2956 uint8_t start_item; /* First item to return */
2957 uint8_t num_items; /* Number of items to return */
2962 struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
2964 struct __ec_todo_unpacked {
2965 uint8_t num_items; /* Number of items */
2966 /* Data for each item */
2967 struct ec_collect_item item[0];
2973 * Get the next pending MKBP event.
2975 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2977 #define EC_CMD_GET_NEXT_EVENT 0x0067
2979 enum ec_mkbp_event {
2980 /* Keyboard matrix changed. The event data is the new matrix state. */
2981 EC_MKBP_EVENT_KEY_MATRIX = 0,
2983 /* New host event. The event data is 4 bytes of host event flags. */
2984 EC_MKBP_EVENT_HOST_EVENT = 1,
2986 /* New Sensor FIFO data. The event data is fifo_info structure. */
2987 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2989 /* The state of the non-matrixed buttons have changed. */
2990 EC_MKBP_EVENT_BUTTON = 3,
2992 /* The state of the switches have changed. */
2993 EC_MKBP_EVENT_SWITCH = 4,
2995 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2996 EC_MKBP_EVENT_FINGERPRINT = 5,
2999 * Sysrq event: send emulated sysrq. The event data is sysrq,
3000 * corresponding to the key to be pressed.
3002 EC_MKBP_EVENT_SYSRQ = 6,
3004 /* Number of MKBP events */
3005 EC_MKBP_EVENT_COUNT,
3008 union __ec_align_offset1 ec_response_get_next_data {
3009 uint8_t key_matrix[13];
3012 uint32_t host_event;
3014 struct __ec_todo_unpacked {
3015 /* For aligning the fifo_info */
3016 uint8_t reserved[3];
3017 struct ec_response_motion_sense_fifo_info info;
3029 struct __ec_align1 ec_response_get_next_event {
3031 /* Followed by event data if any */
3032 union ec_response_get_next_data data;
3035 /* Bit indices for buttons and switches.*/
3037 #define EC_MKBP_POWER_BUTTON 0
3038 #define EC_MKBP_VOL_UP 1
3039 #define EC_MKBP_VOL_DOWN 2
3040 #define EC_MKBP_RECOVERY 3
3043 #define EC_MKBP_LID_OPEN 0
3044 #define EC_MKBP_TABLET_MODE 1
3046 /* Run keyboard factory test scanning */
3047 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3049 struct __ec_align2 ec_response_keyboard_factory_test {
3050 uint16_t shorted; /* Keyboard pins are shorted */
3053 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3054 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3055 #define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3056 #define EC_MKBP_FP_FINGER_UP (1 << 30)
3057 #define EC_MKBP_FP_IMAGE_READY (1 << 31)
3059 /*****************************************************************************/
3060 /* Temperature sensor commands */
3062 /* Read temperature sensor info */
3063 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
3065 struct __ec_align1 ec_params_temp_sensor_get_info {
3069 struct __ec_align1 ec_response_temp_sensor_get_info {
3070 char sensor_name[32];
3071 uint8_t sensor_type;
3074 /*****************************************************************************/
3077 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3078 * commands accidentally sent to the wrong interface. See the ACPI section
3082 /*****************************************************************************/
3083 /* Host event commands */
3086 /* Obsolete. New implementation should use EC_CMD_PROGRAM_HOST_EVENT instead */
3088 * Host event mask params and response structures, shared by all of the host
3089 * event commands below.
3091 struct __ec_align4 ec_params_host_event_mask {
3095 struct __ec_align4 ec_response_host_event_mask {
3099 /* These all use ec_response_host_event_mask */
3100 #define EC_CMD_HOST_EVENT_GET_B 0x0087
3101 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3102 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3103 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
3105 /* These all use ec_params_host_event_mask */
3106 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3107 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3108 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
3109 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3110 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3113 * Unified host event programming interface - Should be used by newer versions
3114 * of BIOS/OS to program host events and masks
3117 struct __ec_align4 ec_params_host_event {
3119 /* Action requested by host - one of enum ec_host_event_action. */
3123 * Mask type that the host requested the action on - one of
3124 * enum ec_host_event_mask_type.
3128 /* Set to 0, ignore on read */
3131 /* Value to be used in case of set operations. */
3136 * Response structure returned by EC_CMD_HOST_EVENT.
3137 * Update the value on a GET request. Set to 0 on GET/CLEAR
3140 struct __ec_align4 ec_response_host_event {
3142 /* Mask value in case of get operation */
3146 enum ec_host_event_action {
3148 * params.value is ignored. Value of mask_type populated
3153 /* Bits in params.value are set */
3156 /* Bits in params.value are cleared */
3157 EC_HOST_EVENT_CLEAR,
3160 enum ec_host_event_mask_type {
3162 /* Main host event copy */
3165 /* Copy B of host events */
3169 EC_HOST_EVENT_SCI_MASK,
3172 EC_HOST_EVENT_SMI_MASK,
3174 /* Mask of events that should be always reported in hostevents */
3175 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3177 /* Active wake mask */
3178 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3180 /* Lazy wake mask for S0ix */
3181 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3183 /* Lazy wake mask for S3 */
3184 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3186 /* Lazy wake mask for S5 */
3187 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3190 #define EC_CMD_HOST_EVENT 0x00A4
3192 /*****************************************************************************/
3193 /* Switch commands */
3195 /* Enable/disable LCD backlight */
3196 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
3198 struct __ec_align1 ec_params_switch_enable_backlight {
3202 /* Enable/disable WLAN/Bluetooth */
3203 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
3204 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
3206 /* Version 0 params; no response */
3207 struct __ec_align1 ec_params_switch_enable_wireless_v0 {
3211 /* Version 1 params */
3212 struct __ec_align1 ec_params_switch_enable_wireless_v1 {
3213 /* Flags to enable now */
3216 /* Which flags to copy from now_flags */
3220 * Flags to leave enabled in S3, if they're on at the S0->S3
3221 * transition. (Other flags will be disabled by the S0->S3
3224 uint8_t suspend_flags;
3226 /* Which flags to copy from suspend_flags */
3227 uint8_t suspend_mask;
3230 /* Version 1 response */
3231 struct __ec_align1 ec_response_switch_enable_wireless_v1 {
3232 /* Flags to enable now */
3235 /* Flags to leave enabled in S3 */
3236 uint8_t suspend_flags;
3239 /*****************************************************************************/
3240 /* GPIO commands. Only available on EC if write protect has been disabled. */
3242 /* Set GPIO output value */
3243 #define EC_CMD_GPIO_SET 0x0092
3245 struct __ec_align1 ec_params_gpio_set {
3250 /* Get GPIO value */
3251 #define EC_CMD_GPIO_GET 0x0093
3253 /* Version 0 of input params and response */
3254 struct __ec_align1 ec_params_gpio_get {
3258 struct __ec_align1 ec_response_gpio_get {
3262 /* Version 1 of input params and response */
3263 struct __ec_align1 ec_params_gpio_get_v1 {
3266 struct __ec_align1 {
3268 } get_value_by_name;
3269 struct __ec_align1 {
3275 struct __ec_todo_packed ec_response_gpio_get_v1 {
3277 struct __ec_align1 {
3279 } get_value_by_name, get_count;
3280 struct __ec_todo_unpacked {
3288 enum gpio_get_subcmd {
3289 EC_GPIO_GET_BY_NAME = 0,
3290 EC_GPIO_GET_COUNT = 1,
3291 EC_GPIO_GET_INFO = 2,
3294 /*****************************************************************************/
3295 /* I2C commands. Only available when flash write protect is unlocked. */
3298 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3299 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3301 * Use EC_CMD_I2C_PASSTHRU instead.
3305 #define EC_CMD_I2C_READ 0x0094
3307 struct __ec_align_size1 ec_params_i2c_read {
3308 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3309 uint8_t read_size; /* Either 8 or 16. */
3314 struct __ec_align2 ec_response_i2c_read {
3319 #define EC_CMD_I2C_WRITE 0x0095
3321 struct __ec_align_size1 ec_params_i2c_write {
3323 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3324 uint8_t write_size; /* Either 8 or 16. */
3329 /*****************************************************************************/
3330 /* Charge state commands. Only available when flash write protect unlocked. */
3332 /* Force charge state machine to stop charging the battery or force it to
3333 * discharge the battery.
3335 #define EC_CMD_CHARGE_CONTROL 0x0096
3336 #define EC_VER_CHARGE_CONTROL 1
3338 enum ec_charge_control_mode {
3339 CHARGE_CONTROL_NORMAL = 0,
3340 CHARGE_CONTROL_IDLE,
3341 CHARGE_CONTROL_DISCHARGE,
3344 struct __ec_align4 ec_params_charge_control {
3345 uint32_t mode; /* enum charge_control_mode */
3348 /*****************************************************************************/
3349 /* Console commands. Only available when flash write protect is unlocked. */
3351 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
3352 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
3355 * Read data from the saved snapshot. If the subcmd parameter is
3356 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3357 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3358 * end of the previous snapshot.
3360 * The params are only looked at in version >= 1 of this command. Prior
3361 * versions will just default to CONSOLE_READ_NEXT behavior.
3363 * Response is null-terminated string. Empty string, if there is no more
3366 #define EC_CMD_CONSOLE_READ 0x0098
3368 enum ec_console_read_subcmd {
3369 CONSOLE_READ_NEXT = 0,
3373 struct __ec_align1 ec_params_console_read_v1 {
3374 uint8_t subcmd; /* enum ec_console_read_subcmd */
3377 /*****************************************************************************/
3380 * Cut off battery power immediately or after the host has shut down.
3382 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3383 * EC_RES_SUCCESS if the command was successful.
3384 * EC_RES_ERROR if the cut off command failed.
3386 #define EC_CMD_BATTERY_CUT_OFF 0x0099
3388 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3390 struct __ec_align1 ec_params_battery_cutoff {
3394 /*****************************************************************************/
3395 /* USB port mux control. */
3398 * Switch USB mux or return to automatic switching.
3400 #define EC_CMD_USB_MUX 0x009A
3402 struct __ec_align1 ec_params_usb_mux {
3406 /*****************************************************************************/
3407 /* LDOs / FETs control. */
3410 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3411 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3415 * Switch on/off a LDO.
3417 #define EC_CMD_LDO_SET 0x009B
3419 struct __ec_align1 ec_params_ldo_set {
3427 #define EC_CMD_LDO_GET 0x009C
3429 struct __ec_align1 ec_params_ldo_get {
3433 struct __ec_align1 ec_response_ldo_get {
3437 /*****************************************************************************/
3443 #define EC_CMD_POWER_INFO 0x009D
3445 struct __ec_align4 ec_response_power_info {
3446 uint32_t usb_dev_type;
3447 uint16_t voltage_ac;
3448 uint16_t voltage_system;
3449 uint16_t current_system;
3450 uint16_t usb_current_limit;
3453 /*****************************************************************************/
3454 /* I2C passthru command */
3456 #define EC_CMD_I2C_PASSTHRU 0x009E
3458 /* Read data; if not present, message is a write */
3459 #define EC_I2C_FLAG_READ (1 << 15)
3461 /* Mask for address */
3462 #define EC_I2C_ADDR_MASK 0x3ff
3464 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3465 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3468 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3470 struct __ec_align2 ec_params_i2c_passthru_msg {
3471 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3472 uint16_t len; /* Number of bytes to read or write */
3475 struct __ec_align2 ec_params_i2c_passthru {
3476 uint8_t port; /* I2C port number */
3477 uint8_t num_msgs; /* Number of messages */
3478 struct ec_params_i2c_passthru_msg msg[];
3479 /* Data to write for all messages is concatenated here */
3482 struct __ec_align1 ec_response_i2c_passthru {
3483 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3484 uint8_t num_msgs; /* Number of messages processed */
3485 uint8_t data[]; /* Data read by messages concatenated here */
3488 /*****************************************************************************/
3489 /* Power button hang detect */
3491 #define EC_CMD_HANG_DETECT 0x009F
3493 /* Reasons to start hang detection timer */
3494 /* Power button pressed */
3495 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3498 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3501 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
3503 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
3504 #define EC_HANG_START_ON_RESUME (1 << 3)
3506 /* Reasons to cancel hang detection */
3508 /* Power button released */
3509 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3511 /* Any host command from AP received */
3512 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3514 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3515 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3518 * If this flag is set, all the other fields are ignored, and the hang detect
3519 * timer is started. This provides the AP a way to start the hang timer
3520 * without reconfiguring any of the other hang detect settings. Note that
3521 * you must previously have configured the timeouts.
3523 #define EC_HANG_START_NOW (1 << 30)
3526 * If this flag is set, all the other fields are ignored (including
3527 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3528 * without reconfiguring any of the other hang detect settings.
3530 #define EC_HANG_STOP_NOW (1 << 31)
3532 struct __ec_align4 ec_params_hang_detect {
3533 /* Flags; see EC_HANG_* */
3536 /* Timeout in msec before generating host event, if enabled */
3537 uint16_t host_event_timeout_msec;
3539 /* Timeout in msec before generating warm reboot, if enabled */
3540 uint16_t warm_reboot_timeout_msec;
3543 /*****************************************************************************/
3544 /* Commands for battery charging */
3547 * This is the single catch-all host command to exchange data regarding the
3548 * charge state machine (v2 and up).
3550 #define EC_CMD_CHARGE_STATE 0x00A0
3552 /* Subcommands for this host command */
3553 enum charge_state_command {
3554 CHARGE_STATE_CMD_GET_STATE,
3555 CHARGE_STATE_CMD_GET_PARAM,
3556 CHARGE_STATE_CMD_SET_PARAM,
3557 CHARGE_STATE_NUM_CMDS
3561 * Known param numbers are defined here. Ranges are reserved for board-specific
3562 * params, which are handled by the particular implementations.
3564 enum charge_state_params {
3565 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3566 CS_PARAM_CHG_CURRENT, /* charger current limit */
3567 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3568 CS_PARAM_CHG_STATUS, /* charger-specific status */
3569 CS_PARAM_CHG_OPTION, /* charger-specific options */
3570 CS_PARAM_LIMIT_POWER, /*
3571 * Check if power is limited due to
3572 * low battery and / or a weak external
3573 * charger. READ ONLY.
3575 /* How many so far? */
3578 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3579 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3580 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3582 /* Other custom param ranges go here... */
3585 struct __ec_todo_packed ec_params_charge_state {
3586 uint8_t cmd; /* enum charge_state_command */
3588 struct __ec_align1 {
3592 struct __ec_todo_unpacked {
3593 uint32_t param; /* enum charge_state_param */
3596 struct __ec_todo_unpacked {
3597 uint32_t param; /* param to set */
3598 uint32_t value; /* value to set */
3603 struct __ec_align4 ec_response_charge_state {
3605 struct __ec_align4 {
3609 int chg_input_current;
3610 int batt_state_of_charge;
3613 struct __ec_align4 {
3616 struct __ec_align4 {
3617 /* no return values */
3624 * Set maximum battery charging current.
3626 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
3628 struct __ec_align4 ec_params_current_limit {
3629 uint32_t limit; /* in mA */
3633 * Set maximum external voltage / current.
3635 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
3637 /* Command v0 is used only on Spring and is obsolete + unsupported */
3638 struct __ec_align2 ec_params_external_power_limit_v1 {
3639 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3640 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
3643 #define EC_POWER_LIMIT_NONE 0xffff
3646 * Set maximum voltage & current of a dedicated charge port
3648 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3650 struct __ec_align2 ec_params_dedicated_charger_limit {
3651 uint16_t current_lim; /* in mA */
3652 uint16_t voltage_lim; /* in mV */
3655 /*****************************************************************************/
3656 /* Hibernate/Deep Sleep Commands */
3658 /* Set the delay before going into hibernation. */
3659 #define EC_CMD_HIBERNATION_DELAY 0x00A8
3661 struct __ec_align4 ec_params_hibernation_delay {
3663 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3664 * current settings without changing them.
3669 struct __ec_align4 ec_response_hibernation_delay {
3671 * The current time in seconds in which the system has been in the G3
3672 * state. This value is reset if the EC transitions out of G3.
3677 * The current time remaining in seconds until the EC should hibernate.
3678 * This value is also reset if the EC transitions out of G3.
3680 uint32_t time_remaining;
3683 * The current time in seconds that the EC should wait in G3 before
3686 uint32_t hibernate_delay;
3689 /* Inform the EC when entering a sleep state */
3690 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3692 enum host_sleep_event {
3693 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3694 HOST_SLEEP_EVENT_S3_RESUME = 2,
3695 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3696 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3699 struct __ec_align1 ec_params_host_sleep_event {
3700 uint8_t sleep_event;
3703 /*****************************************************************************/
3705 #define EC_CMD_DEVICE_EVENT 0x00AA
3707 enum ec_device_event {
3708 EC_DEVICE_EVENT_TRACKPAD,
3709 EC_DEVICE_EVENT_DSP,
3710 EC_DEVICE_EVENT_WIFI,
3713 enum ec_device_event_param {
3714 /* Get and clear pending device events */
3715 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3716 /* Get device event mask */
3717 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3718 /* Set device event mask */
3719 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3722 #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3724 struct __ec_align_size1 ec_params_device_event {
3725 uint32_t event_mask;
3729 struct __ec_align4 ec_response_device_event {
3730 uint32_t event_mask;
3733 /*****************************************************************************/
3734 /* Smart battery pass-through */
3736 /* Get / Set 16-bit smart battery registers */
3737 #define EC_CMD_SB_READ_WORD 0x00B0
3738 #define EC_CMD_SB_WRITE_WORD 0x00B1
3740 /* Get / Set string smart battery parameters
3741 * formatted as SMBUS "block".
3743 #define EC_CMD_SB_READ_BLOCK 0x00B2
3744 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
3746 struct __ec_align1 ec_params_sb_rd {
3750 struct __ec_align2 ec_response_sb_rd_word {
3754 struct __ec_align1 ec_params_sb_wr_word {
3759 struct __ec_align1 ec_response_sb_rd_block {
3763 struct __ec_align1 ec_params_sb_wr_block {
3768 /*****************************************************************************/
3769 /* Battery vendor parameters
3771 * Get or set vendor-specific parameters in the battery. Implementations may
3772 * differ between boards or batteries. On a set operation, the response
3773 * contains the actual value set, which may be rounded or clipped from the
3777 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
3779 enum ec_battery_vendor_param_mode {
3780 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3781 BATTERY_VENDOR_PARAM_MODE_SET,
3784 struct __ec_align_size1 ec_params_battery_vendor_param {
3790 struct __ec_align4 ec_response_battery_vendor_param {
3794 /*****************************************************************************/
3796 * Smart Battery Firmware Update Commands
3798 #define EC_CMD_SB_FW_UPDATE 0x00B5
3800 enum ec_sb_fw_update_subcmd {
3801 EC_SB_FW_UPDATE_PREPARE = 0x0,
3802 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3803 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3804 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3805 EC_SB_FW_UPDATE_END = 0x4,
3806 EC_SB_FW_UPDATE_STATUS = 0x5,
3807 EC_SB_FW_UPDATE_PROTECT = 0x6,
3808 EC_SB_FW_UPDATE_MAX = 0x7,
3811 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3812 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3813 #define SB_FW_UPDATE_CMD_INFO_SIZE 8
3815 struct __ec_align4 ec_sb_fw_update_header {
3816 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3817 uint16_t fw_id; /* firmware id */
3820 struct __ec_align4 ec_params_sb_fw_update {
3821 struct ec_sb_fw_update_header hdr;
3823 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3824 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3825 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3826 /* EC_SB_FW_UPDATE_END = 0x4 */
3827 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3828 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
3829 struct __ec_align4 {
3833 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
3834 struct __ec_align4 {
3835 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3840 struct __ec_align1 ec_response_sb_fw_update {
3842 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3843 struct __ec_align1 {
3844 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3847 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3848 struct __ec_align1 {
3849 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3855 * Entering Verified Boot Mode Command
3856 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3857 * Valid Modes are: normal, developer, and recovery.
3859 #define EC_CMD_ENTERING_MODE 0x00B6
3861 struct __ec_align4 ec_params_entering_mode {
3865 #define VBOOT_MODE_NORMAL 0
3866 #define VBOOT_MODE_DEVELOPER 1
3867 #define VBOOT_MODE_RECOVERY 2
3869 /*****************************************************************************/
3871 * I2C passthru protection command: Protects I2C tunnels against access on
3872 * certain addresses (board-specific).
3874 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
3876 enum ec_i2c_passthru_protect_subcmd {
3877 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3878 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3881 struct __ec_align1 ec_params_i2c_passthru_protect {
3883 uint8_t port; /* I2C port number */
3886 struct __ec_align1 ec_response_i2c_passthru_protect {
3887 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
3890 /*****************************************************************************/
3891 /* System commands */
3894 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3895 * necessarily reboot the EC. Rename to "image" or something similar?
3897 #define EC_CMD_REBOOT_EC 0x00D2
3900 enum ec_reboot_cmd {
3901 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
3902 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3903 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
3904 /* (command 3 was jump to RW-B) */
3905 EC_REBOOT_COLD = 4, /* Cold-reboot */
3906 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3907 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
3908 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
3911 /* Flags for ec_params_reboot_ec.reboot_flags */
3912 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
3913 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
3914 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2) /* Switch RW slot */
3916 struct __ec_align1 ec_params_reboot_ec {
3917 uint8_t cmd; /* enum ec_reboot_cmd */
3918 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3922 * Get information on last EC panic.
3924 * Returns variable-length platform-dependent panic information. See panic.h
3927 #define EC_CMD_GET_PANIC_INFO 0x00D3
3929 /*****************************************************************************/
3933 * These do not follow the normal rules for commands. See each command for
3940 * This command will work even when the EC LPC interface is busy, because the
3941 * reboot command is processed at interrupt level. Note that when the EC
3942 * reboots, the host will reboot too, so there is no response to this command.
3944 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3946 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3949 * Resend last response (not supported on LPC).
3951 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3952 * there was no previous command, or the previous command's response was too
3955 #define EC_CMD_RESEND_RESPONSE 0x00DB
3958 * This header byte on a command indicate version 0. Any header byte less
3959 * than this means that we are talking to an old EC which doesn't support
3960 * versioning. In that case, we assume version 0.
3962 * Header bytes greater than this indicate a later version. For example,
3963 * EC_CMD_VERSION0 + 1 means we are using version 1.
3965 * The old EC interface must not use commands 0xdc or higher.
3967 #define EC_CMD_VERSION0 0x00DC
3969 /*****************************************************************************/
3973 * These commands are for PD MCU communication.
3976 /* EC to PD MCU exchange status command */
3977 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
3978 #define EC_VER_PD_EXCHANGE_STATUS 2
3980 enum pd_charge_state {
3981 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3982 PD_CHARGE_NONE, /* No charging allowed */
3983 PD_CHARGE_5V, /* 5V charging only */
3984 PD_CHARGE_MAX /* Charge at max voltage */
3987 /* Status of EC being sent to PD */
3988 #define EC_STATUS_HIBERNATING (1 << 0)
3990 struct __ec_align1 ec_params_pd_status {
3991 uint8_t status; /* EC status */
3992 int8_t batt_soc; /* battery state of charge */
3993 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
3996 /* Status of PD being sent back to EC */
3997 #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3998 #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3999 #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
4000 #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
4001 #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
4002 #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
4003 #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
4004 #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4005 PD_STATUS_TCPC_ALERT_1 | \
4006 PD_STATUS_HOST_EVENT)
4007 struct __ec_align_size1 ec_response_pd_status {
4008 uint32_t curr_lim_ma; /* input current limit */
4009 uint16_t status; /* PD MCU status */
4010 int8_t active_charge_port; /* active charging port */
4013 /* AP to PD MCU host event status command, cleared on read */
4014 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4016 /* PD MCU host event status bits */
4017 #define PD_EVENT_UPDATE_DEVICE (1 << 0)
4018 #define PD_EVENT_POWER_CHANGE (1 << 1)
4019 #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
4020 #define PD_EVENT_DATA_SWAP (1 << 3)
4021 struct __ec_align4 ec_response_host_event_status {
4022 uint32_t status; /* PD MCU host event status */
4025 /* Set USB type-C port role and muxes */
4026 #define EC_CMD_USB_PD_CONTROL 0x0101
4028 enum usb_pd_control_role {
4029 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
4030 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
4031 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4032 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4033 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4034 USB_PD_CTRL_ROLE_COUNT
4037 enum usb_pd_control_mux {
4038 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4039 USB_PD_CTRL_MUX_NONE = 1,
4040 USB_PD_CTRL_MUX_USB = 2,
4041 USB_PD_CTRL_MUX_DP = 3,
4042 USB_PD_CTRL_MUX_DOCK = 4,
4043 USB_PD_CTRL_MUX_AUTO = 5,
4044 USB_PD_CTRL_MUX_COUNT
4047 enum usb_pd_control_swap {
4048 USB_PD_CTRL_SWAP_NONE = 0,
4049 USB_PD_CTRL_SWAP_DATA = 1,
4050 USB_PD_CTRL_SWAP_POWER = 2,
4051 USB_PD_CTRL_SWAP_VCONN = 3,
4052 USB_PD_CTRL_SWAP_COUNT
4055 struct __ec_align1 ec_params_usb_pd_control {
4062 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
4063 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
4064 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4066 #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
4067 #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
4068 #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
4069 #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
4070 #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
4071 #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
4072 #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
4074 struct __ec_align1 ec_response_usb_pd_control {
4081 struct __ec_align1 ec_response_usb_pd_control_v1 {
4088 #define EC_CMD_USB_PD_PORTS 0x0102
4090 /* Maximum number of PD ports on a device, num_ports will be <= this */
4091 #define EC_USB_PD_MAX_PORTS 8
4093 struct __ec_align1 ec_response_usb_pd_ports {
4097 #define EC_CMD_USB_PD_POWER_INFO 0x0103
4099 #define PD_POWER_CHARGING_PORT 0xff
4100 struct __ec_align1 ec_params_usb_pd_power_info {
4108 USB_CHG_TYPE_PROPRIETARY,
4109 USB_CHG_TYPE_BC12_DCP,
4110 USB_CHG_TYPE_BC12_CDP,
4111 USB_CHG_TYPE_BC12_SDP,
4114 USB_CHG_TYPE_UNKNOWN,
4116 enum usb_power_roles {
4117 USB_PD_PORT_POWER_DISCONNECTED,
4118 USB_PD_PORT_POWER_SOURCE,
4119 USB_PD_PORT_POWER_SINK,
4120 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4123 struct __ec_align2 usb_chg_measures {
4124 uint16_t voltage_max;
4125 uint16_t voltage_now;
4126 uint16_t current_max;
4127 uint16_t current_lim;
4130 struct __ec_align4 ec_response_usb_pd_power_info {
4135 struct usb_chg_measures meas;
4139 /* Write USB-PD device FW */
4140 #define EC_CMD_USB_PD_FW_UPDATE 0x0110
4142 enum usb_pd_fw_update_cmds {
4144 USB_PD_FW_FLASH_ERASE,
4145 USB_PD_FW_FLASH_WRITE,
4146 USB_PD_FW_ERASE_SIG,
4149 struct __ec_align4 ec_params_usb_pd_fw_update {
4153 uint32_t size; /* Size to write in bytes */
4154 /* Followed by data to write */
4157 /* Write USB-PD Accessory RW_HASH table entry */
4158 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4159 /* RW hash is first 20 bytes of SHA-256 of RW section */
4160 #define PD_RW_HASH_SIZE 20
4161 struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
4163 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4164 uint8_t reserved; /* For alignment of current_image
4165 * TODO(rspangler) but it's not aligned!
4166 * Should have been reserved[2]. */
4167 uint32_t current_image; /* One of ec_current_image */
4170 /* Read USB-PD Accessory info */
4171 #define EC_CMD_USB_PD_DEV_INFO 0x0112
4173 struct __ec_align1 ec_params_usb_pd_info_request {
4177 /* Read USB-PD Device discovery info */
4178 #define EC_CMD_USB_PD_DISCOVERY 0x0113
4179 struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
4180 uint16_t vid; /* USB-IF VID */
4181 uint16_t pid; /* USB-IF PID */
4182 uint8_t ptype; /* product type (hub,periph,cable,ama) */
4185 /* Override default charge behavior */
4186 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
4188 /* Negative port parameters have special meaning */
4189 enum usb_pd_override_ports {
4190 OVERRIDE_DONT_CHARGE = -2,
4192 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4195 struct __ec_align2 ec_params_charge_port_override {
4196 int16_t override_port; /* Override port# */
4199 /* Read (and delete) one entry of PD event log */
4200 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4202 struct __ec_align4 ec_response_pd_log {
4203 uint32_t timestamp; /* relative timestamp in milliseconds */
4204 uint8_t type; /* event type : see PD_EVENT_xx below */
4205 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4206 uint16_t data; /* type-defined data payload */
4207 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
4211 /* The timestamp is the microsecond counter shifted to get about a ms. */
4212 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4214 #define PD_LOG_SIZE_MASK 0x1f
4215 #define PD_LOG_PORT_MASK 0xe0
4216 #define PD_LOG_PORT_SHIFT 5
4217 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4218 ((size) & PD_LOG_SIZE_MASK))
4219 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4220 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4222 /* PD event log : entry types */
4224 #define PD_EVENT_MCU_BASE 0x00
4225 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4226 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4227 /* Reserved for custom board event */
4228 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4229 /* PD generic accessory events */
4230 #define PD_EVENT_ACC_BASE 0x20
4231 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4232 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4233 /* PD power supply events */
4234 #define PD_EVENT_PS_BASE 0x40
4235 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4236 /* PD video dongles events */
4237 #define PD_EVENT_VIDEO_BASE 0x60
4238 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4239 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4240 /* Returned in the "type" field, when there is no entry available */
4241 #define PD_EVENT_NO_ENTRY 0xff
4244 * PD_EVENT_MCU_CHARGE event definition :
4245 * the payload is "struct usb_chg_measures"
4246 * the data field contains the port state flags as defined below :
4248 /* Port partner is a dual role device */
4249 #define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4250 /* Port is the pending override port */
4251 #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4252 /* Port is the override port */
4253 #define CHARGE_FLAGS_OVERRIDE (1 << 13)
4255 #define CHARGE_FLAGS_TYPE_SHIFT 3
4256 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4257 /* Power delivery role */
4258 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4261 * PD_EVENT_PS_FAULT data field flags definition :
4263 #define PS_FAULT_OCP 1
4264 #define PS_FAULT_FAST_OCP 2
4265 #define PS_FAULT_OVP 3
4266 #define PS_FAULT_DISCH 4
4269 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4271 struct __ec_align4 mcdp_version {
4277 struct __ec_align4 mcdp_info {
4280 struct mcdp_version irom;
4281 struct mcdp_version fw;
4284 /* struct mcdp_info field decoding */
4285 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4286 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4288 /* Get/Set USB-PD Alternate mode info */
4289 #define EC_CMD_USB_PD_GET_AMODE 0x0116
4290 struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
4291 uint16_t svid_idx; /* SVID index to get */
4292 uint8_t port; /* port */
4295 struct __ec_align4 ec_params_usb_pd_get_mode_response {
4296 uint16_t svid; /* SVID */
4297 uint16_t opos; /* Object Position */
4298 uint32_t vdo[6]; /* Mode VDOs */
4301 #define EC_CMD_USB_PD_SET_AMODE 0x0117
4306 /* Not a command. Do NOT remove. */
4310 struct __ec_align4 ec_params_usb_pd_set_mode_request {
4311 uint32_t cmd; /* enum pd_mode_cmd */
4312 uint16_t svid; /* SVID to set */
4313 uint8_t opos; /* Object Position */
4314 uint8_t port; /* port */
4317 /* Ask the PD MCU to record a log of a requested type */
4318 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
4320 struct __ec_align1 ec_params_pd_write_log_entry {
4321 uint8_t type; /* event type : see PD_EVENT_xx above */
4322 uint8_t port; /* port#, or 0 for events unrelated to a given port */
4326 /* Control USB-PD chip */
4327 #define EC_CMD_PD_CONTROL 0x0119
4329 enum ec_pd_control_cmd {
4330 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4331 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4332 PD_RESET, /* Force reset the PD chip */
4333 PD_CONTROL_DISABLE /* Disable further calls to this command */
4336 struct __ec_align1 ec_params_pd_control {
4337 uint8_t chip; /* chip id (should be 0) */
4341 /* Get info about USB-C SS muxes */
4342 #define EC_CMD_USB_PD_MUX_INFO 0x011A
4344 struct __ec_align1 ec_params_usb_pd_mux_info {
4345 uint8_t port; /* USB-C port number */
4348 /* Flags representing mux state */
4349 #define USB_PD_MUX_USB_ENABLED (1 << 0)
4350 #define USB_PD_MUX_DP_ENABLED (1 << 1)
4351 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4352 #define USB_PD_MUX_HPD_IRQ (1 << 3)
4354 struct __ec_align1 ec_response_usb_pd_mux_info {
4355 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4358 #define EC_CMD_PD_CHIP_INFO 0x011B
4360 struct __ec_align1 ec_params_pd_chip_info {
4361 uint8_t port; /* USB-C port number */
4362 uint8_t renew; /* Force renewal */
4365 struct __ec_align2 ec_response_pd_chip_info {
4367 uint16_t product_id;
4370 uint8_t fw_version_string[8];
4371 uint64_t fw_version_number;
4375 /* Run RW signature verification and get status */
4376 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4378 struct __ec_align4 ec_response_rwsig_check_status {
4382 /* For controlling RWSIG task */
4383 #define EC_CMD_RWSIG_ACTION 0x011D
4386 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4387 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4390 struct __ec_align4 ec_params_rwsig_action {
4394 /* Run verification on a slot */
4395 #define EC_CMD_EFS_VERIFY 0x011E
4397 struct __ec_align1 ec_params_efs_verify {
4398 uint8_t region; /* enum ec_flash_region */
4402 * Retrieve info from Cros Board Info store. Response is based on the data
4403 * type. Integers return a uint32. Strings return a string, using the response
4404 * size to determine how big it is.
4406 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
4408 * Write info into Cros Board Info on EEPROM. Write fails if the board has
4409 * hardware write-protect enabled.
4411 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
4414 CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
4415 CBI_TAG_OEM_ID = 1, /* uint8_t */
4416 CBI_TAG_SKU_ID = 2, /* uint8_t */
4421 * Flags to control read operation
4423 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
4424 * write was successful without reboot.
4426 #define CBI_GET_RELOAD (1 << 0)
4428 struct __ec_align4 ec_params_get_cbi {
4429 uint32_t type; /* enum cbi_data_tag */
4430 uint32_t flag; /* CBI_GET_* */
4434 * Flags to control write behavior.
4436 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
4437 * useful when writing multiple fields in a row.
4438 * INIT: Needs to be set when creating a new CBI from scratch. All fields
4439 * will be initialized to zero first.
4441 #define CBI_SET_NO_SYNC (1 << 0)
4442 #define CBI_SET_INIT (1 << 1)
4444 struct __ec_align1 ec_params_set_cbi {
4445 uint32_t tag; /* enum cbi_data_tag */
4446 uint32_t flag; /* CBI_SET_* */
4447 uint32_t size; /* Data size */
4448 uint8_t data[]; /* For string and raw data */
4451 /*****************************************************************************/
4452 /* The command range 0x200-0x2FF is reserved for Rotor. */
4454 /*****************************************************************************/
4456 * Reserve a range of host commands for the CR51 firmware.
4458 #define EC_CMD_CR51_BASE 0x0300
4459 #define EC_CMD_CR51_LAST 0x03FF
4461 /*****************************************************************************/
4462 /* Fingerprint MCU commands: range 0x0400-0x040x */
4464 /* Fingerprint SPI sensor passthru command: prototyping ONLY */
4465 #define EC_CMD_FP_PASSTHRU 0x0400
4467 #define EC_FP_FLAG_NOT_COMPLETE 0x1
4469 struct __ec_align2 ec_params_fp_passthru {
4470 uint16_t len; /* Number of bytes to write then read */
4471 uint16_t flags; /* EC_FP_FLAG_xxx */
4472 uint8_t data[]; /* Data to send */
4475 /* Fingerprint sensor configuration command: prototyping ONLY */
4476 #define EC_CMD_FP_SENSOR_CONFIG 0x0401
4478 #define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4480 struct __ec_align2 ec_params_fp_sensor_config {
4481 uint8_t count; /* Number of setup registers */
4483 * the value to send to each of the 'count' setup registers
4484 * is stored in the 'data' array for 'len' bytes just after
4487 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4491 /* Configure the Fingerprint MCU behavior */
4492 #define EC_CMD_FP_MODE 0x0402
4494 /* Put the sensor in its lowest power mode */
4495 #define FP_MODE_DEEPSLEEP (1<<0)
4496 /* Wait to see a finger on the sensor */
4497 #define FP_MODE_FINGER_DOWN (1<<1)
4498 /* Poll until the finger has left the sensor */
4499 #define FP_MODE_FINGER_UP (1<<2)
4500 /* Capture the current finger image */
4501 #define FP_MODE_CAPTURE (1<<3)
4502 /* special value: don't change anything just read back current mode */
4503 #define FP_MODE_DONT_CHANGE (1<<31)
4505 struct __ec_align4 ec_params_fp_mode {
4506 uint32_t mode; /* as defined by FP_MODE_ constants */
4510 struct __ec_align4 ec_response_fp_mode {
4511 uint32_t mode; /* as defined by FP_MODE_ constants */
4515 /* Retrieve Fingerprint sensor information */
4516 #define EC_CMD_FP_INFO 0x0403
4518 struct __ec_align2 ec_response_fp_info {
4519 /* Sensor identification */
4521 uint32_t product_id;
4524 /* Image frame characteristics */
4525 uint32_t frame_size;
4526 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4532 /* Get the last captured finger frame: TODO: will be AES-encrypted */
4533 #define EC_CMD_FP_FRAME 0x0404
4535 struct __ec_align4 ec_params_fp_frame {
4540 /*****************************************************************************/
4541 /* Touchpad MCU commands: range 0x0500-0x05FF */
4543 /* Perform touchpad self test */
4544 #define EC_CMD_TP_SELF_TEST 0x0500
4546 /* Get number of frame types, and the size of each type */
4547 #define EC_CMD_TP_FRAME_INFO 0x0501
4549 struct __ec_align4 ec_response_tp_frame_info {
4551 uint32_t frame_sizes[0];
4554 /* Create a snapshot of current frame readings */
4555 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4557 /* Read the frame */
4558 #define EC_CMD_TP_FRAME_GET 0x0503
4560 struct __ec_align4 ec_params_tp_frame_get {
4561 uint32_t frame_index;
4566 /*****************************************************************************/
4568 * Reserve a range of host commands for board-specific, experimental, or
4569 * special purpose features. These can be (re)used without updating this file.
4571 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4572 * their EC commands for easier development, testing, debugging, and support.
4574 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4575 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4577 * In your experimental code, you may want to do something like this:
4579 * #define EC_CMD_MAGIC_FOO 0x0000
4580 * #define EC_CMD_MAGIC_BAR 0x0001
4581 * #define EC_CMD_MAGIC_HEY 0x0002
4583 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4586 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4589 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4592 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4593 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4596 * Given the private host command offset, calculate the true private host
4599 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4600 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4602 /*****************************************************************************/
4606 * Some platforms have sub-processors chained to each other. For example.
4608 * AP <--> EC <--> PD MCU
4610 * The top 2 bits of the command number are used to indicate which device the
4611 * command is intended for. Device 0 is always the device receiving the
4612 * command; other device mapping is board-specific.
4614 * When a device receives a command to be passed to a sub-processor, it passes
4615 * it on with the device number set back to 0. This allows the sub-processor
4616 * to remain blissfully unaware of whether the command originated on the next
4617 * device up the chain, or was passed through from the AP.
4619 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4620 * AP sends command 0x4002 to the EC
4621 * EC sends command 0x0002 to the PD MCU
4622 * EC forwards PD MCU response back to the AP
4625 /* Offset and max command number for sub-device n */
4626 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4627 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4629 /*****************************************************************************/
4631 * Deprecated constants. These constants have been renamed for clarity. The
4632 * meaning and size has not changed. Programs that use the old names should
4633 * switch to the new names soon, as the old names may not be carried forward
4636 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4637 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4638 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4640 #endif /* !__ACPI__ && !__KERNEL__ */
4642 #endif /* __CROS_EC_COMMANDS_H */