github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/ectool/commands.go (about) 1 package main 2 3 /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 /* Host communication command constants for Chrome EC */ 9 10 const ( 11 12 /* 13 * Current version of this protocol 14 * 15 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is 16 * determined in other ways. Remove this once the kernel code no longer 17 * depends on it. 18 */ 19 ecProtoVersion = 0x00000002 20 21 /* I/O addresses for ACPI commands */ 22 ecLpcAddrAcpiData = 0x62 23 ecLpcAddrAcpiCmd = 0x66 24 25 /* I/O addresses for host command */ 26 ecLpcAddrHostData = 0x200 27 ecLpcAddrHostCmd = 0x204 28 29 /* I/O addresses for host command args and params */ 30 /* Protocol version 2 */ 31 ecLpcAddrHostArgs = 0x800 /* And 0x801, 0x802, 0x803 */ 32 ecLpcAddrHostParam = 0x804 /* For version 2 params; size is 33 * ecProto2MaxParamSize */ 34 /* Protocol version 3 */ 35 ecLpcAddrHostPacket = 0x800 /* Offset of version 3 packet */ 36 ecLpcHostPacketSize = 0x100 /* Max size of version 3 packet */ 37 38 /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff 39 * and they tell the kernel that so we have to think of it as two parts. */ 40 ecHostCmdRegion0 = 0x800 41 ecHostCmdRegion1 = 0x880 42 ecHostCmdRegionSize = 0x80 43 44 /* EC command register bit functions */ 45 ecLpcCmdrData = (1 << 0) /* Data ready for host to read */ 46 ecLpcCmdrPending = (1 << 1) /* Write pending to EC */ 47 ecLpcCmdrBusy = (1 << 2) /* EC is busy processing a command */ 48 ecLpcCmdrCmd = (1 << 3) /* Last host write was a command */ 49 ecLpcCmdrAcpiBrst = (1 << 4) /* Burst mode (not used) */ 50 ecLpcCmdrSci = (1 << 5) /* SCI event is pending */ 51 ecLpcCmdrSmi = (1 << 6) /* SMI event is pending */ 52 53 ecLpcAddrMemmap = 0x900 54 ecMemmapSize = 255 /* ACPI IO buffer max is 255 bytes */ 55 ecMemmapTextMax = 8 /* Size of a string in the memory map */ 56 57 /* The offset address of each type of data in mapped memory. */ 58 ecMemmapTempSensor = 0x00 /* Temp sensors 0x00 - 0x0f */ 59 ecMemmapFan = 0x10 /* Fan speeds 0x10 - 0x17 */ 60 ecMemmapTempSensorB = 0x18 /* More temp sensors 0x18 - 0x1f */ 61 ecMemmapID = 0x20 /* 0x20 == 'E', 0x21 == 'C' */ 62 ecMemmapIDVersion = 0x22 /* Version of data in 0x20 - 0x2f */ 63 ecMemmapThermalVersion = 0x23 /* Version of data in 0x00 - 0x1f */ 64 ecMemmapBatteryVersion = 0x24 /* Version of data in 0x40 - 0x7f */ 65 ecMemmapSwitchesVersion = 0x25 /* Version of data in 0x30 - 0x33 */ 66 ecMemmapEventsVersion = 0x26 /* Version of data in 0x34 - 0x3f */ 67 ecMemmapHostCmdFlags = 0x27 /* Host cmd interface flags (8 bits) */ 68 /* Unused 0x28 - 0x2f */ 69 ecMemmapSwitches = 0x30 /* 8 bits */ 70 /* Unused 0x31 - 0x33 */ 71 ecMemmapHostEvents = 0x34 /* 32 bits */ 72 /* Reserve 0x38 - 0x3f for additional host event-related stuff */ 73 /* Battery values are all 32 bits */ 74 ecMemmapBattVolt = 0x40 /* Battery Present Voltage */ 75 ecMemmapBattRate = 0x44 /* Battery Present Rate */ 76 ecMemmapBattCap = 0x48 /* Battery Remaining Capacity */ 77 ecMemmapBattFlag = 0x4c /* Battery State, defined below */ 78 ecMemmapBattDcap = 0x50 /* Battery Design Capacity */ 79 ecMemmapBattDvlt = 0x54 /* Battery Design Voltage */ 80 ecMemmapBattLfcc = 0x58 /* Battery Last Full Charge Capacity */ 81 ecMemmapBattCcnt = 0x5c /* Battery Cycle Count */ 82 /* Strings are all 8 bytes (ecMemmapTextMax) */ 83 ecMemmapBattMfgr = 0x60 /* Battery Manufacturer String */ 84 ecMemmapBattModel = 0x68 /* Battery Model Number String */ 85 ecMemmapBattSerial = 0x70 /* Battery Serial Number String */ 86 ecMemmapBattType = 0x78 /* Battery Type String */ 87 ecMemmapAls = 0x80 /* ALS readings in lux (2 X 16 bits) */ 88 /* Unused 0x84 - 0x8f */ 89 ecMemmapAccStatus = 0x90 /* Accelerometer status (8 bits )*/ 90 /* Unused 0x91 */ 91 ecMemmapAccData = 0x92 /* Accelerometer data 0x92 - 0x9f */ 92 ecMemmapGyroData = 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ 93 /* Unused 0xa6 - 0xdf */ 94 95 /* 96 * ACPI is unable to access memory mapped data at or above this offset due to 97 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe 98 * which might be needed by ACPI. 99 */ 100 ecMemmapNoAcpi = 0xe0 101 102 /* Define the format of the accelerometer mapped memory status byte. */ 103 ecMemmapAccStatusSampleIDMask = 0x0f 104 ecMemmapAccStatusBusyBit = (1 << 4) 105 ecMemmapAccStatusPresenceBit = (1 << 7) 106 107 /* Number of temp sensors at ecMemmapTempSensor */ 108 ecTempSensorEntries = 16 109 /* 110 * Number of temp sensors at ecMemmapTempSensorB. 111 * 112 * Valid only if ecMemmapThermalVersion returns >= 2. 113 */ 114 ecTempSensorBEntries = 8 115 116 /* Special values for mapped temperature sensors */ 117 ecTempSensorNotPresent = 0xff 118 ecTempSensorError = 0xfe 119 ecTempSensorNotPowered = 0xfd 120 ecTempSensorNotCalibrated = 0xfc 121 /* 122 * The offset of temperature value stored in mapped memory. This allows 123 * reporting a temperature range of 200K to 454K = -73C to 181C. 124 */ 125 ecTempSensorOffset = 200 126 127 /* 128 * Number of ALS readings at ecMemmapAls 129 */ 130 ecAlsEntries = 2 131 132 /* 133 * The default value a temperature sensor will return when it is present but 134 * has not been read this boot. This is a reasonable number to avoid 135 * triggering alarms on the host. 136 */ 137 ecTempSensorDefault = (296 - ecTempSensorOffset) 138 139 ecFanSpeedEntries = 4 /* Number of fans at ecMemmapFan */ 140 ecFanSpeedNotPresent = 0xffff /* Entry not present */ 141 ecFanSpeedStalled = 0xfffe /* Fan stalled */ 142 143 /* Battery bit flags at ecMemmapBattFlag. */ 144 ecBattFlagAcPresent = 0x01 145 ecBattFlagBattPresent = 0x02 146 ecBattFlagDischarging = 0x04 147 ecBattFlagCharging = 0x08 148 ecBattFlagLevelCritical = 0x10 149 150 /* Switch flags at ecMemmapSwitches */ 151 ecSwitchLidOpen = 0x01 152 ecSwitchPowerButtonPressed = 0x02 153 ecSwitchWriteProtectDisabled = 0x04 154 /* Was recovery requested via keyboard; now unused. */ 155 ecSwitchIgnore1 = 0x08 156 /* Recovery requested via dedicated signal (from servo board) */ 157 ecSwitchDedicatedRecovery = 0x10 158 /* Was fake developer mode switch; now unused. Remove in next refactor. */ 159 ecSwitchIgnore0 = 0x20 160 161 /* Host command interface flags */ 162 /* Host command interface supports LPC args (LPC interface only) */ 163 ecHostCmdFlagLpcArgsSupported = 0x01 164 /* Host command interface supports version 3 protocol */ 165 ecHostCmdFlagVersion3 = 0x02 166 167 /* Wireless switch flags */ 168 ecWirelessSwitchAll = ^0x00 /* All flags */ 169 ecWirelessSwitchWlan = 0x01 /* WLAN radio */ 170 ecWirelessSwitchBluetooth = 0x02 /* Bluetooth radio */ 171 ecWirelessSwitchWwan = 0x04 /* WWAN power */ 172 ecWirelessSwitchWlanPower = 0x08 /* WLAN power */ 173 174 /*****************************************************************************/ 175 /* 176 * ACPI commands 177 * 178 * These are valid ONLY on the ACPI command/data port. 179 */ 180 181 /* 182 * ACPI Read Embedded Controller 183 * 184 * This reads from ACPI memory space on the EC (ecAcpiMem_*). 185 * 186 * Use the following sequence: 187 * 188 * - Write ecCmdAcpiRead to ecLpcAddrAcpiCmd 189 * - Wait for ecLpcCmdrPending bit to clear 190 * - Write address to ecLpcAddrAcpiData 191 * - Wait for ecLpcCmdrData bit to set 192 * - Read value from ecLpcAddrAcpiData 193 */ 194 ecCmdAcpiRead = 0x80 195 196 /* 197 * ACPI Write Embedded Controller 198 * 199 * This reads from ACPI memory space on the EC (ecAcpiMem_*). 200 * 201 * Use the following sequence: 202 * 203 * - Write ecCmdAcpiWrite to ecLpcAddrAcpiCmd 204 * - Wait for ecLpcCmdrPending bit to clear 205 * - Write address to ecLpcAddrAcpiData 206 * - Wait for ecLpcCmdrPending bit to clear 207 * - Write value to ecLpcAddrAcpiData 208 */ 209 ecCmdAcpiWrite = 0x81 210 211 /* 212 * ACPI Burst Enable Embedded Controller 213 * 214 * This enables burst mode on the EC to allow the host to issue several 215 * commands back-to-back. While in this mode, writes to mapped multi-byte 216 * data are locked out to ensure data consistency. 217 */ 218 ecCmdAcpiBurstEnable = 0x82 219 220 /* 221 * ACPI Burst Disable Embedded Controller 222 * 223 * This disables burst mode on the EC and stops preventing EC writes to mapped 224 * multi-byte data. 225 */ 226 ecCmdAcpiBurstDisable = 0x83 227 228 /* 229 * ACPI Query Embedded Controller 230 * 231 * This clears the lowest-order bit in the currently pending host events, and 232 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1 233 * event 0x80000000 = 32), or 0 if no event was pending. 234 */ 235 ecCmdAcpiQueryEvent = 0x84 236 237 /* Valid addresses in ACPI memory space, for read/write commands */ 238 239 /* Memory space version; set to ecAcpiMemVersionCurrent */ 240 ecAcpiMemVersion = 0x00 241 /* 242 * Test location; writing value here updates test compliment byte to (0xff - 243 * value). 244 */ 245 ecAcpiMemTest = 0x01 246 /* Test compliment; writes here are ignored. */ 247 ecAcpiMemTestCompliment = 0x02 248 249 /* Keyboard backlight brightness percent (0 - 100) */ 250 ecAcpiMemKeyboardBacklight = 0x03 251 /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ 252 ecAcpiMemFanDuty = 0x04 253 254 /* 255 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two 256 * independent thresholds attached to them. The current value of the ID 257 * register determines which sensor is affected by the THRESHOLD and COMMIT 258 * registers. The THRESHOLD register uses the same ecTempSensorOffset scheme 259 * as the memory-mapped sensors. The COMMIT register applies those settings. 260 * 261 * The spec does not mandate any way to read back the threshold settings 262 * themselves, but when a threshold is crossed the AP needs a way to determine 263 * which sensor(s) are responsible. Each reading of the ID register clears and 264 * returns one sensor ID that has crossed one of its threshold (in either 265 * direction) since the last read. A value of 0xFF means "no new thresholds 266 * have tripped". Setting or enabling the thresholds for a sensor will clear 267 * the unread event count for that sensor. 268 */ 269 ecAcpiMemTempID = 0x05 270 ecAcpiMemTempThreshold = 0x06 271 ecAcpiMemTempCommit = 0x07 272 /* 273 * Here are the bits for the COMMIT register: 274 * bit 0 selects the threshold index for the chosen sensor (0/1) 275 * bit 1 enables/disables the selected threshold (0 = off, 1 = on) 276 * Each write to the commit register affects one threshold. 277 */ 278 ecAcpiMemTempCommitSelectMask = (1 << 0) 279 ecAcpiMemTempCommitEnableMask = (1 << 1) 280 /* 281 * Example: 282 * 283 * Set the thresholds for sensor 2 to 50 C and 60 C: 284 * write 2 to [0x05] -- select temp sensor 2 285 * write 0x7b to [0x06] -- CToK(50) - ecTempSensorOffset 286 * write 0x2 to [0x07] -- enable threshold 0 with this value 287 * write 0x85 to [0x06] -- CToK(60) - ecTempSensorOffset 288 * write 0x3 to [0x07] -- enable threshold 1 with this value 289 * 290 * Disable the 60 C threshold, leaving the 50 C threshold unchanged: 291 * write 2 to [0x05] -- select temp sensor 2 292 * write 0x1 to [0x07] -- disable threshold 1 293 */ 294 295 /* DPTF battery charging current limit */ 296 ecAcpiMemChargingLimit = 0x08 297 298 /* Charging limit is specified in 64 mA steps */ 299 ecAcpiMemChargingLimitStepMa = 64 300 /* Value to disable DPTF battery charging limit */ 301 ecAcpiMemChargingLimitDisabled = 0xff 302 303 /* 304 * ACPI addresses 0x20 - 0xff map to ecMemmap offset 0x00 - 0xdf. This data 305 * is read-only from the AP. Added in ecAcpiMemVersion 2. 306 */ 307 ecAcpiMemMappedBegin = 0x20 308 ecAcpiMemMappedSize = 0xe0 309 310 /* Current version of ACPI memory address space */ 311 ecAcpiMemVersionCurrent = 2 312 313 /* 314 * This header file is used in coreboot both in C and ACPI code. The ACPI code 315 * is pre-processed to handle constants but the ASL compiler is unable to 316 * handle actual C code so keep it separate. 317 */ 318 319 /* LPC command status byte masks */ 320 /* EC has written a byte in the data register and host hasn't read it yet */ 321 ecLpcStatusToHost = 0x01 322 /* Host has written a command/data byte and the EC hasn't read it yet */ 323 ecLpcStatusFromHost = 0x02 324 /* EC is processing a command */ 325 ecLpcStatusProcessing = 0x04 326 /* Last write to EC was a command, not data */ 327 ecLpcStatusLastCmd = 0x08 328 /* EC is in burst mode */ 329 ecLpcStatusBurstMode = 0x10 330 /* SCI event is pending (requesting SCI query) */ 331 ecLpcStatusSciPending = 0x20 332 /* SMI event is pending (requesting SMI query) */ 333 ecLpcStatusSmiPending = 0x40 334 /* (reserved) */ 335 ecLpcStatusReserved = 0x80 336 337 /* 338 * EC is busy. This covers both the EC processing a command, and the host has 339 * written a new command but the EC hasn't picked it up yet. 340 */ 341 ecLpcStatusBusyMask = (ecLpcStatusFromHost | ecLpcStatusProcessing) 342 ) 343 344 /* Host command response codes */ 345 type ecStatus uint8 346 347 const ( 348 ecResSuccess ecStatus = 0 349 ecResInvalidCommand = 1 350 ecResError = 2 351 ecResInvalidParam = 3 352 ecResAccessDenied = 4 353 ecResInvalidResponse = 5 354 ecResInvalidVersion = 6 355 ecResInvalidChecksum = 7 356 ecResInProgress = 8 /* Accepted, command in progress */ 357 ecResUnavailable = 9 /* No response available */ 358 ecResTimeout = 10 /* We got a timeout */ 359 ecResOverflow = 11 /* Table / data overflow */ 360 ecResInvalidHeader = 12 /* Header contains invalid data */ 361 ecResRequestTruncated = 13 /* Didn't get the entire request */ 362 ecResResponseTooBig = 14 /* Response was too big to handle */ 363 ecResBusError = 15 /* Communications bus error */ 364 ecResBusy = 16 /* Up but too busy. Should retry */ 365 ) 366 367 /* 368 * Host event codes. Note these are 1-based, not 0-based, because ACPI query 369 * EC command uses code 0 to mean "no event pending". We explicitly specify 370 * each value in the enum listing so they won't change if we delete/insert an 371 * item or rearrange the list (it needs to be stable across platforms, not 372 * just within a single compiled instance). 373 */ 374 type hostEventCode uint8 375 376 const ( 377 ecHostEventLidClosed hostEventCode = 1 378 ecHostEventLidOpen = 2 379 ecHostEventPowerButton = 3 380 ecHostEventAcConnected = 4 381 ecHostEventAcDisconnected = 5 382 ecHostEventBatteryLow = 6 383 ecHostEventBatteryCritical = 7 384 ecHostEventBattery = 8 385 ecHostEventThermalThreshold = 9 386 ecHostEventThermalOverload = 10 387 ecHostEventThermal = 11 388 ecHostEventUsbCharger = 12 389 ecHostEventKeyPressed = 13 390 /* 391 * EC has finished initializing the host interface. The host can check 392 * for this event following sending a ecCmdRebootEc command to 393 * determine when the EC is ready to accept subsequent commands. 394 */ 395 ecHostEventInterfaceReady = 14 396 /* Keyboard recovery combo has been pressed */ 397 ecHostEventKeyboardRecovery = 15 398 399 /* Shutdown due to thermal overload */ 400 ecHostEventThermalShutdown = 16 401 /* Shutdown due to battery level too low */ 402 ecHostEventBatteryShutdown = 17 403 404 /* Suggest that the AP throttle itself */ 405 ecHostEventThrottleStart = 18 406 /* Suggest that the AP resume normal speed */ 407 ecHostEventThrottleStop = 19 408 409 /* Hang detect logic detected a hang and host event timeout expired */ 410 ecHostEventHangDetect = 20 411 /* Hang detect logic detected a hang and warm rebooted the AP */ 412 ecHostEventHangReboot = 21 413 414 /* PD MCU triggering host event */ 415 ecHostEventPdMcu = 22 416 417 /* Battery Status flags have changed */ 418 ecHostEventBatteryStatus = 23 419 420 /* EC encountered a panic, triggering a reset */ 421 ecHostEventPanic = 24 422 423 /* 424 * The high bit of the event mask is not used as a host event code. If 425 * it reads back as set, then the entire event mask should be 426 * considered invalid by the host. This can happen when reading the 427 * raw event status via ecMemmapHostEvents but the LPC interface is 428 * not initialized on the EC, or improperly configured on the host. 429 */ 430 ecHostEventInvalid = 32 431 ) 432 433 /* Host event mask */ 434 func ecHostEventMask(eventCode uint8) uint8 { 435 return 1 << ((eventCode) - 1) 436 } 437 438 /* TYPE */ 439 /* Arguments at ecLpcAddrHostArgs */ 440 type ecLpcHostArgs struct { 441 flags uint8 442 commandVersion uint8 443 dataSize uint8 444 /* 445 * Checksum; sum of command + flags + commandVersion + dataSize + 446 * all params/response data bytes. 447 */ 448 checksum uint8 449 } 450 451 /* Flags for ecLpcHostArgs.flags */ 452 /* 453 * Args are from host. Data area at ecLpcAddrHostParam contains command 454 * params. 455 * 456 * If EC gets a command and this flag is not set, this is an old-style command. 457 * Command version is 0 and params from host are at ecLpcAddrOldParam with 458 * unknown length. EC must respond with an old-style response (that is 459 * withouth setting ecHostArgsFlagToHost). 460 */ 461 const ecHostArgsFlagFromHost = 0x01 462 463 /* 464 * Args are from EC. Data area at ecLpcAddrHostParam contains response. 465 * 466 * If EC responds to a command and this flag is not set, this is an old-style 467 * response. Command version is 0 and response data from EC is at 468 * ecLpcAddrOldParam with unknown length. 469 */ 470 const ecHostArgsFlagToHost = 0x02 471 472 /*****************************************************************************/ 473 /* 474 * Byte codes returned by EC over SPI interface. 475 * 476 * These can be used by the AP to debug the EC interface, and to determine 477 * when the EC is not in a state where it will ever get around to responding 478 * to the AP. 479 * 480 * Example of sequence of bytes read from EC for a current good transfer: 481 * 1. - - AP asserts chip select (CS#) 482 * 2. ecSpiOldReady - AP sends first byte(s) of request 483 * 3. - - EC starts handling CS# interrupt 484 * 4. ecSpiReceiving - AP sends remaining byte(s) of request 485 * 5. ecSpiProcessing - EC starts processing request; AP is clocking in 486 * bytes looking for ecSpiFrameStart 487 * 6. - - EC finishes processing and sets up response 488 * 7. ecSpiFrameStart - AP reads frame byte 489 * 8. (response packet) - AP reads response packet 490 * 9. ecSpiPastEnd - Any additional bytes read by AP 491 * 10 - - AP deasserts chip select 492 * 11 - - EC processes CS# interrupt and sets up DMA for 493 * next request 494 * 495 * If the AP is waiting for ecSpiFrameStart and sees any value other than 496 * the following byte values: 497 * ecSpiOldReady 498 * ecSpiRxReady 499 * ecSpiReceiving 500 * ecSpiProcessing 501 * 502 * Then the EC found an error in the request, or was not ready for the request 503 * and lost data. The AP should give up waiting for ecSpiFrameStart 504 * because the EC is unable to tell when the AP is done sending its request. 505 */ 506 507 /* 508 * Framing byte which precedes a response packet from the EC. After sending a 509 * request, the AP will clock in bytes until it sees the framing byte, then 510 * clock in the response packet. 511 */ 512 const ( 513 ecSpiFrameStart = 0xec 514 515 /* 516 * Padding bytes which are clocked out after the end of a response packet. 517 */ 518 ecSpiPastEnd = 0xed 519 520 /* 521 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects 522 * that the AP will send a valid packet header (starting with 523 * ecCommandProtocol3) in the next 32 bytes. 524 */ 525 ecSpiRxReady = 0xf8 526 527 /* 528 * EC has started receiving the request from the AP, but hasn't started 529 * processing it yet. 530 */ 531 ecSpiReceiving = 0xf9 532 533 /* EC has received the entire request from the AP and is processing it. */ 534 ecSpiProcessing = 0xfa 535 536 /* 537 * EC received bad data from the AP, such as a packet header with an invalid 538 * length. EC will ignore all data until chip select deasserts. 539 */ 540 ecSpiRxBadData = 0xfb 541 542 /* 543 * EC received data from the AP before it was ready. That is, the AP asserted 544 * chip select and started clocking data before the EC was ready to receive it. 545 * EC will ignore all data until chip select deasserts. 546 */ 547 ecSpiNotReady = 0xfc 548 549 /* 550 * EC was ready to receive a request from the AP. EC has treated the byte sent 551 * by the AP as part of a request packet, or (for old-style ECs) is processing 552 * a fully received packet but is not ready to respond yet. 553 */ 554 ecSpiOldReady = 0xfd 555 556 /*****************************************************************************/ 557 558 /* 559 * Protocol version 2 for I2C and SPI send a request this way: 560 * 561 * 0 ecCmdVersion0 + (command version) 562 * 1 Command number 563 * 2 Length of params = N 564 * 3..N+2 Params, if any 565 * N+3 8-bit checksum of bytes 0..N+2 566 * 567 * The corresponding response is: 568 * 569 * 0 Result code (ecRes_*) 570 * 1 Length of params = M 571 * 2..M+1 Params, if any 572 * M+2 8-bit checksum of bytes 0..M+1 573 */ 574 ecProto2RequestHeaderBytes = 3 575 ecProto2RequestTrailerBytes = 1 576 ecProto2RequestOverhead = (ecProto2RequestHeaderBytes + 577 ecProto2RequestTrailerBytes) 578 579 ecProto2ResponseHeaderBytes = 2 580 ecProto2ResponseTrailerBytes = 1 581 ecProto2ResponseOverhead = (ecProto2ResponseHeaderBytes + 582 ecProto2ResponseTrailerBytes) 583 584 /* Parameter length was limited by the LPC interface */ 585 ecProto2MaxParamSize = 0xfc 586 587 /* Maximum request and response packet sizes for protocol version 2 */ 588 ecProto2MaxRequestSize = (ecProto2RequestOverhead + 589 ecProto2MaxParamSize) 590 ecProto2MaxResponseSize = (ecProto2ResponseOverhead + 591 ecProto2MaxParamSize) 592 593 /*****************************************************************************/ 594 595 /* 596 * Value written to legacy command port / prefix byte to indicate protocol 597 * 3+ structs are being used. Usage is bus-dependent. 598 */ 599 ecCommandProtocol3 = 0xda 600 601 ecHostRequestVersion = 3 602 ) 603 604 /* TYPE */ 605 /* Version 3 request from host */ 606 type ecHostRequest struct { 607 /* Struct version (=3) 608 * 609 * EC will return ecResInvalidHeader if it receives a header with a 610 * version it doesn't know how to parse. 611 */ 612 structVersion uint8 613 614 /* 615 * Checksum of request and data; sum of all bytes including checksum 616 * should total to 0. 617 */ 618 checksum uint8 619 620 /* Command code */ 621 command uint16 622 623 /* Command version */ 624 commandVersion uint8 625 626 /* Unused byte in current protocol version; set to 0 */ 627 reserved uint8 628 629 /* Length of data which follows this header */ 630 dataLen uint16 631 } 632 633 const ecHostResponseVersion = 3 634 635 /* TYPE */ 636 /* Version 3 response from EC */ 637 type ecHostResponse struct { 638 /* Struct version (=3) */ 639 structVersion uint8 640 641 /* 642 * Checksum of response and data; sum of all bytes including checksum 643 * should total to 0. 644 */ 645 checksum uint8 646 647 /* Result code (ecRes_*) */ 648 result uint16 649 650 /* Length of data which follows this header */ 651 dataLen uint16 652 653 /* Unused bytes in current protocol version; set to 0 */ 654 reserved uint16 655 } 656 657 /*****************************************************************************/ 658 /* 659 * Notes on commands: 660 * 661 * Each command is an 16-bit command value. Commands which take params or 662 * return response data specify structs for that data. If no struct is 663 * specified, the command does not input or output data, respectively. 664 * Parameter/response length is implicit in the structs. Some underlying 665 * communication protocols (I2C, SPI) may add length or checksum headers, but 666 * those are implementation-dependent and not defined here. 667 */ 668 669 /*****************************************************************************/ 670 /* General / test commands */ 671 672 /* 673 * Get protocol version, used to deal with non-backward compatible protocol 674 * changes. 675 */ 676 const ecCmdProtoVersion = 0x00 677 678 /* TYPE */ 679 type ecResponseProtoVersion struct { 680 version uint32 681 } 682 683 const ( 684 /* 685 * Hello. This is a simple command to test the EC is responsive to 686 * commands. 687 */ 688 ecCmdHello = 0x01 689 ) 690 691 /* TYPE */ 692 type ecParamsHello struct { 693 inData uint32 /* Pass anything here */ 694 } 695 696 /* TYPE */ 697 type ecResponseHello struct { 698 outData uint32 /* Output will be inData + 0x01020304 */ 699 } 700 701 const ( 702 /* Get version number */ 703 ecCmdGetVersion = 0x02 704 ) 705 706 type ecCurrentImage uint8 707 708 const ( 709 ecImageUnknown ecCurrentImage = 0 710 ecImageRo 711 ecImageRw 712 ) 713 714 /* TYPE */ 715 type ecResponseGetVersion struct { 716 /* Null-terminated version strings for RO, RW */ 717 versionStringRo [32]byte 718 versionStringRw [32]byte 719 reserved [32]byte /* Was previously RW-B string */ 720 currentImage uint32 /* One of ecCurrentImage */ 721 } 722 723 const ( 724 /* Read test */ 725 ecCmdReadTest = 0x03 726 ) 727 728 /* TYPE */ 729 type ecParamsReadTest struct { 730 offset uint32 /* Starting value for read buffer */ 731 size uint32 /* Size to read in bytes */ 732 } 733 734 /* TYPE */ 735 type ecResponseReadTest struct { 736 data [32]uint32 737 } 738 739 const ( 740 /* 741 * Get build information 742 * 743 * Response is null-terminated string. 744 */ 745 ecCmdGetBuildInfo = 0x04 746 747 /* Get chip info */ 748 ecCmdGetChipInfo = 0x05 749 ) 750 751 /* TYPE */ 752 type ecResponseGetChipInfo struct { 753 /* Null-terminated strings */ 754 vendor [32]byte 755 name [32]byte 756 revision [32]byte /* Mask version */ 757 } 758 759 const ( 760 /* Get board HW version */ 761 ecCmdGetBoardVersion = 0x06 762 ) 763 764 /* TYPE */ 765 type ecResponseBoardVersion struct { 766 boardVersion uint16 /* A monotonously incrementing number. */ 767 } 768 769 /* 770 * Read memory-mapped data. 771 * 772 * This is an alternate interface to memory-mapped data for bus protocols 773 * which don't support direct-mapped memory - I2C, SPI, etc. 774 * 775 * Response is params.size bytes of data. 776 */ 777 const ( 778 ecCmdReadMemmap = 0x07 779 ) 780 781 /* TYPE */ 782 type ecParamsReadMemmap struct { 783 offset uint8 /* Offset in memmap (ecMemmap_*) */ 784 size uint8 /* Size to read in bytes */ 785 } 786 787 /* Read versions supported for a command */ 788 const ecCmdGetCmdVersions = 0x08 789 790 /* TYPE */ 791 type ecParamsGetCmdVersions struct { 792 cmd uint8 /* Command to check */ 793 } 794 795 /* TYPE */ 796 type ecParamsGetCmdVersionsV1 struct { 797 cmd uint16 /* Command to check */ 798 } 799 800 /* TYPE */ 801 type ecResponseGetCmdVersions struct { 802 /* 803 * Mask of supported versions; use ecVerMask() to compare with a 804 * desired version. 805 */ 806 versionMask uint32 807 } 808 809 /* 810 * Check EC communcations status (busy). This is needed on i2c/spi but not 811 * on lpc since it has its own out-of-band busy indicator. 812 * 813 * lpc must read the status from the command register. Attempting this on 814 * lpc will overwrite the args/parameter space and corrupt its data. 815 */ 816 const ecCmdGetCommsStatus = 0x09 817 818 /* Avoid using ecStatus which is for return values */ 819 type ecCommsStatus uint8 820 821 const ( 822 ecCommsStatusProcessing ecCommsStatus = 1 << 0 /* Processing cmd */ 823 ) 824 825 /* TYPE */ 826 type ecResponseGetCommsStatus struct { 827 flags uint32 /* Mask of enum ecCommsStatus */ 828 } 829 830 const ( 831 /* Fake a variety of responses, purely for testing purposes. */ 832 ecCmdTestProtocol = 0x0a 833 ) 834 835 /* TYPE */ 836 /* Tell the EC what to send back to us. */ 837 type ecParamsTestProtocol struct { 838 ecResult uint32 839 retLen uint32 840 buf [32]uint8 841 } 842 843 /* TYPE */ 844 /* Here it comes... */ 845 type ecResponseTestProtocol struct { 846 buf [32]uint8 847 } 848 849 /* Get prococol information */ 850 const ecCmdGetProtocolInfo = 0x0b 851 852 /* Flags for ecResponseGetProtocolInfo.flags */ 853 /* ecResInProgress may be returned if a command is slow */ 854 const ecProtocolInfoInProgressSupported = (1 << 0) 855 856 /* TYPE */ 857 type ecResponseGetProtocolInfo struct { 858 /* Fields which exist if at least protocol version 3 supported */ 859 860 /* Bitmask of protocol versions supported (1 << n means version n)*/ 861 protocolVersions uint32 862 863 /* Maximum request packet size, in bytes */ 864 maxRequestPacketSize uint16 865 866 /* Maximum response packet size, in bytes */ 867 maxResponsePacketSize uint16 868 869 /* Flags; see ecProtocolInfo_* */ 870 flags uint32 871 } 872 873 /*****************************************************************************/ 874 /* Get/Set miscellaneous values */ 875 const ( 876 /* The upper byte of .flags tells what to do (nothing means "get") */ 877 ecGsvSet = 0x80000000 878 879 /* The lower three bytes of .flags identifies the parameter, if that has 880 meaning for an individual command. */ 881 ecGsvParamMask = 0x00ffffff 882 ) 883 884 /* TYPE */ 885 type ecParamsGetSetValue struct { 886 flags uint32 887 value uint32 888 } 889 890 /* TYPE */ 891 type ecResponseGetSetValue struct { 892 flags uint32 893 value uint32 894 } 895 896 /* More than one command can use these structs to get/set parameters. */ 897 const ecCmdGsvPauseInS5 = 0x0c 898 899 /*****************************************************************************/ 900 /* Flash commands */ 901 902 /* Get flash info */ 903 const ecCmdFlashInfo = 0x10 904 905 /* TYPE */ 906 /* Version 0 returns these fields */ 907 type ecResponseFlashInfo struct { 908 /* Usable flash size, in bytes */ 909 flashSize uint32 910 /* 911 * Write block size. Write offset and size must be a multiple 912 * of this. 913 */ 914 writeBlockSize uint32 915 /* 916 * Erase block size. Erase offset and size must be a multiple 917 * of this. 918 */ 919 eraseBlockSize uint32 920 /* 921 * Protection block size. Protection offset and size must be a 922 * multiple of this. 923 */ 924 protectBlockSize uint32 925 } 926 927 /* Flags for version 1+ flash info command */ 928 /* EC flash erases bits to 0 instead of 1 */ 929 const ecFlashInfoEraseTo0 = (1 << 0) 930 931 /* TYPE */ 932 /* 933 * Version 1 returns the same initial fields as version 0, with additional 934 * fields following. 935 * 936 * gcc anonymous structs don't seem to get along with the directive; 937 * if they did we'd define the version 0 struct as a sub-struct of this one. 938 */ 939 type ecResponseFlashInfo1 struct { 940 /* Version 0 fields; see above for description */ 941 flashSize uint32 942 writeBlockSize uint32 943 eraseBlockSize uint32 944 protectBlockSize uint32 945 946 /* Version 1 adds these fields: */ 947 /* 948 * Ideal write size in bytes. Writes will be fastest if size is 949 * exactly this and offset is a multiple of this. For example, an EC 950 * may have a write buffer which can do half-page operations if data is 951 * aligned, and a slower word-at-a-time write mode. 952 */ 953 writeIdealSize uint32 954 955 /* Flags; see ecFlashInfo_* */ 956 flags uint32 957 } 958 959 /* 960 * Read flash 961 * 962 * Response is params.size bytes of data. 963 */ 964 const ecCmdFlashRead = 0x11 965 966 /* TYPE */ 967 type ecParamsFlashRead struct { 968 offset uint32 /* Byte offset to read */ 969 size uint32 /* Size to read in bytes */ 970 } 971 972 const ( 973 /* Write flash */ 974 ecCmdFlashWrite = 0x12 975 ecVerFlashWrite = 1 976 977 /* Version 0 of the flash command supported only 64 bytes of data */ 978 ecFlashWriteVer0Size = 64 979 ) 980 981 /* TYPE */ 982 type ecParamsFlashWrite struct { 983 offset uint32 /* Byte offset to write */ 984 size uint32 /* Size to write in bytes */ 985 /* Followed by data to write */ 986 } 987 988 /* Erase flash */ 989 const ecCmdFlashErase = 0x13 990 991 /* TYPE */ 992 type ecParamsFlashErase struct { 993 offset uint32 /* Byte offset to erase */ 994 size uint32 /* Size to erase in bytes */ 995 } 996 997 const ( 998 /* 999 * Get/set flash protection. 1000 * 1001 * If mask!=0, sets/clear the requested bits of flags. Depending on the 1002 * firmware write protect GPIO, not all flags will take effect immediately; 1003 * some flags require a subsequent hard reset to take effect. Check the 1004 * returned flags bits to see what actually happened. 1005 * 1006 * If mask=0, simply returns the current flags state. 1007 */ 1008 ecCmdFlashProtect = 0x15 1009 ecVerFlashProtect = 1 /* Command version 1 */ 1010 1011 /* Flags for flash protection */ 1012 /* RO flash code protected when the EC boots */ 1013 ecFlashProtectRoAtBoot = (1 << 0) 1014 /* 1015 * RO flash code protected now. If this bit is set, at-boot status cannot 1016 * be changed. 1017 */ 1018 ecFlashProtectRoNow = (1 << 1) 1019 /* Entire flash code protected now, until reboot. */ 1020 ecFlashProtectAllNow = (1 << 2) 1021 /* Flash write protect GPIO is asserted now */ 1022 ecFlashProtectGpioAsserted = (1 << 3) 1023 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ 1024 ecFlashProtectErrorStuck = (1 << 4) 1025 /* 1026 * Error - flash protection is in inconsistent state. At least one bank of 1027 * flash which should be protected is not protected. Usually fixed by 1028 * re-requesting the desired flags, or by a hard reset if that fails. 1029 */ 1030 ecFlashProtectErrorInconsistent = (1 << 5) 1031 /* Entire flash code protected when the EC boots */ 1032 ecFlashProtectAllAtBoot = (1 << 6) 1033 ) 1034 1035 /* TYPE */ 1036 type ecParamsFlashProtect struct { 1037 mask uint32 /* Bits in flags to apply */ 1038 flags uint32 /* New flags to apply */ 1039 } 1040 1041 /* TYPE */ 1042 type ecResponseFlashProtect struct { 1043 /* Current value of flash protect flags */ 1044 flags uint32 1045 /* 1046 * Flags which are valid on this platform. This allows the caller 1047 * to distinguish between flags which aren't set vs. flags which can't 1048 * be set on this platform. 1049 */ 1050 validFlags uint32 1051 /* Flags which can be changed given the current protection state */ 1052 writableFlags uint32 1053 } 1054 1055 /* 1056 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash 1057 * write protect. These commands may be reused with version > 0. 1058 */ 1059 1060 /* Get the region offset/size */ 1061 const ecCmdFlashRegionInfo = 0x16 1062 const ecVerFlashRegionInfo = 1 1063 1064 type ecFlashRegion uint8 1065 1066 const ( 1067 /* Region which holds read-only EC image */ 1068 ecFlashRegionRo ecFlashRegion = iota 1069 /* Region which holds rewritable EC image */ 1070 ecFlashRegionRw 1071 /* 1072 * Region which should be write-protected in the factory (a superset of 1073 * ecFlashRegionRo) 1074 */ 1075 ecFlashRegionWpRo 1076 /* Number of regions */ 1077 ecFlashRegionCount 1078 ) 1079 1080 /* TYPE */ 1081 type ecParamsFlashRegionInfo struct { 1082 region uint32 /* enum ecFlashRegion */ 1083 } 1084 1085 /* TYPE */ 1086 type ecResponseFlashRegionInfo struct { 1087 offset uint32 1088 size uint32 1089 } 1090 1091 const ( 1092 /* Read/write VbNvContext */ 1093 ecCmdVbnvContext = 0x17 1094 ecVerVbnvContext = 1 1095 ecVbnvBlockSize = 16 1096 ) 1097 1098 type ecVbnvcontextOp uint8 1099 1100 const ( 1101 ecVbnvContextOpRead ecVbnvcontextOp = iota 1102 ecVbnvContextOpWrite 1103 ) 1104 1105 /* TYPE */ 1106 type ecParamsVbnvcontext struct { 1107 op uint32 1108 block [ecVbnvBlockSize]uint8 1109 } 1110 1111 /* TYPE */ 1112 type ecResponseVbnvcontext struct { 1113 block [ecVbnvBlockSize]uint8 1114 } 1115 1116 /*****************************************************************************/ 1117 /* PWM commands */ 1118 1119 /* Get fan target RPM */ 1120 const ecCmdPwmGetFanTargetRpm = 0x20 1121 1122 /* TYPE */ 1123 type ecResponsePwmGetFanRpm struct { 1124 rpm uint32 1125 } 1126 1127 /* Set target fan RPM */ 1128 const ecCmdPwmSetFanTargetRpm = 0x21 1129 1130 /* TYPE */ 1131 /* Version 0 of input params */ 1132 type ecParamsPwmSetFanTargetRpmV0 struct { 1133 rpm uint32 1134 } 1135 1136 /* TYPE */ 1137 /* Version 1 of input params */ 1138 type ecParamsPwmSetFanTargetRpmV1 struct { 1139 rpm uint32 1140 fanIdx uint8 1141 } 1142 1143 /* Get keyboard backlight */ 1144 const ecCmdPwmGetKeyboardBacklight = 0x22 1145 1146 /* TYPE */ 1147 type ecResponsePwmGetKeyboardBacklight struct { 1148 percent uint8 1149 enabled uint8 1150 } 1151 1152 /* Set keyboard backlight */ 1153 const ecCmdPwmSetKeyboardBacklight = 0x23 1154 1155 /* TYPE */ 1156 type ecParamsPwmSetKeyboardBacklight struct { 1157 percent uint8 1158 } 1159 1160 /* Set target fan PWM duty cycle */ 1161 const ecCmdPwmSetFanDuty = 0x24 1162 1163 /* TYPE */ 1164 /* Version 0 of input params */ 1165 type ecParamsPwmSetFanDutyV0 struct { 1166 percent uint32 1167 } 1168 1169 /* TYPE */ 1170 /* Version 1 of input params */ 1171 type ecParamsPwmSetFanDutyV1 struct { 1172 percent uint32 1173 fanIdx uint8 1174 } 1175 1176 /*****************************************************************************/ 1177 /* 1178 * Lightbar commands. This looks worse than it is. Since we only use one HOST 1179 * command to say "talk to the lightbar", we put the "and tell it to do X" part 1180 * into a subcommand. We'll make separate structs for subcommands with 1181 * different input args, so that we know how much to expect. 1182 */ 1183 const ecCmdLightbarCmd = 0x28 1184 1185 /* TYPE */ 1186 type rgbS struct { 1187 r, g, b uint8 1188 } 1189 1190 const lbBatteryLevels = 4 1191 1192 /* TYPE */ 1193 /* List of tweakable parameters. NOTE: It's so it can be sent in a 1194 * host command, but the alignment is the same regardless. Keep it that way. 1195 */ 1196 type lightbarParamsV0 struct { 1197 /* Timing */ 1198 googleRampUp int32 1199 googleRampDown int32 1200 s3s0RampUp int32 1201 s0TickDelay [2]int32 /* AC=0/1 */ 1202 s0aTickDelay [2]int32 /* AC=0/1 */ 1203 s0s3RampDown int32 1204 s3SleepFor int32 1205 s3RampUp int32 1206 s3RampDown int32 1207 1208 /* Oscillation */ 1209 newS0 uint8 1210 oscMin [2]uint8 /* AC=0/1 */ 1211 oscMax [2]uint8 /* AC=0/1 */ 1212 wOfs [2]uint8 /* AC=0/1 */ 1213 1214 /* Brightness limits based on the backlight and AC. */ 1215 brightBlOffFixed [2]uint8 /* AC=0/1 */ 1216 brightBlOnMin [2]uint8 /* AC=0/1 */ 1217 brightBlOnMax [2]uint8 /* AC=0/1 */ 1218 1219 /* Battery level thresholds */ 1220 batteryhreshold [lbBatteryLevels - 1]uint8 1221 1222 /* Map [AC][batteryLevel] to color index */ 1223 s0Idx [2][lbBatteryLevels]uint8 /* AP is running */ 1224 s3Idx [2][lbBatteryLevels]uint8 /* AP is sleeping */ 1225 1226 /* Color palette */ 1227 color [8]rgbS /* 0-3 are Google colors */ 1228 } 1229 1230 /* TYPE */ 1231 type lightbarParamsV1 struct { 1232 /* Timing */ 1233 googleRampUp int32 1234 googleRampDown int32 1235 s3s0RampUp int32 1236 s0TickDelay [2]int32 /* AC=0/1 */ 1237 s0aTickDelay [2]int32 /* AC=0/1 */ 1238 s0s3RampDown int32 1239 s3SleepFor int32 1240 s3RampUp int32 1241 s3RampDown int32 1242 s5RampUp int32 1243 s5RampDown int32 1244 tapTickDelay int32 1245 tapGateDelay int32 1246 tapDisplayTime int32 1247 1248 /* Tap-for-battery params */ 1249 tapPctRed uint8 1250 tapPctGreen uint8 1251 tapSegMinOn uint8 1252 tapSegMaxOn uint8 1253 tapSegOsc uint8 1254 tapIdx [3]uint8 1255 1256 /* Oscillation */ 1257 oscMin [2]uint8 /* AC=0/1 */ 1258 oscMax [2]uint8 /* AC=0/1 */ 1259 wOfs [2]uint8 /* AC=0/1 */ 1260 1261 /* Brightness limits based on the backlight and AC. */ 1262 brightBlOffFixed [2]uint8 /* AC=0/1 */ 1263 brightBlOnMin [2]uint8 /* AC=0/1 */ 1264 brightBlOnMax [2]uint8 /* AC=0/1 */ 1265 1266 /* Battery level thresholds */ 1267 batteryhreshold [lbBatteryLevels - 1]uint8 1268 1269 /* Map [AC][batteryLevel] to color index */ 1270 s0Idx [2][lbBatteryLevels]uint8 /* AP is running */ 1271 s3Idx [2][lbBatteryLevels]uint8 /* AP is sleeping */ 1272 1273 /* s5: single color pulse on inhibited power-up */ 1274 s5Idx uint8 1275 1276 /* Color palette */ 1277 color [8]rgbS /* 0-3 are Google colors */ 1278 } 1279 1280 /* TYPE */ 1281 /* Lightbar command params v2 1282 * crbug.com/467716 1283 * 1284 * lightbarParmsV1 was too big for i2c, therefore in v2, we split them up by 1285 * logical groups to make it more manageable ( < 120 bytes). 1286 * 1287 * NOTE: Each of these groups must be less than 120 bytes. 1288 */ 1289 1290 type lightbarParamsV2Timing struct { 1291 /* Timing */ 1292 googleRampUp int32 1293 googleRampDown int32 1294 s3s0RampUp int32 1295 s0TickDelay [2]int32 /* AC=0/1 */ 1296 s0aTickDelay [2]int32 /* AC=0/1 */ 1297 s0s3RampDown int32 1298 s3SleepFor int32 1299 s3RampUp int32 1300 s3RampDown int32 1301 s5RampUp int32 1302 s5RampDown int32 1303 tapTickDelay int32 1304 tapGateDelay int32 1305 tapDisplayTime int32 1306 } 1307 1308 /* TYPE */ 1309 type lightbarParamsV2Tap struct { 1310 /* Tap-for-battery params */ 1311 tapPctRed uint8 1312 tapPctGreen uint8 1313 tapSegMinOn uint8 1314 tapSegMaxOn uint8 1315 tapSegOsc uint8 1316 tapIdx [3]uint8 1317 } 1318 1319 /* TYPE */ 1320 type lightbarParamsV2Oscillation struct { 1321 /* Oscillation */ 1322 oscMin [2]uint8 /* AC=0/1 */ 1323 oscMax [2]uint8 /* AC=0/1 */ 1324 wOfs [2]uint8 /* AC=0/1 */ 1325 } 1326 1327 /* TYPE */ 1328 type lightbarParamsV2Brightness struct { 1329 /* Brightness limits based on the backlight and AC. */ 1330 brightBlOffFixed [2]uint8 /* AC=0/1 */ 1331 brightBlOnMin [2]uint8 /* AC=0/1 */ 1332 brightBlOnMax [2]uint8 /* AC=0/1 */ 1333 } 1334 1335 /* TYPE */ 1336 type lightbarParamsV2Thresholds struct { 1337 /* Battery level thresholds */ 1338 batteryhreshold [lbBatteryLevels - 1]uint8 1339 } 1340 1341 /* TYPE */ 1342 type lightbarParamsV2Colors struct { 1343 /* Map [AC][batteryLevel] to color index */ 1344 s0Idx [2][lbBatteryLevels]uint8 /* AP is running */ 1345 s3Idx [2][lbBatteryLevels]uint8 /* AP is sleeping */ 1346 1347 /* s5: single color pulse on inhibited power-up */ 1348 s5Idx uint8 1349 1350 /* Color palette */ 1351 color [8]rgbS /* 0-3 are Google colors */ 1352 } 1353 1354 /* Lightbyte program. */ 1355 const ecLbProgLen = 192 1356 1357 /* TYPE */ 1358 type lightbarProgram struct { 1359 size uint8 1360 data [ecLbProgLen]uint8 1361 } 1362 1363 /* TYPE */ 1364 /* this one is messy 1365 type ecParamsLightbar struct { 1366 cmd uint8 /* Command (see enum lightbarCommand) 1367 union { 1368 struct { 1369 /* no args 1370 } dump, off, on, init, getSeq, getParamsV0, getParamsV1 1371 version, getBrightness, getDemo, suspend, resume 1372 getParamsV2Timing, getParamsV2Tap 1373 getParamsV2Osc, getParamsV2Bright 1374 getParamsV2Thlds, getParamsV2Colors; 1375 1376 struct { 1377 uint8 num; 1378 } setBrightness, seq, demo; 1379 1380 struct { 1381 uint8 ctrl, reg, value; 1382 } reg; 1383 1384 struct { 1385 uint8 led, red, green, blue; 1386 } setRgb; 1387 1388 struct { 1389 uint8 led; 1390 } getRgb; 1391 1392 struct { 1393 uint8 enable; 1394 } manualSuspendCtrl; 1395 1396 struct lightbarParamsV0 setParamsV0; 1397 struct lightbarParamsV1 setParamsV1; 1398 1399 struct lightbarParamsV2Timing setV2parTiming; 1400 struct lightbarParamsV2Tap setV2parTap; 1401 struct lightbarParamsV2Oscillation setV2parOsc; 1402 struct lightbarParamsV2Brightness setV2parBright; 1403 struct lightbarParamsV2Thresholds setV2parThlds; 1404 struct lightbarParamsV2Colors setV2parColors; 1405 1406 struct lightbarProgram setProgram; 1407 }; 1408 } ; 1409 */ 1410 /* TYPE */ 1411 /* 1412 type ecResponseLightbar struct { 1413 union { 1414 struct { 1415 struct { 1416 uint8 reg; 1417 uint8 ic0; 1418 uint8 ic1; 1419 } vals[23]; 1420 } dump; 1421 1422 struct { 1423 uint8 num; 1424 } getSeq, getBrightness, getDemo; 1425 1426 struct lightbarParamsV0 getParamsV0; 1427 struct lightbarParamsV1 getParamsV1; 1428 1429 1430 struct lightbarParamsV2Timing getParamsV2Timing; 1431 struct lightbarParamsV2Tap getParamsV2Tap; 1432 struct lightbarParamsV2Oscillation getParamsV2Osc; 1433 struct lightbarParamsV2Brightness getParamsV2Bright; 1434 struct lightbarParamsV2Thresholds getParamsV2Thlds; 1435 struct lightbarParamsV2Colors getParamsV2Colors; 1436 1437 struct { 1438 uint32 num; 1439 uint32 flags; 1440 } version; 1441 1442 struct { 1443 uint8 red, green, blue; 1444 } getRgb; 1445 1446 struct { 1447 /* no return params * 1448 } off, on, init, setBrightness, seq, reg, setRgb 1449 demo, setParamsV0, setParamsV1 1450 setProgram, manualSuspendCtrl, suspend, resume 1451 setV2parTiming, setV2parTap 1452 setV2parOsc, setV2parBright, setV2parThlds 1453 setV2parColors; 1454 }; 1455 } ; 1456 */ 1457 /* Lightbar commands */ 1458 type lightbarCommand uint8 1459 1460 const ( 1461 lightbarCmdDump lightbarCommand = 0 1462 lightbarCmdOff = 1 1463 lightbarCmdOn = 2 1464 lightbarCmdInit = 3 1465 lightbarCmdSetBrightness = 4 1466 lightbarCmdSeq = 5 1467 lightbarCmdReg = 6 1468 lightbarCmdSetRgb = 7 1469 lightbarCmdGetSeq = 8 1470 lightbarCmdDemo = 9 1471 lightbarCmdGetParamsV0 = 10 1472 lightbarCmdSetParamsV0 = 11 1473 lightbarCmdVersion = 12 1474 lightbarCmdGetBrightness = 13 1475 lightbarCmdGetRgb = 14 1476 lightbarCmdGetDemo = 15 1477 lightbarCmdGetParamsV1 = 16 1478 lightbarCmdSetParamsV1 = 17 1479 lightbarCmdSetProgram = 18 1480 lightbarCmdManualSuspendCtrl = 19 1481 lightbarCmdSuspend = 20 1482 lightbarCmdResume = 21 1483 lightbarCmdGetParamsV2Timing = 22 1484 lightbarCmdSetParamsV2Timing = 23 1485 lightbarCmdGetParamsV2Tap = 24 1486 lightbarCmdSetParamsV2Tap = 25 1487 lightbarCmdGetParamsV2Oscillation = 26 1488 lightbarCmdSetParamsV2Oscillation = 27 1489 lightbarCmdGetParamsV2Brightness = 28 1490 lightbarCmdSetParamsV2Brightness = 29 1491 lightbarCmdGetParamsV2Thresholds = 30 1492 lightbarCmdSetParamsV2Thresholds = 31 1493 lightbarCmdGetParamsV2Colors = 32 1494 lightbarCmdSetParamsV2Colors = 33 1495 lightbarNumCmds 1496 ) 1497 1498 /*****************************************************************************/ 1499 /* LED control commands */ 1500 1501 const ecCmdLedControl = 0x29 1502 1503 type ecLedID uint8 1504 1505 const ( 1506 /* LED to indicate battery state of charge */ 1507 ecLedIDBatteryLed ecLedID = 0 1508 /* 1509 * LED to indicate system power state (on or in suspend). 1510 * May be on power button or on C-panel. 1511 */ 1512 ecLedIDPowerLed 1513 /* LED on power adapter or its plug */ 1514 ecLedIDAdapterLed 1515 1516 ecLedIDCount 1517 ) 1518 const ( 1519 /* LED control flags */ 1520 ecLedFlagsQuery = (1 << iota) /* Query LED capability only */ 1521 ecLedFlagsAuto /* Switch LED back to automatic control */ 1522 ) 1523 1524 type ecLedColors uint8 1525 1526 const ( 1527 ecLedColorRed ecLedColors = 0 1528 ecLedColorGreen 1529 ecLedColorBlue 1530 ecLedColorYellow 1531 ecLedColorWhite 1532 1533 ecLedColorCount 1534 ) 1535 1536 /* TYPE */ 1537 type ecParamsLedControl struct { 1538 ledID uint8 /* Which LED to control */ 1539 flags uint8 /* Control flags */ 1540 1541 brightness [ecLedColorCount]uint8 1542 } 1543 1544 /* TYPE */ 1545 type ecResponseLedControl struct { 1546 /* 1547 * Available brightness value range. 1548 * 1549 * Range 0 means color channel not present. 1550 * Range 1 means on/off control. 1551 * Other values means the LED is control by PWM. 1552 */ 1553 brightnessRange [ecLedColorCount]uint8 1554 } 1555 1556 /*****************************************************************************/ 1557 /* Verified boot commands */ 1558 1559 /* 1560 * Note: command code 0x29 version 0 was VBOOTCmd in Link EVT; it may be 1561 * reused for other purposes with version > 0. 1562 */ 1563 1564 /* Verified boot hash command */ 1565 const ecCmdVbootHash = 0x2A 1566 1567 /* TYPE */ 1568 type ecParamsVbootHash struct { 1569 cmd uint8 /* enum ecVbootHashCmd */ 1570 hashype uint8 /* enum ecVbootHashType */ 1571 nonceSize uint8 /* Nonce size; may be 0 */ 1572 reserved0 uint8 /* Reserved; set 0 */ 1573 offset uint32 /* Offset in flash to hash */ 1574 size uint32 /* Number of bytes to hash */ 1575 nonceData [64]uint8 /* Nonce data; ignored if nonceSize=0 */ 1576 } 1577 1578 /* TYPE */ 1579 type ecResponseVbootHash struct { 1580 status uint8 /* enum ecVbootHashStatus */ 1581 hashype uint8 /* enum ecVbootHashType */ 1582 digestSize uint8 /* Size of hash digest in bytes */ 1583 reserved0 uint8 /* Ignore; will be 0 */ 1584 offset uint32 /* Offset in flash which was hashed */ 1585 size uint32 /* Number of bytes hashed */ 1586 hashDigest [64]uint8 /* Hash digest data */ 1587 } 1588 1589 type ecVbootHashCmd uint8 1590 1591 const ( 1592 ecVbootHashGet ecVbootHashCmd = 0 /* Get current hash status */ 1593 ecVbootHashAbort = 1 /* Abort calculating current hash */ 1594 ecVbootHashStart = 2 /* Start computing a new hash */ 1595 ecVbootHashRecalc = 3 /* Synchronously compute a new hash */ 1596 ) 1597 1598 type ecVbootHashType uint8 1599 1600 const ( 1601 ecVbootHashTypeSha256 ecVbootHashType = 0 /* SHA-256 */ 1602 ) 1603 1604 type ecVbootHashStatus uint8 1605 1606 const ( 1607 ecVbootHashStatusNone ecVbootHashStatus = 0 /* No hash (not started, or aborted) */ 1608 ecVbootHashStatusDone = 1 /* Finished computing a hash */ 1609 ecVbootHashStatusBusy = 2 /* Busy computing a hash */ 1610 ) 1611 1612 /* 1613 * Special values for offset for ecVbootHashStart and ecVbootHashRecalc. 1614 * If one of these is specified, the EC will automatically update offset and 1615 * size to the correct values for the specified image (RO or RW). 1616 */ 1617 const ecVbootHashOffsetRo = 0xfffffffe 1618 const ecVbootHashOffsetRw = 0xfffffffd 1619 1620 /*****************************************************************************/ 1621 /* 1622 * Motion sense commands. We'll make separate structs for sub-commands with 1623 * different input args, so that we know how much to expect. 1624 */ 1625 const ecCmdMotionSenseCmd = 0x2B 1626 1627 /* Motion sense commands */ 1628 type motionsenseCommand uint8 1629 1630 const ( 1631 /* Dump command returns all motion sensor data including motion sense 1632 * module flags and individual sensor flags. 1633 */ 1634 motionsenseCmdDump motionsenseCommand = iota 1635 1636 /* 1637 * Info command returns data describing the details of a given sensor 1638 * including enum motionsensorType, enum motionsensorLocation, and 1639 * enum motionsensorChip. 1640 */ 1641 motionsenseCmdInfo 1642 1643 /* 1644 * EC Rate command is a setter/getter command for the EC sampling rate 1645 * of all motion sensors in milliseconds. 1646 */ 1647 motionsenseCmdEcRate 1648 1649 /* 1650 * Sensor ODR command is a setter/getter command for the output data 1651 * rate of a specific motion sensor in millihertz. 1652 */ 1653 motionsenseCmdSensorOdr 1654 1655 /* 1656 * Sensor range command is a setter/getter command for the range of 1657 * a specified motion sensor in +/-G's or +/- deg/s. 1658 */ 1659 motionsenseCmdSensorRange 1660 1661 /* 1662 * Setter/getter command for the keyboard wake angle. When the lid 1663 * angle is greater than this value, keyboard wake is disabled in S3 1664 * and when the lid angle goes less than this value, keyboard wake is 1665 * enabled. Note, the lid angle measurement is an approximate 1666 * un-calibrated value, hence the wake angle isn't exact. 1667 */ 1668 motionsenseCmdKbWakeAngle 1669 1670 /* Number of motionsense sub-commands. */ 1671 motionsenseNumCmds 1672 ) 1673 1674 /* List of motion sensor types. */ 1675 type motionsensorType uint8 1676 1677 const ( 1678 motionsenseTypeAccel motionsensorType = 0 1679 motionsenseTypeGyro = 1 1680 ) 1681 1682 /* List of motion sensor locations. */ 1683 type motionsensorLocation uint8 1684 1685 const ( 1686 motionsenseLocBase motionsensorLocation = 0 1687 motionsenseLocLid = 1 1688 ) 1689 1690 /* List of motion sensor chips. */ 1691 type motionsensorChip uint8 1692 1693 const ( 1694 motionsenseChipKxcj9 motionsensorChip = 0 1695 motionsenseChipLsm6ds0 = 1 1696 ) 1697 1698 /* Module flag masks used for the dump sub-command. */ 1699 const motionsenseModuleFlagActive = (1 << 0) 1700 1701 /* Sensor flag masks used for the dump sub-command. */ 1702 const motionsenseSensorFlagPresent = (1 << 0) 1703 1704 /* 1705 * Send this value for the data element to only perform a read. If you 1706 * send any other value, the EC will interpret it as data to set and will 1707 * return the actual value set. 1708 */ 1709 const ecMotionSenseNoValue = -1 1710 1711 /* some other time 1712 type ecParamsMotionSense struct { 1713 cmd uint8 1714 union { 1715 /* Used for MOTIONSENSECmdDump * / 1716 struct { 1717 /* 1718 * Maximal number of sensor the host is expecting. 1719 * 0 means the host is only interested in the number 1720 * of sensors controlled by the EC. 1721 * / 1722 uint8 maxSensorCount; 1723 } dump; 1724 1725 /* 1726 * Used for MOTIONSENSECmdEcRate and 1727 * MOTIONSENSECmdKbWakeAngle. 1728 * / 1729 struct { 1730 /* Data to set or ecMotionSenseNoValue to read. * / 1731 data int16 1732 } ecRate, kbWakeAngle; 1733 1734 /* Used for MOTIONSENSECmdInfo. * / 1735 struct { 1736 uint8 sensorNum; 1737 } info; 1738 1739 /* 1740 * Used for MOTIONSENSECmdSensorOdr and 1741 * MOTIONSENSECmdSensorRange. 1742 * / 1743 struct { 1744 uint8 sensorNum; 1745 1746 /* Rounding flag, true for round-up, false for down. * / 1747 uint8 roundup; 1748 1749 uint16 reserved; 1750 1751 /* Data to set or ecMotionSenseNoValue to read. * / 1752 data int32 1753 } sensorOdr, sensorRange; 1754 }; 1755 } ; 1756 */ 1757 /* TYPE */ 1758 type ecResponseMotionSensorData struct { 1759 /* Flags for each sensor. */ 1760 flags uint8 1761 padding uint8 1762 1763 /* Each sensor is up to 3-axis. */ 1764 data [3]int16 1765 } 1766 1767 /* TYPE */ 1768 /* some other time 1769 1770 type ecResponseMotionSense struct { 1771 union { 1772 /* Used for MOTIONSENSECmdDump * / 1773 struct { 1774 /* Flags representing the motion sensor module. * / 1775 uint8 moduleFlags; 1776 1777 /* Number of sensors managed directly by the EC * / 1778 uint8 sensorCount; 1779 1780 /* 1781 * sensor data is truncated if responseMax is too small 1782 * for holding all the data. 1783 * / 1784 struct ecResponseMotionSensorData sensor[0]; 1785 } dump; 1786 1787 /* Used for MOTIONSENSECmdInfo. * / 1788 struct { 1789 /* Should be element of enum motionsensorType. * / 1790 uint8 type; 1791 1792 /* Should be element of enum motionsensorLocation. * / 1793 uint8 location; 1794 1795 /* Should be element of enum motionsensorChip. * / 1796 uint8 chip; 1797 } info; 1798 1799 /* 1800 * Used for MOTIONSENSECmdEcRate, MOTIONSENSECmdSensorOdr 1801 * MOTIONSENSECmdSensorRange, and 1802 * MOTIONSENSECmdKbWakeAngle. 1803 * / 1804 struct { 1805 /* Current value of the parameter queried. * / 1806 ret int32 1807 } ecRate, sensorOdr, sensorRange, kbWakeAngle; 1808 }; 1809 } ; 1810 */ 1811 /*****************************************************************************/ 1812 /* Force lid open command */ 1813 1814 /* Make lid event always open */ 1815 const ecCmdForceLidOpen = 0x2c 1816 1817 /* TYPE */ 1818 type ecParamsForceLidOpen struct { 1819 enabled uint8 1820 } 1821 1822 /*****************************************************************************/ 1823 /* USB charging control commands */ 1824 1825 /* Set USB port charging mode */ 1826 const ecCmdUsbChargeSetMode = 0x30 1827 1828 /* TYPE */ 1829 type ecParamsUsbChargeSetMode struct { 1830 usbPortID uint8 1831 mode uint8 1832 } 1833 1834 /*****************************************************************************/ 1835 /* Persistent storage for host */ 1836 1837 /* Maximum bytes that can be read/written in a single command */ 1838 const ecPstoreSizeMax = 64 1839 1840 /* Get persistent storage info */ 1841 const ecCmdPstoreInfo = 0x40 1842 1843 /* TYPE */ 1844 type ecResponsePstoreInfo struct { 1845 /* Persistent storage size, in bytes */ 1846 pstoreSize uint32 1847 /* Access size; read/write offset and size must be a multiple of this */ 1848 accessSize uint32 1849 } 1850 1851 /* 1852 * Read persistent storage 1853 * 1854 * Response is params.size bytes of data. 1855 */ 1856 const ecCmdPstoreRead = 0x41 1857 1858 /* TYPE */ 1859 type ecParamsPstoreRead struct { 1860 offset uint32 /* Byte offset to read */ 1861 size uint32 /* Size to read in bytes */ 1862 } 1863 1864 /* Write persistent storage */ 1865 const ecCmdPstoreWrite = 0x42 1866 1867 /* TYPE */ 1868 type ecParamsPstoreWrite struct { 1869 offset uint32 /* Byte offset to write */ 1870 size uint32 /* Size to write in bytes */ 1871 data [ecPstoreSizeMax]uint8 1872 } 1873 1874 /* TYPE */ 1875 /*****************************************************************************/ 1876 /* Real-time clock */ 1877 1878 /* RTC params and response structures */ 1879 type ecParamsRtc struct { 1880 time uint32 1881 } 1882 1883 /* TYPE */ 1884 type ecResponseRtc struct { 1885 time uint32 1886 } 1887 1888 /* These use ecResponseRtc */ 1889 const ecCmdRtcGetValue = 0x44 1890 const ecCmdRtcGetAlarm = 0x45 1891 1892 /* These all use ecParamsRtc */ 1893 const ecCmdRtcSetValue = 0x46 1894 const ecCmdRtcSetAlarm = 0x47 1895 1896 /*****************************************************************************/ 1897 /* Port80 log access */ 1898 1899 /* Maximum entries that can be read/written in a single command */ 1900 const ecPort80SizeMax = 32 1901 1902 /* Get last port80 code from previous boot */ 1903 const ecCmdPort80LastBoot = 0x48 1904 const ecCmdPort80Read = 0x48 1905 1906 type ecPort80Subcmd uint8 1907 1908 const ( 1909 ecPort80GetInfo ecPort80Subcmd = 0 1910 ecPort80ReadBuffer 1911 ) 1912 1913 /* TYPE */ 1914 type ecParamsPort80Read struct { 1915 subcmd uint16 1916 offset uint32 1917 numEntries uint32 1918 } 1919 1920 /* TYPE */ 1921 type ecResponsePort80Read struct { 1922 /* 1923 struct { 1924 uint32 writes; 1925 uint32 historySize; 1926 uint32 lastBoot; 1927 } getInfo;*/ 1928 1929 codes [ecPort80SizeMax]uint16 1930 } 1931 1932 /* TYPE */ 1933 type ecResponsePort80LastBoot struct { 1934 code uint16 1935 } 1936 1937 /*****************************************************************************/ 1938 /* Thermal engine commands. Note that there are two implementations. We'll 1939 * reuse the command number, but the data and behavior is incompatible. 1940 * Version 0 is what originally shipped on Link. 1941 * Version 1 separates the CPU thermal limits from the fan control. 1942 */ 1943 1944 const ecCmdThermalSetThreshold = 0x50 1945 const ecCmdThermalGetThreshold = 0x51 1946 1947 /* TYPE */ 1948 /* The version 0 structs are opaque. You have to know what they are for 1949 * the get/set commands to make any sense. 1950 */ 1951 1952 /* Version 0 - set */ 1953 type ecParamsThermalSetThreshold struct { 1954 sensorype uint8 1955 thresholdID uint8 1956 value uint16 1957 } 1958 1959 /* TYPE */ 1960 /* Version 0 - get */ 1961 type ecParamsThermalGetThreshold struct { 1962 sensorype uint8 1963 thresholdID uint8 1964 } 1965 1966 /* TYPE */ 1967 type ecResponseThermalGetThreshold struct { 1968 value uint16 1969 } 1970 1971 /* The version 1 structs are visible. */ 1972 type ecTempThresholds uint8 1973 1974 const ( 1975 ecTempThreshWarn ecTempThresholds = 0 1976 ecTempThreshHigh 1977 ecTempThreshHalt 1978 1979 ecTempThreshCount 1980 ) 1981 1982 /* TYPE */ 1983 /* Thermal configuration for one temperature sensor. Temps are in degrees K. 1984 * Zero values will be silently ignored by the thermal task. 1985 */ 1986 type ecThermalConfig struct { 1987 tempHost [ecTempThreshCount]uint32 /* levels of hotness */ 1988 tempFanOff uint32 /* no active cooling needed */ 1989 tempFanMax uint32 /* max active cooling needed */ 1990 } 1991 1992 /* TYPE */ 1993 /* Version 1 - get config for one sensor. */ 1994 type ecParamsThermalGetThresholdV1 struct { 1995 sensorNum uint32 1996 } 1997 1998 /* TYPE */ 1999 /* This returns a struct ecThermalConfig */ 2000 2001 /* Version 1 - set config for one sensor. 2002 * Use read-modify-write for best results! */ 2003 type ecParamsThermalSetThresholdV1 struct { 2004 sensorNum uint32 2005 cfg ecThermalConfig 2006 } 2007 2008 /* This returns no data */ 2009 2010 /****************************************************************************/ 2011 2012 /* Toggle automatic fan control */ 2013 const ecCmdThermalAutoFanCtrl = 0x52 2014 2015 /* TYPE */ 2016 /* Version 1 of input params */ 2017 type ecParamsAutoFanCtrlV1 struct { 2018 fanIdx uint8 2019 } 2020 2021 /* Get/Set TMP006 calibration data */ 2022 const ecCmdTmp006GetCalibration = 0x53 2023 const ecCmdTmp006SetCalibration = 0x54 2024 2025 /* TYPE */ 2026 /* 2027 * The original TMP006 calibration only needed four params, but now we need 2028 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave 2029 * the params opaque. The v1 "get" response will include the algorithm number 2030 * and how many params it requires. That way we can change the EC code without 2031 * needing to update this file. We can also use a different algorithm on each 2032 * sensor. 2033 */ 2034 2035 /* This is the same struct for both v0 and v1. */ 2036 type ecParamsTmp006GetCalibration struct { 2037 index uint8 2038 } 2039 2040 /* TYPE */ 2041 /* Version 0 */ 2042 type ecResponseTmp006GetCalibrationV0 struct { 2043 s0, b0, b1, bw float32 2044 } 2045 2046 /* TYPE */ 2047 type ecParamsTmp006SetCalibrationV0 struct { 2048 index uint8 2049 reserved [3]uint8 2050 s0, b0, b1, b2 float32 2051 } 2052 2053 /* TYPE */ 2054 /* Version 1 */ 2055 type ecResponseTmp006GetCalibrationV1 struct { 2056 algorithm uint8 2057 numParams uint8 2058 reserved [2]uint8 2059 val []float32 2060 } 2061 2062 /* TYPE */ 2063 type ecParamsTmp006SetCalibrationV1 struct { 2064 index uint8 2065 algorithm uint8 2066 numParams uint8 2067 reserved uint8 2068 val []float32 2069 } 2070 2071 /* Read raw TMP006 data */ 2072 const ecCmdTmp006GetRaw = 0x55 2073 2074 /* TYPE */ 2075 type ecParamsTmp006GetRaw struct { 2076 index uint8 2077 } 2078 2079 /* TYPE */ 2080 type ecResponseTmp006GetRaw struct { 2081 t int32 /* In 1/100 K */ 2082 v int32 /* In nV */ 2083 } 2084 2085 /*****************************************************************************/ 2086 /* MKBP - Matrix KeyBoard Protocol */ 2087 2088 /* 2089 * Read key state 2090 * 2091 * Returns raw data for keyboard cols; see ecResponseMkbpInfo.cols for 2092 * expected response size. 2093 */ 2094 const ecCmdMkbpState = 0x60 2095 2096 /* Provide information about the matrix : number of rows and columns */ 2097 const ecCmdMkbpInfo = 0x61 2098 2099 /* TYPE */ 2100 type ecResponseMkbpInfo struct { 2101 rows uint32 2102 cols uint32 2103 switches uint8 2104 } 2105 2106 /* Simulate key press */ 2107 const ecCmdMkbpSimulateKey = 0x62 2108 2109 /* TYPE */ 2110 type ecParamsMkbpSimulateKey struct { 2111 col uint8 2112 row uint8 2113 pressed uint8 2114 } 2115 2116 /* Configure keyboard scanning */ 2117 const ecCmdMkbpSetConfig = 0x64 2118 const ecCmdMkbpGetConfig = 0x65 2119 2120 /* flags */ 2121 type mkbpConfigFlags uint8 2122 2123 const ( 2124 ecMkbpFlagsEnable mkbpConfigFlags = 1 /* Enable keyboard scanning */ 2125 ) 2126 2127 type mkbpConfigValid uint8 2128 2129 const ( 2130 ecMkbpValidScanPeriod mkbpConfigValid = 1 << 0 2131 ecMkbpValidPollTimeout = 1 << 1 2132 ecMkbpValidMinPostScanDelay = 1 << 3 2133 ecMkbpValidOutputSettle = 1 << 4 2134 ecMkbpValidDebounceDown = 1 << 5 2135 ecMkbpValidDebounceUp = 1 << 6 2136 ecMkbpValidFifoMaxDepth = 1 << 7 2137 ) 2138 2139 /* TYPE */ 2140 /* Configuration for our key scanning algorithm */ 2141 type ecMkbpConfig struct { 2142 validMask uint32 /* valid fields */ 2143 flags uint8 /* some flags (enum mkbpConfigFlags) */ 2144 validFlags uint8 /* which flags are valid */ 2145 scanPeriodUs uint16 /* period between start of scans */ 2146 /* revert to interrupt mode after no activity for this long */ 2147 pollimeoutUs uint32 2148 /* 2149 * minimum post-scan relax time. Once we finish a scan we check 2150 * the time until we are due to start the next one. If this time is 2151 * shorter this field, we use this instead. 2152 */ 2153 minPostScanDelayUs uint16 2154 /* delay between setting up output and waiting for it to settle */ 2155 outputSettleUs uint16 2156 debounceDownUs uint16 /* time for debounce on key down */ 2157 debounceUpUs uint16 /* time for debounce on key up */ 2158 /* maximum depth to allow for fifo (0 = no keyscan output) */ 2159 fifoMaxDepth uint8 2160 } 2161 2162 /* TYPE */ 2163 type ecParamsMkbpSetConfig struct { 2164 config ecMkbpConfig 2165 } 2166 2167 /* TYPE */ 2168 type ecResponseMkbpGetConfig struct { 2169 config ecMkbpConfig 2170 } 2171 2172 /* Run the key scan emulation */ 2173 const ecCmdKeyscanSeqCtrl = 0x66 2174 2175 type ecKeyscanSeqCmd uint8 2176 2177 const ( 2178 ecKeyscanSeqStatus ecKeyscanSeqCmd = 0 /* Get status information */ 2179 ecKeyscanSeqClear = 1 /* Clear sequence */ 2180 ecKeyscanSeqAdd = 2 /* Add item to sequence */ 2181 ecKeyscanSeqStart = 3 /* Start running sequence */ 2182 ecKeyscanSeqCollect = 4 /* Collect sequence summary data */ 2183 ) 2184 2185 type ecCollectFlags uint8 2186 2187 const ( 2188 /* Indicates this scan was processed by the EC. Due to timing, some 2189 * scans may be skipped. 2190 */ 2191 ecKeyscanSeqFlagDone ecCollectFlags = 1 << iota 2192 ) 2193 2194 /* TYPE */ 2195 type ecCollectItem struct { 2196 flags uint8 /* some flags (enum ecCollectFlags) */ 2197 } 2198 2199 /* TYPE */ 2200 /* later 2201 type ecParamsKeyscanSeqCtrl struct { 2202 cmd uint8 /* Command to send (enum ecKeyscanSeqCmd) * / 2203 union { 2204 struct { 2205 uint8 active; /* still active * / 2206 uint8 numItems; /* number of items * / 2207 /* Current item being presented * / 2208 uint8 curItem; 2209 } status; 2210 struct { 2211 /* 2212 * Absolute time for this scan, measured from the 2213 * start of the sequence. 2214 * / 2215 uint32 timeUs; 2216 uint8 scan[0]; /* keyscan data * / 2217 } add; 2218 struct { 2219 uint8 startItem; /* First item to return * / 2220 uint8 numItems; /* Number of items to return * / 2221 } collect; 2222 }; 2223 } ; 2224 */ 2225 /* TYPE */ 2226 /* lter 2227 type ecResultKeyscanSeqCtrl struct { 2228 union { 2229 struct { 2230 uint8 numItems; /* Number of items * 2231 /* Data for each item * 2232 struct ecCollectItem item[0] 2233 } collect; 2234 }; 2235 } ; 2236 */ 2237 /* 2238 * Get the next pending MKBP event. 2239 * 2240 * Returns ecResUnavailable if there is no event pending. 2241 */ 2242 const ecCmdGetNextEvent = 0x67 2243 2244 type ecMkbpEvent uint8 2245 2246 const ( 2247 /* Keyboard matrix changed. The event data is the new matrix state. */ 2248 ecMkbpEventKeyMatrix = iota 2249 2250 /* New host event. The event data is 4 bytes of host event flags. */ 2251 ecMkbpEventHostEvent 2252 2253 /* Number of MKBP events */ 2254 ecMkbpEventCount 2255 ) 2256 2257 /* TYPE */ 2258 type ecResponseGetNextEvent struct { 2259 eventype uint8 2260 /* Followed by event data if any */ 2261 } 2262 2263 /*****************************************************************************/ 2264 /* Temperature sensor commands */ 2265 2266 /* Read temperature sensor info */ 2267 const ecCmdTempSensorGetInfo = 0x70 2268 2269 /* TYPE */ 2270 type ecParamsTempSensorGetInfo struct { 2271 id uint8 2272 } 2273 2274 /* TYPE */ 2275 type ecResponseTempSensorGetInfo struct { 2276 sensorName [32]byte 2277 sensorype uint8 2278 } 2279 2280 /* TYPE */ 2281 /*****************************************************************************/ 2282 2283 /* 2284 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI 2285 * commands accidentally sent to the wrong interface. See the ACPI section 2286 * below. 2287 */ 2288 2289 /*****************************************************************************/ 2290 /* Host event commands */ 2291 2292 /* 2293 * Host event mask params and response structures, shared by all of the host 2294 * event commands below. 2295 */ 2296 type ecParamsHostEventMask struct { 2297 mask uint32 2298 } 2299 2300 /* TYPE */ 2301 type ecResponseHostEventMask struct { 2302 mask uint32 2303 } 2304 2305 /* These all use ecResponseHostEventMask */ 2306 const ecCmdHostEventGetB = 0x87 2307 const ecCmdHostEventGetSmiMask = 0x88 2308 const ecCmdHostEventGetSciMask = 0x89 2309 const ecCmdHostEventGetWakeMask = 0x8d 2310 2311 /* These all use ecParamsHostEventMask */ 2312 const ecCmdHostEventSetSmiMask = 0x8a 2313 const ecCmdHostEventSetSciMask = 0x8b 2314 const ecCmdHostEventClear = 0x8c 2315 const ecCmdHostEventSetWakeMask = 0x8e 2316 const ecCmdHostEventClearB = 0x8f 2317 2318 /*****************************************************************************/ 2319 /* Switch commands */ 2320 2321 /* Enable/disable LCD backlight */ 2322 const ecCmdSwitchEnableBklight = 0x90 2323 2324 /* TYPE */ 2325 type ecParamsSwitchEnableBacklight struct { 2326 enabled uint8 2327 } 2328 2329 /* Enable/disable WLAN/Bluetooth */ 2330 const ecCmdSwitchEnableWireless = 0x91 2331 const ecVerSwitchEnableWireless = 1 2332 2333 /* TYPE */ 2334 /* Version 0 params; no response */ 2335 type ecParamsSwitchEnableWirelessV0 struct { 2336 enabled uint8 2337 } 2338 2339 /* TYPE */ 2340 /* Version 1 params */ 2341 type ecParamsSwitchEnableWirelessV1 struct { 2342 /* Flags to enable now */ 2343 nowFlags uint8 2344 2345 /* Which flags to copy from nowFlags */ 2346 nowMask uint8 2347 2348 /* 2349 * Flags to leave enabled in S3, if they're on at the S0->S3 2350 * transition. (Other flags will be disabled by the S0->S3 2351 * transition.) 2352 */ 2353 suspendFlags uint8 2354 2355 /* Which flags to copy from suspendFlags */ 2356 suspendMask uint8 2357 } 2358 2359 /* TYPE */ 2360 /* Version 1 response */ 2361 type ecResponseSwitchEnableWirelessV1 struct { 2362 /* Flags to enable now */ 2363 nowFlags uint8 2364 2365 /* Flags to leave enabled in S3 */ 2366 suspendFlags uint8 2367 } 2368 2369 /*****************************************************************************/ 2370 /* GPIO commands. Only available on EC if write protect has been disabled. */ 2371 2372 /* Set GPIO output value */ 2373 const ecCmdGpioSet = 0x92 2374 2375 /* TYPE */ 2376 type ecParamsGpioSet struct { 2377 name [32]byte 2378 val uint8 2379 } 2380 2381 /* Get GPIO value */ 2382 const ecCmdGpioGet = 0x93 2383 2384 /* TYPE */ 2385 /* Version 0 of input params and response */ 2386 type ecParamsGpioGet struct { 2387 name [32]byte 2388 } 2389 2390 /* TYPE */ 2391 type ecResponseGpioGet struct { 2392 val uint8 2393 } 2394 2395 /* TYPE */ 2396 /* Version 1 of input params and response */ 2397 type ecParamsGpioGetV1 struct { 2398 subcmd uint8 2399 data [32]byte 2400 } 2401 2402 /* TYPE */ 2403 /* later 2404 type ecResponseGpioGetV1 struct { 2405 union { 2406 struct { 2407 uint8 val; 2408 } getValueByName, getCount; 2409 struct { 2410 uint8 val; 2411 char name[32]; 2412 uint32 flags; 2413 } getInfo; 2414 }; 2415 } ; 2416 */ 2417 type gpioGetSubcmd uint8 2418 2419 const ( 2420 ecGpioGetByName gpioGetSubcmd = 0 2421 ecGpioGetCount = 1 2422 ecGpioGetInfo = 2 2423 ) 2424 2425 /*****************************************************************************/ 2426 /* I2C commands. Only available when flash write protect is unlocked. */ 2427 2428 /* 2429 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be 2430 * removed soon. Use ecCmdI2cXfer instead. 2431 */ 2432 2433 /* Read I2C bus */ 2434 const ecCmdI2cRead = 0x94 2435 2436 /* TYPE */ 2437 type ecParamsI2cRead struct { 2438 addr uint16 /* 8-bit address (7-bit shifted << 1) */ 2439 readSize uint8 /* Either 8 or 16. */ 2440 port uint8 2441 offset uint8 2442 } 2443 2444 /* TYPE */ 2445 type ecResponseI2cRead struct { 2446 data uint16 2447 } 2448 2449 /* Write I2C bus */ 2450 const ecCmdI2cWrite = 0x95 2451 2452 /* TYPE */ 2453 type ecParamsI2cWrite struct { 2454 data uint16 2455 addr uint16 /* 8-bit address (7-bit shifted << 1) */ 2456 writeSize uint8 /* Either 8 or 16. */ 2457 port uint8 2458 offset uint8 2459 } 2460 2461 /*****************************************************************************/ 2462 /* Charge state commands. Only available when flash write protect unlocked. */ 2463 2464 /* Force charge state machine to stop charging the battery or force it to 2465 * discharge the battery. 2466 */ 2467 const ecCmdChargeControl = 0x96 2468 const ecVerChargeControl = 1 2469 2470 type ecChargeControlMode uint8 2471 2472 const ( 2473 chargeControlNormal ecChargeControlMode = 0 2474 chargeControlIdle 2475 chargeControlDischarge 2476 ) 2477 2478 /* TYPE */ 2479 type ecParamsChargeControl struct { 2480 mode uint32 /* enum chargeControlMode */ 2481 } 2482 2483 /*****************************************************************************/ 2484 /* Console commands. Only available when flash write protect is unlocked. */ 2485 2486 /* Snapshot console output buffer for use by ecCmdConsoleRead. */ 2487 const ecCmdConsoleSnapshot = 0x97 2488 2489 /* 2490 * Read next chunk of data from saved snapshot. 2491 * 2492 * Response is null-terminated string. Empty string, if there is no more 2493 * remaining output. 2494 */ 2495 const ecCmdConsoleRead = 0x98 2496 2497 /*****************************************************************************/ 2498 2499 /* 2500 * Cut off battery power immediately or after the host has shut down. 2501 * 2502 * return ecResInvalidCommand if unsupported by a board/battery. 2503 * ecResSuccess if the command was successful. 2504 * ecResError if the cut off command failed. 2505 */ 2506 const ecCmdBatteryCutOff = 0x99 2507 2508 const ecBatteryCutoffFlagAtShutdown = (1 << 0) 2509 2510 /* TYPE */ 2511 type ecParamsBatteryCutoff struct { 2512 flags uint8 2513 } 2514 2515 /*****************************************************************************/ 2516 /* USB port mux control. */ 2517 2518 /* 2519 * Switch USB mux or return to automatic switching. 2520 */ 2521 const ecCmdUsbMux = 0x9a 2522 2523 /* TYPE */ 2524 type ecParamsUsbMux struct { 2525 mux uint8 2526 } 2527 2528 /*****************************************************************************/ 2529 /* LDOs / FETs control. */ 2530 2531 type ecLdoState uint8 2532 2533 const ( 2534 ecLdoStateOff ecLdoState = 0 /* the LDO / FET is shut down */ 2535 ecLdoStateOn = 1 /* the LDO / FET is ON / providing power */ 2536 ) 2537 2538 /* 2539 * Switch on/off a LDO. 2540 */ 2541 const ecCmdLdoSet = 0x9b 2542 2543 /* TYPE */ 2544 type ecParamsLdoSet struct { 2545 index uint8 2546 state uint8 2547 } 2548 2549 /* 2550 * Get LDO state. 2551 */ 2552 const ecCmdLdoGet = 0x9c 2553 2554 /* TYPE */ 2555 type ecParamsLdoGet struct { 2556 index uint8 2557 } 2558 2559 /* TYPE */ 2560 type ecResponseLdoGet struct { 2561 state uint8 2562 } 2563 2564 /*****************************************************************************/ 2565 /* Power info. */ 2566 2567 /* 2568 * Get power info. 2569 */ 2570 const ecCmdPowerInfo = 0x9d 2571 2572 /* TYPE */ 2573 type ecResponsePowerInfo struct { 2574 usbDevype uint32 2575 voltageAc uint16 2576 voltageSystem uint16 2577 currentSystem uint16 2578 usbCurrentLimit uint16 2579 } 2580 2581 /*****************************************************************************/ 2582 /* I2C passthru command */ 2583 2584 const ecCmdI2cPassthru = 0x9e 2585 2586 /* Read data; if not present, message is a write */ 2587 const ecI2cFlagRead = (1 << 15) 2588 2589 /* Mask for address */ 2590 const ecI2cAddrMask = 0x3ff 2591 2592 const ecI2cStatusNak = (1 << 0) /* Transfer was not acknowledged */ 2593 const ecI2cStatusTimeout = (1 << 1) /* Timeout during transfer */ 2594 2595 /* Any error */ 2596 const ecI2cStatusError = (ecI2cStatusNak | ecI2cStatusTimeout) 2597 2598 /* TYPE */ 2599 type ecParamsI2cPassthruMsg struct { 2600 addrFlags uint16 /* I2C slave address (7 or 10 bits) and flags */ 2601 len uint16 /* Number of bytes to read or write */ 2602 } 2603 2604 /* TYPE */ 2605 type ecParamsI2cPassthru struct { 2606 port uint8 /* I2C port number */ 2607 numMsgs uint8 /* Number of messages */ 2608 msg []ecParamsI2cPassthruMsg 2609 /* Data to write for all messages is concatenated here */ 2610 } 2611 2612 /* TYPE */ 2613 type ecResponseI2cPassthru struct { 2614 i2cStatus uint8 /* Status flags (ecI2cStatus_...) */ 2615 numMsgs uint8 /* Number of messages processed */ 2616 data []uint8 /* Data read by messages concatenated here */ 2617 } 2618 2619 /*****************************************************************************/ 2620 /* Power button hang detect */ 2621 2622 const ecCmdHangDetect = 0x9f 2623 2624 /* Reasons to start hang detection timer */ 2625 /* Power button pressed */ 2626 const ecHangStartOnPowerPress = (1 << 0) 2627 2628 /* Lid closed */ 2629 const ecHangStartOnLidClose = (1 << 1) 2630 2631 /* Lid opened */ 2632 const ecHangStartOnLidOpen = (1 << 2) 2633 2634 /* Start of AP S3->S0 transition (booting or resuming from suspend) */ 2635 const ecHangStartOnResume = (1 << 3) 2636 2637 /* Reasons to cancel hang detection */ 2638 2639 /* Power button released */ 2640 const ecHangStopOnPowerRelease = (1 << 8) 2641 2642 /* Any host command from AP received */ 2643 const ecHangStopOnHostCommand = (1 << 9) 2644 2645 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ 2646 const ecHangStopOnSuspend = (1 << 10) 2647 2648 /* 2649 * If this flag is set, all the other fields are ignored, and the hang detect 2650 * timer is started. This provides the AP a way to start the hang timer 2651 * without reconfiguring any of the other hang detect settings. Note that 2652 * you must previously have configured the timeouts. 2653 */ 2654 const ecHangStartNow = (1 << 30) 2655 2656 /* 2657 * If this flag is set, all the other fields are ignored (including 2658 * ecHangStartNow). This provides the AP a way to stop the hang timer 2659 * without reconfiguring any of the other hang detect settings. 2660 */ 2661 const ecHangStopNow = (1 << 31) 2662 2663 /* TYPE */ 2664 type ecParamsHangDetect struct { 2665 /* Flags; see ecHang_* */ 2666 flags uint32 2667 2668 /* Timeout in msec before generating host event, if enabled */ 2669 hostEventimeoutMsec uint16 2670 2671 /* Timeout in msec before generating warm reboot, if enabled */ 2672 warmRebootimeoutMsec uint16 2673 } 2674 2675 /*****************************************************************************/ 2676 /* Commands for battery charging */ 2677 2678 /* 2679 * This is the single catch-all host command to exchange data regarding the 2680 * charge state machine (v2 and up). 2681 */ 2682 const ecCmdChargeState = 0xa0 2683 2684 /* Subcommands for this host command */ 2685 type chargeStateCommand uint8 2686 2687 const ( 2688 chargeStateCmdGetState chargeStateCommand = iota 2689 chargeStateCmdGetParam 2690 chargeStateCmdSetParam 2691 chargeStateNumCmds 2692 ) 2693 2694 /* 2695 * Known param numbers are defined here. Ranges are reserved for board-specific 2696 * params, which are handled by the particular implementations. 2697 */ 2698 type chargeStateParams uint8 2699 2700 const ( 2701 csParamChgVoltage chargeStateParams = iota /* charger voltage limit */ 2702 csParamChgCurrent /* charger current limit */ 2703 csParamChgInputCurrent /* charger input current limit */ 2704 csParamChgStatus /* charger-specific status */ 2705 csParamChgOption /* charger-specific options */ 2706 /* How many so far? */ 2707 csNumBaseParams 2708 2709 /* Range for CONFIGChargerProfileOverride params */ 2710 csParamCustomProfileMin = 0x10000 2711 csParamCustomProfileMax = 0x1ffff 2712 2713 /* Other custom param ranges go here... */ 2714 ) 2715 2716 /* TYPE */ 2717 /* ler 2718 type ecParamsChargeState struct { 2719 cmd uint8 /* enum chargeStateCommand * / 2720 union { 2721 struct { 2722 /* no args * / 2723 } getState; 2724 2725 struct { 2726 uint32 param; /* enum chargeStateParam * / 2727 } getParam; 2728 2729 struct { 2730 uint32 param; /* param to set * / 2731 uint32 value; /* value to set * / 2732 } setParam; 2733 }; 2734 } ; 2735 2736 /* TYPE */ 2737 /* later 2738 type ecResponseChargeState struct { 2739 union { 2740 struct { 2741 int ac; 2742 int chgVoltage; 2743 int chgCurrent; 2744 int chgInputCurrent; 2745 int battStateOfCharge; 2746 } getState; 2747 2748 struct { 2749 uint32 value; 2750 } getParam; 2751 struct { 2752 /* no return values * 2753 } setParam; 2754 }; 2755 } ; 2756 */ 2757 2758 /* 2759 * Set maximum battery charging current. 2760 */ 2761 const ecCmdChargeCurrentLimit = 0xa1 2762 2763 /* TYPE */ 2764 type ecParamsCurrentLimit struct { 2765 limit uint32 /* in mA */ 2766 } 2767 2768 /* 2769 * Set maximum external power current. 2770 */ 2771 const ecCmdExtPowerCurrentLimit = 0xa2 2772 2773 /* TYPE */ 2774 type ecParamsExtPowerCurrentLimit struct { 2775 limit uint32 /* in mA */ 2776 } 2777 2778 /*****************************************************************************/ 2779 /* Smart battery pass-through */ 2780 2781 /* Get / Set 16-bit smart battery registers */ 2782 const ecCmdSbReadWord = 0xb0 2783 const ecCmdSbWriteWord = 0xb1 2784 2785 /* Get / Set string smart battery parameters 2786 * formatted as SMBUS "block". 2787 */ 2788 const ecCmdSbReadBlock = 0xb2 2789 const ecCmdSbWriteBlock = 0xb3 2790 2791 /* TYPE */ 2792 type ecParamsSbRd struct { 2793 reg uint8 2794 } 2795 2796 /* TYPE */ 2797 type ecResponseSbRdWord struct { 2798 value uint16 2799 } 2800 2801 /* TYPE */ 2802 type ecParamsSbWrWord struct { 2803 reg uint8 2804 value uint16 2805 } 2806 2807 /* TYPE */ 2808 type ecResponseSbRdBlock struct { 2809 data [32]uint8 2810 } 2811 2812 /* TYPE */ 2813 type ecParamsSbWrBlock struct { 2814 reg uint8 2815 data [32]uint16 2816 } 2817 2818 /*****************************************************************************/ 2819 /* Battery vendor parameters 2820 * 2821 * Get or set vendor-specific parameters in the battery. Implementations may 2822 * differ between boards or batteries. On a set operation, the response 2823 * contains the actual value set, which may be rounded or clipped from the 2824 * requested value. 2825 */ 2826 2827 const ecCmdBatteryVendorParam = 0xb4 2828 2829 type ecBatteryVendorParamMode uint8 2830 2831 const ( 2832 batteryVendorParamModeGet ecBatteryVendorParamMode = 0 2833 batteryVendorParamModeSet 2834 ) 2835 2836 /* TYPE */ 2837 type ecParamsBatteryVendorParam struct { 2838 param uint32 2839 value uint32 2840 mode uint8 2841 } 2842 2843 /* TYPE */ 2844 type ecResponseBatteryVendorParam struct { 2845 value uint32 2846 } 2847 2848 /*****************************************************************************/ 2849 /* 2850 * Smart Battery Firmware Update Commands 2851 */ 2852 const ecCmdSbFwUpdate = 0xb5 2853 2854 type ecSbFwUpdateSubcmd uint8 2855 2856 const ( 2857 ecSbFwUpdatePrepare ecSbFwUpdateSubcmd = 0x0 2858 ecSbFwUpdateInfo = 0x1 /*query sb info */ 2859 ecSbFwUpdateBegin = 0x2 /*check if protected */ 2860 ecSbFwUpdateWrite = 0x3 /*check if protected */ 2861 ecSbFwUpdateEnd = 0x4 2862 ecSbFwUpdateStatus = 0x5 2863 ecSbFwUpdateProtect = 0x6 2864 ecSbFwUpdateMax = 0x7 2865 ) 2866 2867 const sbFwUpdateCmdWriteBlockSize = 32 2868 const sbFwUpdateCmdStatusSize = 2 2869 const sbFwUpdateCmdInfoSize = 8 2870 2871 /* TYPE */ 2872 type ecSbFwUpdateHeader struct { 2873 subcmd uint16 /* enum ecSbFwUpdateSubcmd */ 2874 fwID uint16 /* firmware id */ 2875 } 2876 2877 /* TYPE */ 2878 type ecParamsSbFwUpdate struct { 2879 hdr ecSbFwUpdateHeader 2880 /* no args. */ 2881 /* ecSbFwUpdatePrepare = 0x0 */ 2882 /* ecSbFwUpdateInfo = 0x1 */ 2883 /* ecSbFwUpdateBegin = 0x2 */ 2884 /* ecSbFwUpdateEnd = 0x4 */ 2885 /* ecSbFwUpdateStatus = 0x5 */ 2886 /* ecSbFwUpdateProtect = 0x6 */ 2887 /* or ... */ 2888 /* ecSbFwUpdateWrite = 0x3 */ 2889 data [sbFwUpdateCmdWriteBlockSize]uint8 2890 } 2891 2892 /* TYPE */ 2893 type ecResponseSbFwUpdate struct { 2894 data []uint8 2895 /* ecSbFwUpdateInfo = 0x1 */ 2896 //uint8 data[SBFwUpdateCmdInfoSize]; 2897 /* ecSbFwUpdateStatus = 0x5 */ 2898 //uint8 data[SBFwUpdateCmdStatusSize]; 2899 } 2900 2901 /* 2902 * Entering Verified Boot Mode Command 2903 * Default mode is VBOOTModeNormal if EC did not receive this command. 2904 * Valid Modes are: normal, developer, and recovery. 2905 */ 2906 const ecCmdEnteringMode = 0xb6 2907 2908 /* TYPE */ 2909 type ecParamsEnteringMode struct { 2910 vbootMode int 2911 } 2912 2913 const vbootModeNormal = 0 2914 const vbootModeDeveloper = 1 2915 const vbootModeRecovery = 2 2916 2917 /*****************************************************************************/ 2918 /* System commands */ 2919 2920 /* 2921 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't 2922 * necessarily reboot the EC. Rename to "image" or something similar? 2923 */ 2924 const ecCmdRebootEc = 0xd2 2925 2926 /* Command */ 2927 type ecRebootCmd uint8 2928 2929 const ( 2930 ecRebootCancel ecRebootCmd = 0 /* Cancel a pending reboot */ 2931 ecRebootJumpRo = 1 /* Jump to RO without rebooting */ 2932 ecRebootJumpRw = 2 /* Jump to RW without rebooting */ 2933 /* (command 3 was jump to RW-B) */ 2934 ecRebootCold = 4 /* Cold-reboot */ 2935 ecRebootDisableJump = 5 /* Disable jump until next reboot */ 2936 ecRebootHibernate = 6 /* Hibernate EC */ 2937 ) 2938 2939 /* Flags for ecParamsRebootEc.rebootFlags */ 2940 const ecRebootFlagReserved0 = (1 << 0) /* Was recovery request */ 2941 const ecRebootFlagOnApShutdown = (1 << 1) /* Reboot after AP shutdown */ 2942 2943 /* TYPE */ 2944 type ecParamsRebootEc struct { 2945 cmd uint8 /* enum ecRebootCmd */ 2946 flags uint8 /* See ecRebootFlag_* */ 2947 } 2948 2949 /* 2950 * Get information on last EC panic. 2951 * 2952 * Returns variable-length platform-dependent panic information. See panic.h 2953 * for details. 2954 */ 2955 const ecCmdGetPanicInfo = 0xd3 2956 2957 /*****************************************************************************/ 2958 /* 2959 * Special commands 2960 * 2961 * These do not follow the normal rules for commands. See each command for 2962 * details. 2963 */ 2964 2965 /* 2966 * Reboot NOW 2967 * 2968 * This command will work even when the EC LPC interface is busy, because the 2969 * reboot command is processed at interrupt level. Note that when the EC 2970 * reboots, the host will reboot too, so there is no response to this command. 2971 * 2972 * Use ecCmdRebootEc to reboot the EC more politely. 2973 */ 2974 const ecCmdReboot = 0xd1 /* Think "die" */ 2975 2976 /* 2977 * Resend last response (not supported on LPC). 2978 * 2979 * Returns ecResUnavailable if there is no response available - for example 2980 * there was no previous command, or the previous command's response was too 2981 * big to save. 2982 */ 2983 const ecCmdResendResponse = 0xdb 2984 2985 /* 2986 * This header byte on a command indicate version 0. Any header byte less 2987 * than this means that we are talking to an old EC which doesn't support 2988 * versioning. In that case, we assume version 0. 2989 * 2990 * Header bytes greater than this indicate a later version. For example 2991 * ecCmdVersion0 + 1 means we are using version 1. 2992 * 2993 * The old EC interface must not use commands 0xdc or higher. 2994 */ 2995 const ecCmdVersion0 = 0xdc 2996 2997 /*****************************************************************************/ 2998 /* 2999 * PD commands 3000 * 3001 * These commands are for PD MCU communication. 3002 */ 3003 3004 /* EC to PD MCU exchange status command */ 3005 const ecCmdPdExchangeStatus = 0x100 3006 3007 type pdChargeState uint8 3008 3009 const ( 3010 pdChargeNoChange pdChargeState = 0 /* Don't change charge state */ 3011 pdChargeNone /* No charging allowed */ 3012 pdCharge5v /* 5V charging only */ 3013 pdChargeMax /* Charge at max voltage */ 3014 ) 3015 3016 /* TYPE */ 3017 /* Status of EC being sent to PD */ 3018 type ecParamsPdStatus struct { 3019 battSoc int8 /* battery state of charge */ 3020 chargeState uint8 /* charging state (from enum pdChargeState) */ 3021 } 3022 3023 /* Status of PD being sent back to EC */ 3024 const pdStatusHostEvent = (1 << 0) /* Forward host event to AP */ 3025 const pdStatusInRw = (1 << 1) /* Running RW image */ 3026 const pdStatusJumpedToImage = (1 << 2) /* Current image was jumped to */ 3027 /* TYPE */ 3028 type ecResponsePdStatus struct { 3029 status uint32 /* PD MCU status */ 3030 currLimMa uint32 /* input current limit */ 3031 activeChargePort int32 /* active charging port */ 3032 } 3033 3034 /* AP to PD MCU host event status command, cleared on read */ 3035 const ecCmdPdHostEventStatus = 0x104 3036 3037 /* PD MCU host event status bits */ 3038 const pdEventUpdateDevice = (1 << 0) 3039 const pdEventPowerChange = (1 << 1) 3040 const pdEventIdentityReceived = (1 << 2) 3041 3042 /* TYPE */ 3043 type ecResponseHostEventStatus struct { 3044 status uint32 /* PD MCU host event status */ 3045 } 3046 3047 /* Set USB type-C port role and muxes */ 3048 const ecCmdUsbPdControl = 0x101 3049 3050 type usbPdControlRole uint8 3051 3052 const ( 3053 usbPdCtrlRoleNoChange usbPdControlRole = 0 3054 usbPdCtrlRoleToggleOn = 1 /* == AUTO */ 3055 usbPdCtrlRoleToggleOff = 2 3056 usbPdCtrlRoleForceSink = 3 3057 usbPdCtrlRoleForceSource = 4 3058 usbPdCtrlRoleCount 3059 ) 3060 3061 type usbPdControlMux uint8 3062 3063 const ( 3064 usbPdCtrlMuxNoChange usbPdControlMux = 0 3065 usbPdCtrlMuxNone = 1 3066 usbPdCtrlMuxUsb = 2 3067 usbPdCtrlMuxDp = 3 3068 usbPdCtrlMuxDock = 4 3069 usbPdCtrlMuxAuto = 5 3070 usbPdCtrlMuxCount 3071 ) 3072 3073 /* TYPE */ 3074 type ecParamsUsbPdControl struct { 3075 port uint8 3076 role uint8 3077 mux uint8 3078 } 3079 3080 /* TYPE */ 3081 type ecResponseUsbPdControl struct { 3082 enabled uint8 3083 role uint8 3084 polarity uint8 3085 state uint8 3086 } 3087 3088 /* TYPE */ 3089 type ecResponseUsbPdControlV1 struct { 3090 enabled uint8 3091 role uint8 /* [0] power: 0=SNK/1=SRC [1] data: 0=UFP/1=DFP */ 3092 polarity uint8 3093 state [32]byte 3094 } 3095 3096 const ecCmdUsbPdPorts = 0x102 3097 3098 /* TYPE */ 3099 type ecResponseUsbPdPorts struct { 3100 numPorts uint8 3101 } 3102 3103 const ecCmdUsbPdPowerInfo = 0x103 3104 3105 const pdPowerChargingPort = 0xff 3106 3107 /* TYPE */ 3108 type ecParamsUsbPdPowerInfo struct { 3109 port uint8 3110 } 3111 3112 type usbChgType uint8 3113 3114 const ( 3115 usbChgTypeNone usbChgType = iota 3116 usbChgTypePd 3117 usbChgTypeC 3118 usbChgTypeProprietary 3119 usbChgTypeBc12Dcp 3120 usbChgTypeBc12Cdp 3121 usbChgTypeBc12Sdp 3122 usbChgTypeOther 3123 usbChgTypeVbus 3124 usbChgTypeUnknown 3125 ) 3126 3127 type usbPowerRoles uint8 3128 3129 const ( 3130 usbPdPortPowerDisconnected usbPowerRoles = iota 3131 usbPdPortPowerSource 3132 usbPdPortPowerSink 3133 usbPdPortPowerSinkNotCharging 3134 ) 3135 3136 /* TYPE */ 3137 type usbChgMeasures struct { 3138 voltageMax uint16 3139 voltageNow uint16 3140 currentMax uint16 3141 currentLim uint16 3142 } 3143 3144 /* TYPE */ 3145 type ecResponseUsbPdPowerInfo struct { 3146 role uint8 3147 etype uint8 3148 dualrole uint8 3149 reserved1 uint8 3150 meas usbChgMeasures 3151 maxPower uint32 3152 } 3153 3154 /* Write USB-PD device FW */ 3155 const ecCmdUsbPdFwUpdate = 0x110 3156 3157 type usbPdFwUpdateCmds uint8 3158 3159 const ( 3160 usbPdFwReboot usbPdFwUpdateCmds = iota 3161 usbPdFwFlashErase 3162 usbPdFwFlashWrite 3163 usbPdFwEraseSig 3164 ) 3165 3166 /* TYPE */ 3167 type ecParamsUsbPdFwUpdate struct { 3168 devID uint16 3169 cmd uint8 3170 port uint8 3171 size uint32 /* Size to write in bytes */ 3172 /* Followed by data to write */ 3173 } 3174 3175 /* Write USB-PD Accessory RWHash table entry */ 3176 const ecCmdUsbPdRwHashEntry = 0x111 3177 3178 /* RW hash is first 20 bytes of SHA-256 of RW section */ 3179 const pdRwHashSize = 20 3180 3181 /* TYPE */ 3182 type ecParamsUsbPdRwHashEntry struct { 3183 devID uint16 3184 devRwHash [pdRwHashSize]uint8 3185 reserved uint8 /* For alignment of currentImage */ 3186 currentImage uint32 /* One of ecCurrentImage */ 3187 } 3188 3189 /* Read USB-PD Accessory info */ 3190 const ecCmdUsbPdDevInfo = 0x112 3191 3192 /* TYPE */ 3193 type ecParamsUsbPdInfoRequest struct { 3194 port uint8 3195 } 3196 3197 /* Read USB-PD Device discovery info */ 3198 const ecCmdUsbPdDiscovery = 0x113 3199 3200 /* TYPE */ 3201 type ecParamsUsbPdDiscoveryEntry struct { 3202 vid uint16 /* USB-IF VID */ 3203 pid uint16 /* USB-IF PID */ 3204 ptype uint8 /* product type (hub,periph,cable,ama) */ 3205 } 3206 3207 /* Override default charge behavior */ 3208 const ecCmdPdChargePortOverride = 0x114 3209 3210 /* Negative port parameters have special meaning */ 3211 type usbPdOverridePorts int8 3212 3213 const ( 3214 overrideDontCharge usbPdOverridePorts = -2 3215 overrideOff = -1 3216 /* [0, pdPortCount): Port# */ 3217 ) 3218 3219 /* TYPE */ 3220 type ecParamsChargePortOverride struct { 3221 overridePort int16 /* Override port# */ 3222 } 3223 3224 /* Read (and delete) one entry of PD event log */ 3225 const ecCmdPdGetLogEntry = 0x115 3226 3227 /* TYPE */ 3228 type ecResponsePdLog struct { 3229 timestamp uint32 /* relative timestamp in milliseconds */ 3230 etype uint8 /* event type : see pdEventXx below */ 3231 sizePort uint8 /* [7:5] port number [4:0] payload size in bytes */ 3232 data uint16 /* type-defined data payload */ 3233 payload []uint8 /* optional additional data payload: 0..16 bytes */ 3234 } 3235 3236 /* The timestamp is the microsecond counter shifted to get about a ms. */ 3237 const pdLogTimestampShift = 10 /* 1 LSB = 1024us */ 3238 3239 const pdLogSizeMask = 0x1F 3240 const pdLogPortMask = 0xE0 3241 const pdLogPortShift = 5 3242 3243 func pdLogPortSize(port, size uint8) uint8 { 3244 return (port << pdLogPortShift) | (size & pdLogSizeMask) 3245 } 3246 3247 func pdLogPort(sizePort uint8) uint8 { 3248 return sizePort >> pdLogPortShift 3249 } 3250 func pdLogSize(sizePort uint8) uint8 { 3251 return sizePort & pdLogSizeMask 3252 } 3253 3254 /* PD event log : entry types */ 3255 /* PD MCU events */ 3256 const pdEventMcuBase = 0x00 3257 const pdEventMcuCharge = (pdEventMcuBase + 0) 3258 const pdEventMcuConnect = (pdEventMcuBase + 1) 3259 3260 /* Reserved for custom board event */ 3261 const pdEventMcuBoardCustom = (pdEventMcuBase + 2) 3262 3263 /* PD generic accessory events */ 3264 const pdEventAccBase = 0x20 3265 const pdEventAccRwFail = (pdEventAccBase + 0) 3266 const pdEventAccRwErase = (pdEventAccBase + 1) 3267 3268 /* PD power supply events */ 3269 const pdEventPsBase = 0x40 3270 const pdEventPsFault = (pdEventPsBase + 0) 3271 3272 /* PD video dongles events */ 3273 const pdEventVideoBase = 0x60 3274 const pdEventVideoDpMode = (pdEventVideoBase + 0) 3275 const pdEventVideoCodec = (pdEventVideoBase + 1) 3276 3277 /* Returned in the "type" field, when there is no entry available */ 3278 const pdEventNoEntry = 0xFF 3279 3280 /* 3281 * pdEventMcuCharge event definition : 3282 * the payload is "struct usbChgMeasures" 3283 * the data field contains the port state flags as defined below : 3284 */ 3285 /* Port partner is a dual role device */ 3286 const chargeFlagsDualRole = (1 << 15) 3287 3288 /* Port is the pending override port */ 3289 const chargeFlagsDelayedOverride = (1 << 14) 3290 3291 /* Port is the override port */ 3292 const chargeFlagsOverride = (1 << 13) 3293 3294 /* Charger type */ 3295 const chargeFlagsTypeShift = 3 3296 const chargeFlagsTypeMask = (0xF << chargeFlagsTypeShift) 3297 3298 /* Power delivery role */ 3299 const chargeFlagsRoleMask = (7 << 0) 3300 3301 /* 3302 * pdEventPsFault data field flags definition : 3303 */ 3304 const psFaultOcp = 1 3305 const psFaultFastOcp = 2 3306 const psFaultOvp = 3 3307 const psFaultDisch = 4 3308 3309 /* TYPE */ 3310 /* 3311 * pdEventVideoCodec payload is "struct mcdpInfo". 3312 */ 3313 type mcdpVersion struct { 3314 major uint8 3315 minor uint8 3316 build uint16 3317 } 3318 3319 /* TYPE */ 3320 type mcdpInfo struct { 3321 family [2]uint8 3322 chipid [2]uint8 3323 irom mcdpVersion 3324 fw mcdpVersion 3325 } 3326 3327 /* struct mcdpInfo field decoding */ 3328 func mcdpChipid(chipid []uint8) uint16 { 3329 return (uint16(chipid[0]) << 8) | uint16(chipid[1]) 3330 } 3331 3332 func mcdpFamily(family []uint8) uint16 { 3333 return (uint16(family[0]) << 8) | uint16(family[1]) 3334 } 3335 3336 /* Get/Set USB-PD Alternate mode info */ 3337 const ecCmdUsbPdGetAmode = 0x116 3338 3339 /* TYPE */ 3340 type ecParamsUsbPdGetModeRequest struct { 3341 svidIdx uint16 /* SVID index to get */ 3342 port uint8 /* port */ 3343 } 3344 3345 /* TYPE */ 3346 type ecParamsUsbPdGetModeResponse struct { 3347 svid uint16 /* SVID */ 3348 opos uint16 /* Object Position */ 3349 vdo [6]uint32 /* Mode VDOs */ 3350 } 3351 3352 const ecCmdUsbPdSetAmode = 0x117 3353 3354 type pdModeCmd uint8 3355 3356 const ( 3357 pdExitMode pdModeCmd = 0 3358 pdEnterMode = 1 3359 /* Not a command. Do NOT remove. */ 3360 pdModeCmdCount 3361 ) 3362 3363 /* TYPE */ 3364 type ecParamsUsbPdSetModeRequest struct { 3365 cmd uint32 /* enum pdModeCmd */ 3366 svid uint16 /* SVID to set */ 3367 opos uint8 /* Object Position */ 3368 port uint8 /* port */ 3369 } 3370 3371 /* Ask the PD MCU to record a log of a requested type */ 3372 const ecCmdPdWriteLogEntry = 0x118 3373 3374 /* TYPE */ 3375 type ecParamsPdWriteLogEntry struct { 3376 etype uint8 /* event type : see pdEventXx above */ 3377 port uint8 /* port#, or 0 for events unrelated to a given port */ 3378 } 3379 3380 /*****************************************************************************/ 3381 /* 3382 * Passthru commands 3383 * 3384 * Some platforms have sub-processors chained to each other. For example. 3385 * 3386 * AP <--> EC <--> PD MCU 3387 * 3388 * The top 2 bits of the command number are used to indicate which device the 3389 * command is intended for. Device 0 is always the device receiving the 3390 * command; other device mapping is board-specific. 3391 * 3392 * When a device receives a command to be passed to a sub-processor, it passes 3393 * it on with the device number set back to 0. This allows the sub-processor 3394 * to remain blissfully unaware of whether the command originated on the next 3395 * device up the chain, or was passed through from the AP. 3396 * 3397 * In the above example, if the AP wants to send command 0x0002 to the PD MCU 3398 * AP sends command 0x4002 to the EC 3399 * EC sends command 0x0002 to the PD MCU 3400 * EC forwards PD MCU response back to the AP 3401 */ 3402 3403 /* Offset and max command number for sub-device n */ 3404 func ecCmdPassthruOffset(n uint) uint { 3405 return 0x4000 * n 3406 } 3407 3408 func ecCmdPassthruMax(n uint) uint { 3409 return ecCmdPassthruOffset(n) + 0x3fff 3410 } 3411 3412 /*****************************************************************************/ 3413 /* 3414 * Deprecated constants. These constants have been renamed for clarity. The 3415 * meaning and size has not changed. Programs that use the old names should 3416 * switch to the new names soon, as the old names may not be carried forward 3417 * forever. 3418 */ 3419 const ecHostParamSize = ecProto2MaxParamSize 3420 const ecLpcAddrOldParam = ecHostCmdRegion1 3421 const ecOldParamSize = ecHostCmdRegionSize 3422 3423 func ecVerMask(version uint8) uint8 { 3424 /* Command version mask */ 3425 return 1 << version 3426 }