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 */ |
| 600 | #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1)) |
| 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, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1115 | }; |
| 1116 | |
| 1117 | #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) |
| 1118 | #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1119 | struct __ec_align4 ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1120 | uint32_t flags[2]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1121 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1122 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1123 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 1124 | /* Get the board's SKU ID from EC */ |
| 1125 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1126 | |
| 1127 | struct __ec_align4 ec_response_sku_id { |
| 1128 | uint32_t sku_id; |
| 1129 | }; |
| 1130 | |
| 1131 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1132 | /* Flash commands */ |
| 1133 | |
| 1134 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1135 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1136 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1137 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1138 | /* Version 0 returns these fields */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1139 | struct __ec_align4 ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1140 | /* Usable flash size, in bytes */ |
| 1141 | uint32_t flash_size; |
| 1142 | /* |
| 1143 | * Write block size. Write offset and size must be a multiple |
| 1144 | * of this. |
| 1145 | */ |
| 1146 | uint32_t write_block_size; |
| 1147 | /* |
| 1148 | * Erase block size. Erase offset and size must be a multiple |
| 1149 | * of this. |
| 1150 | */ |
| 1151 | uint32_t erase_block_size; |
| 1152 | /* |
| 1153 | * Protection block size. Protection offset and size must be a |
| 1154 | * multiple of this. |
| 1155 | */ |
| 1156 | uint32_t protect_block_size; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1157 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1158 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1159 | /* Flags for version 1+ flash info command */ |
| 1160 | /* EC flash erases bits to 0 instead of 1 */ |
| 1161 | #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0) |
| 1162 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 1163 | /* Flash must be selected for read/write/erase operations to succeed. This may |
| 1164 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1165 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1166 | * or where the read/write/erase operations require cleanly suspending other |
| 1167 | * chip functionality. */ |
| 1168 | #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1) |
| 1169 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1170 | /* |
| 1171 | * Version 1 returns the same initial fields as version 0, with additional |
| 1172 | * fields following. |
| 1173 | * |
| 1174 | * 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] | 1175 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1176 | * one. |
| 1177 | * |
| 1178 | * Version 2 supports flash banks of different sizes: |
| 1179 | * The caller specified the number of banks it has preallocated |
| 1180 | * (num_banks_desc) |
| 1181 | * The EC returns the number of banks describing the flash memory. |
| 1182 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1183 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1184 | struct __ec_align4 ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1185 | /* Version 0 fields; see above for description */ |
| 1186 | uint32_t flash_size; |
| 1187 | uint32_t write_block_size; |
| 1188 | uint32_t erase_block_size; |
| 1189 | uint32_t protect_block_size; |
| 1190 | |
| 1191 | /* Version 1 adds these fields: */ |
| 1192 | /* |
| 1193 | * Ideal write size in bytes. Writes will be fastest if size is |
| 1194 | * exactly this and offset is a multiple of this. For example, an EC |
| 1195 | * may have a write buffer which can do half-page operations if data is |
| 1196 | * aligned, and a slower word-at-a-time write mode. |
| 1197 | */ |
| 1198 | uint32_t write_ideal_size; |
| 1199 | |
| 1200 | /* Flags; see EC_FLASH_INFO_* */ |
| 1201 | uint32_t flags; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1202 | }; |
| 1203 | |
| 1204 | struct __ec_align4 ec_params_flash_info_2 { |
| 1205 | /* Number of banks to describe */ |
| 1206 | uint16_t num_banks_desc; |
| 1207 | /* Reserved; set 0; ignore on read */ |
| 1208 | uint8_t reserved[2]; |
| 1209 | }; |
| 1210 | |
| 1211 | struct ec_flash_bank { |
| 1212 | /* Number of sector is in this bank. */ |
| 1213 | uint16_t count; |
| 1214 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1215 | uint8_t size_exp; |
| 1216 | /* Minimal write size for the sectors in this bank */ |
| 1217 | uint8_t write_size_exp; |
| 1218 | /* Erase size for the sectors in this bank */ |
| 1219 | uint8_t erase_size_exp; |
| 1220 | /* Size for write protection, usually identical to erase size. */ |
| 1221 | uint8_t protect_size_exp; |
| 1222 | /* Reserved; set 0; ignore on read */ |
| 1223 | uint8_t reserved[2]; |
| 1224 | }; |
| 1225 | |
| 1226 | struct __ec_align4 ec_response_flash_info_2 { |
| 1227 | /* Total flash in the EC. */ |
| 1228 | uint32_t flash_size; |
| 1229 | /* Flags; see EC_FLASH_INFO_* */ |
| 1230 | uint32_t flags; |
| 1231 | /* Maximum size to use to send data to write to the EC. */ |
| 1232 | uint32_t write_ideal_size; |
| 1233 | /* Number of banks present in the EC. */ |
| 1234 | uint16_t num_banks_total; |
| 1235 | /* Number of banks described in banks array. */ |
| 1236 | uint16_t num_banks_desc; |
| 1237 | struct ec_flash_bank banks[0]; |
| 1238 | }; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1239 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1240 | /* |
| 1241 | * Read flash |
| 1242 | * |
| 1243 | * Response is params.size bytes of data. |
| 1244 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1245 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1246 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1247 | struct __ec_align4 ec_params_flash_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1248 | uint32_t offset; /* Byte offset to read */ |
| 1249 | uint32_t size; /* Size to read in bytes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1250 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1251 | |
| 1252 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1253 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1254 | #define EC_VER_FLASH_WRITE 1 |
| 1255 | |
| 1256 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1257 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1258 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1259 | struct __ec_align4 ec_params_flash_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1260 | uint32_t offset; /* Byte offset to write */ |
| 1261 | uint32_t size; /* Size to write in bytes */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1262 | /* Followed by data to write */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1263 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1264 | |
| 1265 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1266 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1267 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1268 | /* v0 */ |
| 1269 | struct __ec_align4 ec_params_flash_erase { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1270 | uint32_t offset; /* Byte offset to erase */ |
| 1271 | uint32_t size; /* Size to erase in bytes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1272 | }; |
| 1273 | |
| 1274 | |
| 1275 | #define EC_VER_FLASH_WRITE 1 |
| 1276 | /* v1 add async erase: |
| 1277 | * subcommands can returns: |
| 1278 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1279 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1280 | * EC_RES_ERROR : other errors. |
| 1281 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1282 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1283 | * |
| 1284 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1285 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1286 | * the proper result. |
| 1287 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1288 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1289 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1290 | * permitted while erasing. (For instance, STM32F4). |
| 1291 | */ |
| 1292 | enum ec_flash_erase_cmd { |
| 1293 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1294 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1295 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1296 | }; |
| 1297 | |
| 1298 | struct __ec_align4 ec_params_flash_erase_v1 { |
| 1299 | /* One of ec_flash_erase_cmd. */ |
| 1300 | uint8_t cmd; |
| 1301 | /* Pad byte; currently always contains 0 */ |
| 1302 | uint8_t reserved; |
| 1303 | /* No flags defined yet; set to 0 */ |
| 1304 | uint16_t flag; |
| 1305 | /* Same as v0 parameters. */ |
| 1306 | struct ec_params_flash_erase params; |
| 1307 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1308 | |
| 1309 | /* |
| 1310 | * Get/set flash protection. |
| 1311 | * |
| 1312 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1313 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1314 | * some flags require a subsequent hard reset to take effect. Check the |
| 1315 | * returned flags bits to see what actually happened. |
| 1316 | * |
| 1317 | * If mask=0, simply returns the current flags state. |
| 1318 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1319 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1320 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1321 | |
| 1322 | /* Flags for flash protection */ |
| 1323 | /* RO flash code protected when the EC boots */ |
| 1324 | #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0) |
| 1325 | /* |
| 1326 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1327 | * be changed. |
| 1328 | */ |
| 1329 | #define EC_FLASH_PROTECT_RO_NOW (1 << 1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1330 | /* Entire flash code protected now, until reboot. */ |
| 1331 | #define EC_FLASH_PROTECT_ALL_NOW (1 << 2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1332 | /* Flash write protect GPIO is asserted now */ |
| 1333 | #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3) |
| 1334 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
| 1335 | #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4) |
| 1336 | /* |
| 1337 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1338 | * flash which should be protected is not protected. Usually fixed by |
| 1339 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1340 | */ |
| 1341 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1342 | /* Entire flash code protected when the EC boots */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1343 | #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1344 | /* RW flash code protected when the EC boots */ |
| 1345 | #define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7) |
| 1346 | /* RW flash code protected now. */ |
| 1347 | #define EC_FLASH_PROTECT_RW_NOW (1 << 8) |
| 1348 | /* Rollback information flash region protected when the EC boots */ |
| 1349 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9) |
| 1350 | /* Rollback information flash region protected now */ |
| 1351 | #define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1352 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1353 | struct __ec_align4 ec_params_flash_protect { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1354 | uint32_t mask; /* Bits in flags to apply */ |
| 1355 | uint32_t flags; /* New flags to apply */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1356 | }; |
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_response_flash_protect { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1359 | /* Current value of flash protect flags */ |
| 1360 | uint32_t flags; |
| 1361 | /* |
| 1362 | * Flags which are valid on this platform. This allows the caller |
| 1363 | * to distinguish between flags which aren't set vs. flags which can't |
| 1364 | * be set on this platform. |
| 1365 | */ |
| 1366 | uint32_t valid_flags; |
| 1367 | /* Flags which can be changed given the current protection state */ |
| 1368 | uint32_t writable_flags; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1369 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1373 | * write protect. These commands may be reused with version > 0. |
| 1374 | */ |
| 1375 | |
| 1376 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1377 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1378 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1379 | |
| 1380 | enum ec_flash_region { |
| 1381 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1382 | EC_FLASH_REGION_RO = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1383 | /* Region which holds rewritable EC image */ |
| 1384 | EC_FLASH_REGION_RW, |
| 1385 | /* |
| 1386 | * Region which should be write-protected in the factory (a superset of |
| 1387 | * EC_FLASH_REGION_RO) |
| 1388 | */ |
| 1389 | EC_FLASH_REGION_WP_RO, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1390 | /* Number of regions */ |
| 1391 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1392 | }; |
| 1393 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1394 | struct __ec_align4 ec_params_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1395 | uint32_t region; /* enum ec_flash_region */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1396 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1397 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1398 | struct __ec_align4 ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1399 | uint32_t offset; |
| 1400 | uint32_t size; |
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 | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1403 | /* Read/write VbNvContext */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1404 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1405 | #define EC_VER_VBNV_CONTEXT 1 |
| 1406 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1407 | |
| 1408 | enum ec_vbnvcontext_op { |
| 1409 | EC_VBNV_CONTEXT_OP_READ, |
| 1410 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1411 | }; |
| 1412 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1413 | struct __ec_align4 ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1414 | uint32_t op; |
| 1415 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1416 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1417 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1418 | struct __ec_align4 ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1419 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1420 | }; |
| 1421 | |
| 1422 | |
| 1423 | /* Get SPI flash information */ |
| 1424 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1425 | |
| 1426 | struct __ec_align1 ec_response_flash_spi_info { |
| 1427 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1428 | uint8_t jedec[3]; |
| 1429 | |
| 1430 | /* Pad byte; currently always contains 0 */ |
| 1431 | uint8_t reserved0; |
| 1432 | |
| 1433 | /* Manufacturer / device ID from command 0x90 */ |
| 1434 | uint8_t mfr_dev_id[2]; |
| 1435 | |
| 1436 | /* Status registers from command 0x05 and 0x35 */ |
| 1437 | uint8_t sr1, sr2; |
| 1438 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1439 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 1440 | |
| 1441 | /* Select flash during flash operations */ |
| 1442 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1443 | |
| 1444 | struct __ec_align4 ec_params_flash_select { |
| 1445 | /* 1 to select flash, 0 to deselect flash */ |
| 1446 | uint8_t select; |
| 1447 | }; |
| 1448 | |
| 1449 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1450 | /*****************************************************************************/ |
| 1451 | /* PWM commands */ |
| 1452 | |
| 1453 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1454 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1455 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1456 | struct __ec_align4 ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1457 | uint32_t rpm; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1458 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1459 | |
| 1460 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1461 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1462 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1463 | /* Version 0 of input params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1464 | struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1465 | uint32_t rpm; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1466 | }; |
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 1 of input params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1469 | struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1470 | uint32_t rpm; |
| 1471 | uint8_t fan_idx; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1472 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1473 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1474 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1475 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1476 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1477 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1478 | struct __ec_align1 ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1479 | uint8_t percent; |
| 1480 | uint8_t enabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1481 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1482 | |
| 1483 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1484 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1485 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1486 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1487 | struct __ec_align1 ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1488 | uint8_t percent; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1489 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1490 | |
| 1491 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1492 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1493 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1494 | /* Version 0 of input params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1495 | struct __ec_align4 ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1496 | uint32_t percent; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1497 | }; |
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 1 of input params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1500 | struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1501 | uint32_t percent; |
| 1502 | uint8_t fan_idx; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1503 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1504 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1505 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1506 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1507 | #define EC_PWM_MAX_DUTY 0xffff |
| 1508 | |
| 1509 | enum ec_pwm_type { |
| 1510 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1511 | EC_PWM_TYPE_GENERIC = 0, |
| 1512 | /* Keyboard backlight */ |
| 1513 | EC_PWM_TYPE_KB_LIGHT, |
| 1514 | /* Display backlight */ |
| 1515 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1516 | EC_PWM_TYPE_COUNT, |
| 1517 | }; |
| 1518 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1519 | struct __ec_align4 ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1520 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1521 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1522 | uint8_t index; /* Type-specific index, or 0 if unique */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1523 | }; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1524 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1525 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1526 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1527 | struct __ec_align1 ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1528 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1529 | uint8_t index; /* Type-specific index, or 0 if unique */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1530 | }; |
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_align2 ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1533 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1534 | }; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1535 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1536 | /*****************************************************************************/ |
| 1537 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1538 | * 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] | 1539 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1540 | * into a subcommand. We'll make separate structs for subcommands with |
| 1541 | * different input args, so that we know how much to expect. |
| 1542 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1543 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1544 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1545 | struct __ec_todo_unpacked rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1546 | uint8_t r, g, b; |
| 1547 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1548 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1549 | #define LB_BATTERY_LEVELS 4 |
| 1550 | /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a |
| 1551 | * host command, but the alignment is the same regardless. Keep it that way. |
| 1552 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1553 | struct __ec_todo_packed lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1554 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1555 | int32_t google_ramp_up; |
| 1556 | int32_t google_ramp_down; |
| 1557 | int32_t s3s0_ramp_up; |
| 1558 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1559 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1560 | int32_t s0s3_ramp_down; |
| 1561 | int32_t s3_sleep_for; |
| 1562 | int32_t s3_ramp_up; |
| 1563 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1564 | |
| 1565 | /* Oscillation */ |
| 1566 | uint8_t new_s0; |
| 1567 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1568 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1569 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1570 | |
| 1571 | /* Brightness limits based on the backlight and AC. */ |
| 1572 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1573 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1574 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1575 | |
| 1576 | /* Battery level thresholds */ |
| 1577 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1578 | |
| 1579 | /* Map [AC][battery_level] to color index */ |
| 1580 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1581 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1582 | |
| 1583 | /* Color palette */ |
| 1584 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1585 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1586 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1587 | struct __ec_todo_packed lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1588 | /* Timing */ |
| 1589 | int32_t google_ramp_up; |
| 1590 | int32_t google_ramp_down; |
| 1591 | int32_t s3s0_ramp_up; |
| 1592 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1593 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1594 | int32_t s0s3_ramp_down; |
| 1595 | int32_t s3_sleep_for; |
| 1596 | int32_t s3_ramp_up; |
| 1597 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1598 | int32_t s5_ramp_up; |
| 1599 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1600 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1601 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1602 | int32_t tap_display_time; |
| 1603 | |
| 1604 | /* Tap-for-battery params */ |
| 1605 | uint8_t tap_pct_red; |
| 1606 | uint8_t tap_pct_green; |
| 1607 | uint8_t tap_seg_min_on; |
| 1608 | uint8_t tap_seg_max_on; |
| 1609 | uint8_t tap_seg_osc; |
| 1610 | uint8_t tap_idx[3]; |
| 1611 | |
| 1612 | /* Oscillation */ |
| 1613 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1614 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1615 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1616 | |
| 1617 | /* Brightness limits based on the backlight and AC. */ |
| 1618 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1619 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1620 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1621 | |
| 1622 | /* Battery level thresholds */ |
| 1623 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1624 | |
| 1625 | /* Map [AC][battery_level] to color index */ |
| 1626 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1627 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1628 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1629 | /* s5: single color pulse on inhibited power-up */ |
| 1630 | uint8_t s5_idx; |
| 1631 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1632 | /* Color palette */ |
| 1633 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1634 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1635 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1636 | /* Lightbar command params v2 |
| 1637 | * crbug.com/467716 |
| 1638 | * |
| 1639 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 1640 | * logical groups to make it more manageable ( < 120 bytes). |
| 1641 | * |
| 1642 | * NOTE: Each of these groups must be less than 120 bytes. |
| 1643 | */ |
| 1644 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1645 | struct __ec_todo_packed lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1646 | /* Timing */ |
| 1647 | int32_t google_ramp_up; |
| 1648 | int32_t google_ramp_down; |
| 1649 | int32_t s3s0_ramp_up; |
| 1650 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1651 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1652 | int32_t s0s3_ramp_down; |
| 1653 | int32_t s3_sleep_for; |
| 1654 | int32_t s3_ramp_up; |
| 1655 | int32_t s3_ramp_down; |
| 1656 | int32_t s5_ramp_up; |
| 1657 | int32_t s5_ramp_down; |
| 1658 | int32_t tap_tick_delay; |
| 1659 | int32_t tap_gate_delay; |
| 1660 | int32_t tap_display_time; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1661 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1662 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1663 | struct __ec_todo_packed lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1664 | /* Tap-for-battery params */ |
| 1665 | uint8_t tap_pct_red; |
| 1666 | uint8_t tap_pct_green; |
| 1667 | uint8_t tap_seg_min_on; |
| 1668 | uint8_t tap_seg_max_on; |
| 1669 | uint8_t tap_seg_osc; |
| 1670 | uint8_t tap_idx[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1671 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1672 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1673 | struct __ec_todo_packed lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1674 | /* Oscillation */ |
| 1675 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1676 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1677 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1678 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1679 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1680 | struct __ec_todo_packed lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1681 | /* Brightness limits based on the backlight and AC. */ |
| 1682 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1683 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1684 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1685 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1686 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1687 | struct __ec_todo_packed lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1688 | /* Battery level thresholds */ |
| 1689 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 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_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1693 | /* Map [AC][battery_level] to color index */ |
| 1694 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1695 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1696 | |
| 1697 | /* s5: single color pulse on inhibited power-up */ |
| 1698 | uint8_t s5_idx; |
| 1699 | |
| 1700 | /* Color palette */ |
| 1701 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1702 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1703 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1704 | /* Lightbyte program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1705 | #define EC_LB_PROG_LEN 192 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1706 | struct __ec_todo_unpacked lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1707 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1708 | uint8_t data[EC_LB_PROG_LEN]; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1709 | }; |
| 1710 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1711 | struct __ec_todo_packed ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1712 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 1713 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1714 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1715 | /* no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1716 | } dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1717 | version, get_brightness, get_demo, suspend, resume, |
| 1718 | get_params_v2_timing, get_params_v2_tap, |
| 1719 | get_params_v2_osc, get_params_v2_bright, |
| 1720 | get_params_v2_thlds, get_params_v2_colors; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1721 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1722 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1723 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1724 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1725 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1726 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1727 | uint8_t ctrl, reg, value; |
| 1728 | } reg; |
| 1729 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1730 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1731 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1732 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1733 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1734 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1735 | uint8_t led; |
| 1736 | } get_rgb; |
| 1737 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1738 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1739 | uint8_t enable; |
| 1740 | } manual_suspend_ctrl; |
| 1741 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1742 | struct lightbar_params_v0 set_params_v0; |
| 1743 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1744 | |
| 1745 | struct lightbar_params_v2_timing set_v2par_timing; |
| 1746 | struct lightbar_params_v2_tap set_v2par_tap; |
| 1747 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 1748 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 1749 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 1750 | struct lightbar_params_v2_colors set_v2par_colors; |
| 1751 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1752 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1753 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1754 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1755 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1756 | struct __ec_todo_packed ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1757 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1758 | struct __ec_todo_unpacked { |
| 1759 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1760 | uint8_t reg; |
| 1761 | uint8_t ic0; |
| 1762 | uint8_t ic1; |
| 1763 | } vals[23]; |
| 1764 | } dump; |
| 1765 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1766 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1767 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1768 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1769 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1770 | struct lightbar_params_v0 get_params_v0; |
| 1771 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1772 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1773 | |
| 1774 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 1775 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 1776 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 1777 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 1778 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 1779 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 1780 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1781 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1782 | uint32_t num; |
| 1783 | uint32_t flags; |
| 1784 | } version; |
| 1785 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1786 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1787 | uint8_t red, green, blue; |
| 1788 | } get_rgb; |
| 1789 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1790 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1791 | /* no return params */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1792 | } off, on, init, set_brightness, seq, reg, set_rgb, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1793 | demo, set_params_v0, set_params_v1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1794 | set_program, manual_suspend_ctrl, suspend, resume, |
| 1795 | set_v2par_timing, set_v2par_tap, |
| 1796 | set_v2par_osc, set_v2par_bright, set_v2par_thlds, |
| 1797 | set_v2par_colors; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1798 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1799 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1800 | |
| 1801 | /* Lightbar commands */ |
| 1802 | enum lightbar_command { |
| 1803 | LIGHTBAR_CMD_DUMP = 0, |
| 1804 | LIGHTBAR_CMD_OFF = 1, |
| 1805 | LIGHTBAR_CMD_ON = 2, |
| 1806 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1807 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1808 | LIGHTBAR_CMD_SEQ = 5, |
| 1809 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1810 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1811 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 1812 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1813 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 1814 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1815 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1816 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 1817 | LIGHTBAR_CMD_GET_RGB = 14, |
| 1818 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 1819 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 1820 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 1821 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1822 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 1823 | LIGHTBAR_CMD_SUSPEND = 20, |
| 1824 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1825 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 1826 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 1827 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 1828 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 1829 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 1830 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 1831 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 1832 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 1833 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 1834 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 1835 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 1836 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1837 | LIGHTBAR_NUM_CMDS |
| 1838 | }; |
| 1839 | |
| 1840 | /*****************************************************************************/ |
| 1841 | /* LED control commands */ |
| 1842 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1843 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1844 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1845 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1846 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1847 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1848 | /* |
| 1849 | * LED to indicate system power state (on or in suspend). |
| 1850 | * May be on power button or on C-panel. |
| 1851 | */ |
| 1852 | EC_LED_ID_POWER_LED, |
| 1853 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1854 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1855 | /* LED to indicate left side */ |
| 1856 | EC_LED_ID_LEFT_LED, |
| 1857 | /* LED to indicate right side */ |
| 1858 | EC_LED_ID_RIGHT_LED, |
| 1859 | /* LED to indicate recovery mode with HW_REINIT */ |
| 1860 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 1861 | /* LED to indicate sysrq debug mode. */ |
| 1862 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1863 | |
| 1864 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1865 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1866 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1867 | /* LED control flags */ |
| 1868 | #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */ |
| 1869 | #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */ |
| 1870 | |
| 1871 | enum ec_led_colors { |
| 1872 | EC_LED_COLOR_RED = 0, |
| 1873 | EC_LED_COLOR_GREEN, |
| 1874 | EC_LED_COLOR_BLUE, |
| 1875 | EC_LED_COLOR_YELLOW, |
| 1876 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1877 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1878 | |
| 1879 | EC_LED_COLOR_COUNT |
| 1880 | }; |
| 1881 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1882 | struct __ec_align1 ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1883 | uint8_t led_id; /* Which LED to control */ |
| 1884 | uint8_t flags; /* Control flags */ |
| 1885 | |
| 1886 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1887 | }; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1888 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1889 | struct __ec_align1 ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 1890 | /* |
| 1891 | * Available brightness value range. |
| 1892 | * |
| 1893 | * Range 0 means color channel not present. |
| 1894 | * Range 1 means on/off control. |
| 1895 | * Other values means the LED is control by PWM. |
| 1896 | */ |
| 1897 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1898 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1899 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1900 | /*****************************************************************************/ |
| 1901 | /* Verified boot commands */ |
| 1902 | |
| 1903 | /* |
| 1904 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 1905 | * reused for other purposes with version > 0. |
| 1906 | */ |
| 1907 | |
| 1908 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1909 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1910 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1911 | struct __ec_align4 ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1912 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 1913 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1914 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 1915 | uint8_t reserved0; /* Reserved; set 0 */ |
| 1916 | uint32_t offset; /* Offset in flash to hash */ |
| 1917 | uint32_t size; /* Number of bytes to hash */ |
| 1918 | uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1919 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1920 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1921 | struct __ec_align4 ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1922 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 1923 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1924 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 1925 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 1926 | uint32_t offset; /* Offset in flash which was hashed */ |
| 1927 | uint32_t size; /* Number of bytes hashed */ |
| 1928 | uint8_t hash_digest[64]; /* Hash digest data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1929 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1930 | |
| 1931 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1932 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 1933 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 1934 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 1935 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1936 | }; |
| 1937 | |
| 1938 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1939 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1940 | }; |
| 1941 | |
| 1942 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1943 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 1944 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 1945 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1946 | }; |
| 1947 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1948 | /* |
| 1949 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 1950 | * If one of these is specified, the EC will automatically update offset and |
| 1951 | * size to the correct values for the specified image (RO or RW). |
| 1952 | */ |
| 1953 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 1954 | #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd |
| 1955 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1956 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1957 | /* |
| 1958 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 1959 | * different input args, so that we know how much to expect. |
| 1960 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1961 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1962 | |
| 1963 | /* Motion sense commands */ |
| 1964 | enum motionsense_command { |
| 1965 | /* |
| 1966 | * Dump command returns all motion sensor data including motion sense |
| 1967 | * module flags and individual sensor flags. |
| 1968 | */ |
| 1969 | MOTIONSENSE_CMD_DUMP = 0, |
| 1970 | |
| 1971 | /* |
| 1972 | * Info command returns data describing the details of a given sensor, |
| 1973 | * including enum motionsensor_type, enum motionsensor_location, and |
| 1974 | * enum motionsensor_chip. |
| 1975 | */ |
| 1976 | MOTIONSENSE_CMD_INFO = 1, |
| 1977 | |
| 1978 | /* |
| 1979 | * 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] | 1980 | * in milliseconds. |
| 1981 | * It is per sensor, the EC run sample task at the minimum of all |
| 1982 | * sensors EC_RATE. |
| 1983 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 1984 | * to collect all the sensor samples. |
| 1985 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 1986 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1987 | */ |
| 1988 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 1989 | |
| 1990 | /* |
| 1991 | * Sensor ODR command is a setter/getter command for the output data |
| 1992 | * rate of a specific motion sensor in millihertz. |
| 1993 | */ |
| 1994 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 1995 | |
| 1996 | /* |
| 1997 | * Sensor range command is a setter/getter command for the range of |
| 1998 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 1999 | */ |
| 2000 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2001 | |
| 2002 | /* |
| 2003 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2004 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2005 | * and when the lid angle goes less than this value, keyboard wake is |
| 2006 | * enabled. Note, the lid angle measurement is an approximate, |
| 2007 | * un-calibrated value, hence the wake angle isn't exact. |
| 2008 | */ |
| 2009 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2010 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2011 | /* |
| 2012 | * Returns a single sensor data. |
| 2013 | */ |
| 2014 | MOTIONSENSE_CMD_DATA = 6, |
| 2015 | |
| 2016 | /* |
| 2017 | * Return sensor fifo info. |
| 2018 | */ |
| 2019 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2020 | |
| 2021 | /* |
| 2022 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2023 | * The host can use that element to synchronize its operation. |
| 2024 | */ |
| 2025 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2026 | |
| 2027 | /* |
| 2028 | * Return a portion of the fifo. |
| 2029 | */ |
| 2030 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2031 | |
| 2032 | /* |
| 2033 | * Perform low level calibration. |
| 2034 | * On sensors that support it, ask to do offset calibration. |
| 2035 | */ |
| 2036 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2037 | |
| 2038 | /* |
| 2039 | * Sensor Offset command is a setter/getter command for the offset |
| 2040 | * used for calibration. |
| 2041 | * The offsets can be calculated by the host, or via |
| 2042 | * PERFORM_CALIB command. |
| 2043 | */ |
| 2044 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2045 | |
| 2046 | /* |
| 2047 | * List available activities for a MOTION sensor. |
| 2048 | * Indicates if they are enabled or disabled. |
| 2049 | */ |
| 2050 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2051 | |
| 2052 | /* |
| 2053 | * Activity management |
| 2054 | * Enable/Disable activity recognition. |
| 2055 | */ |
| 2056 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2057 | |
| 2058 | /* |
| 2059 | * Lid Angle |
| 2060 | */ |
| 2061 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2062 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2063 | /* |
| 2064 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2065 | * By default the FIFO does not send interrupt to process the FIFO |
| 2066 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2067 | */ |
| 2068 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2069 | |
| 2070 | /* |
| 2071 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2072 | * to arbitrary values, or will lock to the last read actual values. |
| 2073 | */ |
| 2074 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2075 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2076 | /* Number of motionsense sub-commands. */ |
| 2077 | MOTIONSENSE_NUM_CMDS |
| 2078 | }; |
| 2079 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2080 | /* List of motion sensor types. */ |
| 2081 | enum motionsensor_type { |
| 2082 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2083 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2084 | MOTIONSENSE_TYPE_MAG = 2, |
| 2085 | MOTIONSENSE_TYPE_PROX = 3, |
| 2086 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2087 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2088 | MOTIONSENSE_TYPE_BARO = 6, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2089 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2090 | }; |
| 2091 | |
| 2092 | /* List of motion sensor locations. */ |
| 2093 | enum motionsensor_location { |
| 2094 | MOTIONSENSE_LOC_BASE = 0, |
| 2095 | MOTIONSENSE_LOC_LID = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2096 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2097 | }; |
| 2098 | |
| 2099 | /* List of motion sensor chips. */ |
| 2100 | enum motionsensor_chip { |
| 2101 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2102 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2103 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2104 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2105 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2106 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2107 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2108 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2109 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2110 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2111 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2112 | }; |
| 2113 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2114 | struct __ec_todo_packed ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2115 | /* Flags for each sensor. */ |
| 2116 | uint8_t flags; |
| 2117 | /* sensor number the data comes from */ |
| 2118 | uint8_t sensor_num; |
| 2119 | /* Each sensor is up to 3-axis. */ |
| 2120 | union { |
| 2121 | int16_t data[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2122 | struct __ec_todo_packed { |
| 2123 | uint16_t reserved; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2124 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2125 | }; |
| 2126 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2127 | uint8_t activity; /* motionsensor_activity */ |
| 2128 | uint8_t state; |
| 2129 | int16_t add_info[2]; |
| 2130 | }; |
| 2131 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2132 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2133 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2134 | /* Note: used in ec_response_get_next_data */ |
| 2135 | struct __ec_todo_packed ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2136 | /* Size of the fifo */ |
| 2137 | uint16_t size; |
| 2138 | /* Amount of space used in the fifo */ |
| 2139 | uint16_t count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2140 | /* Timestamp recorded in us */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2141 | uint32_t timestamp; |
| 2142 | /* Total amount of vector lost */ |
| 2143 | uint16_t total_lost; |
| 2144 | /* Lost events since the last fifo_info, per sensors */ |
| 2145 | uint16_t lost[0]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2146 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2147 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2148 | struct __ec_todo_packed ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2149 | uint32_t number_data; |
| 2150 | struct ec_response_motion_sensor_data data[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 | |
| 2153 | /* List supported activity recognition */ |
| 2154 | enum motionsensor_activity { |
| 2155 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2156 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2157 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
| 2158 | }; |
| 2159 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2160 | struct __ec_todo_unpacked ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2161 | uint8_t sensor_num; |
| 2162 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2163 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2164 | uint8_t reserved; |
| 2165 | uint16_t parameters[3]; /* activity dependent parameters */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2166 | }; |
| 2167 | |
| 2168 | /* Module flag masks used for the dump sub-command. */ |
| 2169 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0) |
| 2170 | |
| 2171 | /* Sensor flag masks used for the dump sub-command. */ |
| 2172 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0) |
| 2173 | |
| 2174 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2175 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2176 | * data contains time stamp |
| 2177 | */ |
| 2178 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0) |
| 2179 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1) |
| 2180 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2181 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2182 | |
| 2183 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2184 | * Send this value for the data element to only perform a read. If you |
| 2185 | * send any other value, the EC will interpret it as data to set and will |
| 2186 | * return the actual value set. |
| 2187 | */ |
| 2188 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2189 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2190 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2191 | |
| 2192 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2193 | /* Set Calibration information */ |
| 2194 | #define MOTION_SENSE_SET_OFFSET 1 |
| 2195 | |
| 2196 | #define LID_ANGLE_UNRELIABLE 500 |
| 2197 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2198 | enum motionsense_spoof_mode { |
| 2199 | /* Disable spoof mode. */ |
| 2200 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2201 | |
| 2202 | /* Enable spoof mode, but use provided component values. */ |
| 2203 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2204 | |
| 2205 | /* Enable spoof mode, but use the current sensor values. */ |
| 2206 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2207 | |
| 2208 | /* Query the current spoof mode status for the sensor. */ |
| 2209 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2210 | }; |
| 2211 | |
| 2212 | struct __ec_todo_packed ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2213 | uint8_t cmd; |
| 2214 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2215 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2216 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2217 | /* |
| 2218 | * Maximal number of sensor the host is expecting. |
| 2219 | * 0 means the host is only interested in the number |
| 2220 | * of sensors controlled by the EC. |
| 2221 | */ |
| 2222 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2223 | } dump; |
| 2224 | |
| 2225 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2226 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2227 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2228 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2229 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 2230 | * kb_wake_angle: angle to wakup AP. |
| 2231 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2232 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2233 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2234 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2235 | /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2236 | * and MOTIONSENSE_CMD_PERFORM_CALIB. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2237 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2238 | uint8_t sensor_num; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2239 | } info, info_3, data, fifo_flush, perform_calib, |
| 2240 | list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2243 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2244 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2245 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2246 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2247 | uint8_t sensor_num; |
| 2248 | |
| 2249 | /* Rounding flag, true for round-up, false for down. */ |
| 2250 | uint8_t roundup; |
| 2251 | |
| 2252 | uint16_t reserved; |
| 2253 | |
| 2254 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2255 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2256 | } ec_rate, sensor_odr, sensor_range; |
| 2257 | |
| 2258 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2259 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2260 | uint8_t sensor_num; |
| 2261 | |
| 2262 | /* |
| 2263 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2264 | * the calibration information in the EC. |
| 2265 | * If unset, just retrieve calibration information. |
| 2266 | */ |
| 2267 | uint16_t flags; |
| 2268 | |
| 2269 | /* |
| 2270 | * Temperature at calibration, in units of 0.01 C |
| 2271 | * 0x8000: invalid / unknown. |
| 2272 | * 0x0: 0C |
| 2273 | * 0x7fff: +327.67C |
| 2274 | */ |
| 2275 | int16_t temp; |
| 2276 | |
| 2277 | /* |
| 2278 | * Offset for calibration. |
| 2279 | * Unit: |
| 2280 | * Accelerometer: 1/1024 g |
| 2281 | * Gyro: 1/1024 deg/s |
| 2282 | * Compass: 1/16 uT |
| 2283 | */ |
| 2284 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2285 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2286 | |
| 2287 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2288 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2289 | } fifo_info; |
| 2290 | |
| 2291 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2292 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2293 | /* |
| 2294 | * Number of expected vector to return. |
| 2295 | * EC may return less or 0 if none available. |
| 2296 | */ |
| 2297 | uint32_t max_data_vector; |
| 2298 | } fifo_read; |
| 2299 | |
| 2300 | struct ec_motion_sense_activity set_activity; |
| 2301 | |
| 2302 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2303 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2304 | } lid_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2305 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2306 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2307 | struct __ec_todo_unpacked { |
| 2308 | /* |
| 2309 | * 1: enable, 0 disable fifo, |
| 2310 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2311 | */ |
| 2312 | int8_t enable; |
| 2313 | } fifo_int_enable; |
| 2314 | |
| 2315 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2316 | struct __ec_todo_packed { |
| 2317 | uint8_t sensor_id; |
| 2318 | |
| 2319 | /* See enum motionsense_spoof_mode. */ |
| 2320 | uint8_t spoof_enable; |
| 2321 | |
| 2322 | /* Ignored, used for alignment. */ |
| 2323 | uint8_t reserved; |
| 2324 | |
| 2325 | /* Individual component values to spoof. */ |
| 2326 | int16_t components[3]; |
| 2327 | } spoof; |
| 2328 | }; |
| 2329 | }; |
| 2330 | |
| 2331 | struct __ec_todo_packed ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2332 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2333 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2334 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2335 | /* Flags representing the motion sensor module. */ |
| 2336 | uint8_t module_flags; |
| 2337 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2338 | /* Number of sensors managed directly by the EC */ |
| 2339 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2340 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2341 | /* |
| 2342 | * sensor data is truncated if response_max is too small |
| 2343 | * for holding all the data. |
| 2344 | */ |
| 2345 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2346 | } dump; |
| 2347 | |
| 2348 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2349 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2350 | /* Should be element of enum motionsensor_type. */ |
| 2351 | uint8_t type; |
| 2352 | |
| 2353 | /* Should be element of enum motionsensor_location. */ |
| 2354 | uint8_t location; |
| 2355 | |
| 2356 | /* Should be element of enum motionsensor_chip. */ |
| 2357 | uint8_t chip; |
| 2358 | } info; |
| 2359 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2360 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 2361 | struct __ec_todo_unpacked { |
| 2362 | /* Should be element of enum motionsensor_type. */ |
| 2363 | uint8_t type; |
| 2364 | |
| 2365 | /* Should be element of enum motionsensor_location. */ |
| 2366 | uint8_t location; |
| 2367 | |
| 2368 | /* Should be element of enum motionsensor_chip. */ |
| 2369 | uint8_t chip; |
| 2370 | |
| 2371 | /* Minimum sensor sampling frequency */ |
| 2372 | uint32_t min_frequency; |
| 2373 | |
| 2374 | /* Maximum sensor sampling frequency */ |
| 2375 | uint32_t max_frequency; |
| 2376 | |
| 2377 | /* Max number of sensor events that could be in fifo */ |
| 2378 | uint32_t fifo_max_event_count; |
| 2379 | } info_3; |
| 2380 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2381 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 2382 | struct ec_response_motion_sensor_data data; |
| 2383 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2384 | /* |
| 2385 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2386 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 2387 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 2388 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 2389 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2390 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2391 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2392 | /* Current value of the parameter queried. */ |
| 2393 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2394 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 2395 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2396 | |
| 2397 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2398 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2399 | int16_t temp; |
| 2400 | int16_t offset[3]; |
| 2401 | } sensor_offset, perform_calib; |
| 2402 | |
| 2403 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 2404 | |
| 2405 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 2406 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2407 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2408 | uint16_t reserved; |
| 2409 | uint32_t enabled; |
| 2410 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2411 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2412 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2413 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2414 | } set_activity; |
| 2415 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2416 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2417 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2418 | /* |
| 2419 | * Angle between 0 and 360 degree if available, |
| 2420 | * LID_ANGLE_UNRELIABLE otherwise. |
| 2421 | */ |
| 2422 | uint16_t value; |
| 2423 | } lid_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2424 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2425 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2426 | |
| 2427 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2428 | /* Force lid open command */ |
| 2429 | |
| 2430 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2431 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2432 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2433 | struct __ec_align1 ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2434 | uint8_t enabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2435 | }; |
| 2436 | |
| 2437 | /*****************************************************************************/ |
| 2438 | /* Configure the behavior of the power button */ |
| 2439 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 2440 | |
| 2441 | enum ec_config_power_button_flags { |
| 2442 | /* Enable/Disable power button pulses for x86 devices */ |
| 2443 | EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0), |
| 2444 | }; |
| 2445 | |
| 2446 | struct __ec_align1 ec_params_config_power_button { |
| 2447 | /* See enum ec_config_power_button_flags */ |
| 2448 | uint8_t flags; |
| 2449 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2450 | |
| 2451 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2452 | /* USB charging control commands */ |
| 2453 | |
| 2454 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2455 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2456 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2457 | struct __ec_align1 ec_params_usb_charge_set_mode { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2458 | uint8_t usb_port_id; |
| 2459 | uint8_t mode; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2460 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2461 | |
| 2462 | /*****************************************************************************/ |
| 2463 | /* Persistent storage for host */ |
| 2464 | |
| 2465 | /* Maximum bytes that can be read/written in a single command */ |
| 2466 | #define EC_PSTORE_SIZE_MAX 64 |
| 2467 | |
| 2468 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2469 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2470 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2471 | struct __ec_align4 ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2472 | /* Persistent storage size, in bytes */ |
| 2473 | uint32_t pstore_size; |
| 2474 | /* Access size; read/write offset and size must be a multiple of this */ |
| 2475 | uint32_t access_size; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2476 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2477 | |
| 2478 | /* |
| 2479 | * Read persistent storage |
| 2480 | * |
| 2481 | * Response is params.size bytes of data. |
| 2482 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2483 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2484 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2485 | struct __ec_align4 ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2486 | uint32_t offset; /* Byte offset to read */ |
| 2487 | uint32_t size; /* Size to read in bytes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2488 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2489 | |
| 2490 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2491 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2492 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2493 | struct __ec_align4 ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2494 | uint32_t offset; /* Byte offset to write */ |
| 2495 | uint32_t size; /* Size to write in bytes */ |
| 2496 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2497 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2498 | |
| 2499 | /*****************************************************************************/ |
| 2500 | /* Real-time clock */ |
| 2501 | |
| 2502 | /* RTC params and response structures */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2503 | struct __ec_align4 ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2504 | uint32_t time; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2505 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2506 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2507 | struct __ec_align4 ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2508 | uint32_t time; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2509 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2510 | |
| 2511 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2512 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 2513 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2514 | |
| 2515 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2516 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 2517 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 2518 | |
| 2519 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 2520 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2521 | |
| 2522 | /*****************************************************************************/ |
| 2523 | /* Port80 log access */ |
| 2524 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2525 | /* Maximum entries that can be read/written in a single command */ |
| 2526 | #define EC_PORT80_SIZE_MAX 32 |
| 2527 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2528 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2529 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 2530 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2531 | |
| 2532 | enum ec_port80_subcmd { |
| 2533 | EC_PORT80_GET_INFO = 0, |
| 2534 | EC_PORT80_READ_BUFFER, |
| 2535 | }; |
| 2536 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2537 | struct __ec_todo_packed ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2538 | uint16_t subcmd; |
| 2539 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2540 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2541 | uint32_t offset; |
| 2542 | uint32_t num_entries; |
| 2543 | } read_buffer; |
| 2544 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2545 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2546 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2547 | struct __ec_todo_packed ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2548 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2549 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2550 | uint32_t writes; |
| 2551 | uint32_t history_size; |
| 2552 | uint32_t last_boot; |
| 2553 | } get_info; |
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 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 2556 | } data; |
| 2557 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2558 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2559 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2560 | struct __ec_align2 ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2561 | uint16_t code; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2562 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2563 | |
| 2564 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2565 | /* Temporary secure storage for host verified boot use */ |
| 2566 | |
| 2567 | /* Number of bytes in a vstore slot */ |
| 2568 | #define EC_VSTORE_SLOT_SIZE 64 |
| 2569 | |
| 2570 | /* Maximum number of vstore slots */ |
| 2571 | #define EC_VSTORE_SLOT_MAX 32 |
| 2572 | |
| 2573 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2574 | #define EC_CMD_VSTORE_INFO 0x0049 |
| 2575 | struct __ec_align_size1 ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2576 | /* Indicates which slots are locked */ |
| 2577 | uint32_t slot_locked; |
| 2578 | /* Total number of slots available */ |
| 2579 | uint8_t slot_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2580 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2581 | |
| 2582 | /* |
| 2583 | * Read temporary secure storage |
| 2584 | * |
| 2585 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 2586 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2587 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2588 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2589 | struct __ec_align1 ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2590 | uint8_t slot; /* Slot to read from */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2591 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2592 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2593 | struct __ec_align1 ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2594 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2595 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2596 | |
| 2597 | /* |
| 2598 | * Write temporary secure storage and lock it. |
| 2599 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2600 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2601 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2602 | struct __ec_align1 ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2603 | uint8_t slot; /* Slot to write to */ |
| 2604 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2605 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2606 | |
| 2607 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2608 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 2609 | * reuse the command number, but the data and behavior is incompatible. |
| 2610 | * Version 0 is what originally shipped on Link. |
| 2611 | * Version 1 separates the CPU thermal limits from the fan control. |
| 2612 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2613 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2614 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 2615 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2616 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2617 | /* The version 0 structs are opaque. You have to know what they are for |
| 2618 | * the get/set commands to make any sense. |
| 2619 | */ |
| 2620 | |
| 2621 | /* Version 0 - set */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2622 | struct __ec_align2 ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2623 | uint8_t sensor_type; |
| 2624 | uint8_t threshold_id; |
| 2625 | uint16_t value; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2626 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2627 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2628 | /* Version 0 - get */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2629 | struct __ec_align1 ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2630 | uint8_t sensor_type; |
| 2631 | uint8_t threshold_id; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2632 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2633 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2634 | struct __ec_align2 ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2635 | uint16_t value; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2636 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2637 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2638 | |
| 2639 | /* The version 1 structs are visible. */ |
| 2640 | enum ec_temp_thresholds { |
| 2641 | EC_TEMP_THRESH_WARN = 0, |
| 2642 | EC_TEMP_THRESH_HIGH, |
| 2643 | EC_TEMP_THRESH_HALT, |
| 2644 | |
| 2645 | EC_TEMP_THRESH_COUNT |
| 2646 | }; |
| 2647 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2648 | /* |
| 2649 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2650 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2651 | * |
| 2652 | * Note that this structure is a sub-structure of |
| 2653 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2654 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2655 | struct __ec_align4 ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2656 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
| 2657 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 2658 | uint32_t temp_fan_max; /* max active cooling needed */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2659 | }; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2660 | |
| 2661 | /* Version 1 - get config for one sensor. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2662 | struct __ec_align4 ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2663 | uint32_t sensor_num; |
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 | /* This returns a struct ec_thermal_config */ |
| 2666 | |
| 2667 | /* Version 1 - set config for one sensor. |
| 2668 | * Use read-modify-write for best results! */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2669 | struct __ec_align4 ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2670 | uint32_t sensor_num; |
| 2671 | struct ec_thermal_config cfg; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2672 | }; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2673 | /* This returns no data */ |
| 2674 | |
| 2675 | /****************************************************************************/ |
| 2676 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2677 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2678 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2679 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2680 | /* Version 1 of input params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2681 | struct __ec_align1 ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2682 | uint8_t fan_idx; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2683 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2684 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2685 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2686 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 2687 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2688 | |
| 2689 | /* |
| 2690 | * The original TMP006 calibration only needed four params, but now we need |
| 2691 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 2692 | * the params opaque. The v1 "get" response will include the algorithm number |
| 2693 | * and how many params it requires. That way we can change the EC code without |
| 2694 | * needing to update this file. We can also use a different algorithm on each |
| 2695 | * sensor. |
| 2696 | */ |
| 2697 | |
| 2698 | /* This is the same struct for both v0 and v1. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2699 | struct __ec_align1 ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2700 | uint8_t index; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2701 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2702 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2703 | /* Version 0 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2704 | struct __ec_align4 ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2705 | float s0; |
| 2706 | float b0; |
| 2707 | float b1; |
| 2708 | float b2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2709 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2710 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2711 | struct __ec_align4 ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2712 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2713 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2714 | float s0; |
| 2715 | float b0; |
| 2716 | float b1; |
| 2717 | float b2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2718 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2719 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2720 | /* Version 1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2721 | struct __ec_align4 ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2722 | uint8_t algorithm; |
| 2723 | uint8_t num_params; |
| 2724 | uint8_t reserved[2]; |
| 2725 | float val[0]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2726 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2727 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2728 | struct __ec_align4 ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2729 | uint8_t index; |
| 2730 | uint8_t algorithm; |
| 2731 | uint8_t num_params; |
| 2732 | uint8_t reserved; |
| 2733 | float val[0]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2734 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2735 | |
| 2736 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2737 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2738 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2739 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2740 | struct __ec_align1 ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2741 | uint8_t index; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2742 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2743 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2744 | struct __ec_align4 ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2745 | int32_t t; /* In 1/100 K */ |
| 2746 | int32_t v; /* In nV */ |
| 2747 | }; |
| 2748 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2749 | /*****************************************************************************/ |
| 2750 | /* MKBP - Matrix KeyBoard Protocol */ |
| 2751 | |
| 2752 | /* |
| 2753 | * Read key state |
| 2754 | * |
| 2755 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 2756 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2757 | * |
| 2758 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 2759 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 2760 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2761 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2762 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2763 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2764 | /* |
| 2765 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 2766 | */ |
| 2767 | #define EC_CMD_MKBP_INFO 0x0061 |
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 | struct __ec_align_size1 ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2770 | uint32_t rows; |
| 2771 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2772 | /* Formerly "switches", which was 0. */ |
| 2773 | uint8_t reserved; |
| 2774 | }; |
| 2775 | |
| 2776 | struct __ec_align1 ec_params_mkbp_info { |
| 2777 | uint8_t info_type; |
| 2778 | uint8_t event_type; |
| 2779 | }; |
| 2780 | |
| 2781 | enum ec_mkbp_info_type { |
| 2782 | /* |
| 2783 | * Info about the keyboard matrix: number of rows and columns. |
| 2784 | * |
| 2785 | * Returns struct ec_response_mkbp_info. |
| 2786 | */ |
| 2787 | EC_MKBP_INFO_KBD = 0, |
| 2788 | |
| 2789 | /* |
| 2790 | * For buttons and switches, info about which specifically are |
| 2791 | * supported. event_type must be set to one of the values in enum |
| 2792 | * ec_mkbp_event. |
| 2793 | * |
| 2794 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 2795 | * bitmask indicating which buttons or switches are present. See the |
| 2796 | * bit inidices below. |
| 2797 | */ |
| 2798 | EC_MKBP_INFO_SUPPORTED = 1, |
| 2799 | |
| 2800 | /* |
| 2801 | * Instantaneous state of buttons and switches. |
| 2802 | * |
| 2803 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 2804 | * |
| 2805 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 2806 | * indicating the current state of the keyboard matrix. |
| 2807 | * |
| 2808 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 2809 | * event state. |
| 2810 | * |
| 2811 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 2812 | * state of supported buttons. |
| 2813 | * |
| 2814 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 2815 | * state of supported switches. |
| 2816 | */ |
| 2817 | EC_MKBP_INFO_CURRENT = 2, |
| 2818 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2819 | |
| 2820 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2821 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2822 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2823 | struct __ec_align1 ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2824 | uint8_t col; |
| 2825 | uint8_t row; |
| 2826 | uint8_t pressed; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2827 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2828 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2829 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2830 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 2831 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2832 | |
| 2833 | /* flags */ |
| 2834 | enum mkbp_config_flags { |
| 2835 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 2836 | }; |
| 2837 | |
| 2838 | enum mkbp_config_valid { |
| 2839 | EC_MKBP_VALID_SCAN_PERIOD = 1 << 0, |
| 2840 | EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1, |
| 2841 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3, |
| 2842 | EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4, |
| 2843 | EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5, |
| 2844 | EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6, |
| 2845 | EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7, |
| 2846 | }; |
| 2847 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2848 | /* |
| 2849 | * Configuration for our key scanning algorithm. |
| 2850 | * |
| 2851 | * Note that this is used as a sub-structure of |
| 2852 | * ec_{params/response}_mkbp_get_config. |
| 2853 | */ |
| 2854 | struct __ec_align_size1 ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2855 | uint32_t valid_mask; /* valid fields */ |
| 2856 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 2857 | uint8_t valid_flags; /* which flags are valid */ |
| 2858 | uint16_t scan_period_us; /* period between start of scans */ |
| 2859 | /* revert to interrupt mode after no activity for this long */ |
| 2860 | uint32_t poll_timeout_us; |
| 2861 | /* |
| 2862 | * minimum post-scan relax time. Once we finish a scan we check |
| 2863 | * the time until we are due to start the next one. If this time is |
| 2864 | * shorter this field, we use this instead. |
| 2865 | */ |
| 2866 | uint16_t min_post_scan_delay_us; |
| 2867 | /* delay between setting up output and waiting for it to settle */ |
| 2868 | uint16_t output_settle_us; |
| 2869 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 2870 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 2871 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 2872 | uint8_t fifo_max_depth; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2873 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2874 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2875 | struct __ec_align_size1 ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2876 | struct ec_mkbp_config config; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2877 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2878 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2879 | struct __ec_align_size1 ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2880 | struct ec_mkbp_config config; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2881 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2882 | |
| 2883 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2884 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2885 | |
| 2886 | enum ec_keyscan_seq_cmd { |
| 2887 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 2888 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 2889 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 2890 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 2891 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 2892 | }; |
| 2893 | |
| 2894 | enum ec_collect_flags { |
| 2895 | /* |
| 2896 | * Indicates this scan was processed by the EC. Due to timing, some |
| 2897 | * scans may be skipped. |
| 2898 | */ |
| 2899 | EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0, |
| 2900 | }; |
| 2901 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2902 | struct __ec_align1 ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2903 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
| 2904 | }; |
| 2905 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2906 | struct __ec_todo_packed ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2907 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 2908 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2909 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2910 | uint8_t active; /* still active */ |
| 2911 | uint8_t num_items; /* number of items */ |
| 2912 | /* Current item being presented */ |
| 2913 | uint8_t cur_item; |
| 2914 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2915 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2916 | /* |
| 2917 | * Absolute time for this scan, measured from the |
| 2918 | * start of the sequence. |
| 2919 | */ |
| 2920 | uint32_t time_us; |
| 2921 | uint8_t scan[0]; /* keyscan data */ |
| 2922 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2923 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2924 | uint8_t start_item; /* First item to return */ |
| 2925 | uint8_t num_items; /* Number of items to return */ |
| 2926 | } collect; |
| 2927 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2928 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2929 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2930 | struct __ec_todo_packed ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2931 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2932 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2933 | uint8_t num_items; /* Number of items */ |
| 2934 | /* Data for each item */ |
| 2935 | struct ec_collect_item item[0]; |
| 2936 | } collect; |
| 2937 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2938 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2939 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2940 | /* |
| 2941 | * Get the next pending MKBP event. |
| 2942 | * |
| 2943 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 2944 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2945 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2946 | |
| 2947 | enum ec_mkbp_event { |
| 2948 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 2949 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 2950 | |
| 2951 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 2952 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 2953 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2954 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 2955 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 2956 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2957 | /* The state of the non-matrixed buttons have changed. */ |
| 2958 | EC_MKBP_EVENT_BUTTON = 3, |
| 2959 | |
| 2960 | /* The state of the switches have changed. */ |
| 2961 | EC_MKBP_EVENT_SWITCH = 4, |
| 2962 | |
| 2963 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 2964 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 2965 | |
| 2966 | /* |
| 2967 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 2968 | * corresponding to the key to be pressed. |
| 2969 | */ |
| 2970 | EC_MKBP_EVENT_SYSRQ = 6, |
| 2971 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2972 | /* Number of MKBP events */ |
| 2973 | EC_MKBP_EVENT_COUNT, |
| 2974 | }; |
| 2975 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2976 | union __ec_align_offset1 ec_response_get_next_data { |
| 2977 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2978 | |
| 2979 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2980 | uint32_t host_event; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2981 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2982 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2983 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2984 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2985 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2986 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2987 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2988 | uint32_t buttons; |
| 2989 | |
| 2990 | uint32_t switches; |
| 2991 | |
| 2992 | uint32_t fp_events; |
| 2993 | |
| 2994 | uint32_t sysrq; |
| 2995 | }; |
| 2996 | |
| 2997 | struct __ec_align1 ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2998 | uint8_t event_type; |
| 2999 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3000 | union ec_response_get_next_data data; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3001 | }; |
| 3002 | |
| 3003 | /* Bit indices for buttons and switches.*/ |
| 3004 | /* Buttons */ |
| 3005 | #define EC_MKBP_POWER_BUTTON 0 |
| 3006 | #define EC_MKBP_VOL_UP 1 |
| 3007 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 3008 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3009 | |
| 3010 | /* Switches */ |
| 3011 | #define EC_MKBP_LID_OPEN 0 |
| 3012 | #define EC_MKBP_TABLET_MODE 1 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3013 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3014 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3015 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3016 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3017 | struct __ec_align2 ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3018 | uint16_t shorted; /* Keyboard pins are shorted */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3019 | }; |
| 3020 | |
| 3021 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3022 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
| 3023 | #define EC_MKBP_FP_FINGER_DOWN (1 << 29) |
| 3024 | #define EC_MKBP_FP_FINGER_UP (1 << 30) |
| 3025 | #define EC_MKBP_FP_IMAGE_READY (1 << 31) |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3026 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3027 | /*****************************************************************************/ |
| 3028 | /* Temperature sensor commands */ |
| 3029 | |
| 3030 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3031 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3032 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3033 | struct __ec_align1 ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3034 | uint8_t id; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3035 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3036 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3037 | struct __ec_align1 ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3038 | char sensor_name[32]; |
| 3039 | uint8_t sensor_type; |
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 | |
| 3042 | /*****************************************************************************/ |
| 3043 | |
| 3044 | /* |
| 3045 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 3046 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 3047 | * below. |
| 3048 | */ |
| 3049 | |
| 3050 | /*****************************************************************************/ |
| 3051 | /* Host event commands */ |
| 3052 | |
| 3053 | /* |
| 3054 | * Host event mask params and response structures, shared by all of the host |
| 3055 | * event commands below. |
| 3056 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3057 | struct __ec_align4 ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3058 | uint32_t mask; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3059 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3060 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3061 | struct __ec_align4 ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3062 | uint32_t mask; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3063 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3064 | |
| 3065 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3066 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 3067 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 3068 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 3069 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3070 | |
| 3071 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3072 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 3073 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 3074 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 3075 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 3076 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3077 | |
| 3078 | /*****************************************************************************/ |
| 3079 | /* Switch commands */ |
| 3080 | |
| 3081 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3082 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3083 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3084 | struct __ec_align1 ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3085 | uint8_t enabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3086 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3087 | |
| 3088 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3089 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3090 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3091 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3092 | /* Version 0 params; no response */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3093 | struct __ec_align1 ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3094 | uint8_t enabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3095 | }; |
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 1 params */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3098 | struct __ec_align1 ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3099 | /* Flags to enable now */ |
| 3100 | uint8_t now_flags; |
| 3101 | |
| 3102 | /* Which flags to copy from now_flags */ |
| 3103 | uint8_t now_mask; |
| 3104 | |
| 3105 | /* |
| 3106 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 3107 | * transition. (Other flags will be disabled by the S0->S3 |
| 3108 | * transition.) |
| 3109 | */ |
| 3110 | uint8_t suspend_flags; |
| 3111 | |
| 3112 | /* Which flags to copy from suspend_flags */ |
| 3113 | uint8_t suspend_mask; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3114 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3115 | |
| 3116 | /* Version 1 response */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3117 | struct __ec_align1 ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3118 | /* Flags to enable now */ |
| 3119 | uint8_t now_flags; |
| 3120 | |
| 3121 | /* Flags to leave enabled in S3 */ |
| 3122 | uint8_t suspend_flags; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3123 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3124 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3125 | /*****************************************************************************/ |
| 3126 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 3127 | |
| 3128 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3129 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3130 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3131 | struct __ec_align1 ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3132 | char name[32]; |
| 3133 | uint8_t val; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3134 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3135 | |
| 3136 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3137 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3138 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3139 | /* Version 0 of input params and response */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3140 | struct __ec_align1 ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3141 | char name[32]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3142 | }; |
| 3143 | |
| 3144 | struct __ec_align1 ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3145 | uint8_t val; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3146 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3147 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3148 | /* Version 1 of input params and response */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3149 | struct __ec_align1 ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3150 | uint8_t subcmd; |
| 3151 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3152 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3153 | char name[32]; |
| 3154 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3155 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3156 | uint8_t index; |
| 3157 | } get_info; |
| 3158 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3159 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3160 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3161 | struct __ec_todo_packed ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3162 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3163 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3164 | uint8_t val; |
| 3165 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3166 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3167 | uint8_t val; |
| 3168 | char name[32]; |
| 3169 | uint32_t flags; |
| 3170 | } get_info; |
| 3171 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3172 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3173 | |
| 3174 | enum gpio_get_subcmd { |
| 3175 | EC_GPIO_GET_BY_NAME = 0, |
| 3176 | EC_GPIO_GET_COUNT = 1, |
| 3177 | EC_GPIO_GET_INFO = 2, |
| 3178 | }; |
| 3179 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3180 | /*****************************************************************************/ |
| 3181 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 3182 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3183 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3184 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 3185 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 3186 | * |
| 3187 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3188 | */ |
| 3189 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3190 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3191 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3192 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3193 | struct __ec_align_size1 ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3194 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3195 | uint8_t read_size; /* Either 8 or 16. */ |
| 3196 | uint8_t port; |
| 3197 | uint8_t offset; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3198 | }; |
| 3199 | |
| 3200 | struct __ec_align2 ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3201 | uint16_t data; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3202 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3203 | |
| 3204 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3205 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3206 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3207 | struct __ec_align_size1 ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3208 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3209 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3210 | uint8_t write_size; /* Either 8 or 16. */ |
| 3211 | uint8_t port; |
| 3212 | uint8_t offset; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3213 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3214 | |
| 3215 | /*****************************************************************************/ |
| 3216 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 3217 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3218 | /* Force charge state machine to stop charging the battery or force it to |
| 3219 | * discharge the battery. |
| 3220 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3221 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3222 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3223 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3224 | enum ec_charge_control_mode { |
| 3225 | CHARGE_CONTROL_NORMAL = 0, |
| 3226 | CHARGE_CONTROL_IDLE, |
| 3227 | CHARGE_CONTROL_DISCHARGE, |
| 3228 | }; |
| 3229 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3230 | struct __ec_align4 ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3231 | uint32_t mode; /* enum charge_control_mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3232 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3233 | |
| 3234 | /*****************************************************************************/ |
| 3235 | /* Console commands. Only available when flash write protect is unlocked. */ |
| 3236 | |
| 3237 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3238 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3239 | |
| 3240 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3241 | * Read data from the saved snapshot. If the subcmd parameter is |
| 3242 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 3243 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 3244 | * end of the previous snapshot. |
| 3245 | * |
| 3246 | * The params are only looked at in version >= 1 of this command. Prior |
| 3247 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3248 | * |
| 3249 | * Response is null-terminated string. Empty string, if there is no more |
| 3250 | * remaining output. |
| 3251 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3252 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3253 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3254 | enum ec_console_read_subcmd { |
| 3255 | CONSOLE_READ_NEXT = 0, |
| 3256 | CONSOLE_READ_RECENT |
| 3257 | }; |
| 3258 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3259 | struct __ec_align1 ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3260 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3261 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3262 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3263 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3264 | |
| 3265 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3266 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3267 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3268 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 3269 | * EC_RES_SUCCESS if the command was successful. |
| 3270 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3271 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3272 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3273 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3274 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0) |
| 3275 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3276 | struct __ec_align1 ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3277 | uint8_t flags; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3278 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3279 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3280 | /*****************************************************************************/ |
| 3281 | /* USB port mux control. */ |
| 3282 | |
| 3283 | /* |
| 3284 | * Switch USB mux or return to automatic switching. |
| 3285 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3286 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3287 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3288 | struct __ec_align1 ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3289 | uint8_t mux; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3290 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3291 | |
| 3292 | /*****************************************************************************/ |
| 3293 | /* LDOs / FETs control. */ |
| 3294 | |
| 3295 | enum ec_ldo_state { |
| 3296 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 3297 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 3298 | }; |
| 3299 | |
| 3300 | /* |
| 3301 | * Switch on/off a LDO. |
| 3302 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3303 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3304 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3305 | struct __ec_align1 ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3306 | uint8_t index; |
| 3307 | uint8_t state; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3308 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3309 | |
| 3310 | /* |
| 3311 | * Get LDO state. |
| 3312 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3313 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3314 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3315 | struct __ec_align1 ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3316 | uint8_t index; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3317 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3318 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3319 | struct __ec_align1 ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3320 | uint8_t state; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3321 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3322 | |
| 3323 | /*****************************************************************************/ |
| 3324 | /* Power info. */ |
| 3325 | |
| 3326 | /* |
| 3327 | * Get power info. |
| 3328 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3329 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3330 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3331 | struct __ec_align4 ec_response_power_info { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3332 | uint32_t usb_dev_type; |
| 3333 | uint16_t voltage_ac; |
| 3334 | uint16_t voltage_system; |
| 3335 | uint16_t current_system; |
| 3336 | uint16_t usb_current_limit; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3337 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3338 | |
| 3339 | /*****************************************************************************/ |
| 3340 | /* I2C passthru command */ |
| 3341 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3342 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3343 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3344 | /* Read data; if not present, message is a write */ |
| 3345 | #define EC_I2C_FLAG_READ (1 << 15) |
| 3346 | |
| 3347 | /* Mask for address */ |
| 3348 | #define EC_I2C_ADDR_MASK 0x3ff |
| 3349 | |
| 3350 | #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */ |
| 3351 | #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */ |
| 3352 | |
| 3353 | /* Any error */ |
| 3354 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 3355 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3356 | struct __ec_align2 ec_params_i2c_passthru_msg { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3357 | uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */ |
| 3358 | uint16_t len; /* Number of bytes to read or write */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3359 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3360 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3361 | struct __ec_align2 ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3362 | uint8_t port; /* I2C port number */ |
| 3363 | uint8_t num_msgs; /* Number of messages */ |
| 3364 | struct ec_params_i2c_passthru_msg msg[]; |
| 3365 | /* Data to write for all messages is concatenated here */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3366 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3367 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3368 | struct __ec_align1 ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3369 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 3370 | uint8_t num_msgs; /* Number of messages processed */ |
| 3371 | uint8_t data[]; /* Data read by messages concatenated here */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3372 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3373 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 3374 | /*****************************************************************************/ |
| 3375 | /* Power button hang detect */ |
| 3376 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3377 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 3378 | |
| 3379 | /* Reasons to start hang detection timer */ |
| 3380 | /* Power button pressed */ |
| 3381 | #define EC_HANG_START_ON_POWER_PRESS (1 << 0) |
| 3382 | |
| 3383 | /* Lid closed */ |
| 3384 | #define EC_HANG_START_ON_LID_CLOSE (1 << 1) |
| 3385 | |
| 3386 | /* Lid opened */ |
| 3387 | #define EC_HANG_START_ON_LID_OPEN (1 << 2) |
| 3388 | |
| 3389 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
| 3390 | #define EC_HANG_START_ON_RESUME (1 << 3) |
| 3391 | |
| 3392 | /* Reasons to cancel hang detection */ |
| 3393 | |
| 3394 | /* Power button released */ |
| 3395 | #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8) |
| 3396 | |
| 3397 | /* Any host command from AP received */ |
| 3398 | #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9) |
| 3399 | |
| 3400 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
| 3401 | #define EC_HANG_STOP_ON_SUSPEND (1 << 10) |
| 3402 | |
| 3403 | /* |
| 3404 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 3405 | * timer is started. This provides the AP a way to start the hang timer |
| 3406 | * without reconfiguring any of the other hang detect settings. Note that |
| 3407 | * you must previously have configured the timeouts. |
| 3408 | */ |
| 3409 | #define EC_HANG_START_NOW (1 << 30) |
| 3410 | |
| 3411 | /* |
| 3412 | * If this flag is set, all the other fields are ignored (including |
| 3413 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 3414 | * without reconfiguring any of the other hang detect settings. |
| 3415 | */ |
| 3416 | #define EC_HANG_STOP_NOW (1 << 31) |
| 3417 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3418 | struct __ec_align4 ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 3419 | /* Flags; see EC_HANG_* */ |
| 3420 | uint32_t flags; |
| 3421 | |
| 3422 | /* Timeout in msec before generating host event, if enabled */ |
| 3423 | uint16_t host_event_timeout_msec; |
| 3424 | |
| 3425 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 3426 | uint16_t warm_reboot_timeout_msec; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3427 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3428 | |
| 3429 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3430 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3431 | |
| 3432 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3433 | * This is the single catch-all host command to exchange data regarding the |
| 3434 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3435 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3436 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3437 | |
| 3438 | /* Subcommands for this host command */ |
| 3439 | enum charge_state_command { |
| 3440 | CHARGE_STATE_CMD_GET_STATE, |
| 3441 | CHARGE_STATE_CMD_GET_PARAM, |
| 3442 | CHARGE_STATE_CMD_SET_PARAM, |
| 3443 | CHARGE_STATE_NUM_CMDS |
| 3444 | }; |
| 3445 | |
| 3446 | /* |
| 3447 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 3448 | * params, which are handled by the particular implementations. |
| 3449 | */ |
| 3450 | enum charge_state_params { |
| 3451 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 3452 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 3453 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 3454 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 3455 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3456 | CS_PARAM_LIMIT_POWER, /* |
| 3457 | * Check if power is limited due to |
| 3458 | * low battery and / or a weak external |
| 3459 | * charger. READ ONLY. |
| 3460 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3461 | /* How many so far? */ |
| 3462 | CS_NUM_BASE_PARAMS, |
| 3463 | |
| 3464 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 3465 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 3466 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 3467 | |
| 3468 | /* Other custom param ranges go here... */ |
| 3469 | }; |
| 3470 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3471 | struct __ec_todo_packed ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3472 | uint8_t cmd; /* enum charge_state_command */ |
| 3473 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3474 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3475 | /* no args */ |
| 3476 | } get_state; |
| 3477 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3478 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3479 | uint32_t param; /* enum charge_state_param */ |
| 3480 | } get_param; |
| 3481 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3482 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3483 | uint32_t param; /* param to set */ |
| 3484 | uint32_t value; /* value to set */ |
| 3485 | } set_param; |
| 3486 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3487 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3488 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3489 | struct __ec_align4 ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3490 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3491 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3492 | int ac; |
| 3493 | int chg_voltage; |
| 3494 | int chg_current; |
| 3495 | int chg_input_current; |
| 3496 | int batt_state_of_charge; |
| 3497 | } get_state; |
| 3498 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3499 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3500 | uint32_t value; |
| 3501 | } get_param; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3502 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3503 | /* no return values */ |
| 3504 | } set_param; |
| 3505 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3506 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3507 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3508 | |
| 3509 | /* |
| 3510 | * Set maximum battery charging current. |
| 3511 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3512 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3513 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3514 | struct __ec_align4 ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3515 | uint32_t limit; /* in mA */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3516 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3517 | |
| 3518 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3519 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3520 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3521 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3522 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3523 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3524 | struct __ec_align2 ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3525 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 3526 | 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] | 3527 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3528 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3529 | #define EC_POWER_LIMIT_NONE 0xffff |
| 3530 | |
| 3531 | /*****************************************************************************/ |
| 3532 | /* Hibernate/Deep Sleep Commands */ |
| 3533 | |
| 3534 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3535 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3536 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3537 | struct __ec_align4 ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3538 | /* |
| 3539 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 3540 | * current settings without changing them. |
| 3541 | */ |
| 3542 | uint32_t seconds; |
| 3543 | }; |
| 3544 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3545 | struct __ec_align4 ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3546 | /* |
| 3547 | * The current time in seconds in which the system has been in the G3 |
| 3548 | * state. This value is reset if the EC transitions out of G3. |
| 3549 | */ |
| 3550 | uint32_t time_g3; |
| 3551 | |
| 3552 | /* |
| 3553 | * The current time remaining in seconds until the EC should hibernate. |
| 3554 | * This value is also reset if the EC transitions out of G3. |
| 3555 | */ |
| 3556 | uint32_t time_remaining; |
| 3557 | |
| 3558 | /* |
| 3559 | * The current time in seconds that the EC should wait in G3 before |
| 3560 | * hibernating. |
| 3561 | */ |
| 3562 | uint32_t hibernate_delay; |
| 3563 | }; |
| 3564 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3565 | /* Inform the EC when entering a sleep state */ |
| 3566 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 3567 | |
| 3568 | enum host_sleep_event { |
| 3569 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 3570 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 3571 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
| 3572 | HOST_SLEEP_EVENT_S0IX_RESUME = 4 |
| 3573 | }; |
| 3574 | |
| 3575 | struct __ec_align1 ec_params_host_sleep_event { |
| 3576 | uint8_t sleep_event; |
| 3577 | }; |
| 3578 | |
| 3579 | /*****************************************************************************/ |
| 3580 | /* Device events */ |
| 3581 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 3582 | |
| 3583 | enum ec_device_event { |
| 3584 | EC_DEVICE_EVENT_TRACKPAD, |
| 3585 | EC_DEVICE_EVENT_DSP, |
| 3586 | EC_DEVICE_EVENT_WIFI, |
| 3587 | }; |
| 3588 | |
| 3589 | enum ec_device_event_param { |
| 3590 | /* Get and clear pending device events */ |
| 3591 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 3592 | /* Get device event mask */ |
| 3593 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 3594 | /* Set device event mask */ |
| 3595 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 3596 | }; |
| 3597 | |
| 3598 | #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32)) |
| 3599 | |
| 3600 | struct __ec_align_size1 ec_params_device_event { |
| 3601 | uint32_t event_mask; |
| 3602 | uint8_t param; |
| 3603 | }; |
| 3604 | |
| 3605 | struct __ec_align4 ec_response_device_event { |
| 3606 | uint32_t event_mask; |
| 3607 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3608 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3609 | /*****************************************************************************/ |
| 3610 | /* Smart battery pass-through */ |
| 3611 | |
| 3612 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3613 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 3614 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3615 | |
| 3616 | /* Get / Set string smart battery parameters |
| 3617 | * formatted as SMBUS "block". |
| 3618 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3619 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 3620 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3621 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3622 | struct __ec_align1 ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3623 | uint8_t reg; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3624 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3625 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3626 | struct __ec_align2 ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3627 | uint16_t value; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3628 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3629 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3630 | struct __ec_align1 ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3631 | uint8_t reg; |
| 3632 | uint16_t value; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3633 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3634 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3635 | struct __ec_align1 ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3636 | uint8_t data[32]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3637 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3638 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3639 | struct __ec_align1 ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3640 | uint8_t reg; |
| 3641 | uint16_t data[32]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3642 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3643 | |
| 3644 | /*****************************************************************************/ |
| 3645 | /* Battery vendor parameters |
| 3646 | * |
| 3647 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 3648 | * differ between boards or batteries. On a set operation, the response |
| 3649 | * contains the actual value set, which may be rounded or clipped from the |
| 3650 | * requested value. |
| 3651 | */ |
| 3652 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3653 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3654 | |
| 3655 | enum ec_battery_vendor_param_mode { |
| 3656 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 3657 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 3658 | }; |
| 3659 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3660 | struct __ec_align_size1 ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3661 | uint32_t param; |
| 3662 | uint32_t value; |
| 3663 | uint8_t mode; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3664 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3665 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3666 | struct __ec_align4 ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3667 | uint32_t value; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3668 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3669 | |
| 3670 | /*****************************************************************************/ |
| 3671 | /* |
| 3672 | * Smart Battery Firmware Update Commands |
| 3673 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3674 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3675 | |
| 3676 | enum ec_sb_fw_update_subcmd { |
| 3677 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 3678 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 3679 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 3680 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 3681 | EC_SB_FW_UPDATE_END = 0x4, |
| 3682 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 3683 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 3684 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 3685 | }; |
| 3686 | |
| 3687 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 3688 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 3689 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 3690 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3691 | struct __ec_align4 ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3692 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 3693 | uint16_t fw_id; /* firmware id */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3694 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3695 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3696 | struct __ec_align4 ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3697 | struct ec_sb_fw_update_header hdr; |
| 3698 | union { |
| 3699 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 3700 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 3701 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 3702 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 3703 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 3704 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3705 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3706 | /* no args */ |
| 3707 | } dummy; |
| 3708 | |
| 3709 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3710 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3711 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 3712 | } write; |
| 3713 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3714 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3715 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3716 | struct __ec_align1 ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3717 | union { |
| 3718 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3719 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3720 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 3721 | } info; |
| 3722 | |
| 3723 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3724 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3725 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 3726 | } status; |
| 3727 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3728 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3729 | |
| 3730 | /* |
| 3731 | * Entering Verified Boot Mode Command |
| 3732 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 3733 | * Valid Modes are: normal, developer, and recovery. |
| 3734 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3735 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3736 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3737 | struct __ec_align4 ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3738 | int vboot_mode; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3739 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3740 | |
| 3741 | #define VBOOT_MODE_NORMAL 0 |
| 3742 | #define VBOOT_MODE_DEVELOPER 1 |
| 3743 | #define VBOOT_MODE_RECOVERY 2 |
| 3744 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3745 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3746 | /* |
| 3747 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 3748 | * certain addresses (board-specific). |
| 3749 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3750 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3751 | |
| 3752 | enum ec_i2c_passthru_protect_subcmd { |
| 3753 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0, |
| 3754 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1, |
| 3755 | }; |
| 3756 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3757 | struct __ec_align1 ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3758 | uint8_t subcmd; |
| 3759 | uint8_t port; /* I2C port number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3760 | }; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3761 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3762 | struct __ec_align1 ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3763 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3764 | }; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3765 | |
| 3766 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3767 | /* System commands */ |
| 3768 | |
| 3769 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3770 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 3771 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3772 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3773 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3774 | |
| 3775 | /* Command */ |
| 3776 | enum ec_reboot_cmd { |
| 3777 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3778 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 3779 | EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3780 | /* (command 3 was jump to RW-B) */ |
| 3781 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3782 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 3783 | EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3784 | }; |
| 3785 | |
| 3786 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
| 3787 | #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3788 | #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] | 3789 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3790 | struct __ec_align1 ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3791 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 3792 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3793 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3794 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3795 | /* |
| 3796 | * Get information on last EC panic. |
| 3797 | * |
| 3798 | * Returns variable-length platform-dependent panic information. See panic.h |
| 3799 | * for details. |
| 3800 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3801 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3802 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3803 | /*****************************************************************************/ |
| 3804 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3805 | * Special commands |
| 3806 | * |
| 3807 | * These do not follow the normal rules for commands. See each command for |
| 3808 | * details. |
| 3809 | */ |
| 3810 | |
| 3811 | /* |
| 3812 | * Reboot NOW |
| 3813 | * |
| 3814 | * This command will work even when the EC LPC interface is busy, because the |
| 3815 | * reboot command is processed at interrupt level. Note that when the EC |
| 3816 | * reboots, the host will reboot too, so there is no response to this command. |
| 3817 | * |
| 3818 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 3819 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3820 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3821 | |
| 3822 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3823 | * Resend last response (not supported on LPC). |
| 3824 | * |
| 3825 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 3826 | * there was no previous command, or the previous command's response was too |
| 3827 | * big to save. |
| 3828 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3829 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3830 | |
| 3831 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3832 | * This header byte on a command indicate version 0. Any header byte less |
| 3833 | * than this means that we are talking to an old EC which doesn't support |
| 3834 | * versioning. In that case, we assume version 0. |
| 3835 | * |
| 3836 | * Header bytes greater than this indicate a later version. For example, |
| 3837 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 3838 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3839 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3840 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3841 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3842 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3843 | /*****************************************************************************/ |
| 3844 | /* |
| 3845 | * PD commands |
| 3846 | * |
| 3847 | * These commands are for PD MCU communication. |
| 3848 | */ |
| 3849 | |
| 3850 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3851 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3852 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3853 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3854 | enum pd_charge_state { |
| 3855 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 3856 | PD_CHARGE_NONE, /* No charging allowed */ |
| 3857 | PD_CHARGE_5V, /* 5V charging only */ |
| 3858 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 3859 | }; |
| 3860 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3861 | /* Status of EC being sent to PD */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3862 | #define EC_STATUS_HIBERNATING (1 << 0) |
| 3863 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3864 | struct __ec_align1 ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3865 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3866 | int8_t batt_soc; /* battery state of charge */ |
| 3867 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3868 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3869 | |
| 3870 | /* Status of PD being sent back to EC */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3871 | #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */ |
| 3872 | #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */ |
| 3873 | #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] | 3874 | #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */ |
| 3875 | #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */ |
| 3876 | #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */ |
| 3877 | #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */ |
| 3878 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 3879 | PD_STATUS_TCPC_ALERT_1 | \ |
| 3880 | PD_STATUS_HOST_EVENT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3881 | struct __ec_align_size1 ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3882 | uint32_t curr_lim_ma; /* input current limit */ |
| 3883 | uint16_t status; /* PD MCU status */ |
| 3884 | int8_t active_charge_port; /* active charging port */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3885 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3886 | |
| 3887 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3888 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3889 | |
| 3890 | /* PD MCU host event status bits */ |
| 3891 | #define PD_EVENT_UPDATE_DEVICE (1 << 0) |
| 3892 | #define PD_EVENT_POWER_CHANGE (1 << 1) |
| 3893 | #define PD_EVENT_IDENTITY_RECEIVED (1 << 2) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3894 | #define PD_EVENT_DATA_SWAP (1 << 3) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3895 | struct __ec_align4 ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3896 | uint32_t status; /* PD MCU host event status */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3897 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3898 | |
| 3899 | /* Set USB type-C port role and muxes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3900 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3901 | |
| 3902 | enum usb_pd_control_role { |
| 3903 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 3904 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 3905 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 3906 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 3907 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
| 3908 | USB_PD_CTRL_ROLE_COUNT |
| 3909 | }; |
| 3910 | |
| 3911 | enum usb_pd_control_mux { |
| 3912 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 3913 | USB_PD_CTRL_MUX_NONE = 1, |
| 3914 | USB_PD_CTRL_MUX_USB = 2, |
| 3915 | USB_PD_CTRL_MUX_DP = 3, |
| 3916 | USB_PD_CTRL_MUX_DOCK = 4, |
| 3917 | USB_PD_CTRL_MUX_AUTO = 5, |
| 3918 | USB_PD_CTRL_MUX_COUNT |
| 3919 | }; |
| 3920 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3921 | enum usb_pd_control_swap { |
| 3922 | USB_PD_CTRL_SWAP_NONE = 0, |
| 3923 | USB_PD_CTRL_SWAP_DATA = 1, |
| 3924 | USB_PD_CTRL_SWAP_POWER = 2, |
| 3925 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 3926 | USB_PD_CTRL_SWAP_COUNT |
| 3927 | }; |
| 3928 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3929 | struct __ec_align1 ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3930 | uint8_t port; |
| 3931 | uint8_t role; |
| 3932 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3933 | uint8_t swap; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3934 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3935 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3936 | #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ |
| 3937 | #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ |
| 3938 | #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ |
| 3939 | |
| 3940 | #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */ |
| 3941 | #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */ |
| 3942 | #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */ |
| 3943 | #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */ |
| 3944 | #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */ |
| 3945 | #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */ |
| 3946 | #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */ |
| 3947 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3948 | struct __ec_align1 ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3949 | uint8_t enabled; |
| 3950 | uint8_t role; |
| 3951 | uint8_t polarity; |
| 3952 | uint8_t state; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3953 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3954 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3955 | struct __ec_align1 ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3956 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3957 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3958 | uint8_t polarity; |
| 3959 | char state[32]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3960 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3961 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3962 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3963 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 3964 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 3965 | #define EC_USB_PD_MAX_PORTS 8 |
| 3966 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3967 | struct __ec_align1 ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3968 | uint8_t num_ports; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3969 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3970 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3971 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3972 | |
| 3973 | #define PD_POWER_CHARGING_PORT 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3974 | struct __ec_align1 ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3975 | uint8_t port; |
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 | |
| 3978 | enum usb_chg_type { |
| 3979 | USB_CHG_TYPE_NONE, |
| 3980 | USB_CHG_TYPE_PD, |
| 3981 | USB_CHG_TYPE_C, |
| 3982 | USB_CHG_TYPE_PROPRIETARY, |
| 3983 | USB_CHG_TYPE_BC12_DCP, |
| 3984 | USB_CHG_TYPE_BC12_CDP, |
| 3985 | USB_CHG_TYPE_BC12_SDP, |
| 3986 | USB_CHG_TYPE_OTHER, |
| 3987 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3988 | USB_CHG_TYPE_UNKNOWN, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3989 | }; |
| 3990 | enum usb_power_roles { |
| 3991 | USB_PD_PORT_POWER_DISCONNECTED, |
| 3992 | USB_PD_PORT_POWER_SOURCE, |
| 3993 | USB_PD_PORT_POWER_SINK, |
| 3994 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 3995 | }; |
| 3996 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3997 | struct __ec_align2 usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3998 | uint16_t voltage_max; |
| 3999 | uint16_t voltage_now; |
| 4000 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4001 | uint16_t current_lim; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4002 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4003 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4004 | struct __ec_align4 ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4005 | uint8_t role; |
| 4006 | uint8_t type; |
| 4007 | uint8_t dualrole; |
| 4008 | uint8_t reserved1; |
| 4009 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4010 | uint32_t max_power; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4011 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4012 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4013 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4014 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4015 | |
| 4016 | enum usb_pd_fw_update_cmds { |
| 4017 | USB_PD_FW_REBOOT, |
| 4018 | USB_PD_FW_FLASH_ERASE, |
| 4019 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4020 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4021 | }; |
| 4022 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4023 | struct __ec_align4 ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4024 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4025 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4026 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4027 | uint32_t size; /* Size to write in bytes */ |
| 4028 | /* Followed by data to write */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4029 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4030 | |
| 4031 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4032 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4033 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 4034 | #define PD_RW_HASH_SIZE 20 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4035 | struct __ec_align1 ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4036 | uint16_t dev_id; |
| 4037 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4038 | uint8_t reserved; /* For alignment of current_image |
| 4039 | * TODO(rspangler) but it's not aligned! |
| 4040 | * Should have been reserved[2]. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4041 | uint32_t current_image; /* One of ec_current_image */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4042 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4043 | |
| 4044 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4045 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4046 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4047 | struct __ec_align1 ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4048 | uint8_t port; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4049 | }; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4050 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4051 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4052 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
| 4053 | struct __ec_align_size1 ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4054 | uint16_t vid; /* USB-IF VID */ |
| 4055 | uint16_t pid; /* USB-IF PID */ |
| 4056 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4057 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4058 | |
| 4059 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4060 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4061 | |
| 4062 | /* Negative port parameters have special meaning */ |
| 4063 | enum usb_pd_override_ports { |
| 4064 | OVERRIDE_DONT_CHARGE = -2, |
| 4065 | OVERRIDE_OFF = -1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4066 | /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4067 | }; |
| 4068 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4069 | struct __ec_align2 ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4070 | int16_t override_port; /* Override port# */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4071 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4072 | |
| 4073 | /* Read (and delete) one entry of PD event log */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4074 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4075 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4076 | struct __ec_align4 ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4077 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 4078 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 4079 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 4080 | uint16_t data; /* type-defined data payload */ |
| 4081 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4082 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4083 | |
| 4084 | |
| 4085 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 4086 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 4087 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4088 | #define PD_LOG_SIZE_MASK 0x1f |
| 4089 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4090 | #define PD_LOG_PORT_SHIFT 5 |
| 4091 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 4092 | ((size) & PD_LOG_SIZE_MASK)) |
| 4093 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 4094 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 4095 | |
| 4096 | /* PD event log : entry types */ |
| 4097 | /* PD MCU events */ |
| 4098 | #define PD_EVENT_MCU_BASE 0x00 |
| 4099 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 4100 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 4101 | /* Reserved for custom board event */ |
| 4102 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 4103 | /* PD generic accessory events */ |
| 4104 | #define PD_EVENT_ACC_BASE 0x20 |
| 4105 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 4106 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 4107 | /* PD power supply events */ |
| 4108 | #define PD_EVENT_PS_BASE 0x40 |
| 4109 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 4110 | /* PD video dongles events */ |
| 4111 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 4112 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 4113 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 4114 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4115 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4116 | |
| 4117 | /* |
| 4118 | * PD_EVENT_MCU_CHARGE event definition : |
| 4119 | * the payload is "struct usb_chg_measures" |
| 4120 | * the data field contains the port state flags as defined below : |
| 4121 | */ |
| 4122 | /* Port partner is a dual role device */ |
| 4123 | #define CHARGE_FLAGS_DUAL_ROLE (1 << 15) |
| 4124 | /* Port is the pending override port */ |
| 4125 | #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14) |
| 4126 | /* Port is the override port */ |
| 4127 | #define CHARGE_FLAGS_OVERRIDE (1 << 13) |
| 4128 | /* Charger type */ |
| 4129 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4130 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4131 | /* Power delivery role */ |
| 4132 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 4133 | |
| 4134 | /* |
| 4135 | * PD_EVENT_PS_FAULT data field flags definition : |
| 4136 | */ |
| 4137 | #define PS_FAULT_OCP 1 |
| 4138 | #define PS_FAULT_FAST_OCP 2 |
| 4139 | #define PS_FAULT_OVP 3 |
| 4140 | #define PS_FAULT_DISCH 4 |
| 4141 | |
| 4142 | /* |
| 4143 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 4144 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4145 | struct __ec_align4 mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4146 | uint8_t major; |
| 4147 | uint8_t minor; |
| 4148 | uint16_t build; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4149 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4150 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4151 | struct __ec_align4 mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4152 | uint8_t family[2]; |
| 4153 | uint8_t chipid[2]; |
| 4154 | struct mcdp_version irom; |
| 4155 | struct mcdp_version fw; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4156 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4157 | |
| 4158 | /* struct mcdp_info field decoding */ |
| 4159 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 4160 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 4161 | |
| 4162 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4163 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
| 4164 | struct __ec_align_size1 ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4165 | uint16_t svid_idx; /* SVID index to get */ |
| 4166 | uint8_t port; /* port */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4167 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4168 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4169 | struct __ec_align4 ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4170 | uint16_t svid; /* SVID */ |
| 4171 | uint16_t opos; /* Object Position */ |
| 4172 | uint32_t vdo[6]; /* Mode VDOs */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4173 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4174 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4175 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4176 | |
| 4177 | enum pd_mode_cmd { |
| 4178 | PD_EXIT_MODE = 0, |
| 4179 | PD_ENTER_MODE = 1, |
| 4180 | /* Not a command. Do NOT remove. */ |
| 4181 | PD_MODE_CMD_COUNT, |
| 4182 | }; |
| 4183 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4184 | struct __ec_align4 ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4185 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 4186 | uint16_t svid; /* SVID to set */ |
| 4187 | uint8_t opos; /* Object Position */ |
| 4188 | uint8_t port; /* port */ |
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 | |
| 4191 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4192 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4193 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4194 | struct __ec_align1 ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4195 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 4196 | 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] | 4197 | }; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4198 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4199 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4200 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4201 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4202 | |
| 4203 | enum ec_pd_control_cmd { |
| 4204 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 4205 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 4206 | PD_RESET, /* Force reset the PD chip */ |
| 4207 | PD_CONTROL_DISABLE /* Disable further calls to this command */ |
| 4208 | }; |
| 4209 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4210 | struct __ec_align1 ec_params_pd_control { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4211 | uint8_t chip; /* chip id (should be 0) */ |
| 4212 | uint8_t subcmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4213 | }; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4214 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4215 | /* Get info about USB-C SS muxes */ |
| 4216 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 4217 | |
| 4218 | struct __ec_align1 ec_params_usb_pd_mux_info { |
| 4219 | uint8_t port; /* USB-C port number */ |
| 4220 | }; |
| 4221 | |
| 4222 | /* Flags representing mux state */ |
| 4223 | #define USB_PD_MUX_USB_ENABLED (1 << 0) |
| 4224 | #define USB_PD_MUX_DP_ENABLED (1 << 1) |
| 4225 | #define USB_PD_MUX_POLARITY_INVERTED (1 << 2) |
| 4226 | #define USB_PD_MUX_HPD_IRQ (1 << 3) |
| 4227 | |
| 4228 | struct __ec_align1 ec_response_usb_pd_mux_info { |
| 4229 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
| 4230 | }; |
| 4231 | |
| 4232 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 4233 | |
| 4234 | struct __ec_align1 ec_params_pd_chip_info { |
| 4235 | uint8_t port; /* USB-C port number */ |
| 4236 | uint8_t renew; /* Force renewal */ |
| 4237 | }; |
| 4238 | |
| 4239 | struct __ec_align2 ec_response_pd_chip_info { |
| 4240 | uint16_t vendor_id; |
| 4241 | uint16_t product_id; |
| 4242 | uint16_t device_id; |
| 4243 | union { |
| 4244 | uint8_t fw_version_string[8]; |
| 4245 | uint64_t fw_version_number; |
| 4246 | }; |
| 4247 | }; |
| 4248 | |
| 4249 | /* Run RW signature verification and get status */ |
| 4250 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 4251 | |
| 4252 | struct __ec_align4 ec_response_rwsig_check_status { |
| 4253 | uint32_t status; |
| 4254 | }; |
| 4255 | |
| 4256 | /* For controlling RWSIG task */ |
| 4257 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 4258 | |
| 4259 | enum rwsig_action { |
| 4260 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 4261 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 4262 | }; |
| 4263 | |
| 4264 | struct __ec_align4 ec_params_rwsig_action { |
| 4265 | uint32_t action; |
| 4266 | }; |
| 4267 | |
| 4268 | /*****************************************************************************/ |
| 4269 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4270 | |
| 4271 | /*****************************************************************************/ |
| 4272 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4273 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4274 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4275 | #define EC_CMD_CR51_BASE 0x0300 |
| 4276 | #define EC_CMD_CR51_LAST 0x03FF |
| 4277 | |
| 4278 | /*****************************************************************************/ |
| 4279 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 4280 | |
| 4281 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 4282 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 4283 | |
| 4284 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 4285 | |
| 4286 | struct __ec_align2 ec_params_fp_passthru { |
| 4287 | uint16_t len; /* Number of bytes to write then read */ |
| 4288 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 4289 | uint8_t data[]; /* Data to send */ |
| 4290 | }; |
| 4291 | |
| 4292 | /* Fingerprint sensor configuration command: prototyping ONLY */ |
| 4293 | #define EC_CMD_FP_SENSOR_CONFIG 0x0401 |
| 4294 | |
| 4295 | #define EC_FP_SENSOR_CONFIG_MAX_REGS 16 |
| 4296 | |
| 4297 | struct __ec_align2 ec_params_fp_sensor_config { |
| 4298 | uint8_t count; /* Number of setup registers */ |
| 4299 | /* |
| 4300 | * the value to send to each of the 'count' setup registers |
| 4301 | * is stored in the 'data' array for 'len' bytes just after |
| 4302 | * the previous one. |
| 4303 | */ |
| 4304 | uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS]; |
| 4305 | uint8_t data[]; |
| 4306 | }; |
| 4307 | |
| 4308 | /* Configure the Fingerprint MCU behavior */ |
| 4309 | #define EC_CMD_FP_MODE 0x0402 |
| 4310 | |
| 4311 | /* Put the sensor in its lowest power mode */ |
| 4312 | #define FP_MODE_DEEPSLEEP (1<<0) |
| 4313 | /* Wait to see a finger on the sensor */ |
| 4314 | #define FP_MODE_FINGER_DOWN (1<<1) |
| 4315 | /* Poll until the finger has left the sensor */ |
| 4316 | #define FP_MODE_FINGER_UP (1<<2) |
| 4317 | /* Capture the current finger image */ |
| 4318 | #define FP_MODE_CAPTURE (1<<3) |
| 4319 | /* special value: don't change anything just read back current mode */ |
| 4320 | #define FP_MODE_DONT_CHANGE (1<<31) |
| 4321 | |
| 4322 | struct __ec_align4 ec_params_fp_mode { |
| 4323 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
| 4324 | /* TBD */ |
| 4325 | }; |
| 4326 | |
| 4327 | struct __ec_align4 ec_response_fp_mode { |
| 4328 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
| 4329 | /* TBD */ |
| 4330 | }; |
| 4331 | |
| 4332 | /* Retrieve Fingerprint sensor information */ |
| 4333 | #define EC_CMD_FP_INFO 0x0403 |
| 4334 | |
| 4335 | struct __ec_align2 ec_response_fp_info { |
| 4336 | /* Sensor identification */ |
| 4337 | uint32_t vendor_id; |
| 4338 | uint32_t product_id; |
| 4339 | uint32_t model_id; |
| 4340 | uint32_t version; |
| 4341 | /* Image frame characteristics */ |
| 4342 | uint32_t frame_size; |
| 4343 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 4344 | uint16_t width; |
| 4345 | uint16_t height; |
| 4346 | uint16_t bpp; |
| 4347 | }; |
| 4348 | |
| 4349 | /* Get the last captured finger frame: TODO: will be AES-encrypted */ |
| 4350 | #define EC_CMD_FP_FRAME 0x0404 |
| 4351 | |
| 4352 | struct __ec_align4 ec_params_fp_frame { |
| 4353 | uint32_t offset; |
| 4354 | uint32_t size; |
| 4355 | }; |
| 4356 | |
| 4357 | /*****************************************************************************/ |
| 4358 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 4359 | |
| 4360 | /* Perform touchpad self test */ |
| 4361 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 4362 | |
| 4363 | /* Get number of frame types, and the size of each type */ |
| 4364 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 4365 | |
| 4366 | struct __ec_align4 ec_response_tp_frame_info { |
| 4367 | uint32_t n_frames; |
| 4368 | uint32_t frame_sizes[0]; |
| 4369 | }; |
| 4370 | |
| 4371 | /* Create a snapshot of current frame readings */ |
| 4372 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 4373 | |
| 4374 | /* Read the frame */ |
| 4375 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 4376 | |
| 4377 | struct __ec_align4 ec_params_tp_frame_get { |
| 4378 | uint32_t frame_index; |
| 4379 | uint32_t offset; |
| 4380 | uint32_t size; |
| 4381 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4382 | |
| 4383 | /*****************************************************************************/ |
| 4384 | /* |
| 4385 | * Reserve a range of host commands for board-specific, experimental, or |
| 4386 | * special purpose features. These can be (re)used without updating this file. |
| 4387 | * |
| 4388 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 4389 | * their EC commands for easier development, testing, debugging, and support. |
| 4390 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4391 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 4392 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 4393 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4394 | * In your experimental code, you may want to do something like this: |
| 4395 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4396 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 4397 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 4398 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 4399 | * |
| 4400 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 4401 | * EC_VER_MASK(0); |
| 4402 | * |
| 4403 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 4404 | * EC_VER_MASK(0); |
| 4405 | * |
| 4406 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 4407 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4408 | */ |
| 4409 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 4410 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 4411 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4412 | /* |
| 4413 | * Given the private host command offset, calculate the true private host |
| 4414 | * command value. |
| 4415 | */ |
| 4416 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 4417 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 4418 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4419 | /*****************************************************************************/ |
| 4420 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4421 | * Passthru commands |
| 4422 | * |
| 4423 | * Some platforms have sub-processors chained to each other. For example. |
| 4424 | * |
| 4425 | * AP <--> EC <--> PD MCU |
| 4426 | * |
| 4427 | * The top 2 bits of the command number are used to indicate which device the |
| 4428 | * command is intended for. Device 0 is always the device receiving the |
| 4429 | * command; other device mapping is board-specific. |
| 4430 | * |
| 4431 | * When a device receives a command to be passed to a sub-processor, it passes |
| 4432 | * it on with the device number set back to 0. This allows the sub-processor |
| 4433 | * to remain blissfully unaware of whether the command originated on the next |
| 4434 | * device up the chain, or was passed through from the AP. |
| 4435 | * |
| 4436 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 4437 | * AP sends command 0x4002 to the EC |
| 4438 | * EC sends command 0x0002 to the PD MCU |
| 4439 | * EC forwards PD MCU response back to the AP |
| 4440 | */ |
| 4441 | |
| 4442 | /* Offset and max command number for sub-device n */ |
| 4443 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 4444 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 4445 | |
| 4446 | /*****************************************************************************/ |
| 4447 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4448 | * Deprecated constants. These constants have been renamed for clarity. The |
| 4449 | * meaning and size has not changed. Programs that use the old names should |
| 4450 | * switch to the new names soon, as the old names may not be carried forward |
| 4451 | * forever. |
| 4452 | */ |
| 4453 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 4454 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 4455 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 4456 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame^] | 4457 | #endif /* !__ACPI__ && !__KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4458 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4459 | #endif /* __CROS_EC_EC_COMMANDS_H */ |