github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/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 1519 const ( 1520 /* LED control flags */ 1521 ecLedFlagsQuery = (1 << iota) /* Query LED capability only */ 1522 ecLedFlagsAuto /* Switch LED back to automatic control */ 1523 ) 1524 1525 type ecLedColors uint8 1526 1527 const ( 1528 ecLedColorRed ecLedColors = 0 1529 ecLedColorGreen 1530 ecLedColorBlue 1531 ecLedColorYellow 1532 ecLedColorWhite 1533 1534 ecLedColorCount 1535 ) 1536 1537 /* TYPE */ 1538 type ecParamsLedControl struct { 1539 ledID uint8 /* Which LED to control */ 1540 flags uint8 /* Control flags */ 1541 1542 brightness [ecLedColorCount]uint8 1543 } 1544 1545 /* TYPE */ 1546 type ecResponseLedControl struct { 1547 /* 1548 * Available brightness value range. 1549 * 1550 * Range 0 means color channel not present. 1551 * Range 1 means on/off control. 1552 * Other values means the LED is control by PWM. 1553 */ 1554 brightnessRange [ecLedColorCount]uint8 1555 } 1556 1557 /*****************************************************************************/ 1558 /* Verified boot commands */ 1559 1560 /* 1561 * Note: command code 0x29 version 0 was VBOOTCmd in Link EVT; it may be 1562 * reused for other purposes with version > 0. 1563 */ 1564 1565 /* Verified boot hash command */ 1566 const ecCmdVbootHash = 0x2A 1567 1568 /* TYPE */ 1569 type ecParamsVbootHash struct { 1570 cmd uint8 /* enum ecVbootHashCmd */ 1571 hashype uint8 /* enum ecVbootHashType */ 1572 nonceSize uint8 /* Nonce size; may be 0 */ 1573 reserved0 uint8 /* Reserved; set 0 */ 1574 offset uint32 /* Offset in flash to hash */ 1575 size uint32 /* Number of bytes to hash */ 1576 nonceData [64]uint8 /* Nonce data; ignored if nonceSize=0 */ 1577 } 1578 1579 /* TYPE */ 1580 type ecResponseVbootHash struct { 1581 status uint8 /* enum ecVbootHashStatus */ 1582 hashype uint8 /* enum ecVbootHashType */ 1583 digestSize uint8 /* Size of hash digest in bytes */ 1584 reserved0 uint8 /* Ignore; will be 0 */ 1585 offset uint32 /* Offset in flash which was hashed */ 1586 size uint32 /* Number of bytes hashed */ 1587 hashDigest [64]uint8 /* Hash digest data */ 1588 } 1589 1590 type ecVbootHashCmd uint8 1591 1592 const ( 1593 ecVbootHashGet ecVbootHashCmd = 0 /* Get current hash status */ 1594 ecVbootHashAbort = 1 /* Abort calculating current hash */ 1595 ecVbootHashStart = 2 /* Start computing a new hash */ 1596 ecVbootHashRecalc = 3 /* Synchronously compute a new hash */ 1597 ) 1598 1599 type ecVbootHashType uint8 1600 1601 const ( 1602 ecVbootHashTypeSha256 ecVbootHashType = 0 /* SHA-256 */ 1603 ) 1604 1605 type ecVbootHashStatus uint8 1606 1607 const ( 1608 ecVbootHashStatusNone ecVbootHashStatus = 0 /* No hash (not started, or aborted) */ 1609 ecVbootHashStatusDone = 1 /* Finished computing a hash */ 1610 ecVbootHashStatusBusy = 2 /* Busy computing a hash */ 1611 ) 1612 1613 /* 1614 * Special values for offset for ecVbootHashStart and ecVbootHashRecalc. 1615 * If one of these is specified, the EC will automatically update offset and 1616 * size to the correct values for the specified image (RO or RW). 1617 */ 1618 const ecVbootHashOffsetRo = 0xfffffffe 1619 const ecVbootHashOffsetRw = 0xfffffffd 1620 1621 /*****************************************************************************/ 1622 /* 1623 * Motion sense commands. We'll make separate structs for sub-commands with 1624 * different input args, so that we know how much to expect. 1625 */ 1626 const ecCmdMotionSenseCmd = 0x2B 1627 1628 /* Motion sense commands */ 1629 type motionsenseCommand uint8 1630 1631 const ( 1632 /* Dump command returns all motion sensor data including motion sense 1633 * module flags and individual sensor flags. 1634 */ 1635 motionsenseCmdDump motionsenseCommand = iota 1636 1637 /* 1638 * Info command returns data describing the details of a given sensor 1639 * including enum motionsensorType, enum motionsensorLocation, and 1640 * enum motionsensorChip. 1641 */ 1642 motionsenseCmdInfo 1643 1644 /* 1645 * EC Rate command is a setter/getter command for the EC sampling rate 1646 * of all motion sensors in milliseconds. 1647 */ 1648 motionsenseCmdEcRate 1649 1650 /* 1651 * Sensor ODR command is a setter/getter command for the output data 1652 * rate of a specific motion sensor in millihertz. 1653 */ 1654 motionsenseCmdSensorOdr 1655 1656 /* 1657 * Sensor range command is a setter/getter command for the range of 1658 * a specified motion sensor in +/-G's or +/- deg/s. 1659 */ 1660 motionsenseCmdSensorRange 1661 1662 /* 1663 * Setter/getter command for the keyboard wake angle. When the lid 1664 * angle is greater than this value, keyboard wake is disabled in S3 1665 * and when the lid angle goes less than this value, keyboard wake is 1666 * enabled. Note, the lid angle measurement is an approximate 1667 * un-calibrated value, hence the wake angle isn't exact. 1668 */ 1669 motionsenseCmdKbWakeAngle 1670 1671 /* Number of motionsense sub-commands. */ 1672 motionsenseNumCmds 1673 ) 1674 1675 /* List of motion sensor types. */ 1676 type motionsensorType uint8 1677 1678 const ( 1679 motionsenseTypeAccel motionsensorType = 0 1680 motionsenseTypeGyro = 1 1681 ) 1682 1683 /* List of motion sensor locations. */ 1684 type motionsensorLocation uint8 1685 1686 const ( 1687 motionsenseLocBase motionsensorLocation = 0 1688 motionsenseLocLid = 1 1689 ) 1690 1691 /* List of motion sensor chips. */ 1692 type motionsensorChip uint8 1693 1694 const ( 1695 motionsenseChipKxcj9 motionsensorChip = 0 1696 motionsenseChipLsm6ds0 = 1 1697 ) 1698 1699 /* Module flag masks used for the dump sub-command. */ 1700 const motionsenseModuleFlagActive = (1 << 0) 1701 1702 /* Sensor flag masks used for the dump sub-command. */ 1703 const motionsenseSensorFlagPresent = (1 << 0) 1704 1705 /* 1706 * Send this value for the data element to only perform a read. If you 1707 * send any other value, the EC will interpret it as data to set and will 1708 * return the actual value set. 1709 */ 1710 const ecMotionSenseNoValue = -1 1711 1712 /* some other time 1713 type ecParamsMotionSense struct { 1714 cmd uint8 1715 union { 1716 /* Used for MOTIONSENSECmdDump * / 1717 struct { 1718 /* 1719 * Maximal number of sensor the host is expecting. 1720 * 0 means the host is only interested in the number 1721 * of sensors controlled by the EC. 1722 * / 1723 uint8 maxSensorCount; 1724 } dump; 1725 1726 /* 1727 * Used for MOTIONSENSECmdEcRate and 1728 * MOTIONSENSECmdKbWakeAngle. 1729 * / 1730 struct { 1731 /* Data to set or ecMotionSenseNoValue to read. * / 1732 data int16 1733 } ecRate, kbWakeAngle; 1734 1735 /* Used for MOTIONSENSECmdInfo. * / 1736 struct { 1737 uint8 sensorNum; 1738 } info; 1739 1740 /* 1741 * Used for MOTIONSENSECmdSensorOdr and 1742 * MOTIONSENSECmdSensorRange. 1743 * / 1744 struct { 1745 uint8 sensorNum; 1746 1747 /* Rounding flag, true for round-up, false for down. * / 1748 uint8 roundup; 1749 1750 uint16 reserved; 1751 1752 /* Data to set or ecMotionSenseNoValue to read. * / 1753 data int32 1754 } sensorOdr, sensorRange; 1755 }; 1756 } ; 1757 */ 1758 /* TYPE */ 1759 type ecResponseMotionSensorData struct { 1760 /* Flags for each sensor. */ 1761 flags uint8 1762 padding uint8 1763 1764 /* Each sensor is up to 3-axis. */ 1765 data [3]int16 1766 } 1767 1768 /* TYPE */ 1769 /* some other time 1770 1771 type ecResponseMotionSense struct { 1772 union { 1773 /* Used for MOTIONSENSECmdDump * / 1774 struct { 1775 /* Flags representing the motion sensor module. * / 1776 uint8 moduleFlags; 1777 1778 /* Number of sensors managed directly by the EC * / 1779 uint8 sensorCount; 1780 1781 /* 1782 * sensor data is truncated if responseMax is too small 1783 * for holding all the data. 1784 * / 1785 struct ecResponseMotionSensorData sensor[0]; 1786 } dump; 1787 1788 /* Used for MOTIONSENSECmdInfo. * / 1789 struct { 1790 /* Should be element of enum motionsensorType. * / 1791 uint8 type; 1792 1793 /* Should be element of enum motionsensorLocation. * / 1794 uint8 location; 1795 1796 /* Should be element of enum motionsensorChip. * / 1797 uint8 chip; 1798 } info; 1799 1800 /* 1801 * Used for MOTIONSENSECmdEcRate, MOTIONSENSECmdSensorOdr 1802 * MOTIONSENSECmdSensorRange, and 1803 * MOTIONSENSECmdKbWakeAngle. 1804 * / 1805 struct { 1806 /* Current value of the parameter queried. * / 1807 ret int32 1808 } ecRate, sensorOdr, sensorRange, kbWakeAngle; 1809 }; 1810 } ; 1811 */ 1812 /*****************************************************************************/ 1813 /* Force lid open command */ 1814 1815 /* Make lid event always open */ 1816 const ecCmdForceLidOpen = 0x2c 1817 1818 /* TYPE */ 1819 type ecParamsForceLidOpen struct { 1820 enabled uint8 1821 } 1822 1823 /*****************************************************************************/ 1824 /* USB charging control commands */ 1825 1826 /* Set USB port charging mode */ 1827 const ecCmdUsbChargeSetMode = 0x30 1828 1829 /* TYPE */ 1830 type ecParamsUsbChargeSetMode struct { 1831 usbPortID uint8 1832 mode uint8 1833 } 1834 1835 /*****************************************************************************/ 1836 /* Persistent storage for host */ 1837 1838 /* Maximum bytes that can be read/written in a single command */ 1839 const ecPstoreSizeMax = 64 1840 1841 /* Get persistent storage info */ 1842 const ecCmdPstoreInfo = 0x40 1843 1844 /* TYPE */ 1845 type ecResponsePstoreInfo struct { 1846 /* Persistent storage size, in bytes */ 1847 pstoreSize uint32 1848 /* Access size; read/write offset and size must be a multiple of this */ 1849 accessSize uint32 1850 } 1851 1852 /* 1853 * Read persistent storage 1854 * 1855 * Response is params.size bytes of data. 1856 */ 1857 const ecCmdPstoreRead = 0x41 1858 1859 /* TYPE */ 1860 type ecParamsPstoreRead struct { 1861 offset uint32 /* Byte offset to read */ 1862 size uint32 /* Size to read in bytes */ 1863 } 1864 1865 /* Write persistent storage */ 1866 const ecCmdPstoreWrite = 0x42 1867 1868 /* TYPE */ 1869 type ecParamsPstoreWrite struct { 1870 offset uint32 /* Byte offset to write */ 1871 size uint32 /* Size to write in bytes */ 1872 data [ecPstoreSizeMax]uint8 1873 } 1874 1875 /* TYPE */ 1876 /*****************************************************************************/ 1877 /* Real-time clock */ 1878 1879 /* RTC params and response structures */ 1880 type ecParamsRtc struct { 1881 time uint32 1882 } 1883 1884 /* TYPE */ 1885 type ecResponseRtc struct { 1886 time uint32 1887 } 1888 1889 /* These use ecResponseRtc */ 1890 const ecCmdRtcGetValue = 0x44 1891 const ecCmdRtcGetAlarm = 0x45 1892 1893 /* These all use ecParamsRtc */ 1894 const ecCmdRtcSetValue = 0x46 1895 const ecCmdRtcSetAlarm = 0x47 1896 1897 /*****************************************************************************/ 1898 /* Port80 log access */ 1899 1900 /* Maximum entries that can be read/written in a single command */ 1901 const ecPort80SizeMax = 32 1902 1903 /* Get last port80 code from previous boot */ 1904 const ecCmdPort80LastBoot = 0x48 1905 const ecCmdPort80Read = 0x48 1906 1907 type ecPort80Subcmd uint8 1908 1909 const ( 1910 ecPort80GetInfo ecPort80Subcmd = 0 1911 ecPort80ReadBuffer 1912 ) 1913 1914 /* TYPE */ 1915 type ecParamsPort80Read struct { 1916 subcmd uint16 1917 offset uint32 1918 numEntries uint32 1919 } 1920 1921 /* TYPE */ 1922 type ecResponsePort80Read struct { 1923 /* 1924 struct { 1925 uint32 writes; 1926 uint32 historySize; 1927 uint32 lastBoot; 1928 } getInfo;*/ 1929 1930 codes [ecPort80SizeMax]uint16 1931 } 1932 1933 /* TYPE */ 1934 type ecResponsePort80LastBoot struct { 1935 code uint16 1936 } 1937 1938 /*****************************************************************************/ 1939 /* Thermal engine commands. Note that there are two implementations. We'll 1940 * reuse the command number, but the data and behavior is incompatible. 1941 * Version 0 is what originally shipped on Link. 1942 * Version 1 separates the CPU thermal limits from the fan control. 1943 */ 1944 1945 const ( 1946 ecCmdThermalSetThreshold = 0x50 1947 ecCmdThermalGetThreshold = 0x51 1948 ) 1949 1950 /* TYPE */ 1951 /* The version 0 structs are opaque. You have to know what they are for 1952 * the get/set commands to make any sense. 1953 */ 1954 1955 /* Version 0 - set */ 1956 type ecParamsThermalSetThreshold struct { 1957 sensorype uint8 1958 thresholdID uint8 1959 value uint16 1960 } 1961 1962 /* TYPE */ 1963 /* Version 0 - get */ 1964 type ecParamsThermalGetThreshold struct { 1965 sensorype uint8 1966 thresholdID uint8 1967 } 1968 1969 /* TYPE */ 1970 type ecResponseThermalGetThreshold struct { 1971 value uint16 1972 } 1973 1974 /* The version 1 structs are visible. */ 1975 type ecTempThresholds uint8 1976 1977 const ( 1978 ecTempThreshWarn ecTempThresholds = 0 1979 ecTempThreshHigh 1980 ecTempThreshHalt 1981 1982 ecTempThreshCount 1983 ) 1984 1985 /* TYPE */ 1986 /* Thermal configuration for one temperature sensor. Temps are in degrees K. 1987 * Zero values will be silently ignored by the thermal task. 1988 */ 1989 type ecThermalConfig struct { 1990 tempHost [ecTempThreshCount]uint32 /* levels of hotness */ 1991 tempFanOff uint32 /* no active cooling needed */ 1992 tempFanMax uint32 /* max active cooling needed */ 1993 } 1994 1995 /* TYPE */ 1996 /* Version 1 - get config for one sensor. */ 1997 type ecParamsThermalGetThresholdV1 struct { 1998 sensorNum uint32 1999 } 2000 2001 /* TYPE */ 2002 /* This returns a struct ecThermalConfig */ 2003 2004 /* Version 1 - set config for one sensor. 2005 * Use read-modify-write for best results! */ 2006 type ecParamsThermalSetThresholdV1 struct { 2007 sensorNum uint32 2008 cfg ecThermalConfig 2009 } 2010 2011 /* This returns no data */ 2012 2013 /****************************************************************************/ 2014 2015 /* Toggle automatic fan control */ 2016 const ecCmdThermalAutoFanCtrl = 0x52 2017 2018 /* TYPE */ 2019 /* Version 1 of input params */ 2020 type ecParamsAutoFanCtrlV1 struct { 2021 fanIdx uint8 2022 } 2023 2024 /* Get/Set TMP006 calibration data */ 2025 const ecCmdTmp006GetCalibration = 0x53 2026 const ecCmdTmp006SetCalibration = 0x54 2027 2028 /* TYPE */ 2029 /* 2030 * The original TMP006 calibration only needed four params, but now we need 2031 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave 2032 * the params opaque. The v1 "get" response will include the algorithm number 2033 * and how many params it requires. That way we can change the EC code without 2034 * needing to update this file. We can also use a different algorithm on each 2035 * sensor. 2036 */ 2037 2038 /* This is the same struct for both v0 and v1. */ 2039 type ecParamsTmp006GetCalibration struct { 2040 index uint8 2041 } 2042 2043 /* TYPE */ 2044 /* Version 0 */ 2045 type ecResponseTmp006GetCalibrationV0 struct { 2046 s0, b0, b1, bw float32 2047 } 2048 2049 /* TYPE */ 2050 type ecParamsTmp006SetCalibrationV0 struct { 2051 index uint8 2052 reserved [3]uint8 2053 s0, b0, b1, b2 float32 2054 } 2055 2056 /* TYPE */ 2057 /* Version 1 */ 2058 type ecResponseTmp006GetCalibrationV1 struct { 2059 algorithm uint8 2060 numParams uint8 2061 reserved [2]uint8 2062 val []float32 2063 } 2064 2065 /* TYPE */ 2066 type ecParamsTmp006SetCalibrationV1 struct { 2067 index uint8 2068 algorithm uint8 2069 numParams uint8 2070 reserved uint8 2071 val []float32 2072 } 2073 2074 /* Read raw TMP006 data */ 2075 const ecCmdTmp006GetRaw = 0x55 2076 2077 /* TYPE */ 2078 type ecParamsTmp006GetRaw struct { 2079 index uint8 2080 } 2081 2082 /* TYPE */ 2083 type ecResponseTmp006GetRaw struct { 2084 t int32 /* In 1/100 K */ 2085 v int32 /* In nV */ 2086 } 2087 2088 /*****************************************************************************/ 2089 /* MKBP - Matrix KeyBoard Protocol */ 2090 2091 /* 2092 * Read key state 2093 * 2094 * Returns raw data for keyboard cols; see ecResponseMkbpInfo.cols for 2095 * expected response size. 2096 */ 2097 const ecCmdMkbpState = 0x60 2098 2099 /* Provide information about the matrix : number of rows and columns */ 2100 const ecCmdMkbpInfo = 0x61 2101 2102 /* TYPE */ 2103 type ecResponseMkbpInfo struct { 2104 rows uint32 2105 cols uint32 2106 switches uint8 2107 } 2108 2109 /* Simulate key press */ 2110 const ecCmdMkbpSimulateKey = 0x62 2111 2112 /* TYPE */ 2113 type ecParamsMkbpSimulateKey struct { 2114 col uint8 2115 row uint8 2116 pressed uint8 2117 } 2118 2119 /* Configure keyboard scanning */ 2120 const ecCmdMkbpSetConfig = 0x64 2121 const ecCmdMkbpGetConfig = 0x65 2122 2123 /* flags */ 2124 type mkbpConfigFlags uint8 2125 2126 const ( 2127 ecMkbpFlagsEnable mkbpConfigFlags = 1 /* Enable keyboard scanning */ 2128 ) 2129 2130 type mkbpConfigValid uint8 2131 2132 const ( 2133 ecMkbpValidScanPeriod mkbpConfigValid = 1 << 0 2134 ecMkbpValidPollTimeout = 1 << 1 2135 ecMkbpValidMinPostScanDelay = 1 << 3 2136 ecMkbpValidOutputSettle = 1 << 4 2137 ecMkbpValidDebounceDown = 1 << 5 2138 ecMkbpValidDebounceUp = 1 << 6 2139 ecMkbpValidFifoMaxDepth = 1 << 7 2140 ) 2141 2142 /* TYPE */ 2143 /* Configuration for our key scanning algorithm */ 2144 type ecMkbpConfig struct { 2145 validMask uint32 /* valid fields */ 2146 flags uint8 /* some flags (enum mkbpConfigFlags) */ 2147 validFlags uint8 /* which flags are valid */ 2148 scanPeriodUs uint16 /* period between start of scans */ 2149 /* revert to interrupt mode after no activity for this long */ 2150 pollimeoutUs uint32 2151 /* 2152 * minimum post-scan relax time. Once we finish a scan we check 2153 * the time until we are due to start the next one. If this time is 2154 * shorter this field, we use this instead. 2155 */ 2156 minPostScanDelayUs uint16 2157 /* delay between setting up output and waiting for it to settle */ 2158 outputSettleUs uint16 2159 debounceDownUs uint16 /* time for debounce on key down */ 2160 debounceUpUs uint16 /* time for debounce on key up */ 2161 /* maximum depth to allow for fifo (0 = no keyscan output) */ 2162 fifoMaxDepth uint8 2163 } 2164 2165 /* TYPE */ 2166 type ecParamsMkbpSetConfig struct { 2167 config ecMkbpConfig 2168 } 2169 2170 /* TYPE */ 2171 type ecResponseMkbpGetConfig struct { 2172 config ecMkbpConfig 2173 } 2174 2175 /* Run the key scan emulation */ 2176 const ecCmdKeyscanSeqCtrl = 0x66 2177 2178 type ecKeyscanSeqCmd uint8 2179 2180 const ( 2181 ecKeyscanSeqStatus ecKeyscanSeqCmd = 0 /* Get status information */ 2182 ecKeyscanSeqClear = 1 /* Clear sequence */ 2183 ecKeyscanSeqAdd = 2 /* Add item to sequence */ 2184 ecKeyscanSeqStart = 3 /* Start running sequence */ 2185 ecKeyscanSeqCollect = 4 /* Collect sequence summary data */ 2186 ) 2187 2188 type ecCollectFlags uint8 2189 2190 const ( 2191 /* Indicates this scan was processed by the EC. Due to timing, some 2192 * scans may be skipped. 2193 */ 2194 ecKeyscanSeqFlagDone ecCollectFlags = 1 << iota 2195 ) 2196 2197 /* TYPE */ 2198 type ecCollectItem struct { 2199 flags uint8 /* some flags (enum ecCollectFlags) */ 2200 } 2201 2202 /* TYPE */ 2203 /* later 2204 type ecParamsKeyscanSeqCtrl struct { 2205 cmd uint8 /* Command to send (enum ecKeyscanSeqCmd) * / 2206 union { 2207 struct { 2208 uint8 active; /* still active * / 2209 uint8 numItems; /* number of items * / 2210 /* Current item being presented * / 2211 uint8 curItem; 2212 } status; 2213 struct { 2214 /* 2215 * Absolute time for this scan, measured from the 2216 * start of the sequence. 2217 * / 2218 uint32 timeUs; 2219 uint8 scan[0]; /* keyscan data * / 2220 } add; 2221 struct { 2222 uint8 startItem; /* First item to return * / 2223 uint8 numItems; /* Number of items to return * / 2224 } collect; 2225 }; 2226 } ; 2227 */ 2228 /* TYPE */ 2229 /* lter 2230 type ecResultKeyscanSeqCtrl struct { 2231 union { 2232 struct { 2233 uint8 numItems; /* Number of items * 2234 /* Data for each item * 2235 struct ecCollectItem item[0] 2236 } collect; 2237 }; 2238 } ; 2239 */ 2240 /* 2241 * Get the next pending MKBP event. 2242 * 2243 * Returns ecResUnavailable if there is no event pending. 2244 */ 2245 const ecCmdGetNextEvent = 0x67 2246 2247 type ecMkbpEvent uint8 2248 2249 const ( 2250 /* Keyboard matrix changed. The event data is the new matrix state. */ 2251 ecMkbpEventKeyMatrix = iota 2252 2253 /* New host event. The event data is 4 bytes of host event flags. */ 2254 ecMkbpEventHostEvent 2255 2256 /* Number of MKBP events */ 2257 ecMkbpEventCount 2258 ) 2259 2260 /* TYPE */ 2261 type ecResponseGetNextEvent struct { 2262 eventype uint8 2263 /* Followed by event data if any */ 2264 } 2265 2266 /*****************************************************************************/ 2267 /* Temperature sensor commands */ 2268 2269 /* Read temperature sensor info */ 2270 const ecCmdTempSensorGetInfo = 0x70 2271 2272 /* TYPE */ 2273 type ecParamsTempSensorGetInfo struct { 2274 id uint8 2275 } 2276 2277 /* TYPE */ 2278 type ecResponseTempSensorGetInfo struct { 2279 sensorName [32]byte 2280 sensorype uint8 2281 } 2282 2283 /* TYPE */ 2284 /*****************************************************************************/ 2285 2286 /* 2287 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI 2288 * commands accidentally sent to the wrong interface. See the ACPI section 2289 * below. 2290 */ 2291 2292 /*****************************************************************************/ 2293 /* Host event commands */ 2294 2295 /* 2296 * Host event mask params and response structures, shared by all of the host 2297 * event commands below. 2298 */ 2299 type ecParamsHostEventMask struct { 2300 mask uint32 2301 } 2302 2303 /* TYPE */ 2304 type ecResponseHostEventMask struct { 2305 mask uint32 2306 } 2307 2308 /* These all use ecResponseHostEventMask */ 2309 const ( 2310 ecCmdHostEventGetB = 0x87 2311 ecCmdHostEventGetSmiMask = 0x88 2312 ecCmdHostEventGetSciMask = 0x89 2313 ecCmdHostEventGetWakeMask = 0x8d 2314 ) 2315 2316 /* These all use ecParamsHostEventMask */ 2317 const ( 2318 ecCmdHostEventSetSmiMask = 0x8a 2319 ecCmdHostEventSetSciMask = 0x8b 2320 ecCmdHostEventClear = 0x8c 2321 ecCmdHostEventSetWakeMask = 0x8e 2322 ecCmdHostEventClearB = 0x8f 2323 ) 2324 2325 /*****************************************************************************/ 2326 /* Switch commands */ 2327 2328 /* Enable/disable LCD backlight */ 2329 const ecCmdSwitchEnableBklight = 0x90 2330 2331 /* TYPE */ 2332 type ecParamsSwitchEnableBacklight struct { 2333 enabled uint8 2334 } 2335 2336 /* Enable/disable WLAN/Bluetooth */ 2337 const ecCmdSwitchEnableWireless = 0x91 2338 const ecVerSwitchEnableWireless = 1 2339 2340 /* TYPE */ 2341 /* Version 0 params; no response */ 2342 type ecParamsSwitchEnableWirelessV0 struct { 2343 enabled uint8 2344 } 2345 2346 /* TYPE */ 2347 /* Version 1 params */ 2348 type ecParamsSwitchEnableWirelessV1 struct { 2349 /* Flags to enable now */ 2350 nowFlags uint8 2351 2352 /* Which flags to copy from nowFlags */ 2353 nowMask uint8 2354 2355 /* 2356 * Flags to leave enabled in S3, if they're on at the S0->S3 2357 * transition. (Other flags will be disabled by the S0->S3 2358 * transition.) 2359 */ 2360 suspendFlags uint8 2361 2362 /* Which flags to copy from suspendFlags */ 2363 suspendMask uint8 2364 } 2365 2366 /* TYPE */ 2367 /* Version 1 response */ 2368 type ecResponseSwitchEnableWirelessV1 struct { 2369 /* Flags to enable now */ 2370 nowFlags uint8 2371 2372 /* Flags to leave enabled in S3 */ 2373 suspendFlags uint8 2374 } 2375 2376 /*****************************************************************************/ 2377 /* GPIO commands. Only available on EC if write protect has been disabled. */ 2378 2379 /* Set GPIO output value */ 2380 const ecCmdGpioSet = 0x92 2381 2382 /* TYPE */ 2383 type ecParamsGpioSet struct { 2384 name [32]byte 2385 val uint8 2386 } 2387 2388 /* Get GPIO value */ 2389 const ecCmdGpioGet = 0x93 2390 2391 /* TYPE */ 2392 /* Version 0 of input params and response */ 2393 type ecParamsGpioGet struct { 2394 name [32]byte 2395 } 2396 2397 /* TYPE */ 2398 type ecResponseGpioGet struct { 2399 val uint8 2400 } 2401 2402 /* TYPE */ 2403 /* Version 1 of input params and response */ 2404 type ecParamsGpioGetV1 struct { 2405 subcmd uint8 2406 data [32]byte 2407 } 2408 2409 /* TYPE */ 2410 /* later 2411 type ecResponseGpioGetV1 struct { 2412 union { 2413 struct { 2414 uint8 val; 2415 } getValueByName, getCount; 2416 struct { 2417 uint8 val; 2418 char name[32]; 2419 uint32 flags; 2420 } getInfo; 2421 }; 2422 } ; 2423 */ 2424 type gpioGetSubcmd uint8 2425 2426 const ( 2427 ecGpioGetByName gpioGetSubcmd = 0 2428 ecGpioGetCount = 1 2429 ecGpioGetInfo = 2 2430 ) 2431 2432 /*****************************************************************************/ 2433 /* I2C commands. Only available when flash write protect is unlocked. */ 2434 2435 /* 2436 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be 2437 * removed soon. Use ecCmdI2cXfer instead. 2438 */ 2439 2440 /* Read I2C bus */ 2441 const ecCmdI2cRead = 0x94 2442 2443 /* TYPE */ 2444 type ecParamsI2cRead struct { 2445 addr uint16 /* 8-bit address (7-bit shifted << 1) */ 2446 readSize uint8 /* Either 8 or 16. */ 2447 port uint8 2448 offset uint8 2449 } 2450 2451 /* TYPE */ 2452 type ecResponseI2cRead struct { 2453 data uint16 2454 } 2455 2456 /* Write I2C bus */ 2457 const ecCmdI2cWrite = 0x95 2458 2459 /* TYPE */ 2460 type ecParamsI2cWrite struct { 2461 data uint16 2462 addr uint16 /* 8-bit address (7-bit shifted << 1) */ 2463 writeSize uint8 /* Either 8 or 16. */ 2464 port uint8 2465 offset uint8 2466 } 2467 2468 /*****************************************************************************/ 2469 /* Charge state commands. Only available when flash write protect unlocked. */ 2470 2471 /* Force charge state machine to stop charging the battery or force it to 2472 * discharge the battery. 2473 */ 2474 const ecCmdChargeControl = 0x96 2475 const ecVerChargeControl = 1 2476 2477 type ecChargeControlMode uint8 2478 2479 const ( 2480 chargeControlNormal ecChargeControlMode = 0 2481 chargeControlIdle 2482 chargeControlDischarge 2483 ) 2484 2485 /* TYPE */ 2486 type ecParamsChargeControl struct { 2487 mode uint32 /* enum chargeControlMode */ 2488 } 2489 2490 /*****************************************************************************/ 2491 /* Console commands. Only available when flash write protect is unlocked. */ 2492 2493 /* Snapshot console output buffer for use by ecCmdConsoleRead. */ 2494 const ecCmdConsoleSnapshot = 0x97 2495 2496 /* 2497 * Read next chunk of data from saved snapshot. 2498 * 2499 * Response is null-terminated string. Empty string, if there is no more 2500 * remaining output. 2501 */ 2502 const ecCmdConsoleRead = 0x98 2503 2504 /*****************************************************************************/ 2505 2506 /* 2507 * Cut off battery power immediately or after the host has shut down. 2508 * 2509 * return ecResInvalidCommand if unsupported by a board/battery. 2510 * ecResSuccess if the command was successful. 2511 * ecResError if the cut off command failed. 2512 */ 2513 const ecCmdBatteryCutOff = 0x99 2514 2515 const ecBatteryCutoffFlagAtShutdown = (1 << 0) 2516 2517 /* TYPE */ 2518 type ecParamsBatteryCutoff struct { 2519 flags uint8 2520 } 2521 2522 /*****************************************************************************/ 2523 /* USB port mux control. */ 2524 2525 /* 2526 * Switch USB mux or return to automatic switching. 2527 */ 2528 const ecCmdUsbMux = 0x9a 2529 2530 /* TYPE */ 2531 type ecParamsUsbMux struct { 2532 mux uint8 2533 } 2534 2535 /*****************************************************************************/ 2536 /* LDOs / FETs control. */ 2537 2538 type ecLdoState uint8 2539 2540 const ( 2541 ecLdoStateOff ecLdoState = 0 /* the LDO / FET is shut down */ 2542 ecLdoStateOn = 1 /* the LDO / FET is ON / providing power */ 2543 ) 2544 2545 /* 2546 * Switch on/off a LDO. 2547 */ 2548 const ecCmdLdoSet = 0x9b 2549 2550 /* TYPE */ 2551 type ecParamsLdoSet struct { 2552 index uint8 2553 state uint8 2554 } 2555 2556 /* 2557 * Get LDO state. 2558 */ 2559 const ecCmdLdoGet = 0x9c 2560 2561 /* TYPE */ 2562 type ecParamsLdoGet struct { 2563 index uint8 2564 } 2565 2566 /* TYPE */ 2567 type ecResponseLdoGet struct { 2568 state uint8 2569 } 2570 2571 /*****************************************************************************/ 2572 /* Power info. */ 2573 2574 /* 2575 * Get power info. 2576 */ 2577 const ecCmdPowerInfo = 0x9d 2578 2579 /* TYPE */ 2580 type ecResponsePowerInfo struct { 2581 usbDevype uint32 2582 voltageAc uint16 2583 voltageSystem uint16 2584 currentSystem uint16 2585 usbCurrentLimit uint16 2586 } 2587 2588 /*****************************************************************************/ 2589 /* I2C passthru command */ 2590 2591 const ecCmdI2cPassthru = 0x9e 2592 2593 /* Read data; if not present, message is a write */ 2594 const ecI2cFlagRead = (1 << 15) 2595 2596 /* Mask for address */ 2597 const ecI2cAddrMask = 0x3ff 2598 2599 const ( 2600 ecI2cStatusNak = (1 << 0) /* Transfer was not acknowledged */ 2601 ecI2cStatusTimeout = (1 << 1) /* Timeout during transfer */ 2602 ) 2603 2604 /* Any error */ 2605 const ecI2cStatusError = (ecI2cStatusNak | ecI2cStatusTimeout) 2606 2607 /* TYPE */ 2608 type ecParamsI2cPassthruMsg struct { 2609 addrFlags uint16 /* I2C slave address (7 or 10 bits) and flags */ 2610 len uint16 /* Number of bytes to read or write */ 2611 } 2612 2613 /* TYPE */ 2614 type ecParamsI2cPassthru struct { 2615 port uint8 /* I2C port number */ 2616 numMsgs uint8 /* Number of messages */ 2617 msg []ecParamsI2cPassthruMsg 2618 /* Data to write for all messages is concatenated here */ 2619 } 2620 2621 /* TYPE */ 2622 type ecResponseI2cPassthru struct { 2623 i2cStatus uint8 /* Status flags (ecI2cStatus_...) */ 2624 numMsgs uint8 /* Number of messages processed */ 2625 data []uint8 /* Data read by messages concatenated here */ 2626 } 2627 2628 /*****************************************************************************/ 2629 /* Power button hang detect */ 2630 2631 const ecCmdHangDetect = 0x9f 2632 2633 /* Reasons to start hang detection timer */ 2634 /* Power button pressed */ 2635 const ecHangStartOnPowerPress = (1 << 0) 2636 2637 /* Lid closed */ 2638 const ecHangStartOnLidClose = (1 << 1) 2639 2640 /* Lid opened */ 2641 const ecHangStartOnLidOpen = (1 << 2) 2642 2643 /* Start of AP S3->S0 transition (booting or resuming from suspend) */ 2644 const ecHangStartOnResume = (1 << 3) 2645 2646 /* Reasons to cancel hang detection */ 2647 2648 /* Power button released */ 2649 const ecHangStopOnPowerRelease = (1 << 8) 2650 2651 /* Any host command from AP received */ 2652 const ecHangStopOnHostCommand = (1 << 9) 2653 2654 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ 2655 const ecHangStopOnSuspend = (1 << 10) 2656 2657 /* 2658 * If this flag is set, all the other fields are ignored, and the hang detect 2659 * timer is started. This provides the AP a way to start the hang timer 2660 * without reconfiguring any of the other hang detect settings. Note that 2661 * you must previously have configured the timeouts. 2662 */ 2663 const ecHangStartNow = (1 << 30) 2664 2665 /* 2666 * If this flag is set, all the other fields are ignored (including 2667 * ecHangStartNow). This provides the AP a way to stop the hang timer 2668 * without reconfiguring any of the other hang detect settings. 2669 */ 2670 const ecHangStopNow = (1 << 31) 2671 2672 /* TYPE */ 2673 type ecParamsHangDetect struct { 2674 /* Flags; see ecHang_* */ 2675 flags uint32 2676 2677 /* Timeout in msec before generating host event, if enabled */ 2678 hostEventimeoutMsec uint16 2679 2680 /* Timeout in msec before generating warm reboot, if enabled */ 2681 warmRebootimeoutMsec uint16 2682 } 2683 2684 /*****************************************************************************/ 2685 /* Commands for battery charging */ 2686 2687 /* 2688 * This is the single catch-all host command to exchange data regarding the 2689 * charge state machine (v2 and up). 2690 */ 2691 const ecCmdChargeState = 0xa0 2692 2693 /* Subcommands for this host command */ 2694 type chargeStateCommand uint8 2695 2696 const ( 2697 chargeStateCmdGetState chargeStateCommand = iota 2698 chargeStateCmdGetParam 2699 chargeStateCmdSetParam 2700 chargeStateNumCmds 2701 ) 2702 2703 /* 2704 * Known param numbers are defined here. Ranges are reserved for board-specific 2705 * params, which are handled by the particular implementations. 2706 */ 2707 type chargeStateParams uint8 2708 2709 const ( 2710 csParamChgVoltage chargeStateParams = iota /* charger voltage limit */ 2711 csParamChgCurrent /* charger current limit */ 2712 csParamChgInputCurrent /* charger input current limit */ 2713 csParamChgStatus /* charger-specific status */ 2714 csParamChgOption /* charger-specific options */ 2715 /* How many so far? */ 2716 csNumBaseParams 2717 2718 /* Range for CONFIGChargerProfileOverride params */ 2719 csParamCustomProfileMin = 0x10000 2720 csParamCustomProfileMax = 0x1ffff 2721 2722 /* Other custom param ranges go here... */ 2723 ) 2724 2725 /* TYPE */ 2726 /* ler 2727 type ecParamsChargeState struct { 2728 cmd uint8 /* enum chargeStateCommand * / 2729 union { 2730 struct { 2731 /* no args * / 2732 } getState; 2733 2734 struct { 2735 uint32 param; /* enum chargeStateParam * / 2736 } getParam; 2737 2738 struct { 2739 uint32 param; /* param to set * / 2740 uint32 value; /* value to set * / 2741 } setParam; 2742 }; 2743 } ; 2744 2745 /* TYPE */ 2746 /* later 2747 type ecResponseChargeState struct { 2748 union { 2749 struct { 2750 int ac; 2751 int chgVoltage; 2752 int chgCurrent; 2753 int chgInputCurrent; 2754 int battStateOfCharge; 2755 } getState; 2756 2757 struct { 2758 uint32 value; 2759 } getParam; 2760 struct { 2761 /* no return values * 2762 } setParam; 2763 }; 2764 } ; 2765 */ 2766 2767 /* 2768 * Set maximum battery charging current. 2769 */ 2770 const ecCmdChargeCurrentLimit = 0xa1 2771 2772 /* TYPE */ 2773 type ecParamsCurrentLimit struct { 2774 limit uint32 /* in mA */ 2775 } 2776 2777 /* 2778 * Set maximum external power current. 2779 */ 2780 const ecCmdExtPowerCurrentLimit = 0xa2 2781 2782 /* TYPE */ 2783 type ecParamsExtPowerCurrentLimit struct { 2784 limit uint32 /* in mA */ 2785 } 2786 2787 /*****************************************************************************/ 2788 /* Smart battery pass-through */ 2789 2790 /* Get / Set 16-bit smart battery registers */ 2791 const ecCmdSbReadWord = 0xb0 2792 const ecCmdSbWriteWord = 0xb1 2793 2794 /* Get / Set string smart battery parameters 2795 * formatted as SMBUS "block". 2796 */ 2797 const ecCmdSbReadBlock = 0xb2 2798 const ecCmdSbWriteBlock = 0xb3 2799 2800 /* TYPE */ 2801 type ecParamsSbRd struct { 2802 reg uint8 2803 } 2804 2805 /* TYPE */ 2806 type ecResponseSbRdWord struct { 2807 value uint16 2808 } 2809 2810 /* TYPE */ 2811 type ecParamsSbWrWord struct { 2812 reg uint8 2813 value uint16 2814 } 2815 2816 /* TYPE */ 2817 type ecResponseSbRdBlock struct { 2818 data [32]uint8 2819 } 2820 2821 /* TYPE */ 2822 type ecParamsSbWrBlock struct { 2823 reg uint8 2824 data [32]uint16 2825 } 2826 2827 /*****************************************************************************/ 2828 /* Battery vendor parameters 2829 * 2830 * Get or set vendor-specific parameters in the battery. Implementations may 2831 * differ between boards or batteries. On a set operation, the response 2832 * contains the actual value set, which may be rounded or clipped from the 2833 * requested value. 2834 */ 2835 2836 const ecCmdBatteryVendorParam = 0xb4 2837 2838 type ecBatteryVendorParamMode uint8 2839 2840 const ( 2841 batteryVendorParamModeGet ecBatteryVendorParamMode = 0 2842 batteryVendorParamModeSet 2843 ) 2844 2845 /* TYPE */ 2846 type ecParamsBatteryVendorParam struct { 2847 param uint32 2848 value uint32 2849 mode uint8 2850 } 2851 2852 /* TYPE */ 2853 type ecResponseBatteryVendorParam struct { 2854 value uint32 2855 } 2856 2857 /*****************************************************************************/ 2858 /* 2859 * Smart Battery Firmware Update Commands 2860 */ 2861 const ecCmdSbFwUpdate = 0xb5 2862 2863 type ecSbFwUpdateSubcmd uint8 2864 2865 const ( 2866 ecSbFwUpdatePrepare ecSbFwUpdateSubcmd = 0x0 2867 ecSbFwUpdateInfo = 0x1 /*query sb info */ 2868 ecSbFwUpdateBegin = 0x2 /*check if protected */ 2869 ecSbFwUpdateWrite = 0x3 /*check if protected */ 2870 ecSbFwUpdateEnd = 0x4 2871 ecSbFwUpdateStatus = 0x5 2872 ecSbFwUpdateProtect = 0x6 2873 ecSbFwUpdateMax = 0x7 2874 ) 2875 2876 const ( 2877 sbFwUpdateCmdWriteBlockSize = 32 2878 sbFwUpdateCmdStatusSize = 2 2879 sbFwUpdateCmdInfoSize = 8 2880 ) 2881 2882 /* TYPE */ 2883 type ecSbFwUpdateHeader struct { 2884 subcmd uint16 /* enum ecSbFwUpdateSubcmd */ 2885 fwID uint16 /* firmware id */ 2886 } 2887 2888 /* TYPE */ 2889 type ecParamsSbFwUpdate struct { 2890 hdr ecSbFwUpdateHeader 2891 /* no args. */ 2892 /* ecSbFwUpdatePrepare = 0x0 */ 2893 /* ecSbFwUpdateInfo = 0x1 */ 2894 /* ecSbFwUpdateBegin = 0x2 */ 2895 /* ecSbFwUpdateEnd = 0x4 */ 2896 /* ecSbFwUpdateStatus = 0x5 */ 2897 /* ecSbFwUpdateProtect = 0x6 */ 2898 /* or ... */ 2899 /* ecSbFwUpdateWrite = 0x3 */ 2900 data [sbFwUpdateCmdWriteBlockSize]uint8 2901 } 2902 2903 /* TYPE */ 2904 type ecResponseSbFwUpdate struct { 2905 data []uint8 2906 /* ecSbFwUpdateInfo = 0x1 */ 2907 //uint8 data[SBFwUpdateCmdInfoSize]; 2908 /* ecSbFwUpdateStatus = 0x5 */ 2909 //uint8 data[SBFwUpdateCmdStatusSize]; 2910 } 2911 2912 /* 2913 * Entering Verified Boot Mode Command 2914 * Default mode is VBOOTModeNormal if EC did not receive this command. 2915 * Valid Modes are: normal, developer, and recovery. 2916 */ 2917 const ecCmdEnteringMode = 0xb6 2918 2919 /* TYPE */ 2920 type ecParamsEnteringMode struct { 2921 vbootMode int 2922 } 2923 2924 const ( 2925 vbootModeNormal = 0 2926 vbootModeDeveloper = 1 2927 vbootModeRecovery = 2 2928 ) 2929 2930 /*****************************************************************************/ 2931 /* System commands */ 2932 2933 /* 2934 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't 2935 * necessarily reboot the EC. Rename to "image" or something similar? 2936 */ 2937 const ecCmdRebootEc = 0xd2 2938 2939 /* Command */ 2940 type ecRebootCmd uint8 2941 2942 const ( 2943 ecRebootCancel ecRebootCmd = 0 /* Cancel a pending reboot */ 2944 ecRebootJumpRo = 1 /* Jump to RO without rebooting */ 2945 ecRebootJumpRw = 2 /* Jump to RW without rebooting */ 2946 /* (command 3 was jump to RW-B) */ 2947 ecRebootCold = 4 /* Cold-reboot */ 2948 ecRebootDisableJump = 5 /* Disable jump until next reboot */ 2949 ecRebootHibernate = 6 /* Hibernate EC */ 2950 ) 2951 2952 /* Flags for ecParamsRebootEc.rebootFlags */ 2953 const ecRebootFlagReserved0 = (1 << 0) /* Was recovery request */ 2954 const ecRebootFlagOnApShutdown = (1 << 1) /* Reboot after AP shutdown */ 2955 2956 /* TYPE */ 2957 type ecParamsRebootEc struct { 2958 cmd uint8 /* enum ecRebootCmd */ 2959 flags uint8 /* See ecRebootFlag_* */ 2960 } 2961 2962 /* 2963 * Get information on last EC panic. 2964 * 2965 * Returns variable-length platform-dependent panic information. See panic.h 2966 * for details. 2967 */ 2968 const ecCmdGetPanicInfo = 0xd3 2969 2970 /*****************************************************************************/ 2971 /* 2972 * Special commands 2973 * 2974 * These do not follow the normal rules for commands. See each command for 2975 * details. 2976 */ 2977 2978 /* 2979 * Reboot NOW 2980 * 2981 * This command will work even when the EC LPC interface is busy, because the 2982 * reboot command is processed at interrupt level. Note that when the EC 2983 * reboots, the host will reboot too, so there is no response to this command. 2984 * 2985 * Use ecCmdRebootEc to reboot the EC more politely. 2986 */ 2987 const ecCmdReboot = 0xd1 /* Think "die" */ 2988 2989 /* 2990 * Resend last response (not supported on LPC). 2991 * 2992 * Returns ecResUnavailable if there is no response available - for example 2993 * there was no previous command, or the previous command's response was too 2994 * big to save. 2995 */ 2996 const ecCmdResendResponse = 0xdb 2997 2998 /* 2999 * This header byte on a command indicate version 0. Any header byte less 3000 * than this means that we are talking to an old EC which doesn't support 3001 * versioning. In that case, we assume version 0. 3002 * 3003 * Header bytes greater than this indicate a later version. For example 3004 * ecCmdVersion0 + 1 means we are using version 1. 3005 * 3006 * The old EC interface must not use commands 0xdc or higher. 3007 */ 3008 const ecCmdVersion0 = 0xdc 3009 3010 /*****************************************************************************/ 3011 /* 3012 * PD commands 3013 * 3014 * These commands are for PD MCU communication. 3015 */ 3016 3017 /* EC to PD MCU exchange status command */ 3018 const ecCmdPdExchangeStatus = 0x100 3019 3020 type pdChargeState uint8 3021 3022 const ( 3023 pdChargeNoChange pdChargeState = 0 /* Don't change charge state */ 3024 pdChargeNone /* No charging allowed */ 3025 pdCharge5v /* 5V charging only */ 3026 pdChargeMax /* Charge at max voltage */ 3027 ) 3028 3029 /* TYPE */ 3030 /* Status of EC being sent to PD */ 3031 type ecParamsPdStatus struct { 3032 battSoc int8 /* battery state of charge */ 3033 chargeState uint8 /* charging state (from enum pdChargeState) */ 3034 } 3035 3036 /* Status of PD being sent back to EC */ 3037 const ( 3038 pdStatusHostEvent = (1 << 0) /* Forward host event to AP */ 3039 pdStatusInRw = (1 << 1) /* Running RW image */ 3040 pdStatusJumpedToImage = (1 << 2) /* Current image was jumped to */ 3041 ) 3042 3043 /* TYPE */ 3044 type ecResponsePdStatus struct { 3045 status uint32 /* PD MCU status */ 3046 currLimMa uint32 /* input current limit */ 3047 activeChargePort int32 /* active charging port */ 3048 } 3049 3050 /* AP to PD MCU host event status command, cleared on read */ 3051 const ecCmdPdHostEventStatus = 0x104 3052 3053 /* PD MCU host event status bits */ 3054 const ( 3055 pdEventUpdateDevice = (1 << 0) 3056 pdEventPowerChange = (1 << 1) 3057 pdEventIdentityReceived = (1 << 2) 3058 ) 3059 3060 /* TYPE */ 3061 type ecResponseHostEventStatus struct { 3062 status uint32 /* PD MCU host event status */ 3063 } 3064 3065 /* Set USB type-C port role and muxes */ 3066 const ecCmdUsbPdControl = 0x101 3067 3068 type usbPdControlRole uint8 3069 3070 const ( 3071 usbPdCtrlRoleNoChange usbPdControlRole = 0 3072 usbPdCtrlRoleToggleOn = 1 /* == AUTO */ 3073 usbPdCtrlRoleToggleOff = 2 3074 usbPdCtrlRoleForceSink = 3 3075 usbPdCtrlRoleForceSource = 4 3076 usbPdCtrlRoleCount 3077 ) 3078 3079 type usbPdControlMux uint8 3080 3081 const ( 3082 usbPdCtrlMuxNoChange usbPdControlMux = 0 3083 usbPdCtrlMuxNone = 1 3084 usbPdCtrlMuxUsb = 2 3085 usbPdCtrlMuxDp = 3 3086 usbPdCtrlMuxDock = 4 3087 usbPdCtrlMuxAuto = 5 3088 usbPdCtrlMuxCount 3089 ) 3090 3091 /* TYPE */ 3092 type ecParamsUsbPdControl struct { 3093 port uint8 3094 role uint8 3095 mux uint8 3096 } 3097 3098 /* TYPE */ 3099 type ecResponseUsbPdControl struct { 3100 enabled uint8 3101 role uint8 3102 polarity uint8 3103 state uint8 3104 } 3105 3106 /* TYPE */ 3107 type ecResponseUsbPdControlV1 struct { 3108 enabled uint8 3109 role uint8 /* [0] power: 0=SNK/1=SRC [1] data: 0=UFP/1=DFP */ 3110 polarity uint8 3111 state [32]byte 3112 } 3113 3114 const ecCmdUsbPdPorts = 0x102 3115 3116 /* TYPE */ 3117 type ecResponseUsbPdPorts struct { 3118 numPorts uint8 3119 } 3120 3121 const ecCmdUsbPdPowerInfo = 0x103 3122 3123 const pdPowerChargingPort = 0xff 3124 3125 /* TYPE */ 3126 type ecParamsUsbPdPowerInfo struct { 3127 port uint8 3128 } 3129 3130 type usbChgType uint8 3131 3132 const ( 3133 usbChgTypeNone usbChgType = iota 3134 usbChgTypePd 3135 usbChgTypeC 3136 usbChgTypeProprietary 3137 usbChgTypeBc12Dcp 3138 usbChgTypeBc12Cdp 3139 usbChgTypeBc12Sdp 3140 usbChgTypeOther 3141 usbChgTypeVbus 3142 usbChgTypeUnknown 3143 ) 3144 3145 type usbPowerRoles uint8 3146 3147 const ( 3148 usbPdPortPowerDisconnected usbPowerRoles = iota 3149 usbPdPortPowerSource 3150 usbPdPortPowerSink 3151 usbPdPortPowerSinkNotCharging 3152 ) 3153 3154 /* TYPE */ 3155 type usbChgMeasures struct { 3156 voltageMax uint16 3157 voltageNow uint16 3158 currentMax uint16 3159 currentLim uint16 3160 } 3161 3162 /* TYPE */ 3163 type ecResponseUsbPdPowerInfo struct { 3164 role uint8 3165 etype uint8 3166 dualrole uint8 3167 reserved1 uint8 3168 meas usbChgMeasures 3169 maxPower uint32 3170 } 3171 3172 /* Write USB-PD device FW */ 3173 const ecCmdUsbPdFwUpdate = 0x110 3174 3175 type usbPdFwUpdateCmds uint8 3176 3177 const ( 3178 usbPdFwReboot usbPdFwUpdateCmds = iota 3179 usbPdFwFlashErase 3180 usbPdFwFlashWrite 3181 usbPdFwEraseSig 3182 ) 3183 3184 /* TYPE */ 3185 type ecParamsUsbPdFwUpdate struct { 3186 devID uint16 3187 cmd uint8 3188 port uint8 3189 size uint32 /* Size to write in bytes */ 3190 /* Followed by data to write */ 3191 } 3192 3193 /* Write USB-PD Accessory RWHash table entry */ 3194 const ecCmdUsbPdRwHashEntry = 0x111 3195 3196 /* RW hash is first 20 bytes of SHA-256 of RW section */ 3197 const pdRwHashSize = 20 3198 3199 /* TYPE */ 3200 type ecParamsUsbPdRwHashEntry struct { 3201 devID uint16 3202 devRwHash [pdRwHashSize]uint8 3203 reserved uint8 /* For alignment of currentImage */ 3204 currentImage uint32 /* One of ecCurrentImage */ 3205 } 3206 3207 /* Read USB-PD Accessory info */ 3208 const ecCmdUsbPdDevInfo = 0x112 3209 3210 /* TYPE */ 3211 type ecParamsUsbPdInfoRequest struct { 3212 port uint8 3213 } 3214 3215 /* Read USB-PD Device discovery info */ 3216 const ecCmdUsbPdDiscovery = 0x113 3217 3218 /* TYPE */ 3219 type ecParamsUsbPdDiscoveryEntry struct { 3220 vid uint16 /* USB-IF VID */ 3221 pid uint16 /* USB-IF PID */ 3222 ptype uint8 /* product type (hub,periph,cable,ama) */ 3223 } 3224 3225 /* Override default charge behavior */ 3226 const ecCmdPdChargePortOverride = 0x114 3227 3228 /* Negative port parameters have special meaning */ 3229 type usbPdOverridePorts int8 3230 3231 const ( 3232 overrideDontCharge usbPdOverridePorts = -2 3233 overrideOff = -1 3234 /* [0, pdPortCount): Port# */ 3235 ) 3236 3237 /* TYPE */ 3238 type ecParamsChargePortOverride struct { 3239 overridePort int16 /* Override port# */ 3240 } 3241 3242 /* Read (and delete) one entry of PD event log */ 3243 const ecCmdPdGetLogEntry = 0x115 3244 3245 /* TYPE */ 3246 type ecResponsePdLog struct { 3247 timestamp uint32 /* relative timestamp in milliseconds */ 3248 etype uint8 /* event type : see pdEventXx below */ 3249 sizePort uint8 /* [7:5] port number [4:0] payload size in bytes */ 3250 data uint16 /* type-defined data payload */ 3251 payload []uint8 /* optional additional data payload: 0..16 bytes */ 3252 } 3253 3254 /* The timestamp is the microsecond counter shifted to get about a ms. */ 3255 const ( 3256 pdLogTimestampShift = 10 /* 1 LSB = 1024us */ 3257 pdLogSizeMask = 0x1F 3258 pdLogPortMask = 0xE0 3259 pdLogPortShift = 5 3260 ) 3261 3262 func pdLogPortSize(port, size uint8) uint8 { 3263 return (port << pdLogPortShift) | (size & pdLogSizeMask) 3264 } 3265 3266 func pdLogPort(sizePort uint8) uint8 { 3267 return sizePort >> pdLogPortShift 3268 } 3269 3270 func pdLogSize(sizePort uint8) uint8 { 3271 return sizePort & pdLogSizeMask 3272 } 3273 3274 /* PD event log : entry types */ 3275 /* PD MCU events */ 3276 const ( 3277 pdEventMcuBase = 0x00 3278 pdEventMcuCharge = (pdEventMcuBase + 0) 3279 pdEventMcuConnect = (pdEventMcuBase + 1) 3280 ) 3281 3282 /* Reserved for custom board event */ 3283 const pdEventMcuBoardCustom = (pdEventMcuBase + 2) 3284 3285 /* PD generic accessory events */ 3286 const ( 3287 pdEventAccBase = 0x20 3288 pdEventAccRwFail = (pdEventAccBase + 0) 3289 pdEventAccRwErase = (pdEventAccBase + 1) 3290 ) 3291 3292 /* PD power supply events */ 3293 const pdEventPsBase = 0x40 3294 const pdEventPsFault = (pdEventPsBase + 0) 3295 3296 /* PD video dongles events */ 3297 const ( 3298 pdEventVideoBase = 0x60 3299 pdEventVideoDpMode = (pdEventVideoBase + 0) 3300 pdEventVideoCodec = (pdEventVideoBase + 1) 3301 ) 3302 3303 /* Returned in the "type" field, when there is no entry available */ 3304 const pdEventNoEntry = 0xFF 3305 3306 /* 3307 * pdEventMcuCharge event definition : 3308 * the payload is "struct usbChgMeasures" 3309 * the data field contains the port state flags as defined below : 3310 */ 3311 /* Port partner is a dual role device */ 3312 const chargeFlagsDualRole = (1 << 15) 3313 3314 /* Port is the pending override port */ 3315 const chargeFlagsDelayedOverride = (1 << 14) 3316 3317 /* Port is the override port */ 3318 const chargeFlagsOverride = (1 << 13) 3319 3320 /* Charger type */ 3321 const chargeFlagsTypeShift = 3 3322 const chargeFlagsTypeMask = (0xF << chargeFlagsTypeShift) 3323 3324 /* Power delivery role */ 3325 const chargeFlagsRoleMask = (7 << 0) 3326 3327 /* 3328 * pdEventPsFault data field flags definition : 3329 */ 3330 const ( 3331 psFaultOcp = 1 3332 psFaultFastOcp = 2 3333 psFaultOvp = 3 3334 psFaultDisch = 4 3335 ) 3336 3337 /* TYPE */ 3338 /* 3339 * pdEventVideoCodec payload is "struct mcdpInfo". 3340 */ 3341 type mcdpVersion struct { 3342 major uint8 3343 minor uint8 3344 build uint16 3345 } 3346 3347 /* TYPE */ 3348 type mcdpInfo struct { 3349 family [2]uint8 3350 chipid [2]uint8 3351 irom mcdpVersion 3352 fw mcdpVersion 3353 } 3354 3355 /* struct mcdpInfo field decoding */ 3356 func mcdpChipid(chipid []uint8) uint16 { 3357 return (uint16(chipid[0]) << 8) | uint16(chipid[1]) 3358 } 3359 3360 func mcdpFamily(family []uint8) uint16 { 3361 return (uint16(family[0]) << 8) | uint16(family[1]) 3362 } 3363 3364 /* Get/Set USB-PD Alternate mode info */ 3365 const ecCmdUsbPdGetAmode = 0x116 3366 3367 /* TYPE */ 3368 type ecParamsUsbPdGetModeRequest struct { 3369 svidIdx uint16 /* SVID index to get */ 3370 port uint8 /* port */ 3371 } 3372 3373 /* TYPE */ 3374 type ecParamsUsbPdGetModeResponse struct { 3375 svid uint16 /* SVID */ 3376 opos uint16 /* Object Position */ 3377 vdo [6]uint32 /* Mode VDOs */ 3378 } 3379 3380 const ecCmdUsbPdSetAmode = 0x117 3381 3382 type pdModeCmd uint8 3383 3384 const ( 3385 pdExitMode pdModeCmd = 0 3386 pdEnterMode = 1 3387 /* Not a command. Do NOT remove. */ 3388 pdModeCmdCount 3389 ) 3390 3391 /* TYPE */ 3392 type ecParamsUsbPdSetModeRequest struct { 3393 cmd uint32 /* enum pdModeCmd */ 3394 svid uint16 /* SVID to set */ 3395 opos uint8 /* Object Position */ 3396 port uint8 /* port */ 3397 } 3398 3399 /* Ask the PD MCU to record a log of a requested type */ 3400 const ecCmdPdWriteLogEntry = 0x118 3401 3402 /* TYPE */ 3403 type ecParamsPdWriteLogEntry struct { 3404 etype uint8 /* event type : see pdEventXx above */ 3405 port uint8 /* port#, or 0 for events unrelated to a given port */ 3406 } 3407 3408 /*****************************************************************************/ 3409 /* 3410 * Passthru commands 3411 * 3412 * Some platforms have sub-processors chained to each other. For example. 3413 * 3414 * AP <--> EC <--> PD MCU 3415 * 3416 * The top 2 bits of the command number are used to indicate which device the 3417 * command is intended for. Device 0 is always the device receiving the 3418 * command; other device mapping is board-specific. 3419 * 3420 * When a device receives a command to be passed to a sub-processor, it passes 3421 * it on with the device number set back to 0. This allows the sub-processor 3422 * to remain blissfully unaware of whether the command originated on the next 3423 * device up the chain, or was passed through from the AP. 3424 * 3425 * In the above example, if the AP wants to send command 0x0002 to the PD MCU 3426 * AP sends command 0x4002 to the EC 3427 * EC sends command 0x0002 to the PD MCU 3428 * EC forwards PD MCU response back to the AP 3429 */ 3430 3431 /* Offset and max command number for sub-device n */ 3432 func ecCmdPassthruOffset(n uint) uint { 3433 return 0x4000 * n 3434 } 3435 3436 func ecCmdPassthruMax(n uint) uint { 3437 return ecCmdPassthruOffset(n) + 0x3fff 3438 } 3439 3440 /*****************************************************************************/ 3441 /* 3442 * Deprecated constants. These constants have been renamed for clarity. The 3443 * meaning and size has not changed. Programs that use the old names should 3444 * switch to the new names soon, as the old names may not be carried forward 3445 * forever. 3446 */ 3447 const ( 3448 ecHostParamSize = ecProto2MaxParamSize 3449 ecLpcAddrOldParam = ecHostCmdRegion1 3450 ecOldParamSize = ecHostCmdRegionSize 3451 ) 3452 3453 func ecVerMask(version uint8) uint8 { 3454 /* Command version mask */ 3455 return 1 << version 3456 }