1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Host communication command constants for ChromeOS EC
5 * Copyright (C) 2012 Google, Inc
7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
11 /* Host communication command constants for Chrome EC */
13 #ifndef __CROS_EC_COMMANDS_H
14 #define __CROS_EC_COMMANDS_H
19 #define BUILD_ASSERT(_cond)
22 * Current version of this protocol
24 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
25 * determined in other ways. Remove this once the kernel code no longer
28 #define EC_PROTO_VERSION 0x00000002
30 /* Command version mask */
31 #define EC_VER_MASK(version) (1UL << (version))
33 /* I/O addresses for ACPI commands */
34 #define EC_LPC_ADDR_ACPI_DATA 0x62
35 #define EC_LPC_ADDR_ACPI_CMD 0x66
37 /* I/O addresses for host command */
38 #define EC_LPC_ADDR_HOST_DATA 0x200
39 #define EC_LPC_ADDR_HOST_CMD 0x204
41 /* I/O addresses for host command args and params */
42 /* Protocol version 2 */
43 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
44 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
45 * EC_PROTO2_MAX_PARAM_SIZE
47 /* Protocol version 3 */
48 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
49 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
52 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
53 * and they tell the kernel that so we have to think of it as two parts.
55 #define EC_HOST_CMD_REGION0 0x800
56 #define EC_HOST_CMD_REGION1 0x880
57 #define EC_HOST_CMD_REGION_SIZE 0x80
59 /* EC command register bit functions */
60 #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
61 #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
62 #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
63 #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
64 #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
65 #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
66 #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
68 #define EC_LPC_ADDR_MEMMAP 0x900
69 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
70 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
72 /* The offset address of each type of data in mapped memory. */
73 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
74 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
75 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
76 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
77 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
78 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
79 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
80 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
81 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
82 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
83 /* Unused 0x28 - 0x2f */
84 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
85 /* Unused 0x31 - 0x33 */
86 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
87 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
88 /* Battery values are all 32 bits */
89 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
90 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
91 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
92 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
93 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
94 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
95 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
96 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
97 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
98 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
99 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
100 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
101 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
102 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
103 /* Unused 0x84 - 0x8f */
104 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
106 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
107 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
108 /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
111 /* Define the format of the accelerometer mapped memory status byte. */
112 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
113 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
114 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
116 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
117 #define EC_TEMP_SENSOR_ENTRIES 16
119 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
121 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
123 #define EC_TEMP_SENSOR_B_ENTRIES 8
125 /* Special values for mapped temperature sensors */
126 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
127 #define EC_TEMP_SENSOR_ERROR 0xfe
128 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
129 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
131 * The offset of temperature value stored in mapped memory. This allows
132 * reporting a temperature range of 200K to 454K = -73C to 181C.
134 #define EC_TEMP_SENSOR_OFFSET 200
137 * Number of ALS readings at EC_MEMMAP_ALS
139 #define EC_ALS_ENTRIES 2
142 * The default value a temperature sensor will return when it is present but
143 * has not been read this boot. This is a reasonable number to avoid
144 * triggering alarms on the host.
146 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
148 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
149 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
150 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
152 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
153 #define EC_BATT_FLAG_AC_PRESENT 0x01
154 #define EC_BATT_FLAG_BATT_PRESENT 0x02
155 #define EC_BATT_FLAG_DISCHARGING 0x04
156 #define EC_BATT_FLAG_CHARGING 0x08
157 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
159 /* Switch flags at EC_MEMMAP_SWITCHES */
160 #define EC_SWITCH_LID_OPEN 0x01
161 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
162 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
163 /* Was recovery requested via keyboard; now unused. */
164 #define EC_SWITCH_IGNORE1 0x08
165 /* Recovery requested via dedicated signal (from servo board) */
166 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
167 /* Was fake developer mode switch; now unused. Remove in next refactor. */
168 #define EC_SWITCH_IGNORE0 0x20
170 /* Host command interface flags */
171 /* Host command interface supports LPC args (LPC interface only) */
172 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
173 /* Host command interface supports version 3 protocol */
174 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
176 /* Wireless switch flags */
177 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
178 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
179 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
180 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
181 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
184 * This header file is used in coreboot both in C and ACPI code. The ACPI code
185 * is pre-processed to handle constants but the ASL compiler is unable to
186 * handle actual C code so keep it separate.
191 * Attributes for EC request and response packets. Just defining __packed
192 * results in inefficient assembly code on ARM, if the structure is actually
193 * 32-bit aligned, as it should be for all buffers.
195 * Be very careful when adding these to existing structures. They will round
196 * up the structure size to the specified boundary.
198 * Also be very careful to make that if a structure is included in some other
199 * parent structure that the alignment will still be true given the packing of
200 * the parent structure. This is particularly important if the sub-structure
201 * will be passed as a pointer to another function, since that function will
202 * not know about the misaligment caused by the parent structure's packing.
204 * Also be very careful using __packed - particularly when nesting non-packed
205 * structures inside packed ones. In fact, DO NOT use __packed directly;
206 * always use one of these attributes.
208 * Once everything is annotated properly, the following search strings should
209 * not return ANY matches in this file other than right here:
211 * "__packed" - generates inefficient code; all sub-structs must also be packed
213 * "struct [^_]" - all structs should be annotated, except for structs that are
214 * members of other structs/unions (and their original declarations should be
219 * Packed structures make no assumption about alignment, so they do inefficient
222 #define __ec_align1 __packed
223 #define __ec_align2 __packed
224 #define __ec_align4 __packed
225 #define __ec_align_size1 __packed
226 #define __ec_align_offset1 __packed
227 #define __ec_align_offset2 __packed
228 #define __ec_todo_packed __packed
229 #define __ec_todo_unpacked
232 /* LPC command status byte masks */
233 /* EC has written a byte in the data register and host hasn't read it yet */
234 #define EC_LPC_STATUS_TO_HOST 0x01
235 /* Host has written a command/data byte and the EC hasn't read it yet */
236 #define EC_LPC_STATUS_FROM_HOST 0x02
237 /* EC is processing a command */
238 #define EC_LPC_STATUS_PROCESSING 0x04
239 /* Last write to EC was a command, not data */
240 #define EC_LPC_STATUS_LAST_CMD 0x08
241 /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
242 #define EC_LPC_STATUS_BURST_MODE 0x10
243 /* SCI event is pending (requesting SCI query) */
244 #define EC_LPC_STATUS_SCI_PENDING 0x20
245 /* SMI event is pending (requesting SMI query) */
246 #define EC_LPC_STATUS_SMI_PENDING 0x40
248 #define EC_LPC_STATUS_RESERVED 0x80
251 * EC is busy. This covers both the EC processing a command, and the host has
252 * written a new command but the EC hasn't picked it up yet.
254 #define EC_LPC_STATUS_BUSY_MASK \
255 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
257 /* Host command response codes */
260 EC_RES_INVALID_COMMAND = 1,
262 EC_RES_INVALID_PARAM = 3,
263 EC_RES_ACCESS_DENIED = 4,
264 EC_RES_INVALID_RESPONSE = 5,
265 EC_RES_INVALID_VERSION = 6,
266 EC_RES_INVALID_CHECKSUM = 7,
267 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
268 EC_RES_UNAVAILABLE = 9, /* No response available */
269 EC_RES_TIMEOUT = 10, /* We got a timeout */
270 EC_RES_OVERFLOW = 11, /* Table / data overflow */
271 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
272 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
273 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
277 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
278 * EC command uses code 0 to mean "no event pending". We explicitly specify
279 * each value in the enum listing so they won't change if we delete/insert an
280 * item or rearrange the list (it needs to be stable across platforms, not
281 * just within a single compiled instance).
283 enum host_event_code {
284 EC_HOST_EVENT_LID_CLOSED = 1,
285 EC_HOST_EVENT_LID_OPEN = 2,
286 EC_HOST_EVENT_POWER_BUTTON = 3,
287 EC_HOST_EVENT_AC_CONNECTED = 4,
288 EC_HOST_EVENT_AC_DISCONNECTED = 5,
289 EC_HOST_EVENT_BATTERY_LOW = 6,
290 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
291 EC_HOST_EVENT_BATTERY = 8,
292 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
293 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
294 EC_HOST_EVENT_THERMAL = 11,
295 EC_HOST_EVENT_USB_CHARGER = 12,
296 EC_HOST_EVENT_KEY_PRESSED = 13,
298 * EC has finished initializing the host interface. The host can check
299 * for this event following sending a EC_CMD_REBOOT_EC command to
300 * determine when the EC is ready to accept subsequent commands.
302 EC_HOST_EVENT_INTERFACE_READY = 14,
303 /* Keyboard recovery combo has been pressed */
304 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
306 /* Shutdown due to thermal overload */
307 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
308 /* Shutdown due to battery level too low */
309 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
311 /* Suggest that the AP throttle itself */
312 EC_HOST_EVENT_THROTTLE_START = 18,
313 /* Suggest that the AP resume normal speed */
314 EC_HOST_EVENT_THROTTLE_STOP = 19,
316 /* Hang detect logic detected a hang and host event timeout expired */
317 EC_HOST_EVENT_HANG_DETECT = 20,
318 /* Hang detect logic detected a hang and warm rebooted the AP */
319 EC_HOST_EVENT_HANG_REBOOT = 21,
320 /* PD MCU triggering host event */
321 EC_HOST_EVENT_PD_MCU = 22,
323 /* EC desires to change state of host-controlled USB mux */
324 EC_HOST_EVENT_USB_MUX = 28,
326 /* EC RTC event occurred */
327 EC_HOST_EVENT_RTC = 26,
330 * The high bit of the event mask is not used as a host event code. If
331 * it reads back as set, then the entire event mask should be
332 * considered invalid by the host. This can happen when reading the
333 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
334 * not initialized on the EC, or improperly configured on the host.
336 EC_HOST_EVENT_INVALID = 32
338 /* Host event mask */
339 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
342 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
343 * @flags: The host argument flags.
344 * @command_version: Command version.
345 * @data_size: The length of data.
346 * @checksum: Checksum; sum of command + flags + command_version + data_size +
347 * all params/response data bytes.
349 struct ec_lpc_host_args {
351 uint8_t command_version;
356 /* Flags for ec_lpc_host_args.flags */
358 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
361 * If EC gets a command and this flag is not set, this is an old-style command.
362 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
363 * unknown length. EC must respond with an old-style response (that is,
364 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
366 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
368 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
370 * If EC responds to a command and this flag is not set, this is an old-style
371 * response. Command version is 0 and response data from EC is at
372 * EC_LPC_ADDR_OLD_PARAM with unknown length.
374 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
376 /*****************************************************************************/
378 * Byte codes returned by EC over SPI interface.
380 * These can be used by the AP to debug the EC interface, and to determine
381 * when the EC is not in a state where it will ever get around to responding
384 * Example of sequence of bytes read from EC for a current good transfer:
385 * 1. - - AP asserts chip select (CS#)
386 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
387 * 3. - - EC starts handling CS# interrupt
388 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
389 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
390 * bytes looking for EC_SPI_FRAME_START
391 * 6. - - EC finishes processing and sets up response
392 * 7. EC_SPI_FRAME_START - AP reads frame byte
393 * 8. (response packet) - AP reads response packet
394 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
395 * 10 - - AP deasserts chip select
396 * 11 - - EC processes CS# interrupt and sets up DMA for
399 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
400 * the following byte values:
406 * Then the EC found an error in the request, or was not ready for the request
407 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
408 * because the EC is unable to tell when the AP is done sending its request.
412 * Framing byte which precedes a response packet from the EC. After sending a
413 * request, the AP will clock in bytes until it sees the framing byte, then
414 * clock in the response packet.
416 #define EC_SPI_FRAME_START 0xec
419 * Padding bytes which are clocked out after the end of a response packet.
421 #define EC_SPI_PAST_END 0xed
424 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
425 * that the AP will send a valid packet header (starting with
426 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
428 #define EC_SPI_RX_READY 0xf8
431 * EC has started receiving the request from the AP, but hasn't started
434 #define EC_SPI_RECEIVING 0xf9
436 /* EC has received the entire request from the AP and is processing it. */
437 #define EC_SPI_PROCESSING 0xfa
440 * EC received bad data from the AP, such as a packet header with an invalid
441 * length. EC will ignore all data until chip select deasserts.
443 #define EC_SPI_RX_BAD_DATA 0xfb
446 * EC received data from the AP before it was ready. That is, the AP asserted
447 * chip select and started clocking data before the EC was ready to receive it.
448 * EC will ignore all data until chip select deasserts.
450 #define EC_SPI_NOT_READY 0xfc
453 * EC was ready to receive a request from the AP. EC has treated the byte sent
454 * by the AP as part of a request packet, or (for old-style ECs) is processing
455 * a fully received packet but is not ready to respond yet.
457 #define EC_SPI_OLD_READY 0xfd
459 /*****************************************************************************/
462 * Protocol version 2 for I2C and SPI send a request this way:
464 * 0 EC_CMD_VERSION0 + (command version)
466 * 2 Length of params = N
467 * 3..N+2 Params, if any
468 * N+3 8-bit checksum of bytes 0..N+2
470 * The corresponding response is:
472 * 0 Result code (EC_RES_*)
473 * 1 Length of params = M
474 * 2..M+1 Params, if any
475 * M+2 8-bit checksum of bytes 0..M+1
477 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
478 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
479 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
480 EC_PROTO2_REQUEST_TRAILER_BYTES)
482 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
483 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
484 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
485 EC_PROTO2_RESPONSE_TRAILER_BYTES)
487 /* Parameter length was limited by the LPC interface */
488 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
490 /* Maximum request and response packet sizes for protocol version 2 */
491 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
492 EC_PROTO2_MAX_PARAM_SIZE)
493 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
494 EC_PROTO2_MAX_PARAM_SIZE)
496 /*****************************************************************************/
499 * Value written to legacy command port / prefix byte to indicate protocol
500 * 3+ structs are being used. Usage is bus-dependent.
502 #define EC_COMMAND_PROTOCOL_3 0xda
504 #define EC_HOST_REQUEST_VERSION 3
507 * struct ec_host_request - Version 3 request from host.
508 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
509 * receives a header with a version it doesn't know how to
511 * @checksum: Checksum of request and data; sum of all bytes including checksum
513 * @command: Command to send (EC_CMD_...)
514 * @command_version: Command version.
515 * @reserved: Unused byte in current protocol version; set to 0.
516 * @data_len: Length of data which follows this header.
518 struct ec_host_request {
519 uint8_t struct_version;
522 uint8_t command_version;
527 #define EC_HOST_RESPONSE_VERSION 3
530 * struct ec_host_response - Version 3 response from EC.
531 * @struct_version: Struct version (=3).
532 * @checksum: Checksum of response and data; sum of all bytes including
533 * checksum should total to 0.
534 * @result: EC's response to the command (separate from communication failure)
535 * @data_len: Length of data which follows this header.
536 * @reserved: Unused bytes in current protocol version; set to 0.
538 struct ec_host_response {
539 uint8_t struct_version;
546 /*****************************************************************************/
550 * Each command is an 16-bit command value. Commands which take params or
551 * return response data specify structures for that data. If no structure is
552 * specified, the command does not input or output data, respectively.
553 * Parameter/response length is implicit in the structs. Some underlying
554 * communication protocols (I2C, SPI) may add length or checksum headers, but
555 * those are implementation-dependent and not defined here.
557 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
558 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
561 /*****************************************************************************/
562 /* General / test commands */
565 * Get protocol version, used to deal with non-backward compatible protocol
568 #define EC_CMD_PROTO_VERSION 0x0000
571 * struct ec_response_proto_version - Response to the proto version command.
572 * @version: The protocol version.
574 struct ec_response_proto_version {
579 * Hello. This is a simple command to test the EC is responsive to
582 #define EC_CMD_HELLO 0x0001
585 * struct ec_params_hello - Parameters to the hello command.
586 * @in_data: Pass anything here.
588 struct ec_params_hello {
593 * struct ec_response_hello - Response to the hello command.
594 * @out_data: Output will be in_data + 0x01020304.
596 struct ec_response_hello {
600 /* Get version number */
601 #define EC_CMD_GET_VERSION 0x0002
603 enum ec_current_image {
604 EC_IMAGE_UNKNOWN = 0,
610 * struct ec_response_get_version - Response to the get version command.
611 * @version_string_ro: Null-terminated RO firmware version string.
612 * @version_string_rw: Null-terminated RW firmware version string.
613 * @reserved: Unused bytes; was previously RW-B firmware version string.
614 * @current_image: One of ec_current_image.
616 struct ec_response_get_version {
617 char version_string_ro[32];
618 char version_string_rw[32];
620 uint32_t current_image;
624 #define EC_CMD_READ_TEST 0x0003
627 * struct ec_params_read_test - Parameters for the read test command.
628 * @offset: Starting value for read buffer.
629 * @size: Size to read in bytes.
631 struct ec_params_read_test {
637 * struct ec_response_read_test - Response to the read test command.
638 * @data: Data returned by the read test command.
640 struct ec_response_read_test {
645 * Get build information
647 * Response is null-terminated string.
649 #define EC_CMD_GET_BUILD_INFO 0x0004
652 #define EC_CMD_GET_CHIP_INFO 0x0005
655 * struct ec_response_get_chip_info - Response to the get chip info command.
656 * @vendor: Null-terminated string for chip vendor.
657 * @name: Null-terminated string for chip name.
658 * @revision: Null-terminated string for chip mask version.
660 struct ec_response_get_chip_info {
666 /* Get board HW version */
667 #define EC_CMD_GET_BOARD_VERSION 0x0006
670 * struct ec_response_board_version - Response to the board version command.
671 * @board_version: A monotonously incrementing number.
673 struct ec_response_board_version {
674 uint16_t board_version;
678 * Read memory-mapped data.
680 * This is an alternate interface to memory-mapped data for bus protocols
681 * which don't support direct-mapped memory - I2C, SPI, etc.
683 * Response is params.size bytes of data.
685 #define EC_CMD_READ_MEMMAP 0x0007
688 * struct ec_params_read_memmap - Parameters for the read memory map command.
689 * @offset: Offset in memmap (EC_MEMMAP_*).
690 * @size: Size to read in bytes.
692 struct ec_params_read_memmap {
697 /* Read versions supported for a command */
698 #define EC_CMD_GET_CMD_VERSIONS 0x0008
701 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
702 * @cmd: Command to check.
704 struct ec_params_get_cmd_versions {
709 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
711 * @cmd: Command to check.
713 struct ec_params_get_cmd_versions_v1 {
718 * struct ec_response_get_cmd_version - Response to the get command versions.
719 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
722 struct ec_response_get_cmd_versions {
723 uint32_t version_mask;
727 * Check EC communications status (busy). This is needed on i2c/spi but not
728 * on lpc since it has its own out-of-band busy indicator.
730 * lpc must read the status from the command register. Attempting this on
731 * lpc will overwrite the args/parameter space and corrupt its data.
733 #define EC_CMD_GET_COMMS_STATUS 0x0009
735 /* Avoid using ec_status which is for return values */
736 enum ec_comms_status {
737 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
741 * struct ec_response_get_comms_status - Response to the get comms status
743 * @flags: Mask of enum ec_comms_status.
745 struct ec_response_get_comms_status {
746 uint32_t flags; /* Mask of enum ec_comms_status */
749 /* Fake a variety of responses, purely for testing purposes. */
750 #define EC_CMD_TEST_PROTOCOL 0x000A
752 /* Tell the EC what to send back to us. */
753 struct ec_params_test_protocol {
759 /* Here it comes... */
760 struct ec_response_test_protocol {
764 /* Get protocol information */
765 #define EC_CMD_GET_PROTOCOL_INFO 0x000B
767 /* Flags for ec_response_get_protocol_info.flags */
768 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
769 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
772 * struct ec_response_get_protocol_info - Response to the get protocol info.
773 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
775 * @max_request_packet_size: Maximum request packet size in bytes.
776 * @max_response_packet_size: Maximum response packet size in bytes.
777 * @flags: see EC_PROTOCOL_INFO_*
779 struct ec_response_get_protocol_info {
780 /* Fields which exist if at least protocol version 3 supported */
781 uint32_t protocol_versions;
782 uint16_t max_request_packet_size;
783 uint16_t max_response_packet_size;
788 /*****************************************************************************/
789 /* Get/Set miscellaneous values */
791 /* The upper byte of .flags tells what to do (nothing means "get") */
792 #define EC_GSV_SET 0x80000000
795 * The lower three bytes of .flags identifies the parameter, if that has
796 * meaning for an individual command.
798 #define EC_GSV_PARAM_MASK 0x00ffffff
800 struct ec_params_get_set_value {
805 struct ec_response_get_set_value {
810 /* More than one command can use these structs to get/set parameters. */
811 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
813 /*****************************************************************************/
814 /* List the features supported by the firmware */
815 #define EC_CMD_GET_FEATURES 0x000D
817 /* Supported features */
818 enum ec_feature_code {
820 * This image contains a limited set of features. Another image
821 * in RW partition may support more features.
823 EC_FEATURE_LIMITED = 0,
825 * Commands for probing/reading/writing/erasing the flash in the
828 EC_FEATURE_FLASH = 1,
830 * Can control the fan speed directly.
832 EC_FEATURE_PWM_FAN = 2,
834 * Can control the intensity of the keyboard backlight.
836 EC_FEATURE_PWM_KEYB = 3,
838 * Support Google lightbar, introduced on Pixel.
840 EC_FEATURE_LIGHTBAR = 4,
841 /* Control of LEDs */
843 /* Exposes an interface to control gyro and sensors.
844 * The host goes through the EC to access these sensors.
845 * In addition, the EC may provide composite sensors, like lid angle.
847 EC_FEATURE_MOTION_SENSE = 6,
848 /* The keyboard is controlled by the EC */
850 /* The AP can use part of the EC flash as persistent storage. */
851 EC_FEATURE_PSTORE = 8,
852 /* The EC monitors BIOS port 80h, and can return POST codes. */
853 EC_FEATURE_PORT80 = 9,
855 * Thermal management: include TMP specific commands.
856 * Higher level than direct fan control.
858 EC_FEATURE_THERMAL = 10,
859 /* Can switch the screen backlight on/off */
860 EC_FEATURE_BKLIGHT_SWITCH = 11,
861 /* Can switch the wifi module on/off */
862 EC_FEATURE_WIFI_SWITCH = 12,
863 /* Monitor host events, through for example SMI or SCI */
864 EC_FEATURE_HOST_EVENTS = 13,
865 /* The EC exposes GPIO commands to control/monitor connected devices. */
866 EC_FEATURE_GPIO = 14,
867 /* The EC can send i2c messages to downstream devices. */
869 /* Command to control charger are included */
870 EC_FEATURE_CHARGER = 16,
871 /* Simple battery support. */
872 EC_FEATURE_BATTERY = 17,
874 * Support Smart battery protocol
875 * (Common Smart Battery System Interface Specification)
877 EC_FEATURE_SMART_BATTERY = 18,
878 /* EC can detect when the host hangs. */
879 EC_FEATURE_HANG_DETECT = 19,
880 /* Report power information, for pit only */
882 /* Another Cros EC device is present downstream of this one */
883 EC_FEATURE_SUB_MCU = 21,
884 /* Support USB Power delivery (PD) commands */
885 EC_FEATURE_USB_PD = 22,
886 /* Control USB multiplexer, for audio through USB port for instance. */
887 EC_FEATURE_USB_MUX = 23,
888 /* Motion Sensor code has an internal software FIFO */
889 EC_FEATURE_MOTION_SENSE_FIFO = 24,
890 /* Support temporary secure vstore */
891 EC_FEATURE_VSTORE = 25,
892 /* EC decides on USB-C SS mux state, muxes configured by host */
893 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
894 /* EC has RTC feature that can be controlled by host commands */
896 /* The MCU exposes a Fingerprint sensor */
897 EC_FEATURE_FINGERPRINT = 28,
898 /* The MCU exposes a Touchpad */
899 EC_FEATURE_TOUCHPAD = 29,
900 /* The MCU has RWSIG task enabled */
901 EC_FEATURE_RWSIG = 30,
902 /* EC has device events support */
903 EC_FEATURE_DEVICE_EVENT = 31,
904 /* EC supports the unified wake masks for LPC/eSPI systems */
905 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
906 /* EC supports 64-bit host events */
907 EC_FEATURE_HOST_EVENT64 = 33,
908 /* EC runs code in RAM (not in place, a.k.a. XIP) */
909 EC_FEATURE_EXEC_IN_RAM = 34,
910 /* EC supports CEC commands */
912 /* EC supports tight sensor timestamping. */
913 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
915 * EC supports tablet mode detection aligned to Chrome and allows
916 * setting of threshold by host command using
917 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
919 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
920 /* EC supports audio codec. */
921 EC_FEATURE_AUDIO_CODEC = 38,
922 /* EC Supports SCP. */
924 /* The MCU is an Integrated Sensor Hub */
928 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
929 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
931 struct ec_response_get_features {
935 /*****************************************************************************/
939 #define EC_CMD_FLASH_INFO 0x0010
942 * struct ec_response_flash_info - Response to the flash info command.
943 * @flash_size: Usable flash size in bytes.
944 * @write_block_size: Write block size. Write offset and size must be a
946 * @erase_block_size: Erase block size. Erase offset and size must be a
948 * @protect_block_size: Protection block size. Protection offset and size
949 * must be a multiple of this.
951 * Version 0 returns these fields.
953 struct ec_response_flash_info {
955 uint32_t write_block_size;
956 uint32_t erase_block_size;
957 uint32_t protect_block_size;
961 * Flags for version 1+ flash info command
962 * EC flash erases bits to 0 instead of 1.
964 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
967 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
968 * @flash_size: Usable flash size in bytes.
969 * @write_block_size: Write block size. Write offset and size must be a
971 * @erase_block_size: Erase block size. Erase offset and size must be a
973 * @protect_block_size: Protection block size. Protection offset and size
974 * must be a multiple of this.
975 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
976 * size is exactly this and offset is a multiple of this.
977 * For example, an EC may have a write buffer which can do
978 * half-page operations if data is aligned, and a slower
979 * word-at-a-time write mode.
980 * @flags: Flags; see EC_FLASH_INFO_*
982 * Version 1 returns the same initial fields as version 0, with additional
985 * gcc anonymous structs don't seem to get along with the __packed directive;
986 * if they did we'd define the version 0 structure as a sub-structure of this
989 struct ec_response_flash_info_1 {
990 /* Version 0 fields; see above for description */
992 uint32_t write_block_size;
993 uint32_t erase_block_size;
994 uint32_t protect_block_size;
996 /* Version 1 adds these fields: */
997 uint32_t write_ideal_size;
1004 * Response is params.size bytes of data.
1006 #define EC_CMD_FLASH_READ 0x0011
1009 * struct ec_params_flash_read - Parameters for the flash read command.
1010 * @offset: Byte offset to read.
1011 * @size: Size to read in bytes.
1013 struct ec_params_flash_read {
1019 #define EC_CMD_FLASH_WRITE 0x0012
1020 #define EC_VER_FLASH_WRITE 1
1022 /* Version 0 of the flash command supported only 64 bytes of data */
1023 #define EC_FLASH_WRITE_VER0_SIZE 64
1026 * struct ec_params_flash_write - Parameters for the flash write command.
1027 * @offset: Byte offset to write.
1028 * @size: Size to write in bytes.
1030 struct ec_params_flash_write {
1033 /* Followed by data to write */
1037 #define EC_CMD_FLASH_ERASE 0x0013
1040 * struct ec_params_flash_erase - Parameters for the flash erase command.
1041 * @offset: Byte offset to erase.
1042 * @size: Size to erase in bytes.
1044 struct ec_params_flash_erase {
1050 * Get/set flash protection.
1052 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1053 * firmware write protect GPIO, not all flags will take effect immediately;
1054 * some flags require a subsequent hard reset to take effect. Check the
1055 * returned flags bits to see what actually happened.
1057 * If mask=0, simply returns the current flags state.
1059 #define EC_CMD_FLASH_PROTECT 0x0015
1060 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1062 /* Flags for flash protection */
1063 /* RO flash code protected when the EC boots */
1064 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1066 * RO flash code protected now. If this bit is set, at-boot status cannot
1069 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1070 /* Entire flash code protected now, until reboot. */
1071 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1072 /* Flash write protect GPIO is asserted now */
1073 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1074 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1075 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1077 * Error - flash protection is in inconsistent state. At least one bank of
1078 * flash which should be protected is not protected. Usually fixed by
1079 * re-requesting the desired flags, or by a hard reset if that fails.
1081 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1082 /* Entire flash code protected when the EC boots */
1083 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1086 * struct ec_params_flash_protect - Parameters for the flash protect command.
1087 * @mask: Bits in flags to apply.
1088 * @flags: New flags to apply.
1090 struct ec_params_flash_protect {
1096 * struct ec_response_flash_protect - Response to the flash protect command.
1097 * @flags: Current value of flash protect flags.
1098 * @valid_flags: Flags which are valid on this platform. This allows the
1099 * caller to distinguish between flags which aren't set vs. flags
1100 * which can't be set on this platform.
1101 * @writable_flags: Flags which can be changed given the current protection
1104 struct ec_response_flash_protect {
1106 uint32_t valid_flags;
1107 uint32_t writable_flags;
1111 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1112 * write protect. These commands may be reused with version > 0.
1115 /* Get the region offset/size */
1116 #define EC_CMD_FLASH_REGION_INFO 0x0016
1117 #define EC_VER_FLASH_REGION_INFO 1
1119 enum ec_flash_region {
1120 /* Region which holds read-only EC image */
1121 EC_FLASH_REGION_RO = 0,
1122 /* Region which holds rewritable EC image */
1125 * Region which should be write-protected in the factory (a superset of
1126 * EC_FLASH_REGION_RO)
1128 EC_FLASH_REGION_WP_RO,
1129 /* Number of regions */
1130 EC_FLASH_REGION_COUNT,
1134 * struct ec_params_flash_region_info - Parameters for the flash region info
1136 * @region: Flash region; see EC_FLASH_REGION_*
1138 struct ec_params_flash_region_info {
1142 struct ec_response_flash_region_info {
1147 /* Read/write VbNvContext */
1148 #define EC_CMD_VBNV_CONTEXT 0x0017
1149 #define EC_VER_VBNV_CONTEXT 1
1150 #define EC_VBNV_BLOCK_SIZE 16
1152 enum ec_vbnvcontext_op {
1153 EC_VBNV_CONTEXT_OP_READ,
1154 EC_VBNV_CONTEXT_OP_WRITE,
1157 struct ec_params_vbnvcontext {
1159 uint8_t block[EC_VBNV_BLOCK_SIZE];
1162 struct ec_response_vbnvcontext {
1163 uint8_t block[EC_VBNV_BLOCK_SIZE];
1166 /*****************************************************************************/
1169 /* Get fan target RPM */
1170 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1172 struct ec_response_pwm_get_fan_rpm {
1176 /* Set target fan RPM */
1177 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1179 struct ec_params_pwm_set_fan_target_rpm {
1183 /* Get keyboard backlight */
1184 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1186 struct ec_response_pwm_get_keyboard_backlight {
1191 /* Set keyboard backlight */
1192 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1194 struct ec_params_pwm_set_keyboard_backlight {
1198 /* Set target fan PWM duty cycle */
1199 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1201 struct ec_params_pwm_set_fan_duty {
1205 #define EC_CMD_PWM_SET_DUTY 0x0025
1206 /* 16 bit duty cycle, 0xffff = 100% */
1207 #define EC_PWM_MAX_DUTY 0xffff
1210 /* All types, indexed by board-specific enum pwm_channel */
1211 EC_PWM_TYPE_GENERIC = 0,
1212 /* Keyboard backlight */
1213 EC_PWM_TYPE_KB_LIGHT,
1214 /* Display backlight */
1215 EC_PWM_TYPE_DISPLAY_LIGHT,
1219 struct ec_params_pwm_set_duty {
1220 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1221 uint8_t pwm_type; /* ec_pwm_type */
1222 uint8_t index; /* Type-specific index, or 0 if unique */
1225 #define EC_CMD_PWM_GET_DUTY 0x0026
1227 struct ec_params_pwm_get_duty {
1228 uint8_t pwm_type; /* ec_pwm_type */
1229 uint8_t index; /* Type-specific index, or 0 if unique */
1232 struct ec_response_pwm_get_duty {
1233 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1236 /*****************************************************************************/
1238 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1239 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1240 * into a subcommand. We'll make separate structs for subcommands with
1241 * different input args, so that we know how much to expect.
1243 #define EC_CMD_LIGHTBAR_CMD 0x0028
1247 } __ec_todo_unpacked;
1249 #define LB_BATTERY_LEVELS 4
1252 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1253 * host command, but the alignment is the same regardless. Keep it that way.
1255 struct lightbar_params_v0 {
1257 int32_t google_ramp_up;
1258 int32_t google_ramp_down;
1259 int32_t s3s0_ramp_up;
1260 int32_t s0_tick_delay[2]; /* AC=0/1 */
1261 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1262 int32_t s0s3_ramp_down;
1263 int32_t s3_sleep_for;
1265 int32_t s3_ramp_down;
1269 uint8_t osc_min[2]; /* AC=0/1 */
1270 uint8_t osc_max[2]; /* AC=0/1 */
1271 uint8_t w_ofs[2]; /* AC=0/1 */
1273 /* Brightness limits based on the backlight and AC. */
1274 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1275 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1276 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1278 /* Battery level thresholds */
1279 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1281 /* Map [AC][battery_level] to color index */
1282 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1283 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1286 struct rgb_s color[8]; /* 0-3 are Google colors */
1289 struct lightbar_params_v1 {
1291 int32_t google_ramp_up;
1292 int32_t google_ramp_down;
1293 int32_t s3s0_ramp_up;
1294 int32_t s0_tick_delay[2]; /* AC=0/1 */
1295 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1296 int32_t s0s3_ramp_down;
1297 int32_t s3_sleep_for;
1299 int32_t s3_ramp_down;
1300 int32_t tap_tick_delay;
1301 int32_t tap_display_time;
1303 /* Tap-for-battery params */
1304 uint8_t tap_pct_red;
1305 uint8_t tap_pct_green;
1306 uint8_t tap_seg_min_on;
1307 uint8_t tap_seg_max_on;
1308 uint8_t tap_seg_osc;
1312 uint8_t osc_min[2]; /* AC=0/1 */
1313 uint8_t osc_max[2]; /* AC=0/1 */
1314 uint8_t w_ofs[2]; /* AC=0/1 */
1316 /* Brightness limits based on the backlight and AC. */
1317 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1318 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1319 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1321 /* Battery level thresholds */
1322 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1324 /* Map [AC][battery_level] to color index */
1325 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1326 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1329 struct rgb_s color[8]; /* 0-3 are Google colors */
1332 /* Lightbar program */
1333 #define EC_LB_PROG_LEN 192
1334 struct lightbar_program {
1336 uint8_t data[EC_LB_PROG_LEN];
1337 } __ec_todo_unpacked;
1339 struct ec_params_lightbar {
1340 uint8_t cmd; /* Command (see enum lightbar_command) */
1344 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1345 version, get_brightness, get_demo, suspend, resume;
1347 struct __ec_todo_unpacked {
1349 } set_brightness, seq, demo;
1351 struct __ec_todo_unpacked {
1352 uint8_t ctrl, reg, value;
1355 struct __ec_todo_unpacked {
1356 uint8_t led, red, green, blue;
1359 struct __ec_todo_unpacked {
1363 struct __ec_todo_unpacked {
1365 } manual_suspend_ctrl;
1367 struct lightbar_params_v0 set_params_v0;
1368 struct lightbar_params_v1 set_params_v1;
1369 struct lightbar_program set_program;
1373 struct ec_response_lightbar {
1375 struct __ec_todo_unpacked {
1376 struct __ec_todo_unpacked {
1383 struct __ec_todo_unpacked {
1385 } get_seq, get_brightness, get_demo;
1387 struct lightbar_params_v0 get_params_v0;
1388 struct lightbar_params_v1 get_params_v1;
1390 struct __ec_todo_unpacked {
1395 struct __ec_todo_unpacked {
1396 uint8_t red, green, blue;
1400 /* no return params */
1401 } off, on, init, set_brightness, seq, reg, set_rgb,
1402 demo, set_params_v0, set_params_v1,
1403 set_program, manual_suspend_ctrl, suspend, resume;
1407 /* Lightbar commands */
1408 enum lightbar_command {
1409 LIGHTBAR_CMD_DUMP = 0,
1410 LIGHTBAR_CMD_OFF = 1,
1411 LIGHTBAR_CMD_ON = 2,
1412 LIGHTBAR_CMD_INIT = 3,
1413 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1414 LIGHTBAR_CMD_SEQ = 5,
1415 LIGHTBAR_CMD_REG = 6,
1416 LIGHTBAR_CMD_SET_RGB = 7,
1417 LIGHTBAR_CMD_GET_SEQ = 8,
1418 LIGHTBAR_CMD_DEMO = 9,
1419 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1420 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1421 LIGHTBAR_CMD_VERSION = 12,
1422 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1423 LIGHTBAR_CMD_GET_RGB = 14,
1424 LIGHTBAR_CMD_GET_DEMO = 15,
1425 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1426 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1427 LIGHTBAR_CMD_SET_PROGRAM = 18,
1428 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1429 LIGHTBAR_CMD_SUSPEND = 20,
1430 LIGHTBAR_CMD_RESUME = 21,
1434 /*****************************************************************************/
1435 /* LED control commands */
1437 #define EC_CMD_LED_CONTROL 0x0029
1440 /* LED to indicate battery state of charge */
1441 EC_LED_ID_BATTERY_LED = 0,
1443 * LED to indicate system power state (on or in suspend).
1444 * May be on power button or on C-panel.
1446 EC_LED_ID_POWER_LED,
1447 /* LED on power adapter or its plug */
1448 EC_LED_ID_ADAPTER_LED,
1453 /* LED control flags */
1454 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1455 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1457 enum ec_led_colors {
1458 EC_LED_COLOR_RED = 0,
1461 EC_LED_COLOR_YELLOW,
1467 struct ec_params_led_control {
1468 uint8_t led_id; /* Which LED to control */
1469 uint8_t flags; /* Control flags */
1471 uint8_t brightness[EC_LED_COLOR_COUNT];
1474 struct ec_response_led_control {
1476 * Available brightness value range.
1478 * Range 0 means color channel not present.
1479 * Range 1 means on/off control.
1480 * Other values means the LED is control by PWM.
1482 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1485 /*****************************************************************************/
1486 /* Verified boot commands */
1489 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1490 * reused for other purposes with version > 0.
1493 /* Verified boot hash command */
1494 #define EC_CMD_VBOOT_HASH 0x002A
1496 struct ec_params_vboot_hash {
1497 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1498 uint8_t hash_type; /* enum ec_vboot_hash_type */
1499 uint8_t nonce_size; /* Nonce size; may be 0 */
1500 uint8_t reserved0; /* Reserved; set 0 */
1501 uint32_t offset; /* Offset in flash to hash */
1502 uint32_t size; /* Number of bytes to hash */
1503 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1506 struct ec_response_vboot_hash {
1507 uint8_t status; /* enum ec_vboot_hash_status */
1508 uint8_t hash_type; /* enum ec_vboot_hash_type */
1509 uint8_t digest_size; /* Size of hash digest in bytes */
1510 uint8_t reserved0; /* Ignore; will be 0 */
1511 uint32_t offset; /* Offset in flash which was hashed */
1512 uint32_t size; /* Number of bytes hashed */
1513 uint8_t hash_digest[64]; /* Hash digest data */
1516 enum ec_vboot_hash_cmd {
1517 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1518 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1519 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1520 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1523 enum ec_vboot_hash_type {
1524 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1527 enum ec_vboot_hash_status {
1528 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1529 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1530 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1534 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1535 * If one of these is specified, the EC will automatically update offset and
1536 * size to the correct values for the specified image (RO or RW).
1538 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1539 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1541 /*****************************************************************************/
1543 * Motion sense commands. We'll make separate structs for sub-commands with
1544 * different input args, so that we know how much to expect.
1546 #define EC_CMD_MOTION_SENSE_CMD 0x002B
1548 /* Motion sense commands */
1549 enum motionsense_command {
1551 * Dump command returns all motion sensor data including motion sense
1552 * module flags and individual sensor flags.
1554 MOTIONSENSE_CMD_DUMP = 0,
1557 * Info command returns data describing the details of a given sensor,
1558 * including enum motionsensor_type, enum motionsensor_location, and
1559 * enum motionsensor_chip.
1561 MOTIONSENSE_CMD_INFO = 1,
1564 * EC Rate command is a setter/getter command for the EC sampling rate
1565 * of all motion sensors in milliseconds.
1567 MOTIONSENSE_CMD_EC_RATE = 2,
1570 * Sensor ODR command is a setter/getter command for the output data
1571 * rate of a specific motion sensor in millihertz.
1573 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1576 * Sensor range command is a setter/getter command for the range of
1577 * a specified motion sensor in +/-G's or +/- deg/s.
1579 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1582 * Setter/getter command for the keyboard wake angle. When the lid
1583 * angle is greater than this value, keyboard wake is disabled in S3,
1584 * and when the lid angle goes less than this value, keyboard wake is
1585 * enabled. Note, the lid angle measurement is an approximate,
1586 * un-calibrated value, hence the wake angle isn't exact.
1588 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1591 * Returns a single sensor data.
1593 MOTIONSENSE_CMD_DATA = 6,
1596 * Perform low level calibration.. On sensors that support it, ask to
1597 * do offset calibration.
1599 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1602 * Sensor Offset command is a setter/getter command for the offset used
1603 * for calibration. The offsets can be calculated by the host, or via
1604 * PERFORM_CALIB command.
1606 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1608 /* Number of motionsense sub-commands. */
1609 MOTIONSENSE_NUM_CMDS
1612 enum motionsensor_id {
1613 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1614 EC_MOTION_SENSOR_ACCEL_LID = 1,
1615 EC_MOTION_SENSOR_GYRO = 2,
1618 * Note, if more sensors are added and this count changes, the padding
1619 * in ec_response_motion_sense dump command must be modified.
1621 EC_MOTION_SENSOR_COUNT = 3
1624 /* List of motion sensor types. */
1625 enum motionsensor_type {
1626 MOTIONSENSE_TYPE_ACCEL = 0,
1627 MOTIONSENSE_TYPE_GYRO = 1,
1628 MOTIONSENSE_TYPE_MAG = 2,
1629 MOTIONSENSE_TYPE_PROX = 3,
1630 MOTIONSENSE_TYPE_LIGHT = 4,
1631 MOTIONSENSE_TYPE_ACTIVITY = 5,
1632 MOTIONSENSE_TYPE_BARO = 6,
1633 MOTIONSENSE_TYPE_MAX,
1636 /* List of motion sensor locations. */
1637 enum motionsensor_location {
1638 MOTIONSENSE_LOC_BASE = 0,
1639 MOTIONSENSE_LOC_LID = 1,
1640 MOTIONSENSE_LOC_MAX,
1643 /* List of motion sensor chips. */
1644 enum motionsensor_chip {
1645 MOTIONSENSE_CHIP_KXCJ9 = 0,
1648 /* Module flag masks used for the dump sub-command. */
1649 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1651 /* Sensor flag masks used for the dump sub-command. */
1652 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1655 * Send this value for the data element to only perform a read. If you
1656 * send any other value, the EC will interpret it as data to set and will
1657 * return the actual value set.
1659 #define EC_MOTION_SENSE_NO_VALUE -1
1661 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1663 /* Set Calibration information */
1664 #define MOTION_SENSE_SET_OFFSET 1
1666 struct ec_response_motion_sensor_data {
1667 /* Flags for each sensor. */
1669 /* Sensor number the data comes from */
1671 /* Each sensor is up to 3-axis. */
1674 struct __ec_todo_packed {
1678 struct __ec_todo_unpacked {
1679 uint8_t activity; /* motionsensor_activity */
1681 int16_t add_info[2];
1686 struct ec_params_motion_sense {
1689 /* Used for MOTIONSENSE_CMD_DUMP. */
1690 struct __ec_todo_unpacked {
1695 * Used for MOTIONSENSE_CMD_EC_RATE and
1696 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1698 struct __ec_todo_unpacked {
1699 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1701 } ec_rate, kb_wake_angle;
1703 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1704 struct __ec_todo_packed {
1708 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1709 * the calibration information in the EC.
1710 * If unset, just retrieve calibration information.
1715 * Temperature at calibration, in units of 0.01 C
1716 * 0x8000: invalid / unknown.
1723 * Offset for calibration.
1725 * Accelerometer: 1/1024 g
1726 * Gyro: 1/1024 deg/s
1732 /* Used for MOTIONSENSE_CMD_INFO. */
1733 struct __ec_todo_packed {
1738 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1739 * MOTIONSENSE_CMD_SENSOR_RANGE.
1742 /* Should be element of enum motionsensor_id. */
1745 /* Rounding flag, true for round-up, false for down. */
1750 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1752 } sensor_odr, sensor_range;
1756 struct ec_response_motion_sense {
1758 /* Used for MOTIONSENSE_CMD_DUMP. */
1759 struct __ec_todo_unpacked {
1760 /* Flags representing the motion sensor module. */
1761 uint8_t module_flags;
1763 /* Number of sensors managed directly by the EC. */
1764 uint8_t sensor_count;
1767 * Sensor data is truncated if response_max is too small
1768 * for holding all the data.
1770 struct ec_response_motion_sensor_data sensor[0];
1773 /* Used for MOTIONSENSE_CMD_INFO. */
1774 struct __ec_todo_unpacked {
1775 /* Should be element of enum motionsensor_type. */
1778 /* Should be element of enum motionsensor_location. */
1781 /* Should be element of enum motionsensor_chip. */
1785 /* Used for MOTIONSENSE_CMD_DATA */
1786 struct ec_response_motion_sensor_data data;
1789 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1790 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1791 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1793 struct __ec_todo_unpacked {
1794 /* Current value of the parameter queried. */
1796 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1798 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1799 struct __ec_todo_unpacked {
1802 } sensor_offset, perform_calib;
1806 /*****************************************************************************/
1807 /* USB charging control commands */
1809 /* Set USB port charging mode */
1810 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
1812 struct ec_params_usb_charge_set_mode {
1813 uint8_t usb_port_id;
1817 /*****************************************************************************/
1818 /* Persistent storage for host */
1820 /* Maximum bytes that can be read/written in a single command */
1821 #define EC_PSTORE_SIZE_MAX 64
1823 /* Get persistent storage info */
1824 #define EC_CMD_PSTORE_INFO 0x0040
1826 struct ec_response_pstore_info {
1827 /* Persistent storage size, in bytes */
1828 uint32_t pstore_size;
1829 /* Access size; read/write offset and size must be a multiple of this */
1830 uint32_t access_size;
1834 * Read persistent storage
1836 * Response is params.size bytes of data.
1838 #define EC_CMD_PSTORE_READ 0x0041
1840 struct ec_params_pstore_read {
1841 uint32_t offset; /* Byte offset to read */
1842 uint32_t size; /* Size to read in bytes */
1845 /* Write persistent storage */
1846 #define EC_CMD_PSTORE_WRITE 0x0042
1848 struct ec_params_pstore_write {
1849 uint32_t offset; /* Byte offset to write */
1850 uint32_t size; /* Size to write in bytes */
1851 uint8_t data[EC_PSTORE_SIZE_MAX];
1854 /*****************************************************************************/
1855 /* Real-time clock */
1857 /* RTC params and response structures */
1858 struct ec_params_rtc {
1862 struct ec_response_rtc {
1866 /* These use ec_response_rtc */
1867 #define EC_CMD_RTC_GET_VALUE 0x0044
1868 #define EC_CMD_RTC_GET_ALARM 0x0045
1870 /* These all use ec_params_rtc */
1871 #define EC_CMD_RTC_SET_VALUE 0x0046
1872 #define EC_CMD_RTC_SET_ALARM 0x0047
1874 /* Pass as time param to SET_ALARM to clear the current alarm */
1875 #define EC_RTC_ALARM_CLEAR 0
1877 /*****************************************************************************/
1878 /* Port80 log access */
1880 /* Maximum entries that can be read/written in a single command */
1881 #define EC_PORT80_SIZE_MAX 32
1883 /* Get last port80 code from previous boot */
1884 #define EC_CMD_PORT80_LAST_BOOT 0x0048
1885 #define EC_CMD_PORT80_READ 0x0048
1887 enum ec_port80_subcmd {
1888 EC_PORT80_GET_INFO = 0,
1889 EC_PORT80_READ_BUFFER,
1892 struct ec_params_port80_read {
1895 struct __ec_todo_unpacked {
1897 uint32_t num_entries;
1902 struct ec_response_port80_read {
1904 struct __ec_todo_unpacked {
1906 uint32_t history_size;
1909 struct __ec_todo_unpacked {
1910 uint16_t codes[EC_PORT80_SIZE_MAX];
1915 struct ec_response_port80_last_boot {
1919 /*****************************************************************************/
1920 /* Thermal engine commands. Note that there are two implementations. We'll
1921 * reuse the command number, but the data and behavior is incompatible.
1922 * Version 0 is what originally shipped on Link.
1923 * Version 1 separates the CPU thermal limits from the fan control.
1926 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
1927 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
1929 /* The version 0 structs are opaque. You have to know what they are for
1930 * the get/set commands to make any sense.
1933 /* Version 0 - set */
1934 struct ec_params_thermal_set_threshold {
1935 uint8_t sensor_type;
1936 uint8_t threshold_id;
1940 /* Version 0 - get */
1941 struct ec_params_thermal_get_threshold {
1942 uint8_t sensor_type;
1943 uint8_t threshold_id;
1946 struct ec_response_thermal_get_threshold {
1951 /* The version 1 structs are visible. */
1952 enum ec_temp_thresholds {
1953 EC_TEMP_THRESH_WARN = 0,
1954 EC_TEMP_THRESH_HIGH,
1955 EC_TEMP_THRESH_HALT,
1957 EC_TEMP_THRESH_COUNT
1961 * Thermal configuration for one temperature sensor. Temps are in degrees K.
1962 * Zero values will be silently ignored by the thermal task.
1964 struct ec_thermal_config {
1965 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1966 uint32_t temp_fan_off; /* no active cooling needed */
1967 uint32_t temp_fan_max; /* max active cooling needed */
1970 /* Version 1 - get config for one sensor. */
1971 struct ec_params_thermal_get_threshold_v1 {
1972 uint32_t sensor_num;
1974 /* This returns a struct ec_thermal_config */
1977 * Version 1 - set config for one sensor.
1978 * Use read-modify-write for best results!
1980 struct ec_params_thermal_set_threshold_v1 {
1981 uint32_t sensor_num;
1982 struct ec_thermal_config cfg;
1984 /* This returns no data */
1986 /****************************************************************************/
1988 /* Toggle automatic fan control */
1989 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
1991 /* Get TMP006 calibration data */
1992 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
1994 struct ec_params_tmp006_get_calibration {
1998 struct ec_response_tmp006_get_calibration {
2005 /* Set TMP006 calibration data */
2006 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
2008 struct ec_params_tmp006_set_calibration {
2010 uint8_t reserved[3]; /* Reserved; set 0 */
2017 /* Read raw TMP006 data */
2018 #define EC_CMD_TMP006_GET_RAW 0x0055
2020 struct ec_params_tmp006_get_raw {
2024 struct ec_response_tmp006_get_raw {
2025 int32_t t; /* In 1/100 K */
2026 int32_t v; /* In nV */
2029 /*****************************************************************************/
2030 /* MKBP - Matrix KeyBoard Protocol */
2035 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2036 * expected response size.
2038 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2039 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2040 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2042 #define EC_CMD_MKBP_STATE 0x0060
2045 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2047 #define EC_CMD_MKBP_INFO 0x0061
2049 struct ec_response_mkbp_info {
2052 /* Formerly "switches", which was 0. */
2056 struct ec_params_mkbp_info {
2061 enum ec_mkbp_info_type {
2063 * Info about the keyboard matrix: number of rows and columns.
2065 * Returns struct ec_response_mkbp_info.
2067 EC_MKBP_INFO_KBD = 0,
2070 * For buttons and switches, info about which specifically are
2071 * supported. event_type must be set to one of the values in enum
2074 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2075 * bitmask indicating which buttons or switches are present. See the
2076 * bit inidices below.
2078 EC_MKBP_INFO_SUPPORTED = 1,
2081 * Instantaneous state of buttons and switches.
2083 * event_type must be set to one of the values in enum ec_mkbp_event.
2085 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2086 * indicating the current state of the keyboard matrix.
2088 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2091 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2092 * state of supported buttons.
2094 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2095 * state of supported switches.
2097 EC_MKBP_INFO_CURRENT = 2,
2100 /* Simulate key press */
2101 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2103 struct ec_params_mkbp_simulate_key {
2109 /* Configure keyboard scanning */
2110 #define EC_CMD_MKBP_SET_CONFIG 0x0064
2111 #define EC_CMD_MKBP_GET_CONFIG 0x0065
2114 enum mkbp_config_flags {
2115 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2118 enum mkbp_config_valid {
2119 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2120 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2121 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2122 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2123 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2124 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2125 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2129 * Configuration for our key scanning algorithm.
2131 * Note that this is used as a sub-structure of
2132 * ec_{params/response}_mkbp_get_config.
2134 struct ec_mkbp_config {
2135 uint32_t valid_mask; /* valid fields */
2136 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2137 uint8_t valid_flags; /* which flags are valid */
2138 uint16_t scan_period_us; /* period between start of scans */
2139 /* revert to interrupt mode after no activity for this long */
2140 uint32_t poll_timeout_us;
2142 * minimum post-scan relax time. Once we finish a scan we check
2143 * the time until we are due to start the next one. If this time is
2144 * shorter this field, we use this instead.
2146 uint16_t min_post_scan_delay_us;
2147 /* delay between setting up output and waiting for it to settle */
2148 uint16_t output_settle_us;
2149 uint16_t debounce_down_us; /* time for debounce on key down */
2150 uint16_t debounce_up_us; /* time for debounce on key up */
2151 /* maximum depth to allow for fifo (0 = no keyscan output) */
2152 uint8_t fifo_max_depth;
2155 struct ec_params_mkbp_set_config {
2156 struct ec_mkbp_config config;
2159 struct ec_response_mkbp_get_config {
2160 struct ec_mkbp_config config;
2163 /* Run the key scan emulation */
2164 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2166 enum ec_keyscan_seq_cmd {
2167 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2168 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2169 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2170 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2171 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2174 enum ec_collect_flags {
2176 * Indicates this scan was processed by the EC. Due to timing, some
2177 * scans may be skipped.
2179 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2182 struct ec_collect_item {
2183 uint8_t flags; /* some flags (enum ec_collect_flags) */
2186 struct ec_params_keyscan_seq_ctrl {
2187 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2189 struct __ec_align1 {
2190 uint8_t active; /* still active */
2191 uint8_t num_items; /* number of items */
2192 /* Current item being presented */
2195 struct __ec_todo_unpacked {
2197 * Absolute time for this scan, measured from the
2198 * start of the sequence.
2201 uint8_t scan[0]; /* keyscan data */
2203 struct __ec_align1 {
2204 uint8_t start_item; /* First item to return */
2205 uint8_t num_items; /* Number of items to return */
2210 struct ec_result_keyscan_seq_ctrl {
2212 struct __ec_todo_unpacked {
2213 uint8_t num_items; /* Number of items */
2214 /* Data for each item */
2215 struct ec_collect_item item[0];
2221 * Command for retrieving the next pending MKBP event from the EC device
2223 * The device replies with UNAVAILABLE if there aren't any pending events.
2225 #define EC_CMD_GET_NEXT_EVENT 0x0067
2227 enum ec_mkbp_event {
2228 /* Keyboard matrix changed. The event data is the new matrix state. */
2229 EC_MKBP_EVENT_KEY_MATRIX = 0,
2231 /* New host event. The event data is 4 bytes of host event flags. */
2232 EC_MKBP_EVENT_HOST_EVENT = 1,
2234 /* New Sensor FIFO data. The event data is fifo_info structure. */
2235 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2237 /* The state of the non-matrixed buttons have changed. */
2238 EC_MKBP_EVENT_BUTTON = 3,
2240 /* The state of the switches have changed. */
2241 EC_MKBP_EVENT_SWITCH = 4,
2243 /* EC sent a sysrq command */
2244 EC_MKBP_EVENT_SYSRQ = 6,
2246 /* Notify the AP that something happened on CEC */
2247 EC_MKBP_EVENT_CEC_EVENT = 8,
2249 /* Send an incoming CEC message to the AP */
2250 EC_MKBP_EVENT_CEC_MESSAGE = 9,
2252 /* Number of MKBP events */
2253 EC_MKBP_EVENT_COUNT,
2256 union __ec_align_offset1 ec_response_get_next_data {
2257 uint8_t key_matrix[13];
2260 uint32_t host_event;
2267 union __ec_align_offset1 ec_response_get_next_data_v1 {
2268 uint8_t key_matrix[16];
2269 uint32_t host_event;
2273 uint32_t cec_events;
2274 uint8_t cec_message[16];
2277 struct ec_response_get_next_event {
2279 /* Followed by event data if any */
2280 union ec_response_get_next_data data;
2283 struct ec_response_get_next_event_v1 {
2285 /* Followed by event data if any */
2286 union ec_response_get_next_data_v1 data;
2289 /* Bit indices for buttons and switches.*/
2291 #define EC_MKBP_POWER_BUTTON 0
2292 #define EC_MKBP_VOL_UP 1
2293 #define EC_MKBP_VOL_DOWN 2
2296 #define EC_MKBP_LID_OPEN 0
2297 #define EC_MKBP_TABLET_MODE 1
2298 #define EC_MKBP_BASE_ATTACHED 2
2300 /*****************************************************************************/
2301 /* Temperature sensor commands */
2303 /* Read temperature sensor info */
2304 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
2306 struct ec_params_temp_sensor_get_info {
2310 struct ec_response_temp_sensor_get_info {
2311 char sensor_name[32];
2312 uint8_t sensor_type;
2315 /*****************************************************************************/
2318 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2319 * commands accidentally sent to the wrong interface. See the ACPI section
2323 /*****************************************************************************/
2324 /* Host event commands */
2327 * Host event mask params and response structures, shared by all of the host
2328 * event commands below.
2330 struct ec_params_host_event_mask {
2334 struct ec_response_host_event_mask {
2338 /* These all use ec_response_host_event_mask */
2339 #define EC_CMD_HOST_EVENT_GET_B 0x0087
2340 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
2341 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
2342 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
2344 /* These all use ec_params_host_event_mask */
2345 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
2346 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
2347 #define EC_CMD_HOST_EVENT_CLEAR 0x008C
2348 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
2349 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
2351 /*****************************************************************************/
2352 /* Switch commands */
2354 /* Enable/disable LCD backlight */
2355 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
2357 struct ec_params_switch_enable_backlight {
2361 /* Enable/disable WLAN/Bluetooth */
2362 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
2363 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2365 /* Version 0 params; no response */
2366 struct ec_params_switch_enable_wireless_v0 {
2370 /* Version 1 params */
2371 struct ec_params_switch_enable_wireless_v1 {
2372 /* Flags to enable now */
2375 /* Which flags to copy from now_flags */
2379 * Flags to leave enabled in S3, if they're on at the S0->S3
2380 * transition. (Other flags will be disabled by the S0->S3
2383 uint8_t suspend_flags;
2385 /* Which flags to copy from suspend_flags */
2386 uint8_t suspend_mask;
2389 /* Version 1 response */
2390 struct ec_response_switch_enable_wireless_v1 {
2391 /* Flags to enable now */
2394 /* Flags to leave enabled in S3 */
2395 uint8_t suspend_flags;
2398 /*****************************************************************************/
2399 /* GPIO commands. Only available on EC if write protect has been disabled. */
2401 /* Set GPIO output value */
2402 #define EC_CMD_GPIO_SET 0x0092
2404 struct ec_params_gpio_set {
2409 /* Get GPIO value */
2410 #define EC_CMD_GPIO_GET 0x0093
2412 /* Version 0 of input params and response */
2413 struct ec_params_gpio_get {
2417 struct ec_response_gpio_get {
2421 /* Version 1 of input params and response */
2422 struct ec_params_gpio_get_v1 {
2425 struct __ec_align1 {
2427 } get_value_by_name;
2428 struct __ec_align1 {
2434 struct ec_response_gpio_get_v1 {
2436 struct __ec_align1 {
2438 } get_value_by_name, get_count;
2439 struct __ec_todo_unpacked {
2447 enum gpio_get_subcmd {
2448 EC_GPIO_GET_BY_NAME = 0,
2449 EC_GPIO_GET_COUNT = 1,
2450 EC_GPIO_GET_INFO = 2,
2453 /*****************************************************************************/
2454 /* I2C commands. Only available when flash write protect is unlocked. */
2457 * CAUTION: These commands are deprecated, and are not supported anymore in EC
2458 * builds >= 8398.0.0 (see crosbug.com/p/23570).
2460 * Use EC_CMD_I2C_PASSTHRU instead.
2464 #define EC_CMD_I2C_READ 0x0094
2466 struct ec_params_i2c_read {
2467 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2468 uint8_t read_size; /* Either 8 or 16. */
2473 struct ec_response_i2c_read {
2478 #define EC_CMD_I2C_WRITE 0x0095
2480 struct ec_params_i2c_write {
2482 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2483 uint8_t write_size; /* Either 8 or 16. */
2488 /*****************************************************************************/
2489 /* Charge state commands. Only available when flash write protect unlocked. */
2491 /* Force charge state machine to stop charging the battery or force it to
2492 * discharge the battery.
2494 #define EC_CMD_CHARGE_CONTROL 0x0096
2495 #define EC_VER_CHARGE_CONTROL 1
2497 enum ec_charge_control_mode {
2498 CHARGE_CONTROL_NORMAL = 0,
2499 CHARGE_CONTROL_IDLE,
2500 CHARGE_CONTROL_DISCHARGE,
2503 struct ec_params_charge_control {
2504 uint32_t mode; /* enum charge_control_mode */
2507 /*****************************************************************************/
2509 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2510 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
2513 * Read data from the saved snapshot. If the subcmd parameter is
2514 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2515 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2516 * end of the previous snapshot.
2518 * The params are only looked at in version >= 1 of this command. Prior
2519 * versions will just default to CONSOLE_READ_NEXT behavior.
2521 * Response is null-terminated string. Empty string, if there is no more
2524 #define EC_CMD_CONSOLE_READ 0x0098
2526 enum ec_console_read_subcmd {
2527 CONSOLE_READ_NEXT = 0,
2531 struct ec_params_console_read_v1 {
2532 uint8_t subcmd; /* enum ec_console_read_subcmd */
2535 /*****************************************************************************/
2538 * Cut off battery power immediately or after the host has shut down.
2540 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2541 * EC_RES_SUCCESS if the command was successful.
2542 * EC_RES_ERROR if the cut off command failed.
2544 #define EC_CMD_BATTERY_CUT_OFF 0x0099
2546 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2548 struct ec_params_battery_cutoff {
2552 /*****************************************************************************/
2553 /* USB port mux control. */
2556 * Switch USB mux or return to automatic switching.
2558 #define EC_CMD_USB_MUX 0x009A
2560 struct ec_params_usb_mux {
2564 /*****************************************************************************/
2565 /* LDOs / FETs control. */
2568 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2569 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2573 * Switch on/off a LDO.
2575 #define EC_CMD_LDO_SET 0x009B
2577 struct ec_params_ldo_set {
2585 #define EC_CMD_LDO_GET 0x009C
2587 struct ec_params_ldo_get {
2591 struct ec_response_ldo_get {
2595 /*****************************************************************************/
2601 #define EC_CMD_POWER_INFO 0x009D
2603 struct ec_response_power_info {
2604 uint32_t usb_dev_type;
2605 uint16_t voltage_ac;
2606 uint16_t voltage_system;
2607 uint16_t current_system;
2608 uint16_t usb_current_limit;
2611 /*****************************************************************************/
2612 /* I2C passthru command */
2614 #define EC_CMD_I2C_PASSTHRU 0x009E
2616 /* Read data; if not present, message is a write */
2617 #define EC_I2C_FLAG_READ (1 << 15)
2619 /* Mask for address */
2620 #define EC_I2C_ADDR_MASK 0x3ff
2622 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2623 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2626 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2628 struct ec_params_i2c_passthru_msg {
2629 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2630 uint16_t len; /* Number of bytes to read or write */
2633 struct ec_params_i2c_passthru {
2634 uint8_t port; /* I2C port number */
2635 uint8_t num_msgs; /* Number of messages */
2636 struct ec_params_i2c_passthru_msg msg[];
2637 /* Data to write for all messages is concatenated here */
2640 struct ec_response_i2c_passthru {
2641 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2642 uint8_t num_msgs; /* Number of messages processed */
2643 uint8_t data[]; /* Data read by messages concatenated here */
2646 /*****************************************************************************/
2647 /* Power button hang detect */
2649 #define EC_CMD_HANG_DETECT 0x009F
2651 /* Reasons to start hang detection timer */
2652 /* Power button pressed */
2653 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2656 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2659 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2661 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2662 #define EC_HANG_START_ON_RESUME (1 << 3)
2664 /* Reasons to cancel hang detection */
2666 /* Power button released */
2667 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2669 /* Any host command from AP received */
2670 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2672 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2673 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2676 * If this flag is set, all the other fields are ignored, and the hang detect
2677 * timer is started. This provides the AP a way to start the hang timer
2678 * without reconfiguring any of the other hang detect settings. Note that
2679 * you must previously have configured the timeouts.
2681 #define EC_HANG_START_NOW (1 << 30)
2684 * If this flag is set, all the other fields are ignored (including
2685 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2686 * without reconfiguring any of the other hang detect settings.
2688 #define EC_HANG_STOP_NOW (1 << 31)
2690 struct ec_params_hang_detect {
2691 /* Flags; see EC_HANG_* */
2694 /* Timeout in msec before generating host event, if enabled */
2695 uint16_t host_event_timeout_msec;
2697 /* Timeout in msec before generating warm reboot, if enabled */
2698 uint16_t warm_reboot_timeout_msec;
2701 /*****************************************************************************/
2702 /* Commands for battery charging */
2705 * This is the single catch-all host command to exchange data regarding the
2706 * charge state machine (v2 and up).
2708 #define EC_CMD_CHARGE_STATE 0x00A0
2710 /* Subcommands for this host command */
2711 enum charge_state_command {
2712 CHARGE_STATE_CMD_GET_STATE,
2713 CHARGE_STATE_CMD_GET_PARAM,
2714 CHARGE_STATE_CMD_SET_PARAM,
2715 CHARGE_STATE_NUM_CMDS
2719 * Known param numbers are defined here. Ranges are reserved for board-specific
2720 * params, which are handled by the particular implementations.
2722 enum charge_state_params {
2723 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2724 CS_PARAM_CHG_CURRENT, /* charger current limit */
2725 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2726 CS_PARAM_CHG_STATUS, /* charger-specific status */
2727 CS_PARAM_CHG_OPTION, /* charger-specific options */
2728 /* How many so far? */
2731 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2732 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2733 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2735 /* Other custom param ranges go here... */
2738 struct ec_params_charge_state {
2739 uint8_t cmd; /* enum charge_state_command */
2745 struct __ec_todo_unpacked {
2746 uint32_t param; /* enum charge_state_param */
2749 struct __ec_todo_unpacked {
2750 uint32_t param; /* param to set */
2751 uint32_t value; /* value to set */
2756 struct ec_response_charge_state {
2758 struct __ec_align4 {
2762 int chg_input_current;
2763 int batt_state_of_charge;
2766 struct __ec_align4 {
2770 /* no return values */
2777 * Set maximum battery charging current.
2779 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
2781 struct ec_params_current_limit {
2782 uint32_t limit; /* in mA */
2786 * Set maximum external voltage / current.
2788 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
2790 /* Command v0 is used only on Spring and is obsolete + unsupported */
2791 struct ec_params_external_power_limit_v1 {
2792 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2793 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2796 #define EC_POWER_LIMIT_NONE 0xffff
2798 /* Inform the EC when entering a sleep state */
2799 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
2801 enum host_sleep_event {
2802 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2803 HOST_SLEEP_EVENT_S3_RESUME = 2,
2804 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2805 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2808 struct ec_params_host_sleep_event {
2809 uint8_t sleep_event;
2813 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
2814 * transition failures
2816 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
2818 /* Disable timeout detection for this sleep transition */
2819 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
2821 struct ec_params_host_sleep_event_v1 {
2822 /* The type of sleep being entered or exited. */
2823 uint8_t sleep_event;
2828 /* Parameters that apply for suspend messages. */
2831 * The timeout in milliseconds between when this message
2832 * is received and when the EC will declare sleep
2833 * transition failure if the sleep signal is not
2836 uint16_t sleep_timeout_ms;
2839 /* No parameters for non-suspend messages. */
2843 /* A timeout occurred when this bit is set */
2844 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
2847 * The mask defining which bits correspond to the number of sleep transitions,
2848 * as well as the maximum number of suspend line transitions that will be
2849 * reported back to the host.
2851 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
2853 struct ec_response_host_sleep_event_v1 {
2855 /* Response fields that apply for resume messages. */
2858 * The number of sleep power signal transitions that
2859 * occurred since the suspend message. The high bit
2860 * indicates a timeout occurred.
2862 uint32_t sleep_transitions;
2865 /* No response fields for non-resume messages. */
2869 /*****************************************************************************/
2870 /* Smart battery pass-through */
2872 /* Get / Set 16-bit smart battery registers */
2873 #define EC_CMD_SB_READ_WORD 0x00B0
2874 #define EC_CMD_SB_WRITE_WORD 0x00B1
2876 /* Get / Set string smart battery parameters
2877 * formatted as SMBUS "block".
2879 #define EC_CMD_SB_READ_BLOCK 0x00B2
2880 #define EC_CMD_SB_WRITE_BLOCK 0x00B3
2882 struct ec_params_sb_rd {
2886 struct ec_response_sb_rd_word {
2890 struct ec_params_sb_wr_word {
2895 struct ec_response_sb_rd_block {
2899 struct ec_params_sb_wr_block {
2904 /*****************************************************************************/
2905 /* Battery vendor parameters
2907 * Get or set vendor-specific parameters in the battery. Implementations may
2908 * differ between boards or batteries. On a set operation, the response
2909 * contains the actual value set, which may be rounded or clipped from the
2913 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
2915 enum ec_battery_vendor_param_mode {
2916 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2917 BATTERY_VENDOR_PARAM_MODE_SET,
2920 struct ec_params_battery_vendor_param {
2926 struct ec_response_battery_vendor_param {
2930 /*****************************************************************************/
2931 /* Commands for I2S recording on audio codec. */
2933 #define EC_CMD_CODEC_I2S 0x00BC
2935 enum ec_codec_i2s_subcmd {
2936 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2937 EC_CODEC_SET_GAIN = 0x1,
2938 EC_CODEC_GET_GAIN = 0x2,
2939 EC_CODEC_I2S_ENABLE = 0x3,
2940 EC_CODEC_I2S_SET_CONFIG = 0x4,
2941 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2942 EC_CODEC_I2S_SET_BCLK = 0x6,
2945 enum ec_sample_depth_value {
2946 EC_CODEC_SAMPLE_DEPTH_16 = 0,
2947 EC_CODEC_SAMPLE_DEPTH_24 = 1,
2950 enum ec_i2s_config {
2952 EC_DAI_FMT_RIGHT_J = 1,
2953 EC_DAI_FMT_LEFT_J = 2,
2954 EC_DAI_FMT_PCM_A = 3,
2955 EC_DAI_FMT_PCM_B = 4,
2956 EC_DAI_FMT_PCM_TDM = 5,
2959 struct __ec_todo_packed ec_param_codec_i2s {
2960 /* enum ec_codec_i2s_subcmd */
2964 * EC_CODEC_SET_SAMPLE_DEPTH
2965 * Value should be one of ec_sample_depth_value.
2971 * Value should be 0~43 for both channels.
2973 struct __ec_align1 ec_param_codec_i2s_set_gain {
2979 * EC_CODEC_I2S_ENABLE
2980 * 1 to enable, 0 to disable.
2985 * EC_CODEC_I2S_SET_COFNIG
2986 * Value should be one of ec_i2s_config.
2991 * EC_CODEC_I2S_SET_TDM_CONFIG
2992 * Value should be one of ec_i2s_config.
2994 struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
3003 uint8_t adjacent_to_ch0;
3004 uint8_t adjacent_to_ch1;
3008 * EC_CODEC_I2S_SET_BCLK
3015 * For subcommand EC_CODEC_GET_GAIN.
3017 struct ec_response_codec_gain {
3022 /*****************************************************************************/
3023 /* System commands */
3026 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3027 * necessarily reboot the EC. Rename to "image" or something similar?
3029 #define EC_CMD_REBOOT_EC 0x00D2
3032 enum ec_reboot_cmd {
3033 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
3034 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3035 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
3036 /* (command 3 was jump to RW-B) */
3037 EC_REBOOT_COLD = 4, /* Cold-reboot */
3038 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3039 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
3042 /* Flags for ec_params_reboot_ec.reboot_flags */
3043 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
3044 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
3046 struct ec_params_reboot_ec {
3047 uint8_t cmd; /* enum ec_reboot_cmd */
3048 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3052 * Get information on last EC panic.
3054 * Returns variable-length platform-dependent panic information. See panic.h
3057 #define EC_CMD_GET_PANIC_INFO 0x00D3
3059 /*****************************************************************************/
3063 * These are valid ONLY on the ACPI command/data port.
3067 * ACPI Read Embedded Controller
3069 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3071 * Use the following sequence:
3073 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3074 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3075 * - Write address to EC_LPC_ADDR_ACPI_DATA
3076 * - Wait for EC_LPC_CMDR_DATA bit to set
3077 * - Read value from EC_LPC_ADDR_ACPI_DATA
3079 #define EC_CMD_ACPI_READ 0x80
3082 * ACPI Write Embedded Controller
3084 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3086 * Use the following sequence:
3088 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3089 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3090 * - Write address to EC_LPC_ADDR_ACPI_DATA
3091 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3092 * - Write value to EC_LPC_ADDR_ACPI_DATA
3094 #define EC_CMD_ACPI_WRITE 0x81
3097 * ACPI Query Embedded Controller
3099 * This clears the lowest-order bit in the currently pending host events, and
3100 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3101 * event 0x80000000 = 32), or 0 if no event was pending.
3103 #define EC_CMD_ACPI_QUERY_EVENT 0x84
3105 /* Valid addresses in ACPI memory space, for read/write commands */
3107 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3108 #define EC_ACPI_MEM_VERSION 0x00
3110 * Test location; writing value here updates test compliment byte to (0xff -
3113 #define EC_ACPI_MEM_TEST 0x01
3114 /* Test compliment; writes here are ignored. */
3115 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3117 /* Keyboard backlight brightness percent (0 - 100) */
3118 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3119 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3120 #define EC_ACPI_MEM_FAN_DUTY 0x04
3123 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3124 * independent thresholds attached to them. The current value of the ID
3125 * register determines which sensor is affected by the THRESHOLD and COMMIT
3126 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3127 * as the memory-mapped sensors. The COMMIT register applies those settings.
3129 * The spec does not mandate any way to read back the threshold settings
3130 * themselves, but when a threshold is crossed the AP needs a way to determine
3131 * which sensor(s) are responsible. Each reading of the ID register clears and
3132 * returns one sensor ID that has crossed one of its threshold (in either
3133 * direction) since the last read. A value of 0xFF means "no new thresholds
3134 * have tripped". Setting or enabling the thresholds for a sensor will clear
3135 * the unread event count for that sensor.
3137 #define EC_ACPI_MEM_TEMP_ID 0x05
3138 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3139 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
3141 * Here are the bits for the COMMIT register:
3142 * bit 0 selects the threshold index for the chosen sensor (0/1)
3143 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3144 * Each write to the commit register affects one threshold.
3146 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3147 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3151 * Set the thresholds for sensor 2 to 50 C and 60 C:
3152 * write 2 to [0x05] -- select temp sensor 2
3153 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3154 * write 0x2 to [0x07] -- enable threshold 0 with this value
3155 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3156 * write 0x3 to [0x07] -- enable threshold 1 with this value
3158 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3159 * write 2 to [0x05] -- select temp sensor 2
3160 * write 0x1 to [0x07] -- disable threshold 1
3163 /* DPTF battery charging current limit */
3164 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3166 /* Charging limit is specified in 64 mA steps */
3167 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3168 /* Value to disable DPTF battery charging limit */
3169 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
3171 /* Current version of ACPI memory address space */
3172 #define EC_ACPI_MEM_VERSION_CURRENT 1
3175 /*****************************************************************************/
3179 * These commands are for sending and receiving message via HDMI CEC
3181 #define EC_MAX_CEC_MSG_LEN 16
3183 /* CEC message from the AP to be written on the CEC bus */
3184 #define EC_CMD_CEC_WRITE_MSG 0x00B8
3187 * struct ec_params_cec_write - Message to write to the CEC bus
3188 * @msg: message content to write to the CEC bus
3190 struct ec_params_cec_write {
3191 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3194 /* Set various CEC parameters */
3195 #define EC_CMD_CEC_SET 0x00BA
3198 * struct ec_params_cec_set - CEC parameters set
3199 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3200 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3201 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3202 * this field encodes the requested logical address between 0 and 15
3203 * or 0xff to unregister
3205 struct ec_params_cec_set {
3206 uint8_t cmd; /* enum cec_command */
3210 /* Read various CEC parameters */
3211 #define EC_CMD_CEC_GET 0x00BB
3214 * struct ec_params_cec_get - CEC parameters get
3215 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3217 struct ec_params_cec_get {
3218 uint8_t cmd; /* enum cec_command */
3222 * struct ec_response_cec_get - CEC parameters get response
3223 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3224 * disabled or 1 if CEC functionality is enabled,
3225 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3226 * configured logical address between 0 and 15 or 0xff if unregistered
3228 struct ec_response_cec_get {
3232 /* CEC parameters command */
3233 enum ec_cec_command {
3234 /* CEC reading, writing and events enable */
3236 /* CEC logical address */
3237 CEC_CMD_LOGICAL_ADDRESS,
3240 /* Events from CEC to AP */
3241 enum mkbp_cec_event {
3242 /* Outgoing message was acknowledged by a follower */
3243 EC_MKBP_CEC_SEND_OK = BIT(0),
3244 /* Outgoing message was not acknowledged */
3245 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3248 /*****************************************************************************/
3252 * These do not follow the normal rules for commands. See each command for
3259 * This command will work even when the EC LPC interface is busy, because the
3260 * reboot command is processed at interrupt level. Note that when the EC
3261 * reboots, the host will reboot too, so there is no response to this command.
3263 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3265 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3268 * Resend last response (not supported on LPC).
3270 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3271 * there was no previous command, or the previous command's response was too
3274 #define EC_CMD_RESEND_RESPONSE 0x00DB
3277 * This header byte on a command indicate version 0. Any header byte less
3278 * than this means that we are talking to an old EC which doesn't support
3279 * versioning. In that case, we assume version 0.
3281 * Header bytes greater than this indicate a later version. For example,
3282 * EC_CMD_VERSION0 + 1 means we are using version 1.
3284 * The old EC interface must not use commands 0xdc or higher.
3286 #define EC_CMD_VERSION0 0x00DC
3288 #endif /* !__ACPI__ */
3290 /*****************************************************************************/
3294 * These commands are for PD MCU communication.
3297 /* EC to PD MCU exchange status command */
3298 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
3300 /* Status of EC being sent to PD */
3301 struct ec_params_pd_status {
3302 int8_t batt_soc; /* battery state of charge */
3305 /* Status of PD being sent back to EC */
3306 struct ec_response_pd_status {
3307 int8_t status; /* PD MCU status */
3308 uint32_t curr_lim_ma; /* input current limit */
3311 /* Set USB type-C port role and muxes */
3312 #define EC_CMD_USB_PD_CONTROL 0x0101
3314 enum usb_pd_control_role {
3315 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3316 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3317 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3318 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3319 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3322 enum usb_pd_control_mux {
3323 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3324 USB_PD_CTRL_MUX_NONE = 1,
3325 USB_PD_CTRL_MUX_USB = 2,
3326 USB_PD_CTRL_MUX_DP = 3,
3327 USB_PD_CTRL_MUX_DOCK = 4,
3328 USB_PD_CTRL_MUX_AUTO = 5,
3331 enum usb_pd_control_swap {
3332 USB_PD_CTRL_SWAP_NONE = 0,
3333 USB_PD_CTRL_SWAP_DATA = 1,
3334 USB_PD_CTRL_SWAP_POWER = 2,
3335 USB_PD_CTRL_SWAP_VCONN = 3,
3336 USB_PD_CTRL_SWAP_COUNT
3339 struct ec_params_usb_pd_control {
3346 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3347 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3348 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3350 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3351 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
3352 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
3353 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
3354 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
3355 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3356 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3358 struct ec_response_usb_pd_control_v1 {
3365 #define EC_CMD_USB_PD_PORTS 0x0102
3367 /* Maximum number of PD ports on a device, num_ports will be <= this */
3368 #define EC_USB_PD_MAX_PORTS 8
3370 struct ec_response_usb_pd_ports {
3374 #define EC_CMD_USB_PD_POWER_INFO 0x0103
3376 #define PD_POWER_CHARGING_PORT 0xff
3377 struct ec_params_usb_pd_power_info {
3385 USB_CHG_TYPE_PROPRIETARY,
3386 USB_CHG_TYPE_BC12_DCP,
3387 USB_CHG_TYPE_BC12_CDP,
3388 USB_CHG_TYPE_BC12_SDP,
3391 USB_CHG_TYPE_UNKNOWN,
3393 enum usb_power_roles {
3394 USB_PD_PORT_POWER_DISCONNECTED,
3395 USB_PD_PORT_POWER_SOURCE,
3396 USB_PD_PORT_POWER_SINK,
3397 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3400 struct usb_chg_measures {
3401 uint16_t voltage_max;
3402 uint16_t voltage_now;
3403 uint16_t current_max;
3404 uint16_t current_lim;
3407 struct ec_response_usb_pd_power_info {
3412 struct usb_chg_measures meas;
3416 struct ec_params_usb_pd_info_request {
3421 * This command will return the number of USB PD charge port + the number
3422 * of dedicated port present.
3423 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
3425 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
3426 struct ec_response_charge_port_count {
3430 /* Read USB-PD Device discovery info */
3431 #define EC_CMD_USB_PD_DISCOVERY 0x0113
3432 struct ec_params_usb_pd_discovery_entry {
3433 uint16_t vid; /* USB-IF VID */
3434 uint16_t pid; /* USB-IF PID */
3435 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3438 /* Override default charge behavior */
3439 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
3441 /* Negative port parameters have special meaning */
3442 enum usb_pd_override_ports {
3443 OVERRIDE_DONT_CHARGE = -2,
3445 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
3448 struct ec_params_charge_port_override {
3449 int16_t override_port; /* Override port# */
3452 /* Read (and delete) one entry of PD event log */
3453 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3455 struct ec_response_pd_log {
3456 uint32_t timestamp; /* relative timestamp in milliseconds */
3457 uint8_t type; /* event type : see PD_EVENT_xx below */
3458 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3459 uint16_t data; /* type-defined data payload */
3460 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3463 /* The timestamp is the microsecond counter shifted to get about a ms. */
3464 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3466 #define PD_LOG_SIZE_MASK 0x1f
3467 #define PD_LOG_PORT_MASK 0xe0
3468 #define PD_LOG_PORT_SHIFT 5
3469 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3470 ((size) & PD_LOG_SIZE_MASK))
3471 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3472 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3474 /* PD event log : entry types */
3476 #define PD_EVENT_MCU_BASE 0x00
3477 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3478 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3479 /* Reserved for custom board event */
3480 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3481 /* PD generic accessory events */
3482 #define PD_EVENT_ACC_BASE 0x20
3483 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3484 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3485 /* PD power supply events */
3486 #define PD_EVENT_PS_BASE 0x40
3487 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3488 /* PD video dongles events */
3489 #define PD_EVENT_VIDEO_BASE 0x60
3490 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3491 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3492 /* Returned in the "type" field, when there is no entry available */
3493 #define PD_EVENT_NO_ENTRY 0xff
3496 * PD_EVENT_MCU_CHARGE event definition :
3497 * the payload is "struct usb_chg_measures"
3498 * the data field contains the port state flags as defined below :
3500 /* Port partner is a dual role device */
3501 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
3502 /* Port is the pending override port */
3503 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
3504 /* Port is the override port */
3505 #define CHARGE_FLAGS_OVERRIDE BIT(13)
3507 #define CHARGE_FLAGS_TYPE_SHIFT 3
3508 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
3509 /* Power delivery role */
3510 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3513 * PD_EVENT_PS_FAULT data field flags definition :
3515 #define PS_FAULT_OCP 1
3516 #define PS_FAULT_FAST_OCP 2
3517 #define PS_FAULT_OVP 3
3518 #define PS_FAULT_DISCH 4
3521 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3523 struct mcdp_version {
3532 struct mcdp_version irom;
3533 struct mcdp_version fw;
3536 /* struct mcdp_info field decoding */
3537 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3538 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3540 /* Get info about USB-C SS muxes */
3541 #define EC_CMD_USB_PD_MUX_INFO 0x011A
3543 struct ec_params_usb_pd_mux_info {
3544 uint8_t port; /* USB-C port number */
3547 /* Flags representing mux state */
3548 #define USB_PD_MUX_USB_ENABLED (1 << 0)
3549 #define USB_PD_MUX_DP_ENABLED (1 << 1)
3550 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3551 #define USB_PD_MUX_HPD_IRQ (1 << 3)
3553 struct ec_response_usb_pd_mux_info {
3554 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3556 /*****************************************************************************/
3558 * Reserve a range of host commands for board-specific, experimental, or
3559 * special purpose features. These can be (re)used without updating this file.
3561 * CAUTION: Don't go nuts with this. Shipping products should document ALL
3562 * their EC commands for easier development, testing, debugging, and support.
3564 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
3565 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
3567 * In your experimental code, you may want to do something like this:
3569 * #define EC_CMD_MAGIC_FOO 0x0000
3570 * #define EC_CMD_MAGIC_BAR 0x0001
3571 * #define EC_CMD_MAGIC_HEY 0x0002
3573 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
3576 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
3579 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
3582 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
3583 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
3586 * Given the private host command offset, calculate the true private host
3589 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
3590 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
3592 /*****************************************************************************/
3596 * Some platforms have sub-processors chained to each other. For example.
3598 * AP <--> EC <--> PD MCU
3600 * The top 2 bits of the command number are used to indicate which device the
3601 * command is intended for. Device 0 is always the device receiving the
3602 * command; other device mapping is board-specific.
3604 * When a device receives a command to be passed to a sub-processor, it passes
3605 * it on with the device number set back to 0. This allows the sub-processor
3606 * to remain blissfully unaware of whether the command originated on the next
3607 * device up the chain, or was passed through from the AP.
3609 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3610 * AP sends command 0x4002 to the EC
3611 * EC sends command 0x0002 to the PD MCU
3612 * EC forwards PD MCU response back to the AP
3615 /* Offset and max command number for sub-device n */
3616 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3617 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3619 /*****************************************************************************/
3621 * Deprecated constants. These constants have been renamed for clarity. The
3622 * meaning and size has not changed. Programs that use the old names should
3623 * switch to the new names soon, as the old names may not be carried forward
3626 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3627 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3628 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3630 #endif /* __CROS_EC_COMMANDS_H */