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