Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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