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 | |
| 34 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 35 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 36 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 37 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 38 | * determined in other ways. Remove this once the kernel code no longer |
| 39 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 40 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 41 | #define EC_PROTO_VERSION 0x00000002 |
| 42 | |
| 43 | /* Command version mask */ |
| 44 | #define EC_VER_MASK(version) (1UL << (version)) |
| 45 | |
| 46 | /* I/O addresses for ACPI commands */ |
| 47 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 48 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
| 49 | |
| 50 | /* I/O addresses for host command */ |
| 51 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 52 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
| 53 | |
| 54 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 55 | /* Protocol version 2 */ |
| 56 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
| 57 | #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is |
| 58 | * EC_PROTO2_MAX_PARAM_SIZE */ |
| 59 | /* Protocol version 3 */ |
| 60 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 61 | #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] | 62 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 63 | /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 64 | * and they tell the kernel that so we have to think of it as two parts. */ |
| 65 | #define EC_HOST_CMD_REGION0 0x800 |
| 66 | #define EC_HOST_CMD_REGION1 0x880 |
| 67 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
| 68 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 69 | /* EC command register bit functions */ |
| 70 | #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */ |
| 71 | #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */ |
| 72 | #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */ |
| 73 | #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */ |
| 74 | #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */ |
| 75 | #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */ |
| 76 | #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */ |
| 77 | |
| 78 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 79 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 80 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
| 81 | |
| 82 | /* The offset address of each type of data in mapped memory. */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 83 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 84 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 85 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 86 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 87 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 88 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 89 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
| 90 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
| 91 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 92 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
| 93 | /* Unused 0x28 - 0x2f */ |
| 94 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
| 95 | /* Unused 0x31 - 0x33 */ |
| 96 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */ |
| 97 | /* Reserve 0x38 - 0x3f for additional host event-related stuff */ |
| 98 | /* Battery values are all 32 bits */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 99 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 100 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 101 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
| 102 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */ |
| 103 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 104 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 105 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 106 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 107 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 108 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 109 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 110 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 111 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 112 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
| 113 | /* Unused 0x84 - 0x8f */ |
| 114 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
| 115 | /* Unused 0x91 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 116 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
| 117 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 118 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 119 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 120 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 121 | /* Unused 0xa6 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 122 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 123 | /* |
| 124 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 125 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 126 | * which might be needed by ACPI. |
| 127 | */ |
| 128 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 129 | |
| 130 | /* Define the format of the accelerometer mapped memory status byte. */ |
| 131 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
| 132 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4) |
| 133 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 134 | |
| 135 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
| 136 | #define EC_TEMP_SENSOR_ENTRIES 16 |
| 137 | /* |
| 138 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 139 | * |
| 140 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 141 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 142 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 143 | |
| 144 | /* Special values for mapped temperature sensors */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 145 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 146 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 147 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 148 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 149 | /* |
| 150 | * The offset of temperature value stored in mapped memory. This allows |
| 151 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 152 | */ |
| 153 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 154 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 155 | /* |
| 156 | * Number of ALS readings at EC_MEMMAP_ALS |
| 157 | */ |
| 158 | #define EC_ALS_ENTRIES 2 |
| 159 | |
| 160 | /* |
| 161 | * The default value a temperature sensor will return when it is present but |
| 162 | * has not been read this boot. This is a reasonable number to avoid |
| 163 | * triggering alarms on the host. |
| 164 | */ |
| 165 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 166 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 167 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 168 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 169 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 170 | |
| 171 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 172 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 173 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 174 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 175 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 176 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
| 177 | |
| 178 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 179 | #define EC_SWITCH_LID_OPEN 0x01 |
| 180 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 181 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 182 | /* Was recovery requested via keyboard; now unused. */ |
| 183 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 184 | /* Recovery requested via dedicated signal (from servo board) */ |
| 185 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 186 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 187 | #define EC_SWITCH_IGNORE0 0x20 |
| 188 | |
| 189 | /* Host command interface flags */ |
| 190 | /* Host command interface supports LPC args (LPC interface only) */ |
| 191 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 192 | /* Host command interface supports version 3 protocol */ |
| 193 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 194 | |
| 195 | /* Wireless switch flags */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 196 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 197 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 198 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 199 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 200 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 201 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 202 | /*****************************************************************************/ |
| 203 | /* |
| 204 | * ACPI commands |
| 205 | * |
| 206 | * These are valid ONLY on the ACPI command/data port. |
| 207 | */ |
| 208 | |
| 209 | /* |
| 210 | * ACPI Read Embedded Controller |
| 211 | * |
| 212 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 213 | * |
| 214 | * Use the following sequence: |
| 215 | * |
| 216 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 217 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 218 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 219 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 220 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 221 | */ |
| 222 | #define EC_CMD_ACPI_READ 0x80 |
| 223 | |
| 224 | /* |
| 225 | * ACPI Write Embedded Controller |
| 226 | * |
| 227 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 228 | * |
| 229 | * Use the following sequence: |
| 230 | * |
| 231 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 232 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 233 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 234 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 235 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 236 | */ |
| 237 | #define EC_CMD_ACPI_WRITE 0x81 |
| 238 | |
| 239 | /* |
| 240 | * ACPI Burst Enable Embedded Controller |
| 241 | * |
| 242 | * This enables burst mode on the EC to allow the host to issue several |
| 243 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 244 | * data are locked out to ensure data consistency. |
| 245 | */ |
| 246 | #define EC_CMD_ACPI_BURST_ENABLE 0x82 |
| 247 | |
| 248 | /* |
| 249 | * ACPI Burst Disable Embedded Controller |
| 250 | * |
| 251 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 252 | * multi-byte data. |
| 253 | */ |
| 254 | #define EC_CMD_ACPI_BURST_DISABLE 0x83 |
| 255 | |
| 256 | /* |
| 257 | * ACPI Query Embedded Controller |
| 258 | * |
| 259 | * This clears the lowest-order bit in the currently pending host events, and |
| 260 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 261 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 262 | */ |
| 263 | #define EC_CMD_ACPI_QUERY_EVENT 0x84 |
| 264 | |
| 265 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 266 | |
| 267 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 268 | #define EC_ACPI_MEM_VERSION 0x00 |
| 269 | /* |
| 270 | * Test location; writing value here updates test compliment byte to (0xff - |
| 271 | * value). |
| 272 | */ |
| 273 | #define EC_ACPI_MEM_TEST 0x01 |
| 274 | /* Test compliment; writes here are ignored. */ |
| 275 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
| 276 | |
| 277 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 278 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 279 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 280 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 281 | |
| 282 | /* |
| 283 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 284 | * independent thresholds attached to them. The current value of the ID |
| 285 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 286 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 287 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 288 | * |
| 289 | * The spec does not mandate any way to read back the threshold settings |
| 290 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 291 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 292 | * returns one sensor ID that has crossed one of its threshold (in either |
| 293 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 294 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 295 | * the unread event count for that sensor. |
| 296 | */ |
| 297 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 298 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 299 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 300 | /* |
| 301 | * Here are the bits for the COMMIT register: |
| 302 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 303 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 304 | * Each write to the commit register affects one threshold. |
| 305 | */ |
| 306 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0) |
| 307 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1) |
| 308 | /* |
| 309 | * Example: |
| 310 | * |
| 311 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 312 | * write 2 to [0x05] -- select temp sensor 2 |
| 313 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 314 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 315 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 316 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 317 | * |
| 318 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 319 | * write 2 to [0x05] -- select temp sensor 2 |
| 320 | * write 0x1 to [0x07] -- disable threshold 1 |
| 321 | */ |
| 322 | |
| 323 | /* DPTF battery charging current limit */ |
| 324 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 325 | |
| 326 | /* Charging limit is specified in 64 mA steps */ |
| 327 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 328 | /* Value to disable DPTF battery charging limit */ |
| 329 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
| 330 | |
| 331 | /* |
| 332 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 333 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 334 | */ |
| 335 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 336 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 337 | |
| 338 | /* Current version of ACPI memory address space */ |
| 339 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 340 | |
| 341 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 342 | /* |
| 343 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 344 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 345 | * handle actual C code so keep it separate. |
| 346 | */ |
| 347 | #ifndef __ACPI__ |
| 348 | |
Alexandru Gagniuc | 0d3a512 | 2016-04-26 14:53:46 -0700 | [diff] [blame] | 349 | #include <stdint.h> |
| 350 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 351 | /* |
| 352 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 353 | * checking prefers __packed over __attribute__((packed)). |
| 354 | */ |
| 355 | #ifndef __packed |
| 356 | #define __packed __attribute__((packed)) |
| 357 | #endif |
| 358 | |
| 359 | /* LPC command status byte masks */ |
| 360 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 361 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 362 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 363 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 364 | /* EC is processing a command */ |
| 365 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 366 | /* Last write to EC was a command, not data */ |
| 367 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 368 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 369 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 370 | /* SCI event is pending (requesting SCI query) */ |
| 371 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 372 | /* SMI event is pending (requesting SMI query) */ |
| 373 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 374 | /* (reserved) */ |
| 375 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 376 | |
| 377 | /* |
| 378 | * EC is busy. This covers both the EC processing a command, and the host has |
| 379 | * written a new command but the EC hasn't picked it up yet. |
| 380 | */ |
| 381 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 382 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 383 | |
| 384 | /* Host command response codes */ |
| 385 | enum ec_status { |
| 386 | EC_RES_SUCCESS = 0, |
| 387 | EC_RES_INVALID_COMMAND = 1, |
| 388 | EC_RES_ERROR = 2, |
| 389 | EC_RES_INVALID_PARAM = 3, |
| 390 | EC_RES_ACCESS_DENIED = 4, |
| 391 | EC_RES_INVALID_RESPONSE = 5, |
| 392 | EC_RES_INVALID_VERSION = 6, |
| 393 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 394 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 395 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 396 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 397 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 398 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 399 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 400 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 401 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
| 402 | EC_RES_BUSY = 16 /* Up but too busy. Should retry */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | /* |
| 406 | * Host event codes. Note these are 1-based, not 0-based, because ACPI query |
| 407 | * EC command uses code 0 to mean "no event pending". We explicitly specify |
| 408 | * each value in the enum listing so they won't change if we delete/insert an |
| 409 | * item or rearrange the list (it needs to be stable across platforms, not |
| 410 | * just within a single compiled instance). |
| 411 | */ |
| 412 | enum host_event_code { |
| 413 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 414 | EC_HOST_EVENT_LID_OPEN = 2, |
| 415 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 416 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 417 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 418 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 419 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 420 | EC_HOST_EVENT_BATTERY = 8, |
| 421 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
| 422 | EC_HOST_EVENT_THERMAL_OVERLOAD = 10, |
| 423 | EC_HOST_EVENT_THERMAL = 11, |
| 424 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 425 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 426 | /* |
| 427 | * EC has finished initializing the host interface. The host can check |
| 428 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 429 | * determine when the EC is ready to accept subsequent commands. |
| 430 | */ |
| 431 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 432 | /* Keyboard recovery combo has been pressed */ |
| 433 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 434 | |
| 435 | /* Shutdown due to thermal overload */ |
| 436 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 437 | /* Shutdown due to battery level too low */ |
| 438 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 439 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 440 | /* Suggest that the AP throttle itself */ |
| 441 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 442 | /* Suggest that the AP resume normal speed */ |
| 443 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 444 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 445 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 446 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 447 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 448 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 449 | |
| 450 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 451 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 452 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 453 | /* Battery Status flags have changed */ |
| 454 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 455 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 456 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 457 | EC_HOST_EVENT_PANIC = 24, |
| 458 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 459 | /* Keyboard fastboot combo has been pressed */ |
| 460 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 461 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 462 | /* EC RTC event occurred */ |
| 463 | EC_HOST_EVENT_RTC = 26, |
| 464 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 465 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 466 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 467 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 468 | /* |
| 469 | * The high bit of the event mask is not used as a host event code. If |
| 470 | * it reads back as set, then the entire event mask should be |
| 471 | * considered invalid by the host. This can happen when reading the |
| 472 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 473 | * not initialized on the EC, or improperly configured on the host. |
| 474 | */ |
| 475 | EC_HOST_EVENT_INVALID = 32 |
| 476 | }; |
| 477 | /* Host event mask */ |
| 478 | #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1)) |
| 479 | |
| 480 | /* Arguments at EC_LPC_ADDR_HOST_ARGS */ |
| 481 | struct ec_lpc_host_args { |
| 482 | uint8_t flags; |
| 483 | uint8_t command_version; |
| 484 | uint8_t data_size; |
| 485 | /* |
| 486 | * Checksum; sum of command + flags + command_version + data_size + |
| 487 | * all params/response data bytes. |
| 488 | */ |
| 489 | uint8_t checksum; |
| 490 | } __packed; |
| 491 | |
| 492 | /* Flags for ec_lpc_host_args.flags */ |
| 493 | /* |
| 494 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 495 | * params. |
| 496 | * |
| 497 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 498 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 499 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 500 | * withouth setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 501 | */ |
| 502 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 503 | /* |
| 504 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 505 | * |
| 506 | * If EC responds to a command and this flag is not set, this is an old-style |
| 507 | * response. Command version is 0 and response data from EC is at |
| 508 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 509 | */ |
| 510 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 511 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 512 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 513 | /* |
| 514 | * Byte codes returned by EC over SPI interface. |
| 515 | * |
| 516 | * These can be used by the AP to debug the EC interface, and to determine |
| 517 | * when the EC is not in a state where it will ever get around to responding |
| 518 | * to the AP. |
| 519 | * |
| 520 | * Example of sequence of bytes read from EC for a current good transfer: |
| 521 | * 1. - - AP asserts chip select (CS#) |
| 522 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 523 | * 3. - - EC starts handling CS# interrupt |
| 524 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 525 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 526 | * bytes looking for EC_SPI_FRAME_START |
| 527 | * 6. - - EC finishes processing and sets up response |
| 528 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 529 | * 8. (response packet) - AP reads response packet |
| 530 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 531 | * 10 - - AP deasserts chip select |
| 532 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 533 | * next request |
| 534 | * |
| 535 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 536 | * the following byte values: |
| 537 | * EC_SPI_OLD_READY |
| 538 | * EC_SPI_RX_READY |
| 539 | * EC_SPI_RECEIVING |
| 540 | * EC_SPI_PROCESSING |
| 541 | * |
| 542 | * Then the EC found an error in the request, or was not ready for the request |
| 543 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 544 | * because the EC is unable to tell when the AP is done sending its request. |
| 545 | */ |
| 546 | |
| 547 | /* |
| 548 | * Framing byte which precedes a response packet from the EC. After sending a |
| 549 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 550 | * clock in the response packet. |
| 551 | */ |
| 552 | #define EC_SPI_FRAME_START 0xec |
| 553 | |
| 554 | /* |
| 555 | * Padding bytes which are clocked out after the end of a response packet. |
| 556 | */ |
| 557 | #define EC_SPI_PAST_END 0xed |
| 558 | |
| 559 | /* |
| 560 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 561 | * that the AP will send a valid packet header (starting with |
| 562 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 563 | */ |
| 564 | #define EC_SPI_RX_READY 0xf8 |
| 565 | |
| 566 | /* |
| 567 | * EC has started receiving the request from the AP, but hasn't started |
| 568 | * processing it yet. |
| 569 | */ |
| 570 | #define EC_SPI_RECEIVING 0xf9 |
| 571 | |
| 572 | /* EC has received the entire request from the AP and is processing it. */ |
| 573 | #define EC_SPI_PROCESSING 0xfa |
| 574 | |
| 575 | /* |
| 576 | * EC received bad data from the AP, such as a packet header with an invalid |
| 577 | * length. EC will ignore all data until chip select deasserts. |
| 578 | */ |
| 579 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 580 | |
| 581 | /* |
| 582 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 583 | * chip select and started clocking data before the EC was ready to receive it. |
| 584 | * EC will ignore all data until chip select deasserts. |
| 585 | */ |
| 586 | #define EC_SPI_NOT_READY 0xfc |
| 587 | |
| 588 | /* |
| 589 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 590 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 591 | * a fully received packet but is not ready to respond yet. |
| 592 | */ |
| 593 | #define EC_SPI_OLD_READY 0xfd |
| 594 | |
| 595 | /*****************************************************************************/ |
| 596 | |
| 597 | /* |
| 598 | * Protocol version 2 for I2C and SPI send a request this way: |
| 599 | * |
| 600 | * 0 EC_CMD_VERSION0 + (command version) |
| 601 | * 1 Command number |
| 602 | * 2 Length of params = N |
| 603 | * 3..N+2 Params, if any |
| 604 | * N+3 8-bit checksum of bytes 0..N+2 |
| 605 | * |
| 606 | * The corresponding response is: |
| 607 | * |
| 608 | * 0 Result code (EC_RES_*) |
| 609 | * 1 Length of params = M |
| 610 | * 2..M+1 Params, if any |
| 611 | * M+2 8-bit checksum of bytes 0..M+1 |
| 612 | */ |
| 613 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 614 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 615 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 616 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 617 | |
| 618 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 619 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 620 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 621 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 622 | |
| 623 | /* Parameter length was limited by the LPC interface */ |
| 624 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 625 | |
| 626 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 627 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 628 | EC_PROTO2_MAX_PARAM_SIZE) |
| 629 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 630 | EC_PROTO2_MAX_PARAM_SIZE) |
| 631 | |
| 632 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 633 | |
| 634 | /* |
| 635 | * Value written to legacy command port / prefix byte to indicate protocol |
| 636 | * 3+ structs are being used. Usage is bus-dependent. |
| 637 | */ |
| 638 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 639 | |
| 640 | #define EC_HOST_REQUEST_VERSION 3 |
| 641 | |
| 642 | /* Version 3 request from host */ |
| 643 | struct ec_host_request { |
| 644 | /* Struct version (=3) |
| 645 | * |
| 646 | * EC will return EC_RES_INVALID_HEADER if it receives a header with a |
| 647 | * version it doesn't know how to parse. |
| 648 | */ |
| 649 | uint8_t struct_version; |
| 650 | |
| 651 | /* |
| 652 | * Checksum of request and data; sum of all bytes including checksum |
| 653 | * should total to 0. |
| 654 | */ |
| 655 | uint8_t checksum; |
| 656 | |
| 657 | /* Command code */ |
| 658 | uint16_t command; |
| 659 | |
| 660 | /* Command version */ |
| 661 | uint8_t command_version; |
| 662 | |
| 663 | /* Unused byte in current protocol version; set to 0 */ |
| 664 | uint8_t reserved; |
| 665 | |
| 666 | /* Length of data which follows this header */ |
| 667 | uint16_t data_len; |
| 668 | } __packed; |
| 669 | |
| 670 | #define EC_HOST_RESPONSE_VERSION 3 |
| 671 | |
| 672 | /* Version 3 response from EC */ |
| 673 | struct ec_host_response { |
| 674 | /* Struct version (=3) */ |
| 675 | uint8_t struct_version; |
| 676 | |
| 677 | /* |
| 678 | * Checksum of response and data; sum of all bytes including checksum |
| 679 | * should total to 0. |
| 680 | */ |
| 681 | uint8_t checksum; |
| 682 | |
| 683 | /* Result code (EC_RES_*) */ |
| 684 | uint16_t result; |
| 685 | |
| 686 | /* Length of data which follows this header */ |
| 687 | uint16_t data_len; |
| 688 | |
| 689 | /* Unused bytes in current protocol version; set to 0 */ |
| 690 | uint16_t reserved; |
| 691 | } __packed; |
| 692 | |
| 693 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 694 | /* |
| 695 | * Notes on commands: |
| 696 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 697 | * Each command is an 16-bit command value. Commands which take params or |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 698 | * return response data specify structs for that data. If no struct is |
| 699 | * specified, the command does not input or output data, respectively. |
| 700 | * Parameter/response length is implicit in the structs. Some underlying |
| 701 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 702 | * those are implementation-dependent and not defined here. |
| 703 | */ |
| 704 | |
| 705 | /*****************************************************************************/ |
| 706 | /* General / test commands */ |
| 707 | |
| 708 | /* |
| 709 | * Get protocol version, used to deal with non-backward compatible protocol |
| 710 | * changes. |
| 711 | */ |
| 712 | #define EC_CMD_PROTO_VERSION 0x00 |
| 713 | |
| 714 | struct ec_response_proto_version { |
| 715 | uint32_t version; |
| 716 | } __packed; |
| 717 | |
| 718 | /* |
| 719 | * Hello. This is a simple command to test the EC is responsive to |
| 720 | * commands. |
| 721 | */ |
| 722 | #define EC_CMD_HELLO 0x01 |
| 723 | |
| 724 | struct ec_params_hello { |
| 725 | uint32_t in_data; /* Pass anything here */ |
| 726 | } __packed; |
| 727 | |
| 728 | struct ec_response_hello { |
| 729 | uint32_t out_data; /* Output will be in_data + 0x01020304 */ |
| 730 | } __packed; |
| 731 | |
| 732 | /* Get version number */ |
| 733 | #define EC_CMD_GET_VERSION 0x02 |
| 734 | |
| 735 | enum ec_current_image { |
| 736 | EC_IMAGE_UNKNOWN = 0, |
| 737 | EC_IMAGE_RO, |
| 738 | EC_IMAGE_RW |
| 739 | }; |
| 740 | |
| 741 | struct ec_response_get_version { |
| 742 | /* Null-terminated version strings for RO, RW */ |
| 743 | char version_string_ro[32]; |
| 744 | char version_string_rw[32]; |
| 745 | char reserved[32]; /* Was previously RW-B string */ |
| 746 | uint32_t current_image; /* One of ec_current_image */ |
| 747 | } __packed; |
| 748 | |
| 749 | /* Read test */ |
| 750 | #define EC_CMD_READ_TEST 0x03 |
| 751 | |
| 752 | struct ec_params_read_test { |
| 753 | uint32_t offset; /* Starting value for read buffer */ |
| 754 | uint32_t size; /* Size to read in bytes */ |
| 755 | } __packed; |
| 756 | |
| 757 | struct ec_response_read_test { |
| 758 | uint32_t data[32]; |
| 759 | } __packed; |
| 760 | |
| 761 | /* |
| 762 | * Get build information |
| 763 | * |
| 764 | * Response is null-terminated string. |
| 765 | */ |
| 766 | #define EC_CMD_GET_BUILD_INFO 0x04 |
| 767 | |
| 768 | /* Get chip info */ |
| 769 | #define EC_CMD_GET_CHIP_INFO 0x05 |
| 770 | |
| 771 | struct ec_response_get_chip_info { |
| 772 | /* Null-terminated strings */ |
| 773 | char vendor[32]; |
| 774 | char name[32]; |
| 775 | char revision[32]; /* Mask version */ |
| 776 | } __packed; |
| 777 | |
| 778 | /* Get board HW version */ |
| 779 | #define EC_CMD_GET_BOARD_VERSION 0x06 |
| 780 | |
| 781 | struct ec_response_board_version { |
| 782 | uint16_t board_version; /* A monotonously incrementing number. */ |
| 783 | } __packed; |
| 784 | |
| 785 | /* |
| 786 | * Read memory-mapped data. |
| 787 | * |
| 788 | * This is an alternate interface to memory-mapped data for bus protocols |
| 789 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 790 | * |
| 791 | * Response is params.size bytes of data. |
| 792 | */ |
| 793 | #define EC_CMD_READ_MEMMAP 0x07 |
| 794 | |
| 795 | struct ec_params_read_memmap { |
| 796 | uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */ |
| 797 | uint8_t size; /* Size to read in bytes */ |
| 798 | } __packed; |
| 799 | |
| 800 | /* Read versions supported for a command */ |
| 801 | #define EC_CMD_GET_CMD_VERSIONS 0x08 |
| 802 | |
| 803 | struct ec_params_get_cmd_versions { |
| 804 | uint8_t cmd; /* Command to check */ |
| 805 | } __packed; |
| 806 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 807 | struct ec_params_get_cmd_versions_v1 { |
| 808 | uint16_t cmd; /* Command to check */ |
| 809 | } __packed; |
| 810 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 811 | struct ec_response_get_cmd_versions { |
| 812 | /* |
| 813 | * Mask of supported versions; use EC_VER_MASK() to compare with a |
| 814 | * desired version. |
| 815 | */ |
| 816 | uint32_t version_mask; |
| 817 | } __packed; |
| 818 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 819 | /* |
| 820 | * Check EC communcations status (busy). This is needed on i2c/spi but not |
| 821 | * on lpc since it has its own out-of-band busy indicator. |
| 822 | * |
| 823 | * lpc must read the status from the command register. Attempting this on |
| 824 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 825 | */ |
| 826 | #define EC_CMD_GET_COMMS_STATUS 0x09 |
| 827 | |
| 828 | /* Avoid using ec_status which is for return values */ |
| 829 | enum ec_comms_status { |
| 830 | EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */ |
| 831 | }; |
| 832 | |
| 833 | struct ec_response_get_comms_status { |
| 834 | uint32_t flags; /* Mask of enum ec_comms_status */ |
| 835 | } __packed; |
| 836 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 837 | /* Fake a variety of responses, purely for testing purposes. */ |
| 838 | #define EC_CMD_TEST_PROTOCOL 0x0a |
| 839 | |
| 840 | /* Tell the EC what to send back to us. */ |
| 841 | struct ec_params_test_protocol { |
| 842 | uint32_t ec_result; |
| 843 | uint32_t ret_len; |
| 844 | uint8_t buf[32]; |
| 845 | } __packed; |
| 846 | |
| 847 | /* Here it comes... */ |
| 848 | struct ec_response_test_protocol { |
| 849 | uint8_t buf[32]; |
| 850 | } __packed; |
| 851 | |
| 852 | /* Get prococol information */ |
| 853 | #define EC_CMD_GET_PROTOCOL_INFO 0x0b |
| 854 | |
| 855 | /* Flags for ec_response_get_protocol_info.flags */ |
| 856 | /* EC_RES_IN_PROGRESS may be returned if a command is slow */ |
| 857 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) |
| 858 | |
| 859 | struct ec_response_get_protocol_info { |
| 860 | /* Fields which exist if at least protocol version 3 supported */ |
| 861 | |
| 862 | /* Bitmask of protocol versions supported (1 << n means version n)*/ |
| 863 | uint32_t protocol_versions; |
| 864 | |
| 865 | /* Maximum request packet size, in bytes */ |
| 866 | uint16_t max_request_packet_size; |
| 867 | |
| 868 | /* Maximum response packet size, in bytes */ |
| 869 | uint16_t max_response_packet_size; |
| 870 | |
| 871 | /* Flags; see EC_PROTOCOL_INFO_* */ |
| 872 | uint32_t flags; |
| 873 | } __packed; |
| 874 | |
| 875 | |
| 876 | /*****************************************************************************/ |
| 877 | /* Get/Set miscellaneous values */ |
| 878 | |
| 879 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 880 | #define EC_GSV_SET 0x80000000 |
| 881 | |
| 882 | /* The lower three bytes of .flags identifies the parameter, if that has |
| 883 | meaning for an individual command. */ |
| 884 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 885 | |
| 886 | struct ec_params_get_set_value { |
| 887 | uint32_t flags; |
| 888 | uint32_t value; |
| 889 | } __packed; |
| 890 | |
| 891 | struct ec_response_get_set_value { |
| 892 | uint32_t flags; |
| 893 | uint32_t value; |
| 894 | } __packed; |
| 895 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 896 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 897 | #define EC_CMD_GSV_PAUSE_IN_S5 0x0c |
| 898 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 899 | /*****************************************************************************/ |
| 900 | /* List the features supported by the firmware */ |
| 901 | #define EC_CMD_GET_FEATURES 0x0d |
| 902 | |
| 903 | /* Supported features */ |
| 904 | enum ec_feature_code { |
| 905 | /* |
| 906 | * This image contains a limited set of features. Another image |
| 907 | * in RW partition may support more features. |
| 908 | */ |
| 909 | EC_FEATURE_LIMITED = 0, |
| 910 | /* |
| 911 | * Commands for probing/reading/writing/erasing the flash in the |
| 912 | * EC are present. |
| 913 | */ |
| 914 | EC_FEATURE_FLASH = 1, |
| 915 | /* |
| 916 | * Can control the fan speed directly. |
| 917 | */ |
| 918 | EC_FEATURE_PWM_FAN = 2, |
| 919 | /* |
| 920 | * Can control the intensity of the keyboard backlight. |
| 921 | */ |
| 922 | EC_FEATURE_PWM_KEYB = 3, |
| 923 | /* |
| 924 | * Support Google lightbar, introduced on Pixel. |
| 925 | */ |
| 926 | EC_FEATURE_LIGHTBAR = 4, |
| 927 | /* Control of LEDs */ |
| 928 | EC_FEATURE_LED = 5, |
| 929 | /* Exposes an interface to control gyro and sensors. |
| 930 | * The host goes through the EC to access these sensors. |
| 931 | * In addition, the EC may provide composite sensors, like lid angle. |
| 932 | */ |
| 933 | EC_FEATURE_MOTION_SENSE = 6, |
| 934 | /* The keyboard is controlled by the EC */ |
| 935 | EC_FEATURE_KEYB = 7, |
| 936 | /* The AP can use part of the EC flash as persistent storage. */ |
| 937 | EC_FEATURE_PSTORE = 8, |
| 938 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 939 | EC_FEATURE_PORT80 = 9, |
| 940 | /* |
| 941 | * Thermal management: include TMP specific commands. |
| 942 | * Higher level than direct fan control. |
| 943 | */ |
| 944 | EC_FEATURE_THERMAL = 10, |
| 945 | /* Can switch the screen backlight on/off */ |
| 946 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 947 | /* Can switch the wifi module on/off */ |
| 948 | EC_FEATURE_WIFI_SWITCH = 12, |
| 949 | /* Monitor host events, through for example SMI or SCI */ |
| 950 | EC_FEATURE_HOST_EVENTS = 13, |
| 951 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 952 | EC_FEATURE_GPIO = 14, |
| 953 | /* The EC can send i2c messages to downstream devices. */ |
| 954 | EC_FEATURE_I2C = 15, |
| 955 | /* Command to control charger are included */ |
| 956 | EC_FEATURE_CHARGER = 16, |
| 957 | /* Simple battery support. */ |
| 958 | EC_FEATURE_BATTERY = 17, |
| 959 | /* |
| 960 | * Support Smart battery protocol |
| 961 | * (Common Smart Battery System Interface Specification) |
| 962 | */ |
| 963 | EC_FEATURE_SMART_BATTERY = 18, |
| 964 | /* EC can dectect when the host hangs. */ |
| 965 | EC_FEATURE_HANG_DETECT = 19, |
| 966 | /* Report power information, for pit only */ |
| 967 | EC_FEATURE_PMU = 20, |
| 968 | /* Another Cros EC device is present downstream of this one */ |
| 969 | EC_FEATURE_SUB_MCU = 21, |
| 970 | /* Support USB Power delivery (PD) commands */ |
| 971 | EC_FEATURE_USB_PD = 22, |
| 972 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 973 | EC_FEATURE_USB_MUX = 23, |
| 974 | /* Motion Sensor code has an internal software FIFO */ |
| 975 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 976 | /* Support temporary secure vstore */ |
| 977 | EC_FEATURE_VSTORE = 25, |
| 978 | }; |
| 979 | |
| 980 | #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) |
| 981 | #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) |
| 982 | struct ec_response_get_features { |
| 983 | uint32_t flags[2]; |
| 984 | } __packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 985 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 986 | /*****************************************************************************/ |
| 987 | /* Flash commands */ |
| 988 | |
| 989 | /* Get flash info */ |
| 990 | #define EC_CMD_FLASH_INFO 0x10 |
| 991 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 992 | /* Version 0 returns these fields */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 993 | struct ec_response_flash_info { |
| 994 | /* Usable flash size, in bytes */ |
| 995 | uint32_t flash_size; |
| 996 | /* |
| 997 | * Write block size. Write offset and size must be a multiple |
| 998 | * of this. |
| 999 | */ |
| 1000 | uint32_t write_block_size; |
| 1001 | /* |
| 1002 | * Erase block size. Erase offset and size must be a multiple |
| 1003 | * of this. |
| 1004 | */ |
| 1005 | uint32_t erase_block_size; |
| 1006 | /* |
| 1007 | * Protection block size. Protection offset and size must be a |
| 1008 | * multiple of this. |
| 1009 | */ |
| 1010 | uint32_t protect_block_size; |
| 1011 | } __packed; |
| 1012 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1013 | /* Flags for version 1+ flash info command */ |
| 1014 | /* EC flash erases bits to 0 instead of 1 */ |
| 1015 | #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0) |
| 1016 | |
| 1017 | /* |
| 1018 | * Version 1 returns the same initial fields as version 0, with additional |
| 1019 | * fields following. |
| 1020 | * |
| 1021 | * gcc anonymous structs don't seem to get along with the __packed directive; |
| 1022 | * if they did we'd define the version 0 struct as a sub-struct of this one. |
| 1023 | */ |
| 1024 | struct ec_response_flash_info_1 { |
| 1025 | /* Version 0 fields; see above for description */ |
| 1026 | uint32_t flash_size; |
| 1027 | uint32_t write_block_size; |
| 1028 | uint32_t erase_block_size; |
| 1029 | uint32_t protect_block_size; |
| 1030 | |
| 1031 | /* Version 1 adds these fields: */ |
| 1032 | /* |
| 1033 | * Ideal write size in bytes. Writes will be fastest if size is |
| 1034 | * exactly this and offset is a multiple of this. For example, an EC |
| 1035 | * may have a write buffer which can do half-page operations if data is |
| 1036 | * aligned, and a slower word-at-a-time write mode. |
| 1037 | */ |
| 1038 | uint32_t write_ideal_size; |
| 1039 | |
| 1040 | /* Flags; see EC_FLASH_INFO_* */ |
| 1041 | uint32_t flags; |
| 1042 | } __packed; |
| 1043 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1044 | /* |
| 1045 | * Read flash |
| 1046 | * |
| 1047 | * Response is params.size bytes of data. |
| 1048 | */ |
| 1049 | #define EC_CMD_FLASH_READ 0x11 |
| 1050 | |
| 1051 | struct ec_params_flash_read { |
| 1052 | uint32_t offset; /* Byte offset to read */ |
| 1053 | uint32_t size; /* Size to read in bytes */ |
| 1054 | } __packed; |
| 1055 | |
| 1056 | /* Write flash */ |
| 1057 | #define EC_CMD_FLASH_WRITE 0x12 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1058 | #define EC_VER_FLASH_WRITE 1 |
| 1059 | |
| 1060 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1061 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1062 | |
| 1063 | struct ec_params_flash_write { |
| 1064 | uint32_t offset; /* Byte offset to write */ |
| 1065 | uint32_t size; /* Size to write in bytes */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1066 | /* Followed by data to write */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1067 | } __packed; |
| 1068 | |
| 1069 | /* Erase flash */ |
| 1070 | #define EC_CMD_FLASH_ERASE 0x13 |
| 1071 | |
| 1072 | struct ec_params_flash_erase { |
| 1073 | uint32_t offset; /* Byte offset to erase */ |
| 1074 | uint32_t size; /* Size to erase in bytes */ |
| 1075 | } __packed; |
| 1076 | |
| 1077 | /* |
| 1078 | * Get/set flash protection. |
| 1079 | * |
| 1080 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1081 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1082 | * some flags require a subsequent hard reset to take effect. Check the |
| 1083 | * returned flags bits to see what actually happened. |
| 1084 | * |
| 1085 | * If mask=0, simply returns the current flags state. |
| 1086 | */ |
| 1087 | #define EC_CMD_FLASH_PROTECT 0x15 |
| 1088 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1089 | |
| 1090 | /* Flags for flash protection */ |
| 1091 | /* RO flash code protected when the EC boots */ |
| 1092 | #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0) |
| 1093 | /* |
| 1094 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1095 | * be changed. |
| 1096 | */ |
| 1097 | #define EC_FLASH_PROTECT_RO_NOW (1 << 1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1098 | /* Entire flash code protected now, until reboot. */ |
| 1099 | #define EC_FLASH_PROTECT_ALL_NOW (1 << 2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1100 | /* Flash write protect GPIO is asserted now */ |
| 1101 | #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3) |
| 1102 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
| 1103 | #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4) |
| 1104 | /* |
| 1105 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1106 | * flash which should be protected is not protected. Usually fixed by |
| 1107 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1108 | */ |
| 1109 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1110 | /* Entire flash code protected when the EC boots */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1111 | #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1112 | |
| 1113 | struct ec_params_flash_protect { |
| 1114 | uint32_t mask; /* Bits in flags to apply */ |
| 1115 | uint32_t flags; /* New flags to apply */ |
| 1116 | } __packed; |
| 1117 | |
| 1118 | struct ec_response_flash_protect { |
| 1119 | /* Current value of flash protect flags */ |
| 1120 | uint32_t flags; |
| 1121 | /* |
| 1122 | * Flags which are valid on this platform. This allows the caller |
| 1123 | * to distinguish between flags which aren't set vs. flags which can't |
| 1124 | * be set on this platform. |
| 1125 | */ |
| 1126 | uint32_t valid_flags; |
| 1127 | /* Flags which can be changed given the current protection state */ |
| 1128 | uint32_t writable_flags; |
| 1129 | } __packed; |
| 1130 | |
| 1131 | /* |
| 1132 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1133 | * write protect. These commands may be reused with version > 0. |
| 1134 | */ |
| 1135 | |
| 1136 | /* Get the region offset/size */ |
| 1137 | #define EC_CMD_FLASH_REGION_INFO 0x16 |
| 1138 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1139 | |
| 1140 | enum ec_flash_region { |
| 1141 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1142 | EC_FLASH_REGION_RO = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1143 | /* Region which holds rewritable EC image */ |
| 1144 | EC_FLASH_REGION_RW, |
| 1145 | /* |
| 1146 | * Region which should be write-protected in the factory (a superset of |
| 1147 | * EC_FLASH_REGION_RO) |
| 1148 | */ |
| 1149 | EC_FLASH_REGION_WP_RO, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1150 | /* Number of regions */ |
| 1151 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | struct ec_params_flash_region_info { |
| 1155 | uint32_t region; /* enum ec_flash_region */ |
| 1156 | } __packed; |
| 1157 | |
| 1158 | struct ec_response_flash_region_info { |
| 1159 | uint32_t offset; |
| 1160 | uint32_t size; |
| 1161 | } __packed; |
| 1162 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1163 | /* Read/write VbNvContext */ |
| 1164 | #define EC_CMD_VBNV_CONTEXT 0x17 |
| 1165 | #define EC_VER_VBNV_CONTEXT 1 |
| 1166 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1167 | |
| 1168 | enum ec_vbnvcontext_op { |
| 1169 | EC_VBNV_CONTEXT_OP_READ, |
| 1170 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1171 | }; |
| 1172 | |
| 1173 | struct ec_params_vbnvcontext { |
| 1174 | uint32_t op; |
| 1175 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
| 1176 | } __packed; |
| 1177 | |
| 1178 | struct ec_response_vbnvcontext { |
| 1179 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
| 1180 | } __packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1181 | |
| 1182 | /*****************************************************************************/ |
| 1183 | /* PWM commands */ |
| 1184 | |
| 1185 | /* Get fan target RPM */ |
| 1186 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20 |
| 1187 | |
| 1188 | struct ec_response_pwm_get_fan_rpm { |
| 1189 | uint32_t rpm; |
| 1190 | } __packed; |
| 1191 | |
| 1192 | /* Set target fan RPM */ |
| 1193 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21 |
| 1194 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1195 | /* Version 0 of input params */ |
| 1196 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1197 | uint32_t rpm; |
| 1198 | } __packed; |
| 1199 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1200 | /* Version 1 of input params */ |
| 1201 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
| 1202 | uint32_t rpm; |
| 1203 | uint8_t fan_idx; |
| 1204 | } __packed; |
| 1205 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1206 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 1207 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1208 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22 |
| 1209 | |
| 1210 | struct ec_response_pwm_get_keyboard_backlight { |
| 1211 | uint8_t percent; |
| 1212 | uint8_t enabled; |
| 1213 | } __packed; |
| 1214 | |
| 1215 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 1216 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1217 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23 |
| 1218 | |
| 1219 | struct ec_params_pwm_set_keyboard_backlight { |
| 1220 | uint8_t percent; |
| 1221 | } __packed; |
| 1222 | |
| 1223 | /* Set target fan PWM duty cycle */ |
| 1224 | #define EC_CMD_PWM_SET_FAN_DUTY 0x24 |
| 1225 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1226 | /* Version 0 of input params */ |
| 1227 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1228 | uint32_t percent; |
| 1229 | } __packed; |
| 1230 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1231 | /* Version 1 of input params */ |
| 1232 | struct ec_params_pwm_set_fan_duty_v1 { |
| 1233 | uint32_t percent; |
| 1234 | uint8_t fan_idx; |
| 1235 | } __packed; |
| 1236 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 1237 | #define EC_CMD_PWM_SET_DUTY 0x25 |
| 1238 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1239 | #define EC_PWM_MAX_DUTY 0xffff |
| 1240 | |
| 1241 | enum ec_pwm_type { |
| 1242 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1243 | EC_PWM_TYPE_GENERIC = 0, |
| 1244 | /* Keyboard backlight */ |
| 1245 | EC_PWM_TYPE_KB_LIGHT, |
| 1246 | /* Display backlight */ |
| 1247 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1248 | EC_PWM_TYPE_COUNT, |
| 1249 | }; |
| 1250 | |
| 1251 | struct ec_params_pwm_set_duty { |
| 1252 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1253 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1254 | uint8_t index; /* Type-specific index, or 0 if unique */ |
| 1255 | } __packed; |
| 1256 | |
| 1257 | #define EC_CMD_PWM_GET_DUTY 0x26 |
| 1258 | |
| 1259 | struct ec_params_pwm_get_duty { |
| 1260 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1261 | uint8_t index; /* Type-specific index, or 0 if unique */ |
| 1262 | } __packed; |
| 1263 | |
| 1264 | struct ec_response_pwm_get_duty { |
| 1265 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1266 | } __packed; |
| 1267 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1268 | /*****************************************************************************/ |
| 1269 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1270 | * 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] | 1271 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1272 | * into a subcommand. We'll make separate structs for subcommands with |
| 1273 | * different input args, so that we know how much to expect. |
| 1274 | */ |
| 1275 | #define EC_CMD_LIGHTBAR_CMD 0x28 |
| 1276 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1277 | struct rgb_s { |
| 1278 | uint8_t r, g, b; |
| 1279 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1280 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1281 | #define LB_BATTERY_LEVELS 4 |
| 1282 | /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a |
| 1283 | * host command, but the alignment is the same regardless. Keep it that way. |
| 1284 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1285 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1286 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1287 | int32_t google_ramp_up; |
| 1288 | int32_t google_ramp_down; |
| 1289 | int32_t s3s0_ramp_up; |
| 1290 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1291 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1292 | int32_t s0s3_ramp_down; |
| 1293 | int32_t s3_sleep_for; |
| 1294 | int32_t s3_ramp_up; |
| 1295 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1296 | |
| 1297 | /* Oscillation */ |
| 1298 | uint8_t new_s0; |
| 1299 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1300 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1301 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1302 | |
| 1303 | /* Brightness limits based on the backlight and AC. */ |
| 1304 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1305 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1306 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1307 | |
| 1308 | /* Battery level thresholds */ |
| 1309 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1310 | |
| 1311 | /* Map [AC][battery_level] to color index */ |
| 1312 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1313 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1314 | |
| 1315 | /* Color palette */ |
| 1316 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 1317 | } __packed; |
| 1318 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1319 | struct lightbar_params_v1 { |
| 1320 | /* Timing */ |
| 1321 | int32_t google_ramp_up; |
| 1322 | int32_t google_ramp_down; |
| 1323 | int32_t s3s0_ramp_up; |
| 1324 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1325 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1326 | int32_t s0s3_ramp_down; |
| 1327 | int32_t s3_sleep_for; |
| 1328 | int32_t s3_ramp_up; |
| 1329 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1330 | int32_t s5_ramp_up; |
| 1331 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1332 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1333 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1334 | int32_t tap_display_time; |
| 1335 | |
| 1336 | /* Tap-for-battery params */ |
| 1337 | uint8_t tap_pct_red; |
| 1338 | uint8_t tap_pct_green; |
| 1339 | uint8_t tap_seg_min_on; |
| 1340 | uint8_t tap_seg_max_on; |
| 1341 | uint8_t tap_seg_osc; |
| 1342 | uint8_t tap_idx[3]; |
| 1343 | |
| 1344 | /* Oscillation */ |
| 1345 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1346 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1347 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1348 | |
| 1349 | /* Brightness limits based on the backlight and AC. */ |
| 1350 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1351 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1352 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1353 | |
| 1354 | /* Battery level thresholds */ |
| 1355 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1356 | |
| 1357 | /* Map [AC][battery_level] to color index */ |
| 1358 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1359 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1360 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1361 | /* s5: single color pulse on inhibited power-up */ |
| 1362 | uint8_t s5_idx; |
| 1363 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1364 | /* Color palette */ |
| 1365 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 1366 | } __packed; |
| 1367 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1368 | /* Lightbar command params v2 |
| 1369 | * crbug.com/467716 |
| 1370 | * |
| 1371 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 1372 | * logical groups to make it more manageable ( < 120 bytes). |
| 1373 | * |
| 1374 | * NOTE: Each of these groups must be less than 120 bytes. |
| 1375 | */ |
| 1376 | |
| 1377 | struct lightbar_params_v2_timing { |
| 1378 | /* Timing */ |
| 1379 | int32_t google_ramp_up; |
| 1380 | int32_t google_ramp_down; |
| 1381 | int32_t s3s0_ramp_up; |
| 1382 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1383 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1384 | int32_t s0s3_ramp_down; |
| 1385 | int32_t s3_sleep_for; |
| 1386 | int32_t s3_ramp_up; |
| 1387 | int32_t s3_ramp_down; |
| 1388 | int32_t s5_ramp_up; |
| 1389 | int32_t s5_ramp_down; |
| 1390 | int32_t tap_tick_delay; |
| 1391 | int32_t tap_gate_delay; |
| 1392 | int32_t tap_display_time; |
| 1393 | } __packed; |
| 1394 | |
| 1395 | struct lightbar_params_v2_tap { |
| 1396 | /* Tap-for-battery params */ |
| 1397 | uint8_t tap_pct_red; |
| 1398 | uint8_t tap_pct_green; |
| 1399 | uint8_t tap_seg_min_on; |
| 1400 | uint8_t tap_seg_max_on; |
| 1401 | uint8_t tap_seg_osc; |
| 1402 | uint8_t tap_idx[3]; |
| 1403 | } __packed; |
| 1404 | |
| 1405 | struct lightbar_params_v2_oscillation { |
| 1406 | /* Oscillation */ |
| 1407 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1408 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1409 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1410 | } __packed; |
| 1411 | |
| 1412 | struct lightbar_params_v2_brightness { |
| 1413 | /* Brightness limits based on the backlight and AC. */ |
| 1414 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1415 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1416 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1417 | } __packed; |
| 1418 | |
| 1419 | struct lightbar_params_v2_thresholds { |
| 1420 | /* Battery level thresholds */ |
| 1421 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1422 | } __packed; |
| 1423 | |
| 1424 | struct lightbar_params_v2_colors { |
| 1425 | /* Map [AC][battery_level] to color index */ |
| 1426 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1427 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1428 | |
| 1429 | /* s5: single color pulse on inhibited power-up */ |
| 1430 | uint8_t s5_idx; |
| 1431 | |
| 1432 | /* Color palette */ |
| 1433 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 1434 | } __packed; |
| 1435 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1436 | /* Lightbyte program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1437 | #define EC_LB_PROG_LEN 192 |
| 1438 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1439 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1440 | uint8_t data[EC_LB_PROG_LEN]; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1441 | }; |
| 1442 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1443 | struct ec_params_lightbar { |
| 1444 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 1445 | union { |
| 1446 | struct { |
| 1447 | /* no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1448 | } dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1449 | version, get_brightness, get_demo, suspend, resume, |
| 1450 | get_params_v2_timing, get_params_v2_tap, |
| 1451 | get_params_v2_osc, get_params_v2_bright, |
| 1452 | get_params_v2_thlds, get_params_v2_colors; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1453 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1454 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1455 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1456 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1457 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1458 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1459 | uint8_t ctrl, reg, value; |
| 1460 | } reg; |
| 1461 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1462 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1463 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1464 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1465 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1466 | struct { |
| 1467 | uint8_t led; |
| 1468 | } get_rgb; |
| 1469 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1470 | struct { |
| 1471 | uint8_t enable; |
| 1472 | } manual_suspend_ctrl; |
| 1473 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1474 | struct lightbar_params_v0 set_params_v0; |
| 1475 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1476 | |
| 1477 | struct lightbar_params_v2_timing set_v2par_timing; |
| 1478 | struct lightbar_params_v2_tap set_v2par_tap; |
| 1479 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 1480 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 1481 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 1482 | struct lightbar_params_v2_colors set_v2par_colors; |
| 1483 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1484 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1485 | }; |
| 1486 | } __packed; |
| 1487 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1488 | struct ec_response_lightbar { |
| 1489 | union { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1490 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1491 | struct { |
| 1492 | uint8_t reg; |
| 1493 | uint8_t ic0; |
| 1494 | uint8_t ic1; |
| 1495 | } vals[23]; |
| 1496 | } dump; |
| 1497 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1498 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1499 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1500 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1501 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1502 | struct lightbar_params_v0 get_params_v0; |
| 1503 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1504 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1505 | |
| 1506 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 1507 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 1508 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 1509 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 1510 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 1511 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 1512 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1513 | struct { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1514 | uint32_t num; |
| 1515 | uint32_t flags; |
| 1516 | } version; |
| 1517 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1518 | struct { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1519 | uint8_t red, green, blue; |
| 1520 | } get_rgb; |
| 1521 | |
| 1522 | struct { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1523 | /* no return params */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1524 | } off, on, init, set_brightness, seq, reg, set_rgb, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1525 | demo, set_params_v0, set_params_v1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1526 | set_program, manual_suspend_ctrl, suspend, resume, |
| 1527 | set_v2par_timing, set_v2par_tap, |
| 1528 | set_v2par_osc, set_v2par_bright, set_v2par_thlds, |
| 1529 | set_v2par_colors; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1530 | }; |
| 1531 | } __packed; |
| 1532 | |
| 1533 | /* Lightbar commands */ |
| 1534 | enum lightbar_command { |
| 1535 | LIGHTBAR_CMD_DUMP = 0, |
| 1536 | LIGHTBAR_CMD_OFF = 1, |
| 1537 | LIGHTBAR_CMD_ON = 2, |
| 1538 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1539 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1540 | LIGHTBAR_CMD_SEQ = 5, |
| 1541 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1542 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1543 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 1544 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1545 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 1546 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1547 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1548 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 1549 | LIGHTBAR_CMD_GET_RGB = 14, |
| 1550 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 1551 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 1552 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1553 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1554 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 1555 | LIGHTBAR_CMD_SUSPEND = 20, |
| 1556 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1557 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 1558 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 1559 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 1560 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 1561 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 1562 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 1563 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 1564 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 1565 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 1566 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 1567 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 1568 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1569 | LIGHTBAR_NUM_CMDS |
| 1570 | }; |
| 1571 | |
| 1572 | /*****************************************************************************/ |
| 1573 | /* LED control commands */ |
| 1574 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1575 | #define EC_CMD_LED_CONTROL 0x29 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1576 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1577 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1578 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1579 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1580 | /* |
| 1581 | * LED to indicate system power state (on or in suspend). |
| 1582 | * May be on power button or on C-panel. |
| 1583 | */ |
| 1584 | EC_LED_ID_POWER_LED, |
| 1585 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1586 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1587 | |
| 1588 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1589 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1590 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1591 | /* LED control flags */ |
| 1592 | #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */ |
| 1593 | #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */ |
| 1594 | |
| 1595 | enum ec_led_colors { |
| 1596 | EC_LED_COLOR_RED = 0, |
| 1597 | EC_LED_COLOR_GREEN, |
| 1598 | EC_LED_COLOR_BLUE, |
| 1599 | EC_LED_COLOR_YELLOW, |
| 1600 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1601 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1602 | |
| 1603 | EC_LED_COLOR_COUNT |
| 1604 | }; |
| 1605 | |
| 1606 | struct ec_params_led_control { |
| 1607 | uint8_t led_id; /* Which LED to control */ |
| 1608 | uint8_t flags; /* Control flags */ |
| 1609 | |
| 1610 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
| 1611 | } __packed; |
| 1612 | |
| 1613 | struct ec_response_led_control { |
| 1614 | /* |
| 1615 | * Available brightness value range. |
| 1616 | * |
| 1617 | * Range 0 means color channel not present. |
| 1618 | * Range 1 means on/off control. |
| 1619 | * Other values means the LED is control by PWM. |
| 1620 | */ |
| 1621 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1622 | } __packed; |
| 1623 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1624 | /*****************************************************************************/ |
| 1625 | /* Verified boot commands */ |
| 1626 | |
| 1627 | /* |
| 1628 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 1629 | * reused for other purposes with version > 0. |
| 1630 | */ |
| 1631 | |
| 1632 | /* Verified boot hash command */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1633 | #define EC_CMD_VBOOT_HASH 0x2a |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1634 | |
| 1635 | struct ec_params_vboot_hash { |
| 1636 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 1637 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1638 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 1639 | uint8_t reserved0; /* Reserved; set 0 */ |
| 1640 | uint32_t offset; /* Offset in flash to hash */ |
| 1641 | uint32_t size; /* Number of bytes to hash */ |
| 1642 | uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ |
| 1643 | } __packed; |
| 1644 | |
| 1645 | struct ec_response_vboot_hash { |
| 1646 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 1647 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1648 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 1649 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 1650 | uint32_t offset; /* Offset in flash which was hashed */ |
| 1651 | uint32_t size; /* Number of bytes hashed */ |
| 1652 | uint8_t hash_digest[64]; /* Hash digest data */ |
| 1653 | } __packed; |
| 1654 | |
| 1655 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1656 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 1657 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 1658 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 1659 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1660 | }; |
| 1661 | |
| 1662 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1663 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1664 | }; |
| 1665 | |
| 1666 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1667 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 1668 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 1669 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1670 | }; |
| 1671 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1672 | /* |
| 1673 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 1674 | * If one of these is specified, the EC will automatically update offset and |
| 1675 | * size to the correct values for the specified image (RO or RW). |
| 1676 | */ |
| 1677 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 1678 | #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd |
| 1679 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1680 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1681 | /* |
| 1682 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 1683 | * different input args, so that we know how much to expect. |
| 1684 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1685 | #define EC_CMD_MOTION_SENSE_CMD 0x2b |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1686 | |
| 1687 | /* Motion sense commands */ |
| 1688 | enum motionsense_command { |
| 1689 | /* |
| 1690 | * Dump command returns all motion sensor data including motion sense |
| 1691 | * module flags and individual sensor flags. |
| 1692 | */ |
| 1693 | MOTIONSENSE_CMD_DUMP = 0, |
| 1694 | |
| 1695 | /* |
| 1696 | * Info command returns data describing the details of a given sensor, |
| 1697 | * including enum motionsensor_type, enum motionsensor_location, and |
| 1698 | * enum motionsensor_chip. |
| 1699 | */ |
| 1700 | MOTIONSENSE_CMD_INFO = 1, |
| 1701 | |
| 1702 | /* |
| 1703 | * 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] | 1704 | * in milliseconds. |
| 1705 | * It is per sensor, the EC run sample task at the minimum of all |
| 1706 | * sensors EC_RATE. |
| 1707 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 1708 | * to collect all the sensor samples. |
| 1709 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 1710 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1711 | */ |
| 1712 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 1713 | |
| 1714 | /* |
| 1715 | * Sensor ODR command is a setter/getter command for the output data |
| 1716 | * rate of a specific motion sensor in millihertz. |
| 1717 | */ |
| 1718 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 1719 | |
| 1720 | /* |
| 1721 | * Sensor range command is a setter/getter command for the range of |
| 1722 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 1723 | */ |
| 1724 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 1725 | |
| 1726 | /* |
| 1727 | * Setter/getter command for the keyboard wake angle. When the lid |
| 1728 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 1729 | * and when the lid angle goes less than this value, keyboard wake is |
| 1730 | * enabled. Note, the lid angle measurement is an approximate, |
| 1731 | * un-calibrated value, hence the wake angle isn't exact. |
| 1732 | */ |
| 1733 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 1734 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1735 | /* |
| 1736 | * Returns a single sensor data. |
| 1737 | */ |
| 1738 | MOTIONSENSE_CMD_DATA = 6, |
| 1739 | |
| 1740 | /* |
| 1741 | * Return sensor fifo info. |
| 1742 | */ |
| 1743 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 1744 | |
| 1745 | /* |
| 1746 | * Insert a flush element in the fifo and return sensor fifo info. |
| 1747 | * The host can use that element to synchronize its operation. |
| 1748 | */ |
| 1749 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 1750 | |
| 1751 | /* |
| 1752 | * Return a portion of the fifo. |
| 1753 | */ |
| 1754 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 1755 | |
| 1756 | /* |
| 1757 | * Perform low level calibration. |
| 1758 | * On sensors that support it, ask to do offset calibration. |
| 1759 | */ |
| 1760 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 1761 | |
| 1762 | /* |
| 1763 | * Sensor Offset command is a setter/getter command for the offset |
| 1764 | * used for calibration. |
| 1765 | * The offsets can be calculated by the host, or via |
| 1766 | * PERFORM_CALIB command. |
| 1767 | */ |
| 1768 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 1769 | |
| 1770 | /* |
| 1771 | * List available activities for a MOTION sensor. |
| 1772 | * Indicates if they are enabled or disabled. |
| 1773 | */ |
| 1774 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 1775 | |
| 1776 | /* |
| 1777 | * Activity management |
| 1778 | * Enable/Disable activity recognition. |
| 1779 | */ |
| 1780 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 1781 | |
| 1782 | /* |
| 1783 | * Lid Angle |
| 1784 | */ |
| 1785 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 1786 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1787 | /* Number of motionsense sub-commands. */ |
| 1788 | MOTIONSENSE_NUM_CMDS |
| 1789 | }; |
| 1790 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1791 | /* List of motion sensor types. */ |
| 1792 | enum motionsensor_type { |
| 1793 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 1794 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1795 | MOTIONSENSE_TYPE_MAG = 2, |
| 1796 | MOTIONSENSE_TYPE_PROX = 3, |
| 1797 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 1798 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
| 1799 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1800 | }; |
| 1801 | |
| 1802 | /* List of motion sensor locations. */ |
| 1803 | enum motionsensor_location { |
| 1804 | MOTIONSENSE_LOC_BASE = 0, |
| 1805 | MOTIONSENSE_LOC_LID = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1806 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1807 | }; |
| 1808 | |
| 1809 | /* List of motion sensor chips. */ |
| 1810 | enum motionsensor_chip { |
| 1811 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 1812 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1813 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 1814 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 1815 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 1816 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 1817 | MOTIONSENSE_CHIP_KX022 = 6, |
| 1818 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 1819 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1820 | }; |
| 1821 | |
| 1822 | struct ec_response_motion_sensor_data { |
| 1823 | /* Flags for each sensor. */ |
| 1824 | uint8_t flags; |
| 1825 | /* sensor number the data comes from */ |
| 1826 | uint8_t sensor_num; |
| 1827 | /* Each sensor is up to 3-axis. */ |
| 1828 | union { |
| 1829 | int16_t data[3]; |
| 1830 | struct { |
| 1831 | uint16_t rsvd; |
| 1832 | uint32_t timestamp; |
| 1833 | } __packed; |
| 1834 | struct { |
| 1835 | uint8_t activity; /* motionsensor_activity */ |
| 1836 | uint8_t state; |
| 1837 | int16_t add_info[2]; |
| 1838 | }; |
| 1839 | }; |
| 1840 | } __packed; |
| 1841 | |
| 1842 | struct ec_response_motion_sense_fifo_info { |
| 1843 | /* Size of the fifo */ |
| 1844 | uint16_t size; |
| 1845 | /* Amount of space used in the fifo */ |
| 1846 | uint16_t count; |
| 1847 | /* TImestamp recorded in us */ |
| 1848 | uint32_t timestamp; |
| 1849 | /* Total amount of vector lost */ |
| 1850 | uint16_t total_lost; |
| 1851 | /* Lost events since the last fifo_info, per sensors */ |
| 1852 | uint16_t lost[0]; |
| 1853 | } __packed; |
| 1854 | |
| 1855 | struct ec_response_motion_sense_fifo_data { |
| 1856 | uint32_t number_data; |
| 1857 | struct ec_response_motion_sensor_data data[0]; |
| 1858 | } __packed; |
| 1859 | |
| 1860 | /* List supported activity recognition */ |
| 1861 | enum motionsensor_activity { |
| 1862 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 1863 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 1864 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
| 1865 | }; |
| 1866 | |
| 1867 | struct ec_motion_sense_activity { |
| 1868 | uint8_t sensor_num; |
| 1869 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 1870 | uint8_t enable; /* 1: enable, 0: disable */ |
| 1871 | uint8_t reserved; |
| 1872 | uint16_t parameters[3]; /* activity dependent parameters */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1873 | }; |
| 1874 | |
| 1875 | /* Module flag masks used for the dump sub-command. */ |
| 1876 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0) |
| 1877 | |
| 1878 | /* Sensor flag masks used for the dump sub-command. */ |
| 1879 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0) |
| 1880 | |
| 1881 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1882 | * Flush entry for synchronisation. |
| 1883 | * data contains time stamp |
| 1884 | */ |
| 1885 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0) |
| 1886 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1) |
| 1887 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2) |
| 1888 | |
| 1889 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1890 | * Send this value for the data element to only perform a read. If you |
| 1891 | * send any other value, the EC will interpret it as data to set and will |
| 1892 | * return the actual value set. |
| 1893 | */ |
| 1894 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 1895 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1896 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 1897 | |
| 1898 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 1899 | /* Set Calibration information */ |
| 1900 | #define MOTION_SENSE_SET_OFFSET 1 |
| 1901 | |
| 1902 | #define LID_ANGLE_UNRELIABLE 500 |
| 1903 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1904 | struct ec_params_motion_sense { |
| 1905 | uint8_t cmd; |
| 1906 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1907 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1908 | struct { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1909 | /* |
| 1910 | * Maximal number of sensor the host is expecting. |
| 1911 | * 0 means the host is only interested in the number |
| 1912 | * of sensors controlled by the EC. |
| 1913 | */ |
| 1914 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1915 | } dump; |
| 1916 | |
| 1917 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1918 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1919 | */ |
| 1920 | struct { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1921 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 1922 | * kb_wake_angle: angle to wakup AP. |
| 1923 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1924 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1925 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1926 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1927 | /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 1928 | * and MOTIONSENSE_CMD_PERFORM_CALIB. */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1929 | struct { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1930 | uint8_t sensor_num; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1931 | } info, data, fifo_flush, perform_calib, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1932 | |
| 1933 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1934 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 1935 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1936 | */ |
| 1937 | struct { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1938 | uint8_t sensor_num; |
| 1939 | |
| 1940 | /* Rounding flag, true for round-up, false for down. */ |
| 1941 | uint8_t roundup; |
| 1942 | |
| 1943 | uint16_t reserved; |
| 1944 | |
| 1945 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 1946 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1947 | } ec_rate, sensor_odr, sensor_range; |
| 1948 | |
| 1949 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
| 1950 | struct { |
| 1951 | uint8_t sensor_num; |
| 1952 | |
| 1953 | /* |
| 1954 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 1955 | * the calibration information in the EC. |
| 1956 | * If unset, just retrieve calibration information. |
| 1957 | */ |
| 1958 | uint16_t flags; |
| 1959 | |
| 1960 | /* |
| 1961 | * Temperature at calibration, in units of 0.01 C |
| 1962 | * 0x8000: invalid / unknown. |
| 1963 | * 0x0: 0C |
| 1964 | * 0x7fff: +327.67C |
| 1965 | */ |
| 1966 | int16_t temp; |
| 1967 | |
| 1968 | /* |
| 1969 | * Offset for calibration. |
| 1970 | * Unit: |
| 1971 | * Accelerometer: 1/1024 g |
| 1972 | * Gyro: 1/1024 deg/s |
| 1973 | * Compass: 1/16 uT |
| 1974 | */ |
| 1975 | int16_t offset[3]; |
| 1976 | } __packed sensor_offset; |
| 1977 | |
| 1978 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
| 1979 | struct { |
| 1980 | } fifo_info; |
| 1981 | |
| 1982 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
| 1983 | struct { |
| 1984 | /* |
| 1985 | * Number of expected vector to return. |
| 1986 | * EC may return less or 0 if none available. |
| 1987 | */ |
| 1988 | uint32_t max_data_vector; |
| 1989 | } fifo_read; |
| 1990 | |
| 1991 | struct ec_motion_sense_activity set_activity; |
| 1992 | |
| 1993 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
| 1994 | struct { |
| 1995 | } lid_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1996 | }; |
| 1997 | } __packed; |
| 1998 | |
| 1999 | struct ec_response_motion_sense { |
| 2000 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2001 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2002 | struct { |
| 2003 | /* Flags representing the motion sensor module. */ |
| 2004 | uint8_t module_flags; |
| 2005 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2006 | /* Number of sensors managed directly by the EC */ |
| 2007 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2008 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2009 | /* |
| 2010 | * sensor data is truncated if response_max is too small |
| 2011 | * for holding all the data. |
| 2012 | */ |
| 2013 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2014 | } dump; |
| 2015 | |
| 2016 | /* Used for MOTIONSENSE_CMD_INFO. */ |
| 2017 | struct { |
| 2018 | /* Should be element of enum motionsensor_type. */ |
| 2019 | uint8_t type; |
| 2020 | |
| 2021 | /* Should be element of enum motionsensor_location. */ |
| 2022 | uint8_t location; |
| 2023 | |
| 2024 | /* Should be element of enum motionsensor_chip. */ |
| 2025 | uint8_t chip; |
| 2026 | } info; |
| 2027 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2028 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 2029 | struct ec_response_motion_sensor_data data; |
| 2030 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2031 | /* |
| 2032 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
| 2033 | * MOTIONSENSE_CMD_SENSOR_RANGE, and |
| 2034 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
| 2035 | */ |
| 2036 | struct { |
| 2037 | /* Current value of the parameter queried. */ |
| 2038 | int32_t ret; |
| 2039 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2040 | |
| 2041 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
| 2042 | struct { |
| 2043 | int16_t temp; |
| 2044 | int16_t offset[3]; |
| 2045 | } sensor_offset, perform_calib; |
| 2046 | |
| 2047 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 2048 | |
| 2049 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 2050 | |
| 2051 | struct { |
| 2052 | uint16_t reserved; |
| 2053 | uint32_t enabled; |
| 2054 | uint32_t disabled; |
| 2055 | } __packed list_activities; |
| 2056 | |
| 2057 | struct { |
| 2058 | } set_activity; |
| 2059 | |
| 2060 | |
| 2061 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
| 2062 | struct { |
| 2063 | /* |
| 2064 | * Angle between 0 and 360 degree if available, |
| 2065 | * LID_ANGLE_UNRELIABLE otherwise. |
| 2066 | */ |
| 2067 | uint16_t value; |
| 2068 | } lid_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2069 | }; |
| 2070 | } __packed; |
| 2071 | |
| 2072 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2073 | /* Force lid open command */ |
| 2074 | |
| 2075 | /* Make lid event always open */ |
| 2076 | #define EC_CMD_FORCE_LID_OPEN 0x2c |
| 2077 | |
| 2078 | struct ec_params_force_lid_open { |
| 2079 | uint8_t enabled; |
| 2080 | } __packed; |
| 2081 | |
| 2082 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2083 | /* USB charging control commands */ |
| 2084 | |
| 2085 | /* Set USB port charging mode */ |
| 2086 | #define EC_CMD_USB_CHARGE_SET_MODE 0x30 |
| 2087 | |
| 2088 | struct ec_params_usb_charge_set_mode { |
| 2089 | uint8_t usb_port_id; |
| 2090 | uint8_t mode; |
| 2091 | } __packed; |
| 2092 | |
| 2093 | /*****************************************************************************/ |
| 2094 | /* Persistent storage for host */ |
| 2095 | |
| 2096 | /* Maximum bytes that can be read/written in a single command */ |
| 2097 | #define EC_PSTORE_SIZE_MAX 64 |
| 2098 | |
| 2099 | /* Get persistent storage info */ |
| 2100 | #define EC_CMD_PSTORE_INFO 0x40 |
| 2101 | |
| 2102 | struct ec_response_pstore_info { |
| 2103 | /* Persistent storage size, in bytes */ |
| 2104 | uint32_t pstore_size; |
| 2105 | /* Access size; read/write offset and size must be a multiple of this */ |
| 2106 | uint32_t access_size; |
| 2107 | } __packed; |
| 2108 | |
| 2109 | /* |
| 2110 | * Read persistent storage |
| 2111 | * |
| 2112 | * Response is params.size bytes of data. |
| 2113 | */ |
| 2114 | #define EC_CMD_PSTORE_READ 0x41 |
| 2115 | |
| 2116 | struct ec_params_pstore_read { |
| 2117 | uint32_t offset; /* Byte offset to read */ |
| 2118 | uint32_t size; /* Size to read in bytes */ |
| 2119 | } __packed; |
| 2120 | |
| 2121 | /* Write persistent storage */ |
| 2122 | #define EC_CMD_PSTORE_WRITE 0x42 |
| 2123 | |
| 2124 | struct ec_params_pstore_write { |
| 2125 | uint32_t offset; /* Byte offset to write */ |
| 2126 | uint32_t size; /* Size to write in bytes */ |
| 2127 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
| 2128 | } __packed; |
| 2129 | |
| 2130 | /*****************************************************************************/ |
| 2131 | /* Real-time clock */ |
| 2132 | |
| 2133 | /* RTC params and response structures */ |
| 2134 | struct ec_params_rtc { |
| 2135 | uint32_t time; |
| 2136 | } __packed; |
| 2137 | |
| 2138 | struct ec_response_rtc { |
| 2139 | uint32_t time; |
| 2140 | } __packed; |
| 2141 | |
| 2142 | /* These use ec_response_rtc */ |
| 2143 | #define EC_CMD_RTC_GET_VALUE 0x44 |
| 2144 | #define EC_CMD_RTC_GET_ALARM 0x45 |
| 2145 | |
| 2146 | /* These all use ec_params_rtc */ |
| 2147 | #define EC_CMD_RTC_SET_VALUE 0x46 |
| 2148 | #define EC_CMD_RTC_SET_ALARM 0x47 |
| 2149 | |
| 2150 | /*****************************************************************************/ |
| 2151 | /* Port80 log access */ |
| 2152 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2153 | /* Maximum entries that can be read/written in a single command */ |
| 2154 | #define EC_PORT80_SIZE_MAX 32 |
| 2155 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2156 | /* Get last port80 code from previous boot */ |
| 2157 | #define EC_CMD_PORT80_LAST_BOOT 0x48 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2158 | #define EC_CMD_PORT80_READ 0x48 |
| 2159 | |
| 2160 | enum ec_port80_subcmd { |
| 2161 | EC_PORT80_GET_INFO = 0, |
| 2162 | EC_PORT80_READ_BUFFER, |
| 2163 | }; |
| 2164 | |
| 2165 | struct ec_params_port80_read { |
| 2166 | uint16_t subcmd; |
| 2167 | union { |
| 2168 | struct { |
| 2169 | uint32_t offset; |
| 2170 | uint32_t num_entries; |
| 2171 | } read_buffer; |
| 2172 | }; |
| 2173 | } __packed; |
| 2174 | |
| 2175 | struct ec_response_port80_read { |
| 2176 | union { |
| 2177 | struct { |
| 2178 | uint32_t writes; |
| 2179 | uint32_t history_size; |
| 2180 | uint32_t last_boot; |
| 2181 | } get_info; |
| 2182 | struct { |
| 2183 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 2184 | } data; |
| 2185 | }; |
| 2186 | } __packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2187 | |
| 2188 | struct ec_response_port80_last_boot { |
| 2189 | uint16_t code; |
| 2190 | } __packed; |
| 2191 | |
| 2192 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2193 | /* Temporary secure storage for host verified boot use */ |
| 2194 | |
| 2195 | /* Number of bytes in a vstore slot */ |
| 2196 | #define EC_VSTORE_SLOT_SIZE 64 |
| 2197 | |
| 2198 | /* Maximum number of vstore slots */ |
| 2199 | #define EC_VSTORE_SLOT_MAX 32 |
| 2200 | |
| 2201 | /* Get persistent storage info */ |
| 2202 | #define EC_CMD_VSTORE_INFO 0x49 |
| 2203 | |
| 2204 | struct ec_response_vstore_info { |
| 2205 | /* Indicates which slots are locked */ |
| 2206 | uint32_t slot_locked; |
| 2207 | /* Total number of slots available */ |
| 2208 | uint8_t slot_count; |
| 2209 | } __packed; |
| 2210 | |
| 2211 | /* |
| 2212 | * Read temporary secure storage |
| 2213 | * |
| 2214 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 2215 | */ |
| 2216 | #define EC_CMD_VSTORE_READ 0x4a |
| 2217 | |
| 2218 | struct ec_params_vstore_read { |
| 2219 | uint8_t slot; /* Slot to read from */ |
| 2220 | } __packed; |
| 2221 | |
| 2222 | struct ec_response_vstore_read { |
| 2223 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
| 2224 | } __packed; |
| 2225 | |
| 2226 | /* |
| 2227 | * Write temporary secure storage and lock it. |
| 2228 | */ |
| 2229 | #define EC_CMD_VSTORE_WRITE 0x4b |
| 2230 | |
| 2231 | struct ec_params_vstore_write { |
| 2232 | uint8_t slot; /* Slot to write to */ |
| 2233 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
| 2234 | } __packed; |
| 2235 | |
| 2236 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2237 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 2238 | * reuse the command number, but the data and behavior is incompatible. |
| 2239 | * Version 0 is what originally shipped on Link. |
| 2240 | * Version 1 separates the CPU thermal limits from the fan control. |
| 2241 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2242 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2243 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x50 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2244 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x51 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2245 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2246 | /* The version 0 structs are opaque. You have to know what they are for |
| 2247 | * the get/set commands to make any sense. |
| 2248 | */ |
| 2249 | |
| 2250 | /* Version 0 - set */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2251 | struct ec_params_thermal_set_threshold { |
| 2252 | uint8_t sensor_type; |
| 2253 | uint8_t threshold_id; |
| 2254 | uint16_t value; |
| 2255 | } __packed; |
| 2256 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2257 | /* Version 0 - get */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2258 | struct ec_params_thermal_get_threshold { |
| 2259 | uint8_t sensor_type; |
| 2260 | uint8_t threshold_id; |
| 2261 | } __packed; |
| 2262 | |
| 2263 | struct ec_response_thermal_get_threshold { |
| 2264 | uint16_t value; |
| 2265 | } __packed; |
| 2266 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2267 | |
| 2268 | /* The version 1 structs are visible. */ |
| 2269 | enum ec_temp_thresholds { |
| 2270 | EC_TEMP_THRESH_WARN = 0, |
| 2271 | EC_TEMP_THRESH_HIGH, |
| 2272 | EC_TEMP_THRESH_HALT, |
| 2273 | |
| 2274 | EC_TEMP_THRESH_COUNT |
| 2275 | }; |
| 2276 | |
| 2277 | /* Thermal configuration for one temperature sensor. Temps are in degrees K. |
| 2278 | * Zero values will be silently ignored by the thermal task. |
| 2279 | */ |
| 2280 | struct ec_thermal_config { |
| 2281 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
| 2282 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 2283 | uint32_t temp_fan_max; /* max active cooling needed */ |
| 2284 | } __packed; |
| 2285 | |
| 2286 | /* Version 1 - get config for one sensor. */ |
| 2287 | struct ec_params_thermal_get_threshold_v1 { |
| 2288 | uint32_t sensor_num; |
| 2289 | } __packed; |
| 2290 | /* This returns a struct ec_thermal_config */ |
| 2291 | |
| 2292 | /* Version 1 - set config for one sensor. |
| 2293 | * Use read-modify-write for best results! */ |
| 2294 | struct ec_params_thermal_set_threshold_v1 { |
| 2295 | uint32_t sensor_num; |
| 2296 | struct ec_thermal_config cfg; |
| 2297 | } __packed; |
| 2298 | /* This returns no data */ |
| 2299 | |
| 2300 | /****************************************************************************/ |
| 2301 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2302 | /* Toggle automatic fan control */ |
| 2303 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52 |
| 2304 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2305 | /* Version 1 of input params */ |
| 2306 | struct ec_params_auto_fan_ctrl_v1 { |
| 2307 | uint8_t fan_idx; |
| 2308 | } __packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2309 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2310 | /* Get/Set TMP006 calibration data */ |
| 2311 | #define EC_CMD_TMP006_GET_CALIBRATION 0x53 |
| 2312 | #define EC_CMD_TMP006_SET_CALIBRATION 0x54 |
| 2313 | |
| 2314 | /* |
| 2315 | * The original TMP006 calibration only needed four params, but now we need |
| 2316 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 2317 | * the params opaque. The v1 "get" response will include the algorithm number |
| 2318 | * and how many params it requires. That way we can change the EC code without |
| 2319 | * needing to update this file. We can also use a different algorithm on each |
| 2320 | * sensor. |
| 2321 | */ |
| 2322 | |
| 2323 | /* This is the same struct for both v0 and v1. */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2324 | struct ec_params_tmp006_get_calibration { |
| 2325 | uint8_t index; |
| 2326 | } __packed; |
| 2327 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2328 | /* Version 0 */ |
| 2329 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2330 | float s0; |
| 2331 | float b0; |
| 2332 | float b1; |
| 2333 | float b2; |
| 2334 | } __packed; |
| 2335 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2336 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2337 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2338 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2339 | float s0; |
| 2340 | float b0; |
| 2341 | float b1; |
| 2342 | float b2; |
| 2343 | } __packed; |
| 2344 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2345 | /* Version 1 */ |
| 2346 | struct ec_response_tmp006_get_calibration_v1 { |
| 2347 | uint8_t algorithm; |
| 2348 | uint8_t num_params; |
| 2349 | uint8_t reserved[2]; |
| 2350 | float val[0]; |
| 2351 | } __packed; |
| 2352 | |
| 2353 | struct ec_params_tmp006_set_calibration_v1 { |
| 2354 | uint8_t index; |
| 2355 | uint8_t algorithm; |
| 2356 | uint8_t num_params; |
| 2357 | uint8_t reserved; |
| 2358 | float val[0]; |
| 2359 | } __packed; |
| 2360 | |
| 2361 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2362 | /* Read raw TMP006 data */ |
| 2363 | #define EC_CMD_TMP006_GET_RAW 0x55 |
| 2364 | |
| 2365 | struct ec_params_tmp006_get_raw { |
| 2366 | uint8_t index; |
| 2367 | } __packed; |
| 2368 | |
| 2369 | struct ec_response_tmp006_get_raw { |
| 2370 | int32_t t; /* In 1/100 K */ |
| 2371 | int32_t v; /* In nV */ |
| 2372 | }; |
| 2373 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2374 | /*****************************************************************************/ |
| 2375 | /* MKBP - Matrix KeyBoard Protocol */ |
| 2376 | |
| 2377 | /* |
| 2378 | * Read key state |
| 2379 | * |
| 2380 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 2381 | * expected response size. |
| 2382 | */ |
| 2383 | #define EC_CMD_MKBP_STATE 0x60 |
| 2384 | |
| 2385 | /* Provide information about the matrix : number of rows and columns */ |
| 2386 | #define EC_CMD_MKBP_INFO 0x61 |
| 2387 | |
| 2388 | struct ec_response_mkbp_info { |
| 2389 | uint32_t rows; |
| 2390 | uint32_t cols; |
| 2391 | uint8_t switches; |
| 2392 | } __packed; |
| 2393 | |
| 2394 | /* Simulate key press */ |
| 2395 | #define EC_CMD_MKBP_SIMULATE_KEY 0x62 |
| 2396 | |
| 2397 | struct ec_params_mkbp_simulate_key { |
| 2398 | uint8_t col; |
| 2399 | uint8_t row; |
| 2400 | uint8_t pressed; |
| 2401 | } __packed; |
| 2402 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2403 | /* Configure keyboard scanning */ |
| 2404 | #define EC_CMD_MKBP_SET_CONFIG 0x64 |
| 2405 | #define EC_CMD_MKBP_GET_CONFIG 0x65 |
| 2406 | |
| 2407 | /* flags */ |
| 2408 | enum mkbp_config_flags { |
| 2409 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 2410 | }; |
| 2411 | |
| 2412 | enum mkbp_config_valid { |
| 2413 | EC_MKBP_VALID_SCAN_PERIOD = 1 << 0, |
| 2414 | EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1, |
| 2415 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3, |
| 2416 | EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4, |
| 2417 | EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5, |
| 2418 | EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6, |
| 2419 | EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7, |
| 2420 | }; |
| 2421 | |
| 2422 | /* Configuration for our key scanning algorithm */ |
| 2423 | struct ec_mkbp_config { |
| 2424 | uint32_t valid_mask; /* valid fields */ |
| 2425 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 2426 | uint8_t valid_flags; /* which flags are valid */ |
| 2427 | uint16_t scan_period_us; /* period between start of scans */ |
| 2428 | /* revert to interrupt mode after no activity for this long */ |
| 2429 | uint32_t poll_timeout_us; |
| 2430 | /* |
| 2431 | * minimum post-scan relax time. Once we finish a scan we check |
| 2432 | * the time until we are due to start the next one. If this time is |
| 2433 | * shorter this field, we use this instead. |
| 2434 | */ |
| 2435 | uint16_t min_post_scan_delay_us; |
| 2436 | /* delay between setting up output and waiting for it to settle */ |
| 2437 | uint16_t output_settle_us; |
| 2438 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 2439 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 2440 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 2441 | uint8_t fifo_max_depth; |
| 2442 | } __packed; |
| 2443 | |
| 2444 | struct ec_params_mkbp_set_config { |
| 2445 | struct ec_mkbp_config config; |
| 2446 | } __packed; |
| 2447 | |
| 2448 | struct ec_response_mkbp_get_config { |
| 2449 | struct ec_mkbp_config config; |
| 2450 | } __packed; |
| 2451 | |
| 2452 | /* Run the key scan emulation */ |
| 2453 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66 |
| 2454 | |
| 2455 | enum ec_keyscan_seq_cmd { |
| 2456 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 2457 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 2458 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 2459 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 2460 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 2461 | }; |
| 2462 | |
| 2463 | enum ec_collect_flags { |
| 2464 | /* |
| 2465 | * Indicates this scan was processed by the EC. Due to timing, some |
| 2466 | * scans may be skipped. |
| 2467 | */ |
| 2468 | EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0, |
| 2469 | }; |
| 2470 | |
| 2471 | struct ec_collect_item { |
| 2472 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
| 2473 | }; |
| 2474 | |
| 2475 | struct ec_params_keyscan_seq_ctrl { |
| 2476 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 2477 | union { |
| 2478 | struct { |
| 2479 | uint8_t active; /* still active */ |
| 2480 | uint8_t num_items; /* number of items */ |
| 2481 | /* Current item being presented */ |
| 2482 | uint8_t cur_item; |
| 2483 | } status; |
| 2484 | struct { |
| 2485 | /* |
| 2486 | * Absolute time for this scan, measured from the |
| 2487 | * start of the sequence. |
| 2488 | */ |
| 2489 | uint32_t time_us; |
| 2490 | uint8_t scan[0]; /* keyscan data */ |
| 2491 | } add; |
| 2492 | struct { |
| 2493 | uint8_t start_item; /* First item to return */ |
| 2494 | uint8_t num_items; /* Number of items to return */ |
| 2495 | } collect; |
| 2496 | }; |
| 2497 | } __packed; |
| 2498 | |
| 2499 | struct ec_result_keyscan_seq_ctrl { |
| 2500 | union { |
| 2501 | struct { |
| 2502 | uint8_t num_items; /* Number of items */ |
| 2503 | /* Data for each item */ |
| 2504 | struct ec_collect_item item[0]; |
| 2505 | } collect; |
| 2506 | }; |
| 2507 | } __packed; |
| 2508 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2509 | /* |
| 2510 | * Get the next pending MKBP event. |
| 2511 | * |
| 2512 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 2513 | */ |
| 2514 | #define EC_CMD_GET_NEXT_EVENT 0x67 |
| 2515 | |
| 2516 | enum ec_mkbp_event { |
| 2517 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 2518 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 2519 | |
| 2520 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 2521 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 2522 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2523 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 2524 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 2525 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2526 | /* Number of MKBP events */ |
| 2527 | EC_MKBP_EVENT_COUNT, |
| 2528 | }; |
| 2529 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2530 | union ec_response_get_next_data { |
| 2531 | uint8_t key_matrix[13]; |
| 2532 | |
| 2533 | /* Unaligned */ |
| 2534 | uint32_t host_event; |
| 2535 | |
| 2536 | struct { |
| 2537 | /* For aligning the fifo_info */ |
| 2538 | uint8_t rsvd[3]; |
| 2539 | struct ec_response_motion_sense_fifo_info info; |
| 2540 | } sensor_fifo; |
| 2541 | } __packed; |
| 2542 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2543 | struct ec_response_get_next_event { |
| 2544 | uint8_t event_type; |
| 2545 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2546 | union ec_response_get_next_data data; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2547 | } __packed; |
| 2548 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 2549 | /* Run keyboard factory test scanning */ |
| 2550 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x68 |
| 2551 | |
| 2552 | struct ec_response_keyboard_factory_test { |
| 2553 | uint16_t shorted; /* Keyboard pins are shorted */ |
| 2554 | } __packed; |
| 2555 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2556 | /*****************************************************************************/ |
| 2557 | /* Temperature sensor commands */ |
| 2558 | |
| 2559 | /* Read temperature sensor info */ |
| 2560 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70 |
| 2561 | |
| 2562 | struct ec_params_temp_sensor_get_info { |
| 2563 | uint8_t id; |
| 2564 | } __packed; |
| 2565 | |
| 2566 | struct ec_response_temp_sensor_get_info { |
| 2567 | char sensor_name[32]; |
| 2568 | uint8_t sensor_type; |
| 2569 | } __packed; |
| 2570 | |
| 2571 | /*****************************************************************************/ |
| 2572 | |
| 2573 | /* |
| 2574 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 2575 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 2576 | * below. |
| 2577 | */ |
| 2578 | |
| 2579 | /*****************************************************************************/ |
| 2580 | /* Host event commands */ |
| 2581 | |
| 2582 | /* |
| 2583 | * Host event mask params and response structures, shared by all of the host |
| 2584 | * event commands below. |
| 2585 | */ |
| 2586 | struct ec_params_host_event_mask { |
| 2587 | uint32_t mask; |
| 2588 | } __packed; |
| 2589 | |
| 2590 | struct ec_response_host_event_mask { |
| 2591 | uint32_t mask; |
| 2592 | } __packed; |
| 2593 | |
| 2594 | /* These all use ec_response_host_event_mask */ |
| 2595 | #define EC_CMD_HOST_EVENT_GET_B 0x87 |
| 2596 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88 |
| 2597 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89 |
| 2598 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d |
| 2599 | |
| 2600 | /* These all use ec_params_host_event_mask */ |
| 2601 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a |
| 2602 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b |
| 2603 | #define EC_CMD_HOST_EVENT_CLEAR 0x8c |
| 2604 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e |
| 2605 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f |
| 2606 | |
| 2607 | /*****************************************************************************/ |
| 2608 | /* Switch commands */ |
| 2609 | |
| 2610 | /* Enable/disable LCD backlight */ |
| 2611 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90 |
| 2612 | |
| 2613 | struct ec_params_switch_enable_backlight { |
| 2614 | uint8_t enabled; |
| 2615 | } __packed; |
| 2616 | |
| 2617 | /* Enable/disable WLAN/Bluetooth */ |
| 2618 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2619 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2620 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2621 | /* Version 0 params; no response */ |
| 2622 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2623 | uint8_t enabled; |
| 2624 | } __packed; |
| 2625 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2626 | /* Version 1 params */ |
| 2627 | struct ec_params_switch_enable_wireless_v1 { |
| 2628 | /* Flags to enable now */ |
| 2629 | uint8_t now_flags; |
| 2630 | |
| 2631 | /* Which flags to copy from now_flags */ |
| 2632 | uint8_t now_mask; |
| 2633 | |
| 2634 | /* |
| 2635 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 2636 | * transition. (Other flags will be disabled by the S0->S3 |
| 2637 | * transition.) |
| 2638 | */ |
| 2639 | uint8_t suspend_flags; |
| 2640 | |
| 2641 | /* Which flags to copy from suspend_flags */ |
| 2642 | uint8_t suspend_mask; |
| 2643 | } __packed; |
| 2644 | |
| 2645 | /* Version 1 response */ |
| 2646 | struct ec_response_switch_enable_wireless_v1 { |
| 2647 | /* Flags to enable now */ |
| 2648 | uint8_t now_flags; |
| 2649 | |
| 2650 | /* Flags to leave enabled in S3 */ |
| 2651 | uint8_t suspend_flags; |
| 2652 | } __packed; |
| 2653 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2654 | /*****************************************************************************/ |
| 2655 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 2656 | |
| 2657 | /* Set GPIO output value */ |
| 2658 | #define EC_CMD_GPIO_SET 0x92 |
| 2659 | |
| 2660 | struct ec_params_gpio_set { |
| 2661 | char name[32]; |
| 2662 | uint8_t val; |
| 2663 | } __packed; |
| 2664 | |
| 2665 | /* Get GPIO value */ |
| 2666 | #define EC_CMD_GPIO_GET 0x93 |
| 2667 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2668 | /* Version 0 of input params and response */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2669 | struct ec_params_gpio_get { |
| 2670 | char name[32]; |
| 2671 | } __packed; |
| 2672 | struct ec_response_gpio_get { |
| 2673 | uint8_t val; |
| 2674 | } __packed; |
| 2675 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2676 | /* Version 1 of input params and response */ |
| 2677 | struct ec_params_gpio_get_v1 { |
| 2678 | uint8_t subcmd; |
| 2679 | union { |
| 2680 | struct { |
| 2681 | char name[32]; |
| 2682 | } get_value_by_name; |
| 2683 | struct { |
| 2684 | uint8_t index; |
| 2685 | } get_info; |
| 2686 | }; |
| 2687 | } __packed; |
| 2688 | |
| 2689 | struct ec_response_gpio_get_v1 { |
| 2690 | union { |
| 2691 | struct { |
| 2692 | uint8_t val; |
| 2693 | } get_value_by_name, get_count; |
| 2694 | struct { |
| 2695 | uint8_t val; |
| 2696 | char name[32]; |
| 2697 | uint32_t flags; |
| 2698 | } get_info; |
| 2699 | }; |
| 2700 | } __packed; |
| 2701 | |
| 2702 | enum gpio_get_subcmd { |
| 2703 | EC_GPIO_GET_BY_NAME = 0, |
| 2704 | EC_GPIO_GET_COUNT = 1, |
| 2705 | EC_GPIO_GET_INFO = 2, |
| 2706 | }; |
| 2707 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2708 | /*****************************************************************************/ |
| 2709 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 2710 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2711 | /* |
| 2712 | * TODO(crosbug.com/p/23570): These commands are deprecated, and will be |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2713 | * removed soon. Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2714 | */ |
| 2715 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2716 | /* Read I2C bus */ |
| 2717 | #define EC_CMD_I2C_READ 0x94 |
| 2718 | |
| 2719 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2720 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2721 | uint8_t read_size; /* Either 8 or 16. */ |
| 2722 | uint8_t port; |
| 2723 | uint8_t offset; |
| 2724 | } __packed; |
| 2725 | struct ec_response_i2c_read { |
| 2726 | uint16_t data; |
| 2727 | } __packed; |
| 2728 | |
| 2729 | /* Write I2C bus */ |
| 2730 | #define EC_CMD_I2C_WRITE 0x95 |
| 2731 | |
| 2732 | struct ec_params_i2c_write { |
| 2733 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2734 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2735 | uint8_t write_size; /* Either 8 or 16. */ |
| 2736 | uint8_t port; |
| 2737 | uint8_t offset; |
| 2738 | } __packed; |
| 2739 | |
| 2740 | /*****************************************************************************/ |
| 2741 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 2742 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2743 | /* Force charge state machine to stop charging the battery or force it to |
| 2744 | * discharge the battery. |
| 2745 | */ |
| 2746 | #define EC_CMD_CHARGE_CONTROL 0x96 |
| 2747 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2748 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2749 | enum ec_charge_control_mode { |
| 2750 | CHARGE_CONTROL_NORMAL = 0, |
| 2751 | CHARGE_CONTROL_IDLE, |
| 2752 | CHARGE_CONTROL_DISCHARGE, |
| 2753 | }; |
| 2754 | |
| 2755 | struct ec_params_charge_control { |
| 2756 | uint32_t mode; /* enum charge_control_mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2757 | } __packed; |
| 2758 | |
| 2759 | /*****************************************************************************/ |
| 2760 | /* Console commands. Only available when flash write protect is unlocked. */ |
| 2761 | |
| 2762 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
| 2763 | #define EC_CMD_CONSOLE_SNAPSHOT 0x97 |
| 2764 | |
| 2765 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2766 | * Read data from the saved snapshot. If the subcmd parameter is |
| 2767 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 2768 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 2769 | * end of the previous snapshot. |
| 2770 | * |
| 2771 | * The params are only looked at in version >= 1 of this command. Prior |
| 2772 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2773 | * |
| 2774 | * Response is null-terminated string. Empty string, if there is no more |
| 2775 | * remaining output. |
| 2776 | */ |
| 2777 | #define EC_CMD_CONSOLE_READ 0x98 |
| 2778 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2779 | enum ec_console_read_subcmd { |
| 2780 | CONSOLE_READ_NEXT = 0, |
| 2781 | CONSOLE_READ_RECENT |
| 2782 | }; |
| 2783 | |
| 2784 | struct ec_params_console_read_v1 { |
| 2785 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
| 2786 | } __packed; |
| 2787 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2788 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2789 | |
| 2790 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2791 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2792 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2793 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 2794 | * EC_RES_SUCCESS if the command was successful. |
| 2795 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2796 | */ |
| 2797 | #define EC_CMD_BATTERY_CUT_OFF 0x99 |
| 2798 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2799 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0) |
| 2800 | |
| 2801 | struct ec_params_battery_cutoff { |
| 2802 | uint8_t flags; |
| 2803 | } __packed; |
| 2804 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2805 | /*****************************************************************************/ |
| 2806 | /* USB port mux control. */ |
| 2807 | |
| 2808 | /* |
| 2809 | * Switch USB mux or return to automatic switching. |
| 2810 | */ |
| 2811 | #define EC_CMD_USB_MUX 0x9a |
| 2812 | |
| 2813 | struct ec_params_usb_mux { |
| 2814 | uint8_t mux; |
| 2815 | } __packed; |
| 2816 | |
| 2817 | /*****************************************************************************/ |
| 2818 | /* LDOs / FETs control. */ |
| 2819 | |
| 2820 | enum ec_ldo_state { |
| 2821 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 2822 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 2823 | }; |
| 2824 | |
| 2825 | /* |
| 2826 | * Switch on/off a LDO. |
| 2827 | */ |
| 2828 | #define EC_CMD_LDO_SET 0x9b |
| 2829 | |
| 2830 | struct ec_params_ldo_set { |
| 2831 | uint8_t index; |
| 2832 | uint8_t state; |
| 2833 | } __packed; |
| 2834 | |
| 2835 | /* |
| 2836 | * Get LDO state. |
| 2837 | */ |
| 2838 | #define EC_CMD_LDO_GET 0x9c |
| 2839 | |
| 2840 | struct ec_params_ldo_get { |
| 2841 | uint8_t index; |
| 2842 | } __packed; |
| 2843 | |
| 2844 | struct ec_response_ldo_get { |
| 2845 | uint8_t state; |
| 2846 | } __packed; |
| 2847 | |
| 2848 | /*****************************************************************************/ |
| 2849 | /* Power info. */ |
| 2850 | |
| 2851 | /* |
| 2852 | * Get power info. |
| 2853 | */ |
| 2854 | #define EC_CMD_POWER_INFO 0x9d |
| 2855 | |
| 2856 | struct ec_response_power_info { |
| 2857 | uint32_t usb_dev_type; |
| 2858 | uint16_t voltage_ac; |
| 2859 | uint16_t voltage_system; |
| 2860 | uint16_t current_system; |
| 2861 | uint16_t usb_current_limit; |
| 2862 | } __packed; |
| 2863 | |
| 2864 | /*****************************************************************************/ |
| 2865 | /* I2C passthru command */ |
| 2866 | |
| 2867 | #define EC_CMD_I2C_PASSTHRU 0x9e |
| 2868 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2869 | /* Read data; if not present, message is a write */ |
| 2870 | #define EC_I2C_FLAG_READ (1 << 15) |
| 2871 | |
| 2872 | /* Mask for address */ |
| 2873 | #define EC_I2C_ADDR_MASK 0x3ff |
| 2874 | |
| 2875 | #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */ |
| 2876 | #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */ |
| 2877 | |
| 2878 | /* Any error */ |
| 2879 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 2880 | |
| 2881 | struct ec_params_i2c_passthru_msg { |
| 2882 | uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */ |
| 2883 | uint16_t len; /* Number of bytes to read or write */ |
| 2884 | } __packed; |
| 2885 | |
| 2886 | struct ec_params_i2c_passthru { |
| 2887 | uint8_t port; /* I2C port number */ |
| 2888 | uint8_t num_msgs; /* Number of messages */ |
| 2889 | struct ec_params_i2c_passthru_msg msg[]; |
| 2890 | /* Data to write for all messages is concatenated here */ |
| 2891 | } __packed; |
| 2892 | |
| 2893 | struct ec_response_i2c_passthru { |
| 2894 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 2895 | uint8_t num_msgs; /* Number of messages processed */ |
| 2896 | uint8_t data[]; /* Data read by messages concatenated here */ |
| 2897 | } __packed; |
| 2898 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 2899 | /*****************************************************************************/ |
| 2900 | /* Power button hang detect */ |
| 2901 | |
| 2902 | #define EC_CMD_HANG_DETECT 0x9f |
| 2903 | |
| 2904 | /* Reasons to start hang detection timer */ |
| 2905 | /* Power button pressed */ |
| 2906 | #define EC_HANG_START_ON_POWER_PRESS (1 << 0) |
| 2907 | |
| 2908 | /* Lid closed */ |
| 2909 | #define EC_HANG_START_ON_LID_CLOSE (1 << 1) |
| 2910 | |
| 2911 | /* Lid opened */ |
| 2912 | #define EC_HANG_START_ON_LID_OPEN (1 << 2) |
| 2913 | |
| 2914 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
| 2915 | #define EC_HANG_START_ON_RESUME (1 << 3) |
| 2916 | |
| 2917 | /* Reasons to cancel hang detection */ |
| 2918 | |
| 2919 | /* Power button released */ |
| 2920 | #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8) |
| 2921 | |
| 2922 | /* Any host command from AP received */ |
| 2923 | #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9) |
| 2924 | |
| 2925 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
| 2926 | #define EC_HANG_STOP_ON_SUSPEND (1 << 10) |
| 2927 | |
| 2928 | /* |
| 2929 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 2930 | * timer is started. This provides the AP a way to start the hang timer |
| 2931 | * without reconfiguring any of the other hang detect settings. Note that |
| 2932 | * you must previously have configured the timeouts. |
| 2933 | */ |
| 2934 | #define EC_HANG_START_NOW (1 << 30) |
| 2935 | |
| 2936 | /* |
| 2937 | * If this flag is set, all the other fields are ignored (including |
| 2938 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 2939 | * without reconfiguring any of the other hang detect settings. |
| 2940 | */ |
| 2941 | #define EC_HANG_STOP_NOW (1 << 31) |
| 2942 | |
| 2943 | struct ec_params_hang_detect { |
| 2944 | /* Flags; see EC_HANG_* */ |
| 2945 | uint32_t flags; |
| 2946 | |
| 2947 | /* Timeout in msec before generating host event, if enabled */ |
| 2948 | uint16_t host_event_timeout_msec; |
| 2949 | |
| 2950 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 2951 | uint16_t warm_reboot_timeout_msec; |
| 2952 | } __packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2953 | |
| 2954 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2955 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2956 | |
| 2957 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2958 | * This is the single catch-all host command to exchange data regarding the |
| 2959 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2960 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2961 | #define EC_CMD_CHARGE_STATE 0xa0 |
| 2962 | |
| 2963 | /* Subcommands for this host command */ |
| 2964 | enum charge_state_command { |
| 2965 | CHARGE_STATE_CMD_GET_STATE, |
| 2966 | CHARGE_STATE_CMD_GET_PARAM, |
| 2967 | CHARGE_STATE_CMD_SET_PARAM, |
| 2968 | CHARGE_STATE_NUM_CMDS |
| 2969 | }; |
| 2970 | |
| 2971 | /* |
| 2972 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 2973 | * params, which are handled by the particular implementations. |
| 2974 | */ |
| 2975 | enum charge_state_params { |
| 2976 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 2977 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 2978 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 2979 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 2980 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2981 | CS_PARAM_LIMIT_POWER, /* |
| 2982 | * Check if power is limited due to |
| 2983 | * low battery and / or a weak external |
| 2984 | * charger. READ ONLY. |
| 2985 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2986 | /* How many so far? */ |
| 2987 | CS_NUM_BASE_PARAMS, |
| 2988 | |
| 2989 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 2990 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 2991 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 2992 | |
| 2993 | /* Other custom param ranges go here... */ |
| 2994 | }; |
| 2995 | |
| 2996 | struct ec_params_charge_state { |
| 2997 | uint8_t cmd; /* enum charge_state_command */ |
| 2998 | union { |
| 2999 | struct { |
| 3000 | /* no args */ |
| 3001 | } get_state; |
| 3002 | |
| 3003 | struct { |
| 3004 | uint32_t param; /* enum charge_state_param */ |
| 3005 | } get_param; |
| 3006 | |
| 3007 | struct { |
| 3008 | uint32_t param; /* param to set */ |
| 3009 | uint32_t value; /* value to set */ |
| 3010 | } set_param; |
| 3011 | }; |
| 3012 | } __packed; |
| 3013 | |
| 3014 | struct ec_response_charge_state { |
| 3015 | union { |
| 3016 | struct { |
| 3017 | int ac; |
| 3018 | int chg_voltage; |
| 3019 | int chg_current; |
| 3020 | int chg_input_current; |
| 3021 | int batt_state_of_charge; |
| 3022 | } get_state; |
| 3023 | |
| 3024 | struct { |
| 3025 | uint32_t value; |
| 3026 | } get_param; |
| 3027 | struct { |
| 3028 | /* no return values */ |
| 3029 | } set_param; |
| 3030 | }; |
| 3031 | } __packed; |
| 3032 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3033 | |
| 3034 | /* |
| 3035 | * Set maximum battery charging current. |
| 3036 | */ |
| 3037 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1 |
| 3038 | |
| 3039 | struct ec_params_current_limit { |
| 3040 | uint32_t limit; /* in mA */ |
| 3041 | } __packed; |
| 3042 | |
| 3043 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3044 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3045 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3046 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0xa2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3047 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3048 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
| 3049 | struct ec_params_external_power_limit_v1 { |
| 3050 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 3051 | uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3052 | } __packed; |
| 3053 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3054 | #define EC_POWER_LIMIT_NONE 0xffff |
| 3055 | |
| 3056 | /*****************************************************************************/ |
| 3057 | /* Hibernate/Deep Sleep Commands */ |
| 3058 | |
| 3059 | /* Set the delay before going into hibernation. */ |
| 3060 | #define EC_CMD_HIBERNATION_DELAY 0xa8 |
| 3061 | |
| 3062 | struct ec_params_hibernation_delay { |
| 3063 | /* |
| 3064 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 3065 | * current settings without changing them. |
| 3066 | */ |
| 3067 | uint32_t seconds; |
| 3068 | }; |
| 3069 | |
| 3070 | struct ec_response_hibernation_delay { |
| 3071 | /* |
| 3072 | * The current time in seconds in which the system has been in the G3 |
| 3073 | * state. This value is reset if the EC transitions out of G3. |
| 3074 | */ |
| 3075 | uint32_t time_g3; |
| 3076 | |
| 3077 | /* |
| 3078 | * The current time remaining in seconds until the EC should hibernate. |
| 3079 | * This value is also reset if the EC transitions out of G3. |
| 3080 | */ |
| 3081 | uint32_t time_remaining; |
| 3082 | |
| 3083 | /* |
| 3084 | * The current time in seconds that the EC should wait in G3 before |
| 3085 | * hibernating. |
| 3086 | */ |
| 3087 | uint32_t hibernate_delay; |
| 3088 | }; |
| 3089 | |
| 3090 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3091 | /*****************************************************************************/ |
| 3092 | /* Smart battery pass-through */ |
| 3093 | |
| 3094 | /* Get / Set 16-bit smart battery registers */ |
| 3095 | #define EC_CMD_SB_READ_WORD 0xb0 |
| 3096 | #define EC_CMD_SB_WRITE_WORD 0xb1 |
| 3097 | |
| 3098 | /* Get / Set string smart battery parameters |
| 3099 | * formatted as SMBUS "block". |
| 3100 | */ |
| 3101 | #define EC_CMD_SB_READ_BLOCK 0xb2 |
| 3102 | #define EC_CMD_SB_WRITE_BLOCK 0xb3 |
| 3103 | |
| 3104 | struct ec_params_sb_rd { |
| 3105 | uint8_t reg; |
| 3106 | } __packed; |
| 3107 | |
| 3108 | struct ec_response_sb_rd_word { |
| 3109 | uint16_t value; |
| 3110 | } __packed; |
| 3111 | |
| 3112 | struct ec_params_sb_wr_word { |
| 3113 | uint8_t reg; |
| 3114 | uint16_t value; |
| 3115 | } __packed; |
| 3116 | |
| 3117 | struct ec_response_sb_rd_block { |
| 3118 | uint8_t data[32]; |
| 3119 | } __packed; |
| 3120 | |
| 3121 | struct ec_params_sb_wr_block { |
| 3122 | uint8_t reg; |
| 3123 | uint16_t data[32]; |
| 3124 | } __packed; |
| 3125 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3126 | |
| 3127 | /*****************************************************************************/ |
| 3128 | /* Battery vendor parameters |
| 3129 | * |
| 3130 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 3131 | * differ between boards or batteries. On a set operation, the response |
| 3132 | * contains the actual value set, which may be rounded or clipped from the |
| 3133 | * requested value. |
| 3134 | */ |
| 3135 | |
| 3136 | #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4 |
| 3137 | |
| 3138 | enum ec_battery_vendor_param_mode { |
| 3139 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 3140 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 3141 | }; |
| 3142 | |
| 3143 | struct ec_params_battery_vendor_param { |
| 3144 | uint32_t param; |
| 3145 | uint32_t value; |
| 3146 | uint8_t mode; |
| 3147 | } __packed; |
| 3148 | |
| 3149 | struct ec_response_battery_vendor_param { |
| 3150 | uint32_t value; |
| 3151 | } __packed; |
| 3152 | |
| 3153 | /*****************************************************************************/ |
| 3154 | /* |
| 3155 | * Smart Battery Firmware Update Commands |
| 3156 | */ |
| 3157 | #define EC_CMD_SB_FW_UPDATE 0xb5 |
| 3158 | |
| 3159 | enum ec_sb_fw_update_subcmd { |
| 3160 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 3161 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 3162 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 3163 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 3164 | EC_SB_FW_UPDATE_END = 0x4, |
| 3165 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 3166 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 3167 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 3168 | }; |
| 3169 | |
| 3170 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 3171 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 3172 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 3173 | |
| 3174 | struct ec_sb_fw_update_header { |
| 3175 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 3176 | uint16_t fw_id; /* firmware id */ |
| 3177 | } __packed; |
| 3178 | |
| 3179 | struct ec_params_sb_fw_update { |
| 3180 | struct ec_sb_fw_update_header hdr; |
| 3181 | union { |
| 3182 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 3183 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 3184 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 3185 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 3186 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 3187 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
| 3188 | struct { |
| 3189 | /* no args */ |
| 3190 | } dummy; |
| 3191 | |
| 3192 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
| 3193 | struct { |
| 3194 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 3195 | } write; |
| 3196 | }; |
| 3197 | } __packed; |
| 3198 | |
| 3199 | struct ec_response_sb_fw_update { |
| 3200 | union { |
| 3201 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 3202 | struct { |
| 3203 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 3204 | } info; |
| 3205 | |
| 3206 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 3207 | struct { |
| 3208 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 3209 | } status; |
| 3210 | }; |
| 3211 | } __packed; |
| 3212 | |
| 3213 | /* |
| 3214 | * Entering Verified Boot Mode Command |
| 3215 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 3216 | * Valid Modes are: normal, developer, and recovery. |
| 3217 | */ |
| 3218 | #define EC_CMD_ENTERING_MODE 0xb6 |
| 3219 | |
| 3220 | struct ec_params_entering_mode { |
| 3221 | int vboot_mode; |
| 3222 | } __packed; |
| 3223 | |
| 3224 | #define VBOOT_MODE_NORMAL 0 |
| 3225 | #define VBOOT_MODE_DEVELOPER 1 |
| 3226 | #define VBOOT_MODE_RECOVERY 2 |
| 3227 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3228 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 3229 | /* |
| 3230 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 3231 | * certain addresses (board-specific). |
| 3232 | */ |
| 3233 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0xb7 |
| 3234 | |
| 3235 | enum ec_i2c_passthru_protect_subcmd { |
| 3236 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0, |
| 3237 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1, |
| 3238 | }; |
| 3239 | |
| 3240 | struct ec_params_i2c_passthru_protect { |
| 3241 | uint8_t subcmd; |
| 3242 | uint8_t port; /* I2C port number */ |
| 3243 | } __packed; |
| 3244 | |
| 3245 | struct ec_response_i2c_passthru_protect { |
| 3246 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
| 3247 | } __packed; |
| 3248 | |
| 3249 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3250 | /* System commands */ |
| 3251 | |
| 3252 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3253 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 3254 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3255 | */ |
| 3256 | #define EC_CMD_REBOOT_EC 0xd2 |
| 3257 | |
| 3258 | /* Command */ |
| 3259 | enum ec_reboot_cmd { |
| 3260 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3261 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 3262 | EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3263 | /* (command 3 was jump to RW-B) */ |
| 3264 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3265 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 3266 | EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3267 | }; |
| 3268 | |
| 3269 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
| 3270 | #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3271 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3272 | |
| 3273 | struct ec_params_reboot_ec { |
| 3274 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 3275 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
| 3276 | } __packed; |
| 3277 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3278 | /* |
| 3279 | * Get information on last EC panic. |
| 3280 | * |
| 3281 | * Returns variable-length platform-dependent panic information. See panic.h |
| 3282 | * for details. |
| 3283 | */ |
| 3284 | #define EC_CMD_GET_PANIC_INFO 0xd3 |
| 3285 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3286 | /*****************************************************************************/ |
| 3287 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3288 | * Special commands |
| 3289 | * |
| 3290 | * These do not follow the normal rules for commands. See each command for |
| 3291 | * details. |
| 3292 | */ |
| 3293 | |
| 3294 | /* |
| 3295 | * Reboot NOW |
| 3296 | * |
| 3297 | * This command will work even when the EC LPC interface is busy, because the |
| 3298 | * reboot command is processed at interrupt level. Note that when the EC |
| 3299 | * reboots, the host will reboot too, so there is no response to this command. |
| 3300 | * |
| 3301 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 3302 | */ |
| 3303 | #define EC_CMD_REBOOT 0xd1 /* Think "die" */ |
| 3304 | |
| 3305 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3306 | * Resend last response (not supported on LPC). |
| 3307 | * |
| 3308 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 3309 | * there was no previous command, or the previous command's response was too |
| 3310 | * big to save. |
| 3311 | */ |
| 3312 | #define EC_CMD_RESEND_RESPONSE 0xdb |
| 3313 | |
| 3314 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3315 | * This header byte on a command indicate version 0. Any header byte less |
| 3316 | * than this means that we are talking to an old EC which doesn't support |
| 3317 | * versioning. In that case, we assume version 0. |
| 3318 | * |
| 3319 | * Header bytes greater than this indicate a later version. For example, |
| 3320 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 3321 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3322 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3323 | */ |
| 3324 | #define EC_CMD_VERSION0 0xdc |
| 3325 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3326 | /*****************************************************************************/ |
| 3327 | /* |
| 3328 | * PD commands |
| 3329 | * |
| 3330 | * These commands are for PD MCU communication. |
| 3331 | */ |
| 3332 | |
| 3333 | /* EC to PD MCU exchange status command */ |
| 3334 | #define EC_CMD_PD_EXCHANGE_STATUS 0x100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3335 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3336 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3337 | enum pd_charge_state { |
| 3338 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 3339 | PD_CHARGE_NONE, /* No charging allowed */ |
| 3340 | PD_CHARGE_5V, /* 5V charging only */ |
| 3341 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 3342 | }; |
| 3343 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3344 | /* Status of EC being sent to PD */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3345 | #define EC_STATUS_HIBERNATING (1 << 0) |
| 3346 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3347 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3348 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3349 | int8_t batt_soc; /* battery state of charge */ |
| 3350 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3351 | } __packed; |
| 3352 | |
| 3353 | /* Status of PD being sent back to EC */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3354 | #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */ |
| 3355 | #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */ |
| 3356 | #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] | 3357 | #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */ |
| 3358 | #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */ |
| 3359 | #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */ |
| 3360 | #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */ |
| 3361 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 3362 | PD_STATUS_TCPC_ALERT_1 | \ |
| 3363 | PD_STATUS_HOST_EVENT) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3364 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3365 | uint32_t curr_lim_ma; /* input current limit */ |
| 3366 | uint16_t status; /* PD MCU status */ |
| 3367 | int8_t active_charge_port; /* active charging port */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3368 | } __packed; |
| 3369 | |
| 3370 | /* AP to PD MCU host event status command, cleared on read */ |
| 3371 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x104 |
| 3372 | |
| 3373 | /* PD MCU host event status bits */ |
| 3374 | #define PD_EVENT_UPDATE_DEVICE (1 << 0) |
| 3375 | #define PD_EVENT_POWER_CHANGE (1 << 1) |
| 3376 | #define PD_EVENT_IDENTITY_RECEIVED (1 << 2) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3377 | #define PD_EVENT_DATA_SWAP (1 << 3) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3378 | struct ec_response_host_event_status { |
| 3379 | uint32_t status; /* PD MCU host event status */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3380 | } __packed; |
| 3381 | |
| 3382 | /* Set USB type-C port role and muxes */ |
| 3383 | #define EC_CMD_USB_PD_CONTROL 0x101 |
| 3384 | |
| 3385 | enum usb_pd_control_role { |
| 3386 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 3387 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 3388 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 3389 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 3390 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
| 3391 | USB_PD_CTRL_ROLE_COUNT |
| 3392 | }; |
| 3393 | |
| 3394 | enum usb_pd_control_mux { |
| 3395 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 3396 | USB_PD_CTRL_MUX_NONE = 1, |
| 3397 | USB_PD_CTRL_MUX_USB = 2, |
| 3398 | USB_PD_CTRL_MUX_DP = 3, |
| 3399 | USB_PD_CTRL_MUX_DOCK = 4, |
| 3400 | USB_PD_CTRL_MUX_AUTO = 5, |
| 3401 | USB_PD_CTRL_MUX_COUNT |
| 3402 | }; |
| 3403 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3404 | enum usb_pd_control_swap { |
| 3405 | USB_PD_CTRL_SWAP_NONE = 0, |
| 3406 | USB_PD_CTRL_SWAP_DATA = 1, |
| 3407 | USB_PD_CTRL_SWAP_POWER = 2, |
| 3408 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 3409 | USB_PD_CTRL_SWAP_COUNT |
| 3410 | }; |
| 3411 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3412 | struct ec_params_usb_pd_control { |
| 3413 | uint8_t port; |
| 3414 | uint8_t role; |
| 3415 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3416 | uint8_t swap; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3417 | } __packed; |
| 3418 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3419 | #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ |
| 3420 | #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ |
| 3421 | #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ |
| 3422 | |
| 3423 | #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */ |
| 3424 | #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */ |
| 3425 | #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */ |
| 3426 | #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */ |
| 3427 | #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */ |
| 3428 | #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */ |
| 3429 | #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */ |
| 3430 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3431 | struct ec_response_usb_pd_control { |
| 3432 | uint8_t enabled; |
| 3433 | uint8_t role; |
| 3434 | uint8_t polarity; |
| 3435 | uint8_t state; |
| 3436 | } __packed; |
| 3437 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3438 | struct ec_response_usb_pd_control_v1 { |
| 3439 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3440 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3441 | uint8_t polarity; |
| 3442 | char state[32]; |
| 3443 | } __packed; |
| 3444 | |
| 3445 | #define EC_CMD_USB_PD_PORTS 0x102 |
| 3446 | |
| 3447 | struct ec_response_usb_pd_ports { |
| 3448 | uint8_t num_ports; |
| 3449 | } __packed; |
| 3450 | |
| 3451 | #define EC_CMD_USB_PD_POWER_INFO 0x103 |
| 3452 | |
| 3453 | #define PD_POWER_CHARGING_PORT 0xff |
| 3454 | struct ec_params_usb_pd_power_info { |
| 3455 | uint8_t port; |
| 3456 | } __packed; |
| 3457 | |
| 3458 | enum usb_chg_type { |
| 3459 | USB_CHG_TYPE_NONE, |
| 3460 | USB_CHG_TYPE_PD, |
| 3461 | USB_CHG_TYPE_C, |
| 3462 | USB_CHG_TYPE_PROPRIETARY, |
| 3463 | USB_CHG_TYPE_BC12_DCP, |
| 3464 | USB_CHG_TYPE_BC12_CDP, |
| 3465 | USB_CHG_TYPE_BC12_SDP, |
| 3466 | USB_CHG_TYPE_OTHER, |
| 3467 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3468 | USB_CHG_TYPE_UNKNOWN, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3469 | }; |
| 3470 | enum usb_power_roles { |
| 3471 | USB_PD_PORT_POWER_DISCONNECTED, |
| 3472 | USB_PD_PORT_POWER_SOURCE, |
| 3473 | USB_PD_PORT_POWER_SINK, |
| 3474 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 3475 | }; |
| 3476 | |
| 3477 | struct usb_chg_measures { |
| 3478 | uint16_t voltage_max; |
| 3479 | uint16_t voltage_now; |
| 3480 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3481 | uint16_t current_lim; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3482 | } __packed; |
| 3483 | |
| 3484 | struct ec_response_usb_pd_power_info { |
| 3485 | uint8_t role; |
| 3486 | uint8_t type; |
| 3487 | uint8_t dualrole; |
| 3488 | uint8_t reserved1; |
| 3489 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3490 | uint32_t max_power; |
| 3491 | } __packed; |
| 3492 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3493 | /* Write USB-PD device FW */ |
| 3494 | #define EC_CMD_USB_PD_FW_UPDATE 0x110 |
| 3495 | |
| 3496 | enum usb_pd_fw_update_cmds { |
| 3497 | USB_PD_FW_REBOOT, |
| 3498 | USB_PD_FW_FLASH_ERASE, |
| 3499 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3500 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3501 | }; |
| 3502 | |
| 3503 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3504 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3505 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3506 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3507 | uint32_t size; /* Size to write in bytes */ |
| 3508 | /* Followed by data to write */ |
| 3509 | } __packed; |
| 3510 | |
| 3511 | /* Write USB-PD Accessory RW_HASH table entry */ |
| 3512 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3513 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 3514 | #define PD_RW_HASH_SIZE 20 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3515 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3516 | uint16_t dev_id; |
| 3517 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
| 3518 | uint8_t reserved; /* For alignment of current_image */ |
| 3519 | uint32_t current_image; /* One of ec_current_image */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3520 | } __packed; |
| 3521 | |
| 3522 | /* Read USB-PD Accessory info */ |
| 3523 | #define EC_CMD_USB_PD_DEV_INFO 0x112 |
| 3524 | |
| 3525 | struct ec_params_usb_pd_info_request { |
| 3526 | uint8_t port; |
| 3527 | } __packed; |
| 3528 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3529 | /* Read USB-PD Device discovery info */ |
| 3530 | #define EC_CMD_USB_PD_DISCOVERY 0x113 |
| 3531 | struct ec_params_usb_pd_discovery_entry { |
| 3532 | uint16_t vid; /* USB-IF VID */ |
| 3533 | uint16_t pid; /* USB-IF PID */ |
| 3534 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
| 3535 | } __packed; |
| 3536 | |
| 3537 | /* Override default charge behavior */ |
| 3538 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x114 |
| 3539 | |
| 3540 | /* Negative port parameters have special meaning */ |
| 3541 | enum usb_pd_override_ports { |
| 3542 | OVERRIDE_DONT_CHARGE = -2, |
| 3543 | OVERRIDE_OFF = -1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3544 | /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3545 | }; |
| 3546 | |
| 3547 | struct ec_params_charge_port_override { |
| 3548 | int16_t override_port; /* Override port# */ |
| 3549 | } __packed; |
| 3550 | |
| 3551 | /* Read (and delete) one entry of PD event log */ |
| 3552 | #define EC_CMD_PD_GET_LOG_ENTRY 0x115 |
| 3553 | |
| 3554 | struct ec_response_pd_log { |
| 3555 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 3556 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 3557 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 3558 | uint16_t data; /* type-defined data payload */ |
| 3559 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
| 3560 | } __packed; |
| 3561 | |
| 3562 | |
| 3563 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 3564 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 3565 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3566 | #define PD_LOG_SIZE_MASK 0x1f |
| 3567 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3568 | #define PD_LOG_PORT_SHIFT 5 |
| 3569 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 3570 | ((size) & PD_LOG_SIZE_MASK)) |
| 3571 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 3572 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 3573 | |
| 3574 | /* PD event log : entry types */ |
| 3575 | /* PD MCU events */ |
| 3576 | #define PD_EVENT_MCU_BASE 0x00 |
| 3577 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 3578 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 3579 | /* Reserved for custom board event */ |
| 3580 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 3581 | /* PD generic accessory events */ |
| 3582 | #define PD_EVENT_ACC_BASE 0x20 |
| 3583 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 3584 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 3585 | /* PD power supply events */ |
| 3586 | #define PD_EVENT_PS_BASE 0x40 |
| 3587 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 3588 | /* PD video dongles events */ |
| 3589 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 3590 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 3591 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 3592 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3593 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3594 | |
| 3595 | /* |
| 3596 | * PD_EVENT_MCU_CHARGE event definition : |
| 3597 | * the payload is "struct usb_chg_measures" |
| 3598 | * the data field contains the port state flags as defined below : |
| 3599 | */ |
| 3600 | /* Port partner is a dual role device */ |
| 3601 | #define CHARGE_FLAGS_DUAL_ROLE (1 << 15) |
| 3602 | /* Port is the pending override port */ |
| 3603 | #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14) |
| 3604 | /* Port is the override port */ |
| 3605 | #define CHARGE_FLAGS_OVERRIDE (1 << 13) |
| 3606 | /* Charger type */ |
| 3607 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3608 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3609 | /* Power delivery role */ |
| 3610 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 3611 | |
| 3612 | /* |
| 3613 | * PD_EVENT_PS_FAULT data field flags definition : |
| 3614 | */ |
| 3615 | #define PS_FAULT_OCP 1 |
| 3616 | #define PS_FAULT_FAST_OCP 2 |
| 3617 | #define PS_FAULT_OVP 3 |
| 3618 | #define PS_FAULT_DISCH 4 |
| 3619 | |
| 3620 | /* |
| 3621 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 3622 | */ |
| 3623 | struct mcdp_version { |
| 3624 | uint8_t major; |
| 3625 | uint8_t minor; |
| 3626 | uint16_t build; |
| 3627 | } __packed; |
| 3628 | |
| 3629 | struct mcdp_info { |
| 3630 | uint8_t family[2]; |
| 3631 | uint8_t chipid[2]; |
| 3632 | struct mcdp_version irom; |
| 3633 | struct mcdp_version fw; |
| 3634 | } __packed; |
| 3635 | |
| 3636 | /* struct mcdp_info field decoding */ |
| 3637 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 3638 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 3639 | |
| 3640 | /* Get/Set USB-PD Alternate mode info */ |
| 3641 | #define EC_CMD_USB_PD_GET_AMODE 0x116 |
| 3642 | struct ec_params_usb_pd_get_mode_request { |
| 3643 | uint16_t svid_idx; /* SVID index to get */ |
| 3644 | uint8_t port; /* port */ |
| 3645 | } __packed; |
| 3646 | |
| 3647 | struct ec_params_usb_pd_get_mode_response { |
| 3648 | uint16_t svid; /* SVID */ |
| 3649 | uint16_t opos; /* Object Position */ |
| 3650 | uint32_t vdo[6]; /* Mode VDOs */ |
| 3651 | } __packed; |
| 3652 | |
| 3653 | #define EC_CMD_USB_PD_SET_AMODE 0x117 |
| 3654 | |
| 3655 | enum pd_mode_cmd { |
| 3656 | PD_EXIT_MODE = 0, |
| 3657 | PD_ENTER_MODE = 1, |
| 3658 | /* Not a command. Do NOT remove. */ |
| 3659 | PD_MODE_CMD_COUNT, |
| 3660 | }; |
| 3661 | |
| 3662 | struct ec_params_usb_pd_set_mode_request { |
| 3663 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 3664 | uint16_t svid; /* SVID to set */ |
| 3665 | uint8_t opos; /* Object Position */ |
| 3666 | uint8_t port; /* port */ |
| 3667 | } __packed; |
| 3668 | |
| 3669 | /* Ask the PD MCU to record a log of a requested type */ |
| 3670 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x118 |
| 3671 | |
| 3672 | struct ec_params_pd_write_log_entry { |
| 3673 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 3674 | uint8_t port; /* port#, or 0 for events unrelated to a given port */ |
| 3675 | } __packed; |
| 3676 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3677 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame^] | 3678 | /* Control USB-PD chip */ |
| 3679 | #define EC_CMD_PD_CONTROL 0x119 |
| 3680 | |
| 3681 | enum ec_pd_control_cmd { |
| 3682 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 3683 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 3684 | PD_RESET, /* Force reset the PD chip */ |
| 3685 | PD_CONTROL_DISABLE /* Disable further calls to this command */ |
| 3686 | }; |
| 3687 | |
| 3688 | struct ec_params_pd_control { |
| 3689 | uint8_t chip; /* chip id (should be 0) */ |
| 3690 | uint8_t subcmd; |
| 3691 | } __packed; |
| 3692 | |
| 3693 | #endif /* !__ACPI__ */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3694 | |
| 3695 | /*****************************************************************************/ |
| 3696 | /* |
| 3697 | * Blob commands are just opaque chunks of data, sent with proto v3. |
| 3698 | * params is struct ec_host_request, response is struct ec_host_response. |
| 3699 | */ |
| 3700 | #define EC_CMD_BLOB 0x200 |
| 3701 | |
| 3702 | /*****************************************************************************/ |
| 3703 | /* |
| 3704 | * Reserve a range of host commands for board-specific, experimental, or |
| 3705 | * special purpose features. These can be (re)used without updating this file. |
| 3706 | * |
| 3707 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 3708 | * their EC commands for easier development, testing, debugging, and support. |
| 3709 | * |
| 3710 | * In your experimental code, you may want to do something like this: |
| 3711 | * |
| 3712 | * #define EC_CMD_MAGIC_FOO (EC_CMD_BOARD_SPECIFIC_BASE + 0x000) |
| 3713 | * #define EC_CMD_MAGIC_BAR (EC_CMD_BOARD_SPECIFIC_BASE + 0x001) |
| 3714 | * #define EC_CMD_MAGIC_HEY (EC_CMD_BOARD_SPECIFIC_BASE + 0x002) |
| 3715 | */ |
| 3716 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 3717 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 3718 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3719 | /*****************************************************************************/ |
| 3720 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3721 | * Passthru commands |
| 3722 | * |
| 3723 | * Some platforms have sub-processors chained to each other. For example. |
| 3724 | * |
| 3725 | * AP <--> EC <--> PD MCU |
| 3726 | * |
| 3727 | * The top 2 bits of the command number are used to indicate which device the |
| 3728 | * command is intended for. Device 0 is always the device receiving the |
| 3729 | * command; other device mapping is board-specific. |
| 3730 | * |
| 3731 | * When a device receives a command to be passed to a sub-processor, it passes |
| 3732 | * it on with the device number set back to 0. This allows the sub-processor |
| 3733 | * to remain blissfully unaware of whether the command originated on the next |
| 3734 | * device up the chain, or was passed through from the AP. |
| 3735 | * |
| 3736 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 3737 | * AP sends command 0x4002 to the EC |
| 3738 | * EC sends command 0x0002 to the PD MCU |
| 3739 | * EC forwards PD MCU response back to the AP |
| 3740 | */ |
| 3741 | |
| 3742 | /* Offset and max command number for sub-device n */ |
| 3743 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 3744 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 3745 | |
| 3746 | /*****************************************************************************/ |
| 3747 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3748 | * Deprecated constants. These constants have been renamed for clarity. The |
| 3749 | * meaning and size has not changed. Programs that use the old names should |
| 3750 | * switch to the new names soon, as the old names may not be carried forward |
| 3751 | * forever. |
| 3752 | */ |
| 3753 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 3754 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 3755 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 3756 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3757 | #endif /* __CROS_EC_EC_COMMANDS_H */ |