1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Host communication command constants for ChromeOS EC
5 * Copyright (C) 2012 Google, Inc
7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
11 /* Host communication command constants for Chrome EC */
13 #ifndef __CROS_EC_COMMANDS_H
14 #define __CROS_EC_COMMANDS_H
19 #define BUILD_ASSERT(_cond)
22 * Current version of this protocol
24 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
25 * determined in other ways. Remove this once the kernel code no longer
28 #define EC_PROTO_VERSION 0x00000002
30 /* Command version mask */
31 #define EC_VER_MASK(version) (1UL << (version))
33 /* I/O addresses for ACPI commands */
34 #define EC_LPC_ADDR_ACPI_DATA 0x62
35 #define EC_LPC_ADDR_ACPI_CMD 0x66
37 /* I/O addresses for host command */
38 #define EC_LPC_ADDR_HOST_DATA 0x200
39 #define EC_LPC_ADDR_HOST_CMD 0x204
41 /* I/O addresses for host command args and params */
42 /* Protocol version 2 */
43 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
44 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
45 * EC_PROTO2_MAX_PARAM_SIZE */
46 /* Protocol version 3 */
47 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
48 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
50 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
51 * and they tell the kernel that so we have to think of it as two parts. */
52 #define EC_HOST_CMD_REGION0 0x800
53 #define EC_HOST_CMD_REGION1 0x880
54 #define EC_HOST_CMD_REGION_SIZE 0x80
56 /* EC command register bit functions */
57 #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
58 #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
59 #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
60 #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
61 #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
62 #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
63 #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
65 #define EC_LPC_ADDR_MEMMAP 0x900
66 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
67 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
69 /* The offset address of each type of data in mapped memory. */
70 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
71 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
72 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
73 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
74 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
75 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
76 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
77 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
78 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
79 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
80 /* Unused 0x28 - 0x2f */
81 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
82 /* Unused 0x31 - 0x33 */
83 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
84 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
85 /* Battery values are all 32 bits */
86 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
87 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
88 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
89 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
90 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
91 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
92 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
93 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
94 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
95 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
96 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
97 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
98 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
99 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
100 /* Unused 0x84 - 0x8f */
101 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
103 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
104 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
105 /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
108 /* Define the format of the accelerometer mapped memory status byte. */
109 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
110 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
111 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
113 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
114 #define EC_TEMP_SENSOR_ENTRIES 16
116 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
118 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
120 #define EC_TEMP_SENSOR_B_ENTRIES 8
122 /* Special values for mapped temperature sensors */
123 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
124 #define EC_TEMP_SENSOR_ERROR 0xfe
125 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
126 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
128 * The offset of temperature value stored in mapped memory. This allows
129 * reporting a temperature range of 200K to 454K = -73C to 181C.
131 #define EC_TEMP_SENSOR_OFFSET 200
134 * Number of ALS readings at EC_MEMMAP_ALS
136 #define EC_ALS_ENTRIES 2
139 * The default value a temperature sensor will return when it is present but
140 * has not been read this boot. This is a reasonable number to avoid
141 * triggering alarms on the host.
143 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
145 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
146 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
147 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
149 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
150 #define EC_BATT_FLAG_AC_PRESENT 0x01
151 #define EC_BATT_FLAG_BATT_PRESENT 0x02
152 #define EC_BATT_FLAG_DISCHARGING 0x04
153 #define EC_BATT_FLAG_CHARGING 0x08
154 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
156 /* Switch flags at EC_MEMMAP_SWITCHES */
157 #define EC_SWITCH_LID_OPEN 0x01
158 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
159 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
160 /* Was recovery requested via keyboard; now unused. */
161 #define EC_SWITCH_IGNORE1 0x08
162 /* Recovery requested via dedicated signal (from servo board) */
163 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
164 /* Was fake developer mode switch; now unused. Remove in next refactor. */
165 #define EC_SWITCH_IGNORE0 0x20
167 /* Host command interface flags */
168 /* Host command interface supports LPC args (LPC interface only) */
169 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
170 /* Host command interface supports version 3 protocol */
171 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
173 /* Wireless switch flags */
174 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
175 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
176 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
177 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
178 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
181 * This header file is used in coreboot both in C and ACPI code. The ACPI code
182 * is pre-processed to handle constants but the ASL compiler is unable to
183 * handle actual C code so keep it separate.
188 * Define __packed if someone hasn't beat us to it. Linux kernel style
189 * checking prefers __packed over __attribute__((packed)).
192 #define __packed __attribute__((packed))
195 /* LPC command status byte masks */
196 /* EC has written a byte in the data register and host hasn't read it yet */
197 #define EC_LPC_STATUS_TO_HOST 0x01
198 /* Host has written a command/data byte and the EC hasn't read it yet */
199 #define EC_LPC_STATUS_FROM_HOST 0x02
200 /* EC is processing a command */
201 #define EC_LPC_STATUS_PROCESSING 0x04
202 /* Last write to EC was a command, not data */
203 #define EC_LPC_STATUS_LAST_CMD 0x08
204 /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
205 #define EC_LPC_STATUS_BURST_MODE 0x10
206 /* SCI event is pending (requesting SCI query) */
207 #define EC_LPC_STATUS_SCI_PENDING 0x20
208 /* SMI event is pending (requesting SMI query) */
209 #define EC_LPC_STATUS_SMI_PENDING 0x40
211 #define EC_LPC_STATUS_RESERVED 0x80
214 * EC is busy. This covers both the EC processing a command, and the host has
215 * written a new command but the EC hasn't picked it up yet.
217 #define EC_LPC_STATUS_BUSY_MASK \
218 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
220 /* Host command response codes */
223 EC_RES_INVALID_COMMAND = 1,
225 EC_RES_INVALID_PARAM = 3,
226 EC_RES_ACCESS_DENIED = 4,
227 EC_RES_INVALID_RESPONSE = 5,
228 EC_RES_INVALID_VERSION = 6,
229 EC_RES_INVALID_CHECKSUM = 7,
230 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
231 EC_RES_UNAVAILABLE = 9, /* No response available */
232 EC_RES_TIMEOUT = 10, /* We got a timeout */
233 EC_RES_OVERFLOW = 11, /* Table / data overflow */
234 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
235 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
236 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
240 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
241 * EC command uses code 0 to mean "no event pending". We explicitly specify
242 * each value in the enum listing so they won't change if we delete/insert an
243 * item or rearrange the list (it needs to be stable across platforms, not
244 * just within a single compiled instance).
246 enum host_event_code {
247 EC_HOST_EVENT_LID_CLOSED = 1,
248 EC_HOST_EVENT_LID_OPEN = 2,
249 EC_HOST_EVENT_POWER_BUTTON = 3,
250 EC_HOST_EVENT_AC_CONNECTED = 4,
251 EC_HOST_EVENT_AC_DISCONNECTED = 5,
252 EC_HOST_EVENT_BATTERY_LOW = 6,
253 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
254 EC_HOST_EVENT_BATTERY = 8,
255 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
256 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
257 EC_HOST_EVENT_THERMAL = 11,
258 EC_HOST_EVENT_USB_CHARGER = 12,
259 EC_HOST_EVENT_KEY_PRESSED = 13,
261 * EC has finished initializing the host interface. The host can check
262 * for this event following sending a EC_CMD_REBOOT_EC command to
263 * determine when the EC is ready to accept subsequent commands.
265 EC_HOST_EVENT_INTERFACE_READY = 14,
266 /* Keyboard recovery combo has been pressed */
267 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
269 /* Shutdown due to thermal overload */
270 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
271 /* Shutdown due to battery level too low */
272 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
274 /* Suggest that the AP throttle itself */
275 EC_HOST_EVENT_THROTTLE_START = 18,
276 /* Suggest that the AP resume normal speed */
277 EC_HOST_EVENT_THROTTLE_STOP = 19,
279 /* Hang detect logic detected a hang and host event timeout expired */
280 EC_HOST_EVENT_HANG_DETECT = 20,
281 /* Hang detect logic detected a hang and warm rebooted the AP */
282 EC_HOST_EVENT_HANG_REBOOT = 21,
283 /* PD MCU triggering host event */
284 EC_HOST_EVENT_PD_MCU = 22,
286 /* EC desires to change state of host-controlled USB mux */
287 EC_HOST_EVENT_USB_MUX = 28,
289 /* EC RTC event occurred */
290 EC_HOST_EVENT_RTC = 26,
293 * The high bit of the event mask is not used as a host event code. If
294 * it reads back as set, then the entire event mask should be
295 * considered invalid by the host. This can happen when reading the
296 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
297 * not initialized on the EC, or improperly configured on the host.
299 EC_HOST_EVENT_INVALID = 32
301 /* Host event mask */
302 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
305 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
306 * @flags: The host argument flags.
307 * @command_version: Command version.
308 * @data_size: The length of data.
309 * @checksum: Checksum; sum of command + flags + command_version + data_size +
310 * all params/response data bytes.
312 struct ec_lpc_host_args {
314 uint8_t command_version;
319 /* Flags for ec_lpc_host_args.flags */
321 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
324 * If EC gets a command and this flag is not set, this is an old-style command.
325 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
326 * unknown length. EC must respond with an old-style response (that is,
327 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
329 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
331 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
333 * If EC responds to a command and this flag is not set, this is an old-style
334 * response. Command version is 0 and response data from EC is at
335 * EC_LPC_ADDR_OLD_PARAM with unknown length.
337 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
339 /*****************************************************************************/
341 * Byte codes returned by EC over SPI interface.
343 * These can be used by the AP to debug the EC interface, and to determine
344 * when the EC is not in a state where it will ever get around to responding
347 * Example of sequence of bytes read from EC for a current good transfer:
348 * 1. - - AP asserts chip select (CS#)
349 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
350 * 3. - - EC starts handling CS# interrupt
351 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
352 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
353 * bytes looking for EC_SPI_FRAME_START
354 * 6. - - EC finishes processing and sets up response
355 * 7. EC_SPI_FRAME_START - AP reads frame byte
356 * 8. (response packet) - AP reads response packet
357 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
358 * 10 - - AP deasserts chip select
359 * 11 - - EC processes CS# interrupt and sets up DMA for
362 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
363 * the following byte values:
369 * Then the EC found an error in the request, or was not ready for the request
370 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
371 * because the EC is unable to tell when the AP is done sending its request.
375 * Framing byte which precedes a response packet from the EC. After sending a
376 * request, the AP will clock in bytes until it sees the framing byte, then
377 * clock in the response packet.
379 #define EC_SPI_FRAME_START 0xec
382 * Padding bytes which are clocked out after the end of a response packet.
384 #define EC_SPI_PAST_END 0xed
387 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
388 * that the AP will send a valid packet header (starting with
389 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
391 #define EC_SPI_RX_READY 0xf8
394 * EC has started receiving the request from the AP, but hasn't started
397 #define EC_SPI_RECEIVING 0xf9
399 /* EC has received the entire request from the AP and is processing it. */
400 #define EC_SPI_PROCESSING 0xfa
403 * EC received bad data from the AP, such as a packet header with an invalid
404 * length. EC will ignore all data until chip select deasserts.
406 #define EC_SPI_RX_BAD_DATA 0xfb
409 * EC received data from the AP before it was ready. That is, the AP asserted
410 * chip select and started clocking data before the EC was ready to receive it.
411 * EC will ignore all data until chip select deasserts.
413 #define EC_SPI_NOT_READY 0xfc
416 * EC was ready to receive a request from the AP. EC has treated the byte sent
417 * by the AP as part of a request packet, or (for old-style ECs) is processing
418 * a fully received packet but is not ready to respond yet.
420 #define EC_SPI_OLD_READY 0xfd
422 /*****************************************************************************/
425 * Protocol version 2 for I2C and SPI send a request this way:
427 * 0 EC_CMD_VERSION0 + (command version)
429 * 2 Length of params = N
430 * 3..N+2 Params, if any
431 * N+3 8-bit checksum of bytes 0..N+2
433 * The corresponding response is:
435 * 0 Result code (EC_RES_*)
436 * 1 Length of params = M
437 * 2..M+1 Params, if any
438 * M+2 8-bit checksum of bytes 0..M+1
440 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
441 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
442 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
443 EC_PROTO2_REQUEST_TRAILER_BYTES)
445 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
446 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
447 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
448 EC_PROTO2_RESPONSE_TRAILER_BYTES)
450 /* Parameter length was limited by the LPC interface */
451 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
453 /* Maximum request and response packet sizes for protocol version 2 */
454 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
455 EC_PROTO2_MAX_PARAM_SIZE)
456 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
457 EC_PROTO2_MAX_PARAM_SIZE)
459 /*****************************************************************************/
462 * Value written to legacy command port / prefix byte to indicate protocol
463 * 3+ structs are being used. Usage is bus-dependent.
465 #define EC_COMMAND_PROTOCOL_3 0xda
467 #define EC_HOST_REQUEST_VERSION 3
470 * struct ec_host_request - Version 3 request from host.
471 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
472 * receives a header with a version it doesn't know how to
474 * @checksum: Checksum of request and data; sum of all bytes including checksum
476 * @command: Command to send (EC_CMD_...)
477 * @command_version: Command version.
478 * @reserved: Unused byte in current protocol version; set to 0.
479 * @data_len: Length of data which follows this header.
481 struct ec_host_request {
482 uint8_t struct_version;
485 uint8_t command_version;
490 #define EC_HOST_RESPONSE_VERSION 3
493 * struct ec_host_response - Version 3 response from EC.
494 * @struct_version: Struct version (=3).
495 * @checksum: Checksum of response and data; sum of all bytes including
496 * checksum should total to 0.
497 * @result: EC's response to the command (separate from communication failure)
498 * @data_len: Length of data which follows this header.
499 * @reserved: Unused bytes in current protocol version; set to 0.
501 struct ec_host_response {
502 uint8_t struct_version;
509 /*****************************************************************************/
513 * Each command is an 16-bit command value. Commands which take params or
514 * return response data specify structs for that data. If no struct is
515 * specified, the command does not input or output data, respectively.
516 * Parameter/response length is implicit in the structs. Some underlying
517 * communication protocols (I2C, SPI) may add length or checksum headers, but
518 * those are implementation-dependent and not defined here.
521 /*****************************************************************************/
522 /* General / test commands */
525 * Get protocol version, used to deal with non-backward compatible protocol
528 #define EC_CMD_PROTO_VERSION 0x00
531 * struct ec_response_proto_version - Response to the proto version command.
532 * @version: The protocol version.
534 struct ec_response_proto_version {
539 * Hello. This is a simple command to test the EC is responsive to
542 #define EC_CMD_HELLO 0x01
545 * struct ec_params_hello - Parameters to the hello command.
546 * @in_data: Pass anything here.
548 struct ec_params_hello {
553 * struct ec_response_hello - Response to the hello command.
554 * @out_data: Output will be in_data + 0x01020304.
556 struct ec_response_hello {
560 /* Get version number */
561 #define EC_CMD_GET_VERSION 0x02
563 enum ec_current_image {
564 EC_IMAGE_UNKNOWN = 0,
570 * struct ec_response_get_version - Response to the get version command.
571 * @version_string_ro: Null-terminated RO firmware version string.
572 * @version_string_rw: Null-terminated RW firmware version string.
573 * @reserved: Unused bytes; was previously RW-B firmware version string.
574 * @current_image: One of ec_current_image.
576 struct ec_response_get_version {
577 char version_string_ro[32];
578 char version_string_rw[32];
580 uint32_t current_image;
584 #define EC_CMD_READ_TEST 0x03
587 * struct ec_params_read_test - Parameters for the read test command.
588 * @offset: Starting value for read buffer.
589 * @size: Size to read in bytes.
591 struct ec_params_read_test {
597 * struct ec_response_read_test - Response to the read test command.
598 * @data: Data returned by the read test command.
600 struct ec_response_read_test {
605 * Get build information
607 * Response is null-terminated string.
609 #define EC_CMD_GET_BUILD_INFO 0x04
612 #define EC_CMD_GET_CHIP_INFO 0x05
615 * struct ec_response_get_chip_info - Response to the get chip info command.
616 * @vendor: Null-terminated string for chip vendor.
617 * @name: Null-terminated string for chip name.
618 * @revision: Null-terminated string for chip mask version.
620 struct ec_response_get_chip_info {
626 /* Get board HW version */
627 #define EC_CMD_GET_BOARD_VERSION 0x06
630 * struct ec_response_board_version - Response to the board version command.
631 * @board_version: A monotonously incrementing number.
633 struct ec_response_board_version {
634 uint16_t board_version;
638 * Read memory-mapped data.
640 * This is an alternate interface to memory-mapped data for bus protocols
641 * which don't support direct-mapped memory - I2C, SPI, etc.
643 * Response is params.size bytes of data.
645 #define EC_CMD_READ_MEMMAP 0x07
648 * struct ec_params_read_memmap - Parameters for the read memory map command.
649 * @offset: Offset in memmap (EC_MEMMAP_*).
650 * @size: Size to read in bytes.
652 struct ec_params_read_memmap {
657 /* Read versions supported for a command */
658 #define EC_CMD_GET_CMD_VERSIONS 0x08
661 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
662 * @cmd: Command to check.
664 struct ec_params_get_cmd_versions {
669 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
671 * @cmd: Command to check.
673 struct ec_params_get_cmd_versions_v1 {
678 * struct ec_response_get_cmd_version - Response to the get command versions.
679 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
682 struct ec_response_get_cmd_versions {
683 uint32_t version_mask;
687 * Check EC communcations status (busy). This is needed on i2c/spi but not
688 * on lpc since it has its own out-of-band busy indicator.
690 * lpc must read the status from the command register. Attempting this on
691 * lpc will overwrite the args/parameter space and corrupt its data.
693 #define EC_CMD_GET_COMMS_STATUS 0x09
695 /* Avoid using ec_status which is for return values */
696 enum ec_comms_status {
697 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
701 * struct ec_response_get_comms_status - Response to the get comms status
703 * @flags: Mask of enum ec_comms_status.
705 struct ec_response_get_comms_status {
706 uint32_t flags; /* Mask of enum ec_comms_status */
709 /* Fake a variety of responses, purely for testing purposes. */
710 #define EC_CMD_TEST_PROTOCOL 0x0a
712 /* Tell the EC what to send back to us. */
713 struct ec_params_test_protocol {
719 /* Here it comes... */
720 struct ec_response_test_protocol {
724 /* Get prococol information */
725 #define EC_CMD_GET_PROTOCOL_INFO 0x0b
727 /* Flags for ec_response_get_protocol_info.flags */
728 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
729 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
732 * struct ec_response_get_protocol_info - Response to the get protocol info.
733 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
735 * @max_request_packet_size: Maximum request packet size in bytes.
736 * @max_response_packet_size: Maximum response packet size in bytes.
737 * @flags: see EC_PROTOCOL_INFO_*
739 struct ec_response_get_protocol_info {
740 /* Fields which exist if at least protocol version 3 supported */
741 uint32_t protocol_versions;
742 uint16_t max_request_packet_size;
743 uint16_t max_response_packet_size;
748 /*****************************************************************************/
749 /* Get/Set miscellaneous values */
751 /* The upper byte of .flags tells what to do (nothing means "get") */
752 #define EC_GSV_SET 0x80000000
755 * The lower three bytes of .flags identifies the parameter, if that has
756 * meaning for an individual command.
758 #define EC_GSV_PARAM_MASK 0x00ffffff
760 struct ec_params_get_set_value {
765 struct ec_response_get_set_value {
770 /* More than one command can use these structs to get/set paramters. */
771 #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
773 /*****************************************************************************/
774 /* List the features supported by the firmware */
775 #define EC_CMD_GET_FEATURES 0x0d
777 /* Supported features */
778 enum ec_feature_code {
780 * This image contains a limited set of features. Another image
781 * in RW partition may support more features.
783 EC_FEATURE_LIMITED = 0,
785 * Commands for probing/reading/writing/erasing the flash in the
788 EC_FEATURE_FLASH = 1,
790 * Can control the fan speed directly.
792 EC_FEATURE_PWM_FAN = 2,
794 * Can control the intensity of the keyboard backlight.
796 EC_FEATURE_PWM_KEYB = 3,
798 * Support Google lightbar, introduced on Pixel.
800 EC_FEATURE_LIGHTBAR = 4,
801 /* Control of LEDs */
803 /* Exposes an interface to control gyro and sensors.
804 * The host goes through the EC to access these sensors.
805 * In addition, the EC may provide composite sensors, like lid angle.
807 EC_FEATURE_MOTION_SENSE = 6,
808 /* The keyboard is controlled by the EC */
810 /* The AP can use part of the EC flash as persistent storage. */
811 EC_FEATURE_PSTORE = 8,
812 /* The EC monitors BIOS port 80h, and can return POST codes. */
813 EC_FEATURE_PORT80 = 9,
815 * Thermal management: include TMP specific commands.
816 * Higher level than direct fan control.
818 EC_FEATURE_THERMAL = 10,
819 /* Can switch the screen backlight on/off */
820 EC_FEATURE_BKLIGHT_SWITCH = 11,
821 /* Can switch the wifi module on/off */
822 EC_FEATURE_WIFI_SWITCH = 12,
823 /* Monitor host events, through for example SMI or SCI */
824 EC_FEATURE_HOST_EVENTS = 13,
825 /* The EC exposes GPIO commands to control/monitor connected devices. */
826 EC_FEATURE_GPIO = 14,
827 /* The EC can send i2c messages to downstream devices. */
829 /* Command to control charger are included */
830 EC_FEATURE_CHARGER = 16,
831 /* Simple battery support. */
832 EC_FEATURE_BATTERY = 17,
834 * Support Smart battery protocol
835 * (Common Smart Battery System Interface Specification)
837 EC_FEATURE_SMART_BATTERY = 18,
838 /* EC can detect when the host hangs. */
839 EC_FEATURE_HANG_DETECT = 19,
840 /* Report power information, for pit only */
842 /* Another Cros EC device is present downstream of this one */
843 EC_FEATURE_SUB_MCU = 21,
844 /* Support USB Power delivery (PD) commands */
845 EC_FEATURE_USB_PD = 22,
846 /* Control USB multiplexer, for audio through USB port for instance. */
847 EC_FEATURE_USB_MUX = 23,
848 /* Motion Sensor code has an internal software FIFO */
849 EC_FEATURE_MOTION_SENSE_FIFO = 24,
850 /* Support temporary secure vstore */
851 EC_FEATURE_VSTORE = 25,
852 /* EC decides on USB-C SS mux state, muxes configured by host */
853 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
854 /* EC has RTC feature that can be controlled by host commands */
856 /* The MCU exposes a Fingerprint sensor */
857 EC_FEATURE_FINGERPRINT = 28,
858 /* The MCU exposes a Touchpad */
859 EC_FEATURE_TOUCHPAD = 29,
860 /* The MCU has RWSIG task enabled */
861 EC_FEATURE_RWSIG = 30,
862 /* EC has device events support */
863 EC_FEATURE_DEVICE_EVENT = 31,
864 /* EC supports the unified wake masks for LPC/eSPI systems */
865 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
866 /* EC supports 64-bit host events */
867 EC_FEATURE_HOST_EVENT64 = 33,
868 /* EC runs code in RAM (not in place, a.k.a. XIP) */
869 EC_FEATURE_EXEC_IN_RAM = 34,
870 /* EC supports CEC commands */
872 /* EC supports tight sensor timestamping. */
873 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
875 * EC supports tablet mode detection aligned to Chrome and allows
876 * setting of threshold by host command using
877 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
879 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
880 /* EC supports audio codec. */
881 EC_FEATURE_AUDIO_CODEC = 38,
882 /* EC Supports SCP. */
884 /* The MCU is an Integrated Sensor Hub */
888 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
889 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
891 struct ec_response_get_features {
895 /*****************************************************************************/
899 #define EC_CMD_FLASH_INFO 0x10
902 * struct ec_response_flash_info - Response to the flash info command.
903 * @flash_size: Usable flash size in bytes.
904 * @write_block_size: Write block size. Write offset and size must be a
906 * @erase_block_size: Erase block size. Erase offset and size must be a
908 * @protect_block_size: Protection block size. Protection offset and size
909 * must be a multiple of this.
911 * Version 0 returns these fields.
913 struct ec_response_flash_info {
915 uint32_t write_block_size;
916 uint32_t erase_block_size;
917 uint32_t protect_block_size;
920 /* Flags for version 1+ flash info command */
921 /* EC flash erases bits to 0 instead of 1 */
922 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
925 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
926 * @flash_size: Usable flash size in bytes.
927 * @write_block_size: Write block size. Write offset and size must be a
929 * @erase_block_size: Erase block size. Erase offset and size must be a
931 * @protect_block_size: Protection block size. Protection offset and size
932 * must be a multiple of this.
933 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
934 * size is exactly this and offset is a multiple of this.
935 * For example, an EC may have a write buffer which can do
936 * half-page operations if data is aligned, and a slower
937 * word-at-a-time write mode.
938 * @flags: Flags; see EC_FLASH_INFO_*
940 * Version 1 returns the same initial fields as version 0, with additional
943 * gcc anonymous structs don't seem to get along with the __packed directive;
944 * if they did we'd define the version 0 struct as a sub-struct of this one.
946 struct ec_response_flash_info_1 {
947 /* Version 0 fields; see above for description */
949 uint32_t write_block_size;
950 uint32_t erase_block_size;
951 uint32_t protect_block_size;
953 /* Version 1 adds these fields: */
954 uint32_t write_ideal_size;
961 * Response is params.size bytes of data.
963 #define EC_CMD_FLASH_READ 0x11
966 * struct ec_params_flash_read - Parameters for the flash read command.
967 * @offset: Byte offset to read.
968 * @size: Size to read in bytes.
970 struct ec_params_flash_read {
976 #define EC_CMD_FLASH_WRITE 0x12
977 #define EC_VER_FLASH_WRITE 1
979 /* Version 0 of the flash command supported only 64 bytes of data */
980 #define EC_FLASH_WRITE_VER0_SIZE 64
983 * struct ec_params_flash_write - Parameters for the flash write command.
984 * @offset: Byte offset to write.
985 * @size: Size to write in bytes.
987 struct ec_params_flash_write {
990 /* Followed by data to write */
994 #define EC_CMD_FLASH_ERASE 0x13
997 * struct ec_params_flash_erase - Parameters for the flash erase command.
998 * @offset: Byte offset to erase.
999 * @size: Size to erase in bytes.
1001 struct ec_params_flash_erase {
1007 * Get/set flash protection.
1009 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1010 * firmware write protect GPIO, not all flags will take effect immediately;
1011 * some flags require a subsequent hard reset to take effect. Check the
1012 * returned flags bits to see what actually happened.
1014 * If mask=0, simply returns the current flags state.
1016 #define EC_CMD_FLASH_PROTECT 0x15
1017 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1019 /* Flags for flash protection */
1020 /* RO flash code protected when the EC boots */
1021 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1023 * RO flash code protected now. If this bit is set, at-boot status cannot
1026 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1027 /* Entire flash code protected now, until reboot. */
1028 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1029 /* Flash write protect GPIO is asserted now */
1030 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1031 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1032 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1034 * Error - flash protection is in inconsistent state. At least one bank of
1035 * flash which should be protected is not protected. Usually fixed by
1036 * re-requesting the desired flags, or by a hard reset if that fails.
1038 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1039 /* Entile flash code protected when the EC boots */
1040 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1043 * struct ec_params_flash_protect - Parameters for the flash protect command.
1044 * @mask: Bits in flags to apply.
1045 * @flags: New flags to apply.
1047 struct ec_params_flash_protect {
1053 * struct ec_response_flash_protect - Response to the flash protect command.
1054 * @flags: Current value of flash protect flags.
1055 * @valid_flags: Flags which are valid on this platform. This allows the
1056 * caller to distinguish between flags which aren't set vs. flags
1057 * which can't be set on this platform.
1058 * @writable_flags: Flags which can be changed given the current protection
1061 struct ec_response_flash_protect {
1063 uint32_t valid_flags;
1064 uint32_t writable_flags;
1068 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1069 * write protect. These commands may be reused with version > 0.
1072 /* Get the region offset/size */
1073 #define EC_CMD_FLASH_REGION_INFO 0x16
1074 #define EC_VER_FLASH_REGION_INFO 1
1076 enum ec_flash_region {
1077 /* Region which holds read-only EC image */
1078 EC_FLASH_REGION_RO = 0,
1079 /* Region which holds rewritable EC image */
1082 * Region which should be write-protected in the factory (a superset of
1083 * EC_FLASH_REGION_RO)
1085 EC_FLASH_REGION_WP_RO,
1086 /* Number of regions */
1087 EC_FLASH_REGION_COUNT,
1091 * struct ec_params_flash_region_info - Parameters for the flash region info
1093 * @region: Flash region; see EC_FLASH_REGION_*
1095 struct ec_params_flash_region_info {
1099 struct ec_response_flash_region_info {
1104 /* Read/write VbNvContext */
1105 #define EC_CMD_VBNV_CONTEXT 0x17
1106 #define EC_VER_VBNV_CONTEXT 1
1107 #define EC_VBNV_BLOCK_SIZE 16
1109 enum ec_vbnvcontext_op {
1110 EC_VBNV_CONTEXT_OP_READ,
1111 EC_VBNV_CONTEXT_OP_WRITE,
1114 struct ec_params_vbnvcontext {
1116 uint8_t block[EC_VBNV_BLOCK_SIZE];
1119 struct ec_response_vbnvcontext {
1120 uint8_t block[EC_VBNV_BLOCK_SIZE];
1123 /*****************************************************************************/
1126 /* Get fan target RPM */
1127 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1129 struct ec_response_pwm_get_fan_rpm {
1133 /* Set target fan RPM */
1134 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1136 struct ec_params_pwm_set_fan_target_rpm {
1140 /* Get keyboard backlight */
1141 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1143 struct ec_response_pwm_get_keyboard_backlight {
1148 /* Set keyboard backlight */
1149 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1151 struct ec_params_pwm_set_keyboard_backlight {
1155 /* Set target fan PWM duty cycle */
1156 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
1158 struct ec_params_pwm_set_fan_duty {
1162 #define EC_CMD_PWM_SET_DUTY 0x25
1163 /* 16 bit duty cycle, 0xffff = 100% */
1164 #define EC_PWM_MAX_DUTY 0xffff
1167 /* All types, indexed by board-specific enum pwm_channel */
1168 EC_PWM_TYPE_GENERIC = 0,
1169 /* Keyboard backlight */
1170 EC_PWM_TYPE_KB_LIGHT,
1171 /* Display backlight */
1172 EC_PWM_TYPE_DISPLAY_LIGHT,
1176 struct ec_params_pwm_set_duty {
1177 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1178 uint8_t pwm_type; /* ec_pwm_type */
1179 uint8_t index; /* Type-specific index, or 0 if unique */
1182 #define EC_CMD_PWM_GET_DUTY 0x26
1184 struct ec_params_pwm_get_duty {
1185 uint8_t pwm_type; /* ec_pwm_type */
1186 uint8_t index; /* Type-specific index, or 0 if unique */
1189 struct ec_response_pwm_get_duty {
1190 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1193 /*****************************************************************************/
1195 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1196 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1197 * into a subcommand. We'll make separate structs for subcommands with
1198 * different input args, so that we know how much to expect.
1200 #define EC_CMD_LIGHTBAR_CMD 0x28
1206 #define LB_BATTERY_LEVELS 4
1209 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1210 * host command, but the alignment is the same regardless. Keep it that way.
1212 struct lightbar_params_v0 {
1214 int32_t google_ramp_up;
1215 int32_t google_ramp_down;
1216 int32_t s3s0_ramp_up;
1217 int32_t s0_tick_delay[2]; /* AC=0/1 */
1218 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1219 int32_t s0s3_ramp_down;
1220 int32_t s3_sleep_for;
1222 int32_t s3_ramp_down;
1226 uint8_t osc_min[2]; /* AC=0/1 */
1227 uint8_t osc_max[2]; /* AC=0/1 */
1228 uint8_t w_ofs[2]; /* AC=0/1 */
1230 /* Brightness limits based on the backlight and AC. */
1231 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1232 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1233 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1235 /* Battery level thresholds */
1236 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1238 /* Map [AC][battery_level] to color index */
1239 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1240 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1243 struct rgb_s color[8]; /* 0-3 are Google colors */
1246 struct lightbar_params_v1 {
1248 int32_t google_ramp_up;
1249 int32_t google_ramp_down;
1250 int32_t s3s0_ramp_up;
1251 int32_t s0_tick_delay[2]; /* AC=0/1 */
1252 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1253 int32_t s0s3_ramp_down;
1254 int32_t s3_sleep_for;
1256 int32_t s3_ramp_down;
1257 int32_t tap_tick_delay;
1258 int32_t tap_display_time;
1260 /* Tap-for-battery params */
1261 uint8_t tap_pct_red;
1262 uint8_t tap_pct_green;
1263 uint8_t tap_seg_min_on;
1264 uint8_t tap_seg_max_on;
1265 uint8_t tap_seg_osc;
1269 uint8_t osc_min[2]; /* AC=0/1 */
1270 uint8_t osc_max[2]; /* AC=0/1 */
1271 uint8_t w_ofs[2]; /* AC=0/1 */
1273 /* Brightness limits based on the backlight and AC. */
1274 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1275 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1276 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1278 /* Battery level thresholds */
1279 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1281 /* Map [AC][battery_level] to color index */
1282 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1283 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1286 struct rgb_s color[8]; /* 0-3 are Google colors */
1289 /* Lightbar program */
1290 #define EC_LB_PROG_LEN 192
1291 struct lightbar_program {
1293 uint8_t data[EC_LB_PROG_LEN];
1296 struct ec_params_lightbar {
1297 uint8_t cmd; /* Command (see enum lightbar_command) */
1301 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1302 version, get_brightness, get_demo, suspend, resume;
1306 } set_brightness, seq, demo;
1309 uint8_t ctrl, reg, value;
1313 uint8_t led, red, green, blue;
1322 } manual_suspend_ctrl;
1324 struct lightbar_params_v0 set_params_v0;
1325 struct lightbar_params_v1 set_params_v1;
1326 struct lightbar_program set_program;
1330 struct ec_response_lightbar {
1342 } get_seq, get_brightness, get_demo;
1344 struct lightbar_params_v0 get_params_v0;
1345 struct lightbar_params_v1 get_params_v1;
1353 uint8_t red, green, blue;
1357 /* no return params */
1358 } off, on, init, set_brightness, seq, reg, set_rgb,
1359 demo, set_params_v0, set_params_v1,
1360 set_program, manual_suspend_ctrl, suspend, resume;
1364 /* Lightbar commands */
1365 enum lightbar_command {
1366 LIGHTBAR_CMD_DUMP = 0,
1367 LIGHTBAR_CMD_OFF = 1,
1368 LIGHTBAR_CMD_ON = 2,
1369 LIGHTBAR_CMD_INIT = 3,
1370 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1371 LIGHTBAR_CMD_SEQ = 5,
1372 LIGHTBAR_CMD_REG = 6,
1373 LIGHTBAR_CMD_SET_RGB = 7,
1374 LIGHTBAR_CMD_GET_SEQ = 8,
1375 LIGHTBAR_CMD_DEMO = 9,
1376 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1377 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1378 LIGHTBAR_CMD_VERSION = 12,
1379 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1380 LIGHTBAR_CMD_GET_RGB = 14,
1381 LIGHTBAR_CMD_GET_DEMO = 15,
1382 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1383 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1384 LIGHTBAR_CMD_SET_PROGRAM = 18,
1385 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1386 LIGHTBAR_CMD_SUSPEND = 20,
1387 LIGHTBAR_CMD_RESUME = 21,
1391 /*****************************************************************************/
1392 /* LED control commands */
1394 #define EC_CMD_LED_CONTROL 0x29
1397 /* LED to indicate battery state of charge */
1398 EC_LED_ID_BATTERY_LED = 0,
1400 * LED to indicate system power state (on or in suspend).
1401 * May be on power button or on C-panel.
1403 EC_LED_ID_POWER_LED,
1404 /* LED on power adapter or its plug */
1405 EC_LED_ID_ADAPTER_LED,
1410 /* LED control flags */
1411 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1412 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1414 enum ec_led_colors {
1415 EC_LED_COLOR_RED = 0,
1418 EC_LED_COLOR_YELLOW,
1424 struct ec_params_led_control {
1425 uint8_t led_id; /* Which LED to control */
1426 uint8_t flags; /* Control flags */
1428 uint8_t brightness[EC_LED_COLOR_COUNT];
1431 struct ec_response_led_control {
1433 * Available brightness value range.
1435 * Range 0 means color channel not present.
1436 * Range 1 means on/off control.
1437 * Other values means the LED is control by PWM.
1439 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1442 /*****************************************************************************/
1443 /* Verified boot commands */
1446 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1447 * reused for other purposes with version > 0.
1450 /* Verified boot hash command */
1451 #define EC_CMD_VBOOT_HASH 0x2A
1453 struct ec_params_vboot_hash {
1454 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1455 uint8_t hash_type; /* enum ec_vboot_hash_type */
1456 uint8_t nonce_size; /* Nonce size; may be 0 */
1457 uint8_t reserved0; /* Reserved; set 0 */
1458 uint32_t offset; /* Offset in flash to hash */
1459 uint32_t size; /* Number of bytes to hash */
1460 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1463 struct ec_response_vboot_hash {
1464 uint8_t status; /* enum ec_vboot_hash_status */
1465 uint8_t hash_type; /* enum ec_vboot_hash_type */
1466 uint8_t digest_size; /* Size of hash digest in bytes */
1467 uint8_t reserved0; /* Ignore; will be 0 */
1468 uint32_t offset; /* Offset in flash which was hashed */
1469 uint32_t size; /* Number of bytes hashed */
1470 uint8_t hash_digest[64]; /* Hash digest data */
1473 enum ec_vboot_hash_cmd {
1474 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1475 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1476 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1477 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1480 enum ec_vboot_hash_type {
1481 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1484 enum ec_vboot_hash_status {
1485 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1486 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1487 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1491 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1492 * If one of these is specified, the EC will automatically update offset and
1493 * size to the correct values for the specified image (RO or RW).
1495 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1496 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1498 /*****************************************************************************/
1500 * Motion sense commands. We'll make separate structs for sub-commands with
1501 * different input args, so that we know how much to expect.
1503 #define EC_CMD_MOTION_SENSE_CMD 0x2B
1505 /* Motion sense commands */
1506 enum motionsense_command {
1508 * Dump command returns all motion sensor data including motion sense
1509 * module flags and individual sensor flags.
1511 MOTIONSENSE_CMD_DUMP = 0,
1514 * Info command returns data describing the details of a given sensor,
1515 * including enum motionsensor_type, enum motionsensor_location, and
1516 * enum motionsensor_chip.
1518 MOTIONSENSE_CMD_INFO = 1,
1521 * EC Rate command is a setter/getter command for the EC sampling rate
1522 * of all motion sensors in milliseconds.
1524 MOTIONSENSE_CMD_EC_RATE = 2,
1527 * Sensor ODR command is a setter/getter command for the output data
1528 * rate of a specific motion sensor in millihertz.
1530 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1533 * Sensor range command is a setter/getter command for the range of
1534 * a specified motion sensor in +/-G's or +/- deg/s.
1536 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1539 * Setter/getter command for the keyboard wake angle. When the lid
1540 * angle is greater than this value, keyboard wake is disabled in S3,
1541 * and when the lid angle goes less than this value, keyboard wake is
1542 * enabled. Note, the lid angle measurement is an approximate,
1543 * un-calibrated value, hence the wake angle isn't exact.
1545 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1548 * Returns a single sensor data.
1550 MOTIONSENSE_CMD_DATA = 6,
1553 * Perform low level calibration.. On sensors that support it, ask to
1554 * do offset calibration.
1556 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1559 * Sensor Offset command is a setter/getter command for the offset used
1560 * for calibration. The offsets can be calculated by the host, or via
1561 * PERFORM_CALIB command.
1563 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1565 /* Number of motionsense sub-commands. */
1566 MOTIONSENSE_NUM_CMDS
1569 enum motionsensor_id {
1570 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1571 EC_MOTION_SENSOR_ACCEL_LID = 1,
1572 EC_MOTION_SENSOR_GYRO = 2,
1575 * Note, if more sensors are added and this count changes, the padding
1576 * in ec_response_motion_sense dump command must be modified.
1578 EC_MOTION_SENSOR_COUNT = 3
1581 /* List of motion sensor types. */
1582 enum motionsensor_type {
1583 MOTIONSENSE_TYPE_ACCEL = 0,
1584 MOTIONSENSE_TYPE_GYRO = 1,
1585 MOTIONSENSE_TYPE_MAG = 2,
1586 MOTIONSENSE_TYPE_PROX = 3,
1587 MOTIONSENSE_TYPE_LIGHT = 4,
1588 MOTIONSENSE_TYPE_ACTIVITY = 5,
1589 MOTIONSENSE_TYPE_BARO = 6,
1590 MOTIONSENSE_TYPE_MAX,
1593 /* List of motion sensor locations. */
1594 enum motionsensor_location {
1595 MOTIONSENSE_LOC_BASE = 0,
1596 MOTIONSENSE_LOC_LID = 1,
1597 MOTIONSENSE_LOC_MAX,
1600 /* List of motion sensor chips. */
1601 enum motionsensor_chip {
1602 MOTIONSENSE_CHIP_KXCJ9 = 0,
1605 /* Module flag masks used for the dump sub-command. */
1606 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1608 /* Sensor flag masks used for the dump sub-command. */
1609 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1612 * Send this value for the data element to only perform a read. If you
1613 * send any other value, the EC will interpret it as data to set and will
1614 * return the actual value set.
1616 #define EC_MOTION_SENSE_NO_VALUE -1
1618 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1620 /* Set Calibration information */
1621 #define MOTION_SENSE_SET_OFFSET 1
1623 struct ec_response_motion_sensor_data {
1624 /* Flags for each sensor. */
1626 /* Sensor number the data comes from */
1628 /* Each sensor is up to 3-axis. */
1636 uint8_t activity; /* motionsensor_activity */
1638 int16_t add_info[2];
1643 struct ec_params_motion_sense {
1646 /* Used for MOTIONSENSE_CMD_DUMP. */
1652 * Used for MOTIONSENSE_CMD_EC_RATE and
1653 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1656 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1658 } ec_rate, kb_wake_angle;
1660 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1665 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1666 * the calibration information in the EC.
1667 * If unset, just retrieve calibration information.
1672 * Temperature at calibration, in units of 0.01 C
1673 * 0x8000: invalid / unknown.
1680 * Offset for calibration.
1682 * Accelerometer: 1/1024 g
1683 * Gyro: 1/1024 deg/s
1687 } __packed sensor_offset;
1689 /* Used for MOTIONSENSE_CMD_INFO. */
1695 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1696 * MOTIONSENSE_CMD_SENSOR_RANGE.
1699 /* Should be element of enum motionsensor_id. */
1702 /* Rounding flag, true for round-up, false for down. */
1707 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1709 } sensor_odr, sensor_range;
1713 struct ec_response_motion_sense {
1715 /* Used for MOTIONSENSE_CMD_DUMP. */
1717 /* Flags representing the motion sensor module. */
1718 uint8_t module_flags;
1720 /* Number of sensors managed directly by the EC. */
1721 uint8_t sensor_count;
1724 * Sensor data is truncated if response_max is too small
1725 * for holding all the data.
1727 struct ec_response_motion_sensor_data sensor[0];
1730 /* Used for MOTIONSENSE_CMD_INFO. */
1732 /* Should be element of enum motionsensor_type. */
1735 /* Should be element of enum motionsensor_location. */
1738 /* Should be element of enum motionsensor_chip. */
1742 /* Used for MOTIONSENSE_CMD_DATA */
1743 struct ec_response_motion_sensor_data data;
1746 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1747 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1748 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1751 /* Current value of the parameter queried. */
1753 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1755 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1759 } sensor_offset, perform_calib;
1763 /*****************************************************************************/
1764 /* USB charging control commands */
1766 /* Set USB port charging mode */
1767 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
1769 struct ec_params_usb_charge_set_mode {
1770 uint8_t usb_port_id;
1774 /*****************************************************************************/
1775 /* Persistent storage for host */
1777 /* Maximum bytes that can be read/written in a single command */
1778 #define EC_PSTORE_SIZE_MAX 64
1780 /* Get persistent storage info */
1781 #define EC_CMD_PSTORE_INFO 0x40
1783 struct ec_response_pstore_info {
1784 /* Persistent storage size, in bytes */
1785 uint32_t pstore_size;
1786 /* Access size; read/write offset and size must be a multiple of this */
1787 uint32_t access_size;
1791 * Read persistent storage
1793 * Response is params.size bytes of data.
1795 #define EC_CMD_PSTORE_READ 0x41
1797 struct ec_params_pstore_read {
1798 uint32_t offset; /* Byte offset to read */
1799 uint32_t size; /* Size to read in bytes */
1802 /* Write persistent storage */
1803 #define EC_CMD_PSTORE_WRITE 0x42
1805 struct ec_params_pstore_write {
1806 uint32_t offset; /* Byte offset to write */
1807 uint32_t size; /* Size to write in bytes */
1808 uint8_t data[EC_PSTORE_SIZE_MAX];
1811 /*****************************************************************************/
1812 /* Real-time clock */
1814 /* RTC params and response structures */
1815 struct ec_params_rtc {
1819 struct ec_response_rtc {
1823 /* These use ec_response_rtc */
1824 #define EC_CMD_RTC_GET_VALUE 0x44
1825 #define EC_CMD_RTC_GET_ALARM 0x45
1827 /* These all use ec_params_rtc */
1828 #define EC_CMD_RTC_SET_VALUE 0x46
1829 #define EC_CMD_RTC_SET_ALARM 0x47
1831 /* Pass as param to SET_ALARM to clear the current alarm */
1832 #define EC_RTC_ALARM_CLEAR 0
1834 /*****************************************************************************/
1835 /* Port80 log access */
1837 /* Maximum entries that can be read/written in a single command */
1838 #define EC_PORT80_SIZE_MAX 32
1840 /* Get last port80 code from previous boot */
1841 #define EC_CMD_PORT80_LAST_BOOT 0x48
1842 #define EC_CMD_PORT80_READ 0x48
1844 enum ec_port80_subcmd {
1845 EC_PORT80_GET_INFO = 0,
1846 EC_PORT80_READ_BUFFER,
1849 struct ec_params_port80_read {
1854 uint32_t num_entries;
1859 struct ec_response_port80_read {
1863 uint32_t history_size;
1867 uint16_t codes[EC_PORT80_SIZE_MAX];
1872 struct ec_response_port80_last_boot {
1876 /*****************************************************************************/
1877 /* Thermal engine commands. Note that there are two implementations. We'll
1878 * reuse the command number, but the data and behavior is incompatible.
1879 * Version 0 is what originally shipped on Link.
1880 * Version 1 separates the CPU thermal limits from the fan control.
1883 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1884 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1886 /* The version 0 structs are opaque. You have to know what they are for
1887 * the get/set commands to make any sense.
1890 /* Version 0 - set */
1891 struct ec_params_thermal_set_threshold {
1892 uint8_t sensor_type;
1893 uint8_t threshold_id;
1897 /* Version 0 - get */
1898 struct ec_params_thermal_get_threshold {
1899 uint8_t sensor_type;
1900 uint8_t threshold_id;
1903 struct ec_response_thermal_get_threshold {
1908 /* The version 1 structs are visible. */
1909 enum ec_temp_thresholds {
1910 EC_TEMP_THRESH_WARN = 0,
1911 EC_TEMP_THRESH_HIGH,
1912 EC_TEMP_THRESH_HALT,
1914 EC_TEMP_THRESH_COUNT
1917 /* Thermal configuration for one temperature sensor. Temps are in degrees K.
1918 * Zero values will be silently ignored by the thermal task.
1920 struct ec_thermal_config {
1921 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1922 uint32_t temp_fan_off; /* no active cooling needed */
1923 uint32_t temp_fan_max; /* max active cooling needed */
1926 /* Version 1 - get config for one sensor. */
1927 struct ec_params_thermal_get_threshold_v1 {
1928 uint32_t sensor_num;
1930 /* This returns a struct ec_thermal_config */
1932 /* Version 1 - set config for one sensor.
1933 * Use read-modify-write for best results! */
1934 struct ec_params_thermal_set_threshold_v1 {
1935 uint32_t sensor_num;
1936 struct ec_thermal_config cfg;
1938 /* This returns no data */
1940 /****************************************************************************/
1942 /* Toggle automatic fan control */
1943 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1945 /* Get TMP006 calibration data */
1946 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
1948 struct ec_params_tmp006_get_calibration {
1952 struct ec_response_tmp006_get_calibration {
1959 /* Set TMP006 calibration data */
1960 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
1962 struct ec_params_tmp006_set_calibration {
1964 uint8_t reserved[3]; /* Reserved; set 0 */
1971 /* Read raw TMP006 data */
1972 #define EC_CMD_TMP006_GET_RAW 0x55
1974 struct ec_params_tmp006_get_raw {
1978 struct ec_response_tmp006_get_raw {
1979 int32_t t; /* In 1/100 K */
1980 int32_t v; /* In nV */
1983 /*****************************************************************************/
1984 /* MKBP - Matrix KeyBoard Protocol */
1989 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1990 * expected response size.
1992 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1993 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1994 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
1996 #define EC_CMD_MKBP_STATE 0x60
1999 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2001 #define EC_CMD_MKBP_INFO 0x61
2003 struct ec_response_mkbp_info {
2006 /* Formerly "switches", which was 0. */
2010 struct ec_params_mkbp_info {
2015 enum ec_mkbp_info_type {
2017 * Info about the keyboard matrix: number of rows and columns.
2019 * Returns struct ec_response_mkbp_info.
2021 EC_MKBP_INFO_KBD = 0,
2024 * For buttons and switches, info about which specifically are
2025 * supported. event_type must be set to one of the values in enum
2028 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2029 * bitmask indicating which buttons or switches are present. See the
2030 * bit inidices below.
2032 EC_MKBP_INFO_SUPPORTED = 1,
2035 * Instantaneous state of buttons and switches.
2037 * event_type must be set to one of the values in enum ec_mkbp_event.
2039 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2040 * indicating the current state of the keyboard matrix.
2042 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2045 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2046 * state of supported buttons.
2048 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2049 * state of supported switches.
2051 EC_MKBP_INFO_CURRENT = 2,
2054 /* Simulate key press */
2055 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
2057 struct ec_params_mkbp_simulate_key {
2063 /* Configure keyboard scanning */
2064 #define EC_CMD_MKBP_SET_CONFIG 0x64
2065 #define EC_CMD_MKBP_GET_CONFIG 0x65
2068 enum mkbp_config_flags {
2069 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2072 enum mkbp_config_valid {
2073 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2074 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2075 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2076 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2077 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2078 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2079 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2082 /* Configuration for our key scanning algorithm */
2083 struct ec_mkbp_config {
2084 uint32_t valid_mask; /* valid fields */
2085 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2086 uint8_t valid_flags; /* which flags are valid */
2087 uint16_t scan_period_us; /* period between start of scans */
2088 /* revert to interrupt mode after no activity for this long */
2089 uint32_t poll_timeout_us;
2091 * minimum post-scan relax time. Once we finish a scan we check
2092 * the time until we are due to start the next one. If this time is
2093 * shorter this field, we use this instead.
2095 uint16_t min_post_scan_delay_us;
2096 /* delay between setting up output and waiting for it to settle */
2097 uint16_t output_settle_us;
2098 uint16_t debounce_down_us; /* time for debounce on key down */
2099 uint16_t debounce_up_us; /* time for debounce on key up */
2100 /* maximum depth to allow for fifo (0 = no keyscan output) */
2101 uint8_t fifo_max_depth;
2104 struct ec_params_mkbp_set_config {
2105 struct ec_mkbp_config config;
2108 struct ec_response_mkbp_get_config {
2109 struct ec_mkbp_config config;
2112 /* Run the key scan emulation */
2113 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2115 enum ec_keyscan_seq_cmd {
2116 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2117 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2118 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2119 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2120 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2123 enum ec_collect_flags {
2125 * Indicates this scan was processed by the EC. Due to timing, some
2126 * scans may be skipped.
2128 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2131 struct ec_collect_item {
2132 uint8_t flags; /* some flags (enum ec_collect_flags) */
2135 struct ec_params_keyscan_seq_ctrl {
2136 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2139 uint8_t active; /* still active */
2140 uint8_t num_items; /* number of items */
2141 /* Current item being presented */
2146 * Absolute time for this scan, measured from the
2147 * start of the sequence.
2150 uint8_t scan[0]; /* keyscan data */
2153 uint8_t start_item; /* First item to return */
2154 uint8_t num_items; /* Number of items to return */
2159 struct ec_result_keyscan_seq_ctrl {
2162 uint8_t num_items; /* Number of items */
2163 /* Data for each item */
2164 struct ec_collect_item item[0];
2170 * Command for retrieving the next pending MKBP event from the EC device
2172 * The device replies with UNAVAILABLE if there aren't any pending events.
2174 #define EC_CMD_GET_NEXT_EVENT 0x67
2176 enum ec_mkbp_event {
2177 /* Keyboard matrix changed. The event data is the new matrix state. */
2178 EC_MKBP_EVENT_KEY_MATRIX = 0,
2180 /* New host event. The event data is 4 bytes of host event flags. */
2181 EC_MKBP_EVENT_HOST_EVENT = 1,
2183 /* New Sensor FIFO data. The event data is fifo_info structure. */
2184 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2186 /* The state of the non-matrixed buttons have changed. */
2187 EC_MKBP_EVENT_BUTTON = 3,
2189 /* The state of the switches have changed. */
2190 EC_MKBP_EVENT_SWITCH = 4,
2192 /* EC sent a sysrq command */
2193 EC_MKBP_EVENT_SYSRQ = 6,
2195 /* Notify the AP that something happened on CEC */
2196 EC_MKBP_EVENT_CEC_EVENT = 8,
2198 /* Send an incoming CEC message to the AP */
2199 EC_MKBP_EVENT_CEC_MESSAGE = 9,
2201 /* Number of MKBP events */
2202 EC_MKBP_EVENT_COUNT,
2205 union ec_response_get_next_data {
2206 uint8_t key_matrix[13];
2209 uint32_t host_event;
2216 union ec_response_get_next_data_v1 {
2217 uint8_t key_matrix[16];
2218 uint32_t host_event;
2222 uint32_t cec_events;
2223 uint8_t cec_message[16];
2226 struct ec_response_get_next_event {
2228 /* Followed by event data if any */
2229 union ec_response_get_next_data data;
2232 struct ec_response_get_next_event_v1 {
2234 /* Followed by event data if any */
2235 union ec_response_get_next_data_v1 data;
2238 /* Bit indices for buttons and switches.*/
2240 #define EC_MKBP_POWER_BUTTON 0
2241 #define EC_MKBP_VOL_UP 1
2242 #define EC_MKBP_VOL_DOWN 2
2245 #define EC_MKBP_LID_OPEN 0
2246 #define EC_MKBP_TABLET_MODE 1
2247 #define EC_MKBP_BASE_ATTACHED 2
2249 /*****************************************************************************/
2250 /* Temperature sensor commands */
2252 /* Read temperature sensor info */
2253 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2255 struct ec_params_temp_sensor_get_info {
2259 struct ec_response_temp_sensor_get_info {
2260 char sensor_name[32];
2261 uint8_t sensor_type;
2264 /*****************************************************************************/
2267 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2268 * commands accidentally sent to the wrong interface. See the ACPI section
2272 /*****************************************************************************/
2273 /* Host event commands */
2276 * Host event mask params and response structures, shared by all of the host
2277 * event commands below.
2279 struct ec_params_host_event_mask {
2283 struct ec_response_host_event_mask {
2287 /* These all use ec_response_host_event_mask */
2288 #define EC_CMD_HOST_EVENT_GET_B 0x87
2289 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2290 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2291 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2293 /* These all use ec_params_host_event_mask */
2294 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2295 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2296 #define EC_CMD_HOST_EVENT_CLEAR 0x8c
2297 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2298 #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2300 /*****************************************************************************/
2301 /* Switch commands */
2303 /* Enable/disable LCD backlight */
2304 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2306 struct ec_params_switch_enable_backlight {
2310 /* Enable/disable WLAN/Bluetooth */
2311 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
2312 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2314 /* Version 0 params; no response */
2315 struct ec_params_switch_enable_wireless_v0 {
2319 /* Version 1 params */
2320 struct ec_params_switch_enable_wireless_v1 {
2321 /* Flags to enable now */
2324 /* Which flags to copy from now_flags */
2328 * Flags to leave enabled in S3, if they're on at the S0->S3
2329 * transition. (Other flags will be disabled by the S0->S3
2332 uint8_t suspend_flags;
2334 /* Which flags to copy from suspend_flags */
2335 uint8_t suspend_mask;
2338 /* Version 1 response */
2339 struct ec_response_switch_enable_wireless_v1 {
2340 /* Flags to enable now */
2343 /* Flags to leave enabled in S3 */
2344 uint8_t suspend_flags;
2347 /*****************************************************************************/
2348 /* GPIO commands. Only available on EC if write protect has been disabled. */
2350 /* Set GPIO output value */
2351 #define EC_CMD_GPIO_SET 0x92
2353 struct ec_params_gpio_set {
2358 /* Get GPIO value */
2359 #define EC_CMD_GPIO_GET 0x93
2361 /* Version 0 of input params and response */
2362 struct ec_params_gpio_get {
2365 struct ec_response_gpio_get {
2369 /* Version 1 of input params and response */
2370 struct ec_params_gpio_get_v1 {
2375 } get_value_by_name;
2382 struct ec_response_gpio_get_v1 {
2386 } get_value_by_name, get_count;
2395 enum gpio_get_subcmd {
2396 EC_GPIO_GET_BY_NAME = 0,
2397 EC_GPIO_GET_COUNT = 1,
2398 EC_GPIO_GET_INFO = 2,
2401 /*****************************************************************************/
2402 /* I2C commands. Only available when flash write protect is unlocked. */
2405 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2406 * removed soon. Use EC_CMD_I2C_XFER instead.
2410 #define EC_CMD_I2C_READ 0x94
2412 struct ec_params_i2c_read {
2413 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2414 uint8_t read_size; /* Either 8 or 16. */
2418 struct ec_response_i2c_read {
2423 #define EC_CMD_I2C_WRITE 0x95
2425 struct ec_params_i2c_write {
2427 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2428 uint8_t write_size; /* Either 8 or 16. */
2433 /*****************************************************************************/
2434 /* Charge state commands. Only available when flash write protect unlocked. */
2436 /* Force charge state machine to stop charging the battery or force it to
2437 * discharge the battery.
2439 #define EC_CMD_CHARGE_CONTROL 0x96
2440 #define EC_VER_CHARGE_CONTROL 1
2442 enum ec_charge_control_mode {
2443 CHARGE_CONTROL_NORMAL = 0,
2444 CHARGE_CONTROL_IDLE,
2445 CHARGE_CONTROL_DISCHARGE,
2448 struct ec_params_charge_control {
2449 uint32_t mode; /* enum charge_control_mode */
2452 /*****************************************************************************/
2453 /* Console commands. Only available when flash write protect is unlocked. */
2455 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2456 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
2459 * Read data from the saved snapshot. If the subcmd parameter is
2460 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2461 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2462 * end of the previous snapshot.
2464 * The params are only looked at in version >= 1 of this command. Prior
2465 * versions will just default to CONSOLE_READ_NEXT behavior.
2467 * Response is null-terminated string. Empty string, if there is no more
2470 #define EC_CMD_CONSOLE_READ 0x98
2472 enum ec_console_read_subcmd {
2473 CONSOLE_READ_NEXT = 0,
2477 struct ec_params_console_read_v1 {
2478 uint8_t subcmd; /* enum ec_console_read_subcmd */
2481 /*****************************************************************************/
2484 * Cut off battery power immediately or after the host has shut down.
2486 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2487 * EC_RES_SUCCESS if the command was successful.
2488 * EC_RES_ERROR if the cut off command failed.
2491 #define EC_CMD_BATTERY_CUT_OFF 0x99
2493 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2495 struct ec_params_battery_cutoff {
2499 /*****************************************************************************/
2500 /* USB port mux control. */
2503 * Switch USB mux or return to automatic switching.
2505 #define EC_CMD_USB_MUX 0x9a
2507 struct ec_params_usb_mux {
2511 /*****************************************************************************/
2512 /* LDOs / FETs control. */
2515 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2516 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2520 * Switch on/off a LDO.
2522 #define EC_CMD_LDO_SET 0x9b
2524 struct ec_params_ldo_set {
2532 #define EC_CMD_LDO_GET 0x9c
2534 struct ec_params_ldo_get {
2538 struct ec_response_ldo_get {
2542 /*****************************************************************************/
2548 #define EC_CMD_POWER_INFO 0x9d
2550 struct ec_response_power_info {
2551 uint32_t usb_dev_type;
2552 uint16_t voltage_ac;
2553 uint16_t voltage_system;
2554 uint16_t current_system;
2555 uint16_t usb_current_limit;
2558 /*****************************************************************************/
2559 /* I2C passthru command */
2561 #define EC_CMD_I2C_PASSTHRU 0x9e
2563 /* Read data; if not present, message is a write */
2564 #define EC_I2C_FLAG_READ (1 << 15)
2566 /* Mask for address */
2567 #define EC_I2C_ADDR_MASK 0x3ff
2569 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2570 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2573 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2575 struct ec_params_i2c_passthru_msg {
2576 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2577 uint16_t len; /* Number of bytes to read or write */
2580 struct ec_params_i2c_passthru {
2581 uint8_t port; /* I2C port number */
2582 uint8_t num_msgs; /* Number of messages */
2583 struct ec_params_i2c_passthru_msg msg[];
2584 /* Data to write for all messages is concatenated here */
2587 struct ec_response_i2c_passthru {
2588 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2589 uint8_t num_msgs; /* Number of messages processed */
2590 uint8_t data[]; /* Data read by messages concatenated here */
2593 /*****************************************************************************/
2594 /* Power button hang detect */
2596 #define EC_CMD_HANG_DETECT 0x9f
2598 /* Reasons to start hang detection timer */
2599 /* Power button pressed */
2600 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2603 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2606 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2608 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2609 #define EC_HANG_START_ON_RESUME (1 << 3)
2611 /* Reasons to cancel hang detection */
2613 /* Power button released */
2614 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2616 /* Any host command from AP received */
2617 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2619 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2620 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2623 * If this flag is set, all the other fields are ignored, and the hang detect
2624 * timer is started. This provides the AP a way to start the hang timer
2625 * without reconfiguring any of the other hang detect settings. Note that
2626 * you must previously have configured the timeouts.
2628 #define EC_HANG_START_NOW (1 << 30)
2631 * If this flag is set, all the other fields are ignored (including
2632 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2633 * without reconfiguring any of the other hang detect settings.
2635 #define EC_HANG_STOP_NOW (1 << 31)
2637 struct ec_params_hang_detect {
2638 /* Flags; see EC_HANG_* */
2641 /* Timeout in msec before generating host event, if enabled */
2642 uint16_t host_event_timeout_msec;
2644 /* Timeout in msec before generating warm reboot, if enabled */
2645 uint16_t warm_reboot_timeout_msec;
2648 /*****************************************************************************/
2649 /* Commands for battery charging */
2652 * This is the single catch-all host command to exchange data regarding the
2653 * charge state machine (v2 and up).
2655 #define EC_CMD_CHARGE_STATE 0xa0
2657 /* Subcommands for this host command */
2658 enum charge_state_command {
2659 CHARGE_STATE_CMD_GET_STATE,
2660 CHARGE_STATE_CMD_GET_PARAM,
2661 CHARGE_STATE_CMD_SET_PARAM,
2662 CHARGE_STATE_NUM_CMDS
2666 * Known param numbers are defined here. Ranges are reserved for board-specific
2667 * params, which are handled by the particular implementations.
2669 enum charge_state_params {
2670 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2671 CS_PARAM_CHG_CURRENT, /* charger current limit */
2672 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2673 CS_PARAM_CHG_STATUS, /* charger-specific status */
2674 CS_PARAM_CHG_OPTION, /* charger-specific options */
2675 /* How many so far? */
2678 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2679 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2680 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2682 /* Other custom param ranges go here... */
2685 struct ec_params_charge_state {
2686 uint8_t cmd; /* enum charge_state_command */
2693 uint32_t param; /* enum charge_state_param */
2697 uint32_t param; /* param to set */
2698 uint32_t value; /* value to set */
2703 struct ec_response_charge_state {
2709 int chg_input_current;
2710 int batt_state_of_charge;
2717 /* no return values */
2724 * Set maximum battery charging current.
2726 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2728 struct ec_params_current_limit {
2729 uint32_t limit; /* in mA */
2733 * Set maximum external voltage / current.
2735 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
2737 /* Command v0 is used only on Spring and is obsolete + unsupported */
2738 struct ec_params_external_power_limit_v1 {
2739 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2740 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2743 #define EC_POWER_LIMIT_NONE 0xffff
2745 /* Inform the EC when entering a sleep state */
2746 #define EC_CMD_HOST_SLEEP_EVENT 0xa9
2748 enum host_sleep_event {
2749 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2750 HOST_SLEEP_EVENT_S3_RESUME = 2,
2751 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2752 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2755 struct ec_params_host_sleep_event {
2756 uint8_t sleep_event;
2760 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
2761 * transition failures
2763 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
2765 /* Disable timeout detection for this sleep transition */
2766 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
2768 struct ec_params_host_sleep_event_v1 {
2769 /* The type of sleep being entered or exited. */
2770 uint8_t sleep_event;
2775 /* Parameters that apply for suspend messages. */
2778 * The timeout in milliseconds between when this message
2779 * is received and when the EC will declare sleep
2780 * transition failure if the sleep signal is not
2783 uint16_t sleep_timeout_ms;
2786 /* No parameters for non-suspend messages. */
2790 /* A timeout occurred when this bit is set */
2791 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
2794 * The mask defining which bits correspond to the number of sleep transitions,
2795 * as well as the maximum number of suspend line transitions that will be
2796 * reported back to the host.
2798 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
2800 struct ec_response_host_sleep_event_v1 {
2802 /* Response fields that apply for resume messages. */
2805 * The number of sleep power signal transitions that
2806 * occurred since the suspend message. The high bit
2807 * indicates a timeout occurred.
2809 uint32_t sleep_transitions;
2812 /* No response fields for non-resume messages. */
2816 /*****************************************************************************/
2817 /* Smart battery pass-through */
2819 /* Get / Set 16-bit smart battery registers */
2820 #define EC_CMD_SB_READ_WORD 0xb0
2821 #define EC_CMD_SB_WRITE_WORD 0xb1
2823 /* Get / Set string smart battery parameters
2824 * formatted as SMBUS "block".
2826 #define EC_CMD_SB_READ_BLOCK 0xb2
2827 #define EC_CMD_SB_WRITE_BLOCK 0xb3
2829 struct ec_params_sb_rd {
2833 struct ec_response_sb_rd_word {
2837 struct ec_params_sb_wr_word {
2842 struct ec_response_sb_rd_block {
2846 struct ec_params_sb_wr_block {
2851 /*****************************************************************************/
2852 /* Battery vendor parameters
2854 * Get or set vendor-specific parameters in the battery. Implementations may
2855 * differ between boards or batteries. On a set operation, the response
2856 * contains the actual value set, which may be rounded or clipped from the
2860 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2862 enum ec_battery_vendor_param_mode {
2863 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2864 BATTERY_VENDOR_PARAM_MODE_SET,
2867 struct ec_params_battery_vendor_param {
2873 struct ec_response_battery_vendor_param {
2877 /*****************************************************************************/
2878 /* Commands for I2S recording on audio codec. */
2880 #define EC_CMD_CODEC_I2S 0x00BC
2882 enum ec_codec_i2s_subcmd {
2883 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2884 EC_CODEC_SET_GAIN = 0x1,
2885 EC_CODEC_GET_GAIN = 0x2,
2886 EC_CODEC_I2S_ENABLE = 0x3,
2887 EC_CODEC_I2S_SET_CONFIG = 0x4,
2888 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2889 EC_CODEC_I2S_SET_BCLK = 0x6,
2892 enum ec_sample_depth_value {
2893 EC_CODEC_SAMPLE_DEPTH_16 = 0,
2894 EC_CODEC_SAMPLE_DEPTH_24 = 1,
2897 enum ec_i2s_config {
2899 EC_DAI_FMT_RIGHT_J = 1,
2900 EC_DAI_FMT_LEFT_J = 2,
2901 EC_DAI_FMT_PCM_A = 3,
2902 EC_DAI_FMT_PCM_B = 4,
2903 EC_DAI_FMT_PCM_TDM = 5,
2906 struct ec_param_codec_i2s {
2908 * enum ec_codec_i2s_subcmd
2913 * EC_CODEC_SET_SAMPLE_DEPTH
2914 * Value should be one of ec_sample_depth_value.
2920 * Value should be 0~43 for both channels.
2922 struct ec_param_codec_i2s_set_gain {
2928 * EC_CODEC_I2S_ENABLE
2929 * 1 to enable, 0 to disable.
2934 * EC_CODEC_I2S_SET_COFNIG
2935 * Value should be one of ec_i2s_config.
2940 * EC_CODEC_I2S_SET_TDM_CONFIG
2941 * Value should be one of ec_i2s_config.
2943 struct ec_param_codec_i2s_tdm {
2952 uint8_t adjacent_to_ch0;
2953 uint8_t adjacent_to_ch1;
2954 } __packed tdm_param;
2957 * EC_CODEC_I2S_SET_BCLK
2964 * For subcommand EC_CODEC_GET_GAIN.
2966 struct ec_response_codec_gain {
2971 /*****************************************************************************/
2972 /* System commands */
2975 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2976 * necessarily reboot the EC. Rename to "image" or something similar?
2978 #define EC_CMD_REBOOT_EC 0xd2
2981 enum ec_reboot_cmd {
2982 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2983 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2984 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2985 /* (command 3 was jump to RW-B) */
2986 EC_REBOOT_COLD = 4, /* Cold-reboot */
2987 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2988 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2991 /* Flags for ec_params_reboot_ec.reboot_flags */
2992 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2993 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2995 struct ec_params_reboot_ec {
2996 uint8_t cmd; /* enum ec_reboot_cmd */
2997 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3001 * Get information on last EC panic.
3003 * Returns variable-length platform-dependent panic information. See panic.h
3006 #define EC_CMD_GET_PANIC_INFO 0xd3
3008 /*****************************************************************************/
3012 * These are valid ONLY on the ACPI command/data port.
3016 * ACPI Read Embedded Controller
3018 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3020 * Use the following sequence:
3022 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3023 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3024 * - Write address to EC_LPC_ADDR_ACPI_DATA
3025 * - Wait for EC_LPC_CMDR_DATA bit to set
3026 * - Read value from EC_LPC_ADDR_ACPI_DATA
3028 #define EC_CMD_ACPI_READ 0x80
3031 * ACPI Write Embedded Controller
3033 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3035 * Use the following sequence:
3037 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3038 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3039 * - Write address to EC_LPC_ADDR_ACPI_DATA
3040 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3041 * - Write value to EC_LPC_ADDR_ACPI_DATA
3043 #define EC_CMD_ACPI_WRITE 0x81
3046 * ACPI Query Embedded Controller
3048 * This clears the lowest-order bit in the currently pending host events, and
3049 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3050 * event 0x80000000 = 32), or 0 if no event was pending.
3052 #define EC_CMD_ACPI_QUERY_EVENT 0x84
3054 /* Valid addresses in ACPI memory space, for read/write commands */
3056 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3057 #define EC_ACPI_MEM_VERSION 0x00
3059 * Test location; writing value here updates test compliment byte to (0xff -
3062 #define EC_ACPI_MEM_TEST 0x01
3063 /* Test compliment; writes here are ignored. */
3064 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3066 /* Keyboard backlight brightness percent (0 - 100) */
3067 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3068 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3069 #define EC_ACPI_MEM_FAN_DUTY 0x04
3072 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3073 * independent thresholds attached to them. The current value of the ID
3074 * register determines which sensor is affected by the THRESHOLD and COMMIT
3075 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3076 * as the memory-mapped sensors. The COMMIT register applies those settings.
3078 * The spec does not mandate any way to read back the threshold settings
3079 * themselves, but when a threshold is crossed the AP needs a way to determine
3080 * which sensor(s) are responsible. Each reading of the ID register clears and
3081 * returns one sensor ID that has crossed one of its threshold (in either
3082 * direction) since the last read. A value of 0xFF means "no new thresholds
3083 * have tripped". Setting or enabling the thresholds for a sensor will clear
3084 * the unread event count for that sensor.
3086 #define EC_ACPI_MEM_TEMP_ID 0x05
3087 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3088 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
3090 * Here are the bits for the COMMIT register:
3091 * bit 0 selects the threshold index for the chosen sensor (0/1)
3092 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3093 * Each write to the commit register affects one threshold.
3095 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3096 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3100 * Set the thresholds for sensor 2 to 50 C and 60 C:
3101 * write 2 to [0x05] -- select temp sensor 2
3102 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3103 * write 0x2 to [0x07] -- enable threshold 0 with this value
3104 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3105 * write 0x3 to [0x07] -- enable threshold 1 with this value
3107 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3108 * write 2 to [0x05] -- select temp sensor 2
3109 * write 0x1 to [0x07] -- disable threshold 1
3112 /* DPTF battery charging current limit */
3113 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3115 /* Charging limit is specified in 64 mA steps */
3116 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3117 /* Value to disable DPTF battery charging limit */
3118 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
3120 /* Current version of ACPI memory address space */
3121 #define EC_ACPI_MEM_VERSION_CURRENT 1
3124 /*****************************************************************************/
3128 * These commands are for sending and receiving message via HDMI CEC
3130 #define EC_MAX_CEC_MSG_LEN 16
3132 /* CEC message from the AP to be written on the CEC bus */
3133 #define EC_CMD_CEC_WRITE_MSG 0x00B8
3136 * struct ec_params_cec_write - Message to write to the CEC bus
3137 * @msg: message content to write to the CEC bus
3139 struct ec_params_cec_write {
3140 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3143 /* Set various CEC parameters */
3144 #define EC_CMD_CEC_SET 0x00BA
3147 * struct ec_params_cec_set - CEC parameters set
3148 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3149 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3150 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3151 * this field encodes the requested logical address between 0 and 15
3152 * or 0xff to unregister
3154 struct ec_params_cec_set {
3155 uint8_t cmd; /* enum cec_command */
3159 /* Read various CEC parameters */
3160 #define EC_CMD_CEC_GET 0x00BB
3163 * struct ec_params_cec_get - CEC parameters get
3164 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3166 struct ec_params_cec_get {
3167 uint8_t cmd; /* enum cec_command */
3171 * struct ec_response_cec_get - CEC parameters get response
3172 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3173 * disabled or 1 if CEC functionality is enabled,
3174 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3175 * configured logical address between 0 and 15 or 0xff if unregistered
3177 struct ec_response_cec_get {
3181 /* CEC parameters command */
3182 enum ec_cec_command {
3183 /* CEC reading, writing and events enable */
3185 /* CEC logical address */
3186 CEC_CMD_LOGICAL_ADDRESS,
3189 /* Events from CEC to AP */
3190 enum mkbp_cec_event {
3191 /* Outgoing message was acknowledged by a follower */
3192 EC_MKBP_CEC_SEND_OK = BIT(0),
3193 /* Outgoing message was not acknowledged */
3194 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3197 /*****************************************************************************/
3201 * These do not follow the normal rules for commands. See each command for
3208 * This command will work even when the EC LPC interface is busy, because the
3209 * reboot command is processed at interrupt level. Note that when the EC
3210 * reboots, the host will reboot too, so there is no response to this command.
3212 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3214 #define EC_CMD_REBOOT 0xd1 /* Think "die" */
3217 * Resend last response (not supported on LPC).
3219 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3220 * there was no previous command, or the previous command's response was too
3223 #define EC_CMD_RESEND_RESPONSE 0xdb
3226 * This header byte on a command indicate version 0. Any header byte less
3227 * than this means that we are talking to an old EC which doesn't support
3228 * versioning. In that case, we assume version 0.
3230 * Header bytes greater than this indicate a later version. For example,
3231 * EC_CMD_VERSION0 + 1 means we are using version 1.
3233 * The old EC interface must not use commands 0xdc or higher.
3235 #define EC_CMD_VERSION0 0xdc
3237 #endif /* !__ACPI__ */
3239 /*****************************************************************************/
3243 * These commands are for PD MCU communication.
3246 /* EC to PD MCU exchange status command */
3247 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
3249 /* Status of EC being sent to PD */
3250 struct ec_params_pd_status {
3251 int8_t batt_soc; /* battery state of charge */
3254 /* Status of PD being sent back to EC */
3255 struct ec_response_pd_status {
3256 int8_t status; /* PD MCU status */
3257 uint32_t curr_lim_ma; /* input current limit */
3260 /* Set USB type-C port role and muxes */
3261 #define EC_CMD_USB_PD_CONTROL 0x101
3263 enum usb_pd_control_role {
3264 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3265 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3266 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3267 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3268 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3271 enum usb_pd_control_mux {
3272 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3273 USB_PD_CTRL_MUX_NONE = 1,
3274 USB_PD_CTRL_MUX_USB = 2,
3275 USB_PD_CTRL_MUX_DP = 3,
3276 USB_PD_CTRL_MUX_DOCK = 4,
3277 USB_PD_CTRL_MUX_AUTO = 5,
3280 enum usb_pd_control_swap {
3281 USB_PD_CTRL_SWAP_NONE = 0,
3282 USB_PD_CTRL_SWAP_DATA = 1,
3283 USB_PD_CTRL_SWAP_POWER = 2,
3284 USB_PD_CTRL_SWAP_VCONN = 3,
3285 USB_PD_CTRL_SWAP_COUNT
3288 struct ec_params_usb_pd_control {
3295 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3296 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3297 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3299 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3300 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
3301 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
3302 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
3303 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
3304 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3305 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3307 struct ec_response_usb_pd_control_v1 {
3314 #define EC_CMD_USB_PD_PORTS 0x102
3316 /* Maximum number of PD ports on a device, num_ports will be <= this */
3317 #define EC_USB_PD_MAX_PORTS 8
3319 struct ec_response_usb_pd_ports {
3323 #define EC_CMD_USB_PD_POWER_INFO 0x103
3325 #define PD_POWER_CHARGING_PORT 0xff
3326 struct ec_params_usb_pd_power_info {
3334 USB_CHG_TYPE_PROPRIETARY,
3335 USB_CHG_TYPE_BC12_DCP,
3336 USB_CHG_TYPE_BC12_CDP,
3337 USB_CHG_TYPE_BC12_SDP,
3340 USB_CHG_TYPE_UNKNOWN,
3342 enum usb_power_roles {
3343 USB_PD_PORT_POWER_DISCONNECTED,
3344 USB_PD_PORT_POWER_SOURCE,
3345 USB_PD_PORT_POWER_SINK,
3346 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3349 struct usb_chg_measures {
3350 uint16_t voltage_max;
3351 uint16_t voltage_now;
3352 uint16_t current_max;
3353 uint16_t current_lim;
3356 struct ec_response_usb_pd_power_info {
3361 struct usb_chg_measures meas;
3365 struct ec_params_usb_pd_info_request {
3370 * This command will return the number of USB PD charge port + the number
3371 * of dedicated port present.
3372 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
3374 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
3375 struct ec_response_charge_port_count {
3379 /* Read USB-PD Device discovery info */
3380 #define EC_CMD_USB_PD_DISCOVERY 0x0113
3381 struct ec_params_usb_pd_discovery_entry {
3382 uint16_t vid; /* USB-IF VID */
3383 uint16_t pid; /* USB-IF PID */
3384 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3387 /* Override default charge behavior */
3388 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
3390 /* Negative port parameters have special meaning */
3391 enum usb_pd_override_ports {
3392 OVERRIDE_DONT_CHARGE = -2,
3394 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
3397 struct ec_params_charge_port_override {
3398 int16_t override_port; /* Override port# */
3401 /* Read (and delete) one entry of PD event log */
3402 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3404 struct ec_response_pd_log {
3405 uint32_t timestamp; /* relative timestamp in milliseconds */
3406 uint8_t type; /* event type : see PD_EVENT_xx below */
3407 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3408 uint16_t data; /* type-defined data payload */
3409 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3412 /* The timestamp is the microsecond counter shifted to get about a ms. */
3413 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3415 #define PD_LOG_SIZE_MASK 0x1f
3416 #define PD_LOG_PORT_MASK 0xe0
3417 #define PD_LOG_PORT_SHIFT 5
3418 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3419 ((size) & PD_LOG_SIZE_MASK))
3420 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3421 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3423 /* PD event log : entry types */
3425 #define PD_EVENT_MCU_BASE 0x00
3426 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3427 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3428 /* Reserved for custom board event */
3429 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3430 /* PD generic accessory events */
3431 #define PD_EVENT_ACC_BASE 0x20
3432 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3433 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3434 /* PD power supply events */
3435 #define PD_EVENT_PS_BASE 0x40
3436 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3437 /* PD video dongles events */
3438 #define PD_EVENT_VIDEO_BASE 0x60
3439 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3440 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3441 /* Returned in the "type" field, when there is no entry available */
3442 #define PD_EVENT_NO_ENTRY 0xff
3445 * PD_EVENT_MCU_CHARGE event definition :
3446 * the payload is "struct usb_chg_measures"
3447 * the data field contains the port state flags as defined below :
3449 /* Port partner is a dual role device */
3450 #define CHARGE_FLAGS_DUAL_ROLE BIT(15)
3451 /* Port is the pending override port */
3452 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
3453 /* Port is the override port */
3454 #define CHARGE_FLAGS_OVERRIDE BIT(13)
3456 #define CHARGE_FLAGS_TYPE_SHIFT 3
3457 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
3458 /* Power delivery role */
3459 #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3462 * PD_EVENT_PS_FAULT data field flags definition :
3464 #define PS_FAULT_OCP 1
3465 #define PS_FAULT_FAST_OCP 2
3466 #define PS_FAULT_OVP 3
3467 #define PS_FAULT_DISCH 4
3470 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3472 struct mcdp_version {
3481 struct mcdp_version irom;
3482 struct mcdp_version fw;
3485 /* struct mcdp_info field decoding */
3486 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3487 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3489 /* Get info about USB-C SS muxes */
3490 #define EC_CMD_USB_PD_MUX_INFO 0x11a
3492 struct ec_params_usb_pd_mux_info {
3493 uint8_t port; /* USB-C port number */
3496 /* Flags representing mux state */
3497 #define USB_PD_MUX_USB_ENABLED (1 << 0)
3498 #define USB_PD_MUX_DP_ENABLED (1 << 1)
3499 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3500 #define USB_PD_MUX_HPD_IRQ (1 << 3)
3502 struct ec_response_usb_pd_mux_info {
3503 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3506 /*****************************************************************************/
3510 * Some platforms have sub-processors chained to each other. For example.
3512 * AP <--> EC <--> PD MCU
3514 * The top 2 bits of the command number are used to indicate which device the
3515 * command is intended for. Device 0 is always the device receiving the
3516 * command; other device mapping is board-specific.
3518 * When a device receives a command to be passed to a sub-processor, it passes
3519 * it on with the device number set back to 0. This allows the sub-processor
3520 * to remain blissfully unaware of whether the command originated on the next
3521 * device up the chain, or was passed through from the AP.
3523 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3524 * AP sends command 0x4002 to the EC
3525 * EC sends command 0x0002 to the PD MCU
3526 * EC forwards PD MCU response back to the AP
3529 /* Offset and max command number for sub-device n */
3530 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3531 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3533 /*****************************************************************************/
3535 * Deprecated constants. These constants have been renamed for clarity. The
3536 * meaning and size has not changed. Programs that use the old names should
3537 * switch to the new names soon, as the old names may not be carried forward
3540 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3541 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3542 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3544 #endif /* __CROS_EC_COMMANDS_H */