Patrick Georgi | 593124d | 2020-05-10 19:44:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2 | |
| 3 | /* Host communication command constants for Chrome EC */ |
| 4 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5 | #ifndef __CROS_EC_EC_COMMANDS_H |
| 6 | #define __CROS_EC_EC_COMMANDS_H |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 7 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 8 | #if !defined(__ACPI__) && !defined(__KERNEL__) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #endif |
| 11 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 16 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 17 | /* |
| 18 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 19 | * It is used to not include macros that may cause conflicts in foreign |
| 20 | * projects (refer to crbug.com/984623). |
| 21 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 22 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 25 | * generates more efficient code for accessing request/response structures on |
| 26 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 27 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 28 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 29 | #include "compile_time_macros.h" |
| 30 | |
| 31 | #else |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 32 | /* If BUILD_ASSERT isn't already defined, make it a no-op */ |
| 33 | #ifndef BUILD_ASSERT |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 34 | #define BUILD_ASSERT(_cond) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 35 | #endif /* !BUILD_ASSERT */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 36 | #endif /* CHROMIUM_EC */ |
| 37 | |
| 38 | #ifdef __KERNEL__ |
| 39 | #include <linux/limits.h> |
| 40 | #else |
| 41 | /* |
| 42 | * Defines macros that may be needed but are for sure defined by the linux |
| 43 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 44 | * util/make_linux_ec_commands_h.sh). |
| 45 | * cros_ec_commands.h looks more integrated to the kernel. |
| 46 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 47 | |
| 48 | #ifndef BIT |
| 49 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 50 | #endif |
| 51 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 52 | #ifndef BIT_ULL |
| 53 | #define BIT_ULL(nr) (1ULL << (nr)) |
| 54 | #endif |
| 55 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 56 | /* |
| 57 | * When building Zephyr, this file ends up being included before Zephyr's |
| 58 | * include/sys/util.h so causes a warning there. We don't want to add an #ifdef |
| 59 | * in that file since it won't be accepted upstream. So work around it here. |
| 60 | */ |
| 61 | #ifndef CONFIG_ZEPHYR |
| 62 | #ifndef GENMASK |
| 63 | #define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1)) |
| 64 | #endif |
| 65 | |
| 66 | #ifndef GENMASK_ULL |
| 67 | #define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1)) |
| 68 | #endif |
| 69 | #endif |
| 70 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 71 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 72 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 73 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 74 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 75 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 76 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 77 | * determined in other ways. Remove this once the kernel code no longer |
| 78 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 79 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 80 | #define EC_PROTO_VERSION 0x00000002 |
| 81 | |
| 82 | /* Command version mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 83 | #define EC_VER_MASK(version) BIT(version) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 84 | |
| 85 | /* I/O addresses for ACPI commands */ |
| 86 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 87 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
| 88 | |
| 89 | /* I/O addresses for host command */ |
| 90 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 91 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
| 92 | |
| 93 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 94 | /* Protocol version 2 */ |
| 95 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
| 96 | #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] | 97 | * EC_PROTO2_MAX_PARAM_SIZE |
| 98 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 99 | /* Protocol version 3 */ |
| 100 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 101 | #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] | 102 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 103 | /* |
| 104 | * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 105 | * and they tell the kernel that so we have to think of it as two parts. |
| 106 | */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 107 | #define EC_HOST_CMD_REGION0 0x800 |
| 108 | #define EC_HOST_CMD_REGION1 0x880 |
| 109 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
| 110 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 111 | /* EC command register bit functions */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 112 | #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ |
| 113 | #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ |
| 114 | #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ |
| 115 | #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ |
| 116 | #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ |
| 117 | #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ |
| 118 | #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 119 | |
| 120 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 121 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 122 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
| 123 | |
| 124 | /* The offset address of each type of data in mapped memory. */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 125 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 126 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 127 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 128 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 129 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 130 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 131 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
| 132 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
| 133 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 134 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
| 135 | /* Unused 0x28 - 0x2f */ |
| 136 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
| 137 | /* Unused 0x31 - 0x33 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 138 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ |
| 139 | /* Battery values are all 32 bits, unless otherwise noted. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 140 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 141 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 142 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 143 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ |
| 144 | #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ |
| 145 | #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ |
| 146 | /* Unused 0x4f */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 147 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 148 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 149 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 150 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 151 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 152 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 153 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 154 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 155 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 156 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
| 157 | /* Unused 0x84 - 0x8f */ |
| 158 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
| 159 | /* Unused 0x91 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 160 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
| 161 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 162 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 163 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 164 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 165 | /* Unused 0xa6 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 166 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 167 | /* |
| 168 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 169 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 170 | * which might be needed by ACPI. |
| 171 | */ |
| 172 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 173 | |
| 174 | /* Define the format of the accelerometer mapped memory status byte. */ |
| 175 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 176 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) |
| 177 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 178 | |
| 179 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
| 180 | #define EC_TEMP_SENSOR_ENTRIES 16 |
| 181 | /* |
| 182 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 183 | * |
| 184 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 185 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 186 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 187 | |
| 188 | /* Special values for mapped temperature sensors */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 189 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 190 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 191 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 192 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 193 | /* |
| 194 | * The offset of temperature value stored in mapped memory. This allows |
| 195 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 196 | */ |
| 197 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 198 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 199 | /* |
| 200 | * Number of ALS readings at EC_MEMMAP_ALS |
| 201 | */ |
| 202 | #define EC_ALS_ENTRIES 2 |
| 203 | |
| 204 | /* |
| 205 | * The default value a temperature sensor will return when it is present but |
| 206 | * has not been read this boot. This is a reasonable number to avoid |
| 207 | * triggering alarms on the host. |
| 208 | */ |
| 209 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 210 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 211 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 212 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 213 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 214 | |
| 215 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 216 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 217 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 218 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 219 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 220 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 221 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 222 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 223 | |
| 224 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 225 | #define EC_SWITCH_LID_OPEN 0x01 |
| 226 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 227 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 228 | /* Was recovery requested via keyboard; now unused. */ |
| 229 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 230 | /* Recovery requested via dedicated signal (from servo board) */ |
| 231 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 232 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 233 | #define EC_SWITCH_IGNORE0 0x20 |
| 234 | |
| 235 | /* Host command interface flags */ |
| 236 | /* Host command interface supports LPC args (LPC interface only) */ |
| 237 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 238 | /* Host command interface supports version 3 protocol */ |
| 239 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 240 | |
| 241 | /* Wireless switch flags */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 242 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 243 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 244 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 245 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 246 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 247 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 248 | /*****************************************************************************/ |
| 249 | /* |
| 250 | * ACPI commands |
| 251 | * |
| 252 | * These are valid ONLY on the ACPI command/data port. |
| 253 | */ |
| 254 | |
| 255 | /* |
| 256 | * ACPI Read Embedded Controller |
| 257 | * |
| 258 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 259 | * |
| 260 | * Use the following sequence: |
| 261 | * |
| 262 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 263 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 264 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 265 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 266 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 267 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 268 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * ACPI Write Embedded Controller |
| 272 | * |
| 273 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 274 | * |
| 275 | * Use the following sequence: |
| 276 | * |
| 277 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 278 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 279 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 280 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 281 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 282 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 283 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * ACPI Burst Enable Embedded Controller |
| 287 | * |
| 288 | * This enables burst mode on the EC to allow the host to issue several |
| 289 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 290 | * data are locked out to ensure data consistency. |
| 291 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 292 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * ACPI Burst Disable Embedded Controller |
| 296 | * |
| 297 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 298 | * multi-byte data. |
| 299 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 300 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * ACPI Query Embedded Controller |
| 304 | * |
| 305 | * This clears the lowest-order bit in the currently pending host events, and |
| 306 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 307 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 308 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 309 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 310 | |
| 311 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 312 | |
| 313 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 314 | #define EC_ACPI_MEM_VERSION 0x00 |
| 315 | /* |
| 316 | * Test location; writing value here updates test compliment byte to (0xff - |
| 317 | * value). |
| 318 | */ |
| 319 | #define EC_ACPI_MEM_TEST 0x01 |
| 320 | /* Test compliment; writes here are ignored. */ |
| 321 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
| 322 | |
| 323 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 324 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 325 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 326 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 327 | |
| 328 | /* |
| 329 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 330 | * independent thresholds attached to them. The current value of the ID |
| 331 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 332 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 333 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 334 | * |
| 335 | * The spec does not mandate any way to read back the threshold settings |
| 336 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 337 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 338 | * returns one sensor ID that has crossed one of its threshold (in either |
| 339 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 340 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 341 | * the unread event count for that sensor. |
| 342 | */ |
| 343 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 344 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 345 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 346 | /* |
| 347 | * Here are the bits for the COMMIT register: |
| 348 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 349 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 350 | * Each write to the commit register affects one threshold. |
| 351 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 352 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 353 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 354 | /* |
| 355 | * Example: |
| 356 | * |
| 357 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 358 | * write 2 to [0x05] -- select temp sensor 2 |
| 359 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 360 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 361 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 362 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 363 | * |
| 364 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 365 | * write 2 to [0x05] -- select temp sensor 2 |
| 366 | * write 0x1 to [0x07] -- disable threshold 1 |
| 367 | */ |
| 368 | |
| 369 | /* DPTF battery charging current limit */ |
| 370 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 371 | |
| 372 | /* Charging limit is specified in 64 mA steps */ |
| 373 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 374 | /* Value to disable DPTF battery charging limit */ |
| 375 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 376 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 377 | /* |
| 378 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 379 | * Bits Definition |
| 380 | * 3:1 Device DPTF Profile Number (DDPN) |
| 381 | * 0 = Reserved for backward compatibility (indicates no valid |
| 382 | * profile number. Host should fall back to using TBMD). |
| 383 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 384 | * to be loaded. |
| 385 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 386 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 387 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 388 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 389 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 390 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 391 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 392 | |
| 393 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 394 | * Report device features. Uses the same format as the host command, except: |
| 395 | * |
| 396 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 397 | * of features", which is of limited interest when the system is already |
| 398 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 399 | * these are supported, it defaults to 0. |
| 400 | * This allows detecting the presence of this field since older versions of |
| 401 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 402 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 403 | * are valid. |
| 404 | */ |
| 405 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 406 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 407 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 408 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 409 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 410 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 411 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 412 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 413 | |
| 414 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
| 415 | |
| 416 | /* |
| 417 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 418 | * is enabled (1) or disabled (0). |
| 419 | * bit 0 USB port ID 0 |
| 420 | * ... |
| 421 | * bit 7 USB port ID 7 |
| 422 | */ |
| 423 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 424 | |
| 425 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 426 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 427 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 428 | */ |
| 429 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 430 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 431 | |
| 432 | /* Current version of ACPI memory address space */ |
| 433 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 434 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 435 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 436 | /* |
| 437 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 438 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 439 | * handle actual C code so keep it separate. |
| 440 | */ |
| 441 | #ifndef __ACPI__ |
| 442 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 443 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 444 | /* |
| 445 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 446 | * checking prefers __packed over __attribute__((packed)). |
| 447 | */ |
| 448 | #ifndef __packed |
| 449 | #define __packed __attribute__((packed)) |
| 450 | #endif |
| 451 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 452 | #ifndef __aligned |
| 453 | #define __aligned(x) __attribute__((aligned(x))) |
| 454 | #endif |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 455 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 456 | |
| 457 | /* |
| 458 | * Attributes for EC request and response packets. Just defining __packed |
| 459 | * results in inefficient assembly code on ARM, if the structure is actually |
| 460 | * 32-bit aligned, as it should be for all buffers. |
| 461 | * |
| 462 | * Be very careful when adding these to existing structures. They will round |
| 463 | * up the structure size to the specified boundary. |
| 464 | * |
| 465 | * Also be very careful to make that if a structure is included in some other |
| 466 | * parent structure that the alignment will still be true given the packing of |
| 467 | * the parent structure. This is particularly important if the sub-structure |
| 468 | * 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] | 469 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 470 | * |
| 471 | * Also be very careful using __packed - particularly when nesting non-packed |
| 472 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 473 | * always use one of these attributes. |
| 474 | * |
| 475 | * Once everything is annotated properly, the following search strings should |
| 476 | * not return ANY matches in this file other than right here: |
| 477 | * |
| 478 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 479 | * |
| 480 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 481 | * members of other structs/unions (and their original declarations should be |
| 482 | * annotated). |
| 483 | */ |
| 484 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 485 | |
| 486 | /* |
| 487 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 488 | * byte boundary. |
| 489 | */ |
| 490 | #define __ec_align1 __packed |
| 491 | #define __ec_align2 __packed __aligned(2) |
| 492 | #define __ec_align4 __packed __aligned(4) |
| 493 | |
| 494 | /* |
| 495 | * Packed structure which must be under-aligned, because its size is not a |
| 496 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 497 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 498 | * |
| 499 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 500 | * its members, but use the __packed version for sizeof(). |
| 501 | */ |
| 502 | #define __ec_align_size1 __packed |
| 503 | |
| 504 | /* |
| 505 | * Packed structure which must be under-aligned, because its offset inside a |
| 506 | * parent structure is not a 4-byte multiple. |
| 507 | */ |
| 508 | #define __ec_align_offset1 __packed |
| 509 | #define __ec_align_offset2 __packed __aligned(2) |
| 510 | |
| 511 | /* |
| 512 | * Structures which are complicated enough that I'm skipping them on the first |
| 513 | * pass. They are effectively unchanged from their previous definitions. |
| 514 | * |
| 515 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 516 | * to work out the size and offset of each member and add explicit padding to |
| 517 | * maintain those. |
| 518 | */ |
| 519 | #define __ec_todo_packed __packed |
| 520 | #define __ec_todo_unpacked |
| 521 | |
| 522 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
| 523 | |
| 524 | /* |
| 525 | * Packed structures make no assumption about alignment, so they do inefficient |
| 526 | * byte-wise reads. |
| 527 | */ |
| 528 | #define __ec_align1 __packed |
| 529 | #define __ec_align2 __packed |
| 530 | #define __ec_align4 __packed |
| 531 | #define __ec_align_size1 __packed |
| 532 | #define __ec_align_offset1 __packed |
| 533 | #define __ec_align_offset2 __packed |
| 534 | #define __ec_todo_packed __packed |
| 535 | #define __ec_todo_unpacked |
| 536 | |
| 537 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
| 538 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 539 | /* LPC command status byte masks */ |
| 540 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 541 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 542 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 543 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 544 | /* EC is processing a command */ |
| 545 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 546 | /* Last write to EC was a command, not data */ |
| 547 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 548 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 549 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 550 | /* SCI event is pending (requesting SCI query) */ |
| 551 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 552 | /* SMI event is pending (requesting SMI query) */ |
| 553 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 554 | /* (reserved) */ |
| 555 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 556 | |
| 557 | /* |
| 558 | * EC is busy. This covers both the EC processing a command, and the host has |
| 559 | * written a new command but the EC hasn't picked it up yet. |
| 560 | */ |
| 561 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 562 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 563 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 564 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 565 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 566 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 567 | enum ec_status { |
| 568 | EC_RES_SUCCESS = 0, |
| 569 | EC_RES_INVALID_COMMAND = 1, |
| 570 | EC_RES_ERROR = 2, |
| 571 | EC_RES_INVALID_PARAM = 3, |
| 572 | EC_RES_ACCESS_DENIED = 4, |
| 573 | EC_RES_INVALID_RESPONSE = 5, |
| 574 | EC_RES_INVALID_VERSION = 6, |
| 575 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 576 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 577 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 578 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 579 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 580 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 581 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 582 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 583 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 584 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 585 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 586 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 587 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 588 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 589 | |
| 590 | EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ |
| 591 | } __packed; |
| 592 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 593 | |
| 594 | /* |
| 595 | * Host event codes. Note these are 1-based, not 0-based, because ACPI query |
| 596 | * EC command uses code 0 to mean "no event pending". We explicitly specify |
| 597 | * each value in the enum listing so they won't change if we delete/insert an |
| 598 | * item or rearrange the list (it needs to be stable across platforms, not |
| 599 | * just within a single compiled instance). |
| 600 | */ |
| 601 | enum host_event_code { |
| 602 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 603 | EC_HOST_EVENT_LID_OPEN = 2, |
| 604 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 605 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 606 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 607 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 608 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 609 | EC_HOST_EVENT_BATTERY = 8, |
| 610 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 611 | /* Event generated by a device attached to the EC */ |
| 612 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 613 | EC_HOST_EVENT_THERMAL = 11, |
| 614 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 615 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 616 | /* |
| 617 | * EC has finished initializing the host interface. The host can check |
| 618 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 619 | * determine when the EC is ready to accept subsequent commands. |
| 620 | */ |
| 621 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 622 | /* Keyboard recovery combo has been pressed */ |
| 623 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 624 | |
| 625 | /* Shutdown due to thermal overload */ |
| 626 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 627 | /* Shutdown due to battery level too low */ |
| 628 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 629 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 630 | /* Suggest that the AP throttle itself */ |
| 631 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 632 | /* Suggest that the AP resume normal speed */ |
| 633 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 634 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 635 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 636 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 637 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 638 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 639 | |
| 640 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 641 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 642 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 643 | /* Battery Status flags have changed */ |
| 644 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 645 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 646 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 647 | EC_HOST_EVENT_PANIC = 24, |
| 648 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 649 | /* Keyboard fastboot combo has been pressed */ |
| 650 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 651 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 652 | /* EC RTC event occurred */ |
| 653 | EC_HOST_EVENT_RTC = 26, |
| 654 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 655 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 656 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 657 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 658 | /* EC desires to change state of host-controlled USB mux */ |
| 659 | EC_HOST_EVENT_USB_MUX = 28, |
| 660 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 661 | /* |
| 662 | * The device has changed "modes". This can be one of the following: |
| 663 | * |
| 664 | * - TABLET/LAPTOP mode |
| 665 | * - detachable base attach/detach event |
| 666 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 667 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 668 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 669 | /* Keyboard recovery combo with hardware reinitialization */ |
| 670 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 671 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 672 | /* WoV */ |
| 673 | EC_HOST_EVENT_WOV = 31, |
| 674 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 675 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 676 | * The high bit of the event mask is not used as a host event code. If |
| 677 | * it reads back as set, then the entire event mask should be |
| 678 | * considered invalid by the host. This can happen when reading the |
| 679 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 680 | * not initialized on the EC, or improperly configured on the host. |
| 681 | */ |
| 682 | EC_HOST_EVENT_INVALID = 32 |
| 683 | }; |
| 684 | /* Host event mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 685 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 686 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 687 | /** |
| 688 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 689 | * @flags: The host argument flags. |
| 690 | * @command_version: Command version. |
| 691 | * @data_size: The length of data. |
| 692 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 693 | * all params/response data bytes. |
| 694 | */ |
| 695 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 696 | uint8_t flags; |
| 697 | uint8_t command_version; |
| 698 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 699 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 700 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 701 | |
| 702 | /* Flags for ec_lpc_host_args.flags */ |
| 703 | /* |
| 704 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 705 | * params. |
| 706 | * |
| 707 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 708 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 709 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 710 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 711 | */ |
| 712 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 713 | /* |
| 714 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 715 | * |
| 716 | * If EC responds to a command and this flag is not set, this is an old-style |
| 717 | * response. Command version is 0 and response data from EC is at |
| 718 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 719 | */ |
| 720 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 721 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 722 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 723 | /* |
| 724 | * Byte codes returned by EC over SPI interface. |
| 725 | * |
| 726 | * These can be used by the AP to debug the EC interface, and to determine |
| 727 | * when the EC is not in a state where it will ever get around to responding |
| 728 | * to the AP. |
| 729 | * |
| 730 | * Example of sequence of bytes read from EC for a current good transfer: |
| 731 | * 1. - - AP asserts chip select (CS#) |
| 732 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 733 | * 3. - - EC starts handling CS# interrupt |
| 734 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 735 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 736 | * bytes looking for EC_SPI_FRAME_START |
| 737 | * 6. - - EC finishes processing and sets up response |
| 738 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 739 | * 8. (response packet) - AP reads response packet |
| 740 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 741 | * 10 - - AP deasserts chip select |
| 742 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 743 | * next request |
| 744 | * |
| 745 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 746 | * the following byte values: |
| 747 | * EC_SPI_OLD_READY |
| 748 | * EC_SPI_RX_READY |
| 749 | * EC_SPI_RECEIVING |
| 750 | * EC_SPI_PROCESSING |
| 751 | * |
| 752 | * Then the EC found an error in the request, or was not ready for the request |
| 753 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 754 | * because the EC is unable to tell when the AP is done sending its request. |
| 755 | */ |
| 756 | |
| 757 | /* |
| 758 | * Framing byte which precedes a response packet from the EC. After sending a |
| 759 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 760 | * clock in the response packet. |
| 761 | */ |
| 762 | #define EC_SPI_FRAME_START 0xec |
| 763 | |
| 764 | /* |
| 765 | * Padding bytes which are clocked out after the end of a response packet. |
| 766 | */ |
| 767 | #define EC_SPI_PAST_END 0xed |
| 768 | |
| 769 | /* |
| 770 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 771 | * that the AP will send a valid packet header (starting with |
| 772 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 773 | */ |
| 774 | #define EC_SPI_RX_READY 0xf8 |
| 775 | |
| 776 | /* |
| 777 | * EC has started receiving the request from the AP, but hasn't started |
| 778 | * processing it yet. |
| 779 | */ |
| 780 | #define EC_SPI_RECEIVING 0xf9 |
| 781 | |
| 782 | /* EC has received the entire request from the AP and is processing it. */ |
| 783 | #define EC_SPI_PROCESSING 0xfa |
| 784 | |
| 785 | /* |
| 786 | * EC received bad data from the AP, such as a packet header with an invalid |
| 787 | * length. EC will ignore all data until chip select deasserts. |
| 788 | */ |
| 789 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 790 | |
| 791 | /* |
| 792 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 793 | * chip select and started clocking data before the EC was ready to receive it. |
| 794 | * EC will ignore all data until chip select deasserts. |
| 795 | */ |
| 796 | #define EC_SPI_NOT_READY 0xfc |
| 797 | |
| 798 | /* |
| 799 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 800 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 801 | * a fully received packet but is not ready to respond yet. |
| 802 | */ |
| 803 | #define EC_SPI_OLD_READY 0xfd |
| 804 | |
| 805 | /*****************************************************************************/ |
| 806 | |
| 807 | /* |
| 808 | * Protocol version 2 for I2C and SPI send a request this way: |
| 809 | * |
| 810 | * 0 EC_CMD_VERSION0 + (command version) |
| 811 | * 1 Command number |
| 812 | * 2 Length of params = N |
| 813 | * 3..N+2 Params, if any |
| 814 | * N+3 8-bit checksum of bytes 0..N+2 |
| 815 | * |
| 816 | * The corresponding response is: |
| 817 | * |
| 818 | * 0 Result code (EC_RES_*) |
| 819 | * 1 Length of params = M |
| 820 | * 2..M+1 Params, if any |
| 821 | * M+2 8-bit checksum of bytes 0..M+1 |
| 822 | */ |
| 823 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 824 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 825 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 826 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 827 | |
| 828 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 829 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 830 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 831 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 832 | |
| 833 | /* Parameter length was limited by the LPC interface */ |
| 834 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 835 | |
| 836 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 837 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 838 | EC_PROTO2_MAX_PARAM_SIZE) |
| 839 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 840 | EC_PROTO2_MAX_PARAM_SIZE) |
| 841 | |
| 842 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * Value written to legacy command port / prefix byte to indicate protocol |
| 846 | * 3+ structs are being used. Usage is bus-dependent. |
| 847 | */ |
| 848 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 849 | |
| 850 | #define EC_HOST_REQUEST_VERSION 3 |
| 851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 852 | /** |
| 853 | * struct ec_host_request - Version 3 request from host. |
| 854 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 855 | * receives a header with a version it doesn't know how to |
| 856 | * parse. |
| 857 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 858 | * should total to 0. |
| 859 | * @command: Command to send (EC_CMD_...) |
| 860 | * @command_version: Command version. |
| 861 | * @reserved: Unused byte in current protocol version; set to 0. |
| 862 | * @data_len: Length of data which follows this header. |
| 863 | */ |
| 864 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 865 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 866 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 867 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 868 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 869 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 870 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 871 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 872 | |
| 873 | #define EC_HOST_RESPONSE_VERSION 3 |
| 874 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 875 | /** |
| 876 | * struct ec_host_response - Version 3 response from EC. |
| 877 | * @struct_version: Struct version (=3). |
| 878 | * @checksum: Checksum of response and data; sum of all bytes including |
| 879 | * checksum should total to 0. |
| 880 | * @result: EC's response to the command (separate from communication failure) |
| 881 | * @data_len: Length of data which follows this header. |
| 882 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 883 | */ |
| 884 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 885 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 886 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 887 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 888 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 889 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 890 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 891 | |
| 892 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * Host command protocol V4. |
| 896 | * |
| 897 | * Packets always start with a request or response header. They are followed |
| 898 | * by data_len bytes of data. If the data_crc_present flag is set, the data |
| 899 | * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1 |
| 900 | * polynomial. |
| 901 | * |
| 902 | * Host algorithm when sending a request q: |
| 903 | * |
| 904 | * 101) tries_left=(some value, e.g. 3); |
| 905 | * 102) q.seq_num++ |
| 906 | * 103) q.seq_dup=0 |
| 907 | * 104) Calculate q.header_crc. |
| 908 | * 105) Send request q to EC. |
| 909 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 910 | * |
| 911 | * 201) If r.struct_version != 4, go to 301. |
| 912 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 913 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 914 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 915 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 916 | * 207) If r.seq_dup == 1, go to 301. |
| 917 | * 208) Return error. |
| 918 | * |
| 919 | * 301) If --tries_left <= 0, return error. |
| 920 | * 302) If q.seq_dup == 1, go to 105. |
| 921 | * 303) q.seq_dup = 1 |
| 922 | * 304) Go to 104. |
| 923 | * |
| 924 | * EC algorithm when receiving a request q. |
| 925 | * EC has response buffer r, error buffer e. |
| 926 | * |
| 927 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 928 | * and go to 301 |
| 929 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 930 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 931 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 932 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 933 | * and go to 301. |
| 934 | * 104) If q.seq_dup == 0, go to 201. |
| 935 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 936 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 937 | * |
| 938 | * 201) Process request q into response r. |
| 939 | * 202) r.seq_num = q.seq_num |
| 940 | * 203) r.seq_dup = q.seq_dup |
| 941 | * 204) Calculate r.header_crc |
| 942 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 943 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 944 | * 206) Send response r. |
| 945 | * |
| 946 | * 301) e.seq_num = q.seq_num |
| 947 | * 302) e.seq_dup = q.seq_dup |
| 948 | * 303) Calculate e.header_crc. |
| 949 | * 304) Send error response e. |
| 950 | */ |
| 951 | |
| 952 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 953 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 954 | /* |
| 955 | * bits 0-3: struct_version: Structure version (=4) |
| 956 | * bit 4: is_response: Is response (=0) |
| 957 | * bits 5-6: seq_num: Sequence number |
| 958 | * bit 7: seq_dup: Sequence duplicate flag |
| 959 | */ |
| 960 | uint8_t fields0; |
| 961 | |
| 962 | /* |
| 963 | * bits 0-4: command_version: Command version |
| 964 | * bits 5-6: Reserved (set 0, ignore on read) |
| 965 | * bit 7: data_crc_present: Is data CRC present after data |
| 966 | */ |
| 967 | uint8_t fields1; |
| 968 | |
| 969 | /* Command code (EC_CMD_*) */ |
| 970 | uint16_t command; |
| 971 | |
| 972 | /* Length of data which follows this header (not including data CRC) */ |
| 973 | uint16_t data_len; |
| 974 | |
| 975 | /* Reserved (set 0, ignore on read) */ |
| 976 | uint8_t reserved; |
| 977 | |
| 978 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 979 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 980 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 981 | |
| 982 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 983 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 984 | /* |
| 985 | * bits 0-3: struct_version: Structure version (=4) |
| 986 | * bit 4: is_response: Is response (=1) |
| 987 | * bits 5-6: seq_num: Sequence number |
| 988 | * bit 7: seq_dup: Sequence duplicate flag |
| 989 | */ |
| 990 | uint8_t fields0; |
| 991 | |
| 992 | /* |
| 993 | * bits 0-6: Reserved (set 0, ignore on read) |
| 994 | * bit 7: data_crc_present: Is data CRC present after data |
| 995 | */ |
| 996 | uint8_t fields1; |
| 997 | |
| 998 | /* Result code (EC_RES_*) */ |
| 999 | uint16_t result; |
| 1000 | |
| 1001 | /* Length of data which follows this header (not including data CRC) */ |
| 1002 | uint16_t data_len; |
| 1003 | |
| 1004 | /* Reserved (set 0, ignore on read) */ |
| 1005 | uint8_t reserved; |
| 1006 | |
| 1007 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1008 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1009 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1010 | |
| 1011 | /* Fields in fields0 byte */ |
| 1012 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1013 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1014 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1015 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1016 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
| 1017 | |
| 1018 | /* Fields in fields1 byte */ |
| 1019 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1020 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
| 1021 | |
| 1022 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1023 | /* |
| 1024 | * Notes on commands: |
| 1025 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1026 | * 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] | 1027 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1028 | * specified, the command does not input or output data, respectively. |
| 1029 | * Parameter/response length is implicit in the structs. Some underlying |
| 1030 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1031 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1032 | * |
| 1033 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1034 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1035 | */ |
| 1036 | |
| 1037 | /*****************************************************************************/ |
| 1038 | /* General / test commands */ |
| 1039 | |
| 1040 | /* |
| 1041 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1042 | * changes. |
| 1043 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1044 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1045 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1046 | /** |
| 1047 | * struct ec_response_proto_version - Response to the proto version command. |
| 1048 | * @version: The protocol version. |
| 1049 | */ |
| 1050 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1051 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1052 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Hello. This is a simple command to test the EC is responsive to |
| 1056 | * commands. |
| 1057 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1058 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1059 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1060 | /** |
| 1061 | * struct ec_params_hello - Parameters to the hello command. |
| 1062 | * @in_data: Pass anything here. |
| 1063 | */ |
| 1064 | struct ec_params_hello { |
| 1065 | uint32_t in_data; |
| 1066 | } __ec_align4; |
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_response_hello - Response to the hello command. |
| 1070 | * @out_data: Output will be in_data + 0x01020304. |
| 1071 | */ |
| 1072 | struct ec_response_hello { |
| 1073 | uint32_t out_data; |
| 1074 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1075 | |
| 1076 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1077 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1078 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1079 | #if !defined(CHROMIUM_EC) && !defined(__KERNEL__) |
| 1080 | /* |
| 1081 | * enum ec_current_image is deprecated and replaced by enum ec_image. This |
| 1082 | * macro exists for backwards compatibility of external projects until they |
| 1083 | * have been updated: b/149987779. |
| 1084 | */ |
| 1085 | #define ec_current_image ec_image |
| 1086 | #endif |
| 1087 | |
| 1088 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1089 | EC_IMAGE_UNKNOWN = 0, |
| 1090 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1091 | EC_IMAGE_RW, |
| 1092 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1093 | EC_IMAGE_RO_B, |
| 1094 | EC_IMAGE_RW_B |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1095 | }; |
| 1096 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1097 | /** |
| 1098 | * struct ec_response_get_version - Response to the get version command. |
| 1099 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1100 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1101 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1102 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1103 | */ |
| 1104 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1105 | char version_string_ro[32]; |
| 1106 | char version_string_rw[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1107 | char reserved[32]; |
| 1108 | uint32_t current_image; |
| 1109 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1110 | |
| 1111 | /* Read test */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1112 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1113 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1114 | /** |
| 1115 | * struct ec_params_read_test - Parameters for the read test command. |
| 1116 | * @offset: Starting value for read buffer. |
| 1117 | * @size: Size to read in bytes. |
| 1118 | */ |
| 1119 | struct ec_params_read_test { |
| 1120 | uint32_t offset; |
| 1121 | uint32_t size; |
| 1122 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1123 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1124 | /** |
| 1125 | * struct ec_response_read_test - Response to the read test command. |
| 1126 | * @data: Data returned by the read test command. |
| 1127 | */ |
| 1128 | struct ec_response_read_test { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1129 | uint32_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1130 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * Get build information |
| 1134 | * |
| 1135 | * Response is null-terminated string. |
| 1136 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1137 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1138 | |
| 1139 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1140 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1141 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1142 | /** |
| 1143 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1144 | * @vendor: Null-terminated string for chip vendor. |
| 1145 | * @name: Null-terminated string for chip name. |
| 1146 | * @revision: Null-terminated string for chip mask version. |
| 1147 | */ |
| 1148 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1149 | char vendor[32]; |
| 1150 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1151 | char revision[32]; |
| 1152 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1153 | |
| 1154 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1155 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1156 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1157 | /** |
| 1158 | * struct ec_response_board_version - Response to the board version command. |
| 1159 | * @board_version: A monotonously incrementing number. |
| 1160 | */ |
| 1161 | struct ec_response_board_version { |
| 1162 | uint16_t board_version; |
| 1163 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1164 | |
| 1165 | /* |
| 1166 | * Read memory-mapped data. |
| 1167 | * |
| 1168 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1169 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1170 | * |
| 1171 | * Response is params.size bytes of data. |
| 1172 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1173 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1174 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1175 | /** |
| 1176 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1177 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1178 | * @size: Size to read in bytes. |
| 1179 | */ |
| 1180 | struct ec_params_read_memmap { |
| 1181 | uint8_t offset; |
| 1182 | uint8_t size; |
| 1183 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1184 | |
| 1185 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1186 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1187 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1188 | /** |
| 1189 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1190 | * @cmd: Command to check. |
| 1191 | */ |
| 1192 | struct ec_params_get_cmd_versions { |
| 1193 | uint8_t cmd; |
| 1194 | } __ec_align1; |
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_v1 - Parameters for the get command |
| 1198 | * versions (v1) |
| 1199 | * @cmd: Command to check. |
| 1200 | */ |
| 1201 | struct ec_params_get_cmd_versions_v1 { |
| 1202 | uint16_t cmd; |
| 1203 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1204 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1205 | /** |
| 1206 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1207 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1208 | * a desired version. |
| 1209 | */ |
| 1210 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1211 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1212 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1213 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1214 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1215 | * 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] | 1216 | * on lpc since it has its own out-of-band busy indicator. |
| 1217 | * |
| 1218 | * lpc must read the status from the command register. Attempting this on |
| 1219 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1220 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1221 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* Avoid using ec_status which is for return values */ |
| 1224 | enum ec_comms_status { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1225 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1226 | }; |
| 1227 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1228 | /** |
| 1229 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1230 | * command. |
| 1231 | * @flags: Mask of enum ec_comms_status. |
| 1232 | */ |
| 1233 | struct ec_response_get_comms_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1234 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1235 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1236 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1237 | /* Fake a variety of responses, purely for testing purposes. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1238 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1239 | |
| 1240 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1241 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1242 | uint32_t ec_result; |
| 1243 | uint32_t ret_len; |
| 1244 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1245 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1246 | |
| 1247 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1248 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1249 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1250 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1251 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1252 | /* Get protocol information */ |
| 1253 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1254 | |
| 1255 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1256 | /* 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] | 1257 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1258 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1259 | /** |
| 1260 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1261 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1262 | * version n). |
| 1263 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1264 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1265 | * @flags: see EC_PROTOCOL_INFO_* |
| 1266 | */ |
| 1267 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1268 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1269 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1270 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1271 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1272 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1273 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1274 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1275 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1276 | /*****************************************************************************/ |
| 1277 | /* Get/Set miscellaneous values */ |
| 1278 | |
| 1279 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 1280 | #define EC_GSV_SET 0x80000000 |
| 1281 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1282 | /* |
| 1283 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1284 | * meaning for an individual command. |
| 1285 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1286 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1287 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1288 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1289 | uint32_t flags; |
| 1290 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1291 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1292 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1293 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1294 | uint32_t flags; |
| 1295 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1296 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1297 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1298 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1299 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1300 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1301 | /*****************************************************************************/ |
| 1302 | /* List the features supported by the firmware */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1303 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1304 | |
| 1305 | /* Supported features */ |
| 1306 | enum ec_feature_code { |
| 1307 | /* |
| 1308 | * This image contains a limited set of features. Another image |
| 1309 | * in RW partition may support more features. |
| 1310 | */ |
| 1311 | EC_FEATURE_LIMITED = 0, |
| 1312 | /* |
| 1313 | * Commands for probing/reading/writing/erasing the flash in the |
| 1314 | * EC are present. |
| 1315 | */ |
| 1316 | EC_FEATURE_FLASH = 1, |
| 1317 | /* |
| 1318 | * Can control the fan speed directly. |
| 1319 | */ |
| 1320 | EC_FEATURE_PWM_FAN = 2, |
| 1321 | /* |
| 1322 | * Can control the intensity of the keyboard backlight. |
| 1323 | */ |
| 1324 | EC_FEATURE_PWM_KEYB = 3, |
| 1325 | /* |
| 1326 | * Support Google lightbar, introduced on Pixel. |
| 1327 | */ |
| 1328 | EC_FEATURE_LIGHTBAR = 4, |
| 1329 | /* Control of LEDs */ |
| 1330 | EC_FEATURE_LED = 5, |
| 1331 | /* Exposes an interface to control gyro and sensors. |
| 1332 | * The host goes through the EC to access these sensors. |
| 1333 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1334 | */ |
| 1335 | EC_FEATURE_MOTION_SENSE = 6, |
| 1336 | /* The keyboard is controlled by the EC */ |
| 1337 | EC_FEATURE_KEYB = 7, |
| 1338 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1339 | EC_FEATURE_PSTORE = 8, |
| 1340 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1341 | EC_FEATURE_PORT80 = 9, |
| 1342 | /* |
| 1343 | * Thermal management: include TMP specific commands. |
| 1344 | * Higher level than direct fan control. |
| 1345 | */ |
| 1346 | EC_FEATURE_THERMAL = 10, |
| 1347 | /* Can switch the screen backlight on/off */ |
| 1348 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1349 | /* Can switch the wifi module on/off */ |
| 1350 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1351 | /* Monitor host events, through for example SMI or SCI */ |
| 1352 | EC_FEATURE_HOST_EVENTS = 13, |
| 1353 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1354 | EC_FEATURE_GPIO = 14, |
| 1355 | /* The EC can send i2c messages to downstream devices. */ |
| 1356 | EC_FEATURE_I2C = 15, |
| 1357 | /* Command to control charger are included */ |
| 1358 | EC_FEATURE_CHARGER = 16, |
| 1359 | /* Simple battery support. */ |
| 1360 | EC_FEATURE_BATTERY = 17, |
| 1361 | /* |
| 1362 | * Support Smart battery protocol |
| 1363 | * (Common Smart Battery System Interface Specification) |
| 1364 | */ |
| 1365 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1366 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1367 | EC_FEATURE_HANG_DETECT = 19, |
| 1368 | /* Report power information, for pit only */ |
| 1369 | EC_FEATURE_PMU = 20, |
| 1370 | /* Another Cros EC device is present downstream of this one */ |
| 1371 | EC_FEATURE_SUB_MCU = 21, |
| 1372 | /* Support USB Power delivery (PD) commands */ |
| 1373 | EC_FEATURE_USB_PD = 22, |
| 1374 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1375 | EC_FEATURE_USB_MUX = 23, |
| 1376 | /* Motion Sensor code has an internal software FIFO */ |
| 1377 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1378 | /* Support temporary secure vstore */ |
| 1379 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1380 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1381 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1382 | /* EC has RTC feature that can be controlled by host commands */ |
| 1383 | EC_FEATURE_RTC = 27, |
| 1384 | /* The MCU exposes a Fingerprint sensor */ |
| 1385 | EC_FEATURE_FINGERPRINT = 28, |
| 1386 | /* The MCU exposes a Touchpad */ |
| 1387 | EC_FEATURE_TOUCHPAD = 29, |
| 1388 | /* The MCU has RWSIG task enabled */ |
| 1389 | EC_FEATURE_RWSIG = 30, |
| 1390 | /* EC has device events support */ |
| 1391 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1392 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1393 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1394 | /* EC supports 64-bit host events */ |
| 1395 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1396 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1397 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1398 | /* EC supports CEC commands */ |
| 1399 | EC_FEATURE_CEC = 35, |
| 1400 | /* EC supports tight sensor timestamping. */ |
| 1401 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1402 | /* |
| 1403 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1404 | * setting of threshold by host command using |
| 1405 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1406 | */ |
| 1407 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1408 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 1409 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1410 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1411 | * be sent to RO to be precise. |
| 1412 | */ |
| 1413 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1414 | /* The MCU is a System Companion Processor (SCP). */ |
| 1415 | EC_FEATURE_SCP = 39, |
| 1416 | /* The MCU is an Integrated Sensor Hub */ |
| 1417 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 1418 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1419 | EC_FEATURE_TYPEC_CMD = 41, |
| 1420 | /* |
| 1421 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1422 | * modes or USB4. |
| 1423 | */ |
| 1424 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1425 | /* |
| 1426 | * The EC will wait for an acknowledge from the AP after setting the |
| 1427 | * mux. |
| 1428 | */ |
| 1429 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1430 | }; |
| 1431 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1432 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1433 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1434 | |
| 1435 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1436 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1437 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1438 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1439 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1440 | /* Get the board's SKU ID from EC */ |
| 1441 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1442 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1443 | /* Set SKU ID from AP */ |
| 1444 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1445 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1446 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1447 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1448 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1449 | |
| 1450 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1451 | /* Flash commands */ |
| 1452 | |
| 1453 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1454 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1455 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1456 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1457 | /** |
| 1458 | * struct ec_response_flash_info - Response to the flash info command. |
| 1459 | * @flash_size: Usable flash size in bytes. |
| 1460 | * @write_block_size: Write block size. Write offset and size must be a |
| 1461 | * multiple of this. |
| 1462 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1463 | * multiple of this. |
| 1464 | * @protect_block_size: Protection block size. Protection offset and size |
| 1465 | * must be a multiple of this. |
| 1466 | * |
| 1467 | * Version 0 returns these fields. |
| 1468 | */ |
| 1469 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1470 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1471 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1472 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1473 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1474 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1475 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1476 | /* |
| 1477 | * Flags for version 1+ flash info command |
| 1478 | * EC flash erases bits to 0 instead of 1. |
| 1479 | */ |
| 1480 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1481 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1482 | /* |
| 1483 | * 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] | 1484 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1485 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1486 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1487 | * chip functionality. |
| 1488 | */ |
| 1489 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1490 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1491 | /** |
| 1492 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1493 | * @flash_size: Usable flash size in bytes. |
| 1494 | * @write_block_size: Write block size. Write offset and size must be a |
| 1495 | * multiple of this. |
| 1496 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1497 | * multiple of this. |
| 1498 | * @protect_block_size: Protection block size. Protection offset and size |
| 1499 | * must be a multiple of this. |
| 1500 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1501 | * size is exactly this and offset is a multiple of this. |
| 1502 | * For example, an EC may have a write buffer which can do |
| 1503 | * half-page operations if data is aligned, and a slower |
| 1504 | * word-at-a-time write mode. |
| 1505 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1506 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1507 | * Version 1 returns the same initial fields as version 0, with additional |
| 1508 | * fields following. |
| 1509 | * |
| 1510 | * 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] | 1511 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1512 | * one. |
| 1513 | * |
| 1514 | * Version 2 supports flash banks of different sizes: |
| 1515 | * The caller specified the number of banks it has preallocated |
| 1516 | * (num_banks_desc) |
| 1517 | * The EC returns the number of banks describing the flash memory. |
| 1518 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1519 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1520 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1521 | /* Version 0 fields; see above for description */ |
| 1522 | uint32_t flash_size; |
| 1523 | uint32_t write_block_size; |
| 1524 | uint32_t erase_block_size; |
| 1525 | uint32_t protect_block_size; |
| 1526 | |
| 1527 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1528 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1529 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1530 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1531 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1532 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1533 | /* Number of banks to describe */ |
| 1534 | uint16_t num_banks_desc; |
| 1535 | /* Reserved; set 0; ignore on read */ |
| 1536 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1537 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1538 | |
| 1539 | struct ec_flash_bank { |
| 1540 | /* Number of sector is in this bank. */ |
| 1541 | uint16_t count; |
| 1542 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1543 | uint8_t size_exp; |
| 1544 | /* Minimal write size for the sectors in this bank */ |
| 1545 | uint8_t write_size_exp; |
| 1546 | /* Erase size for the sectors in this bank */ |
| 1547 | uint8_t erase_size_exp; |
| 1548 | /* Size for write protection, usually identical to erase size. */ |
| 1549 | uint8_t protect_size_exp; |
| 1550 | /* Reserved; set 0; ignore on read */ |
| 1551 | uint8_t reserved[2]; |
| 1552 | }; |
| 1553 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1554 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1555 | /* Total flash in the EC. */ |
| 1556 | uint32_t flash_size; |
| 1557 | /* Flags; see EC_FLASH_INFO_* */ |
| 1558 | uint32_t flags; |
| 1559 | /* Maximum size to use to send data to write to the EC. */ |
| 1560 | uint32_t write_ideal_size; |
| 1561 | /* Number of banks present in the EC. */ |
| 1562 | uint16_t num_banks_total; |
| 1563 | /* Number of banks described in banks array. */ |
| 1564 | uint16_t num_banks_desc; |
| 1565 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1566 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1567 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1568 | /* |
| 1569 | * Read flash |
| 1570 | * |
| 1571 | * Response is params.size bytes of data. |
| 1572 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1573 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1574 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1575 | /** |
| 1576 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1577 | * @offset: Byte offset to read. |
| 1578 | * @size: Size to read in bytes. |
| 1579 | */ |
| 1580 | struct ec_params_flash_read { |
| 1581 | uint32_t offset; |
| 1582 | uint32_t size; |
| 1583 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1584 | |
| 1585 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1586 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1587 | #define EC_VER_FLASH_WRITE 1 |
| 1588 | |
| 1589 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1590 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1591 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1592 | /** |
| 1593 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1594 | * @offset: Byte offset to write. |
| 1595 | * @size: Size to write in bytes. |
| 1596 | */ |
| 1597 | struct ec_params_flash_write { |
| 1598 | uint32_t offset; |
| 1599 | uint32_t size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1600 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1601 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1602 | |
| 1603 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1604 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1605 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1606 | /** |
| 1607 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1608 | * @offset: Byte offset to erase. |
| 1609 | * @size: Size to erase in bytes. |
| 1610 | */ |
| 1611 | struct ec_params_flash_erase { |
| 1612 | uint32_t offset; |
| 1613 | uint32_t size; |
| 1614 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1615 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1616 | /* |
| 1617 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1618 | * subcommands can returns: |
| 1619 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1620 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1621 | * EC_RES_ERROR : other errors. |
| 1622 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1623 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1624 | * |
| 1625 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1626 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1627 | * the proper result. |
| 1628 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1629 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1630 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1631 | * permitted while erasing. (For instance, STM32F4). |
| 1632 | */ |
| 1633 | enum ec_flash_erase_cmd { |
| 1634 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1635 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1636 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1637 | }; |
| 1638 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1639 | /** |
| 1640 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1641 | * @cmd: One of ec_flash_erase_cmd. |
| 1642 | * @reserved: Pad byte; currently always contains 0. |
| 1643 | * @flag: No flags defined yet; set to 0. |
| 1644 | * @params: Same as v0 parameters. |
| 1645 | */ |
| 1646 | struct ec_params_flash_erase_v1 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1647 | uint8_t cmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1648 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1649 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1650 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1651 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1652 | |
| 1653 | /* |
| 1654 | * Get/set flash protection. |
| 1655 | * |
| 1656 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1657 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1658 | * some flags require a subsequent hard reset to take effect. Check the |
| 1659 | * returned flags bits to see what actually happened. |
| 1660 | * |
| 1661 | * If mask=0, simply returns the current flags state. |
| 1662 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1663 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1664 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1665 | |
| 1666 | /* Flags for flash protection */ |
| 1667 | /* RO flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1668 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1669 | /* |
| 1670 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1671 | * be changed. |
| 1672 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1673 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1674 | /* Entire flash code protected now, until reboot. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1675 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1676 | /* Flash write protect GPIO is asserted now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1677 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1678 | /* 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] | 1679 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1680 | /* |
| 1681 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1682 | * flash which should be protected is not protected. Usually fixed by |
| 1683 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1684 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1685 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1686 | /* Entire flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1687 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1688 | /* RW flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1689 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1690 | /* RW flash code protected now. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1691 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1692 | /* Rollback information flash region protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1693 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1694 | /* Rollback information flash region protected now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1695 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1696 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1697 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1698 | /** |
| 1699 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1700 | * @mask: Bits in flags to apply. |
| 1701 | * @flags: New flags to apply. |
| 1702 | */ |
| 1703 | struct ec_params_flash_protect { |
| 1704 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1705 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1706 | } __ec_align4; |
| 1707 | |
| 1708 | /** |
| 1709 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1710 | * @flags: Current value of flash protect flags. |
| 1711 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1712 | * caller to distinguish between flags which aren't set vs. flags |
| 1713 | * which can't be set on this platform. |
| 1714 | * @writable_flags: Flags which can be changed given the current protection |
| 1715 | * state. |
| 1716 | */ |
| 1717 | struct ec_response_flash_protect { |
| 1718 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1719 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1720 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1721 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1722 | |
| 1723 | /* |
| 1724 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1725 | * write protect. These commands may be reused with version > 0. |
| 1726 | */ |
| 1727 | |
| 1728 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1729 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1730 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1731 | |
| 1732 | enum ec_flash_region { |
| 1733 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1734 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1735 | /* |
| 1736 | * Region which holds active RW image. 'Active' is different from |
| 1737 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1738 | * scheduled to run, active/non-active applies only to RW images (for |
| 1739 | * the same reason 'update' applies only to RW images. It's a state of |
| 1740 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1741 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1742 | * doesn't enter 'running' state but it's still active on a flash. |
| 1743 | */ |
| 1744 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1745 | /* |
| 1746 | * Region which should be write-protected in the factory (a superset of |
| 1747 | * EC_FLASH_REGION_RO) |
| 1748 | */ |
| 1749 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1750 | /* Region which holds updatable (non-active) RW image */ |
| 1751 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1752 | /* Number of regions */ |
| 1753 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1754 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1755 | /* |
| 1756 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1757 | * so the old constant is deprecated. |
| 1758 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1759 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1760 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1761 | /** |
| 1762 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1763 | * command. |
| 1764 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1765 | */ |
| 1766 | struct ec_params_flash_region_info { |
| 1767 | uint32_t region; |
| 1768 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1769 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1770 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1771 | uint32_t offset; |
| 1772 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1773 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1774 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1775 | /* Read/write VbNvContext */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1776 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1777 | #define EC_VER_VBNV_CONTEXT 1 |
| 1778 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1779 | |
| 1780 | enum ec_vbnvcontext_op { |
| 1781 | EC_VBNV_CONTEXT_OP_READ, |
| 1782 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1783 | }; |
| 1784 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1785 | struct ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1786 | uint32_t op; |
| 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 | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1789 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1790 | struct ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1791 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1792 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1793 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1794 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1795 | /* Get SPI flash information */ |
| 1796 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1797 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1798 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1799 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1800 | uint8_t jedec[3]; |
| 1801 | |
| 1802 | /* Pad byte; currently always contains 0 */ |
| 1803 | uint8_t reserved0; |
| 1804 | |
| 1805 | /* Manufacturer / device ID from command 0x90 */ |
| 1806 | uint8_t mfr_dev_id[2]; |
| 1807 | |
| 1808 | /* Status registers from command 0x05 and 0x35 */ |
| 1809 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1810 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1811 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1812 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1813 | /* Select flash during flash operations */ |
| 1814 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1815 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1816 | /** |
| 1817 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1818 | * @select: 1 to select flash, 0 to deselect flash |
| 1819 | */ |
| 1820 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1821 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1822 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1823 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1824 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1825 | /** |
| 1826 | * Request random numbers to be generated and returned. |
| 1827 | * Can be used to test the random number generator is truly random. |
| 1828 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1829 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1830 | */ |
| 1831 | #define EC_CMD_RAND_NUM 0x001A |
| 1832 | #define EC_VER_RAND_NUM 0 |
| 1833 | |
| 1834 | struct ec_params_rand_num { |
| 1835 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
| 1836 | } __ec_align4; |
| 1837 | |
| 1838 | struct ec_response_rand_num { |
| 1839 | uint8_t rand[0]; /**< generated random numbers */ |
| 1840 | } __ec_align4; |
| 1841 | |
| 1842 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1843 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1844 | /** |
| 1845 | * Get information about the key used to sign the RW firmware. |
| 1846 | * For more details on the fields, see "struct vb21_packed_key". |
| 1847 | */ |
| 1848 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1849 | #define EC_VER_RWSIG_INFO 0 |
| 1850 | |
| 1851 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1852 | |
| 1853 | #ifdef CHROMIUM_EC |
| 1854 | /* Don't force external projects to depend on the vboot headers. */ |
| 1855 | #include "vb21_struct.h" |
| 1856 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1857 | #endif |
| 1858 | |
| 1859 | struct ec_response_rwsig_info { |
| 1860 | /** |
| 1861 | * Signature algorithm used by the key |
| 1862 | * (enum vb2_signature_algorithm). |
| 1863 | */ |
| 1864 | uint16_t sig_alg; |
| 1865 | |
| 1866 | /** |
| 1867 | * Hash digest algorithm used with the key |
| 1868 | * (enum vb2_hash_algorithm). |
| 1869 | */ |
| 1870 | uint16_t hash_alg; |
| 1871 | |
| 1872 | /** Key version. */ |
| 1873 | uint32_t key_version; |
| 1874 | |
| 1875 | /** Key ID (struct vb2_id). */ |
| 1876 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 1877 | |
| 1878 | uint8_t key_is_valid; |
| 1879 | |
| 1880 | /** Alignment padding. */ |
| 1881 | uint8_t reserved[3]; |
| 1882 | } __ec_align4; |
| 1883 | |
| 1884 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 1885 | |
| 1886 | /** |
| 1887 | * Get information about the system, such as reset flags, locked state, etc. |
| 1888 | */ |
| 1889 | #define EC_CMD_SYSINFO 0x001C |
| 1890 | #define EC_VER_SYSINFO 0 |
| 1891 | |
| 1892 | enum sysinfo_flags { |
| 1893 | SYSTEM_IS_LOCKED = BIT(0), |
| 1894 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 1895 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 1896 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
| 1897 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4) |
| 1898 | }; |
| 1899 | |
| 1900 | struct ec_response_sysinfo { |
| 1901 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
| 1902 | uint32_t current_image; /**< enum ec_current_image */ |
| 1903 | uint32_t flags; /**< enum sysinfo_flags */ |
| 1904 | } __ec_align4; |
| 1905 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1906 | /*****************************************************************************/ |
| 1907 | /* PWM commands */ |
| 1908 | |
| 1909 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1910 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1911 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1912 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1913 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1914 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1915 | |
| 1916 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1917 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1918 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1919 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1920 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1921 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1922 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1923 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1924 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1925 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1926 | uint32_t rpm; |
| 1927 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1928 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1929 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1930 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1931 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1932 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1933 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1934 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1935 | uint8_t percent; |
| 1936 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1937 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1938 | |
| 1939 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1940 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1941 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1942 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1943 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1944 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1945 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1946 | |
| 1947 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1948 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1949 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1950 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1951 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1952 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1953 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1954 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1955 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1956 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1957 | uint32_t percent; |
| 1958 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1959 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1960 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1961 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1962 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1963 | #define EC_PWM_MAX_DUTY 0xffff |
| 1964 | |
| 1965 | enum ec_pwm_type { |
| 1966 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1967 | EC_PWM_TYPE_GENERIC = 0, |
| 1968 | /* Keyboard backlight */ |
| 1969 | EC_PWM_TYPE_KB_LIGHT, |
| 1970 | /* Display backlight */ |
| 1971 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1972 | EC_PWM_TYPE_COUNT, |
| 1973 | }; |
| 1974 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1975 | struct ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1976 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1977 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1978 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1979 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1980 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1981 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1982 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1983 | struct ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1984 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1985 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1986 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1987 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1988 | struct ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1989 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1990 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1991 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1992 | /*****************************************************************************/ |
| 1993 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1994 | * 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] | 1995 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1996 | * into a subcommand. We'll make separate structs for subcommands with |
| 1997 | * different input args, so that we know how much to expect. |
| 1998 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1999 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2000 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2001 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2002 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2003 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2004 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2005 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2006 | |
| 2007 | /* |
| 2008 | * 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] | 2009 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2010 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2011 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2012 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2013 | int32_t google_ramp_up; |
| 2014 | int32_t google_ramp_down; |
| 2015 | int32_t s3s0_ramp_up; |
| 2016 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2017 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2018 | int32_t s0s3_ramp_down; |
| 2019 | int32_t s3_sleep_for; |
| 2020 | int32_t s3_ramp_up; |
| 2021 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2022 | |
| 2023 | /* Oscillation */ |
| 2024 | uint8_t new_s0; |
| 2025 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2026 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2027 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2028 | |
| 2029 | /* Brightness limits based on the backlight and AC. */ |
| 2030 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2031 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2032 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2033 | |
| 2034 | /* Battery level thresholds */ |
| 2035 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2036 | |
| 2037 | /* Map [AC][battery_level] to color index */ |
| 2038 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2039 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2040 | |
| 2041 | /* Color palette */ |
| 2042 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2043 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2044 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2045 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2046 | /* Timing */ |
| 2047 | int32_t google_ramp_up; |
| 2048 | int32_t google_ramp_down; |
| 2049 | int32_t s3s0_ramp_up; |
| 2050 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2051 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2052 | int32_t s0s3_ramp_down; |
| 2053 | int32_t s3_sleep_for; |
| 2054 | int32_t s3_ramp_up; |
| 2055 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2056 | int32_t s5_ramp_up; |
| 2057 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2058 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2059 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2060 | int32_t tap_display_time; |
| 2061 | |
| 2062 | /* Tap-for-battery params */ |
| 2063 | uint8_t tap_pct_red; |
| 2064 | uint8_t tap_pct_green; |
| 2065 | uint8_t tap_seg_min_on; |
| 2066 | uint8_t tap_seg_max_on; |
| 2067 | uint8_t tap_seg_osc; |
| 2068 | uint8_t tap_idx[3]; |
| 2069 | |
| 2070 | /* Oscillation */ |
| 2071 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2072 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2073 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2074 | |
| 2075 | /* Brightness limits based on the backlight and AC. */ |
| 2076 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2077 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2078 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2079 | |
| 2080 | /* Battery level thresholds */ |
| 2081 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2082 | |
| 2083 | /* Map [AC][battery_level] to color index */ |
| 2084 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2085 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2086 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2087 | /* s5: single color pulse on inhibited power-up */ |
| 2088 | uint8_t s5_idx; |
| 2089 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2090 | /* Color palette */ |
| 2091 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2092 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2093 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2094 | /* Lightbar command params v2 |
| 2095 | * crbug.com/467716 |
| 2096 | * |
| 2097 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2098 | * logical groups to make it more manageable ( < 120 bytes). |
| 2099 | * |
| 2100 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2101 | */ |
| 2102 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2103 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2104 | /* Timing */ |
| 2105 | int32_t google_ramp_up; |
| 2106 | int32_t google_ramp_down; |
| 2107 | int32_t s3s0_ramp_up; |
| 2108 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2109 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2110 | int32_t s0s3_ramp_down; |
| 2111 | int32_t s3_sleep_for; |
| 2112 | int32_t s3_ramp_up; |
| 2113 | int32_t s3_ramp_down; |
| 2114 | int32_t s5_ramp_up; |
| 2115 | int32_t s5_ramp_down; |
| 2116 | int32_t tap_tick_delay; |
| 2117 | int32_t tap_gate_delay; |
| 2118 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2119 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2120 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2121 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2122 | /* Tap-for-battery params */ |
| 2123 | uint8_t tap_pct_red; |
| 2124 | uint8_t tap_pct_green; |
| 2125 | uint8_t tap_seg_min_on; |
| 2126 | uint8_t tap_seg_max_on; |
| 2127 | uint8_t tap_seg_osc; |
| 2128 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2129 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2130 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2131 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2132 | /* Oscillation */ |
| 2133 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2134 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2135 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2136 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2137 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2138 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2139 | /* Brightness limits based on the backlight and AC. */ |
| 2140 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2141 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2142 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2143 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2144 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2145 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2146 | /* Battery level thresholds */ |
| 2147 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2148 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2149 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2150 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2151 | /* Map [AC][battery_level] to color index */ |
| 2152 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2153 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2154 | |
| 2155 | /* s5: single color pulse on inhibited power-up */ |
| 2156 | uint8_t s5_idx; |
| 2157 | |
| 2158 | /* Color palette */ |
| 2159 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2160 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2161 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2162 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2163 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2164 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2165 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2166 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2167 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2168 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2169 | struct ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2170 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 2171 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2172 | /* |
| 2173 | * The following commands have no args: |
| 2174 | * |
| 2175 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2176 | * version, get_brightness, get_demo, suspend, resume, |
| 2177 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2178 | * get_params_v2_bright, get_params_v2_thlds, |
| 2179 | * get_params_v2_colors |
| 2180 | * |
| 2181 | * Don't use an empty struct, because C++ hates that. |
| 2182 | */ |
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 num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2186 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 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 ctrl, reg, value; |
| 2190 | } reg; |
| 2191 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2192 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2193 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2194 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2195 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2196 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2197 | uint8_t led; |
| 2198 | } get_rgb; |
| 2199 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2200 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2201 | uint8_t enable; |
| 2202 | } manual_suspend_ctrl; |
| 2203 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2204 | struct lightbar_params_v0 set_params_v0; |
| 2205 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2206 | |
| 2207 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2208 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2209 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2210 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2211 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2212 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2213 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2214 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2215 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2216 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2217 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2218 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2219 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2220 | struct __ec_todo_unpacked { |
| 2221 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2222 | uint8_t reg; |
| 2223 | uint8_t ic0; |
| 2224 | uint8_t ic1; |
| 2225 | } vals[23]; |
| 2226 | } dump; |
| 2227 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2228 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2229 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2230 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2231 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2232 | struct lightbar_params_v0 get_params_v0; |
| 2233 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2234 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2235 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2236 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2237 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2238 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2239 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2240 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2241 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2242 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2243 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2244 | uint32_t num; |
| 2245 | uint32_t flags; |
| 2246 | } version; |
| 2247 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2248 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2249 | uint8_t red, green, blue; |
| 2250 | } get_rgb; |
| 2251 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2252 | /* |
| 2253 | * The following commands have no response: |
| 2254 | * |
| 2255 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2256 | * set_params_v0, set_params_v1, set_program, |
| 2257 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2258 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2259 | * set_v2par_thlds, set_v2par_colors |
| 2260 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2261 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2262 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2263 | |
| 2264 | /* Lightbar commands */ |
| 2265 | enum lightbar_command { |
| 2266 | LIGHTBAR_CMD_DUMP = 0, |
| 2267 | LIGHTBAR_CMD_OFF = 1, |
| 2268 | LIGHTBAR_CMD_ON = 2, |
| 2269 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2270 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2271 | LIGHTBAR_CMD_SEQ = 5, |
| 2272 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2273 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2274 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2275 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2276 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2277 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2278 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2279 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2280 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2281 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2282 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2283 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2284 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2285 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2286 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2287 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2288 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2289 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2290 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2291 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2292 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2293 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2294 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2295 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2296 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2297 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2298 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2299 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2300 | LIGHTBAR_NUM_CMDS |
| 2301 | }; |
| 2302 | |
| 2303 | /*****************************************************************************/ |
| 2304 | /* LED control commands */ |
| 2305 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2306 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2307 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2308 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2309 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2310 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2311 | /* |
| 2312 | * LED to indicate system power state (on or in suspend). |
| 2313 | * May be on power button or on C-panel. |
| 2314 | */ |
| 2315 | EC_LED_ID_POWER_LED, |
| 2316 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2317 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2318 | /* LED to indicate left side */ |
| 2319 | EC_LED_ID_LEFT_LED, |
| 2320 | /* LED to indicate right side */ |
| 2321 | EC_LED_ID_RIGHT_LED, |
| 2322 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2323 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2324 | /* LED to indicate sysrq debug mode. */ |
| 2325 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2326 | |
| 2327 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2328 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2329 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2330 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2331 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
| 2332 | #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] | 2333 | |
| 2334 | enum ec_led_colors { |
| 2335 | EC_LED_COLOR_RED = 0, |
| 2336 | EC_LED_COLOR_GREEN, |
| 2337 | EC_LED_COLOR_BLUE, |
| 2338 | EC_LED_COLOR_YELLOW, |
| 2339 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2340 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2341 | |
| 2342 | EC_LED_COLOR_COUNT |
| 2343 | }; |
| 2344 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2345 | struct ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2346 | uint8_t led_id; /* Which LED to control */ |
| 2347 | uint8_t flags; /* Control flags */ |
| 2348 | |
| 2349 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2350 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2351 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2352 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2353 | /* |
| 2354 | * Available brightness value range. |
| 2355 | * |
| 2356 | * Range 0 means color channel not present. |
| 2357 | * Range 1 means on/off control. |
| 2358 | * Other values means the LED is control by PWM. |
| 2359 | */ |
| 2360 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2361 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2362 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2363 | /*****************************************************************************/ |
| 2364 | /* Verified boot commands */ |
| 2365 | |
| 2366 | /* |
| 2367 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2368 | * reused for other purposes with version > 0. |
| 2369 | */ |
| 2370 | |
| 2371 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2372 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2373 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2374 | struct ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2375 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2376 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2377 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2378 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2379 | uint32_t offset; /* Offset in flash to hash */ |
| 2380 | uint32_t size; /* Number of bytes to hash */ |
| 2381 | 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] | 2382 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2383 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2384 | struct ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2385 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2386 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2387 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2388 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2389 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2390 | uint32_t size; /* Number of bytes hashed */ |
| 2391 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2392 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2393 | |
| 2394 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2395 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2396 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2397 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2398 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2399 | }; |
| 2400 | |
| 2401 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2402 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2403 | }; |
| 2404 | |
| 2405 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2406 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2407 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2408 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2409 | }; |
| 2410 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2411 | /* |
| 2412 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2413 | * If one of these is specified, the EC will automatically update offset and |
| 2414 | * size to the correct values for the specified image (RO or RW). |
| 2415 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2416 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2417 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2418 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
| 2419 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2420 | /* |
| 2421 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2422 | * so the old constant is deprecated. |
| 2423 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2424 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2425 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2426 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2427 | /* |
| 2428 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2429 | * different input args, so that we know how much to expect. |
| 2430 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2431 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2432 | |
| 2433 | /* Motion sense commands */ |
| 2434 | enum motionsense_command { |
| 2435 | /* |
| 2436 | * Dump command returns all motion sensor data including motion sense |
| 2437 | * module flags and individual sensor flags. |
| 2438 | */ |
| 2439 | MOTIONSENSE_CMD_DUMP = 0, |
| 2440 | |
| 2441 | /* |
| 2442 | * Info command returns data describing the details of a given sensor, |
| 2443 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2444 | * enum motionsensor_chip. |
| 2445 | */ |
| 2446 | MOTIONSENSE_CMD_INFO = 1, |
| 2447 | |
| 2448 | /* |
| 2449 | * 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] | 2450 | * in milliseconds. |
| 2451 | * It is per sensor, the EC run sample task at the minimum of all |
| 2452 | * sensors EC_RATE. |
| 2453 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2454 | * to collect all the sensor samples. |
| 2455 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2456 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2457 | */ |
| 2458 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2459 | |
| 2460 | /* |
| 2461 | * Sensor ODR command is a setter/getter command for the output data |
| 2462 | * rate of a specific motion sensor in millihertz. |
| 2463 | */ |
| 2464 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2465 | |
| 2466 | /* |
| 2467 | * Sensor range command is a setter/getter command for the range of |
| 2468 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2469 | */ |
| 2470 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2471 | |
| 2472 | /* |
| 2473 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2474 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2475 | * and when the lid angle goes less than this value, keyboard wake is |
| 2476 | * enabled. Note, the lid angle measurement is an approximate, |
| 2477 | * un-calibrated value, hence the wake angle isn't exact. |
| 2478 | */ |
| 2479 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2480 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2481 | /* |
| 2482 | * Returns a single sensor data. |
| 2483 | */ |
| 2484 | MOTIONSENSE_CMD_DATA = 6, |
| 2485 | |
| 2486 | /* |
| 2487 | * Return sensor fifo info. |
| 2488 | */ |
| 2489 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2490 | |
| 2491 | /* |
| 2492 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2493 | * The host can use that element to synchronize its operation. |
| 2494 | */ |
| 2495 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2496 | |
| 2497 | /* |
| 2498 | * Return a portion of the fifo. |
| 2499 | */ |
| 2500 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2501 | |
| 2502 | /* |
| 2503 | * Perform low level calibration. |
| 2504 | * On sensors that support it, ask to do offset calibration. |
| 2505 | */ |
| 2506 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2507 | |
| 2508 | /* |
| 2509 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2510 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2511 | * The offsets can be calculated by the host, or via |
| 2512 | * PERFORM_CALIB command. |
| 2513 | */ |
| 2514 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2515 | |
| 2516 | /* |
| 2517 | * List available activities for a MOTION sensor. |
| 2518 | * Indicates if they are enabled or disabled. |
| 2519 | */ |
| 2520 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2521 | |
| 2522 | /* |
| 2523 | * Activity management |
| 2524 | * Enable/Disable activity recognition. |
| 2525 | */ |
| 2526 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2527 | |
| 2528 | /* |
| 2529 | * Lid Angle |
| 2530 | */ |
| 2531 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2532 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2533 | /* |
| 2534 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2535 | * By default the FIFO does not send interrupt to process the FIFO |
| 2536 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2537 | */ |
| 2538 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2539 | |
| 2540 | /* |
| 2541 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2542 | * to arbitrary values, or will lock to the last read actual values. |
| 2543 | */ |
| 2544 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2545 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2546 | /* Set lid angle for tablet mode detection. */ |
| 2547 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2548 | |
| 2549 | /* |
| 2550 | * Sensor Scale command is a setter/getter command for the calibration |
| 2551 | * scale. |
| 2552 | */ |
| 2553 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2554 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2555 | /* |
| 2556 | * Read the current online calibration values (if available). |
| 2557 | */ |
| 2558 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2559 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2560 | /* |
| 2561 | * Activity management |
| 2562 | * Retrieve current status of given activity. |
| 2563 | */ |
| 2564 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2565 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2566 | /* Number of motionsense sub-commands. */ |
| 2567 | MOTIONSENSE_NUM_CMDS |
| 2568 | }; |
| 2569 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2570 | /* List of motion sensor types. */ |
| 2571 | enum motionsensor_type { |
| 2572 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2573 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2574 | MOTIONSENSE_TYPE_MAG = 2, |
| 2575 | MOTIONSENSE_TYPE_PROX = 3, |
| 2576 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2577 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2578 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2579 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2580 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2581 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2582 | }; |
| 2583 | |
| 2584 | /* List of motion sensor locations. */ |
| 2585 | enum motionsensor_location { |
| 2586 | MOTIONSENSE_LOC_BASE = 0, |
| 2587 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2588 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2589 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2590 | }; |
| 2591 | |
| 2592 | /* List of motion sensor chips. */ |
| 2593 | enum motionsensor_chip { |
| 2594 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2595 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2596 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2597 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2598 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2599 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2600 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2601 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2602 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2603 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2604 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2605 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2606 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2607 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2608 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2609 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2610 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2611 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2612 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2613 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2614 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2615 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2616 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2617 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2618 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2619 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2620 | MOTIONSENSE_CHIP_MAX, |
| 2621 | }; |
| 2622 | |
| 2623 | /* List of orientation positions */ |
| 2624 | enum motionsensor_orientation { |
| 2625 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2626 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2627 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2628 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2629 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2630 | }; |
| 2631 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2632 | struct ec_response_activity_data { |
| 2633 | uint8_t activity; /* motionsensor_activity */ |
| 2634 | uint8_t state; |
| 2635 | } __ec_todo_packed; |
| 2636 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2637 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2638 | /* Flags for each sensor. */ |
| 2639 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2640 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2641 | uint8_t sensor_num; |
| 2642 | /* Each sensor is up to 3-axis. */ |
| 2643 | union { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2644 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2645 | /* for sensors using unsigned data */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2646 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2647 | struct __ec_todo_packed { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2648 | uint16_t reserved; |
| 2649 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2650 | }; |
| 2651 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2652 | struct ec_response_activity_data activity_data; |
| 2653 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2654 | }; |
| 2655 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2656 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2657 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2658 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2659 | struct ec_response_online_calibration_data { |
| 2660 | /** The calibration values. */ |
| 2661 | int16_t data[3]; |
| 2662 | }; |
| 2663 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2664 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2665 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2666 | /* Size of the fifo */ |
| 2667 | uint16_t size; |
| 2668 | /* Amount of space used in the fifo */ |
| 2669 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2670 | /* Timestamp recorded in us. |
| 2671 | * aka accurate timestamp when host event was triggered. |
| 2672 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2673 | uint32_t timestamp; |
| 2674 | /* Total amount of vector lost */ |
| 2675 | uint16_t total_lost; |
| 2676 | /* Lost events since the last fifo_info, per sensors */ |
| 2677 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2678 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2679 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2680 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2681 | uint32_t number_data; |
| 2682 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2683 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2684 | |
| 2685 | /* List supported activity recognition */ |
| 2686 | enum motionsensor_activity { |
| 2687 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2688 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2689 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2690 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2691 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2692 | }; |
| 2693 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2694 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2695 | uint8_t sensor_num; |
| 2696 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2697 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2698 | uint8_t reserved; |
| 2699 | uint16_t parameters[3]; /* activity dependent parameters */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2700 | } __ec_todo_unpacked; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2701 | |
| 2702 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2703 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2704 | |
| 2705 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2706 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2707 | |
| 2708 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2709 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2710 | * data contains time stamp |
| 2711 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2712 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2713 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2714 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2715 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2716 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2717 | |
| 2718 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2719 | * Send this value for the data element to only perform a read. If you |
| 2720 | * send any other value, the EC will interpret it as data to set and will |
| 2721 | * return the actual value set. |
| 2722 | */ |
| 2723 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2724 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2725 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2726 | |
| 2727 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2728 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2729 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2730 | |
| 2731 | /* Default Scale value, factor 1. */ |
| 2732 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2733 | |
| 2734 | #define LID_ANGLE_UNRELIABLE 500 |
| 2735 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2736 | enum motionsense_spoof_mode { |
| 2737 | /* Disable spoof mode. */ |
| 2738 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2739 | |
| 2740 | /* Enable spoof mode, but use provided component values. */ |
| 2741 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2742 | |
| 2743 | /* Enable spoof mode, but use the current sensor values. */ |
| 2744 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2745 | |
| 2746 | /* Query the current spoof mode status for the sensor. */ |
| 2747 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2748 | }; |
| 2749 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2750 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2751 | uint8_t cmd; |
| 2752 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2753 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2754 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2755 | /* |
| 2756 | * Maximal number of sensor the host is expecting. |
| 2757 | * 0 means the host is only interested in the number |
| 2758 | * of sensors controlled by the EC. |
| 2759 | */ |
| 2760 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2761 | } dump; |
| 2762 | |
| 2763 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2764 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2765 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2766 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2767 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 2768 | * kb_wake_angle: angle to wakup AP. |
| 2769 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2770 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2771 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2772 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2773 | /* |
| 2774 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2775 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2776 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2777 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2778 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2779 | |
| 2780 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2781 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2782 | * Allow entering/exiting the calibration mode. |
| 2783 | */ |
| 2784 | struct __ec_todo_unpacked { |
| 2785 | uint8_t sensor_num; |
| 2786 | uint8_t enable; |
| 2787 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2788 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2789 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2790 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2791 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2792 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2793 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2794 | uint8_t sensor_num; |
| 2795 | |
| 2796 | /* Rounding flag, true for round-up, false for down. */ |
| 2797 | uint8_t roundup; |
| 2798 | |
| 2799 | uint16_t reserved; |
| 2800 | |
| 2801 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2802 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2803 | } ec_rate, sensor_odr, sensor_range; |
| 2804 | |
| 2805 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2806 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2807 | uint8_t sensor_num; |
| 2808 | |
| 2809 | /* |
| 2810 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2811 | * the calibration information in the EC. |
| 2812 | * If unset, just retrieve calibration information. |
| 2813 | */ |
| 2814 | uint16_t flags; |
| 2815 | |
| 2816 | /* |
| 2817 | * Temperature at calibration, in units of 0.01 C |
| 2818 | * 0x8000: invalid / unknown. |
| 2819 | * 0x0: 0C |
| 2820 | * 0x7fff: +327.67C |
| 2821 | */ |
| 2822 | int16_t temp; |
| 2823 | |
| 2824 | /* |
| 2825 | * Offset for calibration. |
| 2826 | * Unit: |
| 2827 | * Accelerometer: 1/1024 g |
| 2828 | * Gyro: 1/1024 deg/s |
| 2829 | * Compass: 1/16 uT |
| 2830 | */ |
| 2831 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2832 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2833 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2834 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2835 | struct __ec_todo_packed { |
| 2836 | uint8_t sensor_num; |
| 2837 | |
| 2838 | /* |
| 2839 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2840 | * the calibration information in the EC. |
| 2841 | * If unset, just retrieve calibration information. |
| 2842 | */ |
| 2843 | uint16_t flags; |
| 2844 | |
| 2845 | /* |
| 2846 | * Temperature at calibration, in units of 0.01 C |
| 2847 | * 0x8000: invalid / unknown. |
| 2848 | * 0x0: 0C |
| 2849 | * 0x7fff: +327.67C |
| 2850 | */ |
| 2851 | int16_t temp; |
| 2852 | |
| 2853 | /* |
| 2854 | * Scale for calibration: |
| 2855 | * By default scale is 1, it is encoded on 16bits: |
| 2856 | * 1 = BIT(15) |
| 2857 | * ~2 = 0xFFFF |
| 2858 | * ~0 = 0. |
| 2859 | */ |
| 2860 | uint16_t scale[3]; |
| 2861 | } sensor_scale; |
| 2862 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2863 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2864 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2865 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2866 | |
| 2867 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2868 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2869 | /* |
| 2870 | * Number of expected vector to return. |
| 2871 | * EC may return less or 0 if none available. |
| 2872 | */ |
| 2873 | uint32_t max_data_vector; |
| 2874 | } fifo_read; |
| 2875 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2876 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2877 | struct ec_motion_sense_activity set_activity; |
| 2878 | |
| 2879 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2880 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2881 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2882 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2883 | struct __ec_todo_unpacked { |
| 2884 | /* |
| 2885 | * 1: enable, 0 disable fifo, |
| 2886 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2887 | */ |
| 2888 | int8_t enable; |
| 2889 | } fifo_int_enable; |
| 2890 | |
| 2891 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2892 | struct __ec_todo_packed { |
| 2893 | uint8_t sensor_id; |
| 2894 | |
| 2895 | /* See enum motionsense_spoof_mode. */ |
| 2896 | uint8_t spoof_enable; |
| 2897 | |
| 2898 | /* Ignored, used for alignment. */ |
| 2899 | uint8_t reserved; |
| 2900 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 2901 | union { |
| 2902 | /* Individual component values to spoof. */ |
| 2903 | int16_t components[3]; |
| 2904 | |
| 2905 | /* Used when spoofing an activity */ |
| 2906 | struct { |
| 2907 | /* enum motionsensor_activity */ |
| 2908 | uint8_t activity_num; |
| 2909 | |
| 2910 | /* spoof activity state */ |
| 2911 | uint8_t activity_state; |
| 2912 | }; |
| 2913 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2914 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2915 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2916 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 2917 | struct __ec_todo_unpacked { |
| 2918 | /* |
| 2919 | * Lid angle threshold for switching between tablet and |
| 2920 | * clamshell mode. |
| 2921 | */ |
| 2922 | int16_t lid_angle; |
| 2923 | |
| 2924 | /* |
| 2925 | * Hysteresis degree to prevent fluctuations between |
| 2926 | * clamshell and tablet mode if lid angle keeps |
| 2927 | * changing around the threshold. Lid motion driver will |
| 2928 | * use lid_angle + hys_degree to trigger tablet mode and |
| 2929 | * lid_angle - hys_degree to trigger clamshell mode. |
| 2930 | */ |
| 2931 | int16_t hys_degree; |
| 2932 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2933 | |
| 2934 | /* |
| 2935 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 2936 | * Allow reading a single sensor's online calibration value. |
| 2937 | */ |
| 2938 | struct __ec_todo_unpacked { |
| 2939 | uint8_t sensor_num; |
| 2940 | } online_calib_read; |
| 2941 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2942 | /* |
| 2943 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 2944 | */ |
| 2945 | struct __ec_todo_unpacked { |
| 2946 | uint8_t sensor_num; |
| 2947 | uint8_t activity; /* enum motionsensor_activity */ |
| 2948 | } get_activity; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2949 | }; |
| 2950 | } __ec_todo_packed; |
| 2951 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 2952 | enum motion_sense_cmd_info_flags { |
| 2953 | /* The sensor supports online calibration */ |
| 2954 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 2955 | }; |
| 2956 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2957 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2958 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2959 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2960 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2961 | /* Flags representing the motion sensor module. */ |
| 2962 | uint8_t module_flags; |
| 2963 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2964 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2965 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2966 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2967 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2968 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2969 | * for holding all the data. |
| 2970 | */ |
| 2971 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2972 | } dump; |
| 2973 | |
| 2974 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2975 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2976 | /* Should be element of enum motionsensor_type. */ |
| 2977 | uint8_t type; |
| 2978 | |
| 2979 | /* Should be element of enum motionsensor_location. */ |
| 2980 | uint8_t location; |
| 2981 | |
| 2982 | /* Should be element of enum motionsensor_chip. */ |
| 2983 | uint8_t chip; |
| 2984 | } info; |
| 2985 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2986 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 2987 | struct __ec_todo_unpacked { |
| 2988 | /* Should be element of enum motionsensor_type. */ |
| 2989 | uint8_t type; |
| 2990 | |
| 2991 | /* Should be element of enum motionsensor_location. */ |
| 2992 | uint8_t location; |
| 2993 | |
| 2994 | /* Should be element of enum motionsensor_chip. */ |
| 2995 | uint8_t chip; |
| 2996 | |
| 2997 | /* Minimum sensor sampling frequency */ |
| 2998 | uint32_t min_frequency; |
| 2999 | |
| 3000 | /* Maximum sensor sampling frequency */ |
| 3001 | uint32_t max_frequency; |
| 3002 | |
| 3003 | /* Max number of sensor events that could be in fifo */ |
| 3004 | uint32_t fifo_max_event_count; |
| 3005 | } info_3; |
| 3006 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3007 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3008 | struct __ec_align4 { |
| 3009 | /* Should be element of enum motionsensor_type. */ |
| 3010 | uint8_t type; |
| 3011 | |
| 3012 | /* Should be element of enum motionsensor_location. */ |
| 3013 | uint8_t location; |
| 3014 | |
| 3015 | /* Should be element of enum motionsensor_chip. */ |
| 3016 | uint8_t chip; |
| 3017 | |
| 3018 | /* Minimum sensor sampling frequency */ |
| 3019 | uint32_t min_frequency; |
| 3020 | |
| 3021 | /* Maximum sensor sampling frequency */ |
| 3022 | uint32_t max_frequency; |
| 3023 | |
| 3024 | /* Max number of sensor events that could be in fifo */ |
| 3025 | uint32_t fifo_max_event_count; |
| 3026 | |
| 3027 | /* |
| 3028 | * Should be elements of |
| 3029 | * enum motion_sense_cmd_info_flags |
| 3030 | */ |
| 3031 | uint32_t flags; |
| 3032 | } info_4; |
| 3033 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3034 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3035 | struct ec_response_motion_sensor_data data; |
| 3036 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3037 | /* |
| 3038 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3039 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3040 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3041 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3042 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3043 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3044 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3045 | /* Current value of the parameter queried. */ |
| 3046 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3047 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 3048 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3049 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3050 | /* |
| 3051 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3052 | * PERFORM_CALIB. |
| 3053 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3054 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3055 | int16_t temp; |
| 3056 | int16_t offset[3]; |
| 3057 | } sensor_offset, perform_calib; |
| 3058 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3059 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3060 | struct __ec_todo_unpacked { |
| 3061 | int16_t temp; |
| 3062 | uint16_t scale[3]; |
| 3063 | } sensor_scale; |
| 3064 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3065 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3066 | |
| 3067 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3068 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3069 | struct ec_response_online_calibration_data online_calib_read; |
| 3070 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3071 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3072 | uint16_t reserved; |
| 3073 | uint32_t enabled; |
| 3074 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3075 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3076 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3077 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3078 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3079 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3080 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3081 | /* |
| 3082 | * Angle between 0 and 360 degree if available, |
| 3083 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3084 | */ |
| 3085 | uint16_t value; |
| 3086 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3087 | |
| 3088 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3089 | struct __ec_todo_unpacked { |
| 3090 | /* |
| 3091 | * Lid angle threshold for switching between tablet and |
| 3092 | * clamshell mode. |
| 3093 | */ |
| 3094 | uint16_t lid_angle; |
| 3095 | |
| 3096 | /* Hysteresis degree. */ |
| 3097 | uint16_t hys_degree; |
| 3098 | } tablet_mode_threshold; |
| 3099 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3100 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3101 | struct __ec_todo_unpacked { |
| 3102 | uint8_t state; |
| 3103 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3104 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3105 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3106 | |
| 3107 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3108 | /* Force lid open command */ |
| 3109 | |
| 3110 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3111 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3112 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3113 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3114 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3115 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3116 | |
| 3117 | /*****************************************************************************/ |
| 3118 | /* Configure the behavior of the power button */ |
| 3119 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3120 | |
| 3121 | enum ec_config_power_button_flags { |
| 3122 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3123 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3124 | }; |
| 3125 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3126 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3127 | /* See enum ec_config_power_button_flags */ |
| 3128 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3129 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3130 | |
| 3131 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3132 | /* USB charging control commands */ |
| 3133 | |
| 3134 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3135 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3136 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3137 | enum usb_charge_mode { |
| 3138 | /* Disable USB port. */ |
| 3139 | USB_CHARGE_MODE_DISABLED, |
| 3140 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3141 | USB_CHARGE_MODE_SDP2, |
| 3142 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3143 | USB_CHARGE_MODE_CDP, |
| 3144 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3145 | USB_CHARGE_MODE_DCP_SHORT, |
| 3146 | /* Enable USB port (for dumb ports). */ |
| 3147 | USB_CHARGE_MODE_ENABLED, |
| 3148 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3149 | USB_CHARGE_MODE_DEFAULT, |
| 3150 | |
| 3151 | USB_CHARGE_MODE_COUNT |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3152 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3153 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3154 | enum usb_suspend_charge { |
| 3155 | /* Enable charging in suspend */ |
| 3156 | USB_ALLOW_SUSPEND_CHARGE, |
| 3157 | /* Disable charging in suspend */ |
| 3158 | USB_DISALLOW_SUSPEND_CHARGE |
| 3159 | }; |
| 3160 | |
| 3161 | struct ec_params_usb_charge_set_mode { |
| 3162 | uint8_t usb_port_id; |
| 3163 | uint8_t mode:7; /* enum usb_charge_mode */ |
| 3164 | uint8_t inhibit_charge:1; /* enum usb_suspend_charge */ |
| 3165 | } __ec_align1; |
| 3166 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3167 | /*****************************************************************************/ |
| 3168 | /* Persistent storage for host */ |
| 3169 | |
| 3170 | /* Maximum bytes that can be read/written in a single command */ |
| 3171 | #define EC_PSTORE_SIZE_MAX 64 |
| 3172 | |
| 3173 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3174 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3175 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3176 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3177 | /* Persistent storage size, in bytes */ |
| 3178 | uint32_t pstore_size; |
| 3179 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3180 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3181 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3182 | |
| 3183 | /* |
| 3184 | * Read persistent storage |
| 3185 | * |
| 3186 | * Response is params.size bytes of data. |
| 3187 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3188 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3189 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3190 | struct ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3191 | uint32_t offset; /* Byte offset to read */ |
| 3192 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3193 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3194 | |
| 3195 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3196 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3197 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3198 | struct ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3199 | uint32_t offset; /* Byte offset to write */ |
| 3200 | uint32_t size; /* Size to write in bytes */ |
| 3201 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3202 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3203 | |
| 3204 | /*****************************************************************************/ |
| 3205 | /* Real-time clock */ |
| 3206 | |
| 3207 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3208 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3209 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3210 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3211 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3212 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3213 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3214 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3215 | |
| 3216 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3217 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3218 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3219 | |
| 3220 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3221 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3222 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3223 | |
| 3224 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3225 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3226 | |
| 3227 | /*****************************************************************************/ |
| 3228 | /* Port80 log access */ |
| 3229 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3230 | /* Maximum entries that can be read/written in a single command */ |
| 3231 | #define EC_PORT80_SIZE_MAX 32 |
| 3232 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3233 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3234 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3235 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3236 | |
| 3237 | enum ec_port80_subcmd { |
| 3238 | EC_PORT80_GET_INFO = 0, |
| 3239 | EC_PORT80_READ_BUFFER, |
| 3240 | }; |
| 3241 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3242 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3243 | uint16_t subcmd; |
| 3244 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3245 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3246 | uint32_t offset; |
| 3247 | uint32_t num_entries; |
| 3248 | } read_buffer; |
| 3249 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3250 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3251 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3252 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3253 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3254 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3255 | uint32_t writes; |
| 3256 | uint32_t history_size; |
| 3257 | uint32_t last_boot; |
| 3258 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3259 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3260 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3261 | } data; |
| 3262 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3263 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3265 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3266 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3267 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3268 | |
| 3269 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3270 | /* Temporary secure storage for host verified boot use */ |
| 3271 | |
| 3272 | /* Number of bytes in a vstore slot */ |
| 3273 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3274 | |
| 3275 | /* Maximum number of vstore slots */ |
| 3276 | #define EC_VSTORE_SLOT_MAX 32 |
| 3277 | |
| 3278 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3279 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3280 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3281 | /* Indicates which slots are locked */ |
| 3282 | uint32_t slot_locked; |
| 3283 | /* Total number of slots available */ |
| 3284 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3285 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3286 | |
| 3287 | /* |
| 3288 | * Read temporary secure storage |
| 3289 | * |
| 3290 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3291 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3292 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3293 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3294 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3295 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3296 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3297 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3298 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3299 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3300 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3301 | |
| 3302 | /* |
| 3303 | * Write temporary secure storage and lock it. |
| 3304 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3305 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3307 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3308 | uint8_t slot; /* Slot to write to */ |
| 3309 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3310 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3311 | |
| 3312 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3313 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3314 | * reuse the command number, but the data and behavior is incompatible. |
| 3315 | * Version 0 is what originally shipped on Link. |
| 3316 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3317 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3318 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3319 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3320 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3321 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3322 | /* The version 0 structs are opaque. You have to know what they are for |
| 3323 | * the get/set commands to make any sense. |
| 3324 | */ |
| 3325 | |
| 3326 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3327 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3328 | uint8_t sensor_type; |
| 3329 | uint8_t threshold_id; |
| 3330 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3331 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3332 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3333 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3334 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3335 | uint8_t sensor_type; |
| 3336 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3337 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3338 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3339 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3340 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3341 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3342 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3343 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3344 | /* The version 1 structs are visible. */ |
| 3345 | enum ec_temp_thresholds { |
| 3346 | EC_TEMP_THRESH_WARN = 0, |
| 3347 | EC_TEMP_THRESH_HIGH, |
| 3348 | EC_TEMP_THRESH_HALT, |
| 3349 | |
| 3350 | EC_TEMP_THRESH_COUNT |
| 3351 | }; |
| 3352 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3353 | /* |
| 3354 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3355 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3356 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3357 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3358 | * hysteresis. |
| 3359 | * For example, |
| 3360 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3361 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3362 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3363 | * temperature <= 299 K. |
| 3364 | * |
| 3365 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3366 | * For example, |
| 3367 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3368 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3369 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3370 | * temperature <= 294 K. |
| 3371 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3372 | * Note that this structure is a sub-structure of |
| 3373 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3374 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3375 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3376 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3377 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3378 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3379 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3380 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3381 | |
| 3382 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3383 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3384 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3385 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3386 | /* This returns a struct ec_thermal_config */ |
| 3387 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3388 | /* |
| 3389 | * Version 1 - set config for one sensor. |
| 3390 | * Use read-modify-write for best results! |
| 3391 | */ |
| 3392 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3393 | uint32_t sensor_num; |
| 3394 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3395 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3396 | /* This returns no data */ |
| 3397 | |
| 3398 | /****************************************************************************/ |
| 3399 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3400 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3401 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3402 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3403 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3404 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3405 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3406 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3407 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3408 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3409 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3410 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3411 | |
| 3412 | /* |
| 3413 | * The original TMP006 calibration only needed four params, but now we need |
| 3414 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3415 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3416 | * and how many params it requires. That way we can change the EC code without |
| 3417 | * needing to update this file. We can also use a different algorithm on each |
| 3418 | * sensor. |
| 3419 | */ |
| 3420 | |
| 3421 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3422 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3423 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3424 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3425 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3426 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3427 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3428 | float s0; |
| 3429 | float b0; |
| 3430 | float b1; |
| 3431 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3432 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3433 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3434 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3435 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3436 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3437 | float s0; |
| 3438 | float b0; |
| 3439 | float b1; |
| 3440 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3441 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3442 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3443 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3444 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3445 | uint8_t algorithm; |
| 3446 | uint8_t num_params; |
| 3447 | uint8_t reserved[2]; |
| 3448 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3449 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3450 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3451 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3452 | uint8_t index; |
| 3453 | uint8_t algorithm; |
| 3454 | uint8_t num_params; |
| 3455 | uint8_t reserved; |
| 3456 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3457 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3458 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3459 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3460 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3461 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3462 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3463 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3464 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3465 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3466 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3467 | struct ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3468 | int32_t t; /* In 1/100 K */ |
| 3469 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3470 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3471 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3472 | /*****************************************************************************/ |
| 3473 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3474 | |
| 3475 | /* |
| 3476 | * Read key state |
| 3477 | * |
| 3478 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3479 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3480 | * |
| 3481 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3482 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3483 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3484 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3485 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3486 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3487 | /* |
| 3488 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3489 | */ |
| 3490 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3491 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3492 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3493 | uint32_t rows; |
| 3494 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3495 | /* Formerly "switches", which was 0. */ |
| 3496 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3497 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3498 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3499 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3500 | uint8_t info_type; |
| 3501 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3502 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3503 | |
| 3504 | enum ec_mkbp_info_type { |
| 3505 | /* |
| 3506 | * Info about the keyboard matrix: number of rows and columns. |
| 3507 | * |
| 3508 | * Returns struct ec_response_mkbp_info. |
| 3509 | */ |
| 3510 | EC_MKBP_INFO_KBD = 0, |
| 3511 | |
| 3512 | /* |
| 3513 | * For buttons and switches, info about which specifically are |
| 3514 | * supported. event_type must be set to one of the values in enum |
| 3515 | * ec_mkbp_event. |
| 3516 | * |
| 3517 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3518 | * bitmask indicating which buttons or switches are present. See the |
| 3519 | * bit inidices below. |
| 3520 | */ |
| 3521 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3522 | |
| 3523 | /* |
| 3524 | * Instantaneous state of buttons and switches. |
| 3525 | * |
| 3526 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3527 | * |
| 3528 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3529 | * indicating the current state of the keyboard matrix. |
| 3530 | * |
| 3531 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3532 | * event state. |
| 3533 | * |
| 3534 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3535 | * state of supported buttons. |
| 3536 | * |
| 3537 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3538 | * state of supported switches. |
| 3539 | */ |
| 3540 | EC_MKBP_INFO_CURRENT = 2, |
| 3541 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3542 | |
| 3543 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3544 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3545 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3546 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3547 | uint8_t col; |
| 3548 | uint8_t row; |
| 3549 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3550 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3551 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3552 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3553 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3554 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3555 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3556 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3557 | |
| 3558 | enum keyboard_id { |
| 3559 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3560 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3561 | }; |
| 3562 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3563 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3564 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3565 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3566 | |
| 3567 | /* flags */ |
| 3568 | enum mkbp_config_flags { |
| 3569 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 3570 | }; |
| 3571 | |
| 3572 | enum mkbp_config_valid { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3573 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3574 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3575 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3576 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3577 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3578 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3579 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3580 | }; |
| 3581 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3582 | /* |
| 3583 | * Configuration for our key scanning algorithm. |
| 3584 | * |
| 3585 | * Note that this is used as a sub-structure of |
| 3586 | * ec_{params/response}_mkbp_get_config. |
| 3587 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3588 | struct ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3589 | uint32_t valid_mask; /* valid fields */ |
| 3590 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3591 | uint8_t valid_flags; /* which flags are valid */ |
| 3592 | uint16_t scan_period_us; /* period between start of scans */ |
| 3593 | /* revert to interrupt mode after no activity for this long */ |
| 3594 | uint32_t poll_timeout_us; |
| 3595 | /* |
| 3596 | * minimum post-scan relax time. Once we finish a scan we check |
| 3597 | * the time until we are due to start the next one. If this time is |
| 3598 | * shorter this field, we use this instead. |
| 3599 | */ |
| 3600 | uint16_t min_post_scan_delay_us; |
| 3601 | /* delay between setting up output and waiting for it to settle */ |
| 3602 | uint16_t output_settle_us; |
| 3603 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3604 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 3605 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3606 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3607 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3608 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3609 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3610 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3611 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3612 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3613 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3614 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3615 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3616 | |
| 3617 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3618 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3619 | |
| 3620 | enum ec_keyscan_seq_cmd { |
| 3621 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3622 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3623 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3624 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3625 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 3626 | }; |
| 3627 | |
| 3628 | enum ec_collect_flags { |
| 3629 | /* |
| 3630 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3631 | * scans may be skipped. |
| 3632 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3633 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3634 | }; |
| 3635 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3636 | struct ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3637 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3638 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3639 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3640 | struct ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3641 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 3642 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3643 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3644 | uint8_t active; /* still active */ |
| 3645 | uint8_t num_items; /* number of items */ |
| 3646 | /* Current item being presented */ |
| 3647 | uint8_t cur_item; |
| 3648 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3649 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3650 | /* |
| 3651 | * Absolute time for this scan, measured from the |
| 3652 | * start of the sequence. |
| 3653 | */ |
| 3654 | uint32_t time_us; |
| 3655 | uint8_t scan[0]; /* keyscan data */ |
| 3656 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3657 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3658 | uint8_t start_item; /* First item to return */ |
| 3659 | uint8_t num_items; /* Number of items to return */ |
| 3660 | } collect; |
| 3661 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3662 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3663 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3664 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3665 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3666 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3667 | uint8_t num_items; /* Number of items */ |
| 3668 | /* Data for each item */ |
| 3669 | struct ec_collect_item item[0]; |
| 3670 | } collect; |
| 3671 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3672 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3673 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3674 | /* |
| 3675 | * Get the next pending MKBP event. |
| 3676 | * |
| 3677 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3678 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3679 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3680 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3681 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3682 | |
| 3683 | /* |
| 3684 | * We use the most significant bit of the event type to indicate to the host |
| 3685 | * that the EC has more MKBP events available to provide. |
| 3686 | */ |
| 3687 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3688 | |
| 3689 | /* The mask to apply to get the raw event type */ |
| 3690 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3691 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3692 | enum ec_mkbp_event { |
| 3693 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3694 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3695 | |
| 3696 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3697 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3698 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3699 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3700 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3701 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3702 | /* The state of the non-matrixed buttons have changed. */ |
| 3703 | EC_MKBP_EVENT_BUTTON = 3, |
| 3704 | |
| 3705 | /* The state of the switches have changed. */ |
| 3706 | EC_MKBP_EVENT_SWITCH = 4, |
| 3707 | |
| 3708 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3709 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3710 | |
| 3711 | /* |
| 3712 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3713 | * corresponding to the key to be pressed. |
| 3714 | */ |
| 3715 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3716 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3717 | /* |
| 3718 | * New 64-bit host event. |
| 3719 | * The event data is 8 bytes of host event flags. |
| 3720 | */ |
| 3721 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3722 | |
| 3723 | /* Notify the AP that something happened on CEC */ |
| 3724 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3725 | |
| 3726 | /* Send an incoming CEC message to the AP */ |
| 3727 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3728 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3729 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3730 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3731 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3732 | /* New online calibration values are available. */ |
| 3733 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3734 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3735 | /* Number of MKBP events */ |
| 3736 | EC_MKBP_EVENT_COUNT, |
| 3737 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3738 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3739 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3740 | union __ec_align_offset1 ec_response_get_next_data { |
| 3741 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3742 | |
| 3743 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3744 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3745 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3746 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3747 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3748 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3749 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3750 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3751 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3752 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3753 | uint32_t buttons; |
| 3754 | |
| 3755 | uint32_t switches; |
| 3756 | |
| 3757 | uint32_t fp_events; |
| 3758 | |
| 3759 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3760 | |
| 3761 | /* CEC events from enum mkbp_cec_event */ |
| 3762 | uint32_t cec_events; |
| 3763 | }; |
| 3764 | |
| 3765 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3766 | uint8_t key_matrix[16]; |
| 3767 | |
| 3768 | /* Unaligned */ |
| 3769 | uint32_t host_event; |
| 3770 | uint64_t host_event64; |
| 3771 | |
| 3772 | struct __ec_todo_unpacked { |
| 3773 | /* For aligning the fifo_info */ |
| 3774 | uint8_t reserved[3]; |
| 3775 | struct ec_response_motion_sense_fifo_info info; |
| 3776 | } sensor_fifo; |
| 3777 | |
| 3778 | uint32_t buttons; |
| 3779 | |
| 3780 | uint32_t switches; |
| 3781 | |
| 3782 | uint32_t fp_events; |
| 3783 | |
| 3784 | uint32_t sysrq; |
| 3785 | |
| 3786 | /* CEC events from enum mkbp_cec_event */ |
| 3787 | uint32_t cec_events; |
| 3788 | |
| 3789 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3790 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3791 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3792 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3793 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3794 | uint8_t event_type; |
| 3795 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3796 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3797 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3798 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3799 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3800 | uint8_t event_type; |
| 3801 | /* Followed by event data if any */ |
| 3802 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3803 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3804 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3805 | /* Bit indices for buttons and switches.*/ |
| 3806 | /* Buttons */ |
| 3807 | #define EC_MKBP_POWER_BUTTON 0 |
| 3808 | #define EC_MKBP_VOL_UP 1 |
| 3809 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 3810 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3811 | |
| 3812 | /* Switches */ |
| 3813 | #define EC_MKBP_LID_OPEN 0 |
| 3814 | #define EC_MKBP_TABLET_MODE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3815 | #define EC_MKBP_BASE_ATTACHED 2 |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 3816 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3817 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3818 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3819 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3820 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3821 | struct ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3822 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3823 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3824 | |
| 3825 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3826 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3827 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) |
| 3828 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
| 3829 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ |
| 3830 | >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
| 3831 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 3832 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
| 3833 | #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ |
| 3834 | >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3835 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 3836 | #define EC_MKBP_FP_MATCH BIT(28) |
| 3837 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 3838 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 3839 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3840 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
| 3841 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 3842 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 3843 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 3844 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 3845 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
| 3846 | /* Can be used to detect if image was usable for enrollment or not. */ |
| 3847 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
| 3848 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
| 3849 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 3850 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3851 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3852 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 3853 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 3854 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 3855 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
| 3856 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 3857 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3858 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3859 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 3860 | enum ec_mkbp_event_mask_action { |
| 3861 | /* Retrieve the value of a wake mask. */ |
| 3862 | GET_WAKE_MASK = 0, |
| 3863 | |
| 3864 | /* Set the value of a wake mask. */ |
| 3865 | SET_WAKE_MASK, |
| 3866 | }; |
| 3867 | |
| 3868 | enum ec_mkbp_mask_type { |
| 3869 | /* |
| 3870 | * These are host events sent via MKBP. |
| 3871 | * |
| 3872 | * Some examples are: |
| 3873 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 3874 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 3875 | * |
| 3876 | * The only things that should be in this mask are: |
| 3877 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 3878 | */ |
| 3879 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 3880 | |
| 3881 | /* |
| 3882 | * These are MKBP events. Some examples are: |
| 3883 | * |
| 3884 | * EC_MKBP_EVENT_KEY_MATRIX |
| 3885 | * EC_MKBP_EVENT_SWITCH |
| 3886 | * |
| 3887 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 3888 | */ |
| 3889 | EC_MKBP_EVENT_WAKE_MASK, |
| 3890 | }; |
| 3891 | |
| 3892 | struct ec_params_mkbp_event_wake_mask { |
| 3893 | /* One of enum ec_mkbp_event_mask_action */ |
| 3894 | uint8_t action; |
| 3895 | |
| 3896 | /* |
| 3897 | * Which MKBP mask are you interested in acting upon? This is one of |
| 3898 | * ec_mkbp_mask_type. |
| 3899 | */ |
| 3900 | uint8_t mask_type; |
| 3901 | |
| 3902 | /* If setting a new wake mask, this contains the mask to set. */ |
| 3903 | uint32_t new_wake_mask; |
| 3904 | }; |
| 3905 | |
| 3906 | struct ec_response_mkbp_event_wake_mask { |
| 3907 | uint32_t wake_mask; |
| 3908 | }; |
| 3909 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3910 | /*****************************************************************************/ |
| 3911 | /* Temperature sensor commands */ |
| 3912 | |
| 3913 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3914 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3915 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3916 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3917 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3918 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3919 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3920 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3921 | char sensor_name[32]; |
| 3922 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3923 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3924 | |
| 3925 | /*****************************************************************************/ |
| 3926 | |
| 3927 | /* |
| 3928 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 3929 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 3930 | * below. |
| 3931 | */ |
| 3932 | |
| 3933 | /*****************************************************************************/ |
| 3934 | /* Host event commands */ |
| 3935 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3936 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3937 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3938 | /* |
| 3939 | * Host event mask params and response structures, shared by all of the host |
| 3940 | * event commands below. |
| 3941 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3942 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3943 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3944 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3945 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3946 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3947 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3948 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3949 | |
| 3950 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3951 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 3952 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 3953 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 3954 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3955 | |
| 3956 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3957 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 3958 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 3959 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 3960 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 3961 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3962 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3963 | /* |
| 3964 | * Unified host event programming interface - Should be used by newer versions |
| 3965 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3966 | * |
| 3967 | * EC returns: |
| 3968 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 3969 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3970 | */ |
| 3971 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3972 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3973 | |
| 3974 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 3975 | uint8_t action; |
| 3976 | |
| 3977 | /* |
| 3978 | * Mask type that the host requested the action on - one of |
| 3979 | * enum ec_host_event_mask_type. |
| 3980 | */ |
| 3981 | uint8_t mask_type; |
| 3982 | |
| 3983 | /* Set to 0, ignore on read */ |
| 3984 | uint16_t reserved; |
| 3985 | |
| 3986 | /* Value to be used in case of set operations. */ |
| 3987 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3988 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3989 | |
| 3990 | /* |
| 3991 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 3992 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 3993 | */ |
| 3994 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3995 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3996 | |
| 3997 | /* Mask value in case of get operation */ |
| 3998 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3999 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4000 | |
| 4001 | enum ec_host_event_action { |
| 4002 | /* |
| 4003 | * params.value is ignored. Value of mask_type populated |
| 4004 | * in response.value |
| 4005 | */ |
| 4006 | EC_HOST_EVENT_GET, |
| 4007 | |
| 4008 | /* Bits in params.value are set */ |
| 4009 | EC_HOST_EVENT_SET, |
| 4010 | |
| 4011 | /* Bits in params.value are cleared */ |
| 4012 | EC_HOST_EVENT_CLEAR, |
| 4013 | }; |
| 4014 | |
| 4015 | enum ec_host_event_mask_type { |
| 4016 | |
| 4017 | /* Main host event copy */ |
| 4018 | EC_HOST_EVENT_MAIN, |
| 4019 | |
| 4020 | /* Copy B of host events */ |
| 4021 | EC_HOST_EVENT_B, |
| 4022 | |
| 4023 | /* SCI Mask */ |
| 4024 | EC_HOST_EVENT_SCI_MASK, |
| 4025 | |
| 4026 | /* SMI Mask */ |
| 4027 | EC_HOST_EVENT_SMI_MASK, |
| 4028 | |
| 4029 | /* Mask of events that should be always reported in hostevents */ |
| 4030 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4031 | |
| 4032 | /* Active wake mask */ |
| 4033 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4034 | |
| 4035 | /* Lazy wake mask for S0ix */ |
| 4036 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4037 | |
| 4038 | /* Lazy wake mask for S3 */ |
| 4039 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4040 | |
| 4041 | /* Lazy wake mask for S5 */ |
| 4042 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4043 | }; |
| 4044 | |
| 4045 | #define EC_CMD_HOST_EVENT 0x00A4 |
| 4046 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4047 | /*****************************************************************************/ |
| 4048 | /* Switch commands */ |
| 4049 | |
| 4050 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4051 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
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_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4054 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4055 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4056 | |
| 4057 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4058 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4059 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
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 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4062 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4063 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4064 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4065 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4066 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4067 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4068 | /* Flags to enable now */ |
| 4069 | uint8_t now_flags; |
| 4070 | |
| 4071 | /* Which flags to copy from now_flags */ |
| 4072 | uint8_t now_mask; |
| 4073 | |
| 4074 | /* |
| 4075 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4076 | * transition. (Other flags will be disabled by the S0->S3 |
| 4077 | * transition.) |
| 4078 | */ |
| 4079 | uint8_t suspend_flags; |
| 4080 | |
| 4081 | /* Which flags to copy from suspend_flags */ |
| 4082 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4083 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4084 | |
| 4085 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4086 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4087 | /* Flags to enable now */ |
| 4088 | uint8_t now_flags; |
| 4089 | |
| 4090 | /* Flags to leave enabled in S3 */ |
| 4091 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4092 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4093 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4094 | /*****************************************************************************/ |
| 4095 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4096 | |
| 4097 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4098 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4099 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4100 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4101 | char name[32]; |
| 4102 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4103 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4104 | |
| 4105 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4106 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4107 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4108 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4109 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4110 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4111 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4112 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4113 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4114 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4115 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4116 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4117 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4118 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4119 | uint8_t subcmd; |
| 4120 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4121 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4122 | char name[32]; |
| 4123 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4124 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4125 | uint8_t index; |
| 4126 | } get_info; |
| 4127 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4128 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4129 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4130 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4131 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4132 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4133 | uint8_t val; |
| 4134 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4135 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4136 | uint8_t val; |
| 4137 | char name[32]; |
| 4138 | uint32_t flags; |
| 4139 | } get_info; |
| 4140 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4141 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4142 | |
| 4143 | enum gpio_get_subcmd { |
| 4144 | EC_GPIO_GET_BY_NAME = 0, |
| 4145 | EC_GPIO_GET_COUNT = 1, |
| 4146 | EC_GPIO_GET_INFO = 2, |
| 4147 | }; |
| 4148 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4149 | /*****************************************************************************/ |
| 4150 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4151 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4152 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4153 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4154 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4155 | * |
| 4156 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4157 | */ |
| 4158 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4159 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4160 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4161 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4162 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4163 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4164 | uint8_t read_size; /* Either 8 or 16. */ |
| 4165 | uint8_t port; |
| 4166 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4167 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4168 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4169 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4170 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4171 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4172 | |
| 4173 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4174 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4175 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4176 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4177 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4178 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4179 | uint8_t write_size; /* Either 8 or 16. */ |
| 4180 | uint8_t port; |
| 4181 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4182 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4183 | |
| 4184 | /*****************************************************************************/ |
| 4185 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4186 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4187 | /* Force charge state machine to stop charging the battery or force it to |
| 4188 | * discharge the battery. |
| 4189 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4190 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4191 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4192 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4193 | enum ec_charge_control_mode { |
| 4194 | CHARGE_CONTROL_NORMAL = 0, |
| 4195 | CHARGE_CONTROL_IDLE, |
| 4196 | CHARGE_CONTROL_DISCHARGE, |
| 4197 | }; |
| 4198 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4199 | struct ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4200 | uint32_t mode; /* enum charge_control_mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4201 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4202 | |
| 4203 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4204 | |
| 4205 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4206 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4207 | |
| 4208 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4209 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4210 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4211 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4212 | * end of the previous snapshot. |
| 4213 | * |
| 4214 | * The params are only looked at in version >= 1 of this command. Prior |
| 4215 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4216 | * |
| 4217 | * Response is null-terminated string. Empty string, if there is no more |
| 4218 | * remaining output. |
| 4219 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4220 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4221 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4222 | enum ec_console_read_subcmd { |
| 4223 | CONSOLE_READ_NEXT = 0, |
| 4224 | CONSOLE_READ_RECENT |
| 4225 | }; |
| 4226 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4227 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4228 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4229 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4230 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4231 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4232 | |
| 4233 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4234 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4235 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4236 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4237 | * EC_RES_SUCCESS if the command was successful. |
| 4238 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4239 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4240 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4241 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4242 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4243 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4244 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4245 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4246 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4247 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4248 | /*****************************************************************************/ |
| 4249 | /* USB port mux control. */ |
| 4250 | |
| 4251 | /* |
| 4252 | * Switch USB mux or return to automatic switching. |
| 4253 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4254 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4255 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4256 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4257 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4258 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4259 | |
| 4260 | /*****************************************************************************/ |
| 4261 | /* LDOs / FETs control. */ |
| 4262 | |
| 4263 | enum ec_ldo_state { |
| 4264 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4265 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 4266 | }; |
| 4267 | |
| 4268 | /* |
| 4269 | * Switch on/off a LDO. |
| 4270 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4271 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4272 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4273 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4274 | uint8_t index; |
| 4275 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4276 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4277 | |
| 4278 | /* |
| 4279 | * Get LDO state. |
| 4280 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4281 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4282 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4283 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4284 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4285 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4286 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4287 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4288 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4289 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4290 | |
| 4291 | /*****************************************************************************/ |
| 4292 | /* Power info. */ |
| 4293 | |
| 4294 | /* |
| 4295 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4296 | * |
| 4297 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4298 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4299 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4300 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4301 | /* |
| 4302 | * v1 of EC_CMD_POWER_INFO |
| 4303 | */ |
| 4304 | enum system_power_source { |
| 4305 | /* |
| 4306 | * Haven't established which power source is used yet, |
| 4307 | * or no presence signals are available |
| 4308 | */ |
| 4309 | POWER_SOURCE_UNKNOWN = 0, |
| 4310 | /* System is running on battery alone */ |
| 4311 | POWER_SOURCE_BATTERY = 1, |
| 4312 | /* System is running on A/C alone */ |
| 4313 | POWER_SOURCE_AC = 2, |
| 4314 | /* System is running on A/C and battery */ |
| 4315 | POWER_SOURCE_AC_BATTERY = 3, |
| 4316 | }; |
| 4317 | |
| 4318 | struct ec_response_power_info_v1 { |
| 4319 | /* enum system_power_source */ |
| 4320 | uint8_t system_power_source; |
| 4321 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4322 | uint8_t battery_soc; |
| 4323 | /* AC Adapter 100% rating, Watts */ |
| 4324 | uint8_t ac_adapter_100pct; |
| 4325 | /* AC Adapter 10ms rating, Watts */ |
| 4326 | uint8_t ac_adapter_10ms; |
| 4327 | /* Battery 1C rating, derated */ |
| 4328 | uint8_t battery_1cd; |
| 4329 | /* Rest of Platform average, Watts */ |
| 4330 | uint8_t rop_avg; |
| 4331 | /* Rest of Platform peak, Watts */ |
| 4332 | uint8_t rop_peak; |
| 4333 | /* Nominal charger efficiency, % */ |
| 4334 | uint8_t nominal_charger_eff; |
| 4335 | /* Rest of Platform VR Average Efficiency, % */ |
| 4336 | uint8_t rop_avg_eff; |
| 4337 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4338 | uint8_t rop_peak_eff; |
| 4339 | /* SoC VR Efficiency at Average level, % */ |
| 4340 | uint8_t soc_avg_eff; |
| 4341 | /* SoC VR Efficiency at Peak level, % */ |
| 4342 | uint8_t soc_peak_eff; |
| 4343 | /* Intel-specific items */ |
| 4344 | struct { |
| 4345 | /* Battery's level of DBPT support: 0, 2 */ |
| 4346 | uint8_t batt_dbpt_support_level; |
| 4347 | /* |
| 4348 | * Maximum peak power from battery (10ms), Watts |
| 4349 | * If DBPT is not supported, this is 0 |
| 4350 | */ |
| 4351 | uint8_t batt_dbpt_max_peak_power; |
| 4352 | /* |
| 4353 | * Sustained peak power from battery, Watts |
| 4354 | * If DBPT is not supported, this is 0 |
| 4355 | */ |
| 4356 | uint8_t batt_dbpt_sus_peak_power; |
| 4357 | } intel; |
| 4358 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4359 | |
| 4360 | /*****************************************************************************/ |
| 4361 | /* I2C passthru command */ |
| 4362 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4363 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4364 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4365 | /* Read data; if not present, message is a write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4366 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4367 | |
| 4368 | /* Mask for address */ |
| 4369 | #define EC_I2C_ADDR_MASK 0x3ff |
| 4370 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4371 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4372 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4373 | |
| 4374 | /* Any error */ |
| 4375 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 4376 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4377 | struct ec_params_i2c_passthru_msg { |
| 4378 | uint16_t addr_flags; /* I2C slave address and flags */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4379 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4380 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4381 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4382 | struct ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4383 | uint8_t port; /* I2C port number */ |
| 4384 | uint8_t num_msgs; /* Number of messages */ |
| 4385 | struct ec_params_i2c_passthru_msg msg[]; |
| 4386 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4387 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4388 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4389 | struct ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4390 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4391 | uint8_t num_msgs; /* Number of messages processed */ |
| 4392 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4393 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4394 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4395 | /*****************************************************************************/ |
| 4396 | /* Power button hang detect */ |
| 4397 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4398 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4399 | |
| 4400 | /* Reasons to start hang detection timer */ |
| 4401 | /* Power button pressed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4402 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4403 | |
| 4404 | /* Lid closed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4405 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4406 | |
| 4407 | /* Lid opened */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4408 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4409 | |
| 4410 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4411 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4412 | |
| 4413 | /* Reasons to cancel hang detection */ |
| 4414 | |
| 4415 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4416 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4417 | |
| 4418 | /* Any host command from AP received */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4419 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4420 | |
| 4421 | /* 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] | 4422 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4423 | |
| 4424 | /* |
| 4425 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4426 | * timer is started. This provides the AP a way to start the hang timer |
| 4427 | * without reconfiguring any of the other hang detect settings. Note that |
| 4428 | * you must previously have configured the timeouts. |
| 4429 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4430 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4431 | |
| 4432 | /* |
| 4433 | * If this flag is set, all the other fields are ignored (including |
| 4434 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4435 | * without reconfiguring any of the other hang detect settings. |
| 4436 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4437 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4438 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4439 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4440 | /* Flags; see EC_HANG_* */ |
| 4441 | uint32_t flags; |
| 4442 | |
| 4443 | /* Timeout in msec before generating host event, if enabled */ |
| 4444 | uint16_t host_event_timeout_msec; |
| 4445 | |
| 4446 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4447 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4448 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4449 | |
| 4450 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4451 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4452 | |
| 4453 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4454 | * This is the single catch-all host command to exchange data regarding the |
| 4455 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4456 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4457 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4458 | |
| 4459 | /* Subcommands for this host command */ |
| 4460 | enum charge_state_command { |
| 4461 | CHARGE_STATE_CMD_GET_STATE, |
| 4462 | CHARGE_STATE_CMD_GET_PARAM, |
| 4463 | CHARGE_STATE_CMD_SET_PARAM, |
| 4464 | CHARGE_STATE_NUM_CMDS |
| 4465 | }; |
| 4466 | |
| 4467 | /* |
| 4468 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4469 | * params, which are handled by the particular implementations. |
| 4470 | */ |
| 4471 | enum charge_state_params { |
| 4472 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 4473 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 4474 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 4475 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 4476 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4477 | CS_PARAM_LIMIT_POWER, /* |
| 4478 | * Check if power is limited due to |
| 4479 | * low battery and / or a weak external |
| 4480 | * charger. READ ONLY. |
| 4481 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4482 | /* How many so far? */ |
| 4483 | CS_NUM_BASE_PARAMS, |
| 4484 | |
| 4485 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4486 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4487 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4488 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4489 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4490 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4491 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4492 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4493 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4494 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4495 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4496 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4497 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4498 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4499 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4500 | /* Other custom param ranges go here... */ |
| 4501 | }; |
| 4502 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4503 | struct ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4504 | uint8_t cmd; /* enum charge_state_command */ |
| 4505 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4506 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4507 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4508 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4509 | uint32_t param; /* enum charge_state_param */ |
| 4510 | } get_param; |
| 4511 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4512 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4513 | uint32_t param; /* param to set */ |
| 4514 | uint32_t value; /* value to set */ |
| 4515 | } set_param; |
| 4516 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 4517 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4518 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4519 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4520 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4521 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4522 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4523 | int ac; |
| 4524 | int chg_voltage; |
| 4525 | int chg_current; |
| 4526 | int chg_input_current; |
| 4527 | int batt_state_of_charge; |
| 4528 | } get_state; |
| 4529 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4530 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4531 | uint32_t value; |
| 4532 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4533 | |
| 4534 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4535 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4536 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4537 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4538 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4539 | /* |
| 4540 | * Set maximum battery charging current. |
| 4541 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4542 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4543 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4544 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4545 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4546 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4547 | |
| 4548 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4549 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4550 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4551 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4552 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4553 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4554 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4555 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4556 | 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] | 4557 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4558 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4559 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4560 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4561 | /* |
| 4562 | * Set maximum voltage & current of a dedicated charge port |
| 4563 | */ |
| 4564 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4565 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4566 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4567 | uint16_t current_lim; /* in mA */ |
| 4568 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4569 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4570 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4571 | /*****************************************************************************/ |
| 4572 | /* Hibernate/Deep Sleep Commands */ |
| 4573 | |
| 4574 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4575 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4576 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4577 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4578 | /* |
| 4579 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4580 | * current settings without changing them. |
| 4581 | */ |
| 4582 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4583 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4584 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4585 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4586 | /* |
| 4587 | * The current time in seconds in which the system has been in the G3 |
| 4588 | * state. This value is reset if the EC transitions out of G3. |
| 4589 | */ |
| 4590 | uint32_t time_g3; |
| 4591 | |
| 4592 | /* |
| 4593 | * The current time remaining in seconds until the EC should hibernate. |
| 4594 | * This value is also reset if the EC transitions out of G3. |
| 4595 | */ |
| 4596 | uint32_t time_remaining; |
| 4597 | |
| 4598 | /* |
| 4599 | * The current time in seconds that the EC should wait in G3 before |
| 4600 | * hibernating. |
| 4601 | */ |
| 4602 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4603 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4604 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4605 | /* Inform the EC when entering a sleep state */ |
| 4606 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4607 | |
| 4608 | enum host_sleep_event { |
| 4609 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4610 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 4611 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4612 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
| 4613 | /* S3 suspend with additional enabled wake sources */ |
| 4614 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4615 | }; |
| 4616 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4617 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4618 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4619 | } __ec_align1; |
| 4620 | |
| 4621 | /* |
| 4622 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4623 | * transition failures |
| 4624 | */ |
| 4625 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4626 | |
| 4627 | /* Disable timeout detection for this sleep transition */ |
| 4628 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4629 | |
| 4630 | struct ec_params_host_sleep_event_v1 { |
| 4631 | /* The type of sleep being entered or exited. */ |
| 4632 | uint8_t sleep_event; |
| 4633 | |
| 4634 | /* Padding */ |
| 4635 | uint8_t reserved; |
| 4636 | union { |
| 4637 | /* Parameters that apply for suspend messages. */ |
| 4638 | struct { |
| 4639 | /* |
| 4640 | * The timeout in milliseconds between when this message |
| 4641 | * is received and when the EC will declare sleep |
| 4642 | * transition failure if the sleep signal is not |
| 4643 | * asserted. |
| 4644 | */ |
| 4645 | uint16_t sleep_timeout_ms; |
| 4646 | } suspend_params; |
| 4647 | |
| 4648 | /* No parameters for non-suspend messages. */ |
| 4649 | }; |
| 4650 | } __ec_align2; |
| 4651 | |
| 4652 | /* A timeout occurred when this bit is set */ |
| 4653 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4654 | |
| 4655 | /* |
| 4656 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4657 | * as well as the maximum number of suspend line transitions that will be |
| 4658 | * reported back to the host. |
| 4659 | */ |
| 4660 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4661 | |
| 4662 | struct ec_response_host_sleep_event_v1 { |
| 4663 | union { |
| 4664 | /* Response fields that apply for resume messages. */ |
| 4665 | struct { |
| 4666 | /* |
| 4667 | * The number of sleep power signal transitions that |
| 4668 | * occurred since the suspend message. The high bit |
| 4669 | * indicates a timeout occurred. |
| 4670 | */ |
| 4671 | uint32_t sleep_transitions; |
| 4672 | } resume_response; |
| 4673 | |
| 4674 | /* No response fields for non-resume messages. */ |
| 4675 | }; |
| 4676 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4677 | |
| 4678 | /*****************************************************************************/ |
| 4679 | /* Device events */ |
| 4680 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4681 | |
| 4682 | enum ec_device_event { |
| 4683 | EC_DEVICE_EVENT_TRACKPAD, |
| 4684 | EC_DEVICE_EVENT_DSP, |
| 4685 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 4686 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4687 | }; |
| 4688 | |
| 4689 | enum ec_device_event_param { |
| 4690 | /* Get and clear pending device events */ |
| 4691 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4692 | /* Get device event mask */ |
| 4693 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4694 | /* Set device event mask */ |
| 4695 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4696 | }; |
| 4697 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4698 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4699 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4700 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4701 | uint32_t event_mask; |
| 4702 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4703 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4704 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4705 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4706 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4707 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4708 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4709 | /*****************************************************************************/ |
| 4710 | /* Smart battery pass-through */ |
| 4711 | |
| 4712 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4713 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4714 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4715 | |
| 4716 | /* Get / Set string smart battery parameters |
| 4717 | * formatted as SMBUS "block". |
| 4718 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4719 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 4720 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4721 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4722 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4723 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4724 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4725 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4726 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4727 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4728 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4729 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4730 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4731 | uint8_t reg; |
| 4732 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4733 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4734 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4735 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4736 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4737 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4738 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4739 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4740 | uint8_t reg; |
| 4741 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4742 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4743 | |
| 4744 | /*****************************************************************************/ |
| 4745 | /* Battery vendor parameters |
| 4746 | * |
| 4747 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 4748 | * differ between boards or batteries. On a set operation, the response |
| 4749 | * contains the actual value set, which may be rounded or clipped from the |
| 4750 | * requested value. |
| 4751 | */ |
| 4752 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4753 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4754 | |
| 4755 | enum ec_battery_vendor_param_mode { |
| 4756 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 4757 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 4758 | }; |
| 4759 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4760 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4761 | uint32_t param; |
| 4762 | uint32_t value; |
| 4763 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4764 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4765 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4766 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4767 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4768 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4769 | |
| 4770 | /*****************************************************************************/ |
| 4771 | /* |
| 4772 | * Smart Battery Firmware Update Commands |
| 4773 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4774 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4775 | |
| 4776 | enum ec_sb_fw_update_subcmd { |
| 4777 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 4778 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 4779 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 4780 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 4781 | EC_SB_FW_UPDATE_END = 0x4, |
| 4782 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 4783 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 4784 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 4785 | }; |
| 4786 | |
| 4787 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 4788 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 4789 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 4790 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4791 | struct ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4792 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 4793 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4794 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4795 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4796 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4797 | struct ec_sb_fw_update_header hdr; |
| 4798 | union { |
| 4799 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 4800 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 4801 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 4802 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 4803 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 4804 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4805 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4806 | |
| 4807 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4808 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4809 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 4810 | } write; |
| 4811 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4812 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4813 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4814 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4815 | union { |
| 4816 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4817 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4818 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 4819 | } info; |
| 4820 | |
| 4821 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4822 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4823 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 4824 | } status; |
| 4825 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4826 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4827 | |
| 4828 | /* |
| 4829 | * Entering Verified Boot Mode Command |
| 4830 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 4831 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4832 | * |
| 4833 | * EC no longer needs to know what mode vboot has entered, |
| 4834 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4835 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4836 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4837 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4838 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4839 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4840 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4841 | |
| 4842 | #define VBOOT_MODE_NORMAL 0 |
| 4843 | #define VBOOT_MODE_DEVELOPER 1 |
| 4844 | #define VBOOT_MODE_RECOVERY 2 |
| 4845 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4846 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4847 | /* |
| 4848 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 4849 | * certain addresses (board-specific). |
| 4850 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4851 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4852 | |
| 4853 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4854 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 4855 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 4856 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4857 | }; |
| 4858 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4859 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4860 | uint8_t subcmd; |
| 4861 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4862 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4863 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4864 | struct ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4865 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4866 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4867 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4868 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4869 | /*****************************************************************************/ |
| 4870 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4871 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4872 | * |
| 4873 | * These commands are for sending and receiving message via HDMI CEC |
| 4874 | */ |
| 4875 | |
| 4876 | #define MAX_CEC_MSG_LEN 16 |
| 4877 | |
| 4878 | /* CEC message from the AP to be written on the CEC bus */ |
| 4879 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 4880 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4881 | /** |
| 4882 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 4883 | * @msg: message content to write to the CEC bus |
| 4884 | */ |
| 4885 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4886 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4887 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4888 | |
| 4889 | /* Set various CEC parameters */ |
| 4890 | #define EC_CMD_CEC_SET 0x00BA |
| 4891 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4892 | /** |
| 4893 | * struct ec_params_cec_set - CEC parameters set |
| 4894 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4895 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 4896 | * or 1 to enable CEC functionality, in case cmd is |
| 4897 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 4898 | * address between 0 and 15 or 0xff to unregister |
| 4899 | */ |
| 4900 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4901 | uint8_t cmd; /* enum cec_command */ |
| 4902 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4903 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4904 | |
| 4905 | /* Read various CEC parameters */ |
| 4906 | #define EC_CMD_CEC_GET 0x00BB |
| 4907 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4908 | /** |
| 4909 | * struct ec_params_cec_get - CEC parameters get |
| 4910 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4911 | */ |
| 4912 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4913 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4914 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4915 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4916 | /** |
| 4917 | * struct ec_response_cec_get - CEC parameters get response |
| 4918 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 4919 | * disabled or 1 if CEC functionality is enabled, |
| 4920 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 4921 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 4922 | */ |
| 4923 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4924 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4925 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4926 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4927 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4928 | enum cec_command { |
| 4929 | /* CEC reading, writing and events enable */ |
| 4930 | CEC_CMD_ENABLE, |
| 4931 | /* CEC logical address */ |
| 4932 | CEC_CMD_LOGICAL_ADDRESS, |
| 4933 | }; |
| 4934 | |
| 4935 | /* Events from CEC to AP */ |
| 4936 | enum mkbp_cec_event { |
| 4937 | /* Outgoing message was acknowledged by a follower */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4938 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4939 | /* Outgoing message was not acknowledged */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4940 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4941 | }; |
| 4942 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4943 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4944 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4945 | /* Commands for audio codec. */ |
| 4946 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4947 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4948 | enum ec_codec_subcmd { |
| 4949 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 4950 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 4951 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 4952 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4953 | }; |
| 4954 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4955 | enum ec_codec_cap { |
| 4956 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 4957 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 4958 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4959 | }; |
| 4960 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4961 | enum ec_codec_shm_id { |
| 4962 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 4963 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 4964 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4965 | }; |
| 4966 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4967 | enum ec_codec_shm_type { |
| 4968 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 4969 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4970 | }; |
| 4971 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4972 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 4973 | uint8_t shm_id; |
| 4974 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4975 | }; |
| 4976 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4977 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 4978 | uint64_t phys_addr; |
| 4979 | uint32_t len; |
| 4980 | uint8_t shm_id; |
| 4981 | uint8_t reserved[3]; |
| 4982 | }; |
| 4983 | |
| 4984 | struct __ec_align4 ec_param_ec_codec { |
| 4985 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 4986 | uint8_t reserved[3]; |
| 4987 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4988 | union { |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4989 | struct ec_param_ec_codec_get_shm_addr |
| 4990 | get_shm_addr_param; |
| 4991 | struct ec_param_ec_codec_set_shm_addr |
| 4992 | set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4993 | }; |
| 4994 | }; |
| 4995 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4996 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 4997 | uint32_t capabilities; |
| 4998 | }; |
| 4999 | |
| 5000 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5001 | uint64_t phys_addr; |
| 5002 | uint32_t len; |
| 5003 | uint8_t type; |
| 5004 | uint8_t reserved[3]; |
| 5005 | }; |
| 5006 | |
| 5007 | /*****************************************************************************/ |
| 5008 | |
| 5009 | /* Commands for DMIC on audio codec. */ |
| 5010 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5011 | |
| 5012 | enum ec_codec_dmic_subcmd { |
| 5013 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5014 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5015 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5016 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5017 | }; |
| 5018 | |
| 5019 | enum ec_codec_dmic_channel { |
| 5020 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5021 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5022 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5023 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5024 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5025 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5026 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5027 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5028 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5029 | }; |
| 5030 | |
| 5031 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5032 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5033 | uint8_t gain; |
| 5034 | uint8_t reserved[2]; |
| 5035 | }; |
| 5036 | |
| 5037 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5038 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5039 | uint8_t reserved[3]; |
| 5040 | }; |
| 5041 | |
| 5042 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5043 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5044 | uint8_t reserved[3]; |
| 5045 | |
| 5046 | union { |
| 5047 | struct ec_param_ec_codec_dmic_set_gain_idx |
| 5048 | set_gain_idx_param; |
| 5049 | struct ec_param_ec_codec_dmic_get_gain_idx |
| 5050 | get_gain_idx_param; |
| 5051 | }; |
| 5052 | }; |
| 5053 | |
| 5054 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5055 | uint8_t max_gain; |
| 5056 | }; |
| 5057 | |
| 5058 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5059 | uint8_t gain; |
| 5060 | }; |
| 5061 | |
| 5062 | /*****************************************************************************/ |
| 5063 | |
| 5064 | /* Commands for I2S RX on audio codec. */ |
| 5065 | |
| 5066 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5067 | |
| 5068 | enum ec_codec_i2s_rx_subcmd { |
| 5069 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5070 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5071 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5072 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5073 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5074 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5075 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5076 | }; |
| 5077 | |
| 5078 | enum ec_codec_i2s_rx_sample_depth { |
| 5079 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5080 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5081 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5082 | }; |
| 5083 | |
| 5084 | enum ec_codec_i2s_rx_daifmt { |
| 5085 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5086 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5087 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5088 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5089 | }; |
| 5090 | |
| 5091 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5092 | uint8_t depth; |
| 5093 | uint8_t reserved[3]; |
| 5094 | }; |
| 5095 | |
| 5096 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5097 | uint8_t left; |
| 5098 | uint8_t right; |
| 5099 | uint8_t reserved[2]; |
| 5100 | }; |
| 5101 | |
| 5102 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5103 | uint8_t daifmt; |
| 5104 | uint8_t reserved[3]; |
| 5105 | }; |
| 5106 | |
| 5107 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5108 | uint32_t bclk; |
| 5109 | }; |
| 5110 | |
| 5111 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5112 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5113 | uint8_t reserved[3]; |
| 5114 | |
| 5115 | union { |
| 5116 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
| 5117 | set_sample_depth_param; |
| 5118 | struct ec_param_ec_codec_i2s_rx_set_daifmt |
| 5119 | set_daifmt_param; |
| 5120 | struct ec_param_ec_codec_i2s_rx_set_bclk |
| 5121 | set_bclk_param; |
| 5122 | }; |
| 5123 | }; |
| 5124 | |
| 5125 | /*****************************************************************************/ |
| 5126 | /* Commands for WoV on audio codec. */ |
| 5127 | |
| 5128 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5129 | |
| 5130 | enum ec_codec_wov_subcmd { |
| 5131 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5132 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5133 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5134 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5135 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5136 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5137 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5138 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5139 | }; |
| 5140 | |
| 5141 | /* |
| 5142 | * @hash is SHA256 of the whole language model. |
| 5143 | * @total_len indicates the length of whole language model. |
| 5144 | * @offset is the cursor from the beginning of the model. |
| 5145 | * @buf is the packet buffer. |
| 5146 | * @len denotes how many bytes in the buf. |
| 5147 | */ |
| 5148 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5149 | uint8_t hash[32]; |
| 5150 | uint32_t total_len; |
| 5151 | uint32_t offset; |
| 5152 | uint8_t buf[128]; |
| 5153 | uint32_t len; |
| 5154 | }; |
| 5155 | |
| 5156 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5157 | uint8_t hash[32]; |
| 5158 | uint32_t total_len; |
| 5159 | }; |
| 5160 | |
| 5161 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5162 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5163 | uint8_t reserved[3]; |
| 5164 | |
| 5165 | union { |
| 5166 | struct ec_param_ec_codec_wov_set_lang |
| 5167 | set_lang_param; |
| 5168 | struct ec_param_ec_codec_wov_set_lang_shm |
| 5169 | set_lang_shm_param; |
| 5170 | }; |
| 5171 | }; |
| 5172 | |
| 5173 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5174 | uint8_t hash[32]; |
| 5175 | }; |
| 5176 | |
| 5177 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5178 | uint8_t buf[128]; |
| 5179 | uint32_t len; |
| 5180 | }; |
| 5181 | |
| 5182 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5183 | uint32_t offset; |
| 5184 | uint32_t len; |
| 5185 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5186 | |
| 5187 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5188 | /* Commands for PoE PSE controller */ |
| 5189 | |
| 5190 | #define EC_CMD_PSE 0x00C0 |
| 5191 | |
| 5192 | enum ec_pse_subcmd { |
| 5193 | EC_PSE_STATUS = 0x0, |
| 5194 | EC_PSE_ENABLE = 0x1, |
| 5195 | EC_PSE_DISABLE = 0x2, |
| 5196 | EC_PSE_SUBCMD_COUNT, |
| 5197 | }; |
| 5198 | |
| 5199 | struct __ec_align1 ec_params_pse { |
| 5200 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5201 | uint8_t port; /* PSE port */ |
| 5202 | }; |
| 5203 | |
| 5204 | enum ec_pse_status { |
| 5205 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5206 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5207 | EC_PSE_STATUS_POWERED = 0x2, |
| 5208 | }; |
| 5209 | |
| 5210 | struct __ec_align1 ec_response_pse_status { |
| 5211 | uint8_t status; /* enum ec_pse_status */ |
| 5212 | }; |
| 5213 | |
| 5214 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5215 | /* System commands */ |
| 5216 | |
| 5217 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5218 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5219 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5220 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5221 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5222 | |
| 5223 | /* Command */ |
| 5224 | enum ec_reboot_cmd { |
| 5225 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5226 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5227 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5228 | /* (command 3 was jump to RW-B) */ |
| 5229 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5230 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
Daisuke Nojiri | 40d0bfa | 2017-11-30 17:41:09 -0800 | [diff] [blame] | 5231 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5232 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_IDLE flag */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 5233 | EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5234 | }; |
| 5235 | |
| 5236 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5237 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5238 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5239 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5240 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5241 | struct ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5242 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5243 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5244 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5245 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5246 | /* |
| 5247 | * Get information on last EC panic. |
| 5248 | * |
| 5249 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5250 | * for details. |
| 5251 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5252 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5253 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5254 | /*****************************************************************************/ |
| 5255 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5256 | * Special commands |
| 5257 | * |
| 5258 | * These do not follow the normal rules for commands. See each command for |
| 5259 | * details. |
| 5260 | */ |
| 5261 | |
| 5262 | /* |
| 5263 | * Reboot NOW |
| 5264 | * |
| 5265 | * This command will work even when the EC LPC interface is busy, because the |
| 5266 | * reboot command is processed at interrupt level. Note that when the EC |
| 5267 | * reboots, the host will reboot too, so there is no response to this command. |
| 5268 | * |
| 5269 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5270 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5271 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5272 | |
| 5273 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5274 | * Resend last response (not supported on LPC). |
| 5275 | * |
| 5276 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5277 | * there was no previous command, or the previous command's response was too |
| 5278 | * big to save. |
| 5279 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5280 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5281 | |
| 5282 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5283 | * This header byte on a command indicate version 0. Any header byte less |
| 5284 | * than this means that we are talking to an old EC which doesn't support |
| 5285 | * versioning. In that case, we assume version 0. |
| 5286 | * |
| 5287 | * Header bytes greater than this indicate a later version. For example, |
| 5288 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5289 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5290 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5291 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5292 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5293 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5294 | /*****************************************************************************/ |
| 5295 | /* |
| 5296 | * PD commands |
| 5297 | * |
| 5298 | * These commands are for PD MCU communication. |
| 5299 | */ |
| 5300 | |
| 5301 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5302 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5303 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5304 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5305 | enum pd_charge_state { |
| 5306 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 5307 | PD_CHARGE_NONE, /* No charging allowed */ |
| 5308 | PD_CHARGE_5V, /* 5V charging only */ |
| 5309 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 5310 | }; |
| 5311 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5312 | /* Status of EC being sent to PD */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5313 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5314 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5315 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5316 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5317 | int8_t batt_soc; /* battery state of charge */ |
| 5318 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5319 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5320 | |
| 5321 | /* Status of PD being sent back to EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5322 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5323 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
| 5324 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
| 5325 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5326 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5327 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5328 | #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] | 5329 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 5330 | PD_STATUS_TCPC_ALERT_1 | \ |
| 5331 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5332 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5333 | uint32_t curr_lim_ma; /* input current limit */ |
| 5334 | uint16_t status; /* PD MCU status */ |
| 5335 | int8_t active_charge_port; /* active charging port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5336 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5337 | |
| 5338 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5339 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5340 | |
| 5341 | /* PD MCU host event status bits */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5342 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5343 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5344 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5345 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5346 | #define PD_EVENT_TYPEC BIT(4) |
| 5347 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5348 | struct ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5349 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5350 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5351 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5352 | /* |
| 5353 | * Set USB type-C port role and muxes |
| 5354 | * |
| 5355 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5356 | * |
| 5357 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5358 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5359 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5360 | |
| 5361 | enum usb_pd_control_role { |
| 5362 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5363 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5364 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5365 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5366 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5367 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5368 | USB_PD_CTRL_ROLE_COUNT |
| 5369 | }; |
| 5370 | |
| 5371 | enum usb_pd_control_mux { |
| 5372 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5373 | USB_PD_CTRL_MUX_NONE = 1, |
| 5374 | USB_PD_CTRL_MUX_USB = 2, |
| 5375 | USB_PD_CTRL_MUX_DP = 3, |
| 5376 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5377 | USB_PD_CTRL_MUX_AUTO = 5, |
| 5378 | USB_PD_CTRL_MUX_COUNT |
| 5379 | }; |
| 5380 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5381 | enum usb_pd_control_swap { |
| 5382 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5383 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5384 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5385 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 5386 | USB_PD_CTRL_SWAP_COUNT |
| 5387 | }; |
| 5388 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5389 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5390 | uint8_t port; |
| 5391 | uint8_t role; |
| 5392 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5393 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5394 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5395 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5396 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5397 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
| 5398 | #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] | 5399 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5400 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5401 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5402 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5403 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5404 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5405 | #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] | 5406 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5407 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5408 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5409 | uint8_t enabled; |
| 5410 | uint8_t role; |
| 5411 | uint8_t polarity; |
| 5412 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5413 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5414 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5415 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5416 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5417 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5418 | uint8_t polarity; |
| 5419 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5420 | } __ec_align1; |
| 5421 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5422 | /* Possible port partner connections based on CC line states */ |
| 5423 | enum pd_cc_states { |
| 5424 | PD_CC_NONE = 0, /* No port partner attached */ |
| 5425 | |
| 5426 | /* From DFP perspective */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5427 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5428 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5429 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5430 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
| 5431 | |
| 5432 | /* From UFP perspective */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5433 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5434 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5435 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5436 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5437 | /* Active/Passive Cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5438 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5439 | /* Optical/Non-optical cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5440 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5441 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5442 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
| 5443 | /* Active Link Uni-Direction */ |
| 5444 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5445 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5446 | struct ec_response_usb_pd_control_v2 { |
| 5447 | uint8_t enabled; |
| 5448 | uint8_t role; |
| 5449 | uint8_t polarity; |
| 5450 | char state[32]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5451 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5452 | 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] | 5453 | uint8_t reserved; /* Reserved for future use */ |
| 5454 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 5455 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5456 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5457 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5458 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5459 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5460 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5461 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5462 | #define EC_USB_PD_MAX_PORTS 8 |
| 5463 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5464 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5465 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5466 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5467 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5468 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5469 | |
| 5470 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5471 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5472 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5473 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5474 | |
| 5475 | enum usb_chg_type { |
| 5476 | USB_CHG_TYPE_NONE, |
| 5477 | USB_CHG_TYPE_PD, |
| 5478 | USB_CHG_TYPE_C, |
| 5479 | USB_CHG_TYPE_PROPRIETARY, |
| 5480 | USB_CHG_TYPE_BC12_DCP, |
| 5481 | USB_CHG_TYPE_BC12_CDP, |
| 5482 | USB_CHG_TYPE_BC12_SDP, |
| 5483 | USB_CHG_TYPE_OTHER, |
| 5484 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5485 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5486 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5487 | }; |
| 5488 | enum usb_power_roles { |
| 5489 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5490 | USB_PD_PORT_POWER_SOURCE, |
| 5491 | USB_PD_PORT_POWER_SINK, |
| 5492 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5493 | }; |
| 5494 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5495 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5496 | uint16_t voltage_max; |
| 5497 | uint16_t voltage_now; |
| 5498 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5499 | uint16_t current_lim; |
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 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5502 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5503 | uint8_t role; |
| 5504 | uint8_t type; |
| 5505 | uint8_t dualrole; |
| 5506 | uint8_t reserved1; |
| 5507 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5508 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5509 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5510 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5511 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5512 | /* |
| 5513 | * This command will return the number of USB PD charge port + the number |
| 5514 | * of dedicated port present. |
| 5515 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5516 | */ |
| 5517 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5518 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5519 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5520 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5521 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5522 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5523 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5524 | |
| 5525 | enum usb_pd_fw_update_cmds { |
| 5526 | USB_PD_FW_REBOOT, |
| 5527 | USB_PD_FW_FLASH_ERASE, |
| 5528 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5529 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5530 | }; |
| 5531 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5532 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5533 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5534 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5535 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5536 | uint32_t size; /* Size to write in bytes */ |
| 5537 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5538 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5539 | |
| 5540 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5541 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5542 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5543 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5544 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5545 | uint16_t dev_id; |
| 5546 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5547 | uint8_t reserved; /* |
| 5548 | * For alignment of current_image |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5549 | * TODO(rspangler) but it's not aligned! |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5550 | * Should have been reserved[2]. |
| 5551 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5552 | uint32_t current_image; /* One of ec_image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5553 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5554 | |
| 5555 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5556 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5557 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5558 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5559 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5560 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5561 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5562 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5563 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5564 | struct ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5565 | uint16_t vid; /* USB-IF VID */ |
| 5566 | uint16_t pid; /* USB-IF PID */ |
| 5567 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5568 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5569 | |
| 5570 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5571 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5572 | |
| 5573 | /* Negative port parameters have special meaning */ |
| 5574 | enum usb_pd_override_ports { |
| 5575 | OVERRIDE_DONT_CHARGE = -2, |
| 5576 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5577 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5578 | }; |
| 5579 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5580 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5581 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5582 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5583 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5584 | /* |
| 5585 | * Read (and delete) one entry of PD event log. |
| 5586 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5587 | * future non-PD logs that use the same internal EC event_log. |
| 5588 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5589 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5590 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5591 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5592 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 5593 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5594 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5595 | uint16_t data; /* type-defined data payload */ |
| 5596 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5597 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5598 | |
| 5599 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5600 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5601 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5602 | #define PD_LOG_SIZE_MASK 0x1f |
| 5603 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5604 | #define PD_LOG_PORT_SHIFT 5 |
| 5605 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 5606 | ((size) & PD_LOG_SIZE_MASK)) |
| 5607 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 5608 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 5609 | |
| 5610 | /* PD event log : entry types */ |
| 5611 | /* PD MCU events */ |
| 5612 | #define PD_EVENT_MCU_BASE 0x00 |
| 5613 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 5614 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 5615 | /* Reserved for custom board event */ |
| 5616 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 5617 | /* PD generic accessory events */ |
| 5618 | #define PD_EVENT_ACC_BASE 0x20 |
| 5619 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 5620 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 5621 | /* PD power supply events */ |
| 5622 | #define PD_EVENT_PS_BASE 0x40 |
| 5623 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 5624 | /* PD video dongles events */ |
| 5625 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5626 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 5627 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 5628 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5629 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5630 | |
| 5631 | /* |
| 5632 | * PD_EVENT_MCU_CHARGE event definition : |
| 5633 | * the payload is "struct usb_chg_measures" |
| 5634 | * the data field contains the port state flags as defined below : |
| 5635 | */ |
| 5636 | /* Port partner is a dual role device */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5637 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5638 | /* Port is the pending override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5639 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5640 | /* Port is the override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5641 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5642 | /* Charger type */ |
| 5643 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5644 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5645 | /* Power delivery role */ |
| 5646 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 5647 | |
| 5648 | /* |
| 5649 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5650 | */ |
| 5651 | #define PS_FAULT_OCP 1 |
| 5652 | #define PS_FAULT_FAST_OCP 2 |
| 5653 | #define PS_FAULT_OVP 3 |
| 5654 | #define PS_FAULT_DISCH 4 |
| 5655 | |
| 5656 | /* |
| 5657 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5658 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5659 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5660 | uint8_t major; |
| 5661 | uint8_t minor; |
| 5662 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5663 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5664 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5665 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5666 | uint8_t family[2]; |
| 5667 | uint8_t chipid[2]; |
| 5668 | struct mcdp_version irom; |
| 5669 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5670 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5671 | |
| 5672 | /* struct mcdp_info field decoding */ |
| 5673 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5674 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5675 | |
| 5676 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5677 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5678 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5679 | uint16_t svid_idx; /* SVID index to get */ |
| 5680 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5681 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5682 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5683 | struct ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5684 | uint16_t svid; /* SVID */ |
| 5685 | uint16_t opos; /* Object Position */ |
| 5686 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5687 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5688 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5689 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5690 | |
| 5691 | enum pd_mode_cmd { |
| 5692 | PD_EXIT_MODE = 0, |
| 5693 | PD_ENTER_MODE = 1, |
| 5694 | /* Not a command. Do NOT remove. */ |
| 5695 | PD_MODE_CMD_COUNT, |
| 5696 | }; |
| 5697 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5698 | struct ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5699 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 5700 | uint16_t svid; /* SVID to set */ |
| 5701 | uint8_t opos; /* Object Position */ |
| 5702 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5703 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5704 | |
| 5705 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5706 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5707 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5708 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5709 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 5710 | 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] | 5711 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5712 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5713 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5714 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5715 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5716 | |
| 5717 | enum ec_pd_control_cmd { |
| 5718 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 5719 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 5720 | PD_RESET, /* Force reset the PD chip */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5721 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 5722 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5723 | }; |
| 5724 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5725 | struct ec_params_pd_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5726 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5727 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5728 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5729 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5730 | /* Get info about USB-C SS muxes */ |
| 5731 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 5732 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5733 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5734 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5735 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5736 | |
| 5737 | /* Flags representing mux state */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5738 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 5739 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 5740 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 5741 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 5742 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 5743 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 5744 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
| 5745 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5746 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
| 5747 | |
| 5748 | /* USB-C Dock connected */ |
| 5749 | #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] | 5750 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5751 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5752 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5753 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5754 | |
| 5755 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 5756 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5757 | struct ec_params_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5758 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5759 | /* |
| 5760 | * Fetch the live chip info or hard-coded + cached chip info |
| 5761 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 5762 | * 1: live chip value for VID/PID/FW Version |
| 5763 | */ |
| 5764 | uint8_t live; |
| 5765 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5766 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5767 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5768 | uint16_t vendor_id; |
| 5769 | uint16_t product_id; |
| 5770 | uint16_t device_id; |
| 5771 | union { |
| 5772 | uint8_t fw_version_string[8]; |
| 5773 | uint64_t fw_version_number; |
| 5774 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5775 | } __ec_align2; |
| 5776 | |
| 5777 | struct ec_response_pd_chip_info_v1 { |
| 5778 | uint16_t vendor_id; |
| 5779 | uint16_t product_id; |
| 5780 | uint16_t device_id; |
| 5781 | union { |
| 5782 | uint8_t fw_version_string[8]; |
| 5783 | uint64_t fw_version_number; |
| 5784 | }; |
| 5785 | union { |
| 5786 | uint8_t min_req_fw_version_string[8]; |
| 5787 | uint64_t min_req_fw_version_number; |
| 5788 | }; |
| 5789 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5790 | |
| 5791 | /* Run RW signature verification and get status */ |
| 5792 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 5793 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5794 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5795 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5796 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5797 | |
| 5798 | /* For controlling RWSIG task */ |
| 5799 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 5800 | |
| 5801 | enum rwsig_action { |
| 5802 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 5803 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 5804 | }; |
| 5805 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5806 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5807 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5808 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5809 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5810 | /* Run verification on a slot */ |
| 5811 | #define EC_CMD_EFS_VERIFY 0x011E |
| 5812 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5813 | struct ec_params_efs_verify { |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5814 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5815 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5816 | |
| 5817 | /* |
| 5818 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 5819 | * type. Integers return a uint32. Strings return a string, using the response |
| 5820 | * size to determine how big it is. |
| 5821 | */ |
| 5822 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
| 5823 | /* |
| 5824 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 5825 | * hardware write-protect enabled. |
| 5826 | */ |
| 5827 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
| 5828 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5829 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5830 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
| 5831 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 5832 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 5833 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Wisley Chen | c1efec7 | 2018-11-06 09:28:23 +0800 | [diff] [blame] | 5834 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5835 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5836 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5837 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5838 | /* Second Source Factory Cache */ |
| 5839 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5840 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5841 | }; |
| 5842 | |
| 5843 | /* |
| 5844 | * Flags to control read operation |
| 5845 | * |
| 5846 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 5847 | * write was successful without reboot. |
| 5848 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5849 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5850 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5851 | struct ec_params_get_cbi { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5852 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5853 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5854 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5855 | |
| 5856 | /* |
| 5857 | * Flags to control write behavior. |
| 5858 | * |
| 5859 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 5860 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5861 | * 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] | 5862 | * will be initialized to zero first. |
| 5863 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5864 | #define CBI_SET_NO_SYNC BIT(0) |
| 5865 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5866 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5867 | struct ec_params_set_cbi { |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5868 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5869 | uint32_t flag; /* CBI_SET_* */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5870 | uint32_t size; /* Data size */ |
| 5871 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5872 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5873 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5874 | /* |
| 5875 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 5876 | */ |
| 5877 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 5878 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 5879 | /* EC reset causes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5880 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 5881 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 5882 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 5883 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 5884 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 5885 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 5886 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 5887 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 5888 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 5889 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 5890 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 5891 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 5892 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
| 5893 | #define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from |
| 5894 | * previous boot |
| 5895 | */ |
| 5896 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 5897 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 5898 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 5899 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
| 5900 | #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] | 5901 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This |
| 5902 | * enables PD in RO for Chromebox. |
| 5903 | */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5904 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 5905 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 5906 | #define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5907 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 5908 | /* |
| 5909 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 5910 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 5911 | * compatibility: |
| 5912 | * - New entries must be inserted prior to the _COUNT field |
| 5913 | * - If an existing entry is no longer in service, it must be replaced with a |
| 5914 | * RESERVED entry instead. |
| 5915 | * - The semantic meaning of an entry should not change. |
| 5916 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 5917 | */ |
| 5918 | enum chipset_reset_reason { |
| 5919 | CHIPSET_RESET_BEGIN = 0, |
| 5920 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 5921 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 5922 | CHIPSET_RESET_BOARD_CUSTOM, |
| 5923 | /* Believe that the AP has hung */ |
| 5924 | CHIPSET_RESET_HANG_REBOOT, |
| 5925 | /* Reset by EC console command */ |
| 5926 | CHIPSET_RESET_CONSOLE_CMD, |
| 5927 | /* Reset by EC host command */ |
| 5928 | CHIPSET_RESET_HOST_CMD, |
| 5929 | /* Keyboard module reset key combination */ |
| 5930 | CHIPSET_RESET_KB_SYSRESET, |
| 5931 | /* Keyboard module warm reboot */ |
| 5932 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 5933 | /* Debug module warm reboot */ |
| 5934 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 5935 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 5936 | CHIPSET_RESET_AP_REQ, |
| 5937 | /* Reset as side-effect of startup sequence */ |
| 5938 | CHIPSET_RESET_INIT, |
| 5939 | /* EC detected an AP watchdog event. */ |
| 5940 | CHIPSET_RESET_AP_WATCHDOG, |
| 5941 | |
| 5942 | CHIPSET_RESET_COUNT, |
| 5943 | }; |
| 5944 | |
| 5945 | /* |
| 5946 | * AP hard shutdowns are logged on the same path as resets. |
| 5947 | */ |
| 5948 | enum chipset_shutdown_reason { |
| 5949 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 5950 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 5951 | /* Forcing a shutdown as part of EC initialization */ |
| 5952 | CHIPSET_SHUTDOWN_INIT, |
| 5953 | /* Custom reason on a per-board basis. */ |
| 5954 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 5955 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 5956 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 5957 | /* A power_wait_signal is being asserted */ |
| 5958 | CHIPSET_SHUTDOWN_WAIT, |
| 5959 | /* Critical battery level. */ |
| 5960 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 5961 | /* Because you told me to. */ |
| 5962 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 5963 | /* Forcing a shutdown to effect entry to G3. */ |
| 5964 | CHIPSET_SHUTDOWN_G3, |
| 5965 | /* Force shutdown due to over-temperature. */ |
| 5966 | CHIPSET_SHUTDOWN_THERMAL, |
| 5967 | /* Force a chipset shutdown from the power button through EC */ |
| 5968 | CHIPSET_SHUTDOWN_BUTTON, |
| 5969 | |
| 5970 | CHIPSET_SHUTDOWN_COUNT, |
| 5971 | }; |
| 5972 | |
| 5973 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5974 | struct ec_response_uptime_info { |
| 5975 | /* |
| 5976 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 5977 | * typically do not restart the EC's time_since_boot epoch. |
| 5978 | * |
| 5979 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 5980 | * sense of time, in both phase and frequency. This timebase is similar |
| 5981 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 5982 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5983 | uint32_t time_since_ec_boot_ms; |
| 5984 | |
| 5985 | /* |
| 5986 | * Number of times the AP was reset by the EC since the last EC boot. |
| 5987 | * Note that the AP may be held in reset by the EC during the initial |
| 5988 | * boot sequence, such that the very first AP boot may count as more |
| 5989 | * than one here. |
| 5990 | */ |
| 5991 | uint32_t ap_resets_since_ec_boot; |
| 5992 | |
| 5993 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5994 | * The set of flags which describe the EC's most recent reset. |
| 5995 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5996 | */ |
| 5997 | uint32_t ec_reset_flags; |
| 5998 | |
| 5999 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6000 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6001 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6002 | uint16_t reset_cause; |
| 6003 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6004 | /* Reserved for protocol growth. */ |
| 6005 | uint16_t reserved; |
| 6006 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6007 | /* |
| 6008 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6009 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6010 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6011 | */ |
| 6012 | uint32_t reset_time_ms; |
| 6013 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6014 | } __ec_align4; |
| 6015 | |
| 6016 | /* |
| 6017 | * Add entropy to the device secret (stored in the rollback region). |
| 6018 | * |
| 6019 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6020 | * flash), so the commands are asynchronous. |
| 6021 | */ |
| 6022 | #define EC_CMD_ADD_ENTROPY 0x0122 |
| 6023 | |
| 6024 | enum add_entropy_action { |
| 6025 | /* Add entropy to the current secret. */ |
| 6026 | ADD_ENTROPY_ASYNC = 0, |
| 6027 | /* |
| 6028 | * Add entropy, and also make sure that the previous secret is erased. |
| 6029 | * (this can be implemented by adding entropy multiple times until |
| 6030 | * all rolback blocks have been overwritten). |
| 6031 | */ |
| 6032 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6033 | /* Read back result from the previous operation. */ |
| 6034 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6035 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6036 | |
| 6037 | struct ec_params_rollback_add_entropy { |
| 6038 | uint8_t action; |
| 6039 | } __ec_align1; |
| 6040 | |
| 6041 | /* |
| 6042 | * Perform a single read of a given ADC channel. |
| 6043 | */ |
| 6044 | #define EC_CMD_ADC_READ 0x0123 |
| 6045 | |
| 6046 | struct ec_params_adc_read { |
| 6047 | uint8_t adc_channel; |
| 6048 | } __ec_align1; |
| 6049 | |
| 6050 | struct ec_response_adc_read { |
| 6051 | int32_t adc_value; |
| 6052 | } __ec_align4; |
| 6053 | |
| 6054 | /* |
| 6055 | * Read back rollback info |
| 6056 | */ |
| 6057 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
| 6058 | |
| 6059 | struct ec_response_rollback_info { |
| 6060 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6061 | int32_t rollback_min_version; |
| 6062 | int32_t rw_rollback_version; |
| 6063 | } __ec_align4; |
| 6064 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6065 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6066 | /* Issue AP reset */ |
| 6067 | #define EC_CMD_AP_RESET 0x0125 |
| 6068 | |
| 6069 | /*****************************************************************************/ |
| 6070 | /* Locate peripheral chips |
| 6071 | * |
| 6072 | * Return values: |
| 6073 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6074 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6075 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6076 | */ |
| 6077 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6078 | |
| 6079 | enum ec_chip_type { |
| 6080 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6081 | EC_CHIP_TYPE_TCPC = 1, |
| 6082 | EC_CHIP_TYPE_COUNT, |
| 6083 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6084 | }; |
| 6085 | |
| 6086 | enum ec_bus_type { |
| 6087 | EC_BUS_TYPE_I2C = 0, |
| 6088 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6089 | EC_BUS_TYPE_COUNT, |
| 6090 | EC_BUS_TYPE_MAX = 0xFF, |
| 6091 | }; |
| 6092 | |
| 6093 | struct ec_i2c_info { |
| 6094 | uint16_t port; /* Physical port for device */ |
| 6095 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
| 6096 | }; |
| 6097 | |
| 6098 | struct ec_params_locate_chip { |
| 6099 | uint8_t type; /* enum ec_chip_type */ |
| 6100 | uint8_t index; /* Specifies one instance of chip type */ |
| 6101 | /* Used for type specific parameters in future */ |
| 6102 | union { |
| 6103 | uint16_t reserved; |
| 6104 | }; |
| 6105 | } __ec_align2; |
| 6106 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6107 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6108 | struct ec_response_locate_chip { |
| 6109 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6110 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
| 6111 | union { |
| 6112 | struct ec_i2c_info i2c_info; |
| 6113 | }; |
| 6114 | } __ec_align2; |
| 6115 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6116 | /* |
| 6117 | * Reboot AP on G3 |
| 6118 | * |
| 6119 | * This command is used for validation purpose, where the AP needs to be |
| 6120 | * returned back to S0 state from G3 state without using the servo to trigger |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6121 | * wake events. |
| 6122 | * - With command version 0: |
| 6123 | * AP reboots immediately from G3 |
| 6124 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6125 | * - With command version 1: |
| 6126 | * AP reboots after the user specified delay |
| 6127 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6128 | */ |
| 6129 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6130 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6131 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6132 | /* configurable delay in seconds in G3 state */ |
| 6133 | uint32_t reboot_ap_at_g3_delay; |
| 6134 | } __ec_align4; |
| 6135 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6136 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6137 | /* Get PD port capabilities |
| 6138 | * |
| 6139 | * Returns the following static *capabilities* of the given port: |
| 6140 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6141 | * future CrOS devices would ever be only a source, so the options are |
| 6142 | * sink or dual. |
| 6143 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6144 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6145 | * or none). |
| 6146 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6147 | * for CrOS devices. |
| 6148 | */ |
| 6149 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6150 | |
| 6151 | enum ec_pd_power_role_caps { |
| 6152 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6153 | EC_PD_POWER_ROLE_SINK = 1, |
| 6154 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6155 | }; |
| 6156 | |
| 6157 | enum ec_pd_try_power_role_caps { |
| 6158 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6159 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6160 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6161 | }; |
| 6162 | |
| 6163 | enum ec_pd_data_role_caps { |
| 6164 | EC_PD_DATA_ROLE_DFP = 0, |
| 6165 | EC_PD_DATA_ROLE_UFP = 1, |
| 6166 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6167 | }; |
| 6168 | |
| 6169 | /* From: power_manager/power_supply_properties.proto */ |
| 6170 | enum ec_pd_port_location { |
| 6171 | /* The location of the port is unknown, or there's only one port. */ |
| 6172 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6173 | |
| 6174 | /* |
| 6175 | * Various positions on the device. The first word describes the side of |
| 6176 | * the device where the port is located while the second clarifies the |
| 6177 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6178 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6179 | * device. |
| 6180 | */ |
| 6181 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6182 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6183 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6184 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6185 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6186 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
| 6187 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
| 6188 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6189 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6190 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
| 6191 | }; |
| 6192 | |
| 6193 | struct ec_params_get_pd_port_caps { |
| 6194 | uint8_t port; /* Which port to interrogate */ |
| 6195 | } __ec_align1; |
| 6196 | |
| 6197 | struct ec_response_get_pd_port_caps { |
| 6198 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6199 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6200 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6201 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
| 6202 | } __ec_align1; |
| 6203 | |
| 6204 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6205 | /* |
| 6206 | * Button press simulation |
| 6207 | * |
| 6208 | * This command is used to simulate a button press. |
| 6209 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6210 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6211 | * |
| 6212 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6213 | */ |
| 6214 | #define EC_CMD_BUTTON 0x0129 |
| 6215 | |
| 6216 | struct ec_params_button { |
| 6217 | /* Button mask aligned to enum keyboard_button_type */ |
| 6218 | uint32_t btn_mask; |
| 6219 | |
| 6220 | /* Duration in milliseconds button needs to be pressed */ |
| 6221 | uint32_t press_ms; |
| 6222 | } __ec_align1; |
| 6223 | |
| 6224 | enum keyboard_button_type { |
| 6225 | KEYBOARD_BUTTON_POWER = 0, |
| 6226 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
| 6227 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6228 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6229 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6230 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6231 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6232 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6233 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6234 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6235 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6236 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
| 6237 | |
| 6238 | KEYBOARD_BUTTON_COUNT |
| 6239 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6240 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6241 | /*****************************************************************************/ |
| 6242 | /* |
| 6243 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6244 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6245 | * Additionally, capability to send function codes for the same keys is |
| 6246 | * optional and acceptable. |
| 6247 | * |
| 6248 | * Note: If the top row can generate both function and action codes by |
| 6249 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6250 | * "function" or "action" codes by default. In both cases, the response |
| 6251 | * for this command will look the same. |
| 6252 | */ |
| 6253 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6254 | |
| 6255 | /* Possible values for the top row keys */ |
| 6256 | enum action_key { |
| 6257 | TK_ABSENT = 0, |
| 6258 | TK_BACK = 1, |
| 6259 | TK_FORWARD = 2, |
| 6260 | TK_REFRESH = 3, |
| 6261 | TK_FULLSCREEN = 4, |
| 6262 | TK_OVERVIEW = 5, |
| 6263 | TK_BRIGHTNESS_DOWN = 6, |
| 6264 | TK_BRIGHTNESS_UP = 7, |
| 6265 | TK_VOL_MUTE = 8, |
| 6266 | TK_VOL_DOWN = 9, |
| 6267 | TK_VOL_UP = 10, |
| 6268 | TK_SNAPSHOT = 11, |
| 6269 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6270 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6271 | TK_KBD_BKLIGHT_UP = 14, |
| 6272 | TK_PLAY_PAUSE = 15, |
| 6273 | TK_NEXT_TRACK = 16, |
| 6274 | TK_PREV_TRACK = 17, |
| 6275 | }; |
| 6276 | |
| 6277 | /* |
| 6278 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6279 | * If this needs to change, please create a new version of the command. |
| 6280 | */ |
| 6281 | #define MAX_TOP_ROW_KEYS 15 |
| 6282 | #define MIN_TOP_ROW_KEYS 10 |
| 6283 | |
| 6284 | /* |
| 6285 | * Is the keyboard capable of sending function keys *in addition to* |
| 6286 | * action keys. This is possible for e.g. if the keyboard has a |
| 6287 | * dedicated Fn key. |
| 6288 | */ |
| 6289 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
| 6290 | /* |
| 6291 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6292 | */ |
| 6293 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
| 6294 | /* |
| 6295 | * Whether the keyboard has a screenlock key. |
| 6296 | */ |
| 6297 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
| 6298 | |
| 6299 | struct ec_response_keybd_config { |
| 6300 | /* |
| 6301 | * Number of top row keys, excluding Esc and Screenlock. |
| 6302 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6303 | * (i.e. does not expose any tables to the kernel). |
| 6304 | */ |
| 6305 | uint8_t num_top_row_keys; |
| 6306 | |
| 6307 | /* |
| 6308 | * The action keys in the top row, in order from left to right. |
| 6309 | * The values are filled from enum action_key. Esc and Screenlock |
| 6310 | * keys are not considered part of top row keys. |
| 6311 | */ |
| 6312 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6313 | |
| 6314 | /* Capability flags */ |
| 6315 | uint8_t capabilities; |
| 6316 | |
| 6317 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6318 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6319 | /* |
| 6320 | * Configure smart discharge |
| 6321 | */ |
| 6322 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6323 | |
| 6324 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
| 6325 | |
| 6326 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6327 | struct discharge_rate { |
| 6328 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6329 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
| 6330 | }; |
| 6331 | |
| 6332 | struct smart_discharge_zone { |
| 6333 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6334 | int cutoff; |
| 6335 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6336 | int stayup; |
| 6337 | }; |
| 6338 | |
| 6339 | struct ec_params_smart_discharge { |
| 6340 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
| 6341 | /* |
| 6342 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6343 | * zero to disable smart discharging. That is, the system hibernates as |
| 6344 | * soon as the G3 idle timer expires. |
| 6345 | */ |
| 6346 | uint16_t hours_to_zero; |
| 6347 | /* Set both to zero to keep the current rates. */ |
| 6348 | struct discharge_rate drate; |
| 6349 | }; |
| 6350 | |
| 6351 | struct ec_response_smart_discharge { |
| 6352 | uint16_t hours_to_zero; |
| 6353 | struct discharge_rate drate; |
| 6354 | struct smart_discharge_zone dzone; |
| 6355 | }; |
| 6356 | |
| 6357 | /*****************************************************************************/ |
| 6358 | /* Voltage regulator controls */ |
| 6359 | |
| 6360 | /* |
| 6361 | * Get basic info of voltage regulator for given index. |
| 6362 | * |
| 6363 | * Returns the regulator name and supported voltage list in mV. |
| 6364 | */ |
| 6365 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6366 | |
| 6367 | /* Maximum length of regulator name */ |
| 6368 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6369 | |
| 6370 | /* Maximum length of the supported voltage list. */ |
| 6371 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6372 | |
| 6373 | struct ec_params_regulator_get_info { |
| 6374 | uint32_t index; |
| 6375 | } __ec_align4; |
| 6376 | |
| 6377 | struct ec_response_regulator_get_info { |
| 6378 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6379 | uint16_t num_voltages; |
| 6380 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6381 | } __ec_align2; |
| 6382 | |
| 6383 | /* |
| 6384 | * Configure the regulator as enabled / disabled. |
| 6385 | */ |
| 6386 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6387 | |
| 6388 | struct ec_params_regulator_enable { |
| 6389 | uint32_t index; |
| 6390 | uint8_t enable; |
| 6391 | } __ec_align4; |
| 6392 | |
| 6393 | /* |
| 6394 | * Query if the regulator is enabled. |
| 6395 | * |
| 6396 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6397 | */ |
| 6398 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6399 | |
| 6400 | struct ec_params_regulator_is_enabled { |
| 6401 | uint32_t index; |
| 6402 | } __ec_align4; |
| 6403 | |
| 6404 | struct ec_response_regulator_is_enabled { |
| 6405 | uint8_t enabled; |
| 6406 | } __ec_align1; |
| 6407 | |
| 6408 | /* |
| 6409 | * Set voltage for the voltage regulator within the range specified. |
| 6410 | * |
| 6411 | * The driver should select the voltage in range closest to min_mv. |
| 6412 | * |
| 6413 | * Also note that this might be called before the regulator is enabled, and the |
| 6414 | * setting should be in effect after the regulator is enabled. |
| 6415 | */ |
| 6416 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6417 | |
| 6418 | struct ec_params_regulator_set_voltage { |
| 6419 | uint32_t index; |
| 6420 | uint32_t min_mv; |
| 6421 | uint32_t max_mv; |
| 6422 | } __ec_align4; |
| 6423 | |
| 6424 | /* |
| 6425 | * Get the currently configured voltage for the voltage regulator. |
| 6426 | * |
| 6427 | * Note that this might be called before the regulator is enabled, and this |
| 6428 | * should return the configured output voltage if the regulator is enabled. |
| 6429 | */ |
| 6430 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6431 | |
| 6432 | struct ec_params_regulator_get_voltage { |
| 6433 | uint32_t index; |
| 6434 | } __ec_align4; |
| 6435 | |
| 6436 | struct ec_response_regulator_get_voltage { |
| 6437 | uint32_t voltage_mv; |
| 6438 | } __ec_align4; |
| 6439 | |
| 6440 | /* |
| 6441 | * Gather all discovery information for the given port and partner type. |
| 6442 | * |
| 6443 | * Note that if discovery has not yet completed, only the currently completed |
| 6444 | * responses will be filled in. If the discovery data structures are changed |
| 6445 | * in the process of the command running, BUSY will be returned. |
| 6446 | * |
| 6447 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6448 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6449 | * maximum parameter size. |
| 6450 | */ |
| 6451 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6452 | |
| 6453 | enum typec_partner_type { |
| 6454 | TYPEC_PARTNER_SOP = 0, |
| 6455 | TYPEC_PARTNER_SOP_PRIME = 1, |
| 6456 | }; |
| 6457 | |
| 6458 | struct ec_params_typec_discovery { |
| 6459 | uint8_t port; |
| 6460 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6461 | } __ec_align1; |
| 6462 | |
| 6463 | struct svid_mode_info { |
| 6464 | uint16_t svid; |
| 6465 | uint16_t mode_count; /* Number of modes partner sent */ |
| 6466 | uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6467 | }; |
| 6468 | |
| 6469 | struct ec_response_typec_discovery { |
| 6470 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6471 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
| 6472 | uint16_t reserved; |
| 6473 | uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6474 | struct svid_mode_info svids[0]; |
| 6475 | } __ec_align1; |
| 6476 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6477 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6478 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6479 | |
| 6480 | enum typec_control_command { |
| 6481 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6482 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6483 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
| 6484 | }; |
| 6485 | |
| 6486 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6487 | enum typec_mode { |
| 6488 | TYPEC_MODE_DP, |
| 6489 | TYPEC_MODE_TBT, |
| 6490 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6491 | }; |
| 6492 | |
| 6493 | struct ec_params_typec_control { |
| 6494 | uint8_t port; |
| 6495 | uint8_t command; /* enum typec_control_command */ |
| 6496 | uint16_t reserved; |
| 6497 | |
| 6498 | /* |
| 6499 | * This section will be interpreted based on |command|. Define a |
| 6500 | * placeholder structure to avoid having to increase the size and bump |
| 6501 | * the command version when adding new sub-commands. |
| 6502 | */ |
| 6503 | union { |
| 6504 | uint32_t clear_events_mask; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6505 | uint8_t mode_to_enter; /* enum typec_mode */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6506 | uint8_t placeholder[128]; |
| 6507 | }; |
| 6508 | } __ec_align1; |
| 6509 | |
| 6510 | /* |
| 6511 | * Gather all status information for a port. |
| 6512 | * |
| 6513 | * Note: this covers many of the return fields from the deprecated |
| 6514 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 6515 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 6516 | * EC_CMD_USB_PD_CONTROL command. |
| 6517 | * |
| 6518 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6519 | */ |
| 6520 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 6521 | |
| 6522 | /* |
| 6523 | * Power role. |
| 6524 | * |
| 6525 | * Note this is also used for PD header creation, and values align to those in |
| 6526 | * the Power Delivery Specification Revision 3.0 (See |
| 6527 | * 6.2.1.1.4 Port Power Role). |
| 6528 | */ |
| 6529 | enum pd_power_role { |
| 6530 | PD_ROLE_SINK = 0, |
| 6531 | PD_ROLE_SOURCE = 1 |
| 6532 | }; |
| 6533 | |
| 6534 | /* |
| 6535 | * Data role. |
| 6536 | * |
| 6537 | * Note this is also used for PD header creation, and the first two values |
| 6538 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 6539 | * 6.2.1.1.6 Port Data Role). |
| 6540 | */ |
| 6541 | enum pd_data_role { |
| 6542 | PD_ROLE_UFP = 0, |
| 6543 | PD_ROLE_DFP = 1, |
| 6544 | PD_ROLE_DISCONNECTED = 2, |
| 6545 | }; |
| 6546 | |
| 6547 | enum pd_vconn_role { |
| 6548 | PD_ROLE_VCONN_OFF = 0, |
| 6549 | PD_ROLE_VCONN_SRC = 1, |
| 6550 | }; |
| 6551 | |
| 6552 | /* |
| 6553 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 6554 | * regardless of whether a debug accessory is connected. |
| 6555 | */ |
| 6556 | enum tcpc_cc_polarity { |
| 6557 | /* |
| 6558 | * _CCx: is used to indicate the polarity while not connected to |
| 6559 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 6560 | * the other will be open. |
| 6561 | */ |
| 6562 | POLARITY_CC1 = 0, |
| 6563 | POLARITY_CC2 = 1, |
| 6564 | |
| 6565 | /* |
| 6566 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 6567 | * SRC Debug Accessory. Assert resistors on both lines. |
| 6568 | */ |
| 6569 | POLARITY_CC1_DTS = 2, |
| 6570 | POLARITY_CC2_DTS = 3, |
| 6571 | |
| 6572 | /* |
| 6573 | * The current TCPC code relies on these specific POLARITY values. |
| 6574 | * Adding in a check to verify if the list grows for any reason |
| 6575 | * that this will give a hint that other places need to be |
| 6576 | * adjusted. |
| 6577 | */ |
| 6578 | POLARITY_COUNT |
| 6579 | }; |
| 6580 | |
| 6581 | #define MODE_DP_PIN_A BIT(0) |
| 6582 | #define MODE_DP_PIN_B BIT(1) |
| 6583 | #define MODE_DP_PIN_C BIT(2) |
| 6584 | #define MODE_DP_PIN_D BIT(3) |
| 6585 | #define MODE_DP_PIN_E BIT(4) |
| 6586 | #define MODE_DP_PIN_F BIT(5) |
| 6587 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
| 6588 | |
| 6589 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 6590 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
| 6591 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6592 | /* |
| 6593 | * Encode and decode for BCD revision response |
| 6594 | * |
| 6595 | * Note: the major revision set is written assuming that the value given is the |
| 6596 | * Specification Revision from the PD header, which currently only maps to PD |
| 6597 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 6598 | */ |
| 6599 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 6600 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 6601 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
| 6602 | |
| 6603 | /* |
| 6604 | * Decode helpers for Source and Sink Capability PDOs |
| 6605 | * |
| 6606 | * Note: The Power Delivery Specification should be considered the ultimate |
| 6607 | * source of truth on the decoding of these PDOs |
| 6608 | */ |
| 6609 | #define PDO_TYPE_FIXED (0 << 30) |
| 6610 | #define PDO_TYPE_BATTERY (1 << 30) |
| 6611 | #define PDO_TYPE_VARIABLE (2 << 30) |
| 6612 | #define PDO_TYPE_AUGMENTED (3 << 30) |
| 6613 | #define PDO_TYPE_MASK (3 << 30) |
| 6614 | |
| 6615 | /* |
| 6616 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 6617 | * |
| 6618 | * <31:30> : Fixed Supply |
| 6619 | * <29> : Dual-Role Power |
| 6620 | * <28> : SNK/SRC dependent |
| 6621 | * <27> : Unconstrained Power |
| 6622 | * <26> : USB Communications Capable |
| 6623 | * <25> : Dual-Role Data |
| 6624 | * <24:20> : SNK/SRC dependent |
| 6625 | * <19:10> : Voltage in 50mV Units |
| 6626 | * <9:0> : Maximum Current in 10mA units |
| 6627 | */ |
| 6628 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 6629 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 6630 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 6631 | #define PDO_FIXED_DATA_SWAP BIT(25) |
| 6632 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
| 6633 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6634 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
| 6635 | |
| 6636 | /* |
| 6637 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 6638 | * |
| 6639 | * <31:30> : Battery |
| 6640 | * <29:20> : Maximum Voltage in 50mV units |
| 6641 | * <19:10> : Minimum Voltage in 50mV units |
| 6642 | * <9:0> : Maximum Allowable Power in 250mW units |
| 6643 | */ |
| 6644 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6645 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6646 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
| 6647 | |
| 6648 | /* |
| 6649 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 6650 | * |
| 6651 | * <31:30> : Variable Supply (non-Battery) |
| 6652 | * <29:20> : Maximum Voltage in 50mV units |
| 6653 | * <19:10> : Minimum Voltage in 50mV units |
| 6654 | * <9:0> : Operational Current in 10mA units |
| 6655 | */ |
| 6656 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6657 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6658 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
| 6659 | |
| 6660 | /* |
| 6661 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 6662 | * |
| 6663 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 6664 | * supported as of the cited version. |
| 6665 | * |
| 6666 | * <31:30> : Augmented Power Data Object |
| 6667 | * <29:28> : Programmable Power Supply |
| 6668 | * <27> : PPS Power Limited |
| 6669 | * <26:25> : Reserved |
| 6670 | * <24:17> : Maximum Voltage in 100mV increments |
| 6671 | * <16> : Reserved |
| 6672 | * <15:8> : Minimum Voltage in 100mV increments |
| 6673 | * <7> : Reserved |
| 6674 | * <6:0> : Maximum Current in 50mA increments |
| 6675 | */ |
| 6676 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 6677 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 6678 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
| 6679 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6680 | struct ec_params_typec_status { |
| 6681 | uint8_t port; |
| 6682 | } __ec_align1; |
| 6683 | |
| 6684 | struct ec_response_typec_status { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6685 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 6686 | uint8_t dev_connected; /* Device connected - bool */ |
| 6687 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 6688 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6689 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6690 | uint8_t power_role; /* enum pd_power_role */ |
| 6691 | uint8_t data_role; /* enum pd_data_role */ |
| 6692 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 6693 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6694 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6695 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 6696 | uint8_t cc_state; /* enum pd_cc_states */ |
| 6697 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 6698 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6699 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6700 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6701 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6702 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6703 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6704 | /* |
| 6705 | * BCD PD revisions for partners |
| 6706 | * |
| 6707 | * The format has the PD major reversion in the upper nibble, and PD |
| 6708 | * minor version in the next nibble. Following two nibbles are |
| 6709 | * currently 0. |
| 6710 | * ex. PD 3.2 would map to 0x3200 |
| 6711 | * |
| 6712 | * PD major/minor will be 0 if no PD device is connected. |
| 6713 | */ |
| 6714 | uint16_t sop_revision; |
| 6715 | uint16_t sop_prime_revision; |
| 6716 | |
| 6717 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 6718 | |
| 6719 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6720 | } __ec_align1; |
| 6721 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 6722 | /** |
| 6723 | * Get the number of peripheral charge ports |
| 6724 | */ |
| 6725 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 6726 | |
| 6727 | #define EC_PCHG_MAX_PORTS 8 |
| 6728 | |
| 6729 | struct ec_response_pchg_count { |
| 6730 | uint8_t port_count; |
| 6731 | } __ec_align1; |
| 6732 | |
| 6733 | /** |
| 6734 | * Get the status of a peripheral charge port |
| 6735 | */ |
| 6736 | #define EC_CMD_PCHG 0x0135 |
| 6737 | |
| 6738 | struct ec_params_pchg { |
| 6739 | uint8_t port; |
| 6740 | } __ec_align1; |
| 6741 | |
| 6742 | struct ec_response_pchg { |
| 6743 | uint32_t error; /* enum pchg_error */ |
| 6744 | uint8_t state; /* enum pchg_state state */ |
| 6745 | uint8_t battery_percentage; |
| 6746 | } __ec_align2; |
| 6747 | |
| 6748 | enum pchg_state { |
| 6749 | /* Charger is reset and not initialized. */ |
| 6750 | PCHG_STATE_RESET = 0, |
| 6751 | /* Charger is initialized or disabled. */ |
| 6752 | PCHG_STATE_INITIALIZED, |
| 6753 | /* Charger is enabled and ready to detect a device. */ |
| 6754 | PCHG_STATE_ENABLED, |
| 6755 | /* Device is detected in proximity. */ |
| 6756 | PCHG_STATE_DETECTED, |
| 6757 | /* Device is being charged. */ |
| 6758 | PCHG_STATE_CHARGING, |
| 6759 | }; |
| 6760 | |
| 6761 | #define EC_PCHG_STATE_TEXT { \ |
| 6762 | [PCHG_STATE_RESET] = "RESET", \ |
| 6763 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 6764 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 6765 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 6766 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
| 6767 | } |
| 6768 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6769 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6770 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6771 | |
| 6772 | /*****************************************************************************/ |
| 6773 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6774 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6775 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6776 | #define EC_CMD_CR51_BASE 0x0300 |
| 6777 | #define EC_CMD_CR51_LAST 0x03FF |
| 6778 | |
| 6779 | /*****************************************************************************/ |
| 6780 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 6781 | |
| 6782 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 6783 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 6784 | |
| 6785 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 6786 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6787 | struct ec_params_fp_passthru { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6788 | uint16_t len; /* Number of bytes to write then read */ |
| 6789 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 6790 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6791 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6792 | |
| 6793 | /* Configure the Fingerprint MCU behavior */ |
| 6794 | #define EC_CMD_FP_MODE 0x0402 |
| 6795 | |
| 6796 | /* Put the sensor in its lowest power mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6797 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6798 | /* Wait to see a finger on the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6799 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6800 | /* Poll until the finger has left the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6801 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6802 | /* Capture the current finger image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6803 | #define FP_MODE_CAPTURE BIT(3) |
| 6804 | /* Finger enrollment session on-going */ |
| 6805 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 6806 | /* Enroll the current finger image */ |
| 6807 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
| 6808 | /* Try to match the current finger image */ |
| 6809 | #define FP_MODE_MATCH BIT(6) |
| 6810 | /* Reset and re-initialize the sensor. */ |
| 6811 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6812 | /* Sensor maintenance for dead pixels. */ |
| 6813 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6814 | /* special value: don't change anything just read back current mode */ |
| 6815 | #define FP_MODE_DONT_CHANGE BIT(31) |
| 6816 | |
| 6817 | #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ |
| 6818 | FP_MODE_FINGER_DOWN | \ |
| 6819 | FP_MODE_FINGER_UP | \ |
| 6820 | FP_MODE_CAPTURE | \ |
| 6821 | FP_MODE_ENROLL_SESSION | \ |
| 6822 | FP_MODE_ENROLL_IMAGE | \ |
| 6823 | FP_MODE_MATCH | \ |
| 6824 | FP_MODE_RESET_SENSOR | \ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6825 | FP_MODE_SENSOR_MAINTENANCE | \ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6826 | FP_MODE_DONT_CHANGE) |
| 6827 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6828 | /* Capture types defined in bits [30..28] */ |
| 6829 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6830 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
| 6831 | /* |
| 6832 | * This enum must remain ordered, if you add new values you must ensure that |
| 6833 | * FP_CAPTURE_TYPE_MAX is still the last one. |
| 6834 | */ |
| 6835 | enum fp_capture_type { |
| 6836 | /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ |
| 6837 | FP_CAPTURE_VENDOR_FORMAT = 0, |
| 6838 | /* Simple raw image capture (produces width x height x bpp bits) */ |
| 6839 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
| 6840 | /* Self test pattern (e.g. checkerboard) */ |
| 6841 | FP_CAPTURE_PATTERN0 = 2, |
| 6842 | /* Self test pattern (e.g. inverted checkerboard) */ |
| 6843 | FP_CAPTURE_PATTERN1 = 3, |
| 6844 | /* Capture for Quality test with fixed contrast */ |
| 6845 | FP_CAPTURE_QUALITY_TEST = 4, |
| 6846 | /* Capture for pixel reset value test */ |
| 6847 | FP_CAPTURE_RESET_TEST = 5, |
| 6848 | FP_CAPTURE_TYPE_MAX, |
| 6849 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6850 | /* Extracts the capture type from the sensor 'mode' word */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6851 | #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ |
| 6852 | >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6853 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6854 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6855 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6856 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6857 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6858 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6859 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6860 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6861 | |
| 6862 | /* Retrieve Fingerprint sensor information */ |
| 6863 | #define EC_CMD_FP_INFO 0x0403 |
| 6864 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6865 | /* Number of dead pixels detected on the last maintenance */ |
| 6866 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6867 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 6868 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6869 | /* No interrupt from the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6870 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6871 | /* SPI communication error */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6872 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6873 | /* Invalid sensor Hardware ID */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6874 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6875 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6876 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6877 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6878 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6879 | /* Sensor identification */ |
| 6880 | uint32_t vendor_id; |
| 6881 | uint32_t product_id; |
| 6882 | uint32_t model_id; |
| 6883 | uint32_t version; |
| 6884 | /* Image frame characteristics */ |
| 6885 | uint32_t frame_size; |
| 6886 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6887 | uint16_t width; |
| 6888 | uint16_t height; |
| 6889 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6890 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6891 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6892 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6893 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6894 | /* Sensor identification */ |
| 6895 | uint32_t vendor_id; |
| 6896 | uint32_t product_id; |
| 6897 | uint32_t model_id; |
| 6898 | uint32_t version; |
| 6899 | /* Image frame characteristics */ |
| 6900 | uint32_t frame_size; |
| 6901 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6902 | uint16_t width; |
| 6903 | uint16_t height; |
| 6904 | uint16_t bpp; |
| 6905 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 6906 | /* Template/finger current information */ |
| 6907 | uint32_t template_size; /* max template size in bytes */ |
| 6908 | uint16_t template_max; /* maximum number of fingers/templates */ |
| 6909 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 6910 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6911 | uint32_t template_version; /* version of the template format */ |
| 6912 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6913 | |
| 6914 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6915 | #define EC_CMD_FP_FRAME 0x0404 |
| 6916 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6917 | /* constants defining the 'offset' field which also contains the frame index */ |
| 6918 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6919 | /* Frame buffer where the captured image is stored */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6920 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6921 | /* First frame buffer holding a template */ |
| 6922 | #define FP_FRAME_INDEX_TEMPLATE 1 |
| 6923 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6924 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
| 6925 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6926 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6927 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6928 | |
| 6929 | /* Constants for encryption parameters */ |
| 6930 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 6931 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 6932 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6933 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6934 | #define FP_CONTEXT_TPM_BYTES 32 |
| 6935 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6936 | /* Constants for positive match parameters. */ |
| 6937 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 6938 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6939 | struct ec_fp_template_encryption_metadata { |
| 6940 | /* |
| 6941 | * Version of the structure format (N=3). |
| 6942 | */ |
| 6943 | uint16_t struct_version; |
| 6944 | /* Reserved bytes, set to 0. */ |
| 6945 | uint16_t reserved; |
| 6946 | /* |
| 6947 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 6948 | * a different one is used for every message. |
| 6949 | */ |
| 6950 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6951 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6952 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 6953 | }; |
| 6954 | |
| 6955 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6956 | /* |
| 6957 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 6958 | * in the high nibble, and the real offset within the frame in |
| 6959 | * FP_FRAME_OFFSET_MASK. |
| 6960 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6961 | uint32_t offset; |
| 6962 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6963 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6964 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6965 | /* Load a template into the MCU */ |
| 6966 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 6967 | |
| 6968 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 6969 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 6970 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6971 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6972 | uint32_t offset; |
| 6973 | uint32_t size; |
| 6974 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6975 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6976 | |
| 6977 | /* Clear the current fingerprint user context and set a new one */ |
| 6978 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 6979 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6980 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6981 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6982 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6983 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6984 | enum fp_context_action { |
| 6985 | FP_CONTEXT_ASYNC = 0, |
| 6986 | FP_CONTEXT_GET_RESULT = 1, |
| 6987 | }; |
| 6988 | |
| 6989 | /* Version 1 of the command is "asynchronous". */ |
| 6990 | struct ec_params_fp_context_v1 { |
| 6991 | uint8_t action; /**< enum fp_context_action */ |
| 6992 | uint8_t reserved[3]; /**< padding for alignment */ |
| 6993 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 6994 | } __ec_align4; |
| 6995 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6996 | #define EC_CMD_FP_STATS 0x0407 |
| 6997 | |
| 6998 | #define FPSTATS_CAPTURE_INV BIT(0) |
| 6999 | #define FPSTATS_MATCHING_INV BIT(1) |
| 7000 | |
| 7001 | struct ec_response_fp_stats { |
| 7002 | uint32_t capture_time_us; |
| 7003 | uint32_t matching_time_us; |
| 7004 | uint32_t overall_time_us; |
| 7005 | struct { |
| 7006 | uint32_t lo; |
| 7007 | uint32_t hi; |
| 7008 | } overall_t0; |
| 7009 | uint8_t timestamps_invalid; |
| 7010 | int8_t template_matched; |
| 7011 | } __ec_align2; |
| 7012 | |
| 7013 | #define EC_CMD_FP_SEED 0x0408 |
| 7014 | struct ec_params_fp_seed { |
| 7015 | /* |
| 7016 | * Version of the structure format (N=3). |
| 7017 | */ |
| 7018 | uint16_t struct_version; |
| 7019 | /* Reserved bytes, set to 0. */ |
| 7020 | uint16_t reserved; |
| 7021 | /* Seed from the TPM. */ |
| 7022 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 7023 | } __ec_align4; |
| 7024 | |
| 7025 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 7026 | |
| 7027 | /* FP TPM seed has been set or not */ |
| 7028 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 7029 | |
| 7030 | struct ec_response_fp_encryption_status { |
| 7031 | /* Used bits in encryption engine status */ |
| 7032 | uint32_t valid_flags; |
| 7033 | /* Encryption engine status */ |
| 7034 | uint32_t status; |
| 7035 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7036 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7037 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 7038 | struct ec_params_fp_read_match_secret { |
| 7039 | uint16_t fgr; |
| 7040 | } __ec_align4; |
| 7041 | |
| 7042 | /* The positive match secret has the length of the SHA256 digest. */ |
| 7043 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 7044 | struct ec_response_fp_read_match_secret { |
| 7045 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 7046 | } __ec_align4; |
| 7047 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7048 | /*****************************************************************************/ |
| 7049 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 7050 | |
| 7051 | /* Perform touchpad self test */ |
| 7052 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 7053 | |
| 7054 | /* Get number of frame types, and the size of each type */ |
| 7055 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 7056 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7057 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7058 | uint32_t n_frames; |
| 7059 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7060 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7061 | |
| 7062 | /* Create a snapshot of current frame readings */ |
| 7063 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 7064 | |
| 7065 | /* Read the frame */ |
| 7066 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 7067 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7068 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7069 | uint32_t frame_index; |
| 7070 | uint32_t offset; |
| 7071 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7072 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7073 | |
| 7074 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7075 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 7076 | |
| 7077 | #define EC_COMM_TEXT_MAX 8 |
| 7078 | |
| 7079 | /* |
| 7080 | * Get battery static information, i.e. information that never changes, or |
| 7081 | * very infrequently. |
| 7082 | */ |
| 7083 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 7084 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7085 | /** |
| 7086 | * struct ec_params_battery_static_info - Battery static info parameters |
| 7087 | * @index: Battery index. |
| 7088 | */ |
| 7089 | struct ec_params_battery_static_info { |
| 7090 | uint8_t index; |
| 7091 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7092 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7093 | /** |
| 7094 | * struct ec_response_battery_static_info - Battery static info response |
| 7095 | * @design_capacity: Battery Design Capacity (mAh) |
| 7096 | * @design_voltage: Battery Design Voltage (mV) |
| 7097 | * @manufacturer: Battery Manufacturer String |
| 7098 | * @model: Battery Model Number String |
| 7099 | * @serial: Battery Serial Number String |
| 7100 | * @type: Battery Type String |
| 7101 | * @cycle_count: Battery Cycle Count |
| 7102 | */ |
| 7103 | struct ec_response_battery_static_info { |
| 7104 | uint16_t design_capacity; |
| 7105 | uint16_t design_voltage; |
| 7106 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 7107 | char model[EC_COMM_TEXT_MAX]; |
| 7108 | char serial[EC_COMM_TEXT_MAX]; |
| 7109 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7110 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7111 | uint32_t cycle_count; |
| 7112 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7113 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 7114 | /** |
| 7115 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 7116 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 7117 | * strings. |
| 7118 | * @design_capacity: battery design capacity (in mAh) |
| 7119 | * @design_voltage: battery design voltage (in mV) |
| 7120 | * @cycle_count: battery cycle count |
| 7121 | * @manufacturer_ext: battery manufacturer string |
| 7122 | * @model_ext: battery model string |
| 7123 | * @serial_ext: battery serial number string |
| 7124 | * @type_ext: battery type string |
| 7125 | */ |
| 7126 | struct ec_response_battery_static_info_v1 { |
| 7127 | uint16_t design_capacity; |
| 7128 | uint16_t design_voltage; |
| 7129 | uint32_t cycle_count; |
| 7130 | char manufacturer_ext[12]; |
| 7131 | char model_ext[12]; |
| 7132 | char serial_ext[12]; |
| 7133 | char type_ext[12]; |
| 7134 | } __ec_align4; |
| 7135 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7136 | /* |
| 7137 | * Get battery dynamic information, i.e. information that is likely to change |
| 7138 | * every time it is read. |
| 7139 | */ |
| 7140 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 7141 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7142 | /** |
| 7143 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 7144 | * @index: Battery index. |
| 7145 | */ |
| 7146 | struct ec_params_battery_dynamic_info { |
| 7147 | uint8_t index; |
| 7148 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7149 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7150 | /** |
| 7151 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 7152 | * @actual_voltage: Battery voltage (mV) |
| 7153 | * @actual_current: Battery current (mA); negative=discharging |
| 7154 | * @remaining_capacity: Remaining capacity (mAh) |
| 7155 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 7156 | * @flags: Flags, see EC_BATT_FLAG_* |
| 7157 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 7158 | * @desired_current: Charging current desired by battery (mA) |
| 7159 | */ |
| 7160 | struct ec_response_battery_dynamic_info { |
| 7161 | int16_t actual_voltage; |
| 7162 | int16_t actual_current; |
| 7163 | int16_t remaining_capacity; |
| 7164 | int16_t full_capacity; |
| 7165 | int16_t flags; |
| 7166 | int16_t desired_voltage; |
| 7167 | int16_t desired_current; |
| 7168 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7169 | |
| 7170 | /* |
| 7171 | * Control charger chip. Used to control charger chip on the slave. |
| 7172 | */ |
| 7173 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 7174 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7175 | /** |
| 7176 | * struct ec_params_charger_control - Charger control parameters |
| 7177 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 7178 | * max_current and (possibly) charge battery, negative to request current |
| 7179 | * from base (OTG). |
| 7180 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 7181 | * >= 0. |
| 7182 | * @allow_charging: Allow base battery charging (only makes sense if |
| 7183 | * max_current > 0). |
| 7184 | */ |
| 7185 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7186 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7187 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7188 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7189 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7190 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame^] | 7191 | /* Get ACK from the USB-C SS muxes */ |
| 7192 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 7193 | |
| 7194 | struct ec_params_usb_pd_mux_ack { |
| 7195 | uint8_t port; /* USB-C port number */ |
| 7196 | } __ec_align1; |
| 7197 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7198 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7199 | /* |
| 7200 | * Reserve a range of host commands for board-specific, experimental, or |
| 7201 | * special purpose features. These can be (re)used without updating this file. |
| 7202 | * |
| 7203 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 7204 | * their EC commands for easier development, testing, debugging, and support. |
| 7205 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7206 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 7207 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 7208 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7209 | * In your experimental code, you may want to do something like this: |
| 7210 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7211 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 7212 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 7213 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 7214 | * |
| 7215 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 7216 | * EC_VER_MASK(0); |
| 7217 | * |
| 7218 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 7219 | * EC_VER_MASK(0); |
| 7220 | * |
| 7221 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 7222 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7223 | */ |
| 7224 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 7225 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 7226 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7227 | /* |
| 7228 | * Given the private host command offset, calculate the true private host |
| 7229 | * command value. |
| 7230 | */ |
| 7231 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 7232 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 7233 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7234 | /*****************************************************************************/ |
| 7235 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 7236 | * Passthru commands |
| 7237 | * |
| 7238 | * Some platforms have sub-processors chained to each other. For example. |
| 7239 | * |
| 7240 | * AP <--> EC <--> PD MCU |
| 7241 | * |
| 7242 | * The top 2 bits of the command number are used to indicate which device the |
| 7243 | * command is intended for. Device 0 is always the device receiving the |
| 7244 | * command; other device mapping is board-specific. |
| 7245 | * |
| 7246 | * When a device receives a command to be passed to a sub-processor, it passes |
| 7247 | * it on with the device number set back to 0. This allows the sub-processor |
| 7248 | * to remain blissfully unaware of whether the command originated on the next |
| 7249 | * device up the chain, or was passed through from the AP. |
| 7250 | * |
| 7251 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 7252 | * AP sends command 0x4002 to the EC |
| 7253 | * EC sends command 0x0002 to the PD MCU |
| 7254 | * EC forwards PD MCU response back to the AP |
| 7255 | */ |
| 7256 | |
| 7257 | /* Offset and max command number for sub-device n */ |
| 7258 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 7259 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 7260 | |
| 7261 | /*****************************************************************************/ |
| 7262 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7263 | * Deprecated constants. These constants have been renamed for clarity. The |
| 7264 | * meaning and size has not changed. Programs that use the old names should |
| 7265 | * switch to the new names soon, as the old names may not be carried forward |
| 7266 | * forever. |
| 7267 | */ |
| 7268 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 7269 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 7270 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 7271 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7272 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7273 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7274 | #ifdef __cplusplus |
| 7275 | } |
| 7276 | #endif |
| 7277 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7278 | #endif /* __CROS_EC_EC_COMMANDS_H */ |