1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Host communication command constants for ChromeOS EC 4 * 5 * Copyright (C) 2012 Google, Inc 6 * 7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from 8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h 9 */ 10 11 /* Host communication command constants for Chrome EC */ 12 13 #ifndef __CROS_EC_COMMANDS_H 14 #define __CROS_EC_COMMANDS_H 15 16 #include <linux/bits.h> 17 #include <linux/types.h> 18 19 #define BUILD_ASSERT(_cond) 20 21 /* 22 * Current version of this protocol 23 * 24 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is 25 * determined in other ways. Remove this once the kernel code no longer 26 * depends on it. 27 */ 28 #define EC_PROTO_VERSION 0x00000002 29 30 /* Command version mask */ 31 #define EC_VER_MASK(version) BIT(version) 32 33 /* I/O addresses for ACPI commands */ 34 #define EC_LPC_ADDR_ACPI_DATA 0x62 35 #define EC_LPC_ADDR_ACPI_CMD 0x66 36 37 /* I/O addresses for host command */ 38 #define EC_LPC_ADDR_HOST_DATA 0x200 39 #define EC_LPC_ADDR_HOST_CMD 0x204 40 41 /* I/O addresses for host command args and params */ 42 /* Protocol version 2 */ 43 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ 44 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is 45 * EC_PROTO2_MAX_PARAM_SIZE 46 */ 47 /* Protocol version 3 */ 48 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ 49 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */ 50 51 /* 52 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff 53 * and they tell the kernel that so we have to think of it as two parts. 54 * 55 * Other BIOSes report only the I/O port region spanned by the Microchip 56 * MEC series EC; an attempt to address a larger region may fail. 57 */ 58 #define EC_HOST_CMD_REGION0 0x800 59 #define EC_HOST_CMD_REGION1 0x880 60 #define EC_HOST_CMD_REGION_SIZE 0x80 61 #define EC_HOST_CMD_MEC_REGION_SIZE 0x8 62 63 /* EC command register bit functions */ 64 #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ 65 #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ 66 #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ 67 #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ 68 #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ 69 #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ 70 #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ 71 72 #define EC_LPC_ADDR_MEMMAP 0x900 73 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ 74 #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ 75 76 /* The offset address of each type of data in mapped memory. */ 77 #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ 78 #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ 79 #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ 80 #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ 81 #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ 82 #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ 83 #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ 84 #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ 85 #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ 86 #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ 87 /* Unused 0x28 - 0x2f */ 88 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ 89 /* Unused 0x31 - 0x33 */ 90 #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ 91 /* Battery values are all 32 bits, unless otherwise noted. */ 92 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ 93 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ 94 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ 95 #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ 96 #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ 97 #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ 98 /* Unused 0x4f */ 99 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ 100 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ 101 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ 102 #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ 103 /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ 104 #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ 105 #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ 106 #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ 107 #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ 108 #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ 109 /* Unused 0x84 - 0x8f */ 110 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ 111 /* Unused 0x91 */ 112 #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ 113 /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ 114 /* 0x94 - 0x99: 1st Accelerometer */ 115 /* 0x9a - 0x9f: 2nd Accelerometer */ 116 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ 117 /* Unused 0xa6 - 0xdf */ 118 119 /* 120 * ACPI is unable to access memory mapped data at or above this offset due to 121 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe 122 * which might be needed by ACPI. 123 */ 124 #define EC_MEMMAP_NO_ACPI 0xe0 125 126 /* Define the format of the accelerometer mapped memory status byte. */ 127 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f 128 #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) 129 #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) 130 131 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ 132 #define EC_TEMP_SENSOR_ENTRIES 16 133 /* 134 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. 135 * 136 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. 137 */ 138 #define EC_TEMP_SENSOR_B_ENTRIES 8 139 140 /* Special values for mapped temperature sensors */ 141 #define EC_TEMP_SENSOR_NOT_PRESENT 0xff 142 #define EC_TEMP_SENSOR_ERROR 0xfe 143 #define EC_TEMP_SENSOR_NOT_POWERED 0xfd 144 #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc 145 /* 146 * The offset of temperature value stored in mapped memory. This allows 147 * reporting a temperature range of 200K to 454K = -73C to 181C. 148 */ 149 #define EC_TEMP_SENSOR_OFFSET 200 150 151 /* 152 * Number of ALS readings at EC_MEMMAP_ALS 153 */ 154 #define EC_ALS_ENTRIES 2 155 156 /* 157 * The default value a temperature sensor will return when it is present but 158 * has not been read this boot. This is a reasonable number to avoid 159 * triggering alarms on the host. 160 */ 161 #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) 162 163 #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ 164 #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ 165 #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ 166 167 /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ 168 #define EC_BATT_FLAG_AC_PRESENT 0x01 169 #define EC_BATT_FLAG_BATT_PRESENT 0x02 170 #define EC_BATT_FLAG_DISCHARGING 0x04 171 #define EC_BATT_FLAG_CHARGING 0x08 172 #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 173 /* Set if some of the static/dynamic data is invalid (or outdated). */ 174 #define EC_BATT_FLAG_INVALID_DATA 0x20 175 176 /* Switch flags at EC_MEMMAP_SWITCHES */ 177 #define EC_SWITCH_LID_OPEN 0x01 178 #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 179 #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 180 /* Was recovery requested via keyboard; now unused. */ 181 #define EC_SWITCH_IGNORE1 0x08 182 /* Recovery requested via dedicated signal (from servo board) */ 183 #define EC_SWITCH_DEDICATED_RECOVERY 0x10 184 /* Was fake developer mode switch; now unused. Remove in next refactor. */ 185 #define EC_SWITCH_IGNORE0 0x20 186 187 /* Host command interface flags */ 188 /* Host command interface supports LPC args (LPC interface only) */ 189 #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 190 /* Host command interface supports version 3 protocol */ 191 #define EC_HOST_CMD_FLAG_VERSION_3 0x02 192 193 /* Wireless switch flags */ 194 #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ 195 #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ 196 #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ 197 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ 198 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ 199 200 /*****************************************************************************/ 201 /* 202 * ACPI commands 203 * 204 * These are valid ONLY on the ACPI command/data port. 205 */ 206 207 /* 208 * ACPI Read Embedded Controller 209 * 210 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). 211 * 212 * Use the following sequence: 213 * 214 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD 215 * - Wait for EC_LPC_CMDR_PENDING bit to clear 216 * - Write address to EC_LPC_ADDR_ACPI_DATA 217 * - Wait for EC_LPC_CMDR_DATA bit to set 218 * - Read value from EC_LPC_ADDR_ACPI_DATA 219 */ 220 #define EC_CMD_ACPI_READ 0x0080 221 222 /* 223 * ACPI Write Embedded Controller 224 * 225 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). 226 * 227 * Use the following sequence: 228 * 229 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD 230 * - Wait for EC_LPC_CMDR_PENDING bit to clear 231 * - Write address to EC_LPC_ADDR_ACPI_DATA 232 * - Wait for EC_LPC_CMDR_PENDING bit to clear 233 * - Write value to EC_LPC_ADDR_ACPI_DATA 234 */ 235 #define EC_CMD_ACPI_WRITE 0x0081 236 237 /* 238 * ACPI Burst Enable Embedded Controller 239 * 240 * This enables burst mode on the EC to allow the host to issue several 241 * commands back-to-back. While in this mode, writes to mapped multi-byte 242 * data are locked out to ensure data consistency. 243 */ 244 #define EC_CMD_ACPI_BURST_ENABLE 0x0082 245 246 /* 247 * ACPI Burst Disable Embedded Controller 248 * 249 * This disables burst mode on the EC and stops preventing EC writes to mapped 250 * multi-byte data. 251 */ 252 #define EC_CMD_ACPI_BURST_DISABLE 0x0083 253 254 /* 255 * ACPI Query Embedded Controller 256 * 257 * This clears the lowest-order bit in the currently pending host events, and 258 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, 259 * event 0x80000000 = 32), or 0 if no event was pending. 260 */ 261 #define EC_CMD_ACPI_QUERY_EVENT 0x0084 262 263 /* Valid addresses in ACPI memory space, for read/write commands */ 264 265 /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ 266 #define EC_ACPI_MEM_VERSION 0x00 267 /* 268 * Test location; writing value here updates test compliment byte to (0xff - 269 * value). 270 */ 271 #define EC_ACPI_MEM_TEST 0x01 272 /* Test compliment; writes here are ignored. */ 273 #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 274 275 /* Keyboard backlight brightness percent (0 - 100) */ 276 #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 277 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ 278 #define EC_ACPI_MEM_FAN_DUTY 0x04 279 280 /* 281 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two 282 * independent thresholds attached to them. The current value of the ID 283 * register determines which sensor is affected by the THRESHOLD and COMMIT 284 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme 285 * as the memory-mapped sensors. The COMMIT register applies those settings. 286 * 287 * The spec does not mandate any way to read back the threshold settings 288 * themselves, but when a threshold is crossed the AP needs a way to determine 289 * which sensor(s) are responsible. Each reading of the ID register clears and 290 * returns one sensor ID that has crossed one of its threshold (in either 291 * direction) since the last read. A value of 0xFF means "no new thresholds 292 * have tripped". Setting or enabling the thresholds for a sensor will clear 293 * the unread event count for that sensor. 294 */ 295 #define EC_ACPI_MEM_TEMP_ID 0x05 296 #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 297 #define EC_ACPI_MEM_TEMP_COMMIT 0x07 298 /* 299 * Here are the bits for the COMMIT register: 300 * bit 0 selects the threshold index for the chosen sensor (0/1) 301 * bit 1 enables/disables the selected threshold (0 = off, 1 = on) 302 * Each write to the commit register affects one threshold. 303 */ 304 #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) 305 #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) 306 /* 307 * Example: 308 * 309 * Set the thresholds for sensor 2 to 50 C and 60 C: 310 * write 2 to [0x05] -- select temp sensor 2 311 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET 312 * write 0x2 to [0x07] -- enable threshold 0 with this value 313 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET 314 * write 0x3 to [0x07] -- enable threshold 1 with this value 315 * 316 * Disable the 60 C threshold, leaving the 50 C threshold unchanged: 317 * write 2 to [0x05] -- select temp sensor 2 318 * write 0x1 to [0x07] -- disable threshold 1 319 */ 320 321 /* DPTF battery charging current limit */ 322 #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 323 324 /* Charging limit is specified in 64 mA steps */ 325 #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 326 /* Value to disable DPTF battery charging limit */ 327 #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff 328 329 /* 330 * Report device orientation 331 * Bits Definition 332 * 3:1 Device DPTF Profile Number (DDPN) 333 * 0 = Reserved for backward compatibility (indicates no valid 334 * profile number. Host should fall back to using TBMD). 335 * 1..7 = DPTF Profile number to indicate to host which table needs 336 * to be loaded. 337 * 0 Tablet Mode Device Indicator (TBMD) 338 */ 339 #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 340 #define EC_ACPI_MEM_TBMD_SHIFT 0 341 #define EC_ACPI_MEM_TBMD_MASK 0x1 342 #define EC_ACPI_MEM_DDPN_SHIFT 1 343 #define EC_ACPI_MEM_DDPN_MASK 0x7 344 345 /* 346 * Report device features. Uses the same format as the host command, except: 347 * 348 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set 349 * of features", which is of limited interest when the system is already 350 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since 351 * these are supported, it defaults to 0. 352 * This allows detecting the presence of this field since older versions of 353 * the EC codebase would simply return 0xff to that unknown address. Check 354 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits 355 * are valid. 356 */ 357 #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a 358 #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b 359 #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c 360 #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d 361 #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e 362 #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f 363 #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 364 #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 365 366 #define EC_ACPI_MEM_BATTERY_INDEX 0x12 367 368 /* 369 * USB Port Power. Each bit indicates whether the corresponding USB ports' power 370 * is enabled (1) or disabled (0). 371 * bit 0 USB port ID 0 372 * ... 373 * bit 7 USB port ID 7 374 */ 375 #define EC_ACPI_MEM_USB_PORT_POWER 0x13 376 377 /* 378 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data 379 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. 380 */ 381 #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 382 #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 383 384 /* Current version of ACPI memory address space */ 385 #define EC_ACPI_MEM_VERSION_CURRENT 2 386 387 388 /* 389 * This header file is used in coreboot both in C and ACPI code. The ACPI code 390 * is pre-processed to handle constants but the ASL compiler is unable to 391 * handle actual C code so keep it separate. 392 */ 393 394 395 /* 396 * Attributes for EC request and response packets. Just defining __packed 397 * results in inefficient assembly code on ARM, if the structure is actually 398 * 32-bit aligned, as it should be for all buffers. 399 * 400 * Be very careful when adding these to existing structures. They will round 401 * up the structure size to the specified boundary. 402 * 403 * Also be very careful to make that if a structure is included in some other 404 * parent structure that the alignment will still be true given the packing of 405 * the parent structure. This is particularly important if the sub-structure 406 * will be passed as a pointer to another function, since that function will 407 * not know about the misaligment caused by the parent structure's packing. 408 * 409 * Also be very careful using __packed - particularly when nesting non-packed 410 * structures inside packed ones. In fact, DO NOT use __packed directly; 411 * always use one of these attributes. 412 * 413 * Once everything is annotated properly, the following search strings should 414 * not return ANY matches in this file other than right here: 415 * 416 * "__packed" - generates inefficient code; all sub-structs must also be packed 417 * 418 * "struct [^_]" - all structs should be annotated, except for structs that are 419 * members of other structs/unions (and their original declarations should be 420 * annotated). 421 */ 422 423 /* 424 * Packed structures make no assumption about alignment, so they do inefficient 425 * byte-wise reads. 426 */ 427 #define __ec_align1 __packed 428 #define __ec_align2 __packed 429 #define __ec_align4 __packed 430 #define __ec_align_size1 __packed 431 #define __ec_align_offset1 __packed 432 #define __ec_align_offset2 __packed 433 #define __ec_todo_packed __packed 434 #define __ec_todo_unpacked 435 436 437 /* LPC command status byte masks */ 438 /* EC has written a byte in the data register and host hasn't read it yet */ 439 #define EC_LPC_STATUS_TO_HOST 0x01 440 /* Host has written a command/data byte and the EC hasn't read it yet */ 441 #define EC_LPC_STATUS_FROM_HOST 0x02 442 /* EC is processing a command */ 443 #define EC_LPC_STATUS_PROCESSING 0x04 444 /* Last write to EC was a command, not data */ 445 #define EC_LPC_STATUS_LAST_CMD 0x08 446 /* EC is in burst mode */ 447 #define EC_LPC_STATUS_BURST_MODE 0x10 448 /* SCI event is pending (requesting SCI query) */ 449 #define EC_LPC_STATUS_SCI_PENDING 0x20 450 /* SMI event is pending (requesting SMI query) */ 451 #define EC_LPC_STATUS_SMI_PENDING 0x40 452 /* (reserved) */ 453 #define EC_LPC_STATUS_RESERVED 0x80 454 455 /* 456 * EC is busy. This covers both the EC processing a command, and the host has 457 * written a new command but the EC hasn't picked it up yet. 458 */ 459 #define EC_LPC_STATUS_BUSY_MASK \ 460 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) 461 462 /* 463 * Host command response codes (16-bit). Note that response codes should be 464 * stored in a uint16_t rather than directly in a value of this type. 465 */ 466 enum ec_status { 467 EC_RES_SUCCESS = 0, 468 EC_RES_INVALID_COMMAND = 1, 469 EC_RES_ERROR = 2, 470 EC_RES_INVALID_PARAM = 3, 471 EC_RES_ACCESS_DENIED = 4, 472 EC_RES_INVALID_RESPONSE = 5, 473 EC_RES_INVALID_VERSION = 6, 474 EC_RES_INVALID_CHECKSUM = 7, 475 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ 476 EC_RES_UNAVAILABLE = 9, /* No response available */ 477 EC_RES_TIMEOUT = 10, /* We got a timeout */ 478 EC_RES_OVERFLOW = 11, /* Table / data overflow */ 479 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ 480 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ 481 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ 482 EC_RES_BUS_ERROR = 15, /* Communications bus error */ 483 EC_RES_BUSY = 16, /* Up but too busy. Should retry */ 484 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ 485 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ 486 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ 487 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ 488 }; 489 490 /* 491 * Host event codes. Note these are 1-based, not 0-based, because ACPI query 492 * EC command uses code 0 to mean "no event pending". We explicitly specify 493 * each value in the enum listing so they won't change if we delete/insert an 494 * item or rearrange the list (it needs to be stable across platforms, not 495 * just within a single compiled instance). 496 */ 497 enum host_event_code { 498 EC_HOST_EVENT_LID_CLOSED = 1, 499 EC_HOST_EVENT_LID_OPEN = 2, 500 EC_HOST_EVENT_POWER_BUTTON = 3, 501 EC_HOST_EVENT_AC_CONNECTED = 4, 502 EC_HOST_EVENT_AC_DISCONNECTED = 5, 503 EC_HOST_EVENT_BATTERY_LOW = 6, 504 EC_HOST_EVENT_BATTERY_CRITICAL = 7, 505 EC_HOST_EVENT_BATTERY = 8, 506 EC_HOST_EVENT_THERMAL_THRESHOLD = 9, 507 /* Event generated by a device attached to the EC */ 508 EC_HOST_EVENT_DEVICE = 10, 509 EC_HOST_EVENT_THERMAL = 11, 510 EC_HOST_EVENT_USB_CHARGER = 12, 511 EC_HOST_EVENT_KEY_PRESSED = 13, 512 /* 513 * EC has finished initializing the host interface. The host can check 514 * for this event following sending a EC_CMD_REBOOT_EC command to 515 * determine when the EC is ready to accept subsequent commands. 516 */ 517 EC_HOST_EVENT_INTERFACE_READY = 14, 518 /* Keyboard recovery combo has been pressed */ 519 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, 520 521 /* Shutdown due to thermal overload */ 522 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, 523 /* Shutdown due to battery level too low */ 524 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, 525 526 /* Suggest that the AP throttle itself */ 527 EC_HOST_EVENT_THROTTLE_START = 18, 528 /* Suggest that the AP resume normal speed */ 529 EC_HOST_EVENT_THROTTLE_STOP = 19, 530 531 /* Hang detect logic detected a hang and host event timeout expired */ 532 EC_HOST_EVENT_HANG_DETECT = 20, 533 /* Hang detect logic detected a hang and warm rebooted the AP */ 534 EC_HOST_EVENT_HANG_REBOOT = 21, 535 536 /* PD MCU triggering host event */ 537 EC_HOST_EVENT_PD_MCU = 22, 538 539 /* Battery Status flags have changed */ 540 EC_HOST_EVENT_BATTERY_STATUS = 23, 541 542 /* EC encountered a panic, triggering a reset */ 543 EC_HOST_EVENT_PANIC = 24, 544 545 /* Keyboard fastboot combo has been pressed */ 546 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, 547 548 /* EC RTC event occurred */ 549 EC_HOST_EVENT_RTC = 26, 550 551 /* Emulate MKBP event */ 552 EC_HOST_EVENT_MKBP = 27, 553 554 /* EC desires to change state of host-controlled USB mux */ 555 EC_HOST_EVENT_USB_MUX = 28, 556 557 /* TABLET/LAPTOP mode or detachable base attach/detach event */ 558 EC_HOST_EVENT_MODE_CHANGE = 29, 559 560 /* Keyboard recovery combo with hardware reinitialization */ 561 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, 562 563 /* WoV */ 564 EC_HOST_EVENT_WOV = 31, 565 566 /* 567 * The high bit of the event mask is not used as a host event code. If 568 * it reads back as set, then the entire event mask should be 569 * considered invalid by the host. This can happen when reading the 570 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is 571 * not initialized on the EC, or improperly configured on the host. 572 */ 573 EC_HOST_EVENT_INVALID = 32 574 }; 575 /* Host event mask */ 576 #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) 577 578 /** 579 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS 580 * @flags: The host argument flags. 581 * @command_version: Command version. 582 * @data_size: The length of data. 583 * @checksum: Checksum; sum of command + flags + command_version + data_size + 584 * all params/response data bytes. 585 */ 586 struct ec_lpc_host_args { 587 uint8_t flags; 588 uint8_t command_version; 589 uint8_t data_size; 590 uint8_t checksum; 591 } __ec_align4; 592 593 /* Flags for ec_lpc_host_args.flags */ 594 /* 595 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command 596 * params. 597 * 598 * If EC gets a command and this flag is not set, this is an old-style command. 599 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with 600 * unknown length. EC must respond with an old-style response (that is, 601 * without setting EC_HOST_ARGS_FLAG_TO_HOST). 602 */ 603 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 604 /* 605 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. 606 * 607 * If EC responds to a command and this flag is not set, this is an old-style 608 * response. Command version is 0 and response data from EC is at 609 * EC_LPC_ADDR_OLD_PARAM with unknown length. 610 */ 611 #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 612 613 /*****************************************************************************/ 614 /* 615 * Byte codes returned by EC over SPI interface. 616 * 617 * These can be used by the AP to debug the EC interface, and to determine 618 * when the EC is not in a state where it will ever get around to responding 619 * to the AP. 620 * 621 * Example of sequence of bytes read from EC for a current good transfer: 622 * 1. - - AP asserts chip select (CS#) 623 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request 624 * 3. - - EC starts handling CS# interrupt 625 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request 626 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in 627 * bytes looking for EC_SPI_FRAME_START 628 * 6. - - EC finishes processing and sets up response 629 * 7. EC_SPI_FRAME_START - AP reads frame byte 630 * 8. (response packet) - AP reads response packet 631 * 9. EC_SPI_PAST_END - Any additional bytes read by AP 632 * 10 - - AP deasserts chip select 633 * 11 - - EC processes CS# interrupt and sets up DMA for 634 * next request 635 * 636 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than 637 * the following byte values: 638 * EC_SPI_OLD_READY 639 * EC_SPI_RX_READY 640 * EC_SPI_RECEIVING 641 * EC_SPI_PROCESSING 642 * 643 * Then the EC found an error in the request, or was not ready for the request 644 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, 645 * because the EC is unable to tell when the AP is done sending its request. 646 */ 647 648 /* 649 * Framing byte which precedes a response packet from the EC. After sending a 650 * request, the AP will clock in bytes until it sees the framing byte, then 651 * clock in the response packet. 652 */ 653 #define EC_SPI_FRAME_START 0xec 654 655 /* 656 * Padding bytes which are clocked out after the end of a response packet. 657 */ 658 #define EC_SPI_PAST_END 0xed 659 660 /* 661 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects 662 * that the AP will send a valid packet header (starting with 663 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. 664 */ 665 #define EC_SPI_RX_READY 0xf8 666 667 /* 668 * EC has started receiving the request from the AP, but hasn't started 669 * processing it yet. 670 */ 671 #define EC_SPI_RECEIVING 0xf9 672 673 /* EC has received the entire request from the AP and is processing it. */ 674 #define EC_SPI_PROCESSING 0xfa 675 676 /* 677 * EC received bad data from the AP, such as a packet header with an invalid 678 * length. EC will ignore all data until chip select deasserts. 679 */ 680 #define EC_SPI_RX_BAD_DATA 0xfb 681 682 /* 683 * EC received data from the AP before it was ready. That is, the AP asserted 684 * chip select and started clocking data before the EC was ready to receive it. 685 * EC will ignore all data until chip select deasserts. 686 */ 687 #define EC_SPI_NOT_READY 0xfc 688 689 /* 690 * EC was ready to receive a request from the AP. EC has treated the byte sent 691 * by the AP as part of a request packet, or (for old-style ECs) is processing 692 * a fully received packet but is not ready to respond yet. 693 */ 694 #define EC_SPI_OLD_READY 0xfd 695 696 /*****************************************************************************/ 697 698 /* 699 * Protocol version 2 for I2C and SPI send a request this way: 700 * 701 * 0 EC_CMD_VERSION0 + (command version) 702 * 1 Command number 703 * 2 Length of params = N 704 * 3..N+2 Params, if any 705 * N+3 8-bit checksum of bytes 0..N+2 706 * 707 * The corresponding response is: 708 * 709 * 0 Result code (EC_RES_*) 710 * 1 Length of params = M 711 * 2..M+1 Params, if any 712 * M+2 8-bit checksum of bytes 0..M+1 713 */ 714 #define EC_PROTO2_REQUEST_HEADER_BYTES 3 715 #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 716 #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ 717 EC_PROTO2_REQUEST_TRAILER_BYTES) 718 719 #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 720 #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 721 #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ 722 EC_PROTO2_RESPONSE_TRAILER_BYTES) 723 724 /* Parameter length was limited by the LPC interface */ 725 #define EC_PROTO2_MAX_PARAM_SIZE 0xfc 726 727 /* Maximum request and response packet sizes for protocol version 2 */ 728 #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ 729 EC_PROTO2_MAX_PARAM_SIZE) 730 #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ 731 EC_PROTO2_MAX_PARAM_SIZE) 732 733 /*****************************************************************************/ 734 735 /* 736 * Value written to legacy command port / prefix byte to indicate protocol 737 * 3+ structs are being used. Usage is bus-dependent. 738 */ 739 #define EC_COMMAND_PROTOCOL_3 0xda 740 741 #define EC_HOST_REQUEST_VERSION 3 742 743 /** 744 * struct ec_host_request - Version 3 request from host. 745 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it 746 * receives a header with a version it doesn't know how to 747 * parse. 748 * @checksum: Checksum of request and data; sum of all bytes including checksum 749 * should total to 0. 750 * @command: Command to send (EC_CMD_...) 751 * @command_version: Command version. 752 * @reserved: Unused byte in current protocol version; set to 0. 753 * @data_len: Length of data which follows this header. 754 */ 755 struct ec_host_request { 756 uint8_t struct_version; 757 uint8_t checksum; 758 uint16_t command; 759 uint8_t command_version; 760 uint8_t reserved; 761 uint16_t data_len; 762 } __ec_align4; 763 764 #define EC_HOST_RESPONSE_VERSION 3 765 766 /** 767 * struct ec_host_response - Version 3 response from EC. 768 * @struct_version: Struct version (=3). 769 * @checksum: Checksum of response and data; sum of all bytes including 770 * checksum should total to 0. 771 * @result: EC's response to the command (separate from communication failure) 772 * @data_len: Length of data which follows this header. 773 * @reserved: Unused bytes in current protocol version; set to 0. 774 */ 775 struct ec_host_response { 776 uint8_t struct_version; 777 uint8_t checksum; 778 uint16_t result; 779 uint16_t data_len; 780 uint16_t reserved; 781 } __ec_align4; 782 783 /*****************************************************************************/ 784 785 /* 786 * Host command protocol V4. 787 * 788 * Packets always start with a request or response header. They are followed 789 * by data_len bytes of data. If the data_crc_present flag is set, the data 790 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1 791 * polynomial. 792 * 793 * Host algorithm when sending a request q: 794 * 795 * 101) tries_left=(some value, e.g. 3); 796 * 102) q.seq_num++ 797 * 103) q.seq_dup=0 798 * 104) Calculate q.header_crc. 799 * 105) Send request q to EC. 800 * 106) Wait for response r. Go to 201 if received or 301 if timeout. 801 * 802 * 201) If r.struct_version != 4, go to 301. 803 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. 804 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. 805 * 204) If r.seq_num != q.seq_num, go to 301. 806 * 205) If r.seq_dup == q.seq_dup, return success. 807 * 207) If r.seq_dup == 1, go to 301. 808 * 208) Return error. 809 * 810 * 301) If --tries_left <= 0, return error. 811 * 302) If q.seq_dup == 1, go to 105. 812 * 303) q.seq_dup = 1 813 * 304) Go to 104. 814 * 815 * EC algorithm when receiving a request q. 816 * EC has response buffer r, error buffer e. 817 * 818 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION 819 * and go to 301 820 * 102) If q.header_crc mismatches calculated CRC, set e.result = 821 * EC_RES_INVALID_HEADER_CRC and go to 301 822 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC 823 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC 824 * and go to 301. 825 * 104) If q.seq_dup == 0, go to 201. 826 * 105) If q.seq_num != r.seq_num, go to 201. 827 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. 828 * 829 * 201) Process request q into response r. 830 * 202) r.seq_num = q.seq_num 831 * 203) r.seq_dup = q.seq_dup 832 * 204) Calculate r.header_crc 833 * 205) If r.data_len > 0 and data is no longer available, set e.result = 834 * EC_RES_DUP_UNAVAILABLE and go to 301. 835 * 206) Send response r. 836 * 837 * 301) e.seq_num = q.seq_num 838 * 302) e.seq_dup = q.seq_dup 839 * 303) Calculate e.header_crc. 840 * 304) Send error response e. 841 */ 842 843 /* Version 4 request from host */ 844 struct ec_host_request4 { 845 /* 846 * bits 0-3: struct_version: Structure version (=4) 847 * bit 4: is_response: Is response (=0) 848 * bits 5-6: seq_num: Sequence number 849 * bit 7: seq_dup: Sequence duplicate flag 850 */ 851 uint8_t fields0; 852 853 /* 854 * bits 0-4: command_version: Command version 855 * bits 5-6: Reserved (set 0, ignore on read) 856 * bit 7: data_crc_present: Is data CRC present after data 857 */ 858 uint8_t fields1; 859 860 /* Command code (EC_CMD_*) */ 861 uint16_t command; 862 863 /* Length of data which follows this header (not including data CRC) */ 864 uint16_t data_len; 865 866 /* Reserved (set 0, ignore on read) */ 867 uint8_t reserved; 868 869 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ 870 uint8_t header_crc; 871 } __ec_align4; 872 873 /* Version 4 response from EC */ 874 struct ec_host_response4 { 875 /* 876 * bits 0-3: struct_version: Structure version (=4) 877 * bit 4: is_response: Is response (=1) 878 * bits 5-6: seq_num: Sequence number 879 * bit 7: seq_dup: Sequence duplicate flag 880 */ 881 uint8_t fields0; 882 883 /* 884 * bits 0-6: Reserved (set 0, ignore on read) 885 * bit 7: data_crc_present: Is data CRC present after data 886 */ 887 uint8_t fields1; 888 889 /* Result code (EC_RES_*) */ 890 uint16_t result; 891 892 /* Length of data which follows this header (not including data CRC) */ 893 uint16_t data_len; 894 895 /* Reserved (set 0, ignore on read) */ 896 uint8_t reserved; 897 898 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ 899 uint8_t header_crc; 900 } __ec_align4; 901 902 /* Fields in fields0 byte */ 903 #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f 904 #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 905 #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 906 #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 907 #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 908 909 /* Fields in fields1 byte */ 910 #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ 911 #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 912 913 /*****************************************************************************/ 914 /* 915 * Notes on commands: 916 * 917 * Each command is an 16-bit command value. Commands which take params or 918 * return response data specify structures for that data. If no structure is 919 * specified, the command does not input or output data, respectively. 920 * Parameter/response length is implicit in the structs. Some underlying 921 * communication protocols (I2C, SPI) may add length or checksum headers, but 922 * those are implementation-dependent and not defined here. 923 * 924 * All commands MUST be #defined to be 4-digit UPPER CASE hex values 925 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. 926 */ 927 928 /*****************************************************************************/ 929 /* General / test commands */ 930 931 /* 932 * Get protocol version, used to deal with non-backward compatible protocol 933 * changes. 934 */ 935 #define EC_CMD_PROTO_VERSION 0x0000 936 937 /** 938 * struct ec_response_proto_version - Response to the proto version command. 939 * @version: The protocol version. 940 */ 941 struct ec_response_proto_version { 942 uint32_t version; 943 } __ec_align4; 944 945 /* 946 * Hello. This is a simple command to test the EC is responsive to 947 * commands. 948 */ 949 #define EC_CMD_HELLO 0x0001 950 951 /** 952 * struct ec_params_hello - Parameters to the hello command. 953 * @in_data: Pass anything here. 954 */ 955 struct ec_params_hello { 956 uint32_t in_data; 957 } __ec_align4; 958 959 /** 960 * struct ec_response_hello - Response to the hello command. 961 * @out_data: Output will be in_data + 0x01020304. 962 */ 963 struct ec_response_hello { 964 uint32_t out_data; 965 } __ec_align4; 966 967 /* Get version number */ 968 #define EC_CMD_GET_VERSION 0x0002 969 970 enum ec_current_image { 971 EC_IMAGE_UNKNOWN = 0, 972 EC_IMAGE_RO, 973 EC_IMAGE_RW 974 }; 975 976 /** 977 * struct ec_response_get_version - Response to the get version command. 978 * @version_string_ro: Null-terminated RO firmware version string. 979 * @version_string_rw: Null-terminated RW firmware version string. 980 * @reserved: Unused bytes; was previously RW-B firmware version string. 981 * @current_image: One of ec_current_image. 982 */ 983 struct ec_response_get_version { 984 char version_string_ro[32]; 985 char version_string_rw[32]; 986 char reserved[32]; 987 uint32_t current_image; 988 } __ec_align4; 989 990 /* Read test */ 991 #define EC_CMD_READ_TEST 0x0003 992 993 /** 994 * struct ec_params_read_test - Parameters for the read test command. 995 * @offset: Starting value for read buffer. 996 * @size: Size to read in bytes. 997 */ 998 struct ec_params_read_test { 999 uint32_t offset; 1000 uint32_t size; 1001 } __ec_align4; 1002 1003 /** 1004 * struct ec_response_read_test - Response to the read test command. 1005 * @data: Data returned by the read test command. 1006 */ 1007 struct ec_response_read_test { 1008 uint32_t data[32]; 1009 } __ec_align4; 1010 1011 /* 1012 * Get build information 1013 * 1014 * Response is null-terminated string. 1015 */ 1016 #define EC_CMD_GET_BUILD_INFO 0x0004 1017 1018 /* Get chip info */ 1019 #define EC_CMD_GET_CHIP_INFO 0x0005 1020 1021 /** 1022 * struct ec_response_get_chip_info - Response to the get chip info command. 1023 * @vendor: Null-terminated string for chip vendor. 1024 * @name: Null-terminated string for chip name. 1025 * @revision: Null-terminated string for chip mask version. 1026 */ 1027 struct ec_response_get_chip_info { 1028 char vendor[32]; 1029 char name[32]; 1030 char revision[32]; 1031 } __ec_align4; 1032 1033 /* Get board HW version */ 1034 #define EC_CMD_GET_BOARD_VERSION 0x0006 1035 1036 /** 1037 * struct ec_response_board_version - Response to the board version command. 1038 * @board_version: A monotonously incrementing number. 1039 */ 1040 struct ec_response_board_version { 1041 uint16_t board_version; 1042 } __ec_align2; 1043 1044 /* 1045 * Read memory-mapped data. 1046 * 1047 * This is an alternate interface to memory-mapped data for bus protocols 1048 * which don't support direct-mapped memory - I2C, SPI, etc. 1049 * 1050 * Response is params.size bytes of data. 1051 */ 1052 #define EC_CMD_READ_MEMMAP 0x0007 1053 1054 /** 1055 * struct ec_params_read_memmap - Parameters for the read memory map command. 1056 * @offset: Offset in memmap (EC_MEMMAP_*). 1057 * @size: Size to read in bytes. 1058 */ 1059 struct ec_params_read_memmap { 1060 uint8_t offset; 1061 uint8_t size; 1062 } __ec_align1; 1063 1064 /* Read versions supported for a command */ 1065 #define EC_CMD_GET_CMD_VERSIONS 0x0008 1066 1067 /** 1068 * struct ec_params_get_cmd_versions - Parameters for the get command versions. 1069 * @cmd: Command to check. 1070 */ 1071 struct ec_params_get_cmd_versions { 1072 uint8_t cmd; 1073 } __ec_align1; 1074 1075 /** 1076 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command 1077 * versions (v1) 1078 * @cmd: Command to check. 1079 */ 1080 struct ec_params_get_cmd_versions_v1 { 1081 uint16_t cmd; 1082 } __ec_align2; 1083 1084 /** 1085 * struct ec_response_get_cmd_version - Response to the get command versions. 1086 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with 1087 * a desired version. 1088 */ 1089 struct ec_response_get_cmd_versions { 1090 uint32_t version_mask; 1091 } __ec_align4; 1092 1093 /* 1094 * Check EC communications status (busy). This is needed on i2c/spi but not 1095 * on lpc since it has its own out-of-band busy indicator. 1096 * 1097 * lpc must read the status from the command register. Attempting this on 1098 * lpc will overwrite the args/parameter space and corrupt its data. 1099 */ 1100 #define EC_CMD_GET_COMMS_STATUS 0x0009 1101 1102 /* Avoid using ec_status which is for return values */ 1103 enum ec_comms_status { 1104 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ 1105 }; 1106 1107 /** 1108 * struct ec_response_get_comms_status - Response to the get comms status 1109 * command. 1110 * @flags: Mask of enum ec_comms_status. 1111 */ 1112 struct ec_response_get_comms_status { 1113 uint32_t flags; /* Mask of enum ec_comms_status */ 1114 } __ec_align4; 1115 1116 /* Fake a variety of responses, purely for testing purposes. */ 1117 #define EC_CMD_TEST_PROTOCOL 0x000A 1118 1119 /* Tell the EC what to send back to us. */ 1120 struct ec_params_test_protocol { 1121 uint32_t ec_result; 1122 uint32_t ret_len; 1123 uint8_t buf[32]; 1124 } __ec_align4; 1125 1126 /* Here it comes... */ 1127 struct ec_response_test_protocol { 1128 uint8_t buf[32]; 1129 } __ec_align4; 1130 1131 /* Get protocol information */ 1132 #define EC_CMD_GET_PROTOCOL_INFO 0x000B 1133 1134 /* Flags for ec_response_get_protocol_info.flags */ 1135 /* EC_RES_IN_PROGRESS may be returned if a command is slow */ 1136 #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) 1137 1138 /** 1139 * struct ec_response_get_protocol_info - Response to the get protocol info. 1140 * @protocol_versions: Bitmask of protocol versions supported (1 << n means 1141 * version n). 1142 * @max_request_packet_size: Maximum request packet size in bytes. 1143 * @max_response_packet_size: Maximum response packet size in bytes. 1144 * @flags: see EC_PROTOCOL_INFO_* 1145 */ 1146 struct ec_response_get_protocol_info { 1147 /* Fields which exist if at least protocol version 3 supported */ 1148 uint32_t protocol_versions; 1149 uint16_t max_request_packet_size; 1150 uint16_t max_response_packet_size; 1151 uint32_t flags; 1152 } __ec_align4; 1153 1154 1155 /*****************************************************************************/ 1156 /* Get/Set miscellaneous values */ 1157 1158 /* The upper byte of .flags tells what to do (nothing means "get") */ 1159 #define EC_GSV_SET 0x80000000 1160 1161 /* 1162 * The lower three bytes of .flags identifies the parameter, if that has 1163 * meaning for an individual command. 1164 */ 1165 #define EC_GSV_PARAM_MASK 0x00ffffff 1166 1167 struct ec_params_get_set_value { 1168 uint32_t flags; 1169 uint32_t value; 1170 } __ec_align4; 1171 1172 struct ec_response_get_set_value { 1173 uint32_t flags; 1174 uint32_t value; 1175 } __ec_align4; 1176 1177 /* More than one command can use these structs to get/set parameters. */ 1178 #define EC_CMD_GSV_PAUSE_IN_S5 0x000C 1179 1180 /*****************************************************************************/ 1181 /* List the features supported by the firmware */ 1182 #define EC_CMD_GET_FEATURES 0x000D 1183 1184 /* Supported features */ 1185 enum ec_feature_code { 1186 /* 1187 * This image contains a limited set of features. Another image 1188 * in RW partition may support more features. 1189 */ 1190 EC_FEATURE_LIMITED = 0, 1191 /* 1192 * Commands for probing/reading/writing/erasing the flash in the 1193 * EC are present. 1194 */ 1195 EC_FEATURE_FLASH = 1, 1196 /* 1197 * Can control the fan speed directly. 1198 */ 1199 EC_FEATURE_PWM_FAN = 2, 1200 /* 1201 * Can control the intensity of the keyboard backlight. 1202 */ 1203 EC_FEATURE_PWM_KEYB = 3, 1204 /* 1205 * Support Google lightbar, introduced on Pixel. 1206 */ 1207 EC_FEATURE_LIGHTBAR = 4, 1208 /* Control of LEDs */ 1209 EC_FEATURE_LED = 5, 1210 /* Exposes an interface to control gyro and sensors. 1211 * The host goes through the EC to access these sensors. 1212 * In addition, the EC may provide composite sensors, like lid angle. 1213 */ 1214 EC_FEATURE_MOTION_SENSE = 6, 1215 /* The keyboard is controlled by the EC */ 1216 EC_FEATURE_KEYB = 7, 1217 /* The AP can use part of the EC flash as persistent storage. */ 1218 EC_FEATURE_PSTORE = 8, 1219 /* The EC monitors BIOS port 80h, and can return POST codes. */ 1220 EC_FEATURE_PORT80 = 9, 1221 /* 1222 * Thermal management: include TMP specific commands. 1223 * Higher level than direct fan control. 1224 */ 1225 EC_FEATURE_THERMAL = 10, 1226 /* Can switch the screen backlight on/off */ 1227 EC_FEATURE_BKLIGHT_SWITCH = 11, 1228 /* Can switch the wifi module on/off */ 1229 EC_FEATURE_WIFI_SWITCH = 12, 1230 /* Monitor host events, through for example SMI or SCI */ 1231 EC_FEATURE_HOST_EVENTS = 13, 1232 /* The EC exposes GPIO commands to control/monitor connected devices. */ 1233 EC_FEATURE_GPIO = 14, 1234 /* The EC can send i2c messages to downstream devices. */ 1235 EC_FEATURE_I2C = 15, 1236 /* Command to control charger are included */ 1237 EC_FEATURE_CHARGER = 16, 1238 /* Simple battery support. */ 1239 EC_FEATURE_BATTERY = 17, 1240 /* 1241 * Support Smart battery protocol 1242 * (Common Smart Battery System Interface Specification) 1243 */ 1244 EC_FEATURE_SMART_BATTERY = 18, 1245 /* EC can detect when the host hangs. */ 1246 EC_FEATURE_HANG_DETECT = 19, 1247 /* Report power information, for pit only */ 1248 EC_FEATURE_PMU = 20, 1249 /* Another Cros EC device is present downstream of this one */ 1250 EC_FEATURE_SUB_MCU = 21, 1251 /* Support USB Power delivery (PD) commands */ 1252 EC_FEATURE_USB_PD = 22, 1253 /* Control USB multiplexer, for audio through USB port for instance. */ 1254 EC_FEATURE_USB_MUX = 23, 1255 /* Motion Sensor code has an internal software FIFO */ 1256 EC_FEATURE_MOTION_SENSE_FIFO = 24, 1257 /* Support temporary secure vstore */ 1258 EC_FEATURE_VSTORE = 25, 1259 /* EC decides on USB-C SS mux state, muxes configured by host */ 1260 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, 1261 /* EC has RTC feature that can be controlled by host commands */ 1262 EC_FEATURE_RTC = 27, 1263 /* The MCU exposes a Fingerprint sensor */ 1264 EC_FEATURE_FINGERPRINT = 28, 1265 /* The MCU exposes a Touchpad */ 1266 EC_FEATURE_TOUCHPAD = 29, 1267 /* The MCU has RWSIG task enabled */ 1268 EC_FEATURE_RWSIG = 30, 1269 /* EC has device events support */ 1270 EC_FEATURE_DEVICE_EVENT = 31, 1271 /* EC supports the unified wake masks for LPC/eSPI systems */ 1272 EC_FEATURE_UNIFIED_WAKE_MASKS = 32, 1273 /* EC supports 64-bit host events */ 1274 EC_FEATURE_HOST_EVENT64 = 33, 1275 /* EC runs code in RAM (not in place, a.k.a. XIP) */ 1276 EC_FEATURE_EXEC_IN_RAM = 34, 1277 /* EC supports CEC commands */ 1278 EC_FEATURE_CEC = 35, 1279 /* EC supports tight sensor timestamping. */ 1280 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, 1281 /* 1282 * EC supports tablet mode detection aligned to Chrome and allows 1283 * setting of threshold by host command using 1284 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. 1285 */ 1286 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, 1287 /* The MCU is a System Companion Processor (SCP). */ 1288 EC_FEATURE_SCP = 39, 1289 /* The MCU is an Integrated Sensor Hub */ 1290 EC_FEATURE_ISH = 40, 1291 /* New TCPMv2 TYPEC_ prefaced commands supported */ 1292 EC_FEATURE_TYPEC_CMD = 41, 1293 /* 1294 * The EC will wait for direction from the AP to enter Type-C alternate 1295 * modes or USB4. 1296 */ 1297 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, 1298 /* 1299 * The EC will wait for an acknowledge from the AP after setting the 1300 * mux. 1301 */ 1302 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, 1303 /* The MCU is a System Companion Processor (SCP) 2nd Core. */ 1304 EC_FEATURE_SCP_C1 = 45, 1305 }; 1306 1307 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) 1308 #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) 1309 1310 struct ec_response_get_features { 1311 uint32_t flags[2]; 1312 } __ec_align4; 1313 1314 /*****************************************************************************/ 1315 /* Get the board's SKU ID from EC */ 1316 #define EC_CMD_GET_SKU_ID 0x000E 1317 1318 /* Set SKU ID from AP */ 1319 #define EC_CMD_SET_SKU_ID 0x000F 1320 1321 struct ec_sku_id_info { 1322 uint32_t sku_id; 1323 } __ec_align4; 1324 1325 /*****************************************************************************/ 1326 /* Flash commands */ 1327 1328 /* Get flash info */ 1329 #define EC_CMD_FLASH_INFO 0x0010 1330 #define EC_VER_FLASH_INFO 2 1331 1332 /** 1333 * struct ec_response_flash_info - Response to the flash info command. 1334 * @flash_size: Usable flash size in bytes. 1335 * @write_block_size: Write block size. Write offset and size must be a 1336 * multiple of this. 1337 * @erase_block_size: Erase block size. Erase offset and size must be a 1338 * multiple of this. 1339 * @protect_block_size: Protection block size. Protection offset and size 1340 * must be a multiple of this. 1341 * 1342 * Version 0 returns these fields. 1343 */ 1344 struct ec_response_flash_info { 1345 uint32_t flash_size; 1346 uint32_t write_block_size; 1347 uint32_t erase_block_size; 1348 uint32_t protect_block_size; 1349 } __ec_align4; 1350 1351 /* 1352 * Flags for version 1+ flash info command 1353 * EC flash erases bits to 0 instead of 1. 1354 */ 1355 #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) 1356 1357 /* 1358 * Flash must be selected for read/write/erase operations to succeed. This may 1359 * be necessary on a chip where write/erase can be corrupted by other board 1360 * activity, or where the chip needs to enable some sort of programming voltage, 1361 * or where the read/write/erase operations require cleanly suspending other 1362 * chip functionality. 1363 */ 1364 #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) 1365 1366 /** 1367 * struct ec_response_flash_info_1 - Response to the flash info v1 command. 1368 * @flash_size: Usable flash size in bytes. 1369 * @write_block_size: Write block size. Write offset and size must be a 1370 * multiple of this. 1371 * @erase_block_size: Erase block size. Erase offset and size must be a 1372 * multiple of this. 1373 * @protect_block_size: Protection block size. Protection offset and size 1374 * must be a multiple of this. 1375 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if 1376 * size is exactly this and offset is a multiple of this. 1377 * For example, an EC may have a write buffer which can do 1378 * half-page operations if data is aligned, and a slower 1379 * word-at-a-time write mode. 1380 * @flags: Flags; see EC_FLASH_INFO_* 1381 * 1382 * Version 1 returns the same initial fields as version 0, with additional 1383 * fields following. 1384 * 1385 * gcc anonymous structs don't seem to get along with the __packed directive; 1386 * if they did we'd define the version 0 structure as a sub-structure of this 1387 * one. 1388 * 1389 * Version 2 supports flash banks of different sizes: 1390 * The caller specified the number of banks it has preallocated 1391 * (num_banks_desc) 1392 * The EC returns the number of banks describing the flash memory. 1393 * It adds banks descriptions up to num_banks_desc. 1394 */ 1395 struct ec_response_flash_info_1 { 1396 /* Version 0 fields; see above for description */ 1397 uint32_t flash_size; 1398 uint32_t write_block_size; 1399 uint32_t erase_block_size; 1400 uint32_t protect_block_size; 1401 1402 /* Version 1 adds these fields: */ 1403 uint32_t write_ideal_size; 1404 uint32_t flags; 1405 } __ec_align4; 1406 1407 struct ec_params_flash_info_2 { 1408 /* Number of banks to describe */ 1409 uint16_t num_banks_desc; 1410 /* Reserved; set 0; ignore on read */ 1411 uint8_t reserved[2]; 1412 } __ec_align4; 1413 1414 struct ec_flash_bank { 1415 /* Number of sector is in this bank. */ 1416 uint16_t count; 1417 /* Size in power of 2 of each sector (8 --> 256 bytes) */ 1418 uint8_t size_exp; 1419 /* Minimal write size for the sectors in this bank */ 1420 uint8_t write_size_exp; 1421 /* Erase size for the sectors in this bank */ 1422 uint8_t erase_size_exp; 1423 /* Size for write protection, usually identical to erase size. */ 1424 uint8_t protect_size_exp; 1425 /* Reserved; set 0; ignore on read */ 1426 uint8_t reserved[2]; 1427 }; 1428 1429 struct ec_response_flash_info_2 { 1430 /* Total flash in the EC. */ 1431 uint32_t flash_size; 1432 /* Flags; see EC_FLASH_INFO_* */ 1433 uint32_t flags; 1434 /* Maximum size to use to send data to write to the EC. */ 1435 uint32_t write_ideal_size; 1436 /* Number of banks present in the EC. */ 1437 uint16_t num_banks_total; 1438 /* Number of banks described in banks array. */ 1439 uint16_t num_banks_desc; 1440 struct ec_flash_bank banks[]; 1441 } __ec_align4; 1442 1443 /* 1444 * Read flash 1445 * 1446 * Response is params.size bytes of data. 1447 */ 1448 #define EC_CMD_FLASH_READ 0x0011 1449 1450 /** 1451 * struct ec_params_flash_read - Parameters for the flash read command. 1452 * @offset: Byte offset to read. 1453 * @size: Size to read in bytes. 1454 */ 1455 struct ec_params_flash_read { 1456 uint32_t offset; 1457 uint32_t size; 1458 } __ec_align4; 1459 1460 /* Write flash */ 1461 #define EC_CMD_FLASH_WRITE 0x0012 1462 #define EC_VER_FLASH_WRITE 1 1463 1464 /* Version 0 of the flash command supported only 64 bytes of data */ 1465 #define EC_FLASH_WRITE_VER0_SIZE 64 1466 1467 /** 1468 * struct ec_params_flash_write - Parameters for the flash write command. 1469 * @offset: Byte offset to write. 1470 * @size: Size to write in bytes. 1471 */ 1472 struct ec_params_flash_write { 1473 uint32_t offset; 1474 uint32_t size; 1475 /* Followed by data to write */ 1476 } __ec_align4; 1477 1478 /* Erase flash */ 1479 #define EC_CMD_FLASH_ERASE 0x0013 1480 1481 /** 1482 * struct ec_params_flash_erase - Parameters for the flash erase command, v0. 1483 * @offset: Byte offset to erase. 1484 * @size: Size to erase in bytes. 1485 */ 1486 struct ec_params_flash_erase { 1487 uint32_t offset; 1488 uint32_t size; 1489 } __ec_align4; 1490 1491 /* 1492 * v1 add async erase: 1493 * subcommands can returns: 1494 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). 1495 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. 1496 * EC_RES_ERROR : other errors. 1497 * EC_RES_BUSY : an existing erase operation is in progress. 1498 * EC_RES_ACCESS_DENIED: Trying to erase running image. 1499 * 1500 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just 1501 * properly queued. The user must call ERASE_GET_RESULT subcommand to get 1502 * the proper result. 1503 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send 1504 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. 1505 * ERASE_GET_RESULT command may timeout on EC where flash access is not 1506 * permitted while erasing. (For instance, STM32F4). 1507 */ 1508 enum ec_flash_erase_cmd { 1509 FLASH_ERASE_SECTOR, /* Erase and wait for result */ 1510 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ 1511 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ 1512 }; 1513 1514 /** 1515 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. 1516 * @cmd: One of ec_flash_erase_cmd. 1517 * @reserved: Pad byte; currently always contains 0. 1518 * @flag: No flags defined yet; set to 0. 1519 * @params: Same as v0 parameters. 1520 */ 1521 struct ec_params_flash_erase_v1 { 1522 uint8_t cmd; 1523 uint8_t reserved; 1524 uint16_t flag; 1525 struct ec_params_flash_erase params; 1526 } __ec_align4; 1527 1528 /* 1529 * Get/set flash protection. 1530 * 1531 * If mask!=0, sets/clear the requested bits of flags. Depending on the 1532 * firmware write protect GPIO, not all flags will take effect immediately; 1533 * some flags require a subsequent hard reset to take effect. Check the 1534 * returned flags bits to see what actually happened. 1535 * 1536 * If mask=0, simply returns the current flags state. 1537 */ 1538 #define EC_CMD_FLASH_PROTECT 0x0015 1539 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ 1540 1541 /* Flags for flash protection */ 1542 /* RO flash code protected when the EC boots */ 1543 #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) 1544 /* 1545 * RO flash code protected now. If this bit is set, at-boot status cannot 1546 * be changed. 1547 */ 1548 #define EC_FLASH_PROTECT_RO_NOW BIT(1) 1549 /* Entire flash code protected now, until reboot. */ 1550 #define EC_FLASH_PROTECT_ALL_NOW BIT(2) 1551 /* Flash write protect GPIO is asserted now */ 1552 #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) 1553 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ 1554 #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) 1555 /* 1556 * Error - flash protection is in inconsistent state. At least one bank of 1557 * flash which should be protected is not protected. Usually fixed by 1558 * re-requesting the desired flags, or by a hard reset if that fails. 1559 */ 1560 #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) 1561 /* Entire flash code protected when the EC boots */ 1562 #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) 1563 /* RW flash code protected when the EC boots */ 1564 #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) 1565 /* RW flash code protected now. */ 1566 #define EC_FLASH_PROTECT_RW_NOW BIT(8) 1567 /* Rollback information flash region protected when the EC boots */ 1568 #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) 1569 /* Rollback information flash region protected now */ 1570 #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) 1571 1572 1573 /** 1574 * struct ec_params_flash_protect - Parameters for the flash protect command. 1575 * @mask: Bits in flags to apply. 1576 * @flags: New flags to apply. 1577 */ 1578 struct ec_params_flash_protect { 1579 uint32_t mask; 1580 uint32_t flags; 1581 } __ec_align4; 1582 1583 /** 1584 * struct ec_response_flash_protect - Response to the flash protect command. 1585 * @flags: Current value of flash protect flags. 1586 * @valid_flags: Flags which are valid on this platform. This allows the 1587 * caller to distinguish between flags which aren't set vs. flags 1588 * which can't be set on this platform. 1589 * @writable_flags: Flags which can be changed given the current protection 1590 * state. 1591 */ 1592 struct ec_response_flash_protect { 1593 uint32_t flags; 1594 uint32_t valid_flags; 1595 uint32_t writable_flags; 1596 } __ec_align4; 1597 1598 /* 1599 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash 1600 * write protect. These commands may be reused with version > 0. 1601 */ 1602 1603 /* Get the region offset/size */ 1604 #define EC_CMD_FLASH_REGION_INFO 0x0016 1605 #define EC_VER_FLASH_REGION_INFO 1 1606 1607 enum ec_flash_region { 1608 /* Region which holds read-only EC image */ 1609 EC_FLASH_REGION_RO = 0, 1610 /* 1611 * Region which holds active RW image. 'Active' is different from 1612 * 'running'. Active means 'scheduled-to-run'. Since RO image always 1613 * scheduled to run, active/non-active applies only to RW images (for 1614 * the same reason 'update' applies only to RW images. It's a state of 1615 * an image on a flash. Running image can be RO, RW_A, RW_B but active 1616 * image can only be RW_A or RW_B. In recovery mode, an active RW image 1617 * doesn't enter 'running' state but it's still active on a flash. 1618 */ 1619 EC_FLASH_REGION_ACTIVE, 1620 /* 1621 * Region which should be write-protected in the factory (a superset of 1622 * EC_FLASH_REGION_RO) 1623 */ 1624 EC_FLASH_REGION_WP_RO, 1625 /* Region which holds updatable (non-active) RW image */ 1626 EC_FLASH_REGION_UPDATE, 1627 /* Number of regions */ 1628 EC_FLASH_REGION_COUNT, 1629 }; 1630 /* 1631 * 'RW' is vague if there are multiple RW images; we mean the active one, 1632 * so the old constant is deprecated. 1633 */ 1634 #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE 1635 1636 /** 1637 * struct ec_params_flash_region_info - Parameters for the flash region info 1638 * command. 1639 * @region: Flash region; see EC_FLASH_REGION_* 1640 */ 1641 struct ec_params_flash_region_info { 1642 uint32_t region; 1643 } __ec_align4; 1644 1645 struct ec_response_flash_region_info { 1646 uint32_t offset; 1647 uint32_t size; 1648 } __ec_align4; 1649 1650 /* Read/write VbNvContext */ 1651 #define EC_CMD_VBNV_CONTEXT 0x0017 1652 #define EC_VER_VBNV_CONTEXT 1 1653 #define EC_VBNV_BLOCK_SIZE 16 1654 1655 enum ec_vbnvcontext_op { 1656 EC_VBNV_CONTEXT_OP_READ, 1657 EC_VBNV_CONTEXT_OP_WRITE, 1658 }; 1659 1660 struct ec_params_vbnvcontext { 1661 uint32_t op; 1662 uint8_t block[EC_VBNV_BLOCK_SIZE]; 1663 } __ec_align4; 1664 1665 struct ec_response_vbnvcontext { 1666 uint8_t block[EC_VBNV_BLOCK_SIZE]; 1667 } __ec_align4; 1668 1669 1670 /* Get SPI flash information */ 1671 #define EC_CMD_FLASH_SPI_INFO 0x0018 1672 1673 struct ec_response_flash_spi_info { 1674 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ 1675 uint8_t jedec[3]; 1676 1677 /* Pad byte; currently always contains 0 */ 1678 uint8_t reserved0; 1679 1680 /* Manufacturer / device ID from command 0x90 */ 1681 uint8_t mfr_dev_id[2]; 1682 1683 /* Status registers from command 0x05 and 0x35 */ 1684 uint8_t sr1, sr2; 1685 } __ec_align1; 1686 1687 1688 /* Select flash during flash operations */ 1689 #define EC_CMD_FLASH_SELECT 0x0019 1690 1691 /** 1692 * struct ec_params_flash_select - Parameters for the flash select command. 1693 * @select: 1 to select flash, 0 to deselect flash 1694 */ 1695 struct ec_params_flash_select { 1696 uint8_t select; 1697 } __ec_align4; 1698 1699 1700 /*****************************************************************************/ 1701 /* PWM commands */ 1702 1703 /* Get fan target RPM */ 1704 #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 1705 1706 struct ec_response_pwm_get_fan_rpm { 1707 uint32_t rpm; 1708 } __ec_align4; 1709 1710 /* Set target fan RPM */ 1711 #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 1712 1713 /* Version 0 of input params */ 1714 struct ec_params_pwm_set_fan_target_rpm_v0 { 1715 uint32_t rpm; 1716 } __ec_align4; 1717 1718 /* Version 1 of input params */ 1719 struct ec_params_pwm_set_fan_target_rpm_v1 { 1720 uint32_t rpm; 1721 uint8_t fan_idx; 1722 } __ec_align_size1; 1723 1724 /* Get keyboard backlight */ 1725 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ 1726 #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 1727 1728 struct ec_response_pwm_get_keyboard_backlight { 1729 uint8_t percent; 1730 uint8_t enabled; 1731 } __ec_align1; 1732 1733 /* Set keyboard backlight */ 1734 /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ 1735 #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 1736 1737 struct ec_params_pwm_set_keyboard_backlight { 1738 uint8_t percent; 1739 } __ec_align1; 1740 1741 /* Set target fan PWM duty cycle */ 1742 #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 1743 1744 /* Version 0 of input params */ 1745 struct ec_params_pwm_set_fan_duty_v0 { 1746 uint32_t percent; 1747 } __ec_align4; 1748 1749 /* Version 1 of input params */ 1750 struct ec_params_pwm_set_fan_duty_v1 { 1751 uint32_t percent; 1752 uint8_t fan_idx; 1753 } __ec_align_size1; 1754 1755 #define EC_CMD_PWM_SET_DUTY 0x0025 1756 /* 16 bit duty cycle, 0xffff = 100% */ 1757 #define EC_PWM_MAX_DUTY 0xffff 1758 1759 enum ec_pwm_type { 1760 /* All types, indexed by board-specific enum pwm_channel */ 1761 EC_PWM_TYPE_GENERIC = 0, 1762 /* Keyboard backlight */ 1763 EC_PWM_TYPE_KB_LIGHT, 1764 /* Display backlight */ 1765 EC_PWM_TYPE_DISPLAY_LIGHT, 1766 EC_PWM_TYPE_COUNT, 1767 }; 1768 1769 struct ec_params_pwm_set_duty { 1770 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 1771 uint8_t pwm_type; /* ec_pwm_type */ 1772 uint8_t index; /* Type-specific index, or 0 if unique */ 1773 } __ec_align4; 1774 1775 #define EC_CMD_PWM_GET_DUTY 0x0026 1776 1777 struct ec_params_pwm_get_duty { 1778 uint8_t pwm_type; /* ec_pwm_type */ 1779 uint8_t index; /* Type-specific index, or 0 if unique */ 1780 } __ec_align1; 1781 1782 struct ec_response_pwm_get_duty { 1783 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 1784 } __ec_align2; 1785 1786 /*****************************************************************************/ 1787 /* 1788 * Lightbar commands. This looks worse than it is. Since we only use one HOST 1789 * command to say "talk to the lightbar", we put the "and tell it to do X" part 1790 * into a subcommand. We'll make separate structs for subcommands with 1791 * different input args, so that we know how much to expect. 1792 */ 1793 #define EC_CMD_LIGHTBAR_CMD 0x0028 1794 1795 struct rgb_s { 1796 uint8_t r, g, b; 1797 } __ec_todo_unpacked; 1798 1799 #define LB_BATTERY_LEVELS 4 1800 1801 /* 1802 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a 1803 * host command, but the alignment is the same regardless. Keep it that way. 1804 */ 1805 struct lightbar_params_v0 { 1806 /* Timing */ 1807 int32_t google_ramp_up; 1808 int32_t google_ramp_down; 1809 int32_t s3s0_ramp_up; 1810 int32_t s0_tick_delay[2]; /* AC=0/1 */ 1811 int32_t s0a_tick_delay[2]; /* AC=0/1 */ 1812 int32_t s0s3_ramp_down; 1813 int32_t s3_sleep_for; 1814 int32_t s3_ramp_up; 1815 int32_t s3_ramp_down; 1816 1817 /* Oscillation */ 1818 uint8_t new_s0; 1819 uint8_t osc_min[2]; /* AC=0/1 */ 1820 uint8_t osc_max[2]; /* AC=0/1 */ 1821 uint8_t w_ofs[2]; /* AC=0/1 */ 1822 1823 /* Brightness limits based on the backlight and AC. */ 1824 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ 1825 uint8_t bright_bl_on_min[2]; /* AC=0/1 */ 1826 uint8_t bright_bl_on_max[2]; /* AC=0/1 */ 1827 1828 /* Battery level thresholds */ 1829 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; 1830 1831 /* Map [AC][battery_level] to color index */ 1832 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ 1833 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ 1834 1835 /* Color palette */ 1836 struct rgb_s color[8]; /* 0-3 are Google colors */ 1837 } __ec_todo_packed; 1838 1839 struct lightbar_params_v1 { 1840 /* Timing */ 1841 int32_t google_ramp_up; 1842 int32_t google_ramp_down; 1843 int32_t s3s0_ramp_up; 1844 int32_t s0_tick_delay[2]; /* AC=0/1 */ 1845 int32_t s0a_tick_delay[2]; /* AC=0/1 */ 1846 int32_t s0s3_ramp_down; 1847 int32_t s3_sleep_for; 1848 int32_t s3_ramp_up; 1849 int32_t s3_ramp_down; 1850 int32_t s5_ramp_up; 1851 int32_t s5_ramp_down; 1852 int32_t tap_tick_delay; 1853 int32_t tap_gate_delay; 1854 int32_t tap_display_time; 1855 1856 /* Tap-for-battery params */ 1857 uint8_t tap_pct_red; 1858 uint8_t tap_pct_green; 1859 uint8_t tap_seg_min_on; 1860 uint8_t tap_seg_max_on; 1861 uint8_t tap_seg_osc; 1862 uint8_t tap_idx[3]; 1863 1864 /* Oscillation */ 1865 uint8_t osc_min[2]; /* AC=0/1 */ 1866 uint8_t osc_max[2]; /* AC=0/1 */ 1867 uint8_t w_ofs[2]; /* AC=0/1 */ 1868 1869 /* Brightness limits based on the backlight and AC. */ 1870 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ 1871 uint8_t bright_bl_on_min[2]; /* AC=0/1 */ 1872 uint8_t bright_bl_on_max[2]; /* AC=0/1 */ 1873 1874 /* Battery level thresholds */ 1875 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; 1876 1877 /* Map [AC][battery_level] to color index */ 1878 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ 1879 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ 1880 1881 /* s5: single color pulse on inhibited power-up */ 1882 uint8_t s5_idx; 1883 1884 /* Color palette */ 1885 struct rgb_s color[8]; /* 0-3 are Google colors */ 1886 } __ec_todo_packed; 1887 1888 /* Lightbar command params v2 1889 * crbug.com/467716 1890 * 1891 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by 1892 * logical groups to make it more manageable ( < 120 bytes). 1893 * 1894 * NOTE: Each of these groups must be less than 120 bytes. 1895 */ 1896 1897 struct lightbar_params_v2_timing { 1898 /* Timing */ 1899 int32_t google_ramp_up; 1900 int32_t google_ramp_down; 1901 int32_t s3s0_ramp_up; 1902 int32_t s0_tick_delay[2]; /* AC=0/1 */ 1903 int32_t s0a_tick_delay[2]; /* AC=0/1 */ 1904 int32_t s0s3_ramp_down; 1905 int32_t s3_sleep_for; 1906 int32_t s3_ramp_up; 1907 int32_t s3_ramp_down; 1908 int32_t s5_ramp_up; 1909 int32_t s5_ramp_down; 1910 int32_t tap_tick_delay; 1911 int32_t tap_gate_delay; 1912 int32_t tap_display_time; 1913 } __ec_todo_packed; 1914 1915 struct lightbar_params_v2_tap { 1916 /* Tap-for-battery params */ 1917 uint8_t tap_pct_red; 1918 uint8_t tap_pct_green; 1919 uint8_t tap_seg_min_on; 1920 uint8_t tap_seg_max_on; 1921 uint8_t tap_seg_osc; 1922 uint8_t tap_idx[3]; 1923 } __ec_todo_packed; 1924 1925 struct lightbar_params_v2_oscillation { 1926 /* Oscillation */ 1927 uint8_t osc_min[2]; /* AC=0/1 */ 1928 uint8_t osc_max[2]; /* AC=0/1 */ 1929 uint8_t w_ofs[2]; /* AC=0/1 */ 1930 } __ec_todo_packed; 1931 1932 struct lightbar_params_v2_brightness { 1933 /* Brightness limits based on the backlight and AC. */ 1934 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ 1935 uint8_t bright_bl_on_min[2]; /* AC=0/1 */ 1936 uint8_t bright_bl_on_max[2]; /* AC=0/1 */ 1937 } __ec_todo_packed; 1938 1939 struct lightbar_params_v2_thresholds { 1940 /* Battery level thresholds */ 1941 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; 1942 } __ec_todo_packed; 1943 1944 struct lightbar_params_v2_colors { 1945 /* Map [AC][battery_level] to color index */ 1946 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ 1947 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ 1948 1949 /* s5: single color pulse on inhibited power-up */ 1950 uint8_t s5_idx; 1951 1952 /* Color palette */ 1953 struct rgb_s color[8]; /* 0-3 are Google colors */ 1954 } __ec_todo_packed; 1955 1956 /* Lightbar program. */ 1957 #define EC_LB_PROG_LEN 192 1958 struct lightbar_program { 1959 uint8_t size; 1960 uint8_t data[EC_LB_PROG_LEN]; 1961 } __ec_todo_unpacked; 1962 1963 struct ec_params_lightbar { 1964 uint8_t cmd; /* Command (see enum lightbar_command) */ 1965 union { 1966 /* 1967 * The following commands have no args: 1968 * 1969 * dump, off, on, init, get_seq, get_params_v0, get_params_v1, 1970 * version, get_brightness, get_demo, suspend, resume, 1971 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, 1972 * get_params_v2_bright, get_params_v2_thlds, 1973 * get_params_v2_colors 1974 * 1975 * Don't use an empty struct, because C++ hates that. 1976 */ 1977 1978 struct __ec_todo_unpacked { 1979 uint8_t num; 1980 } set_brightness, seq, demo; 1981 1982 struct __ec_todo_unpacked { 1983 uint8_t ctrl, reg, value; 1984 } reg; 1985 1986 struct __ec_todo_unpacked { 1987 uint8_t led, red, green, blue; 1988 } set_rgb; 1989 1990 struct __ec_todo_unpacked { 1991 uint8_t led; 1992 } get_rgb; 1993 1994 struct __ec_todo_unpacked { 1995 uint8_t enable; 1996 } manual_suspend_ctrl; 1997 1998 struct lightbar_params_v0 set_params_v0; 1999 struct lightbar_params_v1 set_params_v1; 2000 2001 struct lightbar_params_v2_timing set_v2par_timing; 2002 struct lightbar_params_v2_tap set_v2par_tap; 2003 struct lightbar_params_v2_oscillation set_v2par_osc; 2004 struct lightbar_params_v2_brightness set_v2par_bright; 2005 struct lightbar_params_v2_thresholds set_v2par_thlds; 2006 struct lightbar_params_v2_colors set_v2par_colors; 2007 2008 struct lightbar_program set_program; 2009 }; 2010 } __ec_todo_packed; 2011 2012 struct ec_response_lightbar { 2013 union { 2014 struct __ec_todo_unpacked { 2015 struct __ec_todo_unpacked { 2016 uint8_t reg; 2017 uint8_t ic0; 2018 uint8_t ic1; 2019 } vals[23]; 2020 } dump; 2021 2022 struct __ec_todo_unpacked { 2023 uint8_t num; 2024 } get_seq, get_brightness, get_demo; 2025 2026 struct lightbar_params_v0 get_params_v0; 2027 struct lightbar_params_v1 get_params_v1; 2028 2029 2030 struct lightbar_params_v2_timing get_params_v2_timing; 2031 struct lightbar_params_v2_tap get_params_v2_tap; 2032 struct lightbar_params_v2_oscillation get_params_v2_osc; 2033 struct lightbar_params_v2_brightness get_params_v2_bright; 2034 struct lightbar_params_v2_thresholds get_params_v2_thlds; 2035 struct lightbar_params_v2_colors get_params_v2_colors; 2036 2037 struct __ec_todo_unpacked { 2038 uint32_t num; 2039 uint32_t flags; 2040 } version; 2041 2042 struct __ec_todo_unpacked { 2043 uint8_t red, green, blue; 2044 } get_rgb; 2045 2046 /* 2047 * The following commands have no response: 2048 * 2049 * off, on, init, set_brightness, seq, reg, set_rgb, demo, 2050 * set_params_v0, set_params_v1, set_program, 2051 * manual_suspend_ctrl, suspend, resume, set_v2par_timing, 2052 * set_v2par_tap, set_v2par_osc, set_v2par_bright, 2053 * set_v2par_thlds, set_v2par_colors 2054 */ 2055 }; 2056 } __ec_todo_packed; 2057 2058 /* Lightbar commands */ 2059 enum lightbar_command { 2060 LIGHTBAR_CMD_DUMP = 0, 2061 LIGHTBAR_CMD_OFF = 1, 2062 LIGHTBAR_CMD_ON = 2, 2063 LIGHTBAR_CMD_INIT = 3, 2064 LIGHTBAR_CMD_SET_BRIGHTNESS = 4, 2065 LIGHTBAR_CMD_SEQ = 5, 2066 LIGHTBAR_CMD_REG = 6, 2067 LIGHTBAR_CMD_SET_RGB = 7, 2068 LIGHTBAR_CMD_GET_SEQ = 8, 2069 LIGHTBAR_CMD_DEMO = 9, 2070 LIGHTBAR_CMD_GET_PARAMS_V0 = 10, 2071 LIGHTBAR_CMD_SET_PARAMS_V0 = 11, 2072 LIGHTBAR_CMD_VERSION = 12, 2073 LIGHTBAR_CMD_GET_BRIGHTNESS = 13, 2074 LIGHTBAR_CMD_GET_RGB = 14, 2075 LIGHTBAR_CMD_GET_DEMO = 15, 2076 LIGHTBAR_CMD_GET_PARAMS_V1 = 16, 2077 LIGHTBAR_CMD_SET_PARAMS_V1 = 17, 2078 LIGHTBAR_CMD_SET_PROGRAM = 18, 2079 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, 2080 LIGHTBAR_CMD_SUSPEND = 20, 2081 LIGHTBAR_CMD_RESUME = 21, 2082 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, 2083 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, 2084 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, 2085 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, 2086 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, 2087 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, 2088 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, 2089 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, 2090 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, 2091 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, 2092 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, 2093 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, 2094 LIGHTBAR_NUM_CMDS 2095 }; 2096 2097 /*****************************************************************************/ 2098 /* LED control commands */ 2099 2100 #define EC_CMD_LED_CONTROL 0x0029 2101 2102 enum ec_led_id { 2103 /* LED to indicate battery state of charge */ 2104 EC_LED_ID_BATTERY_LED = 0, 2105 /* 2106 * LED to indicate system power state (on or in suspend). 2107 * May be on power button or on C-panel. 2108 */ 2109 EC_LED_ID_POWER_LED, 2110 /* LED on power adapter or its plug */ 2111 EC_LED_ID_ADAPTER_LED, 2112 /* LED to indicate left side */ 2113 EC_LED_ID_LEFT_LED, 2114 /* LED to indicate right side */ 2115 EC_LED_ID_RIGHT_LED, 2116 /* LED to indicate recovery mode with HW_REINIT */ 2117 EC_LED_ID_RECOVERY_HW_REINIT_LED, 2118 /* LED to indicate sysrq debug mode. */ 2119 EC_LED_ID_SYSRQ_DEBUG_LED, 2120 2121 EC_LED_ID_COUNT 2122 }; 2123 2124 /* LED control flags */ 2125 #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ 2126 #define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */ 2127 2128 enum ec_led_colors { 2129 EC_LED_COLOR_RED = 0, 2130 EC_LED_COLOR_GREEN, 2131 EC_LED_COLOR_BLUE, 2132 EC_LED_COLOR_YELLOW, 2133 EC_LED_COLOR_WHITE, 2134 EC_LED_COLOR_AMBER, 2135 2136 EC_LED_COLOR_COUNT 2137 }; 2138 2139 struct ec_params_led_control { 2140 uint8_t led_id; /* Which LED to control */ 2141 uint8_t flags; /* Control flags */ 2142 2143 uint8_t brightness[EC_LED_COLOR_COUNT]; 2144 } __ec_align1; 2145 2146 struct ec_response_led_control { 2147 /* 2148 * Available brightness value range. 2149 * 2150 * Range 0 means color channel not present. 2151 * Range 1 means on/off control. 2152 * Other values means the LED is control by PWM. 2153 */ 2154 uint8_t brightness_range[EC_LED_COLOR_COUNT]; 2155 } __ec_align1; 2156 2157 /*****************************************************************************/ 2158 /* Verified boot commands */ 2159 2160 /* 2161 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be 2162 * reused for other purposes with version > 0. 2163 */ 2164 2165 /* Verified boot hash command */ 2166 #define EC_CMD_VBOOT_HASH 0x002A 2167 2168 struct ec_params_vboot_hash { 2169 uint8_t cmd; /* enum ec_vboot_hash_cmd */ 2170 uint8_t hash_type; /* enum ec_vboot_hash_type */ 2171 uint8_t nonce_size; /* Nonce size; may be 0 */ 2172 uint8_t reserved0; /* Reserved; set 0 */ 2173 uint32_t offset; /* Offset in flash to hash */ 2174 uint32_t size; /* Number of bytes to hash */ 2175 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ 2176 } __ec_align4; 2177 2178 struct ec_response_vboot_hash { 2179 uint8_t status; /* enum ec_vboot_hash_status */ 2180 uint8_t hash_type; /* enum ec_vboot_hash_type */ 2181 uint8_t digest_size; /* Size of hash digest in bytes */ 2182 uint8_t reserved0; /* Ignore; will be 0 */ 2183 uint32_t offset; /* Offset in flash which was hashed */ 2184 uint32_t size; /* Number of bytes hashed */ 2185 uint8_t hash_digest[64]; /* Hash digest data */ 2186 } __ec_align4; 2187 2188 enum ec_vboot_hash_cmd { 2189 EC_VBOOT_HASH_GET = 0, /* Get current hash status */ 2190 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ 2191 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ 2192 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ 2193 }; 2194 2195 enum ec_vboot_hash_type { 2196 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ 2197 }; 2198 2199 enum ec_vboot_hash_status { 2200 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ 2201 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ 2202 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ 2203 }; 2204 2205 /* 2206 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. 2207 * If one of these is specified, the EC will automatically update offset and 2208 * size to the correct values for the specified image (RO or RW). 2209 */ 2210 #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe 2211 #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd 2212 #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc 2213 2214 /* 2215 * 'RW' is vague if there are multiple RW images; we mean the active one, 2216 * so the old constant is deprecated. 2217 */ 2218 #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE 2219 2220 /*****************************************************************************/ 2221 /* 2222 * Motion sense commands. We'll make separate structs for sub-commands with 2223 * different input args, so that we know how much to expect. 2224 */ 2225 #define EC_CMD_MOTION_SENSE_CMD 0x002B 2226 2227 /* Motion sense commands */ 2228 enum motionsense_command { 2229 /* 2230 * Dump command returns all motion sensor data including motion sense 2231 * module flags and individual sensor flags. 2232 */ 2233 MOTIONSENSE_CMD_DUMP = 0, 2234 2235 /* 2236 * Info command returns data describing the details of a given sensor, 2237 * including enum motionsensor_type, enum motionsensor_location, and 2238 * enum motionsensor_chip. 2239 */ 2240 MOTIONSENSE_CMD_INFO = 1, 2241 2242 /* 2243 * EC Rate command is a setter/getter command for the EC sampling rate 2244 * in milliseconds. 2245 * It is per sensor, the EC run sample task at the minimum of all 2246 * sensors EC_RATE. 2247 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR 2248 * to collect all the sensor samples. 2249 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay 2250 * to process of all motion sensors in milliseconds. 2251 */ 2252 MOTIONSENSE_CMD_EC_RATE = 2, 2253 2254 /* 2255 * Sensor ODR command is a setter/getter command for the output data 2256 * rate of a specific motion sensor in millihertz. 2257 */ 2258 MOTIONSENSE_CMD_SENSOR_ODR = 3, 2259 2260 /* 2261 * Sensor range command is a setter/getter command for the range of 2262 * a specified motion sensor in +/-G's or +/- deg/s. 2263 */ 2264 MOTIONSENSE_CMD_SENSOR_RANGE = 4, 2265 2266 /* 2267 * Setter/getter command for the keyboard wake angle. When the lid 2268 * angle is greater than this value, keyboard wake is disabled in S3, 2269 * and when the lid angle goes less than this value, keyboard wake is 2270 * enabled. Note, the lid angle measurement is an approximate, 2271 * un-calibrated value, hence the wake angle isn't exact. 2272 */ 2273 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, 2274 2275 /* 2276 * Returns a single sensor data. 2277 */ 2278 MOTIONSENSE_CMD_DATA = 6, 2279 2280 /* 2281 * Return sensor fifo info. 2282 */ 2283 MOTIONSENSE_CMD_FIFO_INFO = 7, 2284 2285 /* 2286 * Insert a flush element in the fifo and return sensor fifo info. 2287 * The host can use that element to synchronize its operation. 2288 */ 2289 MOTIONSENSE_CMD_FIFO_FLUSH = 8, 2290 2291 /* 2292 * Return a portion of the fifo. 2293 */ 2294 MOTIONSENSE_CMD_FIFO_READ = 9, 2295 2296 /* 2297 * Perform low level calibration. 2298 * On sensors that support it, ask to do offset calibration. 2299 */ 2300 MOTIONSENSE_CMD_PERFORM_CALIB = 10, 2301 2302 /* 2303 * Sensor Offset command is a setter/getter command for the offset 2304 * used for calibration. 2305 * The offsets can be calculated by the host, or via 2306 * PERFORM_CALIB command. 2307 */ 2308 MOTIONSENSE_CMD_SENSOR_OFFSET = 11, 2309 2310 /* 2311 * List available activities for a MOTION sensor. 2312 * Indicates if they are enabled or disabled. 2313 */ 2314 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, 2315 2316 /* 2317 * Activity management 2318 * Enable/Disable activity recognition. 2319 */ 2320 MOTIONSENSE_CMD_SET_ACTIVITY = 13, 2321 2322 /* 2323 * Lid Angle 2324 */ 2325 MOTIONSENSE_CMD_LID_ANGLE = 14, 2326 2327 /* 2328 * Allow the FIFO to trigger interrupt via MKBP events. 2329 * By default the FIFO does not send interrupt to process the FIFO 2330 * until the AP is ready or it is coming from a wakeup sensor. 2331 */ 2332 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, 2333 2334 /* 2335 * Spoof the readings of the sensors. The spoofed readings can be set 2336 * to arbitrary values, or will lock to the last read actual values. 2337 */ 2338 MOTIONSENSE_CMD_SPOOF = 16, 2339 2340 /* Set lid angle for tablet mode detection. */ 2341 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, 2342 2343 /* 2344 * Sensor Scale command is a setter/getter command for the calibration 2345 * scale. 2346 */ 2347 MOTIONSENSE_CMD_SENSOR_SCALE = 18, 2348 2349 /* Number of motionsense sub-commands. */ 2350 MOTIONSENSE_NUM_CMDS 2351 }; 2352 2353 /* List of motion sensor types. */ 2354 enum motionsensor_type { 2355 MOTIONSENSE_TYPE_ACCEL = 0, 2356 MOTIONSENSE_TYPE_GYRO = 1, 2357 MOTIONSENSE_TYPE_MAG = 2, 2358 MOTIONSENSE_TYPE_PROX = 3, 2359 MOTIONSENSE_TYPE_LIGHT = 4, 2360 MOTIONSENSE_TYPE_ACTIVITY = 5, 2361 MOTIONSENSE_TYPE_BARO = 6, 2362 MOTIONSENSE_TYPE_SYNC = 7, 2363 MOTIONSENSE_TYPE_MAX, 2364 }; 2365 2366 /* List of motion sensor locations. */ 2367 enum motionsensor_location { 2368 MOTIONSENSE_LOC_BASE = 0, 2369 MOTIONSENSE_LOC_LID = 1, 2370 MOTIONSENSE_LOC_CAMERA = 2, 2371 MOTIONSENSE_LOC_MAX, 2372 }; 2373 2374 /* List of motion sensor chips. */ 2375 enum motionsensor_chip { 2376 MOTIONSENSE_CHIP_KXCJ9 = 0, 2377 MOTIONSENSE_CHIP_LSM6DS0 = 1, 2378 MOTIONSENSE_CHIP_BMI160 = 2, 2379 MOTIONSENSE_CHIP_SI1141 = 3, 2380 MOTIONSENSE_CHIP_SI1142 = 4, 2381 MOTIONSENSE_CHIP_SI1143 = 5, 2382 MOTIONSENSE_CHIP_KX022 = 6, 2383 MOTIONSENSE_CHIP_L3GD20H = 7, 2384 MOTIONSENSE_CHIP_BMA255 = 8, 2385 MOTIONSENSE_CHIP_BMP280 = 9, 2386 MOTIONSENSE_CHIP_OPT3001 = 10, 2387 MOTIONSENSE_CHIP_BH1730 = 11, 2388 MOTIONSENSE_CHIP_GPIO = 12, 2389 MOTIONSENSE_CHIP_LIS2DH = 13, 2390 MOTIONSENSE_CHIP_LSM6DSM = 14, 2391 MOTIONSENSE_CHIP_LIS2DE = 15, 2392 MOTIONSENSE_CHIP_LIS2MDL = 16, 2393 MOTIONSENSE_CHIP_LSM6DS3 = 17, 2394 MOTIONSENSE_CHIP_LSM6DSO = 18, 2395 MOTIONSENSE_CHIP_LNG2DM = 19, 2396 MOTIONSENSE_CHIP_MAX, 2397 }; 2398 2399 /* List of orientation positions */ 2400 enum motionsensor_orientation { 2401 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, 2402 MOTIONSENSE_ORIENTATION_PORTRAIT = 1, 2403 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, 2404 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, 2405 MOTIONSENSE_ORIENTATION_UNKNOWN = 4, 2406 }; 2407 2408 struct ec_response_motion_sensor_data { 2409 /* Flags for each sensor. */ 2410 uint8_t flags; 2411 /* Sensor number the data comes from. */ 2412 uint8_t sensor_num; 2413 /* Each sensor is up to 3-axis. */ 2414 union { 2415 int16_t data[3]; 2416 struct __ec_todo_packed { 2417 uint16_t reserved; 2418 uint32_t timestamp; 2419 }; 2420 struct __ec_todo_unpacked { 2421 uint8_t activity; /* motionsensor_activity */ 2422 uint8_t state; 2423 int16_t add_info[2]; 2424 }; 2425 }; 2426 } __ec_todo_packed; 2427 2428 /* Note: used in ec_response_get_next_data */ 2429 struct ec_response_motion_sense_fifo_info { 2430 /* Size of the fifo */ 2431 uint16_t size; 2432 /* Amount of space used in the fifo */ 2433 uint16_t count; 2434 /* Timestamp recorded in us. 2435 * aka accurate timestamp when host event was triggered. 2436 */ 2437 uint32_t timestamp; 2438 /* Total amount of vector lost */ 2439 uint16_t total_lost; 2440 /* Lost events since the last fifo_info, per sensors */ 2441 uint16_t lost[]; 2442 } __ec_todo_packed; 2443 2444 struct ec_response_motion_sense_fifo_data { 2445 uint32_t number_data; 2446 struct ec_response_motion_sensor_data data[]; 2447 } __ec_todo_packed; 2448 2449 /* List supported activity recognition */ 2450 enum motionsensor_activity { 2451 MOTIONSENSE_ACTIVITY_RESERVED = 0, 2452 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, 2453 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, 2454 MOTIONSENSE_ACTIVITY_ORIENTATION = 3, 2455 }; 2456 2457 struct ec_motion_sense_activity { 2458 uint8_t sensor_num; 2459 uint8_t activity; /* one of enum motionsensor_activity */ 2460 uint8_t enable; /* 1: enable, 0: disable */ 2461 uint8_t reserved; 2462 uint16_t parameters[3]; /* activity dependent parameters */ 2463 } __ec_todo_unpacked; 2464 2465 /* Module flag masks used for the dump sub-command. */ 2466 #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) 2467 2468 /* Sensor flag masks used for the dump sub-command. */ 2469 #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) 2470 2471 /* 2472 * Flush entry for synchronization. 2473 * data contains time stamp 2474 */ 2475 #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) 2476 #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) 2477 #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) 2478 #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) 2479 #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) 2480 2481 /* 2482 * Send this value for the data element to only perform a read. If you 2483 * send any other value, the EC will interpret it as data to set and will 2484 * return the actual value set. 2485 */ 2486 #define EC_MOTION_SENSE_NO_VALUE -1 2487 2488 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 2489 2490 /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ 2491 /* Set Calibration information */ 2492 #define MOTION_SENSE_SET_OFFSET BIT(0) 2493 2494 /* Default Scale value, factor 1. */ 2495 #define MOTION_SENSE_DEFAULT_SCALE BIT(15) 2496 2497 #define LID_ANGLE_UNRELIABLE 500 2498 2499 enum motionsense_spoof_mode { 2500 /* Disable spoof mode. */ 2501 MOTIONSENSE_SPOOF_MODE_DISABLE = 0, 2502 2503 /* Enable spoof mode, but use provided component values. */ 2504 MOTIONSENSE_SPOOF_MODE_CUSTOM, 2505 2506 /* Enable spoof mode, but use the current sensor values. */ 2507 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, 2508 2509 /* Query the current spoof mode status for the sensor. */ 2510 MOTIONSENSE_SPOOF_MODE_QUERY, 2511 }; 2512 2513 struct ec_params_motion_sense { 2514 uint8_t cmd; 2515 union { 2516 /* Used for MOTIONSENSE_CMD_DUMP. */ 2517 struct __ec_todo_unpacked { 2518 /* 2519 * Maximal number of sensor the host is expecting. 2520 * 0 means the host is only interested in the number 2521 * of sensors controlled by the EC. 2522 */ 2523 uint8_t max_sensor_count; 2524 } dump; 2525 2526 /* 2527 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. 2528 */ 2529 struct __ec_todo_unpacked { 2530 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. 2531 * kb_wake_angle: angle to wakup AP. 2532 */ 2533 int16_t data; 2534 } kb_wake_angle; 2535 2536 /* 2537 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA 2538 * and MOTIONSENSE_CMD_PERFORM_CALIB. 2539 */ 2540 struct __ec_todo_unpacked { 2541 uint8_t sensor_num; 2542 } info, info_3, data, fifo_flush, perform_calib, 2543 list_activities; 2544 2545 /* 2546 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR 2547 * and MOTIONSENSE_CMD_SENSOR_RANGE. 2548 */ 2549 struct __ec_todo_unpacked { 2550 uint8_t sensor_num; 2551 2552 /* Rounding flag, true for round-up, false for down. */ 2553 uint8_t roundup; 2554 2555 uint16_t reserved; 2556 2557 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ 2558 int32_t data; 2559 } ec_rate, sensor_odr, sensor_range; 2560 2561 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ 2562 struct __ec_todo_packed { 2563 uint8_t sensor_num; 2564 2565 /* 2566 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set 2567 * the calibration information in the EC. 2568 * If unset, just retrieve calibration information. 2569 */ 2570 uint16_t flags; 2571 2572 /* 2573 * Temperature at calibration, in units of 0.01 C 2574 * 0x8000: invalid / unknown. 2575 * 0x0: 0C 2576 * 0x7fff: +327.67C 2577 */ 2578 int16_t temp; 2579 2580 /* 2581 * Offset for calibration. 2582 * Unit: 2583 * Accelerometer: 1/1024 g 2584 * Gyro: 1/1024 deg/s 2585 * Compass: 1/16 uT 2586 */ 2587 int16_t offset[3]; 2588 } sensor_offset; 2589 2590 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ 2591 struct __ec_todo_packed { 2592 uint8_t sensor_num; 2593 2594 /* 2595 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set 2596 * the calibration information in the EC. 2597 * If unset, just retrieve calibration information. 2598 */ 2599 uint16_t flags; 2600 2601 /* 2602 * Temperature at calibration, in units of 0.01 C 2603 * 0x8000: invalid / unknown. 2604 * 0x0: 0C 2605 * 0x7fff: +327.67C 2606 */ 2607 int16_t temp; 2608 2609 /* 2610 * Scale for calibration: 2611 * By default scale is 1, it is encoded on 16bits: 2612 * 1 = BIT(15) 2613 * ~2 = 0xFFFF 2614 * ~0 = 0. 2615 */ 2616 uint16_t scale[3]; 2617 } sensor_scale; 2618 2619 2620 /* Used for MOTIONSENSE_CMD_FIFO_INFO */ 2621 /* (no params) */ 2622 2623 /* Used for MOTIONSENSE_CMD_FIFO_READ */ 2624 struct __ec_todo_unpacked { 2625 /* 2626 * Number of expected vector to return. 2627 * EC may return less or 0 if none available. 2628 */ 2629 uint32_t max_data_vector; 2630 } fifo_read; 2631 2632 struct ec_motion_sense_activity set_activity; 2633 2634 /* Used for MOTIONSENSE_CMD_LID_ANGLE */ 2635 /* (no params) */ 2636 2637 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ 2638 struct __ec_todo_unpacked { 2639 /* 2640 * 1: enable, 0 disable fifo, 2641 * EC_MOTION_SENSE_NO_VALUE return value. 2642 */ 2643 int8_t enable; 2644 } fifo_int_enable; 2645 2646 /* Used for MOTIONSENSE_CMD_SPOOF */ 2647 struct __ec_todo_packed { 2648 uint8_t sensor_id; 2649 2650 /* See enum motionsense_spoof_mode. */ 2651 uint8_t spoof_enable; 2652 2653 /* Ignored, used for alignment. */ 2654 uint8_t reserved; 2655 2656 /* Individual component values to spoof. */ 2657 int16_t components[3]; 2658 } spoof; 2659 2660 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ 2661 struct __ec_todo_unpacked { 2662 /* 2663 * Lid angle threshold for switching between tablet and 2664 * clamshell mode. 2665 */ 2666 int16_t lid_angle; 2667 2668 /* 2669 * Hysteresis degree to prevent fluctuations between 2670 * clamshell and tablet mode if lid angle keeps 2671 * changing around the threshold. Lid motion driver will 2672 * use lid_angle + hys_degree to trigger tablet mode and 2673 * lid_angle - hys_degree to trigger clamshell mode. 2674 */ 2675 int16_t hys_degree; 2676 } tablet_mode_threshold; 2677 }; 2678 } __ec_todo_packed; 2679 2680 struct ec_response_motion_sense { 2681 union { 2682 /* Used for MOTIONSENSE_CMD_DUMP */ 2683 struct __ec_todo_unpacked { 2684 /* Flags representing the motion sensor module. */ 2685 uint8_t module_flags; 2686 2687 /* Number of sensors managed directly by the EC. */ 2688 uint8_t sensor_count; 2689 2690 /* 2691 * Sensor data is truncated if response_max is too small 2692 * for holding all the data. 2693 */ 2694 struct ec_response_motion_sensor_data sensor[0]; 2695 } dump; 2696 2697 /* Used for MOTIONSENSE_CMD_INFO. */ 2698 struct __ec_todo_unpacked { 2699 /* Should be element of enum motionsensor_type. */ 2700 uint8_t type; 2701 2702 /* Should be element of enum motionsensor_location. */ 2703 uint8_t location; 2704 2705 /* Should be element of enum motionsensor_chip. */ 2706 uint8_t chip; 2707 } info; 2708 2709 /* Used for MOTIONSENSE_CMD_INFO version 3 */ 2710 struct __ec_todo_unpacked { 2711 /* Should be element of enum motionsensor_type. */ 2712 uint8_t type; 2713 2714 /* Should be element of enum motionsensor_location. */ 2715 uint8_t location; 2716 2717 /* Should be element of enum motionsensor_chip. */ 2718 uint8_t chip; 2719 2720 /* Minimum sensor sampling frequency */ 2721 uint32_t min_frequency; 2722 2723 /* Maximum sensor sampling frequency */ 2724 uint32_t max_frequency; 2725 2726 /* Max number of sensor events that could be in fifo */ 2727 uint32_t fifo_max_event_count; 2728 } info_3; 2729 2730 /* Used for MOTIONSENSE_CMD_DATA */ 2731 struct ec_response_motion_sensor_data data; 2732 2733 /* 2734 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, 2735 * MOTIONSENSE_CMD_SENSOR_RANGE, 2736 * MOTIONSENSE_CMD_KB_WAKE_ANGLE, 2737 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and 2738 * MOTIONSENSE_CMD_SPOOF. 2739 */ 2740 struct __ec_todo_unpacked { 2741 /* Current value of the parameter queried. */ 2742 int32_t ret; 2743 } ec_rate, sensor_odr, sensor_range, kb_wake_angle, 2744 fifo_int_enable, spoof; 2745 2746 /* 2747 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, 2748 * PERFORM_CALIB. 2749 */ 2750 struct __ec_todo_unpacked { 2751 int16_t temp; 2752 int16_t offset[3]; 2753 } sensor_offset, perform_calib; 2754 2755 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ 2756 struct __ec_todo_unpacked { 2757 int16_t temp; 2758 uint16_t scale[3]; 2759 } sensor_scale; 2760 2761 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; 2762 2763 struct ec_response_motion_sense_fifo_data fifo_read; 2764 2765 struct __ec_todo_packed { 2766 uint16_t reserved; 2767 uint32_t enabled; 2768 uint32_t disabled; 2769 } list_activities; 2770 2771 /* No params for set activity */ 2772 2773 /* Used for MOTIONSENSE_CMD_LID_ANGLE */ 2774 struct __ec_todo_unpacked { 2775 /* 2776 * Angle between 0 and 360 degree if available, 2777 * LID_ANGLE_UNRELIABLE otherwise. 2778 */ 2779 uint16_t value; 2780 } lid_angle; 2781 2782 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ 2783 struct __ec_todo_unpacked { 2784 /* 2785 * Lid angle threshold for switching between tablet and 2786 * clamshell mode. 2787 */ 2788 uint16_t lid_angle; 2789 2790 /* Hysteresis degree. */ 2791 uint16_t hys_degree; 2792 } tablet_mode_threshold; 2793 2794 }; 2795 } __ec_todo_packed; 2796 2797 /*****************************************************************************/ 2798 /* Force lid open command */ 2799 2800 /* Make lid event always open */ 2801 #define EC_CMD_FORCE_LID_OPEN 0x002C 2802 2803 struct ec_params_force_lid_open { 2804 uint8_t enabled; 2805 } __ec_align1; 2806 2807 /*****************************************************************************/ 2808 /* Configure the behavior of the power button */ 2809 #define EC_CMD_CONFIG_POWER_BUTTON 0x002D 2810 2811 enum ec_config_power_button_flags { 2812 /* Enable/Disable power button pulses for x86 devices */ 2813 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), 2814 }; 2815 2816 struct ec_params_config_power_button { 2817 /* See enum ec_config_power_button_flags */ 2818 uint8_t flags; 2819 } __ec_align1; 2820 2821 /*****************************************************************************/ 2822 /* USB charging control commands */ 2823 2824 /* Set USB port charging mode */ 2825 #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 2826 2827 struct ec_params_usb_charge_set_mode { 2828 uint8_t usb_port_id; 2829 uint8_t mode:7; 2830 uint8_t inhibit_charge:1; 2831 } __ec_align1; 2832 2833 /*****************************************************************************/ 2834 /* Persistent storage for host */ 2835 2836 /* Maximum bytes that can be read/written in a single command */ 2837 #define EC_PSTORE_SIZE_MAX 64 2838 2839 /* Get persistent storage info */ 2840 #define EC_CMD_PSTORE_INFO 0x0040 2841 2842 struct ec_response_pstore_info { 2843 /* Persistent storage size, in bytes */ 2844 uint32_t pstore_size; 2845 /* Access size; read/write offset and size must be a multiple of this */ 2846 uint32_t access_size; 2847 } __ec_align4; 2848 2849 /* 2850 * Read persistent storage 2851 * 2852 * Response is params.size bytes of data. 2853 */ 2854 #define EC_CMD_PSTORE_READ 0x0041 2855 2856 struct ec_params_pstore_read { 2857 uint32_t offset; /* Byte offset to read */ 2858 uint32_t size; /* Size to read in bytes */ 2859 } __ec_align4; 2860 2861 /* Write persistent storage */ 2862 #define EC_CMD_PSTORE_WRITE 0x0042 2863 2864 struct ec_params_pstore_write { 2865 uint32_t offset; /* Byte offset to write */ 2866 uint32_t size; /* Size to write in bytes */ 2867 uint8_t data[EC_PSTORE_SIZE_MAX]; 2868 } __ec_align4; 2869 2870 /*****************************************************************************/ 2871 /* Real-time clock */ 2872 2873 /* RTC params and response structures */ 2874 struct ec_params_rtc { 2875 uint32_t time; 2876 } __ec_align4; 2877 2878 struct ec_response_rtc { 2879 uint32_t time; 2880 } __ec_align4; 2881 2882 /* These use ec_response_rtc */ 2883 #define EC_CMD_RTC_GET_VALUE 0x0044 2884 #define EC_CMD_RTC_GET_ALARM 0x0045 2885 2886 /* These all use ec_params_rtc */ 2887 #define EC_CMD_RTC_SET_VALUE 0x0046 2888 #define EC_CMD_RTC_SET_ALARM 0x0047 2889 2890 /* Pass as time param to SET_ALARM to clear the current alarm */ 2891 #define EC_RTC_ALARM_CLEAR 0 2892 2893 /*****************************************************************************/ 2894 /* Port80 log access */ 2895 2896 /* Maximum entries that can be read/written in a single command */ 2897 #define EC_PORT80_SIZE_MAX 32 2898 2899 /* Get last port80 code from previous boot */ 2900 #define EC_CMD_PORT80_LAST_BOOT 0x0048 2901 #define EC_CMD_PORT80_READ 0x0048 2902 2903 enum ec_port80_subcmd { 2904 EC_PORT80_GET_INFO = 0, 2905 EC_PORT80_READ_BUFFER, 2906 }; 2907 2908 struct ec_params_port80_read { 2909 uint16_t subcmd; 2910 union { 2911 struct __ec_todo_unpacked { 2912 uint32_t offset; 2913 uint32_t num_entries; 2914 } read_buffer; 2915 }; 2916 } __ec_todo_packed; 2917 2918 struct ec_response_port80_read { 2919 union { 2920 struct __ec_todo_unpacked { 2921 uint32_t writes; 2922 uint32_t history_size; 2923 uint32_t last_boot; 2924 } get_info; 2925 struct __ec_todo_unpacked { 2926 uint16_t codes[EC_PORT80_SIZE_MAX]; 2927 } data; 2928 }; 2929 } __ec_todo_packed; 2930 2931 struct ec_response_port80_last_boot { 2932 uint16_t code; 2933 } __ec_align2; 2934 2935 /*****************************************************************************/ 2936 /* Temporary secure storage for host verified boot use */ 2937 2938 /* Number of bytes in a vstore slot */ 2939 #define EC_VSTORE_SLOT_SIZE 64 2940 2941 /* Maximum number of vstore slots */ 2942 #define EC_VSTORE_SLOT_MAX 32 2943 2944 /* Get persistent storage info */ 2945 #define EC_CMD_VSTORE_INFO 0x0049 2946 struct ec_response_vstore_info { 2947 /* Indicates which slots are locked */ 2948 uint32_t slot_locked; 2949 /* Total number of slots available */ 2950 uint8_t slot_count; 2951 } __ec_align_size1; 2952 2953 /* 2954 * Read temporary secure storage 2955 * 2956 * Response is EC_VSTORE_SLOT_SIZE bytes of data. 2957 */ 2958 #define EC_CMD_VSTORE_READ 0x004A 2959 2960 struct ec_params_vstore_read { 2961 uint8_t slot; /* Slot to read from */ 2962 } __ec_align1; 2963 2964 struct ec_response_vstore_read { 2965 uint8_t data[EC_VSTORE_SLOT_SIZE]; 2966 } __ec_align1; 2967 2968 /* 2969 * Write temporary secure storage and lock it. 2970 */ 2971 #define EC_CMD_VSTORE_WRITE 0x004B 2972 2973 struct ec_params_vstore_write { 2974 uint8_t slot; /* Slot to write to */ 2975 uint8_t data[EC_VSTORE_SLOT_SIZE]; 2976 } __ec_align1; 2977 2978 /*****************************************************************************/ 2979 /* Thermal engine commands. Note that there are two implementations. We'll 2980 * reuse the command number, but the data and behavior is incompatible. 2981 * Version 0 is what originally shipped on Link. 2982 * Version 1 separates the CPU thermal limits from the fan control. 2983 */ 2984 2985 #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 2986 #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 2987 2988 /* The version 0 structs are opaque. You have to know what they are for 2989 * the get/set commands to make any sense. 2990 */ 2991 2992 /* Version 0 - set */ 2993 struct ec_params_thermal_set_threshold { 2994 uint8_t sensor_type; 2995 uint8_t threshold_id; 2996 uint16_t value; 2997 } __ec_align2; 2998 2999 /* Version 0 - get */ 3000 struct ec_params_thermal_get_threshold { 3001 uint8_t sensor_type; 3002 uint8_t threshold_id; 3003 } __ec_align1; 3004 3005 struct ec_response_thermal_get_threshold { 3006 uint16_t value; 3007 } __ec_align2; 3008 3009 3010 /* The version 1 structs are visible. */ 3011 enum ec_temp_thresholds { 3012 EC_TEMP_THRESH_WARN = 0, 3013 EC_TEMP_THRESH_HIGH, 3014 EC_TEMP_THRESH_HALT, 3015 3016 EC_TEMP_THRESH_COUNT 3017 }; 3018 3019 /* 3020 * Thermal configuration for one temperature sensor. Temps are in degrees K. 3021 * Zero values will be silently ignored by the thermal task. 3022 * 3023 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree 3024 * hysteresis. 3025 * For example, 3026 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K 3027 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K 3028 * EC will throttle ap when temperature >= 301 K, and release throttling when 3029 * temperature <= 299 K. 3030 * 3031 * Set 'temp_host_release' value allows thermal task has a custom hysteresis. 3032 * For example, 3033 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K 3034 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K 3035 * EC will throttle ap when temperature >= 301 K, and release throttling when 3036 * temperature <= 294 K. 3037 * 3038 * Note that this structure is a sub-structure of 3039 * ec_params_thermal_set_threshold_v1, but maintains its alignment there. 3040 */ 3041 struct ec_thermal_config { 3042 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ 3043 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ 3044 uint32_t temp_fan_off; /* no active cooling needed */ 3045 uint32_t temp_fan_max; /* max active cooling needed */ 3046 } __ec_align4; 3047 3048 /* Version 1 - get config for one sensor. */ 3049 struct ec_params_thermal_get_threshold_v1 { 3050 uint32_t sensor_num; 3051 } __ec_align4; 3052 /* This returns a struct ec_thermal_config */ 3053 3054 /* 3055 * Version 1 - set config for one sensor. 3056 * Use read-modify-write for best results! 3057 */ 3058 struct ec_params_thermal_set_threshold_v1 { 3059 uint32_t sensor_num; 3060 struct ec_thermal_config cfg; 3061 } __ec_align4; 3062 /* This returns no data */ 3063 3064 /****************************************************************************/ 3065 3066 /* Toggle automatic fan control */ 3067 #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 3068 3069 /* Version 1 of input params */ 3070 struct ec_params_auto_fan_ctrl_v1 { 3071 uint8_t fan_idx; 3072 } __ec_align1; 3073 3074 /* Get/Set TMP006 calibration data */ 3075 #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 3076 #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 3077 3078 /* 3079 * The original TMP006 calibration only needed four params, but now we need 3080 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave 3081 * the params opaque. The v1 "get" response will include the algorithm number 3082 * and how many params it requires. That way we can change the EC code without 3083 * needing to update this file. We can also use a different algorithm on each 3084 * sensor. 3085 */ 3086 3087 /* This is the same struct for both v0 and v1. */ 3088 struct ec_params_tmp006_get_calibration { 3089 uint8_t index; 3090 } __ec_align1; 3091 3092 /* Version 0 */ 3093 struct ec_response_tmp006_get_calibration_v0 { 3094 float s0; 3095 float b0; 3096 float b1; 3097 float b2; 3098 } __ec_align4; 3099 3100 struct ec_params_tmp006_set_calibration_v0 { 3101 uint8_t index; 3102 uint8_t reserved[3]; 3103 float s0; 3104 float b0; 3105 float b1; 3106 float b2; 3107 } __ec_align4; 3108 3109 /* Version 1 */ 3110 struct ec_response_tmp006_get_calibration_v1 { 3111 uint8_t algorithm; 3112 uint8_t num_params; 3113 uint8_t reserved[2]; 3114 float val[]; 3115 } __ec_align4; 3116 3117 struct ec_params_tmp006_set_calibration_v1 { 3118 uint8_t index; 3119 uint8_t algorithm; 3120 uint8_t num_params; 3121 uint8_t reserved; 3122 float val[]; 3123 } __ec_align4; 3124 3125 3126 /* Read raw TMP006 data */ 3127 #define EC_CMD_TMP006_GET_RAW 0x0055 3128 3129 struct ec_params_tmp006_get_raw { 3130 uint8_t index; 3131 } __ec_align1; 3132 3133 struct ec_response_tmp006_get_raw { 3134 int32_t t; /* In 1/100 K */ 3135 int32_t v; /* In nV */ 3136 } __ec_align4; 3137 3138 /*****************************************************************************/ 3139 /* MKBP - Matrix KeyBoard Protocol */ 3140 3141 /* 3142 * Read key state 3143 * 3144 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for 3145 * expected response size. 3146 * 3147 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish 3148 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type 3149 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. 3150 */ 3151 #define EC_CMD_MKBP_STATE 0x0060 3152 3153 /* 3154 * Provide information about various MKBP things. See enum ec_mkbp_info_type. 3155 */ 3156 #define EC_CMD_MKBP_INFO 0x0061 3157 3158 struct ec_response_mkbp_info { 3159 uint32_t rows; 3160 uint32_t cols; 3161 /* Formerly "switches", which was 0. */ 3162 uint8_t reserved; 3163 } __ec_align_size1; 3164 3165 struct ec_params_mkbp_info { 3166 uint8_t info_type; 3167 uint8_t event_type; 3168 } __ec_align1; 3169 3170 enum ec_mkbp_info_type { 3171 /* 3172 * Info about the keyboard matrix: number of rows and columns. 3173 * 3174 * Returns struct ec_response_mkbp_info. 3175 */ 3176 EC_MKBP_INFO_KBD = 0, 3177 3178 /* 3179 * For buttons and switches, info about which specifically are 3180 * supported. event_type must be set to one of the values in enum 3181 * ec_mkbp_event. 3182 * 3183 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte 3184 * bitmask indicating which buttons or switches are present. See the 3185 * bit inidices below. 3186 */ 3187 EC_MKBP_INFO_SUPPORTED = 1, 3188 3189 /* 3190 * Instantaneous state of buttons and switches. 3191 * 3192 * event_type must be set to one of the values in enum ec_mkbp_event. 3193 * 3194 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] 3195 * indicating the current state of the keyboard matrix. 3196 * 3197 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw 3198 * event state. 3199 * 3200 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the 3201 * state of supported buttons. 3202 * 3203 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the 3204 * state of supported switches. 3205 */ 3206 EC_MKBP_INFO_CURRENT = 2, 3207 }; 3208 3209 /* Simulate key press */ 3210 #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 3211 3212 struct ec_params_mkbp_simulate_key { 3213 uint8_t col; 3214 uint8_t row; 3215 uint8_t pressed; 3216 } __ec_align1; 3217 3218 #define EC_CMD_GET_KEYBOARD_ID 0x0063 3219 3220 struct ec_response_keyboard_id { 3221 uint32_t keyboard_id; 3222 } __ec_align4; 3223 3224 enum keyboard_id { 3225 KEYBOARD_ID_UNSUPPORTED = 0, 3226 KEYBOARD_ID_UNREADABLE = 0xffffffff, 3227 }; 3228 3229 /* Configure keyboard scanning */ 3230 #define EC_CMD_MKBP_SET_CONFIG 0x0064 3231 #define EC_CMD_MKBP_GET_CONFIG 0x0065 3232 3233 /* flags */ 3234 enum mkbp_config_flags { 3235 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ 3236 }; 3237 3238 enum mkbp_config_valid { 3239 EC_MKBP_VALID_SCAN_PERIOD = BIT(0), 3240 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), 3241 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), 3242 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), 3243 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), 3244 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), 3245 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), 3246 }; 3247 3248 /* 3249 * Configuration for our key scanning algorithm. 3250 * 3251 * Note that this is used as a sub-structure of 3252 * ec_{params/response}_mkbp_get_config. 3253 */ 3254 struct ec_mkbp_config { 3255 uint32_t valid_mask; /* valid fields */ 3256 uint8_t flags; /* some flags (enum mkbp_config_flags) */ 3257 uint8_t valid_flags; /* which flags are valid */ 3258 uint16_t scan_period_us; /* period between start of scans */ 3259 /* revert to interrupt mode after no activity for this long */ 3260 uint32_t poll_timeout_us; 3261 /* 3262 * minimum post-scan relax time. Once we finish a scan we check 3263 * the time until we are due to start the next one. If this time is 3264 * shorter this field, we use this instead. 3265 */ 3266 uint16_t min_post_scan_delay_us; 3267 /* delay between setting up output and waiting for it to settle */ 3268 uint16_t output_settle_us; 3269 uint16_t debounce_down_us; /* time for debounce on key down */ 3270 uint16_t debounce_up_us; /* time for debounce on key up */ 3271 /* maximum depth to allow for fifo (0 = no keyscan output) */ 3272 uint8_t fifo_max_depth; 3273 } __ec_align_size1; 3274 3275 struct ec_params_mkbp_set_config { 3276 struct ec_mkbp_config config; 3277 } __ec_align_size1; 3278 3279 struct ec_response_mkbp_get_config { 3280 struct ec_mkbp_config config; 3281 } __ec_align_size1; 3282 3283 /* Run the key scan emulation */ 3284 #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 3285 3286 enum ec_keyscan_seq_cmd { 3287 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ 3288 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ 3289 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ 3290 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ 3291 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ 3292 }; 3293 3294 enum ec_collect_flags { 3295 /* 3296 * Indicates this scan was processed by the EC. Due to timing, some 3297 * scans may be skipped. 3298 */ 3299 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), 3300 }; 3301 3302 struct ec_collect_item { 3303 uint8_t flags; /* some flags (enum ec_collect_flags) */ 3304 } __ec_align1; 3305 3306 struct ec_params_keyscan_seq_ctrl { 3307 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ 3308 union { 3309 struct __ec_align1 { 3310 uint8_t active; /* still active */ 3311 uint8_t num_items; /* number of items */ 3312 /* Current item being presented */ 3313 uint8_t cur_item; 3314 } status; 3315 struct __ec_todo_unpacked { 3316 /* 3317 * Absolute time for this scan, measured from the 3318 * start of the sequence. 3319 */ 3320 uint32_t time_us; 3321 uint8_t scan[0]; /* keyscan data */ 3322 } add; 3323 struct __ec_align1 { 3324 uint8_t start_item; /* First item to return */ 3325 uint8_t num_items; /* Number of items to return */ 3326 } collect; 3327 }; 3328 } __ec_todo_packed; 3329 3330 struct ec_result_keyscan_seq_ctrl { 3331 union { 3332 struct __ec_todo_unpacked { 3333 uint8_t num_items; /* Number of items */ 3334 /* Data for each item */ 3335 struct ec_collect_item item[0]; 3336 } collect; 3337 }; 3338 } __ec_todo_packed; 3339 3340 /* 3341 * Get the next pending MKBP event. 3342 * 3343 * Returns EC_RES_UNAVAILABLE if there is no event pending. 3344 */ 3345 #define EC_CMD_GET_NEXT_EVENT 0x0067 3346 3347 #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 3348 3349 /* 3350 * We use the most significant bit of the event type to indicate to the host 3351 * that the EC has more MKBP events available to provide. 3352 */ 3353 #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) 3354 3355 /* The mask to apply to get the raw event type */ 3356 #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) 3357 3358 enum ec_mkbp_event { 3359 /* Keyboard matrix changed. The event data is the new matrix state. */ 3360 EC_MKBP_EVENT_KEY_MATRIX = 0, 3361 3362 /* New host event. The event data is 4 bytes of host event flags. */ 3363 EC_MKBP_EVENT_HOST_EVENT = 1, 3364 3365 /* New Sensor FIFO data. The event data is fifo_info structure. */ 3366 EC_MKBP_EVENT_SENSOR_FIFO = 2, 3367 3368 /* The state of the non-matrixed buttons have changed. */ 3369 EC_MKBP_EVENT_BUTTON = 3, 3370 3371 /* The state of the switches have changed. */ 3372 EC_MKBP_EVENT_SWITCH = 4, 3373 3374 /* New Fingerprint sensor event, the event data is fp_events bitmap. */ 3375 EC_MKBP_EVENT_FINGERPRINT = 5, 3376 3377 /* 3378 * Sysrq event: send emulated sysrq. The event data is sysrq, 3379 * corresponding to the key to be pressed. 3380 */ 3381 EC_MKBP_EVENT_SYSRQ = 6, 3382 3383 /* 3384 * New 64-bit host event. 3385 * The event data is 8 bytes of host event flags. 3386 */ 3387 EC_MKBP_EVENT_HOST_EVENT64 = 7, 3388 3389 /* Notify the AP that something happened on CEC */ 3390 EC_MKBP_EVENT_CEC_EVENT = 8, 3391 3392 /* Send an incoming CEC message to the AP */ 3393 EC_MKBP_EVENT_CEC_MESSAGE = 9, 3394 3395 /* Peripheral device charger event */ 3396 EC_MKBP_EVENT_PCHG = 12, 3397 3398 /* Number of MKBP events */ 3399 EC_MKBP_EVENT_COUNT, 3400 }; 3401 BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); 3402 3403 union __ec_align_offset1 ec_response_get_next_data { 3404 uint8_t key_matrix[13]; 3405 3406 /* Unaligned */ 3407 uint32_t host_event; 3408 uint64_t host_event64; 3409 3410 struct __ec_todo_unpacked { 3411 /* For aligning the fifo_info */ 3412 uint8_t reserved[3]; 3413 struct ec_response_motion_sense_fifo_info info; 3414 } sensor_fifo; 3415 3416 uint32_t buttons; 3417 3418 uint32_t switches; 3419 3420 uint32_t fp_events; 3421 3422 uint32_t sysrq; 3423 3424 /* CEC events from enum mkbp_cec_event */ 3425 uint32_t cec_events; 3426 }; 3427 3428 union __ec_align_offset1 ec_response_get_next_data_v1 { 3429 uint8_t key_matrix[16]; 3430 3431 /* Unaligned */ 3432 uint32_t host_event; 3433 uint64_t host_event64; 3434 3435 struct __ec_todo_unpacked { 3436 /* For aligning the fifo_info */ 3437 uint8_t reserved[3]; 3438 struct ec_response_motion_sense_fifo_info info; 3439 } sensor_fifo; 3440 3441 uint32_t buttons; 3442 3443 uint32_t switches; 3444 3445 uint32_t fp_events; 3446 3447 uint32_t sysrq; 3448 3449 /* CEC events from enum mkbp_cec_event */ 3450 uint32_t cec_events; 3451 3452 uint8_t cec_message[16]; 3453 }; 3454 BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); 3455 3456 struct ec_response_get_next_event { 3457 uint8_t event_type; 3458 /* Followed by event data if any */ 3459 union ec_response_get_next_data data; 3460 } __ec_align1; 3461 3462 struct ec_response_get_next_event_v1 { 3463 uint8_t event_type; 3464 /* Followed by event data if any */ 3465 union ec_response_get_next_data_v1 data; 3466 } __ec_align1; 3467 3468 /* Bit indices for buttons and switches.*/ 3469 /* Buttons */ 3470 #define EC_MKBP_POWER_BUTTON 0 3471 #define EC_MKBP_VOL_UP 1 3472 #define EC_MKBP_VOL_DOWN 2 3473 #define EC_MKBP_RECOVERY 3 3474 #define EC_MKBP_BRI_UP 4 3475 #define EC_MKBP_BRI_DOWN 5 3476 #define EC_MKBP_SCREEN_LOCK 6 3477 3478 /* Switches */ 3479 #define EC_MKBP_LID_OPEN 0 3480 #define EC_MKBP_TABLET_MODE 1 3481 #define EC_MKBP_BASE_ATTACHED 2 3482 #define EC_MKBP_FRONT_PROXIMITY 3 3483 3484 /* Run keyboard factory test scanning */ 3485 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 3486 3487 struct ec_response_keyboard_factory_test { 3488 uint16_t shorted; /* Keyboard pins are shorted */ 3489 } __ec_align2; 3490 3491 /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ 3492 #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) 3493 #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) 3494 #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 3495 #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ 3496 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) 3497 #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 3498 #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 3499 #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ 3500 >> EC_MKBP_FP_MATCH_IDX_OFFSET) 3501 #define EC_MKBP_FP_ENROLL BIT(27) 3502 #define EC_MKBP_FP_MATCH BIT(28) 3503 #define EC_MKBP_FP_FINGER_DOWN BIT(29) 3504 #define EC_MKBP_FP_FINGER_UP BIT(30) 3505 #define EC_MKBP_FP_IMAGE_READY BIT(31) 3506 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ 3507 #define EC_MKBP_FP_ERR_ENROLL_OK 0 3508 #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 3509 #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 3510 #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 3511 #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 3512 /* Can be used to detect if image was usable for enrollment or not. */ 3513 #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 3514 /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ 3515 #define EC_MKBP_FP_ERR_MATCH_NO 0 3516 #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 3517 #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 3518 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 3519 #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 3520 #define EC_MKBP_FP_ERR_MATCH_YES 1 3521 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 3522 #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 3523 3524 3525 /*****************************************************************************/ 3526 /* Temperature sensor commands */ 3527 3528 /* Read temperature sensor info */ 3529 #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 3530 3531 struct ec_params_temp_sensor_get_info { 3532 uint8_t id; 3533 } __ec_align1; 3534 3535 struct ec_response_temp_sensor_get_info { 3536 char sensor_name[32]; 3537 uint8_t sensor_type; 3538 } __ec_align1; 3539 3540 /*****************************************************************************/ 3541 3542 /* 3543 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI 3544 * commands accidentally sent to the wrong interface. See the ACPI section 3545 * below. 3546 */ 3547 3548 /*****************************************************************************/ 3549 /* Host event commands */ 3550 3551 3552 /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ 3553 /* 3554 * Host event mask params and response structures, shared by all of the host 3555 * event commands below. 3556 */ 3557 struct ec_params_host_event_mask { 3558 uint32_t mask; 3559 } __ec_align4; 3560 3561 struct ec_response_host_event_mask { 3562 uint32_t mask; 3563 } __ec_align4; 3564 3565 /* These all use ec_response_host_event_mask */ 3566 #define EC_CMD_HOST_EVENT_GET_B 0x0087 3567 #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 3568 #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 3569 #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D 3570 3571 /* These all use ec_params_host_event_mask */ 3572 #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A 3573 #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B 3574 #define EC_CMD_HOST_EVENT_CLEAR 0x008C 3575 #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E 3576 #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F 3577 3578 /* 3579 * Unified host event programming interface - Should be used by newer versions 3580 * of BIOS/OS to program host events and masks 3581 */ 3582 3583 struct ec_params_host_event { 3584 3585 /* Action requested by host - one of enum ec_host_event_action. */ 3586 uint8_t action; 3587 3588 /* 3589 * Mask type that the host requested the action on - one of 3590 * enum ec_host_event_mask_type. 3591 */ 3592 uint8_t mask_type; 3593 3594 /* Set to 0, ignore on read */ 3595 uint16_t reserved; 3596 3597 /* Value to be used in case of set operations. */ 3598 uint64_t value; 3599 } __ec_align4; 3600 3601 /* 3602 * Response structure returned by EC_CMD_HOST_EVENT. 3603 * Update the value on a GET request. Set to 0 on GET/CLEAR 3604 */ 3605 3606 struct ec_response_host_event { 3607 3608 /* Mask value in case of get operation */ 3609 uint64_t value; 3610 } __ec_align4; 3611 3612 enum ec_host_event_action { 3613 /* 3614 * params.value is ignored. Value of mask_type populated 3615 * in response.value 3616 */ 3617 EC_HOST_EVENT_GET, 3618 3619 /* Bits in params.value are set */ 3620 EC_HOST_EVENT_SET, 3621 3622 /* Bits in params.value are cleared */ 3623 EC_HOST_EVENT_CLEAR, 3624 }; 3625 3626 enum ec_host_event_mask_type { 3627 3628 /* Main host event copy */ 3629 EC_HOST_EVENT_MAIN, 3630 3631 /* Copy B of host events */ 3632 EC_HOST_EVENT_B, 3633 3634 /* SCI Mask */ 3635 EC_HOST_EVENT_SCI_MASK, 3636 3637 /* SMI Mask */ 3638 EC_HOST_EVENT_SMI_MASK, 3639 3640 /* Mask of events that should be always reported in hostevents */ 3641 EC_HOST_EVENT_ALWAYS_REPORT_MASK, 3642 3643 /* Active wake mask */ 3644 EC_HOST_EVENT_ACTIVE_WAKE_MASK, 3645 3646 /* Lazy wake mask for S0ix */ 3647 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, 3648 3649 /* Lazy wake mask for S3 */ 3650 EC_HOST_EVENT_LAZY_WAKE_MASK_S3, 3651 3652 /* Lazy wake mask for S5 */ 3653 EC_HOST_EVENT_LAZY_WAKE_MASK_S5, 3654 }; 3655 3656 #define EC_CMD_HOST_EVENT 0x00A4 3657 3658 /*****************************************************************************/ 3659 /* Switch commands */ 3660 3661 /* Enable/disable LCD backlight */ 3662 #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 3663 3664 struct ec_params_switch_enable_backlight { 3665 uint8_t enabled; 3666 } __ec_align1; 3667 3668 /* Enable/disable WLAN/Bluetooth */ 3669 #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 3670 #define EC_VER_SWITCH_ENABLE_WIRELESS 1 3671 3672 /* Version 0 params; no response */ 3673 struct ec_params_switch_enable_wireless_v0 { 3674 uint8_t enabled; 3675 } __ec_align1; 3676 3677 /* Version 1 params */ 3678 struct ec_params_switch_enable_wireless_v1 { 3679 /* Flags to enable now */ 3680 uint8_t now_flags; 3681 3682 /* Which flags to copy from now_flags */ 3683 uint8_t now_mask; 3684 3685 /* 3686 * Flags to leave enabled in S3, if they're on at the S0->S3 3687 * transition. (Other flags will be disabled by the S0->S3 3688 * transition.) 3689 */ 3690 uint8_t suspend_flags; 3691 3692 /* Which flags to copy from suspend_flags */ 3693 uint8_t suspend_mask; 3694 } __ec_align1; 3695 3696 /* Version 1 response */ 3697 struct ec_response_switch_enable_wireless_v1 { 3698 /* Flags to enable now */ 3699 uint8_t now_flags; 3700 3701 /* Flags to leave enabled in S3 */ 3702 uint8_t suspend_flags; 3703 } __ec_align1; 3704 3705 /*****************************************************************************/ 3706 /* GPIO commands. Only available on EC if write protect has been disabled. */ 3707 3708 /* Set GPIO output value */ 3709 #define EC_CMD_GPIO_SET 0x0092 3710 3711 struct ec_params_gpio_set { 3712 char name[32]; 3713 uint8_t val; 3714 } __ec_align1; 3715 3716 /* Get GPIO value */ 3717 #define EC_CMD_GPIO_GET 0x0093 3718 3719 /* Version 0 of input params and response */ 3720 struct ec_params_gpio_get { 3721 char name[32]; 3722 } __ec_align1; 3723 3724 struct ec_response_gpio_get { 3725 uint8_t val; 3726 } __ec_align1; 3727 3728 /* Version 1 of input params and response */ 3729 struct ec_params_gpio_get_v1 { 3730 uint8_t subcmd; 3731 union { 3732 struct __ec_align1 { 3733 char name[32]; 3734 } get_value_by_name; 3735 struct __ec_align1 { 3736 uint8_t index; 3737 } get_info; 3738 }; 3739 } __ec_align1; 3740 3741 struct ec_response_gpio_get_v1 { 3742 union { 3743 struct __ec_align1 { 3744 uint8_t val; 3745 } get_value_by_name, get_count; 3746 struct __ec_todo_unpacked { 3747 uint8_t val; 3748 char name[32]; 3749 uint32_t flags; 3750 } get_info; 3751 }; 3752 } __ec_todo_packed; 3753 3754 enum gpio_get_subcmd { 3755 EC_GPIO_GET_BY_NAME = 0, 3756 EC_GPIO_GET_COUNT = 1, 3757 EC_GPIO_GET_INFO = 2, 3758 }; 3759 3760 /*****************************************************************************/ 3761 /* I2C commands. Only available when flash write protect is unlocked. */ 3762 3763 /* 3764 * CAUTION: These commands are deprecated, and are not supported anymore in EC 3765 * builds >= 8398.0.0 (see crosbug.com/p/23570). 3766 * 3767 * Use EC_CMD_I2C_PASSTHRU instead. 3768 */ 3769 3770 /* Read I2C bus */ 3771 #define EC_CMD_I2C_READ 0x0094 3772 3773 struct ec_params_i2c_read { 3774 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ 3775 uint8_t read_size; /* Either 8 or 16. */ 3776 uint8_t port; 3777 uint8_t offset; 3778 } __ec_align_size1; 3779 3780 struct ec_response_i2c_read { 3781 uint16_t data; 3782 } __ec_align2; 3783 3784 /* Write I2C bus */ 3785 #define EC_CMD_I2C_WRITE 0x0095 3786 3787 struct ec_params_i2c_write { 3788 uint16_t data; 3789 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ 3790 uint8_t write_size; /* Either 8 or 16. */ 3791 uint8_t port; 3792 uint8_t offset; 3793 } __ec_align_size1; 3794 3795 /*****************************************************************************/ 3796 /* Charge state commands. Only available when flash write protect unlocked. */ 3797 3798 /* Force charge state machine to stop charging the battery or force it to 3799 * discharge the battery. 3800 */ 3801 #define EC_CMD_CHARGE_CONTROL 0x0096 3802 #define EC_VER_CHARGE_CONTROL 1 3803 3804 enum ec_charge_control_mode { 3805 CHARGE_CONTROL_NORMAL = 0, 3806 CHARGE_CONTROL_IDLE, 3807 CHARGE_CONTROL_DISCHARGE, 3808 }; 3809 3810 struct ec_params_charge_control { 3811 uint32_t mode; /* enum charge_control_mode */ 3812 } __ec_align4; 3813 3814 /*****************************************************************************/ 3815 3816 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ 3817 #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 3818 3819 /* 3820 * Read data from the saved snapshot. If the subcmd parameter is 3821 * CONSOLE_READ_NEXT, this will return data starting from the beginning of 3822 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the 3823 * end of the previous snapshot. 3824 * 3825 * The params are only looked at in version >= 1 of this command. Prior 3826 * versions will just default to CONSOLE_READ_NEXT behavior. 3827 * 3828 * Response is null-terminated string. Empty string, if there is no more 3829 * remaining output. 3830 */ 3831 #define EC_CMD_CONSOLE_READ 0x0098 3832 3833 enum ec_console_read_subcmd { 3834 CONSOLE_READ_NEXT = 0, 3835 CONSOLE_READ_RECENT 3836 }; 3837 3838 struct ec_params_console_read_v1 { 3839 uint8_t subcmd; /* enum ec_console_read_subcmd */ 3840 } __ec_align1; 3841 3842 /*****************************************************************************/ 3843 3844 /* 3845 * Cut off battery power immediately or after the host has shut down. 3846 * 3847 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. 3848 * EC_RES_SUCCESS if the command was successful. 3849 * EC_RES_ERROR if the cut off command failed. 3850 */ 3851 #define EC_CMD_BATTERY_CUT_OFF 0x0099 3852 3853 #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) 3854 3855 struct ec_params_battery_cutoff { 3856 uint8_t flags; 3857 } __ec_align1; 3858 3859 /*****************************************************************************/ 3860 /* USB port mux control. */ 3861 3862 /* 3863 * Switch USB mux or return to automatic switching. 3864 */ 3865 #define EC_CMD_USB_MUX 0x009A 3866 3867 struct ec_params_usb_mux { 3868 uint8_t mux; 3869 } __ec_align1; 3870 3871 /*****************************************************************************/ 3872 /* LDOs / FETs control. */ 3873 3874 enum ec_ldo_state { 3875 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ 3876 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ 3877 }; 3878 3879 /* 3880 * Switch on/off a LDO. 3881 */ 3882 #define EC_CMD_LDO_SET 0x009B 3883 3884 struct ec_params_ldo_set { 3885 uint8_t index; 3886 uint8_t state; 3887 } __ec_align1; 3888 3889 /* 3890 * Get LDO state. 3891 */ 3892 #define EC_CMD_LDO_GET 0x009C 3893 3894 struct ec_params_ldo_get { 3895 uint8_t index; 3896 } __ec_align1; 3897 3898 struct ec_response_ldo_get { 3899 uint8_t state; 3900 } __ec_align1; 3901 3902 /*****************************************************************************/ 3903 /* Power info. */ 3904 3905 /* 3906 * Get power info. 3907 */ 3908 #define EC_CMD_POWER_INFO 0x009D 3909 3910 struct ec_response_power_info { 3911 uint32_t usb_dev_type; 3912 uint16_t voltage_ac; 3913 uint16_t voltage_system; 3914 uint16_t current_system; 3915 uint16_t usb_current_limit; 3916 } __ec_align4; 3917 3918 /*****************************************************************************/ 3919 /* I2C passthru command */ 3920 3921 #define EC_CMD_I2C_PASSTHRU 0x009E 3922 3923 /* Read data; if not present, message is a write */ 3924 #define EC_I2C_FLAG_READ BIT(15) 3925 3926 /* Mask for address */ 3927 #define EC_I2C_ADDR_MASK 0x3ff 3928 3929 #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ 3930 #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ 3931 3932 /* Any error */ 3933 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) 3934 3935 struct ec_params_i2c_passthru_msg { 3936 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */ 3937 uint16_t len; /* Number of bytes to read or write */ 3938 } __ec_align2; 3939 3940 struct ec_params_i2c_passthru { 3941 uint8_t port; /* I2C port number */ 3942 uint8_t num_msgs; /* Number of messages */ 3943 struct ec_params_i2c_passthru_msg msg[]; 3944 /* Data to write for all messages is concatenated here */ 3945 } __ec_align2; 3946 3947 struct ec_response_i2c_passthru { 3948 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ 3949 uint8_t num_msgs; /* Number of messages processed */ 3950 uint8_t data[]; /* Data read by messages concatenated here */ 3951 } __ec_align1; 3952 3953 /*****************************************************************************/ 3954 /* Power button hang detect */ 3955 3956 #define EC_CMD_HANG_DETECT 0x009F 3957 3958 /* Reasons to start hang detection timer */ 3959 /* Power button pressed */ 3960 #define EC_HANG_START_ON_POWER_PRESS BIT(0) 3961 3962 /* Lid closed */ 3963 #define EC_HANG_START_ON_LID_CLOSE BIT(1) 3964 3965 /* Lid opened */ 3966 #define EC_HANG_START_ON_LID_OPEN BIT(2) 3967 3968 /* Start of AP S3->S0 transition (booting or resuming from suspend) */ 3969 #define EC_HANG_START_ON_RESUME BIT(3) 3970 3971 /* Reasons to cancel hang detection */ 3972 3973 /* Power button released */ 3974 #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) 3975 3976 /* Any host command from AP received */ 3977 #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) 3978 3979 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ 3980 #define EC_HANG_STOP_ON_SUSPEND BIT(10) 3981 3982 /* 3983 * If this flag is set, all the other fields are ignored, and the hang detect 3984 * timer is started. This provides the AP a way to start the hang timer 3985 * without reconfiguring any of the other hang detect settings. Note that 3986 * you must previously have configured the timeouts. 3987 */ 3988 #define EC_HANG_START_NOW BIT(30) 3989 3990 /* 3991 * If this flag is set, all the other fields are ignored (including 3992 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer 3993 * without reconfiguring any of the other hang detect settings. 3994 */ 3995 #define EC_HANG_STOP_NOW BIT(31) 3996 3997 struct ec_params_hang_detect { 3998 /* Flags; see EC_HANG_* */ 3999 uint32_t flags; 4000 4001 /* Timeout in msec before generating host event, if enabled */ 4002 uint16_t host_event_timeout_msec; 4003 4004 /* Timeout in msec before generating warm reboot, if enabled */ 4005 uint16_t warm_reboot_timeout_msec; 4006 } __ec_align4; 4007 4008 /*****************************************************************************/ 4009 /* Commands for battery charging */ 4010 4011 /* 4012 * This is the single catch-all host command to exchange data regarding the 4013 * charge state machine (v2 and up). 4014 */ 4015 #define EC_CMD_CHARGE_STATE 0x00A0 4016 4017 /* Subcommands for this host command */ 4018 enum charge_state_command { 4019 CHARGE_STATE_CMD_GET_STATE, 4020 CHARGE_STATE_CMD_GET_PARAM, 4021 CHARGE_STATE_CMD_SET_PARAM, 4022 CHARGE_STATE_NUM_CMDS 4023 }; 4024 4025 /* 4026 * Known param numbers are defined here. Ranges are reserved for board-specific 4027 * params, which are handled by the particular implementations. 4028 */ 4029 enum charge_state_params { 4030 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ 4031 CS_PARAM_CHG_CURRENT, /* charger current limit */ 4032 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ 4033 CS_PARAM_CHG_STATUS, /* charger-specific status */ 4034 CS_PARAM_CHG_OPTION, /* charger-specific options */ 4035 CS_PARAM_LIMIT_POWER, /* 4036 * Check if power is limited due to 4037 * low battery and / or a weak external 4038 * charger. READ ONLY. 4039 */ 4040 /* How many so far? */ 4041 CS_NUM_BASE_PARAMS, 4042 4043 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ 4044 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, 4045 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, 4046 4047 /* Range for CONFIG_CHARGE_STATE_DEBUG params */ 4048 CS_PARAM_DEBUG_MIN = 0x20000, 4049 CS_PARAM_DEBUG_CTL_MODE = 0x20000, 4050 CS_PARAM_DEBUG_MANUAL_MODE, 4051 CS_PARAM_DEBUG_SEEMS_DEAD, 4052 CS_PARAM_DEBUG_SEEMS_DISCONNECTED, 4053 CS_PARAM_DEBUG_BATT_REMOVED, 4054 CS_PARAM_DEBUG_MANUAL_CURRENT, 4055 CS_PARAM_DEBUG_MANUAL_VOLTAGE, 4056 CS_PARAM_DEBUG_MAX = 0x2ffff, 4057 4058 /* Other custom param ranges go here... */ 4059 }; 4060 4061 struct ec_params_charge_state { 4062 uint8_t cmd; /* enum charge_state_command */ 4063 union { 4064 /* get_state has no args */ 4065 4066 struct __ec_todo_unpacked { 4067 uint32_t param; /* enum charge_state_param */ 4068 } get_param; 4069 4070 struct __ec_todo_unpacked { 4071 uint32_t param; /* param to set */ 4072 uint32_t value; /* value to set */ 4073 } set_param; 4074 }; 4075 } __ec_todo_packed; 4076 4077 struct ec_response_charge_state { 4078 union { 4079 struct __ec_align4 { 4080 int ac; 4081 int chg_voltage; 4082 int chg_current; 4083 int chg_input_current; 4084 int batt_state_of_charge; 4085 } get_state; 4086 4087 struct __ec_align4 { 4088 uint32_t value; 4089 } get_param; 4090 4091 /* set_param returns no args */ 4092 }; 4093 } __ec_align4; 4094 4095 4096 /* 4097 * Set maximum battery charging current. 4098 */ 4099 #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 4100 4101 struct ec_params_current_limit { 4102 uint32_t limit; /* in mA */ 4103 } __ec_align4; 4104 4105 /* 4106 * Set maximum external voltage / current. 4107 */ 4108 #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 4109 4110 /* Command v0 is used only on Spring and is obsolete + unsupported */ 4111 struct ec_params_external_power_limit_v1 { 4112 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ 4113 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */ 4114 } __ec_align2; 4115 4116 #define EC_POWER_LIMIT_NONE 0xffff 4117 4118 /* 4119 * Set maximum voltage & current of a dedicated charge port 4120 */ 4121 #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 4122 4123 struct ec_params_dedicated_charger_limit { 4124 uint16_t current_lim; /* in mA */ 4125 uint16_t voltage_lim; /* in mV */ 4126 } __ec_align2; 4127 4128 /*****************************************************************************/ 4129 /* Hibernate/Deep Sleep Commands */ 4130 4131 /* Set the delay before going into hibernation. */ 4132 #define EC_CMD_HIBERNATION_DELAY 0x00A8 4133 4134 struct ec_params_hibernation_delay { 4135 /* 4136 * Seconds to wait in G3 before hibernate. Pass in 0 to read the 4137 * current settings without changing them. 4138 */ 4139 uint32_t seconds; 4140 } __ec_align4; 4141 4142 struct ec_response_hibernation_delay { 4143 /* 4144 * The current time in seconds in which the system has been in the G3 4145 * state. This value is reset if the EC transitions out of G3. 4146 */ 4147 uint32_t time_g3; 4148 4149 /* 4150 * The current time remaining in seconds until the EC should hibernate. 4151 * This value is also reset if the EC transitions out of G3. 4152 */ 4153 uint32_t time_remaining; 4154 4155 /* 4156 * The current time in seconds that the EC should wait in G3 before 4157 * hibernating. 4158 */ 4159 uint32_t hibernate_delay; 4160 } __ec_align4; 4161 4162 /* Inform the EC when entering a sleep state */ 4163 #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 4164 4165 enum host_sleep_event { 4166 HOST_SLEEP_EVENT_S3_SUSPEND = 1, 4167 HOST_SLEEP_EVENT_S3_RESUME = 2, 4168 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, 4169 HOST_SLEEP_EVENT_S0IX_RESUME = 4, 4170 /* S3 suspend with additional enabled wake sources */ 4171 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, 4172 }; 4173 4174 struct ec_params_host_sleep_event { 4175 uint8_t sleep_event; 4176 } __ec_align1; 4177 4178 /* 4179 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep 4180 * transition failures 4181 */ 4182 #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 4183 4184 /* Disable timeout detection for this sleep transition */ 4185 #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF 4186 4187 struct ec_params_host_sleep_event_v1 { 4188 /* The type of sleep being entered or exited. */ 4189 uint8_t sleep_event; 4190 4191 /* Padding */ 4192 uint8_t reserved; 4193 union { 4194 /* Parameters that apply for suspend messages. */ 4195 struct { 4196 /* 4197 * The timeout in milliseconds between when this message 4198 * is received and when the EC will declare sleep 4199 * transition failure if the sleep signal is not 4200 * asserted. 4201 */ 4202 uint16_t sleep_timeout_ms; 4203 } suspend_params; 4204 4205 /* No parameters for non-suspend messages. */ 4206 }; 4207 } __ec_align2; 4208 4209 /* A timeout occurred when this bit is set */ 4210 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 4211 4212 /* 4213 * The mask defining which bits correspond to the number of sleep transitions, 4214 * as well as the maximum number of suspend line transitions that will be 4215 * reported back to the host. 4216 */ 4217 #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF 4218 4219 struct ec_response_host_sleep_event_v1 { 4220 union { 4221 /* Response fields that apply for resume messages. */ 4222 struct { 4223 /* 4224 * The number of sleep power signal transitions that 4225 * occurred since the suspend message. The high bit 4226 * indicates a timeout occurred. 4227 */ 4228 uint32_t sleep_transitions; 4229 } resume_response; 4230 4231 /* No response fields for non-resume messages. */ 4232 }; 4233 } __ec_align4; 4234 4235 /*****************************************************************************/ 4236 /* Device events */ 4237 #define EC_CMD_DEVICE_EVENT 0x00AA 4238 4239 enum ec_device_event { 4240 EC_DEVICE_EVENT_TRACKPAD, 4241 EC_DEVICE_EVENT_DSP, 4242 EC_DEVICE_EVENT_WIFI, 4243 EC_DEVICE_EVENT_WLC, 4244 }; 4245 4246 enum ec_device_event_param { 4247 /* Get and clear pending device events */ 4248 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, 4249 /* Get device event mask */ 4250 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, 4251 /* Set device event mask */ 4252 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, 4253 }; 4254 4255 #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) 4256 4257 struct ec_params_device_event { 4258 uint32_t event_mask; 4259 uint8_t param; 4260 } __ec_align_size1; 4261 4262 struct ec_response_device_event { 4263 uint32_t event_mask; 4264 } __ec_align4; 4265 4266 /*****************************************************************************/ 4267 /* Smart battery pass-through */ 4268 4269 /* Get / Set 16-bit smart battery registers */ 4270 #define EC_CMD_SB_READ_WORD 0x00B0 4271 #define EC_CMD_SB_WRITE_WORD 0x00B1 4272 4273 /* Get / Set string smart battery parameters 4274 * formatted as SMBUS "block". 4275 */ 4276 #define EC_CMD_SB_READ_BLOCK 0x00B2 4277 #define EC_CMD_SB_WRITE_BLOCK 0x00B3 4278 4279 struct ec_params_sb_rd { 4280 uint8_t reg; 4281 } __ec_align1; 4282 4283 struct ec_response_sb_rd_word { 4284 uint16_t value; 4285 } __ec_align2; 4286 4287 struct ec_params_sb_wr_word { 4288 uint8_t reg; 4289 uint16_t value; 4290 } __ec_align1; 4291 4292 struct ec_response_sb_rd_block { 4293 uint8_t data[32]; 4294 } __ec_align1; 4295 4296 struct ec_params_sb_wr_block { 4297 uint8_t reg; 4298 uint16_t data[32]; 4299 } __ec_align1; 4300 4301 /*****************************************************************************/ 4302 /* Battery vendor parameters 4303 * 4304 * Get or set vendor-specific parameters in the battery. Implementations may 4305 * differ between boards or batteries. On a set operation, the response 4306 * contains the actual value set, which may be rounded or clipped from the 4307 * requested value. 4308 */ 4309 4310 #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 4311 4312 enum ec_battery_vendor_param_mode { 4313 BATTERY_VENDOR_PARAM_MODE_GET = 0, 4314 BATTERY_VENDOR_PARAM_MODE_SET, 4315 }; 4316 4317 struct ec_params_battery_vendor_param { 4318 uint32_t param; 4319 uint32_t value; 4320 uint8_t mode; 4321 } __ec_align_size1; 4322 4323 struct ec_response_battery_vendor_param { 4324 uint32_t value; 4325 } __ec_align4; 4326 4327 /*****************************************************************************/ 4328 /* 4329 * Smart Battery Firmware Update Commands 4330 */ 4331 #define EC_CMD_SB_FW_UPDATE 0x00B5 4332 4333 enum ec_sb_fw_update_subcmd { 4334 EC_SB_FW_UPDATE_PREPARE = 0x0, 4335 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ 4336 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ 4337 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ 4338 EC_SB_FW_UPDATE_END = 0x4, 4339 EC_SB_FW_UPDATE_STATUS = 0x5, 4340 EC_SB_FW_UPDATE_PROTECT = 0x6, 4341 EC_SB_FW_UPDATE_MAX = 0x7, 4342 }; 4343 4344 #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 4345 #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 4346 #define SB_FW_UPDATE_CMD_INFO_SIZE 8 4347 4348 struct ec_sb_fw_update_header { 4349 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ 4350 uint16_t fw_id; /* firmware id */ 4351 } __ec_align4; 4352 4353 struct ec_params_sb_fw_update { 4354 struct ec_sb_fw_update_header hdr; 4355 union { 4356 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ 4357 /* EC_SB_FW_UPDATE_INFO = 0x1 */ 4358 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ 4359 /* EC_SB_FW_UPDATE_END = 0x4 */ 4360 /* EC_SB_FW_UPDATE_STATUS = 0x5 */ 4361 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ 4362 /* Those have no args */ 4363 4364 /* EC_SB_FW_UPDATE_WRITE = 0x3 */ 4365 struct __ec_align4 { 4366 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; 4367 } write; 4368 }; 4369 } __ec_align4; 4370 4371 struct ec_response_sb_fw_update { 4372 union { 4373 /* EC_SB_FW_UPDATE_INFO = 0x1 */ 4374 struct __ec_align1 { 4375 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; 4376 } info; 4377 4378 /* EC_SB_FW_UPDATE_STATUS = 0x5 */ 4379 struct __ec_align1 { 4380 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; 4381 } status; 4382 }; 4383 } __ec_align1; 4384 4385 /* 4386 * Entering Verified Boot Mode Command 4387 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. 4388 * Valid Modes are: normal, developer, and recovery. 4389 */ 4390 #define EC_CMD_ENTERING_MODE 0x00B6 4391 4392 struct ec_params_entering_mode { 4393 int vboot_mode; 4394 } __ec_align4; 4395 4396 #define VBOOT_MODE_NORMAL 0 4397 #define VBOOT_MODE_DEVELOPER 1 4398 #define VBOOT_MODE_RECOVERY 2 4399 4400 /*****************************************************************************/ 4401 /* 4402 * I2C passthru protection command: Protects I2C tunnels against access on 4403 * certain addresses (board-specific). 4404 */ 4405 #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 4406 4407 enum ec_i2c_passthru_protect_subcmd { 4408 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0, 4409 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1, 4410 }; 4411 4412 struct ec_params_i2c_passthru_protect { 4413 uint8_t subcmd; 4414 uint8_t port; /* I2C port number */ 4415 } __ec_align1; 4416 4417 struct ec_response_i2c_passthru_protect { 4418 uint8_t status; /* Status flags (0: unlocked, 1: locked) */ 4419 } __ec_align1; 4420 4421 4422 /*****************************************************************************/ 4423 /* 4424 * HDMI CEC commands 4425 * 4426 * These commands are for sending and receiving message via HDMI CEC 4427 */ 4428 4429 #define MAX_CEC_MSG_LEN 16 4430 4431 /* CEC message from the AP to be written on the CEC bus */ 4432 #define EC_CMD_CEC_WRITE_MSG 0x00B8 4433 4434 /** 4435 * struct ec_params_cec_write - Message to write to the CEC bus 4436 * @msg: message content to write to the CEC bus 4437 */ 4438 struct ec_params_cec_write { 4439 uint8_t msg[MAX_CEC_MSG_LEN]; 4440 } __ec_align1; 4441 4442 /* Set various CEC parameters */ 4443 #define EC_CMD_CEC_SET 0x00BA 4444 4445 /** 4446 * struct ec_params_cec_set - CEC parameters set 4447 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS 4448 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC 4449 * or 1 to enable CEC functionality, in case cmd is 4450 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical 4451 * address between 0 and 15 or 0xff to unregister 4452 */ 4453 struct ec_params_cec_set { 4454 uint8_t cmd; /* enum cec_command */ 4455 uint8_t val; 4456 } __ec_align1; 4457 4458 /* Read various CEC parameters */ 4459 #define EC_CMD_CEC_GET 0x00BB 4460 4461 /** 4462 * struct ec_params_cec_get - CEC parameters get 4463 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS 4464 */ 4465 struct ec_params_cec_get { 4466 uint8_t cmd; /* enum cec_command */ 4467 } __ec_align1; 4468 4469 /** 4470 * struct ec_response_cec_get - CEC parameters get response 4471 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is 4472 * disabled or 1 if CEC functionality is enabled, 4473 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the 4474 * configured logical address between 0 and 15 or 0xff if unregistered 4475 */ 4476 struct ec_response_cec_get { 4477 uint8_t val; 4478 } __ec_align1; 4479 4480 /* CEC parameters command */ 4481 enum cec_command { 4482 /* CEC reading, writing and events enable */ 4483 CEC_CMD_ENABLE, 4484 /* CEC logical address */ 4485 CEC_CMD_LOGICAL_ADDRESS, 4486 }; 4487 4488 /* Events from CEC to AP */ 4489 enum mkbp_cec_event { 4490 /* Outgoing message was acknowledged by a follower */ 4491 EC_MKBP_CEC_SEND_OK = BIT(0), 4492 /* Outgoing message was not acknowledged */ 4493 EC_MKBP_CEC_SEND_FAILED = BIT(1), 4494 }; 4495 4496 /*****************************************************************************/ 4497 4498 /* Commands for audio codec. */ 4499 #define EC_CMD_EC_CODEC 0x00BC 4500 4501 enum ec_codec_subcmd { 4502 EC_CODEC_GET_CAPABILITIES = 0x0, 4503 EC_CODEC_GET_SHM_ADDR = 0x1, 4504 EC_CODEC_SET_SHM_ADDR = 0x2, 4505 EC_CODEC_SUBCMD_COUNT, 4506 }; 4507 4508 enum ec_codec_cap { 4509 EC_CODEC_CAP_WOV_AUDIO_SHM = 0, 4510 EC_CODEC_CAP_WOV_LANG_SHM = 1, 4511 EC_CODEC_CAP_LAST = 32, 4512 }; 4513 4514 enum ec_codec_shm_id { 4515 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, 4516 EC_CODEC_SHM_ID_WOV_LANG = 0x1, 4517 EC_CODEC_SHM_ID_LAST, 4518 }; 4519 4520 enum ec_codec_shm_type { 4521 EC_CODEC_SHM_TYPE_EC_RAM = 0x0, 4522 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, 4523 }; 4524 4525 struct __ec_align1 ec_param_ec_codec_get_shm_addr { 4526 uint8_t shm_id; 4527 uint8_t reserved[3]; 4528 }; 4529 4530 struct __ec_align4 ec_param_ec_codec_set_shm_addr { 4531 uint64_t phys_addr; 4532 uint32_t len; 4533 uint8_t shm_id; 4534 uint8_t reserved[3]; 4535 }; 4536 4537 struct __ec_align4 ec_param_ec_codec { 4538 uint8_t cmd; /* enum ec_codec_subcmd */ 4539 uint8_t reserved[3]; 4540 4541 union { 4542 struct ec_param_ec_codec_get_shm_addr 4543 get_shm_addr_param; 4544 struct ec_param_ec_codec_set_shm_addr 4545 set_shm_addr_param; 4546 }; 4547 }; 4548 4549 struct __ec_align4 ec_response_ec_codec_get_capabilities { 4550 uint32_t capabilities; 4551 }; 4552 4553 struct __ec_align4 ec_response_ec_codec_get_shm_addr { 4554 uint64_t phys_addr; 4555 uint32_t len; 4556 uint8_t type; 4557 uint8_t reserved[3]; 4558 }; 4559 4560 /*****************************************************************************/ 4561 4562 /* Commands for DMIC on audio codec. */ 4563 #define EC_CMD_EC_CODEC_DMIC 0x00BD 4564 4565 enum ec_codec_dmic_subcmd { 4566 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, 4567 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, 4568 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, 4569 EC_CODEC_DMIC_SUBCMD_COUNT, 4570 }; 4571 4572 enum ec_codec_dmic_channel { 4573 EC_CODEC_DMIC_CHANNEL_0 = 0x0, 4574 EC_CODEC_DMIC_CHANNEL_1 = 0x1, 4575 EC_CODEC_DMIC_CHANNEL_2 = 0x2, 4576 EC_CODEC_DMIC_CHANNEL_3 = 0x3, 4577 EC_CODEC_DMIC_CHANNEL_4 = 0x4, 4578 EC_CODEC_DMIC_CHANNEL_5 = 0x5, 4579 EC_CODEC_DMIC_CHANNEL_6 = 0x6, 4580 EC_CODEC_DMIC_CHANNEL_7 = 0x7, 4581 EC_CODEC_DMIC_CHANNEL_COUNT, 4582 }; 4583 4584 struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { 4585 uint8_t channel; /* enum ec_codec_dmic_channel */ 4586 uint8_t gain; 4587 uint8_t reserved[2]; 4588 }; 4589 4590 struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { 4591 uint8_t channel; /* enum ec_codec_dmic_channel */ 4592 uint8_t reserved[3]; 4593 }; 4594 4595 struct __ec_align4 ec_param_ec_codec_dmic { 4596 uint8_t cmd; /* enum ec_codec_dmic_subcmd */ 4597 uint8_t reserved[3]; 4598 4599 union { 4600 struct ec_param_ec_codec_dmic_set_gain_idx 4601 set_gain_idx_param; 4602 struct ec_param_ec_codec_dmic_get_gain_idx 4603 get_gain_idx_param; 4604 }; 4605 }; 4606 4607 struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { 4608 uint8_t max_gain; 4609 }; 4610 4611 struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { 4612 uint8_t gain; 4613 }; 4614 4615 /*****************************************************************************/ 4616 4617 /* Commands for I2S RX on audio codec. */ 4618 4619 #define EC_CMD_EC_CODEC_I2S_RX 0x00BE 4620 4621 enum ec_codec_i2s_rx_subcmd { 4622 EC_CODEC_I2S_RX_ENABLE = 0x0, 4623 EC_CODEC_I2S_RX_DISABLE = 0x1, 4624 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, 4625 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, 4626 EC_CODEC_I2S_RX_SET_BCLK = 0x4, 4627 EC_CODEC_I2S_RX_RESET = 0x5, 4628 EC_CODEC_I2S_RX_SUBCMD_COUNT, 4629 }; 4630 4631 enum ec_codec_i2s_rx_sample_depth { 4632 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, 4633 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, 4634 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, 4635 }; 4636 4637 enum ec_codec_i2s_rx_daifmt { 4638 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, 4639 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, 4640 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, 4641 EC_CODEC_I2S_RX_DAIFMT_COUNT, 4642 }; 4643 4644 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { 4645 uint8_t depth; 4646 uint8_t reserved[3]; 4647 }; 4648 4649 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { 4650 uint8_t left; 4651 uint8_t right; 4652 uint8_t reserved[2]; 4653 }; 4654 4655 struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { 4656 uint8_t daifmt; 4657 uint8_t reserved[3]; 4658 }; 4659 4660 struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { 4661 uint32_t bclk; 4662 }; 4663 4664 struct __ec_align4 ec_param_ec_codec_i2s_rx { 4665 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ 4666 uint8_t reserved[3]; 4667 4668 union { 4669 struct ec_param_ec_codec_i2s_rx_set_sample_depth 4670 set_sample_depth_param; 4671 struct ec_param_ec_codec_i2s_rx_set_daifmt 4672 set_daifmt_param; 4673 struct ec_param_ec_codec_i2s_rx_set_bclk 4674 set_bclk_param; 4675 }; 4676 }; 4677 4678 /*****************************************************************************/ 4679 /* Commands for WoV on audio codec. */ 4680 4681 #define EC_CMD_EC_CODEC_WOV 0x00BF 4682 4683 enum ec_codec_wov_subcmd { 4684 EC_CODEC_WOV_SET_LANG = 0x0, 4685 EC_CODEC_WOV_SET_LANG_SHM = 0x1, 4686 EC_CODEC_WOV_GET_LANG = 0x2, 4687 EC_CODEC_WOV_ENABLE = 0x3, 4688 EC_CODEC_WOV_DISABLE = 0x4, 4689 EC_CODEC_WOV_READ_AUDIO = 0x5, 4690 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, 4691 EC_CODEC_WOV_SUBCMD_COUNT, 4692 }; 4693 4694 /* 4695 * @hash is SHA256 of the whole language model. 4696 * @total_len indicates the length of whole language model. 4697 * @offset is the cursor from the beginning of the model. 4698 * @buf is the packet buffer. 4699 * @len denotes how many bytes in the buf. 4700 */ 4701 struct __ec_align4 ec_param_ec_codec_wov_set_lang { 4702 uint8_t hash[32]; 4703 uint32_t total_len; 4704 uint32_t offset; 4705 uint8_t buf[128]; 4706 uint32_t len; 4707 }; 4708 4709 struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { 4710 uint8_t hash[32]; 4711 uint32_t total_len; 4712 }; 4713 4714 struct __ec_align4 ec_param_ec_codec_wov { 4715 uint8_t cmd; /* enum ec_codec_wov_subcmd */ 4716 uint8_t reserved[3]; 4717 4718 union { 4719 struct ec_param_ec_codec_wov_set_lang 4720 set_lang_param; 4721 struct ec_param_ec_codec_wov_set_lang_shm 4722 set_lang_shm_param; 4723 }; 4724 }; 4725 4726 struct __ec_align4 ec_response_ec_codec_wov_get_lang { 4727 uint8_t hash[32]; 4728 }; 4729 4730 struct __ec_align4 ec_response_ec_codec_wov_read_audio { 4731 uint8_t buf[128]; 4732 uint32_t len; 4733 }; 4734 4735 struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { 4736 uint32_t offset; 4737 uint32_t len; 4738 }; 4739 4740 /*****************************************************************************/ 4741 /* System commands */ 4742 4743 /* 4744 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't 4745 * necessarily reboot the EC. Rename to "image" or something similar? 4746 */ 4747 #define EC_CMD_REBOOT_EC 0x00D2 4748 4749 /* Command */ 4750 enum ec_reboot_cmd { 4751 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ 4752 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ 4753 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ 4754 /* (command 3 was jump to RW-B) */ 4755 EC_REBOOT_COLD = 4, /* Cold-reboot */ 4756 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ 4757 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ 4758 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */ 4759 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */ 4760 }; 4761 4762 /* Flags for ec_params_reboot_ec.reboot_flags */ 4763 #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ 4764 #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ 4765 #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ 4766 4767 struct ec_params_reboot_ec { 4768 uint8_t cmd; /* enum ec_reboot_cmd */ 4769 uint8_t flags; /* See EC_REBOOT_FLAG_* */ 4770 } __ec_align1; 4771 4772 /* 4773 * Get information on last EC panic. 4774 * 4775 * Returns variable-length platform-dependent panic information. See panic.h 4776 * for details. 4777 */ 4778 #define EC_CMD_GET_PANIC_INFO 0x00D3 4779 4780 /*****************************************************************************/ 4781 /* 4782 * Special commands 4783 * 4784 * These do not follow the normal rules for commands. See each command for 4785 * details. 4786 */ 4787 4788 /* 4789 * Reboot NOW 4790 * 4791 * This command will work even when the EC LPC interface is busy, because the 4792 * reboot command is processed at interrupt level. Note that when the EC 4793 * reboots, the host will reboot too, so there is no response to this command. 4794 * 4795 * Use EC_CMD_REBOOT_EC to reboot the EC more politely. 4796 */ 4797 #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ 4798 4799 /* 4800 * Resend last response (not supported on LPC). 4801 * 4802 * Returns EC_RES_UNAVAILABLE if there is no response available - for example, 4803 * there was no previous command, or the previous command's response was too 4804 * big to save. 4805 */ 4806 #define EC_CMD_RESEND_RESPONSE 0x00DB 4807 4808 /* 4809 * This header byte on a command indicate version 0. Any header byte less 4810 * than this means that we are talking to an old EC which doesn't support 4811 * versioning. In that case, we assume version 0. 4812 * 4813 * Header bytes greater than this indicate a later version. For example, 4814 * EC_CMD_VERSION0 + 1 means we are using version 1. 4815 * 4816 * The old EC interface must not use commands 0xdc or higher. 4817 */ 4818 #define EC_CMD_VERSION0 0x00DC 4819 4820 /*****************************************************************************/ 4821 /* 4822 * PD commands 4823 * 4824 * These commands are for PD MCU communication. 4825 */ 4826 4827 /* EC to PD MCU exchange status command */ 4828 #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 4829 #define EC_VER_PD_EXCHANGE_STATUS 2 4830 4831 enum pd_charge_state { 4832 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ 4833 PD_CHARGE_NONE, /* No charging allowed */ 4834 PD_CHARGE_5V, /* 5V charging only */ 4835 PD_CHARGE_MAX /* Charge at max voltage */ 4836 }; 4837 4838 /* Status of EC being sent to PD */ 4839 #define EC_STATUS_HIBERNATING BIT(0) 4840 4841 struct ec_params_pd_status { 4842 uint8_t status; /* EC status */ 4843 int8_t batt_soc; /* battery state of charge */ 4844 uint8_t charge_state; /* charging state (from enum pd_charge_state) */ 4845 } __ec_align1; 4846 4847 /* Status of PD being sent back to EC */ 4848 #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ 4849 #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ 4850 #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ 4851 #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ 4852 #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ 4853 #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ 4854 #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ 4855 #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ 4856 PD_STATUS_TCPC_ALERT_1 | \ 4857 PD_STATUS_HOST_EVENT) 4858 struct ec_response_pd_status { 4859 uint32_t curr_lim_ma; /* input current limit */ 4860 uint16_t status; /* PD MCU status */ 4861 int8_t active_charge_port; /* active charging port */ 4862 } __ec_align_size1; 4863 4864 /* AP to PD MCU host event status command, cleared on read */ 4865 #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 4866 4867 /* PD MCU host event status bits */ 4868 #define PD_EVENT_UPDATE_DEVICE BIT(0) 4869 #define PD_EVENT_POWER_CHANGE BIT(1) 4870 #define PD_EVENT_IDENTITY_RECEIVED BIT(2) 4871 #define PD_EVENT_DATA_SWAP BIT(3) 4872 struct ec_response_host_event_status { 4873 uint32_t status; /* PD MCU host event status */ 4874 } __ec_align4; 4875 4876 /* Set USB type-C port role and muxes */ 4877 #define EC_CMD_USB_PD_CONTROL 0x0101 4878 4879 enum usb_pd_control_role { 4880 USB_PD_CTRL_ROLE_NO_CHANGE = 0, 4881 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ 4882 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, 4883 USB_PD_CTRL_ROLE_FORCE_SINK = 3, 4884 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, 4885 USB_PD_CTRL_ROLE_FREEZE = 5, 4886 USB_PD_CTRL_ROLE_COUNT 4887 }; 4888 4889 enum usb_pd_control_mux { 4890 USB_PD_CTRL_MUX_NO_CHANGE = 0, 4891 USB_PD_CTRL_MUX_NONE = 1, 4892 USB_PD_CTRL_MUX_USB = 2, 4893 USB_PD_CTRL_MUX_DP = 3, 4894 USB_PD_CTRL_MUX_DOCK = 4, 4895 USB_PD_CTRL_MUX_AUTO = 5, 4896 USB_PD_CTRL_MUX_COUNT 4897 }; 4898 4899 enum usb_pd_control_swap { 4900 USB_PD_CTRL_SWAP_NONE = 0, 4901 USB_PD_CTRL_SWAP_DATA = 1, 4902 USB_PD_CTRL_SWAP_POWER = 2, 4903 USB_PD_CTRL_SWAP_VCONN = 3, 4904 USB_PD_CTRL_SWAP_COUNT 4905 }; 4906 4907 struct ec_params_usb_pd_control { 4908 uint8_t port; 4909 uint8_t role; 4910 uint8_t mux; 4911 uint8_t swap; 4912 } __ec_align1; 4913 4914 #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ 4915 #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ 4916 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */ 4917 4918 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ 4919 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ 4920 #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ 4921 #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ 4922 #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ 4923 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ 4924 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */ 4925 4926 struct ec_response_usb_pd_control { 4927 uint8_t enabled; 4928 uint8_t role; 4929 uint8_t polarity; 4930 uint8_t state; 4931 } __ec_align1; 4932 4933 struct ec_response_usb_pd_control_v1 { 4934 uint8_t enabled; 4935 uint8_t role; 4936 uint8_t polarity; 4937 char state[32]; 4938 } __ec_align1; 4939 4940 /* Values representing usbc PD CC state */ 4941 #define USBC_PD_CC_NONE 0 /* No accessory connected */ 4942 #define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */ 4943 #define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */ 4944 #define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */ 4945 #define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */ 4946 #define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */ 4947 4948 /* Active/Passive Cable */ 4949 #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) 4950 /* Optical/Non-optical cable */ 4951 #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) 4952 /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ 4953 #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) 4954 /* Active Link Uni-Direction */ 4955 #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) 4956 4957 struct ec_response_usb_pd_control_v2 { 4958 uint8_t enabled; 4959 uint8_t role; 4960 uint8_t polarity; 4961 char state[32]; 4962 uint8_t cc_state; /* enum pd_cc_states representing cc state */ 4963 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ 4964 uint8_t reserved; /* Reserved for future use */ 4965 uint8_t control_flags; /* USB_PD_CTRL_*flags */ 4966 uint8_t cable_speed; /* TBT_SS_* cable speed */ 4967 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ 4968 } __ec_align1; 4969 4970 #define EC_CMD_USB_PD_PORTS 0x0102 4971 4972 /* Maximum number of PD ports on a device, num_ports will be <= this */ 4973 #define EC_USB_PD_MAX_PORTS 8 4974 4975 struct ec_response_usb_pd_ports { 4976 uint8_t num_ports; 4977 } __ec_align1; 4978 4979 #define EC_CMD_USB_PD_POWER_INFO 0x0103 4980 4981 #define PD_POWER_CHARGING_PORT 0xff 4982 struct ec_params_usb_pd_power_info { 4983 uint8_t port; 4984 } __ec_align1; 4985 4986 enum usb_chg_type { 4987 USB_CHG_TYPE_NONE, 4988 USB_CHG_TYPE_PD, 4989 USB_CHG_TYPE_C, 4990 USB_CHG_TYPE_PROPRIETARY, 4991 USB_CHG_TYPE_BC12_DCP, 4992 USB_CHG_TYPE_BC12_CDP, 4993 USB_CHG_TYPE_BC12_SDP, 4994 USB_CHG_TYPE_OTHER, 4995 USB_CHG_TYPE_VBUS, 4996 USB_CHG_TYPE_UNKNOWN, 4997 USB_CHG_TYPE_DEDICATED, 4998 }; 4999 enum usb_power_roles { 5000 USB_PD_PORT_POWER_DISCONNECTED, 5001 USB_PD_PORT_POWER_SOURCE, 5002 USB_PD_PORT_POWER_SINK, 5003 USB_PD_PORT_POWER_SINK_NOT_CHARGING, 5004 }; 5005 5006 struct usb_chg_measures { 5007 uint16_t voltage_max; 5008 uint16_t voltage_now; 5009 uint16_t current_max; 5010 uint16_t current_lim; 5011 } __ec_align2; 5012 5013 struct ec_response_usb_pd_power_info { 5014 uint8_t role; 5015 uint8_t type; 5016 uint8_t dualrole; 5017 uint8_t reserved1; 5018 struct usb_chg_measures meas; 5019 uint32_t max_power; 5020 } __ec_align4; 5021 5022 5023 /* 5024 * This command will return the number of USB PD charge port + the number 5025 * of dedicated port present. 5026 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports 5027 */ 5028 #define EC_CMD_CHARGE_PORT_COUNT 0x0105 5029 struct ec_response_charge_port_count { 5030 uint8_t port_count; 5031 } __ec_align1; 5032 5033 /* Write USB-PD device FW */ 5034 #define EC_CMD_USB_PD_FW_UPDATE 0x0110 5035 5036 enum usb_pd_fw_update_cmds { 5037 USB_PD_FW_REBOOT, 5038 USB_PD_FW_FLASH_ERASE, 5039 USB_PD_FW_FLASH_WRITE, 5040 USB_PD_FW_ERASE_SIG, 5041 }; 5042 5043 struct ec_params_usb_pd_fw_update { 5044 uint16_t dev_id; 5045 uint8_t cmd; 5046 uint8_t port; 5047 uint32_t size; /* Size to write in bytes */ 5048 /* Followed by data to write */ 5049 } __ec_align4; 5050 5051 /* Write USB-PD Accessory RW_HASH table entry */ 5052 #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 5053 /* RW hash is first 20 bytes of SHA-256 of RW section */ 5054 #define PD_RW_HASH_SIZE 20 5055 struct ec_params_usb_pd_rw_hash_entry { 5056 uint16_t dev_id; 5057 uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; 5058 uint8_t reserved; /* 5059 * For alignment of current_image 5060 * TODO(rspangler) but it's not aligned! 5061 * Should have been reserved[2]. 5062 */ 5063 uint32_t current_image; /* One of ec_current_image */ 5064 } __ec_align1; 5065 5066 /* Read USB-PD Accessory info */ 5067 #define EC_CMD_USB_PD_DEV_INFO 0x0112 5068 5069 struct ec_params_usb_pd_info_request { 5070 uint8_t port; 5071 } __ec_align1; 5072 5073 /* Read USB-PD Device discovery info */ 5074 #define EC_CMD_USB_PD_DISCOVERY 0x0113 5075 struct ec_params_usb_pd_discovery_entry { 5076 uint16_t vid; /* USB-IF VID */ 5077 uint16_t pid; /* USB-IF PID */ 5078 uint8_t ptype; /* product type (hub,periph,cable,ama) */ 5079 } __ec_align_size1; 5080 5081 /* Override default charge behavior */ 5082 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 5083 5084 /* Negative port parameters have special meaning */ 5085 enum usb_pd_override_ports { 5086 OVERRIDE_DONT_CHARGE = -2, 5087 OVERRIDE_OFF = -1, 5088 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */ 5089 }; 5090 5091 struct ec_params_charge_port_override { 5092 int16_t override_port; /* Override port# */ 5093 } __ec_align2; 5094 5095 /* 5096 * Read (and delete) one entry of PD event log. 5097 * TODO(crbug.com/751742): Make this host command more generic to accommodate 5098 * future non-PD logs that use the same internal EC event_log. 5099 */ 5100 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 5101 5102 struct ec_response_pd_log { 5103 uint32_t timestamp; /* relative timestamp in milliseconds */ 5104 uint8_t type; /* event type : see PD_EVENT_xx below */ 5105 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ 5106 uint16_t data; /* type-defined data payload */ 5107 uint8_t payload[]; /* optional additional data payload: 0..16 bytes */ 5108 } __ec_align4; 5109 5110 /* The timestamp is the microsecond counter shifted to get about a ms. */ 5111 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ 5112 5113 #define PD_LOG_SIZE_MASK 0x1f 5114 #define PD_LOG_PORT_MASK 0xe0 5115 #define PD_LOG_PORT_SHIFT 5 5116 #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ 5117 ((size) & PD_LOG_SIZE_MASK)) 5118 #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) 5119 #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) 5120 5121 /* PD event log : entry types */ 5122 /* PD MCU events */ 5123 #define PD_EVENT_MCU_BASE 0x00 5124 #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) 5125 #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) 5126 /* Reserved for custom board event */ 5127 #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) 5128 /* PD generic accessory events */ 5129 #define PD_EVENT_ACC_BASE 0x20 5130 #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) 5131 #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) 5132 /* PD power supply events */ 5133 #define PD_EVENT_PS_BASE 0x40 5134 #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) 5135 /* PD video dongles events */ 5136 #define PD_EVENT_VIDEO_BASE 0x60 5137 #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) 5138 #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) 5139 /* Returned in the "type" field, when there is no entry available */ 5140 #define PD_EVENT_NO_ENTRY 0xff 5141 5142 /* 5143 * PD_EVENT_MCU_CHARGE event definition : 5144 * the payload is "struct usb_chg_measures" 5145 * the data field contains the port state flags as defined below : 5146 */ 5147 /* Port partner is a dual role device */ 5148 #define CHARGE_FLAGS_DUAL_ROLE BIT(15) 5149 /* Port is the pending override port */ 5150 #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) 5151 /* Port is the override port */ 5152 #define CHARGE_FLAGS_OVERRIDE BIT(13) 5153 /* Charger type */ 5154 #define CHARGE_FLAGS_TYPE_SHIFT 3 5155 #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) 5156 /* Power delivery role */ 5157 #define CHARGE_FLAGS_ROLE_MASK (7 << 0) 5158 5159 /* 5160 * PD_EVENT_PS_FAULT data field flags definition : 5161 */ 5162 #define PS_FAULT_OCP 1 5163 #define PS_FAULT_FAST_OCP 2 5164 #define PS_FAULT_OVP 3 5165 #define PS_FAULT_DISCH 4 5166 5167 /* 5168 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". 5169 */ 5170 struct mcdp_version { 5171 uint8_t major; 5172 uint8_t minor; 5173 uint16_t build; 5174 } __ec_align4; 5175 5176 struct mcdp_info { 5177 uint8_t family[2]; 5178 uint8_t chipid[2]; 5179 struct mcdp_version irom; 5180 struct mcdp_version fw; 5181 } __ec_align4; 5182 5183 /* struct mcdp_info field decoding */ 5184 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) 5185 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) 5186 5187 /* Get/Set USB-PD Alternate mode info */ 5188 #define EC_CMD_USB_PD_GET_AMODE 0x0116 5189 struct ec_params_usb_pd_get_mode_request { 5190 uint16_t svid_idx; /* SVID index to get */ 5191 uint8_t port; /* port */ 5192 } __ec_align_size1; 5193 5194 struct ec_params_usb_pd_get_mode_response { 5195 uint16_t svid; /* SVID */ 5196 uint16_t opos; /* Object Position */ 5197 uint32_t vdo[6]; /* Mode VDOs */ 5198 } __ec_align4; 5199 5200 #define EC_CMD_USB_PD_SET_AMODE 0x0117 5201 5202 enum pd_mode_cmd { 5203 PD_EXIT_MODE = 0, 5204 PD_ENTER_MODE = 1, 5205 /* Not a command. Do NOT remove. */ 5206 PD_MODE_CMD_COUNT, 5207 }; 5208 5209 struct ec_params_usb_pd_set_mode_request { 5210 uint32_t cmd; /* enum pd_mode_cmd */ 5211 uint16_t svid; /* SVID to set */ 5212 uint8_t opos; /* Object Position */ 5213 uint8_t port; /* port */ 5214 } __ec_align4; 5215 5216 /* Ask the PD MCU to record a log of a requested type */ 5217 #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 5218 5219 struct ec_params_pd_write_log_entry { 5220 uint8_t type; /* event type : see PD_EVENT_xx above */ 5221 uint8_t port; /* port#, or 0 for events unrelated to a given port */ 5222 } __ec_align1; 5223 5224 5225 /* Control USB-PD chip */ 5226 #define EC_CMD_PD_CONTROL 0x0119 5227 5228 enum ec_pd_control_cmd { 5229 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ 5230 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ 5231 PD_RESET, /* Force reset the PD chip */ 5232 PD_CONTROL_DISABLE, /* Disable further calls to this command */ 5233 PD_CHIP_ON, /* Power on the PD chip */ 5234 }; 5235 5236 struct ec_params_pd_control { 5237 uint8_t chip; /* chip id */ 5238 uint8_t subcmd; 5239 } __ec_align1; 5240 5241 /* Get info about USB-C SS muxes */ 5242 #define EC_CMD_USB_PD_MUX_INFO 0x011A 5243 5244 struct ec_params_usb_pd_mux_info { 5245 uint8_t port; /* USB-C port number */ 5246 } __ec_align1; 5247 5248 /* Flags representing mux state */ 5249 #define USB_PD_MUX_NONE 0 /* Open switch */ 5250 #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ 5251 #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ 5252 #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ 5253 #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ 5254 #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ 5255 #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ 5256 #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ 5257 #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ 5258 5259 struct ec_response_usb_pd_mux_info { 5260 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ 5261 } __ec_align1; 5262 5263 #define EC_CMD_PD_CHIP_INFO 0x011B 5264 5265 struct ec_params_pd_chip_info { 5266 uint8_t port; /* USB-C port number */ 5267 uint8_t renew; /* Force renewal */ 5268 } __ec_align1; 5269 5270 struct ec_response_pd_chip_info { 5271 uint16_t vendor_id; 5272 uint16_t product_id; 5273 uint16_t device_id; 5274 union { 5275 uint8_t fw_version_string[8]; 5276 uint64_t fw_version_number; 5277 }; 5278 } __ec_align2; 5279 5280 struct ec_response_pd_chip_info_v1 { 5281 uint16_t vendor_id; 5282 uint16_t product_id; 5283 uint16_t device_id; 5284 union { 5285 uint8_t fw_version_string[8]; 5286 uint64_t fw_version_number; 5287 }; 5288 union { 5289 uint8_t min_req_fw_version_string[8]; 5290 uint64_t min_req_fw_version_number; 5291 }; 5292 } __ec_align2; 5293 5294 /* Run RW signature verification and get status */ 5295 #define EC_CMD_RWSIG_CHECK_STATUS 0x011C 5296 5297 struct ec_response_rwsig_check_status { 5298 uint32_t status; 5299 } __ec_align4; 5300 5301 /* For controlling RWSIG task */ 5302 #define EC_CMD_RWSIG_ACTION 0x011D 5303 5304 enum rwsig_action { 5305 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ 5306 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ 5307 }; 5308 5309 struct ec_params_rwsig_action { 5310 uint32_t action; 5311 } __ec_align4; 5312 5313 /* Run verification on a slot */ 5314 #define EC_CMD_EFS_VERIFY 0x011E 5315 5316 struct ec_params_efs_verify { 5317 uint8_t region; /* enum ec_flash_region */ 5318 } __ec_align1; 5319 5320 /* 5321 * Retrieve info from Cros Board Info store. Response is based on the data 5322 * type. Integers return a uint32. Strings return a string, using the response 5323 * size to determine how big it is. 5324 */ 5325 #define EC_CMD_GET_CROS_BOARD_INFO 0x011F 5326 /* 5327 * Write info into Cros Board Info on EEPROM. Write fails if the board has 5328 * hardware write-protect enabled. 5329 */ 5330 #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 5331 5332 enum cbi_data_tag { 5333 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ 5334 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ 5335 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ 5336 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ 5337 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ 5338 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ 5339 CBI_TAG_COUNT, 5340 }; 5341 5342 /* 5343 * Flags to control read operation 5344 * 5345 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify 5346 * write was successful without reboot. 5347 */ 5348 #define CBI_GET_RELOAD BIT(0) 5349 5350 struct ec_params_get_cbi { 5351 uint32_t tag; /* enum cbi_data_tag */ 5352 uint32_t flag; /* CBI_GET_* */ 5353 } __ec_align4; 5354 5355 /* 5356 * Flags to control write behavior. 5357 * 5358 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's 5359 * useful when writing multiple fields in a row. 5360 * INIT: Need to be set when creating a new CBI from scratch. All fields 5361 * will be initialized to zero first. 5362 */ 5363 #define CBI_SET_NO_SYNC BIT(0) 5364 #define CBI_SET_INIT BIT(1) 5365 5366 struct ec_params_set_cbi { 5367 uint32_t tag; /* enum cbi_data_tag */ 5368 uint32_t flag; /* CBI_SET_* */ 5369 uint32_t size; /* Data size */ 5370 uint8_t data[]; /* For string and raw data */ 5371 } __ec_align1; 5372 5373 /* 5374 * Information about resets of the AP by the EC and the EC's own uptime. 5375 */ 5376 #define EC_CMD_GET_UPTIME_INFO 0x0121 5377 5378 struct ec_response_uptime_info { 5379 /* 5380 * Number of milliseconds since the last EC boot. Sysjump resets 5381 * typically do not restart the EC's time_since_boot epoch. 5382 * 5383 * WARNING: The EC's sense of time is much less accurate than the AP's 5384 * sense of time, in both phase and frequency. This timebase is similar 5385 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. 5386 */ 5387 uint32_t time_since_ec_boot_ms; 5388 5389 /* 5390 * Number of times the AP was reset by the EC since the last EC boot. 5391 * Note that the AP may be held in reset by the EC during the initial 5392 * boot sequence, such that the very first AP boot may count as more 5393 * than one here. 5394 */ 5395 uint32_t ap_resets_since_ec_boot; 5396 5397 /* 5398 * The set of flags which describe the EC's most recent reset. See 5399 * include/system.h RESET_FLAG_* for details. 5400 */ 5401 uint32_t ec_reset_flags; 5402 5403 /* Empty log entries have both the cause and timestamp set to zero. */ 5404 struct ap_reset_log_entry { 5405 /* 5406 * See include/chipset.h: enum chipset_{reset,shutdown}_reason 5407 * for details. 5408 */ 5409 uint16_t reset_cause; 5410 5411 /* Reserved for protocol growth. */ 5412 uint16_t reserved; 5413 5414 /* 5415 * The time of the reset's assertion, in milliseconds since the 5416 * last EC boot, in the same epoch as time_since_ec_boot_ms. 5417 * Set to zero if the log entry is empty. 5418 */ 5419 uint32_t reset_time_ms; 5420 } recent_ap_reset[4]; 5421 } __ec_align4; 5422 5423 /* 5424 * Add entropy to the device secret (stored in the rollback region). 5425 * 5426 * Depending on the chip, the operation may take a long time (e.g. to erase 5427 * flash), so the commands are asynchronous. 5428 */ 5429 #define EC_CMD_ADD_ENTROPY 0x0122 5430 5431 enum add_entropy_action { 5432 /* Add entropy to the current secret. */ 5433 ADD_ENTROPY_ASYNC = 0, 5434 /* 5435 * Add entropy, and also make sure that the previous secret is erased. 5436 * (this can be implemented by adding entropy multiple times until 5437 * all rolback blocks have been overwritten). 5438 */ 5439 ADD_ENTROPY_RESET_ASYNC = 1, 5440 /* Read back result from the previous operation. */ 5441 ADD_ENTROPY_GET_RESULT = 2, 5442 }; 5443 5444 struct ec_params_rollback_add_entropy { 5445 uint8_t action; 5446 } __ec_align1; 5447 5448 /* 5449 * Perform a single read of a given ADC channel. 5450 */ 5451 #define EC_CMD_ADC_READ 0x0123 5452 5453 struct ec_params_adc_read { 5454 uint8_t adc_channel; 5455 } __ec_align1; 5456 5457 struct ec_response_adc_read { 5458 int32_t adc_value; 5459 } __ec_align4; 5460 5461 /* 5462 * Read back rollback info 5463 */ 5464 #define EC_CMD_ROLLBACK_INFO 0x0124 5465 5466 struct ec_response_rollback_info { 5467 int32_t id; /* Incrementing number to indicate which region to use. */ 5468 int32_t rollback_min_version; 5469 int32_t rw_rollback_version; 5470 } __ec_align4; 5471 5472 5473 /* Issue AP reset */ 5474 #define EC_CMD_AP_RESET 0x0125 5475 5476 /** 5477 * Get the number of peripheral charge ports 5478 */ 5479 #define EC_CMD_PCHG_COUNT 0x0134 5480 5481 #define EC_PCHG_MAX_PORTS 8 5482 5483 struct ec_response_pchg_count { 5484 uint8_t port_count; 5485 } __ec_align1; 5486 5487 /** 5488 * Get the status of a peripheral charge port 5489 */ 5490 #define EC_CMD_PCHG 0x0135 5491 5492 struct ec_params_pchg { 5493 uint8_t port; 5494 } __ec_align1; 5495 5496 struct ec_response_pchg { 5497 uint32_t error; /* enum pchg_error */ 5498 uint8_t state; /* enum pchg_state state */ 5499 uint8_t battery_percentage; 5500 uint8_t unused0; 5501 uint8_t unused1; 5502 /* Fields added in version 1 */ 5503 uint32_t fw_version; 5504 uint32_t dropped_event_count; 5505 } __ec_align2; 5506 5507 enum pchg_state { 5508 /* Charger is reset and not initialized. */ 5509 PCHG_STATE_RESET = 0, 5510 /* Charger is initialized or disabled. */ 5511 PCHG_STATE_INITIALIZED, 5512 /* Charger is enabled and ready to detect a device. */ 5513 PCHG_STATE_ENABLED, 5514 /* Device is in proximity. */ 5515 PCHG_STATE_DETECTED, 5516 /* Device is being charged. */ 5517 PCHG_STATE_CHARGING, 5518 /* Device is fully charged. It implies DETECTED (& not charging). */ 5519 PCHG_STATE_FULL, 5520 /* In download (a.k.a. firmware update) mode */ 5521 PCHG_STATE_DOWNLOAD, 5522 /* In download mode. Ready for receiving data. */ 5523 PCHG_STATE_DOWNLOADING, 5524 /* Device is ready for data communication. */ 5525 PCHG_STATE_CONNECTED, 5526 /* Put no more entry below */ 5527 PCHG_STATE_COUNT, 5528 }; 5529 5530 #define EC_PCHG_STATE_TEXT { \ 5531 [PCHG_STATE_RESET] = "RESET", \ 5532 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ 5533 [PCHG_STATE_ENABLED] = "ENABLED", \ 5534 [PCHG_STATE_DETECTED] = "DETECTED", \ 5535 [PCHG_STATE_CHARGING] = "CHARGING", \ 5536 [PCHG_STATE_FULL] = "FULL", \ 5537 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ 5538 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ 5539 [PCHG_STATE_CONNECTED] = "CONNECTED", \ 5540 } 5541 5542 /* 5543 * Update firmware of peripheral chip 5544 */ 5545 #define EC_CMD_PCHG_UPDATE 0x0136 5546 5547 /* Port number is encoded in bit[28:31]. */ 5548 #define EC_MKBP_PCHG_PORT_SHIFT 28 5549 /* Utility macro for converting MKBP event to port number. */ 5550 #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) 5551 /* Utility macro for extracting event bits. */ 5552 #define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \ 5553 & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0)) 5554 5555 #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) 5556 #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) 5557 #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) 5558 #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) 5559 #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4) 5560 5561 enum ec_pchg_update_cmd { 5562 /* Reset chip to normal mode. */ 5563 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, 5564 /* Reset and put a chip in update (a.k.a. download) mode. */ 5565 EC_PCHG_UPDATE_CMD_OPEN, 5566 /* Write a block of data containing FW image. */ 5567 EC_PCHG_UPDATE_CMD_WRITE, 5568 /* Close update session. */ 5569 EC_PCHG_UPDATE_CMD_CLOSE, 5570 /* End of commands */ 5571 EC_PCHG_UPDATE_CMD_COUNT, 5572 }; 5573 5574 struct ec_params_pchg_update { 5575 /* PCHG port number */ 5576 uint8_t port; 5577 /* enum ec_pchg_update_cmd */ 5578 uint8_t cmd; 5579 /* Padding */ 5580 uint8_t reserved0; 5581 uint8_t reserved1; 5582 /* Version of new firmware */ 5583 uint32_t version; 5584 /* CRC32 of new firmware */ 5585 uint32_t crc32; 5586 /* Address in chip memory where <data> is written to */ 5587 uint32_t addr; 5588 /* Size of <data> */ 5589 uint32_t size; 5590 /* Partial data of new firmware */ 5591 uint8_t data[]; 5592 } __ec_align4; 5593 5594 BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT 5595 < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8)); 5596 5597 struct ec_response_pchg_update { 5598 /* Block size */ 5599 uint32_t block_size; 5600 } __ec_align4; 5601 5602 5603 /*****************************************************************************/ 5604 /* Voltage regulator controls */ 5605 5606 /* 5607 * Get basic info of voltage regulator for given index. 5608 * 5609 * Returns the regulator name and supported voltage list in mV. 5610 */ 5611 #define EC_CMD_REGULATOR_GET_INFO 0x012C 5612 5613 /* Maximum length of regulator name */ 5614 #define EC_REGULATOR_NAME_MAX_LEN 16 5615 5616 /* Maximum length of the supported voltage list. */ 5617 #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 5618 5619 struct ec_params_regulator_get_info { 5620 uint32_t index; 5621 } __ec_align4; 5622 5623 struct ec_response_regulator_get_info { 5624 char name[EC_REGULATOR_NAME_MAX_LEN]; 5625 uint16_t num_voltages; 5626 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; 5627 } __ec_align2; 5628 5629 /* 5630 * Configure the regulator as enabled / disabled. 5631 */ 5632 #define EC_CMD_REGULATOR_ENABLE 0x012D 5633 5634 struct ec_params_regulator_enable { 5635 uint32_t index; 5636 uint8_t enable; 5637 } __ec_align4; 5638 5639 /* 5640 * Query if the regulator is enabled. 5641 * 5642 * Returns 1 if the regulator is enabled, 0 if not. 5643 */ 5644 #define EC_CMD_REGULATOR_IS_ENABLED 0x012E 5645 5646 struct ec_params_regulator_is_enabled { 5647 uint32_t index; 5648 } __ec_align4; 5649 5650 struct ec_response_regulator_is_enabled { 5651 uint8_t enabled; 5652 } __ec_align1; 5653 5654 /* 5655 * Set voltage for the voltage regulator within the range specified. 5656 * 5657 * The driver should select the voltage in range closest to min_mv. 5658 * 5659 * Also note that this might be called before the regulator is enabled, and the 5660 * setting should be in effect after the regulator is enabled. 5661 */ 5662 #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F 5663 5664 struct ec_params_regulator_set_voltage { 5665 uint32_t index; 5666 uint32_t min_mv; 5667 uint32_t max_mv; 5668 } __ec_align4; 5669 5670 /* 5671 * Get the currently configured voltage for the voltage regulator. 5672 * 5673 * Note that this might be called before the regulator is enabled, and this 5674 * should return the configured output voltage if the regulator is enabled. 5675 */ 5676 #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 5677 5678 struct ec_params_regulator_get_voltage { 5679 uint32_t index; 5680 } __ec_align4; 5681 5682 struct ec_response_regulator_get_voltage { 5683 uint32_t voltage_mv; 5684 } __ec_align4; 5685 5686 /* 5687 * Gather all discovery information for the given port and partner type. 5688 * 5689 * Note that if discovery has not yet completed, only the currently completed 5690 * responses will be filled in. If the discovery data structures are changed 5691 * in the process of the command running, BUSY will be returned. 5692 * 5693 * VDO field sizes are set to the maximum possible number of VDOs a VDM may 5694 * contain, while the number of SVIDs here is selected to fit within the PROTO2 5695 * maximum parameter size. 5696 */ 5697 #define EC_CMD_TYPEC_DISCOVERY 0x0131 5698 5699 enum typec_partner_type { 5700 TYPEC_PARTNER_SOP = 0, 5701 TYPEC_PARTNER_SOP_PRIME = 1, 5702 }; 5703 5704 struct ec_params_typec_discovery { 5705 uint8_t port; 5706 uint8_t partner_type; /* enum typec_partner_type */ 5707 } __ec_align1; 5708 5709 struct svid_mode_info { 5710 uint16_t svid; 5711 uint16_t mode_count; /* Number of modes partner sent */ 5712 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ 5713 }; 5714 5715 struct ec_response_typec_discovery { 5716 uint8_t identity_count; /* Number of identity VDOs partner sent */ 5717 uint8_t svid_count; /* Number of SVIDs partner sent */ 5718 uint16_t reserved; 5719 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ 5720 struct svid_mode_info svids[]; 5721 } __ec_align1; 5722 5723 /* USB Type-C commands for AP-controlled device policy. */ 5724 #define EC_CMD_TYPEC_CONTROL 0x0132 5725 5726 enum typec_control_command { 5727 TYPEC_CONTROL_COMMAND_EXIT_MODES, 5728 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, 5729 TYPEC_CONTROL_COMMAND_ENTER_MODE, 5730 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, 5731 TYPEC_CONTROL_COMMAND_USB_MUX_SET, 5732 }; 5733 5734 /* Replies the AP may specify to the TBT EnterMode command as a UFP */ 5735 enum typec_tbt_ufp_reply { 5736 TYPEC_TBT_UFP_REPLY_NAK, 5737 TYPEC_TBT_UFP_REPLY_ACK, 5738 }; 5739 5740 struct typec_usb_mux_set { 5741 uint8_t mux_index; /* Index of the mux to set in the chain */ 5742 uint8_t mux_flags; /* USB_PD_MUX_*-encoded USB mux state to set */ 5743 } __ec_align1; 5744 5745 struct ec_params_typec_control { 5746 uint8_t port; 5747 uint8_t command; /* enum typec_control_command */ 5748 uint16_t reserved; 5749 5750 /* 5751 * This section will be interpreted based on |command|. Define a 5752 * placeholder structure to avoid having to increase the size and bump 5753 * the command version when adding new sub-commands. 5754 */ 5755 union { 5756 uint32_t clear_events_mask; 5757 uint8_t mode_to_enter; /* enum typec_mode */ 5758 uint8_t tbt_ufp_reply; /* enum typec_tbt_ufp_reply */ 5759 struct typec_usb_mux_set mux_params; 5760 uint8_t placeholder[128]; 5761 }; 5762 } __ec_align1; 5763 5764 /* 5765 * Gather all status information for a port. 5766 * 5767 * Note: this covers many of the return fields from the deprecated 5768 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the 5769 * discovery data. The "enum pd_cc_states" is defined with the deprecated 5770 * EC_CMD_USB_PD_CONTROL command. 5771 * 5772 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. 5773 */ 5774 #define EC_CMD_TYPEC_STATUS 0x0133 5775 5776 /* 5777 * Power role. 5778 * 5779 * Note this is also used for PD header creation, and values align to those in 5780 * the Power Delivery Specification Revision 3.0 (See 5781 * 6.2.1.1.4 Port Power Role). 5782 */ 5783 enum pd_power_role { 5784 PD_ROLE_SINK = 0, 5785 PD_ROLE_SOURCE = 1 5786 }; 5787 5788 /* 5789 * Data role. 5790 * 5791 * Note this is also used for PD header creation, and the first two values 5792 * align to those in the Power Delivery Specification Revision 3.0 (See 5793 * 6.2.1.1.6 Port Data Role). 5794 */ 5795 enum pd_data_role { 5796 PD_ROLE_UFP = 0, 5797 PD_ROLE_DFP = 1, 5798 PD_ROLE_DISCONNECTED = 2, 5799 }; 5800 5801 enum pd_vconn_role { 5802 PD_ROLE_VCONN_OFF = 0, 5803 PD_ROLE_VCONN_SRC = 1, 5804 }; 5805 5806 /* 5807 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, 5808 * regardless of whether a debug accessory is connected. 5809 */ 5810 enum tcpc_cc_polarity { 5811 /* 5812 * _CCx: is used to indicate the polarity while not connected to 5813 * a Debug Accessory. Only one CC line will assert a resistor and 5814 * the other will be open. 5815 */ 5816 POLARITY_CC1 = 0, 5817 POLARITY_CC2 = 1, 5818 5819 /* 5820 * _CCx_DTS is used to indicate the polarity while connected to a 5821 * SRC Debug Accessory. Assert resistors on both lines. 5822 */ 5823 POLARITY_CC1_DTS = 2, 5824 POLARITY_CC2_DTS = 3, 5825 5826 /* 5827 * The current TCPC code relies on these specific POLARITY values. 5828 * Adding in a check to verify if the list grows for any reason 5829 * that this will give a hint that other places need to be 5830 * adjusted. 5831 */ 5832 POLARITY_COUNT 5833 }; 5834 5835 #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) 5836 #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) 5837 #define PD_STATUS_EVENT_HARD_RESET BIT(2) 5838 #define PD_STATUS_EVENT_DISCONNECTED BIT(3) 5839 #define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4) 5840 #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) 5841 5842 struct ec_params_typec_status { 5843 uint8_t port; 5844 } __ec_align1; 5845 5846 struct ec_response_typec_status { 5847 uint8_t pd_enabled; /* PD communication enabled - bool */ 5848 uint8_t dev_connected; /* Device connected - bool */ 5849 uint8_t sop_connected; /* Device is SOP PD capable - bool */ 5850 uint8_t source_cap_count; /* Number of Source Cap PDOs */ 5851 5852 uint8_t power_role; /* enum pd_power_role */ 5853 uint8_t data_role; /* enum pd_data_role */ 5854 uint8_t vconn_role; /* enum pd_vconn_role */ 5855 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ 5856 5857 uint8_t polarity; /* enum tcpc_cc_polarity */ 5858 uint8_t cc_state; /* enum pd_cc_states */ 5859 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ 5860 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ 5861 5862 char tc_state[32]; /* TC state name */ 5863 5864 uint32_t events; /* PD_STATUS_EVENT bitmask */ 5865 5866 /* 5867 * BCD PD revisions for partners 5868 * 5869 * The format has the PD major reversion in the upper nibble, and PD 5870 * minor version in the next nibble. Following two nibbles are 5871 * currently 0. 5872 * ex. PD 3.2 would map to 0x3200 5873 * 5874 * PD major/minor will be 0 if no PD device is connected. 5875 */ 5876 uint16_t sop_revision; 5877 uint16_t sop_prime_revision; 5878 5879 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ 5880 5881 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ 5882 } __ec_align1; 5883 5884 /*****************************************************************************/ 5885 /* The command range 0x200-0x2FF is reserved for Rotor. */ 5886 5887 /*****************************************************************************/ 5888 /* 5889 * Reserve a range of host commands for the CR51 firmware. 5890 */ 5891 #define EC_CMD_CR51_BASE 0x0300 5892 #define EC_CMD_CR51_LAST 0x03FF 5893 5894 /*****************************************************************************/ 5895 /* Fingerprint MCU commands: range 0x0400-0x040x */ 5896 5897 /* Fingerprint SPI sensor passthru command: prototyping ONLY */ 5898 #define EC_CMD_FP_PASSTHRU 0x0400 5899 5900 #define EC_FP_FLAG_NOT_COMPLETE 0x1 5901 5902 struct ec_params_fp_passthru { 5903 uint16_t len; /* Number of bytes to write then read */ 5904 uint16_t flags; /* EC_FP_FLAG_xxx */ 5905 uint8_t data[]; /* Data to send */ 5906 } __ec_align2; 5907 5908 /* Configure the Fingerprint MCU behavior */ 5909 #define EC_CMD_FP_MODE 0x0402 5910 5911 /* Put the sensor in its lowest power mode */ 5912 #define FP_MODE_DEEPSLEEP BIT(0) 5913 /* Wait to see a finger on the sensor */ 5914 #define FP_MODE_FINGER_DOWN BIT(1) 5915 /* Poll until the finger has left the sensor */ 5916 #define FP_MODE_FINGER_UP BIT(2) 5917 /* Capture the current finger image */ 5918 #define FP_MODE_CAPTURE BIT(3) 5919 /* Finger enrollment session on-going */ 5920 #define FP_MODE_ENROLL_SESSION BIT(4) 5921 /* Enroll the current finger image */ 5922 #define FP_MODE_ENROLL_IMAGE BIT(5) 5923 /* Try to match the current finger image */ 5924 #define FP_MODE_MATCH BIT(6) 5925 /* Reset and re-initialize the sensor. */ 5926 #define FP_MODE_RESET_SENSOR BIT(7) 5927 /* special value: don't change anything just read back current mode */ 5928 #define FP_MODE_DONT_CHANGE BIT(31) 5929 5930 #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ 5931 FP_MODE_FINGER_DOWN | \ 5932 FP_MODE_FINGER_UP | \ 5933 FP_MODE_CAPTURE | \ 5934 FP_MODE_ENROLL_SESSION | \ 5935 FP_MODE_ENROLL_IMAGE | \ 5936 FP_MODE_MATCH | \ 5937 FP_MODE_RESET_SENSOR | \ 5938 FP_MODE_DONT_CHANGE) 5939 5940 /* Capture types defined in bits [30..28] */ 5941 #define FP_MODE_CAPTURE_TYPE_SHIFT 28 5942 #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) 5943 /* 5944 * This enum must remain ordered, if you add new values you must ensure that 5945 * FP_CAPTURE_TYPE_MAX is still the last one. 5946 */ 5947 enum fp_capture_type { 5948 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ 5949 FP_CAPTURE_VENDOR_FORMAT = 0, 5950 /* Simple raw image capture (produces width x height x bpp bits) */ 5951 FP_CAPTURE_SIMPLE_IMAGE = 1, 5952 /* Self test pattern (e.g. checkerboard) */ 5953 FP_CAPTURE_PATTERN0 = 2, 5954 /* Self test pattern (e.g. inverted checkerboard) */ 5955 FP_CAPTURE_PATTERN1 = 3, 5956 /* Capture for Quality test with fixed contrast */ 5957 FP_CAPTURE_QUALITY_TEST = 4, 5958 /* Capture for pixel reset value test */ 5959 FP_CAPTURE_RESET_TEST = 5, 5960 FP_CAPTURE_TYPE_MAX, 5961 }; 5962 /* Extracts the capture type from the sensor 'mode' word */ 5963 #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ 5964 >> FP_MODE_CAPTURE_TYPE_SHIFT) 5965 5966 struct ec_params_fp_mode { 5967 uint32_t mode; /* as defined by FP_MODE_ constants */ 5968 } __ec_align4; 5969 5970 struct ec_response_fp_mode { 5971 uint32_t mode; /* as defined by FP_MODE_ constants */ 5972 } __ec_align4; 5973 5974 /* Retrieve Fingerprint sensor information */ 5975 #define EC_CMD_FP_INFO 0x0403 5976 5977 /* Number of dead pixels detected on the last maintenance */ 5978 #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) 5979 /* Unknown number of dead pixels detected on the last maintenance */ 5980 #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) 5981 /* No interrupt from the sensor */ 5982 #define FP_ERROR_NO_IRQ BIT(12) 5983 /* SPI communication error */ 5984 #define FP_ERROR_SPI_COMM BIT(13) 5985 /* Invalid sensor Hardware ID */ 5986 #define FP_ERROR_BAD_HWID BIT(14) 5987 /* Sensor initialization failed */ 5988 #define FP_ERROR_INIT_FAIL BIT(15) 5989 5990 struct ec_response_fp_info_v0 { 5991 /* Sensor identification */ 5992 uint32_t vendor_id; 5993 uint32_t product_id; 5994 uint32_t model_id; 5995 uint32_t version; 5996 /* Image frame characteristics */ 5997 uint32_t frame_size; 5998 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ 5999 uint16_t width; 6000 uint16_t height; 6001 uint16_t bpp; 6002 uint16_t errors; /* see FP_ERROR_ flags above */ 6003 } __ec_align4; 6004 6005 struct ec_response_fp_info { 6006 /* Sensor identification */ 6007 uint32_t vendor_id; 6008 uint32_t product_id; 6009 uint32_t model_id; 6010 uint32_t version; 6011 /* Image frame characteristics */ 6012 uint32_t frame_size; 6013 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ 6014 uint16_t width; 6015 uint16_t height; 6016 uint16_t bpp; 6017 uint16_t errors; /* see FP_ERROR_ flags above */ 6018 /* Template/finger current information */ 6019 uint32_t template_size; /* max template size in bytes */ 6020 uint16_t template_max; /* maximum number of fingers/templates */ 6021 uint16_t template_valid; /* number of valid fingers/templates */ 6022 uint32_t template_dirty; /* bitmap of templates with MCU side changes */ 6023 uint32_t template_version; /* version of the template format */ 6024 } __ec_align4; 6025 6026 /* Get the last captured finger frame or a template content */ 6027 #define EC_CMD_FP_FRAME 0x0404 6028 6029 /* constants defining the 'offset' field which also contains the frame index */ 6030 #define FP_FRAME_INDEX_SHIFT 28 6031 /* Frame buffer where the captured image is stored */ 6032 #define FP_FRAME_INDEX_RAW_IMAGE 0 6033 /* First frame buffer holding a template */ 6034 #define FP_FRAME_INDEX_TEMPLATE 1 6035 #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) 6036 #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF 6037 6038 /* Version of the format of the encrypted templates. */ 6039 #define FP_TEMPLATE_FORMAT_VERSION 3 6040 6041 /* Constants for encryption parameters */ 6042 #define FP_CONTEXT_NONCE_BYTES 12 6043 #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) 6044 #define FP_CONTEXT_TAG_BYTES 16 6045 #define FP_CONTEXT_SALT_BYTES 16 6046 #define FP_CONTEXT_TPM_BYTES 32 6047 6048 struct ec_fp_template_encryption_metadata { 6049 /* 6050 * Version of the structure format (N=3). 6051 */ 6052 uint16_t struct_version; 6053 /* Reserved bytes, set to 0. */ 6054 uint16_t reserved; 6055 /* 6056 * The salt is *only* ever used for key derivation. The nonce is unique, 6057 * a different one is used for every message. 6058 */ 6059 uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; 6060 uint8_t salt[FP_CONTEXT_SALT_BYTES]; 6061 uint8_t tag[FP_CONTEXT_TAG_BYTES]; 6062 }; 6063 6064 struct ec_params_fp_frame { 6065 /* 6066 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE 6067 * in the high nibble, and the real offset within the frame in 6068 * FP_FRAME_OFFSET_MASK. 6069 */ 6070 uint32_t offset; 6071 uint32_t size; 6072 } __ec_align4; 6073 6074 /* Load a template into the MCU */ 6075 #define EC_CMD_FP_TEMPLATE 0x0405 6076 6077 /* Flag in the 'size' field indicating that the full template has been sent */ 6078 #define FP_TEMPLATE_COMMIT 0x80000000 6079 6080 struct ec_params_fp_template { 6081 uint32_t offset; 6082 uint32_t size; 6083 uint8_t data[]; 6084 } __ec_align4; 6085 6086 /* Clear the current fingerprint user context and set a new one */ 6087 #define EC_CMD_FP_CONTEXT 0x0406 6088 6089 struct ec_params_fp_context { 6090 uint32_t userid[FP_CONTEXT_USERID_WORDS]; 6091 } __ec_align4; 6092 6093 #define EC_CMD_FP_STATS 0x0407 6094 6095 #define FPSTATS_CAPTURE_INV BIT(0) 6096 #define FPSTATS_MATCHING_INV BIT(1) 6097 6098 struct ec_response_fp_stats { 6099 uint32_t capture_time_us; 6100 uint32_t matching_time_us; 6101 uint32_t overall_time_us; 6102 struct { 6103 uint32_t lo; 6104 uint32_t hi; 6105 } overall_t0; 6106 uint8_t timestamps_invalid; 6107 int8_t template_matched; 6108 } __ec_align2; 6109 6110 #define EC_CMD_FP_SEED 0x0408 6111 struct ec_params_fp_seed { 6112 /* 6113 * Version of the structure format (N=3). 6114 */ 6115 uint16_t struct_version; 6116 /* Reserved bytes, set to 0. */ 6117 uint16_t reserved; 6118 /* Seed from the TPM. */ 6119 uint8_t seed[FP_CONTEXT_TPM_BYTES]; 6120 } __ec_align4; 6121 6122 #define EC_CMD_FP_ENC_STATUS 0x0409 6123 6124 /* FP TPM seed has been set or not */ 6125 #define FP_ENC_STATUS_SEED_SET BIT(0) 6126 6127 struct ec_response_fp_encryption_status { 6128 /* Used bits in encryption engine status */ 6129 uint32_t valid_flags; 6130 /* Encryption engine status */ 6131 uint32_t status; 6132 } __ec_align4; 6133 6134 /*****************************************************************************/ 6135 /* Touchpad MCU commands: range 0x0500-0x05FF */ 6136 6137 /* Perform touchpad self test */ 6138 #define EC_CMD_TP_SELF_TEST 0x0500 6139 6140 /* Get number of frame types, and the size of each type */ 6141 #define EC_CMD_TP_FRAME_INFO 0x0501 6142 6143 struct ec_response_tp_frame_info { 6144 uint32_t n_frames; 6145 uint32_t frame_sizes[]; 6146 } __ec_align4; 6147 6148 /* Create a snapshot of current frame readings */ 6149 #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 6150 6151 /* Read the frame */ 6152 #define EC_CMD_TP_FRAME_GET 0x0503 6153 6154 struct ec_params_tp_frame_get { 6155 uint32_t frame_index; 6156 uint32_t offset; 6157 uint32_t size; 6158 } __ec_align4; 6159 6160 /*****************************************************************************/ 6161 /* EC-EC communication commands: range 0x0600-0x06FF */ 6162 6163 #define EC_COMM_TEXT_MAX 8 6164 6165 /* 6166 * Get battery static information, i.e. information that never changes, or 6167 * very infrequently. 6168 */ 6169 #define EC_CMD_BATTERY_GET_STATIC 0x0600 6170 6171 /** 6172 * struct ec_params_battery_static_info - Battery static info parameters 6173 * @index: Battery index. 6174 */ 6175 struct ec_params_battery_static_info { 6176 uint8_t index; 6177 } __ec_align_size1; 6178 6179 /** 6180 * struct ec_response_battery_static_info - Battery static info response 6181 * @design_capacity: Battery Design Capacity (mAh) 6182 * @design_voltage: Battery Design Voltage (mV) 6183 * @manufacturer: Battery Manufacturer String 6184 * @model: Battery Model Number String 6185 * @serial: Battery Serial Number String 6186 * @type: Battery Type String 6187 * @cycle_count: Battery Cycle Count 6188 */ 6189 struct ec_response_battery_static_info { 6190 uint16_t design_capacity; 6191 uint16_t design_voltage; 6192 char manufacturer[EC_COMM_TEXT_MAX]; 6193 char model[EC_COMM_TEXT_MAX]; 6194 char serial[EC_COMM_TEXT_MAX]; 6195 char type[EC_COMM_TEXT_MAX]; 6196 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ 6197 uint32_t cycle_count; 6198 } __ec_align4; 6199 6200 /* 6201 * Get battery dynamic information, i.e. information that is likely to change 6202 * every time it is read. 6203 */ 6204 #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 6205 6206 /** 6207 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters 6208 * @index: Battery index. 6209 */ 6210 struct ec_params_battery_dynamic_info { 6211 uint8_t index; 6212 } __ec_align_size1; 6213 6214 /** 6215 * struct ec_response_battery_dynamic_info - Battery dynamic info response 6216 * @actual_voltage: Battery voltage (mV) 6217 * @actual_current: Battery current (mA); negative=discharging 6218 * @remaining_capacity: Remaining capacity (mAh) 6219 * @full_capacity: Capacity (mAh, might change occasionally) 6220 * @flags: Flags, see EC_BATT_FLAG_* 6221 * @desired_voltage: Charging voltage desired by battery (mV) 6222 * @desired_current: Charging current desired by battery (mA) 6223 */ 6224 struct ec_response_battery_dynamic_info { 6225 int16_t actual_voltage; 6226 int16_t actual_current; 6227 int16_t remaining_capacity; 6228 int16_t full_capacity; 6229 int16_t flags; 6230 int16_t desired_voltage; 6231 int16_t desired_current; 6232 } __ec_align2; 6233 6234 /* 6235 * Control charger chip. Used to control charger chip on the slave. 6236 */ 6237 #define EC_CMD_CHARGER_CONTROL 0x0602 6238 6239 /** 6240 * struct ec_params_charger_control - Charger control parameters 6241 * @max_current: Charger current (mA). Positive to allow base to draw up to 6242 * max_current and (possibly) charge battery, negative to request current 6243 * from base (OTG). 6244 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is 6245 * >= 0. 6246 * @allow_charging: Allow base battery charging (only makes sense if 6247 * max_current > 0). 6248 */ 6249 struct ec_params_charger_control { 6250 int16_t max_current; 6251 uint16_t otg_voltage; 6252 uint8_t allow_charging; 6253 } __ec_align_size1; 6254 6255 /* Get ACK from the USB-C SS muxes */ 6256 #define EC_CMD_USB_PD_MUX_ACK 0x0603 6257 6258 struct ec_params_usb_pd_mux_ack { 6259 uint8_t port; /* USB-C port number */ 6260 } __ec_align1; 6261 6262 /*****************************************************************************/ 6263 /* 6264 * Reserve a range of host commands for board-specific, experimental, or 6265 * special purpose features. These can be (re)used without updating this file. 6266 * 6267 * CAUTION: Don't go nuts with this. Shipping products should document ALL 6268 * their EC commands for easier development, testing, debugging, and support. 6269 * 6270 * All commands MUST be #defined to be 4-digit UPPER CASE hex values 6271 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. 6272 * 6273 * In your experimental code, you may want to do something like this: 6274 * 6275 * #define EC_CMD_MAGIC_FOO 0x0000 6276 * #define EC_CMD_MAGIC_BAR 0x0001 6277 * #define EC_CMD_MAGIC_HEY 0x0002 6278 * 6279 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, 6280 * EC_VER_MASK(0); 6281 * 6282 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, 6283 * EC_VER_MASK(0); 6284 * 6285 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, 6286 * EC_VER_MASK(0); 6287 */ 6288 #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 6289 #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF 6290 6291 /* 6292 * Given the private host command offset, calculate the true private host 6293 * command value. 6294 */ 6295 #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ 6296 (EC_CMD_BOARD_SPECIFIC_BASE + (command)) 6297 6298 /*****************************************************************************/ 6299 /* 6300 * Passthru commands 6301 * 6302 * Some platforms have sub-processors chained to each other. For example. 6303 * 6304 * AP <--> EC <--> PD MCU 6305 * 6306 * The top 2 bits of the command number are used to indicate which device the 6307 * command is intended for. Device 0 is always the device receiving the 6308 * command; other device mapping is board-specific. 6309 * 6310 * When a device receives a command to be passed to a sub-processor, it passes 6311 * it on with the device number set back to 0. This allows the sub-processor 6312 * to remain blissfully unaware of whether the command originated on the next 6313 * device up the chain, or was passed through from the AP. 6314 * 6315 * In the above example, if the AP wants to send command 0x0002 to the PD MCU, 6316 * AP sends command 0x4002 to the EC 6317 * EC sends command 0x0002 to the PD MCU 6318 * EC forwards PD MCU response back to the AP 6319 */ 6320 6321 /* Offset and max command number for sub-device n */ 6322 #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) 6323 #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) 6324 6325 /*****************************************************************************/ 6326 /* 6327 * Deprecated constants. These constants have been renamed for clarity. The 6328 * meaning and size has not changed. Programs that use the old names should 6329 * switch to the new names soon, as the old names may not be carried forward 6330 * forever. 6331 */ 6332 #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE 6333 #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 6334 #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE 6335 6336 6337 6338 #endif /* __CROS_EC_COMMANDS_H */ 6339