Martin Roth | edb937a | 2016-01-12 16:17:44 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // |
| 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are |
| 5 | // met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright |
| 8 | // notice, this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above |
| 10 | // copyright notice, this list of conditions and the following disclaimer |
| 11 | // in the documentation and/or other materials provided with the |
| 12 | // distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 28 | |
| 29 | /* Host communication command constants for Chrome EC */ |
| 30 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 31 | #ifndef __CROS_EC_EC_COMMANDS_H |
| 32 | #define __CROS_EC_EC_COMMANDS_H |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 33 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 34 | #if !defined(__ACPI__) && !defined(__KERNEL__) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 35 | #include <stdint.h> |
| 36 | #endif |
| 37 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 42 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 43 | /* |
| 44 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 45 | * It is used to not include macros that may cause conflicts in foreign |
| 46 | * projects (refer to crbug.com/984623). |
| 47 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 48 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 49 | /* |
| 50 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 51 | * generates more efficient code for accessing request/response structures on |
| 52 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 53 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 54 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 55 | #include "compile_time_macros.h" |
| 56 | |
| 57 | #else |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 58 | #define BUILD_ASSERT(_cond) |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 59 | #endif /* CHROMIUM_EC */ |
| 60 | |
| 61 | #ifdef __KERNEL__ |
| 62 | #include <linux/limits.h> |
| 63 | #else |
| 64 | /* |
| 65 | * Defines macros that may be needed but are for sure defined by the linux |
| 66 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 67 | * util/make_linux_ec_commands_h.sh). |
| 68 | * cros_ec_commands.h looks more integrated to the kernel. |
| 69 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 70 | |
| 71 | #ifndef BIT |
| 72 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 75 | #ifndef BIT_ULL |
| 76 | #define BIT_ULL(nr) (1ULL << (nr)) |
| 77 | #endif |
| 78 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 79 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 80 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 81 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 82 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 83 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 84 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 85 | * determined in other ways. Remove this once the kernel code no longer |
| 86 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 87 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 88 | #define EC_PROTO_VERSION 0x00000002 |
| 89 | |
| 90 | /* Command version mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 91 | #define EC_VER_MASK(version) BIT(version) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 92 | |
| 93 | /* I/O addresses for ACPI commands */ |
| 94 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 95 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
| 96 | |
| 97 | /* I/O addresses for host command */ |
| 98 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 99 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
| 100 | |
| 101 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 102 | /* Protocol version 2 */ |
| 103 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
| 104 | #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 105 | * EC_PROTO2_MAX_PARAM_SIZE |
| 106 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 107 | /* Protocol version 3 */ |
| 108 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 109 | #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 110 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 111 | /* |
| 112 | * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 113 | * and they tell the kernel that so we have to think of it as two parts. |
| 114 | */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 115 | #define EC_HOST_CMD_REGION0 0x800 |
| 116 | #define EC_HOST_CMD_REGION1 0x880 |
| 117 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
| 118 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 119 | /* EC command register bit functions */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 120 | #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ |
| 121 | #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ |
| 122 | #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ |
| 123 | #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ |
| 124 | #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ |
| 125 | #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ |
| 126 | #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 127 | |
| 128 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 129 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 130 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
| 131 | |
| 132 | /* The offset address of each type of data in mapped memory. */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 133 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 134 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 135 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 136 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 137 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 138 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 139 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
| 140 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
| 141 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 142 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
| 143 | /* Unused 0x28 - 0x2f */ |
| 144 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
| 145 | /* Unused 0x31 - 0x33 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 146 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ |
| 147 | /* Battery values are all 32 bits, unless otherwise noted. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 148 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 149 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 150 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 151 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ |
| 152 | #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ |
| 153 | #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ |
| 154 | /* Unused 0x4f */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 155 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 156 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 157 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 158 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 159 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 160 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 161 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 162 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 163 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 164 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
| 165 | /* Unused 0x84 - 0x8f */ |
| 166 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
| 167 | /* Unused 0x91 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 168 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
| 169 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 170 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 171 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 172 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 173 | /* Unused 0xa6 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 174 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 175 | /* |
| 176 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 177 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 178 | * which might be needed by ACPI. |
| 179 | */ |
| 180 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 181 | |
| 182 | /* Define the format of the accelerometer mapped memory status byte. */ |
| 183 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 184 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) |
| 185 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 186 | |
| 187 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
| 188 | #define EC_TEMP_SENSOR_ENTRIES 16 |
| 189 | /* |
| 190 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 191 | * |
| 192 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 193 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 194 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 195 | |
| 196 | /* Special values for mapped temperature sensors */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 197 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 198 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 199 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 200 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 201 | /* |
| 202 | * The offset of temperature value stored in mapped memory. This allows |
| 203 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 204 | */ |
| 205 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 206 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 207 | /* |
| 208 | * Number of ALS readings at EC_MEMMAP_ALS |
| 209 | */ |
| 210 | #define EC_ALS_ENTRIES 2 |
| 211 | |
| 212 | /* |
| 213 | * The default value a temperature sensor will return when it is present but |
| 214 | * has not been read this boot. This is a reasonable number to avoid |
| 215 | * triggering alarms on the host. |
| 216 | */ |
| 217 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 218 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 219 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 220 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 221 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 222 | |
| 223 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 224 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 225 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 226 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 227 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 228 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 229 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 230 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 231 | |
| 232 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 233 | #define EC_SWITCH_LID_OPEN 0x01 |
| 234 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 235 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 236 | /* Was recovery requested via keyboard; now unused. */ |
| 237 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 238 | /* Recovery requested via dedicated signal (from servo board) */ |
| 239 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 240 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 241 | #define EC_SWITCH_IGNORE0 0x20 |
| 242 | |
| 243 | /* Host command interface flags */ |
| 244 | /* Host command interface supports LPC args (LPC interface only) */ |
| 245 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 246 | /* Host command interface supports version 3 protocol */ |
| 247 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 248 | |
| 249 | /* Wireless switch flags */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 250 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 251 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 252 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 253 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 254 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 255 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 256 | /*****************************************************************************/ |
| 257 | /* |
| 258 | * ACPI commands |
| 259 | * |
| 260 | * These are valid ONLY on the ACPI command/data port. |
| 261 | */ |
| 262 | |
| 263 | /* |
| 264 | * ACPI Read Embedded Controller |
| 265 | * |
| 266 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 267 | * |
| 268 | * Use the following sequence: |
| 269 | * |
| 270 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 271 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 272 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 273 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 274 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 275 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 276 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * ACPI Write Embedded Controller |
| 280 | * |
| 281 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 282 | * |
| 283 | * Use the following sequence: |
| 284 | * |
| 285 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 286 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 287 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 288 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 289 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 290 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 291 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * ACPI Burst Enable Embedded Controller |
| 295 | * |
| 296 | * This enables burst mode on the EC to allow the host to issue several |
| 297 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 298 | * data are locked out to ensure data consistency. |
| 299 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 300 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * ACPI Burst Disable Embedded Controller |
| 304 | * |
| 305 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 306 | * multi-byte data. |
| 307 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 308 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * ACPI Query Embedded Controller |
| 312 | * |
| 313 | * This clears the lowest-order bit in the currently pending host events, and |
| 314 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 315 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 316 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 317 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 318 | |
| 319 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 320 | |
| 321 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 322 | #define EC_ACPI_MEM_VERSION 0x00 |
| 323 | /* |
| 324 | * Test location; writing value here updates test compliment byte to (0xff - |
| 325 | * value). |
| 326 | */ |
| 327 | #define EC_ACPI_MEM_TEST 0x01 |
| 328 | /* Test compliment; writes here are ignored. */ |
| 329 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
| 330 | |
| 331 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 332 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 333 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 334 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 335 | |
| 336 | /* |
| 337 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 338 | * independent thresholds attached to them. The current value of the ID |
| 339 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 340 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 341 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 342 | * |
| 343 | * The spec does not mandate any way to read back the threshold settings |
| 344 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 345 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 346 | * returns one sensor ID that has crossed one of its threshold (in either |
| 347 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 348 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 349 | * the unread event count for that sensor. |
| 350 | */ |
| 351 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 352 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 353 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 354 | /* |
| 355 | * Here are the bits for the COMMIT register: |
| 356 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 357 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 358 | * Each write to the commit register affects one threshold. |
| 359 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 360 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 361 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 362 | /* |
| 363 | * Example: |
| 364 | * |
| 365 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 366 | * write 2 to [0x05] -- select temp sensor 2 |
| 367 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 368 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 369 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 370 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 371 | * |
| 372 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 373 | * write 2 to [0x05] -- select temp sensor 2 |
| 374 | * write 0x1 to [0x07] -- disable threshold 1 |
| 375 | */ |
| 376 | |
| 377 | /* DPTF battery charging current limit */ |
| 378 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 379 | |
| 380 | /* Charging limit is specified in 64 mA steps */ |
| 381 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 382 | /* Value to disable DPTF battery charging limit */ |
| 383 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 384 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 385 | /* |
| 386 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 387 | * Bits Definition |
| 388 | * 3:1 Device DPTF Profile Number (DDPN) |
| 389 | * 0 = Reserved for backward compatibility (indicates no valid |
| 390 | * profile number. Host should fall back to using TBMD). |
| 391 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 392 | * to be loaded. |
| 393 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 394 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 395 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 396 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 397 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 398 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 399 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 400 | |
| 401 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 402 | * Report device features. Uses the same format as the host command, except: |
| 403 | * |
| 404 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 405 | * of features", which is of limited interest when the system is already |
| 406 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 407 | * these are supported, it defaults to 0. |
| 408 | * This allows detecting the presence of this field since older versions of |
| 409 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 410 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 411 | * are valid. |
| 412 | */ |
| 413 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 414 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 415 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 416 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 417 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 418 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 419 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 420 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 421 | |
| 422 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
| 423 | |
| 424 | /* |
| 425 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 426 | * is enabled (1) or disabled (0). |
| 427 | * bit 0 USB port ID 0 |
| 428 | * ... |
| 429 | * bit 7 USB port ID 7 |
| 430 | */ |
| 431 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 432 | |
| 433 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 434 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 435 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 436 | */ |
| 437 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 438 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 439 | |
| 440 | /* Current version of ACPI memory address space */ |
| 441 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 442 | |
| 443 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 444 | /* |
| 445 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 446 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 447 | * handle actual C code so keep it separate. |
| 448 | */ |
| 449 | #ifndef __ACPI__ |
| 450 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 451 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 452 | /* |
| 453 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 454 | * checking prefers __packed over __attribute__((packed)). |
| 455 | */ |
| 456 | #ifndef __packed |
| 457 | #define __packed __attribute__((packed)) |
| 458 | #endif |
| 459 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 460 | #ifndef __aligned |
| 461 | #define __aligned(x) __attribute__((aligned(x))) |
| 462 | #endif |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 463 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 464 | |
| 465 | /* |
| 466 | * Attributes for EC request and response packets. Just defining __packed |
| 467 | * results in inefficient assembly code on ARM, if the structure is actually |
| 468 | * 32-bit aligned, as it should be for all buffers. |
| 469 | * |
| 470 | * Be very careful when adding these to existing structures. They will round |
| 471 | * up the structure size to the specified boundary. |
| 472 | * |
| 473 | * Also be very careful to make that if a structure is included in some other |
| 474 | * parent structure that the alignment will still be true given the packing of |
| 475 | * the parent structure. This is particularly important if the sub-structure |
| 476 | * will be passed as a pointer to another function, since that function will |
Elyes HAOUAS | 58d5df7 | 2018-08-07 12:22:50 +0200 | [diff] [blame] | 477 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 478 | * |
| 479 | * Also be very careful using __packed - particularly when nesting non-packed |
| 480 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 481 | * always use one of these attributes. |
| 482 | * |
| 483 | * Once everything is annotated properly, the following search strings should |
| 484 | * not return ANY matches in this file other than right here: |
| 485 | * |
| 486 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 487 | * |
| 488 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 489 | * members of other structs/unions (and their original declarations should be |
| 490 | * annotated). |
| 491 | */ |
| 492 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 493 | |
| 494 | /* |
| 495 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 496 | * byte boundary. |
| 497 | */ |
| 498 | #define __ec_align1 __packed |
| 499 | #define __ec_align2 __packed __aligned(2) |
| 500 | #define __ec_align4 __packed __aligned(4) |
| 501 | |
| 502 | /* |
| 503 | * Packed structure which must be under-aligned, because its size is not a |
| 504 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 505 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 506 | * |
| 507 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 508 | * its members, but use the __packed version for sizeof(). |
| 509 | */ |
| 510 | #define __ec_align_size1 __packed |
| 511 | |
| 512 | /* |
| 513 | * Packed structure which must be under-aligned, because its offset inside a |
| 514 | * parent structure is not a 4-byte multiple. |
| 515 | */ |
| 516 | #define __ec_align_offset1 __packed |
| 517 | #define __ec_align_offset2 __packed __aligned(2) |
| 518 | |
| 519 | /* |
| 520 | * Structures which are complicated enough that I'm skipping them on the first |
| 521 | * pass. They are effectively unchanged from their previous definitions. |
| 522 | * |
| 523 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 524 | * to work out the size and offset of each member and add explicit padding to |
| 525 | * maintain those. |
| 526 | */ |
| 527 | #define __ec_todo_packed __packed |
| 528 | #define __ec_todo_unpacked |
| 529 | |
| 530 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
| 531 | |
| 532 | /* |
| 533 | * Packed structures make no assumption about alignment, so they do inefficient |
| 534 | * byte-wise reads. |
| 535 | */ |
| 536 | #define __ec_align1 __packed |
| 537 | #define __ec_align2 __packed |
| 538 | #define __ec_align4 __packed |
| 539 | #define __ec_align_size1 __packed |
| 540 | #define __ec_align_offset1 __packed |
| 541 | #define __ec_align_offset2 __packed |
| 542 | #define __ec_todo_packed __packed |
| 543 | #define __ec_todo_unpacked |
| 544 | |
| 545 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
| 546 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 547 | /* LPC command status byte masks */ |
| 548 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 549 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 550 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 551 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 552 | /* EC is processing a command */ |
| 553 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 554 | /* Last write to EC was a command, not data */ |
| 555 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 556 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 557 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 558 | /* SCI event is pending (requesting SCI query) */ |
| 559 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 560 | /* SMI event is pending (requesting SMI query) */ |
| 561 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 562 | /* (reserved) */ |
| 563 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 564 | |
| 565 | /* |
| 566 | * EC is busy. This covers both the EC processing a command, and the host has |
| 567 | * written a new command but the EC hasn't picked it up yet. |
| 568 | */ |
| 569 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 570 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 571 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 572 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 573 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 574 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 575 | enum ec_status { |
| 576 | EC_RES_SUCCESS = 0, |
| 577 | EC_RES_INVALID_COMMAND = 1, |
| 578 | EC_RES_ERROR = 2, |
| 579 | EC_RES_INVALID_PARAM = 3, |
| 580 | EC_RES_ACCESS_DENIED = 4, |
| 581 | EC_RES_INVALID_RESPONSE = 5, |
| 582 | EC_RES_INVALID_VERSION = 6, |
| 583 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 584 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 585 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 586 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 587 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 588 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 589 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 590 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 591 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 592 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 593 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 594 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 595 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 596 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 597 | |
| 598 | EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ |
| 599 | } __packed; |
| 600 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 601 | |
| 602 | /* |
| 603 | * Host event codes. Note these are 1-based, not 0-based, because ACPI query |
| 604 | * EC command uses code 0 to mean "no event pending". We explicitly specify |
| 605 | * each value in the enum listing so they won't change if we delete/insert an |
| 606 | * item or rearrange the list (it needs to be stable across platforms, not |
| 607 | * just within a single compiled instance). |
| 608 | */ |
| 609 | enum host_event_code { |
| 610 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 611 | EC_HOST_EVENT_LID_OPEN = 2, |
| 612 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 613 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 614 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 615 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 616 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 617 | EC_HOST_EVENT_BATTERY = 8, |
| 618 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 619 | /* Event generated by a device attached to the EC */ |
| 620 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 621 | EC_HOST_EVENT_THERMAL = 11, |
| 622 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 623 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 624 | /* |
| 625 | * EC has finished initializing the host interface. The host can check |
| 626 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 627 | * determine when the EC is ready to accept subsequent commands. |
| 628 | */ |
| 629 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 630 | /* Keyboard recovery combo has been pressed */ |
| 631 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 632 | |
| 633 | /* Shutdown due to thermal overload */ |
| 634 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 635 | /* Shutdown due to battery level too low */ |
| 636 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 637 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 638 | /* Suggest that the AP throttle itself */ |
| 639 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 640 | /* Suggest that the AP resume normal speed */ |
| 641 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 642 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 643 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 644 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 645 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 646 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 647 | |
| 648 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 649 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 650 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 651 | /* Battery Status flags have changed */ |
| 652 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 653 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 654 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 655 | EC_HOST_EVENT_PANIC = 24, |
| 656 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 657 | /* Keyboard fastboot combo has been pressed */ |
| 658 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 659 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 660 | /* EC RTC event occurred */ |
| 661 | EC_HOST_EVENT_RTC = 26, |
| 662 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 663 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 664 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 665 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 666 | /* EC desires to change state of host-controlled USB mux */ |
| 667 | EC_HOST_EVENT_USB_MUX = 28, |
| 668 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 669 | /* |
| 670 | * The device has changed "modes". This can be one of the following: |
| 671 | * |
| 672 | * - TABLET/LAPTOP mode |
| 673 | * - detachable base attach/detach event |
| 674 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 675 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 676 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 677 | /* Keyboard recovery combo with hardware reinitialization */ |
| 678 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 679 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 680 | /* WoV */ |
| 681 | EC_HOST_EVENT_WOV = 31, |
| 682 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 683 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 684 | * The high bit of the event mask is not used as a host event code. If |
| 685 | * it reads back as set, then the entire event mask should be |
| 686 | * considered invalid by the host. This can happen when reading the |
| 687 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 688 | * not initialized on the EC, or improperly configured on the host. |
| 689 | */ |
| 690 | EC_HOST_EVENT_INVALID = 32 |
| 691 | }; |
| 692 | /* Host event mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 693 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 694 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 695 | /** |
| 696 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 697 | * @flags: The host argument flags. |
| 698 | * @command_version: Command version. |
| 699 | * @data_size: The length of data. |
| 700 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 701 | * all params/response data bytes. |
| 702 | */ |
| 703 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 704 | uint8_t flags; |
| 705 | uint8_t command_version; |
| 706 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 707 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 708 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 709 | |
| 710 | /* Flags for ec_lpc_host_args.flags */ |
| 711 | /* |
| 712 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 713 | * params. |
| 714 | * |
| 715 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 716 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 717 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 718 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 719 | */ |
| 720 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 721 | /* |
| 722 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 723 | * |
| 724 | * If EC responds to a command and this flag is not set, this is an old-style |
| 725 | * response. Command version is 0 and response data from EC is at |
| 726 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 727 | */ |
| 728 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 729 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 730 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 731 | /* |
| 732 | * Byte codes returned by EC over SPI interface. |
| 733 | * |
| 734 | * These can be used by the AP to debug the EC interface, and to determine |
| 735 | * when the EC is not in a state where it will ever get around to responding |
| 736 | * to the AP. |
| 737 | * |
| 738 | * Example of sequence of bytes read from EC for a current good transfer: |
| 739 | * 1. - - AP asserts chip select (CS#) |
| 740 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 741 | * 3. - - EC starts handling CS# interrupt |
| 742 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 743 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 744 | * bytes looking for EC_SPI_FRAME_START |
| 745 | * 6. - - EC finishes processing and sets up response |
| 746 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 747 | * 8. (response packet) - AP reads response packet |
| 748 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 749 | * 10 - - AP deasserts chip select |
| 750 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 751 | * next request |
| 752 | * |
| 753 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 754 | * the following byte values: |
| 755 | * EC_SPI_OLD_READY |
| 756 | * EC_SPI_RX_READY |
| 757 | * EC_SPI_RECEIVING |
| 758 | * EC_SPI_PROCESSING |
| 759 | * |
| 760 | * Then the EC found an error in the request, or was not ready for the request |
| 761 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 762 | * because the EC is unable to tell when the AP is done sending its request. |
| 763 | */ |
| 764 | |
| 765 | /* |
| 766 | * Framing byte which precedes a response packet from the EC. After sending a |
| 767 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 768 | * clock in the response packet. |
| 769 | */ |
| 770 | #define EC_SPI_FRAME_START 0xec |
| 771 | |
| 772 | /* |
| 773 | * Padding bytes which are clocked out after the end of a response packet. |
| 774 | */ |
| 775 | #define EC_SPI_PAST_END 0xed |
| 776 | |
| 777 | /* |
| 778 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 779 | * that the AP will send a valid packet header (starting with |
| 780 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 781 | */ |
| 782 | #define EC_SPI_RX_READY 0xf8 |
| 783 | |
| 784 | /* |
| 785 | * EC has started receiving the request from the AP, but hasn't started |
| 786 | * processing it yet. |
| 787 | */ |
| 788 | #define EC_SPI_RECEIVING 0xf9 |
| 789 | |
| 790 | /* EC has received the entire request from the AP and is processing it. */ |
| 791 | #define EC_SPI_PROCESSING 0xfa |
| 792 | |
| 793 | /* |
| 794 | * EC received bad data from the AP, such as a packet header with an invalid |
| 795 | * length. EC will ignore all data until chip select deasserts. |
| 796 | */ |
| 797 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 798 | |
| 799 | /* |
| 800 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 801 | * chip select and started clocking data before the EC was ready to receive it. |
| 802 | * EC will ignore all data until chip select deasserts. |
| 803 | */ |
| 804 | #define EC_SPI_NOT_READY 0xfc |
| 805 | |
| 806 | /* |
| 807 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 808 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 809 | * a fully received packet but is not ready to respond yet. |
| 810 | */ |
| 811 | #define EC_SPI_OLD_READY 0xfd |
| 812 | |
| 813 | /*****************************************************************************/ |
| 814 | |
| 815 | /* |
| 816 | * Protocol version 2 for I2C and SPI send a request this way: |
| 817 | * |
| 818 | * 0 EC_CMD_VERSION0 + (command version) |
| 819 | * 1 Command number |
| 820 | * 2 Length of params = N |
| 821 | * 3..N+2 Params, if any |
| 822 | * N+3 8-bit checksum of bytes 0..N+2 |
| 823 | * |
| 824 | * The corresponding response is: |
| 825 | * |
| 826 | * 0 Result code (EC_RES_*) |
| 827 | * 1 Length of params = M |
| 828 | * 2..M+1 Params, if any |
| 829 | * M+2 8-bit checksum of bytes 0..M+1 |
| 830 | */ |
| 831 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 832 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 833 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 834 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 835 | |
| 836 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 837 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 838 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 839 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 840 | |
| 841 | /* Parameter length was limited by the LPC interface */ |
| 842 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 843 | |
| 844 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 845 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 846 | EC_PROTO2_MAX_PARAM_SIZE) |
| 847 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 848 | EC_PROTO2_MAX_PARAM_SIZE) |
| 849 | |
| 850 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * Value written to legacy command port / prefix byte to indicate protocol |
| 854 | * 3+ structs are being used. Usage is bus-dependent. |
| 855 | */ |
| 856 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 857 | |
| 858 | #define EC_HOST_REQUEST_VERSION 3 |
| 859 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 860 | /** |
| 861 | * struct ec_host_request - Version 3 request from host. |
| 862 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 863 | * receives a header with a version it doesn't know how to |
| 864 | * parse. |
| 865 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 866 | * should total to 0. |
| 867 | * @command: Command to send (EC_CMD_...) |
| 868 | * @command_version: Command version. |
| 869 | * @reserved: Unused byte in current protocol version; set to 0. |
| 870 | * @data_len: Length of data which follows this header. |
| 871 | */ |
| 872 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 873 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 874 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 875 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 876 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 877 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 878 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 879 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 880 | |
| 881 | #define EC_HOST_RESPONSE_VERSION 3 |
| 882 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 883 | /** |
| 884 | * struct ec_host_response - Version 3 response from EC. |
| 885 | * @struct_version: Struct version (=3). |
| 886 | * @checksum: Checksum of response and data; sum of all bytes including |
| 887 | * checksum should total to 0. |
| 888 | * @result: EC's response to the command (separate from communication failure) |
| 889 | * @data_len: Length of data which follows this header. |
| 890 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 891 | */ |
| 892 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 893 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 894 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 895 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 896 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 897 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 898 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 899 | |
| 900 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 901 | |
| 902 | /* |
| 903 | * Host command protocol V4. |
| 904 | * |
| 905 | * Packets always start with a request or response header. They are followed |
| 906 | * by data_len bytes of data. If the data_crc_present flag is set, the data |
| 907 | * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1 |
| 908 | * polynomial. |
| 909 | * |
| 910 | * Host algorithm when sending a request q: |
| 911 | * |
| 912 | * 101) tries_left=(some value, e.g. 3); |
| 913 | * 102) q.seq_num++ |
| 914 | * 103) q.seq_dup=0 |
| 915 | * 104) Calculate q.header_crc. |
| 916 | * 105) Send request q to EC. |
| 917 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 918 | * |
| 919 | * 201) If r.struct_version != 4, go to 301. |
| 920 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 921 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 922 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 923 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 924 | * 207) If r.seq_dup == 1, go to 301. |
| 925 | * 208) Return error. |
| 926 | * |
| 927 | * 301) If --tries_left <= 0, return error. |
| 928 | * 302) If q.seq_dup == 1, go to 105. |
| 929 | * 303) q.seq_dup = 1 |
| 930 | * 304) Go to 104. |
| 931 | * |
| 932 | * EC algorithm when receiving a request q. |
| 933 | * EC has response buffer r, error buffer e. |
| 934 | * |
| 935 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 936 | * and go to 301 |
| 937 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 938 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 939 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 940 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 941 | * and go to 301. |
| 942 | * 104) If q.seq_dup == 0, go to 201. |
| 943 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 944 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 945 | * |
| 946 | * 201) Process request q into response r. |
| 947 | * 202) r.seq_num = q.seq_num |
| 948 | * 203) r.seq_dup = q.seq_dup |
| 949 | * 204) Calculate r.header_crc |
| 950 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 951 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 952 | * 206) Send response r. |
| 953 | * |
| 954 | * 301) e.seq_num = q.seq_num |
| 955 | * 302) e.seq_dup = q.seq_dup |
| 956 | * 303) Calculate e.header_crc. |
| 957 | * 304) Send error response e. |
| 958 | */ |
| 959 | |
| 960 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 961 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 962 | /* |
| 963 | * bits 0-3: struct_version: Structure version (=4) |
| 964 | * bit 4: is_response: Is response (=0) |
| 965 | * bits 5-6: seq_num: Sequence number |
| 966 | * bit 7: seq_dup: Sequence duplicate flag |
| 967 | */ |
| 968 | uint8_t fields0; |
| 969 | |
| 970 | /* |
| 971 | * bits 0-4: command_version: Command version |
| 972 | * bits 5-6: Reserved (set 0, ignore on read) |
| 973 | * bit 7: data_crc_present: Is data CRC present after data |
| 974 | */ |
| 975 | uint8_t fields1; |
| 976 | |
| 977 | /* Command code (EC_CMD_*) */ |
| 978 | uint16_t command; |
| 979 | |
| 980 | /* Length of data which follows this header (not including data CRC) */ |
| 981 | uint16_t data_len; |
| 982 | |
| 983 | /* Reserved (set 0, ignore on read) */ |
| 984 | uint8_t reserved; |
| 985 | |
| 986 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 987 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 988 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 989 | |
| 990 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 991 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 992 | /* |
| 993 | * bits 0-3: struct_version: Structure version (=4) |
| 994 | * bit 4: is_response: Is response (=1) |
| 995 | * bits 5-6: seq_num: Sequence number |
| 996 | * bit 7: seq_dup: Sequence duplicate flag |
| 997 | */ |
| 998 | uint8_t fields0; |
| 999 | |
| 1000 | /* |
| 1001 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1002 | * bit 7: data_crc_present: Is data CRC present after data |
| 1003 | */ |
| 1004 | uint8_t fields1; |
| 1005 | |
| 1006 | /* Result code (EC_RES_*) */ |
| 1007 | uint16_t result; |
| 1008 | |
| 1009 | /* Length of data which follows this header (not including data CRC) */ |
| 1010 | uint16_t data_len; |
| 1011 | |
| 1012 | /* Reserved (set 0, ignore on read) */ |
| 1013 | uint8_t reserved; |
| 1014 | |
| 1015 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1016 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1017 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1018 | |
| 1019 | /* Fields in fields0 byte */ |
| 1020 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1021 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1022 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1023 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1024 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
| 1025 | |
| 1026 | /* Fields in fields1 byte */ |
| 1027 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1028 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
| 1029 | |
| 1030 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1031 | /* |
| 1032 | * Notes on commands: |
| 1033 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1034 | * Each command is an 16-bit command value. Commands which take params or |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1035 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1036 | * specified, the command does not input or output data, respectively. |
| 1037 | * Parameter/response length is implicit in the structs. Some underlying |
| 1038 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1039 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1040 | * |
| 1041 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1042 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1043 | */ |
| 1044 | |
| 1045 | /*****************************************************************************/ |
| 1046 | /* General / test commands */ |
| 1047 | |
| 1048 | /* |
| 1049 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1050 | * changes. |
| 1051 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1052 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1053 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1054 | /** |
| 1055 | * struct ec_response_proto_version - Response to the proto version command. |
| 1056 | * @version: The protocol version. |
| 1057 | */ |
| 1058 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1059 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1060 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1061 | |
| 1062 | /* |
| 1063 | * Hello. This is a simple command to test the EC is responsive to |
| 1064 | * commands. |
| 1065 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1066 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1067 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1068 | /** |
| 1069 | * struct ec_params_hello - Parameters to the hello command. |
| 1070 | * @in_data: Pass anything here. |
| 1071 | */ |
| 1072 | struct ec_params_hello { |
| 1073 | uint32_t in_data; |
| 1074 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1075 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1076 | /** |
| 1077 | * struct ec_response_hello - Response to the hello command. |
| 1078 | * @out_data: Output will be in_data + 0x01020304. |
| 1079 | */ |
| 1080 | struct ec_response_hello { |
| 1081 | uint32_t out_data; |
| 1082 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1083 | |
| 1084 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1085 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1086 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 1087 | #if !defined(CHROMIUM_EC) && !defined(__KERNEL__) |
| 1088 | /* |
| 1089 | * enum ec_current_image is deprecated and replaced by enum ec_image. This |
| 1090 | * macro exists for backwards compatibility of external projects until they |
| 1091 | * have been updated: b/149987779. |
| 1092 | */ |
| 1093 | #define ec_current_image ec_image |
| 1094 | #endif |
| 1095 | |
| 1096 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1097 | EC_IMAGE_UNKNOWN = 0, |
| 1098 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 1099 | EC_IMAGE_RW, |
| 1100 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1101 | EC_IMAGE_RO_B, |
| 1102 | EC_IMAGE_RW_B |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1103 | }; |
| 1104 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1105 | /** |
| 1106 | * struct ec_response_get_version - Response to the get version command. |
| 1107 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1108 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1109 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 1110 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1111 | */ |
| 1112 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1113 | char version_string_ro[32]; |
| 1114 | char version_string_rw[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1115 | char reserved[32]; |
| 1116 | uint32_t current_image; |
| 1117 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1118 | |
| 1119 | /* Read test */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1120 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1121 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1122 | /** |
| 1123 | * struct ec_params_read_test - Parameters for the read test command. |
| 1124 | * @offset: Starting value for read buffer. |
| 1125 | * @size: Size to read in bytes. |
| 1126 | */ |
| 1127 | struct ec_params_read_test { |
| 1128 | uint32_t offset; |
| 1129 | uint32_t size; |
| 1130 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1131 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1132 | /** |
| 1133 | * struct ec_response_read_test - Response to the read test command. |
| 1134 | * @data: Data returned by the read test command. |
| 1135 | */ |
| 1136 | struct ec_response_read_test { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1137 | uint32_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1138 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1139 | |
| 1140 | /* |
| 1141 | * Get build information |
| 1142 | * |
| 1143 | * Response is null-terminated string. |
| 1144 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1145 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1146 | |
| 1147 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1148 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1149 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1150 | /** |
| 1151 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1152 | * @vendor: Null-terminated string for chip vendor. |
| 1153 | * @name: Null-terminated string for chip name. |
| 1154 | * @revision: Null-terminated string for chip mask version. |
| 1155 | */ |
| 1156 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1157 | char vendor[32]; |
| 1158 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1159 | char revision[32]; |
| 1160 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1161 | |
| 1162 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1163 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1164 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1165 | /** |
| 1166 | * struct ec_response_board_version - Response to the board version command. |
| 1167 | * @board_version: A monotonously incrementing number. |
| 1168 | */ |
| 1169 | struct ec_response_board_version { |
| 1170 | uint16_t board_version; |
| 1171 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1172 | |
| 1173 | /* |
| 1174 | * Read memory-mapped data. |
| 1175 | * |
| 1176 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1177 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1178 | * |
| 1179 | * Response is params.size bytes of data. |
| 1180 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1181 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1182 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1183 | /** |
| 1184 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1185 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1186 | * @size: Size to read in bytes. |
| 1187 | */ |
| 1188 | struct ec_params_read_memmap { |
| 1189 | uint8_t offset; |
| 1190 | uint8_t size; |
| 1191 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1192 | |
| 1193 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1194 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1195 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1196 | /** |
| 1197 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1198 | * @cmd: Command to check. |
| 1199 | */ |
| 1200 | struct ec_params_get_cmd_versions { |
| 1201 | uint8_t cmd; |
| 1202 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1203 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1204 | /** |
| 1205 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1206 | * versions (v1) |
| 1207 | * @cmd: Command to check. |
| 1208 | */ |
| 1209 | struct ec_params_get_cmd_versions_v1 { |
| 1210 | uint16_t cmd; |
| 1211 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1212 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1213 | /** |
| 1214 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1215 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1216 | * a desired version. |
| 1217 | */ |
| 1218 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1219 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1220 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1221 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1222 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1223 | * Check EC communications status (busy). This is needed on i2c/spi but not |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1224 | * on lpc since it has its own out-of-band busy indicator. |
| 1225 | * |
| 1226 | * lpc must read the status from the command register. Attempting this on |
| 1227 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1228 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1229 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1230 | |
| 1231 | /* Avoid using ec_status which is for return values */ |
| 1232 | enum ec_comms_status { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1233 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1234 | }; |
| 1235 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1236 | /** |
| 1237 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1238 | * command. |
| 1239 | * @flags: Mask of enum ec_comms_status. |
| 1240 | */ |
| 1241 | struct ec_response_get_comms_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1242 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1243 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1244 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1245 | /* Fake a variety of responses, purely for testing purposes. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1246 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1247 | |
| 1248 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1249 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1250 | uint32_t ec_result; |
| 1251 | uint32_t ret_len; |
| 1252 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1253 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1254 | |
| 1255 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1256 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1257 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1258 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1259 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1260 | /* Get protocol information */ |
| 1261 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1262 | |
| 1263 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1264 | /* EC_RES_IN_PROGRESS may be returned if a command is slow */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1265 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1266 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1267 | /** |
| 1268 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1269 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1270 | * version n). |
| 1271 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1272 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1273 | * @flags: see EC_PROTOCOL_INFO_* |
| 1274 | */ |
| 1275 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1276 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1277 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1278 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1279 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1280 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1281 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1282 | |
| 1283 | |
| 1284 | /*****************************************************************************/ |
| 1285 | /* Get/Set miscellaneous values */ |
| 1286 | |
| 1287 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 1288 | #define EC_GSV_SET 0x80000000 |
| 1289 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1290 | /* |
| 1291 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1292 | * meaning for an individual command. |
| 1293 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1294 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1295 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1296 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1297 | uint32_t flags; |
| 1298 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1299 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1300 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1301 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1302 | uint32_t flags; |
| 1303 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1304 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1305 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1306 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1307 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1308 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1309 | /*****************************************************************************/ |
| 1310 | /* List the features supported by the firmware */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1311 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1312 | |
| 1313 | /* Supported features */ |
| 1314 | enum ec_feature_code { |
| 1315 | /* |
| 1316 | * This image contains a limited set of features. Another image |
| 1317 | * in RW partition may support more features. |
| 1318 | */ |
| 1319 | EC_FEATURE_LIMITED = 0, |
| 1320 | /* |
| 1321 | * Commands for probing/reading/writing/erasing the flash in the |
| 1322 | * EC are present. |
| 1323 | */ |
| 1324 | EC_FEATURE_FLASH = 1, |
| 1325 | /* |
| 1326 | * Can control the fan speed directly. |
| 1327 | */ |
| 1328 | EC_FEATURE_PWM_FAN = 2, |
| 1329 | /* |
| 1330 | * Can control the intensity of the keyboard backlight. |
| 1331 | */ |
| 1332 | EC_FEATURE_PWM_KEYB = 3, |
| 1333 | /* |
| 1334 | * Support Google lightbar, introduced on Pixel. |
| 1335 | */ |
| 1336 | EC_FEATURE_LIGHTBAR = 4, |
| 1337 | /* Control of LEDs */ |
| 1338 | EC_FEATURE_LED = 5, |
| 1339 | /* Exposes an interface to control gyro and sensors. |
| 1340 | * The host goes through the EC to access these sensors. |
| 1341 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1342 | */ |
| 1343 | EC_FEATURE_MOTION_SENSE = 6, |
| 1344 | /* The keyboard is controlled by the EC */ |
| 1345 | EC_FEATURE_KEYB = 7, |
| 1346 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1347 | EC_FEATURE_PSTORE = 8, |
| 1348 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1349 | EC_FEATURE_PORT80 = 9, |
| 1350 | /* |
| 1351 | * Thermal management: include TMP specific commands. |
| 1352 | * Higher level than direct fan control. |
| 1353 | */ |
| 1354 | EC_FEATURE_THERMAL = 10, |
| 1355 | /* Can switch the screen backlight on/off */ |
| 1356 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1357 | /* Can switch the wifi module on/off */ |
| 1358 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1359 | /* Monitor host events, through for example SMI or SCI */ |
| 1360 | EC_FEATURE_HOST_EVENTS = 13, |
| 1361 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1362 | EC_FEATURE_GPIO = 14, |
| 1363 | /* The EC can send i2c messages to downstream devices. */ |
| 1364 | EC_FEATURE_I2C = 15, |
| 1365 | /* Command to control charger are included */ |
| 1366 | EC_FEATURE_CHARGER = 16, |
| 1367 | /* Simple battery support. */ |
| 1368 | EC_FEATURE_BATTERY = 17, |
| 1369 | /* |
| 1370 | * Support Smart battery protocol |
| 1371 | * (Common Smart Battery System Interface Specification) |
| 1372 | */ |
| 1373 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1374 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1375 | EC_FEATURE_HANG_DETECT = 19, |
| 1376 | /* Report power information, for pit only */ |
| 1377 | EC_FEATURE_PMU = 20, |
| 1378 | /* Another Cros EC device is present downstream of this one */ |
| 1379 | EC_FEATURE_SUB_MCU = 21, |
| 1380 | /* Support USB Power delivery (PD) commands */ |
| 1381 | EC_FEATURE_USB_PD = 22, |
| 1382 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1383 | EC_FEATURE_USB_MUX = 23, |
| 1384 | /* Motion Sensor code has an internal software FIFO */ |
| 1385 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1386 | /* Support temporary secure vstore */ |
| 1387 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1388 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1389 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1390 | /* EC has RTC feature that can be controlled by host commands */ |
| 1391 | EC_FEATURE_RTC = 27, |
| 1392 | /* The MCU exposes a Fingerprint sensor */ |
| 1393 | EC_FEATURE_FINGERPRINT = 28, |
| 1394 | /* The MCU exposes a Touchpad */ |
| 1395 | EC_FEATURE_TOUCHPAD = 29, |
| 1396 | /* The MCU has RWSIG task enabled */ |
| 1397 | EC_FEATURE_RWSIG = 30, |
| 1398 | /* EC has device events support */ |
| 1399 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1400 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1401 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1402 | /* EC supports 64-bit host events */ |
| 1403 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1404 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1405 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1406 | /* EC supports CEC commands */ |
| 1407 | EC_FEATURE_CEC = 35, |
| 1408 | /* EC supports tight sensor timestamping. */ |
| 1409 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1410 | /* |
| 1411 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1412 | * setting of threshold by host command using |
| 1413 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1414 | */ |
| 1415 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 1416 | /* |
| 1417 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
| 1418 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1419 | * be sent to RO to be precise. |
| 1420 | */ |
| 1421 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1422 | /* The MCU is a System Companion Processor (SCP). */ |
| 1423 | EC_FEATURE_SCP = 39, |
| 1424 | /* The MCU is an Integrated Sensor Hub */ |
| 1425 | EC_FEATURE_ISH = 40, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1426 | }; |
| 1427 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1428 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1429 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1430 | |
| 1431 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1432 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1433 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1434 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1435 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1436 | /* Get the board's SKU ID from EC */ |
| 1437 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1438 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1439 | /* Set SKU ID from AP */ |
| 1440 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1441 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1442 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1443 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1444 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1445 | |
| 1446 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1447 | /* Flash commands */ |
| 1448 | |
| 1449 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1450 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1451 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1452 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1453 | /** |
| 1454 | * struct ec_response_flash_info - Response to the flash info command. |
| 1455 | * @flash_size: Usable flash size in bytes. |
| 1456 | * @write_block_size: Write block size. Write offset and size must be a |
| 1457 | * multiple of this. |
| 1458 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1459 | * multiple of this. |
| 1460 | * @protect_block_size: Protection block size. Protection offset and size |
| 1461 | * must be a multiple of this. |
| 1462 | * |
| 1463 | * Version 0 returns these fields. |
| 1464 | */ |
| 1465 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1466 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1467 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1468 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1469 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1470 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1471 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1472 | /* |
| 1473 | * Flags for version 1+ flash info command |
| 1474 | * EC flash erases bits to 0 instead of 1. |
| 1475 | */ |
| 1476 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1477 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1478 | /* |
| 1479 | * Flash must be selected for read/write/erase operations to succeed. This may |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1480 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1481 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1482 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1483 | * chip functionality. |
| 1484 | */ |
| 1485 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1486 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1487 | /** |
| 1488 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1489 | * @flash_size: Usable flash size in bytes. |
| 1490 | * @write_block_size: Write block size. Write offset and size must be a |
| 1491 | * multiple of this. |
| 1492 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1493 | * multiple of this. |
| 1494 | * @protect_block_size: Protection block size. Protection offset and size |
| 1495 | * must be a multiple of this. |
| 1496 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1497 | * size is exactly this and offset is a multiple of this. |
| 1498 | * For example, an EC may have a write buffer which can do |
| 1499 | * half-page operations if data is aligned, and a slower |
| 1500 | * word-at-a-time write mode. |
| 1501 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1502 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1503 | * Version 1 returns the same initial fields as version 0, with additional |
| 1504 | * fields following. |
| 1505 | * |
| 1506 | * gcc anonymous structs don't seem to get along with the __packed directive; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1507 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1508 | * one. |
| 1509 | * |
| 1510 | * Version 2 supports flash banks of different sizes: |
| 1511 | * The caller specified the number of banks it has preallocated |
| 1512 | * (num_banks_desc) |
| 1513 | * The EC returns the number of banks describing the flash memory. |
| 1514 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1515 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1516 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1517 | /* Version 0 fields; see above for description */ |
| 1518 | uint32_t flash_size; |
| 1519 | uint32_t write_block_size; |
| 1520 | uint32_t erase_block_size; |
| 1521 | uint32_t protect_block_size; |
| 1522 | |
| 1523 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1524 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1525 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1526 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1527 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1528 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1529 | /* Number of banks to describe */ |
| 1530 | uint16_t num_banks_desc; |
| 1531 | /* Reserved; set 0; ignore on read */ |
| 1532 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1533 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1534 | |
| 1535 | struct ec_flash_bank { |
| 1536 | /* Number of sector is in this bank. */ |
| 1537 | uint16_t count; |
| 1538 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1539 | uint8_t size_exp; |
| 1540 | /* Minimal write size for the sectors in this bank */ |
| 1541 | uint8_t write_size_exp; |
| 1542 | /* Erase size for the sectors in this bank */ |
| 1543 | uint8_t erase_size_exp; |
| 1544 | /* Size for write protection, usually identical to erase size. */ |
| 1545 | uint8_t protect_size_exp; |
| 1546 | /* Reserved; set 0; ignore on read */ |
| 1547 | uint8_t reserved[2]; |
| 1548 | }; |
| 1549 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1550 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1551 | /* Total flash in the EC. */ |
| 1552 | uint32_t flash_size; |
| 1553 | /* Flags; see EC_FLASH_INFO_* */ |
| 1554 | uint32_t flags; |
| 1555 | /* Maximum size to use to send data to write to the EC. */ |
| 1556 | uint32_t write_ideal_size; |
| 1557 | /* Number of banks present in the EC. */ |
| 1558 | uint16_t num_banks_total; |
| 1559 | /* Number of banks described in banks array. */ |
| 1560 | uint16_t num_banks_desc; |
| 1561 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1562 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1563 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1564 | /* |
| 1565 | * Read flash |
| 1566 | * |
| 1567 | * Response is params.size bytes of data. |
| 1568 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1569 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1570 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1571 | /** |
| 1572 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1573 | * @offset: Byte offset to read. |
| 1574 | * @size: Size to read in bytes. |
| 1575 | */ |
| 1576 | struct ec_params_flash_read { |
| 1577 | uint32_t offset; |
| 1578 | uint32_t size; |
| 1579 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1580 | |
| 1581 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1582 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1583 | #define EC_VER_FLASH_WRITE 1 |
| 1584 | |
| 1585 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1586 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1587 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1588 | /** |
| 1589 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1590 | * @offset: Byte offset to write. |
| 1591 | * @size: Size to write in bytes. |
| 1592 | */ |
| 1593 | struct ec_params_flash_write { |
| 1594 | uint32_t offset; |
| 1595 | uint32_t size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1596 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1597 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1598 | |
| 1599 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1600 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1601 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1602 | /** |
| 1603 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1604 | * @offset: Byte offset to erase. |
| 1605 | * @size: Size to erase in bytes. |
| 1606 | */ |
| 1607 | struct ec_params_flash_erase { |
| 1608 | uint32_t offset; |
| 1609 | uint32_t size; |
| 1610 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1611 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1612 | /* |
| 1613 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1614 | * subcommands can returns: |
| 1615 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1616 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1617 | * EC_RES_ERROR : other errors. |
| 1618 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1619 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1620 | * |
| 1621 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1622 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1623 | * the proper result. |
| 1624 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1625 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1626 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1627 | * permitted while erasing. (For instance, STM32F4). |
| 1628 | */ |
| 1629 | enum ec_flash_erase_cmd { |
| 1630 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1631 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1632 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1633 | }; |
| 1634 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1635 | /** |
| 1636 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1637 | * @cmd: One of ec_flash_erase_cmd. |
| 1638 | * @reserved: Pad byte; currently always contains 0. |
| 1639 | * @flag: No flags defined yet; set to 0. |
| 1640 | * @params: Same as v0 parameters. |
| 1641 | */ |
| 1642 | struct ec_params_flash_erase_v1 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1643 | uint8_t cmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1644 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1645 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1646 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1647 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1648 | |
| 1649 | /* |
| 1650 | * Get/set flash protection. |
| 1651 | * |
| 1652 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1653 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1654 | * some flags require a subsequent hard reset to take effect. Check the |
| 1655 | * returned flags bits to see what actually happened. |
| 1656 | * |
| 1657 | * If mask=0, simply returns the current flags state. |
| 1658 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1659 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1660 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1661 | |
| 1662 | /* Flags for flash protection */ |
| 1663 | /* RO flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1664 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1665 | /* |
| 1666 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1667 | * be changed. |
| 1668 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1669 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1670 | /* Entire flash code protected now, until reboot. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1671 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1672 | /* Flash write protect GPIO is asserted now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1673 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1674 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1675 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1676 | /* |
| 1677 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1678 | * flash which should be protected is not protected. Usually fixed by |
| 1679 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1680 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1681 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1682 | /* Entire flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1683 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1684 | /* RW flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1685 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1686 | /* RW flash code protected now. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1687 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1688 | /* Rollback information flash region protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1689 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1690 | /* Rollback information flash region protected now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1691 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1692 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1693 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1694 | /** |
| 1695 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1696 | * @mask: Bits in flags to apply. |
| 1697 | * @flags: New flags to apply. |
| 1698 | */ |
| 1699 | struct ec_params_flash_protect { |
| 1700 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1701 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1702 | } __ec_align4; |
| 1703 | |
| 1704 | /** |
| 1705 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1706 | * @flags: Current value of flash protect flags. |
| 1707 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1708 | * caller to distinguish between flags which aren't set vs. flags |
| 1709 | * which can't be set on this platform. |
| 1710 | * @writable_flags: Flags which can be changed given the current protection |
| 1711 | * state. |
| 1712 | */ |
| 1713 | struct ec_response_flash_protect { |
| 1714 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1715 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1716 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1717 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1718 | |
| 1719 | /* |
| 1720 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1721 | * write protect. These commands may be reused with version > 0. |
| 1722 | */ |
| 1723 | |
| 1724 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1725 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1726 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1727 | |
| 1728 | enum ec_flash_region { |
| 1729 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1730 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1731 | /* |
| 1732 | * Region which holds active RW image. 'Active' is different from |
| 1733 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1734 | * scheduled to run, active/non-active applies only to RW images (for |
| 1735 | * the same reason 'update' applies only to RW images. It's a state of |
| 1736 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1737 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1738 | * doesn't enter 'running' state but it's still active on a flash. |
| 1739 | */ |
| 1740 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1741 | /* |
| 1742 | * Region which should be write-protected in the factory (a superset of |
| 1743 | * EC_FLASH_REGION_RO) |
| 1744 | */ |
| 1745 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1746 | /* Region which holds updatable (non-active) RW image */ |
| 1747 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1748 | /* Number of regions */ |
| 1749 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1750 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1751 | /* |
| 1752 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1753 | * so the old constant is deprecated. |
| 1754 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1755 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1756 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1757 | /** |
| 1758 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1759 | * command. |
| 1760 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1761 | */ |
| 1762 | struct ec_params_flash_region_info { |
| 1763 | uint32_t region; |
| 1764 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1765 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1766 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1767 | uint32_t offset; |
| 1768 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1769 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1770 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1771 | /* Read/write VbNvContext */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1772 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1773 | #define EC_VER_VBNV_CONTEXT 1 |
| 1774 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1775 | |
| 1776 | enum ec_vbnvcontext_op { |
| 1777 | EC_VBNV_CONTEXT_OP_READ, |
| 1778 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1779 | }; |
| 1780 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1781 | struct ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1782 | uint32_t op; |
| 1783 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1784 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1785 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1786 | struct ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1787 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1788 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1789 | |
| 1790 | |
| 1791 | /* Get SPI flash information */ |
| 1792 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1793 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1794 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1795 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1796 | uint8_t jedec[3]; |
| 1797 | |
| 1798 | /* Pad byte; currently always contains 0 */ |
| 1799 | uint8_t reserved0; |
| 1800 | |
| 1801 | /* Manufacturer / device ID from command 0x90 */ |
| 1802 | uint8_t mfr_dev_id[2]; |
| 1803 | |
| 1804 | /* Status registers from command 0x05 and 0x35 */ |
| 1805 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1806 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1807 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1808 | |
| 1809 | /* Select flash during flash operations */ |
| 1810 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1811 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1812 | /** |
| 1813 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1814 | * @select: 1 to select flash, 0 to deselect flash |
| 1815 | */ |
| 1816 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1817 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1818 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1819 | |
| 1820 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1821 | /** |
| 1822 | * Request random numbers to be generated and returned. |
| 1823 | * Can be used to test the random number generator is truly random. |
| 1824 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1825 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1826 | */ |
| 1827 | #define EC_CMD_RAND_NUM 0x001A |
| 1828 | #define EC_VER_RAND_NUM 0 |
| 1829 | |
| 1830 | struct ec_params_rand_num { |
| 1831 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
| 1832 | } __ec_align4; |
| 1833 | |
| 1834 | struct ec_response_rand_num { |
| 1835 | uint8_t rand[0]; /**< generated random numbers */ |
| 1836 | } __ec_align4; |
| 1837 | |
| 1838 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1839 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 1840 | /** |
| 1841 | * Get information about the key used to sign the RW firmware. |
| 1842 | * For more details on the fields, see "struct vb21_packed_key". |
| 1843 | */ |
| 1844 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1845 | #define EC_VER_RWSIG_INFO 0 |
| 1846 | |
| 1847 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1848 | |
| 1849 | #ifdef CHROMIUM_EC |
| 1850 | /* Don't force external projects to depend on the vboot headers. */ |
| 1851 | #include "vb21_struct.h" |
| 1852 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1853 | #endif |
| 1854 | |
| 1855 | struct ec_response_rwsig_info { |
| 1856 | /** |
| 1857 | * Signature algorithm used by the key |
| 1858 | * (enum vb2_signature_algorithm). |
| 1859 | */ |
| 1860 | uint16_t sig_alg; |
| 1861 | |
| 1862 | /** |
| 1863 | * Hash digest algorithm used with the key |
| 1864 | * (enum vb2_hash_algorithm). |
| 1865 | */ |
| 1866 | uint16_t hash_alg; |
| 1867 | |
| 1868 | /** Key version. */ |
| 1869 | uint32_t key_version; |
| 1870 | |
| 1871 | /** Key ID (struct vb2_id). */ |
| 1872 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 1873 | |
| 1874 | uint8_t key_is_valid; |
| 1875 | |
| 1876 | /** Alignment padding. */ |
| 1877 | uint8_t reserved[3]; |
| 1878 | } __ec_align4; |
| 1879 | |
| 1880 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 1881 | |
| 1882 | /** |
| 1883 | * Get information about the system, such as reset flags, locked state, etc. |
| 1884 | */ |
| 1885 | #define EC_CMD_SYSINFO 0x001C |
| 1886 | #define EC_VER_SYSINFO 0 |
| 1887 | |
| 1888 | enum sysinfo_flags { |
| 1889 | SYSTEM_IS_LOCKED = BIT(0), |
| 1890 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 1891 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 1892 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
| 1893 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4) |
| 1894 | }; |
| 1895 | |
| 1896 | struct ec_response_sysinfo { |
| 1897 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
| 1898 | uint32_t current_image; /**< enum ec_current_image */ |
| 1899 | uint32_t flags; /**< enum sysinfo_flags */ |
| 1900 | } __ec_align4; |
| 1901 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1902 | /*****************************************************************************/ |
| 1903 | /* PWM commands */ |
| 1904 | |
| 1905 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1906 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1907 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1908 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1909 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1910 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1911 | |
| 1912 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1913 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1914 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1915 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1916 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1917 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1918 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1919 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1920 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1921 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1922 | uint32_t rpm; |
| 1923 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1924 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1925 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1926 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1927 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1928 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1929 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1930 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1931 | uint8_t percent; |
| 1932 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1933 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1934 | |
| 1935 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1936 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1937 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1938 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1939 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1940 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1941 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1942 | |
| 1943 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1944 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1945 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1946 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1947 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1948 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1949 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1950 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1951 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1952 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1953 | uint32_t percent; |
| 1954 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1955 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1956 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1957 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1958 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1959 | #define EC_PWM_MAX_DUTY 0xffff |
| 1960 | |
| 1961 | enum ec_pwm_type { |
| 1962 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1963 | EC_PWM_TYPE_GENERIC = 0, |
| 1964 | /* Keyboard backlight */ |
| 1965 | EC_PWM_TYPE_KB_LIGHT, |
| 1966 | /* Display backlight */ |
| 1967 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1968 | EC_PWM_TYPE_COUNT, |
| 1969 | }; |
| 1970 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1971 | struct ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1972 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1973 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1974 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1975 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1976 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1977 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1978 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1979 | struct ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1980 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1981 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1982 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1983 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1984 | struct ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1985 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1986 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1987 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1988 | /*****************************************************************************/ |
| 1989 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1990 | * Lightbar commands. This looks worse than it is. Since we only use one HOST |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1991 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1992 | * into a subcommand. We'll make separate structs for subcommands with |
| 1993 | * different input args, so that we know how much to expect. |
| 1994 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1995 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1996 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1997 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1998 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1999 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2000 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2001 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2002 | |
| 2003 | /* |
| 2004 | * List of tweakable parameters. NOTE: It's __packed so it can be sent in a |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2005 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2006 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2007 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2008 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2009 | int32_t google_ramp_up; |
| 2010 | int32_t google_ramp_down; |
| 2011 | int32_t s3s0_ramp_up; |
| 2012 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2013 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2014 | int32_t s0s3_ramp_down; |
| 2015 | int32_t s3_sleep_for; |
| 2016 | int32_t s3_ramp_up; |
| 2017 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2018 | |
| 2019 | /* Oscillation */ |
| 2020 | uint8_t new_s0; |
| 2021 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2022 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2023 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2024 | |
| 2025 | /* Brightness limits based on the backlight and AC. */ |
| 2026 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2027 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2028 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2029 | |
| 2030 | /* Battery level thresholds */ |
| 2031 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2032 | |
| 2033 | /* Map [AC][battery_level] to color index */ |
| 2034 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2035 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2036 | |
| 2037 | /* Color palette */ |
| 2038 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2039 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2040 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2041 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2042 | /* Timing */ |
| 2043 | int32_t google_ramp_up; |
| 2044 | int32_t google_ramp_down; |
| 2045 | int32_t s3s0_ramp_up; |
| 2046 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2047 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2048 | int32_t s0s3_ramp_down; |
| 2049 | int32_t s3_sleep_for; |
| 2050 | int32_t s3_ramp_up; |
| 2051 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2052 | int32_t s5_ramp_up; |
| 2053 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2054 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2055 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2056 | int32_t tap_display_time; |
| 2057 | |
| 2058 | /* Tap-for-battery params */ |
| 2059 | uint8_t tap_pct_red; |
| 2060 | uint8_t tap_pct_green; |
| 2061 | uint8_t tap_seg_min_on; |
| 2062 | uint8_t tap_seg_max_on; |
| 2063 | uint8_t tap_seg_osc; |
| 2064 | uint8_t tap_idx[3]; |
| 2065 | |
| 2066 | /* Oscillation */ |
| 2067 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2068 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2069 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2070 | |
| 2071 | /* Brightness limits based on the backlight and AC. */ |
| 2072 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2073 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2074 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2075 | |
| 2076 | /* Battery level thresholds */ |
| 2077 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2078 | |
| 2079 | /* Map [AC][battery_level] to color index */ |
| 2080 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2081 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2082 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2083 | /* s5: single color pulse on inhibited power-up */ |
| 2084 | uint8_t s5_idx; |
| 2085 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2086 | /* Color palette */ |
| 2087 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2088 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2089 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2090 | /* Lightbar command params v2 |
| 2091 | * crbug.com/467716 |
| 2092 | * |
| 2093 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2094 | * logical groups to make it more manageable ( < 120 bytes). |
| 2095 | * |
| 2096 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2097 | */ |
| 2098 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2099 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2100 | /* Timing */ |
| 2101 | int32_t google_ramp_up; |
| 2102 | int32_t google_ramp_down; |
| 2103 | int32_t s3s0_ramp_up; |
| 2104 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2105 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2106 | int32_t s0s3_ramp_down; |
| 2107 | int32_t s3_sleep_for; |
| 2108 | int32_t s3_ramp_up; |
| 2109 | int32_t s3_ramp_down; |
| 2110 | int32_t s5_ramp_up; |
| 2111 | int32_t s5_ramp_down; |
| 2112 | int32_t tap_tick_delay; |
| 2113 | int32_t tap_gate_delay; |
| 2114 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2115 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2116 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2117 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2118 | /* Tap-for-battery params */ |
| 2119 | uint8_t tap_pct_red; |
| 2120 | uint8_t tap_pct_green; |
| 2121 | uint8_t tap_seg_min_on; |
| 2122 | uint8_t tap_seg_max_on; |
| 2123 | uint8_t tap_seg_osc; |
| 2124 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2125 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2126 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2127 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2128 | /* Oscillation */ |
| 2129 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2130 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2131 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2132 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2133 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2134 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2135 | /* Brightness limits based on the backlight and AC. */ |
| 2136 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2137 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2138 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2139 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2140 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2141 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2142 | /* Battery level thresholds */ |
| 2143 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2144 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2145 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2146 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2147 | /* Map [AC][battery_level] to color index */ |
| 2148 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2149 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2150 | |
| 2151 | /* s5: single color pulse on inhibited power-up */ |
| 2152 | uint8_t s5_idx; |
| 2153 | |
| 2154 | /* Color palette */ |
| 2155 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2156 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2157 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2158 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2159 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2160 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2161 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2162 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2163 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2164 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2165 | struct ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2166 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 2167 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2168 | /* |
| 2169 | * The following commands have no args: |
| 2170 | * |
| 2171 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2172 | * version, get_brightness, get_demo, suspend, resume, |
| 2173 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2174 | * get_params_v2_bright, get_params_v2_thlds, |
| 2175 | * get_params_v2_colors |
| 2176 | * |
| 2177 | * Don't use an empty struct, because C++ hates that. |
| 2178 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2179 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2180 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2181 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2182 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2183 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2184 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2185 | uint8_t ctrl, reg, value; |
| 2186 | } reg; |
| 2187 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2188 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2189 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2190 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2191 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2192 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2193 | uint8_t led; |
| 2194 | } get_rgb; |
| 2195 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2196 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2197 | uint8_t enable; |
| 2198 | } manual_suspend_ctrl; |
| 2199 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2200 | struct lightbar_params_v0 set_params_v0; |
| 2201 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2202 | |
| 2203 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2204 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2205 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2206 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2207 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2208 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2209 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2210 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2211 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2212 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2213 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2214 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2215 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2216 | struct __ec_todo_unpacked { |
| 2217 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2218 | uint8_t reg; |
| 2219 | uint8_t ic0; |
| 2220 | uint8_t ic1; |
| 2221 | } vals[23]; |
| 2222 | } dump; |
| 2223 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2224 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2225 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2226 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2227 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2228 | struct lightbar_params_v0 get_params_v0; |
| 2229 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2230 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2231 | |
| 2232 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2233 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2234 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2235 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2236 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2237 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2238 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2239 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2240 | uint32_t num; |
| 2241 | uint32_t flags; |
| 2242 | } version; |
| 2243 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2244 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2245 | uint8_t red, green, blue; |
| 2246 | } get_rgb; |
| 2247 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2248 | /* |
| 2249 | * The following commands have no response: |
| 2250 | * |
| 2251 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2252 | * set_params_v0, set_params_v1, set_program, |
| 2253 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2254 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2255 | * set_v2par_thlds, set_v2par_colors |
| 2256 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2257 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2258 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2259 | |
| 2260 | /* Lightbar commands */ |
| 2261 | enum lightbar_command { |
| 2262 | LIGHTBAR_CMD_DUMP = 0, |
| 2263 | LIGHTBAR_CMD_OFF = 1, |
| 2264 | LIGHTBAR_CMD_ON = 2, |
| 2265 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2266 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2267 | LIGHTBAR_CMD_SEQ = 5, |
| 2268 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2269 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2270 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2271 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2272 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2273 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2274 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2275 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2276 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2277 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2278 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2279 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2280 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2281 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2282 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2283 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2284 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2285 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2286 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2287 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2288 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2289 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2290 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2291 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2292 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2293 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2294 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2295 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2296 | LIGHTBAR_NUM_CMDS |
| 2297 | }; |
| 2298 | |
| 2299 | /*****************************************************************************/ |
| 2300 | /* LED control commands */ |
| 2301 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2302 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2303 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2304 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2305 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2306 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2307 | /* |
| 2308 | * LED to indicate system power state (on or in suspend). |
| 2309 | * May be on power button or on C-panel. |
| 2310 | */ |
| 2311 | EC_LED_ID_POWER_LED, |
| 2312 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2313 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2314 | /* LED to indicate left side */ |
| 2315 | EC_LED_ID_LEFT_LED, |
| 2316 | /* LED to indicate right side */ |
| 2317 | EC_LED_ID_RIGHT_LED, |
| 2318 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2319 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2320 | /* LED to indicate sysrq debug mode. */ |
| 2321 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2322 | |
| 2323 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2324 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2325 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2326 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2327 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
| 2328 | #define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2329 | |
| 2330 | enum ec_led_colors { |
| 2331 | EC_LED_COLOR_RED = 0, |
| 2332 | EC_LED_COLOR_GREEN, |
| 2333 | EC_LED_COLOR_BLUE, |
| 2334 | EC_LED_COLOR_YELLOW, |
| 2335 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2336 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2337 | |
| 2338 | EC_LED_COLOR_COUNT |
| 2339 | }; |
| 2340 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2341 | struct ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2342 | uint8_t led_id; /* Which LED to control */ |
| 2343 | uint8_t flags; /* Control flags */ |
| 2344 | |
| 2345 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2346 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2347 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2348 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2349 | /* |
| 2350 | * Available brightness value range. |
| 2351 | * |
| 2352 | * Range 0 means color channel not present. |
| 2353 | * Range 1 means on/off control. |
| 2354 | * Other values means the LED is control by PWM. |
| 2355 | */ |
| 2356 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2357 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2358 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2359 | /*****************************************************************************/ |
| 2360 | /* Verified boot commands */ |
| 2361 | |
| 2362 | /* |
| 2363 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2364 | * reused for other purposes with version > 0. |
| 2365 | */ |
| 2366 | |
| 2367 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2368 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2369 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2370 | struct ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2371 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2372 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2373 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2374 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2375 | uint32_t offset; /* Offset in flash to hash */ |
| 2376 | uint32_t size; /* Number of bytes to hash */ |
| 2377 | uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2378 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2379 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2380 | struct ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2381 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2382 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2383 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2384 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2385 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2386 | uint32_t size; /* Number of bytes hashed */ |
| 2387 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2388 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2389 | |
| 2390 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2391 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2392 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2393 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2394 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2395 | }; |
| 2396 | |
| 2397 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2398 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2399 | }; |
| 2400 | |
| 2401 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2402 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2403 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2404 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2405 | }; |
| 2406 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2407 | /* |
| 2408 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2409 | * If one of these is specified, the EC will automatically update offset and |
| 2410 | * size to the correct values for the specified image (RO or RW). |
| 2411 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2412 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2413 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2414 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
| 2415 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2416 | /* |
| 2417 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2418 | * so the old constant is deprecated. |
| 2419 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2420 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2421 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2422 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2423 | /* |
| 2424 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2425 | * different input args, so that we know how much to expect. |
| 2426 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2427 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2428 | |
| 2429 | /* Motion sense commands */ |
| 2430 | enum motionsense_command { |
| 2431 | /* |
| 2432 | * Dump command returns all motion sensor data including motion sense |
| 2433 | * module flags and individual sensor flags. |
| 2434 | */ |
| 2435 | MOTIONSENSE_CMD_DUMP = 0, |
| 2436 | |
| 2437 | /* |
| 2438 | * Info command returns data describing the details of a given sensor, |
| 2439 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2440 | * enum motionsensor_chip. |
| 2441 | */ |
| 2442 | MOTIONSENSE_CMD_INFO = 1, |
| 2443 | |
| 2444 | /* |
| 2445 | * EC Rate command is a setter/getter command for the EC sampling rate |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2446 | * in milliseconds. |
| 2447 | * It is per sensor, the EC run sample task at the minimum of all |
| 2448 | * sensors EC_RATE. |
| 2449 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2450 | * to collect all the sensor samples. |
| 2451 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2452 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2453 | */ |
| 2454 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2455 | |
| 2456 | /* |
| 2457 | * Sensor ODR command is a setter/getter command for the output data |
| 2458 | * rate of a specific motion sensor in millihertz. |
| 2459 | */ |
| 2460 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2461 | |
| 2462 | /* |
| 2463 | * Sensor range command is a setter/getter command for the range of |
| 2464 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2465 | */ |
| 2466 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2467 | |
| 2468 | /* |
| 2469 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2470 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2471 | * and when the lid angle goes less than this value, keyboard wake is |
| 2472 | * enabled. Note, the lid angle measurement is an approximate, |
| 2473 | * un-calibrated value, hence the wake angle isn't exact. |
| 2474 | */ |
| 2475 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2476 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2477 | /* |
| 2478 | * Returns a single sensor data. |
| 2479 | */ |
| 2480 | MOTIONSENSE_CMD_DATA = 6, |
| 2481 | |
| 2482 | /* |
| 2483 | * Return sensor fifo info. |
| 2484 | */ |
| 2485 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2486 | |
| 2487 | /* |
| 2488 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2489 | * The host can use that element to synchronize its operation. |
| 2490 | */ |
| 2491 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2492 | |
| 2493 | /* |
| 2494 | * Return a portion of the fifo. |
| 2495 | */ |
| 2496 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2497 | |
| 2498 | /* |
| 2499 | * Perform low level calibration. |
| 2500 | * On sensors that support it, ask to do offset calibration. |
| 2501 | */ |
| 2502 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2503 | |
| 2504 | /* |
| 2505 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2506 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2507 | * The offsets can be calculated by the host, or via |
| 2508 | * PERFORM_CALIB command. |
| 2509 | */ |
| 2510 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2511 | |
| 2512 | /* |
| 2513 | * List available activities for a MOTION sensor. |
| 2514 | * Indicates if they are enabled or disabled. |
| 2515 | */ |
| 2516 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2517 | |
| 2518 | /* |
| 2519 | * Activity management |
| 2520 | * Enable/Disable activity recognition. |
| 2521 | */ |
| 2522 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2523 | |
| 2524 | /* |
| 2525 | * Lid Angle |
| 2526 | */ |
| 2527 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2528 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2529 | /* |
| 2530 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2531 | * By default the FIFO does not send interrupt to process the FIFO |
| 2532 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2533 | */ |
| 2534 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2535 | |
| 2536 | /* |
| 2537 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2538 | * to arbitrary values, or will lock to the last read actual values. |
| 2539 | */ |
| 2540 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2541 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2542 | /* Set lid angle for tablet mode detection. */ |
| 2543 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2544 | |
| 2545 | /* |
| 2546 | * Sensor Scale command is a setter/getter command for the calibration |
| 2547 | * scale. |
| 2548 | */ |
| 2549 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2550 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2551 | /* |
| 2552 | * Read the current online calibration values (if available). |
| 2553 | */ |
| 2554 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2555 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2556 | /* Number of motionsense sub-commands. */ |
| 2557 | MOTIONSENSE_NUM_CMDS |
| 2558 | }; |
| 2559 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2560 | /* List of motion sensor types. */ |
| 2561 | enum motionsensor_type { |
| 2562 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2563 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2564 | MOTIONSENSE_TYPE_MAG = 2, |
| 2565 | MOTIONSENSE_TYPE_PROX = 3, |
| 2566 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2567 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2568 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2569 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2570 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2571 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2572 | }; |
| 2573 | |
| 2574 | /* List of motion sensor locations. */ |
| 2575 | enum motionsensor_location { |
| 2576 | MOTIONSENSE_LOC_BASE = 0, |
| 2577 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2578 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2579 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2580 | }; |
| 2581 | |
| 2582 | /* List of motion sensor chips. */ |
| 2583 | enum motionsensor_chip { |
| 2584 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2585 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2586 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2587 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2588 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2589 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2590 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2591 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2592 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2593 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2594 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2595 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2596 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2597 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2598 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2599 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2600 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2601 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2602 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2603 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2604 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2605 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2606 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2607 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2608 | MOTIONSENSE_CHIP_MAX, |
| 2609 | }; |
| 2610 | |
| 2611 | /* List of orientation positions */ |
| 2612 | enum motionsensor_orientation { |
| 2613 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2614 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2615 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2616 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2617 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2618 | }; |
| 2619 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2620 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2621 | /* Flags for each sensor. */ |
| 2622 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2623 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2624 | uint8_t sensor_num; |
| 2625 | /* Each sensor is up to 3-axis. */ |
| 2626 | union { |
| 2627 | int16_t data[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2628 | struct __ec_todo_packed { |
| 2629 | uint16_t reserved; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2630 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2631 | }; |
| 2632 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2633 | uint8_t activity; /* motionsensor_activity */ |
| 2634 | uint8_t state; |
| 2635 | int16_t add_info[2]; |
| 2636 | }; |
| 2637 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2638 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2639 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2640 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2641 | struct ec_response_online_calibration_data { |
| 2642 | /** The calibration values. */ |
| 2643 | int16_t data[3]; |
| 2644 | }; |
| 2645 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2646 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2647 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2648 | /* Size of the fifo */ |
| 2649 | uint16_t size; |
| 2650 | /* Amount of space used in the fifo */ |
| 2651 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2652 | /* Timestamp recorded in us. |
| 2653 | * aka accurate timestamp when host event was triggered. |
| 2654 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2655 | uint32_t timestamp; |
| 2656 | /* Total amount of vector lost */ |
| 2657 | uint16_t total_lost; |
| 2658 | /* Lost events since the last fifo_info, per sensors */ |
| 2659 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2660 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2661 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2662 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2663 | uint32_t number_data; |
| 2664 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2665 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2666 | |
| 2667 | /* List supported activity recognition */ |
| 2668 | enum motionsensor_activity { |
| 2669 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2670 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2671 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2672 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2673 | }; |
| 2674 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2675 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2676 | uint8_t sensor_num; |
| 2677 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2678 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2679 | uint8_t reserved; |
| 2680 | uint16_t parameters[3]; /* activity dependent parameters */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2681 | } __ec_todo_unpacked; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2682 | |
| 2683 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2684 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2685 | |
| 2686 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2687 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2688 | |
| 2689 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2690 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2691 | * data contains time stamp |
| 2692 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2693 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2694 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2695 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2696 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2697 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2698 | |
| 2699 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2700 | * Send this value for the data element to only perform a read. If you |
| 2701 | * send any other value, the EC will interpret it as data to set and will |
| 2702 | * return the actual value set. |
| 2703 | */ |
| 2704 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2705 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2706 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2707 | |
| 2708 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2709 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2710 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2711 | |
| 2712 | /* Default Scale value, factor 1. */ |
| 2713 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2714 | |
| 2715 | #define LID_ANGLE_UNRELIABLE 500 |
| 2716 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2717 | enum motionsense_spoof_mode { |
| 2718 | /* Disable spoof mode. */ |
| 2719 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2720 | |
| 2721 | /* Enable spoof mode, but use provided component values. */ |
| 2722 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2723 | |
| 2724 | /* Enable spoof mode, but use the current sensor values. */ |
| 2725 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2726 | |
| 2727 | /* Query the current spoof mode status for the sensor. */ |
| 2728 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2729 | }; |
| 2730 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2731 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2732 | uint8_t cmd; |
| 2733 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2734 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2735 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2736 | /* |
| 2737 | * Maximal number of sensor the host is expecting. |
| 2738 | * 0 means the host is only interested in the number |
| 2739 | * of sensors controlled by the EC. |
| 2740 | */ |
| 2741 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2742 | } dump; |
| 2743 | |
| 2744 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2745 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2746 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2747 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2748 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 2749 | * kb_wake_angle: angle to wakup AP. |
| 2750 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2751 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2752 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2753 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2754 | /* |
| 2755 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2756 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2757 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2758 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2759 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2760 | |
| 2761 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2762 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2763 | * Allow entering/exiting the calibration mode. |
| 2764 | */ |
| 2765 | struct __ec_todo_unpacked { |
| 2766 | uint8_t sensor_num; |
| 2767 | uint8_t enable; |
| 2768 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2769 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2770 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2771 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2772 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2773 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2774 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2775 | uint8_t sensor_num; |
| 2776 | |
| 2777 | /* Rounding flag, true for round-up, false for down. */ |
| 2778 | uint8_t roundup; |
| 2779 | |
| 2780 | uint16_t reserved; |
| 2781 | |
| 2782 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2783 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2784 | } ec_rate, sensor_odr, sensor_range; |
| 2785 | |
| 2786 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2787 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2788 | uint8_t sensor_num; |
| 2789 | |
| 2790 | /* |
| 2791 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2792 | * the calibration information in the EC. |
| 2793 | * If unset, just retrieve calibration information. |
| 2794 | */ |
| 2795 | uint16_t flags; |
| 2796 | |
| 2797 | /* |
| 2798 | * Temperature at calibration, in units of 0.01 C |
| 2799 | * 0x8000: invalid / unknown. |
| 2800 | * 0x0: 0C |
| 2801 | * 0x7fff: +327.67C |
| 2802 | */ |
| 2803 | int16_t temp; |
| 2804 | |
| 2805 | /* |
| 2806 | * Offset for calibration. |
| 2807 | * Unit: |
| 2808 | * Accelerometer: 1/1024 g |
| 2809 | * Gyro: 1/1024 deg/s |
| 2810 | * Compass: 1/16 uT |
| 2811 | */ |
| 2812 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2813 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2814 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2815 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2816 | struct __ec_todo_packed { |
| 2817 | uint8_t sensor_num; |
| 2818 | |
| 2819 | /* |
| 2820 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2821 | * the calibration information in the EC. |
| 2822 | * If unset, just retrieve calibration information. |
| 2823 | */ |
| 2824 | uint16_t flags; |
| 2825 | |
| 2826 | /* |
| 2827 | * Temperature at calibration, in units of 0.01 C |
| 2828 | * 0x8000: invalid / unknown. |
| 2829 | * 0x0: 0C |
| 2830 | * 0x7fff: +327.67C |
| 2831 | */ |
| 2832 | int16_t temp; |
| 2833 | |
| 2834 | /* |
| 2835 | * Scale for calibration: |
| 2836 | * By default scale is 1, it is encoded on 16bits: |
| 2837 | * 1 = BIT(15) |
| 2838 | * ~2 = 0xFFFF |
| 2839 | * ~0 = 0. |
| 2840 | */ |
| 2841 | uint16_t scale[3]; |
| 2842 | } sensor_scale; |
| 2843 | |
| 2844 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2845 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2846 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2847 | |
| 2848 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2849 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2850 | /* |
| 2851 | * Number of expected vector to return. |
| 2852 | * EC may return less or 0 if none available. |
| 2853 | */ |
| 2854 | uint32_t max_data_vector; |
| 2855 | } fifo_read; |
| 2856 | |
| 2857 | struct ec_motion_sense_activity set_activity; |
| 2858 | |
| 2859 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2860 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2861 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2862 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2863 | struct __ec_todo_unpacked { |
| 2864 | /* |
| 2865 | * 1: enable, 0 disable fifo, |
| 2866 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2867 | */ |
| 2868 | int8_t enable; |
| 2869 | } fifo_int_enable; |
| 2870 | |
| 2871 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2872 | struct __ec_todo_packed { |
| 2873 | uint8_t sensor_id; |
| 2874 | |
| 2875 | /* See enum motionsense_spoof_mode. */ |
| 2876 | uint8_t spoof_enable; |
| 2877 | |
| 2878 | /* Ignored, used for alignment. */ |
| 2879 | uint8_t reserved; |
| 2880 | |
| 2881 | /* Individual component values to spoof. */ |
| 2882 | int16_t components[3]; |
| 2883 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2884 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2885 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 2886 | struct __ec_todo_unpacked { |
| 2887 | /* |
| 2888 | * Lid angle threshold for switching between tablet and |
| 2889 | * clamshell mode. |
| 2890 | */ |
| 2891 | int16_t lid_angle; |
| 2892 | |
| 2893 | /* |
| 2894 | * Hysteresis degree to prevent fluctuations between |
| 2895 | * clamshell and tablet mode if lid angle keeps |
| 2896 | * changing around the threshold. Lid motion driver will |
| 2897 | * use lid_angle + hys_degree to trigger tablet mode and |
| 2898 | * lid_angle - hys_degree to trigger clamshell mode. |
| 2899 | */ |
| 2900 | int16_t hys_degree; |
| 2901 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 2902 | |
| 2903 | /* |
| 2904 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 2905 | * Allow reading a single sensor's online calibration value. |
| 2906 | */ |
| 2907 | struct __ec_todo_unpacked { |
| 2908 | uint8_t sensor_num; |
| 2909 | } online_calib_read; |
| 2910 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2911 | }; |
| 2912 | } __ec_todo_packed; |
| 2913 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 2914 | enum motion_sense_cmd_info_flags { |
| 2915 | /* The sensor supports online calibration */ |
| 2916 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 2917 | }; |
| 2918 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2919 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2920 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2921 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2922 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2923 | /* Flags representing the motion sensor module. */ |
| 2924 | uint8_t module_flags; |
| 2925 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2926 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2927 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2928 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2929 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2930 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2931 | * for holding all the data. |
| 2932 | */ |
| 2933 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2934 | } dump; |
| 2935 | |
| 2936 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2937 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2938 | /* Should be element of enum motionsensor_type. */ |
| 2939 | uint8_t type; |
| 2940 | |
| 2941 | /* Should be element of enum motionsensor_location. */ |
| 2942 | uint8_t location; |
| 2943 | |
| 2944 | /* Should be element of enum motionsensor_chip. */ |
| 2945 | uint8_t chip; |
| 2946 | } info; |
| 2947 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2948 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 2949 | struct __ec_todo_unpacked { |
| 2950 | /* Should be element of enum motionsensor_type. */ |
| 2951 | uint8_t type; |
| 2952 | |
| 2953 | /* Should be element of enum motionsensor_location. */ |
| 2954 | uint8_t location; |
| 2955 | |
| 2956 | /* Should be element of enum motionsensor_chip. */ |
| 2957 | uint8_t chip; |
| 2958 | |
| 2959 | /* Minimum sensor sampling frequency */ |
| 2960 | uint32_t min_frequency; |
| 2961 | |
| 2962 | /* Maximum sensor sampling frequency */ |
| 2963 | uint32_t max_frequency; |
| 2964 | |
| 2965 | /* Max number of sensor events that could be in fifo */ |
| 2966 | uint32_t fifo_max_event_count; |
| 2967 | } info_3; |
| 2968 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 2969 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 2970 | struct __ec_align4 { |
| 2971 | /* Should be element of enum motionsensor_type. */ |
| 2972 | uint8_t type; |
| 2973 | |
| 2974 | /* Should be element of enum motionsensor_location. */ |
| 2975 | uint8_t location; |
| 2976 | |
| 2977 | /* Should be element of enum motionsensor_chip. */ |
| 2978 | uint8_t chip; |
| 2979 | |
| 2980 | /* Minimum sensor sampling frequency */ |
| 2981 | uint32_t min_frequency; |
| 2982 | |
| 2983 | /* Maximum sensor sampling frequency */ |
| 2984 | uint32_t max_frequency; |
| 2985 | |
| 2986 | /* Max number of sensor events that could be in fifo */ |
| 2987 | uint32_t fifo_max_event_count; |
| 2988 | |
| 2989 | /* |
| 2990 | * Should be elements of |
| 2991 | * enum motion_sense_cmd_info_flags |
| 2992 | */ |
| 2993 | uint32_t flags; |
| 2994 | } info_4; |
| 2995 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2996 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 2997 | struct ec_response_motion_sensor_data data; |
| 2998 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2999 | /* |
| 3000 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3001 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3002 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3003 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3004 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3005 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3006 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3007 | /* Current value of the parameter queried. */ |
| 3008 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3009 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 3010 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3011 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3012 | /* |
| 3013 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3014 | * PERFORM_CALIB. |
| 3015 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3016 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3017 | int16_t temp; |
| 3018 | int16_t offset[3]; |
| 3019 | } sensor_offset, perform_calib; |
| 3020 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3021 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3022 | struct __ec_todo_unpacked { |
| 3023 | int16_t temp; |
| 3024 | uint16_t scale[3]; |
| 3025 | } sensor_scale; |
| 3026 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3027 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3028 | |
| 3029 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3030 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 3031 | struct ec_response_online_calibration_data online_calib_read; |
| 3032 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3033 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3034 | uint16_t reserved; |
| 3035 | uint32_t enabled; |
| 3036 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3037 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3038 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3039 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3040 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3041 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3042 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3043 | /* |
| 3044 | * Angle between 0 and 360 degree if available, |
| 3045 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3046 | */ |
| 3047 | uint16_t value; |
| 3048 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3049 | |
| 3050 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3051 | struct __ec_todo_unpacked { |
| 3052 | /* |
| 3053 | * Lid angle threshold for switching between tablet and |
| 3054 | * clamshell mode. |
| 3055 | */ |
| 3056 | uint16_t lid_angle; |
| 3057 | |
| 3058 | /* Hysteresis degree. */ |
| 3059 | uint16_t hys_degree; |
| 3060 | } tablet_mode_threshold; |
| 3061 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3062 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3063 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3064 | |
| 3065 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3066 | /* Force lid open command */ |
| 3067 | |
| 3068 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3069 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3070 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3071 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3072 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3073 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3074 | |
| 3075 | /*****************************************************************************/ |
| 3076 | /* Configure the behavior of the power button */ |
| 3077 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3078 | |
| 3079 | enum ec_config_power_button_flags { |
| 3080 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3081 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3082 | }; |
| 3083 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3084 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3085 | /* See enum ec_config_power_button_flags */ |
| 3086 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3087 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3088 | |
| 3089 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3090 | /* USB charging control commands */ |
| 3091 | |
| 3092 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3093 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3094 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3095 | enum usb_charge_mode { |
| 3096 | /* Disable USB port. */ |
| 3097 | USB_CHARGE_MODE_DISABLED, |
| 3098 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3099 | USB_CHARGE_MODE_SDP2, |
| 3100 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3101 | USB_CHARGE_MODE_CDP, |
| 3102 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3103 | USB_CHARGE_MODE_DCP_SHORT, |
| 3104 | /* Enable USB port (for dumb ports). */ |
| 3105 | USB_CHARGE_MODE_ENABLED, |
| 3106 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3107 | USB_CHARGE_MODE_DEFAULT, |
| 3108 | |
| 3109 | USB_CHARGE_MODE_COUNT |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3110 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3111 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3112 | enum usb_suspend_charge { |
| 3113 | /* Enable charging in suspend */ |
| 3114 | USB_ALLOW_SUSPEND_CHARGE, |
| 3115 | /* Disable charging in suspend */ |
| 3116 | USB_DISALLOW_SUSPEND_CHARGE |
| 3117 | }; |
| 3118 | |
| 3119 | struct ec_params_usb_charge_set_mode { |
| 3120 | uint8_t usb_port_id; |
| 3121 | uint8_t mode:7; /* enum usb_charge_mode */ |
| 3122 | uint8_t inhibit_charge:1; /* enum usb_suspend_charge */ |
| 3123 | } __ec_align1; |
| 3124 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3125 | /*****************************************************************************/ |
| 3126 | /* Persistent storage for host */ |
| 3127 | |
| 3128 | /* Maximum bytes that can be read/written in a single command */ |
| 3129 | #define EC_PSTORE_SIZE_MAX 64 |
| 3130 | |
| 3131 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3132 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3133 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3134 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3135 | /* Persistent storage size, in bytes */ |
| 3136 | uint32_t pstore_size; |
| 3137 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3138 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3139 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3140 | |
| 3141 | /* |
| 3142 | * Read persistent storage |
| 3143 | * |
| 3144 | * Response is params.size bytes of data. |
| 3145 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3146 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3147 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3148 | struct ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3149 | uint32_t offset; /* Byte offset to read */ |
| 3150 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3151 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3152 | |
| 3153 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3154 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3155 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3156 | struct ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3157 | uint32_t offset; /* Byte offset to write */ |
| 3158 | uint32_t size; /* Size to write in bytes */ |
| 3159 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3160 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3161 | |
| 3162 | /*****************************************************************************/ |
| 3163 | /* Real-time clock */ |
| 3164 | |
| 3165 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3166 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3167 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3168 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3169 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3170 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3171 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3172 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3173 | |
| 3174 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3175 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3176 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3177 | |
| 3178 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3179 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3180 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3181 | |
| 3182 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3183 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3184 | |
| 3185 | /*****************************************************************************/ |
| 3186 | /* Port80 log access */ |
| 3187 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3188 | /* Maximum entries that can be read/written in a single command */ |
| 3189 | #define EC_PORT80_SIZE_MAX 32 |
| 3190 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3191 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3192 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3193 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3194 | |
| 3195 | enum ec_port80_subcmd { |
| 3196 | EC_PORT80_GET_INFO = 0, |
| 3197 | EC_PORT80_READ_BUFFER, |
| 3198 | }; |
| 3199 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3200 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3201 | uint16_t subcmd; |
| 3202 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3203 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3204 | uint32_t offset; |
| 3205 | uint32_t num_entries; |
| 3206 | } read_buffer; |
| 3207 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3208 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3209 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3210 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3211 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3212 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3213 | uint32_t writes; |
| 3214 | uint32_t history_size; |
| 3215 | uint32_t last_boot; |
| 3216 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3217 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3218 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3219 | } data; |
| 3220 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3221 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3222 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3223 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3224 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3225 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3226 | |
| 3227 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3228 | /* Temporary secure storage for host verified boot use */ |
| 3229 | |
| 3230 | /* Number of bytes in a vstore slot */ |
| 3231 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3232 | |
| 3233 | /* Maximum number of vstore slots */ |
| 3234 | #define EC_VSTORE_SLOT_MAX 32 |
| 3235 | |
| 3236 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3237 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3238 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3239 | /* Indicates which slots are locked */ |
| 3240 | uint32_t slot_locked; |
| 3241 | /* Total number of slots available */ |
| 3242 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3243 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3244 | |
| 3245 | /* |
| 3246 | * Read temporary secure storage |
| 3247 | * |
| 3248 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3249 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3250 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3251 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3252 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3253 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3254 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3255 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3256 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3257 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3258 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3259 | |
| 3260 | /* |
| 3261 | * Write temporary secure storage and lock it. |
| 3262 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3263 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3265 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3266 | uint8_t slot; /* Slot to write to */ |
| 3267 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3268 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3269 | |
| 3270 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3271 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3272 | * reuse the command number, but the data and behavior is incompatible. |
| 3273 | * Version 0 is what originally shipped on Link. |
| 3274 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3275 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3276 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3277 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3278 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3279 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3280 | /* The version 0 structs are opaque. You have to know what they are for |
| 3281 | * the get/set commands to make any sense. |
| 3282 | */ |
| 3283 | |
| 3284 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3285 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3286 | uint8_t sensor_type; |
| 3287 | uint8_t threshold_id; |
| 3288 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3289 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3290 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3291 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3292 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3293 | uint8_t sensor_type; |
| 3294 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3295 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3296 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3297 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3298 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3299 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3300 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3301 | |
| 3302 | /* The version 1 structs are visible. */ |
| 3303 | enum ec_temp_thresholds { |
| 3304 | EC_TEMP_THRESH_WARN = 0, |
| 3305 | EC_TEMP_THRESH_HIGH, |
| 3306 | EC_TEMP_THRESH_HALT, |
| 3307 | |
| 3308 | EC_TEMP_THRESH_COUNT |
| 3309 | }; |
| 3310 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3311 | /* |
| 3312 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3313 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3314 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3315 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3316 | * hysteresis. |
| 3317 | * For example, |
| 3318 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3319 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3320 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3321 | * temperature <= 299 K. |
| 3322 | * |
| 3323 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3324 | * For example, |
| 3325 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3326 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3327 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3328 | * temperature <= 294 K. |
| 3329 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3330 | * Note that this structure is a sub-structure of |
| 3331 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3332 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3333 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3334 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3335 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3336 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3337 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3338 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3339 | |
| 3340 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3341 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3342 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3343 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3344 | /* This returns a struct ec_thermal_config */ |
| 3345 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3346 | /* |
| 3347 | * Version 1 - set config for one sensor. |
| 3348 | * Use read-modify-write for best results! |
| 3349 | */ |
| 3350 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3351 | uint32_t sensor_num; |
| 3352 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3353 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3354 | /* This returns no data */ |
| 3355 | |
| 3356 | /****************************************************************************/ |
| 3357 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3358 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3359 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3360 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3361 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3362 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3363 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3364 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3365 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3366 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3367 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3368 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3369 | |
| 3370 | /* |
| 3371 | * The original TMP006 calibration only needed four params, but now we need |
| 3372 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3373 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3374 | * and how many params it requires. That way we can change the EC code without |
| 3375 | * needing to update this file. We can also use a different algorithm on each |
| 3376 | * sensor. |
| 3377 | */ |
| 3378 | |
| 3379 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3380 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3381 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3382 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3383 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3384 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3385 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3386 | float s0; |
| 3387 | float b0; |
| 3388 | float b1; |
| 3389 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3390 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3391 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3392 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3393 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3394 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3395 | float s0; |
| 3396 | float b0; |
| 3397 | float b1; |
| 3398 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3399 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3400 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3401 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3402 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3403 | uint8_t algorithm; |
| 3404 | uint8_t num_params; |
| 3405 | uint8_t reserved[2]; |
| 3406 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3407 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3408 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3409 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3410 | uint8_t index; |
| 3411 | uint8_t algorithm; |
| 3412 | uint8_t num_params; |
| 3413 | uint8_t reserved; |
| 3414 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3415 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3416 | |
| 3417 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3418 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3419 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3420 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3421 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3422 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3423 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3424 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3425 | struct ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3426 | int32_t t; /* In 1/100 K */ |
| 3427 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3428 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3429 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3430 | /*****************************************************************************/ |
| 3431 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3432 | |
| 3433 | /* |
| 3434 | * Read key state |
| 3435 | * |
| 3436 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3437 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3438 | * |
| 3439 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3440 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3441 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3442 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3443 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3444 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3445 | /* |
| 3446 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3447 | */ |
| 3448 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3449 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3450 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3451 | uint32_t rows; |
| 3452 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3453 | /* Formerly "switches", which was 0. */ |
| 3454 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3455 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3456 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3457 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3458 | uint8_t info_type; |
| 3459 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3460 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3461 | |
| 3462 | enum ec_mkbp_info_type { |
| 3463 | /* |
| 3464 | * Info about the keyboard matrix: number of rows and columns. |
| 3465 | * |
| 3466 | * Returns struct ec_response_mkbp_info. |
| 3467 | */ |
| 3468 | EC_MKBP_INFO_KBD = 0, |
| 3469 | |
| 3470 | /* |
| 3471 | * For buttons and switches, info about which specifically are |
| 3472 | * supported. event_type must be set to one of the values in enum |
| 3473 | * ec_mkbp_event. |
| 3474 | * |
| 3475 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3476 | * bitmask indicating which buttons or switches are present. See the |
| 3477 | * bit inidices below. |
| 3478 | */ |
| 3479 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3480 | |
| 3481 | /* |
| 3482 | * Instantaneous state of buttons and switches. |
| 3483 | * |
| 3484 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3485 | * |
| 3486 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3487 | * indicating the current state of the keyboard matrix. |
| 3488 | * |
| 3489 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3490 | * event state. |
| 3491 | * |
| 3492 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3493 | * state of supported buttons. |
| 3494 | * |
| 3495 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3496 | * state of supported switches. |
| 3497 | */ |
| 3498 | EC_MKBP_INFO_CURRENT = 2, |
| 3499 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3500 | |
| 3501 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3502 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3503 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3504 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3505 | uint8_t col; |
| 3506 | uint8_t row; |
| 3507 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3508 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3509 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3510 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3511 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3512 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3513 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3514 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3515 | |
| 3516 | enum keyboard_id { |
| 3517 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3518 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3519 | }; |
| 3520 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3521 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3522 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3523 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3524 | |
| 3525 | /* flags */ |
| 3526 | enum mkbp_config_flags { |
| 3527 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 3528 | }; |
| 3529 | |
| 3530 | enum mkbp_config_valid { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3531 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3532 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3533 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3534 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3535 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3536 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3537 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3538 | }; |
| 3539 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3540 | /* |
| 3541 | * Configuration for our key scanning algorithm. |
| 3542 | * |
| 3543 | * Note that this is used as a sub-structure of |
| 3544 | * ec_{params/response}_mkbp_get_config. |
| 3545 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3546 | struct ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3547 | uint32_t valid_mask; /* valid fields */ |
| 3548 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3549 | uint8_t valid_flags; /* which flags are valid */ |
| 3550 | uint16_t scan_period_us; /* period between start of scans */ |
| 3551 | /* revert to interrupt mode after no activity for this long */ |
| 3552 | uint32_t poll_timeout_us; |
| 3553 | /* |
| 3554 | * minimum post-scan relax time. Once we finish a scan we check |
| 3555 | * the time until we are due to start the next one. If this time is |
| 3556 | * shorter this field, we use this instead. |
| 3557 | */ |
| 3558 | uint16_t min_post_scan_delay_us; |
| 3559 | /* delay between setting up output and waiting for it to settle */ |
| 3560 | uint16_t output_settle_us; |
| 3561 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3562 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 3563 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3564 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3565 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3566 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3567 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3568 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3569 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3570 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3571 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3572 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3573 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3574 | |
| 3575 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3576 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3577 | |
| 3578 | enum ec_keyscan_seq_cmd { |
| 3579 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3580 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3581 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3582 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3583 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 3584 | }; |
| 3585 | |
| 3586 | enum ec_collect_flags { |
| 3587 | /* |
| 3588 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3589 | * scans may be skipped. |
| 3590 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3591 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3592 | }; |
| 3593 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3594 | struct ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3595 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3596 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3597 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3598 | struct ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3599 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 3600 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3601 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3602 | uint8_t active; /* still active */ |
| 3603 | uint8_t num_items; /* number of items */ |
| 3604 | /* Current item being presented */ |
| 3605 | uint8_t cur_item; |
| 3606 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3607 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3608 | /* |
| 3609 | * Absolute time for this scan, measured from the |
| 3610 | * start of the sequence. |
| 3611 | */ |
| 3612 | uint32_t time_us; |
| 3613 | uint8_t scan[0]; /* keyscan data */ |
| 3614 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3615 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3616 | uint8_t start_item; /* First item to return */ |
| 3617 | uint8_t num_items; /* Number of items to return */ |
| 3618 | } collect; |
| 3619 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3620 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3621 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3622 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3623 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3624 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3625 | uint8_t num_items; /* Number of items */ |
| 3626 | /* Data for each item */ |
| 3627 | struct ec_collect_item item[0]; |
| 3628 | } collect; |
| 3629 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3630 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3631 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3632 | /* |
| 3633 | * Get the next pending MKBP event. |
| 3634 | * |
| 3635 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3636 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3637 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3638 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3639 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3640 | |
| 3641 | /* |
| 3642 | * We use the most significant bit of the event type to indicate to the host |
| 3643 | * that the EC has more MKBP events available to provide. |
| 3644 | */ |
| 3645 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3646 | |
| 3647 | /* The mask to apply to get the raw event type */ |
| 3648 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3649 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3650 | enum ec_mkbp_event { |
| 3651 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3652 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3653 | |
| 3654 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3655 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3656 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3657 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3658 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3659 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3660 | /* The state of the non-matrixed buttons have changed. */ |
| 3661 | EC_MKBP_EVENT_BUTTON = 3, |
| 3662 | |
| 3663 | /* The state of the switches have changed. */ |
| 3664 | EC_MKBP_EVENT_SWITCH = 4, |
| 3665 | |
| 3666 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3667 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3668 | |
| 3669 | /* |
| 3670 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3671 | * corresponding to the key to be pressed. |
| 3672 | */ |
| 3673 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3674 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3675 | /* |
| 3676 | * New 64-bit host event. |
| 3677 | * The event data is 8 bytes of host event flags. |
| 3678 | */ |
| 3679 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3680 | |
| 3681 | /* Notify the AP that something happened on CEC */ |
| 3682 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3683 | |
| 3684 | /* Send an incoming CEC message to the AP */ |
| 3685 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3686 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3687 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3688 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3689 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 3690 | /* New online calibration values are available. */ |
| 3691 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3692 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3693 | /* Number of MKBP events */ |
| 3694 | EC_MKBP_EVENT_COUNT, |
| 3695 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3696 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3697 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3698 | union __ec_align_offset1 ec_response_get_next_data { |
| 3699 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3700 | |
| 3701 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3702 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3703 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3704 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3705 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3706 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3707 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3708 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3709 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3710 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3711 | uint32_t buttons; |
| 3712 | |
| 3713 | uint32_t switches; |
| 3714 | |
| 3715 | uint32_t fp_events; |
| 3716 | |
| 3717 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3718 | |
| 3719 | /* CEC events from enum mkbp_cec_event */ |
| 3720 | uint32_t cec_events; |
| 3721 | }; |
| 3722 | |
| 3723 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3724 | uint8_t key_matrix[16]; |
| 3725 | |
| 3726 | /* Unaligned */ |
| 3727 | uint32_t host_event; |
| 3728 | uint64_t host_event64; |
| 3729 | |
| 3730 | struct __ec_todo_unpacked { |
| 3731 | /* For aligning the fifo_info */ |
| 3732 | uint8_t reserved[3]; |
| 3733 | struct ec_response_motion_sense_fifo_info info; |
| 3734 | } sensor_fifo; |
| 3735 | |
| 3736 | uint32_t buttons; |
| 3737 | |
| 3738 | uint32_t switches; |
| 3739 | |
| 3740 | uint32_t fp_events; |
| 3741 | |
| 3742 | uint32_t sysrq; |
| 3743 | |
| 3744 | /* CEC events from enum mkbp_cec_event */ |
| 3745 | uint32_t cec_events; |
| 3746 | |
| 3747 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3748 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3749 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3750 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3751 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3752 | uint8_t event_type; |
| 3753 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3754 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3755 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3756 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3757 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3758 | uint8_t event_type; |
| 3759 | /* Followed by event data if any */ |
| 3760 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3761 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3762 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3763 | /* Bit indices for buttons and switches.*/ |
| 3764 | /* Buttons */ |
| 3765 | #define EC_MKBP_POWER_BUTTON 0 |
| 3766 | #define EC_MKBP_VOL_UP 1 |
| 3767 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 3768 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3769 | |
| 3770 | /* Switches */ |
| 3771 | #define EC_MKBP_LID_OPEN 0 |
| 3772 | #define EC_MKBP_TABLET_MODE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3773 | #define EC_MKBP_BASE_ATTACHED 2 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3774 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3775 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3776 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3777 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3778 | struct ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3779 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3780 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3781 | |
| 3782 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3783 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3784 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) |
| 3785 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
| 3786 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ |
| 3787 | >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
| 3788 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 3789 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
| 3790 | #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ |
| 3791 | >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3792 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 3793 | #define EC_MKBP_FP_MATCH BIT(28) |
| 3794 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 3795 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 3796 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3797 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
| 3798 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 3799 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 3800 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 3801 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 3802 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
| 3803 | /* Can be used to detect if image was usable for enrollment or not. */ |
| 3804 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
| 3805 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
| 3806 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 3807 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3808 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3809 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 3810 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 3811 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 3812 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
| 3813 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 3814 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3815 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3816 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 3817 | enum ec_mkbp_event_mask_action { |
| 3818 | /* Retrieve the value of a wake mask. */ |
| 3819 | GET_WAKE_MASK = 0, |
| 3820 | |
| 3821 | /* Set the value of a wake mask. */ |
| 3822 | SET_WAKE_MASK, |
| 3823 | }; |
| 3824 | |
| 3825 | enum ec_mkbp_mask_type { |
| 3826 | /* |
| 3827 | * These are host events sent via MKBP. |
| 3828 | * |
| 3829 | * Some examples are: |
| 3830 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 3831 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 3832 | * |
| 3833 | * The only things that should be in this mask are: |
| 3834 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 3835 | */ |
| 3836 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 3837 | |
| 3838 | /* |
| 3839 | * These are MKBP events. Some examples are: |
| 3840 | * |
| 3841 | * EC_MKBP_EVENT_KEY_MATRIX |
| 3842 | * EC_MKBP_EVENT_SWITCH |
| 3843 | * |
| 3844 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 3845 | */ |
| 3846 | EC_MKBP_EVENT_WAKE_MASK, |
| 3847 | }; |
| 3848 | |
| 3849 | struct ec_params_mkbp_event_wake_mask { |
| 3850 | /* One of enum ec_mkbp_event_mask_action */ |
| 3851 | uint8_t action; |
| 3852 | |
| 3853 | /* |
| 3854 | * Which MKBP mask are you interested in acting upon? This is one of |
| 3855 | * ec_mkbp_mask_type. |
| 3856 | */ |
| 3857 | uint8_t mask_type; |
| 3858 | |
| 3859 | /* If setting a new wake mask, this contains the mask to set. */ |
| 3860 | uint32_t new_wake_mask; |
| 3861 | }; |
| 3862 | |
| 3863 | struct ec_response_mkbp_event_wake_mask { |
| 3864 | uint32_t wake_mask; |
| 3865 | }; |
| 3866 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3867 | /*****************************************************************************/ |
| 3868 | /* Temperature sensor commands */ |
| 3869 | |
| 3870 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3871 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3872 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3873 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3874 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3875 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3876 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3877 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3878 | char sensor_name[32]; |
| 3879 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3880 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3881 | |
| 3882 | /*****************************************************************************/ |
| 3883 | |
| 3884 | /* |
| 3885 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 3886 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 3887 | * below. |
| 3888 | */ |
| 3889 | |
| 3890 | /*****************************************************************************/ |
| 3891 | /* Host event commands */ |
| 3892 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3893 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3894 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3895 | /* |
| 3896 | * Host event mask params and response structures, shared by all of the host |
| 3897 | * event commands below. |
| 3898 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3899 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3900 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3901 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3902 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3903 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3904 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3905 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3906 | |
| 3907 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3908 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 3909 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 3910 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 3911 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3912 | |
| 3913 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3914 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 3915 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 3916 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 3917 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 3918 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3919 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3920 | /* |
| 3921 | * Unified host event programming interface - Should be used by newer versions |
| 3922 | * of BIOS/OS to program host events and masks |
| 3923 | */ |
| 3924 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3925 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3926 | |
| 3927 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 3928 | uint8_t action; |
| 3929 | |
| 3930 | /* |
| 3931 | * Mask type that the host requested the action on - one of |
| 3932 | * enum ec_host_event_mask_type. |
| 3933 | */ |
| 3934 | uint8_t mask_type; |
| 3935 | |
| 3936 | /* Set to 0, ignore on read */ |
| 3937 | uint16_t reserved; |
| 3938 | |
| 3939 | /* Value to be used in case of set operations. */ |
| 3940 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3941 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3942 | |
| 3943 | /* |
| 3944 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 3945 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 3946 | */ |
| 3947 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3948 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3949 | |
| 3950 | /* Mask value in case of get operation */ |
| 3951 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3952 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3953 | |
| 3954 | enum ec_host_event_action { |
| 3955 | /* |
| 3956 | * params.value is ignored. Value of mask_type populated |
| 3957 | * in response.value |
| 3958 | */ |
| 3959 | EC_HOST_EVENT_GET, |
| 3960 | |
| 3961 | /* Bits in params.value are set */ |
| 3962 | EC_HOST_EVENT_SET, |
| 3963 | |
| 3964 | /* Bits in params.value are cleared */ |
| 3965 | EC_HOST_EVENT_CLEAR, |
| 3966 | }; |
| 3967 | |
| 3968 | enum ec_host_event_mask_type { |
| 3969 | |
| 3970 | /* Main host event copy */ |
| 3971 | EC_HOST_EVENT_MAIN, |
| 3972 | |
| 3973 | /* Copy B of host events */ |
| 3974 | EC_HOST_EVENT_B, |
| 3975 | |
| 3976 | /* SCI Mask */ |
| 3977 | EC_HOST_EVENT_SCI_MASK, |
| 3978 | |
| 3979 | /* SMI Mask */ |
| 3980 | EC_HOST_EVENT_SMI_MASK, |
| 3981 | |
| 3982 | /* Mask of events that should be always reported in hostevents */ |
| 3983 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 3984 | |
| 3985 | /* Active wake mask */ |
| 3986 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 3987 | |
| 3988 | /* Lazy wake mask for S0ix */ |
| 3989 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 3990 | |
| 3991 | /* Lazy wake mask for S3 */ |
| 3992 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 3993 | |
| 3994 | /* Lazy wake mask for S5 */ |
| 3995 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 3996 | }; |
| 3997 | |
| 3998 | #define EC_CMD_HOST_EVENT 0x00A4 |
| 3999 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4000 | /*****************************************************************************/ |
| 4001 | /* Switch commands */ |
| 4002 | |
| 4003 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4004 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4005 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4006 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4007 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4008 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4009 | |
| 4010 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4011 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4012 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4013 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4014 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4015 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4016 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4017 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4018 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4019 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4020 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4021 | /* Flags to enable now */ |
| 4022 | uint8_t now_flags; |
| 4023 | |
| 4024 | /* Which flags to copy from now_flags */ |
| 4025 | uint8_t now_mask; |
| 4026 | |
| 4027 | /* |
| 4028 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4029 | * transition. (Other flags will be disabled by the S0->S3 |
| 4030 | * transition.) |
| 4031 | */ |
| 4032 | uint8_t suspend_flags; |
| 4033 | |
| 4034 | /* Which flags to copy from suspend_flags */ |
| 4035 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4036 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4037 | |
| 4038 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4039 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4040 | /* Flags to enable now */ |
| 4041 | uint8_t now_flags; |
| 4042 | |
| 4043 | /* Flags to leave enabled in S3 */ |
| 4044 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4045 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4046 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4047 | /*****************************************************************************/ |
| 4048 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4049 | |
| 4050 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4051 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4053 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4054 | char name[32]; |
| 4055 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4056 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4057 | |
| 4058 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4059 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4060 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4061 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4062 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4063 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4064 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4065 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4066 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4067 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4068 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4069 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4070 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4071 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4072 | uint8_t subcmd; |
| 4073 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4074 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4075 | char name[32]; |
| 4076 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4077 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4078 | uint8_t index; |
| 4079 | } get_info; |
| 4080 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4081 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4082 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4083 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4084 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4085 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4086 | uint8_t val; |
| 4087 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4088 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4089 | uint8_t val; |
| 4090 | char name[32]; |
| 4091 | uint32_t flags; |
| 4092 | } get_info; |
| 4093 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4094 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4095 | |
| 4096 | enum gpio_get_subcmd { |
| 4097 | EC_GPIO_GET_BY_NAME = 0, |
| 4098 | EC_GPIO_GET_COUNT = 1, |
| 4099 | EC_GPIO_GET_INFO = 2, |
| 4100 | }; |
| 4101 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4102 | /*****************************************************************************/ |
| 4103 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4104 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4105 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4106 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4107 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4108 | * |
| 4109 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4110 | */ |
| 4111 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4112 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4113 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4114 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4115 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4116 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4117 | uint8_t read_size; /* Either 8 or 16. */ |
| 4118 | uint8_t port; |
| 4119 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4120 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4121 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4122 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4123 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4124 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4125 | |
| 4126 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4127 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4128 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4129 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4130 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4131 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4132 | uint8_t write_size; /* Either 8 or 16. */ |
| 4133 | uint8_t port; |
| 4134 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4135 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4136 | |
| 4137 | /*****************************************************************************/ |
| 4138 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4139 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4140 | /* Force charge state machine to stop charging the battery or force it to |
| 4141 | * discharge the battery. |
| 4142 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4143 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4144 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4145 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4146 | enum ec_charge_control_mode { |
| 4147 | CHARGE_CONTROL_NORMAL = 0, |
| 4148 | CHARGE_CONTROL_IDLE, |
| 4149 | CHARGE_CONTROL_DISCHARGE, |
| 4150 | }; |
| 4151 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4152 | struct ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4153 | uint32_t mode; /* enum charge_control_mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4154 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4155 | |
| 4156 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4157 | |
| 4158 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4159 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4160 | |
| 4161 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4162 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4163 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4164 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4165 | * end of the previous snapshot. |
| 4166 | * |
| 4167 | * The params are only looked at in version >= 1 of this command. Prior |
| 4168 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4169 | * |
| 4170 | * Response is null-terminated string. Empty string, if there is no more |
| 4171 | * remaining output. |
| 4172 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4173 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4174 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4175 | enum ec_console_read_subcmd { |
| 4176 | CONSOLE_READ_NEXT = 0, |
| 4177 | CONSOLE_READ_RECENT |
| 4178 | }; |
| 4179 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4180 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4181 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4182 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4183 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4184 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4185 | |
| 4186 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4187 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4188 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4189 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4190 | * EC_RES_SUCCESS if the command was successful. |
| 4191 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4192 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4193 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4194 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4195 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4196 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4197 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4198 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4199 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4200 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4201 | /*****************************************************************************/ |
| 4202 | /* USB port mux control. */ |
| 4203 | |
| 4204 | /* |
| 4205 | * Switch USB mux or return to automatic switching. |
| 4206 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4207 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4208 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4209 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4210 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4211 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4212 | |
| 4213 | /*****************************************************************************/ |
| 4214 | /* LDOs / FETs control. */ |
| 4215 | |
| 4216 | enum ec_ldo_state { |
| 4217 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4218 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 4219 | }; |
| 4220 | |
| 4221 | /* |
| 4222 | * Switch on/off a LDO. |
| 4223 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4224 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4225 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4226 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4227 | uint8_t index; |
| 4228 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4229 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4230 | |
| 4231 | /* |
| 4232 | * Get LDO state. |
| 4233 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4234 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4235 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4236 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4237 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4238 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4239 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4240 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4241 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4242 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4243 | |
| 4244 | /*****************************************************************************/ |
| 4245 | /* Power info. */ |
| 4246 | |
| 4247 | /* |
| 4248 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4249 | * |
| 4250 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4251 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4252 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4253 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4254 | /* |
| 4255 | * v1 of EC_CMD_POWER_INFO |
| 4256 | */ |
| 4257 | enum system_power_source { |
| 4258 | /* |
| 4259 | * Haven't established which power source is used yet, |
| 4260 | * or no presence signals are available |
| 4261 | */ |
| 4262 | POWER_SOURCE_UNKNOWN = 0, |
| 4263 | /* System is running on battery alone */ |
| 4264 | POWER_SOURCE_BATTERY = 1, |
| 4265 | /* System is running on A/C alone */ |
| 4266 | POWER_SOURCE_AC = 2, |
| 4267 | /* System is running on A/C and battery */ |
| 4268 | POWER_SOURCE_AC_BATTERY = 3, |
| 4269 | }; |
| 4270 | |
| 4271 | struct ec_response_power_info_v1 { |
| 4272 | /* enum system_power_source */ |
| 4273 | uint8_t system_power_source; |
| 4274 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4275 | uint8_t battery_soc; |
| 4276 | /* AC Adapter 100% rating, Watts */ |
| 4277 | uint8_t ac_adapter_100pct; |
| 4278 | /* AC Adapter 10ms rating, Watts */ |
| 4279 | uint8_t ac_adapter_10ms; |
| 4280 | /* Battery 1C rating, derated */ |
| 4281 | uint8_t battery_1cd; |
| 4282 | /* Rest of Platform average, Watts */ |
| 4283 | uint8_t rop_avg; |
| 4284 | /* Rest of Platform peak, Watts */ |
| 4285 | uint8_t rop_peak; |
| 4286 | /* Nominal charger efficiency, % */ |
| 4287 | uint8_t nominal_charger_eff; |
| 4288 | /* Rest of Platform VR Average Efficiency, % */ |
| 4289 | uint8_t rop_avg_eff; |
| 4290 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4291 | uint8_t rop_peak_eff; |
| 4292 | /* SoC VR Efficiency at Average level, % */ |
| 4293 | uint8_t soc_avg_eff; |
| 4294 | /* SoC VR Efficiency at Peak level, % */ |
| 4295 | uint8_t soc_peak_eff; |
| 4296 | /* Intel-specific items */ |
| 4297 | struct { |
| 4298 | /* Battery's level of DBPT support: 0, 2 */ |
| 4299 | uint8_t batt_dbpt_support_level; |
| 4300 | /* |
| 4301 | * Maximum peak power from battery (10ms), Watts |
| 4302 | * If DBPT is not supported, this is 0 |
| 4303 | */ |
| 4304 | uint8_t batt_dbpt_max_peak_power; |
| 4305 | /* |
| 4306 | * Sustained peak power from battery, Watts |
| 4307 | * If DBPT is not supported, this is 0 |
| 4308 | */ |
| 4309 | uint8_t batt_dbpt_sus_peak_power; |
| 4310 | } intel; |
| 4311 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4312 | |
| 4313 | /*****************************************************************************/ |
| 4314 | /* I2C passthru command */ |
| 4315 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4316 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4317 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4318 | /* Read data; if not present, message is a write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4319 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4320 | |
| 4321 | /* Mask for address */ |
| 4322 | #define EC_I2C_ADDR_MASK 0x3ff |
| 4323 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4324 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4325 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4326 | |
| 4327 | /* Any error */ |
| 4328 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 4329 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4330 | struct ec_params_i2c_passthru_msg { |
| 4331 | uint16_t addr_flags; /* I2C slave address and flags */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4332 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4333 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4334 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4335 | struct ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4336 | uint8_t port; /* I2C port number */ |
| 4337 | uint8_t num_msgs; /* Number of messages */ |
| 4338 | struct ec_params_i2c_passthru_msg msg[]; |
| 4339 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4340 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4341 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4342 | struct ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4343 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4344 | uint8_t num_msgs; /* Number of messages processed */ |
| 4345 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4346 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4347 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4348 | /*****************************************************************************/ |
| 4349 | /* Power button hang detect */ |
| 4350 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4351 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4352 | |
| 4353 | /* Reasons to start hang detection timer */ |
| 4354 | /* Power button pressed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4355 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4356 | |
| 4357 | /* Lid closed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4358 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4359 | |
| 4360 | /* Lid opened */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4361 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4362 | |
| 4363 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4364 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4365 | |
| 4366 | /* Reasons to cancel hang detection */ |
| 4367 | |
| 4368 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4369 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4370 | |
| 4371 | /* Any host command from AP received */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4372 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4373 | |
| 4374 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4375 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4376 | |
| 4377 | /* |
| 4378 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4379 | * timer is started. This provides the AP a way to start the hang timer |
| 4380 | * without reconfiguring any of the other hang detect settings. Note that |
| 4381 | * you must previously have configured the timeouts. |
| 4382 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4383 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4384 | |
| 4385 | /* |
| 4386 | * If this flag is set, all the other fields are ignored (including |
| 4387 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4388 | * without reconfiguring any of the other hang detect settings. |
| 4389 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4390 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4391 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4392 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4393 | /* Flags; see EC_HANG_* */ |
| 4394 | uint32_t flags; |
| 4395 | |
| 4396 | /* Timeout in msec before generating host event, if enabled */ |
| 4397 | uint16_t host_event_timeout_msec; |
| 4398 | |
| 4399 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4400 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4401 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4402 | |
| 4403 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4404 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4405 | |
| 4406 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4407 | * This is the single catch-all host command to exchange data regarding the |
| 4408 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4409 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4410 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4411 | |
| 4412 | /* Subcommands for this host command */ |
| 4413 | enum charge_state_command { |
| 4414 | CHARGE_STATE_CMD_GET_STATE, |
| 4415 | CHARGE_STATE_CMD_GET_PARAM, |
| 4416 | CHARGE_STATE_CMD_SET_PARAM, |
| 4417 | CHARGE_STATE_NUM_CMDS |
| 4418 | }; |
| 4419 | |
| 4420 | /* |
| 4421 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4422 | * params, which are handled by the particular implementations. |
| 4423 | */ |
| 4424 | enum charge_state_params { |
| 4425 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 4426 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 4427 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 4428 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 4429 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4430 | CS_PARAM_LIMIT_POWER, /* |
| 4431 | * Check if power is limited due to |
| 4432 | * low battery and / or a weak external |
| 4433 | * charger. READ ONLY. |
| 4434 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4435 | /* How many so far? */ |
| 4436 | CS_NUM_BASE_PARAMS, |
| 4437 | |
| 4438 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4439 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4440 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4441 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4442 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4443 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4444 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4445 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4446 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4447 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4448 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4449 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4450 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4451 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4452 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4453 | /* Other custom param ranges go here... */ |
| 4454 | }; |
| 4455 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4456 | struct ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4457 | uint8_t cmd; /* enum charge_state_command */ |
| 4458 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4459 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4460 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4461 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4462 | uint32_t param; /* enum charge_state_param */ |
| 4463 | } get_param; |
| 4464 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4465 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4466 | uint32_t param; /* param to set */ |
| 4467 | uint32_t value; /* value to set */ |
| 4468 | } set_param; |
| 4469 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4470 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4471 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4472 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4473 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4474 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4475 | int ac; |
| 4476 | int chg_voltage; |
| 4477 | int chg_current; |
| 4478 | int chg_input_current; |
| 4479 | int batt_state_of_charge; |
| 4480 | } get_state; |
| 4481 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4482 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4483 | uint32_t value; |
| 4484 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4485 | |
| 4486 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4487 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4488 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4489 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4490 | |
| 4491 | /* |
| 4492 | * Set maximum battery charging current. |
| 4493 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4494 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4495 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4496 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4497 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4498 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4499 | |
| 4500 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4501 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4502 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4503 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4504 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4505 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4506 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4507 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4508 | uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4509 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4510 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4511 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4512 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4513 | /* |
| 4514 | * Set maximum voltage & current of a dedicated charge port |
| 4515 | */ |
| 4516 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4517 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4518 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4519 | uint16_t current_lim; /* in mA */ |
| 4520 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4521 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4522 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4523 | /*****************************************************************************/ |
| 4524 | /* Hibernate/Deep Sleep Commands */ |
| 4525 | |
| 4526 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4527 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4528 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4529 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4530 | /* |
| 4531 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4532 | * current settings without changing them. |
| 4533 | */ |
| 4534 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4535 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4536 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4537 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4538 | /* |
| 4539 | * The current time in seconds in which the system has been in the G3 |
| 4540 | * state. This value is reset if the EC transitions out of G3. |
| 4541 | */ |
| 4542 | uint32_t time_g3; |
| 4543 | |
| 4544 | /* |
| 4545 | * The current time remaining in seconds until the EC should hibernate. |
| 4546 | * This value is also reset if the EC transitions out of G3. |
| 4547 | */ |
| 4548 | uint32_t time_remaining; |
| 4549 | |
| 4550 | /* |
| 4551 | * The current time in seconds that the EC should wait in G3 before |
| 4552 | * hibernating. |
| 4553 | */ |
| 4554 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4555 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4556 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4557 | /* Inform the EC when entering a sleep state */ |
| 4558 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4559 | |
| 4560 | enum host_sleep_event { |
| 4561 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4562 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 4563 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4564 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
| 4565 | /* S3 suspend with additional enabled wake sources */ |
| 4566 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4567 | }; |
| 4568 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4569 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4570 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4571 | } __ec_align1; |
| 4572 | |
| 4573 | /* |
| 4574 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4575 | * transition failures |
| 4576 | */ |
| 4577 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4578 | |
| 4579 | /* Disable timeout detection for this sleep transition */ |
| 4580 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4581 | |
| 4582 | struct ec_params_host_sleep_event_v1 { |
| 4583 | /* The type of sleep being entered or exited. */ |
| 4584 | uint8_t sleep_event; |
| 4585 | |
| 4586 | /* Padding */ |
| 4587 | uint8_t reserved; |
| 4588 | union { |
| 4589 | /* Parameters that apply for suspend messages. */ |
| 4590 | struct { |
| 4591 | /* |
| 4592 | * The timeout in milliseconds between when this message |
| 4593 | * is received and when the EC will declare sleep |
| 4594 | * transition failure if the sleep signal is not |
| 4595 | * asserted. |
| 4596 | */ |
| 4597 | uint16_t sleep_timeout_ms; |
| 4598 | } suspend_params; |
| 4599 | |
| 4600 | /* No parameters for non-suspend messages. */ |
| 4601 | }; |
| 4602 | } __ec_align2; |
| 4603 | |
| 4604 | /* A timeout occurred when this bit is set */ |
| 4605 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4606 | |
| 4607 | /* |
| 4608 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4609 | * as well as the maximum number of suspend line transitions that will be |
| 4610 | * reported back to the host. |
| 4611 | */ |
| 4612 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4613 | |
| 4614 | struct ec_response_host_sleep_event_v1 { |
| 4615 | union { |
| 4616 | /* Response fields that apply for resume messages. */ |
| 4617 | struct { |
| 4618 | /* |
| 4619 | * The number of sleep power signal transitions that |
| 4620 | * occurred since the suspend message. The high bit |
| 4621 | * indicates a timeout occurred. |
| 4622 | */ |
| 4623 | uint32_t sleep_transitions; |
| 4624 | } resume_response; |
| 4625 | |
| 4626 | /* No response fields for non-resume messages. */ |
| 4627 | }; |
| 4628 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4629 | |
| 4630 | /*****************************************************************************/ |
| 4631 | /* Device events */ |
| 4632 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4633 | |
| 4634 | enum ec_device_event { |
| 4635 | EC_DEVICE_EVENT_TRACKPAD, |
| 4636 | EC_DEVICE_EVENT_DSP, |
| 4637 | EC_DEVICE_EVENT_WIFI, |
| 4638 | }; |
| 4639 | |
| 4640 | enum ec_device_event_param { |
| 4641 | /* Get and clear pending device events */ |
| 4642 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4643 | /* Get device event mask */ |
| 4644 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4645 | /* Set device event mask */ |
| 4646 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4647 | }; |
| 4648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4649 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4650 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4651 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4652 | uint32_t event_mask; |
| 4653 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4654 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4655 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4656 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4657 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4658 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4659 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4660 | /*****************************************************************************/ |
| 4661 | /* Smart battery pass-through */ |
| 4662 | |
| 4663 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4664 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4665 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4666 | |
| 4667 | /* Get / Set string smart battery parameters |
| 4668 | * formatted as SMBUS "block". |
| 4669 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4670 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 4671 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4672 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4673 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4674 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4675 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4676 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4677 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4678 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4679 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4680 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4681 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4682 | uint8_t reg; |
| 4683 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4684 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4685 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4686 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4687 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4688 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4689 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4690 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4691 | uint8_t reg; |
| 4692 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4693 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4694 | |
| 4695 | /*****************************************************************************/ |
| 4696 | /* Battery vendor parameters |
| 4697 | * |
| 4698 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 4699 | * differ between boards or batteries. On a set operation, the response |
| 4700 | * contains the actual value set, which may be rounded or clipped from the |
| 4701 | * requested value. |
| 4702 | */ |
| 4703 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4704 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4705 | |
| 4706 | enum ec_battery_vendor_param_mode { |
| 4707 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 4708 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 4709 | }; |
| 4710 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4711 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4712 | uint32_t param; |
| 4713 | uint32_t value; |
| 4714 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4715 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4716 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4717 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4718 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4719 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4720 | |
| 4721 | /*****************************************************************************/ |
| 4722 | /* |
| 4723 | * Smart Battery Firmware Update Commands |
| 4724 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4725 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4726 | |
| 4727 | enum ec_sb_fw_update_subcmd { |
| 4728 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 4729 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 4730 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 4731 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 4732 | EC_SB_FW_UPDATE_END = 0x4, |
| 4733 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 4734 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 4735 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 4736 | }; |
| 4737 | |
| 4738 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 4739 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 4740 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 4741 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4742 | struct ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4743 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 4744 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4745 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4746 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4747 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4748 | struct ec_sb_fw_update_header hdr; |
| 4749 | union { |
| 4750 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 4751 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 4752 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 4753 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 4754 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 4755 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4756 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4757 | |
| 4758 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4759 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4760 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 4761 | } write; |
| 4762 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4763 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4764 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4765 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4766 | union { |
| 4767 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4768 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4769 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 4770 | } info; |
| 4771 | |
| 4772 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4773 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4774 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 4775 | } status; |
| 4776 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4777 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4778 | |
| 4779 | /* |
| 4780 | * Entering Verified Boot Mode Command |
| 4781 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 4782 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4783 | * |
| 4784 | * EC no longer needs to know what mode vboot has entered, |
| 4785 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4786 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4787 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4788 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4789 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4790 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4791 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4792 | |
| 4793 | #define VBOOT_MODE_NORMAL 0 |
| 4794 | #define VBOOT_MODE_DEVELOPER 1 |
| 4795 | #define VBOOT_MODE_RECOVERY 2 |
| 4796 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4797 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4798 | /* |
| 4799 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 4800 | * certain addresses (board-specific). |
| 4801 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4802 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4803 | |
| 4804 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4805 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 4806 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 4807 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4808 | }; |
| 4809 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4810 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4811 | uint8_t subcmd; |
| 4812 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4813 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4814 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4815 | struct ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4816 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4817 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4818 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4819 | |
| 4820 | /*****************************************************************************/ |
| 4821 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4822 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4823 | * |
| 4824 | * These commands are for sending and receiving message via HDMI CEC |
| 4825 | */ |
| 4826 | |
| 4827 | #define MAX_CEC_MSG_LEN 16 |
| 4828 | |
| 4829 | /* CEC message from the AP to be written on the CEC bus */ |
| 4830 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 4831 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4832 | /** |
| 4833 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 4834 | * @msg: message content to write to the CEC bus |
| 4835 | */ |
| 4836 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4837 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4838 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4839 | |
| 4840 | /* Set various CEC parameters */ |
| 4841 | #define EC_CMD_CEC_SET 0x00BA |
| 4842 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4843 | /** |
| 4844 | * struct ec_params_cec_set - CEC parameters set |
| 4845 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4846 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 4847 | * or 1 to enable CEC functionality, in case cmd is |
| 4848 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 4849 | * address between 0 and 15 or 0xff to unregister |
| 4850 | */ |
| 4851 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4852 | uint8_t cmd; /* enum cec_command */ |
| 4853 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4854 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4855 | |
| 4856 | /* Read various CEC parameters */ |
| 4857 | #define EC_CMD_CEC_GET 0x00BB |
| 4858 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4859 | /** |
| 4860 | * struct ec_params_cec_get - CEC parameters get |
| 4861 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4862 | */ |
| 4863 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4864 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4865 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4866 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4867 | /** |
| 4868 | * struct ec_response_cec_get - CEC parameters get response |
| 4869 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 4870 | * disabled or 1 if CEC functionality is enabled, |
| 4871 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 4872 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 4873 | */ |
| 4874 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4875 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4876 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4877 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4878 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4879 | enum cec_command { |
| 4880 | /* CEC reading, writing and events enable */ |
| 4881 | CEC_CMD_ENABLE, |
| 4882 | /* CEC logical address */ |
| 4883 | CEC_CMD_LOGICAL_ADDRESS, |
| 4884 | }; |
| 4885 | |
| 4886 | /* Events from CEC to AP */ |
| 4887 | enum mkbp_cec_event { |
| 4888 | /* Outgoing message was acknowledged by a follower */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4889 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4890 | /* Outgoing message was not acknowledged */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4891 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4892 | }; |
| 4893 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4894 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4895 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4896 | /* Commands for audio codec. */ |
| 4897 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4898 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4899 | enum ec_codec_subcmd { |
| 4900 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 4901 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 4902 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 4903 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4904 | }; |
| 4905 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4906 | enum ec_codec_cap { |
| 4907 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 4908 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 4909 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4910 | }; |
| 4911 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4912 | enum ec_codec_shm_id { |
| 4913 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 4914 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 4915 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4916 | }; |
| 4917 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4918 | enum ec_codec_shm_type { |
| 4919 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 4920 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4921 | }; |
| 4922 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4923 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 4924 | uint8_t shm_id; |
| 4925 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4926 | }; |
| 4927 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4928 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 4929 | uint64_t phys_addr; |
| 4930 | uint32_t len; |
| 4931 | uint8_t shm_id; |
| 4932 | uint8_t reserved[3]; |
| 4933 | }; |
| 4934 | |
| 4935 | struct __ec_align4 ec_param_ec_codec { |
| 4936 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 4937 | uint8_t reserved[3]; |
| 4938 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4939 | union { |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4940 | struct ec_param_ec_codec_get_shm_addr |
| 4941 | get_shm_addr_param; |
| 4942 | struct ec_param_ec_codec_set_shm_addr |
| 4943 | set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4944 | }; |
| 4945 | }; |
| 4946 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4947 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 4948 | uint32_t capabilities; |
| 4949 | }; |
| 4950 | |
| 4951 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 4952 | uint64_t phys_addr; |
| 4953 | uint32_t len; |
| 4954 | uint8_t type; |
| 4955 | uint8_t reserved[3]; |
| 4956 | }; |
| 4957 | |
| 4958 | /*****************************************************************************/ |
| 4959 | |
| 4960 | /* Commands for DMIC on audio codec. */ |
| 4961 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 4962 | |
| 4963 | enum ec_codec_dmic_subcmd { |
| 4964 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 4965 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 4966 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 4967 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 4968 | }; |
| 4969 | |
| 4970 | enum ec_codec_dmic_channel { |
| 4971 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 4972 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 4973 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 4974 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 4975 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 4976 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 4977 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 4978 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 4979 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 4980 | }; |
| 4981 | |
| 4982 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 4983 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 4984 | uint8_t gain; |
| 4985 | uint8_t reserved[2]; |
| 4986 | }; |
| 4987 | |
| 4988 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 4989 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 4990 | uint8_t reserved[3]; |
| 4991 | }; |
| 4992 | |
| 4993 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 4994 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 4995 | uint8_t reserved[3]; |
| 4996 | |
| 4997 | union { |
| 4998 | struct ec_param_ec_codec_dmic_set_gain_idx |
| 4999 | set_gain_idx_param; |
| 5000 | struct ec_param_ec_codec_dmic_get_gain_idx |
| 5001 | get_gain_idx_param; |
| 5002 | }; |
| 5003 | }; |
| 5004 | |
| 5005 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5006 | uint8_t max_gain; |
| 5007 | }; |
| 5008 | |
| 5009 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5010 | uint8_t gain; |
| 5011 | }; |
| 5012 | |
| 5013 | /*****************************************************************************/ |
| 5014 | |
| 5015 | /* Commands for I2S RX on audio codec. */ |
| 5016 | |
| 5017 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5018 | |
| 5019 | enum ec_codec_i2s_rx_subcmd { |
| 5020 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5021 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5022 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5023 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5024 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
| 5025 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5026 | }; |
| 5027 | |
| 5028 | enum ec_codec_i2s_rx_sample_depth { |
| 5029 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5030 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5031 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5032 | }; |
| 5033 | |
| 5034 | enum ec_codec_i2s_rx_daifmt { |
| 5035 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5036 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5037 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5038 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5039 | }; |
| 5040 | |
| 5041 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5042 | uint8_t depth; |
| 5043 | uint8_t reserved[3]; |
| 5044 | }; |
| 5045 | |
| 5046 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5047 | uint8_t left; |
| 5048 | uint8_t right; |
| 5049 | uint8_t reserved[2]; |
| 5050 | }; |
| 5051 | |
| 5052 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5053 | uint8_t daifmt; |
| 5054 | uint8_t reserved[3]; |
| 5055 | }; |
| 5056 | |
| 5057 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5058 | uint32_t bclk; |
| 5059 | }; |
| 5060 | |
| 5061 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5062 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5063 | uint8_t reserved[3]; |
| 5064 | |
| 5065 | union { |
| 5066 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
| 5067 | set_sample_depth_param; |
| 5068 | struct ec_param_ec_codec_i2s_rx_set_daifmt |
| 5069 | set_daifmt_param; |
| 5070 | struct ec_param_ec_codec_i2s_rx_set_bclk |
| 5071 | set_bclk_param; |
| 5072 | }; |
| 5073 | }; |
| 5074 | |
| 5075 | /*****************************************************************************/ |
| 5076 | /* Commands for WoV on audio codec. */ |
| 5077 | |
| 5078 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5079 | |
| 5080 | enum ec_codec_wov_subcmd { |
| 5081 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5082 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5083 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5084 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5085 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5086 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5087 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5088 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5089 | }; |
| 5090 | |
| 5091 | /* |
| 5092 | * @hash is SHA256 of the whole language model. |
| 5093 | * @total_len indicates the length of whole language model. |
| 5094 | * @offset is the cursor from the beginning of the model. |
| 5095 | * @buf is the packet buffer. |
| 5096 | * @len denotes how many bytes in the buf. |
| 5097 | */ |
| 5098 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5099 | uint8_t hash[32]; |
| 5100 | uint32_t total_len; |
| 5101 | uint32_t offset; |
| 5102 | uint8_t buf[128]; |
| 5103 | uint32_t len; |
| 5104 | }; |
| 5105 | |
| 5106 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5107 | uint8_t hash[32]; |
| 5108 | uint32_t total_len; |
| 5109 | }; |
| 5110 | |
| 5111 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5112 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5113 | uint8_t reserved[3]; |
| 5114 | |
| 5115 | union { |
| 5116 | struct ec_param_ec_codec_wov_set_lang |
| 5117 | set_lang_param; |
| 5118 | struct ec_param_ec_codec_wov_set_lang_shm |
| 5119 | set_lang_shm_param; |
| 5120 | }; |
| 5121 | }; |
| 5122 | |
| 5123 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5124 | uint8_t hash[32]; |
| 5125 | }; |
| 5126 | |
| 5127 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5128 | uint8_t buf[128]; |
| 5129 | uint32_t len; |
| 5130 | }; |
| 5131 | |
| 5132 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5133 | uint32_t offset; |
| 5134 | uint32_t len; |
| 5135 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5136 | |
| 5137 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5138 | /* System commands */ |
| 5139 | |
| 5140 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5141 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5142 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5143 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5144 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5145 | |
| 5146 | /* Command */ |
| 5147 | enum ec_reboot_cmd { |
| 5148 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5149 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5150 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5151 | /* (command 3 was jump to RW-B) */ |
| 5152 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5153 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
Daisuke Nojiri | 40d0bfa | 2017-11-30 17:41:09 -0800 | [diff] [blame] | 5154 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
| 5155 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5156 | }; |
| 5157 | |
| 5158 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5159 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5160 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5161 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5162 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5163 | struct ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5164 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5165 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5166 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5167 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5168 | /* |
| 5169 | * Get information on last EC panic. |
| 5170 | * |
| 5171 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5172 | * for details. |
| 5173 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5174 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5175 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5176 | /*****************************************************************************/ |
| 5177 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5178 | * Special commands |
| 5179 | * |
| 5180 | * These do not follow the normal rules for commands. See each command for |
| 5181 | * details. |
| 5182 | */ |
| 5183 | |
| 5184 | /* |
| 5185 | * Reboot NOW |
| 5186 | * |
| 5187 | * This command will work even when the EC LPC interface is busy, because the |
| 5188 | * reboot command is processed at interrupt level. Note that when the EC |
| 5189 | * reboots, the host will reboot too, so there is no response to this command. |
| 5190 | * |
| 5191 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5192 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5193 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5194 | |
| 5195 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5196 | * Resend last response (not supported on LPC). |
| 5197 | * |
| 5198 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5199 | * there was no previous command, or the previous command's response was too |
| 5200 | * big to save. |
| 5201 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5202 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5203 | |
| 5204 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5205 | * This header byte on a command indicate version 0. Any header byte less |
| 5206 | * than this means that we are talking to an old EC which doesn't support |
| 5207 | * versioning. In that case, we assume version 0. |
| 5208 | * |
| 5209 | * Header bytes greater than this indicate a later version. For example, |
| 5210 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5211 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5212 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5213 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5214 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5215 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5216 | /*****************************************************************************/ |
| 5217 | /* |
| 5218 | * PD commands |
| 5219 | * |
| 5220 | * These commands are for PD MCU communication. |
| 5221 | */ |
| 5222 | |
| 5223 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5224 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5225 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5226 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5227 | enum pd_charge_state { |
| 5228 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 5229 | PD_CHARGE_NONE, /* No charging allowed */ |
| 5230 | PD_CHARGE_5V, /* 5V charging only */ |
| 5231 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 5232 | }; |
| 5233 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5234 | /* Status of EC being sent to PD */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5235 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5236 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5237 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5238 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5239 | int8_t batt_soc; /* battery state of charge */ |
| 5240 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5241 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5242 | |
| 5243 | /* Status of PD being sent back to EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5244 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5245 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
| 5246 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
| 5247 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5248 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5249 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5250 | #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5251 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 5252 | PD_STATUS_TCPC_ALERT_1 | \ |
| 5253 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5254 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5255 | uint32_t curr_lim_ma; /* input current limit */ |
| 5256 | uint16_t status; /* PD MCU status */ |
| 5257 | int8_t active_charge_port; /* active charging port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5258 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5259 | |
| 5260 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5261 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5262 | |
| 5263 | /* PD MCU host event status bits */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5264 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5265 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5266 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5267 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5268 | struct ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5269 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5270 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5271 | |
| 5272 | /* Set USB type-C port role and muxes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5273 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5274 | |
| 5275 | enum usb_pd_control_role { |
| 5276 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5277 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5278 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5279 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5280 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5281 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5282 | USB_PD_CTRL_ROLE_COUNT |
| 5283 | }; |
| 5284 | |
| 5285 | enum usb_pd_control_mux { |
| 5286 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5287 | USB_PD_CTRL_MUX_NONE = 1, |
| 5288 | USB_PD_CTRL_MUX_USB = 2, |
| 5289 | USB_PD_CTRL_MUX_DP = 3, |
| 5290 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5291 | USB_PD_CTRL_MUX_AUTO = 5, |
| 5292 | USB_PD_CTRL_MUX_COUNT |
| 5293 | }; |
| 5294 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5295 | enum usb_pd_control_swap { |
| 5296 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5297 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5298 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5299 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 5300 | USB_PD_CTRL_SWAP_COUNT |
| 5301 | }; |
| 5302 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5303 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5304 | uint8_t port; |
| 5305 | uint8_t role; |
| 5306 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5307 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5308 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5309 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5310 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5311 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
| 5312 | #define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5313 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5314 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5315 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5316 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5317 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5318 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5319 | #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5320 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5321 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5322 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5323 | uint8_t enabled; |
| 5324 | uint8_t role; |
| 5325 | uint8_t polarity; |
| 5326 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5327 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5328 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5329 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5330 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5331 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5332 | uint8_t polarity; |
| 5333 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5334 | } __ec_align1; |
| 5335 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5336 | /* Possible port partner connections based on CC line states */ |
| 5337 | enum pd_cc_states { |
| 5338 | PD_CC_NONE = 0, /* No port partner attached */ |
| 5339 | |
| 5340 | /* From DFP perspective */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5341 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5342 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5343 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5344 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
| 5345 | |
| 5346 | /* From UFP perspective */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5347 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5348 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5349 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5350 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5351 | /* Active/Passive Cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5352 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5353 | /* Optical/Non-optical cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5354 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5355 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5356 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
| 5357 | /* Active Link Uni-Direction */ |
| 5358 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5359 | |
| 5360 | /* |
| 5361 | * Underdevelopement : |
| 5362 | * Please remove this tag if using _v2 outside platform/ec |
| 5363 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5364 | struct ec_response_usb_pd_control_v2 { |
| 5365 | uint8_t enabled; |
| 5366 | uint8_t role; |
| 5367 | uint8_t polarity; |
| 5368 | char state[32]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5369 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5370 | uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5371 | uint8_t reserved; /* Reserved for future use */ |
| 5372 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
| 5373 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
| 5374 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5375 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5376 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5377 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5378 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5379 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5380 | #define EC_USB_PD_MAX_PORTS 8 |
| 5381 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5382 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5383 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5384 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5385 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5386 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5387 | |
| 5388 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5389 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5390 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5391 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5392 | |
| 5393 | enum usb_chg_type { |
| 5394 | USB_CHG_TYPE_NONE, |
| 5395 | USB_CHG_TYPE_PD, |
| 5396 | USB_CHG_TYPE_C, |
| 5397 | USB_CHG_TYPE_PROPRIETARY, |
| 5398 | USB_CHG_TYPE_BC12_DCP, |
| 5399 | USB_CHG_TYPE_BC12_CDP, |
| 5400 | USB_CHG_TYPE_BC12_SDP, |
| 5401 | USB_CHG_TYPE_OTHER, |
| 5402 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5403 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5404 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5405 | }; |
| 5406 | enum usb_power_roles { |
| 5407 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5408 | USB_PD_PORT_POWER_SOURCE, |
| 5409 | USB_PD_PORT_POWER_SINK, |
| 5410 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5411 | }; |
| 5412 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5413 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5414 | uint16_t voltage_max; |
| 5415 | uint16_t voltage_now; |
| 5416 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5417 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5418 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5419 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5420 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5421 | uint8_t role; |
| 5422 | uint8_t type; |
| 5423 | uint8_t dualrole; |
| 5424 | uint8_t reserved1; |
| 5425 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5426 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5427 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5428 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5429 | |
| 5430 | /* |
| 5431 | * This command will return the number of USB PD charge port + the number |
| 5432 | * of dedicated port present. |
| 5433 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5434 | */ |
| 5435 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5436 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5437 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5438 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5439 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5440 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5441 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5442 | |
| 5443 | enum usb_pd_fw_update_cmds { |
| 5444 | USB_PD_FW_REBOOT, |
| 5445 | USB_PD_FW_FLASH_ERASE, |
| 5446 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5447 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5448 | }; |
| 5449 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5450 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5451 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5452 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5453 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5454 | uint32_t size; /* Size to write in bytes */ |
| 5455 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5456 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5457 | |
| 5458 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5459 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5460 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5461 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5462 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5463 | uint16_t dev_id; |
| 5464 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5465 | uint8_t reserved; /* |
| 5466 | * For alignment of current_image |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5467 | * TODO(rspangler) but it's not aligned! |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5468 | * Should have been reserved[2]. |
| 5469 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5470 | uint32_t current_image; /* One of ec_image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5471 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5472 | |
| 5473 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5474 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5475 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5476 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5477 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5478 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5479 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5480 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5481 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5482 | struct ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5483 | uint16_t vid; /* USB-IF VID */ |
| 5484 | uint16_t pid; /* USB-IF PID */ |
| 5485 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5486 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5487 | |
| 5488 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5489 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5490 | |
| 5491 | /* Negative port parameters have special meaning */ |
| 5492 | enum usb_pd_override_ports { |
| 5493 | OVERRIDE_DONT_CHARGE = -2, |
| 5494 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5495 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5496 | }; |
| 5497 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5498 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5499 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5500 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5501 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5502 | /* |
| 5503 | * Read (and delete) one entry of PD event log. |
| 5504 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5505 | * future non-PD logs that use the same internal EC event_log. |
| 5506 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5507 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5508 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5509 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5510 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 5511 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5512 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5513 | uint16_t data; /* type-defined data payload */ |
| 5514 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5515 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5516 | |
| 5517 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5518 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5519 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5520 | #define PD_LOG_SIZE_MASK 0x1f |
| 5521 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5522 | #define PD_LOG_PORT_SHIFT 5 |
| 5523 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 5524 | ((size) & PD_LOG_SIZE_MASK)) |
| 5525 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 5526 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 5527 | |
| 5528 | /* PD event log : entry types */ |
| 5529 | /* PD MCU events */ |
| 5530 | #define PD_EVENT_MCU_BASE 0x00 |
| 5531 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 5532 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 5533 | /* Reserved for custom board event */ |
| 5534 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 5535 | /* PD generic accessory events */ |
| 5536 | #define PD_EVENT_ACC_BASE 0x20 |
| 5537 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 5538 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 5539 | /* PD power supply events */ |
| 5540 | #define PD_EVENT_PS_BASE 0x40 |
| 5541 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 5542 | /* PD video dongles events */ |
| 5543 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5544 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 5545 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 5546 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5547 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5548 | |
| 5549 | /* |
| 5550 | * PD_EVENT_MCU_CHARGE event definition : |
| 5551 | * the payload is "struct usb_chg_measures" |
| 5552 | * the data field contains the port state flags as defined below : |
| 5553 | */ |
| 5554 | /* Port partner is a dual role device */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5555 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5556 | /* Port is the pending override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5557 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5558 | /* Port is the override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5559 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5560 | /* Charger type */ |
| 5561 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5562 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5563 | /* Power delivery role */ |
| 5564 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 5565 | |
| 5566 | /* |
| 5567 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5568 | */ |
| 5569 | #define PS_FAULT_OCP 1 |
| 5570 | #define PS_FAULT_FAST_OCP 2 |
| 5571 | #define PS_FAULT_OVP 3 |
| 5572 | #define PS_FAULT_DISCH 4 |
| 5573 | |
| 5574 | /* |
| 5575 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5576 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5577 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5578 | uint8_t major; |
| 5579 | uint8_t minor; |
| 5580 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5581 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5582 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5583 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5584 | uint8_t family[2]; |
| 5585 | uint8_t chipid[2]; |
| 5586 | struct mcdp_version irom; |
| 5587 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5588 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5589 | |
| 5590 | /* struct mcdp_info field decoding */ |
| 5591 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5592 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5593 | |
| 5594 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5595 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5596 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5597 | uint16_t svid_idx; /* SVID index to get */ |
| 5598 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5599 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5600 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5601 | struct ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5602 | uint16_t svid; /* SVID */ |
| 5603 | uint16_t opos; /* Object Position */ |
| 5604 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5605 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5606 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5607 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5608 | |
| 5609 | enum pd_mode_cmd { |
| 5610 | PD_EXIT_MODE = 0, |
| 5611 | PD_ENTER_MODE = 1, |
| 5612 | /* Not a command. Do NOT remove. */ |
| 5613 | PD_MODE_CMD_COUNT, |
| 5614 | }; |
| 5615 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5616 | struct ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5617 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 5618 | uint16_t svid; /* SVID to set */ |
| 5619 | uint8_t opos; /* Object Position */ |
| 5620 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5621 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5622 | |
| 5623 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5624 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5625 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5626 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5627 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 5628 | uint8_t port; /* port#, or 0 for events unrelated to a given port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5629 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5630 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5631 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5632 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5633 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5634 | |
| 5635 | enum ec_pd_control_cmd { |
| 5636 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 5637 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 5638 | PD_RESET, /* Force reset the PD chip */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5639 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 5640 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5641 | }; |
| 5642 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5643 | struct ec_params_pd_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5644 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5645 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5646 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5647 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5648 | /* Get info about USB-C SS muxes */ |
| 5649 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 5650 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5651 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5652 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5653 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5654 | |
| 5655 | /* Flags representing mux state */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5656 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 5657 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 5658 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 5659 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 5660 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 5661 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 5662 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
| 5663 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5664 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
| 5665 | |
| 5666 | /* USB-C Dock connected */ |
| 5667 | #define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5668 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5669 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5670 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5671 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5672 | |
| 5673 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 5674 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5675 | struct ec_params_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5676 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5677 | /* |
| 5678 | * Fetch the live chip info or hard-coded + cached chip info |
| 5679 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 5680 | * 1: live chip value for VID/PID/FW Version |
| 5681 | */ |
| 5682 | uint8_t live; |
| 5683 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5684 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5685 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5686 | uint16_t vendor_id; |
| 5687 | uint16_t product_id; |
| 5688 | uint16_t device_id; |
| 5689 | union { |
| 5690 | uint8_t fw_version_string[8]; |
| 5691 | uint64_t fw_version_number; |
| 5692 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5693 | } __ec_align2; |
| 5694 | |
| 5695 | struct ec_response_pd_chip_info_v1 { |
| 5696 | uint16_t vendor_id; |
| 5697 | uint16_t product_id; |
| 5698 | uint16_t device_id; |
| 5699 | union { |
| 5700 | uint8_t fw_version_string[8]; |
| 5701 | uint64_t fw_version_number; |
| 5702 | }; |
| 5703 | union { |
| 5704 | uint8_t min_req_fw_version_string[8]; |
| 5705 | uint64_t min_req_fw_version_number; |
| 5706 | }; |
| 5707 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5708 | |
| 5709 | /* Run RW signature verification and get status */ |
| 5710 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 5711 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5712 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5713 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5714 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5715 | |
| 5716 | /* For controlling RWSIG task */ |
| 5717 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 5718 | |
| 5719 | enum rwsig_action { |
| 5720 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 5721 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 5722 | }; |
| 5723 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5724 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5725 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5726 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5727 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5728 | /* Run verification on a slot */ |
| 5729 | #define EC_CMD_EFS_VERIFY 0x011E |
| 5730 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5731 | struct ec_params_efs_verify { |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5732 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5733 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5734 | |
| 5735 | /* |
| 5736 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 5737 | * type. Integers return a uint32. Strings return a string, using the response |
| 5738 | * size to determine how big it is. |
| 5739 | */ |
| 5740 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
| 5741 | /* |
| 5742 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 5743 | * hardware write-protect enabled. |
| 5744 | */ |
| 5745 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
| 5746 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5747 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5748 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
| 5749 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 5750 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 5751 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Wisley Chen | c1efec7 | 2018-11-06 09:28:23 +0800 | [diff] [blame] | 5752 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5753 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5754 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5755 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5756 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5757 | }; |
| 5758 | |
| 5759 | /* |
| 5760 | * Flags to control read operation |
| 5761 | * |
| 5762 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 5763 | * write was successful without reboot. |
| 5764 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5765 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5766 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5767 | struct ec_params_get_cbi { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5768 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5769 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5770 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5771 | |
| 5772 | /* |
| 5773 | * Flags to control write behavior. |
| 5774 | * |
| 5775 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 5776 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5777 | * INIT: Need to be set when creating a new CBI from scratch. All fields |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5778 | * will be initialized to zero first. |
| 5779 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5780 | #define CBI_SET_NO_SYNC BIT(0) |
| 5781 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5782 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5783 | struct ec_params_set_cbi { |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5784 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5785 | uint32_t flag; /* CBI_SET_* */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5786 | uint32_t size; /* Data size */ |
| 5787 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5788 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5789 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5790 | /* |
| 5791 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 5792 | */ |
| 5793 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 5794 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5795 | /* Reset causes */ |
| 5796 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 5797 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 5798 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 5799 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 5800 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 5801 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 5802 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 5803 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 5804 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 5805 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 5806 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 5807 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 5808 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
| 5809 | #define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from |
| 5810 | * previous boot |
| 5811 | */ |
| 5812 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 5813 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 5814 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 5815 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
| 5816 | #define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 5817 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This |
| 5818 | * enables PD in RO for Chromebox. |
| 5819 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5820 | |
| 5821 | struct ec_response_uptime_info { |
| 5822 | /* |
| 5823 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 5824 | * typically do not restart the EC's time_since_boot epoch. |
| 5825 | * |
| 5826 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 5827 | * sense of time, in both phase and frequency. This timebase is similar |
| 5828 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 5829 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5830 | uint32_t time_since_ec_boot_ms; |
| 5831 | |
| 5832 | /* |
| 5833 | * Number of times the AP was reset by the EC since the last EC boot. |
| 5834 | * Note that the AP may be held in reset by the EC during the initial |
| 5835 | * boot sequence, such that the very first AP boot may count as more |
| 5836 | * than one here. |
| 5837 | */ |
| 5838 | uint32_t ap_resets_since_ec_boot; |
| 5839 | |
| 5840 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5841 | * The set of flags which describe the EC's most recent reset. |
| 5842 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5843 | */ |
| 5844 | uint32_t ec_reset_flags; |
| 5845 | |
| 5846 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 5847 | struct ap_reset_log_entry { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5848 | /* |
| 5849 | * See include/chipset.h: enum chipset_{reset,shutdown}_reason |
| 5850 | * for details. |
| 5851 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5852 | uint16_t reset_cause; |
| 5853 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5854 | /* Reserved for protocol growth. */ |
| 5855 | uint16_t reserved; |
| 5856 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5857 | /* |
| 5858 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5859 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 5860 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5861 | */ |
| 5862 | uint32_t reset_time_ms; |
| 5863 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5864 | } __ec_align4; |
| 5865 | |
| 5866 | /* |
| 5867 | * Add entropy to the device secret (stored in the rollback region). |
| 5868 | * |
| 5869 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 5870 | * flash), so the commands are asynchronous. |
| 5871 | */ |
| 5872 | #define EC_CMD_ADD_ENTROPY 0x0122 |
| 5873 | |
| 5874 | enum add_entropy_action { |
| 5875 | /* Add entropy to the current secret. */ |
| 5876 | ADD_ENTROPY_ASYNC = 0, |
| 5877 | /* |
| 5878 | * Add entropy, and also make sure that the previous secret is erased. |
| 5879 | * (this can be implemented by adding entropy multiple times until |
| 5880 | * all rolback blocks have been overwritten). |
| 5881 | */ |
| 5882 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 5883 | /* Read back result from the previous operation. */ |
| 5884 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5885 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5886 | |
| 5887 | struct ec_params_rollback_add_entropy { |
| 5888 | uint8_t action; |
| 5889 | } __ec_align1; |
| 5890 | |
| 5891 | /* |
| 5892 | * Perform a single read of a given ADC channel. |
| 5893 | */ |
| 5894 | #define EC_CMD_ADC_READ 0x0123 |
| 5895 | |
| 5896 | struct ec_params_adc_read { |
| 5897 | uint8_t adc_channel; |
| 5898 | } __ec_align1; |
| 5899 | |
| 5900 | struct ec_response_adc_read { |
| 5901 | int32_t adc_value; |
| 5902 | } __ec_align4; |
| 5903 | |
| 5904 | /* |
| 5905 | * Read back rollback info |
| 5906 | */ |
| 5907 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
| 5908 | |
| 5909 | struct ec_response_rollback_info { |
| 5910 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 5911 | int32_t rollback_min_version; |
| 5912 | int32_t rw_rollback_version; |
| 5913 | } __ec_align4; |
| 5914 | |
| 5915 | |
| 5916 | /* Issue AP reset */ |
| 5917 | #define EC_CMD_AP_RESET 0x0125 |
| 5918 | |
| 5919 | /*****************************************************************************/ |
| 5920 | /* Locate peripheral chips |
| 5921 | * |
| 5922 | * Return values: |
| 5923 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 5924 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 5925 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 5926 | */ |
| 5927 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 5928 | |
| 5929 | enum ec_chip_type { |
| 5930 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 5931 | EC_CHIP_TYPE_TCPC = 1, |
| 5932 | EC_CHIP_TYPE_COUNT, |
| 5933 | EC_CHIP_TYPE_MAX = 0xFF, |
| 5934 | }; |
| 5935 | |
| 5936 | enum ec_bus_type { |
| 5937 | EC_BUS_TYPE_I2C = 0, |
| 5938 | EC_BUS_TYPE_EMBEDDED = 1, |
| 5939 | EC_BUS_TYPE_COUNT, |
| 5940 | EC_BUS_TYPE_MAX = 0xFF, |
| 5941 | }; |
| 5942 | |
| 5943 | struct ec_i2c_info { |
| 5944 | uint16_t port; /* Physical port for device */ |
| 5945 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
| 5946 | }; |
| 5947 | |
| 5948 | struct ec_params_locate_chip { |
| 5949 | uint8_t type; /* enum ec_chip_type */ |
| 5950 | uint8_t index; /* Specifies one instance of chip type */ |
| 5951 | /* Used for type specific parameters in future */ |
| 5952 | union { |
| 5953 | uint16_t reserved; |
| 5954 | }; |
| 5955 | } __ec_align2; |
| 5956 | |
| 5957 | |
| 5958 | struct ec_response_locate_chip { |
| 5959 | uint8_t bus_type; /* enum ec_bus_type */ |
| 5960 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
| 5961 | union { |
| 5962 | struct ec_i2c_info i2c_info; |
| 5963 | }; |
| 5964 | } __ec_align2; |
| 5965 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5966 | /* |
| 5967 | * Reboot AP on G3 |
| 5968 | * |
| 5969 | * This command is used for validation purpose, where the AP needs to be |
| 5970 | * returned back to S0 state from G3 state without using the servo to trigger |
| 5971 | * wake events.For this,there is no request or response struct. |
| 5972 | * |
| 5973 | * Order of command usage: |
| 5974 | * ectool reboot_ap_on_g3 && shutdown -h now |
| 5975 | */ |
| 5976 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 5977 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5978 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 5979 | /* Get PD port capabilities |
| 5980 | * |
| 5981 | * Returns the following static *capabilities* of the given port: |
| 5982 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 5983 | * future CrOS devices would ever be only a source, so the options are |
| 5984 | * sink or dual. |
| 5985 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 5986 | * believe any CrOS device would support Try.SNK, so this would be source |
| 5987 | * or none). |
| 5988 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 5989 | * for CrOS devices. |
| 5990 | */ |
| 5991 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 5992 | |
| 5993 | enum ec_pd_power_role_caps { |
| 5994 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 5995 | EC_PD_POWER_ROLE_SINK = 1, |
| 5996 | EC_PD_POWER_ROLE_DUAL = 2, |
| 5997 | }; |
| 5998 | |
| 5999 | enum ec_pd_try_power_role_caps { |
| 6000 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6001 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6002 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6003 | }; |
| 6004 | |
| 6005 | enum ec_pd_data_role_caps { |
| 6006 | EC_PD_DATA_ROLE_DFP = 0, |
| 6007 | EC_PD_DATA_ROLE_UFP = 1, |
| 6008 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6009 | }; |
| 6010 | |
| 6011 | /* From: power_manager/power_supply_properties.proto */ |
| 6012 | enum ec_pd_port_location { |
| 6013 | /* The location of the port is unknown, or there's only one port. */ |
| 6014 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6015 | |
| 6016 | /* |
| 6017 | * Various positions on the device. The first word describes the side of |
| 6018 | * the device where the port is located while the second clarifies the |
| 6019 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6020 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6021 | * device. |
| 6022 | */ |
| 6023 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6024 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6025 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6026 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6027 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6028 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
| 6029 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
| 6030 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6031 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6032 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
| 6033 | }; |
| 6034 | |
| 6035 | struct ec_params_get_pd_port_caps { |
| 6036 | uint8_t port; /* Which port to interrogate */ |
| 6037 | } __ec_align1; |
| 6038 | |
| 6039 | struct ec_response_get_pd_port_caps { |
| 6040 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6041 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6042 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6043 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
| 6044 | } __ec_align1; |
| 6045 | |
| 6046 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame^] | 6047 | /* |
| 6048 | * Button press simulation |
| 6049 | * |
| 6050 | * This command is used to simulate a button press. |
| 6051 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6052 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6053 | * |
| 6054 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6055 | */ |
| 6056 | #define EC_CMD_BUTTON 0x0129 |
| 6057 | |
| 6058 | struct ec_params_button { |
| 6059 | /* Button mask aligned to enum keyboard_button_type */ |
| 6060 | uint32_t btn_mask; |
| 6061 | |
| 6062 | /* Duration in milliseconds button needs to be pressed */ |
| 6063 | uint32_t press_ms; |
| 6064 | } __ec_align1; |
| 6065 | |
| 6066 | enum keyboard_button_type { |
| 6067 | KEYBOARD_BUTTON_POWER = 0, |
| 6068 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
| 6069 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6070 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6071 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6072 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6073 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6074 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6075 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6076 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6077 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6078 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
| 6079 | |
| 6080 | KEYBOARD_BUTTON_COUNT |
| 6081 | }; |
| 6082 | |
| 6083 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6084 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6085 | |
| 6086 | /*****************************************************************************/ |
| 6087 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6088 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6089 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6090 | #define EC_CMD_CR51_BASE 0x0300 |
| 6091 | #define EC_CMD_CR51_LAST 0x03FF |
| 6092 | |
| 6093 | /*****************************************************************************/ |
| 6094 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 6095 | |
| 6096 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 6097 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 6098 | |
| 6099 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 6100 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6101 | struct ec_params_fp_passthru { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6102 | uint16_t len; /* Number of bytes to write then read */ |
| 6103 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 6104 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6105 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6106 | |
| 6107 | /* Configure the Fingerprint MCU behavior */ |
| 6108 | #define EC_CMD_FP_MODE 0x0402 |
| 6109 | |
| 6110 | /* Put the sensor in its lowest power mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6111 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6112 | /* Wait to see a finger on the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6113 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6114 | /* Poll until the finger has left the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6115 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6116 | /* Capture the current finger image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6117 | #define FP_MODE_CAPTURE BIT(3) |
| 6118 | /* Finger enrollment session on-going */ |
| 6119 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 6120 | /* Enroll the current finger image */ |
| 6121 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
| 6122 | /* Try to match the current finger image */ |
| 6123 | #define FP_MODE_MATCH BIT(6) |
| 6124 | /* Reset and re-initialize the sensor. */ |
| 6125 | #define FP_MODE_RESET_SENSOR BIT(7) |
| 6126 | /* special value: don't change anything just read back current mode */ |
| 6127 | #define FP_MODE_DONT_CHANGE BIT(31) |
| 6128 | |
| 6129 | #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ |
| 6130 | FP_MODE_FINGER_DOWN | \ |
| 6131 | FP_MODE_FINGER_UP | \ |
| 6132 | FP_MODE_CAPTURE | \ |
| 6133 | FP_MODE_ENROLL_SESSION | \ |
| 6134 | FP_MODE_ENROLL_IMAGE | \ |
| 6135 | FP_MODE_MATCH | \ |
| 6136 | FP_MODE_RESET_SENSOR | \ |
| 6137 | FP_MODE_DONT_CHANGE) |
| 6138 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6139 | /* Capture types defined in bits [30..28] */ |
| 6140 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6141 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
| 6142 | /* |
| 6143 | * This enum must remain ordered, if you add new values you must ensure that |
| 6144 | * FP_CAPTURE_TYPE_MAX is still the last one. |
| 6145 | */ |
| 6146 | enum fp_capture_type { |
| 6147 | /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ |
| 6148 | FP_CAPTURE_VENDOR_FORMAT = 0, |
| 6149 | /* Simple raw image capture (produces width x height x bpp bits) */ |
| 6150 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
| 6151 | /* Self test pattern (e.g. checkerboard) */ |
| 6152 | FP_CAPTURE_PATTERN0 = 2, |
| 6153 | /* Self test pattern (e.g. inverted checkerboard) */ |
| 6154 | FP_CAPTURE_PATTERN1 = 3, |
| 6155 | /* Capture for Quality test with fixed contrast */ |
| 6156 | FP_CAPTURE_QUALITY_TEST = 4, |
| 6157 | /* Capture for pixel reset value test */ |
| 6158 | FP_CAPTURE_RESET_TEST = 5, |
| 6159 | FP_CAPTURE_TYPE_MAX, |
| 6160 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6161 | /* Extracts the capture type from the sensor 'mode' word */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6162 | #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ |
| 6163 | >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6164 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6165 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6166 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6167 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6168 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6169 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6170 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6171 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6172 | |
| 6173 | /* Retrieve Fingerprint sensor information */ |
| 6174 | #define EC_CMD_FP_INFO 0x0403 |
| 6175 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6176 | /* Number of dead pixels detected on the last maintenance */ |
| 6177 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6178 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 6179 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6180 | /* No interrupt from the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6181 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6182 | /* SPI communication error */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6183 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6184 | /* Invalid sensor Hardware ID */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6185 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6186 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6187 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6188 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6189 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6190 | /* Sensor identification */ |
| 6191 | uint32_t vendor_id; |
| 6192 | uint32_t product_id; |
| 6193 | uint32_t model_id; |
| 6194 | uint32_t version; |
| 6195 | /* Image frame characteristics */ |
| 6196 | uint32_t frame_size; |
| 6197 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6198 | uint16_t width; |
| 6199 | uint16_t height; |
| 6200 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6201 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6202 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6203 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6204 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6205 | /* Sensor identification */ |
| 6206 | uint32_t vendor_id; |
| 6207 | uint32_t product_id; |
| 6208 | uint32_t model_id; |
| 6209 | uint32_t version; |
| 6210 | /* Image frame characteristics */ |
| 6211 | uint32_t frame_size; |
| 6212 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6213 | uint16_t width; |
| 6214 | uint16_t height; |
| 6215 | uint16_t bpp; |
| 6216 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 6217 | /* Template/finger current information */ |
| 6218 | uint32_t template_size; /* max template size in bytes */ |
| 6219 | uint16_t template_max; /* maximum number of fingers/templates */ |
| 6220 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 6221 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6222 | uint32_t template_version; /* version of the template format */ |
| 6223 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6224 | |
| 6225 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6226 | #define EC_CMD_FP_FRAME 0x0404 |
| 6227 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6228 | /* constants defining the 'offset' field which also contains the frame index */ |
| 6229 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6230 | /* Frame buffer where the captured image is stored */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6231 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6232 | /* First frame buffer holding a template */ |
| 6233 | #define FP_FRAME_INDEX_TEMPLATE 1 |
| 6234 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6235 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
| 6236 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6237 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6238 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6239 | |
| 6240 | /* Constants for encryption parameters */ |
| 6241 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 6242 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 6243 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6244 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6245 | #define FP_CONTEXT_TPM_BYTES 32 |
| 6246 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6247 | /* Constants for positive match parameters. */ |
| 6248 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 6249 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6250 | struct ec_fp_template_encryption_metadata { |
| 6251 | /* |
| 6252 | * Version of the structure format (N=3). |
| 6253 | */ |
| 6254 | uint16_t struct_version; |
| 6255 | /* Reserved bytes, set to 0. */ |
| 6256 | uint16_t reserved; |
| 6257 | /* |
| 6258 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 6259 | * a different one is used for every message. |
| 6260 | */ |
| 6261 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6262 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6263 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 6264 | }; |
| 6265 | |
| 6266 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6267 | /* |
| 6268 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 6269 | * in the high nibble, and the real offset within the frame in |
| 6270 | * FP_FRAME_OFFSET_MASK. |
| 6271 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6272 | uint32_t offset; |
| 6273 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6274 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6275 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6276 | /* Load a template into the MCU */ |
| 6277 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 6278 | |
| 6279 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 6280 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 6281 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6282 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6283 | uint32_t offset; |
| 6284 | uint32_t size; |
| 6285 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6286 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6287 | |
| 6288 | /* Clear the current fingerprint user context and set a new one */ |
| 6289 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 6290 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6291 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6292 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6293 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6294 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6295 | enum fp_context_action { |
| 6296 | FP_CONTEXT_ASYNC = 0, |
| 6297 | FP_CONTEXT_GET_RESULT = 1, |
| 6298 | }; |
| 6299 | |
| 6300 | /* Version 1 of the command is "asynchronous". */ |
| 6301 | struct ec_params_fp_context_v1 { |
| 6302 | uint8_t action; /**< enum fp_context_action */ |
| 6303 | uint8_t reserved[3]; /**< padding for alignment */ |
| 6304 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 6305 | } __ec_align4; |
| 6306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6307 | #define EC_CMD_FP_STATS 0x0407 |
| 6308 | |
| 6309 | #define FPSTATS_CAPTURE_INV BIT(0) |
| 6310 | #define FPSTATS_MATCHING_INV BIT(1) |
| 6311 | |
| 6312 | struct ec_response_fp_stats { |
| 6313 | uint32_t capture_time_us; |
| 6314 | uint32_t matching_time_us; |
| 6315 | uint32_t overall_time_us; |
| 6316 | struct { |
| 6317 | uint32_t lo; |
| 6318 | uint32_t hi; |
| 6319 | } overall_t0; |
| 6320 | uint8_t timestamps_invalid; |
| 6321 | int8_t template_matched; |
| 6322 | } __ec_align2; |
| 6323 | |
| 6324 | #define EC_CMD_FP_SEED 0x0408 |
| 6325 | struct ec_params_fp_seed { |
| 6326 | /* |
| 6327 | * Version of the structure format (N=3). |
| 6328 | */ |
| 6329 | uint16_t struct_version; |
| 6330 | /* Reserved bytes, set to 0. */ |
| 6331 | uint16_t reserved; |
| 6332 | /* Seed from the TPM. */ |
| 6333 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 6334 | } __ec_align4; |
| 6335 | |
| 6336 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 6337 | |
| 6338 | /* FP TPM seed has been set or not */ |
| 6339 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 6340 | |
| 6341 | struct ec_response_fp_encryption_status { |
| 6342 | /* Used bits in encryption engine status */ |
| 6343 | uint32_t valid_flags; |
| 6344 | /* Encryption engine status */ |
| 6345 | uint32_t status; |
| 6346 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6347 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6348 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 6349 | struct ec_params_fp_read_match_secret { |
| 6350 | uint16_t fgr; |
| 6351 | } __ec_align4; |
| 6352 | |
| 6353 | /* The positive match secret has the length of the SHA256 digest. */ |
| 6354 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 6355 | struct ec_response_fp_read_match_secret { |
| 6356 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 6357 | } __ec_align4; |
| 6358 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6359 | /*****************************************************************************/ |
| 6360 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 6361 | |
| 6362 | /* Perform touchpad self test */ |
| 6363 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 6364 | |
| 6365 | /* Get number of frame types, and the size of each type */ |
| 6366 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 6367 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6368 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6369 | uint32_t n_frames; |
| 6370 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6371 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6372 | |
| 6373 | /* Create a snapshot of current frame readings */ |
| 6374 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 6375 | |
| 6376 | /* Read the frame */ |
| 6377 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 6378 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6379 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6380 | uint32_t frame_index; |
| 6381 | uint32_t offset; |
| 6382 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6383 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6384 | |
| 6385 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6386 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 6387 | |
| 6388 | #define EC_COMM_TEXT_MAX 8 |
| 6389 | |
| 6390 | /* |
| 6391 | * Get battery static information, i.e. information that never changes, or |
| 6392 | * very infrequently. |
| 6393 | */ |
| 6394 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 6395 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6396 | /** |
| 6397 | * struct ec_params_battery_static_info - Battery static info parameters |
| 6398 | * @index: Battery index. |
| 6399 | */ |
| 6400 | struct ec_params_battery_static_info { |
| 6401 | uint8_t index; |
| 6402 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6403 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6404 | /** |
| 6405 | * struct ec_response_battery_static_info - Battery static info response |
| 6406 | * @design_capacity: Battery Design Capacity (mAh) |
| 6407 | * @design_voltage: Battery Design Voltage (mV) |
| 6408 | * @manufacturer: Battery Manufacturer String |
| 6409 | * @model: Battery Model Number String |
| 6410 | * @serial: Battery Serial Number String |
| 6411 | * @type: Battery Type String |
| 6412 | * @cycle_count: Battery Cycle Count |
| 6413 | */ |
| 6414 | struct ec_response_battery_static_info { |
| 6415 | uint16_t design_capacity; |
| 6416 | uint16_t design_voltage; |
| 6417 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 6418 | char model[EC_COMM_TEXT_MAX]; |
| 6419 | char serial[EC_COMM_TEXT_MAX]; |
| 6420 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6421 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6422 | uint32_t cycle_count; |
| 6423 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6424 | |
| 6425 | /* |
| 6426 | * Get battery dynamic information, i.e. information that is likely to change |
| 6427 | * every time it is read. |
| 6428 | */ |
| 6429 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 6430 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6431 | /** |
| 6432 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 6433 | * @index: Battery index. |
| 6434 | */ |
| 6435 | struct ec_params_battery_dynamic_info { |
| 6436 | uint8_t index; |
| 6437 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6438 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6439 | /** |
| 6440 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 6441 | * @actual_voltage: Battery voltage (mV) |
| 6442 | * @actual_current: Battery current (mA); negative=discharging |
| 6443 | * @remaining_capacity: Remaining capacity (mAh) |
| 6444 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 6445 | * @flags: Flags, see EC_BATT_FLAG_* |
| 6446 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 6447 | * @desired_current: Charging current desired by battery (mA) |
| 6448 | */ |
| 6449 | struct ec_response_battery_dynamic_info { |
| 6450 | int16_t actual_voltage; |
| 6451 | int16_t actual_current; |
| 6452 | int16_t remaining_capacity; |
| 6453 | int16_t full_capacity; |
| 6454 | int16_t flags; |
| 6455 | int16_t desired_voltage; |
| 6456 | int16_t desired_current; |
| 6457 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6458 | |
| 6459 | /* |
| 6460 | * Control charger chip. Used to control charger chip on the slave. |
| 6461 | */ |
| 6462 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 6463 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6464 | /** |
| 6465 | * struct ec_params_charger_control - Charger control parameters |
| 6466 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 6467 | * max_current and (possibly) charge battery, negative to request current |
| 6468 | * from base (OTG). |
| 6469 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 6470 | * >= 0. |
| 6471 | * @allow_charging: Allow base battery charging (only makes sense if |
| 6472 | * max_current > 0). |
| 6473 | */ |
| 6474 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6475 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6476 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6477 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6478 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6479 | |
| 6480 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6481 | /* |
| 6482 | * Reserve a range of host commands for board-specific, experimental, or |
| 6483 | * special purpose features. These can be (re)used without updating this file. |
| 6484 | * |
| 6485 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 6486 | * their EC commands for easier development, testing, debugging, and support. |
| 6487 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6488 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 6489 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 6490 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6491 | * In your experimental code, you may want to do something like this: |
| 6492 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6493 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 6494 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 6495 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 6496 | * |
| 6497 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 6498 | * EC_VER_MASK(0); |
| 6499 | * |
| 6500 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 6501 | * EC_VER_MASK(0); |
| 6502 | * |
| 6503 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 6504 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6505 | */ |
| 6506 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 6507 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 6508 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6509 | /* |
| 6510 | * Given the private host command offset, calculate the true private host |
| 6511 | * command value. |
| 6512 | */ |
| 6513 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 6514 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 6515 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 6516 | /*****************************************************************************/ |
| 6517 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6518 | * Passthru commands |
| 6519 | * |
| 6520 | * Some platforms have sub-processors chained to each other. For example. |
| 6521 | * |
| 6522 | * AP <--> EC <--> PD MCU |
| 6523 | * |
| 6524 | * The top 2 bits of the command number are used to indicate which device the |
| 6525 | * command is intended for. Device 0 is always the device receiving the |
| 6526 | * command; other device mapping is board-specific. |
| 6527 | * |
| 6528 | * When a device receives a command to be passed to a sub-processor, it passes |
| 6529 | * it on with the device number set back to 0. This allows the sub-processor |
| 6530 | * to remain blissfully unaware of whether the command originated on the next |
| 6531 | * device up the chain, or was passed through from the AP. |
| 6532 | * |
| 6533 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 6534 | * AP sends command 0x4002 to the EC |
| 6535 | * EC sends command 0x0002 to the PD MCU |
| 6536 | * EC forwards PD MCU response back to the AP |
| 6537 | */ |
| 6538 | |
| 6539 | /* Offset and max command number for sub-device n */ |
| 6540 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 6541 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 6542 | |
| 6543 | /*****************************************************************************/ |
| 6544 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 6545 | * Deprecated constants. These constants have been renamed for clarity. The |
| 6546 | * meaning and size has not changed. Programs that use the old names should |
| 6547 | * switch to the new names soon, as the old names may not be carried forward |
| 6548 | * forever. |
| 6549 | */ |
| 6550 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 6551 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 6552 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 6553 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6554 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6555 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6556 | #ifdef __cplusplus |
| 6557 | } |
| 6558 | #endif |
| 6559 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6560 | #endif /* __CROS_EC_EC_COMMANDS_H */ |