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.
558 /*****************************************************************************/
559 /* General / test commands */
562 * Get protocol version, used to deal with non-backward compatible protocol
565 #define EC_CMD_PROTO_VERSION 0x00
568 * struct ec_response_proto_version - Response to the proto version command.
569 * @version: The protocol version.
571 struct ec_response_proto_version {
576 * Hello. This is a simple command to test the EC is responsive to
579 #define EC_CMD_HELLO 0x01
582 * struct ec_params_hello - Parameters to the hello command.
583 * @in_data: Pass anything here.
585 struct ec_params_hello {
590 * struct ec_response_hello - Response to the hello command.
591 * @out_data: Output will be in_data + 0x01020304.
593 struct ec_response_hello {
597 /* Get version number */
598 #define EC_CMD_GET_VERSION 0x02
600 enum ec_current_image {
601 EC_IMAGE_UNKNOWN = 0,
607 * struct ec_response_get_version - Response to the get version command.
608 * @version_string_ro: Null-terminated RO firmware version string.
609 * @version_string_rw: Null-terminated RW firmware version string.
610 * @reserved: Unused bytes; was previously RW-B firmware version string.
611 * @current_image: One of ec_current_image.
613 struct ec_response_get_version {
614 char version_string_ro[32];
615 char version_string_rw[32];
617 uint32_t current_image;
621 #define EC_CMD_READ_TEST 0x03
624 * struct ec_params_read_test - Parameters for the read test command.
625 * @offset: Starting value for read buffer.
626 * @size: Size to read in bytes.
628 struct ec_params_read_test {
634 * struct ec_response_read_test - Response to the read test command.
635 * @data: Data returned by the read test command.
637 struct ec_response_read_test {
642 * Get build information
644 * Response is null-terminated string.
646 #define EC_CMD_GET_BUILD_INFO 0x04
649 #define EC_CMD_GET_CHIP_INFO 0x05
652 * struct ec_response_get_chip_info - Response to the get chip info command.
653 * @vendor: Null-terminated string for chip vendor.
654 * @name: Null-terminated string for chip name.
655 * @revision: Null-terminated string for chip mask version.
657 struct ec_response_get_chip_info {
663 /* Get board HW version */
664 #define EC_CMD_GET_BOARD_VERSION 0x06
667 * struct ec_response_board_version - Response to the board version command.
668 * @board_version: A monotonously incrementing number.
670 struct ec_response_board_version {
671 uint16_t board_version;
675 * Read memory-mapped data.
677 * This is an alternate interface to memory-mapped data for bus protocols
678 * which don't support direct-mapped memory - I2C, SPI, etc.
680 * Response is params.size bytes of data.
682 #define EC_CMD_READ_MEMMAP 0x07
685 * struct ec_params_read_memmap - Parameters for the read memory map command.
686 * @offset: Offset in memmap (EC_MEMMAP_*).
687 * @size: Size to read in bytes.
689 struct ec_params_read_memmap {
694 /* Read versions supported for a command */
695 #define EC_CMD_GET_CMD_VERSIONS 0x08
698 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
699 * @cmd: Command to check.
701 struct ec_params_get_cmd_versions {
706 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
708 * @cmd: Command to check.
710 struct ec_params_get_cmd_versions_v1 {
715 * struct ec_response_get_cmd_version - Response to the get command versions.
716 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
719 struct ec_response_get_cmd_versions {
720 uint32_t version_mask;
724 * Check EC communications status (busy). This is needed on i2c/spi but not
725 * on lpc since it has its own out-of-band busy indicator.
727 * lpc must read the status from the command register. Attempting this on
728 * lpc will overwrite the args/parameter space and corrupt its data.
730 #define EC_CMD_GET_COMMS_STATUS 0x09
732 /* Avoid using ec_status which is for return values */
733 enum ec_comms_status {
734 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
738 * struct ec_response_get_comms_status - Response to the get comms status
740 * @flags: Mask of enum ec_comms_status.
742 struct ec_response_get_comms_status {
743 uint32_t flags; /* Mask of enum ec_comms_status */
746 /* Fake a variety of responses, purely for testing purposes. */
747 #define EC_CMD_TEST_PROTOCOL 0x0a
749 /* Tell the EC what to send back to us. */
750 struct ec_params_test_protocol {
756 /* Here it comes... */
757 struct ec_response_test_protocol {
761 /* Get protocol information */
762 #define EC_CMD_GET_PROTOCOL_INFO 0x0b
764 /* Flags for ec_response_get_protocol_info.flags */
765 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
766 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
769 * struct ec_response_get_protocol_info - Response to the get protocol info.
770 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
772 * @max_request_packet_size: Maximum request packet size in bytes.
773 * @max_response_packet_size: Maximum response packet size in bytes.
774 * @flags: see EC_PROTOCOL_INFO_*
776 struct ec_response_get_protocol_info {
777 /* Fields which exist if at least protocol version 3 supported */
778 uint32_t protocol_versions;
779 uint16_t max_request_packet_size;
780 uint16_t max_response_packet_size;
785 /*****************************************************************************/
786 /* Get/Set miscellaneous values */
788 /* The upper byte of .flags tells what to do (nothing means "get") */
789 #define EC_GSV_SET 0x80000000
792 * The lower three bytes of .flags identifies the parameter, if that has
793 * meaning for an individual command.
795 #define EC_GSV_PARAM_MASK 0x00ffffff
797 struct ec_params_get_set_value {
802 struct ec_response_get_set_value {
807 /* More than one command can use these structs to get/set parameters. */
808 #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
810 /*****************************************************************************/
811 /* List the features supported by the firmware */
812 #define EC_CMD_GET_FEATURES 0x0d
814 /* Supported features */
815 enum ec_feature_code {
817 * This image contains a limited set of features. Another image
818 * in RW partition may support more features.
820 EC_FEATURE_LIMITED = 0,
822 * Commands for probing/reading/writing/erasing the flash in the
825 EC_FEATURE_FLASH = 1,
827 * Can control the fan speed directly.
829 EC_FEATURE_PWM_FAN = 2,
831 * Can control the intensity of the keyboard backlight.
833 EC_FEATURE_PWM_KEYB = 3,
835 * Support Google lightbar, introduced on Pixel.
837 EC_FEATURE_LIGHTBAR = 4,
838 /* Control of LEDs */
840 /* Exposes an interface to control gyro and sensors.
841 * The host goes through the EC to access these sensors.
842 * In addition, the EC may provide composite sensors, like lid angle.
844 EC_FEATURE_MOTION_SENSE = 6,
845 /* The keyboard is controlled by the EC */
847 /* The AP can use part of the EC flash as persistent storage. */
848 EC_FEATURE_PSTORE = 8,
849 /* The EC monitors BIOS port 80h, and can return POST codes. */
850 EC_FEATURE_PORT80 = 9,
852 * Thermal management: include TMP specific commands.
853 * Higher level than direct fan control.
855 EC_FEATURE_THERMAL = 10,
856 /* Can switch the screen backlight on/off */
857 EC_FEATURE_BKLIGHT_SWITCH = 11,
858 /* Can switch the wifi module on/off */
859 EC_FEATURE_WIFI_SWITCH = 12,
860 /* Monitor host events, through for example SMI or SCI */
861 EC_FEATURE_HOST_EVENTS = 13,
862 /* The EC exposes GPIO commands to control/monitor connected devices. */
863 EC_FEATURE_GPIO = 14,
864 /* The EC can send i2c messages to downstream devices. */
866 /* Command to control charger are included */
867 EC_FEATURE_CHARGER = 16,
868 /* Simple battery support. */
869 EC_FEATURE_BATTERY = 17,
871 * Support Smart battery protocol
872 * (Common Smart Battery System Interface Specification)
874 EC_FEATURE_SMART_BATTERY = 18,
875 /* EC can detect when the host hangs. */
876 EC_FEATURE_HANG_DETECT = 19,
877 /* Report power information, for pit only */
879 /* Another Cros EC device is present downstream of this one */
880 EC_FEATURE_SUB_MCU = 21,
881 /* Support USB Power delivery (PD) commands */
882 EC_FEATURE_USB_PD = 22,
883 /* Control USB multiplexer, for audio through USB port for instance. */
884 EC_FEATURE_USB_MUX = 23,
885 /* Motion Sensor code has an internal software FIFO */
886 EC_FEATURE_MOTION_SENSE_FIFO = 24,
887 /* Support temporary secure vstore */
888 EC_FEATURE_VSTORE = 25,
889 /* EC decides on USB-C SS mux state, muxes configured by host */
890 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
891 /* EC has RTC feature that can be controlled by host commands */
893 /* The MCU exposes a Fingerprint sensor */
894 EC_FEATURE_FINGERPRINT = 28,
895 /* The MCU exposes a Touchpad */
896 EC_FEATURE_TOUCHPAD = 29,
897 /* The MCU has RWSIG task enabled */
898 EC_FEATURE_RWSIG = 30,
899 /* EC has device events support */
900 EC_FEATURE_DEVICE_EVENT = 31,
901 /* EC supports the unified wake masks for LPC/eSPI systems */
902 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
903 /* EC supports 64-bit host events */
904 EC_FEATURE_HOST_EVENT64 = 33,
905 /* EC runs code in RAM (not in place, a.k.a. XIP) */
906 EC_FEATURE_EXEC_IN_RAM = 34,
907 /* EC supports CEC commands */
909 /* EC supports tight sensor timestamping. */
910 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
912 * EC supports tablet mode detection aligned to Chrome and allows
913 * setting of threshold by host command using
914 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
916 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
917 /* EC supports audio codec. */
918 EC_FEATURE_AUDIO_CODEC = 38,
919 /* EC Supports SCP. */
921 /* The MCU is an Integrated Sensor Hub */
925 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
926 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
928 struct ec_response_get_features {
932 /*****************************************************************************/
936 #define EC_CMD_FLASH_INFO 0x10
939 * struct ec_response_flash_info - Response to the flash info command.
940 * @flash_size: Usable flash size in bytes.
941 * @write_block_size: Write block size. Write offset and size must be a
943 * @erase_block_size: Erase block size. Erase offset and size must be a
945 * @protect_block_size: Protection block size. Protection offset and size
946 * must be a multiple of this.
948 * Version 0 returns these fields.
950 struct ec_response_flash_info {
952 uint32_t write_block_size;
953 uint32_t erase_block_size;
954 uint32_t protect_block_size;
958 * Flags for version 1+ flash info command
959 * EC flash erases bits to 0 instead of 1.
961 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
964 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
965 * @flash_size: Usable flash size in bytes.
966 * @write_block_size: Write block size. Write offset and size must be a
968 * @erase_block_size: Erase block size. Erase offset and size must be a
970 * @protect_block_size: Protection block size. Protection offset and size
971 * must be a multiple of this.
972 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
973 * size is exactly this and offset is a multiple of this.
974 * For example, an EC may have a write buffer which can do
975 * half-page operations if data is aligned, and a slower
976 * word-at-a-time write mode.
977 * @flags: Flags; see EC_FLASH_INFO_*
979 * Version 1 returns the same initial fields as version 0, with additional
982 * gcc anonymous structs don't seem to get along with the __packed directive;
983 * if they did we'd define the version 0 structure as a sub-structure of this
986 struct ec_response_flash_info_1 {
987 /* Version 0 fields; see above for description */
989 uint32_t write_block_size;
990 uint32_t erase_block_size;
991 uint32_t protect_block_size;
993 /* Version 1 adds these fields: */
994 uint32_t write_ideal_size;
1001 * Response is params.size bytes of data.
1003 #define EC_CMD_FLASH_READ 0x11
1006 * struct ec_params_flash_read - Parameters for the flash read command.
1007 * @offset: Byte offset to read.
1008 * @size: Size to read in bytes.
1010 struct ec_params_flash_read {
1016 #define EC_CMD_FLASH_WRITE 0x12
1017 #define EC_VER_FLASH_WRITE 1
1019 /* Version 0 of the flash command supported only 64 bytes of data */
1020 #define EC_FLASH_WRITE_VER0_SIZE 64
1023 * struct ec_params_flash_write - Parameters for the flash write command.
1024 * @offset: Byte offset to write.
1025 * @size: Size to write in bytes.
1027 struct ec_params_flash_write {
1030 /* Followed by data to write */
1034 #define EC_CMD_FLASH_ERASE 0x13
1037 * struct ec_params_flash_erase - Parameters for the flash erase command.
1038 * @offset: Byte offset to erase.
1039 * @size: Size to erase in bytes.
1041 struct ec_params_flash_erase {
1047 * Get/set flash protection.
1049 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1050 * firmware write protect GPIO, not all flags will take effect immediately;
1051 * some flags require a subsequent hard reset to take effect. Check the
1052 * returned flags bits to see what actually happened.
1054 * If mask=0, simply returns the current flags state.
1056 #define EC_CMD_FLASH_PROTECT 0x15
1057 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1059 /* Flags for flash protection */
1060 /* RO flash code protected when the EC boots */
1061 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1063 * RO flash code protected now. If this bit is set, at-boot status cannot
1066 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1067 /* Entire flash code protected now, until reboot. */
1068 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1069 /* Flash write protect GPIO is asserted now */
1070 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1071 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1072 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1074 * Error - flash protection is in inconsistent state. At least one bank of
1075 * flash which should be protected is not protected. Usually fixed by
1076 * re-requesting the desired flags, or by a hard reset if that fails.
1078 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1079 /* Entire flash code protected when the EC boots */
1080 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1083 * struct ec_params_flash_protect - Parameters for the flash protect command.
1084 * @mask: Bits in flags to apply.
1085 * @flags: New flags to apply.
1087 struct ec_params_flash_protect {
1093 * struct ec_response_flash_protect - Response to the flash protect command.
1094 * @flags: Current value of flash protect flags.
1095 * @valid_flags: Flags which are valid on this platform. This allows the
1096 * caller to distinguish between flags which aren't set vs. flags
1097 * which can't be set on this platform.
1098 * @writable_flags: Flags which can be changed given the current protection
1101 struct ec_response_flash_protect {
1103 uint32_t valid_flags;
1104 uint32_t writable_flags;
1108 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1109 * write protect. These commands may be reused with version > 0.
1112 /* Get the region offset/size */
1113 #define EC_CMD_FLASH_REGION_INFO 0x16
1114 #define EC_VER_FLASH_REGION_INFO 1
1116 enum ec_flash_region {
1117 /* Region which holds read-only EC image */
1118 EC_FLASH_REGION_RO = 0,
1119 /* Region which holds rewritable EC image */
1122 * Region which should be write-protected in the factory (a superset of
1123 * EC_FLASH_REGION_RO)
1125 EC_FLASH_REGION_WP_RO,
1126 /* Number of regions */
1127 EC_FLASH_REGION_COUNT,
1131 * struct ec_params_flash_region_info - Parameters for the flash region info
1133 * @region: Flash region; see EC_FLASH_REGION_*
1135 struct ec_params_flash_region_info {
1139 struct ec_response_flash_region_info {
1144 /* Read/write VbNvContext */
1145 #define EC_CMD_VBNV_CONTEXT 0x17
1146 #define EC_VER_VBNV_CONTEXT 1
1147 #define EC_VBNV_BLOCK_SIZE 16
1149 enum ec_vbnvcontext_op {
1150 EC_VBNV_CONTEXT_OP_READ,
1151 EC_VBNV_CONTEXT_OP_WRITE,
1154 struct ec_params_vbnvcontext {
1156 uint8_t block[EC_VBNV_BLOCK_SIZE];
1159 struct ec_response_vbnvcontext {
1160 uint8_t block[EC_VBNV_BLOCK_SIZE];
1163 /*****************************************************************************/
1166 /* Get fan target RPM */
1167 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1169 struct ec_response_pwm_get_fan_rpm {
1173 /* Set target fan RPM */
1174 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1176 struct ec_params_pwm_set_fan_target_rpm {
1180 /* Get keyboard backlight */
1181 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1183 struct ec_response_pwm_get_keyboard_backlight {
1188 /* Set keyboard backlight */
1189 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1191 struct ec_params_pwm_set_keyboard_backlight {
1195 /* Set target fan PWM duty cycle */
1196 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
1198 struct ec_params_pwm_set_fan_duty {
1202 #define EC_CMD_PWM_SET_DUTY 0x25
1203 /* 16 bit duty cycle, 0xffff = 100% */
1204 #define EC_PWM_MAX_DUTY 0xffff
1207 /* All types, indexed by board-specific enum pwm_channel */
1208 EC_PWM_TYPE_GENERIC = 0,
1209 /* Keyboard backlight */
1210 EC_PWM_TYPE_KB_LIGHT,
1211 /* Display backlight */
1212 EC_PWM_TYPE_DISPLAY_LIGHT,
1216 struct ec_params_pwm_set_duty {
1217 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1218 uint8_t pwm_type; /* ec_pwm_type */
1219 uint8_t index; /* Type-specific index, or 0 if unique */
1222 #define EC_CMD_PWM_GET_DUTY 0x26
1224 struct ec_params_pwm_get_duty {
1225 uint8_t pwm_type; /* ec_pwm_type */
1226 uint8_t index; /* Type-specific index, or 0 if unique */
1229 struct ec_response_pwm_get_duty {
1230 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1233 /*****************************************************************************/
1235 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1236 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1237 * into a subcommand. We'll make separate structs for subcommands with
1238 * different input args, so that we know how much to expect.
1240 #define EC_CMD_LIGHTBAR_CMD 0x28
1244 } __ec_todo_unpacked;
1246 #define LB_BATTERY_LEVELS 4
1249 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1250 * host command, but the alignment is the same regardless. Keep it that way.
1252 struct lightbar_params_v0 {
1254 int32_t google_ramp_up;
1255 int32_t google_ramp_down;
1256 int32_t s3s0_ramp_up;
1257 int32_t s0_tick_delay[2]; /* AC=0/1 */
1258 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1259 int32_t s0s3_ramp_down;
1260 int32_t s3_sleep_for;
1262 int32_t s3_ramp_down;
1266 uint8_t osc_min[2]; /* AC=0/1 */
1267 uint8_t osc_max[2]; /* AC=0/1 */
1268 uint8_t w_ofs[2]; /* AC=0/1 */
1270 /* Brightness limits based on the backlight and AC. */
1271 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1272 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1273 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1275 /* Battery level thresholds */
1276 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1278 /* Map [AC][battery_level] to color index */
1279 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1280 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1283 struct rgb_s color[8]; /* 0-3 are Google colors */
1286 struct lightbar_params_v1 {
1288 int32_t google_ramp_up;
1289 int32_t google_ramp_down;
1290 int32_t s3s0_ramp_up;
1291 int32_t s0_tick_delay[2]; /* AC=0/1 */
1292 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1293 int32_t s0s3_ramp_down;
1294 int32_t s3_sleep_for;
1296 int32_t s3_ramp_down;
1297 int32_t tap_tick_delay;
1298 int32_t tap_display_time;
1300 /* Tap-for-battery params */
1301 uint8_t tap_pct_red;
1302 uint8_t tap_pct_green;
1303 uint8_t tap_seg_min_on;
1304 uint8_t tap_seg_max_on;
1305 uint8_t tap_seg_osc;
1309 uint8_t osc_min[2]; /* AC=0/1 */
1310 uint8_t osc_max[2]; /* AC=0/1 */
1311 uint8_t w_ofs[2]; /* AC=0/1 */
1313 /* Brightness limits based on the backlight and AC. */
1314 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1315 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1316 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1318 /* Battery level thresholds */
1319 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1321 /* Map [AC][battery_level] to color index */
1322 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1323 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1326 struct rgb_s color[8]; /* 0-3 are Google colors */
1329 /* Lightbar program */
1330 #define EC_LB_PROG_LEN 192
1331 struct lightbar_program {
1333 uint8_t data[EC_LB_PROG_LEN];
1334 } __ec_todo_unpacked;
1336 struct ec_params_lightbar {
1337 uint8_t cmd; /* Command (see enum lightbar_command) */
1341 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1342 version, get_brightness, get_demo, suspend, resume;
1344 struct __ec_todo_unpacked {
1346 } set_brightness, seq, demo;
1348 struct __ec_todo_unpacked {
1349 uint8_t ctrl, reg, value;
1352 struct __ec_todo_unpacked {
1353 uint8_t led, red, green, blue;
1356 struct __ec_todo_unpacked {
1360 struct __ec_todo_unpacked {
1362 } manual_suspend_ctrl;
1364 struct lightbar_params_v0 set_params_v0;
1365 struct lightbar_params_v1 set_params_v1;
1366 struct lightbar_program set_program;
1370 struct ec_response_lightbar {
1372 struct __ec_todo_unpacked {
1373 struct __ec_todo_unpacked {
1380 struct __ec_todo_unpacked {
1382 } get_seq, get_brightness, get_demo;
1384 struct lightbar_params_v0 get_params_v0;
1385 struct lightbar_params_v1 get_params_v1;
1387 struct __ec_todo_unpacked {
1392 struct __ec_todo_unpacked {
1393 uint8_t red, green, blue;
1397 /* no return params */
1398 } off, on, init, set_brightness, seq, reg, set_rgb,
1399 demo, set_params_v0, set_params_v1,
1400 set_program, manual_suspend_ctrl, suspend, resume;
1404 /* Lightbar commands */
1405 enum lightbar_command {
1406 LIGHTBAR_CMD_DUMP = 0,
1407 LIGHTBAR_CMD_OFF = 1,
1408 LIGHTBAR_CMD_ON = 2,
1409 LIGHTBAR_CMD_INIT = 3,
1410 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1411 LIGHTBAR_CMD_SEQ = 5,
1412 LIGHTBAR_CMD_REG = 6,
1413 LIGHTBAR_CMD_SET_RGB = 7,
1414 LIGHTBAR_CMD_GET_SEQ = 8,
1415 LIGHTBAR_CMD_DEMO = 9,
1416 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1417 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1418 LIGHTBAR_CMD_VERSION = 12,
1419 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1420 LIGHTBAR_CMD_GET_RGB = 14,
1421 LIGHTBAR_CMD_GET_DEMO = 15,
1422 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1423 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1424 LIGHTBAR_CMD_SET_PROGRAM = 18,
1425 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1426 LIGHTBAR_CMD_SUSPEND = 20,
1427 LIGHTBAR_CMD_RESUME = 21,
1431 /*****************************************************************************/
1432 /* LED control commands */
1434 #define EC_CMD_LED_CONTROL 0x29
1437 /* LED to indicate battery state of charge */
1438 EC_LED_ID_BATTERY_LED = 0,
1440 * LED to indicate system power state (on or in suspend).
1441 * May be on power button or on C-panel.
1443 EC_LED_ID_POWER_LED,
1444 /* LED on power adapter or its plug */
1445 EC_LED_ID_ADAPTER_LED,
1450 /* LED control flags */
1451 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1452 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1454 enum ec_led_colors {
1455 EC_LED_COLOR_RED = 0,
1458 EC_LED_COLOR_YELLOW,
1464 struct ec_params_led_control {
1465 uint8_t led_id; /* Which LED to control */
1466 uint8_t flags; /* Control flags */
1468 uint8_t brightness[EC_LED_COLOR_COUNT];
1471 struct ec_response_led_control {
1473 * Available brightness value range.
1475 * Range 0 means color channel not present.
1476 * Range 1 means on/off control.
1477 * Other values means the LED is control by PWM.
1479 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1482 /*****************************************************************************/
1483 /* Verified boot commands */
1486 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1487 * reused for other purposes with version > 0.
1490 /* Verified boot hash command */
1491 #define EC_CMD_VBOOT_HASH 0x2A
1493 struct ec_params_vboot_hash {
1494 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1495 uint8_t hash_type; /* enum ec_vboot_hash_type */
1496 uint8_t nonce_size; /* Nonce size; may be 0 */
1497 uint8_t reserved0; /* Reserved; set 0 */
1498 uint32_t offset; /* Offset in flash to hash */
1499 uint32_t size; /* Number of bytes to hash */
1500 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1503 struct ec_response_vboot_hash {
1504 uint8_t status; /* enum ec_vboot_hash_status */
1505 uint8_t hash_type; /* enum ec_vboot_hash_type */
1506 uint8_t digest_size; /* Size of hash digest in bytes */
1507 uint8_t reserved0; /* Ignore; will be 0 */
1508 uint32_t offset; /* Offset in flash which was hashed */
1509 uint32_t size; /* Number of bytes hashed */
1510 uint8_t hash_digest[64]; /* Hash digest data */
1513 enum ec_vboot_hash_cmd {
1514 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1515 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1516 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1517 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1520 enum ec_vboot_hash_type {
1521 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1524 enum ec_vboot_hash_status {
1525 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1526 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1527 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1531 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1532 * If one of these is specified, the EC will automatically update offset and
1533 * size to the correct values for the specified image (RO or RW).
1535 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1536 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1538 /*****************************************************************************/
1540 * Motion sense commands. We'll make separate structs for sub-commands with
1541 * different input args, so that we know how much to expect.
1543 #define EC_CMD_MOTION_SENSE_CMD 0x2B
1545 /* Motion sense commands */
1546 enum motionsense_command {
1548 * Dump command returns all motion sensor data including motion sense
1549 * module flags and individual sensor flags.
1551 MOTIONSENSE_CMD_DUMP = 0,
1554 * Info command returns data describing the details of a given sensor,
1555 * including enum motionsensor_type, enum motionsensor_location, and
1556 * enum motionsensor_chip.
1558 MOTIONSENSE_CMD_INFO = 1,
1561 * EC Rate command is a setter/getter command for the EC sampling rate
1562 * of all motion sensors in milliseconds.
1564 MOTIONSENSE_CMD_EC_RATE = 2,
1567 * Sensor ODR command is a setter/getter command for the output data
1568 * rate of a specific motion sensor in millihertz.
1570 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1573 * Sensor range command is a setter/getter command for the range of
1574 * a specified motion sensor in +/-G's or +/- deg/s.
1576 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1579 * Setter/getter command for the keyboard wake angle. When the lid
1580 * angle is greater than this value, keyboard wake is disabled in S3,
1581 * and when the lid angle goes less than this value, keyboard wake is
1582 * enabled. Note, the lid angle measurement is an approximate,
1583 * un-calibrated value, hence the wake angle isn't exact.
1585 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1588 * Returns a single sensor data.
1590 MOTIONSENSE_CMD_DATA = 6,
1593 * Perform low level calibration.. On sensors that support it, ask to
1594 * do offset calibration.
1596 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1599 * Sensor Offset command is a setter/getter command for the offset used
1600 * for calibration. The offsets can be calculated by the host, or via
1601 * PERFORM_CALIB command.
1603 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1605 /* Number of motionsense sub-commands. */
1606 MOTIONSENSE_NUM_CMDS
1609 enum motionsensor_id {
1610 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1611 EC_MOTION_SENSOR_ACCEL_LID = 1,
1612 EC_MOTION_SENSOR_GYRO = 2,
1615 * Note, if more sensors are added and this count changes, the padding
1616 * in ec_response_motion_sense dump command must be modified.
1618 EC_MOTION_SENSOR_COUNT = 3
1621 /* List of motion sensor types. */
1622 enum motionsensor_type {
1623 MOTIONSENSE_TYPE_ACCEL = 0,
1624 MOTIONSENSE_TYPE_GYRO = 1,
1625 MOTIONSENSE_TYPE_MAG = 2,
1626 MOTIONSENSE_TYPE_PROX = 3,
1627 MOTIONSENSE_TYPE_LIGHT = 4,
1628 MOTIONSENSE_TYPE_ACTIVITY = 5,
1629 MOTIONSENSE_TYPE_BARO = 6,
1630 MOTIONSENSE_TYPE_MAX,
1633 /* List of motion sensor locations. */
1634 enum motionsensor_location {
1635 MOTIONSENSE_LOC_BASE = 0,
1636 MOTIONSENSE_LOC_LID = 1,
1637 MOTIONSENSE_LOC_MAX,
1640 /* List of motion sensor chips. */
1641 enum motionsensor_chip {
1642 MOTIONSENSE_CHIP_KXCJ9 = 0,
1645 /* Module flag masks used for the dump sub-command. */
1646 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1648 /* Sensor flag masks used for the dump sub-command. */
1649 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1652 * Send this value for the data element to only perform a read. If you
1653 * send any other value, the EC will interpret it as data to set and will
1654 * return the actual value set.
1656 #define EC_MOTION_SENSE_NO_VALUE -1
1658 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1660 /* Set Calibration information */
1661 #define MOTION_SENSE_SET_OFFSET 1
1663 struct ec_response_motion_sensor_data {
1664 /* Flags for each sensor. */
1666 /* Sensor number the data comes from */
1668 /* Each sensor is up to 3-axis. */
1671 struct __ec_todo_packed {
1675 struct __ec_todo_unpacked {
1676 uint8_t activity; /* motionsensor_activity */
1678 int16_t add_info[2];
1683 struct ec_params_motion_sense {
1686 /* Used for MOTIONSENSE_CMD_DUMP. */
1687 struct __ec_todo_unpacked {
1692 * Used for MOTIONSENSE_CMD_EC_RATE and
1693 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1695 struct __ec_todo_unpacked {
1696 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1698 } ec_rate, kb_wake_angle;
1700 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1701 struct __ec_todo_packed {
1705 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1706 * the calibration information in the EC.
1707 * If unset, just retrieve calibration information.
1712 * Temperature at calibration, in units of 0.01 C
1713 * 0x8000: invalid / unknown.
1720 * Offset for calibration.
1722 * Accelerometer: 1/1024 g
1723 * Gyro: 1/1024 deg/s
1729 /* Used for MOTIONSENSE_CMD_INFO. */
1730 struct __ec_todo_packed {
1735 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1736 * MOTIONSENSE_CMD_SENSOR_RANGE.
1739 /* Should be element of enum motionsensor_id. */
1742 /* Rounding flag, true for round-up, false for down. */
1747 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1749 } sensor_odr, sensor_range;
1753 struct ec_response_motion_sense {
1755 /* Used for MOTIONSENSE_CMD_DUMP. */
1756 struct __ec_todo_unpacked {
1757 /* Flags representing the motion sensor module. */
1758 uint8_t module_flags;
1760 /* Number of sensors managed directly by the EC. */
1761 uint8_t sensor_count;
1764 * Sensor data is truncated if response_max is too small
1765 * for holding all the data.
1767 struct ec_response_motion_sensor_data sensor[0];
1770 /* Used for MOTIONSENSE_CMD_INFO. */
1771 struct __ec_todo_unpacked {
1772 /* Should be element of enum motionsensor_type. */
1775 /* Should be element of enum motionsensor_location. */
1778 /* Should be element of enum motionsensor_chip. */
1782 /* Used for MOTIONSENSE_CMD_DATA */
1783 struct ec_response_motion_sensor_data data;
1786 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1787 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1788 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1790 struct __ec_todo_unpacked {
1791 /* Current value of the parameter queried. */
1793 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1795 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1796 struct __ec_todo_unpacked {
1799 } sensor_offset, perform_calib;
1803 /*****************************************************************************/
1804 /* USB charging control commands */
1806 /* Set USB port charging mode */
1807 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
1809 struct ec_params_usb_charge_set_mode {
1810 uint8_t usb_port_id;
1814 /*****************************************************************************/
1815 /* Persistent storage for host */
1817 /* Maximum bytes that can be read/written in a single command */
1818 #define EC_PSTORE_SIZE_MAX 64
1820 /* Get persistent storage info */
1821 #define EC_CMD_PSTORE_INFO 0x40
1823 struct ec_response_pstore_info {
1824 /* Persistent storage size, in bytes */
1825 uint32_t pstore_size;
1826 /* Access size; read/write offset and size must be a multiple of this */
1827 uint32_t access_size;
1831 * Read persistent storage
1833 * Response is params.size bytes of data.
1835 #define EC_CMD_PSTORE_READ 0x41
1837 struct ec_params_pstore_read {
1838 uint32_t offset; /* Byte offset to read */
1839 uint32_t size; /* Size to read in bytes */
1842 /* Write persistent storage */
1843 #define EC_CMD_PSTORE_WRITE 0x42
1845 struct ec_params_pstore_write {
1846 uint32_t offset; /* Byte offset to write */
1847 uint32_t size; /* Size to write in bytes */
1848 uint8_t data[EC_PSTORE_SIZE_MAX];
1851 /*****************************************************************************/
1852 /* Real-time clock */
1854 /* RTC params and response structures */
1855 struct ec_params_rtc {
1859 struct ec_response_rtc {
1863 /* These use ec_response_rtc */
1864 #define EC_CMD_RTC_GET_VALUE 0x44
1865 #define EC_CMD_RTC_GET_ALARM 0x45
1867 /* These all use ec_params_rtc */
1868 #define EC_CMD_RTC_SET_VALUE 0x46
1869 #define EC_CMD_RTC_SET_ALARM 0x47
1871 /* Pass as time param to SET_ALARM to clear the current alarm */
1872 #define EC_RTC_ALARM_CLEAR 0
1874 /*****************************************************************************/
1875 /* Port80 log access */
1877 /* Maximum entries that can be read/written in a single command */
1878 #define EC_PORT80_SIZE_MAX 32
1880 /* Get last port80 code from previous boot */
1881 #define EC_CMD_PORT80_LAST_BOOT 0x48
1882 #define EC_CMD_PORT80_READ 0x48
1884 enum ec_port80_subcmd {
1885 EC_PORT80_GET_INFO = 0,
1886 EC_PORT80_READ_BUFFER,
1889 struct ec_params_port80_read {
1892 struct __ec_todo_unpacked {
1894 uint32_t num_entries;
1899 struct ec_response_port80_read {
1901 struct __ec_todo_unpacked {
1903 uint32_t history_size;
1906 struct __ec_todo_unpacked {
1907 uint16_t codes[EC_PORT80_SIZE_MAX];
1912 struct ec_response_port80_last_boot {
1916 /*****************************************************************************/
1917 /* Thermal engine commands. Note that there are two implementations. We'll
1918 * reuse the command number, but the data and behavior is incompatible.
1919 * Version 0 is what originally shipped on Link.
1920 * Version 1 separates the CPU thermal limits from the fan control.
1923 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1924 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1926 /* The version 0 structs are opaque. You have to know what they are for
1927 * the get/set commands to make any sense.
1930 /* Version 0 - set */
1931 struct ec_params_thermal_set_threshold {
1932 uint8_t sensor_type;
1933 uint8_t threshold_id;
1937 /* Version 0 - get */
1938 struct ec_params_thermal_get_threshold {
1939 uint8_t sensor_type;
1940 uint8_t threshold_id;
1943 struct ec_response_thermal_get_threshold {
1948 /* The version 1 structs are visible. */
1949 enum ec_temp_thresholds {
1950 EC_TEMP_THRESH_WARN = 0,
1951 EC_TEMP_THRESH_HIGH,
1952 EC_TEMP_THRESH_HALT,
1954 EC_TEMP_THRESH_COUNT
1958 * Thermal configuration for one temperature sensor. Temps are in degrees K.
1959 * Zero values will be silently ignored by the thermal task.
1961 struct ec_thermal_config {
1962 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1963 uint32_t temp_fan_off; /* no active cooling needed */
1964 uint32_t temp_fan_max; /* max active cooling needed */
1967 /* Version 1 - get config for one sensor. */
1968 struct ec_params_thermal_get_threshold_v1 {
1969 uint32_t sensor_num;
1971 /* This returns a struct ec_thermal_config */
1974 * Version 1 - set config for one sensor.
1975 * Use read-modify-write for best results!
1977 struct ec_params_thermal_set_threshold_v1 {
1978 uint32_t sensor_num;
1979 struct ec_thermal_config cfg;
1981 /* This returns no data */
1983 /****************************************************************************/
1985 /* Toggle automatic fan control */
1986 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1988 /* Get TMP006 calibration data */
1989 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
1991 struct ec_params_tmp006_get_calibration {
1995 struct ec_response_tmp006_get_calibration {
2002 /* Set TMP006 calibration data */
2003 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
2005 struct ec_params_tmp006_set_calibration {
2007 uint8_t reserved[3]; /* Reserved; set 0 */
2014 /* Read raw TMP006 data */
2015 #define EC_CMD_TMP006_GET_RAW 0x55
2017 struct ec_params_tmp006_get_raw {
2021 struct ec_response_tmp006_get_raw {
2022 int32_t t; /* In 1/100 K */
2023 int32_t v; /* In nV */
2026 /*****************************************************************************/
2027 /* MKBP - Matrix KeyBoard Protocol */
2032 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2033 * expected response size.
2035 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2036 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2037 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2039 #define EC_CMD_MKBP_STATE 0x60
2042 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2044 #define EC_CMD_MKBP_INFO 0x61
2046 struct ec_response_mkbp_info {
2049 /* Formerly "switches", which was 0. */
2053 struct ec_params_mkbp_info {
2058 enum ec_mkbp_info_type {
2060 * Info about the keyboard matrix: number of rows and columns.
2062 * Returns struct ec_response_mkbp_info.
2064 EC_MKBP_INFO_KBD = 0,
2067 * For buttons and switches, info about which specifically are
2068 * supported. event_type must be set to one of the values in enum
2071 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2072 * bitmask indicating which buttons or switches are present. See the
2073 * bit inidices below.
2075 EC_MKBP_INFO_SUPPORTED = 1,
2078 * Instantaneous state of buttons and switches.
2080 * event_type must be set to one of the values in enum ec_mkbp_event.
2082 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2083 * indicating the current state of the keyboard matrix.
2085 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2088 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2089 * state of supported buttons.
2091 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2092 * state of supported switches.
2094 EC_MKBP_INFO_CURRENT = 2,
2097 /* Simulate key press */
2098 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
2100 struct ec_params_mkbp_simulate_key {
2106 /* Configure keyboard scanning */
2107 #define EC_CMD_MKBP_SET_CONFIG 0x64
2108 #define EC_CMD_MKBP_GET_CONFIG 0x65
2111 enum mkbp_config_flags {
2112 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2115 enum mkbp_config_valid {
2116 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2117 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2118 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2119 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2120 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2121 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2122 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2126 * Configuration for our key scanning algorithm.
2128 * Note that this is used as a sub-structure of
2129 * ec_{params/response}_mkbp_get_config.
2131 struct ec_mkbp_config {
2132 uint32_t valid_mask; /* valid fields */
2133 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2134 uint8_t valid_flags; /* which flags are valid */
2135 uint16_t scan_period_us; /* period between start of scans */
2136 /* revert to interrupt mode after no activity for this long */
2137 uint32_t poll_timeout_us;
2139 * minimum post-scan relax time. Once we finish a scan we check
2140 * the time until we are due to start the next one. If this time is
2141 * shorter this field, we use this instead.
2143 uint16_t min_post_scan_delay_us;
2144 /* delay between setting up output and waiting for it to settle */
2145 uint16_t output_settle_us;
2146 uint16_t debounce_down_us; /* time for debounce on key down */
2147 uint16_t debounce_up_us; /* time for debounce on key up */
2148 /* maximum depth to allow for fifo (0 = no keyscan output) */
2149 uint8_t fifo_max_depth;
2152 struct ec_params_mkbp_set_config {
2153 struct ec_mkbp_config config;
2156 struct ec_response_mkbp_get_config {
2157 struct ec_mkbp_config config;
2160 /* Run the key scan emulation */
2161 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2163 enum ec_keyscan_seq_cmd {
2164 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2165 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2166 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2167 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2168 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2171 enum ec_collect_flags {
2173 * Indicates this scan was processed by the EC. Due to timing, some
2174 * scans may be skipped.
2176 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2179 struct ec_collect_item {
2180 uint8_t flags; /* some flags (enum ec_collect_flags) */
2183 struct ec_params_keyscan_seq_ctrl {
2184 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2186 struct __ec_align1 {
2187 uint8_t active; /* still active */
2188 uint8_t num_items; /* number of items */
2189 /* Current item being presented */
2192 struct __ec_todo_unpacked {
2194 * Absolute time for this scan, measured from the
2195 * start of the sequence.
2198 uint8_t scan[0]; /* keyscan data */
2200 struct __ec_align1 {
2201 uint8_t start_item; /* First item to return */
2202 uint8_t num_items; /* Number of items to return */
2207 struct ec_result_keyscan_seq_ctrl {
2209 struct __ec_todo_unpacked {
2210 uint8_t num_items; /* Number of items */
2211 /* Data for each item */
2212 struct ec_collect_item item[0];
2218 * Command for retrieving the next pending MKBP event from the EC device
2220 * The device replies with UNAVAILABLE if there aren't any pending events.
2222 #define EC_CMD_GET_NEXT_EVENT 0x67
2224 enum ec_mkbp_event {
2225 /* Keyboard matrix changed. The event data is the new matrix state. */
2226 EC_MKBP_EVENT_KEY_MATRIX = 0,
2228 /* New host event. The event data is 4 bytes of host event flags. */
2229 EC_MKBP_EVENT_HOST_EVENT = 1,
2231 /* New Sensor FIFO data. The event data is fifo_info structure. */
2232 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2234 /* The state of the non-matrixed buttons have changed. */
2235 EC_MKBP_EVENT_BUTTON = 3,
2237 /* The state of the switches have changed. */
2238 EC_MKBP_EVENT_SWITCH = 4,
2240 /* EC sent a sysrq command */
2241 EC_MKBP_EVENT_SYSRQ = 6,
2243 /* Notify the AP that something happened on CEC */
2244 EC_MKBP_EVENT_CEC_EVENT = 8,
2246 /* Send an incoming CEC message to the AP */
2247 EC_MKBP_EVENT_CEC_MESSAGE = 9,
2249 /* Number of MKBP events */
2250 EC_MKBP_EVENT_COUNT,
2253 union __ec_align_offset1 ec_response_get_next_data {
2254 uint8_t key_matrix[13];
2257 uint32_t host_event;
2264 union __ec_align_offset1 ec_response_get_next_data_v1 {
2265 uint8_t key_matrix[16];
2266 uint32_t host_event;
2270 uint32_t cec_events;
2271 uint8_t cec_message[16];
2274 struct ec_response_get_next_event {
2276 /* Followed by event data if any */
2277 union ec_response_get_next_data data;
2280 struct ec_response_get_next_event_v1 {
2282 /* Followed by event data if any */
2283 union ec_response_get_next_data_v1 data;
2286 /* Bit indices for buttons and switches.*/
2288 #define EC_MKBP_POWER_BUTTON 0
2289 #define EC_MKBP_VOL_UP 1
2290 #define EC_MKBP_VOL_DOWN 2
2293 #define EC_MKBP_LID_OPEN 0
2294 #define EC_MKBP_TABLET_MODE 1
2295 #define EC_MKBP_BASE_ATTACHED 2
2297 /*****************************************************************************/
2298 /* Temperature sensor commands */
2300 /* Read temperature sensor info */
2301 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2303 struct ec_params_temp_sensor_get_info {
2307 struct ec_response_temp_sensor_get_info {
2308 char sensor_name[32];
2309 uint8_t sensor_type;
2312 /*****************************************************************************/
2315 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2316 * commands accidentally sent to the wrong interface. See the ACPI section
2320 /*****************************************************************************/
2321 /* Host event commands */
2324 * Host event mask params and response structures, shared by all of the host
2325 * event commands below.
2327 struct ec_params_host_event_mask {
2331 struct ec_response_host_event_mask {
2335 /* These all use ec_response_host_event_mask */
2336 #define EC_CMD_HOST_EVENT_GET_B 0x87
2337 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2338 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2339 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2341 /* These all use ec_params_host_event_mask */
2342 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2343 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2344 #define EC_CMD_HOST_EVENT_CLEAR 0x8c
2345 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2346 #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2348 /*****************************************************************************/
2349 /* Switch commands */
2351 /* Enable/disable LCD backlight */
2352 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2354 struct ec_params_switch_enable_backlight {
2358 /* Enable/disable WLAN/Bluetooth */
2359 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
2360 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2362 /* Version 0 params; no response */
2363 struct ec_params_switch_enable_wireless_v0 {
2367 /* Version 1 params */
2368 struct ec_params_switch_enable_wireless_v1 {
2369 /* Flags to enable now */
2372 /* Which flags to copy from now_flags */
2376 * Flags to leave enabled in S3, if they're on at the S0->S3
2377 * transition. (Other flags will be disabled by the S0->S3
2380 uint8_t suspend_flags;
2382 /* Which flags to copy from suspend_flags */
2383 uint8_t suspend_mask;
2386 /* Version 1 response */
2387 struct ec_response_switch_enable_wireless_v1 {
2388 /* Flags to enable now */
2391 /* Flags to leave enabled in S3 */
2392 uint8_t suspend_flags;
2395 /*****************************************************************************/
2396 /* GPIO commands. Only available on EC if write protect has been disabled. */
2398 /* Set GPIO output value */
2399 #define EC_CMD_GPIO_SET 0x92
2401 struct ec_params_gpio_set {
2406 /* Get GPIO value */
2407 #define EC_CMD_GPIO_GET 0x93
2409 /* Version 0 of input params and response */
2410 struct ec_params_gpio_get {
2414 struct ec_response_gpio_get {
2418 /* Version 1 of input params and response */
2419 struct ec_params_gpio_get_v1 {
2422 struct __ec_align1 {
2424 } get_value_by_name;
2425 struct __ec_align1 {
2431 struct ec_response_gpio_get_v1 {
2433 struct __ec_align1 {
2435 } get_value_by_name, get_count;
2436 struct __ec_todo_unpacked {
2444 enum gpio_get_subcmd {
2445 EC_GPIO_GET_BY_NAME = 0,
2446 EC_GPIO_GET_COUNT = 1,
2447 EC_GPIO_GET_INFO = 2,
2450 /*****************************************************************************/
2451 /* I2C commands. Only available when flash write protect is unlocked. */
2454 * CAUTION: These commands are deprecated, and are not supported anymore in EC
2455 * builds >= 8398.0.0 (see crosbug.com/p/23570).
2457 * Use EC_CMD_I2C_PASSTHRU instead.
2461 #define EC_CMD_I2C_READ 0x94
2463 struct ec_params_i2c_read {
2464 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2465 uint8_t read_size; /* Either 8 or 16. */
2470 struct ec_response_i2c_read {
2475 #define EC_CMD_I2C_WRITE 0x95
2477 struct ec_params_i2c_write {
2479 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2480 uint8_t write_size; /* Either 8 or 16. */
2485 /*****************************************************************************/
2486 /* Charge state commands. Only available when flash write protect unlocked. */
2488 /* Force charge state machine to stop charging the battery or force it to
2489 * discharge the battery.
2491 #define EC_CMD_CHARGE_CONTROL 0x96
2492 #define EC_VER_CHARGE_CONTROL 1
2494 enum ec_charge_control_mode {
2495 CHARGE_CONTROL_NORMAL = 0,
2496 CHARGE_CONTROL_IDLE,
2497 CHARGE_CONTROL_DISCHARGE,
2500 struct ec_params_charge_control {
2501 uint32_t mode; /* enum charge_control_mode */
2504 /*****************************************************************************/
2506 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2507 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
2510 * Read data from the saved snapshot. If the subcmd parameter is
2511 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2512 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2513 * end of the previous snapshot.
2515 * The params are only looked at in version >= 1 of this command. Prior
2516 * versions will just default to CONSOLE_READ_NEXT behavior.
2518 * Response is null-terminated string. Empty string, if there is no more
2521 #define EC_CMD_CONSOLE_READ 0x98
2523 enum ec_console_read_subcmd {
2524 CONSOLE_READ_NEXT = 0,
2528 struct ec_params_console_read_v1 {
2529 uint8_t subcmd; /* enum ec_console_read_subcmd */
2532 /*****************************************************************************/
2535 * Cut off battery power immediately or after the host has shut down.
2537 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2538 * EC_RES_SUCCESS if the command was successful.
2539 * EC_RES_ERROR if the cut off command failed.
2542 #define EC_CMD_BATTERY_CUT_OFF 0x99
2544 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2546 struct ec_params_battery_cutoff {
2550 /*****************************************************************************/
2551 /* USB port mux control. */
2554 * Switch USB mux or return to automatic switching.
2556 #define EC_CMD_USB_MUX 0x9a
2558 struct ec_params_usb_mux {
2562 /*****************************************************************************/
2563 /* LDOs / FETs control. */
2566 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2567 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2571 * Switch on/off a LDO.
2573 #define EC_CMD_LDO_SET 0x9b
2575 struct ec_params_ldo_set {
2583 #define EC_CMD_LDO_GET 0x9c
2585 struct ec_params_ldo_get {
2589 struct ec_response_ldo_get {
2593 /*****************************************************************************/
2599 #define EC_CMD_POWER_INFO 0x9d
2601 struct ec_response_power_info {
2602 uint32_t usb_dev_type;
2603 uint16_t voltage_ac;
2604 uint16_t voltage_system;
2605 uint16_t current_system;
2606 uint16_t usb_current_limit;
2609 /*****************************************************************************/
2610 /* I2C passthru command */
2612 #define EC_CMD_I2C_PASSTHRU 0x9e
2614 /* Read data; if not present, message is a write */
2615 #define EC_I2C_FLAG_READ (1 << 15)
2617 /* Mask for address */
2618 #define EC_I2C_ADDR_MASK 0x3ff
2620 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2621 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2624 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2626 struct ec_params_i2c_passthru_msg {
2627 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2628 uint16_t len; /* Number of bytes to read or write */
2631 struct ec_params_i2c_passthru {
2632 uint8_t port; /* I2C port number */
2633 uint8_t num_msgs; /* Number of messages */
2634 struct ec_params_i2c_passthru_msg msg[];
2635 /* Data to write for all messages is concatenated here */
2638 struct ec_response_i2c_passthru {
2639 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2640 uint8_t num_msgs; /* Number of messages processed */
2641 uint8_t data[]; /* Data read by messages concatenated here */
2644 /*****************************************************************************/
2645 /* Power button hang detect */
2647 #define EC_CMD_HANG_DETECT 0x9f
2649 /* Reasons to start hang detection timer */
2650 /* Power button pressed */
2651 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2654 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2657 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2659 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2660 #define EC_HANG_START_ON_RESUME (1 << 3)
2662 /* Reasons to cancel hang detection */
2664 /* Power button released */
2665 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2667 /* Any host command from AP received */
2668 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2670 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2671 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2674 * If this flag is set, all the other fields are ignored, and the hang detect
2675 * timer is started. This provides the AP a way to start the hang timer
2676 * without reconfiguring any of the other hang detect settings. Note that
2677 * you must previously have configured the timeouts.
2679 #define EC_HANG_START_NOW (1 << 30)
2682 * If this flag is set, all the other fields are ignored (including
2683 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2684 * without reconfiguring any of the other hang detect settings.
2686 #define EC_HANG_STOP_NOW (1 << 31)
2688 struct ec_params_hang_detect {
2689 /* Flags; see EC_HANG_* */
2692 /* Timeout in msec before generating host event, if enabled */
2693 uint16_t host_event_timeout_msec;
2695 /* Timeout in msec before generating warm reboot, if enabled */
2696 uint16_t warm_reboot_timeout_msec;
2699 /*****************************************************************************/
2700 /* Commands for battery charging */
2703 * This is the single catch-all host command to exchange data regarding the
2704 * charge state machine (v2 and up).
2706 #define EC_CMD_CHARGE_STATE 0xa0
2708 /* Subcommands for this host command */
2709 enum charge_state_command {
2710 CHARGE_STATE_CMD_GET_STATE,
2711 CHARGE_STATE_CMD_GET_PARAM,
2712 CHARGE_STATE_CMD_SET_PARAM,
2713 CHARGE_STATE_NUM_CMDS
2717 * Known param numbers are defined here. Ranges are reserved for board-specific
2718 * params, which are handled by the particular implementations.
2720 enum charge_state_params {
2721 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2722 CS_PARAM_CHG_CURRENT, /* charger current limit */
2723 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2724 CS_PARAM_CHG_STATUS, /* charger-specific status */
2725 CS_PARAM_CHG_OPTION, /* charger-specific options */
2726 /* How many so far? */
2729 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2730 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2731 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2733 /* Other custom param ranges go here... */
2736 struct ec_params_charge_state {
2737 uint8_t cmd; /* enum charge_state_command */
2743 struct __ec_todo_unpacked {
2744 uint32_t param; /* enum charge_state_param */
2747 struct __ec_todo_unpacked {
2748 uint32_t param; /* param to set */
2749 uint32_t value; /* value to set */
2754 struct ec_response_charge_state {
2756 struct __ec_align4 {
2760 int chg_input_current;
2761 int batt_state_of_charge;
2764 struct __ec_align4 {
2768 /* no return values */
2775 * Set maximum battery charging current.
2777 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2779 struct ec_params_current_limit {
2780 uint32_t limit; /* in mA */
2784 * Set maximum external voltage / current.
2786 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
2788 /* Command v0 is used only on Spring and is obsolete + unsupported */
2789 struct ec_params_external_power_limit_v1 {
2790 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2791 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2794 #define EC_POWER_LIMIT_NONE 0xffff
2796 /* Inform the EC when entering a sleep state */
2797 #define EC_CMD_HOST_SLEEP_EVENT 0xa9
2799 enum host_sleep_event {
2800 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2801 HOST_SLEEP_EVENT_S3_RESUME = 2,
2802 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2803 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2806 struct ec_params_host_sleep_event {
2807 uint8_t sleep_event;
2811 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
2812 * transition failures
2814 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
2816 /* Disable timeout detection for this sleep transition */
2817 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
2819 struct ec_params_host_sleep_event_v1 {
2820 /* The type of sleep being entered or exited. */
2821 uint8_t sleep_event;
2826 /* Parameters that apply for suspend messages. */
2829 * The timeout in milliseconds between when this message
2830 * is received and when the EC will declare sleep
2831 * transition failure if the sleep signal is not
2834 uint16_t sleep_timeout_ms;
2837 /* No parameters for non-suspend messages. */
2841 /* A timeout occurred when this bit is set */
2842 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
2845 * The mask defining which bits correspond to the number of sleep transitions,
2846 * as well as the maximum number of suspend line transitions that will be
2847 * reported back to the host.
2849 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
2851 struct ec_response_host_sleep_event_v1 {
2853 /* Response fields that apply for resume messages. */
2856 * The number of sleep power signal transitions that
2857 * occurred since the suspend message. The high bit
2858 * indicates a timeout occurred.
2860 uint32_t sleep_transitions;
2863 /* No response fields for non-resume messages. */
2867 /*****************************************************************************/
2868 /* Smart battery pass-through */
2870 /* Get / Set 16-bit smart battery registers */
2871 #define EC_CMD_SB_READ_WORD 0xb0
2872 #define EC_CMD_SB_WRITE_WORD 0xb1
2874 /* Get / Set string smart battery parameters
2875 * formatted as SMBUS "block".
2877 #define EC_CMD_SB_READ_BLOCK 0xb2
2878 #define EC_CMD_SB_WRITE_BLOCK 0xb3
2880 struct ec_params_sb_rd {
2884 struct ec_response_sb_rd_word {
2888 struct ec_params_sb_wr_word {
2893 struct ec_response_sb_rd_block {
2897 struct ec_params_sb_wr_block {
2902 /*****************************************************************************/
2903 /* Battery vendor parameters
2905 * Get or set vendor-specific parameters in the battery. Implementations may
2906 * differ between boards or batteries. On a set operation, the response
2907 * contains the actual value set, which may be rounded or clipped from the
2911 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2913 enum ec_battery_vendor_param_mode {
2914 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2915 BATTERY_VENDOR_PARAM_MODE_SET,
2918 struct ec_params_battery_vendor_param {
2924 struct ec_response_battery_vendor_param {
2928 /*****************************************************************************/
2929 /* Commands for I2S recording on audio codec. */
2931 #define EC_CMD_CODEC_I2S 0x00BC
2933 enum ec_codec_i2s_subcmd {
2934 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2935 EC_CODEC_SET_GAIN = 0x1,
2936 EC_CODEC_GET_GAIN = 0x2,
2937 EC_CODEC_I2S_ENABLE = 0x3,
2938 EC_CODEC_I2S_SET_CONFIG = 0x4,
2939 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2940 EC_CODEC_I2S_SET_BCLK = 0x6,
2943 enum ec_sample_depth_value {
2944 EC_CODEC_SAMPLE_DEPTH_16 = 0,
2945 EC_CODEC_SAMPLE_DEPTH_24 = 1,
2948 enum ec_i2s_config {
2950 EC_DAI_FMT_RIGHT_J = 1,
2951 EC_DAI_FMT_LEFT_J = 2,
2952 EC_DAI_FMT_PCM_A = 3,
2953 EC_DAI_FMT_PCM_B = 4,
2954 EC_DAI_FMT_PCM_TDM = 5,
2957 struct __ec_todo_packed ec_param_codec_i2s {
2958 /* enum ec_codec_i2s_subcmd */
2962 * EC_CODEC_SET_SAMPLE_DEPTH
2963 * Value should be one of ec_sample_depth_value.
2969 * Value should be 0~43 for both channels.
2971 struct __ec_align1 ec_param_codec_i2s_set_gain {
2977 * EC_CODEC_I2S_ENABLE
2978 * 1 to enable, 0 to disable.
2983 * EC_CODEC_I2S_SET_COFNIG
2984 * Value should be one of ec_i2s_config.
2989 * EC_CODEC_I2S_SET_TDM_CONFIG
2990 * Value should be one of ec_i2s_config.
2992 struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
3001 uint8_t adjacent_to_ch0;
3002 uint8_t adjacent_to_ch1;
3006 * EC_CODEC_I2S_SET_BCLK
3013 * For subcommand EC_CODEC_GET_GAIN.
3015 struct ec_response_codec_gain {
3020 /*****************************************************************************/
3021 /* System commands */
3024 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3025 * necessarily reboot the EC. Rename to "image" or something similar?
3027 #define EC_CMD_REBOOT_EC 0xd2
3030 enum ec_reboot_cmd {
3031 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
3032 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3033 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
3034 /* (command 3 was jump to RW-B) */
3035 EC_REBOOT_COLD = 4, /* Cold-reboot */
3036 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3037 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
3040 /* Flags for ec_params_reboot_ec.reboot_flags */
3041 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
3042 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
3044 struct ec_params_reboot_ec {
3045 uint8_t cmd; /* enum ec_reboot_cmd */
3046 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3050 * Get information on last EC panic.
3052 * Returns variable-length platform-dependent panic information. See panic.h
3055 #define EC_CMD_GET_PANIC_INFO 0xd3
3057 /*****************************************************************************/
3061 * These are valid ONLY on the ACPI command/data port.
3065 * ACPI Read Embedded Controller
3067 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3069 * Use the following sequence:
3071 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3072 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3073 * - Write address to EC_LPC_ADDR_ACPI_DATA
3074 * - Wait for EC_LPC_CMDR_DATA bit to set
3075 * - Read value from EC_LPC_ADDR_ACPI_DATA
3077 #define EC_CMD_ACPI_READ 0x80
3080 * ACPI Write Embedded Controller
3082 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3084 * Use the following sequence:
3086 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3087 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3088 * - Write address to EC_LPC_ADDR_ACPI_DATA
3089 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3090 * - Write value to EC_LPC_ADDR_ACPI_DATA
3092 #define EC_CMD_ACPI_WRITE 0x81
3095 * ACPI Query Embedded Controller
3097 * This clears the lowest-order bit in the currently pending host events, and
3098 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3099 * event 0x80000000 = 32), or 0 if no event was pending.
3101 #define EC_CMD_ACPI_QUERY_EVENT 0x84
3103 /* Valid addresses in ACPI memory space, for read/write commands */
3105 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3106 #define EC_ACPI_MEM_VERSION 0x00
3108 * Test location; writing value here updates test compliment byte to (0xff -
3111 #define EC_ACPI_MEM_TEST 0x01
3112 /* Test compliment; writes here are ignored. */
3113 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3115 /* Keyboard backlight brightness percent (0 - 100) */
3116 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3117 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3118 #define EC_ACPI_MEM_FAN_DUTY 0x04
3121 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3122 * independent thresholds attached to them. The current value of the ID
3123 * register determines which sensor is affected by the THRESHOLD and COMMIT
3124 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3125 * as the memory-mapped sensors. The COMMIT register applies those settings.
3127 * The spec does not mandate any way to read back the threshold settings
3128 * themselves, but when a threshold is crossed the AP needs a way to determine
3129 * which sensor(s) are responsible. Each reading of the ID register clears and
3130 * returns one sensor ID that has crossed one of its threshold (in either
3131 * direction) since the last read. A value of 0xFF means "no new thresholds
3132 * have tripped". Setting or enabling the thresholds for a sensor will clear
3133 * the unread event count for that sensor.
3135 #define EC_ACPI_MEM_TEMP_ID 0x05
3136 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3137 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
3139 * Here are the bits for the COMMIT register:
3140 * bit 0 selects the threshold index for the chosen sensor (0/1)
3141 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3142 * Each write to the commit register affects one threshold.
3144 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3145 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3149 * Set the thresholds for sensor 2 to 50 C and 60 C:
3150 * write 2 to [0x05] -- select temp sensor 2
3151 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3152 * write 0x2 to [0x07] -- enable threshold 0 with this value
3153 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3154 * write 0x3 to [0x07] -- enable threshold 1 with this value
3156 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3157 * write 2 to [0x05] -- select temp sensor 2
3158 * write 0x1 to [0x07] -- disable threshold 1
3161 /* DPTF battery charging current limit */
3162 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3164 /* Charging limit is specified in 64 mA steps */
3165 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3166 /* Value to disable DPTF battery charging limit */
3167 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
3169 /* Current version of ACPI memory address space */
3170 #define EC_ACPI_MEM_VERSION_CURRENT 1
3173 /*****************************************************************************/
3177 * These commands are for sending and receiving message via HDMI CEC
3179 #define EC_MAX_CEC_MSG_LEN 16
3181 /* CEC message from the AP to be written on the CEC bus */
3182 #define EC_CMD_CEC_WRITE_MSG 0x00B8
3185 * struct ec_params_cec_write - Message to write to the CEC bus
3186 * @msg: message content to write to the CEC bus
3188 struct ec_params_cec_write {
3189 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3192 /* Set various CEC parameters */
3193 #define EC_CMD_CEC_SET 0x00BA
3196 * struct ec_params_cec_set - CEC parameters set
3197 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3198 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3199 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3200 * this field encodes the requested logical address between 0 and 15
3201 * or 0xff to unregister
3203 struct ec_params_cec_set {
3204 uint8_t cmd; /* enum cec_command */
3208 /* Read various CEC parameters */
3209 #define EC_CMD_CEC_GET 0x00BB
3212 * struct ec_params_cec_get - CEC parameters get
3213 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3215 struct ec_params_cec_get {
3216 uint8_t cmd; /* enum cec_command */
3220 * struct ec_response_cec_get - CEC parameters get response
3221 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3222 * disabled or 1 if CEC functionality is enabled,
3223 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3224 * configured logical address between 0 and 15 or 0xff if unregistered
3226 struct ec_response_cec_get {
3230 /* CEC parameters command */
3231 enum ec_cec_command {
3232 /* CEC reading, writing and events enable */
3234 /* CEC logical address */
3235 CEC_CMD_LOGICAL_ADDRESS,
3238 /* Events from CEC to AP */
3239 enum mkbp_cec_event {
3240 /* Outgoing message was acknowledged by a follower */
3241 EC_MKBP_CEC_SEND_OK = BIT(0),
3242 /* Outgoing message was not acknowledged */
3243 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3246 /*****************************************************************************/
3250 * These do not follow the normal rules for commands. See each command for
3257 * This command will work even when the EC LPC interface is busy, because the
3258 * reboot command is processed at interrupt level. Note that when the EC
3259 * reboots, the host will reboot too, so there is no response to this command.
3261 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3263 #define EC_CMD_REBOOT 0xd1 /* Think "die" */
3266 * Resend last response (not supported on LPC).
3268 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3269 * there was no previous command, or the previous command's response was too
3272 #define EC_CMD_RESEND_RESPONSE 0xdb
3275 * This header byte on a command indicate version 0. Any header byte less
3276 * than this means that we are talking to an old EC which doesn't support
3277 * versioning. In that case, we assume version 0.
3279 * Header bytes greater than this indicate a later version. For example,
3280 * EC_CMD_VERSION0 + 1 means we are using version 1.
3282 * The old EC interface must not use commands 0xdc or higher.
3284 #define EC_CMD_VERSION0 0xdc
3286 #endif /* !__ACPI__ */
3288 /*****************************************************************************/
3292 * These commands are for PD MCU communication.
3295 /* EC to PD MCU exchange status command */
3296 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
3298 /* Status of EC being sent to PD */
3299 struct ec_params_pd_status {
3300 int8_t batt_soc; /* battery state of charge */
3303 /* Status of PD being sent back to EC */
3304 struct ec_response_pd_status {
3305 int8_t status; /* PD MCU status */
3306 uint32_t curr_lim_ma; /* input current limit */
3309 /* Set USB type-C port role and muxes */
3310 #define EC_CMD_USB_PD_CONTROL 0x101
3312 enum usb_pd_control_role {
3313 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3314 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3315 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3316 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3317 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3320 enum usb_pd_control_mux {
3321 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3322 USB_PD_CTRL_MUX_NONE = 1,
3323 USB_PD_CTRL_MUX_USB = 2,
3324 USB_PD_CTRL_MUX_DP = 3,
3325 USB_PD_CTRL_MUX_DOCK = 4,
3326 USB_PD_CTRL_MUX_AUTO = 5,
3329 enum usb_pd_control_swap {
3330 USB_PD_CTRL_SWAP_NONE = 0,
3331 USB_PD_CTRL_SWAP_DATA = 1,
3332 USB_PD_CTRL_SWAP_POWER = 2,
3333 USB_PD_CTRL_SWAP_VCONN = 3,
3334 USB_PD_CTRL_SWAP_COUNT
3337 struct ec_params_usb_pd_control {
3344 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3345 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3346 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3348 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3349 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
3350 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
3351 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
3352 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
3353 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3354 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3356 struct ec_response_usb_pd_control_v1 {
3363 #define EC_CMD_USB_PD_PORTS 0x102
3365 /* Maximum number of PD ports on a device, num_ports will be <= this */
3366 #define EC_USB_PD_MAX_PORTS 8
3368 struct ec_response_usb_pd_ports {
3372 #define EC_CMD_USB_PD_POWER_INFO 0x103
3374 #define PD_POWER_CHARGING_PORT 0xff
3375 struct ec_params_usb_pd_power_info {
3383 USB_CHG_TYPE_PROPRIETARY,
3384 USB_CHG_TYPE_BC12_DCP,
3385 USB_CHG_TYPE_BC12_CDP,
3386 USB_CHG_TYPE_BC12_SDP,
3389 USB_CHG_TYPE_UNKNOWN,
3391 enum usb_power_roles {
3392 USB_PD_PORT_POWER_DISCONNECTED,
3393 USB_PD_PORT_POWER_SOURCE,
3394 USB_PD_PORT_POWER_SINK,
3395 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3398 struct usb_chg_measures {
3399 uint16_t voltage_max;
3400 uint16_t voltage_now;
3401 uint16_t current_max;
3402 uint16_t current_lim;
3405 struct ec_response_usb_pd_power_info {
3410 struct usb_chg_measures meas;
3414 struct ec_params_usb_pd_info_request {
3419 * This command will return the number of USB PD charge port + the number
3420 * of dedicated port present.
3421 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
3423 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
3424 struct ec_response_charge_port_count {
3428 /* Read USB-PD Device discovery info */
3429 #define EC_CMD_USB_PD_DISCOVERY 0x0113
3430 struct ec_params_usb_pd_discovery_entry {
3431 uint16_t vid; /* USB-IF VID */
3432 uint16_t pid; /* USB-IF PID */
3433 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3436 /* Override default charge behavior */
3437 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
3439 /* Negative port parameters have special meaning */
3440 enum usb_pd_override_ports {
3441 OVERRIDE_DONT_CHARGE = -2,
3443 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
3446 struct ec_params_charge_port_override {
3447 int16_t override_port; /* Override port# */
3450 /* Read (and delete) one entry of PD event log */
3451 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3453 struct ec_response_pd_log {
3454 uint32_t timestamp; /* relative timestamp in milliseconds */
3455 uint8_t type; /* event type : see PD_EVENT_xx below */
3456 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3457 uint16_t data; /* type-defined data payload */
3458 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3461 /* The timestamp is the microsecond counter shifted to get about a ms. */
3462 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3464 #define PD_LOG_SIZE_MASK 0x1f
3465 #define PD_LOG_PORT_MASK 0xe0
3466 #define PD_LOG_PORT_SHIFT 5
3467 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3468 ((size) & PD_LOG_SIZE_MASK))
3469 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3470 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3472 /* PD event log : entry types */
3474 #define PD_EVENT_MCU_BASE 0x00
3475 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3476 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3477 /* Reserved for custom board event */
3478 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3479 /* PD generic accessory events */
3480 #define PD_EVENT_ACC_BASE 0x20
3481 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3482 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3483 /* PD power supply events */
3484 #define PD_EVENT_PS_BASE 0x40
3485 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3486 /* PD video dongles events */
3487 #define PD_EVENT_VIDEO_BASE 0x60
3488 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3489 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3490 /* Returned in the "type" field, when there is no entry available */
3491 #define PD_EVENT_NO_ENTRY 0xff
3494 * PD_EVENT_MCU_CHARGE event definition :
3495 * the payload is "struct usb_chg_measures"
3496 * the data field contains the port state flags as defined below :
3498 /* Port partner is a dual role device */
3499 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
3500 /* Port is the pending override port */
3501 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
3502 /* Port is the override port */
3503 #define CHARGE_FLAGS_OVERRIDE BIT(13)
3505 #define CHARGE_FLAGS_TYPE_SHIFT 3
3506 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
3507 /* Power delivery role */
3508 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3511 * PD_EVENT_PS_FAULT data field flags definition :
3513 #define PS_FAULT_OCP 1
3514 #define PS_FAULT_FAST_OCP 2
3515 #define PS_FAULT_OVP 3
3516 #define PS_FAULT_DISCH 4
3519 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3521 struct mcdp_version {
3530 struct mcdp_version irom;
3531 struct mcdp_version fw;
3534 /* struct mcdp_info field decoding */
3535 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3536 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3538 /* Get info about USB-C SS muxes */
3539 #define EC_CMD_USB_PD_MUX_INFO 0x11a
3541 struct ec_params_usb_pd_mux_info {
3542 uint8_t port; /* USB-C port number */
3545 /* Flags representing mux state */
3546 #define USB_PD_MUX_USB_ENABLED (1 << 0)
3547 #define USB_PD_MUX_DP_ENABLED (1 << 1)
3548 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3549 #define USB_PD_MUX_HPD_IRQ (1 << 3)
3551 struct ec_response_usb_pd_mux_info {
3552 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3555 /*****************************************************************************/
3559 * Some platforms have sub-processors chained to each other. For example.
3561 * AP <--> EC <--> PD MCU
3563 * The top 2 bits of the command number are used to indicate which device the
3564 * command is intended for. Device 0 is always the device receiving the
3565 * command; other device mapping is board-specific.
3567 * When a device receives a command to be passed to a sub-processor, it passes
3568 * it on with the device number set back to 0. This allows the sub-processor
3569 * to remain blissfully unaware of whether the command originated on the next
3570 * device up the chain, or was passed through from the AP.
3572 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3573 * AP sends command 0x4002 to the EC
3574 * EC sends command 0x0002 to the PD MCU
3575 * EC forwards PD MCU response back to the AP
3578 /* Offset and max command number for sub-device n */
3579 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3580 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3582 /*****************************************************************************/
3584 * Deprecated constants. These constants have been renamed for clarity. The
3585 * meaning and size has not changed. Programs that use the old names should
3586 * switch to the new names soon, as the old names may not be carried forward
3589 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3590 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3591 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3593 #endif /* __CROS_EC_COMMANDS_H */