unify {de,}mangle_poll(), get rid of kernel-side POLL...
[cris-mirror.git] / include / linux / mfd / cros_ec_commands.h
blob2b96e630e3b69fa42a574b75887a899d767e19f2
1 /*
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
31 * depends on it.
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 )*/
107 /* Unused 0x91 */
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.
190 #ifndef __ACPI__
193 * Define __packed if someone hasn't beat us to it. Linux kernel style
194 * checking prefers __packed over __attribute__((packed)).
196 #ifndef __packed
197 #define __packed __attribute__((packed))
198 #endif
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
215 /* (reserved) */
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 */
226 enum ec_status {
227 EC_RES_SUCCESS = 0,
228 EC_RES_INVALID_COMMAND = 1,
229 EC_RES_ERROR = 2,
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,
288 /* PD MCU triggering host event */
289 EC_HOST_EVENT_PD_MCU = 22,
291 /* EC desires to change state of host-controlled USB mux */
292 EC_HOST_EVENT_USB_MUX = 28,
294 /* EC RTC event occurred */
295 EC_HOST_EVENT_RTC = 26,
298 * The high bit of the event mask is not used as a host event code. If
299 * it reads back as set, then the entire event mask should be
300 * considered invalid by the host. This can happen when reading the
301 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
302 * not initialized on the EC, or improperly configured on the host.
304 EC_HOST_EVENT_INVALID = 32
306 /* Host event mask */
307 #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
309 /* Arguments at EC_LPC_ADDR_HOST_ARGS */
310 struct ec_lpc_host_args {
311 uint8_t flags;
312 uint8_t command_version;
313 uint8_t data_size;
315 * Checksum; sum of command + flags + command_version + data_size +
316 * all params/response data bytes.
318 uint8_t checksum;
319 } __packed;
321 /* Flags for ec_lpc_host_args.flags */
323 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
324 * params.
326 * If EC gets a command and this flag is not set, this is an old-style command.
327 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
328 * unknown length. EC must respond with an old-style response (that is,
329 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
331 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
333 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
335 * If EC responds to a command and this flag is not set, this is an old-style
336 * response. Command version is 0 and response data from EC is at
337 * EC_LPC_ADDR_OLD_PARAM with unknown length.
339 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
341 /*****************************************************************************/
343 * Byte codes returned by EC over SPI interface.
345 * These can be used by the AP to debug the EC interface, and to determine
346 * when the EC is not in a state where it will ever get around to responding
347 * to the AP.
349 * Example of sequence of bytes read from EC for a current good transfer:
350 * 1. - - AP asserts chip select (CS#)
351 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
352 * 3. - - EC starts handling CS# interrupt
353 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
354 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
355 * bytes looking for EC_SPI_FRAME_START
356 * 6. - - EC finishes processing and sets up response
357 * 7. EC_SPI_FRAME_START - AP reads frame byte
358 * 8. (response packet) - AP reads response packet
359 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
360 * 10 - - AP deasserts chip select
361 * 11 - - EC processes CS# interrupt and sets up DMA for
362 * next request
364 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
365 * the following byte values:
366 * EC_SPI_OLD_READY
367 * EC_SPI_RX_READY
368 * EC_SPI_RECEIVING
369 * EC_SPI_PROCESSING
371 * Then the EC found an error in the request, or was not ready for the request
372 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
373 * because the EC is unable to tell when the AP is done sending its request.
377 * Framing byte which precedes a response packet from the EC. After sending a
378 * request, the AP will clock in bytes until it sees the framing byte, then
379 * clock in the response packet.
381 #define EC_SPI_FRAME_START 0xec
384 * Padding bytes which are clocked out after the end of a response packet.
386 #define EC_SPI_PAST_END 0xed
389 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
390 * that the AP will send a valid packet header (starting with
391 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
393 #define EC_SPI_RX_READY 0xf8
396 * EC has started receiving the request from the AP, but hasn't started
397 * processing it yet.
399 #define EC_SPI_RECEIVING 0xf9
401 /* EC has received the entire request from the AP and is processing it. */
402 #define EC_SPI_PROCESSING 0xfa
405 * EC received bad data from the AP, such as a packet header with an invalid
406 * length. EC will ignore all data until chip select deasserts.
408 #define EC_SPI_RX_BAD_DATA 0xfb
411 * EC received data from the AP before it was ready. That is, the AP asserted
412 * chip select and started clocking data before the EC was ready to receive it.
413 * EC will ignore all data until chip select deasserts.
415 #define EC_SPI_NOT_READY 0xfc
418 * EC was ready to receive a request from the AP. EC has treated the byte sent
419 * by the AP as part of a request packet, or (for old-style ECs) is processing
420 * a fully received packet but is not ready to respond yet.
422 #define EC_SPI_OLD_READY 0xfd
424 /*****************************************************************************/
427 * Protocol version 2 for I2C and SPI send a request this way:
429 * 0 EC_CMD_VERSION0 + (command version)
430 * 1 Command number
431 * 2 Length of params = N
432 * 3..N+2 Params, if any
433 * N+3 8-bit checksum of bytes 0..N+2
435 * The corresponding response is:
437 * 0 Result code (EC_RES_*)
438 * 1 Length of params = M
439 * 2..M+1 Params, if any
440 * M+2 8-bit checksum of bytes 0..M+1
442 #define EC_PROTO2_REQUEST_HEADER_BYTES 3
443 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
444 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
445 EC_PROTO2_REQUEST_TRAILER_BYTES)
447 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
448 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
449 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
450 EC_PROTO2_RESPONSE_TRAILER_BYTES)
452 /* Parameter length was limited by the LPC interface */
453 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
455 /* Maximum request and response packet sizes for protocol version 2 */
456 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
457 EC_PROTO2_MAX_PARAM_SIZE)
458 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
459 EC_PROTO2_MAX_PARAM_SIZE)
461 /*****************************************************************************/
464 * Value written to legacy command port / prefix byte to indicate protocol
465 * 3+ structs are being used. Usage is bus-dependent.
467 #define EC_COMMAND_PROTOCOL_3 0xda
469 #define EC_HOST_REQUEST_VERSION 3
471 /* Version 3 request from host */
472 struct ec_host_request {
473 /* Struct version (=3)
475 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
476 * version it doesn't know how to parse.
478 uint8_t struct_version;
481 * Checksum of request and data; sum of all bytes including checksum
482 * should total to 0.
484 uint8_t checksum;
486 /* Command code */
487 uint16_t command;
489 /* Command version */
490 uint8_t command_version;
492 /* Unused byte in current protocol version; set to 0 */
493 uint8_t reserved;
495 /* Length of data which follows this header */
496 uint16_t data_len;
497 } __packed;
499 #define EC_HOST_RESPONSE_VERSION 3
501 /* Version 3 response from EC */
502 struct ec_host_response {
503 /* Struct version (=3) */
504 uint8_t struct_version;
507 * Checksum of response and data; sum of all bytes including checksum
508 * should total to 0.
510 uint8_t checksum;
512 /* Result code (EC_RES_*) */
513 uint16_t result;
515 /* Length of data which follows this header */
516 uint16_t data_len;
518 /* Unused bytes in current protocol version; set to 0 */
519 uint16_t reserved;
520 } __packed;
522 /*****************************************************************************/
524 * Notes on commands:
526 * Each command is an 16-bit command value. Commands which take params or
527 * return response data specify structs for that data. If no struct is
528 * specified, the command does not input or output data, respectively.
529 * Parameter/response length is implicit in the structs. Some underlying
530 * communication protocols (I2C, SPI) may add length or checksum headers, but
531 * those are implementation-dependent and not defined here.
534 /*****************************************************************************/
535 /* General / test commands */
538 * Get protocol version, used to deal with non-backward compatible protocol
539 * changes.
541 #define EC_CMD_PROTO_VERSION 0x00
543 struct ec_response_proto_version {
544 uint32_t version;
545 } __packed;
548 * Hello. This is a simple command to test the EC is responsive to
549 * commands.
551 #define EC_CMD_HELLO 0x01
553 struct ec_params_hello {
554 uint32_t in_data; /* Pass anything here */
555 } __packed;
557 struct ec_response_hello {
558 uint32_t out_data; /* Output will be in_data + 0x01020304 */
559 } __packed;
561 /* Get version number */
562 #define EC_CMD_GET_VERSION 0x02
564 enum ec_current_image {
565 EC_IMAGE_UNKNOWN = 0,
566 EC_IMAGE_RO,
567 EC_IMAGE_RW
570 struct ec_response_get_version {
571 /* Null-terminated version strings for RO, RW */
572 char version_string_ro[32];
573 char version_string_rw[32];
574 char reserved[32]; /* Was previously RW-B string */
575 uint32_t current_image; /* One of ec_current_image */
576 } __packed;
578 /* Read test */
579 #define EC_CMD_READ_TEST 0x03
581 struct ec_params_read_test {
582 uint32_t offset; /* Starting value for read buffer */
583 uint32_t size; /* Size to read in bytes */
584 } __packed;
586 struct ec_response_read_test {
587 uint32_t data[32];
588 } __packed;
591 * Get build information
593 * Response is null-terminated string.
595 #define EC_CMD_GET_BUILD_INFO 0x04
597 /* Get chip info */
598 #define EC_CMD_GET_CHIP_INFO 0x05
600 struct ec_response_get_chip_info {
601 /* Null-terminated strings */
602 char vendor[32];
603 char name[32];
604 char revision[32]; /* Mask version */
605 } __packed;
607 /* Get board HW version */
608 #define EC_CMD_GET_BOARD_VERSION 0x06
610 struct ec_response_board_version {
611 uint16_t board_version; /* A monotonously incrementing number. */
612 } __packed;
615 * Read memory-mapped data.
617 * This is an alternate interface to memory-mapped data for bus protocols
618 * which don't support direct-mapped memory - I2C, SPI, etc.
620 * Response is params.size bytes of data.
622 #define EC_CMD_READ_MEMMAP 0x07
624 struct ec_params_read_memmap {
625 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
626 uint8_t size; /* Size to read in bytes */
627 } __packed;
629 /* Read versions supported for a command */
630 #define EC_CMD_GET_CMD_VERSIONS 0x08
632 struct ec_params_get_cmd_versions {
633 uint8_t cmd; /* Command to check */
634 } __packed;
636 struct ec_params_get_cmd_versions_v1 {
637 uint16_t cmd; /* Command to check */
638 } __packed;
640 struct ec_response_get_cmd_versions {
642 * Mask of supported versions; use EC_VER_MASK() to compare with a
643 * desired version.
645 uint32_t version_mask;
646 } __packed;
649 * Check EC communcations status (busy). This is needed on i2c/spi but not
650 * on lpc since it has its own out-of-band busy indicator.
652 * lpc must read the status from the command register. Attempting this on
653 * lpc will overwrite the args/parameter space and corrupt its data.
655 #define EC_CMD_GET_COMMS_STATUS 0x09
657 /* Avoid using ec_status which is for return values */
658 enum ec_comms_status {
659 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
662 struct ec_response_get_comms_status {
663 uint32_t flags; /* Mask of enum ec_comms_status */
664 } __packed;
666 /* Fake a variety of responses, purely for testing purposes. */
667 #define EC_CMD_TEST_PROTOCOL 0x0a
669 /* Tell the EC what to send back to us. */
670 struct ec_params_test_protocol {
671 uint32_t ec_result;
672 uint32_t ret_len;
673 uint8_t buf[32];
674 } __packed;
676 /* Here it comes... */
677 struct ec_response_test_protocol {
678 uint8_t buf[32];
679 } __packed;
681 /* Get prococol information */
682 #define EC_CMD_GET_PROTOCOL_INFO 0x0b
684 /* Flags for ec_response_get_protocol_info.flags */
685 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
686 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
688 struct ec_response_get_protocol_info {
689 /* Fields which exist if at least protocol version 3 supported */
691 /* Bitmask of protocol versions supported (1 << n means version n)*/
692 uint32_t protocol_versions;
694 /* Maximum request packet size, in bytes */
695 uint16_t max_request_packet_size;
697 /* Maximum response packet size, in bytes */
698 uint16_t max_response_packet_size;
700 /* Flags; see EC_PROTOCOL_INFO_* */
701 uint32_t flags;
702 } __packed;
705 /*****************************************************************************/
706 /* Get/Set miscellaneous values */
708 /* The upper byte of .flags tells what to do (nothing means "get") */
709 #define EC_GSV_SET 0x80000000
711 /* The lower three bytes of .flags identifies the parameter, if that has
712 meaning for an individual command. */
713 #define EC_GSV_PARAM_MASK 0x00ffffff
715 struct ec_params_get_set_value {
716 uint32_t flags;
717 uint32_t value;
718 } __packed;
720 struct ec_response_get_set_value {
721 uint32_t flags;
722 uint32_t value;
723 } __packed;
725 /* More than one command can use these structs to get/set paramters. */
726 #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
728 /*****************************************************************************/
729 /* List the features supported by the firmware */
730 #define EC_CMD_GET_FEATURES 0x0d
732 /* Supported features */
733 enum ec_feature_code {
735 * This image contains a limited set of features. Another image
736 * in RW partition may support more features.
738 EC_FEATURE_LIMITED = 0,
740 * Commands for probing/reading/writing/erasing the flash in the
741 * EC are present.
743 EC_FEATURE_FLASH = 1,
745 * Can control the fan speed directly.
747 EC_FEATURE_PWM_FAN = 2,
749 * Can control the intensity of the keyboard backlight.
751 EC_FEATURE_PWM_KEYB = 3,
753 * Support Google lightbar, introduced on Pixel.
755 EC_FEATURE_LIGHTBAR = 4,
756 /* Control of LEDs */
757 EC_FEATURE_LED = 5,
758 /* Exposes an interface to control gyro and sensors.
759 * The host goes through the EC to access these sensors.
760 * In addition, the EC may provide composite sensors, like lid angle.
762 EC_FEATURE_MOTION_SENSE = 6,
763 /* The keyboard is controlled by the EC */
764 EC_FEATURE_KEYB = 7,
765 /* The AP can use part of the EC flash as persistent storage. */
766 EC_FEATURE_PSTORE = 8,
767 /* The EC monitors BIOS port 80h, and can return POST codes. */
768 EC_FEATURE_PORT80 = 9,
770 * Thermal management: include TMP specific commands.
771 * Higher level than direct fan control.
773 EC_FEATURE_THERMAL = 10,
774 /* Can switch the screen backlight on/off */
775 EC_FEATURE_BKLIGHT_SWITCH = 11,
776 /* Can switch the wifi module on/off */
777 EC_FEATURE_WIFI_SWITCH = 12,
778 /* Monitor host events, through for example SMI or SCI */
779 EC_FEATURE_HOST_EVENTS = 13,
780 /* The EC exposes GPIO commands to control/monitor connected devices. */
781 EC_FEATURE_GPIO = 14,
782 /* The EC can send i2c messages to downstream devices. */
783 EC_FEATURE_I2C = 15,
784 /* Command to control charger are included */
785 EC_FEATURE_CHARGER = 16,
786 /* Simple battery support. */
787 EC_FEATURE_BATTERY = 17,
789 * Support Smart battery protocol
790 * (Common Smart Battery System Interface Specification)
792 EC_FEATURE_SMART_BATTERY = 18,
793 /* EC can dectect when the host hangs. */
794 EC_FEATURE_HANG_DETECT = 19,
795 /* Report power information, for pit only */
796 EC_FEATURE_PMU = 20,
797 /* Another Cros EC device is present downstream of this one */
798 EC_FEATURE_SUB_MCU = 21,
799 /* Support USB Power delivery (PD) commands */
800 EC_FEATURE_USB_PD = 22,
801 /* Control USB multiplexer, for audio through USB port for instance. */
802 EC_FEATURE_USB_MUX = 23,
803 /* Motion Sensor code has an internal software FIFO */
804 EC_FEATURE_MOTION_SENSE_FIFO = 24,
805 /* EC has RTC feature that can be controlled by host commands */
806 EC_FEATURE_RTC = 27,
809 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
810 #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
811 struct ec_response_get_features {
812 uint32_t flags[2];
813 } __packed;
815 /*****************************************************************************/
816 /* Flash commands */
818 /* Get flash info */
819 #define EC_CMD_FLASH_INFO 0x10
821 /* Version 0 returns these fields */
822 struct ec_response_flash_info {
823 /* Usable flash size, in bytes */
824 uint32_t flash_size;
826 * Write block size. Write offset and size must be a multiple
827 * of this.
829 uint32_t write_block_size;
831 * Erase block size. Erase offset and size must be a multiple
832 * of this.
834 uint32_t erase_block_size;
836 * Protection block size. Protection offset and size must be a
837 * multiple of this.
839 uint32_t protect_block_size;
840 } __packed;
842 /* Flags for version 1+ flash info command */
843 /* EC flash erases bits to 0 instead of 1 */
844 #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
847 * Version 1 returns the same initial fields as version 0, with additional
848 * fields following.
850 * gcc anonymous structs don't seem to get along with the __packed directive;
851 * if they did we'd define the version 0 struct as a sub-struct of this one.
853 struct ec_response_flash_info_1 {
854 /* Version 0 fields; see above for description */
855 uint32_t flash_size;
856 uint32_t write_block_size;
857 uint32_t erase_block_size;
858 uint32_t protect_block_size;
860 /* Version 1 adds these fields: */
862 * Ideal write size in bytes. Writes will be fastest if size is
863 * exactly this and offset is a multiple of this. For example, an EC
864 * may have a write buffer which can do half-page operations if data is
865 * aligned, and a slower word-at-a-time write mode.
867 uint32_t write_ideal_size;
869 /* Flags; see EC_FLASH_INFO_* */
870 uint32_t flags;
871 } __packed;
874 * Read flash
876 * Response is params.size bytes of data.
878 #define EC_CMD_FLASH_READ 0x11
880 struct ec_params_flash_read {
881 uint32_t offset; /* Byte offset to read */
882 uint32_t size; /* Size to read in bytes */
883 } __packed;
885 /* Write flash */
886 #define EC_CMD_FLASH_WRITE 0x12
887 #define EC_VER_FLASH_WRITE 1
889 /* Version 0 of the flash command supported only 64 bytes of data */
890 #define EC_FLASH_WRITE_VER0_SIZE 64
892 struct ec_params_flash_write {
893 uint32_t offset; /* Byte offset to write */
894 uint32_t size; /* Size to write in bytes */
895 /* Followed by data to write */
896 } __packed;
898 /* Erase flash */
899 #define EC_CMD_FLASH_ERASE 0x13
901 struct ec_params_flash_erase {
902 uint32_t offset; /* Byte offset to erase */
903 uint32_t size; /* Size to erase in bytes */
904 } __packed;
907 * Get/set flash protection.
909 * If mask!=0, sets/clear the requested bits of flags. Depending on the
910 * firmware write protect GPIO, not all flags will take effect immediately;
911 * some flags require a subsequent hard reset to take effect. Check the
912 * returned flags bits to see what actually happened.
914 * If mask=0, simply returns the current flags state.
916 #define EC_CMD_FLASH_PROTECT 0x15
917 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
919 /* Flags for flash protection */
920 /* RO flash code protected when the EC boots */
921 #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
923 * RO flash code protected now. If this bit is set, at-boot status cannot
924 * be changed.
926 #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
927 /* Entire flash code protected now, until reboot. */
928 #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
929 /* Flash write protect GPIO is asserted now */
930 #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
931 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
932 #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
934 * Error - flash protection is in inconsistent state. At least one bank of
935 * flash which should be protected is not protected. Usually fixed by
936 * re-requesting the desired flags, or by a hard reset if that fails.
938 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
939 /* Entile flash code protected when the EC boots */
940 #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
942 struct ec_params_flash_protect {
943 uint32_t mask; /* Bits in flags to apply */
944 uint32_t flags; /* New flags to apply */
945 } __packed;
947 struct ec_response_flash_protect {
948 /* Current value of flash protect flags */
949 uint32_t flags;
951 * Flags which are valid on this platform. This allows the caller
952 * to distinguish between flags which aren't set vs. flags which can't
953 * be set on this platform.
955 uint32_t valid_flags;
956 /* Flags which can be changed given the current protection state */
957 uint32_t writable_flags;
958 } __packed;
961 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
962 * write protect. These commands may be reused with version > 0.
965 /* Get the region offset/size */
966 #define EC_CMD_FLASH_REGION_INFO 0x16
967 #define EC_VER_FLASH_REGION_INFO 1
969 enum ec_flash_region {
970 /* Region which holds read-only EC image */
971 EC_FLASH_REGION_RO = 0,
972 /* Region which holds rewritable EC image */
973 EC_FLASH_REGION_RW,
975 * Region which should be write-protected in the factory (a superset of
976 * EC_FLASH_REGION_RO)
978 EC_FLASH_REGION_WP_RO,
979 /* Number of regions */
980 EC_FLASH_REGION_COUNT,
983 struct ec_params_flash_region_info {
984 uint32_t region; /* enum ec_flash_region */
985 } __packed;
987 struct ec_response_flash_region_info {
988 uint32_t offset;
989 uint32_t size;
990 } __packed;
992 /* Read/write VbNvContext */
993 #define EC_CMD_VBNV_CONTEXT 0x17
994 #define EC_VER_VBNV_CONTEXT 1
995 #define EC_VBNV_BLOCK_SIZE 16
997 enum ec_vbnvcontext_op {
998 EC_VBNV_CONTEXT_OP_READ,
999 EC_VBNV_CONTEXT_OP_WRITE,
1002 struct ec_params_vbnvcontext {
1003 uint32_t op;
1004 uint8_t block[EC_VBNV_BLOCK_SIZE];
1005 } __packed;
1007 struct ec_response_vbnvcontext {
1008 uint8_t block[EC_VBNV_BLOCK_SIZE];
1009 } __packed;
1011 /*****************************************************************************/
1012 /* PWM commands */
1014 /* Get fan target RPM */
1015 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1017 struct ec_response_pwm_get_fan_rpm {
1018 uint32_t rpm;
1019 } __packed;
1021 /* Set target fan RPM */
1022 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1024 struct ec_params_pwm_set_fan_target_rpm {
1025 uint32_t rpm;
1026 } __packed;
1028 /* Get keyboard backlight */
1029 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1031 struct ec_response_pwm_get_keyboard_backlight {
1032 uint8_t percent;
1033 uint8_t enabled;
1034 } __packed;
1036 /* Set keyboard backlight */
1037 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1039 struct ec_params_pwm_set_keyboard_backlight {
1040 uint8_t percent;
1041 } __packed;
1043 /* Set target fan PWM duty cycle */
1044 #define EC_CMD_PWM_SET_FAN_DUTY 0x24
1046 struct ec_params_pwm_set_fan_duty {
1047 uint32_t percent;
1048 } __packed;
1050 #define EC_CMD_PWM_SET_DUTY 0x25
1051 /* 16 bit duty cycle, 0xffff = 100% */
1052 #define EC_PWM_MAX_DUTY 0xffff
1054 enum ec_pwm_type {
1055 /* All types, indexed by board-specific enum pwm_channel */
1056 EC_PWM_TYPE_GENERIC = 0,
1057 /* Keyboard backlight */
1058 EC_PWM_TYPE_KB_LIGHT,
1059 /* Display backlight */
1060 EC_PWM_TYPE_DISPLAY_LIGHT,
1061 EC_PWM_TYPE_COUNT,
1064 struct ec_params_pwm_set_duty {
1065 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1066 uint8_t pwm_type; /* ec_pwm_type */
1067 uint8_t index; /* Type-specific index, or 0 if unique */
1068 } __packed;
1070 #define EC_CMD_PWM_GET_DUTY 0x26
1072 struct ec_params_pwm_get_duty {
1073 uint8_t pwm_type; /* ec_pwm_type */
1074 uint8_t index; /* Type-specific index, or 0 if unique */
1075 } __packed;
1077 struct ec_response_pwm_get_duty {
1078 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1079 } __packed;
1081 /*****************************************************************************/
1083 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1084 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1085 * into a subcommand. We'll make separate structs for subcommands with
1086 * different input args, so that we know how much to expect.
1088 #define EC_CMD_LIGHTBAR_CMD 0x28
1090 struct rgb_s {
1091 uint8_t r, g, b;
1094 #define LB_BATTERY_LEVELS 4
1095 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1096 * host command, but the alignment is the same regardless. Keep it that way.
1098 struct lightbar_params_v0 {
1099 /* Timing */
1100 int32_t google_ramp_up;
1101 int32_t google_ramp_down;
1102 int32_t s3s0_ramp_up;
1103 int32_t s0_tick_delay[2]; /* AC=0/1 */
1104 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1105 int32_t s0s3_ramp_down;
1106 int32_t s3_sleep_for;
1107 int32_t s3_ramp_up;
1108 int32_t s3_ramp_down;
1110 /* Oscillation */
1111 uint8_t new_s0;
1112 uint8_t osc_min[2]; /* AC=0/1 */
1113 uint8_t osc_max[2]; /* AC=0/1 */
1114 uint8_t w_ofs[2]; /* AC=0/1 */
1116 /* Brightness limits based on the backlight and AC. */
1117 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1118 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1119 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1121 /* Battery level thresholds */
1122 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1124 /* Map [AC][battery_level] to color index */
1125 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1126 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1128 /* Color palette */
1129 struct rgb_s color[8]; /* 0-3 are Google colors */
1130 } __packed;
1132 struct lightbar_params_v1 {
1133 /* Timing */
1134 int32_t google_ramp_up;
1135 int32_t google_ramp_down;
1136 int32_t s3s0_ramp_up;
1137 int32_t s0_tick_delay[2]; /* AC=0/1 */
1138 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1139 int32_t s0s3_ramp_down;
1140 int32_t s3_sleep_for;
1141 int32_t s3_ramp_up;
1142 int32_t s3_ramp_down;
1143 int32_t tap_tick_delay;
1144 int32_t tap_display_time;
1146 /* Tap-for-battery params */
1147 uint8_t tap_pct_red;
1148 uint8_t tap_pct_green;
1149 uint8_t tap_seg_min_on;
1150 uint8_t tap_seg_max_on;
1151 uint8_t tap_seg_osc;
1152 uint8_t tap_idx[3];
1154 /* Oscillation */
1155 uint8_t osc_min[2]; /* AC=0/1 */
1156 uint8_t osc_max[2]; /* AC=0/1 */
1157 uint8_t w_ofs[2]; /* AC=0/1 */
1159 /* Brightness limits based on the backlight and AC. */
1160 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1161 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1162 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1164 /* Battery level thresholds */
1165 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1167 /* Map [AC][battery_level] to color index */
1168 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1169 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1171 /* Color palette */
1172 struct rgb_s color[8]; /* 0-3 are Google colors */
1173 } __packed;
1175 /* Lightbar program */
1176 #define EC_LB_PROG_LEN 192
1177 struct lightbar_program {
1178 uint8_t size;
1179 uint8_t data[EC_LB_PROG_LEN];
1182 struct ec_params_lightbar {
1183 uint8_t cmd; /* Command (see enum lightbar_command) */
1184 union {
1185 struct {
1186 /* no args */
1187 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1188 version, get_brightness, get_demo, suspend, resume;
1190 struct {
1191 uint8_t num;
1192 } set_brightness, seq, demo;
1194 struct {
1195 uint8_t ctrl, reg, value;
1196 } reg;
1198 struct {
1199 uint8_t led, red, green, blue;
1200 } set_rgb;
1202 struct {
1203 uint8_t led;
1204 } get_rgb;
1206 struct {
1207 uint8_t enable;
1208 } manual_suspend_ctrl;
1210 struct lightbar_params_v0 set_params_v0;
1211 struct lightbar_params_v1 set_params_v1;
1212 struct lightbar_program set_program;
1214 } __packed;
1216 struct ec_response_lightbar {
1217 union {
1218 struct {
1219 struct {
1220 uint8_t reg;
1221 uint8_t ic0;
1222 uint8_t ic1;
1223 } vals[23];
1224 } dump;
1226 struct {
1227 uint8_t num;
1228 } get_seq, get_brightness, get_demo;
1230 struct lightbar_params_v0 get_params_v0;
1231 struct lightbar_params_v1 get_params_v1;
1233 struct {
1234 uint32_t num;
1235 uint32_t flags;
1236 } version;
1238 struct {
1239 uint8_t red, green, blue;
1240 } get_rgb;
1242 struct {
1243 /* no return params */
1244 } off, on, init, set_brightness, seq, reg, set_rgb,
1245 demo, set_params_v0, set_params_v1,
1246 set_program, manual_suspend_ctrl, suspend, resume;
1248 } __packed;
1250 /* Lightbar commands */
1251 enum lightbar_command {
1252 LIGHTBAR_CMD_DUMP = 0,
1253 LIGHTBAR_CMD_OFF = 1,
1254 LIGHTBAR_CMD_ON = 2,
1255 LIGHTBAR_CMD_INIT = 3,
1256 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
1257 LIGHTBAR_CMD_SEQ = 5,
1258 LIGHTBAR_CMD_REG = 6,
1259 LIGHTBAR_CMD_SET_RGB = 7,
1260 LIGHTBAR_CMD_GET_SEQ = 8,
1261 LIGHTBAR_CMD_DEMO = 9,
1262 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1263 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1264 LIGHTBAR_CMD_VERSION = 12,
1265 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1266 LIGHTBAR_CMD_GET_RGB = 14,
1267 LIGHTBAR_CMD_GET_DEMO = 15,
1268 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1269 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
1270 LIGHTBAR_CMD_SET_PROGRAM = 18,
1271 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1272 LIGHTBAR_CMD_SUSPEND = 20,
1273 LIGHTBAR_CMD_RESUME = 21,
1274 LIGHTBAR_NUM_CMDS
1277 /*****************************************************************************/
1278 /* LED control commands */
1280 #define EC_CMD_LED_CONTROL 0x29
1282 enum ec_led_id {
1283 /* LED to indicate battery state of charge */
1284 EC_LED_ID_BATTERY_LED = 0,
1286 * LED to indicate system power state (on or in suspend).
1287 * May be on power button or on C-panel.
1289 EC_LED_ID_POWER_LED,
1290 /* LED on power adapter or its plug */
1291 EC_LED_ID_ADAPTER_LED,
1293 EC_LED_ID_COUNT
1296 /* LED control flags */
1297 #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1298 #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1300 enum ec_led_colors {
1301 EC_LED_COLOR_RED = 0,
1302 EC_LED_COLOR_GREEN,
1303 EC_LED_COLOR_BLUE,
1304 EC_LED_COLOR_YELLOW,
1305 EC_LED_COLOR_WHITE,
1307 EC_LED_COLOR_COUNT
1310 struct ec_params_led_control {
1311 uint8_t led_id; /* Which LED to control */
1312 uint8_t flags; /* Control flags */
1314 uint8_t brightness[EC_LED_COLOR_COUNT];
1315 } __packed;
1317 struct ec_response_led_control {
1319 * Available brightness value range.
1321 * Range 0 means color channel not present.
1322 * Range 1 means on/off control.
1323 * Other values means the LED is control by PWM.
1325 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1326 } __packed;
1328 /*****************************************************************************/
1329 /* Verified boot commands */
1332 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1333 * reused for other purposes with version > 0.
1336 /* Verified boot hash command */
1337 #define EC_CMD_VBOOT_HASH 0x2A
1339 struct ec_params_vboot_hash {
1340 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1341 uint8_t hash_type; /* enum ec_vboot_hash_type */
1342 uint8_t nonce_size; /* Nonce size; may be 0 */
1343 uint8_t reserved0; /* Reserved; set 0 */
1344 uint32_t offset; /* Offset in flash to hash */
1345 uint32_t size; /* Number of bytes to hash */
1346 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1347 } __packed;
1349 struct ec_response_vboot_hash {
1350 uint8_t status; /* enum ec_vboot_hash_status */
1351 uint8_t hash_type; /* enum ec_vboot_hash_type */
1352 uint8_t digest_size; /* Size of hash digest in bytes */
1353 uint8_t reserved0; /* Ignore; will be 0 */
1354 uint32_t offset; /* Offset in flash which was hashed */
1355 uint32_t size; /* Number of bytes hashed */
1356 uint8_t hash_digest[64]; /* Hash digest data */
1357 } __packed;
1359 enum ec_vboot_hash_cmd {
1360 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1361 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1362 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1363 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1366 enum ec_vboot_hash_type {
1367 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1370 enum ec_vboot_hash_status {
1371 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1372 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1373 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1377 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1378 * If one of these is specified, the EC will automatically update offset and
1379 * size to the correct values for the specified image (RO or RW).
1381 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1382 #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1384 /*****************************************************************************/
1386 * Motion sense commands. We'll make separate structs for sub-commands with
1387 * different input args, so that we know how much to expect.
1389 #define EC_CMD_MOTION_SENSE_CMD 0x2B
1391 /* Motion sense commands */
1392 enum motionsense_command {
1394 * Dump command returns all motion sensor data including motion sense
1395 * module flags and individual sensor flags.
1397 MOTIONSENSE_CMD_DUMP = 0,
1400 * Info command returns data describing the details of a given sensor,
1401 * including enum motionsensor_type, enum motionsensor_location, and
1402 * enum motionsensor_chip.
1404 MOTIONSENSE_CMD_INFO = 1,
1407 * EC Rate command is a setter/getter command for the EC sampling rate
1408 * of all motion sensors in milliseconds.
1410 MOTIONSENSE_CMD_EC_RATE = 2,
1413 * Sensor ODR command is a setter/getter command for the output data
1414 * rate of a specific motion sensor in millihertz.
1416 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1419 * Sensor range command is a setter/getter command for the range of
1420 * a specified motion sensor in +/-G's or +/- deg/s.
1422 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1425 * Setter/getter command for the keyboard wake angle. When the lid
1426 * angle is greater than this value, keyboard wake is disabled in S3,
1427 * and when the lid angle goes less than this value, keyboard wake is
1428 * enabled. Note, the lid angle measurement is an approximate,
1429 * un-calibrated value, hence the wake angle isn't exact.
1431 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1434 * Returns a single sensor data.
1436 MOTIONSENSE_CMD_DATA = 6,
1439 * Perform low level calibration.. On sensors that support it, ask to
1440 * do offset calibration.
1442 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1445 * Sensor Offset command is a setter/getter command for the offset used
1446 * for calibration. The offsets can be calculated by the host, or via
1447 * PERFORM_CALIB command.
1449 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1451 /* Number of motionsense sub-commands. */
1452 MOTIONSENSE_NUM_CMDS
1455 enum motionsensor_id {
1456 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1457 EC_MOTION_SENSOR_ACCEL_LID = 1,
1458 EC_MOTION_SENSOR_GYRO = 2,
1461 * Note, if more sensors are added and this count changes, the padding
1462 * in ec_response_motion_sense dump command must be modified.
1464 EC_MOTION_SENSOR_COUNT = 3
1467 /* List of motion sensor types. */
1468 enum motionsensor_type {
1469 MOTIONSENSE_TYPE_ACCEL = 0,
1470 MOTIONSENSE_TYPE_GYRO = 1,
1471 MOTIONSENSE_TYPE_MAG = 2,
1472 MOTIONSENSE_TYPE_PROX = 3,
1473 MOTIONSENSE_TYPE_LIGHT = 4,
1474 MOTIONSENSE_TYPE_ACTIVITY = 5,
1475 MOTIONSENSE_TYPE_BARO = 6,
1476 MOTIONSENSE_TYPE_MAX,
1479 /* List of motion sensor locations. */
1480 enum motionsensor_location {
1481 MOTIONSENSE_LOC_BASE = 0,
1482 MOTIONSENSE_LOC_LID = 1,
1483 MOTIONSENSE_LOC_MAX,
1486 /* List of motion sensor chips. */
1487 enum motionsensor_chip {
1488 MOTIONSENSE_CHIP_KXCJ9 = 0,
1491 /* Module flag masks used for the dump sub-command. */
1492 #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1494 /* Sensor flag masks used for the dump sub-command. */
1495 #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1498 * Send this value for the data element to only perform a read. If you
1499 * send any other value, the EC will interpret it as data to set and will
1500 * return the actual value set.
1502 #define EC_MOTION_SENSE_NO_VALUE -1
1504 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1506 /* Set Calibration information */
1507 #define MOTION_SENSE_SET_OFFSET 1
1509 struct ec_response_motion_sensor_data {
1510 /* Flags for each sensor. */
1511 uint8_t flags;
1512 /* Sensor number the data comes from */
1513 uint8_t sensor_num;
1514 /* Each sensor is up to 3-axis. */
1515 union {
1516 int16_t data[3];
1517 struct {
1518 uint16_t rsvd;
1519 uint32_t timestamp;
1520 } __packed;
1521 struct {
1522 uint8_t activity; /* motionsensor_activity */
1523 uint8_t state;
1524 int16_t add_info[2];
1527 } __packed;
1529 struct ec_params_motion_sense {
1530 uint8_t cmd;
1531 union {
1532 /* Used for MOTIONSENSE_CMD_DUMP. */
1533 struct {
1534 /* no args */
1535 } dump;
1538 * Used for MOTIONSENSE_CMD_EC_RATE and
1539 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1541 struct {
1542 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1543 int16_t data;
1544 } ec_rate, kb_wake_angle;
1546 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1547 struct {
1548 uint8_t sensor_num;
1551 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1552 * the calibration information in the EC.
1553 * If unset, just retrieve calibration information.
1555 uint16_t flags;
1558 * Temperature at calibration, in units of 0.01 C
1559 * 0x8000: invalid / unknown.
1560 * 0x0: 0C
1561 * 0x7fff: +327.67C
1563 int16_t temp;
1566 * Offset for calibration.
1567 * Unit:
1568 * Accelerometer: 1/1024 g
1569 * Gyro: 1/1024 deg/s
1570 * Compass: 1/16 uT
1572 int16_t offset[3];
1573 } __packed sensor_offset;
1575 /* Used for MOTIONSENSE_CMD_INFO. */
1576 struct {
1577 uint8_t sensor_num;
1578 } info;
1581 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1582 * MOTIONSENSE_CMD_SENSOR_RANGE.
1584 struct {
1585 /* Should be element of enum motionsensor_id. */
1586 uint8_t sensor_num;
1588 /* Rounding flag, true for round-up, false for down. */
1589 uint8_t roundup;
1591 uint16_t reserved;
1593 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1594 int32_t data;
1595 } sensor_odr, sensor_range;
1597 } __packed;
1599 struct ec_response_motion_sense {
1600 union {
1601 /* Used for MOTIONSENSE_CMD_DUMP. */
1602 struct {
1603 /* Flags representing the motion sensor module. */
1604 uint8_t module_flags;
1606 /* Number of sensors managed directly by the EC. */
1607 uint8_t sensor_count;
1610 * Sensor data is truncated if response_max is too small
1611 * for holding all the data.
1613 struct ec_response_motion_sensor_data sensor[0];
1614 } dump;
1616 /* Used for MOTIONSENSE_CMD_INFO. */
1617 struct {
1618 /* Should be element of enum motionsensor_type. */
1619 uint8_t type;
1621 /* Should be element of enum motionsensor_location. */
1622 uint8_t location;
1624 /* Should be element of enum motionsensor_chip. */
1625 uint8_t chip;
1626 } info;
1628 /* Used for MOTIONSENSE_CMD_DATA */
1629 struct ec_response_motion_sensor_data data;
1632 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1633 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1634 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1636 struct {
1637 /* Current value of the parameter queried. */
1638 int32_t ret;
1639 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1641 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1642 struct {
1643 int16_t temp;
1644 int16_t offset[3];
1645 } sensor_offset, perform_calib;
1647 } __packed;
1649 /*****************************************************************************/
1650 /* USB charging control commands */
1652 /* Set USB port charging mode */
1653 #define EC_CMD_USB_CHARGE_SET_MODE 0x30
1655 struct ec_params_usb_charge_set_mode {
1656 uint8_t usb_port_id;
1657 uint8_t mode;
1658 } __packed;
1660 /*****************************************************************************/
1661 /* Persistent storage for host */
1663 /* Maximum bytes that can be read/written in a single command */
1664 #define EC_PSTORE_SIZE_MAX 64
1666 /* Get persistent storage info */
1667 #define EC_CMD_PSTORE_INFO 0x40
1669 struct ec_response_pstore_info {
1670 /* Persistent storage size, in bytes */
1671 uint32_t pstore_size;
1672 /* Access size; read/write offset and size must be a multiple of this */
1673 uint32_t access_size;
1674 } __packed;
1677 * Read persistent storage
1679 * Response is params.size bytes of data.
1681 #define EC_CMD_PSTORE_READ 0x41
1683 struct ec_params_pstore_read {
1684 uint32_t offset; /* Byte offset to read */
1685 uint32_t size; /* Size to read in bytes */
1686 } __packed;
1688 /* Write persistent storage */
1689 #define EC_CMD_PSTORE_WRITE 0x42
1691 struct ec_params_pstore_write {
1692 uint32_t offset; /* Byte offset to write */
1693 uint32_t size; /* Size to write in bytes */
1694 uint8_t data[EC_PSTORE_SIZE_MAX];
1695 } __packed;
1697 /*****************************************************************************/
1698 /* Real-time clock */
1700 /* RTC params and response structures */
1701 struct ec_params_rtc {
1702 uint32_t time;
1703 } __packed;
1705 struct ec_response_rtc {
1706 uint32_t time;
1707 } __packed;
1709 /* These use ec_response_rtc */
1710 #define EC_CMD_RTC_GET_VALUE 0x44
1711 #define EC_CMD_RTC_GET_ALARM 0x45
1713 /* These all use ec_params_rtc */
1714 #define EC_CMD_RTC_SET_VALUE 0x46
1715 #define EC_CMD_RTC_SET_ALARM 0x47
1717 /* Pass as param to SET_ALARM to clear the current alarm */
1718 #define EC_RTC_ALARM_CLEAR 0
1720 /*****************************************************************************/
1721 /* Port80 log access */
1723 /* Maximum entries that can be read/written in a single command */
1724 #define EC_PORT80_SIZE_MAX 32
1726 /* Get last port80 code from previous boot */
1727 #define EC_CMD_PORT80_LAST_BOOT 0x48
1728 #define EC_CMD_PORT80_READ 0x48
1730 enum ec_port80_subcmd {
1731 EC_PORT80_GET_INFO = 0,
1732 EC_PORT80_READ_BUFFER,
1735 struct ec_params_port80_read {
1736 uint16_t subcmd;
1737 union {
1738 struct {
1739 uint32_t offset;
1740 uint32_t num_entries;
1741 } read_buffer;
1743 } __packed;
1745 struct ec_response_port80_read {
1746 union {
1747 struct {
1748 uint32_t writes;
1749 uint32_t history_size;
1750 uint32_t last_boot;
1751 } get_info;
1752 struct {
1753 uint16_t codes[EC_PORT80_SIZE_MAX];
1754 } data;
1756 } __packed;
1758 struct ec_response_port80_last_boot {
1759 uint16_t code;
1760 } __packed;
1762 /*****************************************************************************/
1763 /* Thermal engine commands. Note that there are two implementations. We'll
1764 * reuse the command number, but the data and behavior is incompatible.
1765 * Version 0 is what originally shipped on Link.
1766 * Version 1 separates the CPU thermal limits from the fan control.
1769 #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1770 #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1772 /* The version 0 structs are opaque. You have to know what they are for
1773 * the get/set commands to make any sense.
1776 /* Version 0 - set */
1777 struct ec_params_thermal_set_threshold {
1778 uint8_t sensor_type;
1779 uint8_t threshold_id;
1780 uint16_t value;
1781 } __packed;
1783 /* Version 0 - get */
1784 struct ec_params_thermal_get_threshold {
1785 uint8_t sensor_type;
1786 uint8_t threshold_id;
1787 } __packed;
1789 struct ec_response_thermal_get_threshold {
1790 uint16_t value;
1791 } __packed;
1794 /* The version 1 structs are visible. */
1795 enum ec_temp_thresholds {
1796 EC_TEMP_THRESH_WARN = 0,
1797 EC_TEMP_THRESH_HIGH,
1798 EC_TEMP_THRESH_HALT,
1800 EC_TEMP_THRESH_COUNT
1803 /* Thermal configuration for one temperature sensor. Temps are in degrees K.
1804 * Zero values will be silently ignored by the thermal task.
1806 struct ec_thermal_config {
1807 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1808 uint32_t temp_fan_off; /* no active cooling needed */
1809 uint32_t temp_fan_max; /* max active cooling needed */
1810 } __packed;
1812 /* Version 1 - get config for one sensor. */
1813 struct ec_params_thermal_get_threshold_v1 {
1814 uint32_t sensor_num;
1815 } __packed;
1816 /* This returns a struct ec_thermal_config */
1818 /* Version 1 - set config for one sensor.
1819 * Use read-modify-write for best results! */
1820 struct ec_params_thermal_set_threshold_v1 {
1821 uint32_t sensor_num;
1822 struct ec_thermal_config cfg;
1823 } __packed;
1824 /* This returns no data */
1826 /****************************************************************************/
1828 /* Toggle automatic fan control */
1829 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1831 /* Get TMP006 calibration data */
1832 #define EC_CMD_TMP006_GET_CALIBRATION 0x53
1834 struct ec_params_tmp006_get_calibration {
1835 uint8_t index;
1836 } __packed;
1838 struct ec_response_tmp006_get_calibration {
1839 float s0;
1840 float b0;
1841 float b1;
1842 float b2;
1843 } __packed;
1845 /* Set TMP006 calibration data */
1846 #define EC_CMD_TMP006_SET_CALIBRATION 0x54
1848 struct ec_params_tmp006_set_calibration {
1849 uint8_t index;
1850 uint8_t reserved[3]; /* Reserved; set 0 */
1851 float s0;
1852 float b0;
1853 float b1;
1854 float b2;
1855 } __packed;
1857 /* Read raw TMP006 data */
1858 #define EC_CMD_TMP006_GET_RAW 0x55
1860 struct ec_params_tmp006_get_raw {
1861 uint8_t index;
1862 } __packed;
1864 struct ec_response_tmp006_get_raw {
1865 int32_t t; /* In 1/100 K */
1866 int32_t v; /* In nV */
1869 /*****************************************************************************/
1870 /* MKBP - Matrix KeyBoard Protocol */
1873 * Read key state
1875 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1876 * expected response size.
1878 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1879 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1880 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
1882 #define EC_CMD_MKBP_STATE 0x60
1885 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1887 #define EC_CMD_MKBP_INFO 0x61
1889 struct ec_response_mkbp_info {
1890 uint32_t rows;
1891 uint32_t cols;
1892 /* Formerly "switches", which was 0. */
1893 uint8_t reserved;
1894 } __packed;
1896 struct ec_params_mkbp_info {
1897 uint8_t info_type;
1898 uint8_t event_type;
1899 } __packed;
1901 enum ec_mkbp_info_type {
1903 * Info about the keyboard matrix: number of rows and columns.
1905 * Returns struct ec_response_mkbp_info.
1907 EC_MKBP_INFO_KBD = 0,
1910 * For buttons and switches, info about which specifically are
1911 * supported. event_type must be set to one of the values in enum
1912 * ec_mkbp_event.
1914 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
1915 * bitmask indicating which buttons or switches are present. See the
1916 * bit inidices below.
1918 EC_MKBP_INFO_SUPPORTED = 1,
1921 * Instantaneous state of buttons and switches.
1923 * event_type must be set to one of the values in enum ec_mkbp_event.
1925 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
1926 * indicating the current state of the keyboard matrix.
1928 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
1929 * event state.
1931 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
1932 * state of supported buttons.
1934 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
1935 * state of supported switches.
1937 EC_MKBP_INFO_CURRENT = 2,
1940 /* Simulate key press */
1941 #define EC_CMD_MKBP_SIMULATE_KEY 0x62
1943 struct ec_params_mkbp_simulate_key {
1944 uint8_t col;
1945 uint8_t row;
1946 uint8_t pressed;
1947 } __packed;
1949 /* Configure keyboard scanning */
1950 #define EC_CMD_MKBP_SET_CONFIG 0x64
1951 #define EC_CMD_MKBP_GET_CONFIG 0x65
1953 /* flags */
1954 enum mkbp_config_flags {
1955 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
1958 enum mkbp_config_valid {
1959 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
1960 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
1961 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
1962 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
1963 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
1964 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
1965 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
1968 /* Configuration for our key scanning algorithm */
1969 struct ec_mkbp_config {
1970 uint32_t valid_mask; /* valid fields */
1971 uint8_t flags; /* some flags (enum mkbp_config_flags) */
1972 uint8_t valid_flags; /* which flags are valid */
1973 uint16_t scan_period_us; /* period between start of scans */
1974 /* revert to interrupt mode after no activity for this long */
1975 uint32_t poll_timeout_us;
1977 * minimum post-scan relax time. Once we finish a scan we check
1978 * the time until we are due to start the next one. If this time is
1979 * shorter this field, we use this instead.
1981 uint16_t min_post_scan_delay_us;
1982 /* delay between setting up output and waiting for it to settle */
1983 uint16_t output_settle_us;
1984 uint16_t debounce_down_us; /* time for debounce on key down */
1985 uint16_t debounce_up_us; /* time for debounce on key up */
1986 /* maximum depth to allow for fifo (0 = no keyscan output) */
1987 uint8_t fifo_max_depth;
1988 } __packed;
1990 struct ec_params_mkbp_set_config {
1991 struct ec_mkbp_config config;
1992 } __packed;
1994 struct ec_response_mkbp_get_config {
1995 struct ec_mkbp_config config;
1996 } __packed;
1998 /* Run the key scan emulation */
1999 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2001 enum ec_keyscan_seq_cmd {
2002 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2003 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2004 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2005 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2006 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2009 enum ec_collect_flags {
2011 * Indicates this scan was processed by the EC. Due to timing, some
2012 * scans may be skipped.
2014 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2017 struct ec_collect_item {
2018 uint8_t flags; /* some flags (enum ec_collect_flags) */
2021 struct ec_params_keyscan_seq_ctrl {
2022 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2023 union {
2024 struct {
2025 uint8_t active; /* still active */
2026 uint8_t num_items; /* number of items */
2027 /* Current item being presented */
2028 uint8_t cur_item;
2029 } status;
2030 struct {
2032 * Absolute time for this scan, measured from the
2033 * start of the sequence.
2035 uint32_t time_us;
2036 uint8_t scan[0]; /* keyscan data */
2037 } add;
2038 struct {
2039 uint8_t start_item; /* First item to return */
2040 uint8_t num_items; /* Number of items to return */
2041 } collect;
2043 } __packed;
2045 struct ec_result_keyscan_seq_ctrl {
2046 union {
2047 struct {
2048 uint8_t num_items; /* Number of items */
2049 /* Data for each item */
2050 struct ec_collect_item item[0];
2051 } collect;
2053 } __packed;
2056 * Command for retrieving the next pending MKBP event from the EC device
2058 * The device replies with UNAVAILABLE if there aren't any pending events.
2060 #define EC_CMD_GET_NEXT_EVENT 0x67
2062 enum ec_mkbp_event {
2063 /* Keyboard matrix changed. The event data is the new matrix state. */
2064 EC_MKBP_EVENT_KEY_MATRIX = 0,
2066 /* New host event. The event data is 4 bytes of host event flags. */
2067 EC_MKBP_EVENT_HOST_EVENT = 1,
2069 /* New Sensor FIFO data. The event data is fifo_info structure. */
2070 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2072 /* The state of the non-matrixed buttons have changed. */
2073 EC_MKBP_EVENT_BUTTON = 3,
2075 /* The state of the switches have changed. */
2076 EC_MKBP_EVENT_SWITCH = 4,
2078 /* EC sent a sysrq command */
2079 EC_MKBP_EVENT_SYSRQ = 6,
2081 /* Number of MKBP events */
2082 EC_MKBP_EVENT_COUNT,
2085 union ec_response_get_next_data {
2086 uint8_t key_matrix[13];
2088 /* Unaligned */
2089 uint32_t host_event;
2091 uint32_t buttons;
2092 uint32_t switches;
2093 uint32_t sysrq;
2094 } __packed;
2096 struct ec_response_get_next_event {
2097 uint8_t event_type;
2098 /* Followed by event data if any */
2099 union ec_response_get_next_data data;
2100 } __packed;
2102 /* Bit indices for buttons and switches.*/
2103 /* Buttons */
2104 #define EC_MKBP_POWER_BUTTON 0
2105 #define EC_MKBP_VOL_UP 1
2106 #define EC_MKBP_VOL_DOWN 2
2108 /* Switches */
2109 #define EC_MKBP_LID_OPEN 0
2110 #define EC_MKBP_TABLET_MODE 1
2112 /*****************************************************************************/
2113 /* Temperature sensor commands */
2115 /* Read temperature sensor info */
2116 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2118 struct ec_params_temp_sensor_get_info {
2119 uint8_t id;
2120 } __packed;
2122 struct ec_response_temp_sensor_get_info {
2123 char sensor_name[32];
2124 uint8_t sensor_type;
2125 } __packed;
2127 /*****************************************************************************/
2130 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2131 * commands accidentally sent to the wrong interface. See the ACPI section
2132 * below.
2135 /*****************************************************************************/
2136 /* Host event commands */
2139 * Host event mask params and response structures, shared by all of the host
2140 * event commands below.
2142 struct ec_params_host_event_mask {
2143 uint32_t mask;
2144 } __packed;
2146 struct ec_response_host_event_mask {
2147 uint32_t mask;
2148 } __packed;
2150 /* These all use ec_response_host_event_mask */
2151 #define EC_CMD_HOST_EVENT_GET_B 0x87
2152 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2153 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2154 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2156 /* These all use ec_params_host_event_mask */
2157 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2158 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2159 #define EC_CMD_HOST_EVENT_CLEAR 0x8c
2160 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2161 #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2163 /*****************************************************************************/
2164 /* Switch commands */
2166 /* Enable/disable LCD backlight */
2167 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2169 struct ec_params_switch_enable_backlight {
2170 uint8_t enabled;
2171 } __packed;
2173 /* Enable/disable WLAN/Bluetooth */
2174 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
2175 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
2177 /* Version 0 params; no response */
2178 struct ec_params_switch_enable_wireless_v0 {
2179 uint8_t enabled;
2180 } __packed;
2182 /* Version 1 params */
2183 struct ec_params_switch_enable_wireless_v1 {
2184 /* Flags to enable now */
2185 uint8_t now_flags;
2187 /* Which flags to copy from now_flags */
2188 uint8_t now_mask;
2191 * Flags to leave enabled in S3, if they're on at the S0->S3
2192 * transition. (Other flags will be disabled by the S0->S3
2193 * transition.)
2195 uint8_t suspend_flags;
2197 /* Which flags to copy from suspend_flags */
2198 uint8_t suspend_mask;
2199 } __packed;
2201 /* Version 1 response */
2202 struct ec_response_switch_enable_wireless_v1 {
2203 /* Flags to enable now */
2204 uint8_t now_flags;
2206 /* Flags to leave enabled in S3 */
2207 uint8_t suspend_flags;
2208 } __packed;
2210 /*****************************************************************************/
2211 /* GPIO commands. Only available on EC if write protect has been disabled. */
2213 /* Set GPIO output value */
2214 #define EC_CMD_GPIO_SET 0x92
2216 struct ec_params_gpio_set {
2217 char name[32];
2218 uint8_t val;
2219 } __packed;
2221 /* Get GPIO value */
2222 #define EC_CMD_GPIO_GET 0x93
2224 /* Version 0 of input params and response */
2225 struct ec_params_gpio_get {
2226 char name[32];
2227 } __packed;
2228 struct ec_response_gpio_get {
2229 uint8_t val;
2230 } __packed;
2232 /* Version 1 of input params and response */
2233 struct ec_params_gpio_get_v1 {
2234 uint8_t subcmd;
2235 union {
2236 struct {
2237 char name[32];
2238 } get_value_by_name;
2239 struct {
2240 uint8_t index;
2241 } get_info;
2243 } __packed;
2245 struct ec_response_gpio_get_v1 {
2246 union {
2247 struct {
2248 uint8_t val;
2249 } get_value_by_name, get_count;
2250 struct {
2251 uint8_t val;
2252 char name[32];
2253 uint32_t flags;
2254 } get_info;
2256 } __packed;
2258 enum gpio_get_subcmd {
2259 EC_GPIO_GET_BY_NAME = 0,
2260 EC_GPIO_GET_COUNT = 1,
2261 EC_GPIO_GET_INFO = 2,
2264 /*****************************************************************************/
2265 /* I2C commands. Only available when flash write protect is unlocked. */
2268 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2269 * removed soon. Use EC_CMD_I2C_XFER instead.
2272 /* Read I2C bus */
2273 #define EC_CMD_I2C_READ 0x94
2275 struct ec_params_i2c_read {
2276 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2277 uint8_t read_size; /* Either 8 or 16. */
2278 uint8_t port;
2279 uint8_t offset;
2280 } __packed;
2281 struct ec_response_i2c_read {
2282 uint16_t data;
2283 } __packed;
2285 /* Write I2C bus */
2286 #define EC_CMD_I2C_WRITE 0x95
2288 struct ec_params_i2c_write {
2289 uint16_t data;
2290 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2291 uint8_t write_size; /* Either 8 or 16. */
2292 uint8_t port;
2293 uint8_t offset;
2294 } __packed;
2296 /*****************************************************************************/
2297 /* Charge state commands. Only available when flash write protect unlocked. */
2299 /* Force charge state machine to stop charging the battery or force it to
2300 * discharge the battery.
2302 #define EC_CMD_CHARGE_CONTROL 0x96
2303 #define EC_VER_CHARGE_CONTROL 1
2305 enum ec_charge_control_mode {
2306 CHARGE_CONTROL_NORMAL = 0,
2307 CHARGE_CONTROL_IDLE,
2308 CHARGE_CONTROL_DISCHARGE,
2311 struct ec_params_charge_control {
2312 uint32_t mode; /* enum charge_control_mode */
2313 } __packed;
2315 /*****************************************************************************/
2316 /* Console commands. Only available when flash write protect is unlocked. */
2318 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2319 #define EC_CMD_CONSOLE_SNAPSHOT 0x97
2322 * Read data from the saved snapshot. If the subcmd parameter is
2323 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2324 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2325 * end of the previous snapshot.
2327 * The params are only looked at in version >= 1 of this command. Prior
2328 * versions will just default to CONSOLE_READ_NEXT behavior.
2330 * Response is null-terminated string. Empty string, if there is no more
2331 * remaining output.
2333 #define EC_CMD_CONSOLE_READ 0x98
2335 enum ec_console_read_subcmd {
2336 CONSOLE_READ_NEXT = 0,
2337 CONSOLE_READ_RECENT
2340 struct ec_params_console_read_v1 {
2341 uint8_t subcmd; /* enum ec_console_read_subcmd */
2342 } __packed;
2344 /*****************************************************************************/
2347 * Cut off battery power immediately or after the host has shut down.
2349 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2350 * EC_RES_SUCCESS if the command was successful.
2351 * EC_RES_ERROR if the cut off command failed.
2354 #define EC_CMD_BATTERY_CUT_OFF 0x99
2356 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2358 struct ec_params_battery_cutoff {
2359 uint8_t flags;
2360 } __packed;
2362 /*****************************************************************************/
2363 /* USB port mux control. */
2366 * Switch USB mux or return to automatic switching.
2368 #define EC_CMD_USB_MUX 0x9a
2370 struct ec_params_usb_mux {
2371 uint8_t mux;
2372 } __packed;
2374 /*****************************************************************************/
2375 /* LDOs / FETs control. */
2377 enum ec_ldo_state {
2378 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2379 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2383 * Switch on/off a LDO.
2385 #define EC_CMD_LDO_SET 0x9b
2387 struct ec_params_ldo_set {
2388 uint8_t index;
2389 uint8_t state;
2390 } __packed;
2393 * Get LDO state.
2395 #define EC_CMD_LDO_GET 0x9c
2397 struct ec_params_ldo_get {
2398 uint8_t index;
2399 } __packed;
2401 struct ec_response_ldo_get {
2402 uint8_t state;
2403 } __packed;
2405 /*****************************************************************************/
2406 /* Power info. */
2409 * Get power info.
2411 #define EC_CMD_POWER_INFO 0x9d
2413 struct ec_response_power_info {
2414 uint32_t usb_dev_type;
2415 uint16_t voltage_ac;
2416 uint16_t voltage_system;
2417 uint16_t current_system;
2418 uint16_t usb_current_limit;
2419 } __packed;
2421 /*****************************************************************************/
2422 /* I2C passthru command */
2424 #define EC_CMD_I2C_PASSTHRU 0x9e
2426 /* Read data; if not present, message is a write */
2427 #define EC_I2C_FLAG_READ (1 << 15)
2429 /* Mask for address */
2430 #define EC_I2C_ADDR_MASK 0x3ff
2432 #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2433 #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2435 /* Any error */
2436 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2438 struct ec_params_i2c_passthru_msg {
2439 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2440 uint16_t len; /* Number of bytes to read or write */
2441 } __packed;
2443 struct ec_params_i2c_passthru {
2444 uint8_t port; /* I2C port number */
2445 uint8_t num_msgs; /* Number of messages */
2446 struct ec_params_i2c_passthru_msg msg[];
2447 /* Data to write for all messages is concatenated here */
2448 } __packed;
2450 struct ec_response_i2c_passthru {
2451 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2452 uint8_t num_msgs; /* Number of messages processed */
2453 uint8_t data[]; /* Data read by messages concatenated here */
2454 } __packed;
2456 /*****************************************************************************/
2457 /* Power button hang detect */
2459 #define EC_CMD_HANG_DETECT 0x9f
2461 /* Reasons to start hang detection timer */
2462 /* Power button pressed */
2463 #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2465 /* Lid closed */
2466 #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2468 /* Lid opened */
2469 #define EC_HANG_START_ON_LID_OPEN (1 << 2)
2471 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2472 #define EC_HANG_START_ON_RESUME (1 << 3)
2474 /* Reasons to cancel hang detection */
2476 /* Power button released */
2477 #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2479 /* Any host command from AP received */
2480 #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2482 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2483 #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2486 * If this flag is set, all the other fields are ignored, and the hang detect
2487 * timer is started. This provides the AP a way to start the hang timer
2488 * without reconfiguring any of the other hang detect settings. Note that
2489 * you must previously have configured the timeouts.
2491 #define EC_HANG_START_NOW (1 << 30)
2494 * If this flag is set, all the other fields are ignored (including
2495 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2496 * without reconfiguring any of the other hang detect settings.
2498 #define EC_HANG_STOP_NOW (1 << 31)
2500 struct ec_params_hang_detect {
2501 /* Flags; see EC_HANG_* */
2502 uint32_t flags;
2504 /* Timeout in msec before generating host event, if enabled */
2505 uint16_t host_event_timeout_msec;
2507 /* Timeout in msec before generating warm reboot, if enabled */
2508 uint16_t warm_reboot_timeout_msec;
2509 } __packed;
2511 /*****************************************************************************/
2512 /* Commands for battery charging */
2515 * This is the single catch-all host command to exchange data regarding the
2516 * charge state machine (v2 and up).
2518 #define EC_CMD_CHARGE_STATE 0xa0
2520 /* Subcommands for this host command */
2521 enum charge_state_command {
2522 CHARGE_STATE_CMD_GET_STATE,
2523 CHARGE_STATE_CMD_GET_PARAM,
2524 CHARGE_STATE_CMD_SET_PARAM,
2525 CHARGE_STATE_NUM_CMDS
2529 * Known param numbers are defined here. Ranges are reserved for board-specific
2530 * params, which are handled by the particular implementations.
2532 enum charge_state_params {
2533 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2534 CS_PARAM_CHG_CURRENT, /* charger current limit */
2535 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2536 CS_PARAM_CHG_STATUS, /* charger-specific status */
2537 CS_PARAM_CHG_OPTION, /* charger-specific options */
2538 /* How many so far? */
2539 CS_NUM_BASE_PARAMS,
2541 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2542 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2543 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2545 /* Other custom param ranges go here... */
2548 struct ec_params_charge_state {
2549 uint8_t cmd; /* enum charge_state_command */
2550 union {
2551 struct {
2552 /* no args */
2553 } get_state;
2555 struct {
2556 uint32_t param; /* enum charge_state_param */
2557 } get_param;
2559 struct {
2560 uint32_t param; /* param to set */
2561 uint32_t value; /* value to set */
2562 } set_param;
2564 } __packed;
2566 struct ec_response_charge_state {
2567 union {
2568 struct {
2569 int ac;
2570 int chg_voltage;
2571 int chg_current;
2572 int chg_input_current;
2573 int batt_state_of_charge;
2574 } get_state;
2576 struct {
2577 uint32_t value;
2578 } get_param;
2579 struct {
2580 /* no return values */
2581 } set_param;
2583 } __packed;
2587 * Set maximum battery charging current.
2589 #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2591 struct ec_params_current_limit {
2592 uint32_t limit; /* in mA */
2593 } __packed;
2596 * Set maximum external power current.
2598 #define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2600 struct ec_params_ext_power_current_limit {
2601 uint32_t limit; /* in mA */
2602 } __packed;
2604 /* Inform the EC when entering a sleep state */
2605 #define EC_CMD_HOST_SLEEP_EVENT 0xa9
2607 enum host_sleep_event {
2608 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2609 HOST_SLEEP_EVENT_S3_RESUME = 2,
2610 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2611 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2614 struct ec_params_host_sleep_event {
2615 uint8_t sleep_event;
2616 } __packed;
2618 /*****************************************************************************/
2619 /* Smart battery pass-through */
2621 /* Get / Set 16-bit smart battery registers */
2622 #define EC_CMD_SB_READ_WORD 0xb0
2623 #define EC_CMD_SB_WRITE_WORD 0xb1
2625 /* Get / Set string smart battery parameters
2626 * formatted as SMBUS "block".
2628 #define EC_CMD_SB_READ_BLOCK 0xb2
2629 #define EC_CMD_SB_WRITE_BLOCK 0xb3
2631 struct ec_params_sb_rd {
2632 uint8_t reg;
2633 } __packed;
2635 struct ec_response_sb_rd_word {
2636 uint16_t value;
2637 } __packed;
2639 struct ec_params_sb_wr_word {
2640 uint8_t reg;
2641 uint16_t value;
2642 } __packed;
2644 struct ec_response_sb_rd_block {
2645 uint8_t data[32];
2646 } __packed;
2648 struct ec_params_sb_wr_block {
2649 uint8_t reg;
2650 uint16_t data[32];
2651 } __packed;
2653 /*****************************************************************************/
2654 /* Battery vendor parameters
2656 * Get or set vendor-specific parameters in the battery. Implementations may
2657 * differ between boards or batteries. On a set operation, the response
2658 * contains the actual value set, which may be rounded or clipped from the
2659 * requested value.
2662 #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2664 enum ec_battery_vendor_param_mode {
2665 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2666 BATTERY_VENDOR_PARAM_MODE_SET,
2669 struct ec_params_battery_vendor_param {
2670 uint32_t param;
2671 uint32_t value;
2672 uint8_t mode;
2673 } __packed;
2675 struct ec_response_battery_vendor_param {
2676 uint32_t value;
2677 } __packed;
2679 /*****************************************************************************/
2680 /* System commands */
2683 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2684 * necessarily reboot the EC. Rename to "image" or something similar?
2686 #define EC_CMD_REBOOT_EC 0xd2
2688 /* Command */
2689 enum ec_reboot_cmd {
2690 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2691 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2692 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2693 /* (command 3 was jump to RW-B) */
2694 EC_REBOOT_COLD = 4, /* Cold-reboot */
2695 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2696 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2699 /* Flags for ec_params_reboot_ec.reboot_flags */
2700 #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2701 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2703 struct ec_params_reboot_ec {
2704 uint8_t cmd; /* enum ec_reboot_cmd */
2705 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2706 } __packed;
2709 * Get information on last EC panic.
2711 * Returns variable-length platform-dependent panic information. See panic.h
2712 * for details.
2714 #define EC_CMD_GET_PANIC_INFO 0xd3
2716 /*****************************************************************************/
2718 * ACPI commands
2720 * These are valid ONLY on the ACPI command/data port.
2724 * ACPI Read Embedded Controller
2726 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2728 * Use the following sequence:
2730 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
2731 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2732 * - Write address to EC_LPC_ADDR_ACPI_DATA
2733 * - Wait for EC_LPC_CMDR_DATA bit to set
2734 * - Read value from EC_LPC_ADDR_ACPI_DATA
2736 #define EC_CMD_ACPI_READ 0x80
2739 * ACPI Write Embedded Controller
2741 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2743 * Use the following sequence:
2745 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
2746 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2747 * - Write address to EC_LPC_ADDR_ACPI_DATA
2748 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2749 * - Write value to EC_LPC_ADDR_ACPI_DATA
2751 #define EC_CMD_ACPI_WRITE 0x81
2754 * ACPI Query Embedded Controller
2756 * This clears the lowest-order bit in the currently pending host events, and
2757 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
2758 * event 0x80000000 = 32), or 0 if no event was pending.
2760 #define EC_CMD_ACPI_QUERY_EVENT 0x84
2762 /* Valid addresses in ACPI memory space, for read/write commands */
2764 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
2765 #define EC_ACPI_MEM_VERSION 0x00
2767 * Test location; writing value here updates test compliment byte to (0xff -
2768 * value).
2770 #define EC_ACPI_MEM_TEST 0x01
2771 /* Test compliment; writes here are ignored. */
2772 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
2774 /* Keyboard backlight brightness percent (0 - 100) */
2775 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
2776 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
2777 #define EC_ACPI_MEM_FAN_DUTY 0x04
2780 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
2781 * independent thresholds attached to them. The current value of the ID
2782 * register determines which sensor is affected by the THRESHOLD and COMMIT
2783 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
2784 * as the memory-mapped sensors. The COMMIT register applies those settings.
2786 * The spec does not mandate any way to read back the threshold settings
2787 * themselves, but when a threshold is crossed the AP needs a way to determine
2788 * which sensor(s) are responsible. Each reading of the ID register clears and
2789 * returns one sensor ID that has crossed one of its threshold (in either
2790 * direction) since the last read. A value of 0xFF means "no new thresholds
2791 * have tripped". Setting or enabling the thresholds for a sensor will clear
2792 * the unread event count for that sensor.
2794 #define EC_ACPI_MEM_TEMP_ID 0x05
2795 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
2796 #define EC_ACPI_MEM_TEMP_COMMIT 0x07
2798 * Here are the bits for the COMMIT register:
2799 * bit 0 selects the threshold index for the chosen sensor (0/1)
2800 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
2801 * Each write to the commit register affects one threshold.
2803 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
2804 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
2806 * Example:
2808 * Set the thresholds for sensor 2 to 50 C and 60 C:
2809 * write 2 to [0x05] -- select temp sensor 2
2810 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
2811 * write 0x2 to [0x07] -- enable threshold 0 with this value
2812 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
2813 * write 0x3 to [0x07] -- enable threshold 1 with this value
2815 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
2816 * write 2 to [0x05] -- select temp sensor 2
2817 * write 0x1 to [0x07] -- disable threshold 1
2820 /* DPTF battery charging current limit */
2821 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
2823 /* Charging limit is specified in 64 mA steps */
2824 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
2825 /* Value to disable DPTF battery charging limit */
2826 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
2828 /* Current version of ACPI memory address space */
2829 #define EC_ACPI_MEM_VERSION_CURRENT 1
2832 /*****************************************************************************/
2834 * Special commands
2836 * These do not follow the normal rules for commands. See each command for
2837 * details.
2841 * Reboot NOW
2843 * This command will work even when the EC LPC interface is busy, because the
2844 * reboot command is processed at interrupt level. Note that when the EC
2845 * reboots, the host will reboot too, so there is no response to this command.
2847 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
2849 #define EC_CMD_REBOOT 0xd1 /* Think "die" */
2852 * Resend last response (not supported on LPC).
2854 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
2855 * there was no previous command, or the previous command's response was too
2856 * big to save.
2858 #define EC_CMD_RESEND_RESPONSE 0xdb
2861 * This header byte on a command indicate version 0. Any header byte less
2862 * than this means that we are talking to an old EC which doesn't support
2863 * versioning. In that case, we assume version 0.
2865 * Header bytes greater than this indicate a later version. For example,
2866 * EC_CMD_VERSION0 + 1 means we are using version 1.
2868 * The old EC interface must not use commands 0xdc or higher.
2870 #define EC_CMD_VERSION0 0xdc
2872 #endif /* !__ACPI__ */
2874 /*****************************************************************************/
2876 * PD commands
2878 * These commands are for PD MCU communication.
2881 /* EC to PD MCU exchange status command */
2882 #define EC_CMD_PD_EXCHANGE_STATUS 0x100
2884 /* Status of EC being sent to PD */
2885 struct ec_params_pd_status {
2886 int8_t batt_soc; /* battery state of charge */
2887 } __packed;
2889 /* Status of PD being sent back to EC */
2890 struct ec_response_pd_status {
2891 int8_t status; /* PD MCU status */
2892 uint32_t curr_lim_ma; /* input current limit */
2893 } __packed;
2895 /* Set USB type-C port role and muxes */
2896 #define EC_CMD_USB_PD_CONTROL 0x101
2898 enum usb_pd_control_role {
2899 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
2900 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
2901 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
2902 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
2903 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
2906 enum usb_pd_control_mux {
2907 USB_PD_CTRL_MUX_NO_CHANGE = 0,
2908 USB_PD_CTRL_MUX_NONE = 1,
2909 USB_PD_CTRL_MUX_USB = 2,
2910 USB_PD_CTRL_MUX_DP = 3,
2911 USB_PD_CTRL_MUX_DOCK = 4,
2912 USB_PD_CTRL_MUX_AUTO = 5,
2915 enum usb_pd_control_swap {
2916 USB_PD_CTRL_SWAP_NONE = 0,
2917 USB_PD_CTRL_SWAP_DATA = 1,
2918 USB_PD_CTRL_SWAP_POWER = 2,
2919 USB_PD_CTRL_SWAP_VCONN = 3,
2920 USB_PD_CTRL_SWAP_COUNT
2923 struct ec_params_usb_pd_control {
2924 uint8_t port;
2925 uint8_t role;
2926 uint8_t mux;
2927 uint8_t swap;
2928 } __packed;
2930 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
2931 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
2932 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
2934 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
2935 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
2936 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
2937 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
2938 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
2939 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
2940 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
2942 struct ec_response_usb_pd_control_v1 {
2943 uint8_t enabled;
2944 uint8_t role;
2945 uint8_t polarity;
2946 char state[32];
2947 } __packed;
2949 #define EC_CMD_USB_PD_PORTS 0x102
2951 struct ec_response_usb_pd_ports {
2952 uint8_t num_ports;
2953 } __packed;
2955 #define EC_CMD_USB_PD_POWER_INFO 0x103
2957 #define PD_POWER_CHARGING_PORT 0xff
2958 struct ec_params_usb_pd_power_info {
2959 uint8_t port;
2960 } __packed;
2962 enum usb_chg_type {
2963 USB_CHG_TYPE_NONE,
2964 USB_CHG_TYPE_PD,
2965 USB_CHG_TYPE_C,
2966 USB_CHG_TYPE_PROPRIETARY,
2967 USB_CHG_TYPE_BC12_DCP,
2968 USB_CHG_TYPE_BC12_CDP,
2969 USB_CHG_TYPE_BC12_SDP,
2970 USB_CHG_TYPE_OTHER,
2971 USB_CHG_TYPE_VBUS,
2972 USB_CHG_TYPE_UNKNOWN,
2975 struct usb_chg_measures {
2976 uint16_t voltage_max;
2977 uint16_t voltage_now;
2978 uint16_t current_max;
2979 uint16_t current_lim;
2980 } __packed;
2982 struct ec_response_usb_pd_power_info {
2983 uint8_t role;
2984 uint8_t type;
2985 uint8_t dualrole;
2986 uint8_t reserved1;
2987 struct usb_chg_measures meas;
2988 uint32_t max_power;
2989 } __packed;
2991 /* Get info about USB-C SS muxes */
2992 #define EC_CMD_USB_PD_MUX_INFO 0x11a
2994 struct ec_params_usb_pd_mux_info {
2995 uint8_t port; /* USB-C port number */
2996 } __packed;
2998 /* Flags representing mux state */
2999 #define USB_PD_MUX_USB_ENABLED (1 << 0)
3000 #define USB_PD_MUX_DP_ENABLED (1 << 1)
3001 #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3002 #define USB_PD_MUX_HPD_IRQ (1 << 3)
3004 struct ec_response_usb_pd_mux_info {
3005 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3006 } __packed;
3008 /*****************************************************************************/
3010 * Passthru commands
3012 * Some platforms have sub-processors chained to each other. For example.
3014 * AP <--> EC <--> PD MCU
3016 * The top 2 bits of the command number are used to indicate which device the
3017 * command is intended for. Device 0 is always the device receiving the
3018 * command; other device mapping is board-specific.
3020 * When a device receives a command to be passed to a sub-processor, it passes
3021 * it on with the device number set back to 0. This allows the sub-processor
3022 * to remain blissfully unaware of whether the command originated on the next
3023 * device up the chain, or was passed through from the AP.
3025 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3026 * AP sends command 0x4002 to the EC
3027 * EC sends command 0x0002 to the PD MCU
3028 * EC forwards PD MCU response back to the AP
3031 /* Offset and max command number for sub-device n */
3032 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3033 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3035 /*****************************************************************************/
3037 * Deprecated constants. These constants have been renamed for clarity. The
3038 * meaning and size has not changed. Programs that use the old names should
3039 * switch to the new names soon, as the old names may not be carried forward
3040 * forever.
3042 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3043 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3044 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3046 #endif /* __CROS_EC_COMMANDS_H */