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 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 12 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 13 | /* |
| 14 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 15 | * It is used to not include macros that may cause conflicts in foreign |
| 16 | * projects (refer to crbug.com/984623). |
| 17 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 18 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 19 | /* |
| 20 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 21 | * generates more efficient code for accessing request/response structures on |
| 22 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 23 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 24 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 25 | #include "compile_time_macros.h" |
| 26 | |
| 27 | #else |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 28 | /* If BUILD_ASSERT isn't already defined, make it a no-op */ |
| 29 | #ifndef BUILD_ASSERT |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 30 | #define BUILD_ASSERT(_cond) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 31 | #endif /* !BUILD_ASSERT */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 32 | #endif /* CHROMIUM_EC */ |
| 33 | |
| 34 | #ifdef __KERNEL__ |
| 35 | #include <linux/limits.h> |
| 36 | #else |
| 37 | /* |
| 38 | * Defines macros that may be needed but are for sure defined by the linux |
| 39 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 40 | * util/make_linux_ec_commands_h.sh). |
| 41 | * cros_ec_commands.h looks more integrated to the kernel. |
| 42 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 43 | |
| 44 | #ifndef BIT |
| 45 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 48 | #ifndef BIT_ULL |
| 49 | #define BIT_ULL(nr) (1ULL << (nr)) |
| 50 | #endif |
| 51 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 52 | /* |
| 53 | * When building Zephyr, this file ends up being included before Zephyr's |
| 54 | * include/sys/util.h so causes a warning there. We don't want to add an #ifdef |
| 55 | * in that file since it won't be accepted upstream. So work around it here. |
| 56 | */ |
| 57 | #ifndef CONFIG_ZEPHYR |
| 58 | #ifndef GENMASK |
| 59 | #define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1)) |
| 60 | #endif |
| 61 | |
| 62 | #ifndef GENMASK_ULL |
| 63 | #define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1)) |
| 64 | #endif |
| 65 | #endif |
| 66 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 67 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 68 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 69 | #ifdef __cplusplus |
| 70 | extern "C" { |
| 71 | #endif |
| 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 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 426 | * USB Retimer firmware update. |
| 427 | * Read: |
| 428 | * Result of last operation AP requested |
| 429 | * Write: |
| 430 | * bits[3:0]: USB-C port number |
| 431 | * bits[7:4]: Operation requested by AP |
| 432 | * |
| 433 | * NDA (no device attached) case: |
| 434 | * To update retimer firmware, AP needs set up TBT Alt mode. |
| 435 | * AP requests operations in this sequence: |
| 436 | * 1. Get port information about which ports support retimer firmware update. |
| 437 | * In the query result, each bit represents one port. |
| 438 | * 2. Get current MUX mode, it's NDA. |
| 439 | * 3. Suspend specified PD port's task. |
| 440 | * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode -> |
| 441 | * update firmware -> disconnect MUX -> resume PD task. |
| 442 | * |
| 443 | * DA (device attached) cases: |
| 444 | * Retimer firmware update is not supported in DA cases. |
| 445 | * 1. Get port information about which ports support retimer firmware update |
| 446 | * 2. Get current MUX mode, it's DA. |
| 447 | * 3. AP continues. No more retimer firmware update activities. |
| 448 | * |
| 449 | */ |
| 450 | #define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14 |
| 451 | |
| 452 | #define USB_RETIMER_FW_UPDATE_OP_SHIFT 4 |
| 453 | #define USB_RETIMER_FW_UPDATE_ERR 0xfe |
| 454 | #define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff |
| 455 | /* Retimer firmware update operations */ |
| 456 | #define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */ |
| 457 | #define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */ |
| 458 | #define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */ |
| 459 | #define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */ |
| 460 | #define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */ |
| 461 | #define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */ |
| 462 | #define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */ |
| 463 | #define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */ |
| 464 | |
| 465 | #define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f) |
| 466 | #define EC_ACPI_MEM_USB_RETIMER_OP(x) \ |
| 467 | (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT) |
| 468 | |
| 469 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 470 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 471 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 472 | */ |
| 473 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 474 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 475 | |
| 476 | /* Current version of ACPI memory address space */ |
| 477 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 478 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 479 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 480 | /* |
| 481 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 482 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 483 | * handle actual C code so keep it separate. |
| 484 | */ |
| 485 | #ifndef __ACPI__ |
| 486 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 487 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 488 | /* |
| 489 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 490 | * checking prefers __packed over __attribute__((packed)). |
| 491 | */ |
| 492 | #ifndef __packed |
| 493 | #define __packed __attribute__((packed)) |
| 494 | #endif |
| 495 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 496 | #ifndef __aligned |
| 497 | #define __aligned(x) __attribute__((aligned(x))) |
| 498 | #endif |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 499 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 500 | |
| 501 | /* |
| 502 | * Attributes for EC request and response packets. Just defining __packed |
| 503 | * results in inefficient assembly code on ARM, if the structure is actually |
| 504 | * 32-bit aligned, as it should be for all buffers. |
| 505 | * |
| 506 | * Be very careful when adding these to existing structures. They will round |
| 507 | * up the structure size to the specified boundary. |
| 508 | * |
| 509 | * Also be very careful to make that if a structure is included in some other |
| 510 | * parent structure that the alignment will still be true given the packing of |
| 511 | * the parent structure. This is particularly important if the sub-structure |
| 512 | * 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] | 513 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 514 | * |
| 515 | * Also be very careful using __packed - particularly when nesting non-packed |
| 516 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 517 | * always use one of these attributes. |
| 518 | * |
| 519 | * Once everything is annotated properly, the following search strings should |
| 520 | * not return ANY matches in this file other than right here: |
| 521 | * |
| 522 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 523 | * |
| 524 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 525 | * members of other structs/unions (and their original declarations should be |
| 526 | * annotated). |
| 527 | */ |
| 528 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 529 | |
| 530 | /* |
| 531 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 532 | * byte boundary. |
| 533 | */ |
| 534 | #define __ec_align1 __packed |
| 535 | #define __ec_align2 __packed __aligned(2) |
| 536 | #define __ec_align4 __packed __aligned(4) |
| 537 | |
| 538 | /* |
| 539 | * Packed structure which must be under-aligned, because its size is not a |
| 540 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 541 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 542 | * |
| 543 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 544 | * its members, but use the __packed version for sizeof(). |
| 545 | */ |
| 546 | #define __ec_align_size1 __packed |
| 547 | |
| 548 | /* |
| 549 | * Packed structure which must be under-aligned, because its offset inside a |
| 550 | * parent structure is not a 4-byte multiple. |
| 551 | */ |
| 552 | #define __ec_align_offset1 __packed |
| 553 | #define __ec_align_offset2 __packed __aligned(2) |
| 554 | |
| 555 | /* |
| 556 | * Structures which are complicated enough that I'm skipping them on the first |
| 557 | * pass. They are effectively unchanged from their previous definitions. |
| 558 | * |
| 559 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 560 | * to work out the size and offset of each member and add explicit padding to |
| 561 | * maintain those. |
| 562 | */ |
| 563 | #define __ec_todo_packed __packed |
| 564 | #define __ec_todo_unpacked |
| 565 | |
| 566 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
| 567 | |
| 568 | /* |
| 569 | * Packed structures make no assumption about alignment, so they do inefficient |
| 570 | * byte-wise reads. |
| 571 | */ |
| 572 | #define __ec_align1 __packed |
| 573 | #define __ec_align2 __packed |
| 574 | #define __ec_align4 __packed |
| 575 | #define __ec_align_size1 __packed |
| 576 | #define __ec_align_offset1 __packed |
| 577 | #define __ec_align_offset2 __packed |
| 578 | #define __ec_todo_packed __packed |
| 579 | #define __ec_todo_unpacked |
| 580 | |
| 581 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
| 582 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 583 | /* LPC command status byte masks */ |
| 584 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 585 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 586 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 587 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 588 | /* EC is processing a command */ |
| 589 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 590 | /* Last write to EC was a command, not data */ |
| 591 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 592 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 593 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 594 | /* SCI event is pending (requesting SCI query) */ |
| 595 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 596 | /* SMI event is pending (requesting SMI query) */ |
| 597 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 598 | /* (reserved) */ |
| 599 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 600 | |
| 601 | /* |
| 602 | * EC is busy. This covers both the EC processing a command, and the host has |
| 603 | * written a new command but the EC hasn't picked it up yet. |
| 604 | */ |
| 605 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 606 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 607 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 608 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 609 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 610 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 611 | enum ec_status { |
| 612 | EC_RES_SUCCESS = 0, |
| 613 | EC_RES_INVALID_COMMAND = 1, |
| 614 | EC_RES_ERROR = 2, |
| 615 | EC_RES_INVALID_PARAM = 3, |
| 616 | EC_RES_ACCESS_DENIED = 4, |
| 617 | EC_RES_INVALID_RESPONSE = 5, |
| 618 | EC_RES_INVALID_VERSION = 6, |
| 619 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 620 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 621 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 622 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 623 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 624 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 625 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 626 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 627 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 628 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 629 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 630 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 631 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 632 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 633 | |
| 634 | EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ |
| 635 | } __packed; |
| 636 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 637 | |
| 638 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 639 | * Host event codes. ACPI query EC command uses code 0 to mean "no event |
| 640 | * pending". We explicitly specify each value in the enum listing so they won't |
| 641 | * change if we delete/insert an item or rearrange the list (it needs to be |
| 642 | * stable across platforms, not just within a single compiled instance). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 643 | */ |
| 644 | enum host_event_code { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 645 | EC_HOST_EVENT_NONE = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 646 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 647 | EC_HOST_EVENT_LID_OPEN = 2, |
| 648 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 649 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 650 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 651 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 652 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 653 | EC_HOST_EVENT_BATTERY = 8, |
| 654 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 655 | /* Event generated by a device attached to the EC */ |
| 656 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 657 | EC_HOST_EVENT_THERMAL = 11, |
| 658 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 659 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 660 | /* |
| 661 | * EC has finished initializing the host interface. The host can check |
| 662 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 663 | * determine when the EC is ready to accept subsequent commands. |
| 664 | */ |
| 665 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 666 | /* Keyboard recovery combo has been pressed */ |
| 667 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 668 | |
| 669 | /* Shutdown due to thermal overload */ |
| 670 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 671 | /* Shutdown due to battery level too low */ |
| 672 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 673 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 674 | /* Suggest that the AP throttle itself */ |
| 675 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 676 | /* Suggest that the AP resume normal speed */ |
| 677 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 678 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 679 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 680 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 681 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 682 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 683 | |
| 684 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 685 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 686 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 687 | /* Battery Status flags have changed */ |
| 688 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 689 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 690 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 691 | EC_HOST_EVENT_PANIC = 24, |
| 692 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 693 | /* Keyboard fastboot combo has been pressed */ |
| 694 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 695 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 696 | /* EC RTC event occurred */ |
| 697 | EC_HOST_EVENT_RTC = 26, |
| 698 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 699 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 700 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 701 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 702 | /* EC desires to change state of host-controlled USB mux */ |
| 703 | EC_HOST_EVENT_USB_MUX = 28, |
| 704 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 705 | /* |
| 706 | * The device has changed "modes". This can be one of the following: |
| 707 | * |
| 708 | * - TABLET/LAPTOP mode |
| 709 | * - detachable base attach/detach event |
| 710 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 711 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 712 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 713 | /* Keyboard recovery combo with hardware reinitialization */ |
| 714 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 715 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 716 | /* WoV */ |
| 717 | EC_HOST_EVENT_WOV = 31, |
| 718 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 719 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 720 | * The high bit of the event mask is not used as a host event code. If |
| 721 | * it reads back as set, then the entire event mask should be |
| 722 | * considered invalid by the host. This can happen when reading the |
| 723 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 724 | * not initialized on the EC, or improperly configured on the host. |
| 725 | */ |
| 726 | EC_HOST_EVENT_INVALID = 32 |
| 727 | }; |
| 728 | /* Host event mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 729 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 730 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 731 | /** |
| 732 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 733 | * @flags: The host argument flags. |
| 734 | * @command_version: Command version. |
| 735 | * @data_size: The length of data. |
| 736 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 737 | * all params/response data bytes. |
| 738 | */ |
| 739 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 740 | uint8_t flags; |
| 741 | uint8_t command_version; |
| 742 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 743 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 744 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 745 | |
| 746 | /* Flags for ec_lpc_host_args.flags */ |
| 747 | /* |
| 748 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 749 | * params. |
| 750 | * |
| 751 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 752 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 753 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 754 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 755 | */ |
| 756 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 757 | /* |
| 758 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 759 | * |
| 760 | * If EC responds to a command and this flag is not set, this is an old-style |
| 761 | * response. Command version is 0 and response data from EC is at |
| 762 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 763 | */ |
| 764 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 765 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 766 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 767 | /* |
| 768 | * Byte codes returned by EC over SPI interface. |
| 769 | * |
| 770 | * These can be used by the AP to debug the EC interface, and to determine |
| 771 | * when the EC is not in a state where it will ever get around to responding |
| 772 | * to the AP. |
| 773 | * |
| 774 | * Example of sequence of bytes read from EC for a current good transfer: |
| 775 | * 1. - - AP asserts chip select (CS#) |
| 776 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 777 | * 3. - - EC starts handling CS# interrupt |
| 778 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 779 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 780 | * bytes looking for EC_SPI_FRAME_START |
| 781 | * 6. - - EC finishes processing and sets up response |
| 782 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 783 | * 8. (response packet) - AP reads response packet |
| 784 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 785 | * 10 - - AP deasserts chip select |
| 786 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 787 | * next request |
| 788 | * |
| 789 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 790 | * the following byte values: |
| 791 | * EC_SPI_OLD_READY |
| 792 | * EC_SPI_RX_READY |
| 793 | * EC_SPI_RECEIVING |
| 794 | * EC_SPI_PROCESSING |
| 795 | * |
| 796 | * Then the EC found an error in the request, or was not ready for the request |
| 797 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 798 | * because the EC is unable to tell when the AP is done sending its request. |
| 799 | */ |
| 800 | |
| 801 | /* |
| 802 | * Framing byte which precedes a response packet from the EC. After sending a |
| 803 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 804 | * clock in the response packet. |
| 805 | */ |
| 806 | #define EC_SPI_FRAME_START 0xec |
| 807 | |
| 808 | /* |
| 809 | * Padding bytes which are clocked out after the end of a response packet. |
| 810 | */ |
| 811 | #define EC_SPI_PAST_END 0xed |
| 812 | |
| 813 | /* |
| 814 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 815 | * that the AP will send a valid packet header (starting with |
| 816 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 817 | */ |
| 818 | #define EC_SPI_RX_READY 0xf8 |
| 819 | |
| 820 | /* |
| 821 | * EC has started receiving the request from the AP, but hasn't started |
| 822 | * processing it yet. |
| 823 | */ |
| 824 | #define EC_SPI_RECEIVING 0xf9 |
| 825 | |
| 826 | /* EC has received the entire request from the AP and is processing it. */ |
| 827 | #define EC_SPI_PROCESSING 0xfa |
| 828 | |
| 829 | /* |
| 830 | * EC received bad data from the AP, such as a packet header with an invalid |
| 831 | * length. EC will ignore all data until chip select deasserts. |
| 832 | */ |
| 833 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 834 | |
| 835 | /* |
| 836 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 837 | * chip select and started clocking data before the EC was ready to receive it. |
| 838 | * EC will ignore all data until chip select deasserts. |
| 839 | */ |
| 840 | #define EC_SPI_NOT_READY 0xfc |
| 841 | |
| 842 | /* |
| 843 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 844 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 845 | * a fully received packet but is not ready to respond yet. |
| 846 | */ |
| 847 | #define EC_SPI_OLD_READY 0xfd |
| 848 | |
| 849 | /*****************************************************************************/ |
| 850 | |
| 851 | /* |
| 852 | * Protocol version 2 for I2C and SPI send a request this way: |
| 853 | * |
| 854 | * 0 EC_CMD_VERSION0 + (command version) |
| 855 | * 1 Command number |
| 856 | * 2 Length of params = N |
| 857 | * 3..N+2 Params, if any |
| 858 | * N+3 8-bit checksum of bytes 0..N+2 |
| 859 | * |
| 860 | * The corresponding response is: |
| 861 | * |
| 862 | * 0 Result code (EC_RES_*) |
| 863 | * 1 Length of params = M |
| 864 | * 2..M+1 Params, if any |
| 865 | * M+2 8-bit checksum of bytes 0..M+1 |
| 866 | */ |
| 867 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 868 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 869 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 870 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 871 | |
| 872 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 873 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 874 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 875 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 876 | |
| 877 | /* Parameter length was limited by the LPC interface */ |
| 878 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 879 | |
| 880 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 881 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 882 | EC_PROTO2_MAX_PARAM_SIZE) |
| 883 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 884 | EC_PROTO2_MAX_PARAM_SIZE) |
| 885 | |
| 886 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 887 | |
| 888 | /* |
| 889 | * Value written to legacy command port / prefix byte to indicate protocol |
| 890 | * 3+ structs are being used. Usage is bus-dependent. |
| 891 | */ |
| 892 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 893 | |
| 894 | #define EC_HOST_REQUEST_VERSION 3 |
| 895 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 896 | /** |
| 897 | * struct ec_host_request - Version 3 request from host. |
| 898 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 899 | * receives a header with a version it doesn't know how to |
| 900 | * parse. |
| 901 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 902 | * should total to 0. |
| 903 | * @command: Command to send (EC_CMD_...) |
| 904 | * @command_version: Command version. |
| 905 | * @reserved: Unused byte in current protocol version; set to 0. |
| 906 | * @data_len: Length of data which follows this header. |
| 907 | */ |
| 908 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 909 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 910 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 911 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 912 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 913 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 914 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 915 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 916 | |
| 917 | #define EC_HOST_RESPONSE_VERSION 3 |
| 918 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 919 | /** |
| 920 | * struct ec_host_response - Version 3 response from EC. |
| 921 | * @struct_version: Struct version (=3). |
| 922 | * @checksum: Checksum of response and data; sum of all bytes including |
| 923 | * checksum should total to 0. |
| 924 | * @result: EC's response to the command (separate from communication failure) |
| 925 | * @data_len: Length of data which follows this header. |
| 926 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 927 | */ |
| 928 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 929 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 930 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 931 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 932 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 933 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 934 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 935 | |
| 936 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 937 | |
| 938 | /* |
| 939 | * Host command protocol V4. |
| 940 | * |
| 941 | * Packets always start with a request or response header. They are followed |
| 942 | * by data_len bytes of data. If the data_crc_present flag is set, the data |
Elyes HAOUAS | 1550469 | 2021-01-16 15:01:33 +0100 | [diff] [blame] | 943 | * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 944 | * polynomial. |
| 945 | * |
| 946 | * Host algorithm when sending a request q: |
| 947 | * |
| 948 | * 101) tries_left=(some value, e.g. 3); |
| 949 | * 102) q.seq_num++ |
| 950 | * 103) q.seq_dup=0 |
| 951 | * 104) Calculate q.header_crc. |
| 952 | * 105) Send request q to EC. |
| 953 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 954 | * |
| 955 | * 201) If r.struct_version != 4, go to 301. |
| 956 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 957 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 958 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 959 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 960 | * 207) If r.seq_dup == 1, go to 301. |
| 961 | * 208) Return error. |
| 962 | * |
| 963 | * 301) If --tries_left <= 0, return error. |
| 964 | * 302) If q.seq_dup == 1, go to 105. |
| 965 | * 303) q.seq_dup = 1 |
| 966 | * 304) Go to 104. |
| 967 | * |
| 968 | * EC algorithm when receiving a request q. |
| 969 | * EC has response buffer r, error buffer e. |
| 970 | * |
| 971 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 972 | * and go to 301 |
| 973 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 974 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 975 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 976 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 977 | * and go to 301. |
| 978 | * 104) If q.seq_dup == 0, go to 201. |
| 979 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 980 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 981 | * |
| 982 | * 201) Process request q into response r. |
| 983 | * 202) r.seq_num = q.seq_num |
| 984 | * 203) r.seq_dup = q.seq_dup |
| 985 | * 204) Calculate r.header_crc |
| 986 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 987 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 988 | * 206) Send response r. |
| 989 | * |
| 990 | * 301) e.seq_num = q.seq_num |
| 991 | * 302) e.seq_dup = q.seq_dup |
| 992 | * 303) Calculate e.header_crc. |
| 993 | * 304) Send error response e. |
| 994 | */ |
| 995 | |
| 996 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 997 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 998 | /* |
| 999 | * bits 0-3: struct_version: Structure version (=4) |
| 1000 | * bit 4: is_response: Is response (=0) |
| 1001 | * bits 5-6: seq_num: Sequence number |
| 1002 | * bit 7: seq_dup: Sequence duplicate flag |
| 1003 | */ |
| 1004 | uint8_t fields0; |
| 1005 | |
| 1006 | /* |
| 1007 | * bits 0-4: command_version: Command version |
| 1008 | * bits 5-6: Reserved (set 0, ignore on read) |
| 1009 | * bit 7: data_crc_present: Is data CRC present after data |
| 1010 | */ |
| 1011 | uint8_t fields1; |
| 1012 | |
| 1013 | /* Command code (EC_CMD_*) */ |
| 1014 | uint16_t command; |
| 1015 | |
| 1016 | /* Length of data which follows this header (not including data CRC) */ |
| 1017 | uint16_t data_len; |
| 1018 | |
| 1019 | /* Reserved (set 0, ignore on read) */ |
| 1020 | uint8_t reserved; |
| 1021 | |
| 1022 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1023 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1024 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1025 | |
| 1026 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1027 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1028 | /* |
| 1029 | * bits 0-3: struct_version: Structure version (=4) |
| 1030 | * bit 4: is_response: Is response (=1) |
| 1031 | * bits 5-6: seq_num: Sequence number |
| 1032 | * bit 7: seq_dup: Sequence duplicate flag |
| 1033 | */ |
| 1034 | uint8_t fields0; |
| 1035 | |
| 1036 | /* |
| 1037 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1038 | * bit 7: data_crc_present: Is data CRC present after data |
| 1039 | */ |
| 1040 | uint8_t fields1; |
| 1041 | |
| 1042 | /* Result code (EC_RES_*) */ |
| 1043 | uint16_t result; |
| 1044 | |
| 1045 | /* Length of data which follows this header (not including data CRC) */ |
| 1046 | uint16_t data_len; |
| 1047 | |
| 1048 | /* Reserved (set 0, ignore on read) */ |
| 1049 | uint8_t reserved; |
| 1050 | |
| 1051 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1052 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1053 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1054 | |
| 1055 | /* Fields in fields0 byte */ |
| 1056 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1057 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1058 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1059 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1060 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
| 1061 | |
| 1062 | /* Fields in fields1 byte */ |
| 1063 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1064 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
| 1065 | |
| 1066 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1067 | /* |
| 1068 | * Notes on commands: |
| 1069 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1070 | * 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] | 1071 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1072 | * specified, the command does not input or output data, respectively. |
| 1073 | * Parameter/response length is implicit in the structs. Some underlying |
| 1074 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1075 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1076 | * |
| 1077 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1078 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1079 | */ |
| 1080 | |
| 1081 | /*****************************************************************************/ |
| 1082 | /* General / test commands */ |
| 1083 | |
| 1084 | /* |
| 1085 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1086 | * changes. |
| 1087 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1088 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1089 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1090 | /** |
| 1091 | * struct ec_response_proto_version - Response to the proto version command. |
| 1092 | * @version: The protocol version. |
| 1093 | */ |
| 1094 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1095 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1096 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1097 | |
| 1098 | /* |
| 1099 | * Hello. This is a simple command to test the EC is responsive to |
| 1100 | * commands. |
| 1101 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1102 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1103 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1104 | /** |
| 1105 | * struct ec_params_hello - Parameters to the hello command. |
| 1106 | * @in_data: Pass anything here. |
| 1107 | */ |
| 1108 | struct ec_params_hello { |
| 1109 | uint32_t in_data; |
| 1110 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1111 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1112 | /** |
| 1113 | * struct ec_response_hello - Response to the hello command. |
| 1114 | * @out_data: Output will be in_data + 0x01020304. |
| 1115 | */ |
| 1116 | struct ec_response_hello { |
| 1117 | uint32_t out_data; |
| 1118 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1119 | |
| 1120 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1121 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1122 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1123 | #if !defined(CHROMIUM_EC) && !defined(__KERNEL__) |
| 1124 | /* |
| 1125 | * enum ec_current_image is deprecated and replaced by enum ec_image. This |
| 1126 | * macro exists for backwards compatibility of external projects until they |
| 1127 | * have been updated: b/149987779. |
| 1128 | */ |
| 1129 | #define ec_current_image ec_image |
| 1130 | #endif |
| 1131 | |
| 1132 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1133 | EC_IMAGE_UNKNOWN = 0, |
| 1134 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1135 | EC_IMAGE_RW, |
| 1136 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1137 | EC_IMAGE_RO_B, |
| 1138 | EC_IMAGE_RW_B |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1139 | }; |
| 1140 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1141 | /** |
| 1142 | * struct ec_response_get_version - Response to the get version command. |
| 1143 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1144 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1145 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1146 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1147 | */ |
| 1148 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1149 | char version_string_ro[32]; |
| 1150 | char version_string_rw[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1151 | char reserved[32]; |
| 1152 | uint32_t current_image; |
| 1153 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1154 | |
| 1155 | /* Read test */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1156 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1157 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1158 | /** |
| 1159 | * struct ec_params_read_test - Parameters for the read test command. |
| 1160 | * @offset: Starting value for read buffer. |
| 1161 | * @size: Size to read in bytes. |
| 1162 | */ |
| 1163 | struct ec_params_read_test { |
| 1164 | uint32_t offset; |
| 1165 | uint32_t size; |
| 1166 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1167 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1168 | /** |
| 1169 | * struct ec_response_read_test - Response to the read test command. |
| 1170 | * @data: Data returned by the read test command. |
| 1171 | */ |
| 1172 | struct ec_response_read_test { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1173 | uint32_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1174 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1175 | |
| 1176 | /* |
| 1177 | * Get build information |
| 1178 | * |
| 1179 | * Response is null-terminated string. |
| 1180 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1181 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1182 | |
| 1183 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1184 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1185 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1186 | /** |
| 1187 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1188 | * @vendor: Null-terminated string for chip vendor. |
| 1189 | * @name: Null-terminated string for chip name. |
| 1190 | * @revision: Null-terminated string for chip mask version. |
| 1191 | */ |
| 1192 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1193 | char vendor[32]; |
| 1194 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1195 | char revision[32]; |
| 1196 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1197 | |
| 1198 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1199 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1200 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1201 | /** |
| 1202 | * struct ec_response_board_version - Response to the board version command. |
| 1203 | * @board_version: A monotonously incrementing number. |
| 1204 | */ |
| 1205 | struct ec_response_board_version { |
| 1206 | uint16_t board_version; |
| 1207 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1208 | |
| 1209 | /* |
| 1210 | * Read memory-mapped data. |
| 1211 | * |
| 1212 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1213 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1214 | * |
| 1215 | * Response is params.size bytes of data. |
| 1216 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1217 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1218 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1219 | /** |
| 1220 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1221 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1222 | * @size: Size to read in bytes. |
| 1223 | */ |
| 1224 | struct ec_params_read_memmap { |
| 1225 | uint8_t offset; |
| 1226 | uint8_t size; |
| 1227 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1228 | |
| 1229 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1230 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1231 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1232 | /** |
| 1233 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1234 | * @cmd: Command to check. |
| 1235 | */ |
| 1236 | struct ec_params_get_cmd_versions { |
| 1237 | uint8_t cmd; |
| 1238 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1239 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1240 | /** |
| 1241 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1242 | * versions (v1) |
| 1243 | * @cmd: Command to check. |
| 1244 | */ |
| 1245 | struct ec_params_get_cmd_versions_v1 { |
| 1246 | uint16_t cmd; |
| 1247 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1248 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1249 | /** |
| 1250 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1251 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1252 | * a desired version. |
| 1253 | */ |
| 1254 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1255 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1256 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1257 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1258 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1259 | * 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] | 1260 | * on lpc since it has its own out-of-band busy indicator. |
| 1261 | * |
| 1262 | * lpc must read the status from the command register. Attempting this on |
| 1263 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1264 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1265 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1266 | |
| 1267 | /* Avoid using ec_status which is for return values */ |
| 1268 | enum ec_comms_status { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1269 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1270 | }; |
| 1271 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1272 | /** |
| 1273 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1274 | * command. |
| 1275 | * @flags: Mask of enum ec_comms_status. |
| 1276 | */ |
| 1277 | struct ec_response_get_comms_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1278 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1279 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1280 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1281 | /* Fake a variety of responses, purely for testing purposes. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1282 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1283 | |
| 1284 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1285 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1286 | uint32_t ec_result; |
| 1287 | uint32_t ret_len; |
| 1288 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1289 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1290 | |
| 1291 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1292 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1293 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1294 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1295 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1296 | /* Get protocol information */ |
| 1297 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1298 | |
| 1299 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1300 | /* 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] | 1301 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1302 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1303 | /** |
| 1304 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1305 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1306 | * version n). |
| 1307 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1308 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1309 | * @flags: see EC_PROTOCOL_INFO_* |
| 1310 | */ |
| 1311 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1312 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1313 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1314 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1315 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1316 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1317 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1318 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1319 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1320 | /*****************************************************************************/ |
| 1321 | /* Get/Set miscellaneous values */ |
| 1322 | |
| 1323 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 1324 | #define EC_GSV_SET 0x80000000 |
| 1325 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1326 | /* |
| 1327 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1328 | * meaning for an individual command. |
| 1329 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1330 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1331 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1332 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1333 | uint32_t flags; |
| 1334 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1335 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1336 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1337 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1338 | uint32_t flags; |
| 1339 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1340 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1341 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1342 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1343 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1344 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1345 | /*****************************************************************************/ |
| 1346 | /* List the features supported by the firmware */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1347 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1348 | |
| 1349 | /* Supported features */ |
| 1350 | enum ec_feature_code { |
| 1351 | /* |
| 1352 | * This image contains a limited set of features. Another image |
| 1353 | * in RW partition may support more features. |
| 1354 | */ |
| 1355 | EC_FEATURE_LIMITED = 0, |
| 1356 | /* |
| 1357 | * Commands for probing/reading/writing/erasing the flash in the |
| 1358 | * EC are present. |
| 1359 | */ |
| 1360 | EC_FEATURE_FLASH = 1, |
| 1361 | /* |
| 1362 | * Can control the fan speed directly. |
| 1363 | */ |
| 1364 | EC_FEATURE_PWM_FAN = 2, |
| 1365 | /* |
| 1366 | * Can control the intensity of the keyboard backlight. |
| 1367 | */ |
| 1368 | EC_FEATURE_PWM_KEYB = 3, |
| 1369 | /* |
| 1370 | * Support Google lightbar, introduced on Pixel. |
| 1371 | */ |
| 1372 | EC_FEATURE_LIGHTBAR = 4, |
| 1373 | /* Control of LEDs */ |
| 1374 | EC_FEATURE_LED = 5, |
| 1375 | /* Exposes an interface to control gyro and sensors. |
| 1376 | * The host goes through the EC to access these sensors. |
| 1377 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1378 | */ |
| 1379 | EC_FEATURE_MOTION_SENSE = 6, |
| 1380 | /* The keyboard is controlled by the EC */ |
| 1381 | EC_FEATURE_KEYB = 7, |
| 1382 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1383 | EC_FEATURE_PSTORE = 8, |
| 1384 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1385 | EC_FEATURE_PORT80 = 9, |
| 1386 | /* |
| 1387 | * Thermal management: include TMP specific commands. |
| 1388 | * Higher level than direct fan control. |
| 1389 | */ |
| 1390 | EC_FEATURE_THERMAL = 10, |
| 1391 | /* Can switch the screen backlight on/off */ |
| 1392 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1393 | /* Can switch the wifi module on/off */ |
| 1394 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1395 | /* Monitor host events, through for example SMI or SCI */ |
| 1396 | EC_FEATURE_HOST_EVENTS = 13, |
| 1397 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1398 | EC_FEATURE_GPIO = 14, |
| 1399 | /* The EC can send i2c messages to downstream devices. */ |
| 1400 | EC_FEATURE_I2C = 15, |
| 1401 | /* Command to control charger are included */ |
| 1402 | EC_FEATURE_CHARGER = 16, |
| 1403 | /* Simple battery support. */ |
| 1404 | EC_FEATURE_BATTERY = 17, |
| 1405 | /* |
| 1406 | * Support Smart battery protocol |
| 1407 | * (Common Smart Battery System Interface Specification) |
| 1408 | */ |
| 1409 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1410 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1411 | EC_FEATURE_HANG_DETECT = 19, |
| 1412 | /* Report power information, for pit only */ |
| 1413 | EC_FEATURE_PMU = 20, |
| 1414 | /* Another Cros EC device is present downstream of this one */ |
| 1415 | EC_FEATURE_SUB_MCU = 21, |
| 1416 | /* Support USB Power delivery (PD) commands */ |
| 1417 | EC_FEATURE_USB_PD = 22, |
| 1418 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1419 | EC_FEATURE_USB_MUX = 23, |
| 1420 | /* Motion Sensor code has an internal software FIFO */ |
| 1421 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1422 | /* Support temporary secure vstore */ |
| 1423 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1424 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1425 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1426 | /* EC has RTC feature that can be controlled by host commands */ |
| 1427 | EC_FEATURE_RTC = 27, |
| 1428 | /* The MCU exposes a Fingerprint sensor */ |
| 1429 | EC_FEATURE_FINGERPRINT = 28, |
| 1430 | /* The MCU exposes a Touchpad */ |
| 1431 | EC_FEATURE_TOUCHPAD = 29, |
| 1432 | /* The MCU has RWSIG task enabled */ |
| 1433 | EC_FEATURE_RWSIG = 30, |
| 1434 | /* EC has device events support */ |
| 1435 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1436 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1437 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1438 | /* EC supports 64-bit host events */ |
| 1439 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1440 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1441 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1442 | /* EC supports CEC commands */ |
| 1443 | EC_FEATURE_CEC = 35, |
| 1444 | /* EC supports tight sensor timestamping. */ |
| 1445 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1446 | /* |
| 1447 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1448 | * setting of threshold by host command using |
| 1449 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1450 | */ |
| 1451 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1452 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1453 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1454 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1455 | * be sent to RO to be precise. |
| 1456 | */ |
| 1457 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1458 | /* The MCU is a System Companion Processor (SCP). */ |
| 1459 | EC_FEATURE_SCP = 39, |
| 1460 | /* The MCU is an Integrated Sensor Hub */ |
| 1461 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1462 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1463 | EC_FEATURE_TYPEC_CMD = 41, |
| 1464 | /* |
| 1465 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1466 | * modes or USB4. |
| 1467 | */ |
| 1468 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1469 | /* |
| 1470 | * The EC will wait for an acknowledge from the AP after setting the |
| 1471 | * mux. |
| 1472 | */ |
| 1473 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1474 | }; |
| 1475 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1476 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1477 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1478 | |
| 1479 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1480 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1481 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1482 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1483 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1484 | /* Get the board's SKU ID from EC */ |
| 1485 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1486 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1487 | /* Set SKU ID from AP */ |
| 1488 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1489 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1490 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1491 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1492 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1493 | |
| 1494 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1495 | /* Flash commands */ |
| 1496 | |
| 1497 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1498 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1499 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1500 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1501 | /** |
| 1502 | * struct ec_response_flash_info - Response to the flash info command. |
| 1503 | * @flash_size: Usable flash size in bytes. |
| 1504 | * @write_block_size: Write block size. Write offset and size must be a |
| 1505 | * multiple of this. |
| 1506 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1507 | * multiple of this. |
| 1508 | * @protect_block_size: Protection block size. Protection offset and size |
| 1509 | * must be a multiple of this. |
| 1510 | * |
| 1511 | * Version 0 returns these fields. |
| 1512 | */ |
| 1513 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1514 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1515 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1516 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1517 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1518 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1519 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1520 | /* |
| 1521 | * Flags for version 1+ flash info command |
| 1522 | * EC flash erases bits to 0 instead of 1. |
| 1523 | */ |
| 1524 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1525 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1526 | /* |
| 1527 | * 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] | 1528 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1529 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1530 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1531 | * chip functionality. |
| 1532 | */ |
| 1533 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1534 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1535 | /** |
| 1536 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1537 | * @flash_size: Usable flash size in bytes. |
| 1538 | * @write_block_size: Write block size. Write offset and size must be a |
| 1539 | * multiple of this. |
| 1540 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1541 | * multiple of this. |
| 1542 | * @protect_block_size: Protection block size. Protection offset and size |
| 1543 | * must be a multiple of this. |
| 1544 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1545 | * size is exactly this and offset is a multiple of this. |
| 1546 | * For example, an EC may have a write buffer which can do |
| 1547 | * half-page operations if data is aligned, and a slower |
| 1548 | * word-at-a-time write mode. |
| 1549 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1550 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1551 | * Version 1 returns the same initial fields as version 0, with additional |
| 1552 | * fields following. |
| 1553 | * |
| 1554 | * 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] | 1555 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1556 | * one. |
| 1557 | * |
| 1558 | * Version 2 supports flash banks of different sizes: |
| 1559 | * The caller specified the number of banks it has preallocated |
| 1560 | * (num_banks_desc) |
| 1561 | * The EC returns the number of banks describing the flash memory. |
| 1562 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1563 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1564 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1565 | /* Version 0 fields; see above for description */ |
| 1566 | uint32_t flash_size; |
| 1567 | uint32_t write_block_size; |
| 1568 | uint32_t erase_block_size; |
| 1569 | uint32_t protect_block_size; |
| 1570 | |
| 1571 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1572 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1573 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1574 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1575 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1576 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1577 | /* Number of banks to describe */ |
| 1578 | uint16_t num_banks_desc; |
| 1579 | /* Reserved; set 0; ignore on read */ |
| 1580 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1581 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1582 | |
| 1583 | struct ec_flash_bank { |
| 1584 | /* Number of sector is in this bank. */ |
| 1585 | uint16_t count; |
| 1586 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1587 | uint8_t size_exp; |
| 1588 | /* Minimal write size for the sectors in this bank */ |
| 1589 | uint8_t write_size_exp; |
| 1590 | /* Erase size for the sectors in this bank */ |
| 1591 | uint8_t erase_size_exp; |
| 1592 | /* Size for write protection, usually identical to erase size. */ |
| 1593 | uint8_t protect_size_exp; |
| 1594 | /* Reserved; set 0; ignore on read */ |
| 1595 | uint8_t reserved[2]; |
| 1596 | }; |
| 1597 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1598 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1599 | /* Total flash in the EC. */ |
| 1600 | uint32_t flash_size; |
| 1601 | /* Flags; see EC_FLASH_INFO_* */ |
| 1602 | uint32_t flags; |
| 1603 | /* Maximum size to use to send data to write to the EC. */ |
| 1604 | uint32_t write_ideal_size; |
| 1605 | /* Number of banks present in the EC. */ |
| 1606 | uint16_t num_banks_total; |
| 1607 | /* Number of banks described in banks array. */ |
| 1608 | uint16_t num_banks_desc; |
| 1609 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1610 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1611 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1612 | /* |
| 1613 | * Read flash |
| 1614 | * |
| 1615 | * Response is params.size bytes of data. |
| 1616 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1617 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1618 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1619 | /** |
| 1620 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1621 | * @offset: Byte offset to read. |
| 1622 | * @size: Size to read in bytes. |
| 1623 | */ |
| 1624 | struct ec_params_flash_read { |
| 1625 | uint32_t offset; |
| 1626 | uint32_t size; |
| 1627 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1628 | |
| 1629 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1630 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1631 | #define EC_VER_FLASH_WRITE 1 |
| 1632 | |
| 1633 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1634 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1635 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1636 | /** |
| 1637 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1638 | * @offset: Byte offset to write. |
| 1639 | * @size: Size to write in bytes. |
| 1640 | */ |
| 1641 | struct ec_params_flash_write { |
| 1642 | uint32_t offset; |
| 1643 | uint32_t size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1644 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1645 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1646 | |
| 1647 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1648 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1649 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1650 | /** |
| 1651 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1652 | * @offset: Byte offset to erase. |
| 1653 | * @size: Size to erase in bytes. |
| 1654 | */ |
| 1655 | struct ec_params_flash_erase { |
| 1656 | uint32_t offset; |
| 1657 | uint32_t size; |
| 1658 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1659 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1660 | /* |
| 1661 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1662 | * subcommands can returns: |
| 1663 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1664 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1665 | * EC_RES_ERROR : other errors. |
| 1666 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1667 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1668 | * |
| 1669 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1670 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1671 | * the proper result. |
| 1672 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1673 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1674 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1675 | * permitted while erasing. (For instance, STM32F4). |
| 1676 | */ |
| 1677 | enum ec_flash_erase_cmd { |
| 1678 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1679 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1680 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1681 | }; |
| 1682 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1683 | /** |
| 1684 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1685 | * @cmd: One of ec_flash_erase_cmd. |
| 1686 | * @reserved: Pad byte; currently always contains 0. |
| 1687 | * @flag: No flags defined yet; set to 0. |
| 1688 | * @params: Same as v0 parameters. |
| 1689 | */ |
| 1690 | struct ec_params_flash_erase_v1 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1691 | uint8_t cmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1692 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1693 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1694 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1695 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1696 | |
| 1697 | /* |
| 1698 | * Get/set flash protection. |
| 1699 | * |
| 1700 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1701 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1702 | * some flags require a subsequent hard reset to take effect. Check the |
| 1703 | * returned flags bits to see what actually happened. |
| 1704 | * |
| 1705 | * If mask=0, simply returns the current flags state. |
| 1706 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1707 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1708 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1709 | |
| 1710 | /* Flags for flash protection */ |
| 1711 | /* RO flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1712 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1713 | /* |
| 1714 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1715 | * be changed. |
| 1716 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1717 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1718 | /* Entire flash code protected now, until reboot. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1719 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1720 | /* Flash write protect GPIO is asserted now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1721 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1722 | /* 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] | 1723 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1724 | /* |
| 1725 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1726 | * flash which should be protected is not protected. Usually fixed by |
| 1727 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1728 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1729 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1730 | /* Entire flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1731 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1732 | /* RW flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1733 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1734 | /* RW flash code protected now. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1735 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1736 | /* Rollback information flash region protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1737 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1738 | /* Rollback information flash region protected now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1739 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1740 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1741 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1742 | /** |
| 1743 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1744 | * @mask: Bits in flags to apply. |
| 1745 | * @flags: New flags to apply. |
| 1746 | */ |
| 1747 | struct ec_params_flash_protect { |
| 1748 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1749 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1750 | } __ec_align4; |
| 1751 | |
| 1752 | /** |
| 1753 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1754 | * @flags: Current value of flash protect flags. |
| 1755 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1756 | * caller to distinguish between flags which aren't set vs. flags |
| 1757 | * which can't be set on this platform. |
| 1758 | * @writable_flags: Flags which can be changed given the current protection |
| 1759 | * state. |
| 1760 | */ |
| 1761 | struct ec_response_flash_protect { |
| 1762 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1763 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1764 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1765 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1766 | |
| 1767 | /* |
| 1768 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1769 | * write protect. These commands may be reused with version > 0. |
| 1770 | */ |
| 1771 | |
| 1772 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1773 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1774 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1775 | |
| 1776 | enum ec_flash_region { |
| 1777 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1778 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1779 | /* |
| 1780 | * Region which holds active RW image. 'Active' is different from |
| 1781 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1782 | * scheduled to run, active/non-active applies only to RW images (for |
| 1783 | * the same reason 'update' applies only to RW images. It's a state of |
| 1784 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1785 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1786 | * doesn't enter 'running' state but it's still active on a flash. |
| 1787 | */ |
| 1788 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1789 | /* |
| 1790 | * Region which should be write-protected in the factory (a superset of |
| 1791 | * EC_FLASH_REGION_RO) |
| 1792 | */ |
| 1793 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1794 | /* Region which holds updatable (non-active) RW image */ |
| 1795 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1796 | /* Number of regions */ |
| 1797 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1798 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1799 | /* |
| 1800 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1801 | * so the old constant is deprecated. |
| 1802 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1803 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1804 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1805 | /** |
| 1806 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1807 | * command. |
| 1808 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1809 | */ |
| 1810 | struct ec_params_flash_region_info { |
| 1811 | uint32_t region; |
| 1812 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1813 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1814 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1815 | uint32_t offset; |
| 1816 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1817 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1818 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 1819 | /* |
| 1820 | * Read/write VbNvContext |
| 1821 | * |
| 1822 | * Deprecated as of February 2021. No current devices use VBNV in EC |
| 1823 | * BBRAM anymore, so this is guaranteed to fail. |
| 1824 | * |
| 1825 | * TODO(b/178689388): remove from this header once no external |
| 1826 | * dependencies reference these constants. |
| 1827 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1828 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1829 | #define EC_VER_VBNV_CONTEXT 1 |
| 1830 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1831 | |
| 1832 | enum ec_vbnvcontext_op { |
| 1833 | EC_VBNV_CONTEXT_OP_READ, |
| 1834 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1835 | }; |
| 1836 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1837 | struct ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1838 | uint32_t op; |
| 1839 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1840 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1841 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1842 | struct ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1843 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1844 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1845 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1846 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1847 | /* Get SPI flash information */ |
| 1848 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1849 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1850 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1851 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1852 | uint8_t jedec[3]; |
| 1853 | |
| 1854 | /* Pad byte; currently always contains 0 */ |
| 1855 | uint8_t reserved0; |
| 1856 | |
| 1857 | /* Manufacturer / device ID from command 0x90 */ |
| 1858 | uint8_t mfr_dev_id[2]; |
| 1859 | |
| 1860 | /* Status registers from command 0x05 and 0x35 */ |
| 1861 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1862 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1863 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1864 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1865 | /* Select flash during flash operations */ |
| 1866 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1867 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1868 | /** |
| 1869 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1870 | * @select: 1 to select flash, 0 to deselect flash |
| 1871 | */ |
| 1872 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1873 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1874 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1875 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1876 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1877 | /** |
| 1878 | * Request random numbers to be generated and returned. |
| 1879 | * Can be used to test the random number generator is truly random. |
| 1880 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1881 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1882 | */ |
| 1883 | #define EC_CMD_RAND_NUM 0x001A |
| 1884 | #define EC_VER_RAND_NUM 0 |
| 1885 | |
| 1886 | struct ec_params_rand_num { |
| 1887 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
| 1888 | } __ec_align4; |
| 1889 | |
| 1890 | struct ec_response_rand_num { |
| 1891 | uint8_t rand[0]; /**< generated random numbers */ |
| 1892 | } __ec_align4; |
| 1893 | |
| 1894 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1895 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1896 | /** |
| 1897 | * Get information about the key used to sign the RW firmware. |
| 1898 | * For more details on the fields, see "struct vb21_packed_key". |
| 1899 | */ |
| 1900 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1901 | #define EC_VER_RWSIG_INFO 0 |
| 1902 | |
| 1903 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1904 | |
| 1905 | #ifdef CHROMIUM_EC |
| 1906 | /* Don't force external projects to depend on the vboot headers. */ |
| 1907 | #include "vb21_struct.h" |
| 1908 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1909 | #endif |
| 1910 | |
| 1911 | struct ec_response_rwsig_info { |
| 1912 | /** |
| 1913 | * Signature algorithm used by the key |
| 1914 | * (enum vb2_signature_algorithm). |
| 1915 | */ |
| 1916 | uint16_t sig_alg; |
| 1917 | |
| 1918 | /** |
| 1919 | * Hash digest algorithm used with the key |
| 1920 | * (enum vb2_hash_algorithm). |
| 1921 | */ |
| 1922 | uint16_t hash_alg; |
| 1923 | |
| 1924 | /** Key version. */ |
| 1925 | uint32_t key_version; |
| 1926 | |
| 1927 | /** Key ID (struct vb2_id). */ |
| 1928 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 1929 | |
| 1930 | uint8_t key_is_valid; |
| 1931 | |
| 1932 | /** Alignment padding. */ |
| 1933 | uint8_t reserved[3]; |
| 1934 | } __ec_align4; |
| 1935 | |
| 1936 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 1937 | |
| 1938 | /** |
| 1939 | * Get information about the system, such as reset flags, locked state, etc. |
| 1940 | */ |
| 1941 | #define EC_CMD_SYSINFO 0x001C |
| 1942 | #define EC_VER_SYSINFO 0 |
| 1943 | |
| 1944 | enum sysinfo_flags { |
| 1945 | SYSTEM_IS_LOCKED = BIT(0), |
| 1946 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 1947 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 1948 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
| 1949 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4) |
| 1950 | }; |
| 1951 | |
| 1952 | struct ec_response_sysinfo { |
| 1953 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
| 1954 | uint32_t current_image; /**< enum ec_current_image */ |
| 1955 | uint32_t flags; /**< enum sysinfo_flags */ |
| 1956 | } __ec_align4; |
| 1957 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1958 | /*****************************************************************************/ |
| 1959 | /* PWM commands */ |
| 1960 | |
| 1961 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1962 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1963 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1964 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1965 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1966 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1967 | |
| 1968 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1969 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1970 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1971 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1972 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1973 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1974 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1975 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1976 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1977 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1978 | uint32_t rpm; |
| 1979 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1980 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1981 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1982 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1983 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1984 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1985 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1986 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1987 | uint8_t percent; |
| 1988 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1989 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1990 | |
| 1991 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1992 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1993 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1994 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1995 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1996 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1997 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1998 | |
| 1999 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2000 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2001 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2002 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2003 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2004 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2005 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2006 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2007 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2008 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2009 | uint32_t percent; |
| 2010 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2011 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2012 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2013 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2014 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 2015 | #define EC_PWM_MAX_DUTY 0xffff |
| 2016 | |
| 2017 | enum ec_pwm_type { |
| 2018 | /* All types, indexed by board-specific enum pwm_channel */ |
| 2019 | EC_PWM_TYPE_GENERIC = 0, |
| 2020 | /* Keyboard backlight */ |
| 2021 | EC_PWM_TYPE_KB_LIGHT, |
| 2022 | /* Display backlight */ |
| 2023 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 2024 | EC_PWM_TYPE_COUNT, |
| 2025 | }; |
| 2026 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2027 | struct ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2028 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 2029 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2030 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2031 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2032 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2033 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2034 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2035 | struct ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2036 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2037 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2038 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2039 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2040 | struct ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2041 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2042 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2043 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2044 | /*****************************************************************************/ |
| 2045 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2046 | * 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] | 2047 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 2048 | * into a subcommand. We'll make separate structs for subcommands with |
| 2049 | * different input args, so that we know how much to expect. |
| 2050 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2051 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2053 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2054 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2055 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2056 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2057 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2058 | |
| 2059 | /* |
| 2060 | * 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] | 2061 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2062 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2063 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2064 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2065 | int32_t google_ramp_up; |
| 2066 | int32_t google_ramp_down; |
| 2067 | int32_t s3s0_ramp_up; |
| 2068 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2069 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2070 | int32_t s0s3_ramp_down; |
| 2071 | int32_t s3_sleep_for; |
| 2072 | int32_t s3_ramp_up; |
| 2073 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2074 | |
| 2075 | /* Oscillation */ |
| 2076 | uint8_t new_s0; |
| 2077 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2078 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2079 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2080 | |
| 2081 | /* Brightness limits based on the backlight and AC. */ |
| 2082 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2083 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2084 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2085 | |
| 2086 | /* Battery level thresholds */ |
| 2087 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2088 | |
| 2089 | /* Map [AC][battery_level] to color index */ |
| 2090 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2091 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2092 | |
| 2093 | /* Color palette */ |
| 2094 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2095 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2096 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2097 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2098 | /* Timing */ |
| 2099 | int32_t google_ramp_up; |
| 2100 | int32_t google_ramp_down; |
| 2101 | int32_t s3s0_ramp_up; |
| 2102 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2103 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2104 | int32_t s0s3_ramp_down; |
| 2105 | int32_t s3_sleep_for; |
| 2106 | int32_t s3_ramp_up; |
| 2107 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2108 | int32_t s5_ramp_up; |
| 2109 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2110 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2111 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2112 | int32_t tap_display_time; |
| 2113 | |
| 2114 | /* Tap-for-battery params */ |
| 2115 | uint8_t tap_pct_red; |
| 2116 | uint8_t tap_pct_green; |
| 2117 | uint8_t tap_seg_min_on; |
| 2118 | uint8_t tap_seg_max_on; |
| 2119 | uint8_t tap_seg_osc; |
| 2120 | uint8_t tap_idx[3]; |
| 2121 | |
| 2122 | /* Oscillation */ |
| 2123 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2124 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2125 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2126 | |
| 2127 | /* Brightness limits based on the backlight and AC. */ |
| 2128 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2129 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2130 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2131 | |
| 2132 | /* Battery level thresholds */ |
| 2133 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2134 | |
| 2135 | /* Map [AC][battery_level] to color index */ |
| 2136 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2137 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2138 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2139 | /* s5: single color pulse on inhibited power-up */ |
| 2140 | uint8_t s5_idx; |
| 2141 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2142 | /* Color palette */ |
| 2143 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2144 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2145 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2146 | /* Lightbar command params v2 |
| 2147 | * crbug.com/467716 |
| 2148 | * |
| 2149 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2150 | * logical groups to make it more manageable ( < 120 bytes). |
| 2151 | * |
| 2152 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2153 | */ |
| 2154 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2155 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2156 | /* Timing */ |
| 2157 | int32_t google_ramp_up; |
| 2158 | int32_t google_ramp_down; |
| 2159 | int32_t s3s0_ramp_up; |
| 2160 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2161 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2162 | int32_t s0s3_ramp_down; |
| 2163 | int32_t s3_sleep_for; |
| 2164 | int32_t s3_ramp_up; |
| 2165 | int32_t s3_ramp_down; |
| 2166 | int32_t s5_ramp_up; |
| 2167 | int32_t s5_ramp_down; |
| 2168 | int32_t tap_tick_delay; |
| 2169 | int32_t tap_gate_delay; |
| 2170 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2171 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2172 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2173 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2174 | /* Tap-for-battery params */ |
| 2175 | uint8_t tap_pct_red; |
| 2176 | uint8_t tap_pct_green; |
| 2177 | uint8_t tap_seg_min_on; |
| 2178 | uint8_t tap_seg_max_on; |
| 2179 | uint8_t tap_seg_osc; |
| 2180 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2181 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2182 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2183 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2184 | /* Oscillation */ |
| 2185 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2186 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2187 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2188 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2189 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2190 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2191 | /* Brightness limits based on the backlight and AC. */ |
| 2192 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2193 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2194 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2195 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2196 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2197 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2198 | /* Battery level thresholds */ |
| 2199 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2200 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2201 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2202 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2203 | /* Map [AC][battery_level] to color index */ |
| 2204 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2205 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2206 | |
| 2207 | /* s5: single color pulse on inhibited power-up */ |
| 2208 | uint8_t s5_idx; |
| 2209 | |
| 2210 | /* Color palette */ |
| 2211 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2212 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2213 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2214 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2215 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2216 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2217 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2218 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2219 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2220 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2221 | struct ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2222 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 2223 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2224 | /* |
| 2225 | * The following commands have no args: |
| 2226 | * |
| 2227 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2228 | * version, get_brightness, get_demo, suspend, resume, |
| 2229 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2230 | * get_params_v2_bright, get_params_v2_thlds, |
| 2231 | * get_params_v2_colors |
| 2232 | * |
| 2233 | * Don't use an empty struct, because C++ hates that. |
| 2234 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2235 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2236 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2237 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2238 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2239 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2240 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2241 | uint8_t ctrl, reg, value; |
| 2242 | } reg; |
| 2243 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2244 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2245 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2246 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 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 led; |
| 2250 | } get_rgb; |
| 2251 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2252 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2253 | uint8_t enable; |
| 2254 | } manual_suspend_ctrl; |
| 2255 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2256 | struct lightbar_params_v0 set_params_v0; |
| 2257 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2258 | |
| 2259 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2260 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2261 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2262 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2263 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2264 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2265 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2266 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2267 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2268 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2269 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2270 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2271 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2272 | struct __ec_todo_unpacked { |
| 2273 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2274 | uint8_t reg; |
| 2275 | uint8_t ic0; |
| 2276 | uint8_t ic1; |
| 2277 | } vals[23]; |
| 2278 | } dump; |
| 2279 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2280 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2281 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2282 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2283 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2284 | struct lightbar_params_v0 get_params_v0; |
| 2285 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2286 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2287 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2288 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2289 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2290 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2291 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2292 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2293 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2294 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2295 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2296 | uint32_t num; |
| 2297 | uint32_t flags; |
| 2298 | } version; |
| 2299 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2300 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2301 | uint8_t red, green, blue; |
| 2302 | } get_rgb; |
| 2303 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2304 | /* |
| 2305 | * The following commands have no response: |
| 2306 | * |
| 2307 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2308 | * set_params_v0, set_params_v1, set_program, |
| 2309 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2310 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2311 | * set_v2par_thlds, set_v2par_colors |
| 2312 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2313 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2314 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2315 | |
| 2316 | /* Lightbar commands */ |
| 2317 | enum lightbar_command { |
| 2318 | LIGHTBAR_CMD_DUMP = 0, |
| 2319 | LIGHTBAR_CMD_OFF = 1, |
| 2320 | LIGHTBAR_CMD_ON = 2, |
| 2321 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2322 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2323 | LIGHTBAR_CMD_SEQ = 5, |
| 2324 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2325 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2326 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2327 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2328 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2329 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2330 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2331 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2332 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2333 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2334 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2335 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2336 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2337 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2338 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2339 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2340 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2341 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2342 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2343 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2344 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2345 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2346 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2347 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2348 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2349 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2350 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2351 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2352 | LIGHTBAR_NUM_CMDS |
| 2353 | }; |
| 2354 | |
| 2355 | /*****************************************************************************/ |
| 2356 | /* LED control commands */ |
| 2357 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2358 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2359 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2360 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2361 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2362 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2363 | /* |
| 2364 | * LED to indicate system power state (on or in suspend). |
| 2365 | * May be on power button or on C-panel. |
| 2366 | */ |
| 2367 | EC_LED_ID_POWER_LED, |
| 2368 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2369 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2370 | /* LED to indicate left side */ |
| 2371 | EC_LED_ID_LEFT_LED, |
| 2372 | /* LED to indicate right side */ |
| 2373 | EC_LED_ID_RIGHT_LED, |
| 2374 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2375 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2376 | /* LED to indicate sysrq debug mode. */ |
| 2377 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2378 | |
| 2379 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2380 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2381 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2382 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2383 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
| 2384 | #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] | 2385 | |
| 2386 | enum ec_led_colors { |
| 2387 | EC_LED_COLOR_RED = 0, |
| 2388 | EC_LED_COLOR_GREEN, |
| 2389 | EC_LED_COLOR_BLUE, |
| 2390 | EC_LED_COLOR_YELLOW, |
| 2391 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2392 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2393 | |
| 2394 | EC_LED_COLOR_COUNT |
| 2395 | }; |
| 2396 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2397 | struct ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2398 | uint8_t led_id; /* Which LED to control */ |
| 2399 | uint8_t flags; /* Control flags */ |
| 2400 | |
| 2401 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2402 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2403 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2404 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2405 | /* |
| 2406 | * Available brightness value range. |
| 2407 | * |
| 2408 | * Range 0 means color channel not present. |
| 2409 | * Range 1 means on/off control. |
| 2410 | * Other values means the LED is control by PWM. |
| 2411 | */ |
| 2412 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2413 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2414 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2415 | /*****************************************************************************/ |
| 2416 | /* Verified boot commands */ |
| 2417 | |
| 2418 | /* |
| 2419 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2420 | * reused for other purposes with version > 0. |
| 2421 | */ |
| 2422 | |
| 2423 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2424 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2425 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2426 | struct ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2427 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2428 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2429 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2430 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2431 | uint32_t offset; /* Offset in flash to hash */ |
| 2432 | uint32_t size; /* Number of bytes to hash */ |
| 2433 | 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] | 2434 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2435 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2436 | struct ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2437 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2438 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2439 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2440 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2441 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2442 | uint32_t size; /* Number of bytes hashed */ |
| 2443 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2444 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2445 | |
| 2446 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2447 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2448 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2449 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2450 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2451 | }; |
| 2452 | |
| 2453 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2454 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2455 | }; |
| 2456 | |
| 2457 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2458 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2459 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2460 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2461 | }; |
| 2462 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2463 | /* |
| 2464 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2465 | * If one of these is specified, the EC will automatically update offset and |
| 2466 | * size to the correct values for the specified image (RO or RW). |
| 2467 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2468 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2469 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2470 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
| 2471 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2472 | /* |
| 2473 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2474 | * so the old constant is deprecated. |
| 2475 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2476 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2477 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2478 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2479 | /* |
| 2480 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2481 | * different input args, so that we know how much to expect. |
| 2482 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2483 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2484 | |
| 2485 | /* Motion sense commands */ |
| 2486 | enum motionsense_command { |
| 2487 | /* |
| 2488 | * Dump command returns all motion sensor data including motion sense |
| 2489 | * module flags and individual sensor flags. |
| 2490 | */ |
| 2491 | MOTIONSENSE_CMD_DUMP = 0, |
| 2492 | |
| 2493 | /* |
| 2494 | * Info command returns data describing the details of a given sensor, |
| 2495 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2496 | * enum motionsensor_chip. |
| 2497 | */ |
| 2498 | MOTIONSENSE_CMD_INFO = 1, |
| 2499 | |
| 2500 | /* |
| 2501 | * 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] | 2502 | * in milliseconds. |
| 2503 | * It is per sensor, the EC run sample task at the minimum of all |
| 2504 | * sensors EC_RATE. |
| 2505 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2506 | * to collect all the sensor samples. |
| 2507 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2508 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2509 | */ |
| 2510 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2511 | |
| 2512 | /* |
| 2513 | * Sensor ODR command is a setter/getter command for the output data |
| 2514 | * rate of a specific motion sensor in millihertz. |
| 2515 | */ |
| 2516 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2517 | |
| 2518 | /* |
| 2519 | * Sensor range command is a setter/getter command for the range of |
| 2520 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2521 | */ |
| 2522 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2523 | |
| 2524 | /* |
| 2525 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2526 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2527 | * and when the lid angle goes less than this value, keyboard wake is |
| 2528 | * enabled. Note, the lid angle measurement is an approximate, |
| 2529 | * un-calibrated value, hence the wake angle isn't exact. |
| 2530 | */ |
| 2531 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2532 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2533 | /* |
| 2534 | * Returns a single sensor data. |
| 2535 | */ |
| 2536 | MOTIONSENSE_CMD_DATA = 6, |
| 2537 | |
| 2538 | /* |
| 2539 | * Return sensor fifo info. |
| 2540 | */ |
| 2541 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2542 | |
| 2543 | /* |
| 2544 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2545 | * The host can use that element to synchronize its operation. |
| 2546 | */ |
| 2547 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2548 | |
| 2549 | /* |
| 2550 | * Return a portion of the fifo. |
| 2551 | */ |
| 2552 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2553 | |
| 2554 | /* |
| 2555 | * Perform low level calibration. |
| 2556 | * On sensors that support it, ask to do offset calibration. |
| 2557 | */ |
| 2558 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2559 | |
| 2560 | /* |
| 2561 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2562 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2563 | * The offsets can be calculated by the host, or via |
| 2564 | * PERFORM_CALIB command. |
| 2565 | */ |
| 2566 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2567 | |
| 2568 | /* |
| 2569 | * List available activities for a MOTION sensor. |
| 2570 | * Indicates if they are enabled or disabled. |
| 2571 | */ |
| 2572 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2573 | |
| 2574 | /* |
| 2575 | * Activity management |
| 2576 | * Enable/Disable activity recognition. |
| 2577 | */ |
| 2578 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2579 | |
| 2580 | /* |
| 2581 | * Lid Angle |
| 2582 | */ |
| 2583 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2584 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2585 | /* |
| 2586 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2587 | * By default the FIFO does not send interrupt to process the FIFO |
| 2588 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2589 | */ |
| 2590 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2591 | |
| 2592 | /* |
| 2593 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2594 | * to arbitrary values, or will lock to the last read actual values. |
| 2595 | */ |
| 2596 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2597 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2598 | /* Set lid angle for tablet mode detection. */ |
| 2599 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2600 | |
| 2601 | /* |
| 2602 | * Sensor Scale command is a setter/getter command for the calibration |
| 2603 | * scale. |
| 2604 | */ |
| 2605 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2606 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2607 | /* |
| 2608 | * Read the current online calibration values (if available). |
| 2609 | */ |
| 2610 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2611 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2612 | /* |
| 2613 | * Activity management |
| 2614 | * Retrieve current status of given activity. |
| 2615 | */ |
| 2616 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2617 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2618 | /* Number of motionsense sub-commands. */ |
| 2619 | MOTIONSENSE_NUM_CMDS |
| 2620 | }; |
| 2621 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2622 | /* List of motion sensor types. */ |
| 2623 | enum motionsensor_type { |
| 2624 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2625 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2626 | MOTIONSENSE_TYPE_MAG = 2, |
| 2627 | MOTIONSENSE_TYPE_PROX = 3, |
| 2628 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2629 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2630 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2631 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2632 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2633 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2634 | }; |
| 2635 | |
| 2636 | /* List of motion sensor locations. */ |
| 2637 | enum motionsensor_location { |
| 2638 | MOTIONSENSE_LOC_BASE = 0, |
| 2639 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2640 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2641 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2642 | }; |
| 2643 | |
| 2644 | /* List of motion sensor chips. */ |
| 2645 | enum motionsensor_chip { |
| 2646 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2647 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2648 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2649 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2650 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2651 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2652 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2653 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2654 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2655 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2656 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2657 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2658 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2659 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2660 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2661 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2662 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2663 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2664 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2665 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2666 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2667 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2668 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2669 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2670 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2671 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 2672 | MOTIONSENSE_CHIP_ICM42607 = 26, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2673 | MOTIONSENSE_CHIP_MAX, |
| 2674 | }; |
| 2675 | |
| 2676 | /* List of orientation positions */ |
| 2677 | enum motionsensor_orientation { |
| 2678 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2679 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2680 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2681 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2682 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2683 | }; |
| 2684 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2685 | struct ec_response_activity_data { |
| 2686 | uint8_t activity; /* motionsensor_activity */ |
| 2687 | uint8_t state; |
| 2688 | } __ec_todo_packed; |
| 2689 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2690 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2691 | /* Flags for each sensor. */ |
| 2692 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2693 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2694 | uint8_t sensor_num; |
| 2695 | /* Each sensor is up to 3-axis. */ |
| 2696 | union { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2697 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2698 | /* for sensors using unsigned data */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2699 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2700 | struct __ec_todo_packed { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2701 | uint16_t reserved; |
| 2702 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2703 | }; |
| 2704 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2705 | struct ec_response_activity_data activity_data; |
| 2706 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2707 | }; |
| 2708 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2709 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2710 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2711 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2712 | struct ec_response_online_calibration_data { |
| 2713 | /** The calibration values. */ |
| 2714 | int16_t data[3]; |
| 2715 | }; |
| 2716 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2717 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2718 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2719 | /* Size of the fifo */ |
| 2720 | uint16_t size; |
| 2721 | /* Amount of space used in the fifo */ |
| 2722 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2723 | /* Timestamp recorded in us. |
| 2724 | * aka accurate timestamp when host event was triggered. |
| 2725 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2726 | uint32_t timestamp; |
| 2727 | /* Total amount of vector lost */ |
| 2728 | uint16_t total_lost; |
| 2729 | /* Lost events since the last fifo_info, per sensors */ |
| 2730 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2731 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2732 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2733 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2734 | uint32_t number_data; |
| 2735 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2736 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2737 | |
| 2738 | /* List supported activity recognition */ |
| 2739 | enum motionsensor_activity { |
| 2740 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2741 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2742 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2743 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2744 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2745 | }; |
| 2746 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2747 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2748 | uint8_t sensor_num; |
| 2749 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2750 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2751 | uint8_t reserved; |
| 2752 | uint16_t parameters[3]; /* activity dependent parameters */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2753 | } __ec_todo_unpacked; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2754 | |
| 2755 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2756 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2757 | |
| 2758 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2759 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2760 | |
| 2761 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2762 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2763 | * data contains time stamp |
| 2764 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2765 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2766 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2767 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2768 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2769 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2770 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 2771 | #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7) |
| 2772 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2773 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2774 | * Send this value for the data element to only perform a read. If you |
| 2775 | * send any other value, the EC will interpret it as data to set and will |
| 2776 | * return the actual value set. |
| 2777 | */ |
| 2778 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2779 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2780 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2781 | |
| 2782 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2783 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2784 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2785 | |
| 2786 | /* Default Scale value, factor 1. */ |
| 2787 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2788 | |
| 2789 | #define LID_ANGLE_UNRELIABLE 500 |
| 2790 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2791 | enum motionsense_spoof_mode { |
| 2792 | /* Disable spoof mode. */ |
| 2793 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2794 | |
| 2795 | /* Enable spoof mode, but use provided component values. */ |
| 2796 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2797 | |
| 2798 | /* Enable spoof mode, but use the current sensor values. */ |
| 2799 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2800 | |
| 2801 | /* Query the current spoof mode status for the sensor. */ |
| 2802 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2803 | }; |
| 2804 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2805 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2806 | uint8_t cmd; |
| 2807 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2808 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2809 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2810 | /* |
| 2811 | * Maximal number of sensor the host is expecting. |
| 2812 | * 0 means the host is only interested in the number |
| 2813 | * of sensors controlled by the EC. |
| 2814 | */ |
| 2815 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2816 | } dump; |
| 2817 | |
| 2818 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2819 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2820 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2821 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2822 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 2823 | * kb_wake_angle: angle to wakup AP. |
| 2824 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2825 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2826 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2828 | /* |
| 2829 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2830 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2831 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2832 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2833 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2834 | |
| 2835 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2836 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2837 | * Allow entering/exiting the calibration mode. |
| 2838 | */ |
| 2839 | struct __ec_todo_unpacked { |
| 2840 | uint8_t sensor_num; |
| 2841 | uint8_t enable; |
| 2842 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2843 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2844 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2845 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2846 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2847 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2848 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2849 | uint8_t sensor_num; |
| 2850 | |
| 2851 | /* Rounding flag, true for round-up, false for down. */ |
| 2852 | uint8_t roundup; |
| 2853 | |
| 2854 | uint16_t reserved; |
| 2855 | |
| 2856 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2857 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2858 | } ec_rate, sensor_odr, sensor_range; |
| 2859 | |
| 2860 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2861 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2862 | uint8_t sensor_num; |
| 2863 | |
| 2864 | /* |
| 2865 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2866 | * the calibration information in the EC. |
| 2867 | * If unset, just retrieve calibration information. |
| 2868 | */ |
| 2869 | uint16_t flags; |
| 2870 | |
| 2871 | /* |
| 2872 | * Temperature at calibration, in units of 0.01 C |
| 2873 | * 0x8000: invalid / unknown. |
| 2874 | * 0x0: 0C |
| 2875 | * 0x7fff: +327.67C |
| 2876 | */ |
| 2877 | int16_t temp; |
| 2878 | |
| 2879 | /* |
| 2880 | * Offset for calibration. |
| 2881 | * Unit: |
| 2882 | * Accelerometer: 1/1024 g |
| 2883 | * Gyro: 1/1024 deg/s |
| 2884 | * Compass: 1/16 uT |
| 2885 | */ |
| 2886 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2887 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2888 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2889 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2890 | struct __ec_todo_packed { |
| 2891 | uint8_t sensor_num; |
| 2892 | |
| 2893 | /* |
| 2894 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2895 | * the calibration information in the EC. |
| 2896 | * If unset, just retrieve calibration information. |
| 2897 | */ |
| 2898 | uint16_t flags; |
| 2899 | |
| 2900 | /* |
| 2901 | * Temperature at calibration, in units of 0.01 C |
| 2902 | * 0x8000: invalid / unknown. |
| 2903 | * 0x0: 0C |
| 2904 | * 0x7fff: +327.67C |
| 2905 | */ |
| 2906 | int16_t temp; |
| 2907 | |
| 2908 | /* |
| 2909 | * Scale for calibration: |
| 2910 | * By default scale is 1, it is encoded on 16bits: |
| 2911 | * 1 = BIT(15) |
| 2912 | * ~2 = 0xFFFF |
| 2913 | * ~0 = 0. |
| 2914 | */ |
| 2915 | uint16_t scale[3]; |
| 2916 | } sensor_scale; |
| 2917 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2918 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2919 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2920 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2921 | |
| 2922 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2923 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2924 | /* |
| 2925 | * Number of expected vector to return. |
| 2926 | * EC may return less or 0 if none available. |
| 2927 | */ |
| 2928 | uint32_t max_data_vector; |
| 2929 | } fifo_read; |
| 2930 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2931 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2932 | struct ec_motion_sense_activity set_activity; |
| 2933 | |
| 2934 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2935 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2936 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2937 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2938 | struct __ec_todo_unpacked { |
| 2939 | /* |
| 2940 | * 1: enable, 0 disable fifo, |
| 2941 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2942 | */ |
| 2943 | int8_t enable; |
| 2944 | } fifo_int_enable; |
| 2945 | |
| 2946 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2947 | struct __ec_todo_packed { |
| 2948 | uint8_t sensor_id; |
| 2949 | |
| 2950 | /* See enum motionsense_spoof_mode. */ |
| 2951 | uint8_t spoof_enable; |
| 2952 | |
| 2953 | /* Ignored, used for alignment. */ |
| 2954 | uint8_t reserved; |
| 2955 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2956 | union { |
| 2957 | /* Individual component values to spoof. */ |
| 2958 | int16_t components[3]; |
| 2959 | |
| 2960 | /* Used when spoofing an activity */ |
| 2961 | struct { |
| 2962 | /* enum motionsensor_activity */ |
| 2963 | uint8_t activity_num; |
| 2964 | |
| 2965 | /* spoof activity state */ |
| 2966 | uint8_t activity_state; |
| 2967 | }; |
| 2968 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2969 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2970 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2971 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 2972 | struct __ec_todo_unpacked { |
| 2973 | /* |
| 2974 | * Lid angle threshold for switching between tablet and |
| 2975 | * clamshell mode. |
| 2976 | */ |
| 2977 | int16_t lid_angle; |
| 2978 | |
| 2979 | /* |
| 2980 | * Hysteresis degree to prevent fluctuations between |
| 2981 | * clamshell and tablet mode if lid angle keeps |
| 2982 | * changing around the threshold. Lid motion driver will |
| 2983 | * use lid_angle + hys_degree to trigger tablet mode and |
| 2984 | * lid_angle - hys_degree to trigger clamshell mode. |
| 2985 | */ |
| 2986 | int16_t hys_degree; |
| 2987 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2988 | |
| 2989 | /* |
| 2990 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 2991 | * Allow reading a single sensor's online calibration value. |
| 2992 | */ |
| 2993 | struct __ec_todo_unpacked { |
| 2994 | uint8_t sensor_num; |
| 2995 | } online_calib_read; |
| 2996 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2997 | /* |
| 2998 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 2999 | */ |
| 3000 | struct __ec_todo_unpacked { |
| 3001 | uint8_t sensor_num; |
| 3002 | uint8_t activity; /* enum motionsensor_activity */ |
| 3003 | } get_activity; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3004 | }; |
| 3005 | } __ec_todo_packed; |
| 3006 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3007 | enum motion_sense_cmd_info_flags { |
| 3008 | /* The sensor supports online calibration */ |
| 3009 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 3010 | }; |
| 3011 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3012 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3013 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3014 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3015 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3016 | /* Flags representing the motion sensor module. */ |
| 3017 | uint8_t module_flags; |
| 3018 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3019 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3020 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3021 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3022 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3023 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3024 | * for holding all the data. |
| 3025 | */ |
| 3026 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3027 | } dump; |
| 3028 | |
| 3029 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3030 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3031 | /* Should be element of enum motionsensor_type. */ |
| 3032 | uint8_t type; |
| 3033 | |
| 3034 | /* Should be element of enum motionsensor_location. */ |
| 3035 | uint8_t location; |
| 3036 | |
| 3037 | /* Should be element of enum motionsensor_chip. */ |
| 3038 | uint8_t chip; |
| 3039 | } info; |
| 3040 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3041 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 3042 | struct __ec_todo_unpacked { |
| 3043 | /* Should be element of enum motionsensor_type. */ |
| 3044 | uint8_t type; |
| 3045 | |
| 3046 | /* Should be element of enum motionsensor_location. */ |
| 3047 | uint8_t location; |
| 3048 | |
| 3049 | /* Should be element of enum motionsensor_chip. */ |
| 3050 | uint8_t chip; |
| 3051 | |
| 3052 | /* Minimum sensor sampling frequency */ |
| 3053 | uint32_t min_frequency; |
| 3054 | |
| 3055 | /* Maximum sensor sampling frequency */ |
| 3056 | uint32_t max_frequency; |
| 3057 | |
| 3058 | /* Max number of sensor events that could be in fifo */ |
| 3059 | uint32_t fifo_max_event_count; |
| 3060 | } info_3; |
| 3061 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3062 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3063 | struct __ec_align4 { |
| 3064 | /* Should be element of enum motionsensor_type. */ |
| 3065 | uint8_t type; |
| 3066 | |
| 3067 | /* Should be element of enum motionsensor_location. */ |
| 3068 | uint8_t location; |
| 3069 | |
| 3070 | /* Should be element of enum motionsensor_chip. */ |
| 3071 | uint8_t chip; |
| 3072 | |
| 3073 | /* Minimum sensor sampling frequency */ |
| 3074 | uint32_t min_frequency; |
| 3075 | |
| 3076 | /* Maximum sensor sampling frequency */ |
| 3077 | uint32_t max_frequency; |
| 3078 | |
| 3079 | /* Max number of sensor events that could be in fifo */ |
| 3080 | uint32_t fifo_max_event_count; |
| 3081 | |
| 3082 | /* |
| 3083 | * Should be elements of |
| 3084 | * enum motion_sense_cmd_info_flags |
| 3085 | */ |
| 3086 | uint32_t flags; |
| 3087 | } info_4; |
| 3088 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3089 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3090 | struct ec_response_motion_sensor_data data; |
| 3091 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3092 | /* |
| 3093 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3094 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3095 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3096 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3097 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3098 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3099 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3100 | /* Current value of the parameter queried. */ |
| 3101 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3102 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 3103 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3104 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3105 | /* |
| 3106 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3107 | * PERFORM_CALIB. |
| 3108 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3109 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3110 | int16_t temp; |
| 3111 | int16_t offset[3]; |
| 3112 | } sensor_offset, perform_calib; |
| 3113 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3114 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3115 | struct __ec_todo_unpacked { |
| 3116 | int16_t temp; |
| 3117 | uint16_t scale[3]; |
| 3118 | } sensor_scale; |
| 3119 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3120 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3121 | |
| 3122 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3123 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3124 | struct ec_response_online_calibration_data online_calib_read; |
| 3125 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3126 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3127 | uint16_t reserved; |
| 3128 | uint32_t enabled; |
| 3129 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3130 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3131 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3132 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3133 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3134 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3135 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3136 | /* |
| 3137 | * Angle between 0 and 360 degree if available, |
| 3138 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3139 | */ |
| 3140 | uint16_t value; |
| 3141 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3142 | |
| 3143 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3144 | struct __ec_todo_unpacked { |
| 3145 | /* |
| 3146 | * Lid angle threshold for switching between tablet and |
| 3147 | * clamshell mode. |
| 3148 | */ |
| 3149 | uint16_t lid_angle; |
| 3150 | |
| 3151 | /* Hysteresis degree. */ |
| 3152 | uint16_t hys_degree; |
| 3153 | } tablet_mode_threshold; |
| 3154 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3155 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3156 | struct __ec_todo_unpacked { |
| 3157 | uint8_t state; |
| 3158 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3159 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3160 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3161 | |
| 3162 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3163 | /* Force lid open command */ |
| 3164 | |
| 3165 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3166 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3167 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3168 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3169 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3170 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3171 | |
| 3172 | /*****************************************************************************/ |
| 3173 | /* Configure the behavior of the power button */ |
| 3174 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3175 | |
| 3176 | enum ec_config_power_button_flags { |
| 3177 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3178 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3179 | }; |
| 3180 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3181 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3182 | /* See enum ec_config_power_button_flags */ |
| 3183 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3184 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3185 | |
| 3186 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3187 | /* USB charging control commands */ |
| 3188 | |
| 3189 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3190 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3191 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3192 | enum usb_charge_mode { |
| 3193 | /* Disable USB port. */ |
| 3194 | USB_CHARGE_MODE_DISABLED, |
| 3195 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3196 | USB_CHARGE_MODE_SDP2, |
| 3197 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3198 | USB_CHARGE_MODE_CDP, |
| 3199 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3200 | USB_CHARGE_MODE_DCP_SHORT, |
| 3201 | /* Enable USB port (for dumb ports). */ |
| 3202 | USB_CHARGE_MODE_ENABLED, |
| 3203 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3204 | USB_CHARGE_MODE_DEFAULT, |
| 3205 | |
| 3206 | USB_CHARGE_MODE_COUNT |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3207 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3208 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3209 | enum usb_suspend_charge { |
| 3210 | /* Enable charging in suspend */ |
| 3211 | USB_ALLOW_SUSPEND_CHARGE, |
| 3212 | /* Disable charging in suspend */ |
| 3213 | USB_DISALLOW_SUSPEND_CHARGE |
| 3214 | }; |
| 3215 | |
| 3216 | struct ec_params_usb_charge_set_mode { |
| 3217 | uint8_t usb_port_id; |
| 3218 | uint8_t mode:7; /* enum usb_charge_mode */ |
| 3219 | uint8_t inhibit_charge:1; /* enum usb_suspend_charge */ |
| 3220 | } __ec_align1; |
| 3221 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3222 | /*****************************************************************************/ |
| 3223 | /* Persistent storage for host */ |
| 3224 | |
| 3225 | /* Maximum bytes that can be read/written in a single command */ |
| 3226 | #define EC_PSTORE_SIZE_MAX 64 |
| 3227 | |
| 3228 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3229 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3230 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3231 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3232 | /* Persistent storage size, in bytes */ |
| 3233 | uint32_t pstore_size; |
| 3234 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3235 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3236 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3237 | |
| 3238 | /* |
| 3239 | * Read persistent storage |
| 3240 | * |
| 3241 | * Response is params.size bytes of data. |
| 3242 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3243 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3244 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3245 | struct ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3246 | uint32_t offset; /* Byte offset to read */ |
| 3247 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3248 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3249 | |
| 3250 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3251 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3252 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3253 | struct ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3254 | uint32_t offset; /* Byte offset to write */ |
| 3255 | uint32_t size; /* Size to write in bytes */ |
| 3256 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3257 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3258 | |
| 3259 | /*****************************************************************************/ |
| 3260 | /* Real-time clock */ |
| 3261 | |
| 3262 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3263 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3264 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3265 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3266 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3267 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3268 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3269 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3270 | |
| 3271 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3272 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3273 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3274 | |
| 3275 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3276 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3277 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3278 | |
| 3279 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3280 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3281 | |
| 3282 | /*****************************************************************************/ |
| 3283 | /* Port80 log access */ |
| 3284 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3285 | /* Maximum entries that can be read/written in a single command */ |
| 3286 | #define EC_PORT80_SIZE_MAX 32 |
| 3287 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3288 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3289 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3290 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3291 | |
| 3292 | enum ec_port80_subcmd { |
| 3293 | EC_PORT80_GET_INFO = 0, |
| 3294 | EC_PORT80_READ_BUFFER, |
| 3295 | }; |
| 3296 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3297 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3298 | uint16_t subcmd; |
| 3299 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3300 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3301 | uint32_t offset; |
| 3302 | uint32_t num_entries; |
| 3303 | } read_buffer; |
| 3304 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3305 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3307 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3308 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3309 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3310 | uint32_t writes; |
| 3311 | uint32_t history_size; |
| 3312 | uint32_t last_boot; |
| 3313 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3314 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3315 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3316 | } data; |
| 3317 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3318 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3319 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3320 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3321 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3322 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3323 | |
| 3324 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3325 | /* Temporary secure storage for host verified boot use */ |
| 3326 | |
| 3327 | /* Number of bytes in a vstore slot */ |
| 3328 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3329 | |
| 3330 | /* Maximum number of vstore slots */ |
| 3331 | #define EC_VSTORE_SLOT_MAX 32 |
| 3332 | |
| 3333 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3334 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3335 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3336 | /* Indicates which slots are locked */ |
| 3337 | uint32_t slot_locked; |
| 3338 | /* Total number of slots available */ |
| 3339 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3340 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3341 | |
| 3342 | /* |
| 3343 | * Read temporary secure storage |
| 3344 | * |
| 3345 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3346 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3347 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3348 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3349 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3350 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3351 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3352 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3353 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3354 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3355 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3356 | |
| 3357 | /* |
| 3358 | * Write temporary secure storage and lock it. |
| 3359 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3360 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3361 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3362 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3363 | uint8_t slot; /* Slot to write to */ |
| 3364 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3365 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3366 | |
| 3367 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3368 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3369 | * reuse the command number, but the data and behavior is incompatible. |
| 3370 | * Version 0 is what originally shipped on Link. |
| 3371 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3372 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3373 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3374 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3375 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3376 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3377 | /* The version 0 structs are opaque. You have to know what they are for |
| 3378 | * the get/set commands to make any sense. |
| 3379 | */ |
| 3380 | |
| 3381 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3382 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3383 | uint8_t sensor_type; |
| 3384 | uint8_t threshold_id; |
| 3385 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3386 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3387 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3388 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3389 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3390 | uint8_t sensor_type; |
| 3391 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3392 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3393 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3394 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3395 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3396 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3397 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3398 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3399 | /* The version 1 structs are visible. */ |
| 3400 | enum ec_temp_thresholds { |
| 3401 | EC_TEMP_THRESH_WARN = 0, |
| 3402 | EC_TEMP_THRESH_HIGH, |
| 3403 | EC_TEMP_THRESH_HALT, |
| 3404 | |
| 3405 | EC_TEMP_THRESH_COUNT |
| 3406 | }; |
| 3407 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3408 | /* |
| 3409 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3410 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3411 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3412 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3413 | * hysteresis. |
| 3414 | * For example, |
| 3415 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3416 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3417 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3418 | * temperature <= 299 K. |
| 3419 | * |
| 3420 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3421 | * For example, |
| 3422 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3423 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3424 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3425 | * temperature <= 294 K. |
| 3426 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3427 | * Note that this structure is a sub-structure of |
| 3428 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3429 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3430 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3431 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3432 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3433 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3434 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3435 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3436 | |
| 3437 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3438 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3439 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3440 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3441 | /* This returns a struct ec_thermal_config */ |
| 3442 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3443 | /* |
| 3444 | * Version 1 - set config for one sensor. |
| 3445 | * Use read-modify-write for best results! |
| 3446 | */ |
| 3447 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3448 | uint32_t sensor_num; |
| 3449 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3450 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3451 | /* This returns no data */ |
| 3452 | |
| 3453 | /****************************************************************************/ |
| 3454 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3455 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3456 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3457 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3458 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3459 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3460 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3461 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3462 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3463 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3464 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3465 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3466 | |
| 3467 | /* |
| 3468 | * The original TMP006 calibration only needed four params, but now we need |
| 3469 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3470 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3471 | * and how many params it requires. That way we can change the EC code without |
| 3472 | * needing to update this file. We can also use a different algorithm on each |
| 3473 | * sensor. |
| 3474 | */ |
| 3475 | |
| 3476 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3477 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3478 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3479 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3480 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3481 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3482 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3483 | float s0; |
| 3484 | float b0; |
| 3485 | float b1; |
| 3486 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3487 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3488 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3489 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3490 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3491 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3492 | float s0; |
| 3493 | float b0; |
| 3494 | float b1; |
| 3495 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3496 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3497 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3498 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3499 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3500 | uint8_t algorithm; |
| 3501 | uint8_t num_params; |
| 3502 | uint8_t reserved[2]; |
| 3503 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3504 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3505 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3506 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3507 | uint8_t index; |
| 3508 | uint8_t algorithm; |
| 3509 | uint8_t num_params; |
| 3510 | uint8_t reserved; |
| 3511 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3512 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3513 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3514 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3515 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3516 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3517 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3518 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3519 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3520 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3521 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3522 | struct ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3523 | int32_t t; /* In 1/100 K */ |
| 3524 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3525 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3526 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3527 | /*****************************************************************************/ |
| 3528 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3529 | |
| 3530 | /* |
| 3531 | * Read key state |
| 3532 | * |
| 3533 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3534 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3535 | * |
| 3536 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3537 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3538 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3539 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3540 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3541 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3542 | /* |
| 3543 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3544 | */ |
| 3545 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3546 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3547 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3548 | uint32_t rows; |
| 3549 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3550 | /* Formerly "switches", which was 0. */ |
| 3551 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3552 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3553 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3554 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3555 | uint8_t info_type; |
| 3556 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3557 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3558 | |
| 3559 | enum ec_mkbp_info_type { |
| 3560 | /* |
| 3561 | * Info about the keyboard matrix: number of rows and columns. |
| 3562 | * |
| 3563 | * Returns struct ec_response_mkbp_info. |
| 3564 | */ |
| 3565 | EC_MKBP_INFO_KBD = 0, |
| 3566 | |
| 3567 | /* |
| 3568 | * For buttons and switches, info about which specifically are |
| 3569 | * supported. event_type must be set to one of the values in enum |
| 3570 | * ec_mkbp_event. |
| 3571 | * |
| 3572 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3573 | * bitmask indicating which buttons or switches are present. See the |
| 3574 | * bit inidices below. |
| 3575 | */ |
| 3576 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3577 | |
| 3578 | /* |
| 3579 | * Instantaneous state of buttons and switches. |
| 3580 | * |
| 3581 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3582 | * |
| 3583 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3584 | * indicating the current state of the keyboard matrix. |
| 3585 | * |
| 3586 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3587 | * event state. |
| 3588 | * |
| 3589 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3590 | * state of supported buttons. |
| 3591 | * |
| 3592 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3593 | * state of supported switches. |
| 3594 | */ |
| 3595 | EC_MKBP_INFO_CURRENT = 2, |
| 3596 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3597 | |
| 3598 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3599 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3600 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3601 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3602 | uint8_t col; |
| 3603 | uint8_t row; |
| 3604 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3605 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3606 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3607 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3608 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3609 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3610 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3611 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3612 | |
| 3613 | enum keyboard_id { |
| 3614 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3615 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3616 | }; |
| 3617 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3618 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3619 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3620 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3621 | |
| 3622 | /* flags */ |
| 3623 | enum mkbp_config_flags { |
| 3624 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 3625 | }; |
| 3626 | |
| 3627 | enum mkbp_config_valid { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3628 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3629 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3630 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3631 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3632 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3633 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3634 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3635 | }; |
| 3636 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3637 | /* |
| 3638 | * Configuration for our key scanning algorithm. |
| 3639 | * |
| 3640 | * Note that this is used as a sub-structure of |
| 3641 | * ec_{params/response}_mkbp_get_config. |
| 3642 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3643 | struct ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3644 | uint32_t valid_mask; /* valid fields */ |
| 3645 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3646 | uint8_t valid_flags; /* which flags are valid */ |
| 3647 | uint16_t scan_period_us; /* period between start of scans */ |
| 3648 | /* revert to interrupt mode after no activity for this long */ |
| 3649 | uint32_t poll_timeout_us; |
| 3650 | /* |
| 3651 | * minimum post-scan relax time. Once we finish a scan we check |
| 3652 | * the time until we are due to start the next one. If this time is |
| 3653 | * shorter this field, we use this instead. |
| 3654 | */ |
| 3655 | uint16_t min_post_scan_delay_us; |
| 3656 | /* delay between setting up output and waiting for it to settle */ |
| 3657 | uint16_t output_settle_us; |
| 3658 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3659 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 3660 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3661 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3662 | } __ec_align_size1; |
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_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3665 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3666 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3667 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3668 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3669 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3670 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3671 | |
| 3672 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3673 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3674 | |
| 3675 | enum ec_keyscan_seq_cmd { |
| 3676 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3677 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3678 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3679 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3680 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 3681 | }; |
| 3682 | |
| 3683 | enum ec_collect_flags { |
| 3684 | /* |
| 3685 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3686 | * scans may be skipped. |
| 3687 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3688 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3689 | }; |
| 3690 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3691 | struct ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3692 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3693 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3694 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3695 | struct ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3696 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 3697 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3698 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3699 | uint8_t active; /* still active */ |
| 3700 | uint8_t num_items; /* number of items */ |
| 3701 | /* Current item being presented */ |
| 3702 | uint8_t cur_item; |
| 3703 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3704 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3705 | /* |
| 3706 | * Absolute time for this scan, measured from the |
| 3707 | * start of the sequence. |
| 3708 | */ |
| 3709 | uint32_t time_us; |
| 3710 | uint8_t scan[0]; /* keyscan data */ |
| 3711 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3712 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3713 | uint8_t start_item; /* First item to return */ |
| 3714 | uint8_t num_items; /* Number of items to return */ |
| 3715 | } collect; |
| 3716 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3717 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3718 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3719 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3720 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3721 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3722 | uint8_t num_items; /* Number of items */ |
| 3723 | /* Data for each item */ |
| 3724 | struct ec_collect_item item[0]; |
| 3725 | } collect; |
| 3726 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3727 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3728 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3729 | /* |
| 3730 | * Get the next pending MKBP event. |
| 3731 | * |
| 3732 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3733 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3734 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3735 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3736 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3737 | |
| 3738 | /* |
| 3739 | * We use the most significant bit of the event type to indicate to the host |
| 3740 | * that the EC has more MKBP events available to provide. |
| 3741 | */ |
| 3742 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3743 | |
| 3744 | /* The mask to apply to get the raw event type */ |
| 3745 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3746 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3747 | enum ec_mkbp_event { |
| 3748 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3749 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3750 | |
| 3751 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3752 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3753 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3754 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3755 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3756 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3757 | /* The state of the non-matrixed buttons have changed. */ |
| 3758 | EC_MKBP_EVENT_BUTTON = 3, |
| 3759 | |
| 3760 | /* The state of the switches have changed. */ |
| 3761 | EC_MKBP_EVENT_SWITCH = 4, |
| 3762 | |
| 3763 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3764 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3765 | |
| 3766 | /* |
| 3767 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3768 | * corresponding to the key to be pressed. |
| 3769 | */ |
| 3770 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3771 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3772 | /* |
| 3773 | * New 64-bit host event. |
| 3774 | * The event data is 8 bytes of host event flags. |
| 3775 | */ |
| 3776 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3777 | |
| 3778 | /* Notify the AP that something happened on CEC */ |
| 3779 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3780 | |
| 3781 | /* Send an incoming CEC message to the AP */ |
| 3782 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3784 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3785 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3786 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3787 | /* New online calibration values are available. */ |
| 3788 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3789 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 3790 | /* Peripheral device charger event */ |
| 3791 | EC_MKBP_EVENT_PCHG = 12, |
| 3792 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3793 | /* Number of MKBP events */ |
| 3794 | EC_MKBP_EVENT_COUNT, |
| 3795 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3796 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3797 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3798 | union __ec_align_offset1 ec_response_get_next_data { |
| 3799 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3800 | |
| 3801 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3802 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3803 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3804 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3805 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3806 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3807 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3808 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3809 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3810 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3811 | uint32_t buttons; |
| 3812 | |
| 3813 | uint32_t switches; |
| 3814 | |
| 3815 | uint32_t fp_events; |
| 3816 | |
| 3817 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3818 | |
| 3819 | /* CEC events from enum mkbp_cec_event */ |
| 3820 | uint32_t cec_events; |
| 3821 | }; |
| 3822 | |
| 3823 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3824 | uint8_t key_matrix[16]; |
| 3825 | |
| 3826 | /* Unaligned */ |
| 3827 | uint32_t host_event; |
| 3828 | uint64_t host_event64; |
| 3829 | |
| 3830 | struct __ec_todo_unpacked { |
| 3831 | /* For aligning the fifo_info */ |
| 3832 | uint8_t reserved[3]; |
| 3833 | struct ec_response_motion_sense_fifo_info info; |
| 3834 | } sensor_fifo; |
| 3835 | |
| 3836 | uint32_t buttons; |
| 3837 | |
| 3838 | uint32_t switches; |
| 3839 | |
| 3840 | uint32_t fp_events; |
| 3841 | |
| 3842 | uint32_t sysrq; |
| 3843 | |
| 3844 | /* CEC events from enum mkbp_cec_event */ |
| 3845 | uint32_t cec_events; |
| 3846 | |
| 3847 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3848 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3849 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3850 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3851 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3852 | uint8_t event_type; |
| 3853 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3854 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3855 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3856 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3857 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3858 | uint8_t event_type; |
| 3859 | /* Followed by event data if any */ |
| 3860 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3861 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3862 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3863 | /* Bit indices for buttons and switches.*/ |
| 3864 | /* Buttons */ |
| 3865 | #define EC_MKBP_POWER_BUTTON 0 |
| 3866 | #define EC_MKBP_VOL_UP 1 |
| 3867 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 3868 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3869 | |
| 3870 | /* Switches */ |
| 3871 | #define EC_MKBP_LID_OPEN 0 |
| 3872 | #define EC_MKBP_TABLET_MODE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3873 | #define EC_MKBP_BASE_ATTACHED 2 |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3874 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3875 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3876 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3877 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3878 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3879 | struct ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3880 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3881 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3882 | |
| 3883 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3884 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3885 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) |
| 3886 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
| 3887 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ |
| 3888 | >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
| 3889 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 3890 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
| 3891 | #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ |
| 3892 | >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3893 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 3894 | #define EC_MKBP_FP_MATCH BIT(28) |
| 3895 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 3896 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 3897 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3898 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
| 3899 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 3900 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 3901 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 3902 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 3903 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
| 3904 | /* Can be used to detect if image was usable for enrollment or not. */ |
| 3905 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
| 3906 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
| 3907 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 3908 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3909 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3910 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 3911 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 3912 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 3913 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
| 3914 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 3915 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3916 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3917 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 3918 | enum ec_mkbp_event_mask_action { |
| 3919 | /* Retrieve the value of a wake mask. */ |
| 3920 | GET_WAKE_MASK = 0, |
| 3921 | |
| 3922 | /* Set the value of a wake mask. */ |
| 3923 | SET_WAKE_MASK, |
| 3924 | }; |
| 3925 | |
| 3926 | enum ec_mkbp_mask_type { |
| 3927 | /* |
| 3928 | * These are host events sent via MKBP. |
| 3929 | * |
| 3930 | * Some examples are: |
| 3931 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 3932 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 3933 | * |
| 3934 | * The only things that should be in this mask are: |
| 3935 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 3936 | */ |
| 3937 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 3938 | |
| 3939 | /* |
| 3940 | * These are MKBP events. Some examples are: |
| 3941 | * |
| 3942 | * EC_MKBP_EVENT_KEY_MATRIX |
| 3943 | * EC_MKBP_EVENT_SWITCH |
| 3944 | * |
| 3945 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 3946 | */ |
| 3947 | EC_MKBP_EVENT_WAKE_MASK, |
| 3948 | }; |
| 3949 | |
| 3950 | struct ec_params_mkbp_event_wake_mask { |
| 3951 | /* One of enum ec_mkbp_event_mask_action */ |
| 3952 | uint8_t action; |
| 3953 | |
| 3954 | /* |
| 3955 | * Which MKBP mask are you interested in acting upon? This is one of |
| 3956 | * ec_mkbp_mask_type. |
| 3957 | */ |
| 3958 | uint8_t mask_type; |
| 3959 | |
| 3960 | /* If setting a new wake mask, this contains the mask to set. */ |
| 3961 | uint32_t new_wake_mask; |
| 3962 | }; |
| 3963 | |
| 3964 | struct ec_response_mkbp_event_wake_mask { |
| 3965 | uint32_t wake_mask; |
| 3966 | }; |
| 3967 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3968 | /*****************************************************************************/ |
| 3969 | /* Temperature sensor commands */ |
| 3970 | |
| 3971 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3972 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3973 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3974 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3975 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3976 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3977 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3978 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3979 | char sensor_name[32]; |
| 3980 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3981 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3982 | |
| 3983 | /*****************************************************************************/ |
| 3984 | |
| 3985 | /* |
| 3986 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 3987 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 3988 | * below. |
| 3989 | */ |
| 3990 | |
| 3991 | /*****************************************************************************/ |
| 3992 | /* Host event commands */ |
| 3993 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3994 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3995 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3996 | /* |
| 3997 | * Host event mask params and response structures, shared by all of the host |
| 3998 | * event commands below. |
| 3999 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4000 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4001 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4002 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4003 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4004 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4005 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4006 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4007 | |
| 4008 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4009 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 4010 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 4011 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 4012 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4013 | |
| 4014 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4015 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 4016 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 4017 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 4018 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 4019 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4020 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4021 | /* |
| 4022 | * Unified host event programming interface - Should be used by newer versions |
| 4023 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4024 | * |
| 4025 | * EC returns: |
| 4026 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 4027 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4028 | */ |
| 4029 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4030 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4031 | |
| 4032 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 4033 | uint8_t action; |
| 4034 | |
| 4035 | /* |
| 4036 | * Mask type that the host requested the action on - one of |
| 4037 | * enum ec_host_event_mask_type. |
| 4038 | */ |
| 4039 | uint8_t mask_type; |
| 4040 | |
| 4041 | /* Set to 0, ignore on read */ |
| 4042 | uint16_t reserved; |
| 4043 | |
| 4044 | /* Value to be used in case of set operations. */ |
| 4045 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4046 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4047 | |
| 4048 | /* |
| 4049 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 4050 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 4051 | */ |
| 4052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4053 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4054 | |
| 4055 | /* Mask value in case of get operation */ |
| 4056 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4057 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4058 | |
| 4059 | enum ec_host_event_action { |
| 4060 | /* |
| 4061 | * params.value is ignored. Value of mask_type populated |
| 4062 | * in response.value |
| 4063 | */ |
| 4064 | EC_HOST_EVENT_GET, |
| 4065 | |
| 4066 | /* Bits in params.value are set */ |
| 4067 | EC_HOST_EVENT_SET, |
| 4068 | |
| 4069 | /* Bits in params.value are cleared */ |
| 4070 | EC_HOST_EVENT_CLEAR, |
| 4071 | }; |
| 4072 | |
| 4073 | enum ec_host_event_mask_type { |
| 4074 | |
| 4075 | /* Main host event copy */ |
| 4076 | EC_HOST_EVENT_MAIN, |
| 4077 | |
| 4078 | /* Copy B of host events */ |
| 4079 | EC_HOST_EVENT_B, |
| 4080 | |
| 4081 | /* SCI Mask */ |
| 4082 | EC_HOST_EVENT_SCI_MASK, |
| 4083 | |
| 4084 | /* SMI Mask */ |
| 4085 | EC_HOST_EVENT_SMI_MASK, |
| 4086 | |
| 4087 | /* Mask of events that should be always reported in hostevents */ |
| 4088 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4089 | |
| 4090 | /* Active wake mask */ |
| 4091 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4092 | |
| 4093 | /* Lazy wake mask for S0ix */ |
| 4094 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4095 | |
| 4096 | /* Lazy wake mask for S3 */ |
| 4097 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4098 | |
| 4099 | /* Lazy wake mask for S5 */ |
| 4100 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4101 | }; |
| 4102 | |
| 4103 | #define EC_CMD_HOST_EVENT 0x00A4 |
| 4104 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4105 | /*****************************************************************************/ |
| 4106 | /* Switch commands */ |
| 4107 | |
| 4108 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4109 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4110 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4111 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4112 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4113 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4114 | |
| 4115 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4116 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4117 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4118 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4119 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4120 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4121 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4122 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4123 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4124 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4125 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4126 | /* Flags to enable now */ |
| 4127 | uint8_t now_flags; |
| 4128 | |
| 4129 | /* Which flags to copy from now_flags */ |
| 4130 | uint8_t now_mask; |
| 4131 | |
| 4132 | /* |
| 4133 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4134 | * transition. (Other flags will be disabled by the S0->S3 |
| 4135 | * transition.) |
| 4136 | */ |
| 4137 | uint8_t suspend_flags; |
| 4138 | |
| 4139 | /* Which flags to copy from suspend_flags */ |
| 4140 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4141 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4142 | |
| 4143 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4144 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4145 | /* Flags to enable now */ |
| 4146 | uint8_t now_flags; |
| 4147 | |
| 4148 | /* Flags to leave enabled in S3 */ |
| 4149 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4150 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4151 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4152 | /*****************************************************************************/ |
| 4153 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4154 | |
| 4155 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4156 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4157 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4158 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4159 | char name[32]; |
| 4160 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4161 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4162 | |
| 4163 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4164 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4165 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4166 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4167 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4168 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4169 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4170 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4171 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4172 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4173 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4174 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4175 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4176 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4177 | uint8_t subcmd; |
| 4178 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4179 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4180 | char name[32]; |
| 4181 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4182 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4183 | uint8_t index; |
| 4184 | } get_info; |
| 4185 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4186 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4187 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4188 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4189 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4190 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4191 | uint8_t val; |
| 4192 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4193 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4194 | uint8_t val; |
| 4195 | char name[32]; |
| 4196 | uint32_t flags; |
| 4197 | } get_info; |
| 4198 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4199 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4200 | |
| 4201 | enum gpio_get_subcmd { |
| 4202 | EC_GPIO_GET_BY_NAME = 0, |
| 4203 | EC_GPIO_GET_COUNT = 1, |
| 4204 | EC_GPIO_GET_INFO = 2, |
| 4205 | }; |
| 4206 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4207 | /*****************************************************************************/ |
| 4208 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4209 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4210 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4211 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4212 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4213 | * |
| 4214 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4215 | */ |
| 4216 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4217 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4218 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4219 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4220 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4221 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4222 | uint8_t read_size; /* Either 8 or 16. */ |
| 4223 | uint8_t port; |
| 4224 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4225 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4226 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4227 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4228 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4229 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4230 | |
| 4231 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4232 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4233 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4234 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4235 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4236 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4237 | uint8_t write_size; /* Either 8 or 16. */ |
| 4238 | uint8_t port; |
| 4239 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4240 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4241 | |
| 4242 | /*****************************************************************************/ |
| 4243 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4244 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4245 | /* Force charge state machine to stop charging the battery or force it to |
| 4246 | * discharge the battery. |
| 4247 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4248 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4249 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4250 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4251 | enum ec_charge_control_mode { |
| 4252 | CHARGE_CONTROL_NORMAL = 0, |
| 4253 | CHARGE_CONTROL_IDLE, |
| 4254 | CHARGE_CONTROL_DISCHARGE, |
| 4255 | }; |
| 4256 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4257 | struct ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4258 | uint32_t mode; /* enum charge_control_mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4259 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4260 | |
| 4261 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4262 | |
| 4263 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4264 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4265 | |
| 4266 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4267 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4268 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4269 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4270 | * end of the previous snapshot. |
| 4271 | * |
| 4272 | * The params are only looked at in version >= 1 of this command. Prior |
| 4273 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4274 | * |
| 4275 | * Response is null-terminated string. Empty string, if there is no more |
| 4276 | * remaining output. |
| 4277 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4278 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4279 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4280 | enum ec_console_read_subcmd { |
| 4281 | CONSOLE_READ_NEXT = 0, |
| 4282 | CONSOLE_READ_RECENT |
| 4283 | }; |
| 4284 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4285 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4286 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4287 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4288 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4289 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4290 | |
| 4291 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4292 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4293 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4294 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4295 | * EC_RES_SUCCESS if the command was successful. |
| 4296 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4297 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4298 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4299 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4300 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4301 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4302 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4303 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4304 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4305 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4306 | /*****************************************************************************/ |
| 4307 | /* USB port mux control. */ |
| 4308 | |
| 4309 | /* |
| 4310 | * Switch USB mux or return to automatic switching. |
| 4311 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4312 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4313 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4314 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4315 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4316 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4317 | |
| 4318 | /*****************************************************************************/ |
| 4319 | /* LDOs / FETs control. */ |
| 4320 | |
| 4321 | enum ec_ldo_state { |
| 4322 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4323 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 4324 | }; |
| 4325 | |
| 4326 | /* |
| 4327 | * Switch on/off a LDO. |
| 4328 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4329 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4330 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4331 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4332 | uint8_t index; |
| 4333 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4334 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4335 | |
| 4336 | /* |
| 4337 | * Get LDO state. |
| 4338 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4339 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4340 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4341 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4342 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4343 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4344 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4345 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4346 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4347 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4348 | |
| 4349 | /*****************************************************************************/ |
| 4350 | /* Power info. */ |
| 4351 | |
| 4352 | /* |
| 4353 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4354 | * |
| 4355 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4356 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4357 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4358 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4359 | /* |
| 4360 | * v1 of EC_CMD_POWER_INFO |
| 4361 | */ |
| 4362 | enum system_power_source { |
| 4363 | /* |
| 4364 | * Haven't established which power source is used yet, |
| 4365 | * or no presence signals are available |
| 4366 | */ |
| 4367 | POWER_SOURCE_UNKNOWN = 0, |
| 4368 | /* System is running on battery alone */ |
| 4369 | POWER_SOURCE_BATTERY = 1, |
| 4370 | /* System is running on A/C alone */ |
| 4371 | POWER_SOURCE_AC = 2, |
| 4372 | /* System is running on A/C and battery */ |
| 4373 | POWER_SOURCE_AC_BATTERY = 3, |
| 4374 | }; |
| 4375 | |
| 4376 | struct ec_response_power_info_v1 { |
| 4377 | /* enum system_power_source */ |
| 4378 | uint8_t system_power_source; |
| 4379 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4380 | uint8_t battery_soc; |
| 4381 | /* AC Adapter 100% rating, Watts */ |
| 4382 | uint8_t ac_adapter_100pct; |
| 4383 | /* AC Adapter 10ms rating, Watts */ |
| 4384 | uint8_t ac_adapter_10ms; |
| 4385 | /* Battery 1C rating, derated */ |
| 4386 | uint8_t battery_1cd; |
| 4387 | /* Rest of Platform average, Watts */ |
| 4388 | uint8_t rop_avg; |
| 4389 | /* Rest of Platform peak, Watts */ |
| 4390 | uint8_t rop_peak; |
| 4391 | /* Nominal charger efficiency, % */ |
| 4392 | uint8_t nominal_charger_eff; |
| 4393 | /* Rest of Platform VR Average Efficiency, % */ |
| 4394 | uint8_t rop_avg_eff; |
| 4395 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4396 | uint8_t rop_peak_eff; |
| 4397 | /* SoC VR Efficiency at Average level, % */ |
| 4398 | uint8_t soc_avg_eff; |
| 4399 | /* SoC VR Efficiency at Peak level, % */ |
| 4400 | uint8_t soc_peak_eff; |
| 4401 | /* Intel-specific items */ |
| 4402 | struct { |
| 4403 | /* Battery's level of DBPT support: 0, 2 */ |
| 4404 | uint8_t batt_dbpt_support_level; |
| 4405 | /* |
| 4406 | * Maximum peak power from battery (10ms), Watts |
| 4407 | * If DBPT is not supported, this is 0 |
| 4408 | */ |
| 4409 | uint8_t batt_dbpt_max_peak_power; |
| 4410 | /* |
| 4411 | * Sustained peak power from battery, Watts |
| 4412 | * If DBPT is not supported, this is 0 |
| 4413 | */ |
| 4414 | uint8_t batt_dbpt_sus_peak_power; |
| 4415 | } intel; |
| 4416 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4417 | |
| 4418 | /*****************************************************************************/ |
| 4419 | /* I2C passthru command */ |
| 4420 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4421 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4422 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4423 | /* Read data; if not present, message is a write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4424 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4425 | |
| 4426 | /* Mask for address */ |
| 4427 | #define EC_I2C_ADDR_MASK 0x3ff |
| 4428 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4429 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4430 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4431 | |
| 4432 | /* Any error */ |
| 4433 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 4434 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4435 | struct ec_params_i2c_passthru_msg { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 4436 | uint16_t addr_flags; /* I2C peripheral address and flags */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4437 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4438 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4439 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4440 | struct ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4441 | uint8_t port; /* I2C port number */ |
| 4442 | uint8_t num_msgs; /* Number of messages */ |
| 4443 | struct ec_params_i2c_passthru_msg msg[]; |
| 4444 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4445 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4446 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4447 | struct ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4448 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4449 | uint8_t num_msgs; /* Number of messages processed */ |
| 4450 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4451 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4452 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4453 | /*****************************************************************************/ |
| 4454 | /* Power button hang detect */ |
| 4455 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4456 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4457 | |
| 4458 | /* Reasons to start hang detection timer */ |
| 4459 | /* Power button pressed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4460 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4461 | |
| 4462 | /* Lid closed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4463 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4464 | |
| 4465 | /* Lid opened */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4466 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4467 | |
| 4468 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4469 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4470 | |
| 4471 | /* Reasons to cancel hang detection */ |
| 4472 | |
| 4473 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4474 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4475 | |
| 4476 | /* Any host command from AP received */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4477 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4478 | |
| 4479 | /* 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] | 4480 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4481 | |
| 4482 | /* |
| 4483 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4484 | * timer is started. This provides the AP a way to start the hang timer |
| 4485 | * without reconfiguring any of the other hang detect settings. Note that |
| 4486 | * you must previously have configured the timeouts. |
| 4487 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4488 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4489 | |
| 4490 | /* |
| 4491 | * If this flag is set, all the other fields are ignored (including |
| 4492 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4493 | * without reconfiguring any of the other hang detect settings. |
| 4494 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4495 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4496 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4497 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4498 | /* Flags; see EC_HANG_* */ |
| 4499 | uint32_t flags; |
| 4500 | |
| 4501 | /* Timeout in msec before generating host event, if enabled */ |
| 4502 | uint16_t host_event_timeout_msec; |
| 4503 | |
| 4504 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4505 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4506 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4507 | |
| 4508 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4509 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4510 | |
| 4511 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4512 | * This is the single catch-all host command to exchange data regarding the |
| 4513 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4514 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4515 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4516 | |
| 4517 | /* Subcommands for this host command */ |
| 4518 | enum charge_state_command { |
| 4519 | CHARGE_STATE_CMD_GET_STATE, |
| 4520 | CHARGE_STATE_CMD_GET_PARAM, |
| 4521 | CHARGE_STATE_CMD_SET_PARAM, |
| 4522 | CHARGE_STATE_NUM_CMDS |
| 4523 | }; |
| 4524 | |
| 4525 | /* |
| 4526 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4527 | * params, which are handled by the particular implementations. |
| 4528 | */ |
| 4529 | enum charge_state_params { |
| 4530 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 4531 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 4532 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 4533 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 4534 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4535 | CS_PARAM_LIMIT_POWER, /* |
| 4536 | * Check if power is limited due to |
| 4537 | * low battery and / or a weak external |
| 4538 | * charger. READ ONLY. |
| 4539 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4540 | /* How many so far? */ |
| 4541 | CS_NUM_BASE_PARAMS, |
| 4542 | |
| 4543 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4544 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4545 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4546 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4547 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4548 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4549 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4550 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4551 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4552 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4553 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4554 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4555 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4556 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4557 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4558 | /* Other custom param ranges go here... */ |
| 4559 | }; |
| 4560 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4561 | struct ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4562 | uint8_t cmd; /* enum charge_state_command */ |
| 4563 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4564 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4565 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4566 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4567 | uint32_t param; /* enum charge_state_param */ |
| 4568 | } get_param; |
| 4569 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4570 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4571 | uint32_t param; /* param to set */ |
| 4572 | uint32_t value; /* value to set */ |
| 4573 | } set_param; |
| 4574 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 4575 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4576 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4577 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4578 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4579 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4580 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4581 | int ac; |
| 4582 | int chg_voltage; |
| 4583 | int chg_current; |
| 4584 | int chg_input_current; |
| 4585 | int batt_state_of_charge; |
| 4586 | } get_state; |
| 4587 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4588 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4589 | uint32_t value; |
| 4590 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4591 | |
| 4592 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4593 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4594 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4595 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4596 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4597 | /* |
| 4598 | * Set maximum battery charging current. |
| 4599 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4600 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4601 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4602 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4603 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4604 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4605 | |
| 4606 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4607 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4608 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4609 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4610 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4611 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4612 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4613 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4614 | 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] | 4615 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4616 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4617 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4618 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4619 | /* |
| 4620 | * Set maximum voltage & current of a dedicated charge port |
| 4621 | */ |
| 4622 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4623 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4624 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4625 | uint16_t current_lim; /* in mA */ |
| 4626 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4627 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4628 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4629 | /*****************************************************************************/ |
| 4630 | /* Hibernate/Deep Sleep Commands */ |
| 4631 | |
| 4632 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4633 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4634 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4635 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4636 | /* |
| 4637 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4638 | * current settings without changing them. |
| 4639 | */ |
| 4640 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4641 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4642 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4643 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4644 | /* |
| 4645 | * The current time in seconds in which the system has been in the G3 |
| 4646 | * state. This value is reset if the EC transitions out of G3. |
| 4647 | */ |
| 4648 | uint32_t time_g3; |
| 4649 | |
| 4650 | /* |
| 4651 | * The current time remaining in seconds until the EC should hibernate. |
| 4652 | * This value is also reset if the EC transitions out of G3. |
| 4653 | */ |
| 4654 | uint32_t time_remaining; |
| 4655 | |
| 4656 | /* |
| 4657 | * The current time in seconds that the EC should wait in G3 before |
| 4658 | * hibernating. |
| 4659 | */ |
| 4660 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4661 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4662 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4663 | /* Inform the EC when entering a sleep state */ |
| 4664 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4665 | |
| 4666 | enum host_sleep_event { |
| 4667 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4668 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 4669 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4670 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
| 4671 | /* S3 suspend with additional enabled wake sources */ |
| 4672 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4673 | }; |
| 4674 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4675 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4676 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4677 | } __ec_align1; |
| 4678 | |
| 4679 | /* |
| 4680 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4681 | * transition failures |
| 4682 | */ |
| 4683 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4684 | |
| 4685 | /* Disable timeout detection for this sleep transition */ |
| 4686 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4687 | |
| 4688 | struct ec_params_host_sleep_event_v1 { |
| 4689 | /* The type of sleep being entered or exited. */ |
| 4690 | uint8_t sleep_event; |
| 4691 | |
| 4692 | /* Padding */ |
| 4693 | uint8_t reserved; |
| 4694 | union { |
| 4695 | /* Parameters that apply for suspend messages. */ |
| 4696 | struct { |
| 4697 | /* |
| 4698 | * The timeout in milliseconds between when this message |
| 4699 | * is received and when the EC will declare sleep |
| 4700 | * transition failure if the sleep signal is not |
| 4701 | * asserted. |
| 4702 | */ |
| 4703 | uint16_t sleep_timeout_ms; |
| 4704 | } suspend_params; |
| 4705 | |
| 4706 | /* No parameters for non-suspend messages. */ |
| 4707 | }; |
| 4708 | } __ec_align2; |
| 4709 | |
| 4710 | /* A timeout occurred when this bit is set */ |
| 4711 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4712 | |
| 4713 | /* |
| 4714 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4715 | * as well as the maximum number of suspend line transitions that will be |
| 4716 | * reported back to the host. |
| 4717 | */ |
| 4718 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4719 | |
| 4720 | struct ec_response_host_sleep_event_v1 { |
| 4721 | union { |
| 4722 | /* Response fields that apply for resume messages. */ |
| 4723 | struct { |
| 4724 | /* |
| 4725 | * The number of sleep power signal transitions that |
| 4726 | * occurred since the suspend message. The high bit |
| 4727 | * indicates a timeout occurred. |
| 4728 | */ |
| 4729 | uint32_t sleep_transitions; |
| 4730 | } resume_response; |
| 4731 | |
| 4732 | /* No response fields for non-resume messages. */ |
| 4733 | }; |
| 4734 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4735 | |
| 4736 | /*****************************************************************************/ |
| 4737 | /* Device events */ |
| 4738 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4739 | |
| 4740 | enum ec_device_event { |
| 4741 | EC_DEVICE_EVENT_TRACKPAD, |
| 4742 | EC_DEVICE_EVENT_DSP, |
| 4743 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 4744 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4745 | }; |
| 4746 | |
| 4747 | enum ec_device_event_param { |
| 4748 | /* Get and clear pending device events */ |
| 4749 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4750 | /* Get device event mask */ |
| 4751 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4752 | /* Set device event mask */ |
| 4753 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4754 | }; |
| 4755 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4756 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4757 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4758 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4759 | uint32_t event_mask; |
| 4760 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4761 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4762 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4763 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4764 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4765 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4766 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4767 | /*****************************************************************************/ |
| 4768 | /* Smart battery pass-through */ |
| 4769 | |
| 4770 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4771 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4772 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4773 | |
| 4774 | /* Get / Set string smart battery parameters |
| 4775 | * formatted as SMBUS "block". |
| 4776 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4777 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 4778 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4779 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4780 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4781 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4782 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4784 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4785 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4786 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4787 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4788 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4789 | uint8_t reg; |
| 4790 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4791 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4792 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4793 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4794 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4795 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4796 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4797 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4798 | uint8_t reg; |
| 4799 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4800 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4801 | |
| 4802 | /*****************************************************************************/ |
| 4803 | /* Battery vendor parameters |
| 4804 | * |
| 4805 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 4806 | * differ between boards or batteries. On a set operation, the response |
| 4807 | * contains the actual value set, which may be rounded or clipped from the |
| 4808 | * requested value. |
| 4809 | */ |
| 4810 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4811 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4812 | |
| 4813 | enum ec_battery_vendor_param_mode { |
| 4814 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 4815 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 4816 | }; |
| 4817 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4818 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4819 | uint32_t param; |
| 4820 | uint32_t value; |
| 4821 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4822 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4823 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4824 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4825 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4826 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4827 | |
| 4828 | /*****************************************************************************/ |
| 4829 | /* |
| 4830 | * Smart Battery Firmware Update Commands |
| 4831 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4832 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4833 | |
| 4834 | enum ec_sb_fw_update_subcmd { |
| 4835 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 4836 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 4837 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 4838 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 4839 | EC_SB_FW_UPDATE_END = 0x4, |
| 4840 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 4841 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 4842 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 4843 | }; |
| 4844 | |
| 4845 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 4846 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 4847 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 4848 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4849 | struct ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4850 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 4851 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4852 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4853 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4854 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4855 | struct ec_sb_fw_update_header hdr; |
| 4856 | union { |
| 4857 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 4858 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 4859 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 4860 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 4861 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 4862 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4863 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4864 | |
| 4865 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4866 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4867 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 4868 | } write; |
| 4869 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4870 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4871 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4872 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4873 | union { |
| 4874 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4875 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4876 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 4877 | } info; |
| 4878 | |
| 4879 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4880 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4881 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 4882 | } status; |
| 4883 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4884 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4885 | |
| 4886 | /* |
| 4887 | * Entering Verified Boot Mode Command |
| 4888 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 4889 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4890 | * |
| 4891 | * EC no longer needs to know what mode vboot has entered, |
| 4892 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4893 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4894 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4895 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4896 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4897 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4898 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4899 | |
| 4900 | #define VBOOT_MODE_NORMAL 0 |
| 4901 | #define VBOOT_MODE_DEVELOPER 1 |
| 4902 | #define VBOOT_MODE_RECOVERY 2 |
| 4903 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4904 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4905 | /* |
| 4906 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 4907 | * certain addresses (board-specific). |
| 4908 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4909 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4910 | |
| 4911 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4912 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 4913 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 4914 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4915 | }; |
| 4916 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4917 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4918 | uint8_t subcmd; |
| 4919 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4920 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4921 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4922 | struct ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4923 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4924 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4925 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4926 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4927 | /*****************************************************************************/ |
| 4928 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4929 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4930 | * |
| 4931 | * These commands are for sending and receiving message via HDMI CEC |
| 4932 | */ |
| 4933 | |
| 4934 | #define MAX_CEC_MSG_LEN 16 |
| 4935 | |
| 4936 | /* CEC message from the AP to be written on the CEC bus */ |
| 4937 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 4938 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4939 | /** |
| 4940 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 4941 | * @msg: message content to write to the CEC bus |
| 4942 | */ |
| 4943 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4944 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4945 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4946 | |
| 4947 | /* Set various CEC parameters */ |
| 4948 | #define EC_CMD_CEC_SET 0x00BA |
| 4949 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4950 | /** |
| 4951 | * struct ec_params_cec_set - CEC parameters set |
| 4952 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4953 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 4954 | * or 1 to enable CEC functionality, in case cmd is |
| 4955 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 4956 | * address between 0 and 15 or 0xff to unregister |
| 4957 | */ |
| 4958 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4959 | uint8_t cmd; /* enum cec_command */ |
| 4960 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4961 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4962 | |
| 4963 | /* Read various CEC parameters */ |
| 4964 | #define EC_CMD_CEC_GET 0x00BB |
| 4965 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4966 | /** |
| 4967 | * struct ec_params_cec_get - CEC parameters get |
| 4968 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4969 | */ |
| 4970 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4971 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4972 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4973 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4974 | /** |
| 4975 | * struct ec_response_cec_get - CEC parameters get response |
| 4976 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 4977 | * disabled or 1 if CEC functionality is enabled, |
| 4978 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 4979 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 4980 | */ |
| 4981 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4982 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4983 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4984 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4985 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4986 | enum cec_command { |
| 4987 | /* CEC reading, writing and events enable */ |
| 4988 | CEC_CMD_ENABLE, |
| 4989 | /* CEC logical address */ |
| 4990 | CEC_CMD_LOGICAL_ADDRESS, |
| 4991 | }; |
| 4992 | |
| 4993 | /* Events from CEC to AP */ |
| 4994 | enum mkbp_cec_event { |
| 4995 | /* Outgoing message was acknowledged by a follower */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4996 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4997 | /* Outgoing message was not acknowledged */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4998 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4999 | }; |
| 5000 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5001 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5002 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5003 | /* Commands for audio codec. */ |
| 5004 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5005 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5006 | enum ec_codec_subcmd { |
| 5007 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 5008 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 5009 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 5010 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5011 | }; |
| 5012 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5013 | enum ec_codec_cap { |
| 5014 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 5015 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 5016 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5017 | }; |
| 5018 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5019 | enum ec_codec_shm_id { |
| 5020 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 5021 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 5022 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5023 | }; |
| 5024 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5025 | enum ec_codec_shm_type { |
| 5026 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 5027 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5028 | }; |
| 5029 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5030 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 5031 | uint8_t shm_id; |
| 5032 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5033 | }; |
| 5034 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5035 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 5036 | uint64_t phys_addr; |
| 5037 | uint32_t len; |
| 5038 | uint8_t shm_id; |
| 5039 | uint8_t reserved[3]; |
| 5040 | }; |
| 5041 | |
| 5042 | struct __ec_align4 ec_param_ec_codec { |
| 5043 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 5044 | uint8_t reserved[3]; |
| 5045 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5046 | union { |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5047 | struct ec_param_ec_codec_get_shm_addr |
| 5048 | get_shm_addr_param; |
| 5049 | struct ec_param_ec_codec_set_shm_addr |
| 5050 | set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5051 | }; |
| 5052 | }; |
| 5053 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5054 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 5055 | uint32_t capabilities; |
| 5056 | }; |
| 5057 | |
| 5058 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5059 | uint64_t phys_addr; |
| 5060 | uint32_t len; |
| 5061 | uint8_t type; |
| 5062 | uint8_t reserved[3]; |
| 5063 | }; |
| 5064 | |
| 5065 | /*****************************************************************************/ |
| 5066 | |
| 5067 | /* Commands for DMIC on audio codec. */ |
| 5068 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5069 | |
| 5070 | enum ec_codec_dmic_subcmd { |
| 5071 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5072 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5073 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5074 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5075 | }; |
| 5076 | |
| 5077 | enum ec_codec_dmic_channel { |
| 5078 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5079 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5080 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5081 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5082 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5083 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5084 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5085 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5086 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5087 | }; |
| 5088 | |
| 5089 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5090 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5091 | uint8_t gain; |
| 5092 | uint8_t reserved[2]; |
| 5093 | }; |
| 5094 | |
| 5095 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5096 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5097 | uint8_t reserved[3]; |
| 5098 | }; |
| 5099 | |
| 5100 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5101 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5102 | uint8_t reserved[3]; |
| 5103 | |
| 5104 | union { |
| 5105 | struct ec_param_ec_codec_dmic_set_gain_idx |
| 5106 | set_gain_idx_param; |
| 5107 | struct ec_param_ec_codec_dmic_get_gain_idx |
| 5108 | get_gain_idx_param; |
| 5109 | }; |
| 5110 | }; |
| 5111 | |
| 5112 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5113 | uint8_t max_gain; |
| 5114 | }; |
| 5115 | |
| 5116 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5117 | uint8_t gain; |
| 5118 | }; |
| 5119 | |
| 5120 | /*****************************************************************************/ |
| 5121 | |
| 5122 | /* Commands for I2S RX on audio codec. */ |
| 5123 | |
| 5124 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5125 | |
| 5126 | enum ec_codec_i2s_rx_subcmd { |
| 5127 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5128 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5129 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5130 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5131 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5132 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5133 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5134 | }; |
| 5135 | |
| 5136 | enum ec_codec_i2s_rx_sample_depth { |
| 5137 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5138 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5139 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5140 | }; |
| 5141 | |
| 5142 | enum ec_codec_i2s_rx_daifmt { |
| 5143 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5144 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5145 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5146 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5147 | }; |
| 5148 | |
| 5149 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5150 | uint8_t depth; |
| 5151 | uint8_t reserved[3]; |
| 5152 | }; |
| 5153 | |
| 5154 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5155 | uint8_t left; |
| 5156 | uint8_t right; |
| 5157 | uint8_t reserved[2]; |
| 5158 | }; |
| 5159 | |
| 5160 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5161 | uint8_t daifmt; |
| 5162 | uint8_t reserved[3]; |
| 5163 | }; |
| 5164 | |
| 5165 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5166 | uint32_t bclk; |
| 5167 | }; |
| 5168 | |
| 5169 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5170 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5171 | uint8_t reserved[3]; |
| 5172 | |
| 5173 | union { |
| 5174 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
| 5175 | set_sample_depth_param; |
| 5176 | struct ec_param_ec_codec_i2s_rx_set_daifmt |
| 5177 | set_daifmt_param; |
| 5178 | struct ec_param_ec_codec_i2s_rx_set_bclk |
| 5179 | set_bclk_param; |
| 5180 | }; |
| 5181 | }; |
| 5182 | |
| 5183 | /*****************************************************************************/ |
| 5184 | /* Commands for WoV on audio codec. */ |
| 5185 | |
| 5186 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5187 | |
| 5188 | enum ec_codec_wov_subcmd { |
| 5189 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5190 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5191 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5192 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5193 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5194 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5195 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5196 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5197 | }; |
| 5198 | |
| 5199 | /* |
| 5200 | * @hash is SHA256 of the whole language model. |
| 5201 | * @total_len indicates the length of whole language model. |
| 5202 | * @offset is the cursor from the beginning of the model. |
| 5203 | * @buf is the packet buffer. |
| 5204 | * @len denotes how many bytes in the buf. |
| 5205 | */ |
| 5206 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5207 | uint8_t hash[32]; |
| 5208 | uint32_t total_len; |
| 5209 | uint32_t offset; |
| 5210 | uint8_t buf[128]; |
| 5211 | uint32_t len; |
| 5212 | }; |
| 5213 | |
| 5214 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5215 | uint8_t hash[32]; |
| 5216 | uint32_t total_len; |
| 5217 | }; |
| 5218 | |
| 5219 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5220 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5221 | uint8_t reserved[3]; |
| 5222 | |
| 5223 | union { |
| 5224 | struct ec_param_ec_codec_wov_set_lang |
| 5225 | set_lang_param; |
| 5226 | struct ec_param_ec_codec_wov_set_lang_shm |
| 5227 | set_lang_shm_param; |
| 5228 | }; |
| 5229 | }; |
| 5230 | |
| 5231 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5232 | uint8_t hash[32]; |
| 5233 | }; |
| 5234 | |
| 5235 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5236 | uint8_t buf[128]; |
| 5237 | uint32_t len; |
| 5238 | }; |
| 5239 | |
| 5240 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5241 | uint32_t offset; |
| 5242 | uint32_t len; |
| 5243 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5244 | |
| 5245 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5246 | /* Commands for PoE PSE controller */ |
| 5247 | |
| 5248 | #define EC_CMD_PSE 0x00C0 |
| 5249 | |
| 5250 | enum ec_pse_subcmd { |
| 5251 | EC_PSE_STATUS = 0x0, |
| 5252 | EC_PSE_ENABLE = 0x1, |
| 5253 | EC_PSE_DISABLE = 0x2, |
| 5254 | EC_PSE_SUBCMD_COUNT, |
| 5255 | }; |
| 5256 | |
| 5257 | struct __ec_align1 ec_params_pse { |
| 5258 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5259 | uint8_t port; /* PSE port */ |
| 5260 | }; |
| 5261 | |
| 5262 | enum ec_pse_status { |
| 5263 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5264 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5265 | EC_PSE_STATUS_POWERED = 0x2, |
| 5266 | }; |
| 5267 | |
| 5268 | struct __ec_align1 ec_response_pse_status { |
| 5269 | uint8_t status; /* enum ec_pse_status */ |
| 5270 | }; |
| 5271 | |
| 5272 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5273 | /* System commands */ |
| 5274 | |
| 5275 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5276 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5277 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5278 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5279 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5280 | |
| 5281 | /* Command */ |
| 5282 | enum ec_reboot_cmd { |
| 5283 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5284 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5285 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5286 | /* (command 3 was jump to RW-B) */ |
| 5287 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5288 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
Daisuke Nojiri | 40d0bfa | 2017-11-30 17:41:09 -0800 | [diff] [blame] | 5289 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5290 | 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] | 5291 | 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] | 5292 | }; |
| 5293 | |
| 5294 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5295 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5296 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5297 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5298 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5299 | struct ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5300 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5301 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5302 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5303 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5304 | /* |
| 5305 | * Get information on last EC panic. |
| 5306 | * |
| 5307 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5308 | * for details. |
| 5309 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5310 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5311 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5312 | /*****************************************************************************/ |
| 5313 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5314 | * Special commands |
| 5315 | * |
| 5316 | * These do not follow the normal rules for commands. See each command for |
| 5317 | * details. |
| 5318 | */ |
| 5319 | |
| 5320 | /* |
| 5321 | * Reboot NOW |
| 5322 | * |
| 5323 | * This command will work even when the EC LPC interface is busy, because the |
| 5324 | * reboot command is processed at interrupt level. Note that when the EC |
| 5325 | * reboots, the host will reboot too, so there is no response to this command. |
| 5326 | * |
| 5327 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5328 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5329 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5330 | |
| 5331 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5332 | * Resend last response (not supported on LPC). |
| 5333 | * |
| 5334 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5335 | * there was no previous command, or the previous command's response was too |
| 5336 | * big to save. |
| 5337 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5338 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5339 | |
| 5340 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5341 | * This header byte on a command indicate version 0. Any header byte less |
| 5342 | * than this means that we are talking to an old EC which doesn't support |
| 5343 | * versioning. In that case, we assume version 0. |
| 5344 | * |
| 5345 | * Header bytes greater than this indicate a later version. For example, |
| 5346 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5347 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5348 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5349 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5350 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5351 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5352 | /*****************************************************************************/ |
| 5353 | /* |
| 5354 | * PD commands |
| 5355 | * |
| 5356 | * These commands are for PD MCU communication. |
| 5357 | */ |
| 5358 | |
| 5359 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5360 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5361 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5362 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5363 | enum pd_charge_state { |
| 5364 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 5365 | PD_CHARGE_NONE, /* No charging allowed */ |
| 5366 | PD_CHARGE_5V, /* 5V charging only */ |
| 5367 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 5368 | }; |
| 5369 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5370 | /* Status of EC being sent to PD */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5371 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5372 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5373 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5374 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5375 | int8_t batt_soc; /* battery state of charge */ |
| 5376 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5377 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5378 | |
| 5379 | /* Status of PD being sent back to EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5380 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5381 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
| 5382 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
| 5383 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5384 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5385 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5386 | #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] | 5387 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 5388 | PD_STATUS_TCPC_ALERT_1 | \ |
| 5389 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5390 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5391 | uint32_t curr_lim_ma; /* input current limit */ |
| 5392 | uint16_t status; /* PD MCU status */ |
| 5393 | int8_t active_charge_port; /* active charging port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5394 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5395 | |
| 5396 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5397 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5398 | |
| 5399 | /* PD MCU host event status bits */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5400 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5401 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5402 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5403 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5404 | #define PD_EVENT_TYPEC BIT(4) |
| 5405 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5406 | struct ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5407 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5408 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5409 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5410 | /* |
| 5411 | * Set USB type-C port role and muxes |
| 5412 | * |
| 5413 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5414 | * |
| 5415 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5416 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5417 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5418 | |
| 5419 | enum usb_pd_control_role { |
| 5420 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5421 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5422 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5423 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5424 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5425 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5426 | USB_PD_CTRL_ROLE_COUNT |
| 5427 | }; |
| 5428 | |
| 5429 | enum usb_pd_control_mux { |
| 5430 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5431 | USB_PD_CTRL_MUX_NONE = 1, |
| 5432 | USB_PD_CTRL_MUX_USB = 2, |
| 5433 | USB_PD_CTRL_MUX_DP = 3, |
| 5434 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5435 | USB_PD_CTRL_MUX_AUTO = 5, |
| 5436 | USB_PD_CTRL_MUX_COUNT |
| 5437 | }; |
| 5438 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5439 | enum usb_pd_control_swap { |
| 5440 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5441 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5442 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5443 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 5444 | USB_PD_CTRL_SWAP_COUNT |
| 5445 | }; |
| 5446 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5447 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5448 | uint8_t port; |
| 5449 | uint8_t role; |
| 5450 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5451 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5452 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5453 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5454 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5455 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
| 5456 | #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] | 5457 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5458 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5459 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5460 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5461 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5462 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5463 | #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] | 5464 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5465 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5466 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5467 | uint8_t enabled; |
| 5468 | uint8_t role; |
| 5469 | uint8_t polarity; |
| 5470 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5471 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5472 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5473 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5474 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5475 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5476 | uint8_t polarity; |
| 5477 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5478 | } __ec_align1; |
| 5479 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5480 | /* Possible port partner connections based on CC line states */ |
| 5481 | enum pd_cc_states { |
| 5482 | PD_CC_NONE = 0, /* No port partner attached */ |
| 5483 | |
| 5484 | /* From DFP perspective */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5485 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5486 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5487 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5488 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
| 5489 | |
| 5490 | /* From UFP perspective */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5491 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5492 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5493 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5494 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5495 | /* Active/Passive Cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5496 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5497 | /* Optical/Non-optical cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5498 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5499 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5500 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
| 5501 | /* Active Link Uni-Direction */ |
| 5502 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5503 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5504 | struct ec_response_usb_pd_control_v2 { |
| 5505 | uint8_t enabled; |
| 5506 | uint8_t role; |
| 5507 | uint8_t polarity; |
| 5508 | char state[32]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5509 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5510 | 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] | 5511 | uint8_t reserved; /* Reserved for future use */ |
| 5512 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 5513 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5514 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5515 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5516 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5517 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5518 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5519 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5520 | #define EC_USB_PD_MAX_PORTS 8 |
| 5521 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5522 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5523 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5524 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5525 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5526 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5527 | |
| 5528 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5529 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5530 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5531 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5532 | |
| 5533 | enum usb_chg_type { |
| 5534 | USB_CHG_TYPE_NONE, |
| 5535 | USB_CHG_TYPE_PD, |
| 5536 | USB_CHG_TYPE_C, |
| 5537 | USB_CHG_TYPE_PROPRIETARY, |
| 5538 | USB_CHG_TYPE_BC12_DCP, |
| 5539 | USB_CHG_TYPE_BC12_CDP, |
| 5540 | USB_CHG_TYPE_BC12_SDP, |
| 5541 | USB_CHG_TYPE_OTHER, |
| 5542 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5543 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5544 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5545 | }; |
| 5546 | enum usb_power_roles { |
| 5547 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5548 | USB_PD_PORT_POWER_SOURCE, |
| 5549 | USB_PD_PORT_POWER_SINK, |
| 5550 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5551 | }; |
| 5552 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5553 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5554 | uint16_t voltage_max; |
| 5555 | uint16_t voltage_now; |
| 5556 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5557 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5558 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5559 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5560 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5561 | uint8_t role; |
| 5562 | uint8_t type; |
| 5563 | uint8_t dualrole; |
| 5564 | uint8_t reserved1; |
| 5565 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5566 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5567 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5568 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5569 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5570 | /* |
| 5571 | * This command will return the number of USB PD charge port + the number |
| 5572 | * of dedicated port present. |
| 5573 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5574 | */ |
| 5575 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5576 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5577 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5578 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5579 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5580 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5581 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5582 | |
| 5583 | enum usb_pd_fw_update_cmds { |
| 5584 | USB_PD_FW_REBOOT, |
| 5585 | USB_PD_FW_FLASH_ERASE, |
| 5586 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5587 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5588 | }; |
| 5589 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5590 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5591 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5592 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5593 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5594 | uint32_t size; /* Size to write in bytes */ |
| 5595 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5596 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5597 | |
| 5598 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5599 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5600 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5601 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5602 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5603 | uint16_t dev_id; |
| 5604 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5605 | uint8_t reserved; /* |
| 5606 | * For alignment of current_image |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5607 | * TODO(rspangler) but it's not aligned! |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5608 | * Should have been reserved[2]. |
| 5609 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5610 | uint32_t current_image; /* One of ec_image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5611 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5612 | |
| 5613 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5614 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5615 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5616 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5617 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5618 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5619 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5620 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5621 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5622 | struct ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5623 | uint16_t vid; /* USB-IF VID */ |
| 5624 | uint16_t pid; /* USB-IF PID */ |
| 5625 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5626 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5627 | |
| 5628 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5629 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5630 | |
| 5631 | /* Negative port parameters have special meaning */ |
| 5632 | enum usb_pd_override_ports { |
| 5633 | OVERRIDE_DONT_CHARGE = -2, |
| 5634 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5635 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5636 | }; |
| 5637 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5638 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5639 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5640 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5641 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5642 | /* |
| 5643 | * Read (and delete) one entry of PD event log. |
| 5644 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5645 | * future non-PD logs that use the same internal EC event_log. |
| 5646 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5647 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5649 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5650 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 5651 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5652 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5653 | uint16_t data; /* type-defined data payload */ |
| 5654 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5655 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5656 | |
| 5657 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5658 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5659 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5660 | #define PD_LOG_SIZE_MASK 0x1f |
| 5661 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5662 | #define PD_LOG_PORT_SHIFT 5 |
| 5663 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 5664 | ((size) & PD_LOG_SIZE_MASK)) |
| 5665 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 5666 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 5667 | |
| 5668 | /* PD event log : entry types */ |
| 5669 | /* PD MCU events */ |
| 5670 | #define PD_EVENT_MCU_BASE 0x00 |
| 5671 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 5672 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 5673 | /* Reserved for custom board event */ |
| 5674 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 5675 | /* PD generic accessory events */ |
| 5676 | #define PD_EVENT_ACC_BASE 0x20 |
| 5677 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 5678 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 5679 | /* PD power supply events */ |
| 5680 | #define PD_EVENT_PS_BASE 0x40 |
| 5681 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 5682 | /* PD video dongles events */ |
| 5683 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5684 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 5685 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 5686 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5687 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5688 | |
| 5689 | /* |
| 5690 | * PD_EVENT_MCU_CHARGE event definition : |
| 5691 | * the payload is "struct usb_chg_measures" |
| 5692 | * the data field contains the port state flags as defined below : |
| 5693 | */ |
| 5694 | /* Port partner is a dual role device */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5695 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5696 | /* Port is the pending override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5697 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5698 | /* Port is the override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5699 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5700 | /* Charger type */ |
| 5701 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5702 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5703 | /* Power delivery role */ |
| 5704 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 5705 | |
| 5706 | /* |
| 5707 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5708 | */ |
| 5709 | #define PS_FAULT_OCP 1 |
| 5710 | #define PS_FAULT_FAST_OCP 2 |
| 5711 | #define PS_FAULT_OVP 3 |
| 5712 | #define PS_FAULT_DISCH 4 |
| 5713 | |
| 5714 | /* |
| 5715 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5716 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5717 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5718 | uint8_t major; |
| 5719 | uint8_t minor; |
| 5720 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5721 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5722 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5723 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5724 | uint8_t family[2]; |
| 5725 | uint8_t chipid[2]; |
| 5726 | struct mcdp_version irom; |
| 5727 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5728 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5729 | |
| 5730 | /* struct mcdp_info field decoding */ |
| 5731 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5732 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5733 | |
| 5734 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5735 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5736 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5737 | uint16_t svid_idx; /* SVID index to get */ |
| 5738 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5739 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5740 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5741 | struct ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5742 | uint16_t svid; /* SVID */ |
| 5743 | uint16_t opos; /* Object Position */ |
| 5744 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5745 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5746 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5747 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5748 | |
| 5749 | enum pd_mode_cmd { |
| 5750 | PD_EXIT_MODE = 0, |
| 5751 | PD_ENTER_MODE = 1, |
| 5752 | /* Not a command. Do NOT remove. */ |
| 5753 | PD_MODE_CMD_COUNT, |
| 5754 | }; |
| 5755 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5756 | struct ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5757 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 5758 | uint16_t svid; /* SVID to set */ |
| 5759 | uint8_t opos; /* Object Position */ |
| 5760 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5761 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5762 | |
| 5763 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5764 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5765 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5766 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5767 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 5768 | 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] | 5769 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5770 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5771 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5772 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5773 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5774 | |
| 5775 | enum ec_pd_control_cmd { |
| 5776 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 5777 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 5778 | PD_RESET, /* Force reset the PD chip */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5779 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 5780 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5781 | }; |
| 5782 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5783 | struct ec_params_pd_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5784 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5785 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5786 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5787 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5788 | /* Get info about USB-C SS muxes */ |
| 5789 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 5790 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5791 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5792 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5793 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5794 | |
| 5795 | /* Flags representing mux state */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5796 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 5797 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 5798 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 5799 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 5800 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 5801 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 5802 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
| 5803 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5804 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
| 5805 | |
| 5806 | /* USB-C Dock connected */ |
| 5807 | #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] | 5808 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5809 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5810 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5811 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5812 | |
| 5813 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 5814 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5815 | struct ec_params_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5816 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5817 | /* |
| 5818 | * Fetch the live chip info or hard-coded + cached chip info |
| 5819 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 5820 | * 1: live chip value for VID/PID/FW Version |
| 5821 | */ |
| 5822 | uint8_t live; |
| 5823 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5824 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5825 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5826 | uint16_t vendor_id; |
| 5827 | uint16_t product_id; |
| 5828 | uint16_t device_id; |
| 5829 | union { |
| 5830 | uint8_t fw_version_string[8]; |
| 5831 | uint64_t fw_version_number; |
| 5832 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5833 | } __ec_align2; |
| 5834 | |
| 5835 | struct ec_response_pd_chip_info_v1 { |
| 5836 | uint16_t vendor_id; |
| 5837 | uint16_t product_id; |
| 5838 | uint16_t device_id; |
| 5839 | union { |
| 5840 | uint8_t fw_version_string[8]; |
| 5841 | uint64_t fw_version_number; |
| 5842 | }; |
| 5843 | union { |
| 5844 | uint8_t min_req_fw_version_string[8]; |
| 5845 | uint64_t min_req_fw_version_number; |
| 5846 | }; |
| 5847 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5848 | |
| 5849 | /* Run RW signature verification and get status */ |
| 5850 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 5851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5852 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5853 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5854 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5855 | |
| 5856 | /* For controlling RWSIG task */ |
| 5857 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 5858 | |
| 5859 | enum rwsig_action { |
| 5860 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 5861 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 5862 | }; |
| 5863 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5864 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5865 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5866 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5867 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5868 | /* Run verification on a slot */ |
| 5869 | #define EC_CMD_EFS_VERIFY 0x011E |
| 5870 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5871 | struct ec_params_efs_verify { |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5872 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5873 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5874 | |
| 5875 | /* |
| 5876 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 5877 | * type. Integers return a uint32. Strings return a string, using the response |
| 5878 | * size to determine how big it is. |
| 5879 | */ |
| 5880 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
| 5881 | /* |
| 5882 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 5883 | * hardware write-protect enabled. |
| 5884 | */ |
| 5885 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
| 5886 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5887 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5888 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
| 5889 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 5890 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 5891 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Wisley Chen | c1efec7 | 2018-11-06 09:28:23 +0800 | [diff] [blame] | 5892 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5893 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5894 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5895 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5896 | /* Second Source Factory Cache */ |
| 5897 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 5898 | CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5899 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5900 | }; |
| 5901 | |
| 5902 | /* |
| 5903 | * Flags to control read operation |
| 5904 | * |
| 5905 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 5906 | * write was successful without reboot. |
| 5907 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5908 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5909 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5910 | struct ec_params_get_cbi { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5911 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5912 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5913 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5914 | |
| 5915 | /* |
| 5916 | * Flags to control write behavior. |
| 5917 | * |
| 5918 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 5919 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5920 | * 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] | 5921 | * will be initialized to zero first. |
| 5922 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5923 | #define CBI_SET_NO_SYNC BIT(0) |
| 5924 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5925 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5926 | struct ec_params_set_cbi { |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5927 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5928 | uint32_t flag; /* CBI_SET_* */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5929 | uint32_t size; /* Data size */ |
| 5930 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5931 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5932 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5933 | /* |
| 5934 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 5935 | */ |
| 5936 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 5937 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 5938 | /* EC reset causes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5939 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 5940 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 5941 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 5942 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 5943 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 5944 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 5945 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 5946 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 5947 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 5948 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 5949 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 5950 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 5951 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
| 5952 | #define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from |
| 5953 | * previous boot |
| 5954 | */ |
| 5955 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 5956 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 5957 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 5958 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
| 5959 | #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] | 5960 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This |
| 5961 | * enables PD in RO for Chromebox. |
| 5962 | */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5963 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 5964 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 5965 | #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] | 5966 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 5967 | /* |
| 5968 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 5969 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 5970 | * compatibility: |
| 5971 | * - New entries must be inserted prior to the _COUNT field |
| 5972 | * - If an existing entry is no longer in service, it must be replaced with a |
| 5973 | * RESERVED entry instead. |
| 5974 | * - The semantic meaning of an entry should not change. |
| 5975 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 5976 | */ |
| 5977 | enum chipset_reset_reason { |
| 5978 | CHIPSET_RESET_BEGIN = 0, |
| 5979 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 5980 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 5981 | CHIPSET_RESET_BOARD_CUSTOM, |
| 5982 | /* Believe that the AP has hung */ |
| 5983 | CHIPSET_RESET_HANG_REBOOT, |
| 5984 | /* Reset by EC console command */ |
| 5985 | CHIPSET_RESET_CONSOLE_CMD, |
| 5986 | /* Reset by EC host command */ |
| 5987 | CHIPSET_RESET_HOST_CMD, |
| 5988 | /* Keyboard module reset key combination */ |
| 5989 | CHIPSET_RESET_KB_SYSRESET, |
| 5990 | /* Keyboard module warm reboot */ |
| 5991 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 5992 | /* Debug module warm reboot */ |
| 5993 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 5994 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 5995 | CHIPSET_RESET_AP_REQ, |
| 5996 | /* Reset as side-effect of startup sequence */ |
| 5997 | CHIPSET_RESET_INIT, |
| 5998 | /* EC detected an AP watchdog event. */ |
| 5999 | CHIPSET_RESET_AP_WATCHDOG, |
| 6000 | |
| 6001 | CHIPSET_RESET_COUNT, |
| 6002 | }; |
| 6003 | |
| 6004 | /* |
| 6005 | * AP hard shutdowns are logged on the same path as resets. |
| 6006 | */ |
| 6007 | enum chipset_shutdown_reason { |
| 6008 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 6009 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 6010 | /* Forcing a shutdown as part of EC initialization */ |
| 6011 | CHIPSET_SHUTDOWN_INIT, |
| 6012 | /* Custom reason on a per-board basis. */ |
| 6013 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 6014 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 6015 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 6016 | /* A power_wait_signal is being asserted */ |
| 6017 | CHIPSET_SHUTDOWN_WAIT, |
| 6018 | /* Critical battery level. */ |
| 6019 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 6020 | /* Because you told me to. */ |
| 6021 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 6022 | /* Forcing a shutdown to effect entry to G3. */ |
| 6023 | CHIPSET_SHUTDOWN_G3, |
| 6024 | /* Force shutdown due to over-temperature. */ |
| 6025 | CHIPSET_SHUTDOWN_THERMAL, |
| 6026 | /* Force a chipset shutdown from the power button through EC */ |
| 6027 | CHIPSET_SHUTDOWN_BUTTON, |
| 6028 | |
| 6029 | CHIPSET_SHUTDOWN_COUNT, |
| 6030 | }; |
| 6031 | |
| 6032 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6033 | struct ec_response_uptime_info { |
| 6034 | /* |
| 6035 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 6036 | * typically do not restart the EC's time_since_boot epoch. |
| 6037 | * |
| 6038 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 6039 | * sense of time, in both phase and frequency. This timebase is similar |
| 6040 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 6041 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6042 | uint32_t time_since_ec_boot_ms; |
| 6043 | |
| 6044 | /* |
| 6045 | * Number of times the AP was reset by the EC since the last EC boot. |
| 6046 | * Note that the AP may be held in reset by the EC during the initial |
| 6047 | * boot sequence, such that the very first AP boot may count as more |
| 6048 | * than one here. |
| 6049 | */ |
| 6050 | uint32_t ap_resets_since_ec_boot; |
| 6051 | |
| 6052 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6053 | * The set of flags which describe the EC's most recent reset. |
| 6054 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6055 | */ |
| 6056 | uint32_t ec_reset_flags; |
| 6057 | |
| 6058 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6059 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6060 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6061 | uint16_t reset_cause; |
| 6062 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6063 | /* Reserved for protocol growth. */ |
| 6064 | uint16_t reserved; |
| 6065 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6066 | /* |
| 6067 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6068 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6069 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6070 | */ |
| 6071 | uint32_t reset_time_ms; |
| 6072 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6073 | } __ec_align4; |
| 6074 | |
| 6075 | /* |
| 6076 | * Add entropy to the device secret (stored in the rollback region). |
| 6077 | * |
| 6078 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6079 | * flash), so the commands are asynchronous. |
| 6080 | */ |
| 6081 | #define EC_CMD_ADD_ENTROPY 0x0122 |
| 6082 | |
| 6083 | enum add_entropy_action { |
| 6084 | /* Add entropy to the current secret. */ |
| 6085 | ADD_ENTROPY_ASYNC = 0, |
| 6086 | /* |
| 6087 | * Add entropy, and also make sure that the previous secret is erased. |
| 6088 | * (this can be implemented by adding entropy multiple times until |
| 6089 | * all rolback blocks have been overwritten). |
| 6090 | */ |
| 6091 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6092 | /* Read back result from the previous operation. */ |
| 6093 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6094 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6095 | |
| 6096 | struct ec_params_rollback_add_entropy { |
| 6097 | uint8_t action; |
| 6098 | } __ec_align1; |
| 6099 | |
| 6100 | /* |
| 6101 | * Perform a single read of a given ADC channel. |
| 6102 | */ |
| 6103 | #define EC_CMD_ADC_READ 0x0123 |
| 6104 | |
| 6105 | struct ec_params_adc_read { |
| 6106 | uint8_t adc_channel; |
| 6107 | } __ec_align1; |
| 6108 | |
| 6109 | struct ec_response_adc_read { |
| 6110 | int32_t adc_value; |
| 6111 | } __ec_align4; |
| 6112 | |
| 6113 | /* |
| 6114 | * Read back rollback info |
| 6115 | */ |
| 6116 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
| 6117 | |
| 6118 | struct ec_response_rollback_info { |
| 6119 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6120 | int32_t rollback_min_version; |
| 6121 | int32_t rw_rollback_version; |
| 6122 | } __ec_align4; |
| 6123 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6124 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6125 | /* Issue AP reset */ |
| 6126 | #define EC_CMD_AP_RESET 0x0125 |
| 6127 | |
| 6128 | /*****************************************************************************/ |
| 6129 | /* Locate peripheral chips |
| 6130 | * |
| 6131 | * Return values: |
| 6132 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6133 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6134 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6135 | */ |
| 6136 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6137 | |
| 6138 | enum ec_chip_type { |
| 6139 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6140 | EC_CHIP_TYPE_TCPC = 1, |
| 6141 | EC_CHIP_TYPE_COUNT, |
| 6142 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6143 | }; |
| 6144 | |
| 6145 | enum ec_bus_type { |
| 6146 | EC_BUS_TYPE_I2C = 0, |
| 6147 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6148 | EC_BUS_TYPE_COUNT, |
| 6149 | EC_BUS_TYPE_MAX = 0xFF, |
| 6150 | }; |
| 6151 | |
| 6152 | struct ec_i2c_info { |
| 6153 | uint16_t port; /* Physical port for device */ |
| 6154 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
| 6155 | }; |
| 6156 | |
| 6157 | struct ec_params_locate_chip { |
| 6158 | uint8_t type; /* enum ec_chip_type */ |
| 6159 | uint8_t index; /* Specifies one instance of chip type */ |
| 6160 | /* Used for type specific parameters in future */ |
| 6161 | union { |
| 6162 | uint16_t reserved; |
| 6163 | }; |
| 6164 | } __ec_align2; |
| 6165 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6166 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6167 | struct ec_response_locate_chip { |
| 6168 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6169 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
| 6170 | union { |
| 6171 | struct ec_i2c_info i2c_info; |
| 6172 | }; |
| 6173 | } __ec_align2; |
| 6174 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6175 | /* |
| 6176 | * Reboot AP on G3 |
| 6177 | * |
| 6178 | * This command is used for validation purpose, where the AP needs to be |
| 6179 | * 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] | 6180 | * wake events. |
| 6181 | * - With command version 0: |
| 6182 | * AP reboots immediately from G3 |
| 6183 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6184 | * - With command version 1: |
| 6185 | * AP reboots after the user specified delay |
| 6186 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6187 | */ |
| 6188 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6189 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6190 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6191 | /* configurable delay in seconds in G3 state */ |
| 6192 | uint32_t reboot_ap_at_g3_delay; |
| 6193 | } __ec_align4; |
| 6194 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6195 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6196 | /* Get PD port capabilities |
| 6197 | * |
| 6198 | * Returns the following static *capabilities* of the given port: |
| 6199 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6200 | * future CrOS devices would ever be only a source, so the options are |
| 6201 | * sink or dual. |
| 6202 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6203 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6204 | * or none). |
| 6205 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6206 | * for CrOS devices. |
| 6207 | */ |
| 6208 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6209 | |
| 6210 | enum ec_pd_power_role_caps { |
| 6211 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6212 | EC_PD_POWER_ROLE_SINK = 1, |
| 6213 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6214 | }; |
| 6215 | |
| 6216 | enum ec_pd_try_power_role_caps { |
| 6217 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6218 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6219 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6220 | }; |
| 6221 | |
| 6222 | enum ec_pd_data_role_caps { |
| 6223 | EC_PD_DATA_ROLE_DFP = 0, |
| 6224 | EC_PD_DATA_ROLE_UFP = 1, |
| 6225 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6226 | }; |
| 6227 | |
| 6228 | /* From: power_manager/power_supply_properties.proto */ |
| 6229 | enum ec_pd_port_location { |
| 6230 | /* The location of the port is unknown, or there's only one port. */ |
| 6231 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6232 | |
| 6233 | /* |
| 6234 | * Various positions on the device. The first word describes the side of |
| 6235 | * the device where the port is located while the second clarifies the |
| 6236 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6237 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6238 | * device. |
| 6239 | */ |
| 6240 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6241 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6242 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6243 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6244 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6245 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
| 6246 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
| 6247 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6248 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6249 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
| 6250 | }; |
| 6251 | |
| 6252 | struct ec_params_get_pd_port_caps { |
| 6253 | uint8_t port; /* Which port to interrogate */ |
| 6254 | } __ec_align1; |
| 6255 | |
| 6256 | struct ec_response_get_pd_port_caps { |
| 6257 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6258 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6259 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6260 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
| 6261 | } __ec_align1; |
| 6262 | |
| 6263 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6264 | /* |
| 6265 | * Button press simulation |
| 6266 | * |
| 6267 | * This command is used to simulate a button press. |
| 6268 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6269 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6270 | * |
| 6271 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6272 | */ |
| 6273 | #define EC_CMD_BUTTON 0x0129 |
| 6274 | |
| 6275 | struct ec_params_button { |
| 6276 | /* Button mask aligned to enum keyboard_button_type */ |
| 6277 | uint32_t btn_mask; |
| 6278 | |
| 6279 | /* Duration in milliseconds button needs to be pressed */ |
| 6280 | uint32_t press_ms; |
| 6281 | } __ec_align1; |
| 6282 | |
| 6283 | enum keyboard_button_type { |
| 6284 | KEYBOARD_BUTTON_POWER = 0, |
| 6285 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
| 6286 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6287 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6288 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6289 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6290 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6291 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6292 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6293 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6294 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6295 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
| 6296 | |
| 6297 | KEYBOARD_BUTTON_COUNT |
| 6298 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6299 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6300 | /*****************************************************************************/ |
| 6301 | /* |
| 6302 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6303 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6304 | * Additionally, capability to send function codes for the same keys is |
| 6305 | * optional and acceptable. |
| 6306 | * |
| 6307 | * Note: If the top row can generate both function and action codes by |
| 6308 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6309 | * "function" or "action" codes by default. In both cases, the response |
| 6310 | * for this command will look the same. |
| 6311 | */ |
| 6312 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6313 | |
| 6314 | /* Possible values for the top row keys */ |
| 6315 | enum action_key { |
| 6316 | TK_ABSENT = 0, |
| 6317 | TK_BACK = 1, |
| 6318 | TK_FORWARD = 2, |
| 6319 | TK_REFRESH = 3, |
| 6320 | TK_FULLSCREEN = 4, |
| 6321 | TK_OVERVIEW = 5, |
| 6322 | TK_BRIGHTNESS_DOWN = 6, |
| 6323 | TK_BRIGHTNESS_UP = 7, |
| 6324 | TK_VOL_MUTE = 8, |
| 6325 | TK_VOL_DOWN = 9, |
| 6326 | TK_VOL_UP = 10, |
| 6327 | TK_SNAPSHOT = 11, |
| 6328 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6329 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6330 | TK_KBD_BKLIGHT_UP = 14, |
| 6331 | TK_PLAY_PAUSE = 15, |
| 6332 | TK_NEXT_TRACK = 16, |
| 6333 | TK_PREV_TRACK = 17, |
| 6334 | }; |
| 6335 | |
| 6336 | /* |
| 6337 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6338 | * If this needs to change, please create a new version of the command. |
| 6339 | */ |
| 6340 | #define MAX_TOP_ROW_KEYS 15 |
| 6341 | #define MIN_TOP_ROW_KEYS 10 |
| 6342 | |
| 6343 | /* |
| 6344 | * Is the keyboard capable of sending function keys *in addition to* |
| 6345 | * action keys. This is possible for e.g. if the keyboard has a |
| 6346 | * dedicated Fn key. |
| 6347 | */ |
| 6348 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
| 6349 | /* |
| 6350 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6351 | */ |
| 6352 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
| 6353 | /* |
| 6354 | * Whether the keyboard has a screenlock key. |
| 6355 | */ |
| 6356 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
| 6357 | |
| 6358 | struct ec_response_keybd_config { |
| 6359 | /* |
| 6360 | * Number of top row keys, excluding Esc and Screenlock. |
| 6361 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6362 | * (i.e. does not expose any tables to the kernel). |
| 6363 | */ |
| 6364 | uint8_t num_top_row_keys; |
| 6365 | |
| 6366 | /* |
| 6367 | * The action keys in the top row, in order from left to right. |
| 6368 | * The values are filled from enum action_key. Esc and Screenlock |
| 6369 | * keys are not considered part of top row keys. |
| 6370 | */ |
| 6371 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6372 | |
| 6373 | /* Capability flags */ |
| 6374 | uint8_t capabilities; |
| 6375 | |
| 6376 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6377 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6378 | /* |
| 6379 | * Configure smart discharge |
| 6380 | */ |
| 6381 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6382 | |
| 6383 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
| 6384 | |
| 6385 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6386 | struct discharge_rate { |
| 6387 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6388 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
| 6389 | }; |
| 6390 | |
| 6391 | struct smart_discharge_zone { |
| 6392 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6393 | int cutoff; |
| 6394 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6395 | int stayup; |
| 6396 | }; |
| 6397 | |
| 6398 | struct ec_params_smart_discharge { |
| 6399 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
| 6400 | /* |
| 6401 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6402 | * zero to disable smart discharging. That is, the system hibernates as |
| 6403 | * soon as the G3 idle timer expires. |
| 6404 | */ |
| 6405 | uint16_t hours_to_zero; |
| 6406 | /* Set both to zero to keep the current rates. */ |
| 6407 | struct discharge_rate drate; |
| 6408 | }; |
| 6409 | |
| 6410 | struct ec_response_smart_discharge { |
| 6411 | uint16_t hours_to_zero; |
| 6412 | struct discharge_rate drate; |
| 6413 | struct smart_discharge_zone dzone; |
| 6414 | }; |
| 6415 | |
| 6416 | /*****************************************************************************/ |
| 6417 | /* Voltage regulator controls */ |
| 6418 | |
| 6419 | /* |
| 6420 | * Get basic info of voltage regulator for given index. |
| 6421 | * |
| 6422 | * Returns the regulator name and supported voltage list in mV. |
| 6423 | */ |
| 6424 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6425 | |
| 6426 | /* Maximum length of regulator name */ |
| 6427 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6428 | |
| 6429 | /* Maximum length of the supported voltage list. */ |
| 6430 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6431 | |
| 6432 | struct ec_params_regulator_get_info { |
| 6433 | uint32_t index; |
| 6434 | } __ec_align4; |
| 6435 | |
| 6436 | struct ec_response_regulator_get_info { |
| 6437 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6438 | uint16_t num_voltages; |
| 6439 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6440 | } __ec_align2; |
| 6441 | |
| 6442 | /* |
| 6443 | * Configure the regulator as enabled / disabled. |
| 6444 | */ |
| 6445 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6446 | |
| 6447 | struct ec_params_regulator_enable { |
| 6448 | uint32_t index; |
| 6449 | uint8_t enable; |
| 6450 | } __ec_align4; |
| 6451 | |
| 6452 | /* |
| 6453 | * Query if the regulator is enabled. |
| 6454 | * |
| 6455 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6456 | */ |
| 6457 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6458 | |
| 6459 | struct ec_params_regulator_is_enabled { |
| 6460 | uint32_t index; |
| 6461 | } __ec_align4; |
| 6462 | |
| 6463 | struct ec_response_regulator_is_enabled { |
| 6464 | uint8_t enabled; |
| 6465 | } __ec_align1; |
| 6466 | |
| 6467 | /* |
| 6468 | * Set voltage for the voltage regulator within the range specified. |
| 6469 | * |
| 6470 | * The driver should select the voltage in range closest to min_mv. |
| 6471 | * |
| 6472 | * Also note that this might be called before the regulator is enabled, and the |
| 6473 | * setting should be in effect after the regulator is enabled. |
| 6474 | */ |
| 6475 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6476 | |
| 6477 | struct ec_params_regulator_set_voltage { |
| 6478 | uint32_t index; |
| 6479 | uint32_t min_mv; |
| 6480 | uint32_t max_mv; |
| 6481 | } __ec_align4; |
| 6482 | |
| 6483 | /* |
| 6484 | * Get the currently configured voltage for the voltage regulator. |
| 6485 | * |
| 6486 | * Note that this might be called before the regulator is enabled, and this |
| 6487 | * should return the configured output voltage if the regulator is enabled. |
| 6488 | */ |
| 6489 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6490 | |
| 6491 | struct ec_params_regulator_get_voltage { |
| 6492 | uint32_t index; |
| 6493 | } __ec_align4; |
| 6494 | |
| 6495 | struct ec_response_regulator_get_voltage { |
| 6496 | uint32_t voltage_mv; |
| 6497 | } __ec_align4; |
| 6498 | |
| 6499 | /* |
| 6500 | * Gather all discovery information for the given port and partner type. |
| 6501 | * |
| 6502 | * Note that if discovery has not yet completed, only the currently completed |
| 6503 | * responses will be filled in. If the discovery data structures are changed |
| 6504 | * in the process of the command running, BUSY will be returned. |
| 6505 | * |
| 6506 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6507 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6508 | * maximum parameter size. |
| 6509 | */ |
| 6510 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6511 | |
| 6512 | enum typec_partner_type { |
| 6513 | TYPEC_PARTNER_SOP = 0, |
| 6514 | TYPEC_PARTNER_SOP_PRIME = 1, |
| 6515 | }; |
| 6516 | |
| 6517 | struct ec_params_typec_discovery { |
| 6518 | uint8_t port; |
| 6519 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6520 | } __ec_align1; |
| 6521 | |
| 6522 | struct svid_mode_info { |
| 6523 | uint16_t svid; |
| 6524 | uint16_t mode_count; /* Number of modes partner sent */ |
| 6525 | uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6526 | }; |
| 6527 | |
| 6528 | struct ec_response_typec_discovery { |
| 6529 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6530 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
| 6531 | uint16_t reserved; |
| 6532 | uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6533 | struct svid_mode_info svids[0]; |
| 6534 | } __ec_align1; |
| 6535 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6536 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6537 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6538 | |
| 6539 | enum typec_control_command { |
| 6540 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6541 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6542 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
| 6543 | }; |
| 6544 | |
| 6545 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6546 | enum typec_mode { |
| 6547 | TYPEC_MODE_DP, |
| 6548 | TYPEC_MODE_TBT, |
| 6549 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6550 | }; |
| 6551 | |
| 6552 | struct ec_params_typec_control { |
| 6553 | uint8_t port; |
| 6554 | uint8_t command; /* enum typec_control_command */ |
| 6555 | uint16_t reserved; |
| 6556 | |
| 6557 | /* |
| 6558 | * This section will be interpreted based on |command|. Define a |
| 6559 | * placeholder structure to avoid having to increase the size and bump |
| 6560 | * the command version when adding new sub-commands. |
| 6561 | */ |
| 6562 | union { |
| 6563 | uint32_t clear_events_mask; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6564 | uint8_t mode_to_enter; /* enum typec_mode */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6565 | uint8_t placeholder[128]; |
| 6566 | }; |
| 6567 | } __ec_align1; |
| 6568 | |
| 6569 | /* |
| 6570 | * Gather all status information for a port. |
| 6571 | * |
| 6572 | * Note: this covers many of the return fields from the deprecated |
| 6573 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 6574 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 6575 | * EC_CMD_USB_PD_CONTROL command. |
| 6576 | * |
| 6577 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6578 | */ |
| 6579 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 6580 | |
| 6581 | /* |
| 6582 | * Power role. |
| 6583 | * |
| 6584 | * Note this is also used for PD header creation, and values align to those in |
| 6585 | * the Power Delivery Specification Revision 3.0 (See |
| 6586 | * 6.2.1.1.4 Port Power Role). |
| 6587 | */ |
| 6588 | enum pd_power_role { |
| 6589 | PD_ROLE_SINK = 0, |
| 6590 | PD_ROLE_SOURCE = 1 |
| 6591 | }; |
| 6592 | |
| 6593 | /* |
| 6594 | * Data role. |
| 6595 | * |
| 6596 | * Note this is also used for PD header creation, and the first two values |
| 6597 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 6598 | * 6.2.1.1.6 Port Data Role). |
| 6599 | */ |
| 6600 | enum pd_data_role { |
| 6601 | PD_ROLE_UFP = 0, |
| 6602 | PD_ROLE_DFP = 1, |
| 6603 | PD_ROLE_DISCONNECTED = 2, |
| 6604 | }; |
| 6605 | |
| 6606 | enum pd_vconn_role { |
| 6607 | PD_ROLE_VCONN_OFF = 0, |
| 6608 | PD_ROLE_VCONN_SRC = 1, |
| 6609 | }; |
| 6610 | |
| 6611 | /* |
| 6612 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 6613 | * regardless of whether a debug accessory is connected. |
| 6614 | */ |
| 6615 | enum tcpc_cc_polarity { |
| 6616 | /* |
| 6617 | * _CCx: is used to indicate the polarity while not connected to |
| 6618 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 6619 | * the other will be open. |
| 6620 | */ |
| 6621 | POLARITY_CC1 = 0, |
| 6622 | POLARITY_CC2 = 1, |
| 6623 | |
| 6624 | /* |
| 6625 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 6626 | * SRC Debug Accessory. Assert resistors on both lines. |
| 6627 | */ |
| 6628 | POLARITY_CC1_DTS = 2, |
| 6629 | POLARITY_CC2_DTS = 3, |
| 6630 | |
| 6631 | /* |
| 6632 | * The current TCPC code relies on these specific POLARITY values. |
| 6633 | * Adding in a check to verify if the list grows for any reason |
| 6634 | * that this will give a hint that other places need to be |
| 6635 | * adjusted. |
| 6636 | */ |
| 6637 | POLARITY_COUNT |
| 6638 | }; |
| 6639 | |
| 6640 | #define MODE_DP_PIN_A BIT(0) |
| 6641 | #define MODE_DP_PIN_B BIT(1) |
| 6642 | #define MODE_DP_PIN_C BIT(2) |
| 6643 | #define MODE_DP_PIN_D BIT(3) |
| 6644 | #define MODE_DP_PIN_E BIT(4) |
| 6645 | #define MODE_DP_PIN_F BIT(5) |
| 6646 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
| 6647 | |
| 6648 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 6649 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6650 | #define PD_STATUS_EVENT_HARD_RESET BIT(2) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6651 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6652 | /* |
| 6653 | * Encode and decode for BCD revision response |
| 6654 | * |
| 6655 | * Note: the major revision set is written assuming that the value given is the |
| 6656 | * Specification Revision from the PD header, which currently only maps to PD |
| 6657 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 6658 | */ |
| 6659 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 6660 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 6661 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
| 6662 | |
| 6663 | /* |
| 6664 | * Decode helpers for Source and Sink Capability PDOs |
| 6665 | * |
| 6666 | * Note: The Power Delivery Specification should be considered the ultimate |
| 6667 | * source of truth on the decoding of these PDOs |
| 6668 | */ |
| 6669 | #define PDO_TYPE_FIXED (0 << 30) |
| 6670 | #define PDO_TYPE_BATTERY (1 << 30) |
| 6671 | #define PDO_TYPE_VARIABLE (2 << 30) |
| 6672 | #define PDO_TYPE_AUGMENTED (3 << 30) |
| 6673 | #define PDO_TYPE_MASK (3 << 30) |
| 6674 | |
| 6675 | /* |
| 6676 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 6677 | * |
| 6678 | * <31:30> : Fixed Supply |
| 6679 | * <29> : Dual-Role Power |
| 6680 | * <28> : SNK/SRC dependent |
| 6681 | * <27> : Unconstrained Power |
| 6682 | * <26> : USB Communications Capable |
| 6683 | * <25> : Dual-Role Data |
| 6684 | * <24:20> : SNK/SRC dependent |
| 6685 | * <19:10> : Voltage in 50mV Units |
| 6686 | * <9:0> : Maximum Current in 10mA units |
| 6687 | */ |
| 6688 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 6689 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 6690 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 6691 | #define PDO_FIXED_DATA_SWAP BIT(25) |
| 6692 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
| 6693 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6694 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
| 6695 | |
| 6696 | /* |
| 6697 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 6698 | * |
| 6699 | * <31:30> : Battery |
| 6700 | * <29:20> : Maximum Voltage in 50mV units |
| 6701 | * <19:10> : Minimum Voltage in 50mV units |
| 6702 | * <9:0> : Maximum Allowable Power in 250mW units |
| 6703 | */ |
| 6704 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6705 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6706 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
| 6707 | |
| 6708 | /* |
| 6709 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 6710 | * |
| 6711 | * <31:30> : Variable Supply (non-Battery) |
| 6712 | * <29:20> : Maximum Voltage in 50mV units |
| 6713 | * <19:10> : Minimum Voltage in 50mV units |
| 6714 | * <9:0> : Operational Current in 10mA units |
| 6715 | */ |
| 6716 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6717 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6718 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
| 6719 | |
| 6720 | /* |
| 6721 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 6722 | * |
| 6723 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 6724 | * supported as of the cited version. |
| 6725 | * |
| 6726 | * <31:30> : Augmented Power Data Object |
| 6727 | * <29:28> : Programmable Power Supply |
| 6728 | * <27> : PPS Power Limited |
| 6729 | * <26:25> : Reserved |
| 6730 | * <24:17> : Maximum Voltage in 100mV increments |
| 6731 | * <16> : Reserved |
| 6732 | * <15:8> : Minimum Voltage in 100mV increments |
| 6733 | * <7> : Reserved |
| 6734 | * <6:0> : Maximum Current in 50mA increments |
| 6735 | */ |
| 6736 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 6737 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 6738 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
| 6739 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6740 | struct ec_params_typec_status { |
| 6741 | uint8_t port; |
| 6742 | } __ec_align1; |
| 6743 | |
| 6744 | struct ec_response_typec_status { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6745 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 6746 | uint8_t dev_connected; /* Device connected - bool */ |
| 6747 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 6748 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6749 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6750 | uint8_t power_role; /* enum pd_power_role */ |
| 6751 | uint8_t data_role; /* enum pd_data_role */ |
| 6752 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 6753 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6754 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6755 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 6756 | uint8_t cc_state; /* enum pd_cc_states */ |
| 6757 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 6758 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6759 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6760 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6761 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6762 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6763 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6764 | /* |
| 6765 | * BCD PD revisions for partners |
| 6766 | * |
| 6767 | * The format has the PD major reversion in the upper nibble, and PD |
| 6768 | * minor version in the next nibble. Following two nibbles are |
| 6769 | * currently 0. |
| 6770 | * ex. PD 3.2 would map to 0x3200 |
| 6771 | * |
| 6772 | * PD major/minor will be 0 if no PD device is connected. |
| 6773 | */ |
| 6774 | uint16_t sop_revision; |
| 6775 | uint16_t sop_prime_revision; |
| 6776 | |
| 6777 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 6778 | |
| 6779 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6780 | } __ec_align1; |
| 6781 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6782 | /** |
| 6783 | * Get the number of peripheral charge ports |
| 6784 | */ |
| 6785 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 6786 | |
| 6787 | #define EC_PCHG_MAX_PORTS 8 |
| 6788 | |
| 6789 | struct ec_response_pchg_count { |
| 6790 | uint8_t port_count; |
| 6791 | } __ec_align1; |
| 6792 | |
| 6793 | /** |
| 6794 | * Get the status of a peripheral charge port |
| 6795 | */ |
| 6796 | #define EC_CMD_PCHG 0x0135 |
| 6797 | |
| 6798 | struct ec_params_pchg { |
| 6799 | uint8_t port; |
| 6800 | } __ec_align1; |
| 6801 | |
| 6802 | struct ec_response_pchg { |
| 6803 | uint32_t error; /* enum pchg_error */ |
| 6804 | uint8_t state; /* enum pchg_state state */ |
| 6805 | uint8_t battery_percentage; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6806 | uint8_t unused0; |
| 6807 | uint8_t unused1; |
| 6808 | /* Fields added in version 1 */ |
| 6809 | uint32_t fw_version; |
| 6810 | uint32_t dropped_event_count; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6811 | } __ec_align2; |
| 6812 | |
| 6813 | enum pchg_state { |
| 6814 | /* Charger is reset and not initialized. */ |
| 6815 | PCHG_STATE_RESET = 0, |
| 6816 | /* Charger is initialized or disabled. */ |
| 6817 | PCHG_STATE_INITIALIZED, |
| 6818 | /* Charger is enabled and ready to detect a device. */ |
| 6819 | PCHG_STATE_ENABLED, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6820 | /* Device is in proximity. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6821 | PCHG_STATE_DETECTED, |
| 6822 | /* Device is being charged. */ |
| 6823 | PCHG_STATE_CHARGING, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6824 | /* Device is fully charged. It implies DETECTED (& not charging). */ |
| 6825 | PCHG_STATE_FULL, |
| 6826 | /* In download (a.k.a. firmware update) mode */ |
| 6827 | PCHG_STATE_DOWNLOAD, |
| 6828 | /* In download mode. Ready for receiving data. */ |
| 6829 | PCHG_STATE_DOWNLOADING, |
| 6830 | /* Device is ready for data communication. */ |
| 6831 | PCHG_STATE_CONNECTED, |
| 6832 | /* Put no more entry below */ |
| 6833 | PCHG_STATE_COUNT, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6834 | }; |
| 6835 | |
| 6836 | #define EC_PCHG_STATE_TEXT { \ |
| 6837 | [PCHG_STATE_RESET] = "RESET", \ |
| 6838 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 6839 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 6840 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 6841 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6842 | [PCHG_STATE_FULL] = "FULL", \ |
| 6843 | [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ |
| 6844 | [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ |
| 6845 | [PCHG_STATE_CONNECTED] = "CONNECTED", \ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6846 | } |
| 6847 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 6848 | /** |
| 6849 | * Update firmware of peripheral chip |
| 6850 | */ |
| 6851 | #define EC_CMD_PCHG_UPDATE 0x0136 |
| 6852 | |
| 6853 | /* Port number is encoded in bit[28:31]. */ |
| 6854 | #define EC_MKBP_PCHG_PORT_SHIFT 28 |
| 6855 | /* Utility macro for converting MKBP event to port number. */ |
| 6856 | #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) |
| 6857 | /* Utility macro for extracting event bits. */ |
| 6858 | #define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \ |
| 6859 | & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0)) |
| 6860 | |
| 6861 | #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) |
| 6862 | #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) |
| 6863 | #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) |
| 6864 | #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) |
| 6865 | |
| 6866 | enum ec_pchg_update_cmd { |
| 6867 | /* Reset chip to normal mode. */ |
| 6868 | EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, |
| 6869 | /* Reset and put a chip in update (a.k.a. download) mode. */ |
| 6870 | EC_PCHG_UPDATE_CMD_OPEN, |
| 6871 | /* Write a block of data containing FW image. */ |
| 6872 | EC_PCHG_UPDATE_CMD_WRITE, |
| 6873 | /* Close update session. */ |
| 6874 | EC_PCHG_UPDATE_CMD_CLOSE, |
| 6875 | /* End of commands */ |
| 6876 | EC_PCHG_UPDATE_CMD_COUNT, |
| 6877 | }; |
| 6878 | |
| 6879 | struct ec_params_pchg_update { |
| 6880 | /* PCHG port number */ |
| 6881 | uint8_t port; |
| 6882 | /* enum ec_pchg_update_cmd */ |
| 6883 | uint8_t cmd; |
| 6884 | /* Padding */ |
| 6885 | uint8_t reserved0; |
| 6886 | uint8_t reserved1; |
| 6887 | /* Version of new firmware */ |
| 6888 | uint32_t version; |
| 6889 | /* CRC32 of new firmware */ |
| 6890 | uint32_t crc32; |
| 6891 | /* Address in chip memory where <data> is written to */ |
| 6892 | uint32_t addr; |
| 6893 | /* Size of <data> */ |
| 6894 | uint32_t size; |
| 6895 | /* Partial data of new firmware */ |
| 6896 | uint8_t data[]; |
| 6897 | } __ec_align4; |
| 6898 | |
| 6899 | BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT |
| 6900 | < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8)); |
| 6901 | |
| 6902 | struct ec_response_pchg_update { |
| 6903 | /* Block size */ |
| 6904 | uint32_t block_size; |
| 6905 | } __ec_align4; |
| 6906 | |
| 6907 | |
| 6908 | #define EC_CMD_DISPLAY_SOC 0x0137 |
| 6909 | |
| 6910 | struct ec_response_display_soc { |
| 6911 | int16_t display_soc; /* Display charge in 10ths of a % (1000=100.0%) */ |
| 6912 | int16_t full_factor; /* Full factor in 10ths of a % (1000=100.0%) */ |
| 6913 | int16_t shutdown_soc; /* Shutdown SoC in 10ths of a % (1000=100.0%) */ |
| 6914 | } __ec_align2; |
| 6915 | |
| 6916 | |
| 6917 | #define EC_CMD_SET_BASE_STATE 0x0138 |
| 6918 | |
| 6919 | struct ec_params_set_base_state { |
| 6920 | uint8_t cmd; /* enum ec_set_base_state_cmd */ |
| 6921 | } __ec_align1; |
| 6922 | |
| 6923 | enum ec_set_base_state_cmd { |
| 6924 | EC_SET_BASE_STATE_DETACH = 0, |
| 6925 | EC_SET_BASE_STATE_ATTACH, |
| 6926 | EC_SET_BASE_STATE_RESET, |
| 6927 | }; |
| 6928 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6929 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6930 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6931 | |
| 6932 | /*****************************************************************************/ |
| 6933 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6934 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6935 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6936 | #define EC_CMD_CR51_BASE 0x0300 |
| 6937 | #define EC_CMD_CR51_LAST 0x03FF |
| 6938 | |
| 6939 | /*****************************************************************************/ |
| 6940 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 6941 | |
| 6942 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 6943 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 6944 | |
| 6945 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 6946 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6947 | struct ec_params_fp_passthru { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6948 | uint16_t len; /* Number of bytes to write then read */ |
| 6949 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 6950 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6951 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6952 | |
| 6953 | /* Configure the Fingerprint MCU behavior */ |
| 6954 | #define EC_CMD_FP_MODE 0x0402 |
| 6955 | |
| 6956 | /* Put the sensor in its lowest power mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6957 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6958 | /* Wait to see a finger on the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6959 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6960 | /* Poll until the finger has left the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6961 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6962 | /* Capture the current finger image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6963 | #define FP_MODE_CAPTURE BIT(3) |
| 6964 | /* Finger enrollment session on-going */ |
| 6965 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 6966 | /* Enroll the current finger image */ |
| 6967 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
| 6968 | /* Try to match the current finger image */ |
| 6969 | #define FP_MODE_MATCH BIT(6) |
| 6970 | /* Reset and re-initialize the sensor. */ |
| 6971 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6972 | /* Sensor maintenance for dead pixels. */ |
| 6973 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6974 | /* special value: don't change anything just read back current mode */ |
| 6975 | #define FP_MODE_DONT_CHANGE BIT(31) |
| 6976 | |
| 6977 | #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ |
| 6978 | FP_MODE_FINGER_DOWN | \ |
| 6979 | FP_MODE_FINGER_UP | \ |
| 6980 | FP_MODE_CAPTURE | \ |
| 6981 | FP_MODE_ENROLL_SESSION | \ |
| 6982 | FP_MODE_ENROLL_IMAGE | \ |
| 6983 | FP_MODE_MATCH | \ |
| 6984 | FP_MODE_RESET_SENSOR | \ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6985 | FP_MODE_SENSOR_MAINTENANCE | \ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6986 | FP_MODE_DONT_CHANGE) |
| 6987 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6988 | /* Capture types defined in bits [30..28] */ |
| 6989 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6990 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
| 6991 | /* |
| 6992 | * This enum must remain ordered, if you add new values you must ensure that |
| 6993 | * FP_CAPTURE_TYPE_MAX is still the last one. |
| 6994 | */ |
| 6995 | enum fp_capture_type { |
| 6996 | /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ |
| 6997 | FP_CAPTURE_VENDOR_FORMAT = 0, |
| 6998 | /* Simple raw image capture (produces width x height x bpp bits) */ |
| 6999 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
| 7000 | /* Self test pattern (e.g. checkerboard) */ |
| 7001 | FP_CAPTURE_PATTERN0 = 2, |
| 7002 | /* Self test pattern (e.g. inverted checkerboard) */ |
| 7003 | FP_CAPTURE_PATTERN1 = 3, |
| 7004 | /* Capture for Quality test with fixed contrast */ |
| 7005 | FP_CAPTURE_QUALITY_TEST = 4, |
| 7006 | /* Capture for pixel reset value test */ |
| 7007 | FP_CAPTURE_RESET_TEST = 5, |
| 7008 | FP_CAPTURE_TYPE_MAX, |
| 7009 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7010 | /* Extracts the capture type from the sensor 'mode' word */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7011 | #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ |
| 7012 | >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7013 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7014 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7015 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7016 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7017 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7018 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7019 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7020 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7021 | |
| 7022 | /* Retrieve Fingerprint sensor information */ |
| 7023 | #define EC_CMD_FP_INFO 0x0403 |
| 7024 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7025 | /* Number of dead pixels detected on the last maintenance */ |
| 7026 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7027 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 7028 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7029 | /* No interrupt from the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7030 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7031 | /* SPI communication error */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7032 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7033 | /* Invalid sensor Hardware ID */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7034 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7035 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7036 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7037 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7038 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7039 | /* Sensor identification */ |
| 7040 | uint32_t vendor_id; |
| 7041 | uint32_t product_id; |
| 7042 | uint32_t model_id; |
| 7043 | uint32_t version; |
| 7044 | /* Image frame characteristics */ |
| 7045 | uint32_t frame_size; |
| 7046 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7047 | uint16_t width; |
| 7048 | uint16_t height; |
| 7049 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7050 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7051 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7053 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7054 | /* Sensor identification */ |
| 7055 | uint32_t vendor_id; |
| 7056 | uint32_t product_id; |
| 7057 | uint32_t model_id; |
| 7058 | uint32_t version; |
| 7059 | /* Image frame characteristics */ |
| 7060 | uint32_t frame_size; |
| 7061 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7062 | uint16_t width; |
| 7063 | uint16_t height; |
| 7064 | uint16_t bpp; |
| 7065 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 7066 | /* Template/finger current information */ |
| 7067 | uint32_t template_size; /* max template size in bytes */ |
| 7068 | uint16_t template_max; /* maximum number of fingers/templates */ |
| 7069 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 7070 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7071 | uint32_t template_version; /* version of the template format */ |
| 7072 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7073 | |
| 7074 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7075 | #define EC_CMD_FP_FRAME 0x0404 |
| 7076 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7077 | /* constants defining the 'offset' field which also contains the frame index */ |
| 7078 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7079 | /* Frame buffer where the captured image is stored */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7080 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7081 | /* First frame buffer holding a template */ |
| 7082 | #define FP_FRAME_INDEX_TEMPLATE 1 |
| 7083 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7084 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
| 7085 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7086 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7087 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7088 | |
| 7089 | /* Constants for encryption parameters */ |
| 7090 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 7091 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 7092 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7093 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7094 | #define FP_CONTEXT_TPM_BYTES 32 |
| 7095 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7096 | /* Constants for positive match parameters. */ |
| 7097 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 7098 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7099 | struct ec_fp_template_encryption_metadata { |
| 7100 | /* |
| 7101 | * Version of the structure format (N=3). |
| 7102 | */ |
| 7103 | uint16_t struct_version; |
| 7104 | /* Reserved bytes, set to 0. */ |
| 7105 | uint16_t reserved; |
| 7106 | /* |
| 7107 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 7108 | * a different one is used for every message. |
| 7109 | */ |
| 7110 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7111 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7112 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 7113 | }; |
| 7114 | |
| 7115 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7116 | /* |
| 7117 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 7118 | * in the high nibble, and the real offset within the frame in |
| 7119 | * FP_FRAME_OFFSET_MASK. |
| 7120 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7121 | uint32_t offset; |
| 7122 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7123 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7124 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7125 | /* Load a template into the MCU */ |
| 7126 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 7127 | |
| 7128 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 7129 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 7130 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7131 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7132 | uint32_t offset; |
| 7133 | uint32_t size; |
| 7134 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7135 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7136 | |
| 7137 | /* Clear the current fingerprint user context and set a new one */ |
| 7138 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 7139 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7140 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7141 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7142 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7143 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7144 | enum fp_context_action { |
| 7145 | FP_CONTEXT_ASYNC = 0, |
| 7146 | FP_CONTEXT_GET_RESULT = 1, |
| 7147 | }; |
| 7148 | |
| 7149 | /* Version 1 of the command is "asynchronous". */ |
| 7150 | struct ec_params_fp_context_v1 { |
| 7151 | uint8_t action; /**< enum fp_context_action */ |
| 7152 | uint8_t reserved[3]; /**< padding for alignment */ |
| 7153 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 7154 | } __ec_align4; |
| 7155 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7156 | #define EC_CMD_FP_STATS 0x0407 |
| 7157 | |
| 7158 | #define FPSTATS_CAPTURE_INV BIT(0) |
| 7159 | #define FPSTATS_MATCHING_INV BIT(1) |
| 7160 | |
| 7161 | struct ec_response_fp_stats { |
| 7162 | uint32_t capture_time_us; |
| 7163 | uint32_t matching_time_us; |
| 7164 | uint32_t overall_time_us; |
| 7165 | struct { |
| 7166 | uint32_t lo; |
| 7167 | uint32_t hi; |
| 7168 | } overall_t0; |
| 7169 | uint8_t timestamps_invalid; |
| 7170 | int8_t template_matched; |
| 7171 | } __ec_align2; |
| 7172 | |
| 7173 | #define EC_CMD_FP_SEED 0x0408 |
| 7174 | struct ec_params_fp_seed { |
| 7175 | /* |
| 7176 | * Version of the structure format (N=3). |
| 7177 | */ |
| 7178 | uint16_t struct_version; |
| 7179 | /* Reserved bytes, set to 0. */ |
| 7180 | uint16_t reserved; |
| 7181 | /* Seed from the TPM. */ |
| 7182 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 7183 | } __ec_align4; |
| 7184 | |
| 7185 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 7186 | |
| 7187 | /* FP TPM seed has been set or not */ |
| 7188 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 7189 | |
| 7190 | struct ec_response_fp_encryption_status { |
| 7191 | /* Used bits in encryption engine status */ |
| 7192 | uint32_t valid_flags; |
| 7193 | /* Encryption engine status */ |
| 7194 | uint32_t status; |
| 7195 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7196 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7197 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 7198 | struct ec_params_fp_read_match_secret { |
| 7199 | uint16_t fgr; |
| 7200 | } __ec_align4; |
| 7201 | |
| 7202 | /* The positive match secret has the length of the SHA256 digest. */ |
| 7203 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 7204 | struct ec_response_fp_read_match_secret { |
| 7205 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 7206 | } __ec_align4; |
| 7207 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7208 | /*****************************************************************************/ |
| 7209 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 7210 | |
| 7211 | /* Perform touchpad self test */ |
| 7212 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 7213 | |
| 7214 | /* Get number of frame types, and the size of each type */ |
| 7215 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 7216 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7217 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7218 | uint32_t n_frames; |
| 7219 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7220 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7221 | |
| 7222 | /* Create a snapshot of current frame readings */ |
| 7223 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 7224 | |
| 7225 | /* Read the frame */ |
| 7226 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 7227 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7228 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7229 | uint32_t frame_index; |
| 7230 | uint32_t offset; |
| 7231 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7232 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7233 | |
| 7234 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7235 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 7236 | |
| 7237 | #define EC_COMM_TEXT_MAX 8 |
| 7238 | |
| 7239 | /* |
| 7240 | * Get battery static information, i.e. information that never changes, or |
| 7241 | * very infrequently. |
| 7242 | */ |
| 7243 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 7244 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7245 | /** |
| 7246 | * struct ec_params_battery_static_info - Battery static info parameters |
| 7247 | * @index: Battery index. |
| 7248 | */ |
| 7249 | struct ec_params_battery_static_info { |
| 7250 | uint8_t index; |
| 7251 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7252 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7253 | /** |
| 7254 | * struct ec_response_battery_static_info - Battery static info response |
| 7255 | * @design_capacity: Battery Design Capacity (mAh) |
| 7256 | * @design_voltage: Battery Design Voltage (mV) |
| 7257 | * @manufacturer: Battery Manufacturer String |
| 7258 | * @model: Battery Model Number String |
| 7259 | * @serial: Battery Serial Number String |
| 7260 | * @type: Battery Type String |
| 7261 | * @cycle_count: Battery Cycle Count |
| 7262 | */ |
| 7263 | struct ec_response_battery_static_info { |
| 7264 | uint16_t design_capacity; |
| 7265 | uint16_t design_voltage; |
| 7266 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 7267 | char model[EC_COMM_TEXT_MAX]; |
| 7268 | char serial[EC_COMM_TEXT_MAX]; |
| 7269 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7270 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7271 | uint32_t cycle_count; |
| 7272 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7273 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7274 | /** |
| 7275 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 7276 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 7277 | * strings. |
| 7278 | * @design_capacity: battery design capacity (in mAh) |
| 7279 | * @design_voltage: battery design voltage (in mV) |
| 7280 | * @cycle_count: battery cycle count |
| 7281 | * @manufacturer_ext: battery manufacturer string |
| 7282 | * @model_ext: battery model string |
| 7283 | * @serial_ext: battery serial number string |
| 7284 | * @type_ext: battery type string |
| 7285 | */ |
| 7286 | struct ec_response_battery_static_info_v1 { |
| 7287 | uint16_t design_capacity; |
| 7288 | uint16_t design_voltage; |
| 7289 | uint32_t cycle_count; |
| 7290 | char manufacturer_ext[12]; |
| 7291 | char model_ext[12]; |
| 7292 | char serial_ext[12]; |
| 7293 | char type_ext[12]; |
| 7294 | } __ec_align4; |
| 7295 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7296 | /* |
| 7297 | * Get battery dynamic information, i.e. information that is likely to change |
| 7298 | * every time it is read. |
| 7299 | */ |
| 7300 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 7301 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7302 | /** |
| 7303 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 7304 | * @index: Battery index. |
| 7305 | */ |
| 7306 | struct ec_params_battery_dynamic_info { |
| 7307 | uint8_t index; |
| 7308 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7309 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7310 | /** |
| 7311 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 7312 | * @actual_voltage: Battery voltage (mV) |
| 7313 | * @actual_current: Battery current (mA); negative=discharging |
| 7314 | * @remaining_capacity: Remaining capacity (mAh) |
| 7315 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 7316 | * @flags: Flags, see EC_BATT_FLAG_* |
| 7317 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 7318 | * @desired_current: Charging current desired by battery (mA) |
| 7319 | */ |
| 7320 | struct ec_response_battery_dynamic_info { |
| 7321 | int16_t actual_voltage; |
| 7322 | int16_t actual_current; |
| 7323 | int16_t remaining_capacity; |
| 7324 | int16_t full_capacity; |
| 7325 | int16_t flags; |
| 7326 | int16_t desired_voltage; |
| 7327 | int16_t desired_current; |
| 7328 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7329 | |
| 7330 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame^] | 7331 | * Control charger chip. Used to control charger chip on the peripheral. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7332 | */ |
| 7333 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 7334 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7335 | /** |
| 7336 | * struct ec_params_charger_control - Charger control parameters |
| 7337 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 7338 | * max_current and (possibly) charge battery, negative to request current |
| 7339 | * from base (OTG). |
| 7340 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 7341 | * >= 0. |
| 7342 | * @allow_charging: Allow base battery charging (only makes sense if |
| 7343 | * max_current > 0). |
| 7344 | */ |
| 7345 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7346 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7347 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7348 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7349 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7350 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7351 | /* Get ACK from the USB-C SS muxes */ |
| 7352 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 7353 | |
| 7354 | struct ec_params_usb_pd_mux_ack { |
| 7355 | uint8_t port; /* USB-C port number */ |
| 7356 | } __ec_align1; |
| 7357 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7358 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7359 | /* |
| 7360 | * Reserve a range of host commands for board-specific, experimental, or |
| 7361 | * special purpose features. These can be (re)used without updating this file. |
| 7362 | * |
| 7363 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 7364 | * their EC commands for easier development, testing, debugging, and support. |
| 7365 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7366 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 7367 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 7368 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7369 | * In your experimental code, you may want to do something like this: |
| 7370 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7371 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 7372 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 7373 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 7374 | * |
| 7375 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 7376 | * EC_VER_MASK(0); |
| 7377 | * |
| 7378 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 7379 | * EC_VER_MASK(0); |
| 7380 | * |
| 7381 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 7382 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7383 | */ |
| 7384 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 7385 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 7386 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7387 | /* |
| 7388 | * Given the private host command offset, calculate the true private host |
| 7389 | * command value. |
| 7390 | */ |
| 7391 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 7392 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 7393 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7394 | /*****************************************************************************/ |
| 7395 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 7396 | * Passthru commands |
| 7397 | * |
| 7398 | * Some platforms have sub-processors chained to each other. For example. |
| 7399 | * |
| 7400 | * AP <--> EC <--> PD MCU |
| 7401 | * |
| 7402 | * The top 2 bits of the command number are used to indicate which device the |
| 7403 | * command is intended for. Device 0 is always the device receiving the |
| 7404 | * command; other device mapping is board-specific. |
| 7405 | * |
| 7406 | * When a device receives a command to be passed to a sub-processor, it passes |
| 7407 | * it on with the device number set back to 0. This allows the sub-processor |
| 7408 | * to remain blissfully unaware of whether the command originated on the next |
| 7409 | * device up the chain, or was passed through from the AP. |
| 7410 | * |
| 7411 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 7412 | * AP sends command 0x4002 to the EC |
| 7413 | * EC sends command 0x0002 to the PD MCU |
| 7414 | * EC forwards PD MCU response back to the AP |
| 7415 | */ |
| 7416 | |
| 7417 | /* Offset and max command number for sub-device n */ |
| 7418 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 7419 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 7420 | |
| 7421 | /*****************************************************************************/ |
| 7422 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7423 | * Deprecated constants. These constants have been renamed for clarity. The |
| 7424 | * meaning and size has not changed. Programs that use the old names should |
| 7425 | * switch to the new names soon, as the old names may not be carried forward |
| 7426 | * forever. |
| 7427 | */ |
| 7428 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 7429 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 7430 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 7431 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7432 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7433 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7434 | #ifdef __cplusplus |
| 7435 | } |
| 7436 | #endif |
| 7437 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7438 | #endif /* __CROS_EC_EC_COMMANDS_H */ |