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