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
17 * Current version of this protocol
19 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
20 * determined in other ways. Remove this once the kernel code no longer
23 #define EC_PROTO_VERSION 0x00000002
25 /* Command version mask */
26 #define EC_VER_MASK(version) (1UL << (version))
28 /* I/O addresses for ACPI commands */
29 #define EC_LPC_ADDR_ACPI_DATA 0x62
30 #define EC_LPC_ADDR_ACPI_CMD 0x66
32 /* I/O addresses for host command */
33 #define EC_LPC_ADDR_HOST_DATA 0x200
34 #define EC_LPC_ADDR_HOST_CMD 0x204
36 /* I/O addresses for host command args and params */
37 /* Protocol version 2 */
38 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
39 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
40 * EC_PROTO2_MAX_PARAM_SIZE */
41 /* Protocol version 3 */
42 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
43 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
45 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
46 * and they tell the kernel that so we have to think of it as two parts. */
47 #define EC_HOST_CMD_REGION0 0x800
48 #define EC_HOST_CMD_REGION1 0x880
49 #define EC_HOST_CMD_REGION_SIZE 0x80
51 /* EC command register bit functions */
52 #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
53 #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
54 #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
55 #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
56 #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
57 #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
58 #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
60 #define EC_LPC_ADDR_MEMMAP 0x900
61 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
62 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
64 /* The offset address of each type of data in mapped memory. */
65 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
66 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
67 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
68 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
69 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
70 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
71 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
72 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
73 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
74 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
75 /* Unused 0x28 - 0x2f */
76 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
77 /* Unused 0x31 - 0x33 */
78 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
79 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
80 /* Battery values are all 32 bits */
81 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
82 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
83 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
84 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
85 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
86 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
87 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
88 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
89 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
90 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
91 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
92 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
93 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
94 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
95 /* Unused 0x84 - 0x8f */
96 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
98 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
99 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
100 /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
103 /* Define the format of the accelerometer mapped memory status byte. */
104 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
105 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
106 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
108 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
109 #define EC_TEMP_SENSOR_ENTRIES 16
111 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
113 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
115 #define EC_TEMP_SENSOR_B_ENTRIES 8
117 /* Special values for mapped temperature sensors */
118 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
119 #define EC_TEMP_SENSOR_ERROR 0xfe
120 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
121 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
123 * The offset of temperature value stored in mapped memory. This allows
124 * reporting a temperature range of 200K to 454K = -73C to 181C.
126 #define EC_TEMP_SENSOR_OFFSET 200
129 * Number of ALS readings at EC_MEMMAP_ALS
131 #define EC_ALS_ENTRIES 2
134 * The default value a temperature sensor will return when it is present but
135 * has not been read this boot. This is a reasonable number to avoid
136 * triggering alarms on the host.
138 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
140 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
141 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
142 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
144 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
145 #define EC_BATT_FLAG_AC_PRESENT 0x01
146 #define EC_BATT_FLAG_BATT_PRESENT 0x02
147 #define EC_BATT_FLAG_DISCHARGING 0x04
148 #define EC_BATT_FLAG_CHARGING 0x08
149 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
151 /* Switch flags at EC_MEMMAP_SWITCHES */
152 #define EC_SWITCH_LID_OPEN 0x01
153 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
154 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
155 /* Was recovery requested via keyboard; now unused. */
156 #define EC_SWITCH_IGNORE1 0x08
157 /* Recovery requested via dedicated signal (from servo board) */
158 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
159 /* Was fake developer mode switch; now unused. Remove in next refactor. */
160 #define EC_SWITCH_IGNORE0 0x20
162 /* Host command interface flags */
163 /* Host command interface supports LPC args (LPC interface only) */
164 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
165 /* Host command interface supports version 3 protocol */
166 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
168 /* Wireless switch flags */
169 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
170 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
171 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
172 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
173 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
176 * This header file is used in coreboot both in C and ACPI code. The ACPI code
177 * is pre-processed to handle constants but the ASL compiler is unable to
178 * handle actual C code so keep it separate.
183 * Define __packed if someone hasn't beat us to it. Linux kernel style
184 * checking prefers __packed over __attribute__((packed)).
187 #define __packed __attribute__((packed))
190 /* LPC command status byte masks */
191 /* EC has written a byte in the data register and host hasn't read it yet */
192 #define EC_LPC_STATUS_TO_HOST 0x01
193 /* Host has written a command/data byte and the EC hasn't read it yet */
194 #define EC_LPC_STATUS_FROM_HOST 0x02
195 /* EC is processing a command */
196 #define EC_LPC_STATUS_PROCESSING 0x04
197 /* Last write to EC was a command, not data */
198 #define EC_LPC_STATUS_LAST_CMD 0x08
199 /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
200 #define EC_LPC_STATUS_BURST_MODE 0x10
201 /* SCI event is pending (requesting SCI query) */
202 #define EC_LPC_STATUS_SCI_PENDING 0x20
203 /* SMI event is pending (requesting SMI query) */
204 #define EC_LPC_STATUS_SMI_PENDING 0x40
206 #define EC_LPC_STATUS_RESERVED 0x80
209 * EC is busy. This covers both the EC processing a command, and the host has
210 * written a new command but the EC hasn't picked it up yet.
212 #define EC_LPC_STATUS_BUSY_MASK \
213 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
215 /* Host command response codes */
218 EC_RES_INVALID_COMMAND = 1,
220 EC_RES_INVALID_PARAM = 3,
221 EC_RES_ACCESS_DENIED = 4,
222 EC_RES_INVALID_RESPONSE = 5,
223 EC_RES_INVALID_VERSION = 6,
224 EC_RES_INVALID_CHECKSUM = 7,
225 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
226 EC_RES_UNAVAILABLE = 9, /* No response available */
227 EC_RES_TIMEOUT = 10, /* We got a timeout */
228 EC_RES_OVERFLOW = 11, /* Table / data overflow */
229 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
230 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
231 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
235 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
236 * EC command uses code 0 to mean "no event pending". We explicitly specify
237 * each value in the enum listing so they won't change if we delete/insert an
238 * item or rearrange the list (it needs to be stable across platforms, not
239 * just within a single compiled instance).
241 enum host_event_code {
242 EC_HOST_EVENT_LID_CLOSED = 1,
243 EC_HOST_EVENT_LID_OPEN = 2,
244 EC_HOST_EVENT_POWER_BUTTON = 3,
245 EC_HOST_EVENT_AC_CONNECTED = 4,
246 EC_HOST_EVENT_AC_DISCONNECTED = 5,
247 EC_HOST_EVENT_BATTERY_LOW = 6,
248 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
249 EC_HOST_EVENT_BATTERY = 8,
250 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
251 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
252 EC_HOST_EVENT_THERMAL = 11,
253 EC_HOST_EVENT_USB_CHARGER = 12,
254 EC_HOST_EVENT_KEY_PRESSED = 13,
256 * EC has finished initializing the host interface. The host can check
257 * for this event following sending a EC_CMD_REBOOT_EC command to
258 * determine when the EC is ready to accept subsequent commands.
260 EC_HOST_EVENT_INTERFACE_READY = 14,
261 /* Keyboard recovery combo has been pressed */
262 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
264 /* Shutdown due to thermal overload */
265 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
266 /* Shutdown due to battery level too low */
267 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
269 /* Suggest that the AP throttle itself */
270 EC_HOST_EVENT_THROTTLE_START = 18,
271 /* Suggest that the AP resume normal speed */
272 EC_HOST_EVENT_THROTTLE_STOP = 19,
274 /* Hang detect logic detected a hang and host event timeout expired */
275 EC_HOST_EVENT_HANG_DETECT = 20,
276 /* Hang detect logic detected a hang and warm rebooted the AP */
277 EC_HOST_EVENT_HANG_REBOOT = 21,
278 /* PD MCU triggering host event */
279 EC_HOST_EVENT_PD_MCU = 22,
281 /* EC desires to change state of host-controlled USB mux */
282 EC_HOST_EVENT_USB_MUX = 28,
284 /* EC RTC event occurred */
285 EC_HOST_EVENT_RTC = 26,
288 * The high bit of the event mask is not used as a host event code. If
289 * it reads back as set, then the entire event mask should be
290 * considered invalid by the host. This can happen when reading the
291 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
292 * not initialized on the EC, or improperly configured on the host.
294 EC_HOST_EVENT_INVALID = 32
296 /* Host event mask */
297 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
300 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
301 * @flags: The host argument flags.
302 * @command_version: Command version.
303 * @data_size: The length of data.
304 * @checksum: Checksum; sum of command + flags + command_version + data_size +
305 * all params/response data bytes.
307 struct ec_lpc_host_args {
309 uint8_t command_version;
314 /* Flags for ec_lpc_host_args.flags */
316 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
319 * If EC gets a command and this flag is not set, this is an old-style command.
320 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
321 * unknown length. EC must respond with an old-style response (that is,
322 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
324 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
326 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
328 * If EC responds to a command and this flag is not set, this is an old-style
329 * response. Command version is 0 and response data from EC is at
330 * EC_LPC_ADDR_OLD_PARAM with unknown length.
332 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
334 /*****************************************************************************/
336 * Byte codes returned by EC over SPI interface.
338 * These can be used by the AP to debug the EC interface, and to determine
339 * when the EC is not in a state where it will ever get around to responding
342 * Example of sequence of bytes read from EC for a current good transfer:
343 * 1. - - AP asserts chip select (CS#)
344 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
345 * 3. - - EC starts handling CS# interrupt
346 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
347 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
348 * bytes looking for EC_SPI_FRAME_START
349 * 6. - - EC finishes processing and sets up response
350 * 7. EC_SPI_FRAME_START - AP reads frame byte
351 * 8. (response packet) - AP reads response packet
352 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
353 * 10 - - AP deasserts chip select
354 * 11 - - EC processes CS# interrupt and sets up DMA for
357 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
358 * the following byte values:
364 * Then the EC found an error in the request, or was not ready for the request
365 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
366 * because the EC is unable to tell when the AP is done sending its request.
370 * Framing byte which precedes a response packet from the EC. After sending a
371 * request, the AP will clock in bytes until it sees the framing byte, then
372 * clock in the response packet.
374 #define EC_SPI_FRAME_START 0xec
377 * Padding bytes which are clocked out after the end of a response packet.
379 #define EC_SPI_PAST_END 0xed
382 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
383 * that the AP will send a valid packet header (starting with
384 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
386 #define EC_SPI_RX_READY 0xf8
389 * EC has started receiving the request from the AP, but hasn't started
392 #define EC_SPI_RECEIVING 0xf9
394 /* EC has received the entire request from the AP and is processing it. */
395 #define EC_SPI_PROCESSING 0xfa
398 * EC received bad data from the AP, such as a packet header with an invalid
399 * length. EC will ignore all data until chip select deasserts.
401 #define EC_SPI_RX_BAD_DATA 0xfb
404 * EC received data from the AP before it was ready. That is, the AP asserted
405 * chip select and started clocking data before the EC was ready to receive it.
406 * EC will ignore all data until chip select deasserts.
408 #define EC_SPI_NOT_READY 0xfc
411 * EC was ready to receive a request from the AP. EC has treated the byte sent
412 * by the AP as part of a request packet, or (for old-style ECs) is processing
413 * a fully received packet but is not ready to respond yet.
415 #define EC_SPI_OLD_READY 0xfd
417 /*****************************************************************************/
420 * Protocol version 2 for I2C and SPI send a request this way:
422 * 0 EC_CMD_VERSION0 + (command version)
424 * 2 Length of params = N
425 * 3..N+2 Params, if any
426 * N+3 8-bit checksum of bytes 0..N+2
428 * The corresponding response is:
430 * 0 Result code (EC_RES_*)
431 * 1 Length of params = M
432 * 2..M+1 Params, if any
433 * M+2 8-bit checksum of bytes 0..M+1
435 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
436 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
437 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
438 EC_PROTO2_REQUEST_TRAILER_BYTES)
440 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
441 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
442 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
443 EC_PROTO2_RESPONSE_TRAILER_BYTES)
445 /* Parameter length was limited by the LPC interface */
446 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
448 /* Maximum request and response packet sizes for protocol version 2 */
449 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
450 EC_PROTO2_MAX_PARAM_SIZE)
451 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
452 EC_PROTO2_MAX_PARAM_SIZE)
454 /*****************************************************************************/
457 * Value written to legacy command port / prefix byte to indicate protocol
458 * 3+ structs are being used. Usage is bus-dependent.
460 #define EC_COMMAND_PROTOCOL_3 0xda
462 #define EC_HOST_REQUEST_VERSION 3
465 * struct ec_host_request - Version 3 request from host.
466 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
467 * receives a header with a version it doesn't know how to
469 * @checksum: Checksum of request and data; sum of all bytes including checksum
471 * @command: Command to send (EC_CMD_...)
472 * @command_version: Command version.
473 * @reserved: Unused byte in current protocol version; set to 0.
474 * @data_len: Length of data which follows this header.
476 struct ec_host_request {
477 uint8_t struct_version;
480 uint8_t command_version;
485 #define EC_HOST_RESPONSE_VERSION 3
488 * struct ec_host_response - Version 3 response from EC.
489 * @struct_version: Struct version (=3).
490 * @checksum: Checksum of response and data; sum of all bytes including
491 * checksum should total to 0.
492 * @result: EC's response to the command (separate from communication failure)
493 * @data_len: Length of data which follows this header.
494 * @reserved: Unused bytes in current protocol version; set to 0.
496 struct ec_host_response {
497 uint8_t struct_version;
504 /*****************************************************************************/
508 * Each command is an 16-bit command value. Commands which take params or
509 * return response data specify structs for that data. If no struct is
510 * specified, the command does not input or output data, respectively.
511 * Parameter/response length is implicit in the structs. Some underlying
512 * communication protocols (I2C, SPI) may add length or checksum headers, but
513 * those are implementation-dependent and not defined here.
516 /*****************************************************************************/
517 /* General / test commands */
520 * Get protocol version, used to deal with non-backward compatible protocol
523 #define EC_CMD_PROTO_VERSION 0x00
526 * struct ec_response_proto_version - Response to the proto version command.
527 * @version: The protocol version.
529 struct ec_response_proto_version {
534 * Hello. This is a simple command to test the EC is responsive to
537 #define EC_CMD_HELLO 0x01
540 * struct ec_params_hello - Parameters to the hello command.
541 * @in_data: Pass anything here.
543 struct ec_params_hello {
548 * struct ec_response_hello - Response to the hello command.
549 * @out_data: Output will be in_data + 0x01020304.
551 struct ec_response_hello {
555 /* Get version number */
556 #define EC_CMD_GET_VERSION 0x02
558 enum ec_current_image {
559 EC_IMAGE_UNKNOWN = 0,
565 * struct ec_response_get_version - Response to the get version command.
566 * @version_string_ro: Null-terminated RO firmware version string.
567 * @version_string_rw: Null-terminated RW firmware version string.
568 * @reserved: Unused bytes; was previously RW-B firmware version string.
569 * @current_image: One of ec_current_image.
571 struct ec_response_get_version {
572 char version_string_ro[32];
573 char version_string_rw[32];
575 uint32_t current_image;
579 #define EC_CMD_READ_TEST 0x03
582 * struct ec_params_read_test - Parameters for the read test command.
583 * @offset: Starting value for read buffer.
584 * @size: Size to read in bytes.
586 struct ec_params_read_test {
592 * struct ec_response_read_test - Response to the read test command.
593 * @data: Data returned by the read test command.
595 struct ec_response_read_test {
600 * Get build information
602 * Response is null-terminated string.
604 #define EC_CMD_GET_BUILD_INFO 0x04
607 #define EC_CMD_GET_CHIP_INFO 0x05
610 * struct ec_response_get_chip_info - Response to the get chip info command.
611 * @vendor: Null-terminated string for chip vendor.
612 * @name: Null-terminated string for chip name.
613 * @revision: Null-terminated string for chip mask version.
615 struct ec_response_get_chip_info {
621 /* Get board HW version */
622 #define EC_CMD_GET_BOARD_VERSION 0x06
625 * struct ec_response_board_version - Response to the board version command.
626 * @board_version: A monotonously incrementing number.
628 struct ec_response_board_version {
629 uint16_t board_version;
633 * Read memory-mapped data.
635 * This is an alternate interface to memory-mapped data for bus protocols
636 * which don't support direct-mapped memory - I2C, SPI, etc.
638 * Response is params.size bytes of data.
640 #define EC_CMD_READ_MEMMAP 0x07
643 * struct ec_params_read_memmap - Parameters for the read memory map command.
644 * @offset: Offset in memmap (EC_MEMMAP_*).
645 * @size: Size to read in bytes.
647 struct ec_params_read_memmap {
652 /* Read versions supported for a command */
653 #define EC_CMD_GET_CMD_VERSIONS 0x08
656 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
657 * @cmd: Command to check.
659 struct ec_params_get_cmd_versions {
664 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
666 * @cmd: Command to check.
668 struct ec_params_get_cmd_versions_v1 {
673 * struct ec_response_get_cmd_version - Response to the get command versions.
674 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
677 struct ec_response_get_cmd_versions {
678 uint32_t version_mask;
682 * Check EC communcations status (busy). This is needed on i2c/spi but not
683 * on lpc since it has its own out-of-band busy indicator.
685 * lpc must read the status from the command register. Attempting this on
686 * lpc will overwrite the args/parameter space and corrupt its data.
688 #define EC_CMD_GET_COMMS_STATUS 0x09
690 /* Avoid using ec_status which is for return values */
691 enum ec_comms_status {
692 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
696 * struct ec_response_get_comms_status - Response to the get comms status
698 * @flags: Mask of enum ec_comms_status.
700 struct ec_response_get_comms_status {
701 uint32_t flags; /* Mask of enum ec_comms_status */
704 /* Fake a variety of responses, purely for testing purposes. */
705 #define EC_CMD_TEST_PROTOCOL 0x0a
707 /* Tell the EC what to send back to us. */
708 struct ec_params_test_protocol {
714 /* Here it comes... */
715 struct ec_response_test_protocol {
719 /* Get prococol information */
720 #define EC_CMD_GET_PROTOCOL_INFO 0x0b
722 /* Flags for ec_response_get_protocol_info.flags */
723 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
724 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
727 * struct ec_response_get_protocol_info - Response to the get protocol info.
728 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
730 * @max_request_packet_size: Maximum request packet size in bytes.
731 * @max_response_packet_size: Maximum response packet size in bytes.
732 * @flags: see EC_PROTOCOL_INFO_*
734 struct ec_response_get_protocol_info {
735 /* Fields which exist if at least protocol version 3 supported */
736 uint32_t protocol_versions;
737 uint16_t max_request_packet_size;
738 uint16_t max_response_packet_size;
743 /*****************************************************************************/
744 /* Get/Set miscellaneous values */
746 /* The upper byte of .flags tells what to do (nothing means "get") */
747 #define EC_GSV_SET 0x80000000
750 * The lower three bytes of .flags identifies the parameter, if that has
751 * meaning for an individual command.
753 #define EC_GSV_PARAM_MASK 0x00ffffff
755 struct ec_params_get_set_value {
760 struct ec_response_get_set_value {
765 /* More than one command can use these structs to get/set paramters. */
766 #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
768 /*****************************************************************************/
769 /* List the features supported by the firmware */
770 #define EC_CMD_GET_FEATURES 0x0d
772 /* Supported features */
773 enum ec_feature_code {
775 * This image contains a limited set of features. Another image
776 * in RW partition may support more features.
778 EC_FEATURE_LIMITED = 0,
780 * Commands for probing/reading/writing/erasing the flash in the
783 EC_FEATURE_FLASH = 1,
785 * Can control the fan speed directly.
787 EC_FEATURE_PWM_FAN = 2,
789 * Can control the intensity of the keyboard backlight.
791 EC_FEATURE_PWM_KEYB = 3,
793 * Support Google lightbar, introduced on Pixel.
795 EC_FEATURE_LIGHTBAR = 4,
796 /* Control of LEDs */
798 /* Exposes an interface to control gyro and sensors.
799 * The host goes through the EC to access these sensors.
800 * In addition, the EC may provide composite sensors, like lid angle.
802 EC_FEATURE_MOTION_SENSE = 6,
803 /* The keyboard is controlled by the EC */
805 /* The AP can use part of the EC flash as persistent storage. */
806 EC_FEATURE_PSTORE = 8,
807 /* The EC monitors BIOS port 80h, and can return POST codes. */
808 EC_FEATURE_PORT80 = 9,
810 * Thermal management: include TMP specific commands.
811 * Higher level than direct fan control.
813 EC_FEATURE_THERMAL = 10,
814 /* Can switch the screen backlight on/off */
815 EC_FEATURE_BKLIGHT_SWITCH = 11,
816 /* Can switch the wifi module on/off */
817 EC_FEATURE_WIFI_SWITCH = 12,
818 /* Monitor host events, through for example SMI or SCI */
819 EC_FEATURE_HOST_EVENTS = 13,
820 /* The EC exposes GPIO commands to control/monitor connected devices. */
821 EC_FEATURE_GPIO = 14,
822 /* The EC can send i2c messages to downstream devices. */
824 /* Command to control charger are included */
825 EC_FEATURE_CHARGER = 16,
826 /* Simple battery support. */
827 EC_FEATURE_BATTERY = 17,
829 * Support Smart battery protocol
830 * (Common Smart Battery System Interface Specification)
832 EC_FEATURE_SMART_BATTERY = 18,
833 /* EC can detect when the host hangs. */
834 EC_FEATURE_HANG_DETECT = 19,
835 /* Report power information, for pit only */
837 /* Another Cros EC device is present downstream of this one */
838 EC_FEATURE_SUB_MCU = 21,
839 /* Support USB Power delivery (PD) commands */
840 EC_FEATURE_USB_PD = 22,
841 /* Control USB multiplexer, for audio through USB port for instance. */
842 EC_FEATURE_USB_MUX = 23,
843 /* Motion Sensor code has an internal software FIFO */
844 EC_FEATURE_MOTION_SENSE_FIFO = 24,
845 /* Support temporary secure vstore */
846 EC_FEATURE_VSTORE = 25,
847 /* EC decides on USB-C SS mux state, muxes configured by host */
848 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
849 /* EC has RTC feature that can be controlled by host commands */
851 /* The MCU exposes a Fingerprint sensor */
852 EC_FEATURE_FINGERPRINT = 28,
853 /* The MCU exposes a Touchpad */
854 EC_FEATURE_TOUCHPAD = 29,
855 /* The MCU has RWSIG task enabled */
856 EC_FEATURE_RWSIG = 30,
857 /* EC has device events support */
858 EC_FEATURE_DEVICE_EVENT = 31,
859 /* EC supports the unified wake masks for LPC/eSPI systems */
860 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
861 /* EC supports 64-bit host events */
862 EC_FEATURE_HOST_EVENT64 = 33,
863 /* EC runs code in RAM (not in place, a.k.a. XIP) */
864 EC_FEATURE_EXEC_IN_RAM = 34,
865 /* EC supports CEC commands */
867 /* EC supports tight sensor timestamping. */
868 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
870 * EC supports tablet mode detection aligned to Chrome and allows
871 * setting of threshold by host command using
872 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
874 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
875 /* EC supports audio codec. */
876 EC_FEATURE_AUDIO_CODEC = 38,
877 /* EC Supports SCP. */
879 /* The MCU is an Integrated Sensor Hub */
883 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
884 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
886 struct ec_response_get_features {
890 /*****************************************************************************/
894 #define EC_CMD_FLASH_INFO 0x10
897 * struct ec_response_flash_info - Response to the flash info command.
898 * @flash_size: Usable flash size in bytes.
899 * @write_block_size: Write block size. Write offset and size must be a
901 * @erase_block_size: Erase block size. Erase offset and size must be a
903 * @protect_block_size: Protection block size. Protection offset and size
904 * must be a multiple of this.
906 * Version 0 returns these fields.
908 struct ec_response_flash_info {
910 uint32_t write_block_size;
911 uint32_t erase_block_size;
912 uint32_t protect_block_size;
915 /* Flags for version 1+ flash info command */
916 /* EC flash erases bits to 0 instead of 1 */
917 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
920 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
921 * @flash_size: Usable flash size in bytes.
922 * @write_block_size: Write block size. Write offset and size must be a
924 * @erase_block_size: Erase block size. Erase offset and size must be a
926 * @protect_block_size: Protection block size. Protection offset and size
927 * must be a multiple of this.
928 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
929 * size is exactly this and offset is a multiple of this.
930 * For example, an EC may have a write buffer which can do
931 * half-page operations if data is aligned, and a slower
932 * word-at-a-time write mode.
933 * @flags: Flags; see EC_FLASH_INFO_*
935 * Version 1 returns the same initial fields as version 0, with additional
938 * gcc anonymous structs don't seem to get along with the __packed directive;
939 * if they did we'd define the version 0 struct as a sub-struct of this one.
941 struct ec_response_flash_info_1 {
942 /* Version 0 fields; see above for description */
944 uint32_t write_block_size;
945 uint32_t erase_block_size;
946 uint32_t protect_block_size;
948 /* Version 1 adds these fields: */
949 uint32_t write_ideal_size;
956 * Response is params.size bytes of data.
958 #define EC_CMD_FLASH_READ 0x11
961 * struct ec_params_flash_read - Parameters for the flash read command.
962 * @offset: Byte offset to read.
963 * @size: Size to read in bytes.
965 struct ec_params_flash_read {
971 #define EC_CMD_FLASH_WRITE 0x12
972 #define EC_VER_FLASH_WRITE 1
974 /* Version 0 of the flash command supported only 64 bytes of data */
975 #define EC_FLASH_WRITE_VER0_SIZE 64
978 * struct ec_params_flash_write - Parameters for the flash write command.
979 * @offset: Byte offset to write.
980 * @size: Size to write in bytes.
982 struct ec_params_flash_write {
985 /* Followed by data to write */
989 #define EC_CMD_FLASH_ERASE 0x13
992 * struct ec_params_flash_erase - Parameters for the flash erase command.
993 * @offset: Byte offset to erase.
994 * @size: Size to erase in bytes.
996 struct ec_params_flash_erase {
1002 * Get/set flash protection.
1004 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1005 * firmware write protect GPIO, not all flags will take effect immediately;
1006 * some flags require a subsequent hard reset to take effect. Check the
1007 * returned flags bits to see what actually happened.
1009 * If mask=0, simply returns the current flags state.
1011 #define EC_CMD_FLASH_PROTECT 0x15
1012 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1014 /* Flags for flash protection */
1015 /* RO flash code protected when the EC boots */
1016 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1018 * RO flash code protected now. If this bit is set, at-boot status cannot
1021 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1022 /* Entire flash code protected now, until reboot. */
1023 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1024 /* Flash write protect GPIO is asserted now */
1025 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1026 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1027 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1029 * Error - flash protection is in inconsistent state. At least one bank of
1030 * flash which should be protected is not protected. Usually fixed by
1031 * re-requesting the desired flags, or by a hard reset if that fails.
1033 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1034 /* Entile flash code protected when the EC boots */
1035 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1038 * struct ec_params_flash_protect - Parameters for the flash protect command.
1039 * @mask: Bits in flags to apply.
1040 * @flags: New flags to apply.
1042 struct ec_params_flash_protect {
1048 * struct ec_response_flash_protect - Response to the flash protect command.
1049 * @flags: Current value of flash protect flags.
1050 * @valid_flags: Flags which are valid on this platform. This allows the
1051 * caller to distinguish between flags which aren't set vs. flags
1052 * which can't be set on this platform.
1053 * @writable_flags: Flags which can be changed given the current protection
1056 struct ec_response_flash_protect {
1058 uint32_t valid_flags;
1059 uint32_t writable_flags;
1063 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1064 * write protect. These commands may be reused with version > 0.
1067 /* Get the region offset/size */
1068 #define EC_CMD_FLASH_REGION_INFO 0x16
1069 #define EC_VER_FLASH_REGION_INFO 1
1071 enum ec_flash_region {
1072 /* Region which holds read-only EC image */
1073 EC_FLASH_REGION_RO = 0,
1074 /* Region which holds rewritable EC image */
1077 * Region which should be write-protected in the factory (a superset of
1078 * EC_FLASH_REGION_RO)
1080 EC_FLASH_REGION_WP_RO,
1081 /* Number of regions */
1082 EC_FLASH_REGION_COUNT,
1086 * struct ec_params_flash_region_info - Parameters for the flash region info
1088 * @region: Flash region; see EC_FLASH_REGION_*
1090 struct ec_params_flash_region_info {
1094 struct ec_response_flash_region_info {
1099 /* Read/write VbNvContext */
1100 #define EC_CMD_VBNV_CONTEXT 0x17
1101 #define EC_VER_VBNV_CONTEXT 1
1102 #define EC_VBNV_BLOCK_SIZE 16
1104 enum ec_vbnvcontext_op {
1105 EC_VBNV_CONTEXT_OP_READ,
1106 EC_VBNV_CONTEXT_OP_WRITE,
1109 struct ec_params_vbnvcontext {
1111 uint8_t block[EC_VBNV_BLOCK_SIZE];
1114 struct ec_response_vbnvcontext {
1115 uint8_t block[EC_VBNV_BLOCK_SIZE];
1118 /*****************************************************************************/
1121 /* Get fan target RPM */
1122 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1124 struct ec_response_pwm_get_fan_rpm {
1128 /* Set target fan RPM */
1129 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1131 struct ec_params_pwm_set_fan_target_rpm {
1135 /* Get keyboard backlight */
1136 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1138 struct ec_response_pwm_get_keyboard_backlight {
1143 /* Set keyboard backlight */
1144 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1146 struct ec_params_pwm_set_keyboard_backlight {
1150 /* Set target fan PWM duty cycle */
1151 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
1153 struct ec_params_pwm_set_fan_duty {
1157 #define EC_CMD_PWM_SET_DUTY 0x25
1158 /* 16 bit duty cycle, 0xffff = 100% */
1159 #define EC_PWM_MAX_DUTY 0xffff
1162 /* All types, indexed by board-specific enum pwm_channel */
1163 EC_PWM_TYPE_GENERIC = 0,
1164 /* Keyboard backlight */
1165 EC_PWM_TYPE_KB_LIGHT,
1166 /* Display backlight */
1167 EC_PWM_TYPE_DISPLAY_LIGHT,
1171 struct ec_params_pwm_set_duty {
1172 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1173 uint8_t pwm_type; /* ec_pwm_type */
1174 uint8_t index; /* Type-specific index, or 0 if unique */
1177 #define EC_CMD_PWM_GET_DUTY 0x26
1179 struct ec_params_pwm_get_duty {
1180 uint8_t pwm_type; /* ec_pwm_type */
1181 uint8_t index; /* Type-specific index, or 0 if unique */
1184 struct ec_response_pwm_get_duty {
1185 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1188 /*****************************************************************************/
1190 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1191 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1192 * into a subcommand. We'll make separate structs for subcommands with
1193 * different input args, so that we know how much to expect.
1195 #define EC_CMD_LIGHTBAR_CMD 0x28
1201 #define LB_BATTERY_LEVELS 4
1204 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1205 * host command, but the alignment is the same regardless. Keep it that way.
1207 struct lightbar_params_v0 {
1209 int32_t google_ramp_up;
1210 int32_t google_ramp_down;
1211 int32_t s3s0_ramp_up;
1212 int32_t s0_tick_delay[2]; /* AC=0/1 */
1213 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1214 int32_t s0s3_ramp_down;
1215 int32_t s3_sleep_for;
1217 int32_t s3_ramp_down;
1221 uint8_t osc_min[2]; /* AC=0/1 */
1222 uint8_t osc_max[2]; /* AC=0/1 */
1223 uint8_t w_ofs[2]; /* AC=0/1 */
1225 /* Brightness limits based on the backlight and AC. */
1226 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1227 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1228 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1230 /* Battery level thresholds */
1231 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1233 /* Map [AC][battery_level] to color index */
1234 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1235 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1238 struct rgb_s color[8]; /* 0-3 are Google colors */
1241 struct lightbar_params_v1 {
1243 int32_t google_ramp_up;
1244 int32_t google_ramp_down;
1245 int32_t s3s0_ramp_up;
1246 int32_t s0_tick_delay[2]; /* AC=0/1 */
1247 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1248 int32_t s0s3_ramp_down;
1249 int32_t s3_sleep_for;
1251 int32_t s3_ramp_down;
1252 int32_t tap_tick_delay;
1253 int32_t tap_display_time;
1255 /* Tap-for-battery params */
1256 uint8_t tap_pct_red;
1257 uint8_t tap_pct_green;
1258 uint8_t tap_seg_min_on;
1259 uint8_t tap_seg_max_on;
1260 uint8_t tap_seg_osc;
1264 uint8_t osc_min[2]; /* AC=0/1 */
1265 uint8_t osc_max[2]; /* AC=0/1 */
1266 uint8_t w_ofs[2]; /* AC=0/1 */
1268 /* Brightness limits based on the backlight and AC. */
1269 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1270 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1271 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1273 /* Battery level thresholds */
1274 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1276 /* Map [AC][battery_level] to color index */
1277 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1278 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1281 struct rgb_s color[8]; /* 0-3 are Google colors */
1284 /* Lightbar program */
1285 #define EC_LB_PROG_LEN 192
1286 struct lightbar_program {
1288 uint8_t data[EC_LB_PROG_LEN];
1291 struct ec_params_lightbar {
1292 uint8_t cmd; /* Command (see enum lightbar_command) */
1296 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1297 version, get_brightness, get_demo, suspend, resume;
1301 } set_brightness, seq, demo;
1304 uint8_t ctrl, reg, value;
1308 uint8_t led, red, green, blue;
1317 } manual_suspend_ctrl;
1319 struct lightbar_params_v0 set_params_v0;
1320 struct lightbar_params_v1 set_params_v1;
1321 struct lightbar_program set_program;
1325 struct ec_response_lightbar {
1337 } get_seq, get_brightness, get_demo;
1339 struct lightbar_params_v0 get_params_v0;
1340 struct lightbar_params_v1 get_params_v1;
1348 uint8_t red, green, blue;
1352 /* no return params */
1353 } off, on, init, set_brightness, seq, reg, set_rgb,
1354 demo, set_params_v0, set_params_v1,
1355 set_program, manual_suspend_ctrl, suspend, resume;
1359 /* Lightbar commands */
1360 enum lightbar_command {
1361 LIGHTBAR_CMD_DUMP = 0,
1362 LIGHTBAR_CMD_OFF = 1,
1363 LIGHTBAR_CMD_ON = 2,
1364 LIGHTBAR_CMD_INIT = 3,
1365 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1366 LIGHTBAR_CMD_SEQ = 5,
1367 LIGHTBAR_CMD_REG = 6,
1368 LIGHTBAR_CMD_SET_RGB = 7,
1369 LIGHTBAR_CMD_GET_SEQ = 8,
1370 LIGHTBAR_CMD_DEMO = 9,
1371 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1372 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1373 LIGHTBAR_CMD_VERSION = 12,
1374 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1375 LIGHTBAR_CMD_GET_RGB = 14,
1376 LIGHTBAR_CMD_GET_DEMO = 15,
1377 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1378 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1379 LIGHTBAR_CMD_SET_PROGRAM = 18,
1380 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1381 LIGHTBAR_CMD_SUSPEND = 20,
1382 LIGHTBAR_CMD_RESUME = 21,
1386 /*****************************************************************************/
1387 /* LED control commands */
1389 #define EC_CMD_LED_CONTROL 0x29
1392 /* LED to indicate battery state of charge */
1393 EC_LED_ID_BATTERY_LED = 0,
1395 * LED to indicate system power state (on or in suspend).
1396 * May be on power button or on C-panel.
1398 EC_LED_ID_POWER_LED,
1399 /* LED on power adapter or its plug */
1400 EC_LED_ID_ADAPTER_LED,
1405 /* LED control flags */
1406 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1407 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1409 enum ec_led_colors {
1410 EC_LED_COLOR_RED = 0,
1413 EC_LED_COLOR_YELLOW,
1419 struct ec_params_led_control {
1420 uint8_t led_id; /* Which LED to control */
1421 uint8_t flags; /* Control flags */
1423 uint8_t brightness[EC_LED_COLOR_COUNT];
1426 struct ec_response_led_control {
1428 * Available brightness value range.
1430 * Range 0 means color channel not present.
1431 * Range 1 means on/off control.
1432 * Other values means the LED is control by PWM.
1434 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1437 /*****************************************************************************/
1438 /* Verified boot commands */
1441 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1442 * reused for other purposes with version > 0.
1445 /* Verified boot hash command */
1446 #define EC_CMD_VBOOT_HASH 0x2A
1448 struct ec_params_vboot_hash {
1449 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1450 uint8_t hash_type; /* enum ec_vboot_hash_type */
1451 uint8_t nonce_size; /* Nonce size; may be 0 */
1452 uint8_t reserved0; /* Reserved; set 0 */
1453 uint32_t offset; /* Offset in flash to hash */
1454 uint32_t size; /* Number of bytes to hash */
1455 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1458 struct ec_response_vboot_hash {
1459 uint8_t status; /* enum ec_vboot_hash_status */
1460 uint8_t hash_type; /* enum ec_vboot_hash_type */
1461 uint8_t digest_size; /* Size of hash digest in bytes */
1462 uint8_t reserved0; /* Ignore; will be 0 */
1463 uint32_t offset; /* Offset in flash which was hashed */
1464 uint32_t size; /* Number of bytes hashed */
1465 uint8_t hash_digest[64]; /* Hash digest data */
1468 enum ec_vboot_hash_cmd {
1469 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1470 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1471 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1472 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1475 enum ec_vboot_hash_type {
1476 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1479 enum ec_vboot_hash_status {
1480 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1481 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1482 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1486 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1487 * If one of these is specified, the EC will automatically update offset and
1488 * size to the correct values for the specified image (RO or RW).
1490 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1491 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1493 /*****************************************************************************/
1495 * Motion sense commands. We'll make separate structs for sub-commands with
1496 * different input args, so that we know how much to expect.
1498 #define EC_CMD_MOTION_SENSE_CMD 0x2B
1500 /* Motion sense commands */
1501 enum motionsense_command {
1503 * Dump command returns all motion sensor data including motion sense
1504 * module flags and individual sensor flags.
1506 MOTIONSENSE_CMD_DUMP = 0,
1509 * Info command returns data describing the details of a given sensor,
1510 * including enum motionsensor_type, enum motionsensor_location, and
1511 * enum motionsensor_chip.
1513 MOTIONSENSE_CMD_INFO = 1,
1516 * EC Rate command is a setter/getter command for the EC sampling rate
1517 * of all motion sensors in milliseconds.
1519 MOTIONSENSE_CMD_EC_RATE = 2,
1522 * Sensor ODR command is a setter/getter command for the output data
1523 * rate of a specific motion sensor in millihertz.
1525 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1528 * Sensor range command is a setter/getter command for the range of
1529 * a specified motion sensor in +/-G's or +/- deg/s.
1531 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1534 * Setter/getter command for the keyboard wake angle. When the lid
1535 * angle is greater than this value, keyboard wake is disabled in S3,
1536 * and when the lid angle goes less than this value, keyboard wake is
1537 * enabled. Note, the lid angle measurement is an approximate,
1538 * un-calibrated value, hence the wake angle isn't exact.
1540 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1543 * Returns a single sensor data.
1545 MOTIONSENSE_CMD_DATA = 6,
1548 * Perform low level calibration.. On sensors that support it, ask to
1549 * do offset calibration.
1551 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1554 * Sensor Offset command is a setter/getter command for the offset used
1555 * for calibration. The offsets can be calculated by the host, or via
1556 * PERFORM_CALIB command.
1558 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1560 /* Number of motionsense sub-commands. */
1561 MOTIONSENSE_NUM_CMDS
1564 enum motionsensor_id {
1565 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1566 EC_MOTION_SENSOR_ACCEL_LID = 1,
1567 EC_MOTION_SENSOR_GYRO = 2,
1570 * Note, if more sensors are added and this count changes, the padding
1571 * in ec_response_motion_sense dump command must be modified.
1573 EC_MOTION_SENSOR_COUNT = 3
1576 /* List of motion sensor types. */
1577 enum motionsensor_type {
1578 MOTIONSENSE_TYPE_ACCEL = 0,
1579 MOTIONSENSE_TYPE_GYRO = 1,
1580 MOTIONSENSE_TYPE_MAG = 2,
1581 MOTIONSENSE_TYPE_PROX = 3,
1582 MOTIONSENSE_TYPE_LIGHT = 4,
1583 MOTIONSENSE_TYPE_ACTIVITY = 5,
1584 MOTIONSENSE_TYPE_BARO = 6,
1585 MOTIONSENSE_TYPE_MAX,
1588 /* List of motion sensor locations. */
1589 enum motionsensor_location {
1590 MOTIONSENSE_LOC_BASE = 0,
1591 MOTIONSENSE_LOC_LID = 1,
1592 MOTIONSENSE_LOC_MAX,
1595 /* List of motion sensor chips. */
1596 enum motionsensor_chip {
1597 MOTIONSENSE_CHIP_KXCJ9 = 0,
1600 /* Module flag masks used for the dump sub-command. */
1601 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1603 /* Sensor flag masks used for the dump sub-command. */
1604 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1607 * Send this value for the data element to only perform a read. If you
1608 * send any other value, the EC will interpret it as data to set and will
1609 * return the actual value set.
1611 #define EC_MOTION_SENSE_NO_VALUE -1
1613 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1615 /* Set Calibration information */
1616 #define MOTION_SENSE_SET_OFFSET 1
1618 struct ec_response_motion_sensor_data {
1619 /* Flags for each sensor. */
1621 /* Sensor number the data comes from */
1623 /* Each sensor is up to 3-axis. */
1631 uint8_t activity; /* motionsensor_activity */
1633 int16_t add_info[2];
1638 struct ec_params_motion_sense {
1641 /* Used for MOTIONSENSE_CMD_DUMP. */
1647 * Used for MOTIONSENSE_CMD_EC_RATE and
1648 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1651 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1653 } ec_rate, kb_wake_angle;
1655 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1660 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1661 * the calibration information in the EC.
1662 * If unset, just retrieve calibration information.
1667 * Temperature at calibration, in units of 0.01 C
1668 * 0x8000: invalid / unknown.
1675 * Offset for calibration.
1677 * Accelerometer: 1/1024 g
1678 * Gyro: 1/1024 deg/s
1682 } __packed sensor_offset;
1684 /* Used for MOTIONSENSE_CMD_INFO. */
1690 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1691 * MOTIONSENSE_CMD_SENSOR_RANGE.
1694 /* Should be element of enum motionsensor_id. */
1697 /* Rounding flag, true for round-up, false for down. */
1702 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1704 } sensor_odr, sensor_range;
1708 struct ec_response_motion_sense {
1710 /* Used for MOTIONSENSE_CMD_DUMP. */
1712 /* Flags representing the motion sensor module. */
1713 uint8_t module_flags;
1715 /* Number of sensors managed directly by the EC. */
1716 uint8_t sensor_count;
1719 * Sensor data is truncated if response_max is too small
1720 * for holding all the data.
1722 struct ec_response_motion_sensor_data sensor[0];
1725 /* Used for MOTIONSENSE_CMD_INFO. */
1727 /* Should be element of enum motionsensor_type. */
1730 /* Should be element of enum motionsensor_location. */
1733 /* Should be element of enum motionsensor_chip. */
1737 /* Used for MOTIONSENSE_CMD_DATA */
1738 struct ec_response_motion_sensor_data data;
1741 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1742 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1743 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1746 /* Current value of the parameter queried. */
1748 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1750 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1754 } sensor_offset, perform_calib;
1758 /*****************************************************************************/
1759 /* USB charging control commands */
1761 /* Set USB port charging mode */
1762 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
1764 struct ec_params_usb_charge_set_mode {
1765 uint8_t usb_port_id;
1769 /*****************************************************************************/
1770 /* Persistent storage for host */
1772 /* Maximum bytes that can be read/written in a single command */
1773 #define EC_PSTORE_SIZE_MAX 64
1775 /* Get persistent storage info */
1776 #define EC_CMD_PSTORE_INFO 0x40
1778 struct ec_response_pstore_info {
1779 /* Persistent storage size, in bytes */
1780 uint32_t pstore_size;
1781 /* Access size; read/write offset and size must be a multiple of this */
1782 uint32_t access_size;
1786 * Read persistent storage
1788 * Response is params.size bytes of data.
1790 #define EC_CMD_PSTORE_READ 0x41
1792 struct ec_params_pstore_read {
1793 uint32_t offset; /* Byte offset to read */
1794 uint32_t size; /* Size to read in bytes */
1797 /* Write persistent storage */
1798 #define EC_CMD_PSTORE_WRITE 0x42
1800 struct ec_params_pstore_write {
1801 uint32_t offset; /* Byte offset to write */
1802 uint32_t size; /* Size to write in bytes */
1803 uint8_t data[EC_PSTORE_SIZE_MAX];
1806 /*****************************************************************************/
1807 /* Real-time clock */
1809 /* RTC params and response structures */
1810 struct ec_params_rtc {
1814 struct ec_response_rtc {
1818 /* These use ec_response_rtc */
1819 #define EC_CMD_RTC_GET_VALUE 0x44
1820 #define EC_CMD_RTC_GET_ALARM 0x45
1822 /* These all use ec_params_rtc */
1823 #define EC_CMD_RTC_SET_VALUE 0x46
1824 #define EC_CMD_RTC_SET_ALARM 0x47
1826 /* Pass as param to SET_ALARM to clear the current alarm */
1827 #define EC_RTC_ALARM_CLEAR 0
1829 /*****************************************************************************/
1830 /* Port80 log access */
1832 /* Maximum entries that can be read/written in a single command */
1833 #define EC_PORT80_SIZE_MAX 32
1835 /* Get last port80 code from previous boot */
1836 #define EC_CMD_PORT80_LAST_BOOT 0x48
1837 #define EC_CMD_PORT80_READ 0x48
1839 enum ec_port80_subcmd {
1840 EC_PORT80_GET_INFO = 0,
1841 EC_PORT80_READ_BUFFER,
1844 struct ec_params_port80_read {
1849 uint32_t num_entries;
1854 struct ec_response_port80_read {
1858 uint32_t history_size;
1862 uint16_t codes[EC_PORT80_SIZE_MAX];
1867 struct ec_response_port80_last_boot {
1871 /*****************************************************************************/
1872 /* Thermal engine commands. Note that there are two implementations. We'll
1873 * reuse the command number, but the data and behavior is incompatible.
1874 * Version 0 is what originally shipped on Link.
1875 * Version 1 separates the CPU thermal limits from the fan control.
1878 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1879 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1881 /* The version 0 structs are opaque. You have to know what they are for
1882 * the get/set commands to make any sense.
1885 /* Version 0 - set */
1886 struct ec_params_thermal_set_threshold {
1887 uint8_t sensor_type;
1888 uint8_t threshold_id;
1892 /* Version 0 - get */
1893 struct ec_params_thermal_get_threshold {
1894 uint8_t sensor_type;
1895 uint8_t threshold_id;
1898 struct ec_response_thermal_get_threshold {
1903 /* The version 1 structs are visible. */
1904 enum ec_temp_thresholds {
1905 EC_TEMP_THRESH_WARN = 0,
1906 EC_TEMP_THRESH_HIGH,
1907 EC_TEMP_THRESH_HALT,
1909 EC_TEMP_THRESH_COUNT
1912 /* Thermal configuration for one temperature sensor. Temps are in degrees K.
1913 * Zero values will be silently ignored by the thermal task.
1915 struct ec_thermal_config {
1916 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1917 uint32_t temp_fan_off; /* no active cooling needed */
1918 uint32_t temp_fan_max; /* max active cooling needed */
1921 /* Version 1 - get config for one sensor. */
1922 struct ec_params_thermal_get_threshold_v1 {
1923 uint32_t sensor_num;
1925 /* This returns a struct ec_thermal_config */
1927 /* Version 1 - set config for one sensor.
1928 * Use read-modify-write for best results! */
1929 struct ec_params_thermal_set_threshold_v1 {
1930 uint32_t sensor_num;
1931 struct ec_thermal_config cfg;
1933 /* This returns no data */
1935 /****************************************************************************/
1937 /* Toggle automatic fan control */
1938 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1940 /* Get TMP006 calibration data */
1941 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
1943 struct ec_params_tmp006_get_calibration {
1947 struct ec_response_tmp006_get_calibration {
1954 /* Set TMP006 calibration data */
1955 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
1957 struct ec_params_tmp006_set_calibration {
1959 uint8_t reserved[3]; /* Reserved; set 0 */
1966 /* Read raw TMP006 data */
1967 #define EC_CMD_TMP006_GET_RAW 0x55
1969 struct ec_params_tmp006_get_raw {
1973 struct ec_response_tmp006_get_raw {
1974 int32_t t; /* In 1/100 K */
1975 int32_t v; /* In nV */
1978 /*****************************************************************************/
1979 /* MKBP - Matrix KeyBoard Protocol */
1984 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1985 * expected response size.
1987 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1988 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1989 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
1991 #define EC_CMD_MKBP_STATE 0x60
1994 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1996 #define EC_CMD_MKBP_INFO 0x61
1998 struct ec_response_mkbp_info {
2001 /* Formerly "switches", which was 0. */
2005 struct ec_params_mkbp_info {
2010 enum ec_mkbp_info_type {
2012 * Info about the keyboard matrix: number of rows and columns.
2014 * Returns struct ec_response_mkbp_info.
2016 EC_MKBP_INFO_KBD = 0,
2019 * For buttons and switches, info about which specifically are
2020 * supported. event_type must be set to one of the values in enum
2023 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2024 * bitmask indicating which buttons or switches are present. See the
2025 * bit inidices below.
2027 EC_MKBP_INFO_SUPPORTED = 1,
2030 * Instantaneous state of buttons and switches.
2032 * event_type must be set to one of the values in enum ec_mkbp_event.
2034 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2035 * indicating the current state of the keyboard matrix.
2037 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2040 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2041 * state of supported buttons.
2043 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2044 * state of supported switches.
2046 EC_MKBP_INFO_CURRENT = 2,
2049 /* Simulate key press */
2050 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
2052 struct ec_params_mkbp_simulate_key {
2058 /* Configure keyboard scanning */
2059 #define EC_CMD_MKBP_SET_CONFIG 0x64
2060 #define EC_CMD_MKBP_GET_CONFIG 0x65
2063 enum mkbp_config_flags {
2064 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2067 enum mkbp_config_valid {
2068 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2069 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2070 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2071 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2072 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2073 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2074 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2077 /* Configuration for our key scanning algorithm */
2078 struct ec_mkbp_config {
2079 uint32_t valid_mask; /* valid fields */
2080 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2081 uint8_t valid_flags; /* which flags are valid */
2082 uint16_t scan_period_us; /* period between start of scans */
2083 /* revert to interrupt mode after no activity for this long */
2084 uint32_t poll_timeout_us;
2086 * minimum post-scan relax time. Once we finish a scan we check
2087 * the time until we are due to start the next one. If this time is
2088 * shorter this field, we use this instead.
2090 uint16_t min_post_scan_delay_us;
2091 /* delay between setting up output and waiting for it to settle */
2092 uint16_t output_settle_us;
2093 uint16_t debounce_down_us; /* time for debounce on key down */
2094 uint16_t debounce_up_us; /* time for debounce on key up */
2095 /* maximum depth to allow for fifo (0 = no keyscan output) */
2096 uint8_t fifo_max_depth;
2099 struct ec_params_mkbp_set_config {
2100 struct ec_mkbp_config config;
2103 struct ec_response_mkbp_get_config {
2104 struct ec_mkbp_config config;
2107 /* Run the key scan emulation */
2108 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2110 enum ec_keyscan_seq_cmd {
2111 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2112 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2113 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2114 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2115 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2118 enum ec_collect_flags {
2120 * Indicates this scan was processed by the EC. Due to timing, some
2121 * scans may be skipped.
2123 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2126 struct ec_collect_item {
2127 uint8_t flags; /* some flags (enum ec_collect_flags) */
2130 struct ec_params_keyscan_seq_ctrl {
2131 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2134 uint8_t active; /* still active */
2135 uint8_t num_items; /* number of items */
2136 /* Current item being presented */
2141 * Absolute time for this scan, measured from the
2142 * start of the sequence.
2145 uint8_t scan[0]; /* keyscan data */
2148 uint8_t start_item; /* First item to return */
2149 uint8_t num_items; /* Number of items to return */
2154 struct ec_result_keyscan_seq_ctrl {
2157 uint8_t num_items; /* Number of items */
2158 /* Data for each item */
2159 struct ec_collect_item item[0];
2165 * Command for retrieving the next pending MKBP event from the EC device
2167 * The device replies with UNAVAILABLE if there aren't any pending events.
2169 #define EC_CMD_GET_NEXT_EVENT 0x67
2171 enum ec_mkbp_event {
2172 /* Keyboard matrix changed. The event data is the new matrix state. */
2173 EC_MKBP_EVENT_KEY_MATRIX = 0,
2175 /* New host event. The event data is 4 bytes of host event flags. */
2176 EC_MKBP_EVENT_HOST_EVENT = 1,
2178 /* New Sensor FIFO data. The event data is fifo_info structure. */
2179 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2181 /* The state of the non-matrixed buttons have changed. */
2182 EC_MKBP_EVENT_BUTTON = 3,
2184 /* The state of the switches have changed. */
2185 EC_MKBP_EVENT_SWITCH = 4,
2187 /* EC sent a sysrq command */
2188 EC_MKBP_EVENT_SYSRQ = 6,
2190 /* Notify the AP that something happened on CEC */
2191 EC_MKBP_EVENT_CEC_EVENT = 8,
2193 /* Send an incoming CEC message to the AP */
2194 EC_MKBP_EVENT_CEC_MESSAGE = 9,
2196 /* Number of MKBP events */
2197 EC_MKBP_EVENT_COUNT,
2200 union ec_response_get_next_data {
2201 uint8_t key_matrix[13];
2204 uint32_t host_event;
2211 union ec_response_get_next_data_v1 {
2212 uint8_t key_matrix[16];
2213 uint32_t host_event;
2217 uint32_t cec_events;
2218 uint8_t cec_message[16];
2221 struct ec_response_get_next_event {
2223 /* Followed by event data if any */
2224 union ec_response_get_next_data data;
2227 struct ec_response_get_next_event_v1 {
2229 /* Followed by event data if any */
2230 union ec_response_get_next_data_v1 data;
2233 /* Bit indices for buttons and switches.*/
2235 #define EC_MKBP_POWER_BUTTON 0
2236 #define EC_MKBP_VOL_UP 1
2237 #define EC_MKBP_VOL_DOWN 2
2240 #define EC_MKBP_LID_OPEN 0
2241 #define EC_MKBP_TABLET_MODE 1
2242 #define EC_MKBP_BASE_ATTACHED 2
2244 /*****************************************************************************/
2245 /* Temperature sensor commands */
2247 /* Read temperature sensor info */
2248 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2250 struct ec_params_temp_sensor_get_info {
2254 struct ec_response_temp_sensor_get_info {
2255 char sensor_name[32];
2256 uint8_t sensor_type;
2259 /*****************************************************************************/
2262 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2263 * commands accidentally sent to the wrong interface. See the ACPI section
2267 /*****************************************************************************/
2268 /* Host event commands */
2271 * Host event mask params and response structures, shared by all of the host
2272 * event commands below.
2274 struct ec_params_host_event_mask {
2278 struct ec_response_host_event_mask {
2282 /* These all use ec_response_host_event_mask */
2283 #define EC_CMD_HOST_EVENT_GET_B 0x87
2284 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2285 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2286 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2288 /* These all use ec_params_host_event_mask */
2289 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2290 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2291 #define EC_CMD_HOST_EVENT_CLEAR 0x8c
2292 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2293 #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2295 /*****************************************************************************/
2296 /* Switch commands */
2298 /* Enable/disable LCD backlight */
2299 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2301 struct ec_params_switch_enable_backlight {
2305 /* Enable/disable WLAN/Bluetooth */
2306 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
2307 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2309 /* Version 0 params; no response */
2310 struct ec_params_switch_enable_wireless_v0 {
2314 /* Version 1 params */
2315 struct ec_params_switch_enable_wireless_v1 {
2316 /* Flags to enable now */
2319 /* Which flags to copy from now_flags */
2323 * Flags to leave enabled in S3, if they're on at the S0->S3
2324 * transition. (Other flags will be disabled by the S0->S3
2327 uint8_t suspend_flags;
2329 /* Which flags to copy from suspend_flags */
2330 uint8_t suspend_mask;
2333 /* Version 1 response */
2334 struct ec_response_switch_enable_wireless_v1 {
2335 /* Flags to enable now */
2338 /* Flags to leave enabled in S3 */
2339 uint8_t suspend_flags;
2342 /*****************************************************************************/
2343 /* GPIO commands. Only available on EC if write protect has been disabled. */
2345 /* Set GPIO output value */
2346 #define EC_CMD_GPIO_SET 0x92
2348 struct ec_params_gpio_set {
2353 /* Get GPIO value */
2354 #define EC_CMD_GPIO_GET 0x93
2356 /* Version 0 of input params and response */
2357 struct ec_params_gpio_get {
2360 struct ec_response_gpio_get {
2364 /* Version 1 of input params and response */
2365 struct ec_params_gpio_get_v1 {
2370 } get_value_by_name;
2377 struct ec_response_gpio_get_v1 {
2381 } get_value_by_name, get_count;
2390 enum gpio_get_subcmd {
2391 EC_GPIO_GET_BY_NAME = 0,
2392 EC_GPIO_GET_COUNT = 1,
2393 EC_GPIO_GET_INFO = 2,
2396 /*****************************************************************************/
2397 /* I2C commands. Only available when flash write protect is unlocked. */
2400 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2401 * removed soon. Use EC_CMD_I2C_XFER instead.
2405 #define EC_CMD_I2C_READ 0x94
2407 struct ec_params_i2c_read {
2408 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2409 uint8_t read_size; /* Either 8 or 16. */
2413 struct ec_response_i2c_read {
2418 #define EC_CMD_I2C_WRITE 0x95
2420 struct ec_params_i2c_write {
2422 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2423 uint8_t write_size; /* Either 8 or 16. */
2428 /*****************************************************************************/
2429 /* Charge state commands. Only available when flash write protect unlocked. */
2431 /* Force charge state machine to stop charging the battery or force it to
2432 * discharge the battery.
2434 #define EC_CMD_CHARGE_CONTROL 0x96
2435 #define EC_VER_CHARGE_CONTROL 1
2437 enum ec_charge_control_mode {
2438 CHARGE_CONTROL_NORMAL = 0,
2439 CHARGE_CONTROL_IDLE,
2440 CHARGE_CONTROL_DISCHARGE,
2443 struct ec_params_charge_control {
2444 uint32_t mode; /* enum charge_control_mode */
2447 /*****************************************************************************/
2448 /* Console commands. Only available when flash write protect is unlocked. */
2450 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2451 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
2454 * Read data from the saved snapshot. If the subcmd parameter is
2455 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2456 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2457 * end of the previous snapshot.
2459 * The params are only looked at in version >= 1 of this command. Prior
2460 * versions will just default to CONSOLE_READ_NEXT behavior.
2462 * Response is null-terminated string. Empty string, if there is no more
2465 #define EC_CMD_CONSOLE_READ 0x98
2467 enum ec_console_read_subcmd {
2468 CONSOLE_READ_NEXT = 0,
2472 struct ec_params_console_read_v1 {
2473 uint8_t subcmd; /* enum ec_console_read_subcmd */
2476 /*****************************************************************************/
2479 * Cut off battery power immediately or after the host has shut down.
2481 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2482 * EC_RES_SUCCESS if the command was successful.
2483 * EC_RES_ERROR if the cut off command failed.
2486 #define EC_CMD_BATTERY_CUT_OFF 0x99
2488 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2490 struct ec_params_battery_cutoff {
2494 /*****************************************************************************/
2495 /* USB port mux control. */
2498 * Switch USB mux or return to automatic switching.
2500 #define EC_CMD_USB_MUX 0x9a
2502 struct ec_params_usb_mux {
2506 /*****************************************************************************/
2507 /* LDOs / FETs control. */
2510 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2511 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2515 * Switch on/off a LDO.
2517 #define EC_CMD_LDO_SET 0x9b
2519 struct ec_params_ldo_set {
2527 #define EC_CMD_LDO_GET 0x9c
2529 struct ec_params_ldo_get {
2533 struct ec_response_ldo_get {
2537 /*****************************************************************************/
2543 #define EC_CMD_POWER_INFO 0x9d
2545 struct ec_response_power_info {
2546 uint32_t usb_dev_type;
2547 uint16_t voltage_ac;
2548 uint16_t voltage_system;
2549 uint16_t current_system;
2550 uint16_t usb_current_limit;
2553 /*****************************************************************************/
2554 /* I2C passthru command */
2556 #define EC_CMD_I2C_PASSTHRU 0x9e
2558 /* Read data; if not present, message is a write */
2559 #define EC_I2C_FLAG_READ (1 << 15)
2561 /* Mask for address */
2562 #define EC_I2C_ADDR_MASK 0x3ff
2564 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2565 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2568 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2570 struct ec_params_i2c_passthru_msg {
2571 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2572 uint16_t len; /* Number of bytes to read or write */
2575 struct ec_params_i2c_passthru {
2576 uint8_t port; /* I2C port number */
2577 uint8_t num_msgs; /* Number of messages */
2578 struct ec_params_i2c_passthru_msg msg[];
2579 /* Data to write for all messages is concatenated here */
2582 struct ec_response_i2c_passthru {
2583 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2584 uint8_t num_msgs; /* Number of messages processed */
2585 uint8_t data[]; /* Data read by messages concatenated here */
2588 /*****************************************************************************/
2589 /* Power button hang detect */
2591 #define EC_CMD_HANG_DETECT 0x9f
2593 /* Reasons to start hang detection timer */
2594 /* Power button pressed */
2595 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2598 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2601 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2603 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2604 #define EC_HANG_START_ON_RESUME (1 << 3)
2606 /* Reasons to cancel hang detection */
2608 /* Power button released */
2609 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2611 /* Any host command from AP received */
2612 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2614 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2615 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2618 * If this flag is set, all the other fields are ignored, and the hang detect
2619 * timer is started. This provides the AP a way to start the hang timer
2620 * without reconfiguring any of the other hang detect settings. Note that
2621 * you must previously have configured the timeouts.
2623 #define EC_HANG_START_NOW (1 << 30)
2626 * If this flag is set, all the other fields are ignored (including
2627 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2628 * without reconfiguring any of the other hang detect settings.
2630 #define EC_HANG_STOP_NOW (1 << 31)
2632 struct ec_params_hang_detect {
2633 /* Flags; see EC_HANG_* */
2636 /* Timeout in msec before generating host event, if enabled */
2637 uint16_t host_event_timeout_msec;
2639 /* Timeout in msec before generating warm reboot, if enabled */
2640 uint16_t warm_reboot_timeout_msec;
2643 /*****************************************************************************/
2644 /* Commands for battery charging */
2647 * This is the single catch-all host command to exchange data regarding the
2648 * charge state machine (v2 and up).
2650 #define EC_CMD_CHARGE_STATE 0xa0
2652 /* Subcommands for this host command */
2653 enum charge_state_command {
2654 CHARGE_STATE_CMD_GET_STATE,
2655 CHARGE_STATE_CMD_GET_PARAM,
2656 CHARGE_STATE_CMD_SET_PARAM,
2657 CHARGE_STATE_NUM_CMDS
2661 * Known param numbers are defined here. Ranges are reserved for board-specific
2662 * params, which are handled by the particular implementations.
2664 enum charge_state_params {
2665 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2666 CS_PARAM_CHG_CURRENT, /* charger current limit */
2667 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2668 CS_PARAM_CHG_STATUS, /* charger-specific status */
2669 CS_PARAM_CHG_OPTION, /* charger-specific options */
2670 /* How many so far? */
2673 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2674 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2675 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2677 /* Other custom param ranges go here... */
2680 struct ec_params_charge_state {
2681 uint8_t cmd; /* enum charge_state_command */
2688 uint32_t param; /* enum charge_state_param */
2692 uint32_t param; /* param to set */
2693 uint32_t value; /* value to set */
2698 struct ec_response_charge_state {
2704 int chg_input_current;
2705 int batt_state_of_charge;
2712 /* no return values */
2719 * Set maximum battery charging current.
2721 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2723 struct ec_params_current_limit {
2724 uint32_t limit; /* in mA */
2728 * Set maximum external voltage / current.
2730 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
2732 /* Command v0 is used only on Spring and is obsolete + unsupported */
2733 struct ec_params_external_power_limit_v1 {
2734 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2735 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2738 #define EC_POWER_LIMIT_NONE 0xffff
2740 /* Inform the EC when entering a sleep state */
2741 #define EC_CMD_HOST_SLEEP_EVENT 0xa9
2743 enum host_sleep_event {
2744 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2745 HOST_SLEEP_EVENT_S3_RESUME = 2,
2746 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2747 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2750 struct ec_params_host_sleep_event {
2751 uint8_t sleep_event;
2755 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
2756 * transition failures
2758 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
2760 /* Disable timeout detection for this sleep transition */
2761 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
2763 struct ec_params_host_sleep_event_v1 {
2764 /* The type of sleep being entered or exited. */
2765 uint8_t sleep_event;
2770 /* Parameters that apply for suspend messages. */
2773 * The timeout in milliseconds between when this message
2774 * is received and when the EC will declare sleep
2775 * transition failure if the sleep signal is not
2778 uint16_t sleep_timeout_ms;
2781 /* No parameters for non-suspend messages. */
2785 /* A timeout occurred when this bit is set */
2786 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
2789 * The mask defining which bits correspond to the number of sleep transitions,
2790 * as well as the maximum number of suspend line transitions that will be
2791 * reported back to the host.
2793 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
2795 struct ec_response_host_sleep_event_v1 {
2797 /* Response fields that apply for resume messages. */
2800 * The number of sleep power signal transitions that
2801 * occurred since the suspend message. The high bit
2802 * indicates a timeout occurred.
2804 uint32_t sleep_transitions;
2807 /* No response fields for non-resume messages. */
2811 /*****************************************************************************/
2812 /* Smart battery pass-through */
2814 /* Get / Set 16-bit smart battery registers */
2815 #define EC_CMD_SB_READ_WORD 0xb0
2816 #define EC_CMD_SB_WRITE_WORD 0xb1
2818 /* Get / Set string smart battery parameters
2819 * formatted as SMBUS "block".
2821 #define EC_CMD_SB_READ_BLOCK 0xb2
2822 #define EC_CMD_SB_WRITE_BLOCK 0xb3
2824 struct ec_params_sb_rd {
2828 struct ec_response_sb_rd_word {
2832 struct ec_params_sb_wr_word {
2837 struct ec_response_sb_rd_block {
2841 struct ec_params_sb_wr_block {
2846 /*****************************************************************************/
2847 /* Battery vendor parameters
2849 * Get or set vendor-specific parameters in the battery. Implementations may
2850 * differ between boards or batteries. On a set operation, the response
2851 * contains the actual value set, which may be rounded or clipped from the
2855 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2857 enum ec_battery_vendor_param_mode {
2858 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2859 BATTERY_VENDOR_PARAM_MODE_SET,
2862 struct ec_params_battery_vendor_param {
2868 struct ec_response_battery_vendor_param {
2872 /*****************************************************************************/
2873 /* Commands for I2S recording on audio codec. */
2875 #define EC_CMD_CODEC_I2S 0x00BC
2877 enum ec_codec_i2s_subcmd {
2878 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2879 EC_CODEC_SET_GAIN = 0x1,
2880 EC_CODEC_GET_GAIN = 0x2,
2881 EC_CODEC_I2S_ENABLE = 0x3,
2882 EC_CODEC_I2S_SET_CONFIG = 0x4,
2883 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2884 EC_CODEC_I2S_SET_BCLK = 0x6,
2887 enum ec_sample_depth_value {
2888 EC_CODEC_SAMPLE_DEPTH_16 = 0,
2889 EC_CODEC_SAMPLE_DEPTH_24 = 1,
2892 enum ec_i2s_config {
2894 EC_DAI_FMT_RIGHT_J = 1,
2895 EC_DAI_FMT_LEFT_J = 2,
2896 EC_DAI_FMT_PCM_A = 3,
2897 EC_DAI_FMT_PCM_B = 4,
2898 EC_DAI_FMT_PCM_TDM = 5,
2901 struct ec_param_codec_i2s {
2903 * enum ec_codec_i2s_subcmd
2908 * EC_CODEC_SET_SAMPLE_DEPTH
2909 * Value should be one of ec_sample_depth_value.
2915 * Value should be 0~43 for both channels.
2917 struct ec_param_codec_i2s_set_gain {
2923 * EC_CODEC_I2S_ENABLE
2924 * 1 to enable, 0 to disable.
2929 * EC_CODEC_I2S_SET_COFNIG
2930 * Value should be one of ec_i2s_config.
2935 * EC_CODEC_I2S_SET_TDM_CONFIG
2936 * Value should be one of ec_i2s_config.
2938 struct ec_param_codec_i2s_tdm {
2947 uint8_t adjacent_to_ch0;
2948 uint8_t adjacent_to_ch1;
2949 } __packed tdm_param;
2952 * EC_CODEC_I2S_SET_BCLK
2959 * For subcommand EC_CODEC_GET_GAIN.
2961 struct ec_response_codec_gain {
2966 /*****************************************************************************/
2967 /* System commands */
2970 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2971 * necessarily reboot the EC. Rename to "image" or something similar?
2973 #define EC_CMD_REBOOT_EC 0xd2
2976 enum ec_reboot_cmd {
2977 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2978 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2979 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2980 /* (command 3 was jump to RW-B) */
2981 EC_REBOOT_COLD = 4, /* Cold-reboot */
2982 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2983 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2986 /* Flags for ec_params_reboot_ec.reboot_flags */
2987 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2988 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2990 struct ec_params_reboot_ec {
2991 uint8_t cmd; /* enum ec_reboot_cmd */
2992 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2996 * Get information on last EC panic.
2998 * Returns variable-length platform-dependent panic information. See panic.h
3001 #define EC_CMD_GET_PANIC_INFO 0xd3
3003 /*****************************************************************************/
3007 * These are valid ONLY on the ACPI command/data port.
3011 * ACPI Read Embedded Controller
3013 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3015 * Use the following sequence:
3017 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3018 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3019 * - Write address to EC_LPC_ADDR_ACPI_DATA
3020 * - Wait for EC_LPC_CMDR_DATA bit to set
3021 * - Read value from EC_LPC_ADDR_ACPI_DATA
3023 #define EC_CMD_ACPI_READ 0x80
3026 * ACPI Write Embedded Controller
3028 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3030 * Use the following sequence:
3032 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3033 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3034 * - Write address to EC_LPC_ADDR_ACPI_DATA
3035 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3036 * - Write value to EC_LPC_ADDR_ACPI_DATA
3038 #define EC_CMD_ACPI_WRITE 0x81
3041 * ACPI Query Embedded Controller
3043 * This clears the lowest-order bit in the currently pending host events, and
3044 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3045 * event 0x80000000 = 32), or 0 if no event was pending.
3047 #define EC_CMD_ACPI_QUERY_EVENT 0x84
3049 /* Valid addresses in ACPI memory space, for read/write commands */
3051 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3052 #define EC_ACPI_MEM_VERSION 0x00
3054 * Test location; writing value here updates test compliment byte to (0xff -
3057 #define EC_ACPI_MEM_TEST 0x01
3058 /* Test compliment; writes here are ignored. */
3059 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3061 /* Keyboard backlight brightness percent (0 - 100) */
3062 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3063 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3064 #define EC_ACPI_MEM_FAN_DUTY 0x04
3067 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3068 * independent thresholds attached to them. The current value of the ID
3069 * register determines which sensor is affected by the THRESHOLD and COMMIT
3070 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3071 * as the memory-mapped sensors. The COMMIT register applies those settings.
3073 * The spec does not mandate any way to read back the threshold settings
3074 * themselves, but when a threshold is crossed the AP needs a way to determine
3075 * which sensor(s) are responsible. Each reading of the ID register clears and
3076 * returns one sensor ID that has crossed one of its threshold (in either
3077 * direction) since the last read. A value of 0xFF means "no new thresholds
3078 * have tripped". Setting or enabling the thresholds for a sensor will clear
3079 * the unread event count for that sensor.
3081 #define EC_ACPI_MEM_TEMP_ID 0x05
3082 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3083 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
3085 * Here are the bits for the COMMIT register:
3086 * bit 0 selects the threshold index for the chosen sensor (0/1)
3087 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3088 * Each write to the commit register affects one threshold.
3090 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3091 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3095 * Set the thresholds for sensor 2 to 50 C and 60 C:
3096 * write 2 to [0x05] -- select temp sensor 2
3097 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3098 * write 0x2 to [0x07] -- enable threshold 0 with this value
3099 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3100 * write 0x3 to [0x07] -- enable threshold 1 with this value
3102 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3103 * write 2 to [0x05] -- select temp sensor 2
3104 * write 0x1 to [0x07] -- disable threshold 1
3107 /* DPTF battery charging current limit */
3108 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3110 /* Charging limit is specified in 64 mA steps */
3111 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3112 /* Value to disable DPTF battery charging limit */
3113 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
3115 /* Current version of ACPI memory address space */
3116 #define EC_ACPI_MEM_VERSION_CURRENT 1
3119 /*****************************************************************************/
3123 * These commands are for sending and receiving message via HDMI CEC
3125 #define EC_MAX_CEC_MSG_LEN 16
3127 /* CEC message from the AP to be written on the CEC bus */
3128 #define EC_CMD_CEC_WRITE_MSG 0x00B8
3131 * struct ec_params_cec_write - Message to write to the CEC bus
3132 * @msg: message content to write to the CEC bus
3134 struct ec_params_cec_write {
3135 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3138 /* Set various CEC parameters */
3139 #define EC_CMD_CEC_SET 0x00BA
3142 * struct ec_params_cec_set - CEC parameters set
3143 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3144 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3145 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3146 * this field encodes the requested logical address between 0 and 15
3147 * or 0xff to unregister
3149 struct ec_params_cec_set {
3150 uint8_t cmd; /* enum cec_command */
3154 /* Read various CEC parameters */
3155 #define EC_CMD_CEC_GET 0x00BB
3158 * struct ec_params_cec_get - CEC parameters get
3159 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3161 struct ec_params_cec_get {
3162 uint8_t cmd; /* enum cec_command */
3166 * struct ec_response_cec_get - CEC parameters get response
3167 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3168 * disabled or 1 if CEC functionality is enabled,
3169 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3170 * configured logical address between 0 and 15 or 0xff if unregistered
3172 struct ec_response_cec_get {
3176 /* CEC parameters command */
3177 enum ec_cec_command {
3178 /* CEC reading, writing and events enable */
3180 /* CEC logical address */
3181 CEC_CMD_LOGICAL_ADDRESS,
3184 /* Events from CEC to AP */
3185 enum mkbp_cec_event {
3186 /* Outgoing message was acknowledged by a follower */
3187 EC_MKBP_CEC_SEND_OK = BIT(0),
3188 /* Outgoing message was not acknowledged */
3189 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3192 /*****************************************************************************/
3196 * These do not follow the normal rules for commands. See each command for
3203 * This command will work even when the EC LPC interface is busy, because the
3204 * reboot command is processed at interrupt level. Note that when the EC
3205 * reboots, the host will reboot too, so there is no response to this command.
3207 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3209 #define EC_CMD_REBOOT 0xd1 /* Think "die" */
3212 * Resend last response (not supported on LPC).
3214 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3215 * there was no previous command, or the previous command's response was too
3218 #define EC_CMD_RESEND_RESPONSE 0xdb
3221 * This header byte on a command indicate version 0. Any header byte less
3222 * than this means that we are talking to an old EC which doesn't support
3223 * versioning. In that case, we assume version 0.
3225 * Header bytes greater than this indicate a later version. For example,
3226 * EC_CMD_VERSION0 + 1 means we are using version 1.
3228 * The old EC interface must not use commands 0xdc or higher.
3230 #define EC_CMD_VERSION0 0xdc
3232 #endif /* !__ACPI__ */
3234 /*****************************************************************************/
3238 * These commands are for PD MCU communication.
3241 /* EC to PD MCU exchange status command */
3242 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
3244 /* Status of EC being sent to PD */
3245 struct ec_params_pd_status {
3246 int8_t batt_soc; /* battery state of charge */
3249 /* Status of PD being sent back to EC */
3250 struct ec_response_pd_status {
3251 int8_t status; /* PD MCU status */
3252 uint32_t curr_lim_ma; /* input current limit */
3255 /* Set USB type-C port role and muxes */
3256 #define EC_CMD_USB_PD_CONTROL 0x101
3258 enum usb_pd_control_role {
3259 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3260 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3261 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3262 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3263 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3266 enum usb_pd_control_mux {
3267 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3268 USB_PD_CTRL_MUX_NONE = 1,
3269 USB_PD_CTRL_MUX_USB = 2,
3270 USB_PD_CTRL_MUX_DP = 3,
3271 USB_PD_CTRL_MUX_DOCK = 4,
3272 USB_PD_CTRL_MUX_AUTO = 5,
3275 enum usb_pd_control_swap {
3276 USB_PD_CTRL_SWAP_NONE = 0,
3277 USB_PD_CTRL_SWAP_DATA = 1,
3278 USB_PD_CTRL_SWAP_POWER = 2,
3279 USB_PD_CTRL_SWAP_VCONN = 3,
3280 USB_PD_CTRL_SWAP_COUNT
3283 struct ec_params_usb_pd_control {
3290 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3291 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3292 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3294 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3295 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
3296 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
3297 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
3298 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
3299 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3300 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3302 struct ec_response_usb_pd_control_v1 {
3309 #define EC_CMD_USB_PD_PORTS 0x102
3311 /* Maximum number of PD ports on a device, num_ports will be <= this */
3312 #define EC_USB_PD_MAX_PORTS 8
3314 struct ec_response_usb_pd_ports {
3318 #define EC_CMD_USB_PD_POWER_INFO 0x103
3320 #define PD_POWER_CHARGING_PORT 0xff
3321 struct ec_params_usb_pd_power_info {
3329 USB_CHG_TYPE_PROPRIETARY,
3330 USB_CHG_TYPE_BC12_DCP,
3331 USB_CHG_TYPE_BC12_CDP,
3332 USB_CHG_TYPE_BC12_SDP,
3335 USB_CHG_TYPE_UNKNOWN,
3337 enum usb_power_roles {
3338 USB_PD_PORT_POWER_DISCONNECTED,
3339 USB_PD_PORT_POWER_SOURCE,
3340 USB_PD_PORT_POWER_SINK,
3341 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3344 struct usb_chg_measures {
3345 uint16_t voltage_max;
3346 uint16_t voltage_now;
3347 uint16_t current_max;
3348 uint16_t current_lim;
3351 struct ec_response_usb_pd_power_info {
3356 struct usb_chg_measures meas;
3360 struct ec_params_usb_pd_info_request {
3365 * This command will return the number of USB PD charge port + the number
3366 * of dedicated port present.
3367 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
3369 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
3370 struct ec_response_charge_port_count {
3374 /* Read USB-PD Device discovery info */
3375 #define EC_CMD_USB_PD_DISCOVERY 0x0113
3376 struct ec_params_usb_pd_discovery_entry {
3377 uint16_t vid; /* USB-IF VID */
3378 uint16_t pid; /* USB-IF PID */
3379 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3382 /* Override default charge behavior */
3383 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
3385 /* Negative port parameters have special meaning */
3386 enum usb_pd_override_ports {
3387 OVERRIDE_DONT_CHARGE = -2,
3389 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
3392 struct ec_params_charge_port_override {
3393 int16_t override_port; /* Override port# */
3396 /* Read (and delete) one entry of PD event log */
3397 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3399 struct ec_response_pd_log {
3400 uint32_t timestamp; /* relative timestamp in milliseconds */
3401 uint8_t type; /* event type : see PD_EVENT_xx below */
3402 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3403 uint16_t data; /* type-defined data payload */
3404 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3407 /* The timestamp is the microsecond counter shifted to get about a ms. */
3408 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3410 #define PD_LOG_SIZE_MASK 0x1f
3411 #define PD_LOG_PORT_MASK 0xe0
3412 #define PD_LOG_PORT_SHIFT 5
3413 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3414 ((size) & PD_LOG_SIZE_MASK))
3415 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3416 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3418 /* PD event log : entry types */
3420 #define PD_EVENT_MCU_BASE 0x00
3421 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3422 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3423 /* Reserved for custom board event */
3424 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3425 /* PD generic accessory events */
3426 #define PD_EVENT_ACC_BASE 0x20
3427 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3428 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3429 /* PD power supply events */
3430 #define PD_EVENT_PS_BASE 0x40
3431 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3432 /* PD video dongles events */
3433 #define PD_EVENT_VIDEO_BASE 0x60
3434 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3435 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3436 /* Returned in the "type" field, when there is no entry available */
3437 #define PD_EVENT_NO_ENTRY 0xff
3440 * PD_EVENT_MCU_CHARGE event definition :
3441 * the payload is "struct usb_chg_measures"
3442 * the data field contains the port state flags as defined below :
3444 /* Port partner is a dual role device */
3445 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
3446 /* Port is the pending override port */
3447 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
3448 /* Port is the override port */
3449 #define CHARGE_FLAGS_OVERRIDE BIT(13)
3451 #define CHARGE_FLAGS_TYPE_SHIFT 3
3452 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
3453 /* Power delivery role */
3454 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3457 * PD_EVENT_PS_FAULT data field flags definition :
3459 #define PS_FAULT_OCP 1
3460 #define PS_FAULT_FAST_OCP 2
3461 #define PS_FAULT_OVP 3
3462 #define PS_FAULT_DISCH 4
3465 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3467 struct mcdp_version {
3476 struct mcdp_version irom;
3477 struct mcdp_version fw;
3480 /* struct mcdp_info field decoding */
3481 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3482 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3484 /* Get info about USB-C SS muxes */
3485 #define EC_CMD_USB_PD_MUX_INFO 0x11a
3487 struct ec_params_usb_pd_mux_info {
3488 uint8_t port; /* USB-C port number */
3491 /* Flags representing mux state */
3492 #define USB_PD_MUX_USB_ENABLED (1 << 0)
3493 #define USB_PD_MUX_DP_ENABLED (1 << 1)
3494 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3495 #define USB_PD_MUX_HPD_IRQ (1 << 3)
3497 struct ec_response_usb_pd_mux_info {
3498 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3501 /*****************************************************************************/
3505 * Some platforms have sub-processors chained to each other. For example.
3507 * AP <--> EC <--> PD MCU
3509 * The top 2 bits of the command number are used to indicate which device the
3510 * command is intended for. Device 0 is always the device receiving the
3511 * command; other device mapping is board-specific.
3513 * When a device receives a command to be passed to a sub-processor, it passes
3514 * it on with the device number set back to 0. This allows the sub-processor
3515 * to remain blissfully unaware of whether the command originated on the next
3516 * device up the chain, or was passed through from the AP.
3518 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3519 * AP sends command 0x4002 to the EC
3520 * EC sends command 0x0002 to the PD MCU
3521 * EC forwards PD MCU response back to the AP
3524 /* Offset and max command number for sub-device n */
3525 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3526 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3528 /*****************************************************************************/
3530 * Deprecated constants. These constants have been renamed for clarity. The
3531 * meaning and size has not changed. Programs that use the old names should
3532 * switch to the new names soon, as the old names may not be carried forward
3535 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3536 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3537 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3539 #endif /* __CROS_EC_COMMANDS_H */