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