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
349 * This header file is used in coreboot both in C and ACPI code. The ACPI code
350 * is pre-processed to handle constants but the ASL compiler is unable to
351 * handle actual C code so keep it separate.
356 * Define __packed if someone hasn't beat us to it. Linux kernel style
357 * checking prefers __packed over __attribute__((packed)).
360 #define __packed __attribute__((packed))
364 #define __aligned(x) __attribute__((aligned(x)))
368 * Attributes for EC request and response packets. Just defining __packed
369 * results in inefficient assembly code on ARM, if the structure is actually
370 * 32-bit aligned, as it should be for all buffers.
372 * Be very careful when adding these to existing structures. They will round
373 * up the structure size to the specified boundary.
375 * Also be very careful to make that if a structure is included in some other
376 * parent structure that the alignment will still be true given the packing of
377 * the parent structure. This is particularly important if the sub-structure
378 * will be passed as a pointer to another function, since that function will
379 * not know about the misaligment caused by the parent structure's packing.
381 * Also be very careful using __packed - particularly when nesting non-packed
382 * structures inside packed ones. In fact, DO NOT use __packed directly;
383 * always use one of these attributes.
385 * Once everything is annotated properly, the following search strings should
386 * not return ANY matches in this file other than right here:
388 * "__packed" - generates inefficient code; all sub-structs must also be packed
390 * "struct [^_]" - all structs should be annotated, except for structs that are
391 * members of other structs/unions (and their original declarations should be
394 #ifdef CONFIG_HOSTCMD_ALIGNED
397 * Packed structures where offset and size are always aligned to 1, 2, or 4
400 #define __ec_align1 __packed
401 #define __ec_align2 __packed __aligned(2)
402 #define __ec_align4 __packed __aligned(4)
405 * Packed structure which must be under-aligned, because its size is not a
406 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
407 * of all multi-byte fields in it, even though they are themselves aligned.
409 * In theory, we could duplicate the structure with __aligned(4) for accessing
410 * its members, but use the __packed version for sizeof().
412 #define __ec_align_size1 __packed
415 * Packed structure which must be under-aligned, because its offset inside a
416 * parent structure is not a 4-byte multiple.
418 #define __ec_align_offset1 __packed
419 #define __ec_align_offset2 __packed __aligned(2)
422 * Structures which are complicated enough that I'm skipping them on the first
423 * pass. They are effectively unchanged from their previous definitions.
425 * TODO(rspangler): Figure out what to do with these. It's likely necessary
426 * to work out the size and offset of each member and add explicit padding to
429 #define __ec_todo_packed __packed
430 #define __ec_todo_unpacked
432 #else /* !CONFIG_HOSTCMD_ALIGNED */
435 * Packed structures make no assumption about alignment, so they do inefficient
438 #define __ec_align1 __packed
439 #define __ec_align2 __packed
440 #define __ec_align4 __packed
441 #define __ec_align_size1 __packed
442 #define __ec_align_offset1 __packed
443 #define __ec_align_offset2 __packed
444 #define __ec_todo_packed __packed
445 #define __ec_todo_unpacked
447 #endif /* !CONFIG_HOSTCMD_ALIGNED */
449 /* LPC command status byte masks */
450 /* EC has written a byte in the data register and host hasn't read it yet */
451 #define EC_LPC_STATUS_TO_HOST 0x01
452 /* Host has written a command/data byte and the EC hasn't read it yet */
453 #define EC_LPC_STATUS_FROM_HOST 0x02
454 /* EC is processing a command */
455 #define EC_LPC_STATUS_PROCESSING 0x04
456 /* Last write to EC was a command, not data */
457 #define EC_LPC_STATUS_LAST_CMD 0x08
458 /* EC is in burst mode */
459 #define EC_LPC_STATUS_BURST_MODE 0x10
460 /* SCI event is pending (requesting SCI query) */
461 #define EC_LPC_STATUS_SCI_PENDING 0x20
462 /* SMI event is pending (requesting SMI query) */
463 #define EC_LPC_STATUS_SMI_PENDING 0x40
465 #define EC_LPC_STATUS_RESERVED 0x80
468 * EC is busy. This covers both the EC processing a command, and the host has
469 * written a new command but the EC hasn't picked it up yet.
471 #define EC_LPC_STATUS_BUSY_MASK \
472 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
474 /* Host command response codes (16-bit). Note that response codes should be
475 * stored in a uint16_t rather than directly in a value of this type.
479 EC_RES_INVALID_COMMAND = 1,
481 EC_RES_INVALID_PARAM = 3,
482 EC_RES_ACCESS_DENIED = 4,
483 EC_RES_INVALID_RESPONSE = 5,
484 EC_RES_INVALID_VERSION = 6,
485 EC_RES_INVALID_CHECKSUM = 7,
486 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
487 EC_RES_UNAVAILABLE = 9, /* No response available */
488 EC_RES_TIMEOUT = 10, /* We got a timeout */
489 EC_RES_OVERFLOW = 11, /* Table / data overflow */
490 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
491 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
492 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
493 EC_RES_BUS_ERROR = 15, /* Communications bus error */
494 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
498 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
499 * EC command uses code 0 to mean "no event pending". We explicitly specify
500 * each value in the enum listing so they won't change if we delete/insert an
501 * item or rearrange the list (it needs to be stable across platforms, not
502 * just within a single compiled instance).
504 enum host_event_code {
505 EC_HOST_EVENT_LID_CLOSED = 1,
506 EC_HOST_EVENT_LID_OPEN = 2,
507 EC_HOST_EVENT_POWER_BUTTON = 3,
508 EC_HOST_EVENT_AC_CONNECTED = 4,
509 EC_HOST_EVENT_AC_DISCONNECTED = 5,
510 EC_HOST_EVENT_BATTERY_LOW = 6,
511 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
512 EC_HOST_EVENT_BATTERY = 8,
513 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
514 /* Event generated by a device attached to the EC */
515 EC_HOST_EVENT_DEVICE = 10,
516 EC_HOST_EVENT_THERMAL = 11,
517 EC_HOST_EVENT_USB_CHARGER = 12,
518 EC_HOST_EVENT_KEY_PRESSED = 13,
520 * EC has finished initializing the host interface. The host can check
521 * for this event following sending a EC_CMD_REBOOT_EC command to
522 * determine when the EC is ready to accept subsequent commands.
524 EC_HOST_EVENT_INTERFACE_READY = 14,
525 /* Keyboard recovery combo has been pressed */
526 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
528 /* Shutdown due to thermal overload */
529 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
530 /* Shutdown due to battery level too low */
531 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
533 /* Suggest that the AP throttle itself */
534 EC_HOST_EVENT_THROTTLE_START = 18,
535 /* Suggest that the AP resume normal speed */
536 EC_HOST_EVENT_THROTTLE_STOP = 19,
538 /* Hang detect logic detected a hang and host event timeout expired */
539 EC_HOST_EVENT_HANG_DETECT = 20,
540 /* Hang detect logic detected a hang and warm rebooted the AP */
541 EC_HOST_EVENT_HANG_REBOOT = 21,
543 /* PD MCU triggering host event */
544 EC_HOST_EVENT_PD_MCU = 22,
546 /* Battery Status flags have changed */
547 EC_HOST_EVENT_BATTERY_STATUS = 23,
549 /* EC encountered a panic, triggering a reset */
550 EC_HOST_EVENT_PANIC = 24,
552 /* Keyboard fastboot combo has been pressed */
553 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
555 /* EC RTC event occurred */
556 EC_HOST_EVENT_RTC = 26,
558 /* Emulate MKBP event */
559 EC_HOST_EVENT_MKBP = 27,
561 /* EC desires to change state of host-controlled USB mux */
562 EC_HOST_EVENT_USB_MUX = 28,
564 /* TABLET/LAPTOP mode event*/
565 EC_HOST_EVENT_MODE_CHANGE = 29,
567 /* Keyboard recovery combo with hardware reinitialization */
568 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
571 * Reserve this last bit to indicate that at least one bit in a
572 * secondary host event word is set. See crbug.com/633646.
574 EC_HOST_EVENT_EXTENDED = 31,
577 * The high bit of the event mask is not used as a host event code. If
578 * it reads back as set, then the entire event mask should be
579 * considered invalid by the host. This can happen when reading the
580 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
581 * not initialized on the EC, or improperly configured on the host.
583 EC_HOST_EVENT_INVALID = 32
585 /* Host event mask */
586 #define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
588 /* Arguments at EC_LPC_ADDR_HOST_ARGS */
589 struct __ec_align4 ec_lpc_host_args {
591 uint8_t command_version;
594 * Checksum; sum of command + flags + command_version + data_size +
595 * all params/response data bytes.
600 /* Flags for ec_lpc_host_args.flags */
602 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
605 * If EC gets a command and this flag is not set, this is an old-style command.
606 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
607 * unknown length. EC must respond with an old-style response (that is,
608 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
610 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
612 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
614 * If EC responds to a command and this flag is not set, this is an old-style
615 * response. Command version is 0 and response data from EC is at
616 * EC_LPC_ADDR_OLD_PARAM with unknown length.
618 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
620 /*****************************************************************************/
622 * Byte codes returned by EC over SPI interface.
624 * These can be used by the AP to debug the EC interface, and to determine
625 * when the EC is not in a state where it will ever get around to responding
628 * Example of sequence of bytes read from EC for a current good transfer:
629 * 1. - - AP asserts chip select (CS#)
630 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
631 * 3. - - EC starts handling CS# interrupt
632 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
633 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
634 * bytes looking for EC_SPI_FRAME_START
635 * 6. - - EC finishes processing and sets up response
636 * 7. EC_SPI_FRAME_START - AP reads frame byte
637 * 8. (response packet) - AP reads response packet
638 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
639 * 10 - - AP deasserts chip select
640 * 11 - - EC processes CS# interrupt and sets up DMA for
643 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
644 * the following byte values:
650 * Then the EC found an error in the request, or was not ready for the request
651 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
652 * because the EC is unable to tell when the AP is done sending its request.
656 * Framing byte which precedes a response packet from the EC. After sending a
657 * request, the AP will clock in bytes until it sees the framing byte, then
658 * clock in the response packet.
660 #define EC_SPI_FRAME_START 0xec
663 * Padding bytes which are clocked out after the end of a response packet.
665 #define EC_SPI_PAST_END 0xed
668 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
669 * that the AP will send a valid packet header (starting with
670 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
672 #define EC_SPI_RX_READY 0xf8
675 * EC has started receiving the request from the AP, but hasn't started
678 #define EC_SPI_RECEIVING 0xf9
680 /* EC has received the entire request from the AP and is processing it. */
681 #define EC_SPI_PROCESSING 0xfa
684 * EC received bad data from the AP, such as a packet header with an invalid
685 * length. EC will ignore all data until chip select deasserts.
687 #define EC_SPI_RX_BAD_DATA 0xfb
690 * EC received data from the AP before it was ready. That is, the AP asserted
691 * chip select and started clocking data before the EC was ready to receive it.
692 * EC will ignore all data until chip select deasserts.
694 #define EC_SPI_NOT_READY 0xfc
697 * EC was ready to receive a request from the AP. EC has treated the byte sent
698 * by the AP as part of a request packet, or (for old-style ECs) is processing
699 * a fully received packet but is not ready to respond yet.
701 #define EC_SPI_OLD_READY 0xfd
703 /*****************************************************************************/
706 * Protocol version 2 for I2C and SPI send a request this way:
708 * 0 EC_CMD_VERSION0 + (command version)
710 * 2 Length of params = N
711 * 3..N+2 Params, if any
712 * N+3 8-bit checksum of bytes 0..N+2
714 * The corresponding response is:
716 * 0 Result code (EC_RES_*)
717 * 1 Length of params = M
718 * 2..M+1 Params, if any
719 * M+2 8-bit checksum of bytes 0..M+1
721 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
722 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
723 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
724 EC_PROTO2_REQUEST_TRAILER_BYTES)
726 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
727 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
728 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
729 EC_PROTO2_RESPONSE_TRAILER_BYTES)
731 /* Parameter length was limited by the LPC interface */
732 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
734 /* Maximum request and response packet sizes for protocol version 2 */
735 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
736 EC_PROTO2_MAX_PARAM_SIZE)
737 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
738 EC_PROTO2_MAX_PARAM_SIZE)
740 /*****************************************************************************/
743 * Value written to legacy command port / prefix byte to indicate protocol
744 * 3+ structs are being used. Usage is bus-dependent.
746 #define EC_COMMAND_PROTOCOL_3 0xda
748 #define EC_HOST_REQUEST_VERSION 3
750 /* Version 3 request from host */
751 struct __ec_align4 ec_host_request {
752 /* Structure version (=3)
754 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
755 * version it doesn't know how to parse.
757 uint8_t struct_version;
760 * Checksum of request and data; sum of all bytes including checksum
768 /* Command version */
769 uint8_t command_version;
771 /* Unused byte in current protocol version; set to 0 */
774 /* Length of data which follows this header */
778 #define EC_HOST_RESPONSE_VERSION 3
780 /* Version 3 response from EC */
781 struct __ec_align4 ec_host_response {
782 /* Structure version (=3) */
783 uint8_t struct_version;
786 * Checksum of response and data; sum of all bytes including checksum
791 /* Result code (EC_RES_*) */
794 /* Length of data which follows this header */
797 /* Unused bytes in current protocol version; set to 0 */
801 /*****************************************************************************/
805 * Each command is an 16-bit command value. Commands which take params or
806 * return response data specify structures for that data. If no structure is
807 * specified, the command does not input or output data, respectively.
808 * Parameter/response length is implicit in the structs. Some underlying
809 * communication protocols (I2C, SPI) may add length or checksum headers, but
810 * those are implementation-dependent and not defined here.
812 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
813 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
816 /*****************************************************************************/
817 /* General / test commands */
820 * Get protocol version, used to deal with non-backward compatible protocol
823 #define EC_CMD_PROTO_VERSION 0x0000
825 struct __ec_align4 ec_response_proto_version {
830 * Hello. This is a simple command to test the EC is responsive to
833 #define EC_CMD_HELLO 0x0001
835 struct __ec_align4 ec_params_hello {
836 uint32_t in_data; /* Pass anything here */
839 struct __ec_align4 ec_response_hello {
840 uint32_t out_data; /* Output will be in_data + 0x01020304 */
843 /* Get version number */
844 #define EC_CMD_GET_VERSION 0x0002
846 enum ec_current_image {
847 EC_IMAGE_UNKNOWN = 0,
852 struct __ec_align4 ec_response_get_version {
853 /* Null-terminated version strings for RO, RW */
854 char version_string_ro[32];
855 char version_string_rw[32];
856 char reserved[32]; /* Was previously RW-B string */
857 uint32_t current_image; /* One of ec_current_image */
861 #define EC_CMD_READ_TEST 0x0003
863 struct __ec_align4 ec_params_read_test {
864 uint32_t offset; /* Starting value for read buffer */
865 uint32_t size; /* Size to read in bytes */
868 struct __ec_align4 ec_response_read_test {
873 * Get build information
875 * Response is null-terminated string.
877 #define EC_CMD_GET_BUILD_INFO 0x0004
880 #define EC_CMD_GET_CHIP_INFO 0x0005
882 struct __ec_align4 ec_response_get_chip_info {
883 /* Null-terminated strings */
886 char revision[32]; /* Mask version */
889 /* Get board HW version */
890 #define EC_CMD_GET_BOARD_VERSION 0x0006
892 struct __ec_align2 ec_response_board_version {
893 uint16_t board_version; /* A monotonously incrementing number. */
897 * Read memory-mapped data.
899 * This is an alternate interface to memory-mapped data for bus protocols
900 * which don't support direct-mapped memory - I2C, SPI, etc.
902 * Response is params.size bytes of data.
904 #define EC_CMD_READ_MEMMAP 0x0007
906 struct __ec_align1 ec_params_read_memmap {
907 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
908 uint8_t size; /* Size to read in bytes */
911 /* Read versions supported for a command */
912 #define EC_CMD_GET_CMD_VERSIONS 0x0008
914 struct __ec_align1 ec_params_get_cmd_versions {
915 uint8_t cmd; /* Command to check */
918 struct __ec_align2 ec_params_get_cmd_versions_v1 {
919 uint16_t cmd; /* Command to check */
922 struct __ec_align4 ec_response_get_cmd_versions {
924 * Mask of supported versions; use EC_VER_MASK() to compare with a
927 uint32_t version_mask;
931 * Check EC communications status (busy). This is needed on i2c/spi but not
932 * on lpc since it has its own out-of-band busy indicator.
934 * lpc must read the status from the command register. Attempting this on
935 * lpc will overwrite the args/parameter space and corrupt its data.
937 #define EC_CMD_GET_COMMS_STATUS 0x0009
939 /* Avoid using ec_status which is for return values */
940 enum ec_comms_status {
941 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
944 struct __ec_align4 ec_response_get_comms_status {
945 uint32_t flags; /* Mask of enum ec_comms_status */
948 /* Fake a variety of responses, purely for testing purposes. */
949 #define EC_CMD_TEST_PROTOCOL 0x000A
951 /* Tell the EC what to send back to us. */
952 struct __ec_align4 ec_params_test_protocol {
958 /* Here it comes... */
959 struct __ec_align4 ec_response_test_protocol {
963 /* Get protocol information */
964 #define EC_CMD_GET_PROTOCOL_INFO 0x000B
966 /* Flags for ec_response_get_protocol_info.flags */
967 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
968 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
970 struct __ec_align4 ec_response_get_protocol_info {
971 /* Fields which exist if at least protocol version 3 supported */
973 /* Bitmask of protocol versions supported (1 << n means version n)*/
974 uint32_t protocol_versions;
976 /* Maximum request packet size, in bytes */
977 uint16_t max_request_packet_size;
979 /* Maximum response packet size, in bytes */
980 uint16_t max_response_packet_size;
982 /* Flags; see EC_PROTOCOL_INFO_* */
986 /*****************************************************************************/
987 /* Get/Set miscellaneous values */
989 /* The upper byte of .flags tells what to do (nothing means "get") */
990 #define EC_GSV_SET 0x80000000
992 /* The lower three bytes of .flags identifies the parameter, if that has
993 meaning for an individual command. */
994 #define EC_GSV_PARAM_MASK 0x00ffffff
996 struct __ec_align4 ec_params_get_set_value {
1001 struct __ec_align4 ec_response_get_set_value {
1006 /* More than one command can use these structs to get/set parameters. */
1007 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
1009 /*****************************************************************************/
1010 /* List the features supported by the firmware */
1011 #define EC_CMD_GET_FEATURES 0x000D
1013 /* Supported features */
1014 enum ec_feature_code {
1016 * This image contains a limited set of features. Another image
1017 * in RW partition may support more features.
1019 EC_FEATURE_LIMITED = 0,
1021 * Commands for probing/reading/writing/erasing the flash in the
1024 EC_FEATURE_FLASH = 1,
1026 * Can control the fan speed directly.
1028 EC_FEATURE_PWM_FAN = 2,
1030 * Can control the intensity of the keyboard backlight.
1032 EC_FEATURE_PWM_KEYB = 3,
1034 * Support Google lightbar, introduced on Pixel.
1036 EC_FEATURE_LIGHTBAR = 4,
1037 /* Control of LEDs */
1039 /* Exposes an interface to control gyro and sensors.
1040 * The host goes through the EC to access these sensors.
1041 * In addition, the EC may provide composite sensors, like lid angle.
1043 EC_FEATURE_MOTION_SENSE = 6,
1044 /* The keyboard is controlled by the EC */
1045 EC_FEATURE_KEYB = 7,
1046 /* The AP can use part of the EC flash as persistent storage. */
1047 EC_FEATURE_PSTORE = 8,
1048 /* The EC monitors BIOS port 80h, and can return POST codes. */
1049 EC_FEATURE_PORT80 = 9,
1051 * Thermal management: include TMP specific commands.
1052 * Higher level than direct fan control.
1054 EC_FEATURE_THERMAL = 10,
1055 /* Can switch the screen backlight on/off */
1056 EC_FEATURE_BKLIGHT_SWITCH = 11,
1057 /* Can switch the wifi module on/off */
1058 EC_FEATURE_WIFI_SWITCH = 12,
1059 /* Monitor host events, through for example SMI or SCI */
1060 EC_FEATURE_HOST_EVENTS = 13,
1061 /* The EC exposes GPIO commands to control/monitor connected devices. */
1062 EC_FEATURE_GPIO = 14,
1063 /* The EC can send i2c messages to downstream devices. */
1064 EC_FEATURE_I2C = 15,
1065 /* Command to control charger are included */
1066 EC_FEATURE_CHARGER = 16,
1067 /* Simple battery support. */
1068 EC_FEATURE_BATTERY = 17,
1070 * Support Smart battery protocol
1071 * (Common Smart Battery System Interface Specification)
1073 EC_FEATURE_SMART_BATTERY = 18,
1074 /* EC can detect when the host hangs. */
1075 EC_FEATURE_HANG_DETECT = 19,
1076 /* Report power information, for pit only */
1077 EC_FEATURE_PMU = 20,
1078 /* Another Cros EC device is present downstream of this one */
1079 EC_FEATURE_SUB_MCU = 21,
1080 /* Support USB Power delivery (PD) commands */
1081 EC_FEATURE_USB_PD = 22,
1082 /* Control USB multiplexer, for audio through USB port for instance. */
1083 EC_FEATURE_USB_MUX = 23,
1084 /* Motion Sensor code has an internal software FIFO */
1085 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1086 /* Support temporary secure vstore */
1087 EC_FEATURE_VSTORE = 25,
1088 /* EC decides on USB-C SS mux state, muxes configured by host */
1089 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1090 /* EC has RTC feature that can be controlled by host commands */
1091 EC_FEATURE_RTC = 27,
1092 /* The MCU exposes a Fingerprint sensor */
1093 EC_FEATURE_FINGERPRINT = 28,
1094 /* The MCU exposes a Touchpad */
1095 EC_FEATURE_TOUCHPAD = 29,
1096 /* The MCU has RWSIG task enabled */
1097 EC_FEATURE_RWSIG = 30,
1098 /* EC has device events support */
1099 EC_FEATURE_DEVICE_EVENT = 31,
1100 /* EC supports the unified wake masks for LPC/eSPI systems */
1101 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1102 /* EC supports 64-bit host events */
1103 EC_FEATURE_HOST_EVENT64 = 33,
1104 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1105 EC_FEATURE_EXEC_IN_RAM = 34,
1106 /* EC supports CEC commands */
1107 EC_FEATURE_CEC = 35,
1108 /* EC supports tight sensor timestamping. */
1109 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
1111 * EC supports tablet mode detection aligned to Chrome and allows
1112 * setting of threshold by host command using
1113 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1115 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
1117 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
1118 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1119 * be sent to RO to be precise.
1121 EC_FEATURE_EFS2 = 38,
1122 /* The MCU is a System Companion Processor (SCP). */
1123 EC_FEATURE_SCP = 39,
1124 /* The MCU is an Integrated Sensor Hub */
1125 EC_FEATURE_ISH = 40,
1126 /* New TCPMv2 TYPEC_ prefaced commands supported */
1127 EC_FEATURE_TYPEC_CMD = 41,
1129 * The EC will wait for direction from the AP to enter Type-C alternate
1132 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1134 * The EC will wait for an acknowledge from the AP after setting the
1137 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
1140 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1141 #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1143 struct ec_response_get_features {
1147 /*****************************************************************************/
1148 /* Get the board's SKU ID from EC */
1149 #define EC_CMD_GET_SKU_ID 0x000E
1151 /* Set SKU ID from AP */
1152 #define EC_CMD_SET_SKU_ID 0x000F
1154 struct __ec_align4 ec_sku_id_info {
1158 /*****************************************************************************/
1159 /* Flash commands */
1161 /* Get flash info */
1162 #define EC_CMD_FLASH_INFO 0x0010
1163 #define EC_VER_FLASH_INFO 2
1165 /* Version 0 returns these fields */
1166 struct __ec_align4 ec_response_flash_info {
1167 /* Usable flash size, in bytes */
1168 uint32_t flash_size;
1170 * Write block size. Write offset and size must be a multiple
1173 uint32_t write_block_size;
1175 * Erase block size. Erase offset and size must be a multiple
1178 uint32_t erase_block_size;
1180 * Protection block size. Protection offset and size must be a
1183 uint32_t protect_block_size;
1186 /* Flags for version 1+ flash info command */
1187 /* EC flash erases bits to 0 instead of 1 */
1188 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1190 /* Flash must be selected for read/write/erase operations to succeed. This may
1191 * be necessary on a chip where write/erase can be corrupted by other board
1192 * activity, or where the chip needs to enable some sort of programming voltage,
1193 * or where the read/write/erase operations require cleanly suspending other
1194 * chip functionality. */
1195 #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1198 * Version 1 returns the same initial fields as version 0, with additional
1201 * gcc anonymous structs don't seem to get along with the __packed directive;
1202 * if they did we'd define the version 0 structure as a sub-structure of this
1205 * Version 2 supports flash banks of different sizes:
1206 * The caller specified the number of banks it has preallocated
1208 * The EC returns the number of banks describing the flash memory.
1209 * It adds banks descriptions up to num_banks_desc.
1211 struct __ec_align4 ec_response_flash_info_1 {
1212 /* Version 0 fields; see above for description */
1213 uint32_t flash_size;
1214 uint32_t write_block_size;
1215 uint32_t erase_block_size;
1216 uint32_t protect_block_size;
1218 /* Version 1 adds these fields: */
1220 * Ideal write size in bytes. Writes will be fastest if size is
1221 * exactly this and offset is a multiple of this. For example, an EC
1222 * may have a write buffer which can do half-page operations if data is
1223 * aligned, and a slower word-at-a-time write mode.
1225 uint32_t write_ideal_size;
1227 /* Flags; see EC_FLASH_INFO_* */
1231 struct __ec_align4 ec_params_flash_info_2 {
1232 /* Number of banks to describe */
1233 uint16_t num_banks_desc;
1234 /* Reserved; set 0; ignore on read */
1235 uint8_t reserved[2];
1238 struct ec_flash_bank {
1239 /* Number of sector is in this bank. */
1241 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1243 /* Minimal write size for the sectors in this bank */
1244 uint8_t write_size_exp;
1245 /* Erase size for the sectors in this bank */
1246 uint8_t erase_size_exp;
1247 /* Size for write protection, usually identical to erase size. */
1248 uint8_t protect_size_exp;
1249 /* Reserved; set 0; ignore on read */
1250 uint8_t reserved[2];
1253 struct __ec_align4 ec_response_flash_info_2 {
1254 /* Total flash in the EC. */
1255 uint32_t flash_size;
1256 /* Flags; see EC_FLASH_INFO_* */
1258 /* Maximum size to use to send data to write to the EC. */
1259 uint32_t write_ideal_size;
1260 /* Number of banks present in the EC. */
1261 uint16_t num_banks_total;
1262 /* Number of banks described in banks array. */
1263 uint16_t num_banks_desc;
1264 struct ec_flash_bank banks[0];
1270 * Response is params.size bytes of data.
1272 #define EC_CMD_FLASH_READ 0x0011
1274 struct __ec_align4 ec_params_flash_read {
1275 uint32_t offset; /* Byte offset to read */
1276 uint32_t size; /* Size to read in bytes */
1280 #define EC_CMD_FLASH_WRITE 0x0012
1281 #define EC_VER_FLASH_WRITE 1
1283 /* Version 0 of the flash command supported only 64 bytes of data */
1284 #define EC_FLASH_WRITE_VER0_SIZE 64
1286 struct __ec_align4 ec_params_flash_write {
1287 uint32_t offset; /* Byte offset to write */
1288 uint32_t size; /* Size to write in bytes */
1289 /* Followed by data to write */
1293 #define EC_CMD_FLASH_ERASE 0x0013
1296 struct __ec_align4 ec_params_flash_erase {
1297 uint32_t offset; /* Byte offset to erase */
1298 uint32_t size; /* Size to erase in bytes */
1301 #define EC_VER_FLASH_WRITE 1
1302 /* v1 add async erase:
1303 * subcommands can returns:
1304 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1305 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1306 * EC_RES_ERROR : other errors.
1307 * EC_RES_BUSY : an existing erase operation is in progress.
1308 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1310 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1311 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1312 * the proper result.
1313 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1314 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1315 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1316 * permitted while erasing. (For instance, STM32F4).
1318 enum ec_flash_erase_cmd {
1319 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1320 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1321 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1324 struct __ec_align4 ec_params_flash_erase_v1 {
1325 /* One of ec_flash_erase_cmd. */
1327 /* Pad byte; currently always contains 0 */
1329 /* No flags defined yet; set to 0 */
1331 /* Same as v0 parameters. */
1332 struct ec_params_flash_erase params;
1336 * Get/set flash protection.
1338 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1339 * firmware write protect GPIO, not all flags will take effect immediately;
1340 * some flags require a subsequent hard reset to take effect. Check the
1341 * returned flags bits to see what actually happened.
1343 * If mask=0, simply returns the current flags state.
1345 #define EC_CMD_FLASH_PROTECT 0x0015
1346 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1348 /* Flags for flash protection */
1349 /* RO flash code protected when the EC boots */
1350 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1352 * RO flash code protected now. If this bit is set, at-boot status cannot
1355 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1356 /* Entire flash code protected now, until reboot. */
1357 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1358 /* Flash write protect GPIO is asserted now */
1359 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1360 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1361 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1363 * Error - flash protection is in inconsistent state. At least one bank of
1364 * flash which should be protected is not protected. Usually fixed by
1365 * re-requesting the desired flags, or by a hard reset if that fails.
1367 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1368 /* Entire flash code protected when the EC boots */
1369 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1370 /* RW flash code protected when the EC boots */
1371 #define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1372 /* RW flash code protected now. */
1373 #define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1374 /* Rollback information flash region protected when the EC boots */
1375 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1376 /* Rollback information flash region protected now */
1377 #define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
1379 struct __ec_align4 ec_params_flash_protect {
1380 uint32_t mask; /* Bits in flags to apply */
1381 uint32_t flags; /* New flags to apply */
1384 struct __ec_align4 ec_response_flash_protect {
1385 /* Current value of flash protect flags */
1388 * Flags which are valid on this platform. This allows the caller
1389 * to distinguish between flags which aren't set vs. flags which can't
1390 * be set on this platform.
1392 uint32_t valid_flags;
1393 /* Flags which can be changed given the current protection state */
1394 uint32_t writable_flags;
1398 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1399 * write protect. These commands may be reused with version > 0.
1402 /* Get the region offset/size */
1403 #define EC_CMD_FLASH_REGION_INFO 0x0016
1404 #define EC_VER_FLASH_REGION_INFO 1
1406 enum ec_flash_region {
1407 /* Region which holds read-only EC image */
1408 EC_FLASH_REGION_RO = 0,
1409 /* Region which holds active rewritable EC image */
1410 EC_FLASH_REGION_ACTIVE,
1412 * Region which should be write-protected in the factory (a superset of
1413 * EC_FLASH_REGION_RO)
1415 EC_FLASH_REGION_WP_RO,
1416 /* Region which holds updatable image */
1417 EC_FLASH_REGION_UPDATE,
1418 /* Number of regions */
1419 EC_FLASH_REGION_COUNT,
1422 struct __ec_align4 ec_params_flash_region_info {
1423 uint32_t region; /* enum ec_flash_region */
1426 struct __ec_align4 ec_response_flash_region_info {
1431 /* Read/write VbNvContext */
1432 #define EC_CMD_VBNV_CONTEXT 0x0017
1433 #define EC_VER_VBNV_CONTEXT 1
1434 #define EC_VBNV_BLOCK_SIZE 16
1435 #define EC_VBNV_BLOCK_SIZE_V2 64
1437 enum ec_vbnvcontext_op {
1438 EC_VBNV_CONTEXT_OP_READ,
1439 EC_VBNV_CONTEXT_OP_WRITE,
1442 struct __ec_align4 ec_params_vbnvcontext {
1444 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1447 struct __ec_align4 ec_response_vbnvcontext {
1448 uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
1451 /* Get SPI flash information */
1452 #define EC_CMD_FLASH_SPI_INFO 0x0018
1454 struct __ec_align1 ec_response_flash_spi_info {
1455 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1458 /* Pad byte; currently always contains 0 */
1461 /* Manufacturer / device ID from command 0x90 */
1462 uint8_t mfr_dev_id[2];
1464 /* Status registers from command 0x05 and 0x35 */
1468 /* Select flash during flash operations */
1469 #define EC_CMD_FLASH_SELECT 0x0019
1471 struct __ec_align4 ec_params_flash_select {
1472 /* 1 to select flash, 0 to deselect flash */
1476 /*****************************************************************************/
1479 /* Get fan target RPM */
1480 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1482 struct __ec_align4 ec_response_pwm_get_fan_rpm {
1486 /* Set target fan RPM */
1487 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1489 /* Version 0 of input params */
1490 struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
1494 /* Version 1 of input params */
1495 struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
1500 /* Get keyboard backlight */
1501 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1502 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1504 struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
1509 /* Set keyboard backlight */
1510 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1511 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1513 struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
1517 /* Set target fan PWM duty cycle */
1518 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1520 /* Version 0 of input params */
1521 struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
1525 /* Version 1 of input params */
1526 struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
1531 #define EC_CMD_PWM_SET_DUTY 0x0025
1532 /* 16 bit duty cycle, 0xffff = 100% */
1533 #define EC_PWM_MAX_DUTY 0xffff
1536 /* All types, indexed by board-specific enum pwm_channel */
1537 EC_PWM_TYPE_GENERIC = 0,
1538 /* Keyboard backlight */
1539 EC_PWM_TYPE_KB_LIGHT,
1540 /* Display backlight */
1541 EC_PWM_TYPE_DISPLAY_LIGHT,
1545 struct __ec_align4 ec_params_pwm_set_duty {
1546 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1547 uint8_t pwm_type; /* ec_pwm_type */
1548 uint8_t index; /* Type-specific index, or 0 if unique */
1551 #define EC_CMD_PWM_GET_DUTY 0x0026
1553 struct __ec_align1 ec_params_pwm_get_duty {
1554 uint8_t pwm_type; /* ec_pwm_type */
1555 uint8_t index; /* Type-specific index, or 0 if unique */
1558 struct __ec_align2 ec_response_pwm_get_duty {
1559 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1562 /*****************************************************************************/
1564 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1565 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1566 * into a subcommand. We'll make separate structs for subcommands with
1567 * different input args, so that we know how much to expect.
1569 #define EC_CMD_LIGHTBAR_CMD 0x0028
1571 struct __ec_todo_unpacked rgb_s {
1575 #define LB_BATTERY_LEVELS 4
1576 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1577 * host command, but the alignment is the same regardless. Keep it that way.
1579 struct __ec_todo_packed lightbar_params_v0 {
1581 int32_t google_ramp_up;
1582 int32_t google_ramp_down;
1583 int32_t s3s0_ramp_up;
1584 int32_t s0_tick_delay[2]; /* AC=0/1 */
1585 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1586 int32_t s0s3_ramp_down;
1587 int32_t s3_sleep_for;
1589 int32_t s3_ramp_down;
1593 uint8_t osc_min[2]; /* AC=0/1 */
1594 uint8_t osc_max[2]; /* AC=0/1 */
1595 uint8_t w_ofs[2]; /* AC=0/1 */
1597 /* Brightness limits based on the backlight and AC. */
1598 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1599 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1600 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1602 /* Battery level thresholds */
1603 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1605 /* Map [AC][battery_level] to color index */
1606 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1607 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1610 struct rgb_s color[8]; /* 0-3 are Google colors */
1613 struct __ec_todo_packed lightbar_params_v1 {
1615 int32_t google_ramp_up;
1616 int32_t google_ramp_down;
1617 int32_t s3s0_ramp_up;
1618 int32_t s0_tick_delay[2]; /* AC=0/1 */
1619 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1620 int32_t s0s3_ramp_down;
1621 int32_t s3_sleep_for;
1623 int32_t s3_ramp_down;
1625 int32_t s5_ramp_down;
1626 int32_t tap_tick_delay;
1627 int32_t tap_gate_delay;
1628 int32_t tap_display_time;
1630 /* Tap-for-battery params */
1631 uint8_t tap_pct_red;
1632 uint8_t tap_pct_green;
1633 uint8_t tap_seg_min_on;
1634 uint8_t tap_seg_max_on;
1635 uint8_t tap_seg_osc;
1639 uint8_t osc_min[2]; /* AC=0/1 */
1640 uint8_t osc_max[2]; /* AC=0/1 */
1641 uint8_t w_ofs[2]; /* AC=0/1 */
1643 /* Brightness limits based on the backlight and AC. */
1644 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1645 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1646 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1648 /* Battery level thresholds */
1649 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1651 /* Map [AC][battery_level] to color index */
1652 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1653 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1655 /* s5: single color pulse on inhibited power-up */
1659 struct rgb_s color[8]; /* 0-3 are Google colors */
1662 /* Lightbar command params v2
1665 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1666 * logical groups to make it more manageable ( < 120 bytes).
1668 * NOTE: Each of these groups must be less than 120 bytes.
1671 struct __ec_todo_packed lightbar_params_v2_timing {
1673 int32_t google_ramp_up;
1674 int32_t google_ramp_down;
1675 int32_t s3s0_ramp_up;
1676 int32_t s0_tick_delay[2]; /* AC=0/1 */
1677 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1678 int32_t s0s3_ramp_down;
1679 int32_t s3_sleep_for;
1681 int32_t s3_ramp_down;
1683 int32_t s5_ramp_down;
1684 int32_t tap_tick_delay;
1685 int32_t tap_gate_delay;
1686 int32_t tap_display_time;
1689 struct __ec_todo_packed lightbar_params_v2_tap {
1690 /* Tap-for-battery params */
1691 uint8_t tap_pct_red;
1692 uint8_t tap_pct_green;
1693 uint8_t tap_seg_min_on;
1694 uint8_t tap_seg_max_on;
1695 uint8_t tap_seg_osc;
1699 struct __ec_todo_packed lightbar_params_v2_oscillation {
1701 uint8_t osc_min[2]; /* AC=0/1 */
1702 uint8_t osc_max[2]; /* AC=0/1 */
1703 uint8_t w_ofs[2]; /* AC=0/1 */
1706 struct __ec_todo_packed lightbar_params_v2_brightness {
1707 /* Brightness limits based on the backlight and AC. */
1708 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1709 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1710 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1713 struct __ec_todo_packed lightbar_params_v2_thresholds {
1714 /* Battery level thresholds */
1715 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1718 struct __ec_todo_packed lightbar_params_v2_colors {
1719 /* Map [AC][battery_level] to color index */
1720 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1721 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1723 /* s5: single color pulse on inhibited power-up */
1727 struct rgb_s color[8]; /* 0-3 are Google colors */
1730 /* Lightbyte program. */
1731 #define EC_LB_PROG_LEN 192
1732 struct __ec_todo_unpacked lightbar_program {
1734 uint8_t data[EC_LB_PROG_LEN];
1737 struct __ec_todo_packed ec_params_lightbar {
1738 uint8_t cmd; /* Command (see enum lightbar_command) */
1740 struct __ec_todo_unpacked {
1742 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1743 version, get_brightness, get_demo, suspend, resume,
1744 get_params_v2_timing, get_params_v2_tap,
1745 get_params_v2_osc, get_params_v2_bright,
1746 get_params_v2_thlds, get_params_v2_colors;
1748 struct __ec_todo_unpacked {
1750 } set_brightness, seq, demo;
1752 struct __ec_todo_unpacked {
1753 uint8_t ctrl, reg, value;
1756 struct __ec_todo_unpacked {
1757 uint8_t led, red, green, blue;
1760 struct __ec_todo_unpacked {
1764 struct __ec_todo_unpacked {
1766 } manual_suspend_ctrl;
1768 struct lightbar_params_v0 set_params_v0;
1769 struct lightbar_params_v1 set_params_v1;
1771 struct lightbar_params_v2_timing set_v2par_timing;
1772 struct lightbar_params_v2_tap set_v2par_tap;
1773 struct lightbar_params_v2_oscillation set_v2par_osc;
1774 struct lightbar_params_v2_brightness set_v2par_bright;
1775 struct lightbar_params_v2_thresholds set_v2par_thlds;
1776 struct lightbar_params_v2_colors set_v2par_colors;
1778 struct lightbar_program set_program;
1782 struct __ec_todo_packed ec_response_lightbar {
1784 struct __ec_todo_unpacked {
1785 struct __ec_todo_unpacked {
1792 struct __ec_todo_unpacked {
1794 } get_seq, get_brightness, get_demo;
1796 struct lightbar_params_v0 get_params_v0;
1797 struct lightbar_params_v1 get_params_v1;
1799 struct lightbar_params_v2_timing get_params_v2_timing;
1800 struct lightbar_params_v2_tap get_params_v2_tap;
1801 struct lightbar_params_v2_oscillation get_params_v2_osc;
1802 struct lightbar_params_v2_brightness get_params_v2_bright;
1803 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1804 struct lightbar_params_v2_colors get_params_v2_colors;
1806 struct __ec_todo_unpacked {
1811 struct __ec_todo_unpacked {
1812 uint8_t red, green, blue;
1815 struct __ec_todo_unpacked {
1816 /* no return params */
1817 } off, on, init, set_brightness, seq, reg, set_rgb,
1818 demo, set_params_v0, set_params_v1,
1819 set_program, manual_suspend_ctrl, suspend, resume,
1820 set_v2par_timing, set_v2par_tap,
1821 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1826 /* Lightbar commands */
1827 enum lightbar_command {
1828 LIGHTBAR_CMD_DUMP = 0,
1829 LIGHTBAR_CMD_OFF = 1,
1830 LIGHTBAR_CMD_ON = 2,
1831 LIGHTBAR_CMD_INIT = 3,
1832 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1833 LIGHTBAR_CMD_SEQ = 5,
1834 LIGHTBAR_CMD_REG = 6,
1835 LIGHTBAR_CMD_SET_RGB = 7,
1836 LIGHTBAR_CMD_GET_SEQ = 8,
1837 LIGHTBAR_CMD_DEMO = 9,
1838 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1839 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1840 LIGHTBAR_CMD_VERSION = 12,
1841 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1842 LIGHTBAR_CMD_GET_RGB = 14,
1843 LIGHTBAR_CMD_GET_DEMO = 15,
1844 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1845 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1846 LIGHTBAR_CMD_SET_PROGRAM = 18,
1847 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1848 LIGHTBAR_CMD_SUSPEND = 20,
1849 LIGHTBAR_CMD_RESUME = 21,
1850 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1851 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1852 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1853 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1854 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1855 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1856 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1857 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1858 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1859 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1860 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1861 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
1865 /*****************************************************************************/
1866 /* LED control commands */
1868 #define EC_CMD_LED_CONTROL 0x0029
1871 /* LED to indicate battery state of charge */
1872 EC_LED_ID_BATTERY_LED = 0,
1874 * LED to indicate system power state (on or in suspend).
1875 * May be on power button or on C-panel.
1877 EC_LED_ID_POWER_LED,
1878 /* LED on power adapter or its plug */
1879 EC_LED_ID_ADAPTER_LED,
1880 /* LED to indicate left side */
1882 /* LED to indicate right side */
1883 EC_LED_ID_RIGHT_LED,
1884 /* LED to indicate recovery mode with HW_REINIT */
1885 EC_LED_ID_RECOVERY_HW_REINIT_LED,
1886 /* LED to indicate sysrq debug mode. */
1887 EC_LED_ID_SYSRQ_DEBUG_LED,
1892 /* LED control flags */
1893 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1894 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1896 enum ec_led_colors {
1897 EC_LED_COLOR_RED = 0,
1900 EC_LED_COLOR_YELLOW,
1907 struct __ec_align1 ec_params_led_control {
1908 uint8_t led_id; /* Which LED to control */
1909 uint8_t flags; /* Control flags */
1911 uint8_t brightness[EC_LED_COLOR_COUNT];
1914 struct __ec_align1 ec_response_led_control {
1916 * Available brightness value range.
1918 * Range 0 means color channel not present.
1919 * Range 1 means on/off control.
1920 * Other values means the LED is control by PWM.
1922 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1925 /*****************************************************************************/
1926 /* Verified boot commands */
1929 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1930 * reused for other purposes with version > 0.
1933 /* Verified boot hash command */
1934 #define EC_CMD_VBOOT_HASH 0x002A
1936 struct __ec_align4 ec_params_vboot_hash {
1937 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1938 uint8_t hash_type; /* enum ec_vboot_hash_type */
1939 uint8_t nonce_size; /* Nonce size; may be 0 */
1940 uint8_t reserved0; /* Reserved; set 0 */
1941 uint32_t offset; /* Offset in flash to hash */
1942 uint32_t size; /* Number of bytes to hash */
1943 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1946 struct __ec_align4 ec_response_vboot_hash {
1947 uint8_t status; /* enum ec_vboot_hash_status */
1948 uint8_t hash_type; /* enum ec_vboot_hash_type */
1949 uint8_t digest_size; /* Size of hash digest in bytes */
1950 uint8_t reserved0; /* Ignore; will be 0 */
1951 uint32_t offset; /* Offset in flash which was hashed */
1952 uint32_t size; /* Number of bytes hashed */
1953 uint8_t hash_digest[64]; /* Hash digest data */
1956 enum ec_vboot_hash_cmd {
1957 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1958 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1959 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1960 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1963 enum ec_vboot_hash_type {
1964 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1967 enum ec_vboot_hash_status {
1968 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1969 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1970 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1974 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1975 * If one of these is specified, the EC will automatically update offset and
1976 * size to the correct values for the specified image (RO or RW).
1978 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1979 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
1980 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
1982 /*****************************************************************************/
1984 * Motion sense commands. We'll make separate structs for sub-commands with
1985 * different input args, so that we know how much to expect.
1987 #define EC_CMD_MOTION_SENSE_CMD 0x002B
1989 /* Motion sense commands */
1990 enum motionsense_command {
1992 * Dump command returns all motion sensor data including motion sense
1993 * module flags and individual sensor flags.
1995 MOTIONSENSE_CMD_DUMP = 0,
1998 * Info command returns data describing the details of a given sensor,
1999 * including enum motionsensor_type, enum motionsensor_location, and
2000 * enum motionsensor_chip.
2002 MOTIONSENSE_CMD_INFO = 1,
2005 * EC Rate command is a setter/getter command for the EC sampling rate
2007 * It is per sensor, the EC run sample task at the minimum of all
2009 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2010 * to collect all the sensor samples.
2011 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2012 * to process of all motion sensors in milliseconds.
2014 MOTIONSENSE_CMD_EC_RATE = 2,
2017 * Sensor ODR command is a setter/getter command for the output data
2018 * rate of a specific motion sensor in millihertz.
2020 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2023 * Sensor range command is a setter/getter command for the range of
2024 * a specified motion sensor in +/-G's or +/- deg/s.
2026 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2029 * Setter/getter command for the keyboard wake angle. When the lid
2030 * angle is greater than this value, keyboard wake is disabled in S3,
2031 * and when the lid angle goes less than this value, keyboard wake is
2032 * enabled. Note, the lid angle measurement is an approximate,
2033 * un-calibrated value, hence the wake angle isn't exact.
2035 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2038 * Returns a single sensor data.
2040 MOTIONSENSE_CMD_DATA = 6,
2043 * Return sensor fifo info.
2045 MOTIONSENSE_CMD_FIFO_INFO = 7,
2048 * Insert a flush element in the fifo and return sensor fifo info.
2049 * The host can use that element to synchronize its operation.
2051 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2054 * Return a portion of the fifo.
2056 MOTIONSENSE_CMD_FIFO_READ = 9,
2059 * Perform low level calibration.
2060 * On sensors that support it, ask to do offset calibration.
2062 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2065 * Sensor Offset command is a setter/getter command for the offset
2066 * used for calibration.
2067 * The offsets can be calculated by the host, or via
2068 * PERFORM_CALIB command.
2070 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2073 * List available activities for a MOTION sensor.
2074 * Indicates if they are enabled or disabled.
2076 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2079 * Activity management
2080 * Enable/Disable activity recognition.
2082 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2087 MOTIONSENSE_CMD_LID_ANGLE = 14,
2090 * Allow the FIFO to trigger interrupt via MKBP events.
2091 * By default the FIFO does not send interrupt to process the FIFO
2092 * until the AP is ready or it is coming from a wakeup sensor.
2094 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2097 * Spoof the readings of the sensors. The spoofed readings can be set
2098 * to arbitrary values, or will lock to the last read actual values.
2100 MOTIONSENSE_CMD_SPOOF = 16,
2102 /* Number of motionsense sub-commands. */
2103 MOTIONSENSE_NUM_CMDS
2106 /* List of motion sensor types. */
2107 enum motionsensor_type {
2108 MOTIONSENSE_TYPE_ACCEL = 0,
2109 MOTIONSENSE_TYPE_GYRO = 1,
2110 MOTIONSENSE_TYPE_MAG = 2,
2111 MOTIONSENSE_TYPE_PROX = 3,
2112 MOTIONSENSE_TYPE_LIGHT = 4,
2113 MOTIONSENSE_TYPE_ACTIVITY = 5,
2114 MOTIONSENSE_TYPE_BARO = 6,
2115 MOTIONSENSE_TYPE_MAX,
2118 /* List of motion sensor locations. */
2119 enum motionsensor_location {
2120 MOTIONSENSE_LOC_BASE = 0,
2121 MOTIONSENSE_LOC_LID = 1,
2122 MOTIONSENSE_LOC_MAX,
2125 /* List of motion sensor chips. */
2126 enum motionsensor_chip {
2127 MOTIONSENSE_CHIP_KXCJ9 = 0,
2128 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2129 MOTIONSENSE_CHIP_BMI160 = 2,
2130 MOTIONSENSE_CHIP_SI1141 = 3,
2131 MOTIONSENSE_CHIP_SI1142 = 4,
2132 MOTIONSENSE_CHIP_SI1143 = 5,
2133 MOTIONSENSE_CHIP_KX022 = 6,
2134 MOTIONSENSE_CHIP_L3GD20H = 7,
2135 MOTIONSENSE_CHIP_BMA255 = 8,
2136 MOTIONSENSE_CHIP_BMP280 = 9,
2137 MOTIONSENSE_CHIP_OPT3001 = 10,
2140 struct __ec_todo_packed ec_response_motion_sensor_data {
2141 /* Flags for each sensor. */
2143 /* sensor number the data comes from */
2145 /* Each sensor is up to 3-axis. */
2148 struct __ec_todo_packed {
2152 struct __ec_todo_unpacked {
2153 uint8_t activity; /* motionsensor_activity */
2155 int16_t add_info[2];
2160 /* Note: used in ec_response_get_next_data */
2161 struct __ec_todo_packed ec_response_motion_sense_fifo_info {
2162 /* Size of the fifo */
2164 /* Amount of space used in the fifo */
2166 /* Timestamp recorded in us */
2168 /* Total amount of vector lost */
2169 uint16_t total_lost;
2170 /* Lost events since the last fifo_info, per sensors */
2174 struct __ec_todo_packed ec_response_motion_sense_fifo_data {
2175 uint32_t number_data;
2176 struct ec_response_motion_sensor_data data[0];
2179 /* List supported activity recognition */
2180 enum motionsensor_activity {
2181 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2182 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2183 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2186 struct __ec_todo_unpacked ec_motion_sense_activity {
2188 uint8_t activity; /* one of enum motionsensor_activity */
2189 uint8_t enable; /* 1: enable, 0: disable */
2191 uint16_t parameters[3]; /* activity dependent parameters */
2194 /* Module flag masks used for the dump sub-command. */
2195 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2197 /* Sensor flag masks used for the dump sub-command. */
2198 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2201 * Flush entry for synchronization.
2202 * data contains time stamp
2204 #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2205 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2206 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
2207 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
2210 * Send this value for the data element to only perform a read. If you
2211 * send any other value, the EC will interpret it as data to set and will
2212 * return the actual value set.
2214 #define EC_MOTION_SENSE_NO_VALUE -1
2216 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2218 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2219 /* Set Calibration information */
2220 #define MOTION_SENSE_SET_OFFSET 1
2222 #define LID_ANGLE_UNRELIABLE 500
2224 enum motionsense_spoof_mode {
2225 /* Disable spoof mode. */
2226 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2228 /* Enable spoof mode, but use provided component values. */
2229 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2231 /* Enable spoof mode, but use the current sensor values. */
2232 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2234 /* Query the current spoof mode status for the sensor. */
2235 MOTIONSENSE_SPOOF_MODE_QUERY,
2238 struct __ec_todo_packed ec_params_motion_sense {
2241 /* Used for MOTIONSENSE_CMD_DUMP */
2242 struct __ec_todo_unpacked {
2244 * Maximal number of sensor the host is expecting.
2245 * 0 means the host is only interested in the number
2246 * of sensors controlled by the EC.
2248 uint8_t max_sensor_count;
2252 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2254 struct __ec_todo_unpacked {
2255 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2256 * kb_wake_angle: angle to wakup AP.
2261 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2262 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
2263 struct __ec_todo_unpacked {
2265 } info, info_3, data, fifo_flush, perform_calib,
2269 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2270 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2272 struct __ec_todo_unpacked {
2275 /* Rounding flag, true for round-up, false for down. */
2280 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2282 } ec_rate, sensor_odr, sensor_range;
2284 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2285 struct __ec_todo_packed {
2289 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2290 * the calibration information in the EC.
2291 * If unset, just retrieve calibration information.
2296 * Temperature at calibration, in units of 0.01 C
2297 * 0x8000: invalid / unknown.
2304 * Offset for calibration.
2306 * Accelerometer: 1/1024 g
2307 * Gyro: 1/1024 deg/s
2313 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
2314 struct __ec_todo_unpacked {
2317 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2318 struct __ec_todo_unpacked {
2320 * Number of expected vector to return.
2321 * EC may return less or 0 if none available.
2323 uint32_t max_data_vector;
2326 struct ec_motion_sense_activity set_activity;
2328 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2329 struct __ec_todo_unpacked {
2332 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2333 struct __ec_todo_unpacked {
2335 * 1: enable, 0 disable fifo,
2336 * EC_MOTION_SENSE_NO_VALUE return value.
2341 /* Used for MOTIONSENSE_CMD_SPOOF */
2342 struct __ec_todo_packed {
2345 /* See enum motionsense_spoof_mode. */
2346 uint8_t spoof_enable;
2348 /* Ignored, used for alignment. */
2351 /* Individual component values to spoof. */
2352 int16_t components[3];
2357 struct __ec_todo_packed ec_response_motion_sense {
2359 /* Used for MOTIONSENSE_CMD_DUMP */
2360 struct __ec_todo_unpacked {
2361 /* Flags representing the motion sensor module. */
2362 uint8_t module_flags;
2364 /* Number of sensors managed directly by the EC */
2365 uint8_t sensor_count;
2368 * sensor data is truncated if response_max is too small
2369 * for holding all the data.
2371 struct ec_response_motion_sensor_data sensor[0];
2374 /* Used for MOTIONSENSE_CMD_INFO. */
2375 struct __ec_todo_unpacked {
2376 /* Should be element of enum motionsensor_type. */
2379 /* Should be element of enum motionsensor_location. */
2382 /* Should be element of enum motionsensor_chip. */
2386 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2387 struct __ec_todo_unpacked {
2388 /* Should be element of enum motionsensor_type. */
2391 /* Should be element of enum motionsensor_location. */
2394 /* Should be element of enum motionsensor_chip. */
2397 /* Minimum sensor sampling frequency */
2398 uint32_t min_frequency;
2400 /* Maximum sensor sampling frequency */
2401 uint32_t max_frequency;
2403 /* Max number of sensor events that could be in fifo */
2404 uint32_t fifo_max_event_count;
2407 /* Used for MOTIONSENSE_CMD_DATA */
2408 struct ec_response_motion_sensor_data data;
2411 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2412 * MOTIONSENSE_CMD_SENSOR_RANGE,
2413 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2414 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2415 * MOTIONSENSE_CMD_SPOOF.
2417 struct __ec_todo_unpacked {
2418 /* Current value of the parameter queried. */
2420 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2421 fifo_int_enable, spoof;
2423 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2424 struct __ec_todo_unpacked {
2427 } sensor_offset, perform_calib;
2429 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2431 struct ec_response_motion_sense_fifo_data fifo_read;
2433 struct __ec_todo_packed {
2439 struct __ec_todo_unpacked {
2442 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2443 struct __ec_todo_unpacked {
2445 * Angle between 0 and 360 degree if available,
2446 * LID_ANGLE_UNRELIABLE otherwise.
2453 /*****************************************************************************/
2454 /* Force lid open command */
2456 /* Make lid event always open */
2457 #define EC_CMD_FORCE_LID_OPEN 0x002C
2459 struct __ec_align1 ec_params_force_lid_open {
2463 /*****************************************************************************/
2464 /* Configure the behavior of the power button */
2465 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2467 enum ec_config_power_button_flags {
2468 /* Enable/Disable power button pulses for x86 devices */
2469 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2472 struct __ec_align1 ec_params_config_power_button {
2473 /* See enum ec_config_power_button_flags */
2477 /*****************************************************************************/
2478 /* USB charging control commands */
2480 /* Set USB port charging mode */
2481 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2483 struct __ec_align1 ec_params_usb_charge_set_mode {
2484 uint8_t usb_port_id;
2488 /*****************************************************************************/
2489 /* Persistent storage for host */
2491 /* Maximum bytes that can be read/written in a single command */
2492 #define EC_PSTORE_SIZE_MAX 64
2494 /* Get persistent storage info */
2495 #define EC_CMD_PSTORE_INFO 0x0040
2497 struct __ec_align4 ec_response_pstore_info {
2498 /* Persistent storage size, in bytes */
2499 uint32_t pstore_size;
2500 /* Access size; read/write offset and size must be a multiple of this */
2501 uint32_t access_size;
2505 * Read persistent storage
2507 * Response is params.size bytes of data.
2509 #define EC_CMD_PSTORE_READ 0x0041
2511 struct __ec_align4 ec_params_pstore_read {
2512 uint32_t offset; /* Byte offset to read */
2513 uint32_t size; /* Size to read in bytes */
2516 /* Write persistent storage */
2517 #define EC_CMD_PSTORE_WRITE 0x0042
2519 struct __ec_align4 ec_params_pstore_write {
2520 uint32_t offset; /* Byte offset to write */
2521 uint32_t size; /* Size to write in bytes */
2522 uint8_t data[EC_PSTORE_SIZE_MAX];
2525 /*****************************************************************************/
2526 /* Real-time clock */
2528 /* RTC params and response structures */
2529 struct __ec_align4 ec_params_rtc {
2533 struct __ec_align4 ec_response_rtc {
2537 /* These use ec_response_rtc */
2538 #define EC_CMD_RTC_GET_VALUE 0x0044
2539 #define EC_CMD_RTC_GET_ALARM 0x0045
2541 /* These all use ec_params_rtc */
2542 #define EC_CMD_RTC_SET_VALUE 0x0046
2543 #define EC_CMD_RTC_SET_ALARM 0x0047
2545 /* Pass as time param to SET_ALARM to clear the current alarm */
2546 #define EC_RTC_ALARM_CLEAR 0
2548 /*****************************************************************************/
2549 /* Port80 log access */
2551 /* Maximum entries that can be read/written in a single command */
2552 #define EC_PORT80_SIZE_MAX 32
2554 /* Get last port80 code from previous boot */
2555 #define EC_CMD_PORT80_LAST_BOOT 0x0048
2556 #define EC_CMD_PORT80_READ 0x0048
2558 enum ec_port80_subcmd {
2559 EC_PORT80_GET_INFO = 0,
2560 EC_PORT80_READ_BUFFER,
2563 struct __ec_todo_packed ec_params_port80_read {
2566 struct __ec_todo_unpacked {
2568 uint32_t num_entries;
2573 struct __ec_todo_packed ec_response_port80_read {
2575 struct __ec_todo_unpacked {
2577 uint32_t history_size;
2580 struct __ec_todo_unpacked {
2581 uint16_t codes[EC_PORT80_SIZE_MAX];
2586 struct __ec_align2 ec_response_port80_last_boot {
2590 /*****************************************************************************/
2591 /* Temporary secure storage for host verified boot use */
2593 /* Number of bytes in a vstore slot */
2594 #define EC_VSTORE_SLOT_SIZE 64
2596 /* Maximum number of vstore slots */
2597 #define EC_VSTORE_SLOT_MAX 32
2599 /* Get persistent storage info */
2600 #define EC_CMD_VSTORE_INFO 0x0049
2601 struct __ec_align_size1 ec_response_vstore_info {
2602 /* Indicates which slots are locked */
2603 uint32_t slot_locked;
2604 /* Total number of slots available */
2609 * Read temporary secure storage
2611 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2613 #define EC_CMD_VSTORE_READ 0x004A
2615 struct __ec_align1 ec_params_vstore_read {
2616 uint8_t slot; /* Slot to read from */
2619 struct __ec_align1 ec_response_vstore_read {
2620 uint8_t data[EC_VSTORE_SLOT_SIZE];
2624 * Write temporary secure storage and lock it.
2626 #define EC_CMD_VSTORE_WRITE 0x004B
2628 struct __ec_align1 ec_params_vstore_write {
2629 uint8_t slot; /* Slot to write to */
2630 uint8_t data[EC_VSTORE_SLOT_SIZE];
2633 /*****************************************************************************/
2634 /* Thermal engine commands. Note that there are two implementations. We'll
2635 * reuse the command number, but the data and behavior is incompatible.
2636 * Version 0 is what originally shipped on Link.
2637 * Version 1 separates the CPU thermal limits from the fan control.
2640 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2641 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
2643 /* The version 0 structs are opaque. You have to know what they are for
2644 * the get/set commands to make any sense.
2647 /* Version 0 - set */
2648 struct __ec_align2 ec_params_thermal_set_threshold {
2649 uint8_t sensor_type;
2650 uint8_t threshold_id;
2654 /* Version 0 - get */
2655 struct __ec_align1 ec_params_thermal_get_threshold {
2656 uint8_t sensor_type;
2657 uint8_t threshold_id;
2660 struct __ec_align2 ec_response_thermal_get_threshold {
2664 /* The version 1 structs are visible. */
2665 enum ec_temp_thresholds {
2666 EC_TEMP_THRESH_WARN = 0,
2667 EC_TEMP_THRESH_HIGH,
2668 EC_TEMP_THRESH_HALT,
2670 EC_TEMP_THRESH_COUNT
2674 * Thermal configuration for one temperature sensor. Temps are in degrees K.
2675 * Zero values will be silently ignored by the thermal task.
2677 * Note that this structure is a sub-structure of
2678 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
2680 struct __ec_align4 ec_thermal_config {
2681 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2682 uint32_t temp_fan_off; /* no active cooling needed */
2683 uint32_t temp_fan_max; /* max active cooling needed */
2686 /* Version 1 - get config for one sensor. */
2687 struct __ec_align4 ec_params_thermal_get_threshold_v1 {
2688 uint32_t sensor_num;
2690 /* This returns a struct ec_thermal_config */
2692 /* Version 1 - set config for one sensor.
2693 * Use read-modify-write for best results! */
2694 struct __ec_align4 ec_params_thermal_set_threshold_v1 {
2695 uint32_t sensor_num;
2696 struct ec_thermal_config cfg;
2698 /* This returns no data */
2700 /****************************************************************************/
2702 /* Toggle automatic fan control */
2703 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
2705 /* Version 1 of input params */
2706 struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
2710 /* Get/Set TMP006 calibration data */
2711 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2712 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
2715 * The original TMP006 calibration only needed four params, but now we need
2716 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2717 * the params opaque. The v1 "get" response will include the algorithm number
2718 * and how many params it requires. That way we can change the EC code without
2719 * needing to update this file. We can also use a different algorithm on each
2723 /* This is the same struct for both v0 and v1. */
2724 struct __ec_align1 ec_params_tmp006_get_calibration {
2729 struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
2736 struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
2738 uint8_t reserved[3];
2746 struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
2749 uint8_t reserved[2];
2753 struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
2761 /* Read raw TMP006 data */
2762 #define EC_CMD_TMP006_GET_RAW 0x0055
2764 struct __ec_align1 ec_params_tmp006_get_raw {
2768 struct __ec_align4 ec_response_tmp006_get_raw {
2769 int32_t t; /* In 1/100 K */
2770 int32_t v; /* In nV */
2773 /*****************************************************************************/
2774 /* MKBP - Matrix KeyBoard Protocol */
2779 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2780 * expected response size.
2782 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2783 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2784 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2786 #define EC_CMD_MKBP_STATE 0x0060
2789 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2791 #define EC_CMD_MKBP_INFO 0x0061
2793 struct __ec_align_size1 ec_response_mkbp_info {
2796 /* Formerly "switches", which was 0. */
2800 struct __ec_align1 ec_params_mkbp_info {
2805 enum ec_mkbp_info_type {
2807 * Info about the keyboard matrix: number of rows and columns.
2809 * Returns struct ec_response_mkbp_info.
2811 EC_MKBP_INFO_KBD = 0,
2814 * For buttons and switches, info about which specifically are
2815 * supported. event_type must be set to one of the values in enum
2818 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2819 * bitmask indicating which buttons or switches are present. See the
2820 * bit inidices below.
2822 EC_MKBP_INFO_SUPPORTED = 1,
2825 * Instantaneous state of buttons and switches.
2827 * event_type must be set to one of the values in enum ec_mkbp_event.
2829 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2830 * indicating the current state of the keyboard matrix.
2832 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2835 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2836 * state of supported buttons.
2838 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2839 * state of supported switches.
2841 EC_MKBP_INFO_CURRENT = 2,
2844 /* Simulate key press */
2845 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2847 struct __ec_align1 ec_params_mkbp_simulate_key {
2853 /* Configure keyboard scanning */
2854 #define EC_CMD_MKBP_SET_CONFIG 0x0064
2855 #define EC_CMD_MKBP_GET_CONFIG 0x0065
2858 enum mkbp_config_flags {
2859 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2862 enum mkbp_config_valid {
2863 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2864 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2865 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2866 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2867 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2868 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2869 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2873 * Configuration for our key scanning algorithm.
2875 * Note that this is used as a sub-structure of
2876 * ec_{params/response}_mkbp_get_config.
2878 struct __ec_align_size1 ec_mkbp_config {
2879 uint32_t valid_mask; /* valid fields */
2880 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2881 uint8_t valid_flags; /* which flags are valid */
2882 uint16_t scan_period_us; /* period between start of scans */
2883 /* revert to interrupt mode after no activity for this long */
2884 uint32_t poll_timeout_us;
2886 * minimum post-scan relax time. Once we finish a scan we check
2887 * the time until we are due to start the next one. If this time is
2888 * shorter this field, we use this instead.
2890 uint16_t min_post_scan_delay_us;
2891 /* delay between setting up output and waiting for it to settle */
2892 uint16_t output_settle_us;
2893 uint16_t debounce_down_us; /* time for debounce on key down */
2894 uint16_t debounce_up_us; /* time for debounce on key up */
2895 /* maximum depth to allow for fifo (0 = no keyscan output) */
2896 uint8_t fifo_max_depth;
2899 struct __ec_align_size1 ec_params_mkbp_set_config {
2900 struct ec_mkbp_config config;
2903 struct __ec_align_size1 ec_response_mkbp_get_config {
2904 struct ec_mkbp_config config;
2907 /* Run the key scan emulation */
2908 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2910 enum ec_keyscan_seq_cmd {
2911 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2912 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2913 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2914 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2915 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2918 enum ec_collect_flags {
2920 * Indicates this scan was processed by the EC. Due to timing, some
2921 * scans may be skipped.
2923 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2926 struct __ec_align1 ec_collect_item {
2927 uint8_t flags; /* some flags (enum ec_collect_flags) */
2930 struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
2931 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2933 struct __ec_align1 {
2934 uint8_t active; /* still active */
2935 uint8_t num_items; /* number of items */
2936 /* Current item being presented */
2939 struct __ec_todo_unpacked {
2941 * Absolute time for this scan, measured from the
2942 * start of the sequence.
2945 uint8_t scan[0]; /* keyscan data */
2947 struct __ec_align1 {
2948 uint8_t start_item; /* First item to return */
2949 uint8_t num_items; /* Number of items to return */
2954 struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
2956 struct __ec_todo_unpacked {
2957 uint8_t num_items; /* Number of items */
2958 /* Data for each item */
2959 struct ec_collect_item item[0];
2965 * Get the next pending MKBP event.
2967 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2969 #define EC_CMD_GET_NEXT_EVENT 0x0067
2971 enum ec_mkbp_event {
2972 /* Keyboard matrix changed. The event data is the new matrix state. */
2973 EC_MKBP_EVENT_KEY_MATRIX = 0,
2975 /* New host event. The event data is 4 bytes of host event flags. */
2976 EC_MKBP_EVENT_HOST_EVENT = 1,
2978 /* New Sensor FIFO data. The event data is fifo_info structure. */
2979 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2981 /* The state of the non-matrixed buttons have changed. */
2982 EC_MKBP_EVENT_BUTTON = 3,
2984 /* The state of the switches have changed. */
2985 EC_MKBP_EVENT_SWITCH = 4,
2987 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2988 EC_MKBP_EVENT_FINGERPRINT = 5,
2991 * Sysrq event: send emulated sysrq. The event data is sysrq,
2992 * corresponding to the key to be pressed.
2994 EC_MKBP_EVENT_SYSRQ = 6,
2996 /* Number of MKBP events */
2997 EC_MKBP_EVENT_COUNT,
3000 union __ec_align_offset1 ec_response_get_next_data {
3001 uint8_t key_matrix[13];
3004 uint32_t host_event;
3006 struct __ec_todo_unpacked {
3007 /* For aligning the fifo_info */
3008 uint8_t reserved[3];
3009 struct ec_response_motion_sense_fifo_info info;
3021 struct __ec_align1 ec_response_get_next_event {
3023 /* Followed by event data if any */
3024 union ec_response_get_next_data data;
3027 /* Bit indices for buttons and switches.*/
3029 #define EC_MKBP_POWER_BUTTON 0
3030 #define EC_MKBP_VOL_UP 1
3031 #define EC_MKBP_VOL_DOWN 2
3032 #define EC_MKBP_RECOVERY 3
3035 #define EC_MKBP_LID_OPEN 0
3036 #define EC_MKBP_TABLET_MODE 1
3038 /* Run keyboard factory test scanning */
3039 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3041 struct __ec_align2 ec_response_keyboard_factory_test {
3042 uint16_t shorted; /* Keyboard pins are shorted */
3045 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3046 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3047 #define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3048 #define EC_MKBP_FP_FINGER_UP (1 << 30)
3049 #define EC_MKBP_FP_IMAGE_READY (1 << 31)
3051 /*****************************************************************************/
3052 /* Temperature sensor commands */
3054 /* Read temperature sensor info */
3055 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
3057 struct __ec_align1 ec_params_temp_sensor_get_info {
3061 struct __ec_align1 ec_response_temp_sensor_get_info {
3062 char sensor_name[32];
3063 uint8_t sensor_type;
3066 /*****************************************************************************/
3069 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3070 * commands accidentally sent to the wrong interface. See the ACPI section
3074 /*****************************************************************************/
3075 /* Host event commands */
3077 /* Obsolete. New implementation should use EC_CMD_PROGRAM_HOST_EVENT instead */
3079 * Host event mask params and response structures, shared by all of the host
3080 * event commands below.
3082 struct __ec_align4 ec_params_host_event_mask {
3086 struct __ec_align4 ec_response_host_event_mask {
3090 /* These all use ec_response_host_event_mask */
3091 #define EC_CMD_HOST_EVENT_GET_B 0x0087
3092 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3093 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3094 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
3096 /* These all use ec_params_host_event_mask */
3097 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3098 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3099 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
3100 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3101 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3104 * Unified host event programming interface - Should be used by newer versions
3105 * of BIOS/OS to program host events and masks
3108 struct __ec_align4 ec_params_host_event {
3110 /* Action requested by host - one of enum ec_host_event_action. */
3114 * Mask type that the host requested the action on - one of
3115 * enum ec_host_event_mask_type.
3119 /* Set to 0, ignore on read */
3122 /* Value to be used in case of set operations. */
3127 * Response structure returned by EC_CMD_HOST_EVENT.
3128 * Update the value on a GET request. Set to 0 on GET/CLEAR
3131 struct __ec_align4 ec_response_host_event {
3133 /* Mask value in case of get operation */
3137 enum ec_host_event_action {
3139 * params.value is ignored. Value of mask_type populated
3144 /* Bits in params.value are set */
3147 /* Bits in params.value are cleared */
3148 EC_HOST_EVENT_CLEAR,
3151 enum ec_host_event_mask_type {
3153 /* Main host event copy */
3156 /* Copy B of host events */
3160 EC_HOST_EVENT_SCI_MASK,
3163 EC_HOST_EVENT_SMI_MASK,
3165 /* Mask of events that should be always reported in hostevents */
3166 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3168 /* Active wake mask */
3169 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3171 /* Lazy wake mask for S0ix */
3172 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3174 /* Lazy wake mask for S3 */
3175 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3177 /* Lazy wake mask for S5 */
3178 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3181 #define EC_CMD_HOST_EVENT 0x00A4
3183 /*****************************************************************************/
3184 /* Switch commands */
3186 /* Enable/disable LCD backlight */
3187 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
3189 struct __ec_align1 ec_params_switch_enable_backlight {
3193 /* Enable/disable WLAN/Bluetooth */
3194 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
3195 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
3197 /* Version 0 params; no response */
3198 struct __ec_align1 ec_params_switch_enable_wireless_v0 {
3202 /* Version 1 params */
3203 struct __ec_align1 ec_params_switch_enable_wireless_v1 {
3204 /* Flags to enable now */
3207 /* Which flags to copy from now_flags */
3211 * Flags to leave enabled in S3, if they're on at the S0->S3
3212 * transition. (Other flags will be disabled by the S0->S3
3215 uint8_t suspend_flags;
3217 /* Which flags to copy from suspend_flags */
3218 uint8_t suspend_mask;
3221 /* Version 1 response */
3222 struct __ec_align1 ec_response_switch_enable_wireless_v1 {
3223 /* Flags to enable now */
3226 /* Flags to leave enabled in S3 */
3227 uint8_t suspend_flags;
3230 /*****************************************************************************/
3231 /* GPIO commands. Only available on EC if write protect has been disabled. */
3233 /* Set GPIO output value */
3234 #define EC_CMD_GPIO_SET 0x0092
3236 struct __ec_align1 ec_params_gpio_set {
3241 /* Get GPIO value */
3242 #define EC_CMD_GPIO_GET 0x0093
3244 /* Version 0 of input params and response */
3245 struct __ec_align1 ec_params_gpio_get {
3249 struct __ec_align1 ec_response_gpio_get {
3253 /* Version 1 of input params and response */
3254 struct __ec_align1 ec_params_gpio_get_v1 {
3257 struct __ec_align1 {
3259 } get_value_by_name;
3260 struct __ec_align1 {
3266 struct __ec_todo_packed ec_response_gpio_get_v1 {
3268 struct __ec_align1 {
3270 } get_value_by_name, get_count;
3271 struct __ec_todo_unpacked {
3279 enum gpio_get_subcmd {
3280 EC_GPIO_GET_BY_NAME = 0,
3281 EC_GPIO_GET_COUNT = 1,
3282 EC_GPIO_GET_INFO = 2,
3285 /*****************************************************************************/
3286 /* I2C commands. Only available when flash write protect is unlocked. */
3289 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3290 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3292 * Use EC_CMD_I2C_PASSTHRU instead.
3296 #define EC_CMD_I2C_READ 0x0094
3298 struct __ec_align_size1 ec_params_i2c_read {
3299 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3300 uint8_t read_size; /* Either 8 or 16. */
3305 struct __ec_align2 ec_response_i2c_read {
3310 #define EC_CMD_I2C_WRITE 0x0095
3312 struct __ec_align_size1 ec_params_i2c_write {
3314 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
3315 uint8_t write_size; /* Either 8 or 16. */
3320 /*****************************************************************************/
3321 /* Charge state commands. Only available when flash write protect unlocked. */
3323 /* Force charge state machine to stop charging the battery or force it to
3324 * discharge the battery.
3326 #define EC_CMD_CHARGE_CONTROL 0x0096
3327 #define EC_VER_CHARGE_CONTROL 1
3329 enum ec_charge_control_mode {
3330 CHARGE_CONTROL_NORMAL = 0,
3331 CHARGE_CONTROL_IDLE,
3332 CHARGE_CONTROL_DISCHARGE,
3335 struct __ec_align4 ec_params_charge_control {
3336 uint32_t mode; /* enum charge_control_mode */
3339 /*****************************************************************************/
3340 /* Console commands. Only available when flash write protect is unlocked. */
3342 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
3343 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
3346 * Read data from the saved snapshot. If the subcmd parameter is
3347 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3348 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3349 * end of the previous snapshot.
3351 * The params are only looked at in version >= 1 of this command. Prior
3352 * versions will just default to CONSOLE_READ_NEXT behavior.
3354 * Response is null-terminated string. Empty string, if there is no more
3357 #define EC_CMD_CONSOLE_READ 0x0098
3359 enum ec_console_read_subcmd {
3360 CONSOLE_READ_NEXT = 0,
3364 struct __ec_align1 ec_params_console_read_v1 {
3365 uint8_t subcmd; /* enum ec_console_read_subcmd */
3368 /*****************************************************************************/
3371 * Cut off battery power immediately or after the host has shut down.
3373 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3374 * EC_RES_SUCCESS if the command was successful.
3375 * EC_RES_ERROR if the cut off command failed.
3377 #define EC_CMD_BATTERY_CUT_OFF 0x0099
3379 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3381 struct __ec_align1 ec_params_battery_cutoff {
3385 /*****************************************************************************/
3386 /* USB port mux control. */
3389 * Switch USB mux or return to automatic switching.
3391 #define EC_CMD_USB_MUX 0x009A
3393 struct __ec_align1 ec_params_usb_mux {
3397 /*****************************************************************************/
3398 /* LDOs / FETs control. */
3401 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3402 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3406 * Switch on/off a LDO.
3408 #define EC_CMD_LDO_SET 0x009B
3410 struct __ec_align1 ec_params_ldo_set {
3418 #define EC_CMD_LDO_GET 0x009C
3420 struct __ec_align1 ec_params_ldo_get {
3424 struct __ec_align1 ec_response_ldo_get {
3428 /*****************************************************************************/
3434 #define EC_CMD_POWER_INFO 0x009D
3436 struct __ec_align4 ec_response_power_info {
3437 uint32_t usb_dev_type;
3438 uint16_t voltage_ac;
3439 uint16_t voltage_system;
3440 uint16_t current_system;
3441 uint16_t usb_current_limit;
3444 /*****************************************************************************/
3445 /* I2C passthru command */
3447 #define EC_CMD_I2C_PASSTHRU 0x009E
3449 /* Read data; if not present, message is a write */
3450 #define EC_I2C_FLAG_READ (1 << 15)
3452 /* Mask for address */
3453 #define EC_I2C_ADDR_MASK 0x3ff
3455 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3456 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3459 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3461 struct __ec_align2 ec_params_i2c_passthru_msg {
3462 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3463 uint16_t len; /* Number of bytes to read or write */
3466 struct __ec_align2 ec_params_i2c_passthru {
3467 uint8_t port; /* I2C port number */
3468 uint8_t num_msgs; /* Number of messages */
3469 struct ec_params_i2c_passthru_msg msg[];
3470 /* Data to write for all messages is concatenated here */
3473 struct __ec_align1 ec_response_i2c_passthru {
3474 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3475 uint8_t num_msgs; /* Number of messages processed */
3476 uint8_t data[]; /* Data read by messages concatenated here */
3479 /*****************************************************************************/
3480 /* Power button hang detect */
3482 #define EC_CMD_HANG_DETECT 0x009F
3484 /* Reasons to start hang detection timer */
3485 /* Power button pressed */
3486 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3489 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3492 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
3494 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
3495 #define EC_HANG_START_ON_RESUME (1 << 3)
3497 /* Reasons to cancel hang detection */
3499 /* Power button released */
3500 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3502 /* Any host command from AP received */
3503 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3505 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3506 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3509 * If this flag is set, all the other fields are ignored, and the hang detect
3510 * timer is started. This provides the AP a way to start the hang timer
3511 * without reconfiguring any of the other hang detect settings. Note that
3512 * you must previously have configured the timeouts.
3514 #define EC_HANG_START_NOW (1 << 30)
3517 * If this flag is set, all the other fields are ignored (including
3518 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3519 * without reconfiguring any of the other hang detect settings.
3521 #define EC_HANG_STOP_NOW (1 << 31)
3523 struct __ec_align4 ec_params_hang_detect {
3524 /* Flags; see EC_HANG_* */
3527 /* Timeout in msec before generating host event, if enabled */
3528 uint16_t host_event_timeout_msec;
3530 /* Timeout in msec before generating warm reboot, if enabled */
3531 uint16_t warm_reboot_timeout_msec;
3534 /*****************************************************************************/
3535 /* Commands for battery charging */
3538 * This is the single catch-all host command to exchange data regarding the
3539 * charge state machine (v2 and up).
3541 #define EC_CMD_CHARGE_STATE 0x00A0
3543 /* Subcommands for this host command */
3544 enum charge_state_command {
3545 CHARGE_STATE_CMD_GET_STATE,
3546 CHARGE_STATE_CMD_GET_PARAM,
3547 CHARGE_STATE_CMD_SET_PARAM,
3548 CHARGE_STATE_NUM_CMDS
3552 * Known param numbers are defined here. Ranges are reserved for board-specific
3553 * params, which are handled by the particular implementations.
3555 enum charge_state_params {
3556 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3557 CS_PARAM_CHG_CURRENT, /* charger current limit */
3558 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3559 CS_PARAM_CHG_STATUS, /* charger-specific status */
3560 CS_PARAM_CHG_OPTION, /* charger-specific options */
3561 CS_PARAM_LIMIT_POWER, /*
3562 * Check if power is limited due to
3563 * low battery and / or a weak external
3564 * charger. READ ONLY.
3566 /* How many so far? */
3569 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3570 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3571 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3573 /* Other custom param ranges go here... */
3576 struct __ec_todo_packed ec_params_charge_state {
3577 uint8_t cmd; /* enum charge_state_command */
3579 struct __ec_align1 {
3583 struct __ec_todo_unpacked {
3584 uint32_t param; /* enum charge_state_param */
3587 struct __ec_todo_unpacked {
3588 uint32_t param; /* param to set */
3589 uint32_t value; /* value to set */
3594 struct __ec_align4 ec_response_charge_state {
3596 struct __ec_align4 {
3600 int chg_input_current;
3601 int batt_state_of_charge;
3604 struct __ec_align4 {
3607 struct __ec_align4 {
3608 /* no return values */
3614 * Set maximum battery charging current.
3616 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
3618 struct __ec_align4 ec_params_current_limit {
3619 uint32_t limit; /* in mA */
3623 * Set maximum external voltage / current.
3625 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
3627 /* Command v0 is used only on Spring and is obsolete + unsupported */
3628 struct __ec_align2 ec_params_external_power_limit_v1 {
3629 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3630 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
3633 #define EC_POWER_LIMIT_NONE 0xffff
3636 * Set maximum voltage & current of a dedicated charge port
3638 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3640 struct __ec_align2 ec_params_dedicated_charger_limit {
3641 uint16_t current_lim; /* in mA */
3642 uint16_t voltage_lim; /* in mV */
3645 /*****************************************************************************/
3646 /* Hibernate/Deep Sleep Commands */
3648 /* Set the delay before going into hibernation. */
3649 #define EC_CMD_HIBERNATION_DELAY 0x00A8
3651 struct __ec_align4 ec_params_hibernation_delay {
3653 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3654 * current settings without changing them.
3659 struct __ec_align4 ec_response_hibernation_delay {
3661 * The current time in seconds in which the system has been in the G3
3662 * state. This value is reset if the EC transitions out of G3.
3667 * The current time remaining in seconds until the EC should hibernate.
3668 * This value is also reset if the EC transitions out of G3.
3670 uint32_t time_remaining;
3673 * The current time in seconds that the EC should wait in G3 before
3676 uint32_t hibernate_delay;
3679 /* Inform the EC when entering a sleep state */
3680 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3682 enum host_sleep_event {
3683 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3684 HOST_SLEEP_EVENT_S3_RESUME = 2,
3685 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3686 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3689 struct __ec_align1 ec_params_host_sleep_event {
3690 uint8_t sleep_event;
3693 /*****************************************************************************/
3695 #define EC_CMD_DEVICE_EVENT 0x00AA
3697 enum ec_device_event {
3698 EC_DEVICE_EVENT_TRACKPAD,
3699 EC_DEVICE_EVENT_DSP,
3700 EC_DEVICE_EVENT_WIFI,
3703 enum ec_device_event_param {
3704 /* Get and clear pending device events */
3705 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3706 /* Get device event mask */
3707 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3708 /* Set device event mask */
3709 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3712 #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3714 struct __ec_align_size1 ec_params_device_event {
3715 uint32_t event_mask;
3719 struct __ec_align4 ec_response_device_event {
3720 uint32_t event_mask;
3723 /*****************************************************************************/
3724 /* Smart battery pass-through */
3726 /* Get / Set 16-bit smart battery registers */
3727 #define EC_CMD_SB_READ_WORD 0x00B0
3728 #define EC_CMD_SB_WRITE_WORD 0x00B1
3730 /* Get / Set string smart battery parameters
3731 * formatted as SMBUS "block".
3733 #define EC_CMD_SB_READ_BLOCK 0x00B2
3734 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
3736 struct __ec_align1 ec_params_sb_rd {
3740 struct __ec_align2 ec_response_sb_rd_word {
3744 struct __ec_align1 ec_params_sb_wr_word {
3749 struct __ec_align1 ec_response_sb_rd_block {
3753 struct __ec_align1 ec_params_sb_wr_block {
3758 /*****************************************************************************/
3759 /* Battery vendor parameters
3761 * Get or set vendor-specific parameters in the battery. Implementations may
3762 * differ between boards or batteries. On a set operation, the response
3763 * contains the actual value set, which may be rounded or clipped from the
3767 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
3769 enum ec_battery_vendor_param_mode {
3770 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3771 BATTERY_VENDOR_PARAM_MODE_SET,
3774 struct __ec_align_size1 ec_params_battery_vendor_param {
3780 struct __ec_align4 ec_response_battery_vendor_param {
3784 /*****************************************************************************/
3786 * Smart Battery Firmware Update Commands
3788 #define EC_CMD_SB_FW_UPDATE 0x00B5
3790 enum ec_sb_fw_update_subcmd {
3791 EC_SB_FW_UPDATE_PREPARE = 0x0,
3792 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3793 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3794 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3795 EC_SB_FW_UPDATE_END = 0x4,
3796 EC_SB_FW_UPDATE_STATUS = 0x5,
3797 EC_SB_FW_UPDATE_PROTECT = 0x6,
3798 EC_SB_FW_UPDATE_MAX = 0x7,
3801 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3802 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3803 #define SB_FW_UPDATE_CMD_INFO_SIZE 8
3805 struct __ec_align4 ec_sb_fw_update_header {
3806 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3807 uint16_t fw_id; /* firmware id */
3810 struct __ec_align4 ec_params_sb_fw_update {
3811 struct ec_sb_fw_update_header hdr;
3813 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3814 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3815 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3816 /* EC_SB_FW_UPDATE_END = 0x4 */
3817 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3818 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
3819 struct __ec_align4 {
3823 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
3824 struct __ec_align4 {
3825 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3830 struct __ec_align1 ec_response_sb_fw_update {
3832 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3833 struct __ec_align1 {
3834 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3837 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3838 struct __ec_align1 {
3839 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3845 * Entering Verified Boot Mode Command
3846 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3847 * Valid Modes are: normal, developer, and recovery.
3849 #define EC_CMD_ENTERING_MODE 0x00B6
3851 struct __ec_align4 ec_params_entering_mode {
3855 #define VBOOT_MODE_NORMAL 0
3856 #define VBOOT_MODE_DEVELOPER 1
3857 #define VBOOT_MODE_RECOVERY 2
3859 /*****************************************************************************/
3861 * I2C passthru protection command: Protects I2C tunnels against access on
3862 * certain addresses (board-specific).
3864 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
3866 enum ec_i2c_passthru_protect_subcmd {
3867 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3868 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3871 struct __ec_align1 ec_params_i2c_passthru_protect {
3873 uint8_t port; /* I2C port number */
3876 struct __ec_align1 ec_response_i2c_passthru_protect {
3877 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
3880 /*****************************************************************************/
3881 /* System commands */
3884 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3885 * necessarily reboot the EC. Rename to "image" or something similar?
3887 #define EC_CMD_REBOOT_EC 0x00D2
3890 enum ec_reboot_cmd {
3891 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
3892 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3893 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
3894 /* (command 3 was jump to RW-B) */
3895 EC_REBOOT_COLD = 4, /* Cold-reboot */
3896 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3897 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
3898 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
3901 /* Flags for ec_params_reboot_ec.reboot_flags */
3902 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
3903 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
3904 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2) /* Switch RW slot */
3906 struct __ec_align1 ec_params_reboot_ec {
3907 uint8_t cmd; /* enum ec_reboot_cmd */
3908 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3912 * Get information on last EC panic.
3914 * Returns variable-length platform-dependent panic information. See panic.h
3917 #define EC_CMD_GET_PANIC_INFO 0x00D3
3919 /*****************************************************************************/
3923 * These do not follow the normal rules for commands. See each command for
3930 * This command will work even when the EC LPC interface is busy, because the
3931 * reboot command is processed at interrupt level. Note that when the EC
3932 * reboots, the host will reboot too, so there is no response to this command.
3934 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3936 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3939 * Resend last response (not supported on LPC).
3941 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3942 * there was no previous command, or the previous command's response was too
3945 #define EC_CMD_RESEND_RESPONSE 0x00DB
3948 * This header byte on a command indicate version 0. Any header byte less
3949 * than this means that we are talking to an old EC which doesn't support
3950 * versioning. In that case, we assume version 0.
3952 * Header bytes greater than this indicate a later version. For example,
3953 * EC_CMD_VERSION0 + 1 means we are using version 1.
3955 * The old EC interface must not use commands 0xdc or higher.
3957 #define EC_CMD_VERSION0 0x00DC
3959 /*****************************************************************************/
3963 * These commands are for PD MCU communication.
3966 /* EC to PD MCU exchange status command */
3967 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
3968 #define EC_VER_PD_EXCHANGE_STATUS 2
3970 enum pd_charge_state {
3971 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3972 PD_CHARGE_NONE, /* No charging allowed */
3973 PD_CHARGE_5V, /* 5V charging only */
3974 PD_CHARGE_MAX /* Charge at max voltage */
3977 /* Status of EC being sent to PD */
3978 #define EC_STATUS_HIBERNATING (1 << 0)
3980 struct __ec_align1 ec_params_pd_status {
3981 uint8_t status; /* EC status */
3982 int8_t batt_soc; /* battery state of charge */
3983 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
3986 /* Status of PD being sent back to EC */
3987 #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3988 #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3989 #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
3990 #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3991 #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3992 #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3993 #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3994 #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3995 PD_STATUS_TCPC_ALERT_1 | \
3996 PD_STATUS_HOST_EVENT)
3997 struct __ec_align_size1 ec_response_pd_status {
3998 uint32_t curr_lim_ma; /* input current limit */
3999 uint16_t status; /* PD MCU status */
4000 int8_t active_charge_port; /* active charging port */
4003 /* AP to PD MCU host event status command, cleared on read */
4004 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4006 /* PD MCU host event status bits */
4007 #define PD_EVENT_UPDATE_DEVICE (1 << 0)
4008 #define PD_EVENT_POWER_CHANGE (1 << 1)
4009 #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
4010 #define PD_EVENT_DATA_SWAP (1 << 3)
4011 struct __ec_align4 ec_response_host_event_status {
4012 uint32_t status; /* PD MCU host event status */
4015 /* Set USB type-C port role and muxes */
4016 #define EC_CMD_USB_PD_CONTROL 0x0101
4018 enum usb_pd_control_role {
4019 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
4020 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
4021 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4022 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4023 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4024 USB_PD_CTRL_ROLE_COUNT
4027 enum usb_pd_control_mux {
4028 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4029 USB_PD_CTRL_MUX_NONE = 1,
4030 USB_PD_CTRL_MUX_USB = 2,
4031 USB_PD_CTRL_MUX_DP = 3,
4032 USB_PD_CTRL_MUX_DOCK = 4,
4033 USB_PD_CTRL_MUX_AUTO = 5,
4034 USB_PD_CTRL_MUX_COUNT
4037 enum usb_pd_control_swap {
4038 USB_PD_CTRL_SWAP_NONE = 0,
4039 USB_PD_CTRL_SWAP_DATA = 1,
4040 USB_PD_CTRL_SWAP_POWER = 2,
4041 USB_PD_CTRL_SWAP_VCONN = 3,
4042 USB_PD_CTRL_SWAP_COUNT
4045 struct __ec_align1 ec_params_usb_pd_control {
4052 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
4053 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
4054 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4056 #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
4057 #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
4058 #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
4059 #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
4060 #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
4061 #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
4062 #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
4064 struct __ec_align1 ec_response_usb_pd_control {
4071 struct __ec_align1 ec_response_usb_pd_control_v1 {
4078 #define EC_CMD_USB_PD_PORTS 0x0102
4080 /* Maximum number of PD ports on a device, num_ports will be <= this */
4081 #define EC_USB_PD_MAX_PORTS 8
4083 struct __ec_align1 ec_response_usb_pd_ports {
4087 #define EC_CMD_USB_PD_POWER_INFO 0x0103
4089 #define PD_POWER_CHARGING_PORT 0xff
4090 struct __ec_align1 ec_params_usb_pd_power_info {
4098 USB_CHG_TYPE_PROPRIETARY,
4099 USB_CHG_TYPE_BC12_DCP,
4100 USB_CHG_TYPE_BC12_CDP,
4101 USB_CHG_TYPE_BC12_SDP,
4104 USB_CHG_TYPE_UNKNOWN,
4106 enum usb_power_roles {
4107 USB_PD_PORT_POWER_DISCONNECTED,
4108 USB_PD_PORT_POWER_SOURCE,
4109 USB_PD_PORT_POWER_SINK,
4110 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4113 struct __ec_align2 usb_chg_measures {
4114 uint16_t voltage_max;
4115 uint16_t voltage_now;
4116 uint16_t current_max;
4117 uint16_t current_lim;
4120 struct __ec_align4 ec_response_usb_pd_power_info {
4125 struct usb_chg_measures meas;
4129 /* Write USB-PD device FW */
4130 #define EC_CMD_USB_PD_FW_UPDATE 0x0110
4132 enum usb_pd_fw_update_cmds {
4134 USB_PD_FW_FLASH_ERASE,
4135 USB_PD_FW_FLASH_WRITE,
4136 USB_PD_FW_ERASE_SIG,
4139 struct __ec_align4 ec_params_usb_pd_fw_update {
4143 uint32_t size; /* Size to write in bytes */
4144 /* Followed by data to write */
4147 /* Write USB-PD Accessory RW_HASH table entry */
4148 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4149 /* RW hash is first 20 bytes of SHA-256 of RW section */
4150 #define PD_RW_HASH_SIZE 20
4151 struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
4153 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4154 uint8_t reserved; /* For alignment of current_image
4155 * TODO(rspangler) but it's not aligned!
4156 * Should have been reserved[2]. */
4157 uint32_t current_image; /* One of ec_current_image */
4160 /* Read USB-PD Accessory info */
4161 #define EC_CMD_USB_PD_DEV_INFO 0x0112
4163 struct __ec_align1 ec_params_usb_pd_info_request {
4167 /* Read USB-PD Device discovery info */
4168 #define EC_CMD_USB_PD_DISCOVERY 0x0113
4169 struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
4170 uint16_t vid; /* USB-IF VID */
4171 uint16_t pid; /* USB-IF PID */
4172 uint8_t ptype; /* product type (hub,periph,cable,ama) */
4175 /* Override default charge behavior */
4176 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
4178 /* Negative port parameters have special meaning */
4179 enum usb_pd_override_ports {
4180 OVERRIDE_DONT_CHARGE = -2,
4182 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4185 struct __ec_align2 ec_params_charge_port_override {
4186 int16_t override_port; /* Override port# */
4189 /* Read (and delete) one entry of PD event log */
4190 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
4192 struct __ec_align4 ec_response_pd_log {
4193 uint32_t timestamp; /* relative timestamp in milliseconds */
4194 uint8_t type; /* event type : see PD_EVENT_xx below */
4195 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4196 uint16_t data; /* type-defined data payload */
4197 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
4200 /* The timestamp is the microsecond counter shifted to get about a ms. */
4201 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4203 #define PD_LOG_SIZE_MASK 0x1f
4204 #define PD_LOG_PORT_MASK 0xe0
4205 #define PD_LOG_PORT_SHIFT 5
4206 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4207 ((size) & PD_LOG_SIZE_MASK))
4208 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4209 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4211 /* PD event log : entry types */
4213 #define PD_EVENT_MCU_BASE 0x00
4214 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4215 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4216 /* Reserved for custom board event */
4217 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4218 /* PD generic accessory events */
4219 #define PD_EVENT_ACC_BASE 0x20
4220 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4221 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4222 /* PD power supply events */
4223 #define PD_EVENT_PS_BASE 0x40
4224 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4225 /* PD video dongles events */
4226 #define PD_EVENT_VIDEO_BASE 0x60
4227 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4228 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4229 /* Returned in the "type" field, when there is no entry available */
4230 #define PD_EVENT_NO_ENTRY 0xff
4233 * PD_EVENT_MCU_CHARGE event definition :
4234 * the payload is "struct usb_chg_measures"
4235 * the data field contains the port state flags as defined below :
4237 /* Port partner is a dual role device */
4238 #define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4239 /* Port is the pending override port */
4240 #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4241 /* Port is the override port */
4242 #define CHARGE_FLAGS_OVERRIDE (1 << 13)
4244 #define CHARGE_FLAGS_TYPE_SHIFT 3
4245 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4246 /* Power delivery role */
4247 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4250 * PD_EVENT_PS_FAULT data field flags definition :
4252 #define PS_FAULT_OCP 1
4253 #define PS_FAULT_FAST_OCP 2
4254 #define PS_FAULT_OVP 3
4255 #define PS_FAULT_DISCH 4
4258 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4260 struct __ec_align4 mcdp_version {
4266 struct __ec_align4 mcdp_info {
4269 struct mcdp_version irom;
4270 struct mcdp_version fw;
4273 /* struct mcdp_info field decoding */
4274 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4275 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4277 /* Get/Set USB-PD Alternate mode info */
4278 #define EC_CMD_USB_PD_GET_AMODE 0x0116
4279 struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
4280 uint16_t svid_idx; /* SVID index to get */
4281 uint8_t port; /* port */
4284 struct __ec_align4 ec_params_usb_pd_get_mode_response {
4285 uint16_t svid; /* SVID */
4286 uint16_t opos; /* Object Position */
4287 uint32_t vdo[6]; /* Mode VDOs */
4290 #define EC_CMD_USB_PD_SET_AMODE 0x0117
4295 /* Not a command. Do NOT remove. */
4299 struct __ec_align4 ec_params_usb_pd_set_mode_request {
4300 uint32_t cmd; /* enum pd_mode_cmd */
4301 uint16_t svid; /* SVID to set */
4302 uint8_t opos; /* Object Position */
4303 uint8_t port; /* port */
4306 /* Ask the PD MCU to record a log of a requested type */
4307 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
4309 struct __ec_align1 ec_params_pd_write_log_entry {
4310 uint8_t type; /* event type : see PD_EVENT_xx above */
4311 uint8_t port; /* port#, or 0 for events unrelated to a given port */
4314 /* Control USB-PD chip */
4315 #define EC_CMD_PD_CONTROL 0x0119
4317 enum ec_pd_control_cmd {
4318 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4319 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4320 PD_RESET, /* Force reset the PD chip */
4321 PD_CONTROL_DISABLE /* Disable further calls to this command */
4324 struct __ec_align1 ec_params_pd_control {
4325 uint8_t chip; /* chip id (should be 0) */
4329 /* Get info about USB-C SS muxes */
4330 #define EC_CMD_USB_PD_MUX_INFO 0x011A
4332 struct __ec_align1 ec_params_usb_pd_mux_info {
4333 uint8_t port; /* USB-C port number */
4336 /* Flags representing mux state */
4337 #define USB_PD_MUX_USB_ENABLED (1 << 0)
4338 #define USB_PD_MUX_DP_ENABLED (1 << 1)
4339 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4340 #define USB_PD_MUX_HPD_IRQ (1 << 3)
4342 struct __ec_align1 ec_response_usb_pd_mux_info {
4343 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4346 #define EC_CMD_PD_CHIP_INFO 0x011B
4348 struct __ec_align1 ec_params_pd_chip_info {
4349 uint8_t port; /* USB-C port number */
4350 uint8_t renew; /* Force renewal */
4353 struct __ec_align2 ec_response_pd_chip_info {
4355 uint16_t product_id;
4358 uint8_t fw_version_string[8];
4359 uint64_t fw_version_number;
4363 /* Run RW signature verification and get status */
4364 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4366 struct __ec_align4 ec_response_rwsig_check_status {
4370 /* For controlling RWSIG task */
4371 #define EC_CMD_RWSIG_ACTION 0x011D
4374 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4375 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4378 struct __ec_align4 ec_params_rwsig_action {
4382 /* Run verification on a slot */
4383 #define EC_CMD_EFS_VERIFY 0x011E
4385 struct __ec_align1 ec_params_efs_verify {
4386 uint8_t region; /* enum ec_flash_region */
4390 * Retrieve info from Cros Board Info store. Response is based on the data
4391 * type. Integers return a uint32. Strings return a string, using the response
4392 * size to determine how big it is.
4394 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
4396 * Write info into Cros Board Info on EEPROM. Write fails if the board has
4397 * hardware write-protect enabled.
4399 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
4402 CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
4403 CBI_TAG_OEM_ID = 1, /* uint8_t */
4404 CBI_TAG_SKU_ID = 2, /* uint8_t */
4409 * Flags to control read operation
4411 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
4412 * write was successful without reboot.
4414 #define CBI_GET_RELOAD (1 << 0)
4416 struct __ec_align4 ec_params_get_cbi {
4417 uint32_t type; /* enum cbi_data_tag */
4418 uint32_t flag; /* CBI_GET_* */
4422 * Flags to control write behavior.
4424 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
4425 * useful when writing multiple fields in a row.
4426 * INIT: Needs to be set when creating a new CBI from scratch. All fields
4427 * will be initialized to zero first.
4429 #define CBI_SET_NO_SYNC (1 << 0)
4430 #define CBI_SET_INIT (1 << 1)
4432 struct __ec_align1 ec_params_set_cbi {
4433 uint32_t tag; /* enum cbi_data_tag */
4434 uint32_t flag; /* CBI_SET_* */
4435 uint32_t size; /* Data size */
4436 uint8_t data[]; /* For string and raw data */
4439 /*****************************************************************************/
4440 /* The command range 0x200-0x2FF is reserved for Rotor. */
4442 /*****************************************************************************/
4444 * Reserve a range of host commands for the CR51 firmware.
4446 #define EC_CMD_CR51_BASE 0x0300
4447 #define EC_CMD_CR51_LAST 0x03FF
4449 /*****************************************************************************/
4450 /* Fingerprint MCU commands: range 0x0400-0x040x */
4452 /* Fingerprint SPI sensor passthru command: prototyping ONLY */
4453 #define EC_CMD_FP_PASSTHRU 0x0400
4455 #define EC_FP_FLAG_NOT_COMPLETE 0x1
4457 struct __ec_align2 ec_params_fp_passthru {
4458 uint16_t len; /* Number of bytes to write then read */
4459 uint16_t flags; /* EC_FP_FLAG_xxx */
4460 uint8_t data[]; /* Data to send */
4463 /* Fingerprint sensor configuration command: prototyping ONLY */
4464 #define EC_CMD_FP_SENSOR_CONFIG 0x0401
4466 #define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4468 struct __ec_align2 ec_params_fp_sensor_config {
4469 uint8_t count; /* Number of setup registers */
4471 * the value to send to each of the 'count' setup registers
4472 * is stored in the 'data' array for 'len' bytes just after
4475 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4479 /* Configure the Fingerprint MCU behavior */
4480 #define EC_CMD_FP_MODE 0x0402
4482 /* Put the sensor in its lowest power mode */
4483 #define FP_MODE_DEEPSLEEP (1<<0)
4484 /* Wait to see a finger on the sensor */
4485 #define FP_MODE_FINGER_DOWN (1<<1)
4486 /* Poll until the finger has left the sensor */
4487 #define FP_MODE_FINGER_UP (1<<2)
4488 /* Capture the current finger image */
4489 #define FP_MODE_CAPTURE (1<<3)
4490 /* special value: don't change anything just read back current mode */
4491 #define FP_MODE_DONT_CHANGE (1<<31)
4493 struct __ec_align4 ec_params_fp_mode {
4494 uint32_t mode; /* as defined by FP_MODE_ constants */
4498 struct __ec_align4 ec_response_fp_mode {
4499 uint32_t mode; /* as defined by FP_MODE_ constants */
4503 /* Retrieve Fingerprint sensor information */
4504 #define EC_CMD_FP_INFO 0x0403
4506 struct __ec_align2 ec_response_fp_info {
4507 /* Sensor identification */
4509 uint32_t product_id;
4512 /* Image frame characteristics */
4513 uint32_t frame_size;
4514 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4520 /* Get the last captured finger frame: TODO: will be AES-encrypted */
4521 #define EC_CMD_FP_FRAME 0x0404
4523 struct __ec_align4 ec_params_fp_frame {
4528 /*****************************************************************************/
4529 /* Touchpad MCU commands: range 0x0500-0x05FF */
4531 /* Perform touchpad self test */
4532 #define EC_CMD_TP_SELF_TEST 0x0500
4534 /* Get number of frame types, and the size of each type */
4535 #define EC_CMD_TP_FRAME_INFO 0x0501
4537 struct __ec_align4 ec_response_tp_frame_info {
4539 uint32_t frame_sizes[0];
4542 /* Create a snapshot of current frame readings */
4543 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4545 /* Read the frame */
4546 #define EC_CMD_TP_FRAME_GET 0x0503
4548 struct __ec_align4 ec_params_tp_frame_get {
4549 uint32_t frame_index;
4554 /*****************************************************************************/
4556 * Reserve a range of host commands for board-specific, experimental, or
4557 * special purpose features. These can be (re)used without updating this file.
4559 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4560 * their EC commands for easier development, testing, debugging, and support.
4562 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4563 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4565 * In your experimental code, you may want to do something like this:
4567 * #define EC_CMD_MAGIC_FOO 0x0000
4568 * #define EC_CMD_MAGIC_BAR 0x0001
4569 * #define EC_CMD_MAGIC_HEY 0x0002
4571 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4574 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4577 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4580 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4581 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4584 * Given the private host command offset, calculate the true private host
4587 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4588 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4590 /*****************************************************************************/
4594 * Some platforms have sub-processors chained to each other. For example.
4596 * AP <--> EC <--> PD MCU
4598 * The top 2 bits of the command number are used to indicate which device the
4599 * command is intended for. Device 0 is always the device receiving the
4600 * command; other device mapping is board-specific.
4602 * When a device receives a command to be passed to a sub-processor, it passes
4603 * it on with the device number set back to 0. This allows the sub-processor
4604 * to remain blissfully unaware of whether the command originated on the next
4605 * device up the chain, or was passed through from the AP.
4607 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4608 * AP sends command 0x4002 to the EC
4609 * EC sends command 0x0002 to the PD MCU
4610 * EC forwards PD MCU response back to the AP
4613 /* Offset and max command number for sub-device n */
4614 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4615 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4617 /*****************************************************************************/
4619 * Deprecated constants. These constants have been renamed for clarity. The
4620 * meaning and size has not changed. Programs that use the old names should
4621 * switch to the new names soon, as the old names may not be carried forward
4624 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4625 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4626 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4628 #endif /* !__ACPI__ && !__KERNEL__ */
4630 #endif /* __CROS_EC_COMMANDS_H */