2 * Host communication command constants for ChromeOS EC
4 * Copyright (C) 2012 Google, Inc
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * The ChromeOS EC multi function device is used to mux all the requests
16 * to the EC device for its multiple features: keyboard controller,
17 * battery charging and regulator control, firmware update.
19 * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
20 * project in an attempt to make future updates easy to make.
23 #ifndef __CROS_EC_COMMANDS_H
24 #define __CROS_EC_COMMANDS_H
27 * Current version of this protocol
29 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
30 * determined in other ways. Remove this once the kernel code no longer
33 #define EC_PROTO_VERSION 0x00000002
35 /* Command version mask */
36 #define EC_VER_MASK(version) (1UL << (version))
38 /* I/O addresses for ACPI commands */
39 #define EC_LPC_ADDR_ACPI_DATA 0x62
40 #define EC_LPC_ADDR_ACPI_CMD 0x66
42 /* I/O addresses for host command */
43 #define EC_LPC_ADDR_HOST_DATA 0x200
44 #define EC_LPC_ADDR_HOST_CMD 0x204
46 /* I/O addresses for host command args and params */
47 /* Protocol version 2 */
48 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
49 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
50 * EC_PROTO2_MAX_PARAM_SIZE */
51 /* Protocol version 3 */
52 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
53 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
55 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
56 * and they tell the kernel that so we have to think of it as two parts. */
57 #define EC_HOST_CMD_REGION0 0x800
58 #define EC_HOST_CMD_REGION1 0x880
59 #define EC_HOST_CMD_REGION_SIZE 0x80
61 /* EC command register bit functions */
62 #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
63 #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
64 #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
65 #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
66 #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
67 #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
68 #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
70 #define EC_LPC_ADDR_MEMMAP 0x900
71 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
72 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
74 /* The offset address of each type of data in mapped memory. */
75 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
76 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
77 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
78 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
79 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
80 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
81 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
82 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
83 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
84 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
85 /* Unused 0x28 - 0x2f */
86 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
87 /* Unused 0x31 - 0x33 */
88 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
89 /* Reserve 0x38 - 0x3f for additional host event-related stuff */
90 /* Battery values are all 32 bits */
91 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
92 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
93 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
94 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
95 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
96 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
97 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
98 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
99 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
100 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
101 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
102 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
103 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
104 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
105 /* Unused 0x84 - 0x8f */
106 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
108 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
109 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
110 /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
113 /* Define the format of the accelerometer mapped memory status byte. */
114 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
115 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
116 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
118 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
119 #define EC_TEMP_SENSOR_ENTRIES 16
121 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
123 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
125 #define EC_TEMP_SENSOR_B_ENTRIES 8
127 /* Special values for mapped temperature sensors */
128 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
129 #define EC_TEMP_SENSOR_ERROR 0xfe
130 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
131 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
133 * The offset of temperature value stored in mapped memory. This allows
134 * reporting a temperature range of 200K to 454K = -73C to 181C.
136 #define EC_TEMP_SENSOR_OFFSET 200
139 * Number of ALS readings at EC_MEMMAP_ALS
141 #define EC_ALS_ENTRIES 2
144 * The default value a temperature sensor will return when it is present but
145 * has not been read this boot. This is a reasonable number to avoid
146 * triggering alarms on the host.
148 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
150 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
151 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
152 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
154 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
155 #define EC_BATT_FLAG_AC_PRESENT 0x01
156 #define EC_BATT_FLAG_BATT_PRESENT 0x02
157 #define EC_BATT_FLAG_DISCHARGING 0x04
158 #define EC_BATT_FLAG_CHARGING 0x08
159 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
161 /* Switch flags at EC_MEMMAP_SWITCHES */
162 #define EC_SWITCH_LID_OPEN 0x01
163 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
164 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
165 /* Was recovery requested via keyboard; now unused. */
166 #define EC_SWITCH_IGNORE1 0x08
167 /* Recovery requested via dedicated signal (from servo board) */
168 #define EC_SWITCH_DEDICATED_RECOVERY 0x10
169 /* Was fake developer mode switch; now unused. Remove in next refactor. */
170 #define EC_SWITCH_IGNORE0 0x20
172 /* Host command interface flags */
173 /* Host command interface supports LPC args (LPC interface only) */
174 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
175 /* Host command interface supports version 3 protocol */
176 #define EC_HOST_CMD_FLAG_VERSION_3 0x02
178 /* Wireless switch flags */
179 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
180 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
181 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
182 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
183 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
186 * This header file is used in coreboot both in C and ACPI code. The ACPI code
187 * is pre-processed to handle constants but the ASL compiler is unable to
188 * handle actual C code so keep it separate.
193 * Define __packed if someone hasn't beat us to it. Linux kernel style
194 * checking prefers __packed over __attribute__((packed)).
197 #define __packed __attribute__((packed))
200 /* LPC command status byte masks */
201 /* EC has written a byte in the data register and host hasn't read it yet */
202 #define EC_LPC_STATUS_TO_HOST 0x01
203 /* Host has written a command/data byte and the EC hasn't read it yet */
204 #define EC_LPC_STATUS_FROM_HOST 0x02
205 /* EC is processing a command */
206 #define EC_LPC_STATUS_PROCESSING 0x04
207 /* Last write to EC was a command, not data */
208 #define EC_LPC_STATUS_LAST_CMD 0x08
209 /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
210 #define EC_LPC_STATUS_BURST_MODE 0x10
211 /* SCI event is pending (requesting SCI query) */
212 #define EC_LPC_STATUS_SCI_PENDING 0x20
213 /* SMI event is pending (requesting SMI query) */
214 #define EC_LPC_STATUS_SMI_PENDING 0x40
216 #define EC_LPC_STATUS_RESERVED 0x80
219 * EC is busy. This covers both the EC processing a command, and the host has
220 * written a new command but the EC hasn't picked it up yet.
222 #define EC_LPC_STATUS_BUSY_MASK \
223 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
225 /* Host command response codes */
228 EC_RES_INVALID_COMMAND = 1,
230 EC_RES_INVALID_PARAM = 3,
231 EC_RES_ACCESS_DENIED = 4,
232 EC_RES_INVALID_RESPONSE = 5,
233 EC_RES_INVALID_VERSION = 6,
234 EC_RES_INVALID_CHECKSUM = 7,
235 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
236 EC_RES_UNAVAILABLE = 9, /* No response available */
237 EC_RES_TIMEOUT = 10, /* We got a timeout */
238 EC_RES_OVERFLOW = 11, /* Table / data overflow */
239 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
240 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
241 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
245 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
246 * EC command uses code 0 to mean "no event pending". We explicitly specify
247 * each value in the enum listing so they won't change if we delete/insert an
248 * item or rearrange the list (it needs to be stable across platforms, not
249 * just within a single compiled instance).
251 enum host_event_code {
252 EC_HOST_EVENT_LID_CLOSED = 1,
253 EC_HOST_EVENT_LID_OPEN = 2,
254 EC_HOST_EVENT_POWER_BUTTON = 3,
255 EC_HOST_EVENT_AC_CONNECTED = 4,
256 EC_HOST_EVENT_AC_DISCONNECTED = 5,
257 EC_HOST_EVENT_BATTERY_LOW = 6,
258 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
259 EC_HOST_EVENT_BATTERY = 8,
260 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
261 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
262 EC_HOST_EVENT_THERMAL = 11,
263 EC_HOST_EVENT_USB_CHARGER = 12,
264 EC_HOST_EVENT_KEY_PRESSED = 13,
266 * EC has finished initializing the host interface. The host can check
267 * for this event following sending a EC_CMD_REBOOT_EC command to
268 * determine when the EC is ready to accept subsequent commands.
270 EC_HOST_EVENT_INTERFACE_READY = 14,
271 /* Keyboard recovery combo has been pressed */
272 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
274 /* Shutdown due to thermal overload */
275 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
276 /* Shutdown due to battery level too low */
277 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
279 /* Suggest that the AP throttle itself */
280 EC_HOST_EVENT_THROTTLE_START = 18,
281 /* Suggest that the AP resume normal speed */
282 EC_HOST_EVENT_THROTTLE_STOP = 19,
284 /* Hang detect logic detected a hang and host event timeout expired */
285 EC_HOST_EVENT_HANG_DETECT = 20,
286 /* Hang detect logic detected a hang and warm rebooted the AP */
287 EC_HOST_EVENT_HANG_REBOOT = 21,
290 * The high bit of the event mask is not used as a host event code. If
291 * it reads back as set, then the entire event mask should be
292 * considered invalid by the host. This can happen when reading the
293 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
294 * not initialized on the EC, or improperly configured on the host.
296 EC_HOST_EVENT_INVALID = 32
298 /* Host event mask */
299 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
301 /* Arguments at EC_LPC_ADDR_HOST_ARGS */
302 struct ec_lpc_host_args {
304 uint8_t command_version;
307 * Checksum; sum of command + flags + command_version + data_size +
308 * all params/response data bytes.
313 /* Flags for ec_lpc_host_args.flags */
315 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
318 * If EC gets a command and this flag is not set, this is an old-style command.
319 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
320 * unknown length. EC must respond with an old-style response (that is,
321 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
323 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
325 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
327 * If EC responds to a command and this flag is not set, this is an old-style
328 * response. Command version is 0 and response data from EC is at
329 * EC_LPC_ADDR_OLD_PARAM with unknown length.
331 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
333 /*****************************************************************************/
335 * Byte codes returned by EC over SPI interface.
337 * These can be used by the AP to debug the EC interface, and to determine
338 * when the EC is not in a state where it will ever get around to responding
341 * Example of sequence of bytes read from EC for a current good transfer:
342 * 1. - - AP asserts chip select (CS#)
343 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
344 * 3. - - EC starts handling CS# interrupt
345 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
346 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
347 * bytes looking for EC_SPI_FRAME_START
348 * 6. - - EC finishes processing and sets up response
349 * 7. EC_SPI_FRAME_START - AP reads frame byte
350 * 8. (response packet) - AP reads response packet
351 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
352 * 10 - - AP deasserts chip select
353 * 11 - - EC processes CS# interrupt and sets up DMA for
356 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
357 * the following byte values:
363 * Then the EC found an error in the request, or was not ready for the request
364 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
365 * because the EC is unable to tell when the AP is done sending its request.
369 * Framing byte which precedes a response packet from the EC. After sending a
370 * request, the AP will clock in bytes until it sees the framing byte, then
371 * clock in the response packet.
373 #define EC_SPI_FRAME_START 0xec
376 * Padding bytes which are clocked out after the end of a response packet.
378 #define EC_SPI_PAST_END 0xed
381 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
382 * that the AP will send a valid packet header (starting with
383 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
385 #define EC_SPI_RX_READY 0xf8
388 * EC has started receiving the request from the AP, but hasn't started
391 #define EC_SPI_RECEIVING 0xf9
393 /* EC has received the entire request from the AP and is processing it. */
394 #define EC_SPI_PROCESSING 0xfa
397 * EC received bad data from the AP, such as a packet header with an invalid
398 * length. EC will ignore all data until chip select deasserts.
400 #define EC_SPI_RX_BAD_DATA 0xfb
403 * EC received data from the AP before it was ready. That is, the AP asserted
404 * chip select and started clocking data before the EC was ready to receive it.
405 * EC will ignore all data until chip select deasserts.
407 #define EC_SPI_NOT_READY 0xfc
410 * EC was ready to receive a request from the AP. EC has treated the byte sent
411 * by the AP as part of a request packet, or (for old-style ECs) is processing
412 * a fully received packet but is not ready to respond yet.
414 #define EC_SPI_OLD_READY 0xfd
416 /*****************************************************************************/
419 * Protocol version 2 for I2C and SPI send a request this way:
421 * 0 EC_CMD_VERSION0 + (command version)
423 * 2 Length of params = N
424 * 3..N+2 Params, if any
425 * N+3 8-bit checksum of bytes 0..N+2
427 * The corresponding response is:
429 * 0 Result code (EC_RES_*)
430 * 1 Length of params = M
431 * 2..M+1 Params, if any
432 * M+2 8-bit checksum of bytes 0..M+1
434 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
435 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
436 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
437 EC_PROTO2_REQUEST_TRAILER_BYTES)
439 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
440 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
441 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
442 EC_PROTO2_RESPONSE_TRAILER_BYTES)
444 /* Parameter length was limited by the LPC interface */
445 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
447 /* Maximum request and response packet sizes for protocol version 2 */
448 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
449 EC_PROTO2_MAX_PARAM_SIZE)
450 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
451 EC_PROTO2_MAX_PARAM_SIZE)
453 /*****************************************************************************/
456 * Value written to legacy command port / prefix byte to indicate protocol
457 * 3+ structs are being used. Usage is bus-dependent.
459 #define EC_COMMAND_PROTOCOL_3 0xda
461 #define EC_HOST_REQUEST_VERSION 3
463 /* Version 3 request from host */
464 struct ec_host_request {
465 /* Struct version (=3)
467 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
468 * version it doesn't know how to parse.
470 uint8_t struct_version;
473 * Checksum of request and data; sum of all bytes including checksum
481 /* Command version */
482 uint8_t command_version;
484 /* Unused byte in current protocol version; set to 0 */
487 /* Length of data which follows this header */
491 #define EC_HOST_RESPONSE_VERSION 3
493 /* Version 3 response from EC */
494 struct ec_host_response {
495 /* Struct version (=3) */
496 uint8_t struct_version;
499 * Checksum of response and data; sum of all bytes including checksum
504 /* Result code (EC_RES_*) */
507 /* Length of data which follows this header */
510 /* Unused bytes in current protocol version; set to 0 */
514 /*****************************************************************************/
518 * Each command is an 16-bit command value. Commands which take params or
519 * return response data specify structs for that data. If no struct is
520 * specified, the command does not input or output data, respectively.
521 * Parameter/response length is implicit in the structs. Some underlying
522 * communication protocols (I2C, SPI) may add length or checksum headers, but
523 * those are implementation-dependent and not defined here.
526 /*****************************************************************************/
527 /* General / test commands */
530 * Get protocol version, used to deal with non-backward compatible protocol
533 #define EC_CMD_PROTO_VERSION 0x00
535 struct ec_response_proto_version {
540 * Hello. This is a simple command to test the EC is responsive to
543 #define EC_CMD_HELLO 0x01
545 struct ec_params_hello {
546 uint32_t in_data; /* Pass anything here */
549 struct ec_response_hello {
550 uint32_t out_data; /* Output will be in_data + 0x01020304 */
553 /* Get version number */
554 #define EC_CMD_GET_VERSION 0x02
556 enum ec_current_image {
557 EC_IMAGE_UNKNOWN = 0,
562 struct ec_response_get_version {
563 /* Null-terminated version strings for RO, RW */
564 char version_string_ro[32];
565 char version_string_rw[32];
566 char reserved[32]; /* Was previously RW-B string */
567 uint32_t current_image; /* One of ec_current_image */
571 #define EC_CMD_READ_TEST 0x03
573 struct ec_params_read_test {
574 uint32_t offset; /* Starting value for read buffer */
575 uint32_t size; /* Size to read in bytes */
578 struct ec_response_read_test {
583 * Get build information
585 * Response is null-terminated string.
587 #define EC_CMD_GET_BUILD_INFO 0x04
590 #define EC_CMD_GET_CHIP_INFO 0x05
592 struct ec_response_get_chip_info {
593 /* Null-terminated strings */
596 char revision[32]; /* Mask version */
599 /* Get board HW version */
600 #define EC_CMD_GET_BOARD_VERSION 0x06
602 struct ec_response_board_version {
603 uint16_t board_version; /* A monotonously incrementing number. */
607 * Read memory-mapped data.
609 * This is an alternate interface to memory-mapped data for bus protocols
610 * which don't support direct-mapped memory - I2C, SPI, etc.
612 * Response is params.size bytes of data.
614 #define EC_CMD_READ_MEMMAP 0x07
616 struct ec_params_read_memmap {
617 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
618 uint8_t size; /* Size to read in bytes */
621 /* Read versions supported for a command */
622 #define EC_CMD_GET_CMD_VERSIONS 0x08
624 struct ec_params_get_cmd_versions {
625 uint8_t cmd; /* Command to check */
628 struct ec_response_get_cmd_versions {
630 * Mask of supported versions; use EC_VER_MASK() to compare with a
633 uint32_t version_mask;
637 * Check EC communcations status (busy). This is needed on i2c/spi but not
638 * on lpc since it has its own out-of-band busy indicator.
640 * lpc must read the status from the command register. Attempting this on
641 * lpc will overwrite the args/parameter space and corrupt its data.
643 #define EC_CMD_GET_COMMS_STATUS 0x09
645 /* Avoid using ec_status which is for return values */
646 enum ec_comms_status {
647 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
650 struct ec_response_get_comms_status {
651 uint32_t flags; /* Mask of enum ec_comms_status */
654 /* Fake a variety of responses, purely for testing purposes. */
655 #define EC_CMD_TEST_PROTOCOL 0x0a
657 /* Tell the EC what to send back to us. */
658 struct ec_params_test_protocol {
664 /* Here it comes... */
665 struct ec_response_test_protocol {
669 /* Get prococol information */
670 #define EC_CMD_GET_PROTOCOL_INFO 0x0b
672 /* Flags for ec_response_get_protocol_info.flags */
673 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
674 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
676 struct ec_response_get_protocol_info {
677 /* Fields which exist if at least protocol version 3 supported */
679 /* Bitmask of protocol versions supported (1 << n means version n)*/
680 uint32_t protocol_versions;
682 /* Maximum request packet size, in bytes */
683 uint16_t max_request_packet_size;
685 /* Maximum response packet size, in bytes */
686 uint16_t max_response_packet_size;
688 /* Flags; see EC_PROTOCOL_INFO_* */
693 /*****************************************************************************/
694 /* Get/Set miscellaneous values */
696 /* The upper byte of .flags tells what to do (nothing means "get") */
697 #define EC_GSV_SET 0x80000000
699 /* The lower three bytes of .flags identifies the parameter, if that has
700 meaning for an individual command. */
701 #define EC_GSV_PARAM_MASK 0x00ffffff
703 struct ec_params_get_set_value {
708 struct ec_response_get_set_value {
713 /* More than one command can use these structs to get/set paramters. */
714 #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
716 /*****************************************************************************/
717 /* List the features supported by the firmware */
718 #define EC_CMD_GET_FEATURES 0x0d
720 /* Supported features */
721 enum ec_feature_code {
723 * This image contains a limited set of features. Another image
724 * in RW partition may support more features.
726 EC_FEATURE_LIMITED = 0,
728 * Commands for probing/reading/writing/erasing the flash in the
731 EC_FEATURE_FLASH = 1,
733 * Can control the fan speed directly.
735 EC_FEATURE_PWM_FAN = 2,
737 * Can control the intensity of the keyboard backlight.
739 EC_FEATURE_PWM_KEYB = 3,
741 * Support Google lightbar, introduced on Pixel.
743 EC_FEATURE_LIGHTBAR = 4,
744 /* Control of LEDs */
746 /* Exposes an interface to control gyro and sensors.
747 * The host goes through the EC to access these sensors.
748 * In addition, the EC may provide composite sensors, like lid angle.
750 EC_FEATURE_MOTION_SENSE = 6,
751 /* The keyboard is controlled by the EC */
753 /* The AP can use part of the EC flash as persistent storage. */
754 EC_FEATURE_PSTORE = 8,
755 /* The EC monitors BIOS port 80h, and can return POST codes. */
756 EC_FEATURE_PORT80 = 9,
758 * Thermal management: include TMP specific commands.
759 * Higher level than direct fan control.
761 EC_FEATURE_THERMAL = 10,
762 /* Can switch the screen backlight on/off */
763 EC_FEATURE_BKLIGHT_SWITCH = 11,
764 /* Can switch the wifi module on/off */
765 EC_FEATURE_WIFI_SWITCH = 12,
766 /* Monitor host events, through for example SMI or SCI */
767 EC_FEATURE_HOST_EVENTS = 13,
768 /* The EC exposes GPIO commands to control/monitor connected devices. */
769 EC_FEATURE_GPIO = 14,
770 /* The EC can send i2c messages to downstream devices. */
772 /* Command to control charger are included */
773 EC_FEATURE_CHARGER = 16,
774 /* Simple battery support. */
775 EC_FEATURE_BATTERY = 17,
777 * Support Smart battery protocol
778 * (Common Smart Battery System Interface Specification)
780 EC_FEATURE_SMART_BATTERY = 18,
781 /* EC can dectect when the host hangs. */
782 EC_FEATURE_HANG_DETECT = 19,
783 /* Report power information, for pit only */
785 /* Another Cros EC device is present downstream of this one */
786 EC_FEATURE_SUB_MCU = 21,
787 /* Support USB Power delivery (PD) commands */
788 EC_FEATURE_USB_PD = 22,
789 /* Control USB multiplexer, for audio through USB port for instance. */
790 EC_FEATURE_USB_MUX = 23,
791 /* Motion Sensor code has an internal software FIFO */
792 EC_FEATURE_MOTION_SENSE_FIFO = 24,
795 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
796 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
797 struct ec_response_get_features {
801 /*****************************************************************************/
805 #define EC_CMD_FLASH_INFO 0x10
807 /* Version 0 returns these fields */
808 struct ec_response_flash_info {
809 /* Usable flash size, in bytes */
812 * Write block size. Write offset and size must be a multiple
815 uint32_t write_block_size;
817 * Erase block size. Erase offset and size must be a multiple
820 uint32_t erase_block_size;
822 * Protection block size. Protection offset and size must be a
825 uint32_t protect_block_size;
828 /* Flags for version 1+ flash info command */
829 /* EC flash erases bits to 0 instead of 1 */
830 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
833 * Version 1 returns the same initial fields as version 0, with additional
836 * gcc anonymous structs don't seem to get along with the __packed directive;
837 * if they did we'd define the version 0 struct as a sub-struct of this one.
839 struct ec_response_flash_info_1 {
840 /* Version 0 fields; see above for description */
842 uint32_t write_block_size;
843 uint32_t erase_block_size;
844 uint32_t protect_block_size;
846 /* Version 1 adds these fields: */
848 * Ideal write size in bytes. Writes will be fastest if size is
849 * exactly this and offset is a multiple of this. For example, an EC
850 * may have a write buffer which can do half-page operations if data is
851 * aligned, and a slower word-at-a-time write mode.
853 uint32_t write_ideal_size;
855 /* Flags; see EC_FLASH_INFO_* */
862 * Response is params.size bytes of data.
864 #define EC_CMD_FLASH_READ 0x11
866 struct ec_params_flash_read {
867 uint32_t offset; /* Byte offset to read */
868 uint32_t size; /* Size to read in bytes */
872 #define EC_CMD_FLASH_WRITE 0x12
873 #define EC_VER_FLASH_WRITE 1
875 /* Version 0 of the flash command supported only 64 bytes of data */
876 #define EC_FLASH_WRITE_VER0_SIZE 64
878 struct ec_params_flash_write {
879 uint32_t offset; /* Byte offset to write */
880 uint32_t size; /* Size to write in bytes */
881 /* Followed by data to write */
885 #define EC_CMD_FLASH_ERASE 0x13
887 struct ec_params_flash_erase {
888 uint32_t offset; /* Byte offset to erase */
889 uint32_t size; /* Size to erase in bytes */
893 * Get/set flash protection.
895 * If mask!=0, sets/clear the requested bits of flags. Depending on the
896 * firmware write protect GPIO, not all flags will take effect immediately;
897 * some flags require a subsequent hard reset to take effect. Check the
898 * returned flags bits to see what actually happened.
900 * If mask=0, simply returns the current flags state.
902 #define EC_CMD_FLASH_PROTECT 0x15
903 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
905 /* Flags for flash protection */
906 /* RO flash code protected when the EC boots */
907 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
909 * RO flash code protected now. If this bit is set, at-boot status cannot
912 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
913 /* Entire flash code protected now, until reboot. */
914 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
915 /* Flash write protect GPIO is asserted now */
916 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
917 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
918 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
920 * Error - flash protection is in inconsistent state. At least one bank of
921 * flash which should be protected is not protected. Usually fixed by
922 * re-requesting the desired flags, or by a hard reset if that fails.
924 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
925 /* Entile flash code protected when the EC boots */
926 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
928 struct ec_params_flash_protect {
929 uint32_t mask; /* Bits in flags to apply */
930 uint32_t flags; /* New flags to apply */
933 struct ec_response_flash_protect {
934 /* Current value of flash protect flags */
937 * Flags which are valid on this platform. This allows the caller
938 * to distinguish between flags which aren't set vs. flags which can't
939 * be set on this platform.
941 uint32_t valid_flags;
942 /* Flags which can be changed given the current protection state */
943 uint32_t writable_flags;
947 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
948 * write protect. These commands may be reused with version > 0.
951 /* Get the region offset/size */
952 #define EC_CMD_FLASH_REGION_INFO 0x16
953 #define EC_VER_FLASH_REGION_INFO 1
955 enum ec_flash_region {
956 /* Region which holds read-only EC image */
957 EC_FLASH_REGION_RO = 0,
958 /* Region which holds rewritable EC image */
961 * Region which should be write-protected in the factory (a superset of
962 * EC_FLASH_REGION_RO)
964 EC_FLASH_REGION_WP_RO,
965 /* Number of regions */
966 EC_FLASH_REGION_COUNT,
969 struct ec_params_flash_region_info {
970 uint32_t region; /* enum ec_flash_region */
973 struct ec_response_flash_region_info {
978 /* Read/write VbNvContext */
979 #define EC_CMD_VBNV_CONTEXT 0x17
980 #define EC_VER_VBNV_CONTEXT 1
981 #define EC_VBNV_BLOCK_SIZE 16
983 enum ec_vbnvcontext_op {
984 EC_VBNV_CONTEXT_OP_READ,
985 EC_VBNV_CONTEXT_OP_WRITE,
988 struct ec_params_vbnvcontext {
990 uint8_t block[EC_VBNV_BLOCK_SIZE];
993 struct ec_response_vbnvcontext {
994 uint8_t block[EC_VBNV_BLOCK_SIZE];
997 /*****************************************************************************/
1000 /* Get fan target RPM */
1001 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1003 struct ec_response_pwm_get_fan_rpm {
1007 /* Set target fan RPM */
1008 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1010 struct ec_params_pwm_set_fan_target_rpm {
1014 /* Get keyboard backlight */
1015 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1017 struct ec_response_pwm_get_keyboard_backlight {
1022 /* Set keyboard backlight */
1023 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1025 struct ec_params_pwm_set_keyboard_backlight {
1029 /* Set target fan PWM duty cycle */
1030 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
1032 struct ec_params_pwm_set_fan_duty {
1036 #define EC_CMD_PWM_SET_DUTY 0x25
1037 /* 16 bit duty cycle, 0xffff = 100% */
1038 #define EC_PWM_MAX_DUTY 0xffff
1041 /* All types, indexed by board-specific enum pwm_channel */
1042 EC_PWM_TYPE_GENERIC = 0,
1043 /* Keyboard backlight */
1044 EC_PWM_TYPE_KB_LIGHT,
1045 /* Display backlight */
1046 EC_PWM_TYPE_DISPLAY_LIGHT,
1050 struct ec_params_pwm_set_duty {
1051 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1052 uint8_t pwm_type; /* ec_pwm_type */
1053 uint8_t index; /* Type-specific index, or 0 if unique */
1056 #define EC_CMD_PWM_GET_DUTY 0x26
1058 struct ec_params_pwm_get_duty {
1059 uint8_t pwm_type; /* ec_pwm_type */
1060 uint8_t index; /* Type-specific index, or 0 if unique */
1063 struct ec_response_pwm_get_duty {
1064 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1067 /*****************************************************************************/
1069 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1070 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1071 * into a subcommand. We'll make separate structs for subcommands with
1072 * different input args, so that we know how much to expect.
1074 #define EC_CMD_LIGHTBAR_CMD 0x28
1080 #define LB_BATTERY_LEVELS 4
1081 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1082 * host command, but the alignment is the same regardless. Keep it that way.
1084 struct lightbar_params_v0 {
1086 int32_t google_ramp_up;
1087 int32_t google_ramp_down;
1088 int32_t s3s0_ramp_up;
1089 int32_t s0_tick_delay[2]; /* AC=0/1 */
1090 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1091 int32_t s0s3_ramp_down;
1092 int32_t s3_sleep_for;
1094 int32_t s3_ramp_down;
1098 uint8_t osc_min[2]; /* AC=0/1 */
1099 uint8_t osc_max[2]; /* AC=0/1 */
1100 uint8_t w_ofs[2]; /* AC=0/1 */
1102 /* Brightness limits based on the backlight and AC. */
1103 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1104 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1105 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1107 /* Battery level thresholds */
1108 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1110 /* Map [AC][battery_level] to color index */
1111 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1112 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1115 struct rgb_s color[8]; /* 0-3 are Google colors */
1118 struct lightbar_params_v1 {
1120 int32_t google_ramp_up;
1121 int32_t google_ramp_down;
1122 int32_t s3s0_ramp_up;
1123 int32_t s0_tick_delay[2]; /* AC=0/1 */
1124 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1125 int32_t s0s3_ramp_down;
1126 int32_t s3_sleep_for;
1128 int32_t s3_ramp_down;
1129 int32_t tap_tick_delay;
1130 int32_t tap_display_time;
1132 /* Tap-for-battery params */
1133 uint8_t tap_pct_red;
1134 uint8_t tap_pct_green;
1135 uint8_t tap_seg_min_on;
1136 uint8_t tap_seg_max_on;
1137 uint8_t tap_seg_osc;
1141 uint8_t osc_min[2]; /* AC=0/1 */
1142 uint8_t osc_max[2]; /* AC=0/1 */
1143 uint8_t w_ofs[2]; /* AC=0/1 */
1145 /* Brightness limits based on the backlight and AC. */
1146 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1147 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1148 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1150 /* Battery level thresholds */
1151 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1153 /* Map [AC][battery_level] to color index */
1154 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1155 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1158 struct rgb_s color[8]; /* 0-3 are Google colors */
1161 struct ec_params_lightbar {
1162 uint8_t cmd; /* Command (see enum lightbar_command) */
1166 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1167 version, get_brightness, get_demo;
1171 } set_brightness, seq, demo;
1174 uint8_t ctrl, reg, value;
1178 uint8_t led, red, green, blue;
1185 struct lightbar_params_v0 set_params_v0;
1186 struct lightbar_params_v1 set_params_v1;
1190 struct ec_response_lightbar {
1202 } get_seq, get_brightness, get_demo;
1204 struct lightbar_params_v0 get_params_v0;
1205 struct lightbar_params_v1 get_params_v1;
1213 uint8_t red, green, blue;
1217 /* no return params */
1218 } off, on, init, set_brightness, seq, reg, set_rgb,
1219 demo, set_params_v0, set_params_v1;
1223 /* Lightbar commands */
1224 enum lightbar_command {
1225 LIGHTBAR_CMD_DUMP = 0,
1226 LIGHTBAR_CMD_OFF = 1,
1227 LIGHTBAR_CMD_ON = 2,
1228 LIGHTBAR_CMD_INIT = 3,
1229 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1230 LIGHTBAR_CMD_SEQ = 5,
1231 LIGHTBAR_CMD_REG = 6,
1232 LIGHTBAR_CMD_SET_RGB = 7,
1233 LIGHTBAR_CMD_GET_SEQ = 8,
1234 LIGHTBAR_CMD_DEMO = 9,
1235 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1236 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1237 LIGHTBAR_CMD_VERSION = 12,
1238 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1239 LIGHTBAR_CMD_GET_RGB = 14,
1240 LIGHTBAR_CMD_GET_DEMO = 15,
1241 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1242 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1246 /*****************************************************************************/
1247 /* LED control commands */
1249 #define EC_CMD_LED_CONTROL 0x29
1252 /* LED to indicate battery state of charge */
1253 EC_LED_ID_BATTERY_LED = 0,
1255 * LED to indicate system power state (on or in suspend).
1256 * May be on power button or on C-panel.
1258 EC_LED_ID_POWER_LED,
1259 /* LED on power adapter or its plug */
1260 EC_LED_ID_ADAPTER_LED,
1265 /* LED control flags */
1266 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1267 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1269 enum ec_led_colors {
1270 EC_LED_COLOR_RED = 0,
1273 EC_LED_COLOR_YELLOW,
1279 struct ec_params_led_control {
1280 uint8_t led_id; /* Which LED to control */
1281 uint8_t flags; /* Control flags */
1283 uint8_t brightness[EC_LED_COLOR_COUNT];
1286 struct ec_response_led_control {
1288 * Available brightness value range.
1290 * Range 0 means color channel not present.
1291 * Range 1 means on/off control.
1292 * Other values means the LED is control by PWM.
1294 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1297 /*****************************************************************************/
1298 /* Verified boot commands */
1301 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1302 * reused for other purposes with version > 0.
1305 /* Verified boot hash command */
1306 #define EC_CMD_VBOOT_HASH 0x2A
1308 struct ec_params_vboot_hash {
1309 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1310 uint8_t hash_type; /* enum ec_vboot_hash_type */
1311 uint8_t nonce_size; /* Nonce size; may be 0 */
1312 uint8_t reserved0; /* Reserved; set 0 */
1313 uint32_t offset; /* Offset in flash to hash */
1314 uint32_t size; /* Number of bytes to hash */
1315 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1318 struct ec_response_vboot_hash {
1319 uint8_t status; /* enum ec_vboot_hash_status */
1320 uint8_t hash_type; /* enum ec_vboot_hash_type */
1321 uint8_t digest_size; /* Size of hash digest in bytes */
1322 uint8_t reserved0; /* Ignore; will be 0 */
1323 uint32_t offset; /* Offset in flash which was hashed */
1324 uint32_t size; /* Number of bytes hashed */
1325 uint8_t hash_digest[64]; /* Hash digest data */
1328 enum ec_vboot_hash_cmd {
1329 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1330 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1331 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1332 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1335 enum ec_vboot_hash_type {
1336 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1339 enum ec_vboot_hash_status {
1340 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1341 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1342 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1346 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1347 * If one of these is specified, the EC will automatically update offset and
1348 * size to the correct values for the specified image (RO or RW).
1350 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1351 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1353 /*****************************************************************************/
1355 * Motion sense commands. We'll make separate structs for sub-commands with
1356 * different input args, so that we know how much to expect.
1358 #define EC_CMD_MOTION_SENSE_CMD 0x2B
1360 /* Motion sense commands */
1361 enum motionsense_command {
1363 * Dump command returns all motion sensor data including motion sense
1364 * module flags and individual sensor flags.
1366 MOTIONSENSE_CMD_DUMP = 0,
1369 * Info command returns data describing the details of a given sensor,
1370 * including enum motionsensor_type, enum motionsensor_location, and
1371 * enum motionsensor_chip.
1373 MOTIONSENSE_CMD_INFO = 1,
1376 * EC Rate command is a setter/getter command for the EC sampling rate
1377 * of all motion sensors in milliseconds.
1379 MOTIONSENSE_CMD_EC_RATE = 2,
1382 * Sensor ODR command is a setter/getter command for the output data
1383 * rate of a specific motion sensor in millihertz.
1385 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1388 * Sensor range command is a setter/getter command for the range of
1389 * a specified motion sensor in +/-G's or +/- deg/s.
1391 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1394 * Setter/getter command for the keyboard wake angle. When the lid
1395 * angle is greater than this value, keyboard wake is disabled in S3,
1396 * and when the lid angle goes less than this value, keyboard wake is
1397 * enabled. Note, the lid angle measurement is an approximate,
1398 * un-calibrated value, hence the wake angle isn't exact.
1400 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1403 * Returns a single sensor data.
1405 MOTIONSENSE_CMD_DATA = 6,
1408 * Perform low level calibration.. On sensors that support it, ask to
1409 * do offset calibration.
1411 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1414 * Sensor Offset command is a setter/getter command for the offset used
1415 * for calibration. The offsets can be calculated by the host, or via
1416 * PERFORM_CALIB command.
1418 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1420 /* Number of motionsense sub-commands. */
1421 MOTIONSENSE_NUM_CMDS
1424 enum motionsensor_id {
1425 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1426 EC_MOTION_SENSOR_ACCEL_LID = 1,
1427 EC_MOTION_SENSOR_GYRO = 2,
1430 * Note, if more sensors are added and this count changes, the padding
1431 * in ec_response_motion_sense dump command must be modified.
1433 EC_MOTION_SENSOR_COUNT = 3
1436 /* List of motion sensor types. */
1437 enum motionsensor_type {
1438 MOTIONSENSE_TYPE_ACCEL = 0,
1439 MOTIONSENSE_TYPE_GYRO = 1,
1440 MOTIONSENSE_TYPE_MAG = 2,
1441 MOTIONSENSE_TYPE_PROX = 3,
1442 MOTIONSENSE_TYPE_LIGHT = 4,
1443 MOTIONSENSE_TYPE_ACTIVITY = 5,
1444 MOTIONSENSE_TYPE_BARO = 6,
1445 MOTIONSENSE_TYPE_MAX,
1448 /* List of motion sensor locations. */
1449 enum motionsensor_location {
1450 MOTIONSENSE_LOC_BASE = 0,
1451 MOTIONSENSE_LOC_LID = 1,
1452 MOTIONSENSE_LOC_MAX,
1455 /* List of motion sensor chips. */
1456 enum motionsensor_chip {
1457 MOTIONSENSE_CHIP_KXCJ9 = 0,
1460 /* Module flag masks used for the dump sub-command. */
1461 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1463 /* Sensor flag masks used for the dump sub-command. */
1464 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1467 * Send this value for the data element to only perform a read. If you
1468 * send any other value, the EC will interpret it as data to set and will
1469 * return the actual value set.
1471 #define EC_MOTION_SENSE_NO_VALUE -1
1473 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1475 /* Set Calibration information */
1476 #define MOTION_SENSE_SET_OFFSET 1
1478 struct ec_response_motion_sensor_data {
1479 /* Flags for each sensor. */
1481 /* Sensor number the data comes from */
1483 /* Each sensor is up to 3-axis. */
1491 uint8_t activity; /* motionsensor_activity */
1493 int16_t add_info[2];
1498 struct ec_params_motion_sense {
1501 /* Used for MOTIONSENSE_CMD_DUMP. */
1507 * Used for MOTIONSENSE_CMD_EC_RATE and
1508 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1511 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1513 } ec_rate, kb_wake_angle;
1515 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1520 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1521 * the calibration information in the EC.
1522 * If unset, just retrieve calibration information.
1527 * Temperature at calibration, in units of 0.01 C
1528 * 0x8000: invalid / unknown.
1535 * Offset for calibration.
1537 * Accelerometer: 1/1024 g
1538 * Gyro: 1/1024 deg/s
1542 } __packed sensor_offset;
1544 /* Used for MOTIONSENSE_CMD_INFO. */
1550 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1551 * MOTIONSENSE_CMD_SENSOR_RANGE.
1554 /* Should be element of enum motionsensor_id. */
1557 /* Rounding flag, true for round-up, false for down. */
1562 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1564 } sensor_odr, sensor_range;
1568 struct ec_response_motion_sense {
1570 /* Used for MOTIONSENSE_CMD_DUMP. */
1572 /* Flags representing the motion sensor module. */
1573 uint8_t module_flags;
1575 /* Number of sensors managed directly by the EC. */
1576 uint8_t sensor_count;
1579 * Sensor data is truncated if response_max is too small
1580 * for holding all the data.
1582 struct ec_response_motion_sensor_data sensor[0];
1585 /* Used for MOTIONSENSE_CMD_INFO. */
1587 /* Should be element of enum motionsensor_type. */
1590 /* Should be element of enum motionsensor_location. */
1593 /* Should be element of enum motionsensor_chip. */
1597 /* Used for MOTIONSENSE_CMD_DATA */
1598 struct ec_response_motion_sensor_data data;
1601 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1602 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1603 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1606 /* Current value of the parameter queried. */
1608 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1610 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1614 } sensor_offset, perform_calib;
1618 /*****************************************************************************/
1619 /* USB charging control commands */
1621 /* Set USB port charging mode */
1622 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
1624 struct ec_params_usb_charge_set_mode {
1625 uint8_t usb_port_id;
1629 /*****************************************************************************/
1630 /* Persistent storage for host */
1632 /* Maximum bytes that can be read/written in a single command */
1633 #define EC_PSTORE_SIZE_MAX 64
1635 /* Get persistent storage info */
1636 #define EC_CMD_PSTORE_INFO 0x40
1638 struct ec_response_pstore_info {
1639 /* Persistent storage size, in bytes */
1640 uint32_t pstore_size;
1641 /* Access size; read/write offset and size must be a multiple of this */
1642 uint32_t access_size;
1646 * Read persistent storage
1648 * Response is params.size bytes of data.
1650 #define EC_CMD_PSTORE_READ 0x41
1652 struct ec_params_pstore_read {
1653 uint32_t offset; /* Byte offset to read */
1654 uint32_t size; /* Size to read in bytes */
1657 /* Write persistent storage */
1658 #define EC_CMD_PSTORE_WRITE 0x42
1660 struct ec_params_pstore_write {
1661 uint32_t offset; /* Byte offset to write */
1662 uint32_t size; /* Size to write in bytes */
1663 uint8_t data[EC_PSTORE_SIZE_MAX];
1666 /*****************************************************************************/
1667 /* Real-time clock */
1669 /* RTC params and response structures */
1670 struct ec_params_rtc {
1674 struct ec_response_rtc {
1678 /* These use ec_response_rtc */
1679 #define EC_CMD_RTC_GET_VALUE 0x44
1680 #define EC_CMD_RTC_GET_ALARM 0x45
1682 /* These all use ec_params_rtc */
1683 #define EC_CMD_RTC_SET_VALUE 0x46
1684 #define EC_CMD_RTC_SET_ALARM 0x47
1686 /*****************************************************************************/
1687 /* Port80 log access */
1689 /* Maximum entries that can be read/written in a single command */
1690 #define EC_PORT80_SIZE_MAX 32
1692 /* Get last port80 code from previous boot */
1693 #define EC_CMD_PORT80_LAST_BOOT 0x48
1694 #define EC_CMD_PORT80_READ 0x48
1696 enum ec_port80_subcmd {
1697 EC_PORT80_GET_INFO = 0,
1698 EC_PORT80_READ_BUFFER,
1701 struct ec_params_port80_read {
1706 uint32_t num_entries;
1711 struct ec_response_port80_read {
1715 uint32_t history_size;
1719 uint16_t codes[EC_PORT80_SIZE_MAX];
1724 struct ec_response_port80_last_boot {
1728 /*****************************************************************************/
1729 /* Thermal engine commands. Note that there are two implementations. We'll
1730 * reuse the command number, but the data and behavior is incompatible.
1731 * Version 0 is what originally shipped on Link.
1732 * Version 1 separates the CPU thermal limits from the fan control.
1735 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1736 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1738 /* The version 0 structs are opaque. You have to know what they are for
1739 * the get/set commands to make any sense.
1742 /* Version 0 - set */
1743 struct ec_params_thermal_set_threshold {
1744 uint8_t sensor_type;
1745 uint8_t threshold_id;
1749 /* Version 0 - get */
1750 struct ec_params_thermal_get_threshold {
1751 uint8_t sensor_type;
1752 uint8_t threshold_id;
1755 struct ec_response_thermal_get_threshold {
1760 /* The version 1 structs are visible. */
1761 enum ec_temp_thresholds {
1762 EC_TEMP_THRESH_WARN = 0,
1763 EC_TEMP_THRESH_HIGH,
1764 EC_TEMP_THRESH_HALT,
1766 EC_TEMP_THRESH_COUNT
1769 /* Thermal configuration for one temperature sensor. Temps are in degrees K.
1770 * Zero values will be silently ignored by the thermal task.
1772 struct ec_thermal_config {
1773 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1774 uint32_t temp_fan_off; /* no active cooling needed */
1775 uint32_t temp_fan_max; /* max active cooling needed */
1778 /* Version 1 - get config for one sensor. */
1779 struct ec_params_thermal_get_threshold_v1 {
1780 uint32_t sensor_num;
1782 /* This returns a struct ec_thermal_config */
1784 /* Version 1 - set config for one sensor.
1785 * Use read-modify-write for best results! */
1786 struct ec_params_thermal_set_threshold_v1 {
1787 uint32_t sensor_num;
1788 struct ec_thermal_config cfg;
1790 /* This returns no data */
1792 /****************************************************************************/
1794 /* Toggle automatic fan control */
1795 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1797 /* Get TMP006 calibration data */
1798 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
1800 struct ec_params_tmp006_get_calibration {
1804 struct ec_response_tmp006_get_calibration {
1811 /* Set TMP006 calibration data */
1812 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
1814 struct ec_params_tmp006_set_calibration {
1816 uint8_t reserved[3]; /* Reserved; set 0 */
1823 /* Read raw TMP006 data */
1824 #define EC_CMD_TMP006_GET_RAW 0x55
1826 struct ec_params_tmp006_get_raw {
1830 struct ec_response_tmp006_get_raw {
1831 int32_t t; /* In 1/100 K */
1832 int32_t v; /* In nV */
1835 /*****************************************************************************/
1836 /* MKBP - Matrix KeyBoard Protocol */
1841 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1842 * expected response size.
1844 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1845 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1846 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
1848 #define EC_CMD_MKBP_STATE 0x60
1851 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1853 #define EC_CMD_MKBP_INFO 0x61
1855 struct ec_response_mkbp_info {
1858 /* Formerly "switches", which was 0. */
1862 struct ec_params_mkbp_info {
1867 enum ec_mkbp_info_type {
1869 * Info about the keyboard matrix: number of rows and columns.
1871 * Returns struct ec_response_mkbp_info.
1873 EC_MKBP_INFO_KBD = 0,
1876 * For buttons and switches, info about which specifically are
1877 * supported. event_type must be set to one of the values in enum
1880 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
1881 * bitmask indicating which buttons or switches are present. See the
1882 * bit inidices below.
1884 EC_MKBP_INFO_SUPPORTED = 1,
1887 * Instantaneous state of buttons and switches.
1889 * event_type must be set to one of the values in enum ec_mkbp_event.
1891 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
1892 * indicating the current state of the keyboard matrix.
1894 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
1897 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
1898 * state of supported buttons.
1900 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
1901 * state of supported switches.
1903 EC_MKBP_INFO_CURRENT = 2,
1906 /* Simulate key press */
1907 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
1909 struct ec_params_mkbp_simulate_key {
1915 /* Configure keyboard scanning */
1916 #define EC_CMD_MKBP_SET_CONFIG 0x64
1917 #define EC_CMD_MKBP_GET_CONFIG 0x65
1920 enum mkbp_config_flags {
1921 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
1924 enum mkbp_config_valid {
1925 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
1926 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
1927 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
1928 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
1929 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
1930 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
1931 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
1934 /* Configuration for our key scanning algorithm */
1935 struct ec_mkbp_config {
1936 uint32_t valid_mask; /* valid fields */
1937 uint8_t flags; /* some flags (enum mkbp_config_flags) */
1938 uint8_t valid_flags; /* which flags are valid */
1939 uint16_t scan_period_us; /* period between start of scans */
1940 /* revert to interrupt mode after no activity for this long */
1941 uint32_t poll_timeout_us;
1943 * minimum post-scan relax time. Once we finish a scan we check
1944 * the time until we are due to start the next one. If this time is
1945 * shorter this field, we use this instead.
1947 uint16_t min_post_scan_delay_us;
1948 /* delay between setting up output and waiting for it to settle */
1949 uint16_t output_settle_us;
1950 uint16_t debounce_down_us; /* time for debounce on key down */
1951 uint16_t debounce_up_us; /* time for debounce on key up */
1952 /* maximum depth to allow for fifo (0 = no keyscan output) */
1953 uint8_t fifo_max_depth;
1956 struct ec_params_mkbp_set_config {
1957 struct ec_mkbp_config config;
1960 struct ec_response_mkbp_get_config {
1961 struct ec_mkbp_config config;
1964 /* Run the key scan emulation */
1965 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
1967 enum ec_keyscan_seq_cmd {
1968 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
1969 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
1970 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
1971 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
1972 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
1975 enum ec_collect_flags {
1977 * Indicates this scan was processed by the EC. Due to timing, some
1978 * scans may be skipped.
1980 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
1983 struct ec_collect_item {
1984 uint8_t flags; /* some flags (enum ec_collect_flags) */
1987 struct ec_params_keyscan_seq_ctrl {
1988 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
1991 uint8_t active; /* still active */
1992 uint8_t num_items; /* number of items */
1993 /* Current item being presented */
1998 * Absolute time for this scan, measured from the
1999 * start of the sequence.
2002 uint8_t scan[0]; /* keyscan data */
2005 uint8_t start_item; /* First item to return */
2006 uint8_t num_items; /* Number of items to return */
2011 struct ec_result_keyscan_seq_ctrl {
2014 uint8_t num_items; /* Number of items */
2015 /* Data for each item */
2016 struct ec_collect_item item[0];
2022 * Command for retrieving the next pending MKBP event from the EC device
2024 * The device replies with UNAVAILABLE if there aren't any pending events.
2026 #define EC_CMD_GET_NEXT_EVENT 0x67
2028 enum ec_mkbp_event {
2029 /* Keyboard matrix changed. The event data is the new matrix state. */
2030 EC_MKBP_EVENT_KEY_MATRIX = 0,
2032 /* New host event. The event data is 4 bytes of host event flags. */
2033 EC_MKBP_EVENT_HOST_EVENT = 1,
2035 /* New Sensor FIFO data. The event data is fifo_info structure. */
2036 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2038 /* The state of the non-matrixed buttons have changed. */
2039 EC_MKBP_EVENT_BUTTON = 3,
2041 /* The state of the switches have changed. */
2042 EC_MKBP_EVENT_SWITCH = 4,
2044 /* Number of MKBP events */
2045 EC_MKBP_EVENT_COUNT,
2048 union ec_response_get_next_data {
2049 uint8_t key_matrix[13];
2052 uint32_t host_event;
2058 struct ec_response_get_next_event {
2060 /* Followed by event data if any */
2061 union ec_response_get_next_data data;
2064 /* Bit indices for buttons and switches.*/
2066 #define EC_MKBP_POWER_BUTTON 0
2067 #define EC_MKBP_VOL_UP 1
2068 #define EC_MKBP_VOL_DOWN 2
2071 #define EC_MKBP_LID_OPEN 0
2072 #define EC_MKBP_TABLET_MODE 1
2074 /*****************************************************************************/
2075 /* Temperature sensor commands */
2077 /* Read temperature sensor info */
2078 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2080 struct ec_params_temp_sensor_get_info {
2084 struct ec_response_temp_sensor_get_info {
2085 char sensor_name[32];
2086 uint8_t sensor_type;
2089 /*****************************************************************************/
2092 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2093 * commands accidentally sent to the wrong interface. See the ACPI section
2097 /*****************************************************************************/
2098 /* Host event commands */
2101 * Host event mask params and response structures, shared by all of the host
2102 * event commands below.
2104 struct ec_params_host_event_mask {
2108 struct ec_response_host_event_mask {
2112 /* These all use ec_response_host_event_mask */
2113 #define EC_CMD_HOST_EVENT_GET_B 0x87
2114 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2115 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2116 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2118 /* These all use ec_params_host_event_mask */
2119 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2120 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2121 #define EC_CMD_HOST_EVENT_CLEAR 0x8c
2122 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2123 #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2125 /*****************************************************************************/
2126 /* Switch commands */
2128 /* Enable/disable LCD backlight */
2129 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2131 struct ec_params_switch_enable_backlight {
2135 /* Enable/disable WLAN/Bluetooth */
2136 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
2137 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2139 /* Version 0 params; no response */
2140 struct ec_params_switch_enable_wireless_v0 {
2144 /* Version 1 params */
2145 struct ec_params_switch_enable_wireless_v1 {
2146 /* Flags to enable now */
2149 /* Which flags to copy from now_flags */
2153 * Flags to leave enabled in S3, if they're on at the S0->S3
2154 * transition. (Other flags will be disabled by the S0->S3
2157 uint8_t suspend_flags;
2159 /* Which flags to copy from suspend_flags */
2160 uint8_t suspend_mask;
2163 /* Version 1 response */
2164 struct ec_response_switch_enable_wireless_v1 {
2165 /* Flags to enable now */
2168 /* Flags to leave enabled in S3 */
2169 uint8_t suspend_flags;
2172 /*****************************************************************************/
2173 /* GPIO commands. Only available on EC if write protect has been disabled. */
2175 /* Set GPIO output value */
2176 #define EC_CMD_GPIO_SET 0x92
2178 struct ec_params_gpio_set {
2183 /* Get GPIO value */
2184 #define EC_CMD_GPIO_GET 0x93
2186 /* Version 0 of input params and response */
2187 struct ec_params_gpio_get {
2190 struct ec_response_gpio_get {
2194 /* Version 1 of input params and response */
2195 struct ec_params_gpio_get_v1 {
2200 } get_value_by_name;
2207 struct ec_response_gpio_get_v1 {
2211 } get_value_by_name, get_count;
2220 enum gpio_get_subcmd {
2221 EC_GPIO_GET_BY_NAME = 0,
2222 EC_GPIO_GET_COUNT = 1,
2223 EC_GPIO_GET_INFO = 2,
2226 /*****************************************************************************/
2227 /* I2C commands. Only available when flash write protect is unlocked. */
2230 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2231 * removed soon. Use EC_CMD_I2C_XFER instead.
2235 #define EC_CMD_I2C_READ 0x94
2237 struct ec_params_i2c_read {
2238 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2239 uint8_t read_size; /* Either 8 or 16. */
2243 struct ec_response_i2c_read {
2248 #define EC_CMD_I2C_WRITE 0x95
2250 struct ec_params_i2c_write {
2252 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2253 uint8_t write_size; /* Either 8 or 16. */
2258 /*****************************************************************************/
2259 /* Charge state commands. Only available when flash write protect unlocked. */
2261 /* Force charge state machine to stop charging the battery or force it to
2262 * discharge the battery.
2264 #define EC_CMD_CHARGE_CONTROL 0x96
2265 #define EC_VER_CHARGE_CONTROL 1
2267 enum ec_charge_control_mode {
2268 CHARGE_CONTROL_NORMAL = 0,
2269 CHARGE_CONTROL_IDLE,
2270 CHARGE_CONTROL_DISCHARGE,
2273 struct ec_params_charge_control {
2274 uint32_t mode; /* enum charge_control_mode */
2277 /*****************************************************************************/
2278 /* Console commands. Only available when flash write protect is unlocked. */
2280 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2281 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
2284 * Read next chunk of data from saved snapshot.
2286 * Response is null-terminated string. Empty string, if there is no more
2289 #define EC_CMD_CONSOLE_READ 0x98
2291 /*****************************************************************************/
2294 * Cut off battery power immediately or after the host has shut down.
2296 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2297 * EC_RES_SUCCESS if the command was successful.
2298 * EC_RES_ERROR if the cut off command failed.
2301 #define EC_CMD_BATTERY_CUT_OFF 0x99
2303 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2305 struct ec_params_battery_cutoff {
2309 /*****************************************************************************/
2310 /* USB port mux control. */
2313 * Switch USB mux or return to automatic switching.
2315 #define EC_CMD_USB_MUX 0x9a
2317 struct ec_params_usb_mux {
2321 /*****************************************************************************/
2322 /* LDOs / FETs control. */
2325 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2326 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2330 * Switch on/off a LDO.
2332 #define EC_CMD_LDO_SET 0x9b
2334 struct ec_params_ldo_set {
2342 #define EC_CMD_LDO_GET 0x9c
2344 struct ec_params_ldo_get {
2348 struct ec_response_ldo_get {
2352 /*****************************************************************************/
2358 #define EC_CMD_POWER_INFO 0x9d
2360 struct ec_response_power_info {
2361 uint32_t usb_dev_type;
2362 uint16_t voltage_ac;
2363 uint16_t voltage_system;
2364 uint16_t current_system;
2365 uint16_t usb_current_limit;
2368 /*****************************************************************************/
2369 /* I2C passthru command */
2371 #define EC_CMD_I2C_PASSTHRU 0x9e
2373 /* Read data; if not present, message is a write */
2374 #define EC_I2C_FLAG_READ (1 << 15)
2376 /* Mask for address */
2377 #define EC_I2C_ADDR_MASK 0x3ff
2379 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2380 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2383 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2385 struct ec_params_i2c_passthru_msg {
2386 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2387 uint16_t len; /* Number of bytes to read or write */
2390 struct ec_params_i2c_passthru {
2391 uint8_t port; /* I2C port number */
2392 uint8_t num_msgs; /* Number of messages */
2393 struct ec_params_i2c_passthru_msg msg[];
2394 /* Data to write for all messages is concatenated here */
2397 struct ec_response_i2c_passthru {
2398 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2399 uint8_t num_msgs; /* Number of messages processed */
2400 uint8_t data[]; /* Data read by messages concatenated here */
2403 /*****************************************************************************/
2404 /* Power button hang detect */
2406 #define EC_CMD_HANG_DETECT 0x9f
2408 /* Reasons to start hang detection timer */
2409 /* Power button pressed */
2410 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2413 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2416 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2418 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2419 #define EC_HANG_START_ON_RESUME (1 << 3)
2421 /* Reasons to cancel hang detection */
2423 /* Power button released */
2424 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2426 /* Any host command from AP received */
2427 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2429 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2430 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2433 * If this flag is set, all the other fields are ignored, and the hang detect
2434 * timer is started. This provides the AP a way to start the hang timer
2435 * without reconfiguring any of the other hang detect settings. Note that
2436 * you must previously have configured the timeouts.
2438 #define EC_HANG_START_NOW (1 << 30)
2441 * If this flag is set, all the other fields are ignored (including
2442 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2443 * without reconfiguring any of the other hang detect settings.
2445 #define EC_HANG_STOP_NOW (1 << 31)
2447 struct ec_params_hang_detect {
2448 /* Flags; see EC_HANG_* */
2451 /* Timeout in msec before generating host event, if enabled */
2452 uint16_t host_event_timeout_msec;
2454 /* Timeout in msec before generating warm reboot, if enabled */
2455 uint16_t warm_reboot_timeout_msec;
2458 /*****************************************************************************/
2459 /* Commands for battery charging */
2462 * This is the single catch-all host command to exchange data regarding the
2463 * charge state machine (v2 and up).
2465 #define EC_CMD_CHARGE_STATE 0xa0
2467 /* Subcommands for this host command */
2468 enum charge_state_command {
2469 CHARGE_STATE_CMD_GET_STATE,
2470 CHARGE_STATE_CMD_GET_PARAM,
2471 CHARGE_STATE_CMD_SET_PARAM,
2472 CHARGE_STATE_NUM_CMDS
2476 * Known param numbers are defined here. Ranges are reserved for board-specific
2477 * params, which are handled by the particular implementations.
2479 enum charge_state_params {
2480 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2481 CS_PARAM_CHG_CURRENT, /* charger current limit */
2482 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2483 CS_PARAM_CHG_STATUS, /* charger-specific status */
2484 CS_PARAM_CHG_OPTION, /* charger-specific options */
2485 /* How many so far? */
2488 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2489 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2490 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2492 /* Other custom param ranges go here... */
2495 struct ec_params_charge_state {
2496 uint8_t cmd; /* enum charge_state_command */
2503 uint32_t param; /* enum charge_state_param */
2507 uint32_t param; /* param to set */
2508 uint32_t value; /* value to set */
2513 struct ec_response_charge_state {
2519 int chg_input_current;
2520 int batt_state_of_charge;
2527 /* no return values */
2534 * Set maximum battery charging current.
2536 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2538 struct ec_params_current_limit {
2539 uint32_t limit; /* in mA */
2543 * Set maximum external power current.
2545 #define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2547 struct ec_params_ext_power_current_limit {
2548 uint32_t limit; /* in mA */
2551 /* Inform the EC when entering a sleep state */
2552 #define EC_CMD_HOST_SLEEP_EVENT 0xa9
2554 enum host_sleep_event {
2555 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2556 HOST_SLEEP_EVENT_S3_RESUME = 2,
2557 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2558 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2561 struct ec_params_host_sleep_event {
2562 uint8_t sleep_event;
2565 /*****************************************************************************/
2566 /* Smart battery pass-through */
2568 /* Get / Set 16-bit smart battery registers */
2569 #define EC_CMD_SB_READ_WORD 0xb0
2570 #define EC_CMD_SB_WRITE_WORD 0xb1
2572 /* Get / Set string smart battery parameters
2573 * formatted as SMBUS "block".
2575 #define EC_CMD_SB_READ_BLOCK 0xb2
2576 #define EC_CMD_SB_WRITE_BLOCK 0xb3
2578 struct ec_params_sb_rd {
2582 struct ec_response_sb_rd_word {
2586 struct ec_params_sb_wr_word {
2591 struct ec_response_sb_rd_block {
2595 struct ec_params_sb_wr_block {
2600 /*****************************************************************************/
2601 /* Battery vendor parameters
2603 * Get or set vendor-specific parameters in the battery. Implementations may
2604 * differ between boards or batteries. On a set operation, the response
2605 * contains the actual value set, which may be rounded or clipped from the
2609 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2611 enum ec_battery_vendor_param_mode {
2612 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2613 BATTERY_VENDOR_PARAM_MODE_SET,
2616 struct ec_params_battery_vendor_param {
2622 struct ec_response_battery_vendor_param {
2626 /*****************************************************************************/
2627 /* System commands */
2630 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2631 * necessarily reboot the EC. Rename to "image" or something similar?
2633 #define EC_CMD_REBOOT_EC 0xd2
2636 enum ec_reboot_cmd {
2637 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2638 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2639 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2640 /* (command 3 was jump to RW-B) */
2641 EC_REBOOT_COLD = 4, /* Cold-reboot */
2642 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2643 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2646 /* Flags for ec_params_reboot_ec.reboot_flags */
2647 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2648 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2650 struct ec_params_reboot_ec {
2651 uint8_t cmd; /* enum ec_reboot_cmd */
2652 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2656 * Get information on last EC panic.
2658 * Returns variable-length platform-dependent panic information. See panic.h
2661 #define EC_CMD_GET_PANIC_INFO 0xd3
2663 /*****************************************************************************/
2667 * These are valid ONLY on the ACPI command/data port.
2671 * ACPI Read Embedded Controller
2673 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2675 * Use the following sequence:
2677 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
2678 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2679 * - Write address to EC_LPC_ADDR_ACPI_DATA
2680 * - Wait for EC_LPC_CMDR_DATA bit to set
2681 * - Read value from EC_LPC_ADDR_ACPI_DATA
2683 #define EC_CMD_ACPI_READ 0x80
2686 * ACPI Write Embedded Controller
2688 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2690 * Use the following sequence:
2692 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
2693 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2694 * - Write address to EC_LPC_ADDR_ACPI_DATA
2695 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2696 * - Write value to EC_LPC_ADDR_ACPI_DATA
2698 #define EC_CMD_ACPI_WRITE 0x81
2701 * ACPI Query Embedded Controller
2703 * This clears the lowest-order bit in the currently pending host events, and
2704 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
2705 * event 0x80000000 = 32), or 0 if no event was pending.
2707 #define EC_CMD_ACPI_QUERY_EVENT 0x84
2709 /* Valid addresses in ACPI memory space, for read/write commands */
2711 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
2712 #define EC_ACPI_MEM_VERSION 0x00
2714 * Test location; writing value here updates test compliment byte to (0xff -
2717 #define EC_ACPI_MEM_TEST 0x01
2718 /* Test compliment; writes here are ignored. */
2719 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
2721 /* Keyboard backlight brightness percent (0 - 100) */
2722 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
2723 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
2724 #define EC_ACPI_MEM_FAN_DUTY 0x04
2727 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
2728 * independent thresholds attached to them. The current value of the ID
2729 * register determines which sensor is affected by the THRESHOLD and COMMIT
2730 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
2731 * as the memory-mapped sensors. The COMMIT register applies those settings.
2733 * The spec does not mandate any way to read back the threshold settings
2734 * themselves, but when a threshold is crossed the AP needs a way to determine
2735 * which sensor(s) are responsible. Each reading of the ID register clears and
2736 * returns one sensor ID that has crossed one of its threshold (in either
2737 * direction) since the last read. A value of 0xFF means "no new thresholds
2738 * have tripped". Setting or enabling the thresholds for a sensor will clear
2739 * the unread event count for that sensor.
2741 #define EC_ACPI_MEM_TEMP_ID 0x05
2742 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
2743 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
2745 * Here are the bits for the COMMIT register:
2746 * bit 0 selects the threshold index for the chosen sensor (0/1)
2747 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
2748 * Each write to the commit register affects one threshold.
2750 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
2751 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
2755 * Set the thresholds for sensor 2 to 50 C and 60 C:
2756 * write 2 to [0x05] -- select temp sensor 2
2757 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
2758 * write 0x2 to [0x07] -- enable threshold 0 with this value
2759 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
2760 * write 0x3 to [0x07] -- enable threshold 1 with this value
2762 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
2763 * write 2 to [0x05] -- select temp sensor 2
2764 * write 0x1 to [0x07] -- disable threshold 1
2767 /* DPTF battery charging current limit */
2768 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
2770 /* Charging limit is specified in 64 mA steps */
2771 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
2772 /* Value to disable DPTF battery charging limit */
2773 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
2775 /* Current version of ACPI memory address space */
2776 #define EC_ACPI_MEM_VERSION_CURRENT 1
2779 /*****************************************************************************/
2783 * These do not follow the normal rules for commands. See each command for
2790 * This command will work even when the EC LPC interface is busy, because the
2791 * reboot command is processed at interrupt level. Note that when the EC
2792 * reboots, the host will reboot too, so there is no response to this command.
2794 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
2796 #define EC_CMD_REBOOT 0xd1 /* Think "die" */
2799 * Resend last response (not supported on LPC).
2801 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
2802 * there was no previous command, or the previous command's response was too
2805 #define EC_CMD_RESEND_RESPONSE 0xdb
2808 * This header byte on a command indicate version 0. Any header byte less
2809 * than this means that we are talking to an old EC which doesn't support
2810 * versioning. In that case, we assume version 0.
2812 * Header bytes greater than this indicate a later version. For example,
2813 * EC_CMD_VERSION0 + 1 means we are using version 1.
2815 * The old EC interface must not use commands 0xdc or higher.
2817 #define EC_CMD_VERSION0 0xdc
2819 #endif /* !__ACPI__ */
2821 /*****************************************************************************/
2825 * These commands are for PD MCU communication.
2828 /* EC to PD MCU exchange status command */
2829 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
2831 /* Status of EC being sent to PD */
2832 struct ec_params_pd_status {
2833 int8_t batt_soc; /* battery state of charge */
2836 /* Status of PD being sent back to EC */
2837 struct ec_response_pd_status {
2838 int8_t status; /* PD MCU status */
2839 uint32_t curr_lim_ma; /* input current limit */
2842 /* Set USB type-C port role and muxes */
2843 #define EC_CMD_USB_PD_CONTROL 0x101
2845 enum usb_pd_control_role {
2846 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
2847 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
2848 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
2849 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
2850 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
2853 enum usb_pd_control_mux {
2854 USB_PD_CTRL_MUX_NO_CHANGE = 0,
2855 USB_PD_CTRL_MUX_NONE = 1,
2856 USB_PD_CTRL_MUX_USB = 2,
2857 USB_PD_CTRL_MUX_DP = 3,
2858 USB_PD_CTRL_MUX_DOCK = 4,
2859 USB_PD_CTRL_MUX_AUTO = 5,
2862 struct ec_params_usb_pd_control {
2868 /*****************************************************************************/
2872 * Some platforms have sub-processors chained to each other. For example.
2874 * AP <--> EC <--> PD MCU
2876 * The top 2 bits of the command number are used to indicate which device the
2877 * command is intended for. Device 0 is always the device receiving the
2878 * command; other device mapping is board-specific.
2880 * When a device receives a command to be passed to a sub-processor, it passes
2881 * it on with the device number set back to 0. This allows the sub-processor
2882 * to remain blissfully unaware of whether the command originated on the next
2883 * device up the chain, or was passed through from the AP.
2885 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
2886 * AP sends command 0x4002 to the EC
2887 * EC sends command 0x0002 to the PD MCU
2888 * EC forwards PD MCU response back to the AP
2891 /* Offset and max command number for sub-device n */
2892 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
2893 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
2895 /*****************************************************************************/
2897 * Deprecated constants. These constants have been renamed for clarity. The
2898 * meaning and size has not changed. Programs that use the old names should
2899 * switch to the new names soon, as the old names may not be carried forward
2902 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
2903 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
2904 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
2906 #endif /* __CROS_EC_COMMANDS_H */