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 */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 180 | #define EC_TEMP_SENSOR_ENTRIES 16 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 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 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 188 | /* Max temp sensor entries for host commands */ |
| 189 | #define EC_MAX_TEMP_SENSOR_ENTRIES (EC_TEMP_SENSOR_ENTRIES + \ |
| 190 | EC_TEMP_SENSOR_B_ENTRIES) |
| 191 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 192 | /* Special values for mapped temperature sensors */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 193 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 194 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 195 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 196 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 197 | /* |
| 198 | * The offset of temperature value stored in mapped memory. This allows |
| 199 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 200 | */ |
| 201 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 202 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 203 | /* |
| 204 | * Number of ALS readings at EC_MEMMAP_ALS |
| 205 | */ |
| 206 | #define EC_ALS_ENTRIES 2 |
| 207 | |
| 208 | /* |
| 209 | * The default value a temperature sensor will return when it is present but |
| 210 | * has not been read this boot. This is a reasonable number to avoid |
| 211 | * triggering alarms on the host. |
| 212 | */ |
| 213 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 214 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 215 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 216 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 217 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 218 | |
| 219 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 220 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 221 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 222 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 223 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 224 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 225 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 226 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 227 | |
| 228 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 229 | #define EC_SWITCH_LID_OPEN 0x01 |
| 230 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 231 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 232 | /* Was recovery requested via keyboard; now unused. */ |
| 233 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 234 | /* Recovery requested via dedicated signal (from servo board) */ |
| 235 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 236 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 237 | #define EC_SWITCH_IGNORE0 0x20 |
| 238 | |
| 239 | /* Host command interface flags */ |
| 240 | /* Host command interface supports LPC args (LPC interface only) */ |
| 241 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 242 | /* Host command interface supports version 3 protocol */ |
| 243 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 244 | |
| 245 | /* Wireless switch flags */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 246 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 247 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 248 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 249 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 250 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 251 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 252 | /*****************************************************************************/ |
| 253 | /* |
| 254 | * ACPI commands |
| 255 | * |
| 256 | * These are valid ONLY on the ACPI command/data port. |
| 257 | */ |
| 258 | |
| 259 | /* |
| 260 | * ACPI Read Embedded Controller |
| 261 | * |
| 262 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 263 | * |
| 264 | * Use the following sequence: |
| 265 | * |
| 266 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 267 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 268 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 269 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 270 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 271 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 272 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * ACPI Write Embedded Controller |
| 276 | * |
| 277 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 278 | * |
| 279 | * Use the following sequence: |
| 280 | * |
| 281 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 282 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 283 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 284 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 285 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 286 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 287 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 288 | |
| 289 | /* |
| 290 | * ACPI Burst Enable Embedded Controller |
| 291 | * |
| 292 | * This enables burst mode on the EC to allow the host to issue several |
| 293 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 294 | * data are locked out to ensure data consistency. |
| 295 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 296 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * ACPI Burst Disable Embedded Controller |
| 300 | * |
| 301 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 302 | * multi-byte data. |
| 303 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 304 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * ACPI Query Embedded Controller |
| 308 | * |
| 309 | * This clears the lowest-order bit in the currently pending host events, and |
| 310 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 311 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 312 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 313 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 314 | |
| 315 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 316 | |
| 317 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 318 | #define EC_ACPI_MEM_VERSION 0x00 |
| 319 | /* |
| 320 | * Test location; writing value here updates test compliment byte to (0xff - |
| 321 | * value). |
| 322 | */ |
| 323 | #define EC_ACPI_MEM_TEST 0x01 |
| 324 | /* Test compliment; writes here are ignored. */ |
| 325 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
| 326 | |
| 327 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 328 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 329 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 330 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 331 | |
| 332 | /* |
| 333 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 334 | * independent thresholds attached to them. The current value of the ID |
| 335 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 336 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 337 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 338 | * |
| 339 | * The spec does not mandate any way to read back the threshold settings |
| 340 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 341 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 342 | * returns one sensor ID that has crossed one of its threshold (in either |
| 343 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 344 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 345 | * the unread event count for that sensor. |
| 346 | */ |
| 347 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 348 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 349 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 350 | /* |
| 351 | * Here are the bits for the COMMIT register: |
| 352 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 353 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 354 | * Each write to the commit register affects one threshold. |
| 355 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 356 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 357 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 358 | /* |
| 359 | * Example: |
| 360 | * |
| 361 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 362 | * write 2 to [0x05] -- select temp sensor 2 |
| 363 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 364 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 365 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 366 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 367 | * |
| 368 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 369 | * write 2 to [0x05] -- select temp sensor 2 |
| 370 | * write 0x1 to [0x07] -- disable threshold 1 |
| 371 | */ |
| 372 | |
| 373 | /* DPTF battery charging current limit */ |
| 374 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 375 | |
| 376 | /* Charging limit is specified in 64 mA steps */ |
| 377 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 378 | /* Value to disable DPTF battery charging limit */ |
| 379 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 380 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 381 | /* |
| 382 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 383 | * Bits Definition |
| 384 | * 3:1 Device DPTF Profile Number (DDPN) |
| 385 | * 0 = Reserved for backward compatibility (indicates no valid |
| 386 | * profile number. Host should fall back to using TBMD). |
| 387 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 388 | * to be loaded. |
| 389 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 390 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 391 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 392 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 393 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 394 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 395 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 396 | |
| 397 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 398 | * Report device features. Uses the same format as the host command, except: |
| 399 | * |
| 400 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 401 | * of features", which is of limited interest when the system is already |
| 402 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 403 | * these are supported, it defaults to 0. |
| 404 | * This allows detecting the presence of this field since older versions of |
| 405 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 406 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 407 | * are valid. |
| 408 | */ |
| 409 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 410 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 411 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 412 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 413 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 414 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 415 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 416 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 417 | |
| 418 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
| 419 | |
| 420 | /* |
| 421 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 422 | * is enabled (1) or disabled (0). |
| 423 | * bit 0 USB port ID 0 |
| 424 | * ... |
| 425 | * bit 7 USB port ID 7 |
| 426 | */ |
| 427 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 428 | |
| 429 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 430 | * USB Retimer firmware update. |
| 431 | * Read: |
| 432 | * Result of last operation AP requested |
| 433 | * Write: |
| 434 | * bits[3:0]: USB-C port number |
| 435 | * bits[7:4]: Operation requested by AP |
| 436 | * |
| 437 | * NDA (no device attached) case: |
| 438 | * To update retimer firmware, AP needs set up TBT Alt mode. |
| 439 | * AP requests operations in this sequence: |
| 440 | * 1. Get port information about which ports support retimer firmware update. |
| 441 | * In the query result, each bit represents one port. |
| 442 | * 2. Get current MUX mode, it's NDA. |
| 443 | * 3. Suspend specified PD port's task. |
| 444 | * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode -> |
| 445 | * update firmware -> disconnect MUX -> resume PD task. |
| 446 | * |
| 447 | * DA (device attached) cases: |
| 448 | * Retimer firmware update is not supported in DA cases. |
| 449 | * 1. Get port information about which ports support retimer firmware update |
| 450 | * 2. Get current MUX mode, it's DA. |
| 451 | * 3. AP continues. No more retimer firmware update activities. |
| 452 | * |
| 453 | */ |
| 454 | #define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14 |
| 455 | |
| 456 | #define USB_RETIMER_FW_UPDATE_OP_SHIFT 4 |
| 457 | #define USB_RETIMER_FW_UPDATE_ERR 0xfe |
| 458 | #define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 459 | /* Mask to clear unused MUX bits in retimer firmware update */ |
| 460 | #define USB_RETIMER_FW_UPDATE_MUX_MASK (USB_PD_MUX_USB_ENABLED | \ |
| 461 | USB_PD_MUX_DP_ENABLED | \ |
| 462 | USB_PD_MUX_SAFE_MODE | \ |
| 463 | USB_PD_MUX_TBT_COMPAT_ENABLED | \ |
| 464 | USB_PD_MUX_USB4_ENABLED) |
| 465 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 466 | /* Retimer firmware update operations */ |
| 467 | #define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */ |
| 468 | #define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */ |
| 469 | #define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */ |
| 470 | #define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */ |
| 471 | #define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */ |
| 472 | #define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */ |
| 473 | #define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */ |
| 474 | #define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */ |
| 475 | |
| 476 | #define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f) |
| 477 | #define EC_ACPI_MEM_USB_RETIMER_OP(x) \ |
| 478 | (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT) |
| 479 | |
| 480 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 481 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 482 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 483 | */ |
| 484 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 485 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 486 | |
| 487 | /* Current version of ACPI memory address space */ |
| 488 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 489 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 490 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 491 | /* |
| 492 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 493 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 494 | * handle actual C code so keep it separate. |
| 495 | */ |
| 496 | #ifndef __ACPI__ |
| 497 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 498 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 499 | /* |
| 500 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 501 | * checking prefers __packed over __attribute__((packed)). |
| 502 | */ |
| 503 | #ifndef __packed |
| 504 | #define __packed __attribute__((packed)) |
| 505 | #endif |
| 506 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 507 | #ifndef __aligned |
| 508 | #define __aligned(x) __attribute__((aligned(x))) |
| 509 | #endif |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 510 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * Attributes for EC request and response packets. Just defining __packed |
| 514 | * results in inefficient assembly code on ARM, if the structure is actually |
| 515 | * 32-bit aligned, as it should be for all buffers. |
| 516 | * |
| 517 | * Be very careful when adding these to existing structures. They will round |
| 518 | * up the structure size to the specified boundary. |
| 519 | * |
| 520 | * Also be very careful to make that if a structure is included in some other |
| 521 | * parent structure that the alignment will still be true given the packing of |
| 522 | * the parent structure. This is particularly important if the sub-structure |
| 523 | * 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] | 524 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 525 | * |
| 526 | * Also be very careful using __packed - particularly when nesting non-packed |
| 527 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 528 | * always use one of these attributes. |
| 529 | * |
| 530 | * Once everything is annotated properly, the following search strings should |
| 531 | * not return ANY matches in this file other than right here: |
| 532 | * |
| 533 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 534 | * |
| 535 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 536 | * members of other structs/unions (and their original declarations should be |
| 537 | * annotated). |
| 538 | */ |
| 539 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 540 | |
| 541 | /* |
| 542 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 543 | * byte boundary. |
| 544 | */ |
| 545 | #define __ec_align1 __packed |
| 546 | #define __ec_align2 __packed __aligned(2) |
| 547 | #define __ec_align4 __packed __aligned(4) |
| 548 | |
| 549 | /* |
| 550 | * Packed structure which must be under-aligned, because its size is not a |
| 551 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 552 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 553 | * |
| 554 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 555 | * its members, but use the __packed version for sizeof(). |
| 556 | */ |
| 557 | #define __ec_align_size1 __packed |
| 558 | |
| 559 | /* |
| 560 | * Packed structure which must be under-aligned, because its offset inside a |
| 561 | * parent structure is not a 4-byte multiple. |
| 562 | */ |
| 563 | #define __ec_align_offset1 __packed |
| 564 | #define __ec_align_offset2 __packed __aligned(2) |
| 565 | |
| 566 | /* |
| 567 | * Structures which are complicated enough that I'm skipping them on the first |
| 568 | * pass. They are effectively unchanged from their previous definitions. |
| 569 | * |
| 570 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 571 | * to work out the size and offset of each member and add explicit padding to |
| 572 | * maintain those. |
| 573 | */ |
| 574 | #define __ec_todo_packed __packed |
| 575 | #define __ec_todo_unpacked |
| 576 | |
| 577 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
| 578 | |
| 579 | /* |
| 580 | * Packed structures make no assumption about alignment, so they do inefficient |
| 581 | * byte-wise reads. |
| 582 | */ |
| 583 | #define __ec_align1 __packed |
| 584 | #define __ec_align2 __packed |
| 585 | #define __ec_align4 __packed |
| 586 | #define __ec_align_size1 __packed |
| 587 | #define __ec_align_offset1 __packed |
| 588 | #define __ec_align_offset2 __packed |
| 589 | #define __ec_todo_packed __packed |
| 590 | #define __ec_todo_unpacked |
| 591 | |
| 592 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
| 593 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 594 | /* LPC command status byte masks */ |
| 595 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 596 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 597 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 598 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 599 | /* EC is processing a command */ |
| 600 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 601 | /* Last write to EC was a command, not data */ |
| 602 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 603 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 604 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 605 | /* SCI event is pending (requesting SCI query) */ |
| 606 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 607 | /* SMI event is pending (requesting SMI query) */ |
| 608 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 609 | /* (reserved) */ |
| 610 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 611 | |
| 612 | /* |
| 613 | * EC is busy. This covers both the EC processing a command, and the host has |
| 614 | * written a new command but the EC hasn't picked it up yet. |
| 615 | */ |
| 616 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 617 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 618 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 619 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 620 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 621 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 622 | enum ec_status { |
| 623 | EC_RES_SUCCESS = 0, |
| 624 | EC_RES_INVALID_COMMAND = 1, |
| 625 | EC_RES_ERROR = 2, |
| 626 | EC_RES_INVALID_PARAM = 3, |
| 627 | EC_RES_ACCESS_DENIED = 4, |
| 628 | EC_RES_INVALID_RESPONSE = 5, |
| 629 | EC_RES_INVALID_VERSION = 6, |
| 630 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 631 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 632 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 633 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 634 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 635 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 636 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 637 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 638 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 639 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 640 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 641 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 642 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 643 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 644 | |
| 645 | EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ |
| 646 | } __packed; |
| 647 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 648 | |
| 649 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 650 | * Host event codes. ACPI query EC command uses code 0 to mean "no event |
| 651 | * pending". We explicitly specify each value in the enum listing so they won't |
| 652 | * change if we delete/insert an item or rearrange the list (it needs to be |
| 653 | * stable across platforms, not just within a single compiled instance). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 654 | */ |
| 655 | enum host_event_code { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 656 | EC_HOST_EVENT_NONE = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 657 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 658 | EC_HOST_EVENT_LID_OPEN = 2, |
| 659 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 660 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 661 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 662 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 663 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 664 | EC_HOST_EVENT_BATTERY = 8, |
| 665 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 666 | /* Event generated by a device attached to the EC */ |
| 667 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 668 | EC_HOST_EVENT_THERMAL = 11, |
| 669 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 670 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 671 | /* |
| 672 | * EC has finished initializing the host interface. The host can check |
| 673 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 674 | * determine when the EC is ready to accept subsequent commands. |
| 675 | */ |
| 676 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 677 | /* Keyboard recovery combo has been pressed */ |
| 678 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 679 | |
| 680 | /* Shutdown due to thermal overload */ |
| 681 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 682 | /* Shutdown due to battery level too low */ |
| 683 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 684 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 685 | /* Suggest that the AP throttle itself */ |
| 686 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 687 | /* Suggest that the AP resume normal speed */ |
| 688 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 689 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 690 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 691 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 692 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 693 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 694 | |
| 695 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 696 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 697 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 698 | /* Battery Status flags have changed */ |
| 699 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 700 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 701 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 702 | EC_HOST_EVENT_PANIC = 24, |
| 703 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 704 | /* Keyboard fastboot combo has been pressed */ |
| 705 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 706 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 707 | /* EC RTC event occurred */ |
| 708 | EC_HOST_EVENT_RTC = 26, |
| 709 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 710 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 711 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 712 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 713 | /* EC desires to change state of host-controlled USB mux */ |
| 714 | EC_HOST_EVENT_USB_MUX = 28, |
| 715 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 716 | /* |
| 717 | * The device has changed "modes". This can be one of the following: |
| 718 | * |
| 719 | * - TABLET/LAPTOP mode |
| 720 | * - detachable base attach/detach event |
| 721 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 722 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 723 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 724 | /* Keyboard recovery combo with hardware reinitialization */ |
| 725 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 726 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 727 | /* WoV */ |
| 728 | EC_HOST_EVENT_WOV = 31, |
| 729 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 730 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 731 | * The high bit of the event mask is not used as a host event code. If |
| 732 | * it reads back as set, then the entire event mask should be |
| 733 | * considered invalid by the host. This can happen when reading the |
| 734 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 735 | * not initialized on the EC, or improperly configured on the host. |
| 736 | */ |
| 737 | EC_HOST_EVENT_INVALID = 32 |
| 738 | }; |
| 739 | /* Host event mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 740 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 741 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 742 | /** |
| 743 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 744 | * @flags: The host argument flags. |
| 745 | * @command_version: Command version. |
| 746 | * @data_size: The length of data. |
| 747 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 748 | * all params/response data bytes. |
| 749 | */ |
| 750 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 751 | uint8_t flags; |
| 752 | uint8_t command_version; |
| 753 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 754 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 755 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 756 | |
| 757 | /* Flags for ec_lpc_host_args.flags */ |
| 758 | /* |
| 759 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 760 | * params. |
| 761 | * |
| 762 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 763 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 764 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 765 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 766 | */ |
| 767 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 768 | /* |
| 769 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 770 | * |
| 771 | * If EC responds to a command and this flag is not set, this is an old-style |
| 772 | * response. Command version is 0 and response data from EC is at |
| 773 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 774 | */ |
| 775 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 776 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 777 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 778 | /* |
| 779 | * Byte codes returned by EC over SPI interface. |
| 780 | * |
| 781 | * These can be used by the AP to debug the EC interface, and to determine |
| 782 | * when the EC is not in a state where it will ever get around to responding |
| 783 | * to the AP. |
| 784 | * |
| 785 | * Example of sequence of bytes read from EC for a current good transfer: |
| 786 | * 1. - - AP asserts chip select (CS#) |
| 787 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 788 | * 3. - - EC starts handling CS# interrupt |
| 789 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 790 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 791 | * bytes looking for EC_SPI_FRAME_START |
| 792 | * 6. - - EC finishes processing and sets up response |
| 793 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 794 | * 8. (response packet) - AP reads response packet |
| 795 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 796 | * 10 - - AP deasserts chip select |
| 797 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 798 | * next request |
| 799 | * |
| 800 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 801 | * the following byte values: |
| 802 | * EC_SPI_OLD_READY |
| 803 | * EC_SPI_RX_READY |
| 804 | * EC_SPI_RECEIVING |
| 805 | * EC_SPI_PROCESSING |
| 806 | * |
| 807 | * Then the EC found an error in the request, or was not ready for the request |
| 808 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 809 | * because the EC is unable to tell when the AP is done sending its request. |
| 810 | */ |
| 811 | |
| 812 | /* |
| 813 | * Framing byte which precedes a response packet from the EC. After sending a |
| 814 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 815 | * clock in the response packet. |
| 816 | */ |
| 817 | #define EC_SPI_FRAME_START 0xec |
| 818 | |
| 819 | /* |
| 820 | * Padding bytes which are clocked out after the end of a response packet. |
| 821 | */ |
| 822 | #define EC_SPI_PAST_END 0xed |
| 823 | |
| 824 | /* |
| 825 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 826 | * that the AP will send a valid packet header (starting with |
| 827 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 828 | */ |
| 829 | #define EC_SPI_RX_READY 0xf8 |
| 830 | |
| 831 | /* |
| 832 | * EC has started receiving the request from the AP, but hasn't started |
| 833 | * processing it yet. |
| 834 | */ |
| 835 | #define EC_SPI_RECEIVING 0xf9 |
| 836 | |
| 837 | /* EC has received the entire request from the AP and is processing it. */ |
| 838 | #define EC_SPI_PROCESSING 0xfa |
| 839 | |
| 840 | /* |
| 841 | * EC received bad data from the AP, such as a packet header with an invalid |
| 842 | * length. EC will ignore all data until chip select deasserts. |
| 843 | */ |
| 844 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 845 | |
| 846 | /* |
| 847 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 848 | * chip select and started clocking data before the EC was ready to receive it. |
| 849 | * EC will ignore all data until chip select deasserts. |
| 850 | */ |
| 851 | #define EC_SPI_NOT_READY 0xfc |
| 852 | |
| 853 | /* |
| 854 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 855 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 856 | * a fully received packet but is not ready to respond yet. |
| 857 | */ |
| 858 | #define EC_SPI_OLD_READY 0xfd |
| 859 | |
| 860 | /*****************************************************************************/ |
| 861 | |
| 862 | /* |
| 863 | * Protocol version 2 for I2C and SPI send a request this way: |
| 864 | * |
| 865 | * 0 EC_CMD_VERSION0 + (command version) |
| 866 | * 1 Command number |
| 867 | * 2 Length of params = N |
| 868 | * 3..N+2 Params, if any |
| 869 | * N+3 8-bit checksum of bytes 0..N+2 |
| 870 | * |
| 871 | * The corresponding response is: |
| 872 | * |
| 873 | * 0 Result code (EC_RES_*) |
| 874 | * 1 Length of params = M |
| 875 | * 2..M+1 Params, if any |
| 876 | * M+2 8-bit checksum of bytes 0..M+1 |
| 877 | */ |
| 878 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 879 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 880 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 881 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 882 | |
| 883 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 884 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 885 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 886 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 887 | |
| 888 | /* Parameter length was limited by the LPC interface */ |
| 889 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 890 | |
| 891 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 892 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 893 | EC_PROTO2_MAX_PARAM_SIZE) |
| 894 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 895 | EC_PROTO2_MAX_PARAM_SIZE) |
| 896 | |
| 897 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 898 | |
| 899 | /* |
| 900 | * Value written to legacy command port / prefix byte to indicate protocol |
| 901 | * 3+ structs are being used. Usage is bus-dependent. |
| 902 | */ |
| 903 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 904 | |
| 905 | #define EC_HOST_REQUEST_VERSION 3 |
| 906 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 907 | /** |
| 908 | * struct ec_host_request - Version 3 request from host. |
| 909 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 910 | * receives a header with a version it doesn't know how to |
| 911 | * parse. |
| 912 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 913 | * should total to 0. |
| 914 | * @command: Command to send (EC_CMD_...) |
| 915 | * @command_version: Command version. |
| 916 | * @reserved: Unused byte in current protocol version; set to 0. |
| 917 | * @data_len: Length of data which follows this header. |
| 918 | */ |
| 919 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 920 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 921 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 922 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 923 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 924 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 925 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 926 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 927 | |
| 928 | #define EC_HOST_RESPONSE_VERSION 3 |
| 929 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 930 | /** |
| 931 | * struct ec_host_response - Version 3 response from EC. |
| 932 | * @struct_version: Struct version (=3). |
| 933 | * @checksum: Checksum of response and data; sum of all bytes including |
| 934 | * checksum should total to 0. |
| 935 | * @result: EC's response to the command (separate from communication failure) |
| 936 | * @data_len: Length of data which follows this header. |
| 937 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 938 | */ |
| 939 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 940 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 941 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 942 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 943 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 944 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 945 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 946 | |
| 947 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 948 | |
| 949 | /* |
| 950 | * Host command protocol V4. |
| 951 | * |
| 952 | * Packets always start with a request or response header. They are followed |
| 953 | * 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] | 954 | * 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] | 955 | * polynomial. |
| 956 | * |
| 957 | * Host algorithm when sending a request q: |
| 958 | * |
| 959 | * 101) tries_left=(some value, e.g. 3); |
| 960 | * 102) q.seq_num++ |
| 961 | * 103) q.seq_dup=0 |
| 962 | * 104) Calculate q.header_crc. |
| 963 | * 105) Send request q to EC. |
| 964 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 965 | * |
| 966 | * 201) If r.struct_version != 4, go to 301. |
| 967 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 968 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 969 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 970 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 971 | * 207) If r.seq_dup == 1, go to 301. |
| 972 | * 208) Return error. |
| 973 | * |
| 974 | * 301) If --tries_left <= 0, return error. |
| 975 | * 302) If q.seq_dup == 1, go to 105. |
| 976 | * 303) q.seq_dup = 1 |
| 977 | * 304) Go to 104. |
| 978 | * |
| 979 | * EC algorithm when receiving a request q. |
| 980 | * EC has response buffer r, error buffer e. |
| 981 | * |
| 982 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 983 | * and go to 301 |
| 984 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 985 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 986 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 987 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 988 | * and go to 301. |
| 989 | * 104) If q.seq_dup == 0, go to 201. |
| 990 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 991 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 992 | * |
| 993 | * 201) Process request q into response r. |
| 994 | * 202) r.seq_num = q.seq_num |
| 995 | * 203) r.seq_dup = q.seq_dup |
| 996 | * 204) Calculate r.header_crc |
| 997 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 998 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 999 | * 206) Send response r. |
| 1000 | * |
| 1001 | * 301) e.seq_num = q.seq_num |
| 1002 | * 302) e.seq_dup = q.seq_dup |
| 1003 | * 303) Calculate e.header_crc. |
| 1004 | * 304) Send error response e. |
| 1005 | */ |
| 1006 | |
| 1007 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1008 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1009 | /* |
| 1010 | * bits 0-3: struct_version: Structure version (=4) |
| 1011 | * bit 4: is_response: Is response (=0) |
| 1012 | * bits 5-6: seq_num: Sequence number |
| 1013 | * bit 7: seq_dup: Sequence duplicate flag |
| 1014 | */ |
| 1015 | uint8_t fields0; |
| 1016 | |
| 1017 | /* |
| 1018 | * bits 0-4: command_version: Command version |
| 1019 | * bits 5-6: Reserved (set 0, ignore on read) |
| 1020 | * bit 7: data_crc_present: Is data CRC present after data |
| 1021 | */ |
| 1022 | uint8_t fields1; |
| 1023 | |
| 1024 | /* Command code (EC_CMD_*) */ |
| 1025 | uint16_t command; |
| 1026 | |
| 1027 | /* Length of data which follows this header (not including data CRC) */ |
| 1028 | uint16_t data_len; |
| 1029 | |
| 1030 | /* Reserved (set 0, ignore on read) */ |
| 1031 | uint8_t reserved; |
| 1032 | |
| 1033 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1034 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1035 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1036 | |
| 1037 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1038 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1039 | /* |
| 1040 | * bits 0-3: struct_version: Structure version (=4) |
| 1041 | * bit 4: is_response: Is response (=1) |
| 1042 | * bits 5-6: seq_num: Sequence number |
| 1043 | * bit 7: seq_dup: Sequence duplicate flag |
| 1044 | */ |
| 1045 | uint8_t fields0; |
| 1046 | |
| 1047 | /* |
| 1048 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1049 | * bit 7: data_crc_present: Is data CRC present after data |
| 1050 | */ |
| 1051 | uint8_t fields1; |
| 1052 | |
| 1053 | /* Result code (EC_RES_*) */ |
| 1054 | uint16_t result; |
| 1055 | |
| 1056 | /* Length of data which follows this header (not including data CRC) */ |
| 1057 | uint16_t data_len; |
| 1058 | |
| 1059 | /* Reserved (set 0, ignore on read) */ |
| 1060 | uint8_t reserved; |
| 1061 | |
| 1062 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1063 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1064 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1065 | |
| 1066 | /* Fields in fields0 byte */ |
| 1067 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1068 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1069 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1070 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1071 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
| 1072 | |
| 1073 | /* Fields in fields1 byte */ |
| 1074 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1075 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
| 1076 | |
| 1077 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1078 | /* |
| 1079 | * Notes on commands: |
| 1080 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1081 | * 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] | 1082 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1083 | * specified, the command does not input or output data, respectively. |
| 1084 | * Parameter/response length is implicit in the structs. Some underlying |
| 1085 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1086 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1087 | * |
| 1088 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1089 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1090 | */ |
| 1091 | |
| 1092 | /*****************************************************************************/ |
| 1093 | /* General / test commands */ |
| 1094 | |
| 1095 | /* |
| 1096 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1097 | * changes. |
| 1098 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1099 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1100 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1101 | /** |
| 1102 | * struct ec_response_proto_version - Response to the proto version command. |
| 1103 | * @version: The protocol version. |
| 1104 | */ |
| 1105 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1106 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1107 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1108 | |
| 1109 | /* |
| 1110 | * Hello. This is a simple command to test the EC is responsive to |
| 1111 | * commands. |
| 1112 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1113 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1114 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1115 | /** |
| 1116 | * struct ec_params_hello - Parameters to the hello command. |
| 1117 | * @in_data: Pass anything here. |
| 1118 | */ |
| 1119 | struct ec_params_hello { |
| 1120 | uint32_t in_data; |
| 1121 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1122 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1123 | /** |
| 1124 | * struct ec_response_hello - Response to the hello command. |
| 1125 | * @out_data: Output will be in_data + 0x01020304. |
| 1126 | */ |
| 1127 | struct ec_response_hello { |
| 1128 | uint32_t out_data; |
| 1129 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1130 | |
| 1131 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1132 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1133 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1134 | #if !defined(CHROMIUM_EC) && !defined(__KERNEL__) |
| 1135 | /* |
| 1136 | * enum ec_current_image is deprecated and replaced by enum ec_image. This |
| 1137 | * macro exists for backwards compatibility of external projects until they |
| 1138 | * have been updated: b/149987779. |
| 1139 | */ |
| 1140 | #define ec_current_image ec_image |
| 1141 | #endif |
| 1142 | |
| 1143 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1144 | EC_IMAGE_UNKNOWN = 0, |
| 1145 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1146 | EC_IMAGE_RW, |
| 1147 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1148 | EC_IMAGE_RO_B, |
| 1149 | EC_IMAGE_RW_B |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1150 | }; |
| 1151 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1152 | /** |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1153 | * struct ec_response_get_version - Response to the v0 get version command. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1154 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1155 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1156 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1157 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1158 | */ |
| 1159 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1160 | char version_string_ro[32]; |
| 1161 | char version_string_rw[32]; |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1162 | char reserved[32]; /* Changed to cros_fwid_ro in version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1163 | uint32_t current_image; |
| 1164 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1165 | |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1166 | /** |
| 1167 | * struct ec_response_get_version_v1 - Response to the v1 get version command. |
| 1168 | * |
| 1169 | * ec_response_get_version_v1 is a strict superset of ec_response_get_version. |
| 1170 | * The v1 response changes the semantics of one field (reserved to cros_fwid_ro) |
| 1171 | * and adds one additional field (cros_fwid_rw). |
| 1172 | * |
| 1173 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1174 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1175 | * @cros_fwid_ro: Null-terminated RO CrOS FWID string. |
| 1176 | * @current_image: One of ec_image. |
| 1177 | * @cros_fwid_rw: Null-terminated RW CrOS FWID string. |
| 1178 | */ |
| 1179 | struct ec_response_get_version_v1 { |
| 1180 | char version_string_ro[32]; |
| 1181 | char version_string_rw[32]; |
| 1182 | char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */ |
| 1183 | uint32_t current_image; |
| 1184 | char cros_fwid_rw[32]; /* Added in version 1 */ |
| 1185 | } __ec_align4; |
| 1186 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1187 | /* Read test */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1188 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1189 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1190 | /** |
| 1191 | * struct ec_params_read_test - Parameters for the read test command. |
| 1192 | * @offset: Starting value for read buffer. |
| 1193 | * @size: Size to read in bytes. |
| 1194 | */ |
| 1195 | struct ec_params_read_test { |
| 1196 | uint32_t offset; |
| 1197 | uint32_t size; |
| 1198 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1199 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1200 | /** |
| 1201 | * struct ec_response_read_test - Response to the read test command. |
| 1202 | * @data: Data returned by the read test command. |
| 1203 | */ |
| 1204 | struct ec_response_read_test { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1205 | uint32_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1206 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1207 | |
| 1208 | /* |
| 1209 | * Get build information |
| 1210 | * |
| 1211 | * Response is null-terminated string. |
| 1212 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1213 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1214 | |
| 1215 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1216 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1217 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1218 | /** |
| 1219 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1220 | * @vendor: Null-terminated string for chip vendor. |
| 1221 | * @name: Null-terminated string for chip name. |
| 1222 | * @revision: Null-terminated string for chip mask version. |
| 1223 | */ |
| 1224 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1225 | char vendor[32]; |
| 1226 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1227 | char revision[32]; |
| 1228 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1229 | |
| 1230 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1231 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1232 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1233 | /** |
| 1234 | * struct ec_response_board_version - Response to the board version command. |
| 1235 | * @board_version: A monotonously incrementing number. |
| 1236 | */ |
| 1237 | struct ec_response_board_version { |
| 1238 | uint16_t board_version; |
| 1239 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1240 | |
| 1241 | /* |
| 1242 | * Read memory-mapped data. |
| 1243 | * |
| 1244 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1245 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1246 | * |
| 1247 | * Response is params.size bytes of data. |
| 1248 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1249 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1250 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1251 | /** |
| 1252 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1253 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1254 | * @size: Size to read in bytes. |
| 1255 | */ |
| 1256 | struct ec_params_read_memmap { |
| 1257 | uint8_t offset; |
| 1258 | uint8_t size; |
| 1259 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1260 | |
| 1261 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1262 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1263 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1264 | /** |
| 1265 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1266 | * @cmd: Command to check. |
| 1267 | */ |
| 1268 | struct ec_params_get_cmd_versions { |
| 1269 | uint8_t cmd; |
| 1270 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1271 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1272 | /** |
| 1273 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1274 | * versions (v1) |
| 1275 | * @cmd: Command to check. |
| 1276 | */ |
| 1277 | struct ec_params_get_cmd_versions_v1 { |
| 1278 | uint16_t cmd; |
| 1279 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1280 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1281 | /** |
| 1282 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1283 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1284 | * a desired version. |
| 1285 | */ |
| 1286 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1287 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1288 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1289 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1290 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1291 | * 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] | 1292 | * on lpc since it has its own out-of-band busy indicator. |
| 1293 | * |
| 1294 | * lpc must read the status from the command register. Attempting this on |
| 1295 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1296 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1297 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1298 | |
| 1299 | /* Avoid using ec_status which is for return values */ |
| 1300 | enum ec_comms_status { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1301 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1302 | }; |
| 1303 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1304 | /** |
| 1305 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1306 | * command. |
| 1307 | * @flags: Mask of enum ec_comms_status. |
| 1308 | */ |
| 1309 | struct ec_response_get_comms_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1310 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1311 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1312 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1313 | /* Fake a variety of responses, purely for testing purposes. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1314 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1315 | |
| 1316 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1317 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1318 | uint32_t ec_result; |
| 1319 | uint32_t ret_len; |
| 1320 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1321 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1322 | |
| 1323 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1324 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1325 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1326 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1327 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1328 | /* Get protocol information */ |
| 1329 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1330 | |
| 1331 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1332 | /* 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] | 1333 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1334 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1335 | /** |
| 1336 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1337 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1338 | * version n). |
| 1339 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1340 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1341 | * @flags: see EC_PROTOCOL_INFO_* |
| 1342 | */ |
| 1343 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1344 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1345 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1346 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1347 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1348 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1349 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1350 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1351 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1352 | /*****************************************************************************/ |
| 1353 | /* Get/Set miscellaneous values */ |
| 1354 | |
| 1355 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 1356 | #define EC_GSV_SET 0x80000000 |
| 1357 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1358 | /* |
| 1359 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1360 | * meaning for an individual command. |
| 1361 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1362 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1363 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1364 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1365 | uint32_t flags; |
| 1366 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1367 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1368 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1369 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1370 | uint32_t flags; |
| 1371 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1372 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1373 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1374 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1375 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1376 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1377 | /*****************************************************************************/ |
| 1378 | /* List the features supported by the firmware */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1379 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1380 | |
| 1381 | /* Supported features */ |
| 1382 | enum ec_feature_code { |
| 1383 | /* |
| 1384 | * This image contains a limited set of features. Another image |
| 1385 | * in RW partition may support more features. |
| 1386 | */ |
| 1387 | EC_FEATURE_LIMITED = 0, |
| 1388 | /* |
| 1389 | * Commands for probing/reading/writing/erasing the flash in the |
| 1390 | * EC are present. |
| 1391 | */ |
| 1392 | EC_FEATURE_FLASH = 1, |
| 1393 | /* |
| 1394 | * Can control the fan speed directly. |
| 1395 | */ |
| 1396 | EC_FEATURE_PWM_FAN = 2, |
| 1397 | /* |
| 1398 | * Can control the intensity of the keyboard backlight. |
| 1399 | */ |
| 1400 | EC_FEATURE_PWM_KEYB = 3, |
| 1401 | /* |
| 1402 | * Support Google lightbar, introduced on Pixel. |
| 1403 | */ |
| 1404 | EC_FEATURE_LIGHTBAR = 4, |
| 1405 | /* Control of LEDs */ |
| 1406 | EC_FEATURE_LED = 5, |
| 1407 | /* Exposes an interface to control gyro and sensors. |
| 1408 | * The host goes through the EC to access these sensors. |
| 1409 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1410 | */ |
| 1411 | EC_FEATURE_MOTION_SENSE = 6, |
| 1412 | /* The keyboard is controlled by the EC */ |
| 1413 | EC_FEATURE_KEYB = 7, |
| 1414 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1415 | EC_FEATURE_PSTORE = 8, |
| 1416 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1417 | EC_FEATURE_PORT80 = 9, |
| 1418 | /* |
| 1419 | * Thermal management: include TMP specific commands. |
| 1420 | * Higher level than direct fan control. |
| 1421 | */ |
| 1422 | EC_FEATURE_THERMAL = 10, |
| 1423 | /* Can switch the screen backlight on/off */ |
| 1424 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1425 | /* Can switch the wifi module on/off */ |
| 1426 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1427 | /* Monitor host events, through for example SMI or SCI */ |
| 1428 | EC_FEATURE_HOST_EVENTS = 13, |
| 1429 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1430 | EC_FEATURE_GPIO = 14, |
| 1431 | /* The EC can send i2c messages to downstream devices. */ |
| 1432 | EC_FEATURE_I2C = 15, |
| 1433 | /* Command to control charger are included */ |
| 1434 | EC_FEATURE_CHARGER = 16, |
| 1435 | /* Simple battery support. */ |
| 1436 | EC_FEATURE_BATTERY = 17, |
| 1437 | /* |
| 1438 | * Support Smart battery protocol |
| 1439 | * (Common Smart Battery System Interface Specification) |
| 1440 | */ |
| 1441 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1442 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1443 | EC_FEATURE_HANG_DETECT = 19, |
| 1444 | /* Report power information, for pit only */ |
| 1445 | EC_FEATURE_PMU = 20, |
| 1446 | /* Another Cros EC device is present downstream of this one */ |
| 1447 | EC_FEATURE_SUB_MCU = 21, |
| 1448 | /* Support USB Power delivery (PD) commands */ |
| 1449 | EC_FEATURE_USB_PD = 22, |
| 1450 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1451 | EC_FEATURE_USB_MUX = 23, |
| 1452 | /* Motion Sensor code has an internal software FIFO */ |
| 1453 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1454 | /* Support temporary secure vstore */ |
| 1455 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1456 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1457 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1458 | /* EC has RTC feature that can be controlled by host commands */ |
| 1459 | EC_FEATURE_RTC = 27, |
| 1460 | /* The MCU exposes a Fingerprint sensor */ |
| 1461 | EC_FEATURE_FINGERPRINT = 28, |
| 1462 | /* The MCU exposes a Touchpad */ |
| 1463 | EC_FEATURE_TOUCHPAD = 29, |
| 1464 | /* The MCU has RWSIG task enabled */ |
| 1465 | EC_FEATURE_RWSIG = 30, |
| 1466 | /* EC has device events support */ |
| 1467 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1468 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1469 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1470 | /* EC supports 64-bit host events */ |
| 1471 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1472 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1473 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1474 | /* EC supports CEC commands */ |
| 1475 | EC_FEATURE_CEC = 35, |
| 1476 | /* EC supports tight sensor timestamping. */ |
| 1477 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1478 | /* |
| 1479 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1480 | * setting of threshold by host command using |
| 1481 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1482 | */ |
| 1483 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1484 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1485 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1486 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1487 | * be sent to RO to be precise. |
| 1488 | */ |
| 1489 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1490 | /* The MCU is a System Companion Processor (SCP). */ |
| 1491 | EC_FEATURE_SCP = 39, |
| 1492 | /* The MCU is an Integrated Sensor Hub */ |
| 1493 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1494 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1495 | EC_FEATURE_TYPEC_CMD = 41, |
| 1496 | /* |
| 1497 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1498 | * modes or USB4. |
| 1499 | */ |
| 1500 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1501 | /* |
| 1502 | * The EC will wait for an acknowledge from the AP after setting the |
| 1503 | * mux. |
| 1504 | */ |
| 1505 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 1506 | /* |
| 1507 | * The EC supports entering and residing in S4. |
| 1508 | */ |
| 1509 | EC_FEATURE_S4_RESIDENCY = 44, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1510 | }; |
| 1511 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1512 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1513 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1514 | |
| 1515 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1516 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1517 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1518 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1519 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1520 | /* Get the board's SKU ID from EC */ |
| 1521 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1522 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1523 | /* Set SKU ID from AP */ |
| 1524 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1525 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1526 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1527 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1528 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1529 | |
| 1530 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1531 | /* Flash commands */ |
| 1532 | |
| 1533 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1534 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1535 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1536 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1537 | /** |
| 1538 | * struct ec_response_flash_info - Response to the flash info command. |
| 1539 | * @flash_size: Usable flash size in bytes. |
| 1540 | * @write_block_size: Write block size. Write offset and size must be a |
| 1541 | * multiple of this. |
| 1542 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1543 | * multiple of this. |
| 1544 | * @protect_block_size: Protection block size. Protection offset and size |
| 1545 | * must be a multiple of this. |
| 1546 | * |
| 1547 | * Version 0 returns these fields. |
| 1548 | */ |
| 1549 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1550 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1551 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1552 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1553 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1554 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1555 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1556 | /* |
| 1557 | * Flags for version 1+ flash info command |
| 1558 | * EC flash erases bits to 0 instead of 1. |
| 1559 | */ |
| 1560 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1561 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1562 | /* |
| 1563 | * 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] | 1564 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1565 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1566 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1567 | * chip functionality. |
| 1568 | */ |
| 1569 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1570 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1571 | /** |
| 1572 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1573 | * @flash_size: Usable flash size in bytes. |
| 1574 | * @write_block_size: Write block size. Write offset and size must be a |
| 1575 | * multiple of this. |
| 1576 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1577 | * multiple of this. |
| 1578 | * @protect_block_size: Protection block size. Protection offset and size |
| 1579 | * must be a multiple of this. |
| 1580 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1581 | * size is exactly this and offset is a multiple of this. |
| 1582 | * For example, an EC may have a write buffer which can do |
| 1583 | * half-page operations if data is aligned, and a slower |
| 1584 | * word-at-a-time write mode. |
| 1585 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1586 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1587 | * Version 1 returns the same initial fields as version 0, with additional |
| 1588 | * fields following. |
| 1589 | * |
| 1590 | * 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] | 1591 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1592 | * one. |
| 1593 | * |
| 1594 | * Version 2 supports flash banks of different sizes: |
| 1595 | * The caller specified the number of banks it has preallocated |
| 1596 | * (num_banks_desc) |
| 1597 | * The EC returns the number of banks describing the flash memory. |
| 1598 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1599 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1600 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1601 | /* Version 0 fields; see above for description */ |
| 1602 | uint32_t flash_size; |
| 1603 | uint32_t write_block_size; |
| 1604 | uint32_t erase_block_size; |
| 1605 | uint32_t protect_block_size; |
| 1606 | |
| 1607 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1608 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1609 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1610 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1611 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1612 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1613 | /* Number of banks to describe */ |
| 1614 | uint16_t num_banks_desc; |
| 1615 | /* Reserved; set 0; ignore on read */ |
| 1616 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1617 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1618 | |
| 1619 | struct ec_flash_bank { |
| 1620 | /* Number of sector is in this bank. */ |
| 1621 | uint16_t count; |
| 1622 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1623 | uint8_t size_exp; |
| 1624 | /* Minimal write size for the sectors in this bank */ |
| 1625 | uint8_t write_size_exp; |
| 1626 | /* Erase size for the sectors in this bank */ |
| 1627 | uint8_t erase_size_exp; |
| 1628 | /* Size for write protection, usually identical to erase size. */ |
| 1629 | uint8_t protect_size_exp; |
| 1630 | /* Reserved; set 0; ignore on read */ |
| 1631 | uint8_t reserved[2]; |
| 1632 | }; |
| 1633 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1634 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1635 | /* Total flash in the EC. */ |
| 1636 | uint32_t flash_size; |
| 1637 | /* Flags; see EC_FLASH_INFO_* */ |
| 1638 | uint32_t flags; |
| 1639 | /* Maximum size to use to send data to write to the EC. */ |
| 1640 | uint32_t write_ideal_size; |
| 1641 | /* Number of banks present in the EC. */ |
| 1642 | uint16_t num_banks_total; |
| 1643 | /* Number of banks described in banks array. */ |
| 1644 | uint16_t num_banks_desc; |
| 1645 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1646 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1647 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1648 | /* |
| 1649 | * Read flash |
| 1650 | * |
| 1651 | * Response is params.size bytes of data. |
| 1652 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1653 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1654 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1655 | /** |
| 1656 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1657 | * @offset: Byte offset to read. |
| 1658 | * @size: Size to read in bytes. |
| 1659 | */ |
| 1660 | struct ec_params_flash_read { |
| 1661 | uint32_t offset; |
| 1662 | uint32_t size; |
| 1663 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1664 | |
| 1665 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1666 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1667 | #define EC_VER_FLASH_WRITE 1 |
| 1668 | |
| 1669 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1670 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1671 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1672 | /** |
| 1673 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1674 | * @offset: Byte offset to write. |
| 1675 | * @size: Size to write in bytes. |
| 1676 | */ |
| 1677 | struct ec_params_flash_write { |
| 1678 | uint32_t offset; |
| 1679 | uint32_t size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1680 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1681 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1682 | |
| 1683 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1684 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1685 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1686 | /** |
| 1687 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1688 | * @offset: Byte offset to erase. |
| 1689 | * @size: Size to erase in bytes. |
| 1690 | */ |
| 1691 | struct ec_params_flash_erase { |
| 1692 | uint32_t offset; |
| 1693 | uint32_t size; |
| 1694 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1695 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1696 | /* |
| 1697 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1698 | * subcommands can returns: |
| 1699 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1700 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1701 | * EC_RES_ERROR : other errors. |
| 1702 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1703 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1704 | * |
| 1705 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1706 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1707 | * the proper result. |
| 1708 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1709 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1710 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1711 | * permitted while erasing. (For instance, STM32F4). |
| 1712 | */ |
| 1713 | enum ec_flash_erase_cmd { |
| 1714 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1715 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1716 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1717 | }; |
| 1718 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1719 | /** |
| 1720 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1721 | * @cmd: One of ec_flash_erase_cmd. |
| 1722 | * @reserved: Pad byte; currently always contains 0. |
| 1723 | * @flag: No flags defined yet; set to 0. |
| 1724 | * @params: Same as v0 parameters. |
| 1725 | */ |
| 1726 | struct ec_params_flash_erase_v1 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1727 | uint8_t cmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1728 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1729 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1730 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1731 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1732 | |
| 1733 | /* |
| 1734 | * Get/set flash protection. |
| 1735 | * |
| 1736 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1737 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1738 | * some flags require a subsequent hard reset to take effect. Check the |
| 1739 | * returned flags bits to see what actually happened. |
| 1740 | * |
| 1741 | * If mask=0, simply returns the current flags state. |
| 1742 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1743 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1744 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1745 | |
| 1746 | /* Flags for flash protection */ |
| 1747 | /* RO flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1748 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1749 | /* |
| 1750 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1751 | * be changed. |
| 1752 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1753 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1754 | /* Entire flash code protected now, until reboot. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1755 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1756 | /* Flash write protect GPIO is asserted now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1757 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1758 | /* 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] | 1759 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1760 | /* |
| 1761 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1762 | * flash which should be protected is not protected. Usually fixed by |
| 1763 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1764 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1765 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1766 | /* Entire flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1767 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1768 | /* RW flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1769 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1770 | /* RW flash code protected now. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1771 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1772 | /* Rollback information flash region protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1773 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1774 | /* Rollback information flash region protected now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1775 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 1776 | /* Error - Unknown error */ |
| 1777 | #define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1778 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1779 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1780 | /** |
| 1781 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1782 | * @mask: Bits in flags to apply. |
| 1783 | * @flags: New flags to apply. |
| 1784 | */ |
| 1785 | struct ec_params_flash_protect { |
| 1786 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1787 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1788 | } __ec_align4; |
| 1789 | |
| 1790 | /** |
| 1791 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1792 | * @flags: Current value of flash protect flags. |
| 1793 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1794 | * caller to distinguish between flags which aren't set vs. flags |
| 1795 | * which can't be set on this platform. |
| 1796 | * @writable_flags: Flags which can be changed given the current protection |
| 1797 | * state. |
| 1798 | */ |
| 1799 | struct ec_response_flash_protect { |
| 1800 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1801 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1802 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1803 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1804 | |
| 1805 | /* |
| 1806 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1807 | * write protect. These commands may be reused with version > 0. |
| 1808 | */ |
| 1809 | |
| 1810 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1811 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1812 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1813 | |
| 1814 | enum ec_flash_region { |
| 1815 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1816 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1817 | /* |
| 1818 | * Region which holds active RW image. 'Active' is different from |
| 1819 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1820 | * scheduled to run, active/non-active applies only to RW images (for |
| 1821 | * the same reason 'update' applies only to RW images. It's a state of |
| 1822 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1823 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1824 | * doesn't enter 'running' state but it's still active on a flash. |
| 1825 | */ |
| 1826 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1827 | /* |
| 1828 | * Region which should be write-protected in the factory (a superset of |
| 1829 | * EC_FLASH_REGION_RO) |
| 1830 | */ |
| 1831 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1832 | /* Region which holds updatable (non-active) RW image */ |
| 1833 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1834 | /* Number of regions */ |
| 1835 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1836 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1837 | /* |
| 1838 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1839 | * so the old constant is deprecated. |
| 1840 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1841 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1842 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1843 | /** |
| 1844 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1845 | * command. |
| 1846 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1847 | */ |
| 1848 | struct ec_params_flash_region_info { |
| 1849 | uint32_t region; |
| 1850 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1852 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1853 | uint32_t offset; |
| 1854 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1855 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1856 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 1857 | /* |
| 1858 | * Read/write VbNvContext |
| 1859 | * |
| 1860 | * Deprecated as of February 2021. No current devices use VBNV in EC |
| 1861 | * BBRAM anymore, so this is guaranteed to fail. |
| 1862 | * |
| 1863 | * TODO(b/178689388): remove from this header once no external |
| 1864 | * dependencies reference these constants. |
| 1865 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1866 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1867 | #define EC_VER_VBNV_CONTEXT 1 |
| 1868 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1869 | |
| 1870 | enum ec_vbnvcontext_op { |
| 1871 | EC_VBNV_CONTEXT_OP_READ, |
| 1872 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1873 | }; |
| 1874 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1875 | struct ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1876 | uint32_t op; |
| 1877 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1878 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1879 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1880 | struct ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1881 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1882 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1883 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1884 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1885 | /* Get SPI flash information */ |
| 1886 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1887 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1888 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1889 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1890 | uint8_t jedec[3]; |
| 1891 | |
| 1892 | /* Pad byte; currently always contains 0 */ |
| 1893 | uint8_t reserved0; |
| 1894 | |
| 1895 | /* Manufacturer / device ID from command 0x90 */ |
| 1896 | uint8_t mfr_dev_id[2]; |
| 1897 | |
| 1898 | /* Status registers from command 0x05 and 0x35 */ |
| 1899 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1900 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1901 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1902 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1903 | /* Select flash during flash operations */ |
| 1904 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1905 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1906 | /** |
| 1907 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1908 | * @select: 1 to select flash, 0 to deselect flash |
| 1909 | */ |
| 1910 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1911 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1912 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1913 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1914 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1915 | /** |
| 1916 | * Request random numbers to be generated and returned. |
| 1917 | * Can be used to test the random number generator is truly random. |
| 1918 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1919 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1920 | */ |
| 1921 | #define EC_CMD_RAND_NUM 0x001A |
| 1922 | #define EC_VER_RAND_NUM 0 |
| 1923 | |
| 1924 | struct ec_params_rand_num { |
| 1925 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
| 1926 | } __ec_align4; |
| 1927 | |
| 1928 | struct ec_response_rand_num { |
| 1929 | uint8_t rand[0]; /**< generated random numbers */ |
| 1930 | } __ec_align4; |
| 1931 | |
| 1932 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1933 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1934 | /** |
| 1935 | * Get information about the key used to sign the RW firmware. |
| 1936 | * For more details on the fields, see "struct vb21_packed_key". |
| 1937 | */ |
| 1938 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1939 | #define EC_VER_RWSIG_INFO 0 |
| 1940 | |
| 1941 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1942 | |
| 1943 | #ifdef CHROMIUM_EC |
| 1944 | /* Don't force external projects to depend on the vboot headers. */ |
| 1945 | #include "vb21_struct.h" |
| 1946 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1947 | #endif |
| 1948 | |
| 1949 | struct ec_response_rwsig_info { |
| 1950 | /** |
| 1951 | * Signature algorithm used by the key |
| 1952 | * (enum vb2_signature_algorithm). |
| 1953 | */ |
| 1954 | uint16_t sig_alg; |
| 1955 | |
| 1956 | /** |
| 1957 | * Hash digest algorithm used with the key |
| 1958 | * (enum vb2_hash_algorithm). |
| 1959 | */ |
| 1960 | uint16_t hash_alg; |
| 1961 | |
| 1962 | /** Key version. */ |
| 1963 | uint32_t key_version; |
| 1964 | |
| 1965 | /** Key ID (struct vb2_id). */ |
| 1966 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 1967 | |
| 1968 | uint8_t key_is_valid; |
| 1969 | |
| 1970 | /** Alignment padding. */ |
| 1971 | uint8_t reserved[3]; |
| 1972 | } __ec_align4; |
| 1973 | |
| 1974 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 1975 | |
| 1976 | /** |
| 1977 | * Get information about the system, such as reset flags, locked state, etc. |
| 1978 | */ |
| 1979 | #define EC_CMD_SYSINFO 0x001C |
| 1980 | #define EC_VER_SYSINFO 0 |
| 1981 | |
| 1982 | enum sysinfo_flags { |
| 1983 | SYSTEM_IS_LOCKED = BIT(0), |
| 1984 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 1985 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 1986 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 1987 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4), |
| 1988 | /* |
| 1989 | * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is |
| 1990 | * set and cleared when the system shuts down (not when the host event |
| 1991 | * flag is cleared). |
| 1992 | */ |
| 1993 | SYSTEM_IN_MANUAL_RECOVERY = BIT(5), |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1994 | }; |
| 1995 | |
| 1996 | struct ec_response_sysinfo { |
| 1997 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
| 1998 | uint32_t current_image; /**< enum ec_current_image */ |
| 1999 | uint32_t flags; /**< enum sysinfo_flags */ |
| 2000 | } __ec_align4; |
| 2001 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2002 | /*****************************************************************************/ |
| 2003 | /* PWM commands */ |
| 2004 | |
| 2005 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2006 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2007 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2008 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2009 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2010 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2011 | |
| 2012 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2013 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2014 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2015 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2016 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2017 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2018 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2019 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2020 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2021 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2022 | uint32_t rpm; |
| 2023 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2024 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2025 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2026 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2027 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2028 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2029 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2030 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2031 | uint8_t percent; |
| 2032 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2033 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2034 | |
| 2035 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2036 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2037 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2038 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2039 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2040 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2041 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2042 | |
| 2043 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2044 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2045 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2046 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2047 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2048 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2049 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2050 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2051 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2052 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2053 | uint32_t percent; |
| 2054 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2055 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2056 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2057 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2058 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 2059 | #define EC_PWM_MAX_DUTY 0xffff |
| 2060 | |
| 2061 | enum ec_pwm_type { |
| 2062 | /* All types, indexed by board-specific enum pwm_channel */ |
| 2063 | EC_PWM_TYPE_GENERIC = 0, |
| 2064 | /* Keyboard backlight */ |
| 2065 | EC_PWM_TYPE_KB_LIGHT, |
| 2066 | /* Display backlight */ |
| 2067 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 2068 | EC_PWM_TYPE_COUNT, |
| 2069 | }; |
| 2070 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2071 | struct ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2072 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 2073 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2074 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2075 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2076 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2077 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2078 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2079 | struct ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2080 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2081 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2082 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2083 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2084 | struct ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2085 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2086 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2087 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2088 | /*****************************************************************************/ |
| 2089 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2090 | * 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] | 2091 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 2092 | * into a subcommand. We'll make separate structs for subcommands with |
| 2093 | * different input args, so that we know how much to expect. |
| 2094 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2095 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2096 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2097 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2098 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2099 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2100 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2101 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2102 | |
| 2103 | /* |
| 2104 | * 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] | 2105 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2106 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2107 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2108 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2109 | int32_t google_ramp_up; |
| 2110 | int32_t google_ramp_down; |
| 2111 | int32_t s3s0_ramp_up; |
| 2112 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2113 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2114 | int32_t s0s3_ramp_down; |
| 2115 | int32_t s3_sleep_for; |
| 2116 | int32_t s3_ramp_up; |
| 2117 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2118 | |
| 2119 | /* Oscillation */ |
| 2120 | uint8_t new_s0; |
| 2121 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2122 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2123 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2124 | |
| 2125 | /* Brightness limits based on the backlight and AC. */ |
| 2126 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2127 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2128 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2129 | |
| 2130 | /* Battery level thresholds */ |
| 2131 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2132 | |
| 2133 | /* Map [AC][battery_level] to color index */ |
| 2134 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2135 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2136 | |
| 2137 | /* Color palette */ |
| 2138 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2139 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2140 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2141 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2142 | /* Timing */ |
| 2143 | int32_t google_ramp_up; |
| 2144 | int32_t google_ramp_down; |
| 2145 | int32_t s3s0_ramp_up; |
| 2146 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2147 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2148 | int32_t s0s3_ramp_down; |
| 2149 | int32_t s3_sleep_for; |
| 2150 | int32_t s3_ramp_up; |
| 2151 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2152 | int32_t s5_ramp_up; |
| 2153 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2154 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2155 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2156 | int32_t tap_display_time; |
| 2157 | |
| 2158 | /* Tap-for-battery params */ |
| 2159 | uint8_t tap_pct_red; |
| 2160 | uint8_t tap_pct_green; |
| 2161 | uint8_t tap_seg_min_on; |
| 2162 | uint8_t tap_seg_max_on; |
| 2163 | uint8_t tap_seg_osc; |
| 2164 | uint8_t tap_idx[3]; |
| 2165 | |
| 2166 | /* Oscillation */ |
| 2167 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2168 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2169 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2170 | |
| 2171 | /* Brightness limits based on the backlight and AC. */ |
| 2172 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2173 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2174 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2175 | |
| 2176 | /* Battery level thresholds */ |
| 2177 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2178 | |
| 2179 | /* Map [AC][battery_level] to color index */ |
| 2180 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2181 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2182 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2183 | /* s5: single color pulse on inhibited power-up */ |
| 2184 | uint8_t s5_idx; |
| 2185 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2186 | /* Color palette */ |
| 2187 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2188 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2189 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2190 | /* Lightbar command params v2 |
| 2191 | * crbug.com/467716 |
| 2192 | * |
| 2193 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2194 | * logical groups to make it more manageable ( < 120 bytes). |
| 2195 | * |
| 2196 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2197 | */ |
| 2198 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2199 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2200 | /* Timing */ |
| 2201 | int32_t google_ramp_up; |
| 2202 | int32_t google_ramp_down; |
| 2203 | int32_t s3s0_ramp_up; |
| 2204 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2205 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2206 | int32_t s0s3_ramp_down; |
| 2207 | int32_t s3_sleep_for; |
| 2208 | int32_t s3_ramp_up; |
| 2209 | int32_t s3_ramp_down; |
| 2210 | int32_t s5_ramp_up; |
| 2211 | int32_t s5_ramp_down; |
| 2212 | int32_t tap_tick_delay; |
| 2213 | int32_t tap_gate_delay; |
| 2214 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2215 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2216 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2217 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2218 | /* Tap-for-battery params */ |
| 2219 | uint8_t tap_pct_red; |
| 2220 | uint8_t tap_pct_green; |
| 2221 | uint8_t tap_seg_min_on; |
| 2222 | uint8_t tap_seg_max_on; |
| 2223 | uint8_t tap_seg_osc; |
| 2224 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2225 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2226 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2227 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2228 | /* Oscillation */ |
| 2229 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2230 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2231 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2232 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2233 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2234 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2235 | /* Brightness limits based on the backlight and AC. */ |
| 2236 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2237 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2238 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2239 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2240 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2241 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2242 | /* Battery level thresholds */ |
| 2243 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2244 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2245 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2246 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2247 | /* Map [AC][battery_level] to color index */ |
| 2248 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2249 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2250 | |
| 2251 | /* s5: single color pulse on inhibited power-up */ |
| 2252 | uint8_t s5_idx; |
| 2253 | |
| 2254 | /* Color palette */ |
| 2255 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2256 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2257 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2258 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2259 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2260 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2261 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2262 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2263 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2265 | struct ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2266 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 2267 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2268 | /* |
| 2269 | * The following commands have no args: |
| 2270 | * |
| 2271 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2272 | * version, get_brightness, get_demo, suspend, resume, |
| 2273 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2274 | * get_params_v2_bright, get_params_v2_thlds, |
| 2275 | * get_params_v2_colors |
| 2276 | * |
| 2277 | * Don't use an empty struct, because C++ hates that. |
| 2278 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 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 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2283 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2284 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2285 | uint8_t ctrl, reg, value; |
| 2286 | } reg; |
| 2287 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2288 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2289 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2290 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2291 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2292 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2293 | uint8_t led; |
| 2294 | } get_rgb; |
| 2295 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2296 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2297 | uint8_t enable; |
| 2298 | } manual_suspend_ctrl; |
| 2299 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2300 | struct lightbar_params_v0 set_params_v0; |
| 2301 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2302 | |
| 2303 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2304 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2305 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2306 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2307 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2308 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2309 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2310 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2311 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2312 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2313 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2314 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2315 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2316 | struct __ec_todo_unpacked { |
| 2317 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2318 | uint8_t reg; |
| 2319 | uint8_t ic0; |
| 2320 | uint8_t ic1; |
| 2321 | } vals[23]; |
| 2322 | } dump; |
| 2323 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2324 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2325 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2326 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2327 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2328 | struct lightbar_params_v0 get_params_v0; |
| 2329 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2330 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2331 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2332 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2333 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2334 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2335 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2336 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2337 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2338 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2339 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2340 | uint32_t num; |
| 2341 | uint32_t flags; |
| 2342 | } version; |
| 2343 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2344 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2345 | uint8_t red, green, blue; |
| 2346 | } get_rgb; |
| 2347 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2348 | /* |
| 2349 | * The following commands have no response: |
| 2350 | * |
| 2351 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2352 | * set_params_v0, set_params_v1, set_program, |
| 2353 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2354 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2355 | * set_v2par_thlds, set_v2par_colors |
| 2356 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2357 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2358 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2359 | |
| 2360 | /* Lightbar commands */ |
| 2361 | enum lightbar_command { |
| 2362 | LIGHTBAR_CMD_DUMP = 0, |
| 2363 | LIGHTBAR_CMD_OFF = 1, |
| 2364 | LIGHTBAR_CMD_ON = 2, |
| 2365 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2366 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2367 | LIGHTBAR_CMD_SEQ = 5, |
| 2368 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2369 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2370 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2371 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2372 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2373 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2374 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2375 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2376 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2377 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2378 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2379 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2380 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2381 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2382 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2383 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2384 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2385 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2386 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2387 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2388 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2389 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2390 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2391 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2392 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2393 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2394 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2395 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2396 | LIGHTBAR_NUM_CMDS |
| 2397 | }; |
| 2398 | |
| 2399 | /*****************************************************************************/ |
| 2400 | /* LED control commands */ |
| 2401 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2402 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2403 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2404 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2405 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2406 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2407 | /* |
| 2408 | * LED to indicate system power state (on or in suspend). |
| 2409 | * May be on power button or on C-panel. |
| 2410 | */ |
| 2411 | EC_LED_ID_POWER_LED, |
| 2412 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2413 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2414 | /* LED to indicate left side */ |
| 2415 | EC_LED_ID_LEFT_LED, |
| 2416 | /* LED to indicate right side */ |
| 2417 | EC_LED_ID_RIGHT_LED, |
| 2418 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2419 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2420 | /* LED to indicate sysrq debug mode. */ |
| 2421 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2422 | |
| 2423 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2424 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2425 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2426 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2427 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
| 2428 | #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] | 2429 | |
| 2430 | enum ec_led_colors { |
| 2431 | EC_LED_COLOR_RED = 0, |
| 2432 | EC_LED_COLOR_GREEN, |
| 2433 | EC_LED_COLOR_BLUE, |
| 2434 | EC_LED_COLOR_YELLOW, |
| 2435 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2436 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2437 | |
| 2438 | EC_LED_COLOR_COUNT |
| 2439 | }; |
| 2440 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2441 | struct ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2442 | uint8_t led_id; /* Which LED to control */ |
| 2443 | uint8_t flags; /* Control flags */ |
| 2444 | |
| 2445 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2446 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2447 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2448 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2449 | /* |
| 2450 | * Available brightness value range. |
| 2451 | * |
| 2452 | * Range 0 means color channel not present. |
| 2453 | * Range 1 means on/off control. |
| 2454 | * Other values means the LED is control by PWM. |
| 2455 | */ |
| 2456 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2457 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2458 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2459 | /*****************************************************************************/ |
| 2460 | /* Verified boot commands */ |
| 2461 | |
| 2462 | /* |
| 2463 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2464 | * reused for other purposes with version > 0. |
| 2465 | */ |
| 2466 | |
| 2467 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2468 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2469 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2470 | struct ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2471 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2472 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2473 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2474 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2475 | uint32_t offset; /* Offset in flash to hash */ |
| 2476 | uint32_t size; /* Number of bytes to hash */ |
| 2477 | 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] | 2478 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2479 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2480 | struct ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2481 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2482 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2483 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2484 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2485 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2486 | uint32_t size; /* Number of bytes hashed */ |
| 2487 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2488 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2489 | |
| 2490 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2491 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2492 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2493 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2494 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2495 | }; |
| 2496 | |
| 2497 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2498 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2499 | }; |
| 2500 | |
| 2501 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2502 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2503 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2504 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2505 | }; |
| 2506 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2507 | /* |
| 2508 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2509 | * If one of these is specified, the EC will automatically update offset and |
| 2510 | * size to the correct values for the specified image (RO or RW). |
| 2511 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2512 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2513 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2514 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
| 2515 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2516 | /* |
| 2517 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2518 | * so the old constant is deprecated. |
| 2519 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2520 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2521 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2522 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2523 | /* |
| 2524 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2525 | * different input args, so that we know how much to expect. |
| 2526 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2527 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2528 | |
| 2529 | /* Motion sense commands */ |
| 2530 | enum motionsense_command { |
| 2531 | /* |
| 2532 | * Dump command returns all motion sensor data including motion sense |
| 2533 | * module flags and individual sensor flags. |
| 2534 | */ |
| 2535 | MOTIONSENSE_CMD_DUMP = 0, |
| 2536 | |
| 2537 | /* |
| 2538 | * Info command returns data describing the details of a given sensor, |
| 2539 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2540 | * enum motionsensor_chip. |
| 2541 | */ |
| 2542 | MOTIONSENSE_CMD_INFO = 1, |
| 2543 | |
| 2544 | /* |
| 2545 | * 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] | 2546 | * in milliseconds. |
| 2547 | * It is per sensor, the EC run sample task at the minimum of all |
| 2548 | * sensors EC_RATE. |
| 2549 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2550 | * to collect all the sensor samples. |
| 2551 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2552 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2553 | */ |
| 2554 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2555 | |
| 2556 | /* |
| 2557 | * Sensor ODR command is a setter/getter command for the output data |
| 2558 | * rate of a specific motion sensor in millihertz. |
| 2559 | */ |
| 2560 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2561 | |
| 2562 | /* |
| 2563 | * Sensor range command is a setter/getter command for the range of |
| 2564 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2565 | */ |
| 2566 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2567 | |
| 2568 | /* |
| 2569 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2570 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2571 | * and when the lid angle goes less than this value, keyboard wake is |
| 2572 | * enabled. Note, the lid angle measurement is an approximate, |
| 2573 | * un-calibrated value, hence the wake angle isn't exact. |
| 2574 | */ |
| 2575 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2576 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2577 | /* |
| 2578 | * Returns a single sensor data. |
| 2579 | */ |
| 2580 | MOTIONSENSE_CMD_DATA = 6, |
| 2581 | |
| 2582 | /* |
| 2583 | * Return sensor fifo info. |
| 2584 | */ |
| 2585 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2586 | |
| 2587 | /* |
| 2588 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2589 | * The host can use that element to synchronize its operation. |
| 2590 | */ |
| 2591 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2592 | |
| 2593 | /* |
| 2594 | * Return a portion of the fifo. |
| 2595 | */ |
| 2596 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2597 | |
| 2598 | /* |
| 2599 | * Perform low level calibration. |
| 2600 | * On sensors that support it, ask to do offset calibration. |
| 2601 | */ |
| 2602 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2603 | |
| 2604 | /* |
| 2605 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2606 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2607 | * The offsets can be calculated by the host, or via |
| 2608 | * PERFORM_CALIB command. |
| 2609 | */ |
| 2610 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2611 | |
| 2612 | /* |
| 2613 | * List available activities for a MOTION sensor. |
| 2614 | * Indicates if they are enabled or disabled. |
| 2615 | */ |
| 2616 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2617 | |
| 2618 | /* |
| 2619 | * Activity management |
| 2620 | * Enable/Disable activity recognition. |
| 2621 | */ |
| 2622 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2623 | |
| 2624 | /* |
| 2625 | * Lid Angle |
| 2626 | */ |
| 2627 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2628 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2629 | /* |
| 2630 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2631 | * By default the FIFO does not send interrupt to process the FIFO |
| 2632 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2633 | */ |
| 2634 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2635 | |
| 2636 | /* |
| 2637 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2638 | * to arbitrary values, or will lock to the last read actual values. |
| 2639 | */ |
| 2640 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2641 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2642 | /* Set lid angle for tablet mode detection. */ |
| 2643 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2644 | |
| 2645 | /* |
| 2646 | * Sensor Scale command is a setter/getter command for the calibration |
| 2647 | * scale. |
| 2648 | */ |
| 2649 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2650 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2651 | /* |
| 2652 | * Read the current online calibration values (if available). |
| 2653 | */ |
| 2654 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2655 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2656 | /* |
| 2657 | * Activity management |
| 2658 | * Retrieve current status of given activity. |
| 2659 | */ |
| 2660 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2661 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2662 | /* Number of motionsense sub-commands. */ |
| 2663 | MOTIONSENSE_NUM_CMDS |
| 2664 | }; |
| 2665 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2666 | /* List of motion sensor types. */ |
| 2667 | enum motionsensor_type { |
| 2668 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2669 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2670 | MOTIONSENSE_TYPE_MAG = 2, |
| 2671 | MOTIONSENSE_TYPE_PROX = 3, |
| 2672 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2673 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2674 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2675 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2676 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2677 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2678 | }; |
| 2679 | |
| 2680 | /* List of motion sensor locations. */ |
| 2681 | enum motionsensor_location { |
| 2682 | MOTIONSENSE_LOC_BASE = 0, |
| 2683 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2684 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2685 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2686 | }; |
| 2687 | |
| 2688 | /* List of motion sensor chips. */ |
| 2689 | enum motionsensor_chip { |
| 2690 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2691 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2692 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2693 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2694 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2695 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2696 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2697 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2698 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2699 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2700 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2701 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2702 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2703 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2704 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2705 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2706 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2707 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2708 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2709 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2710 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2711 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2712 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2713 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2714 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2715 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2716 | MOTIONSENSE_CHIP_ICM42607 = 26, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2717 | MOTIONSENSE_CHIP_BMA422 = 27, |
| 2718 | MOTIONSENSE_CHIP_BMI323 = 28, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 2719 | MOTIONSENSE_CHIP_BMI220 = 29, |
| 2720 | MOTIONSENSE_CHIP_CM32183 = 30, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2721 | MOTIONSENSE_CHIP_MAX, |
| 2722 | }; |
| 2723 | |
| 2724 | /* List of orientation positions */ |
| 2725 | enum motionsensor_orientation { |
| 2726 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2727 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2728 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2729 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2730 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2731 | }; |
| 2732 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2733 | struct ec_response_activity_data { |
| 2734 | uint8_t activity; /* motionsensor_activity */ |
| 2735 | uint8_t state; |
| 2736 | } __ec_todo_packed; |
| 2737 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2738 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2739 | /* Flags for each sensor. */ |
| 2740 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2741 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2742 | uint8_t sensor_num; |
| 2743 | /* Each sensor is up to 3-axis. */ |
| 2744 | union { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2745 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2746 | /* for sensors using unsigned data */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2747 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2748 | struct __ec_todo_packed { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2749 | uint16_t reserved; |
| 2750 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2751 | }; |
| 2752 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2753 | struct ec_response_activity_data activity_data; |
| 2754 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2755 | }; |
| 2756 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2757 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2758 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2759 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2760 | struct ec_response_online_calibration_data { |
| 2761 | /** The calibration values. */ |
| 2762 | int16_t data[3]; |
| 2763 | }; |
| 2764 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2765 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2766 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2767 | /* Size of the fifo */ |
| 2768 | uint16_t size; |
| 2769 | /* Amount of space used in the fifo */ |
| 2770 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2771 | /* Timestamp recorded in us. |
| 2772 | * aka accurate timestamp when host event was triggered. |
| 2773 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2774 | uint32_t timestamp; |
| 2775 | /* Total amount of vector lost */ |
| 2776 | uint16_t total_lost; |
| 2777 | /* Lost events since the last fifo_info, per sensors */ |
| 2778 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2779 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2780 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2781 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2782 | uint32_t number_data; |
| 2783 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2784 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2785 | |
| 2786 | /* List supported activity recognition */ |
| 2787 | enum motionsensor_activity { |
| 2788 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2789 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2790 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2791 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2792 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2793 | }; |
| 2794 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2795 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2796 | uint8_t sensor_num; |
| 2797 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2798 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2799 | uint8_t reserved; |
| 2800 | uint16_t parameters[3]; /* activity dependent parameters */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2801 | } __ec_todo_unpacked; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2802 | |
| 2803 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2804 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2805 | |
| 2806 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2807 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2808 | |
| 2809 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2810 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2811 | * data contains time stamp |
| 2812 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2813 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2814 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2815 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2816 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2817 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2818 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2819 | #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7) |
| 2820 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2821 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2822 | * Send this value for the data element to only perform a read. If you |
| 2823 | * send any other value, the EC will interpret it as data to set and will |
| 2824 | * return the actual value set. |
| 2825 | */ |
| 2826 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2827 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2828 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2829 | |
| 2830 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2831 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2832 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2833 | |
| 2834 | /* Default Scale value, factor 1. */ |
| 2835 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2836 | |
| 2837 | #define LID_ANGLE_UNRELIABLE 500 |
| 2838 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2839 | enum motionsense_spoof_mode { |
| 2840 | /* Disable spoof mode. */ |
| 2841 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2842 | |
| 2843 | /* Enable spoof mode, but use provided component values. */ |
| 2844 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2845 | |
| 2846 | /* Enable spoof mode, but use the current sensor values. */ |
| 2847 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2848 | |
| 2849 | /* Query the current spoof mode status for the sensor. */ |
| 2850 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2851 | }; |
| 2852 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2853 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2854 | uint8_t cmd; |
| 2855 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2856 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2857 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2858 | /* |
| 2859 | * Maximal number of sensor the host is expecting. |
| 2860 | * 0 means the host is only interested in the number |
| 2861 | * of sensors controlled by the EC. |
| 2862 | */ |
| 2863 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2864 | } dump; |
| 2865 | |
| 2866 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2867 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2868 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2869 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2870 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 2871 | * kb_wake_angle: angle to wakup AP. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2872 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2873 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2874 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2875 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2876 | /* |
| 2877 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2878 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2879 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2880 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2881 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2882 | |
| 2883 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2884 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2885 | * Allow entering/exiting the calibration mode. |
| 2886 | */ |
| 2887 | struct __ec_todo_unpacked { |
| 2888 | uint8_t sensor_num; |
| 2889 | uint8_t enable; |
| 2890 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2891 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2892 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2893 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2894 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2895 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2896 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2897 | uint8_t sensor_num; |
| 2898 | |
| 2899 | /* Rounding flag, true for round-up, false for down. */ |
| 2900 | uint8_t roundup; |
| 2901 | |
| 2902 | uint16_t reserved; |
| 2903 | |
| 2904 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2905 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2906 | } ec_rate, sensor_odr, sensor_range; |
| 2907 | |
| 2908 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2909 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2910 | uint8_t sensor_num; |
| 2911 | |
| 2912 | /* |
| 2913 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2914 | * the calibration information in the EC. |
| 2915 | * If unset, just retrieve calibration information. |
| 2916 | */ |
| 2917 | uint16_t flags; |
| 2918 | |
| 2919 | /* |
| 2920 | * Temperature at calibration, in units of 0.01 C |
| 2921 | * 0x8000: invalid / unknown. |
| 2922 | * 0x0: 0C |
| 2923 | * 0x7fff: +327.67C |
| 2924 | */ |
| 2925 | int16_t temp; |
| 2926 | |
| 2927 | /* |
| 2928 | * Offset for calibration. |
| 2929 | * Unit: |
| 2930 | * Accelerometer: 1/1024 g |
| 2931 | * Gyro: 1/1024 deg/s |
| 2932 | * Compass: 1/16 uT |
| 2933 | */ |
| 2934 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2935 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2936 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2937 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2938 | struct __ec_todo_packed { |
| 2939 | uint8_t sensor_num; |
| 2940 | |
| 2941 | /* |
| 2942 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2943 | * the calibration information in the EC. |
| 2944 | * If unset, just retrieve calibration information. |
| 2945 | */ |
| 2946 | uint16_t flags; |
| 2947 | |
| 2948 | /* |
| 2949 | * Temperature at calibration, in units of 0.01 C |
| 2950 | * 0x8000: invalid / unknown. |
| 2951 | * 0x0: 0C |
| 2952 | * 0x7fff: +327.67C |
| 2953 | */ |
| 2954 | int16_t temp; |
| 2955 | |
| 2956 | /* |
| 2957 | * Scale for calibration: |
| 2958 | * By default scale is 1, it is encoded on 16bits: |
| 2959 | * 1 = BIT(15) |
| 2960 | * ~2 = 0xFFFF |
| 2961 | * ~0 = 0. |
| 2962 | */ |
| 2963 | uint16_t scale[3]; |
| 2964 | } sensor_scale; |
| 2965 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 2966 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2967 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2968 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2969 | |
| 2970 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2971 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2972 | /* |
| 2973 | * Number of expected vector to return. |
| 2974 | * EC may return less or 0 if none available. |
| 2975 | */ |
| 2976 | uint32_t max_data_vector; |
| 2977 | } fifo_read; |
| 2978 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2979 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2980 | struct ec_motion_sense_activity set_activity; |
| 2981 | |
| 2982 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2983 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2984 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2985 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2986 | struct __ec_todo_unpacked { |
| 2987 | /* |
| 2988 | * 1: enable, 0 disable fifo, |
| 2989 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2990 | */ |
| 2991 | int8_t enable; |
| 2992 | } fifo_int_enable; |
| 2993 | |
| 2994 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2995 | struct __ec_todo_packed { |
| 2996 | uint8_t sensor_id; |
| 2997 | |
| 2998 | /* See enum motionsense_spoof_mode. */ |
| 2999 | uint8_t spoof_enable; |
| 3000 | |
| 3001 | /* Ignored, used for alignment. */ |
| 3002 | uint8_t reserved; |
| 3003 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3004 | union { |
| 3005 | /* Individual component values to spoof. */ |
| 3006 | int16_t components[3]; |
| 3007 | |
| 3008 | /* Used when spoofing an activity */ |
| 3009 | struct { |
| 3010 | /* enum motionsensor_activity */ |
| 3011 | uint8_t activity_num; |
| 3012 | |
| 3013 | /* spoof activity state */ |
| 3014 | uint8_t activity_state; |
| 3015 | }; |
| 3016 | }; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3017 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3018 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3019 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3020 | struct __ec_todo_unpacked { |
| 3021 | /* |
| 3022 | * Lid angle threshold for switching between tablet and |
| 3023 | * clamshell mode. |
| 3024 | */ |
| 3025 | int16_t lid_angle; |
| 3026 | |
| 3027 | /* |
| 3028 | * Hysteresis degree to prevent fluctuations between |
| 3029 | * clamshell and tablet mode if lid angle keeps |
| 3030 | * changing around the threshold. Lid motion driver will |
| 3031 | * use lid_angle + hys_degree to trigger tablet mode and |
| 3032 | * lid_angle - hys_degree to trigger clamshell mode. |
| 3033 | */ |
| 3034 | int16_t hys_degree; |
| 3035 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3036 | |
| 3037 | /* |
| 3038 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 3039 | * Allow reading a single sensor's online calibration value. |
| 3040 | */ |
| 3041 | struct __ec_todo_unpacked { |
| 3042 | uint8_t sensor_num; |
| 3043 | } online_calib_read; |
| 3044 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3045 | /* |
| 3046 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 3047 | */ |
| 3048 | struct __ec_todo_unpacked { |
| 3049 | uint8_t sensor_num; |
| 3050 | uint8_t activity; /* enum motionsensor_activity */ |
| 3051 | } get_activity; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3052 | }; |
| 3053 | } __ec_todo_packed; |
| 3054 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3055 | enum motion_sense_cmd_info_flags { |
| 3056 | /* The sensor supports online calibration */ |
| 3057 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 3058 | }; |
| 3059 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3060 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3061 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3062 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3063 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3064 | /* Flags representing the motion sensor module. */ |
| 3065 | uint8_t module_flags; |
| 3066 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3067 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3068 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3069 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3070 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3071 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3072 | * for holding all the data. |
| 3073 | */ |
| 3074 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3075 | } dump; |
| 3076 | |
| 3077 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3078 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3079 | /* Should be element of enum motionsensor_type. */ |
| 3080 | uint8_t type; |
| 3081 | |
| 3082 | /* Should be element of enum motionsensor_location. */ |
| 3083 | uint8_t location; |
| 3084 | |
| 3085 | /* Should be element of enum motionsensor_chip. */ |
| 3086 | uint8_t chip; |
| 3087 | } info; |
| 3088 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3089 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 3090 | struct __ec_todo_unpacked { |
| 3091 | /* Should be element of enum motionsensor_type. */ |
| 3092 | uint8_t type; |
| 3093 | |
| 3094 | /* Should be element of enum motionsensor_location. */ |
| 3095 | uint8_t location; |
| 3096 | |
| 3097 | /* Should be element of enum motionsensor_chip. */ |
| 3098 | uint8_t chip; |
| 3099 | |
| 3100 | /* Minimum sensor sampling frequency */ |
| 3101 | uint32_t min_frequency; |
| 3102 | |
| 3103 | /* Maximum sensor sampling frequency */ |
| 3104 | uint32_t max_frequency; |
| 3105 | |
| 3106 | /* Max number of sensor events that could be in fifo */ |
| 3107 | uint32_t fifo_max_event_count; |
| 3108 | } info_3; |
| 3109 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3110 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3111 | struct __ec_align4 { |
| 3112 | /* Should be element of enum motionsensor_type. */ |
| 3113 | uint8_t type; |
| 3114 | |
| 3115 | /* Should be element of enum motionsensor_location. */ |
| 3116 | uint8_t location; |
| 3117 | |
| 3118 | /* Should be element of enum motionsensor_chip. */ |
| 3119 | uint8_t chip; |
| 3120 | |
| 3121 | /* Minimum sensor sampling frequency */ |
| 3122 | uint32_t min_frequency; |
| 3123 | |
| 3124 | /* Maximum sensor sampling frequency */ |
| 3125 | uint32_t max_frequency; |
| 3126 | |
| 3127 | /* Max number of sensor events that could be in fifo */ |
| 3128 | uint32_t fifo_max_event_count; |
| 3129 | |
| 3130 | /* |
| 3131 | * Should be elements of |
| 3132 | * enum motion_sense_cmd_info_flags |
| 3133 | */ |
| 3134 | uint32_t flags; |
| 3135 | } info_4; |
| 3136 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3137 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3138 | struct ec_response_motion_sensor_data data; |
| 3139 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3140 | /* |
| 3141 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3142 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3143 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3144 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3145 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3146 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3147 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3148 | /* Current value of the parameter queried. */ |
| 3149 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3150 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 3151 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3152 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3153 | /* |
| 3154 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3155 | * PERFORM_CALIB. |
| 3156 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3157 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3158 | int16_t temp; |
| 3159 | int16_t offset[3]; |
| 3160 | } sensor_offset, perform_calib; |
| 3161 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3162 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3163 | struct __ec_todo_unpacked { |
| 3164 | int16_t temp; |
| 3165 | uint16_t scale[3]; |
| 3166 | } sensor_scale; |
| 3167 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3168 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3169 | |
| 3170 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3171 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3172 | struct ec_response_online_calibration_data online_calib_read; |
| 3173 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3174 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3175 | uint16_t reserved; |
| 3176 | uint32_t enabled; |
| 3177 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3178 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3179 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3180 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3181 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3182 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3183 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3184 | /* |
| 3185 | * Angle between 0 and 360 degree if available, |
| 3186 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3187 | */ |
| 3188 | uint16_t value; |
| 3189 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3190 | |
| 3191 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3192 | struct __ec_todo_unpacked { |
| 3193 | /* |
| 3194 | * Lid angle threshold for switching between tablet and |
| 3195 | * clamshell mode. |
| 3196 | */ |
| 3197 | uint16_t lid_angle; |
| 3198 | |
| 3199 | /* Hysteresis degree. */ |
| 3200 | uint16_t hys_degree; |
| 3201 | } tablet_mode_threshold; |
| 3202 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3203 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3204 | struct __ec_todo_unpacked { |
| 3205 | uint8_t state; |
| 3206 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3207 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3208 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3209 | |
| 3210 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3211 | /* Force lid open command */ |
| 3212 | |
| 3213 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3214 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3215 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3216 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3217 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3218 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3219 | |
| 3220 | /*****************************************************************************/ |
| 3221 | /* Configure the behavior of the power button */ |
| 3222 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3223 | |
| 3224 | enum ec_config_power_button_flags { |
| 3225 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3226 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3227 | }; |
| 3228 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3229 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3230 | /* See enum ec_config_power_button_flags */ |
| 3231 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3232 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3233 | |
| 3234 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3235 | /* USB charging control commands */ |
| 3236 | |
| 3237 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3238 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3239 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3240 | enum usb_charge_mode { |
| 3241 | /* Disable USB port. */ |
| 3242 | USB_CHARGE_MODE_DISABLED, |
| 3243 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3244 | USB_CHARGE_MODE_SDP2, |
| 3245 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3246 | USB_CHARGE_MODE_CDP, |
| 3247 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3248 | USB_CHARGE_MODE_DCP_SHORT, |
| 3249 | /* Enable USB port (for dumb ports). */ |
| 3250 | USB_CHARGE_MODE_ENABLED, |
| 3251 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3252 | USB_CHARGE_MODE_DEFAULT, |
| 3253 | |
| 3254 | USB_CHARGE_MODE_COUNT |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3255 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3256 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3257 | enum usb_suspend_charge { |
| 3258 | /* Enable charging in suspend */ |
| 3259 | USB_ALLOW_SUSPEND_CHARGE, |
| 3260 | /* Disable charging in suspend */ |
| 3261 | USB_DISALLOW_SUSPEND_CHARGE |
| 3262 | }; |
| 3263 | |
| 3264 | struct ec_params_usb_charge_set_mode { |
| 3265 | uint8_t usb_port_id; |
| 3266 | uint8_t mode:7; /* enum usb_charge_mode */ |
| 3267 | uint8_t inhibit_charge:1; /* enum usb_suspend_charge */ |
| 3268 | } __ec_align1; |
| 3269 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3270 | /*****************************************************************************/ |
| 3271 | /* Persistent storage for host */ |
| 3272 | |
| 3273 | /* Maximum bytes that can be read/written in a single command */ |
| 3274 | #define EC_PSTORE_SIZE_MAX 64 |
| 3275 | |
| 3276 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3277 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3278 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3279 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3280 | /* Persistent storage size, in bytes */ |
| 3281 | uint32_t pstore_size; |
| 3282 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3283 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3284 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3285 | |
| 3286 | /* |
| 3287 | * Read persistent storage |
| 3288 | * |
| 3289 | * Response is params.size bytes of data. |
| 3290 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3291 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3292 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3293 | struct ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3294 | uint32_t offset; /* Byte offset to read */ |
| 3295 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3296 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3297 | |
| 3298 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3299 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3300 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3301 | struct ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3302 | uint32_t offset; /* Byte offset to write */ |
| 3303 | uint32_t size; /* Size to write in bytes */ |
| 3304 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3305 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3306 | |
| 3307 | /*****************************************************************************/ |
| 3308 | /* Real-time clock */ |
| 3309 | |
| 3310 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3311 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3312 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3313 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3314 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3315 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3316 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3317 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3318 | |
| 3319 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3320 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3321 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3322 | |
| 3323 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3324 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3325 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3326 | |
| 3327 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3328 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3329 | |
| 3330 | /*****************************************************************************/ |
| 3331 | /* Port80 log access */ |
| 3332 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3333 | /* Maximum entries that can be read/written in a single command */ |
| 3334 | #define EC_PORT80_SIZE_MAX 32 |
| 3335 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3336 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3337 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3338 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3339 | |
| 3340 | enum ec_port80_subcmd { |
| 3341 | EC_PORT80_GET_INFO = 0, |
| 3342 | EC_PORT80_READ_BUFFER, |
| 3343 | }; |
| 3344 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3345 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3346 | uint16_t subcmd; |
| 3347 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3348 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3349 | uint32_t offset; |
| 3350 | uint32_t num_entries; |
| 3351 | } read_buffer; |
| 3352 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3353 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3354 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3355 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3356 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3357 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3358 | uint32_t writes; |
| 3359 | uint32_t history_size; |
| 3360 | uint32_t last_boot; |
| 3361 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3362 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3363 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3364 | } data; |
| 3365 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3366 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3367 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3368 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3369 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3370 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3371 | |
| 3372 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3373 | /* Temporary secure storage for host verified boot use */ |
| 3374 | |
| 3375 | /* Number of bytes in a vstore slot */ |
| 3376 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3377 | |
| 3378 | /* Maximum number of vstore slots */ |
| 3379 | #define EC_VSTORE_SLOT_MAX 32 |
| 3380 | |
| 3381 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3382 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3383 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3384 | /* Indicates which slots are locked */ |
| 3385 | uint32_t slot_locked; |
| 3386 | /* Total number of slots available */ |
| 3387 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3388 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3389 | |
| 3390 | /* |
| 3391 | * Read temporary secure storage |
| 3392 | * |
| 3393 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3394 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3395 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3396 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3397 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3398 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3399 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3400 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3401 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3402 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3403 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3404 | |
| 3405 | /* |
| 3406 | * Write temporary secure storage and lock it. |
| 3407 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3408 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3409 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3410 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3411 | uint8_t slot; /* Slot to write to */ |
| 3412 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3413 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3414 | |
| 3415 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3416 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3417 | * reuse the command number, but the data and behavior is incompatible. |
| 3418 | * Version 0 is what originally shipped on Link. |
| 3419 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3420 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3421 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3422 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3423 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3424 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3425 | /* The version 0 structs are opaque. You have to know what they are for |
| 3426 | * the get/set commands to make any sense. |
| 3427 | */ |
| 3428 | |
| 3429 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3430 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3431 | uint8_t sensor_type; |
| 3432 | uint8_t threshold_id; |
| 3433 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3434 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3435 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3436 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3437 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3438 | uint8_t sensor_type; |
| 3439 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3440 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3441 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3442 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3443 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3444 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3445 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3446 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3447 | /* The version 1 structs are visible. */ |
| 3448 | enum ec_temp_thresholds { |
| 3449 | EC_TEMP_THRESH_WARN = 0, |
| 3450 | EC_TEMP_THRESH_HIGH, |
| 3451 | EC_TEMP_THRESH_HALT, |
| 3452 | |
| 3453 | EC_TEMP_THRESH_COUNT |
| 3454 | }; |
| 3455 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3456 | /* |
| 3457 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3458 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3459 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3460 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3461 | * hysteresis. |
| 3462 | * For example, |
| 3463 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3464 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3465 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3466 | * temperature <= 299 K. |
| 3467 | * |
| 3468 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3469 | * For example, |
| 3470 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3471 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3472 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3473 | * temperature <= 294 K. |
| 3474 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3475 | * Note that this structure is a sub-structure of |
| 3476 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3477 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3478 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3479 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3480 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3481 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3482 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3483 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3484 | |
| 3485 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3486 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3487 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3488 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3489 | /* This returns a struct ec_thermal_config */ |
| 3490 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3491 | /* |
| 3492 | * Version 1 - set config for one sensor. |
| 3493 | * Use read-modify-write for best results! |
| 3494 | */ |
| 3495 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3496 | uint32_t sensor_num; |
| 3497 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3498 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3499 | /* This returns no data */ |
| 3500 | |
| 3501 | /****************************************************************************/ |
| 3502 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3503 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3504 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3505 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3506 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3507 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3508 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3509 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3510 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3511 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3512 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3513 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3514 | |
| 3515 | /* |
| 3516 | * The original TMP006 calibration only needed four params, but now we need |
| 3517 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3518 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3519 | * and how many params it requires. That way we can change the EC code without |
| 3520 | * needing to update this file. We can also use a different algorithm on each |
| 3521 | * sensor. |
| 3522 | */ |
| 3523 | |
| 3524 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3525 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3526 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3527 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3528 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3529 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3530 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3531 | float s0; |
| 3532 | float b0; |
| 3533 | float b1; |
| 3534 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3535 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3536 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3537 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3538 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3539 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3540 | float s0; |
| 3541 | float b0; |
| 3542 | float b1; |
| 3543 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3544 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3545 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3546 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3547 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3548 | uint8_t algorithm; |
| 3549 | uint8_t num_params; |
| 3550 | uint8_t reserved[2]; |
| 3551 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3552 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3553 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3554 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3555 | uint8_t index; |
| 3556 | uint8_t algorithm; |
| 3557 | uint8_t num_params; |
| 3558 | uint8_t reserved; |
| 3559 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3560 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3561 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3562 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3563 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3564 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3565 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3566 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3567 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3568 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3569 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3570 | struct ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3571 | int32_t t; /* In 1/100 K */ |
| 3572 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3573 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3574 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3575 | /*****************************************************************************/ |
| 3576 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3577 | |
| 3578 | /* |
| 3579 | * Read key state |
| 3580 | * |
| 3581 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3582 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3583 | * |
| 3584 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3585 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3586 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3587 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3588 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3589 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3590 | /* |
| 3591 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3592 | */ |
| 3593 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3594 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3595 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3596 | uint32_t rows; |
| 3597 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3598 | /* Formerly "switches", which was 0. */ |
| 3599 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3600 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3601 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3602 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3603 | uint8_t info_type; |
| 3604 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3605 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3606 | |
| 3607 | enum ec_mkbp_info_type { |
| 3608 | /* |
| 3609 | * Info about the keyboard matrix: number of rows and columns. |
| 3610 | * |
| 3611 | * Returns struct ec_response_mkbp_info. |
| 3612 | */ |
| 3613 | EC_MKBP_INFO_KBD = 0, |
| 3614 | |
| 3615 | /* |
| 3616 | * For buttons and switches, info about which specifically are |
| 3617 | * supported. event_type must be set to one of the values in enum |
| 3618 | * ec_mkbp_event. |
| 3619 | * |
| 3620 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3621 | * bitmask indicating which buttons or switches are present. See the |
| 3622 | * bit inidices below. |
| 3623 | */ |
| 3624 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3625 | |
| 3626 | /* |
| 3627 | * Instantaneous state of buttons and switches. |
| 3628 | * |
| 3629 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3630 | * |
| 3631 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3632 | * indicating the current state of the keyboard matrix. |
| 3633 | * |
| 3634 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3635 | * event state. |
| 3636 | * |
| 3637 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3638 | * state of supported buttons. |
| 3639 | * |
| 3640 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3641 | * state of supported switches. |
| 3642 | */ |
| 3643 | EC_MKBP_INFO_CURRENT = 2, |
| 3644 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3645 | |
| 3646 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3647 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3649 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3650 | uint8_t col; |
| 3651 | uint8_t row; |
| 3652 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3653 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3654 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3655 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3656 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3657 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3658 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3659 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3660 | |
| 3661 | enum keyboard_id { |
| 3662 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3663 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3664 | }; |
| 3665 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3666 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3667 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3668 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3669 | |
| 3670 | /* flags */ |
| 3671 | enum mkbp_config_flags { |
| 3672 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 3673 | }; |
| 3674 | |
| 3675 | enum mkbp_config_valid { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3676 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3677 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3678 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3679 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3680 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3681 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3682 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3683 | }; |
| 3684 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3685 | /* |
| 3686 | * Configuration for our key scanning algorithm. |
| 3687 | * |
| 3688 | * Note that this is used as a sub-structure of |
| 3689 | * ec_{params/response}_mkbp_get_config. |
| 3690 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3691 | struct ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3692 | uint32_t valid_mask; /* valid fields */ |
| 3693 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3694 | uint8_t valid_flags; /* which flags are valid */ |
| 3695 | uint16_t scan_period_us; /* period between start of scans */ |
| 3696 | /* revert to interrupt mode after no activity for this long */ |
| 3697 | uint32_t poll_timeout_us; |
| 3698 | /* |
| 3699 | * minimum post-scan relax time. Once we finish a scan we check |
| 3700 | * the time until we are due to start the next one. If this time is |
| 3701 | * shorter this field, we use this instead. |
| 3702 | */ |
| 3703 | uint16_t min_post_scan_delay_us; |
| 3704 | /* delay between setting up output and waiting for it to settle */ |
| 3705 | uint16_t output_settle_us; |
| 3706 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3707 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 3708 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3709 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3710 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3711 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3712 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3713 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3714 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3715 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3716 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3717 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3718 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3719 | |
| 3720 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3721 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3722 | |
| 3723 | enum ec_keyscan_seq_cmd { |
| 3724 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3725 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3726 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3727 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3728 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 3729 | }; |
| 3730 | |
| 3731 | enum ec_collect_flags { |
| 3732 | /* |
| 3733 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3734 | * scans may be skipped. |
| 3735 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3736 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3737 | }; |
| 3738 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3739 | struct ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3740 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3741 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3742 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3743 | struct ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3744 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 3745 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3746 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3747 | uint8_t active; /* still active */ |
| 3748 | uint8_t num_items; /* number of items */ |
| 3749 | /* Current item being presented */ |
| 3750 | uint8_t cur_item; |
| 3751 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3752 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3753 | /* |
| 3754 | * Absolute time for this scan, measured from the |
| 3755 | * start of the sequence. |
| 3756 | */ |
| 3757 | uint32_t time_us; |
| 3758 | uint8_t scan[0]; /* keyscan data */ |
| 3759 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3760 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3761 | uint8_t start_item; /* First item to return */ |
| 3762 | uint8_t num_items; /* Number of items to return */ |
| 3763 | } collect; |
| 3764 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3765 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3766 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3767 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3768 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3769 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3770 | uint8_t num_items; /* Number of items */ |
| 3771 | /* Data for each item */ |
| 3772 | struct ec_collect_item item[0]; |
| 3773 | } collect; |
| 3774 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3775 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3776 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3777 | /* |
| 3778 | * Get the next pending MKBP event. |
| 3779 | * |
| 3780 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3781 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3782 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3784 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3785 | |
| 3786 | /* |
| 3787 | * We use the most significant bit of the event type to indicate to the host |
| 3788 | * that the EC has more MKBP events available to provide. |
| 3789 | */ |
| 3790 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3791 | |
| 3792 | /* The mask to apply to get the raw event type */ |
| 3793 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3794 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3795 | enum ec_mkbp_event { |
| 3796 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3797 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3798 | |
| 3799 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3800 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3801 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3802 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3803 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3804 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3805 | /* The state of the non-matrixed buttons have changed. */ |
| 3806 | EC_MKBP_EVENT_BUTTON = 3, |
| 3807 | |
| 3808 | /* The state of the switches have changed. */ |
| 3809 | EC_MKBP_EVENT_SWITCH = 4, |
| 3810 | |
| 3811 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3812 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3813 | |
| 3814 | /* |
| 3815 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3816 | * corresponding to the key to be pressed. |
| 3817 | */ |
| 3818 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3819 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3820 | /* |
| 3821 | * New 64-bit host event. |
| 3822 | * The event data is 8 bytes of host event flags. |
| 3823 | */ |
| 3824 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3825 | |
| 3826 | /* Notify the AP that something happened on CEC */ |
| 3827 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3828 | |
| 3829 | /* Send an incoming CEC message to the AP */ |
| 3830 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3831 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3832 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3833 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3834 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3835 | /* New online calibration values are available. */ |
| 3836 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3837 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 3838 | /* Peripheral device charger event */ |
| 3839 | EC_MKBP_EVENT_PCHG = 12, |
| 3840 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3841 | /* Number of MKBP events */ |
| 3842 | EC_MKBP_EVENT_COUNT, |
| 3843 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3844 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3845 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3846 | union __ec_align_offset1 ec_response_get_next_data { |
| 3847 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3848 | |
| 3849 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3850 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3851 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3852 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3853 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3854 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3855 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3856 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3857 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3858 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3859 | uint32_t buttons; |
| 3860 | |
| 3861 | uint32_t switches; |
| 3862 | |
| 3863 | uint32_t fp_events; |
| 3864 | |
| 3865 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3866 | |
| 3867 | /* CEC events from enum mkbp_cec_event */ |
| 3868 | uint32_t cec_events; |
| 3869 | }; |
| 3870 | |
| 3871 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3872 | uint8_t key_matrix[16]; |
| 3873 | |
| 3874 | /* Unaligned */ |
| 3875 | uint32_t host_event; |
| 3876 | uint64_t host_event64; |
| 3877 | |
| 3878 | struct __ec_todo_unpacked { |
| 3879 | /* For aligning the fifo_info */ |
| 3880 | uint8_t reserved[3]; |
| 3881 | struct ec_response_motion_sense_fifo_info info; |
| 3882 | } sensor_fifo; |
| 3883 | |
| 3884 | uint32_t buttons; |
| 3885 | |
| 3886 | uint32_t switches; |
| 3887 | |
| 3888 | uint32_t fp_events; |
| 3889 | |
| 3890 | uint32_t sysrq; |
| 3891 | |
| 3892 | /* CEC events from enum mkbp_cec_event */ |
| 3893 | uint32_t cec_events; |
| 3894 | |
| 3895 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3896 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3897 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3898 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3899 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3900 | uint8_t event_type; |
| 3901 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3902 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3903 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3904 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3905 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3906 | uint8_t event_type; |
| 3907 | /* Followed by event data if any */ |
| 3908 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3909 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3910 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3911 | /* Bit indices for buttons and switches.*/ |
| 3912 | /* Buttons */ |
| 3913 | #define EC_MKBP_POWER_BUTTON 0 |
| 3914 | #define EC_MKBP_VOL_UP 1 |
| 3915 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 3916 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3917 | |
| 3918 | /* Switches */ |
| 3919 | #define EC_MKBP_LID_OPEN 0 |
| 3920 | #define EC_MKBP_TABLET_MODE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3921 | #define EC_MKBP_BASE_ATTACHED 2 |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3922 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3923 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3924 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3925 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3926 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3927 | struct ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3928 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3929 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3930 | |
| 3931 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3932 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3933 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) |
| 3934 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
| 3935 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ |
| 3936 | >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
| 3937 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 3938 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
| 3939 | #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ |
| 3940 | >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3941 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 3942 | #define EC_MKBP_FP_MATCH BIT(28) |
| 3943 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 3944 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 3945 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3946 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
| 3947 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 3948 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 3949 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 3950 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 3951 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
| 3952 | /* Can be used to detect if image was usable for enrollment or not. */ |
| 3953 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
| 3954 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
| 3955 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 3956 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3957 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3958 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 3959 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 3960 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 3961 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
| 3962 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 3963 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 3964 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3965 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 3966 | enum ec_mkbp_event_mask_action { |
| 3967 | /* Retrieve the value of a wake mask. */ |
| 3968 | GET_WAKE_MASK = 0, |
| 3969 | |
| 3970 | /* Set the value of a wake mask. */ |
| 3971 | SET_WAKE_MASK, |
| 3972 | }; |
| 3973 | |
| 3974 | enum ec_mkbp_mask_type { |
| 3975 | /* |
| 3976 | * These are host events sent via MKBP. |
| 3977 | * |
| 3978 | * Some examples are: |
| 3979 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 3980 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 3981 | * |
| 3982 | * The only things that should be in this mask are: |
| 3983 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 3984 | */ |
| 3985 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 3986 | |
| 3987 | /* |
| 3988 | * These are MKBP events. Some examples are: |
| 3989 | * |
| 3990 | * EC_MKBP_EVENT_KEY_MATRIX |
| 3991 | * EC_MKBP_EVENT_SWITCH |
| 3992 | * |
| 3993 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 3994 | */ |
| 3995 | EC_MKBP_EVENT_WAKE_MASK, |
| 3996 | }; |
| 3997 | |
| 3998 | struct ec_params_mkbp_event_wake_mask { |
| 3999 | /* One of enum ec_mkbp_event_mask_action */ |
| 4000 | uint8_t action; |
| 4001 | |
| 4002 | /* |
| 4003 | * Which MKBP mask are you interested in acting upon? This is one of |
| 4004 | * ec_mkbp_mask_type. |
| 4005 | */ |
| 4006 | uint8_t mask_type; |
| 4007 | |
| 4008 | /* If setting a new wake mask, this contains the mask to set. */ |
| 4009 | uint32_t new_wake_mask; |
| 4010 | }; |
| 4011 | |
| 4012 | struct ec_response_mkbp_event_wake_mask { |
| 4013 | uint32_t wake_mask; |
| 4014 | }; |
| 4015 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4016 | /*****************************************************************************/ |
| 4017 | /* Temperature sensor commands */ |
| 4018 | |
| 4019 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4020 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4021 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4022 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4023 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4024 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4025 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4026 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4027 | char sensor_name[32]; |
| 4028 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4029 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4030 | |
| 4031 | /*****************************************************************************/ |
| 4032 | |
| 4033 | /* |
| 4034 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 4035 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 4036 | * below. |
| 4037 | */ |
| 4038 | |
| 4039 | /*****************************************************************************/ |
| 4040 | /* Host event commands */ |
| 4041 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4042 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4043 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4044 | /* |
| 4045 | * Host event mask params and response structures, shared by all of the host |
| 4046 | * event commands below. |
| 4047 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4048 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4049 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4050 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4051 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4052 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4053 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4054 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4055 | |
| 4056 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4057 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 4058 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 4059 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 4060 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4061 | |
| 4062 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4063 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 4064 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 4065 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 4066 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 4067 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4068 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4069 | /* |
| 4070 | * Unified host event programming interface - Should be used by newer versions |
| 4071 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4072 | * |
| 4073 | * EC returns: |
| 4074 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 4075 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4076 | */ |
| 4077 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4078 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4079 | |
| 4080 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 4081 | uint8_t action; |
| 4082 | |
| 4083 | /* |
| 4084 | * Mask type that the host requested the action on - one of |
| 4085 | * enum ec_host_event_mask_type. |
| 4086 | */ |
| 4087 | uint8_t mask_type; |
| 4088 | |
| 4089 | /* Set to 0, ignore on read */ |
| 4090 | uint16_t reserved; |
| 4091 | |
| 4092 | /* Value to be used in case of set operations. */ |
| 4093 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4094 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4095 | |
| 4096 | /* |
| 4097 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 4098 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 4099 | */ |
| 4100 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4101 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4102 | |
| 4103 | /* Mask value in case of get operation */ |
| 4104 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4105 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4106 | |
| 4107 | enum ec_host_event_action { |
| 4108 | /* |
| 4109 | * params.value is ignored. Value of mask_type populated |
| 4110 | * in response.value |
| 4111 | */ |
| 4112 | EC_HOST_EVENT_GET, |
| 4113 | |
| 4114 | /* Bits in params.value are set */ |
| 4115 | EC_HOST_EVENT_SET, |
| 4116 | |
| 4117 | /* Bits in params.value are cleared */ |
| 4118 | EC_HOST_EVENT_CLEAR, |
| 4119 | }; |
| 4120 | |
| 4121 | enum ec_host_event_mask_type { |
| 4122 | |
| 4123 | /* Main host event copy */ |
| 4124 | EC_HOST_EVENT_MAIN, |
| 4125 | |
| 4126 | /* Copy B of host events */ |
| 4127 | EC_HOST_EVENT_B, |
| 4128 | |
| 4129 | /* SCI Mask */ |
| 4130 | EC_HOST_EVENT_SCI_MASK, |
| 4131 | |
| 4132 | /* SMI Mask */ |
| 4133 | EC_HOST_EVENT_SMI_MASK, |
| 4134 | |
| 4135 | /* Mask of events that should be always reported in hostevents */ |
| 4136 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4137 | |
| 4138 | /* Active wake mask */ |
| 4139 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4140 | |
| 4141 | /* Lazy wake mask for S0ix */ |
| 4142 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4143 | |
| 4144 | /* Lazy wake mask for S3 */ |
| 4145 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4146 | |
| 4147 | /* Lazy wake mask for S5 */ |
| 4148 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4149 | }; |
| 4150 | |
| 4151 | #define EC_CMD_HOST_EVENT 0x00A4 |
| 4152 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4153 | /*****************************************************************************/ |
| 4154 | /* Switch commands */ |
| 4155 | |
| 4156 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4157 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4158 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4159 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4160 | uint8_t enabled; |
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 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4164 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4165 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4166 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4167 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4168 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4169 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4170 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4171 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4172 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4173 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4174 | /* Flags to enable now */ |
| 4175 | uint8_t now_flags; |
| 4176 | |
| 4177 | /* Which flags to copy from now_flags */ |
| 4178 | uint8_t now_mask; |
| 4179 | |
| 4180 | /* |
| 4181 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4182 | * transition. (Other flags will be disabled by the S0->S3 |
| 4183 | * transition.) |
| 4184 | */ |
| 4185 | uint8_t suspend_flags; |
| 4186 | |
| 4187 | /* Which flags to copy from suspend_flags */ |
| 4188 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4189 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4190 | |
| 4191 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4192 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4193 | /* Flags to enable now */ |
| 4194 | uint8_t now_flags; |
| 4195 | |
| 4196 | /* Flags to leave enabled in S3 */ |
| 4197 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4198 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4199 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4200 | /*****************************************************************************/ |
| 4201 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4202 | |
| 4203 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4204 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4205 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4206 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4207 | char name[32]; |
| 4208 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4209 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4210 | |
| 4211 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4212 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4213 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4214 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4215 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4216 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4217 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4218 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4219 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4220 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4221 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4222 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4223 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4224 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4225 | uint8_t subcmd; |
| 4226 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4227 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4228 | char name[32]; |
| 4229 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4230 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4231 | uint8_t index; |
| 4232 | } get_info; |
| 4233 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4234 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4235 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4236 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4237 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4238 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4239 | uint8_t val; |
| 4240 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4241 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4242 | uint8_t val; |
| 4243 | char name[32]; |
| 4244 | uint32_t flags; |
| 4245 | } get_info; |
| 4246 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4247 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4248 | |
| 4249 | enum gpio_get_subcmd { |
| 4250 | EC_GPIO_GET_BY_NAME = 0, |
| 4251 | EC_GPIO_GET_COUNT = 1, |
| 4252 | EC_GPIO_GET_INFO = 2, |
| 4253 | }; |
| 4254 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4255 | /*****************************************************************************/ |
| 4256 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4257 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4258 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4259 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4260 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4261 | * |
| 4262 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4263 | */ |
| 4264 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4265 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4266 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4267 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4268 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4269 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4270 | uint8_t read_size; /* Either 8 or 16. */ |
| 4271 | uint8_t port; |
| 4272 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4273 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4274 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4275 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4276 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4277 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4278 | |
| 4279 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4280 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4281 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4282 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4283 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4284 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4285 | uint8_t write_size; /* Either 8 or 16. */ |
| 4286 | uint8_t port; |
| 4287 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4288 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4289 | |
| 4290 | /*****************************************************************************/ |
| 4291 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4292 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4293 | /* Force charge state machine to stop charging the battery or force it to |
| 4294 | * discharge the battery. |
| 4295 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4296 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4297 | #define EC_VER_CHARGE_CONTROL 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4298 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4299 | enum ec_charge_control_mode { |
| 4300 | CHARGE_CONTROL_NORMAL = 0, |
| 4301 | CHARGE_CONTROL_IDLE, |
| 4302 | CHARGE_CONTROL_DISCHARGE, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4303 | /* Add no more entry below. */ |
| 4304 | CHARGE_CONTROL_COUNT, |
| 4305 | }; |
| 4306 | |
| 4307 | #define EC_CHARGE_MODE_TEXT { \ |
| 4308 | [CHARGE_CONTROL_NORMAL] = "NORMAL", \ |
| 4309 | [CHARGE_CONTROL_IDLE] = "IDLE", \ |
| 4310 | [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ |
| 4311 | } |
| 4312 | |
| 4313 | enum ec_charge_control_cmd { |
| 4314 | EC_CHARGE_CONTROL_CMD_SET = 0, |
| 4315 | EC_CHARGE_CONTROL_CMD_GET, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4316 | }; |
| 4317 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4318 | struct ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4319 | uint32_t mode; /* enum charge_control_mode */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4320 | |
| 4321 | /* Below are the fields added in V2. */ |
| 4322 | uint8_t cmd; /* enum ec_charge_control_cmd. */ |
| 4323 | uint8_t reserved; |
| 4324 | /* |
| 4325 | * Lower and upper thresholds for battery sustainer. This struct isn't |
| 4326 | * named to avoid tainting foreign projects' name spaces. |
| 4327 | * |
| 4328 | * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer |
| 4329 | * will be disabled. To disable battery sustainer, set mode=NORMAL, |
| 4330 | * lower=-1, upper=-1. |
| 4331 | */ |
| 4332 | struct { |
| 4333 | int8_t lower; /* Display SoC in percentage. */ |
| 4334 | int8_t upper; /* Display SoC in percentage. */ |
| 4335 | } sustain_soc; |
| 4336 | } __ec_align4; |
| 4337 | |
| 4338 | /* Added in v2 */ |
| 4339 | struct ec_response_charge_control { |
| 4340 | uint32_t mode; /* enum charge_control_mode */ |
| 4341 | struct { /* Battery sustainer thresholds */ |
| 4342 | int8_t lower; |
| 4343 | int8_t upper; |
| 4344 | } sustain_soc; |
| 4345 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4346 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4347 | |
| 4348 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4349 | |
| 4350 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4351 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4352 | |
| 4353 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4354 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4355 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4356 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4357 | * end of the previous snapshot. |
| 4358 | * |
| 4359 | * The params are only looked at in version >= 1 of this command. Prior |
| 4360 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4361 | * |
| 4362 | * Response is null-terminated string. Empty string, if there is no more |
| 4363 | * remaining output. |
| 4364 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4365 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4366 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4367 | enum ec_console_read_subcmd { |
| 4368 | CONSOLE_READ_NEXT = 0, |
| 4369 | CONSOLE_READ_RECENT |
| 4370 | }; |
| 4371 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4372 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4373 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4374 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4375 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4376 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4377 | |
| 4378 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4379 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4380 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4381 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4382 | * EC_RES_SUCCESS if the command was successful. |
| 4383 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4384 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4385 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4386 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4387 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4388 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4389 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4390 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4391 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4392 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4393 | /*****************************************************************************/ |
| 4394 | /* USB port mux control. */ |
| 4395 | |
| 4396 | /* |
| 4397 | * Switch USB mux or return to automatic switching. |
| 4398 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4399 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4400 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4401 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4402 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4403 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4404 | |
| 4405 | /*****************************************************************************/ |
| 4406 | /* LDOs / FETs control. */ |
| 4407 | |
| 4408 | enum ec_ldo_state { |
| 4409 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4410 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 4411 | }; |
| 4412 | |
| 4413 | /* |
| 4414 | * Switch on/off a LDO. |
| 4415 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4416 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4417 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4418 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4419 | uint8_t index; |
| 4420 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4421 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4422 | |
| 4423 | /* |
| 4424 | * Get LDO state. |
| 4425 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4426 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4427 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4428 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4429 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4430 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4431 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4432 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4433 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4434 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4435 | |
| 4436 | /*****************************************************************************/ |
| 4437 | /* Power info. */ |
| 4438 | |
| 4439 | /* |
| 4440 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4441 | * |
| 4442 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4443 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4444 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4445 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4446 | /* |
| 4447 | * v1 of EC_CMD_POWER_INFO |
| 4448 | */ |
| 4449 | enum system_power_source { |
| 4450 | /* |
| 4451 | * Haven't established which power source is used yet, |
| 4452 | * or no presence signals are available |
| 4453 | */ |
| 4454 | POWER_SOURCE_UNKNOWN = 0, |
| 4455 | /* System is running on battery alone */ |
| 4456 | POWER_SOURCE_BATTERY = 1, |
| 4457 | /* System is running on A/C alone */ |
| 4458 | POWER_SOURCE_AC = 2, |
| 4459 | /* System is running on A/C and battery */ |
| 4460 | POWER_SOURCE_AC_BATTERY = 3, |
| 4461 | }; |
| 4462 | |
| 4463 | struct ec_response_power_info_v1 { |
| 4464 | /* enum system_power_source */ |
| 4465 | uint8_t system_power_source; |
| 4466 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4467 | uint8_t battery_soc; |
| 4468 | /* AC Adapter 100% rating, Watts */ |
| 4469 | uint8_t ac_adapter_100pct; |
| 4470 | /* AC Adapter 10ms rating, Watts */ |
| 4471 | uint8_t ac_adapter_10ms; |
| 4472 | /* Battery 1C rating, derated */ |
| 4473 | uint8_t battery_1cd; |
| 4474 | /* Rest of Platform average, Watts */ |
| 4475 | uint8_t rop_avg; |
| 4476 | /* Rest of Platform peak, Watts */ |
| 4477 | uint8_t rop_peak; |
| 4478 | /* Nominal charger efficiency, % */ |
| 4479 | uint8_t nominal_charger_eff; |
| 4480 | /* Rest of Platform VR Average Efficiency, % */ |
| 4481 | uint8_t rop_avg_eff; |
| 4482 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4483 | uint8_t rop_peak_eff; |
| 4484 | /* SoC VR Efficiency at Average level, % */ |
| 4485 | uint8_t soc_avg_eff; |
| 4486 | /* SoC VR Efficiency at Peak level, % */ |
| 4487 | uint8_t soc_peak_eff; |
| 4488 | /* Intel-specific items */ |
| 4489 | struct { |
| 4490 | /* Battery's level of DBPT support: 0, 2 */ |
| 4491 | uint8_t batt_dbpt_support_level; |
| 4492 | /* |
| 4493 | * Maximum peak power from battery (10ms), Watts |
| 4494 | * If DBPT is not supported, this is 0 |
| 4495 | */ |
| 4496 | uint8_t batt_dbpt_max_peak_power; |
| 4497 | /* |
| 4498 | * Sustained peak power from battery, Watts |
| 4499 | * If DBPT is not supported, this is 0 |
| 4500 | */ |
| 4501 | uint8_t batt_dbpt_sus_peak_power; |
| 4502 | } intel; |
| 4503 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4504 | |
| 4505 | /*****************************************************************************/ |
| 4506 | /* I2C passthru command */ |
| 4507 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4508 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4509 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4510 | /* Read data; if not present, message is a write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4511 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4512 | |
| 4513 | /* Mask for address */ |
| 4514 | #define EC_I2C_ADDR_MASK 0x3ff |
| 4515 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4516 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4517 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4518 | |
| 4519 | /* Any error */ |
| 4520 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 4521 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4522 | struct ec_params_i2c_passthru_msg { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 4523 | uint16_t addr_flags; /* I2C peripheral address and flags */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4524 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4525 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4526 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4527 | struct ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4528 | uint8_t port; /* I2C port number */ |
| 4529 | uint8_t num_msgs; /* Number of messages */ |
| 4530 | struct ec_params_i2c_passthru_msg msg[]; |
| 4531 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4532 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4533 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4534 | struct ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4535 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4536 | uint8_t num_msgs; /* Number of messages processed */ |
| 4537 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4538 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4539 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4540 | /*****************************************************************************/ |
| 4541 | /* Power button hang detect */ |
| 4542 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4543 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4544 | |
| 4545 | /* Reasons to start hang detection timer */ |
| 4546 | /* Power button pressed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4547 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4548 | |
| 4549 | /* Lid closed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4550 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4551 | |
| 4552 | /* Lid opened */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4553 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4554 | |
| 4555 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4556 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4557 | |
| 4558 | /* Reasons to cancel hang detection */ |
| 4559 | |
| 4560 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4561 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4562 | |
| 4563 | /* Any host command from AP received */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4564 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4565 | |
| 4566 | /* 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] | 4567 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4568 | |
| 4569 | /* |
| 4570 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4571 | * timer is started. This provides the AP a way to start the hang timer |
| 4572 | * without reconfiguring any of the other hang detect settings. Note that |
| 4573 | * you must previously have configured the timeouts. |
| 4574 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4575 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4576 | |
| 4577 | /* |
| 4578 | * If this flag is set, all the other fields are ignored (including |
| 4579 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4580 | * without reconfiguring any of the other hang detect settings. |
| 4581 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4582 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4583 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4584 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4585 | /* Flags; see EC_HANG_* */ |
| 4586 | uint32_t flags; |
| 4587 | |
| 4588 | /* Timeout in msec before generating host event, if enabled */ |
| 4589 | uint16_t host_event_timeout_msec; |
| 4590 | |
| 4591 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4592 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4593 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4594 | |
| 4595 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4596 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4597 | |
| 4598 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4599 | * This is the single catch-all host command to exchange data regarding the |
| 4600 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4601 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4602 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4603 | |
| 4604 | /* Subcommands for this host command */ |
| 4605 | enum charge_state_command { |
| 4606 | CHARGE_STATE_CMD_GET_STATE, |
| 4607 | CHARGE_STATE_CMD_GET_PARAM, |
| 4608 | CHARGE_STATE_CMD_SET_PARAM, |
| 4609 | CHARGE_STATE_NUM_CMDS |
| 4610 | }; |
| 4611 | |
| 4612 | /* |
| 4613 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4614 | * params, which are handled by the particular implementations. |
| 4615 | */ |
| 4616 | enum charge_state_params { |
| 4617 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 4618 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 4619 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 4620 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 4621 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4622 | CS_PARAM_LIMIT_POWER, /* |
| 4623 | * Check if power is limited due to |
| 4624 | * low battery and / or a weak external |
| 4625 | * charger. READ ONLY. |
| 4626 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4627 | /* How many so far? */ |
| 4628 | CS_NUM_BASE_PARAMS, |
| 4629 | |
| 4630 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4631 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4632 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4633 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4634 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4635 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4636 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4637 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4638 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4639 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4640 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4641 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4642 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4643 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4644 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4645 | /* Other custom param ranges go here... */ |
| 4646 | }; |
| 4647 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4648 | struct ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4649 | uint8_t cmd; /* enum charge_state_command */ |
| 4650 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4651 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4652 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4653 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4654 | uint32_t param; /* enum charge_state_param */ |
| 4655 | } get_param; |
| 4656 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4657 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4658 | uint32_t param; /* param to set */ |
| 4659 | uint32_t value; /* value to set */ |
| 4660 | } set_param; |
| 4661 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 4662 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4663 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4664 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4665 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4666 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4667 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4668 | int ac; |
| 4669 | int chg_voltage; |
| 4670 | int chg_current; |
| 4671 | int chg_input_current; |
| 4672 | int batt_state_of_charge; |
| 4673 | } get_state; |
| 4674 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4675 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4676 | uint32_t value; |
| 4677 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4678 | |
| 4679 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4680 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4681 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4682 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4683 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4684 | /* |
| 4685 | * Set maximum battery charging current. |
| 4686 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4687 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4688 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4689 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4690 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4691 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4692 | |
| 4693 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4694 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4695 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4696 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4697 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4698 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4699 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4700 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4701 | 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] | 4702 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4703 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4704 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4705 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4706 | /* |
| 4707 | * Set maximum voltage & current of a dedicated charge port |
| 4708 | */ |
| 4709 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4710 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4711 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4712 | uint16_t current_lim; /* in mA */ |
| 4713 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4714 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4715 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4716 | /*****************************************************************************/ |
| 4717 | /* Hibernate/Deep Sleep Commands */ |
| 4718 | |
| 4719 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4720 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4721 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4722 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4723 | /* |
| 4724 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4725 | * current settings without changing them. |
| 4726 | */ |
| 4727 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4728 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4729 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4730 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4731 | /* |
| 4732 | * The current time in seconds in which the system has been in the G3 |
| 4733 | * state. This value is reset if the EC transitions out of G3. |
| 4734 | */ |
| 4735 | uint32_t time_g3; |
| 4736 | |
| 4737 | /* |
| 4738 | * The current time remaining in seconds until the EC should hibernate. |
| 4739 | * This value is also reset if the EC transitions out of G3. |
| 4740 | */ |
| 4741 | uint32_t time_remaining; |
| 4742 | |
| 4743 | /* |
| 4744 | * The current time in seconds that the EC should wait in G3 before |
| 4745 | * hibernating. |
| 4746 | */ |
| 4747 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4748 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4749 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4750 | /* Inform the EC when entering a sleep state */ |
| 4751 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4752 | |
| 4753 | enum host_sleep_event { |
| 4754 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4755 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 4756 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4757 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
| 4758 | /* S3 suspend with additional enabled wake sources */ |
| 4759 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4760 | }; |
| 4761 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4762 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4763 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4764 | } __ec_align1; |
| 4765 | |
| 4766 | /* |
| 4767 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4768 | * transition failures |
| 4769 | */ |
| 4770 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4771 | |
| 4772 | /* Disable timeout detection for this sleep transition */ |
| 4773 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4774 | |
| 4775 | struct ec_params_host_sleep_event_v1 { |
| 4776 | /* The type of sleep being entered or exited. */ |
| 4777 | uint8_t sleep_event; |
| 4778 | |
| 4779 | /* Padding */ |
| 4780 | uint8_t reserved; |
| 4781 | union { |
| 4782 | /* Parameters that apply for suspend messages. */ |
| 4783 | struct { |
| 4784 | /* |
| 4785 | * The timeout in milliseconds between when this message |
| 4786 | * is received and when the EC will declare sleep |
| 4787 | * transition failure if the sleep signal is not |
| 4788 | * asserted. |
| 4789 | */ |
| 4790 | uint16_t sleep_timeout_ms; |
| 4791 | } suspend_params; |
| 4792 | |
| 4793 | /* No parameters for non-suspend messages. */ |
| 4794 | }; |
| 4795 | } __ec_align2; |
| 4796 | |
| 4797 | /* A timeout occurred when this bit is set */ |
| 4798 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4799 | |
| 4800 | /* |
| 4801 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4802 | * as well as the maximum number of suspend line transitions that will be |
| 4803 | * reported back to the host. |
| 4804 | */ |
| 4805 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4806 | |
| 4807 | struct ec_response_host_sleep_event_v1 { |
| 4808 | union { |
| 4809 | /* Response fields that apply for resume messages. */ |
| 4810 | struct { |
| 4811 | /* |
| 4812 | * The number of sleep power signal transitions that |
| 4813 | * occurred since the suspend message. The high bit |
| 4814 | * indicates a timeout occurred. |
| 4815 | */ |
| 4816 | uint32_t sleep_transitions; |
| 4817 | } resume_response; |
| 4818 | |
| 4819 | /* No response fields for non-resume messages. */ |
| 4820 | }; |
| 4821 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4822 | |
| 4823 | /*****************************************************************************/ |
| 4824 | /* Device events */ |
| 4825 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4826 | |
| 4827 | enum ec_device_event { |
| 4828 | EC_DEVICE_EVENT_TRACKPAD, |
| 4829 | EC_DEVICE_EVENT_DSP, |
| 4830 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 4831 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4832 | }; |
| 4833 | |
| 4834 | enum ec_device_event_param { |
| 4835 | /* Get and clear pending device events */ |
| 4836 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4837 | /* Get device event mask */ |
| 4838 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4839 | /* Set device event mask */ |
| 4840 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4841 | }; |
| 4842 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4843 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4844 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4845 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4846 | uint32_t event_mask; |
| 4847 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4848 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4849 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4850 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4851 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4852 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4853 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4854 | /*****************************************************************************/ |
| 4855 | /* Smart battery pass-through */ |
| 4856 | |
| 4857 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4858 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4859 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4860 | |
| 4861 | /* Get / Set string smart battery parameters |
| 4862 | * formatted as SMBUS "block". |
| 4863 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4864 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 4865 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4866 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4867 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4868 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4869 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4870 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4871 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4872 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4873 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4874 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4875 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4876 | uint8_t reg; |
| 4877 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4878 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4879 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4880 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4881 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4882 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4883 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4884 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4885 | uint8_t reg; |
| 4886 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4887 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4888 | |
| 4889 | /*****************************************************************************/ |
| 4890 | /* Battery vendor parameters |
| 4891 | * |
| 4892 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 4893 | * differ between boards or batteries. On a set operation, the response |
| 4894 | * contains the actual value set, which may be rounded or clipped from the |
| 4895 | * requested value. |
| 4896 | */ |
| 4897 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4898 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4899 | |
| 4900 | enum ec_battery_vendor_param_mode { |
| 4901 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 4902 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 4903 | }; |
| 4904 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4905 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4906 | uint32_t param; |
| 4907 | uint32_t value; |
| 4908 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4909 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4910 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4911 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4912 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4913 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4914 | |
| 4915 | /*****************************************************************************/ |
| 4916 | /* |
| 4917 | * Smart Battery Firmware Update Commands |
| 4918 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4919 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4920 | |
| 4921 | enum ec_sb_fw_update_subcmd { |
| 4922 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 4923 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 4924 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 4925 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 4926 | EC_SB_FW_UPDATE_END = 0x4, |
| 4927 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 4928 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 4929 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 4930 | }; |
| 4931 | |
| 4932 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 4933 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 4934 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 4935 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4936 | struct ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4937 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 4938 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4939 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4940 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4941 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4942 | struct ec_sb_fw_update_header hdr; |
| 4943 | union { |
| 4944 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 4945 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 4946 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 4947 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 4948 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 4949 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4950 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4951 | |
| 4952 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4953 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4954 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 4955 | } write; |
| 4956 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4957 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4958 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4959 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4960 | union { |
| 4961 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4962 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4963 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 4964 | } info; |
| 4965 | |
| 4966 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4967 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4968 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 4969 | } status; |
| 4970 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4971 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4972 | |
| 4973 | /* |
| 4974 | * Entering Verified Boot Mode Command |
| 4975 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 4976 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4977 | * |
| 4978 | * EC no longer needs to know what mode vboot has entered, |
| 4979 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4980 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4981 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4982 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4983 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4984 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4985 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4986 | |
| 4987 | #define VBOOT_MODE_NORMAL 0 |
| 4988 | #define VBOOT_MODE_DEVELOPER 1 |
| 4989 | #define VBOOT_MODE_RECOVERY 2 |
| 4990 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4991 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4992 | /* |
| 4993 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 4994 | * certain addresses (board-specific). |
| 4995 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4996 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4997 | |
| 4998 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4999 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 5000 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 5001 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5002 | }; |
| 5003 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5004 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5005 | uint8_t subcmd; |
| 5006 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5007 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5008 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5009 | struct ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5010 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5011 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5012 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5013 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5014 | /*****************************************************************************/ |
| 5015 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5016 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5017 | * |
| 5018 | * These commands are for sending and receiving message via HDMI CEC |
| 5019 | */ |
| 5020 | |
| 5021 | #define MAX_CEC_MSG_LEN 16 |
| 5022 | |
| 5023 | /* CEC message from the AP to be written on the CEC bus */ |
| 5024 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 5025 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5026 | /** |
| 5027 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 5028 | * @msg: message content to write to the CEC bus |
| 5029 | */ |
| 5030 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5031 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5032 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5033 | |
| 5034 | /* Set various CEC parameters */ |
| 5035 | #define EC_CMD_CEC_SET 0x00BA |
| 5036 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5037 | /** |
| 5038 | * struct ec_params_cec_set - CEC parameters set |
| 5039 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5040 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 5041 | * or 1 to enable CEC functionality, in case cmd is |
| 5042 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 5043 | * address between 0 and 15 or 0xff to unregister |
| 5044 | */ |
| 5045 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5046 | uint8_t cmd; /* enum cec_command */ |
| 5047 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5048 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5049 | |
| 5050 | /* Read various CEC parameters */ |
| 5051 | #define EC_CMD_CEC_GET 0x00BB |
| 5052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5053 | /** |
| 5054 | * struct ec_params_cec_get - CEC parameters get |
| 5055 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5056 | */ |
| 5057 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5058 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5059 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5060 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5061 | /** |
| 5062 | * struct ec_response_cec_get - CEC parameters get response |
| 5063 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 5064 | * disabled or 1 if CEC functionality is enabled, |
| 5065 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 5066 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 5067 | */ |
| 5068 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5069 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5070 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5071 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5072 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5073 | enum cec_command { |
| 5074 | /* CEC reading, writing and events enable */ |
| 5075 | CEC_CMD_ENABLE, |
| 5076 | /* CEC logical address */ |
| 5077 | CEC_CMD_LOGICAL_ADDRESS, |
| 5078 | }; |
| 5079 | |
| 5080 | /* Events from CEC to AP */ |
| 5081 | enum mkbp_cec_event { |
| 5082 | /* Outgoing message was acknowledged by a follower */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5083 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5084 | /* Outgoing message was not acknowledged */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5085 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5086 | }; |
| 5087 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5088 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5089 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5090 | /* Commands for audio codec. */ |
| 5091 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5092 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5093 | enum ec_codec_subcmd { |
| 5094 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 5095 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 5096 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 5097 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5098 | }; |
| 5099 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5100 | enum ec_codec_cap { |
| 5101 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 5102 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 5103 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5104 | }; |
| 5105 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5106 | enum ec_codec_shm_id { |
| 5107 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 5108 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 5109 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5110 | }; |
| 5111 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5112 | enum ec_codec_shm_type { |
| 5113 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 5114 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5115 | }; |
| 5116 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5117 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 5118 | uint8_t shm_id; |
| 5119 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5120 | }; |
| 5121 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5122 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 5123 | uint64_t phys_addr; |
| 5124 | uint32_t len; |
| 5125 | uint8_t shm_id; |
| 5126 | uint8_t reserved[3]; |
| 5127 | }; |
| 5128 | |
| 5129 | struct __ec_align4 ec_param_ec_codec { |
| 5130 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 5131 | uint8_t reserved[3]; |
| 5132 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5133 | union { |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5134 | struct ec_param_ec_codec_get_shm_addr |
| 5135 | get_shm_addr_param; |
| 5136 | struct ec_param_ec_codec_set_shm_addr |
| 5137 | set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5138 | }; |
| 5139 | }; |
| 5140 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5141 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 5142 | uint32_t capabilities; |
| 5143 | }; |
| 5144 | |
| 5145 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5146 | uint64_t phys_addr; |
| 5147 | uint32_t len; |
| 5148 | uint8_t type; |
| 5149 | uint8_t reserved[3]; |
| 5150 | }; |
| 5151 | |
| 5152 | /*****************************************************************************/ |
| 5153 | |
| 5154 | /* Commands for DMIC on audio codec. */ |
| 5155 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5156 | |
| 5157 | enum ec_codec_dmic_subcmd { |
| 5158 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5159 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5160 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5161 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5162 | }; |
| 5163 | |
| 5164 | enum ec_codec_dmic_channel { |
| 5165 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5166 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5167 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5168 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5169 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5170 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5171 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5172 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5173 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5174 | }; |
| 5175 | |
| 5176 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5177 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5178 | uint8_t gain; |
| 5179 | uint8_t reserved[2]; |
| 5180 | }; |
| 5181 | |
| 5182 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5183 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5184 | uint8_t reserved[3]; |
| 5185 | }; |
| 5186 | |
| 5187 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5188 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5189 | uint8_t reserved[3]; |
| 5190 | |
| 5191 | union { |
| 5192 | struct ec_param_ec_codec_dmic_set_gain_idx |
| 5193 | set_gain_idx_param; |
| 5194 | struct ec_param_ec_codec_dmic_get_gain_idx |
| 5195 | get_gain_idx_param; |
| 5196 | }; |
| 5197 | }; |
| 5198 | |
| 5199 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5200 | uint8_t max_gain; |
| 5201 | }; |
| 5202 | |
| 5203 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5204 | uint8_t gain; |
| 5205 | }; |
| 5206 | |
| 5207 | /*****************************************************************************/ |
| 5208 | |
| 5209 | /* Commands for I2S RX on audio codec. */ |
| 5210 | |
| 5211 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5212 | |
| 5213 | enum ec_codec_i2s_rx_subcmd { |
| 5214 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5215 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5216 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5217 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5218 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5219 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5220 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5221 | }; |
| 5222 | |
| 5223 | enum ec_codec_i2s_rx_sample_depth { |
| 5224 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5225 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5226 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5227 | }; |
| 5228 | |
| 5229 | enum ec_codec_i2s_rx_daifmt { |
| 5230 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5231 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5232 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5233 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5234 | }; |
| 5235 | |
| 5236 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5237 | uint8_t depth; |
| 5238 | uint8_t reserved[3]; |
| 5239 | }; |
| 5240 | |
| 5241 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5242 | uint8_t left; |
| 5243 | uint8_t right; |
| 5244 | uint8_t reserved[2]; |
| 5245 | }; |
| 5246 | |
| 5247 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5248 | uint8_t daifmt; |
| 5249 | uint8_t reserved[3]; |
| 5250 | }; |
| 5251 | |
| 5252 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5253 | uint32_t bclk; |
| 5254 | }; |
| 5255 | |
| 5256 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5257 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5258 | uint8_t reserved[3]; |
| 5259 | |
| 5260 | union { |
| 5261 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
| 5262 | set_sample_depth_param; |
| 5263 | struct ec_param_ec_codec_i2s_rx_set_daifmt |
| 5264 | set_daifmt_param; |
| 5265 | struct ec_param_ec_codec_i2s_rx_set_bclk |
| 5266 | set_bclk_param; |
| 5267 | }; |
| 5268 | }; |
| 5269 | |
| 5270 | /*****************************************************************************/ |
| 5271 | /* Commands for WoV on audio codec. */ |
| 5272 | |
| 5273 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5274 | |
| 5275 | enum ec_codec_wov_subcmd { |
| 5276 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5277 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5278 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5279 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5280 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5281 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5282 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5283 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5284 | }; |
| 5285 | |
| 5286 | /* |
| 5287 | * @hash is SHA256 of the whole language model. |
| 5288 | * @total_len indicates the length of whole language model. |
| 5289 | * @offset is the cursor from the beginning of the model. |
| 5290 | * @buf is the packet buffer. |
| 5291 | * @len denotes how many bytes in the buf. |
| 5292 | */ |
| 5293 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5294 | uint8_t hash[32]; |
| 5295 | uint32_t total_len; |
| 5296 | uint32_t offset; |
| 5297 | uint8_t buf[128]; |
| 5298 | uint32_t len; |
| 5299 | }; |
| 5300 | |
| 5301 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5302 | uint8_t hash[32]; |
| 5303 | uint32_t total_len; |
| 5304 | }; |
| 5305 | |
| 5306 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5307 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5308 | uint8_t reserved[3]; |
| 5309 | |
| 5310 | union { |
| 5311 | struct ec_param_ec_codec_wov_set_lang |
| 5312 | set_lang_param; |
| 5313 | struct ec_param_ec_codec_wov_set_lang_shm |
| 5314 | set_lang_shm_param; |
| 5315 | }; |
| 5316 | }; |
| 5317 | |
| 5318 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5319 | uint8_t hash[32]; |
| 5320 | }; |
| 5321 | |
| 5322 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5323 | uint8_t buf[128]; |
| 5324 | uint32_t len; |
| 5325 | }; |
| 5326 | |
| 5327 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5328 | uint32_t offset; |
| 5329 | uint32_t len; |
| 5330 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5331 | |
| 5332 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5333 | /* Commands for PoE PSE controller */ |
| 5334 | |
| 5335 | #define EC_CMD_PSE 0x00C0 |
| 5336 | |
| 5337 | enum ec_pse_subcmd { |
| 5338 | EC_PSE_STATUS = 0x0, |
| 5339 | EC_PSE_ENABLE = 0x1, |
| 5340 | EC_PSE_DISABLE = 0x2, |
| 5341 | EC_PSE_SUBCMD_COUNT, |
| 5342 | }; |
| 5343 | |
| 5344 | struct __ec_align1 ec_params_pse { |
| 5345 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5346 | uint8_t port; /* PSE port */ |
| 5347 | }; |
| 5348 | |
| 5349 | enum ec_pse_status { |
| 5350 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5351 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5352 | EC_PSE_STATUS_POWERED = 0x2, |
| 5353 | }; |
| 5354 | |
| 5355 | struct __ec_align1 ec_response_pse_status { |
| 5356 | uint8_t status; /* enum ec_pse_status */ |
| 5357 | }; |
| 5358 | |
| 5359 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5360 | /* System commands */ |
| 5361 | |
| 5362 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5363 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5364 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5365 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5366 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5367 | |
| 5368 | /* Command */ |
| 5369 | enum ec_reboot_cmd { |
| 5370 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5371 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5372 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5373 | /* (command 3 was jump to RW-B) */ |
| 5374 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5375 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
Daisuke Nojiri | 40d0bfa | 2017-11-30 17:41:09 -0800 | [diff] [blame] | 5376 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5377 | 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] | 5378 | 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] | 5379 | }; |
| 5380 | |
| 5381 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5382 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5383 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5384 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5385 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5386 | struct ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5387 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5388 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5389 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5390 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5391 | /* |
| 5392 | * Get information on last EC panic. |
| 5393 | * |
| 5394 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5395 | * for details. |
| 5396 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5397 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5398 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5399 | /*****************************************************************************/ |
| 5400 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5401 | * Special commands |
| 5402 | * |
| 5403 | * These do not follow the normal rules for commands. See each command for |
| 5404 | * details. |
| 5405 | */ |
| 5406 | |
| 5407 | /* |
| 5408 | * Reboot NOW |
| 5409 | * |
| 5410 | * This command will work even when the EC LPC interface is busy, because the |
| 5411 | * reboot command is processed at interrupt level. Note that when the EC |
| 5412 | * reboots, the host will reboot too, so there is no response to this command. |
| 5413 | * |
| 5414 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5415 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5416 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5417 | |
| 5418 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5419 | * Resend last response (not supported on LPC). |
| 5420 | * |
| 5421 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5422 | * there was no previous command, or the previous command's response was too |
| 5423 | * big to save. |
| 5424 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5425 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5426 | |
| 5427 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5428 | * This header byte on a command indicate version 0. Any header byte less |
| 5429 | * than this means that we are talking to an old EC which doesn't support |
| 5430 | * versioning. In that case, we assume version 0. |
| 5431 | * |
| 5432 | * Header bytes greater than this indicate a later version. For example, |
| 5433 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5434 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5435 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5436 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5437 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5438 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5439 | /*****************************************************************************/ |
| 5440 | /* |
| 5441 | * PD commands |
| 5442 | * |
| 5443 | * These commands are for PD MCU communication. |
| 5444 | */ |
| 5445 | |
| 5446 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5447 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5448 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5449 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5450 | enum pd_charge_state { |
| 5451 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 5452 | PD_CHARGE_NONE, /* No charging allowed */ |
| 5453 | PD_CHARGE_5V, /* 5V charging only */ |
| 5454 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 5455 | }; |
| 5456 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5457 | /* Status of EC being sent to PD */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5458 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5459 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5460 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5461 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5462 | int8_t batt_soc; /* battery state of charge */ |
| 5463 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5464 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5465 | |
| 5466 | /* Status of PD being sent back to EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5467 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5468 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
| 5469 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
| 5470 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5471 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5472 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5473 | #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] | 5474 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 5475 | PD_STATUS_TCPC_ALERT_1 | \ |
| 5476 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5477 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5478 | uint32_t curr_lim_ma; /* input current limit */ |
| 5479 | uint16_t status; /* PD MCU status */ |
| 5480 | int8_t active_charge_port; /* active charging port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5481 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5482 | |
| 5483 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5484 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5485 | |
| 5486 | /* PD MCU host event status bits */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5487 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5488 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5489 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5490 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5491 | #define PD_EVENT_TYPEC BIT(4) |
| 5492 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5493 | struct ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5494 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5495 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5496 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5497 | /* |
| 5498 | * Set USB type-C port role and muxes |
| 5499 | * |
| 5500 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5501 | * |
| 5502 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5503 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5504 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5505 | |
| 5506 | enum usb_pd_control_role { |
| 5507 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5508 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5509 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5510 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5511 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5512 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5513 | USB_PD_CTRL_ROLE_COUNT |
| 5514 | }; |
| 5515 | |
| 5516 | enum usb_pd_control_mux { |
| 5517 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5518 | USB_PD_CTRL_MUX_NONE = 1, |
| 5519 | USB_PD_CTRL_MUX_USB = 2, |
| 5520 | USB_PD_CTRL_MUX_DP = 3, |
| 5521 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5522 | USB_PD_CTRL_MUX_AUTO = 5, |
| 5523 | USB_PD_CTRL_MUX_COUNT |
| 5524 | }; |
| 5525 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5526 | enum usb_pd_control_swap { |
| 5527 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5528 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5529 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5530 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 5531 | USB_PD_CTRL_SWAP_COUNT |
| 5532 | }; |
| 5533 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5534 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5535 | uint8_t port; |
| 5536 | uint8_t role; |
| 5537 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5538 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5539 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5540 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5541 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5542 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
| 5543 | #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] | 5544 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5545 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5546 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5547 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5548 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5549 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5550 | #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] | 5551 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5552 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5553 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5554 | uint8_t enabled; |
| 5555 | uint8_t role; |
| 5556 | uint8_t polarity; |
| 5557 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5558 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5559 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5560 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5561 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5562 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5563 | uint8_t polarity; |
| 5564 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5565 | } __ec_align1; |
| 5566 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5567 | /* Possible port partner connections based on CC line states */ |
| 5568 | enum pd_cc_states { |
| 5569 | PD_CC_NONE = 0, /* No port partner attached */ |
| 5570 | |
| 5571 | /* From DFP perspective */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5572 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5573 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5574 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5575 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
| 5576 | |
| 5577 | /* From UFP perspective */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5578 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5579 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5580 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5581 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5582 | /* Active/Passive Cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5583 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5584 | /* Optical/Non-optical cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5585 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5586 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5587 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
| 5588 | /* Active Link Uni-Direction */ |
| 5589 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5590 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5591 | struct ec_response_usb_pd_control_v2 { |
| 5592 | uint8_t enabled; |
| 5593 | uint8_t role; |
| 5594 | uint8_t polarity; |
| 5595 | char state[32]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5596 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5597 | 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] | 5598 | uint8_t reserved; /* Reserved for future use */ |
| 5599 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 5600 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5601 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5602 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5603 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5604 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5605 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5606 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5607 | #define EC_USB_PD_MAX_PORTS 8 |
| 5608 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5609 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5610 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5611 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5612 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5613 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5614 | |
| 5615 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5616 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5617 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5618 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5619 | |
| 5620 | enum usb_chg_type { |
| 5621 | USB_CHG_TYPE_NONE, |
| 5622 | USB_CHG_TYPE_PD, |
| 5623 | USB_CHG_TYPE_C, |
| 5624 | USB_CHG_TYPE_PROPRIETARY, |
| 5625 | USB_CHG_TYPE_BC12_DCP, |
| 5626 | USB_CHG_TYPE_BC12_CDP, |
| 5627 | USB_CHG_TYPE_BC12_SDP, |
| 5628 | USB_CHG_TYPE_OTHER, |
| 5629 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5630 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5631 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5632 | }; |
| 5633 | enum usb_power_roles { |
| 5634 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5635 | USB_PD_PORT_POWER_SOURCE, |
| 5636 | USB_PD_PORT_POWER_SINK, |
| 5637 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5638 | }; |
| 5639 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5640 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5641 | uint16_t voltage_max; |
| 5642 | uint16_t voltage_now; |
| 5643 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5644 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5645 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5646 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5647 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5648 | uint8_t role; |
| 5649 | uint8_t type; |
| 5650 | uint8_t dualrole; |
| 5651 | uint8_t reserved1; |
| 5652 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5653 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5654 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5655 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5656 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5657 | /* |
| 5658 | * This command will return the number of USB PD charge port + the number |
| 5659 | * of dedicated port present. |
| 5660 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5661 | */ |
| 5662 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5663 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5664 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5665 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5666 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5667 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5668 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5669 | |
| 5670 | enum usb_pd_fw_update_cmds { |
| 5671 | USB_PD_FW_REBOOT, |
| 5672 | USB_PD_FW_FLASH_ERASE, |
| 5673 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5674 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5675 | }; |
| 5676 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5677 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5678 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5679 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5680 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5681 | uint32_t size; /* Size to write in bytes */ |
| 5682 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5683 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5684 | |
| 5685 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5686 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5687 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5688 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5689 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5690 | uint16_t dev_id; |
| 5691 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5692 | uint8_t reserved; /* |
| 5693 | * For alignment of current_image |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5694 | * TODO(rspangler) but it's not aligned! |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5695 | * Should have been reserved[2]. |
| 5696 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5697 | uint32_t current_image; /* One of ec_image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5698 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5699 | |
| 5700 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5701 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5702 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5703 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5704 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5705 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5706 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5707 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5708 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5709 | struct ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5710 | uint16_t vid; /* USB-IF VID */ |
| 5711 | uint16_t pid; /* USB-IF PID */ |
| 5712 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5713 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5714 | |
| 5715 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5716 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5717 | |
| 5718 | /* Negative port parameters have special meaning */ |
| 5719 | enum usb_pd_override_ports { |
| 5720 | OVERRIDE_DONT_CHARGE = -2, |
| 5721 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5722 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5723 | }; |
| 5724 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5725 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5726 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5727 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5728 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5729 | /* |
| 5730 | * Read (and delete) one entry of PD event log. |
| 5731 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5732 | * future non-PD logs that use the same internal EC event_log. |
| 5733 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5734 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5735 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5736 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5737 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 5738 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5739 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5740 | uint16_t data; /* type-defined data payload */ |
| 5741 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5742 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5743 | |
| 5744 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5745 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5746 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5747 | #define PD_LOG_SIZE_MASK 0x1f |
| 5748 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5749 | #define PD_LOG_PORT_SHIFT 5 |
| 5750 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 5751 | ((size) & PD_LOG_SIZE_MASK)) |
| 5752 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 5753 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 5754 | |
| 5755 | /* PD event log : entry types */ |
| 5756 | /* PD MCU events */ |
| 5757 | #define PD_EVENT_MCU_BASE 0x00 |
| 5758 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 5759 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 5760 | /* Reserved for custom board event */ |
| 5761 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 5762 | /* PD generic accessory events */ |
| 5763 | #define PD_EVENT_ACC_BASE 0x20 |
| 5764 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 5765 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 5766 | /* PD power supply events */ |
| 5767 | #define PD_EVENT_PS_BASE 0x40 |
| 5768 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 5769 | /* PD video dongles events */ |
| 5770 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5771 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 5772 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 5773 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5774 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5775 | |
| 5776 | /* |
| 5777 | * PD_EVENT_MCU_CHARGE event definition : |
| 5778 | * the payload is "struct usb_chg_measures" |
| 5779 | * the data field contains the port state flags as defined below : |
| 5780 | */ |
| 5781 | /* Port partner is a dual role device */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5782 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5783 | /* Port is the pending override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5784 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5785 | /* Port is the override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5786 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5787 | /* Charger type */ |
| 5788 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5789 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5790 | /* Power delivery role */ |
| 5791 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 5792 | |
| 5793 | /* |
| 5794 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5795 | */ |
| 5796 | #define PS_FAULT_OCP 1 |
| 5797 | #define PS_FAULT_FAST_OCP 2 |
| 5798 | #define PS_FAULT_OVP 3 |
| 5799 | #define PS_FAULT_DISCH 4 |
| 5800 | |
| 5801 | /* |
| 5802 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5803 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5804 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5805 | uint8_t major; |
| 5806 | uint8_t minor; |
| 5807 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5808 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5809 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5810 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5811 | uint8_t family[2]; |
| 5812 | uint8_t chipid[2]; |
| 5813 | struct mcdp_version irom; |
| 5814 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5815 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5816 | |
| 5817 | /* struct mcdp_info field decoding */ |
| 5818 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5819 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5820 | |
| 5821 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5822 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5823 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5824 | uint16_t svid_idx; /* SVID index to get */ |
| 5825 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5826 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5828 | struct ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5829 | uint16_t svid; /* SVID */ |
| 5830 | uint16_t opos; /* Object Position */ |
| 5831 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5832 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5833 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5834 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5835 | |
| 5836 | enum pd_mode_cmd { |
| 5837 | PD_EXIT_MODE = 0, |
| 5838 | PD_ENTER_MODE = 1, |
| 5839 | /* Not a command. Do NOT remove. */ |
| 5840 | PD_MODE_CMD_COUNT, |
| 5841 | }; |
| 5842 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5843 | struct ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5844 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 5845 | uint16_t svid; /* SVID to set */ |
| 5846 | uint8_t opos; /* Object Position */ |
| 5847 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5848 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5849 | |
| 5850 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5851 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5852 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5853 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5854 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 5855 | 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] | 5856 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5857 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5858 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5859 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5860 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5861 | |
| 5862 | enum ec_pd_control_cmd { |
| 5863 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 5864 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 5865 | PD_RESET, /* Force reset the PD chip */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5866 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 5867 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5868 | }; |
| 5869 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5870 | struct ec_params_pd_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5871 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5872 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5873 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5874 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5875 | /* Get info about USB-C SS muxes */ |
| 5876 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 5877 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5878 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5879 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5880 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5881 | |
| 5882 | /* Flags representing mux state */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5883 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 5884 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 5885 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 5886 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 5887 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 5888 | #define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5889 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 5890 | #define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5891 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
| 5892 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5893 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
| 5894 | |
| 5895 | /* USB-C Dock connected */ |
| 5896 | #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] | 5897 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5898 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5899 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5900 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5901 | |
| 5902 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 5903 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5904 | struct ec_params_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5905 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5906 | /* |
| 5907 | * Fetch the live chip info or hard-coded + cached chip info |
| 5908 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 5909 | * 1: live chip value for VID/PID/FW Version |
| 5910 | */ |
| 5911 | uint8_t live; |
| 5912 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5913 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5914 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5915 | uint16_t vendor_id; |
| 5916 | uint16_t product_id; |
| 5917 | uint16_t device_id; |
| 5918 | union { |
| 5919 | uint8_t fw_version_string[8]; |
| 5920 | uint64_t fw_version_number; |
| 5921 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5922 | } __ec_align2; |
| 5923 | |
| 5924 | struct ec_response_pd_chip_info_v1 { |
| 5925 | uint16_t vendor_id; |
| 5926 | uint16_t product_id; |
| 5927 | uint16_t device_id; |
| 5928 | union { |
| 5929 | uint8_t fw_version_string[8]; |
| 5930 | uint64_t fw_version_number; |
| 5931 | }; |
| 5932 | union { |
| 5933 | uint8_t min_req_fw_version_string[8]; |
| 5934 | uint64_t min_req_fw_version_number; |
| 5935 | }; |
| 5936 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5937 | |
| 5938 | /* Run RW signature verification and get status */ |
| 5939 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 5940 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5941 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5942 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5943 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5944 | |
| 5945 | /* For controlling RWSIG task */ |
| 5946 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 5947 | |
| 5948 | enum rwsig_action { |
| 5949 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 5950 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 5951 | }; |
| 5952 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5953 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5954 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5955 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5956 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5957 | /* Run verification on a slot */ |
| 5958 | #define EC_CMD_EFS_VERIFY 0x011E |
| 5959 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5960 | struct ec_params_efs_verify { |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5961 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5962 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5963 | |
| 5964 | /* |
| 5965 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 5966 | * type. Integers return a uint32. Strings return a string, using the response |
| 5967 | * size to determine how big it is. |
| 5968 | */ |
| 5969 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
| 5970 | /* |
| 5971 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 5972 | * hardware write-protect enabled. |
| 5973 | */ |
| 5974 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
| 5975 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5976 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5977 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
| 5978 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 5979 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 5980 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Wisley Chen | c1efec7 | 2018-11-06 09:28:23 +0800 | [diff] [blame] | 5981 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5982 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5983 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5984 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5985 | /* Second Source Factory Cache */ |
| 5986 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 5987 | CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5988 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5989 | }; |
| 5990 | |
| 5991 | /* |
| 5992 | * Flags to control read operation |
| 5993 | * |
| 5994 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 5995 | * write was successful without reboot. |
| 5996 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5997 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5998 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5999 | struct ec_params_get_cbi { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6000 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6001 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6002 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6003 | |
| 6004 | /* |
| 6005 | * Flags to control write behavior. |
| 6006 | * |
| 6007 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 6008 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6009 | * 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] | 6010 | * will be initialized to zero first. |
| 6011 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6012 | #define CBI_SET_NO_SYNC BIT(0) |
| 6013 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6014 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6015 | struct ec_params_set_cbi { |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6016 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6017 | uint32_t flag; /* CBI_SET_* */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6018 | uint32_t size; /* Data size */ |
| 6019 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6020 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6021 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6022 | /* |
| 6023 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 6024 | */ |
| 6025 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 6026 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6027 | /* EC reset causes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6028 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 6029 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 6030 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 6031 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 6032 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 6033 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 6034 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 6035 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 6036 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 6037 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 6038 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 6039 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 6040 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
| 6041 | #define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from |
| 6042 | * previous boot |
| 6043 | */ |
| 6044 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 6045 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 6046 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 6047 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
| 6048 | #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] | 6049 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This |
| 6050 | * enables PD in RO for Chromebox. |
| 6051 | */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6052 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 6053 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 6054 | #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] | 6055 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6056 | /* |
| 6057 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 6058 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 6059 | * compatibility: |
| 6060 | * - New entries must be inserted prior to the _COUNT field |
| 6061 | * - If an existing entry is no longer in service, it must be replaced with a |
| 6062 | * RESERVED entry instead. |
| 6063 | * - The semantic meaning of an entry should not change. |
| 6064 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 6065 | */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6066 | enum chipset_shutdown_reason { |
| 6067 | /* |
| 6068 | * Beginning of reset reasons. |
| 6069 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6070 | CHIPSET_RESET_BEGIN = 0, |
| 6071 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 6072 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 6073 | CHIPSET_RESET_BOARD_CUSTOM, |
| 6074 | /* Believe that the AP has hung */ |
| 6075 | CHIPSET_RESET_HANG_REBOOT, |
| 6076 | /* Reset by EC console command */ |
| 6077 | CHIPSET_RESET_CONSOLE_CMD, |
| 6078 | /* Reset by EC host command */ |
| 6079 | CHIPSET_RESET_HOST_CMD, |
| 6080 | /* Keyboard module reset key combination */ |
| 6081 | CHIPSET_RESET_KB_SYSRESET, |
| 6082 | /* Keyboard module warm reboot */ |
| 6083 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 6084 | /* Debug module warm reboot */ |
| 6085 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 6086 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 6087 | CHIPSET_RESET_AP_REQ, |
| 6088 | /* Reset as side-effect of startup sequence */ |
| 6089 | CHIPSET_RESET_INIT, |
| 6090 | /* EC detected an AP watchdog event. */ |
| 6091 | CHIPSET_RESET_AP_WATCHDOG, |
| 6092 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6093 | CHIPSET_RESET_COUNT, /* End of reset reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6094 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6095 | /* |
| 6096 | * Beginning of shutdown reasons. |
| 6097 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6098 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 6099 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 6100 | /* Forcing a shutdown as part of EC initialization */ |
| 6101 | CHIPSET_SHUTDOWN_INIT, |
| 6102 | /* Custom reason on a per-board basis. */ |
| 6103 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 6104 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 6105 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 6106 | /* A power_wait_signal is being asserted */ |
| 6107 | CHIPSET_SHUTDOWN_WAIT, |
| 6108 | /* Critical battery level. */ |
| 6109 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 6110 | /* Because you told me to. */ |
| 6111 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 6112 | /* Forcing a shutdown to effect entry to G3. */ |
| 6113 | CHIPSET_SHUTDOWN_G3, |
| 6114 | /* Force shutdown due to over-temperature. */ |
| 6115 | CHIPSET_SHUTDOWN_THERMAL, |
| 6116 | /* Force a chipset shutdown from the power button through EC */ |
| 6117 | CHIPSET_SHUTDOWN_BUTTON, |
| 6118 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6119 | CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6120 | }; |
| 6121 | |
| 6122 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6123 | struct ec_response_uptime_info { |
| 6124 | /* |
| 6125 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 6126 | * typically do not restart the EC's time_since_boot epoch. |
| 6127 | * |
| 6128 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 6129 | * sense of time, in both phase and frequency. This timebase is similar |
| 6130 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 6131 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6132 | uint32_t time_since_ec_boot_ms; |
| 6133 | |
| 6134 | /* |
| 6135 | * Number of times the AP was reset by the EC since the last EC boot. |
| 6136 | * Note that the AP may be held in reset by the EC during the initial |
| 6137 | * boot sequence, such that the very first AP boot may count as more |
| 6138 | * than one here. |
| 6139 | */ |
| 6140 | uint32_t ap_resets_since_ec_boot; |
| 6141 | |
| 6142 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6143 | * The set of flags which describe the EC's most recent reset. |
| 6144 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6145 | */ |
| 6146 | uint32_t ec_reset_flags; |
| 6147 | |
| 6148 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6149 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6150 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6151 | uint16_t reset_cause; |
| 6152 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6153 | /* Reserved for protocol growth. */ |
| 6154 | uint16_t reserved; |
| 6155 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6156 | /* |
| 6157 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6158 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6159 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6160 | */ |
| 6161 | uint32_t reset_time_ms; |
| 6162 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6163 | } __ec_align4; |
| 6164 | |
| 6165 | /* |
| 6166 | * Add entropy to the device secret (stored in the rollback region). |
| 6167 | * |
| 6168 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6169 | * flash), so the commands are asynchronous. |
| 6170 | */ |
| 6171 | #define EC_CMD_ADD_ENTROPY 0x0122 |
| 6172 | |
| 6173 | enum add_entropy_action { |
| 6174 | /* Add entropy to the current secret. */ |
| 6175 | ADD_ENTROPY_ASYNC = 0, |
| 6176 | /* |
| 6177 | * Add entropy, and also make sure that the previous secret is erased. |
| 6178 | * (this can be implemented by adding entropy multiple times until |
| 6179 | * all rolback blocks have been overwritten). |
| 6180 | */ |
| 6181 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6182 | /* Read back result from the previous operation. */ |
| 6183 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6184 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6185 | |
| 6186 | struct ec_params_rollback_add_entropy { |
| 6187 | uint8_t action; |
| 6188 | } __ec_align1; |
| 6189 | |
| 6190 | /* |
| 6191 | * Perform a single read of a given ADC channel. |
| 6192 | */ |
| 6193 | #define EC_CMD_ADC_READ 0x0123 |
| 6194 | |
| 6195 | struct ec_params_adc_read { |
| 6196 | uint8_t adc_channel; |
| 6197 | } __ec_align1; |
| 6198 | |
| 6199 | struct ec_response_adc_read { |
| 6200 | int32_t adc_value; |
| 6201 | } __ec_align4; |
| 6202 | |
| 6203 | /* |
| 6204 | * Read back rollback info |
| 6205 | */ |
| 6206 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
| 6207 | |
| 6208 | struct ec_response_rollback_info { |
| 6209 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6210 | int32_t rollback_min_version; |
| 6211 | int32_t rw_rollback_version; |
| 6212 | } __ec_align4; |
| 6213 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6214 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6215 | /* Issue AP reset */ |
| 6216 | #define EC_CMD_AP_RESET 0x0125 |
| 6217 | |
| 6218 | /*****************************************************************************/ |
| 6219 | /* Locate peripheral chips |
| 6220 | * |
| 6221 | * Return values: |
| 6222 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6223 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6224 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6225 | */ |
| 6226 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6227 | |
| 6228 | enum ec_chip_type { |
| 6229 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6230 | EC_CHIP_TYPE_TCPC = 1, |
| 6231 | EC_CHIP_TYPE_COUNT, |
| 6232 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6233 | }; |
| 6234 | |
| 6235 | enum ec_bus_type { |
| 6236 | EC_BUS_TYPE_I2C = 0, |
| 6237 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6238 | EC_BUS_TYPE_COUNT, |
| 6239 | EC_BUS_TYPE_MAX = 0xFF, |
| 6240 | }; |
| 6241 | |
| 6242 | struct ec_i2c_info { |
| 6243 | uint16_t port; /* Physical port for device */ |
| 6244 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
| 6245 | }; |
| 6246 | |
| 6247 | struct ec_params_locate_chip { |
| 6248 | uint8_t type; /* enum ec_chip_type */ |
| 6249 | uint8_t index; /* Specifies one instance of chip type */ |
| 6250 | /* Used for type specific parameters in future */ |
| 6251 | union { |
| 6252 | uint16_t reserved; |
| 6253 | }; |
| 6254 | } __ec_align2; |
| 6255 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6256 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6257 | struct ec_response_locate_chip { |
| 6258 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6259 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
| 6260 | union { |
| 6261 | struct ec_i2c_info i2c_info; |
| 6262 | }; |
| 6263 | } __ec_align2; |
| 6264 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6265 | /* |
| 6266 | * Reboot AP on G3 |
| 6267 | * |
| 6268 | * This command is used for validation purpose, where the AP needs to be |
| 6269 | * 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] | 6270 | * wake events. |
| 6271 | * - With command version 0: |
| 6272 | * AP reboots immediately from G3 |
| 6273 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6274 | * - With command version 1: |
| 6275 | * AP reboots after the user specified delay |
| 6276 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6277 | */ |
| 6278 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6279 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6280 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6281 | /* configurable delay in seconds in G3 state */ |
| 6282 | uint32_t reboot_ap_at_g3_delay; |
| 6283 | } __ec_align4; |
| 6284 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6285 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6286 | /* Get PD port capabilities |
| 6287 | * |
| 6288 | * Returns the following static *capabilities* of the given port: |
| 6289 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6290 | * future CrOS devices would ever be only a source, so the options are |
| 6291 | * sink or dual. |
| 6292 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6293 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6294 | * or none). |
| 6295 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6296 | * for CrOS devices. |
| 6297 | */ |
| 6298 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6299 | |
| 6300 | enum ec_pd_power_role_caps { |
| 6301 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6302 | EC_PD_POWER_ROLE_SINK = 1, |
| 6303 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6304 | }; |
| 6305 | |
| 6306 | enum ec_pd_try_power_role_caps { |
| 6307 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6308 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6309 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6310 | }; |
| 6311 | |
| 6312 | enum ec_pd_data_role_caps { |
| 6313 | EC_PD_DATA_ROLE_DFP = 0, |
| 6314 | EC_PD_DATA_ROLE_UFP = 1, |
| 6315 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6316 | }; |
| 6317 | |
| 6318 | /* From: power_manager/power_supply_properties.proto */ |
| 6319 | enum ec_pd_port_location { |
| 6320 | /* The location of the port is unknown, or there's only one port. */ |
| 6321 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6322 | |
| 6323 | /* |
| 6324 | * Various positions on the device. The first word describes the side of |
| 6325 | * the device where the port is located while the second clarifies the |
| 6326 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6327 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6328 | * device. |
| 6329 | */ |
| 6330 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6331 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6332 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6333 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6334 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6335 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
| 6336 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
| 6337 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6338 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6339 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
| 6340 | }; |
| 6341 | |
| 6342 | struct ec_params_get_pd_port_caps { |
| 6343 | uint8_t port; /* Which port to interrogate */ |
| 6344 | } __ec_align1; |
| 6345 | |
| 6346 | struct ec_response_get_pd_port_caps { |
| 6347 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6348 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6349 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6350 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
| 6351 | } __ec_align1; |
| 6352 | |
| 6353 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6354 | /* |
| 6355 | * Button press simulation |
| 6356 | * |
| 6357 | * This command is used to simulate a button press. |
| 6358 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6359 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6360 | * |
| 6361 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6362 | */ |
| 6363 | #define EC_CMD_BUTTON 0x0129 |
| 6364 | |
| 6365 | struct ec_params_button { |
| 6366 | /* Button mask aligned to enum keyboard_button_type */ |
| 6367 | uint32_t btn_mask; |
| 6368 | |
| 6369 | /* Duration in milliseconds button needs to be pressed */ |
| 6370 | uint32_t press_ms; |
| 6371 | } __ec_align1; |
| 6372 | |
| 6373 | enum keyboard_button_type { |
| 6374 | KEYBOARD_BUTTON_POWER = 0, |
| 6375 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
| 6376 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6377 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6378 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6379 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6380 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6381 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6382 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6383 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6384 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6385 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
| 6386 | |
| 6387 | KEYBOARD_BUTTON_COUNT |
| 6388 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6389 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6390 | /*****************************************************************************/ |
| 6391 | /* |
| 6392 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6393 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6394 | * Additionally, capability to send function codes for the same keys is |
| 6395 | * optional and acceptable. |
| 6396 | * |
| 6397 | * Note: If the top row can generate both function and action codes by |
| 6398 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6399 | * "function" or "action" codes by default. In both cases, the response |
| 6400 | * for this command will look the same. |
| 6401 | */ |
| 6402 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6403 | |
| 6404 | /* Possible values for the top row keys */ |
| 6405 | enum action_key { |
| 6406 | TK_ABSENT = 0, |
| 6407 | TK_BACK = 1, |
| 6408 | TK_FORWARD = 2, |
| 6409 | TK_REFRESH = 3, |
| 6410 | TK_FULLSCREEN = 4, |
| 6411 | TK_OVERVIEW = 5, |
| 6412 | TK_BRIGHTNESS_DOWN = 6, |
| 6413 | TK_BRIGHTNESS_UP = 7, |
| 6414 | TK_VOL_MUTE = 8, |
| 6415 | TK_VOL_DOWN = 9, |
| 6416 | TK_VOL_UP = 10, |
| 6417 | TK_SNAPSHOT = 11, |
| 6418 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6419 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6420 | TK_KBD_BKLIGHT_UP = 14, |
| 6421 | TK_PLAY_PAUSE = 15, |
| 6422 | TK_NEXT_TRACK = 16, |
| 6423 | TK_PREV_TRACK = 17, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 6424 | TK_KBD_BKLIGHT_TOGGLE = 18, |
| 6425 | TK_MICMUTE = 19, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6426 | TK_MENU = 20, |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6427 | }; |
| 6428 | |
| 6429 | /* |
| 6430 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6431 | * If this needs to change, please create a new version of the command. |
| 6432 | */ |
| 6433 | #define MAX_TOP_ROW_KEYS 15 |
| 6434 | #define MIN_TOP_ROW_KEYS 10 |
| 6435 | |
| 6436 | /* |
| 6437 | * Is the keyboard capable of sending function keys *in addition to* |
| 6438 | * action keys. This is possible for e.g. if the keyboard has a |
| 6439 | * dedicated Fn key. |
| 6440 | */ |
| 6441 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
| 6442 | /* |
| 6443 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6444 | */ |
| 6445 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
| 6446 | /* |
| 6447 | * Whether the keyboard has a screenlock key. |
| 6448 | */ |
| 6449 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
| 6450 | |
| 6451 | struct ec_response_keybd_config { |
| 6452 | /* |
| 6453 | * Number of top row keys, excluding Esc and Screenlock. |
| 6454 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6455 | * (i.e. does not expose any tables to the kernel). |
| 6456 | */ |
| 6457 | uint8_t num_top_row_keys; |
| 6458 | |
| 6459 | /* |
| 6460 | * The action keys in the top row, in order from left to right. |
| 6461 | * The values are filled from enum action_key. Esc and Screenlock |
| 6462 | * keys are not considered part of top row keys. |
| 6463 | */ |
| 6464 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6465 | |
| 6466 | /* Capability flags */ |
| 6467 | uint8_t capabilities; |
| 6468 | |
| 6469 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6470 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6471 | /* |
| 6472 | * Configure smart discharge |
| 6473 | */ |
| 6474 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6475 | |
| 6476 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
| 6477 | |
| 6478 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6479 | struct discharge_rate { |
| 6480 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6481 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
| 6482 | }; |
| 6483 | |
| 6484 | struct smart_discharge_zone { |
| 6485 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6486 | int cutoff; |
| 6487 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6488 | int stayup; |
| 6489 | }; |
| 6490 | |
| 6491 | struct ec_params_smart_discharge { |
| 6492 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
| 6493 | /* |
| 6494 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6495 | * zero to disable smart discharging. That is, the system hibernates as |
| 6496 | * soon as the G3 idle timer expires. |
| 6497 | */ |
| 6498 | uint16_t hours_to_zero; |
| 6499 | /* Set both to zero to keep the current rates. */ |
| 6500 | struct discharge_rate drate; |
| 6501 | }; |
| 6502 | |
| 6503 | struct ec_response_smart_discharge { |
| 6504 | uint16_t hours_to_zero; |
| 6505 | struct discharge_rate drate; |
| 6506 | struct smart_discharge_zone dzone; |
| 6507 | }; |
| 6508 | |
| 6509 | /*****************************************************************************/ |
| 6510 | /* Voltage regulator controls */ |
| 6511 | |
| 6512 | /* |
| 6513 | * Get basic info of voltage regulator for given index. |
| 6514 | * |
| 6515 | * Returns the regulator name and supported voltage list in mV. |
| 6516 | */ |
| 6517 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6518 | |
| 6519 | /* Maximum length of regulator name */ |
| 6520 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6521 | |
| 6522 | /* Maximum length of the supported voltage list. */ |
| 6523 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6524 | |
| 6525 | struct ec_params_regulator_get_info { |
| 6526 | uint32_t index; |
| 6527 | } __ec_align4; |
| 6528 | |
| 6529 | struct ec_response_regulator_get_info { |
| 6530 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6531 | uint16_t num_voltages; |
| 6532 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6533 | } __ec_align2; |
| 6534 | |
| 6535 | /* |
| 6536 | * Configure the regulator as enabled / disabled. |
| 6537 | */ |
| 6538 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6539 | |
| 6540 | struct ec_params_regulator_enable { |
| 6541 | uint32_t index; |
| 6542 | uint8_t enable; |
| 6543 | } __ec_align4; |
| 6544 | |
| 6545 | /* |
| 6546 | * Query if the regulator is enabled. |
| 6547 | * |
| 6548 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6549 | */ |
| 6550 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6551 | |
| 6552 | struct ec_params_regulator_is_enabled { |
| 6553 | uint32_t index; |
| 6554 | } __ec_align4; |
| 6555 | |
| 6556 | struct ec_response_regulator_is_enabled { |
| 6557 | uint8_t enabled; |
| 6558 | } __ec_align1; |
| 6559 | |
| 6560 | /* |
| 6561 | * Set voltage for the voltage regulator within the range specified. |
| 6562 | * |
| 6563 | * The driver should select the voltage in range closest to min_mv. |
| 6564 | * |
| 6565 | * Also note that this might be called before the regulator is enabled, and the |
| 6566 | * setting should be in effect after the regulator is enabled. |
| 6567 | */ |
| 6568 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6569 | |
| 6570 | struct ec_params_regulator_set_voltage { |
| 6571 | uint32_t index; |
| 6572 | uint32_t min_mv; |
| 6573 | uint32_t max_mv; |
| 6574 | } __ec_align4; |
| 6575 | |
| 6576 | /* |
| 6577 | * Get the currently configured voltage for the voltage regulator. |
| 6578 | * |
| 6579 | * Note that this might be called before the regulator is enabled, and this |
| 6580 | * should return the configured output voltage if the regulator is enabled. |
| 6581 | */ |
| 6582 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6583 | |
| 6584 | struct ec_params_regulator_get_voltage { |
| 6585 | uint32_t index; |
| 6586 | } __ec_align4; |
| 6587 | |
| 6588 | struct ec_response_regulator_get_voltage { |
| 6589 | uint32_t voltage_mv; |
| 6590 | } __ec_align4; |
| 6591 | |
| 6592 | /* |
| 6593 | * Gather all discovery information for the given port and partner type. |
| 6594 | * |
| 6595 | * Note that if discovery has not yet completed, only the currently completed |
| 6596 | * responses will be filled in. If the discovery data structures are changed |
| 6597 | * in the process of the command running, BUSY will be returned. |
| 6598 | * |
| 6599 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6600 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6601 | * maximum parameter size. |
| 6602 | */ |
| 6603 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6604 | |
| 6605 | enum typec_partner_type { |
| 6606 | TYPEC_PARTNER_SOP = 0, |
| 6607 | TYPEC_PARTNER_SOP_PRIME = 1, |
| 6608 | }; |
| 6609 | |
| 6610 | struct ec_params_typec_discovery { |
| 6611 | uint8_t port; |
| 6612 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6613 | } __ec_align1; |
| 6614 | |
| 6615 | struct svid_mode_info { |
| 6616 | uint16_t svid; |
| 6617 | uint16_t mode_count; /* Number of modes partner sent */ |
| 6618 | uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6619 | }; |
| 6620 | |
| 6621 | struct ec_response_typec_discovery { |
| 6622 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6623 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
| 6624 | uint16_t reserved; |
| 6625 | uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6626 | struct svid_mode_info svids[0]; |
| 6627 | } __ec_align1; |
| 6628 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6629 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6630 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6631 | |
| 6632 | enum typec_control_command { |
| 6633 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6634 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6635 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6636 | TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6637 | }; |
| 6638 | |
| 6639 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6640 | enum typec_mode { |
| 6641 | TYPEC_MODE_DP, |
| 6642 | TYPEC_MODE_TBT, |
| 6643 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6644 | }; |
| 6645 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6646 | /* Replies the AP may specify to the TBT EnterMode command as a UFP */ |
| 6647 | enum typec_tbt_ufp_reply { |
| 6648 | TYPEC_TBT_UFP_REPLY_NAK, |
| 6649 | TYPEC_TBT_UFP_REPLY_ACK, |
| 6650 | }; |
| 6651 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6652 | struct ec_params_typec_control { |
| 6653 | uint8_t port; |
| 6654 | uint8_t command; /* enum typec_control_command */ |
| 6655 | uint16_t reserved; |
| 6656 | |
| 6657 | /* |
| 6658 | * This section will be interpreted based on |command|. Define a |
| 6659 | * placeholder structure to avoid having to increase the size and bump |
| 6660 | * the command version when adding new sub-commands. |
| 6661 | */ |
| 6662 | union { |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6663 | /* Used for CLEAR_EVENTS */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6664 | uint32_t clear_events_mask; |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6665 | /* Used for ENTER_MODE - enum typec_mode */ |
| 6666 | uint8_t mode_to_enter; |
| 6667 | /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */ |
| 6668 | uint8_t tbt_ufp_reply; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6669 | uint8_t placeholder[128]; |
| 6670 | }; |
| 6671 | } __ec_align1; |
| 6672 | |
| 6673 | /* |
| 6674 | * Gather all status information for a port. |
| 6675 | * |
| 6676 | * Note: this covers many of the return fields from the deprecated |
| 6677 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 6678 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 6679 | * EC_CMD_USB_PD_CONTROL command. |
| 6680 | * |
| 6681 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6682 | */ |
| 6683 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 6684 | |
| 6685 | /* |
| 6686 | * Power role. |
| 6687 | * |
| 6688 | * Note this is also used for PD header creation, and values align to those in |
| 6689 | * the Power Delivery Specification Revision 3.0 (See |
| 6690 | * 6.2.1.1.4 Port Power Role). |
| 6691 | */ |
| 6692 | enum pd_power_role { |
| 6693 | PD_ROLE_SINK = 0, |
| 6694 | PD_ROLE_SOURCE = 1 |
| 6695 | }; |
| 6696 | |
| 6697 | /* |
| 6698 | * Data role. |
| 6699 | * |
| 6700 | * Note this is also used for PD header creation, and the first two values |
| 6701 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 6702 | * 6.2.1.1.6 Port Data Role). |
| 6703 | */ |
| 6704 | enum pd_data_role { |
| 6705 | PD_ROLE_UFP = 0, |
| 6706 | PD_ROLE_DFP = 1, |
| 6707 | PD_ROLE_DISCONNECTED = 2, |
| 6708 | }; |
| 6709 | |
| 6710 | enum pd_vconn_role { |
| 6711 | PD_ROLE_VCONN_OFF = 0, |
| 6712 | PD_ROLE_VCONN_SRC = 1, |
| 6713 | }; |
| 6714 | |
| 6715 | /* |
| 6716 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 6717 | * regardless of whether a debug accessory is connected. |
| 6718 | */ |
| 6719 | enum tcpc_cc_polarity { |
| 6720 | /* |
| 6721 | * _CCx: is used to indicate the polarity while not connected to |
| 6722 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 6723 | * the other will be open. |
| 6724 | */ |
| 6725 | POLARITY_CC1 = 0, |
| 6726 | POLARITY_CC2 = 1, |
| 6727 | |
| 6728 | /* |
| 6729 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 6730 | * SRC Debug Accessory. Assert resistors on both lines. |
| 6731 | */ |
| 6732 | POLARITY_CC1_DTS = 2, |
| 6733 | POLARITY_CC2_DTS = 3, |
| 6734 | |
| 6735 | /* |
| 6736 | * The current TCPC code relies on these specific POLARITY values. |
| 6737 | * Adding in a check to verify if the list grows for any reason |
| 6738 | * that this will give a hint that other places need to be |
| 6739 | * adjusted. |
| 6740 | */ |
| 6741 | POLARITY_COUNT |
| 6742 | }; |
| 6743 | |
| 6744 | #define MODE_DP_PIN_A BIT(0) |
| 6745 | #define MODE_DP_PIN_B BIT(1) |
| 6746 | #define MODE_DP_PIN_C BIT(2) |
| 6747 | #define MODE_DP_PIN_D BIT(3) |
| 6748 | #define MODE_DP_PIN_E BIT(4) |
| 6749 | #define MODE_DP_PIN_F BIT(5) |
| 6750 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
| 6751 | |
| 6752 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 6753 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6754 | #define PD_STATUS_EVENT_HARD_RESET BIT(2) |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 6755 | #define PD_STATUS_EVENT_DISCONNECTED BIT(3) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6756 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6757 | /* |
| 6758 | * Encode and decode for BCD revision response |
| 6759 | * |
| 6760 | * Note: the major revision set is written assuming that the value given is the |
| 6761 | * Specification Revision from the PD header, which currently only maps to PD |
| 6762 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 6763 | */ |
| 6764 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 6765 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 6766 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
| 6767 | |
| 6768 | /* |
| 6769 | * Decode helpers for Source and Sink Capability PDOs |
| 6770 | * |
| 6771 | * Note: The Power Delivery Specification should be considered the ultimate |
| 6772 | * source of truth on the decoding of these PDOs |
| 6773 | */ |
| 6774 | #define PDO_TYPE_FIXED (0 << 30) |
| 6775 | #define PDO_TYPE_BATTERY (1 << 30) |
| 6776 | #define PDO_TYPE_VARIABLE (2 << 30) |
| 6777 | #define PDO_TYPE_AUGMENTED (3 << 30) |
| 6778 | #define PDO_TYPE_MASK (3 << 30) |
| 6779 | |
| 6780 | /* |
| 6781 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 6782 | * |
| 6783 | * <31:30> : Fixed Supply |
| 6784 | * <29> : Dual-Role Power |
| 6785 | * <28> : SNK/SRC dependent |
| 6786 | * <27> : Unconstrained Power |
| 6787 | * <26> : USB Communications Capable |
| 6788 | * <25> : Dual-Role Data |
| 6789 | * <24:20> : SNK/SRC dependent |
| 6790 | * <19:10> : Voltage in 50mV Units |
| 6791 | * <9:0> : Maximum Current in 10mA units |
| 6792 | */ |
| 6793 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 6794 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 6795 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 6796 | #define PDO_FIXED_DATA_SWAP BIT(25) |
| 6797 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
| 6798 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6799 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
| 6800 | |
| 6801 | /* |
| 6802 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 6803 | * |
| 6804 | * <31:30> : Battery |
| 6805 | * <29:20> : Maximum Voltage in 50mV units |
| 6806 | * <19:10> : Minimum Voltage in 50mV units |
| 6807 | * <9:0> : Maximum Allowable Power in 250mW units |
| 6808 | */ |
| 6809 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6810 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6811 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
| 6812 | |
| 6813 | /* |
| 6814 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 6815 | * |
| 6816 | * <31:30> : Variable Supply (non-Battery) |
| 6817 | * <29:20> : Maximum Voltage in 50mV units |
| 6818 | * <19:10> : Minimum Voltage in 50mV units |
| 6819 | * <9:0> : Operational Current in 10mA units |
| 6820 | */ |
| 6821 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 6822 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6823 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
| 6824 | |
| 6825 | /* |
| 6826 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 6827 | * |
| 6828 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 6829 | * supported as of the cited version. |
| 6830 | * |
| 6831 | * <31:30> : Augmented Power Data Object |
| 6832 | * <29:28> : Programmable Power Supply |
| 6833 | * <27> : PPS Power Limited |
| 6834 | * <26:25> : Reserved |
| 6835 | * <24:17> : Maximum Voltage in 100mV increments |
| 6836 | * <16> : Reserved |
| 6837 | * <15:8> : Minimum Voltage in 100mV increments |
| 6838 | * <7> : Reserved |
| 6839 | * <6:0> : Maximum Current in 50mA increments |
| 6840 | */ |
| 6841 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 6842 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 6843 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
| 6844 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6845 | struct ec_params_typec_status { |
| 6846 | uint8_t port; |
| 6847 | } __ec_align1; |
| 6848 | |
| 6849 | struct ec_response_typec_status { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6850 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 6851 | uint8_t dev_connected; /* Device connected - bool */ |
| 6852 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 6853 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6854 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6855 | uint8_t power_role; /* enum pd_power_role */ |
| 6856 | uint8_t data_role; /* enum pd_data_role */ |
| 6857 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 6858 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6859 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6860 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 6861 | uint8_t cc_state; /* enum pd_cc_states */ |
| 6862 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 6863 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6864 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6865 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6866 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6867 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6868 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6869 | /* |
| 6870 | * BCD PD revisions for partners |
| 6871 | * |
| 6872 | * The format has the PD major reversion in the upper nibble, and PD |
| 6873 | * minor version in the next nibble. Following two nibbles are |
| 6874 | * currently 0. |
| 6875 | * ex. PD 3.2 would map to 0x3200 |
| 6876 | * |
| 6877 | * PD major/minor will be 0 if no PD device is connected. |
| 6878 | */ |
| 6879 | uint16_t sop_revision; |
| 6880 | uint16_t sop_prime_revision; |
| 6881 | |
| 6882 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 6883 | |
| 6884 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6885 | } __ec_align1; |
| 6886 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6887 | /** |
| 6888 | * Get the number of peripheral charge ports |
| 6889 | */ |
| 6890 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 6891 | |
| 6892 | #define EC_PCHG_MAX_PORTS 8 |
| 6893 | |
| 6894 | struct ec_response_pchg_count { |
| 6895 | uint8_t port_count; |
| 6896 | } __ec_align1; |
| 6897 | |
| 6898 | /** |
| 6899 | * Get the status of a peripheral charge port |
| 6900 | */ |
| 6901 | #define EC_CMD_PCHG 0x0135 |
| 6902 | |
| 6903 | struct ec_params_pchg { |
| 6904 | uint8_t port; |
| 6905 | } __ec_align1; |
| 6906 | |
| 6907 | struct ec_response_pchg { |
| 6908 | uint32_t error; /* enum pchg_error */ |
| 6909 | uint8_t state; /* enum pchg_state state */ |
| 6910 | uint8_t battery_percentage; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6911 | uint8_t unused0; |
| 6912 | uint8_t unused1; |
| 6913 | /* Fields added in version 1 */ |
| 6914 | uint32_t fw_version; |
| 6915 | uint32_t dropped_event_count; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6916 | } __ec_align2; |
| 6917 | |
| 6918 | enum pchg_state { |
| 6919 | /* Charger is reset and not initialized. */ |
| 6920 | PCHG_STATE_RESET = 0, |
| 6921 | /* Charger is initialized or disabled. */ |
| 6922 | PCHG_STATE_INITIALIZED, |
| 6923 | /* Charger is enabled and ready to detect a device. */ |
| 6924 | PCHG_STATE_ENABLED, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6925 | /* Device is in proximity. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6926 | PCHG_STATE_DETECTED, |
| 6927 | /* Device is being charged. */ |
| 6928 | PCHG_STATE_CHARGING, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6929 | /* Device is fully charged. It implies DETECTED (& not charging). */ |
| 6930 | PCHG_STATE_FULL, |
| 6931 | /* In download (a.k.a. firmware update) mode */ |
| 6932 | PCHG_STATE_DOWNLOAD, |
| 6933 | /* In download mode. Ready for receiving data. */ |
| 6934 | PCHG_STATE_DOWNLOADING, |
| 6935 | /* Device is ready for data communication. */ |
| 6936 | PCHG_STATE_CONNECTED, |
| 6937 | /* Put no more entry below */ |
| 6938 | PCHG_STATE_COUNT, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6939 | }; |
| 6940 | |
| 6941 | #define EC_PCHG_STATE_TEXT { \ |
| 6942 | [PCHG_STATE_RESET] = "RESET", \ |
| 6943 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 6944 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 6945 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 6946 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6947 | [PCHG_STATE_FULL] = "FULL", \ |
| 6948 | [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ |
| 6949 | [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ |
| 6950 | [PCHG_STATE_CONNECTED] = "CONNECTED", \ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6951 | } |
| 6952 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6953 | /** |
| 6954 | * Update firmware of peripheral chip |
| 6955 | */ |
| 6956 | #define EC_CMD_PCHG_UPDATE 0x0136 |
| 6957 | |
| 6958 | /* Port number is encoded in bit[28:31]. */ |
| 6959 | #define EC_MKBP_PCHG_PORT_SHIFT 28 |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6960 | /* Utility macros for converting MKBP event <-> port number. */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6961 | #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6962 | #define EC_MKBP_PCHG_PORT_TO_EVENT(p) (BIT((p) + EC_MKBP_PCHG_PORT_SHIFT)) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6963 | /* Utility macro for extracting event bits. */ |
| 6964 | #define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \ |
| 6965 | & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0)) |
| 6966 | |
| 6967 | #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) |
| 6968 | #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) |
| 6969 | #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) |
| 6970 | #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 6971 | #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 6972 | |
| 6973 | enum ec_pchg_update_cmd { |
| 6974 | /* Reset chip to normal mode. */ |
| 6975 | EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, |
| 6976 | /* Reset and put a chip in update (a.k.a. download) mode. */ |
| 6977 | EC_PCHG_UPDATE_CMD_OPEN, |
| 6978 | /* Write a block of data containing FW image. */ |
| 6979 | EC_PCHG_UPDATE_CMD_WRITE, |
| 6980 | /* Close update session. */ |
| 6981 | EC_PCHG_UPDATE_CMD_CLOSE, |
| 6982 | /* End of commands */ |
| 6983 | EC_PCHG_UPDATE_CMD_COUNT, |
| 6984 | }; |
| 6985 | |
| 6986 | struct ec_params_pchg_update { |
| 6987 | /* PCHG port number */ |
| 6988 | uint8_t port; |
| 6989 | /* enum ec_pchg_update_cmd */ |
| 6990 | uint8_t cmd; |
| 6991 | /* Padding */ |
| 6992 | uint8_t reserved0; |
| 6993 | uint8_t reserved1; |
| 6994 | /* Version of new firmware */ |
| 6995 | uint32_t version; |
| 6996 | /* CRC32 of new firmware */ |
| 6997 | uint32_t crc32; |
| 6998 | /* Address in chip memory where <data> is written to */ |
| 6999 | uint32_t addr; |
| 7000 | /* Size of <data> */ |
| 7001 | uint32_t size; |
| 7002 | /* Partial data of new firmware */ |
| 7003 | uint8_t data[]; |
| 7004 | } __ec_align4; |
| 7005 | |
| 7006 | BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT |
| 7007 | < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8)); |
| 7008 | |
| 7009 | struct ec_response_pchg_update { |
| 7010 | /* Block size */ |
| 7011 | uint32_t block_size; |
| 7012 | } __ec_align4; |
| 7013 | |
| 7014 | |
| 7015 | #define EC_CMD_DISPLAY_SOC 0x0137 |
| 7016 | |
| 7017 | struct ec_response_display_soc { |
| 7018 | int16_t display_soc; /* Display charge in 10ths of a % (1000=100.0%) */ |
| 7019 | int16_t full_factor; /* Full factor in 10ths of a % (1000=100.0%) */ |
| 7020 | int16_t shutdown_soc; /* Shutdown SoC in 10ths of a % (1000=100.0%) */ |
| 7021 | } __ec_align2; |
| 7022 | |
| 7023 | |
| 7024 | #define EC_CMD_SET_BASE_STATE 0x0138 |
| 7025 | |
| 7026 | struct ec_params_set_base_state { |
| 7027 | uint8_t cmd; /* enum ec_set_base_state_cmd */ |
| 7028 | } __ec_align1; |
| 7029 | |
| 7030 | enum ec_set_base_state_cmd { |
| 7031 | EC_SET_BASE_STATE_DETACH = 0, |
| 7032 | EC_SET_BASE_STATE_ATTACH, |
| 7033 | EC_SET_BASE_STATE_RESET, |
| 7034 | }; |
| 7035 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame^] | 7036 | #define EC_CMD_I2C_CONTROL 0x0139 |
| 7037 | |
| 7038 | /* Subcommands for I2C control */ |
| 7039 | |
| 7040 | enum ec_i2c_control_command { |
| 7041 | EC_I2C_CONTROL_GET_SPEED, |
| 7042 | EC_I2C_CONTROL_SET_SPEED, |
| 7043 | }; |
| 7044 | |
| 7045 | #define EC_I2C_CONTROL_SPEED_UNKNOWN 0 |
| 7046 | |
| 7047 | struct ec_params_i2c_control { |
| 7048 | uint8_t port; /* I2C port number */ |
| 7049 | uint8_t cmd; /* enum ec_i2c_control_command */ |
| 7050 | union { |
| 7051 | uint16_t speed_khz; |
| 7052 | } cmd_params; |
| 7053 | } __ec_align_size1; |
| 7054 | |
| 7055 | struct ec_response_i2c_control { |
| 7056 | union { |
| 7057 | uint16_t speed_khz; |
| 7058 | } cmd_response; |
| 7059 | } __ec_align_size1; |
| 7060 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 7061 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7062 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7063 | |
| 7064 | /*****************************************************************************/ |
| 7065 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7066 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7067 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7068 | #define EC_CMD_CR51_BASE 0x0300 |
| 7069 | #define EC_CMD_CR51_LAST 0x03FF |
| 7070 | |
| 7071 | /*****************************************************************************/ |
| 7072 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 7073 | |
| 7074 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 7075 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 7076 | |
| 7077 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 7078 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7079 | struct ec_params_fp_passthru { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7080 | uint16_t len; /* Number of bytes to write then read */ |
| 7081 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 7082 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7083 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7084 | |
| 7085 | /* Configure the Fingerprint MCU behavior */ |
| 7086 | #define EC_CMD_FP_MODE 0x0402 |
| 7087 | |
| 7088 | /* Put the sensor in its lowest power mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7089 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7090 | /* Wait to see a finger on the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7091 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7092 | /* Poll until the finger has left the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7093 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7094 | /* Capture the current finger image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7095 | #define FP_MODE_CAPTURE BIT(3) |
| 7096 | /* Finger enrollment session on-going */ |
| 7097 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 7098 | /* Enroll the current finger image */ |
| 7099 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
| 7100 | /* Try to match the current finger image */ |
| 7101 | #define FP_MODE_MATCH BIT(6) |
| 7102 | /* Reset and re-initialize the sensor. */ |
| 7103 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 7104 | /* Sensor maintenance for dead pixels. */ |
| 7105 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7106 | /* special value: don't change anything just read back current mode */ |
| 7107 | #define FP_MODE_DONT_CHANGE BIT(31) |
| 7108 | |
| 7109 | #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ |
| 7110 | FP_MODE_FINGER_DOWN | \ |
| 7111 | FP_MODE_FINGER_UP | \ |
| 7112 | FP_MODE_CAPTURE | \ |
| 7113 | FP_MODE_ENROLL_SESSION | \ |
| 7114 | FP_MODE_ENROLL_IMAGE | \ |
| 7115 | FP_MODE_MATCH | \ |
| 7116 | FP_MODE_RESET_SENSOR | \ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 7117 | FP_MODE_SENSOR_MAINTENANCE | \ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7118 | FP_MODE_DONT_CHANGE) |
| 7119 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7120 | /* Capture types defined in bits [30..28] */ |
| 7121 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7122 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
| 7123 | /* |
| 7124 | * This enum must remain ordered, if you add new values you must ensure that |
| 7125 | * FP_CAPTURE_TYPE_MAX is still the last one. |
| 7126 | */ |
| 7127 | enum fp_capture_type { |
| 7128 | /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ |
| 7129 | FP_CAPTURE_VENDOR_FORMAT = 0, |
| 7130 | /* Simple raw image capture (produces width x height x bpp bits) */ |
| 7131 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
| 7132 | /* Self test pattern (e.g. checkerboard) */ |
| 7133 | FP_CAPTURE_PATTERN0 = 2, |
| 7134 | /* Self test pattern (e.g. inverted checkerboard) */ |
| 7135 | FP_CAPTURE_PATTERN1 = 3, |
| 7136 | /* Capture for Quality test with fixed contrast */ |
| 7137 | FP_CAPTURE_QUALITY_TEST = 4, |
| 7138 | /* Capture for pixel reset value test */ |
| 7139 | FP_CAPTURE_RESET_TEST = 5, |
| 7140 | FP_CAPTURE_TYPE_MAX, |
| 7141 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7142 | /* Extracts the capture type from the sensor 'mode' word */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7143 | #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ |
| 7144 | >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7145 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7146 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7147 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7148 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7149 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7150 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7151 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7152 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7153 | |
| 7154 | /* Retrieve Fingerprint sensor information */ |
| 7155 | #define EC_CMD_FP_INFO 0x0403 |
| 7156 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7157 | /* Number of dead pixels detected on the last maintenance */ |
| 7158 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7159 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 7160 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7161 | /* No interrupt from the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7162 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7163 | /* SPI communication error */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7164 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7165 | /* Invalid sensor Hardware ID */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7166 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7167 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7168 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7169 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7170 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7171 | /* Sensor identification */ |
| 7172 | uint32_t vendor_id; |
| 7173 | uint32_t product_id; |
| 7174 | uint32_t model_id; |
| 7175 | uint32_t version; |
| 7176 | /* Image frame characteristics */ |
| 7177 | uint32_t frame_size; |
| 7178 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7179 | uint16_t width; |
| 7180 | uint16_t height; |
| 7181 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7182 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7183 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7184 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7185 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7186 | /* Sensor identification */ |
| 7187 | uint32_t vendor_id; |
| 7188 | uint32_t product_id; |
| 7189 | uint32_t model_id; |
| 7190 | uint32_t version; |
| 7191 | /* Image frame characteristics */ |
| 7192 | uint32_t frame_size; |
| 7193 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7194 | uint16_t width; |
| 7195 | uint16_t height; |
| 7196 | uint16_t bpp; |
| 7197 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 7198 | /* Template/finger current information */ |
| 7199 | uint32_t template_size; /* max template size in bytes */ |
| 7200 | uint16_t template_max; /* maximum number of fingers/templates */ |
| 7201 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 7202 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7203 | uint32_t template_version; /* version of the template format */ |
| 7204 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7205 | |
| 7206 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7207 | #define EC_CMD_FP_FRAME 0x0404 |
| 7208 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7209 | /* constants defining the 'offset' field which also contains the frame index */ |
| 7210 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7211 | /* Frame buffer where the captured image is stored */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7212 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7213 | /* First frame buffer holding a template */ |
| 7214 | #define FP_FRAME_INDEX_TEMPLATE 1 |
| 7215 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7216 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
| 7217 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7218 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7219 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7220 | |
| 7221 | /* Constants for encryption parameters */ |
| 7222 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 7223 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 7224 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7225 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7226 | #define FP_CONTEXT_TPM_BYTES 32 |
| 7227 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7228 | /* Constants for positive match parameters. */ |
| 7229 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 7230 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7231 | struct ec_fp_template_encryption_metadata { |
| 7232 | /* |
| 7233 | * Version of the structure format (N=3). |
| 7234 | */ |
| 7235 | uint16_t struct_version; |
| 7236 | /* Reserved bytes, set to 0. */ |
| 7237 | uint16_t reserved; |
| 7238 | /* |
| 7239 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 7240 | * a different one is used for every message. |
| 7241 | */ |
| 7242 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7243 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7244 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 7245 | }; |
| 7246 | |
| 7247 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7248 | /* |
| 7249 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 7250 | * in the high nibble, and the real offset within the frame in |
| 7251 | * FP_FRAME_OFFSET_MASK. |
| 7252 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7253 | uint32_t offset; |
| 7254 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7255 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7256 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7257 | /* Load a template into the MCU */ |
| 7258 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 7259 | |
| 7260 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 7261 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 7262 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7263 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7264 | uint32_t offset; |
| 7265 | uint32_t size; |
| 7266 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7267 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7268 | |
| 7269 | /* Clear the current fingerprint user context and set a new one */ |
| 7270 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 7271 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7272 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7273 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7274 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7275 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7276 | enum fp_context_action { |
| 7277 | FP_CONTEXT_ASYNC = 0, |
| 7278 | FP_CONTEXT_GET_RESULT = 1, |
| 7279 | }; |
| 7280 | |
| 7281 | /* Version 1 of the command is "asynchronous". */ |
| 7282 | struct ec_params_fp_context_v1 { |
| 7283 | uint8_t action; /**< enum fp_context_action */ |
| 7284 | uint8_t reserved[3]; /**< padding for alignment */ |
| 7285 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 7286 | } __ec_align4; |
| 7287 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7288 | #define EC_CMD_FP_STATS 0x0407 |
| 7289 | |
| 7290 | #define FPSTATS_CAPTURE_INV BIT(0) |
| 7291 | #define FPSTATS_MATCHING_INV BIT(1) |
| 7292 | |
| 7293 | struct ec_response_fp_stats { |
| 7294 | uint32_t capture_time_us; |
| 7295 | uint32_t matching_time_us; |
| 7296 | uint32_t overall_time_us; |
| 7297 | struct { |
| 7298 | uint32_t lo; |
| 7299 | uint32_t hi; |
| 7300 | } overall_t0; |
| 7301 | uint8_t timestamps_invalid; |
| 7302 | int8_t template_matched; |
| 7303 | } __ec_align2; |
| 7304 | |
| 7305 | #define EC_CMD_FP_SEED 0x0408 |
| 7306 | struct ec_params_fp_seed { |
| 7307 | /* |
| 7308 | * Version of the structure format (N=3). |
| 7309 | */ |
| 7310 | uint16_t struct_version; |
| 7311 | /* Reserved bytes, set to 0. */ |
| 7312 | uint16_t reserved; |
| 7313 | /* Seed from the TPM. */ |
| 7314 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 7315 | } __ec_align4; |
| 7316 | |
| 7317 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 7318 | |
| 7319 | /* FP TPM seed has been set or not */ |
| 7320 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 7321 | |
| 7322 | struct ec_response_fp_encryption_status { |
| 7323 | /* Used bits in encryption engine status */ |
| 7324 | uint32_t valid_flags; |
| 7325 | /* Encryption engine status */ |
| 7326 | uint32_t status; |
| 7327 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7328 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7329 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 7330 | struct ec_params_fp_read_match_secret { |
| 7331 | uint16_t fgr; |
| 7332 | } __ec_align4; |
| 7333 | |
| 7334 | /* The positive match secret has the length of the SHA256 digest. */ |
| 7335 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 7336 | struct ec_response_fp_read_match_secret { |
| 7337 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 7338 | } __ec_align4; |
| 7339 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7340 | /*****************************************************************************/ |
| 7341 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 7342 | |
| 7343 | /* Perform touchpad self test */ |
| 7344 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 7345 | |
| 7346 | /* Get number of frame types, and the size of each type */ |
| 7347 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 7348 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7349 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7350 | uint32_t n_frames; |
| 7351 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7352 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7353 | |
| 7354 | /* Create a snapshot of current frame readings */ |
| 7355 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 7356 | |
| 7357 | /* Read the frame */ |
| 7358 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 7359 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7360 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7361 | uint32_t frame_index; |
| 7362 | uint32_t offset; |
| 7363 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7364 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7365 | |
| 7366 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7367 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 7368 | |
| 7369 | #define EC_COMM_TEXT_MAX 8 |
| 7370 | |
| 7371 | /* |
| 7372 | * Get battery static information, i.e. information that never changes, or |
| 7373 | * very infrequently. |
| 7374 | */ |
| 7375 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 7376 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7377 | /** |
| 7378 | * struct ec_params_battery_static_info - Battery static info parameters |
| 7379 | * @index: Battery index. |
| 7380 | */ |
| 7381 | struct ec_params_battery_static_info { |
| 7382 | uint8_t index; |
| 7383 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7384 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7385 | /** |
| 7386 | * struct ec_response_battery_static_info - Battery static info response |
| 7387 | * @design_capacity: Battery Design Capacity (mAh) |
| 7388 | * @design_voltage: Battery Design Voltage (mV) |
| 7389 | * @manufacturer: Battery Manufacturer String |
| 7390 | * @model: Battery Model Number String |
| 7391 | * @serial: Battery Serial Number String |
| 7392 | * @type: Battery Type String |
| 7393 | * @cycle_count: Battery Cycle Count |
| 7394 | */ |
| 7395 | struct ec_response_battery_static_info { |
| 7396 | uint16_t design_capacity; |
| 7397 | uint16_t design_voltage; |
| 7398 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 7399 | char model[EC_COMM_TEXT_MAX]; |
| 7400 | char serial[EC_COMM_TEXT_MAX]; |
| 7401 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7402 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7403 | uint32_t cycle_count; |
| 7404 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7405 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7406 | /** |
| 7407 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 7408 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 7409 | * strings. |
| 7410 | * @design_capacity: battery design capacity (in mAh) |
| 7411 | * @design_voltage: battery design voltage (in mV) |
| 7412 | * @cycle_count: battery cycle count |
| 7413 | * @manufacturer_ext: battery manufacturer string |
| 7414 | * @model_ext: battery model string |
| 7415 | * @serial_ext: battery serial number string |
| 7416 | * @type_ext: battery type string |
| 7417 | */ |
| 7418 | struct ec_response_battery_static_info_v1 { |
| 7419 | uint16_t design_capacity; |
| 7420 | uint16_t design_voltage; |
| 7421 | uint32_t cycle_count; |
| 7422 | char manufacturer_ext[12]; |
| 7423 | char model_ext[12]; |
| 7424 | char serial_ext[12]; |
| 7425 | char type_ext[12]; |
| 7426 | } __ec_align4; |
| 7427 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7428 | /* |
| 7429 | * Get battery dynamic information, i.e. information that is likely to change |
| 7430 | * every time it is read. |
| 7431 | */ |
| 7432 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 7433 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7434 | /** |
| 7435 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 7436 | * @index: Battery index. |
| 7437 | */ |
| 7438 | struct ec_params_battery_dynamic_info { |
| 7439 | uint8_t index; |
| 7440 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7441 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7442 | /** |
| 7443 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 7444 | * @actual_voltage: Battery voltage (mV) |
| 7445 | * @actual_current: Battery current (mA); negative=discharging |
| 7446 | * @remaining_capacity: Remaining capacity (mAh) |
| 7447 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 7448 | * @flags: Flags, see EC_BATT_FLAG_* |
| 7449 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 7450 | * @desired_current: Charging current desired by battery (mA) |
| 7451 | */ |
| 7452 | struct ec_response_battery_dynamic_info { |
| 7453 | int16_t actual_voltage; |
| 7454 | int16_t actual_current; |
| 7455 | int16_t remaining_capacity; |
| 7456 | int16_t full_capacity; |
| 7457 | int16_t flags; |
| 7458 | int16_t desired_voltage; |
| 7459 | int16_t desired_current; |
| 7460 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7461 | |
| 7462 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7463 | * Control charger chip. Used to control charger chip on the peripheral. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7464 | */ |
| 7465 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 7466 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7467 | /** |
| 7468 | * struct ec_params_charger_control - Charger control parameters |
| 7469 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 7470 | * max_current and (possibly) charge battery, negative to request current |
| 7471 | * from base (OTG). |
| 7472 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 7473 | * >= 0. |
| 7474 | * @allow_charging: Allow base battery charging (only makes sense if |
| 7475 | * max_current > 0). |
| 7476 | */ |
| 7477 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7478 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7479 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7480 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7481 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7482 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7483 | /* Get ACK from the USB-C SS muxes */ |
| 7484 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 7485 | |
| 7486 | struct ec_params_usb_pd_mux_ack { |
| 7487 | uint8_t port; /* USB-C port number */ |
| 7488 | } __ec_align1; |
| 7489 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7490 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7491 | /* |
| 7492 | * Reserve a range of host commands for board-specific, experimental, or |
| 7493 | * special purpose features. These can be (re)used without updating this file. |
| 7494 | * |
| 7495 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 7496 | * their EC commands for easier development, testing, debugging, and support. |
| 7497 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7498 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 7499 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 7500 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7501 | * In your experimental code, you may want to do something like this: |
| 7502 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7503 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 7504 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 7505 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 7506 | * |
| 7507 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 7508 | * EC_VER_MASK(0); |
| 7509 | * |
| 7510 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 7511 | * EC_VER_MASK(0); |
| 7512 | * |
| 7513 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 7514 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7515 | */ |
| 7516 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 7517 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 7518 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7519 | /* |
| 7520 | * Given the private host command offset, calculate the true private host |
| 7521 | * command value. |
| 7522 | */ |
| 7523 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 7524 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 7525 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7526 | /*****************************************************************************/ |
| 7527 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 7528 | * Passthru commands |
| 7529 | * |
| 7530 | * Some platforms have sub-processors chained to each other. For example. |
| 7531 | * |
| 7532 | * AP <--> EC <--> PD MCU |
| 7533 | * |
| 7534 | * The top 2 bits of the command number are used to indicate which device the |
| 7535 | * command is intended for. Device 0 is always the device receiving the |
| 7536 | * command; other device mapping is board-specific. |
| 7537 | * |
| 7538 | * When a device receives a command to be passed to a sub-processor, it passes |
| 7539 | * it on with the device number set back to 0. This allows the sub-processor |
| 7540 | * to remain blissfully unaware of whether the command originated on the next |
| 7541 | * device up the chain, or was passed through from the AP. |
| 7542 | * |
| 7543 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 7544 | * AP sends command 0x4002 to the EC |
| 7545 | * EC sends command 0x0002 to the PD MCU |
| 7546 | * EC forwards PD MCU response back to the AP |
| 7547 | */ |
| 7548 | |
| 7549 | /* Offset and max command number for sub-device n */ |
| 7550 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 7551 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 7552 | |
| 7553 | /*****************************************************************************/ |
| 7554 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7555 | * Deprecated constants. These constants have been renamed for clarity. The |
| 7556 | * meaning and size has not changed. Programs that use the old names should |
| 7557 | * switch to the new names soon, as the old names may not be carried forward |
| 7558 | * forever. |
| 7559 | */ |
| 7560 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 7561 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 7562 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 7563 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7564 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7565 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7566 | #ifdef __cplusplus |
| 7567 | } |
| 7568 | #endif |
| 7569 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7570 | #endif /* __CROS_EC_EC_COMMANDS_H */ |