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 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 3 | |
| 4 | |
| 5 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 6 | /* Host communication command constants for Chrome EC */ |
| 7 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 8 | /* |
| 9 | * TODO(b/272518464): Work around coreboot GCC preprocessor bug. |
| 10 | * #line marks the *next* line, so it is off by one. |
| 11 | */ |
| 12 | #line 13 |
| 13 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 14 | #ifndef __CROS_EC_EC_COMMANDS_H |
| 15 | #define __CROS_EC_EC_COMMANDS_H |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 16 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 17 | #if !defined(__ACPI__) && !defined(__KERNEL__) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #endif |
| 20 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 21 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 22 | /* |
| 23 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 24 | * It is used to not include macros that may cause conflicts in foreign |
| 25 | * projects (refer to crbug.com/984623). |
| 26 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 27 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 28 | /* |
| 29 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 30 | * generates more efficient code for accessing request/response structures on |
| 31 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 32 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 33 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 34 | #include "compile_time_macros.h" |
| 35 | |
| 36 | #else |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 37 | /* If BUILD_ASSERT isn't already defined, make it a no-op */ |
| 38 | #ifndef BUILD_ASSERT |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 39 | #define BUILD_ASSERT(_cond) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 40 | #endif /* !BUILD_ASSERT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 41 | #endif /* CHROMIUM_EC */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 42 | |
| 43 | #ifdef __KERNEL__ |
| 44 | #include <linux/limits.h> |
| 45 | #else |
| 46 | /* |
| 47 | * Defines macros that may be needed but are for sure defined by the linux |
| 48 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 49 | * util/make_linux_ec_commands_h.sh). |
| 50 | * cros_ec_commands.h looks more integrated to the kernel. |
| 51 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 52 | |
| 53 | #ifndef BIT |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 54 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 55 | #endif |
| 56 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 57 | #ifndef BIT_ULL |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 58 | #define BIT_ULL(nr) (1ULL << (nr)) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 59 | #endif |
| 60 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 61 | /* |
| 62 | * When building Zephyr, this file ends up being included before Zephyr's |
| 63 | * include/sys/util.h so causes a warning there. We don't want to add an #ifdef |
| 64 | * in that file since it won't be accepted upstream. So work around it here. |
| 65 | */ |
| 66 | #ifndef CONFIG_ZEPHYR |
| 67 | #ifndef GENMASK |
| 68 | #define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1)) |
| 69 | #endif |
| 70 | |
| 71 | #ifndef GENMASK_ULL |
| 72 | #define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1)) |
| 73 | #endif |
| 74 | #endif |
| 75 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 76 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 77 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 78 | #ifdef __cplusplus |
| 79 | extern "C" { |
| 80 | #endif |
| 81 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Constant for creation of flexible array members that work in both C and |
| 84 | * C++. Flexible array members were added in C99 and are not part of the C++ |
| 85 | * standard. However, clang++ supports them for C++. |
| 86 | * When compiling with gcc, flexible array members are not allowed to appear |
| 87 | * in an otherwise empty struct, so we use the GCC zero-length array |
| 88 | * extension that works with both clang/gcc/g++. |
| 89 | */ |
| 90 | #if defined(__cplusplus) && defined(__clang__) |
| 91 | #define FLEXIBLE_ARRAY_MEMBER_SIZE |
| 92 | #else |
| 93 | #define FLEXIBLE_ARRAY_MEMBER_SIZE 0 |
| 94 | #endif |
| 95 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 96 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 97 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 98 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 99 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 100 | * determined in other ways. Remove this once the kernel code no longer |
| 101 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 102 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 103 | #define EC_PROTO_VERSION 0x00000002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 104 | |
| 105 | /* Command version mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 106 | #define EC_VER_MASK(version) BIT(version) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 107 | |
| 108 | /* I/O addresses for ACPI commands */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 109 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 110 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 111 | |
| 112 | /* I/O addresses for host command */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 113 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 114 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 115 | |
| 116 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 117 | /* Protocol version 2 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 118 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 119 | /* For version 2 params; size is EC_PROTO2_MAX_PARAM_SIZE */ |
| 120 | #define EC_LPC_ADDR_HOST_PARAM 0x804 |
| 121 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 122 | /* Protocol version 3 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 123 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 124 | #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] | 125 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 126 | /* |
| 127 | * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 128 | * and they tell the kernel that so we have to think of it as two parts. |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 129 | * |
| 130 | * Other BIOSes report only the I/O port region spanned by the Microchip |
| 131 | * MEC series EC; an attempt to address a larger region may fail. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 132 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 133 | #define EC_HOST_CMD_REGION0 0x800 |
| 134 | #define EC_HOST_CMD_REGION1 0x880 |
| 135 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 136 | #define EC_HOST_CMD_MEC_REGION_SIZE 0x8 |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 137 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 138 | /* EC command register bit functions */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 139 | #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ |
| 140 | #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ |
| 141 | #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ |
| 142 | #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ |
| 143 | #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ |
| 144 | #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ |
| 145 | #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 146 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 147 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 148 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 149 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 150 | |
| 151 | /* The offset address of each type of data in mapped memory. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 152 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 153 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 154 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 155 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
| 156 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 157 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 158 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 159 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 160 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
| 161 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 162 | /* Unused 0x28 - 0x2f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 163 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 164 | /* Unused 0x31 - 0x33 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 165 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 166 | /* Battery values are all 32 bits, unless otherwise noted. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 167 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 168 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 169 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
| 170 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ |
| 171 | #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ |
| 172 | #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 173 | /* Unused 0x4f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 174 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 175 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 176 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 177 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 178 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 179 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 180 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 181 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 182 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
| 183 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 184 | /* Unused 0x84 - 0x8f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 185 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 186 | /* Unused 0x91 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 187 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 188 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 189 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 190 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 191 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 192 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 193 | #define EC_MEMMAP_GPU 0xa6 /* GPU-specific, 8 bits */ |
| 194 | |
| 195 | /* |
| 196 | * Bit fields for EC_MEMMAP_GPU |
| 197 | * 0:2: D-Notify level (0:D1, ... 4:D5) |
| 198 | * 3: Over temperature |
| 199 | */ |
| 200 | #define EC_MEMMAP_GPU_D_NOTIFY_MASK GENMASK(2, 0) |
| 201 | #define EC_MEMMAP_GPU_OVERT_BIT BIT(3) |
| 202 | |
| 203 | /* Power Participant related components */ |
| 204 | #define EC_MEMMAP_PWR_SRC 0xa7 /* Power source (8-bit) */ |
| 205 | /* Unused 0xa8 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 206 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 207 | /* |
| 208 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 209 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 210 | * which might be needed by ACPI. |
| 211 | */ |
| 212 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 213 | |
| 214 | /* Define the format of the accelerometer mapped memory status byte. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 215 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
| 216 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) |
| 217 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 218 | |
| 219 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 220 | #define EC_TEMP_SENSOR_ENTRIES 16 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 221 | /* |
| 222 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 223 | * |
| 224 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 225 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 226 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 227 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 228 | /* Max temp sensor entries for host commands */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 229 | #define EC_MAX_TEMP_SENSOR_ENTRIES \ |
| 230 | (EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 231 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 232 | /* Special values for mapped temperature sensors */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 233 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 234 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 235 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 236 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 237 | /* |
| 238 | * The offset of temperature value stored in mapped memory. This allows |
| 239 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 240 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 241 | #define EC_TEMP_SENSOR_OFFSET 200 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 242 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 243 | /* |
| 244 | * Number of ALS readings at EC_MEMMAP_ALS |
| 245 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 246 | #define EC_ALS_ENTRIES 2 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * The default value a temperature sensor will return when it is present but |
| 250 | * has not been read this boot. This is a reasonable number to avoid |
| 251 | * triggering alarms on the host. |
| 252 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 253 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 254 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 255 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 256 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 257 | |
| 258 | /* Report 0 for fan stalled so userspace applications can take |
| 259 | * an appropriate action based on this value to control the fan. |
| 260 | */ |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 261 | #define EC_FAN_SPEED_STALLED 0x0 |
| 262 | /* This should be used only for ectool to support old ECs. */ |
| 263 | #define EC_FAN_SPEED_STALLED_DEPRECATED 0xfffe |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 264 | |
| 265 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 266 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 267 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 268 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 269 | #define EC_BATT_FLAG_CHARGING 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 270 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 271 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 272 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 273 | #define EC_BATT_FLAG_CUT_OFF 0x40 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 274 | |
| 275 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 276 | #define EC_SWITCH_LID_OPEN 0x01 |
| 277 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 278 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 279 | /* Was recovery requested via keyboard; now unused. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 280 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 281 | /* Recovery requested via dedicated signal (from servo board) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 282 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 283 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 284 | #define EC_SWITCH_IGNORE0 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 285 | |
| 286 | /* Host command interface flags */ |
| 287 | /* Host command interface supports LPC args (LPC interface only) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 288 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 289 | /* Host command interface supports version 3 protocol */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 290 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 291 | |
| 292 | /* Wireless switch flags */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 293 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 294 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 295 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 296 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 297 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 298 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 299 | /*****************************************************************************/ |
| 300 | /* |
| 301 | * ACPI commands |
| 302 | * |
| 303 | * These are valid ONLY on the ACPI command/data port. |
| 304 | */ |
| 305 | |
| 306 | /* |
| 307 | * ACPI Read Embedded Controller |
| 308 | * |
| 309 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 310 | * |
| 311 | * Use the following sequence: |
| 312 | * |
| 313 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 314 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 315 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 316 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 317 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 318 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 319 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 320 | |
| 321 | /* |
| 322 | * ACPI Write Embedded Controller |
| 323 | * |
| 324 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 325 | * |
| 326 | * Use the following sequence: |
| 327 | * |
| 328 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 329 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 330 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 331 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 332 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 333 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 334 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * ACPI Burst Enable Embedded Controller |
| 338 | * |
| 339 | * This enables burst mode on the EC to allow the host to issue several |
| 340 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 341 | * data are locked out to ensure data consistency. |
| 342 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 343 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * ACPI Burst Disable Embedded Controller |
| 347 | * |
| 348 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 349 | * multi-byte data. |
| 350 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 351 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * ACPI Query Embedded Controller |
| 355 | * |
| 356 | * This clears the lowest-order bit in the currently pending host events, and |
| 357 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 358 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 359 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 360 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 361 | |
| 362 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 363 | |
| 364 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 365 | #define EC_ACPI_MEM_VERSION 0x00 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 366 | /* |
| 367 | * Test location; writing value here updates test compliment byte to (0xff - |
| 368 | * value). |
| 369 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 370 | #define EC_ACPI_MEM_TEST 0x01 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 371 | /* Test compliment; writes here are ignored. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 372 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 373 | |
| 374 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 375 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 376 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 377 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 378 | |
| 379 | /* |
| 380 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 381 | * independent thresholds attached to them. The current value of the ID |
| 382 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 383 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 384 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 385 | * |
| 386 | * The spec does not mandate any way to read back the threshold settings |
| 387 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 388 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 389 | * returns one sensor ID that has crossed one of its threshold (in either |
| 390 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 391 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 392 | * the unread event count for that sensor. |
| 393 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 394 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 395 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 396 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 397 | /* |
| 398 | * Here are the bits for the COMMIT register: |
| 399 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 400 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 401 | * Each write to the commit register affects one threshold. |
| 402 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 403 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 404 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 405 | /* |
| 406 | * Example: |
| 407 | * |
| 408 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 409 | * write 2 to [0x05] -- select temp sensor 2 |
| 410 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 411 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 412 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 413 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 414 | * |
| 415 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 416 | * write 2 to [0x05] -- select temp sensor 2 |
| 417 | * write 0x1 to [0x07] -- disable threshold 1 |
| 418 | */ |
| 419 | |
| 420 | /* DPTF battery charging current limit */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 421 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 422 | |
| 423 | /* Charging limit is specified in 64 mA steps */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 424 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 425 | /* Value to disable DPTF battery charging limit */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 426 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 427 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 428 | /* |
| 429 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 430 | * Bits Definition |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 431 | * 4 Off Body/On Body status: 0 = Off Body. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 432 | * 3:1 Device DPTF Profile Number (DDPN) |
| 433 | * 0 = Reserved for backward compatibility (indicates no valid |
| 434 | * profile number. Host should fall back to using TBMD). |
| 435 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 436 | * to be loaded. |
| 437 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 438 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 439 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 440 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 441 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 442 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 443 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 444 | #define EC_ACPI_MEM_STTB_SHIFT 4 |
| 445 | #define EC_ACPI_MEM_STTB_MASK 0x1 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 446 | |
| 447 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 448 | * Report device features. Uses the same format as the host command, except: |
| 449 | * |
| 450 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 451 | * of features", which is of limited interest when the system is already |
| 452 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 453 | * these are supported, it defaults to 0. |
| 454 | * This allows detecting the presence of this field since older versions of |
| 455 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 456 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 457 | * are valid. |
| 458 | */ |
| 459 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 460 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 461 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 462 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 463 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 464 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 465 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 466 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 467 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 468 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 469 | |
| 470 | /* |
| 471 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 472 | * is enabled (1) or disabled (0). |
| 473 | * bit 0 USB port ID 0 |
| 474 | * ... |
| 475 | * bit 7 USB port ID 7 |
| 476 | */ |
| 477 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 478 | |
| 479 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 480 | * USB Retimer firmware update. |
| 481 | * Read: |
| 482 | * Result of last operation AP requested |
| 483 | * Write: |
| 484 | * bits[3:0]: USB-C port number |
| 485 | * bits[7:4]: Operation requested by AP |
| 486 | * |
| 487 | * NDA (no device attached) case: |
| 488 | * To update retimer firmware, AP needs set up TBT Alt mode. |
| 489 | * AP requests operations in this sequence: |
| 490 | * 1. Get port information about which ports support retimer firmware update. |
| 491 | * In the query result, each bit represents one port. |
| 492 | * 2. Get current MUX mode, it's NDA. |
| 493 | * 3. Suspend specified PD port's task. |
| 494 | * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode -> |
| 495 | * update firmware -> disconnect MUX -> resume PD task. |
| 496 | * |
| 497 | * DA (device attached) cases: |
| 498 | * Retimer firmware update is not supported in DA cases. |
| 499 | * 1. Get port information about which ports support retimer firmware update |
| 500 | * 2. Get current MUX mode, it's DA. |
| 501 | * 3. AP continues. No more retimer firmware update activities. |
| 502 | * |
| 503 | */ |
| 504 | #define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14 |
| 505 | |
| 506 | #define USB_RETIMER_FW_UPDATE_OP_SHIFT 4 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 507 | #define USB_RETIMER_FW_UPDATE_ERR 0xfe |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 508 | #define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 509 | /* Mask to clear unused MUX bits in retimer firmware update */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 510 | #define USB_RETIMER_FW_UPDATE_MUX_MASK \ |
| 511 | (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \ |
| 512 | USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \ |
| 513 | USB_PD_MUX_USB4_ENABLED) |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 514 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 515 | /* Retimer firmware update operations */ |
| 516 | #define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */ |
| 517 | #define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 518 | #define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */ |
| 519 | #define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */ |
| 520 | #define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */ |
| 521 | #define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */ |
| 522 | #define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 523 | #define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */ |
| 524 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 525 | #define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x)&0x0f) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 526 | #define EC_ACPI_MEM_USB_RETIMER_OP(x) \ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 527 | (((x)&0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 528 | |
| 529 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 530 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 531 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 532 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 533 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 534 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 535 | |
| 536 | /* Current version of ACPI memory address space */ |
| 537 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 538 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 539 | /* |
| 540 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 541 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 542 | * handle actual C code so keep it separate. |
| 543 | */ |
| 544 | #ifndef __ACPI__ |
| 545 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 546 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 547 | /* |
| 548 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 549 | * checking prefers __packed over __attribute__((packed)). |
| 550 | */ |
| 551 | #ifndef __packed |
| 552 | #define __packed __attribute__((packed)) |
| 553 | #endif |
| 554 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 555 | #ifndef __aligned |
| 556 | #define __aligned(x) __attribute__((aligned(x))) |
| 557 | #endif |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 558 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 559 | |
| 560 | /* |
| 561 | * Attributes for EC request and response packets. Just defining __packed |
| 562 | * results in inefficient assembly code on ARM, if the structure is actually |
| 563 | * 32-bit aligned, as it should be for all buffers. |
| 564 | * |
| 565 | * Be very careful when adding these to existing structures. They will round |
| 566 | * up the structure size to the specified boundary. |
| 567 | * |
| 568 | * Also be very careful to make that if a structure is included in some other |
| 569 | * parent structure that the alignment will still be true given the packing of |
| 570 | * the parent structure. This is particularly important if the sub-structure |
| 571 | * 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] | 572 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 573 | * |
| 574 | * Also be very careful using __packed - particularly when nesting non-packed |
| 575 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 576 | * always use one of these attributes. |
| 577 | * |
| 578 | * Once everything is annotated properly, the following search strings should |
| 579 | * not return ANY matches in this file other than right here: |
| 580 | * |
| 581 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 582 | * |
| 583 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 584 | * members of other structs/unions (and their original declarations should be |
| 585 | * annotated). |
| 586 | */ |
| 587 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 588 | |
| 589 | /* |
| 590 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 591 | * byte boundary. |
| 592 | */ |
| 593 | #define __ec_align1 __packed |
| 594 | #define __ec_align2 __packed __aligned(2) |
| 595 | #define __ec_align4 __packed __aligned(4) |
| 596 | |
| 597 | /* |
| 598 | * Packed structure which must be under-aligned, because its size is not a |
| 599 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 600 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 601 | * |
| 602 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 603 | * its members, but use the __packed version for sizeof(). |
| 604 | */ |
| 605 | #define __ec_align_size1 __packed |
| 606 | |
| 607 | /* |
| 608 | * Packed structure which must be under-aligned, because its offset inside a |
| 609 | * parent structure is not a 4-byte multiple. |
| 610 | */ |
| 611 | #define __ec_align_offset1 __packed |
| 612 | #define __ec_align_offset2 __packed __aligned(2) |
| 613 | |
| 614 | /* |
| 615 | * Structures which are complicated enough that I'm skipping them on the first |
| 616 | * pass. They are effectively unchanged from their previous definitions. |
| 617 | * |
| 618 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 619 | * to work out the size and offset of each member and add explicit padding to |
| 620 | * maintain those. |
| 621 | */ |
| 622 | #define __ec_todo_packed __packed |
| 623 | #define __ec_todo_unpacked |
| 624 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 625 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * Packed structures make no assumption about alignment, so they do inefficient |
| 629 | * byte-wise reads. |
| 630 | */ |
| 631 | #define __ec_align1 __packed |
| 632 | #define __ec_align2 __packed |
| 633 | #define __ec_align4 __packed |
| 634 | #define __ec_align_size1 __packed |
| 635 | #define __ec_align_offset1 __packed |
| 636 | #define __ec_align_offset2 __packed |
| 637 | #define __ec_todo_packed __packed |
| 638 | #define __ec_todo_unpacked |
| 639 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 640 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 641 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 642 | /* LPC command status byte masks */ |
| 643 | /* EC has written a byte in the data register and host hasn't read it yet */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 644 | #define EC_LPC_STATUS_TO_HOST 0x01 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 645 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 646 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 647 | /* EC is processing a command */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 648 | #define EC_LPC_STATUS_PROCESSING 0x04 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 649 | /* Last write to EC was a command, not data */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 650 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 651 | /* EC is in burst mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 652 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 653 | /* SCI event is pending (requesting SCI query) */ |
| 654 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 655 | /* SMI event is pending (requesting SMI query) */ |
| 656 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 657 | /* (reserved) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 658 | #define EC_LPC_STATUS_RESERVED 0x80 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 659 | |
| 660 | /* |
| 661 | * EC is busy. This covers both the EC processing a command, and the host has |
| 662 | * written a new command but the EC hasn't picked it up yet. |
| 663 | */ |
| 664 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 665 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 666 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 667 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 668 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 669 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 670 | enum ec_status { |
| 671 | EC_RES_SUCCESS = 0, |
| 672 | EC_RES_INVALID_COMMAND = 1, |
| 673 | EC_RES_ERROR = 2, |
| 674 | EC_RES_INVALID_PARAM = 3, |
| 675 | EC_RES_ACCESS_DENIED = 4, |
| 676 | EC_RES_INVALID_RESPONSE = 5, |
| 677 | EC_RES_INVALID_VERSION = 6, |
| 678 | EC_RES_INVALID_CHECKSUM = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 679 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 680 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 681 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 682 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
| 683 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 684 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
| 685 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
| 686 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
| 687 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 688 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 689 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 690 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 691 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 692 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 693 | EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 694 | } __packed; |
| 695 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 696 | |
| 697 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 698 | * Host event codes. ACPI query EC command uses code 0 to mean "no event |
| 699 | * pending". We explicitly specify each value in the enum listing so they won't |
| 700 | * change if we delete/insert an item or rearrange the list (it needs to be |
| 701 | * stable across platforms, not just within a single compiled instance). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 702 | */ |
| 703 | enum host_event_code { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 704 | EC_HOST_EVENT_NONE = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 705 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 706 | EC_HOST_EVENT_LID_OPEN = 2, |
| 707 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 708 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 709 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 710 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 711 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 712 | EC_HOST_EVENT_BATTERY = 8, |
| 713 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 714 | /* Event generated by a device attached to the EC */ |
| 715 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 716 | EC_HOST_EVENT_THERMAL = 11, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 717 | /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */ |
| 718 | EC_HOST_EVENT_GPU = 12, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 719 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 720 | /* |
| 721 | * EC has finished initializing the host interface. The host can check |
| 722 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 723 | * determine when the EC is ready to accept subsequent commands. |
| 724 | */ |
| 725 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 726 | /* Keyboard recovery combo has been pressed */ |
| 727 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 728 | |
| 729 | /* Shutdown due to thermal overload */ |
| 730 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 731 | /* Shutdown due to battery level too low */ |
| 732 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 733 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 734 | /* Suggest that the AP throttle itself */ |
| 735 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 736 | /* Suggest that the AP resume normal speed */ |
| 737 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 738 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 739 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 740 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 741 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 742 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 743 | |
| 744 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 745 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 746 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 747 | /* Battery Status flags have changed */ |
| 748 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 749 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 750 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 751 | EC_HOST_EVENT_PANIC = 24, |
| 752 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 753 | /* Keyboard fastboot combo has been pressed */ |
| 754 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 755 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 756 | /* EC RTC event occurred */ |
| 757 | EC_HOST_EVENT_RTC = 26, |
| 758 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 759 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 760 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 761 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 762 | /* EC desires to change state of host-controlled USB mux */ |
| 763 | EC_HOST_EVENT_USB_MUX = 28, |
| 764 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 765 | /* |
| 766 | * The device has changed "modes". This can be one of the following: |
| 767 | * |
| 768 | * - TABLET/LAPTOP mode |
| 769 | * - detachable base attach/detach event |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 770 | * - on body/off body transition event |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 771 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 772 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 773 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 774 | /* Keyboard recovery combo with hardware reinitialization */ |
| 775 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 776 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 777 | /* WoV */ |
| 778 | EC_HOST_EVENT_WOV = 31, |
| 779 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 780 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 781 | * The high bit of the event mask is not used as a host event code. If |
| 782 | * it reads back as set, then the entire event mask should be |
| 783 | * considered invalid by the host. This can happen when reading the |
| 784 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 785 | * not initialized on the EC, or improperly configured on the host. |
| 786 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 787 | EC_HOST_EVENT_INVALID = 32, |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 788 | |
| 789 | /* Body detect (lap/desk) change event */ |
| 790 | EC_HOST_EVENT_BODY_DETECT_CHANGE = 33, |
| 791 | |
| 792 | /* |
| 793 | * Only 64 host events are supported. This enum uses 1-based counting so |
| 794 | * it can skip 0 (NONE), so the last legal host event number is 64. |
| 795 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 796 | }; |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 797 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 798 | /* Host event mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 799 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 800 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 801 | /* clang-format off */ |
| 802 | #define HOST_EVENT_TEXT \ |
| 803 | { \ |
| 804 | [EC_HOST_EVENT_NONE] = "NONE", \ |
| 805 | [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \ |
| 806 | [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \ |
| 807 | [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \ |
| 808 | [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \ |
| 809 | [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \ |
| 810 | [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \ |
| 811 | [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \ |
| 812 | [EC_HOST_EVENT_BATTERY] = "BATTERY", \ |
| 813 | [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \ |
| 814 | [EC_HOST_EVENT_DEVICE] = "DEVICE", \ |
| 815 | [EC_HOST_EVENT_THERMAL] = "THERMAL", \ |
| 816 | [EC_HOST_EVENT_GPU] = "GPU", \ |
| 817 | [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \ |
| 818 | [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \ |
| 819 | [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \ |
| 820 | [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \ |
| 821 | [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \ |
| 822 | [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \ |
| 823 | [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \ |
| 824 | [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \ |
| 825 | [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \ |
| 826 | [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \ |
| 827 | [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \ |
| 828 | [EC_HOST_EVENT_PANIC] = "PANIC", \ |
| 829 | [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \ |
| 830 | [EC_HOST_EVENT_RTC] = "RTC", \ |
| 831 | [EC_HOST_EVENT_MKBP] = "MKBP", \ |
| 832 | [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \ |
| 833 | [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \ |
| 834 | [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \ |
| 835 | "KEYBOARD_RECOVERY_HW_REINIT", \ |
| 836 | [EC_HOST_EVENT_WOV] = "WOV", \ |
| 837 | [EC_HOST_EVENT_INVALID] = "INVALID", \ |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 838 | [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 839 | } |
| 840 | /* clang-format on */ |
| 841 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 842 | /** |
| 843 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 844 | * @flags: The host argument flags. |
| 845 | * @command_version: Command version. |
| 846 | * @data_size: The length of data. |
| 847 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 848 | * all params/response data bytes. |
| 849 | */ |
| 850 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 851 | uint8_t flags; |
| 852 | uint8_t command_version; |
| 853 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 854 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 855 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 856 | |
| 857 | /* Flags for ec_lpc_host_args.flags */ |
| 858 | /* |
| 859 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 860 | * params. |
| 861 | * |
| 862 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 863 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 864 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 865 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 866 | */ |
| 867 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 868 | /* |
| 869 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 870 | * |
| 871 | * If EC responds to a command and this flag is not set, this is an old-style |
| 872 | * response. Command version is 0 and response data from EC is at |
| 873 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 874 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 875 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 876 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 877 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 878 | /* |
| 879 | * Byte codes returned by EC over SPI interface. |
| 880 | * |
| 881 | * These can be used by the AP to debug the EC interface, and to determine |
| 882 | * when the EC is not in a state where it will ever get around to responding |
| 883 | * to the AP. |
| 884 | * |
| 885 | * Example of sequence of bytes read from EC for a current good transfer: |
| 886 | * 1. - - AP asserts chip select (CS#) |
| 887 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 888 | * 3. - - EC starts handling CS# interrupt |
| 889 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 890 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 891 | * bytes looking for EC_SPI_FRAME_START |
| 892 | * 6. - - EC finishes processing and sets up response |
| 893 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 894 | * 8. (response packet) - AP reads response packet |
| 895 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 896 | * 10 - - AP deasserts chip select |
| 897 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 898 | * next request |
| 899 | * |
| 900 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 901 | * the following byte values: |
| 902 | * EC_SPI_OLD_READY |
| 903 | * EC_SPI_RX_READY |
| 904 | * EC_SPI_RECEIVING |
| 905 | * EC_SPI_PROCESSING |
| 906 | * |
| 907 | * Then the EC found an error in the request, or was not ready for the request |
| 908 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 909 | * because the EC is unable to tell when the AP is done sending its request. |
| 910 | */ |
| 911 | |
| 912 | /* |
| 913 | * Framing byte which precedes a response packet from the EC. After sending a |
| 914 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 915 | * clock in the response packet. |
| 916 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 917 | #define EC_SPI_FRAME_START 0xec |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 918 | |
| 919 | /* |
| 920 | * Padding bytes which are clocked out after the end of a response packet. |
| 921 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 922 | #define EC_SPI_PAST_END 0xed |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 923 | |
| 924 | /* |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 925 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 926 | * that the AP will send a valid packet header (starting with |
| 927 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 928 | * |
| 929 | * NOTE: Some SPI configurations place the Most Significant Bit on SDO when |
| 930 | * CS goes low. This macro has the Most Significant Bit set to zero, |
| 931 | * so SDO will not be driven high when CS goes low. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 932 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 933 | #define EC_SPI_RX_READY 0x78 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 934 | |
| 935 | /* |
| 936 | * EC has started receiving the request from the AP, but hasn't started |
| 937 | * processing it yet. |
| 938 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 939 | #define EC_SPI_RECEIVING 0xf9 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 940 | |
| 941 | /* EC has received the entire request from the AP and is processing it. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 942 | #define EC_SPI_PROCESSING 0xfa |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | * EC received bad data from the AP, such as a packet header with an invalid |
| 946 | * length. EC will ignore all data until chip select deasserts. |
| 947 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 948 | #define EC_SPI_RX_BAD_DATA 0xfb |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 949 | |
| 950 | /* |
| 951 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 952 | * chip select and started clocking data before the EC was ready to receive it. |
| 953 | * EC will ignore all data until chip select deasserts. |
| 954 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 955 | #define EC_SPI_NOT_READY 0xfc |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 956 | |
| 957 | /* |
| 958 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 959 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 960 | * a fully received packet but is not ready to respond yet. |
| 961 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 962 | #define EC_SPI_OLD_READY 0xfd |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 963 | |
| 964 | /*****************************************************************************/ |
| 965 | |
| 966 | /* |
| 967 | * Protocol version 2 for I2C and SPI send a request this way: |
| 968 | * |
| 969 | * 0 EC_CMD_VERSION0 + (command version) |
| 970 | * 1 Command number |
| 971 | * 2 Length of params = N |
| 972 | * 3..N+2 Params, if any |
| 973 | * N+3 8-bit checksum of bytes 0..N+2 |
| 974 | * |
| 975 | * The corresponding response is: |
| 976 | * |
| 977 | * 0 Result code (EC_RES_*) |
| 978 | * 1 Length of params = M |
| 979 | * 2..M+1 Params, if any |
| 980 | * M+2 8-bit checksum of bytes 0..M+1 |
| 981 | */ |
| 982 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 983 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 984 | #define EC_PROTO2_REQUEST_OVERHEAD \ |
| 985 | (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 986 | |
| 987 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 988 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 989 | #define EC_PROTO2_RESPONSE_OVERHEAD \ |
| 990 | (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 991 | |
| 992 | /* Parameter length was limited by the LPC interface */ |
| 993 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 994 | |
| 995 | /* Maximum request and response packet sizes for protocol version 2 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 996 | #define EC_PROTO2_MAX_REQUEST_SIZE \ |
| 997 | (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
| 998 | #define EC_PROTO2_MAX_RESPONSE_SIZE \ |
| 999 | (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1000 | |
| 1001 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1002 | |
| 1003 | /* |
| 1004 | * Value written to legacy command port / prefix byte to indicate protocol |
| 1005 | * 3+ structs are being used. Usage is bus-dependent. |
| 1006 | */ |
| 1007 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 1008 | |
| 1009 | #define EC_HOST_REQUEST_VERSION 3 |
| 1010 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1011 | /** |
| 1012 | * struct ec_host_request - Version 3 request from host. |
| 1013 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 1014 | * receives a header with a version it doesn't know how to |
| 1015 | * parse. |
| 1016 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 1017 | * should total to 0. |
| 1018 | * @command: Command to send (EC_CMD_...) |
| 1019 | * @command_version: Command version. |
| 1020 | * @reserved: Unused byte in current protocol version; set to 0. |
| 1021 | * @data_len: Length of data which follows this header. |
| 1022 | */ |
| 1023 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1024 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1025 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1026 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1027 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1028 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1029 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1030 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1031 | |
| 1032 | #define EC_HOST_RESPONSE_VERSION 3 |
| 1033 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1034 | /** |
| 1035 | * struct ec_host_response - Version 3 response from EC. |
| 1036 | * @struct_version: Struct version (=3). |
| 1037 | * @checksum: Checksum of response and data; sum of all bytes including |
| 1038 | * checksum should total to 0. |
| 1039 | * @result: EC's response to the command (separate from communication failure) |
| 1040 | * @data_len: Length of data which follows this header. |
| 1041 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 1042 | */ |
| 1043 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1044 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1045 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1046 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1047 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1048 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1049 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1050 | |
| 1051 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1052 | |
| 1053 | /* |
| 1054 | * Host command protocol V4. |
| 1055 | * |
| 1056 | * Packets always start with a request or response header. They are followed |
| 1057 | * 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] | 1058 | * 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] | 1059 | * polynomial. |
| 1060 | * |
| 1061 | * Host algorithm when sending a request q: |
| 1062 | * |
| 1063 | * 101) tries_left=(some value, e.g. 3); |
| 1064 | * 102) q.seq_num++ |
| 1065 | * 103) q.seq_dup=0 |
| 1066 | * 104) Calculate q.header_crc. |
| 1067 | * 105) Send request q to EC. |
| 1068 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 1069 | * |
| 1070 | * 201) If r.struct_version != 4, go to 301. |
| 1071 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 1072 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 1073 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 1074 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 1075 | * 207) If r.seq_dup == 1, go to 301. |
| 1076 | * 208) Return error. |
| 1077 | * |
| 1078 | * 301) If --tries_left <= 0, return error. |
| 1079 | * 302) If q.seq_dup == 1, go to 105. |
| 1080 | * 303) q.seq_dup = 1 |
| 1081 | * 304) Go to 104. |
| 1082 | * |
| 1083 | * EC algorithm when receiving a request q. |
| 1084 | * EC has response buffer r, error buffer e. |
| 1085 | * |
| 1086 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 1087 | * and go to 301 |
| 1088 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 1089 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 1090 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 1091 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 1092 | * and go to 301. |
| 1093 | * 104) If q.seq_dup == 0, go to 201. |
| 1094 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 1095 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 1096 | * |
| 1097 | * 201) Process request q into response r. |
| 1098 | * 202) r.seq_num = q.seq_num |
| 1099 | * 203) r.seq_dup = q.seq_dup |
| 1100 | * 204) Calculate r.header_crc |
| 1101 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 1102 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 1103 | * 206) Send response r. |
| 1104 | * |
| 1105 | * 301) e.seq_num = q.seq_num |
| 1106 | * 302) e.seq_dup = q.seq_dup |
| 1107 | * 303) Calculate e.header_crc. |
| 1108 | * 304) Send error response e. |
| 1109 | */ |
| 1110 | |
| 1111 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1112 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1113 | /* |
| 1114 | * bits 0-3: struct_version: Structure version (=4) |
| 1115 | * bit 4: is_response: Is response (=0) |
| 1116 | * bits 5-6: seq_num: Sequence number |
| 1117 | * bit 7: seq_dup: Sequence duplicate flag |
| 1118 | */ |
| 1119 | uint8_t fields0; |
| 1120 | |
| 1121 | /* |
| 1122 | * bits 0-4: command_version: Command version |
| 1123 | * bits 5-6: Reserved (set 0, ignore on read) |
| 1124 | * bit 7: data_crc_present: Is data CRC present after data |
| 1125 | */ |
| 1126 | uint8_t fields1; |
| 1127 | |
| 1128 | /* Command code (EC_CMD_*) */ |
| 1129 | uint16_t command; |
| 1130 | |
| 1131 | /* Length of data which follows this header (not including data CRC) */ |
| 1132 | uint16_t data_len; |
| 1133 | |
| 1134 | /* Reserved (set 0, ignore on read) */ |
| 1135 | uint8_t reserved; |
| 1136 | |
| 1137 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1138 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1139 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1140 | |
| 1141 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1142 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1143 | /* |
| 1144 | * bits 0-3: struct_version: Structure version (=4) |
| 1145 | * bit 4: is_response: Is response (=1) |
| 1146 | * bits 5-6: seq_num: Sequence number |
| 1147 | * bit 7: seq_dup: Sequence duplicate flag |
| 1148 | */ |
| 1149 | uint8_t fields0; |
| 1150 | |
| 1151 | /* |
| 1152 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1153 | * bit 7: data_crc_present: Is data CRC present after data |
| 1154 | */ |
| 1155 | uint8_t fields1; |
| 1156 | |
| 1157 | /* Result code (EC_RES_*) */ |
| 1158 | uint16_t result; |
| 1159 | |
| 1160 | /* Length of data which follows this header (not including data CRC) */ |
| 1161 | uint16_t data_len; |
| 1162 | |
| 1163 | /* Reserved (set 0, ignore on read) */ |
| 1164 | uint8_t reserved; |
| 1165 | |
| 1166 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1167 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1168 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1169 | |
| 1170 | /* Fields in fields0 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1171 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1172 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1173 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1174 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1175 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1176 | |
| 1177 | /* Fields in fields1 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1178 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1179 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1180 | |
| 1181 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1182 | /* |
| 1183 | * Notes on commands: |
| 1184 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1185 | * 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] | 1186 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1187 | * specified, the command does not input or output data, respectively. |
| 1188 | * Parameter/response length is implicit in the structs. Some underlying |
| 1189 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1190 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1191 | * |
| 1192 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1193 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1194 | */ |
| 1195 | |
| 1196 | /*****************************************************************************/ |
| 1197 | /* General / test commands */ |
| 1198 | |
| 1199 | /* |
| 1200 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1201 | * changes. |
| 1202 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1203 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1204 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1205 | /** |
| 1206 | * struct ec_response_proto_version - Response to the proto version command. |
| 1207 | * @version: The protocol version. |
| 1208 | */ |
| 1209 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1210 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1211 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1212 | |
| 1213 | /* |
| 1214 | * Hello. This is a simple command to test the EC is responsive to |
| 1215 | * commands. |
| 1216 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1217 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1218 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1219 | /** |
| 1220 | * struct ec_params_hello - Parameters to the hello command. |
| 1221 | * @in_data: Pass anything here. |
| 1222 | */ |
| 1223 | struct ec_params_hello { |
| 1224 | uint32_t in_data; |
| 1225 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1226 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1227 | /** |
| 1228 | * struct ec_response_hello - Response to the hello command. |
| 1229 | * @out_data: Output will be in_data + 0x01020304. |
| 1230 | */ |
| 1231 | struct ec_response_hello { |
| 1232 | uint32_t out_data; |
| 1233 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1234 | |
| 1235 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1236 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1237 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1238 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1239 | EC_IMAGE_UNKNOWN = 0, |
| 1240 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1241 | EC_IMAGE_RW, |
| 1242 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1243 | EC_IMAGE_RO_B, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1244 | EC_IMAGE_RW_B, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1245 | }; |
| 1246 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1247 | /** |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1248 | * 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] | 1249 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1250 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1251 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1252 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1253 | */ |
| 1254 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1255 | char version_string_ro[32]; |
| 1256 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1257 | char reserved[32]; /* Changed to cros_fwid_ro in version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1258 | uint32_t current_image; |
| 1259 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1260 | |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1261 | /** |
| 1262 | * struct ec_response_get_version_v1 - Response to the v1 get version command. |
| 1263 | * |
| 1264 | * ec_response_get_version_v1 is a strict superset of ec_response_get_version. |
| 1265 | * The v1 response changes the semantics of one field (reserved to cros_fwid_ro) |
| 1266 | * and adds one additional field (cros_fwid_rw). |
| 1267 | * |
| 1268 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1269 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1270 | * @cros_fwid_ro: Null-terminated RO CrOS FWID string. |
| 1271 | * @current_image: One of ec_image. |
| 1272 | * @cros_fwid_rw: Null-terminated RW CrOS FWID string. |
| 1273 | */ |
| 1274 | struct ec_response_get_version_v1 { |
| 1275 | char version_string_ro[32]; |
| 1276 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1277 | char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1278 | uint32_t current_image; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1279 | char cros_fwid_rw[32]; /* Added in version 1 */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1280 | } __ec_align4; |
| 1281 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 1282 | /* Read test - OBSOLETE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1283 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1284 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1285 | /* |
| 1286 | * Get build information |
| 1287 | * |
| 1288 | * Response is null-terminated string. |
| 1289 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1290 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1291 | |
| 1292 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1293 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1294 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1295 | /** |
| 1296 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1297 | * @vendor: Null-terminated string for chip vendor. |
| 1298 | * @name: Null-terminated string for chip name. |
| 1299 | * @revision: Null-terminated string for chip mask version. |
| 1300 | */ |
| 1301 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1302 | char vendor[32]; |
| 1303 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1304 | char revision[32]; |
| 1305 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1306 | |
| 1307 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1308 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1309 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1310 | /** |
| 1311 | * struct ec_response_board_version - Response to the board version command. |
| 1312 | * @board_version: A monotonously incrementing number. |
| 1313 | */ |
| 1314 | struct ec_response_board_version { |
| 1315 | uint16_t board_version; |
| 1316 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1317 | |
| 1318 | /* |
| 1319 | * Read memory-mapped data. |
| 1320 | * |
| 1321 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1322 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1323 | * |
| 1324 | * Response is params.size bytes of data. |
| 1325 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1326 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1327 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1328 | /** |
| 1329 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1330 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1331 | * @size: Size to read in bytes. |
| 1332 | */ |
| 1333 | struct ec_params_read_memmap { |
| 1334 | uint8_t offset; |
| 1335 | uint8_t size; |
| 1336 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1337 | |
| 1338 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1339 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1340 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1341 | /** |
| 1342 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1343 | * @cmd: Command to check. |
| 1344 | */ |
| 1345 | struct ec_params_get_cmd_versions { |
| 1346 | uint8_t cmd; |
| 1347 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1348 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1349 | /** |
| 1350 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1351 | * versions (v1) |
| 1352 | * @cmd: Command to check. |
| 1353 | */ |
| 1354 | struct ec_params_get_cmd_versions_v1 { |
| 1355 | uint16_t cmd; |
| 1356 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1357 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1358 | /** |
| 1359 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1360 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1361 | * a desired version. |
| 1362 | */ |
| 1363 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1364 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1365 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1366 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1367 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1368 | * 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] | 1369 | * on lpc since it has its own out-of-band busy indicator. |
| 1370 | * |
| 1371 | * lpc must read the status from the command register. Attempting this on |
| 1372 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1373 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1374 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1375 | |
| 1376 | /* Avoid using ec_status which is for return values */ |
| 1377 | enum ec_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1378 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1379 | }; |
| 1380 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1381 | /** |
| 1382 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1383 | * command. |
| 1384 | * @flags: Mask of enum ec_comms_status. |
| 1385 | */ |
| 1386 | struct ec_response_get_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1387 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1388 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1389 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1390 | /* Fake a variety of responses, purely for testing purposes. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1391 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1392 | |
| 1393 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1394 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1395 | uint32_t ec_result; |
| 1396 | uint32_t ret_len; |
| 1397 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1398 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1399 | |
| 1400 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1401 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1402 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1403 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1404 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1405 | /* Get protocol information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1406 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1407 | |
| 1408 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1409 | /* 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] | 1410 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1411 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1412 | /** |
| 1413 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1414 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1415 | * version n). |
| 1416 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1417 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1418 | * @flags: see EC_PROTOCOL_INFO_* |
| 1419 | */ |
| 1420 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1421 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1422 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1423 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1424 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1425 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1426 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1427 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1428 | /*****************************************************************************/ |
| 1429 | /* Get/Set miscellaneous values */ |
| 1430 | |
| 1431 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1432 | #define EC_GSV_SET 0x80000000 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1433 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1434 | /* |
| 1435 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1436 | * meaning for an individual command. |
| 1437 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1438 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1439 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1440 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1441 | uint32_t flags; |
| 1442 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1443 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1444 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1445 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1446 | uint32_t flags; |
| 1447 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1448 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1449 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1450 | /* More than one command can use these structs to get/set parameters. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1451 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1452 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1453 | /*****************************************************************************/ |
| 1454 | /* List the features supported by the firmware */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1455 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1456 | |
| 1457 | /* Supported features */ |
| 1458 | enum ec_feature_code { |
| 1459 | /* |
| 1460 | * This image contains a limited set of features. Another image |
| 1461 | * in RW partition may support more features. |
| 1462 | */ |
| 1463 | EC_FEATURE_LIMITED = 0, |
| 1464 | /* |
| 1465 | * Commands for probing/reading/writing/erasing the flash in the |
| 1466 | * EC are present. |
| 1467 | */ |
| 1468 | EC_FEATURE_FLASH = 1, |
| 1469 | /* |
| 1470 | * Can control the fan speed directly. |
| 1471 | */ |
| 1472 | EC_FEATURE_PWM_FAN = 2, |
| 1473 | /* |
| 1474 | * Can control the intensity of the keyboard backlight. |
| 1475 | */ |
| 1476 | EC_FEATURE_PWM_KEYB = 3, |
| 1477 | /* |
| 1478 | * Support Google lightbar, introduced on Pixel. |
| 1479 | */ |
| 1480 | EC_FEATURE_LIGHTBAR = 4, |
| 1481 | /* Control of LEDs */ |
| 1482 | EC_FEATURE_LED = 5, |
| 1483 | /* Exposes an interface to control gyro and sensors. |
| 1484 | * The host goes through the EC to access these sensors. |
| 1485 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1486 | */ |
| 1487 | EC_FEATURE_MOTION_SENSE = 6, |
| 1488 | /* The keyboard is controlled by the EC */ |
| 1489 | EC_FEATURE_KEYB = 7, |
| 1490 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1491 | EC_FEATURE_PSTORE = 8, |
| 1492 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1493 | EC_FEATURE_PORT80 = 9, |
| 1494 | /* |
| 1495 | * Thermal management: include TMP specific commands. |
| 1496 | * Higher level than direct fan control. |
| 1497 | */ |
| 1498 | EC_FEATURE_THERMAL = 10, |
| 1499 | /* Can switch the screen backlight on/off */ |
| 1500 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1501 | /* Can switch the wifi module on/off */ |
| 1502 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1503 | /* Monitor host events, through for example SMI or SCI */ |
| 1504 | EC_FEATURE_HOST_EVENTS = 13, |
| 1505 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1506 | EC_FEATURE_GPIO = 14, |
| 1507 | /* The EC can send i2c messages to downstream devices. */ |
| 1508 | EC_FEATURE_I2C = 15, |
| 1509 | /* Command to control charger are included */ |
| 1510 | EC_FEATURE_CHARGER = 16, |
| 1511 | /* Simple battery support. */ |
| 1512 | EC_FEATURE_BATTERY = 17, |
| 1513 | /* |
| 1514 | * Support Smart battery protocol |
| 1515 | * (Common Smart Battery System Interface Specification) |
| 1516 | */ |
| 1517 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1518 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1519 | EC_FEATURE_HANG_DETECT = 19, |
| 1520 | /* Report power information, for pit only */ |
| 1521 | EC_FEATURE_PMU = 20, |
| 1522 | /* Another Cros EC device is present downstream of this one */ |
| 1523 | EC_FEATURE_SUB_MCU = 21, |
| 1524 | /* Support USB Power delivery (PD) commands */ |
| 1525 | EC_FEATURE_USB_PD = 22, |
| 1526 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1527 | EC_FEATURE_USB_MUX = 23, |
| 1528 | /* Motion Sensor code has an internal software FIFO */ |
| 1529 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1530 | /* Support temporary secure vstore */ |
| 1531 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1532 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1533 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1534 | /* EC has RTC feature that can be controlled by host commands */ |
| 1535 | EC_FEATURE_RTC = 27, |
| 1536 | /* The MCU exposes a Fingerprint sensor */ |
| 1537 | EC_FEATURE_FINGERPRINT = 28, |
| 1538 | /* The MCU exposes a Touchpad */ |
| 1539 | EC_FEATURE_TOUCHPAD = 29, |
| 1540 | /* The MCU has RWSIG task enabled */ |
| 1541 | EC_FEATURE_RWSIG = 30, |
| 1542 | /* EC has device events support */ |
| 1543 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1544 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1545 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1546 | /* EC supports 64-bit host events */ |
| 1547 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1548 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1549 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1550 | /* EC supports CEC commands */ |
| 1551 | EC_FEATURE_CEC = 35, |
| 1552 | /* EC supports tight sensor timestamping. */ |
| 1553 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1554 | /* |
| 1555 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1556 | * setting of threshold by host command using |
| 1557 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1558 | */ |
| 1559 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1560 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1561 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1562 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1563 | * be sent to RO to be precise. |
| 1564 | */ |
| 1565 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1566 | /* The MCU is a System Companion Processor (SCP). */ |
| 1567 | EC_FEATURE_SCP = 39, |
| 1568 | /* The MCU is an Integrated Sensor Hub */ |
| 1569 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1570 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1571 | EC_FEATURE_TYPEC_CMD = 41, |
| 1572 | /* |
| 1573 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1574 | * modes or USB4. |
| 1575 | */ |
| 1576 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1577 | /* |
| 1578 | * The EC will wait for an acknowledge from the AP after setting the |
| 1579 | * mux. |
| 1580 | */ |
| 1581 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1582 | /* |
| 1583 | * The EC supports entering and residing in S4. |
| 1584 | */ |
| 1585 | EC_FEATURE_S4_RESIDENCY = 44, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 1586 | /* |
| 1587 | * The EC supports the AP directing mux sets for the board. |
| 1588 | */ |
| 1589 | EC_FEATURE_TYPEC_AP_MUX_SET = 45, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1590 | /* |
| 1591 | * The EC supports the AP composing VDMs for us to send. |
| 1592 | */ |
| 1593 | EC_FEATURE_TYPEC_AP_VDM_SEND = 46, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1594 | }; |
| 1595 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1596 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1597 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1598 | |
| 1599 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1600 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1601 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1602 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1603 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1604 | /* Get the board's SKU ID from EC */ |
| 1605 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1606 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1607 | /* Set SKU ID from AP */ |
| 1608 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1609 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1610 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1611 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1612 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1613 | |
| 1614 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1615 | /* Flash commands */ |
| 1616 | |
| 1617 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1618 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1619 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1620 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1621 | /** |
| 1622 | * struct ec_response_flash_info - Response to the flash info command. |
| 1623 | * @flash_size: Usable flash size in bytes. |
| 1624 | * @write_block_size: Write block size. Write offset and size must be a |
| 1625 | * multiple of this. |
| 1626 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1627 | * multiple of this. |
| 1628 | * @protect_block_size: Protection block size. Protection offset and size |
| 1629 | * must be a multiple of this. |
| 1630 | * |
| 1631 | * Version 0 returns these fields. |
| 1632 | */ |
| 1633 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1634 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1635 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1636 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1637 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1638 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1639 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1640 | /* |
| 1641 | * Flags for version 1+ flash info command |
| 1642 | * EC flash erases bits to 0 instead of 1. |
| 1643 | */ |
| 1644 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1645 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1646 | /* |
| 1647 | * 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] | 1648 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1649 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1650 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1651 | * chip functionality. |
| 1652 | */ |
| 1653 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1654 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1655 | /** |
| 1656 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1657 | * @flash_size: Usable flash size in bytes. |
| 1658 | * @write_block_size: Write block size. Write offset and size must be a |
| 1659 | * multiple of this. |
| 1660 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1661 | * multiple of this. |
| 1662 | * @protect_block_size: Protection block size. Protection offset and size |
| 1663 | * must be a multiple of this. |
| 1664 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1665 | * size is exactly this and offset is a multiple of this. |
| 1666 | * For example, an EC may have a write buffer which can do |
| 1667 | * half-page operations if data is aligned, and a slower |
| 1668 | * word-at-a-time write mode. |
| 1669 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1670 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1671 | * Version 1 returns the same initial fields as version 0, with additional |
| 1672 | * fields following. |
| 1673 | * |
| 1674 | * 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] | 1675 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1676 | * one. |
| 1677 | * |
| 1678 | * Version 2 supports flash banks of different sizes: |
| 1679 | * The caller specified the number of banks it has preallocated |
| 1680 | * (num_banks_desc) |
| 1681 | * The EC returns the number of banks describing the flash memory. |
| 1682 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1683 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1684 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1685 | /* Version 0 fields; see above for description */ |
| 1686 | uint32_t flash_size; |
| 1687 | uint32_t write_block_size; |
| 1688 | uint32_t erase_block_size; |
| 1689 | uint32_t protect_block_size; |
| 1690 | |
| 1691 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1692 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1693 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 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 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1697 | /* Number of banks to describe */ |
| 1698 | uint16_t num_banks_desc; |
| 1699 | /* Reserved; set 0; ignore on read */ |
| 1700 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1701 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1702 | |
| 1703 | struct ec_flash_bank { |
| 1704 | /* Number of sector is in this bank. */ |
| 1705 | uint16_t count; |
| 1706 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1707 | uint8_t size_exp; |
| 1708 | /* Minimal write size for the sectors in this bank */ |
| 1709 | uint8_t write_size_exp; |
| 1710 | /* Erase size for the sectors in this bank */ |
| 1711 | uint8_t erase_size_exp; |
| 1712 | /* Size for write protection, usually identical to erase size. */ |
| 1713 | uint8_t protect_size_exp; |
| 1714 | /* Reserved; set 0; ignore on read */ |
| 1715 | uint8_t reserved[2]; |
| 1716 | }; |
| 1717 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1718 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1719 | /* Total flash in the EC. */ |
| 1720 | uint32_t flash_size; |
| 1721 | /* Flags; see EC_FLASH_INFO_* */ |
| 1722 | uint32_t flags; |
| 1723 | /* Maximum size to use to send data to write to the EC. */ |
| 1724 | uint32_t write_ideal_size; |
| 1725 | /* Number of banks present in the EC. */ |
| 1726 | uint16_t num_banks_total; |
| 1727 | /* Number of banks described in banks array. */ |
| 1728 | uint16_t num_banks_desc; |
| 1729 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1730 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1731 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1732 | /* |
| 1733 | * Read flash |
| 1734 | * |
| 1735 | * Response is params.size bytes of data. |
| 1736 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1737 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1738 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1739 | /** |
| 1740 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1741 | * @offset: Byte offset to read. |
| 1742 | * @size: Size to read in bytes. |
| 1743 | */ |
| 1744 | struct ec_params_flash_read { |
| 1745 | uint32_t offset; |
| 1746 | uint32_t size; |
| 1747 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1748 | |
| 1749 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1750 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1751 | #define EC_VER_FLASH_WRITE 1 |
| 1752 | |
| 1753 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1754 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1755 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1756 | /** |
| 1757 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1758 | * @offset: Byte offset to write. |
| 1759 | * @size: Size to write in bytes. |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1760 | * @data: Data to write. |
| 1761 | * @data.words32: uint32_t data to write. |
| 1762 | * @data.bytes: uint8_t data to write. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1763 | */ |
| 1764 | struct ec_params_flash_write { |
| 1765 | uint32_t offset; |
| 1766 | uint32_t size; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1767 | /* Followed by data to write. This union allows accessing an |
| 1768 | * underlying buffer as uint32s or uint8s for convenience. |
| 1769 | */ |
| 1770 | union { |
| 1771 | uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1772 | uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1773 | } data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1774 | } __ec_align4; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1775 | BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1776 | |
| 1777 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1778 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1779 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1780 | /** |
| 1781 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1782 | * @offset: Byte offset to erase. |
| 1783 | * @size: Size to erase in bytes. |
| 1784 | */ |
| 1785 | struct ec_params_flash_erase { |
| 1786 | uint32_t offset; |
| 1787 | uint32_t size; |
| 1788 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1789 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1790 | /* |
| 1791 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1792 | * subcommands can returns: |
| 1793 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1794 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1795 | * EC_RES_ERROR : other errors. |
| 1796 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1797 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1798 | * |
| 1799 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1800 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1801 | * the proper result. |
| 1802 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1803 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1804 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1805 | * permitted while erasing. (For instance, STM32F4). |
| 1806 | */ |
| 1807 | enum ec_flash_erase_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1808 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1809 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1810 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1811 | }; |
| 1812 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1813 | /** |
| 1814 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1815 | * @cmd: One of ec_flash_erase_cmd. |
| 1816 | * @reserved: Pad byte; currently always contains 0. |
| 1817 | * @flag: No flags defined yet; set to 0. |
| 1818 | * @params: Same as v0 parameters. |
| 1819 | */ |
| 1820 | struct ec_params_flash_erase_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1821 | uint8_t cmd; |
| 1822 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1823 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1824 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1825 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1826 | |
| 1827 | /* |
| 1828 | * Get/set flash protection. |
| 1829 | * |
| 1830 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1831 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1832 | * some flags require a subsequent hard reset to take effect. Check the |
| 1833 | * returned flags bits to see what actually happened. |
| 1834 | * |
| 1835 | * If mask=0, simply returns the current flags state. |
| 1836 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1837 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1838 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1839 | |
| 1840 | /* Flags for flash protection */ |
| 1841 | /* RO flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1842 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1843 | /* |
| 1844 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1845 | * be changed. |
| 1846 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1847 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1848 | /* Entire flash code protected now, until reboot. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1849 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1850 | /* Flash write protect GPIO is asserted now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1851 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1852 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1853 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1854 | /* |
| 1855 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1856 | * flash which should be protected is not protected. Usually fixed by |
| 1857 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1858 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1859 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1860 | /* Entire flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1861 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1862 | /* RW flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1863 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1864 | /* RW flash code protected now. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1865 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1866 | /* Rollback information flash region protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1867 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1868 | /* Rollback information flash region protected now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1869 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1870 | /* Error - Unknown error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1871 | #define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1872 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1873 | /** |
| 1874 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1875 | * @mask: Bits in flags to apply. |
| 1876 | * @flags: New flags to apply. |
| 1877 | */ |
| 1878 | struct ec_params_flash_protect { |
| 1879 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1880 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1881 | } __ec_align4; |
| 1882 | |
| 1883 | /** |
| 1884 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1885 | * @flags: Current value of flash protect flags. |
| 1886 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1887 | * caller to distinguish between flags which aren't set vs. flags |
| 1888 | * which can't be set on this platform. |
| 1889 | * @writable_flags: Flags which can be changed given the current protection |
| 1890 | * state. |
| 1891 | */ |
| 1892 | struct ec_response_flash_protect { |
| 1893 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1894 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1895 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1896 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1897 | |
| 1898 | /* |
| 1899 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1900 | * write protect. These commands may be reused with version > 0. |
| 1901 | */ |
| 1902 | |
| 1903 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1904 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1905 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1906 | |
| 1907 | enum ec_flash_region { |
| 1908 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1909 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1910 | /* |
| 1911 | * Region which holds active RW image. 'Active' is different from |
| 1912 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1913 | * scheduled to run, active/non-active applies only to RW images (for |
| 1914 | * the same reason 'update' applies only to RW images. It's a state of |
| 1915 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1916 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1917 | * doesn't enter 'running' state but it's still active on a flash. |
| 1918 | */ |
| 1919 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1920 | /* |
| 1921 | * Region which should be write-protected in the factory (a superset of |
| 1922 | * EC_FLASH_REGION_RO) |
| 1923 | */ |
| 1924 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1925 | /* Region which holds updatable (non-active) RW image */ |
| 1926 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1927 | /* Number of regions */ |
| 1928 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1929 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1930 | /* |
| 1931 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1932 | * so the old constant is deprecated. |
| 1933 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1934 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1935 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1936 | /** |
| 1937 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1938 | * command. |
| 1939 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1940 | */ |
| 1941 | struct ec_params_flash_region_info { |
| 1942 | uint32_t region; |
| 1943 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1944 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1945 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1946 | uint32_t offset; |
| 1947 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1948 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1949 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1950 | /* Get SPI flash information */ |
| 1951 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1952 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1953 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1954 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1955 | uint8_t jedec[3]; |
| 1956 | |
| 1957 | /* Pad byte; currently always contains 0 */ |
| 1958 | uint8_t reserved0; |
| 1959 | |
| 1960 | /* Manufacturer / device ID from command 0x90 */ |
| 1961 | uint8_t mfr_dev_id[2]; |
| 1962 | |
| 1963 | /* Status registers from command 0x05 and 0x35 */ |
| 1964 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1965 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1966 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1967 | /* Select flash during flash operations */ |
| 1968 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1969 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1970 | /** |
| 1971 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1972 | * @select: 1 to select flash, 0 to deselect flash |
| 1973 | */ |
| 1974 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1975 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1976 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1977 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1978 | /** |
| 1979 | * Request random numbers to be generated and returned. |
| 1980 | * Can be used to test the random number generator is truly random. |
| 1981 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1982 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1983 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1984 | #define EC_CMD_RAND_NUM 0x001A |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1985 | #define EC_VER_RAND_NUM 0 |
| 1986 | |
| 1987 | struct ec_params_rand_num { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1988 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1989 | } __ec_align4; |
| 1990 | |
| 1991 | struct ec_response_rand_num { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1992 | /** |
| 1993 | * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true |
| 1994 | * size of rand is determined by ec_params_rand_num's num_rand_bytes. |
| 1995 | */ |
| 1996 | uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1997 | } __ec_align1; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1998 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1999 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2000 | /** |
| 2001 | * Get information about the key used to sign the RW firmware. |
| 2002 | * For more details on the fields, see "struct vb21_packed_key". |
| 2003 | */ |
| 2004 | #define EC_CMD_RWSIG_INFO 0x001B |
| 2005 | #define EC_VER_RWSIG_INFO 0 |
| 2006 | |
| 2007 | #define VBOOT2_KEY_ID_BYTES 20 |
| 2008 | |
| 2009 | #ifdef CHROMIUM_EC |
| 2010 | /* Don't force external projects to depend on the vboot headers. */ |
| 2011 | #include "vb21_struct.h" |
| 2012 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 2013 | #endif |
| 2014 | |
| 2015 | struct ec_response_rwsig_info { |
| 2016 | /** |
| 2017 | * Signature algorithm used by the key |
| 2018 | * (enum vb2_signature_algorithm). |
| 2019 | */ |
| 2020 | uint16_t sig_alg; |
| 2021 | |
| 2022 | /** |
| 2023 | * Hash digest algorithm used with the key |
| 2024 | * (enum vb2_hash_algorithm). |
| 2025 | */ |
| 2026 | uint16_t hash_alg; |
| 2027 | |
| 2028 | /** Key version. */ |
| 2029 | uint32_t key_version; |
| 2030 | |
| 2031 | /** Key ID (struct vb2_id). */ |
| 2032 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 2033 | |
| 2034 | uint8_t key_is_valid; |
| 2035 | |
| 2036 | /** Alignment padding. */ |
| 2037 | uint8_t reserved[3]; |
| 2038 | } __ec_align4; |
| 2039 | |
| 2040 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 2041 | |
| 2042 | /** |
| 2043 | * Get information about the system, such as reset flags, locked state, etc. |
| 2044 | */ |
| 2045 | #define EC_CMD_SYSINFO 0x001C |
| 2046 | #define EC_VER_SYSINFO 0 |
| 2047 | |
| 2048 | enum sysinfo_flags { |
| 2049 | SYSTEM_IS_LOCKED = BIT(0), |
| 2050 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 2051 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 2052 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2053 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4), |
| 2054 | /* |
| 2055 | * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is |
| 2056 | * set and cleared when the system shuts down (not when the host event |
| 2057 | * flag is cleared). |
| 2058 | */ |
| 2059 | SYSTEM_IN_MANUAL_RECOVERY = BIT(5), |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2060 | }; |
| 2061 | |
| 2062 | struct ec_response_sysinfo { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2063 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2064 | uint32_t current_image; /**< enum ec_image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2065 | uint32_t flags; /**< enum sysinfo_flags */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2066 | } __ec_align4; |
| 2067 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2068 | /*****************************************************************************/ |
| 2069 | /* PWM commands */ |
| 2070 | |
| 2071 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2072 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2073 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2074 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2075 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2076 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2077 | |
| 2078 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2079 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2080 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2081 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2082 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2083 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2084 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2085 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2086 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2087 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2088 | uint32_t rpm; |
| 2089 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2090 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2091 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2092 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2093 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2094 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2095 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2096 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2097 | uint8_t percent; |
| 2098 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2099 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2100 | |
| 2101 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2102 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2103 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2104 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2105 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2106 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2107 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2108 | |
| 2109 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2110 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2111 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2112 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2113 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2114 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2115 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2116 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2117 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2118 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2119 | uint32_t percent; |
| 2120 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2121 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2122 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2123 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2124 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 2125 | #define EC_PWM_MAX_DUTY 0xffff |
| 2126 | |
| 2127 | enum ec_pwm_type { |
| 2128 | /* All types, indexed by board-specific enum pwm_channel */ |
| 2129 | EC_PWM_TYPE_GENERIC = 0, |
| 2130 | /* Keyboard backlight */ |
| 2131 | EC_PWM_TYPE_KB_LIGHT, |
| 2132 | /* Display backlight */ |
| 2133 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 2134 | EC_PWM_TYPE_COUNT, |
| 2135 | }; |
| 2136 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2137 | struct ec_params_pwm_set_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2138 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 2139 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2140 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2141 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2142 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2143 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2144 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2145 | struct ec_params_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2146 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2147 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2148 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2149 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2150 | struct ec_response_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2151 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2152 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2153 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2154 | /*****************************************************************************/ |
| 2155 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2156 | * 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] | 2157 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 2158 | * into a subcommand. We'll make separate structs for subcommands with |
| 2159 | * different input args, so that we know how much to expect. |
| 2160 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2161 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2162 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2163 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2164 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2165 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2166 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2167 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2168 | |
| 2169 | /* |
| 2170 | * 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] | 2171 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2172 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2173 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2174 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2175 | int32_t google_ramp_up; |
| 2176 | int32_t google_ramp_down; |
| 2177 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2178 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2179 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2180 | int32_t s0s3_ramp_down; |
| 2181 | int32_t s3_sleep_for; |
| 2182 | int32_t s3_ramp_up; |
| 2183 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2184 | |
| 2185 | /* Oscillation */ |
| 2186 | uint8_t new_s0; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2187 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2188 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2189 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2190 | |
| 2191 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2192 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2193 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2194 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2195 | |
| 2196 | /* Battery level thresholds */ |
| 2197 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2198 | |
| 2199 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2200 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2201 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2202 | |
| 2203 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2204 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2205 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2206 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2207 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2208 | /* Timing */ |
| 2209 | int32_t google_ramp_up; |
| 2210 | int32_t google_ramp_down; |
| 2211 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2212 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2213 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2214 | int32_t s0s3_ramp_down; |
| 2215 | int32_t s3_sleep_for; |
| 2216 | int32_t s3_ramp_up; |
| 2217 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2218 | int32_t s5_ramp_up; |
| 2219 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2220 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2221 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2222 | int32_t tap_display_time; |
| 2223 | |
| 2224 | /* Tap-for-battery params */ |
| 2225 | uint8_t tap_pct_red; |
| 2226 | uint8_t tap_pct_green; |
| 2227 | uint8_t tap_seg_min_on; |
| 2228 | uint8_t tap_seg_max_on; |
| 2229 | uint8_t tap_seg_osc; |
| 2230 | uint8_t tap_idx[3]; |
| 2231 | |
| 2232 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2233 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2234 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2235 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2236 | |
| 2237 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2238 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2239 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2240 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* Battery level thresholds */ |
| 2243 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2244 | |
| 2245 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2246 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2247 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2248 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2249 | /* s5: single color pulse on inhibited power-up */ |
| 2250 | uint8_t s5_idx; |
| 2251 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2252 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2253 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2254 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2255 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2256 | /* Lightbar command params v2 |
| 2257 | * crbug.com/467716 |
| 2258 | * |
| 2259 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2260 | * logical groups to make it more manageable ( < 120 bytes). |
| 2261 | * |
| 2262 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2263 | */ |
| 2264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2265 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2266 | /* Timing */ |
| 2267 | int32_t google_ramp_up; |
| 2268 | int32_t google_ramp_down; |
| 2269 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2270 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2271 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2272 | int32_t s0s3_ramp_down; |
| 2273 | int32_t s3_sleep_for; |
| 2274 | int32_t s3_ramp_up; |
| 2275 | int32_t s3_ramp_down; |
| 2276 | int32_t s5_ramp_up; |
| 2277 | int32_t s5_ramp_down; |
| 2278 | int32_t tap_tick_delay; |
| 2279 | int32_t tap_gate_delay; |
| 2280 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2281 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2282 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2283 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2284 | /* Tap-for-battery params */ |
| 2285 | uint8_t tap_pct_red; |
| 2286 | uint8_t tap_pct_green; |
| 2287 | uint8_t tap_seg_min_on; |
| 2288 | uint8_t tap_seg_max_on; |
| 2289 | uint8_t tap_seg_osc; |
| 2290 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2291 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2292 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2293 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2294 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2295 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2296 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2297 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2298 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2299 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2300 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2301 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2302 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2303 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2304 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2305 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2307 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2308 | /* Battery level thresholds */ |
| 2309 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2310 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2311 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2312 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2313 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2314 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2315 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2316 | |
| 2317 | /* s5: single color pulse on inhibited power-up */ |
| 2318 | uint8_t s5_idx; |
| 2319 | |
| 2320 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2321 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2322 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2323 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2324 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2325 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2326 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2327 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2328 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2329 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2330 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2331 | struct ec_params_lightbar { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2332 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2333 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2334 | /* |
| 2335 | * The following commands have no args: |
| 2336 | * |
| 2337 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2338 | * version, get_brightness, get_demo, suspend, resume, |
| 2339 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2340 | * get_params_v2_bright, get_params_v2_thlds, |
| 2341 | * get_params_v2_colors |
| 2342 | * |
| 2343 | * Don't use an empty struct, because C++ hates that. |
| 2344 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2345 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2346 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2347 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2348 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2349 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2350 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2351 | uint8_t ctrl, reg, value; |
| 2352 | } reg; |
| 2353 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2354 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2355 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2356 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2357 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2358 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2359 | uint8_t led; |
| 2360 | } get_rgb; |
| 2361 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2362 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2363 | uint8_t enable; |
| 2364 | } manual_suspend_ctrl; |
| 2365 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2366 | struct lightbar_params_v0 set_params_v0; |
| 2367 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2368 | |
| 2369 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2370 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2371 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2372 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2373 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2374 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2375 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2376 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2377 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2378 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2379 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2380 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2381 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2382 | struct __ec_todo_unpacked { |
| 2383 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2384 | uint8_t reg; |
| 2385 | uint8_t ic0; |
| 2386 | uint8_t ic1; |
| 2387 | } vals[23]; |
| 2388 | } dump; |
| 2389 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2390 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2391 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2392 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2393 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2394 | struct lightbar_params_v0 get_params_v0; |
| 2395 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2396 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2397 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2398 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2399 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2400 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2401 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2402 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2403 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2404 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2405 | uint32_t num; |
| 2406 | uint32_t flags; |
| 2407 | } version; |
| 2408 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2409 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2410 | uint8_t red, green, blue; |
| 2411 | } get_rgb; |
| 2412 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2413 | /* |
| 2414 | * The following commands have no response: |
| 2415 | * |
| 2416 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2417 | * set_params_v0, set_params_v1, set_program, |
| 2418 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2419 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2420 | * set_v2par_thlds, set_v2par_colors |
| 2421 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2422 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2423 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2424 | |
| 2425 | /* Lightbar commands */ |
| 2426 | enum lightbar_command { |
| 2427 | LIGHTBAR_CMD_DUMP = 0, |
| 2428 | LIGHTBAR_CMD_OFF = 1, |
| 2429 | LIGHTBAR_CMD_ON = 2, |
| 2430 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2431 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2432 | LIGHTBAR_CMD_SEQ = 5, |
| 2433 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2434 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2435 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2436 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2437 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2438 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2439 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2440 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2441 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2442 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2443 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2444 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2445 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2446 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2447 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2448 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2449 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2450 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2451 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2452 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2453 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2454 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2455 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2456 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2457 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2458 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2459 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2460 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2461 | LIGHTBAR_NUM_CMDS, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2462 | }; |
| 2463 | |
| 2464 | /*****************************************************************************/ |
| 2465 | /* LED control commands */ |
| 2466 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2467 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2468 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2469 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2470 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2471 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2472 | /* |
| 2473 | * LED to indicate system power state (on or in suspend). |
| 2474 | * May be on power button or on C-panel. |
| 2475 | */ |
| 2476 | EC_LED_ID_POWER_LED, |
| 2477 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2478 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2479 | /* LED to indicate left side */ |
| 2480 | EC_LED_ID_LEFT_LED, |
| 2481 | /* LED to indicate right side */ |
| 2482 | EC_LED_ID_RIGHT_LED, |
| 2483 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2484 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2485 | /* LED to indicate sysrq debug mode. */ |
| 2486 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2487 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2488 | EC_LED_ID_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2489 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2490 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2491 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2492 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2493 | #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] | 2494 | |
| 2495 | enum ec_led_colors { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2496 | EC_LED_COLOR_INVALID = -1, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2497 | EC_LED_COLOR_RED = 0, |
| 2498 | EC_LED_COLOR_GREEN, |
| 2499 | EC_LED_COLOR_BLUE, |
| 2500 | EC_LED_COLOR_YELLOW, |
| 2501 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2502 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2503 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2504 | EC_LED_COLOR_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2505 | }; |
| 2506 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2507 | struct ec_params_led_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2508 | uint8_t led_id; /* Which LED to control */ |
| 2509 | uint8_t flags; /* Control flags */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2510 | |
| 2511 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2512 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2513 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2514 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2515 | /* |
| 2516 | * Available brightness value range. |
| 2517 | * |
| 2518 | * Range 0 means color channel not present. |
| 2519 | * Range 1 means on/off control. |
| 2520 | * Other values means the LED is control by PWM. |
| 2521 | */ |
| 2522 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2523 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2524 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2525 | /*****************************************************************************/ |
| 2526 | /* Verified boot commands */ |
| 2527 | |
| 2528 | /* |
| 2529 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2530 | * reused for other purposes with version > 0. |
| 2531 | */ |
| 2532 | |
| 2533 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2534 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2535 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2536 | struct ec_params_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2537 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2538 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2539 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2540 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2541 | uint32_t offset; /* Offset in flash to hash */ |
| 2542 | uint32_t size; /* Number of bytes to hash */ |
| 2543 | 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] | 2544 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2545 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2546 | struct ec_response_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2547 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2548 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2549 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2550 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2551 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2552 | uint32_t size; /* Number of bytes hashed */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2553 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2554 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2555 | |
| 2556 | enum ec_vboot_hash_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2557 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2558 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2559 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2560 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2561 | }; |
| 2562 | |
| 2563 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2564 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2565 | }; |
| 2566 | |
| 2567 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2568 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2569 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2570 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2571 | }; |
| 2572 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2573 | /* |
| 2574 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2575 | * If one of these is specified, the EC will automatically update offset and |
| 2576 | * size to the correct values for the specified image (RO or RW). |
| 2577 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2578 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2579 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2580 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2581 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2582 | /* |
| 2583 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2584 | * so the old constant is deprecated. |
| 2585 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2586 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2587 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2588 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2589 | /* |
| 2590 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2591 | * different input args, so that we know how much to expect. |
| 2592 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2593 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2594 | |
| 2595 | /* Motion sense commands */ |
| 2596 | enum motionsense_command { |
| 2597 | /* |
| 2598 | * Dump command returns all motion sensor data including motion sense |
| 2599 | * module flags and individual sensor flags. |
| 2600 | */ |
| 2601 | MOTIONSENSE_CMD_DUMP = 0, |
| 2602 | |
| 2603 | /* |
| 2604 | * Info command returns data describing the details of a given sensor, |
| 2605 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2606 | * enum motionsensor_chip. |
| 2607 | */ |
| 2608 | MOTIONSENSE_CMD_INFO = 1, |
| 2609 | |
| 2610 | /* |
| 2611 | * 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] | 2612 | * in milliseconds. |
| 2613 | * It is per sensor, the EC run sample task at the minimum of all |
| 2614 | * sensors EC_RATE. |
| 2615 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2616 | * to collect all the sensor samples. |
| 2617 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2618 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2619 | */ |
| 2620 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2621 | |
| 2622 | /* |
| 2623 | * Sensor ODR command is a setter/getter command for the output data |
| 2624 | * rate of a specific motion sensor in millihertz. |
| 2625 | */ |
| 2626 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2627 | |
| 2628 | /* |
| 2629 | * Sensor range command is a setter/getter command for the range of |
| 2630 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2631 | */ |
| 2632 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2633 | |
| 2634 | /* |
| 2635 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2636 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2637 | * and when the lid angle goes less than this value, keyboard wake is |
| 2638 | * enabled. Note, the lid angle measurement is an approximate, |
| 2639 | * un-calibrated value, hence the wake angle isn't exact. |
| 2640 | */ |
| 2641 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2642 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2643 | /* |
| 2644 | * Returns a single sensor data. |
| 2645 | */ |
| 2646 | MOTIONSENSE_CMD_DATA = 6, |
| 2647 | |
| 2648 | /* |
| 2649 | * Return sensor fifo info. |
| 2650 | */ |
| 2651 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2652 | |
| 2653 | /* |
| 2654 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2655 | * The host can use that element to synchronize its operation. |
| 2656 | */ |
| 2657 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2658 | |
| 2659 | /* |
| 2660 | * Return a portion of the fifo. |
| 2661 | */ |
| 2662 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2663 | |
| 2664 | /* |
| 2665 | * Perform low level calibration. |
| 2666 | * On sensors that support it, ask to do offset calibration. |
| 2667 | */ |
| 2668 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2669 | |
| 2670 | /* |
| 2671 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2672 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2673 | * The offsets can be calculated by the host, or via |
| 2674 | * PERFORM_CALIB command. |
| 2675 | */ |
| 2676 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2677 | |
| 2678 | /* |
| 2679 | * List available activities for a MOTION sensor. |
| 2680 | * Indicates if they are enabled or disabled. |
| 2681 | */ |
| 2682 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2683 | |
| 2684 | /* |
| 2685 | * Activity management |
| 2686 | * Enable/Disable activity recognition. |
| 2687 | */ |
| 2688 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2689 | |
| 2690 | /* |
| 2691 | * Lid Angle |
| 2692 | */ |
| 2693 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2694 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2695 | /* |
| 2696 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2697 | * By default the FIFO does not send interrupt to process the FIFO |
| 2698 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2699 | */ |
| 2700 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2701 | |
| 2702 | /* |
| 2703 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2704 | * to arbitrary values, or will lock to the last read actual values. |
| 2705 | */ |
| 2706 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2707 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2708 | /* Set lid angle for tablet mode detection. */ |
| 2709 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2710 | |
| 2711 | /* |
| 2712 | * Sensor Scale command is a setter/getter command for the calibration |
| 2713 | * scale. |
| 2714 | */ |
| 2715 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2716 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2717 | /* |
| 2718 | * Read the current online calibration values (if available). |
| 2719 | */ |
| 2720 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2721 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2722 | /* |
| 2723 | * Activity management |
| 2724 | * Retrieve current status of given activity. |
| 2725 | */ |
| 2726 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2727 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2728 | /* Number of motionsense sub-commands. */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2729 | MOTIONSENSE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2730 | }; |
| 2731 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2732 | /* List of motion sensor types. */ |
| 2733 | enum motionsensor_type { |
| 2734 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2735 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2736 | MOTIONSENSE_TYPE_MAG = 2, |
| 2737 | MOTIONSENSE_TYPE_PROX = 3, |
| 2738 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2739 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2740 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2741 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2742 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2743 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2744 | }; |
| 2745 | |
| 2746 | /* List of motion sensor locations. */ |
| 2747 | enum motionsensor_location { |
| 2748 | MOTIONSENSE_LOC_BASE = 0, |
| 2749 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2750 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2751 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2752 | }; |
| 2753 | |
| 2754 | /* List of motion sensor chips. */ |
| 2755 | enum motionsensor_chip { |
| 2756 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2757 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2758 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2759 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2760 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2761 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2762 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2763 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2764 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2765 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2766 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2767 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2768 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2769 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2770 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2771 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2772 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2773 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2774 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2775 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2776 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2777 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2778 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2779 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2780 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2781 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2782 | MOTIONSENSE_CHIP_ICM42607 = 26, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2783 | MOTIONSENSE_CHIP_BMA422 = 27, |
| 2784 | MOTIONSENSE_CHIP_BMI323 = 28, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 2785 | MOTIONSENSE_CHIP_BMI220 = 29, |
| 2786 | MOTIONSENSE_CHIP_CM32183 = 30, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2787 | MOTIONSENSE_CHIP_MAX, |
| 2788 | }; |
| 2789 | |
| 2790 | /* List of orientation positions */ |
| 2791 | enum motionsensor_orientation { |
| 2792 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2793 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2794 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2795 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2796 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2797 | }; |
| 2798 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2799 | struct ec_response_activity_data { |
| 2800 | uint8_t activity; /* motionsensor_activity */ |
| 2801 | uint8_t state; |
| 2802 | } __ec_todo_packed; |
| 2803 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2804 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2805 | /* Flags for each sensor. */ |
| 2806 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2807 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2808 | uint8_t sensor_num; |
| 2809 | /* Each sensor is up to 3-axis. */ |
| 2810 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2811 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2812 | /* for sensors using unsigned data */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2813 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2814 | struct __ec_todo_packed { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2815 | uint16_t reserved; |
| 2816 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2817 | }; |
| 2818 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2819 | struct ec_response_activity_data activity_data; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2820 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2821 | }; |
| 2822 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2823 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2824 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2825 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2826 | struct ec_response_online_calibration_data { |
| 2827 | /** The calibration values. */ |
| 2828 | int16_t data[3]; |
| 2829 | }; |
| 2830 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2831 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2832 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2833 | /* Size of the fifo */ |
| 2834 | uint16_t size; |
| 2835 | /* Amount of space used in the fifo */ |
| 2836 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2837 | /* Timestamp recorded in us. |
| 2838 | * aka accurate timestamp when host event was triggered. |
| 2839 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2840 | uint32_t timestamp; |
| 2841 | /* Total amount of vector lost */ |
| 2842 | uint16_t total_lost; |
| 2843 | /* Lost events since the last fifo_info, per sensors */ |
| 2844 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2845 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2846 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2847 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2848 | uint32_t number_data; |
| 2849 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2850 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2851 | |
| 2852 | /* List supported activity recognition */ |
| 2853 | enum motionsensor_activity { |
| 2854 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2855 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2856 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2857 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2858 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2859 | }; |
| 2860 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2861 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2862 | uint8_t sensor_num; |
| 2863 | uint8_t activity; /* one of enum motionsensor_activity */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2864 | uint8_t enable; /* 1: enable, 0: disable */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2865 | uint8_t reserved; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2866 | uint16_t parameters[4]; /* activity dependent parameters */ |
| 2867 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2868 | |
| 2869 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2870 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2871 | |
| 2872 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2873 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2874 | |
| 2875 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2876 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2877 | * data contains time stamp |
| 2878 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2879 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2880 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2881 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2882 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2883 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2884 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2885 | #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7) |
| 2886 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2887 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2888 | * Send this value for the data element to only perform a read. If you |
| 2889 | * send any other value, the EC will interpret it as data to set and will |
| 2890 | * return the actual value set. |
| 2891 | */ |
| 2892 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2893 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2894 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2895 | |
| 2896 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2897 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2898 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2899 | |
| 2900 | /* Default Scale value, factor 1. */ |
| 2901 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2902 | |
| 2903 | #define LID_ANGLE_UNRELIABLE 500 |
| 2904 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2905 | enum motionsense_spoof_mode { |
| 2906 | /* Disable spoof mode. */ |
| 2907 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2908 | |
| 2909 | /* Enable spoof mode, but use provided component values. */ |
| 2910 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2911 | |
| 2912 | /* Enable spoof mode, but use the current sensor values. */ |
| 2913 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2914 | |
| 2915 | /* Query the current spoof mode status for the sensor. */ |
| 2916 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2917 | }; |
| 2918 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2919 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2920 | uint8_t cmd; |
| 2921 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2922 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2923 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2924 | /* |
| 2925 | * Maximal number of sensor the host is expecting. |
| 2926 | * 0 means the host is only interested in the number |
| 2927 | * of sensors controlled by the EC. |
| 2928 | */ |
| 2929 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2930 | } dump; |
| 2931 | |
| 2932 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2933 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2934 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2935 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2936 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 2937 | * kb_wake_angle: angle to wakup AP. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2938 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2939 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2940 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2941 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2942 | /* |
| 2943 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2944 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2945 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2946 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2947 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2948 | |
| 2949 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2950 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2951 | * Allow entering/exiting the calibration mode. |
| 2952 | */ |
| 2953 | struct __ec_todo_unpacked { |
| 2954 | uint8_t sensor_num; |
| 2955 | uint8_t enable; |
| 2956 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2957 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2958 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2959 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2960 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2961 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2962 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2963 | uint8_t sensor_num; |
| 2964 | |
| 2965 | /* Rounding flag, true for round-up, false for down. */ |
| 2966 | uint8_t roundup; |
| 2967 | |
| 2968 | uint16_t reserved; |
| 2969 | |
| 2970 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2971 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2972 | } ec_rate, sensor_odr, sensor_range; |
| 2973 | |
| 2974 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2975 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2976 | uint8_t sensor_num; |
| 2977 | |
| 2978 | /* |
| 2979 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2980 | * the calibration information in the EC. |
| 2981 | * If unset, just retrieve calibration information. |
| 2982 | */ |
| 2983 | uint16_t flags; |
| 2984 | |
| 2985 | /* |
| 2986 | * Temperature at calibration, in units of 0.01 C |
| 2987 | * 0x8000: invalid / unknown. |
| 2988 | * 0x0: 0C |
| 2989 | * 0x7fff: +327.67C |
| 2990 | */ |
| 2991 | int16_t temp; |
| 2992 | |
| 2993 | /* |
| 2994 | * Offset for calibration. |
| 2995 | * Unit: |
| 2996 | * Accelerometer: 1/1024 g |
| 2997 | * Gyro: 1/1024 deg/s |
| 2998 | * Compass: 1/16 uT |
| 2999 | */ |
| 3000 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3001 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3002 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3003 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3004 | struct __ec_todo_packed { |
| 3005 | uint8_t sensor_num; |
| 3006 | |
| 3007 | /* |
| 3008 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 3009 | * the calibration information in the EC. |
| 3010 | * If unset, just retrieve calibration information. |
| 3011 | */ |
| 3012 | uint16_t flags; |
| 3013 | |
| 3014 | /* |
| 3015 | * Temperature at calibration, in units of 0.01 C |
| 3016 | * 0x8000: invalid / unknown. |
| 3017 | * 0x0: 0C |
| 3018 | * 0x7fff: +327.67C |
| 3019 | */ |
| 3020 | int16_t temp; |
| 3021 | |
| 3022 | /* |
| 3023 | * Scale for calibration: |
| 3024 | * By default scale is 1, it is encoded on 16bits: |
| 3025 | * 1 = BIT(15) |
| 3026 | * ~2 = 0xFFFF |
| 3027 | * ~0 = 0. |
| 3028 | */ |
| 3029 | uint16_t scale[3]; |
| 3030 | } sensor_scale; |
| 3031 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3032 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3033 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3034 | |
| 3035 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3036 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3037 | /* |
| 3038 | * Number of expected vector to return. |
| 3039 | * EC may return less or 0 if none available. |
| 3040 | */ |
| 3041 | uint32_t max_data_vector; |
| 3042 | } fifo_read; |
| 3043 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3044 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3045 | struct ec_motion_sense_activity set_activity; |
| 3046 | |
| 3047 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3048 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3049 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3050 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 3051 | struct __ec_todo_unpacked { |
| 3052 | /* |
| 3053 | * 1: enable, 0 disable fifo, |
| 3054 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 3055 | */ |
| 3056 | int8_t enable; |
| 3057 | } fifo_int_enable; |
| 3058 | |
| 3059 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 3060 | struct __ec_todo_packed { |
| 3061 | uint8_t sensor_id; |
| 3062 | |
| 3063 | /* See enum motionsense_spoof_mode. */ |
| 3064 | uint8_t spoof_enable; |
| 3065 | |
| 3066 | /* Ignored, used for alignment. */ |
| 3067 | uint8_t reserved; |
| 3068 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3069 | union { |
| 3070 | /* Individual component values to spoof. */ |
| 3071 | int16_t components[3]; |
| 3072 | |
| 3073 | /* Used when spoofing an activity */ |
| 3074 | struct { |
| 3075 | /* enum motionsensor_activity */ |
| 3076 | uint8_t activity_num; |
| 3077 | |
| 3078 | /* spoof activity state */ |
| 3079 | uint8_t activity_state; |
| 3080 | }; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3081 | } __ec_todo_packed; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3082 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3083 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3084 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3085 | struct __ec_todo_unpacked { |
| 3086 | /* |
| 3087 | * Lid angle threshold for switching between tablet and |
| 3088 | * clamshell mode. |
| 3089 | */ |
| 3090 | int16_t lid_angle; |
| 3091 | |
| 3092 | /* |
| 3093 | * Hysteresis degree to prevent fluctuations between |
| 3094 | * clamshell and tablet mode if lid angle keeps |
| 3095 | * changing around the threshold. Lid motion driver will |
| 3096 | * use lid_angle + hys_degree to trigger tablet mode and |
| 3097 | * lid_angle - hys_degree to trigger clamshell mode. |
| 3098 | */ |
| 3099 | int16_t hys_degree; |
| 3100 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3101 | |
| 3102 | /* |
| 3103 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 3104 | * Allow reading a single sensor's online calibration value. |
| 3105 | */ |
| 3106 | struct __ec_todo_unpacked { |
| 3107 | uint8_t sensor_num; |
| 3108 | } online_calib_read; |
| 3109 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3110 | /* |
| 3111 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 3112 | */ |
| 3113 | struct __ec_todo_unpacked { |
| 3114 | uint8_t sensor_num; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3115 | uint8_t activity; /* enum motionsensor_activity */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3116 | } get_activity; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3117 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3118 | } __ec_todo_packed; |
| 3119 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3120 | enum motion_sense_cmd_info_flags { |
| 3121 | /* The sensor supports online calibration */ |
| 3122 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 3123 | }; |
| 3124 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3125 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3126 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3127 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3128 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3129 | /* Flags representing the motion sensor module. */ |
| 3130 | uint8_t module_flags; |
| 3131 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3132 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3133 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3134 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3135 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3136 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3137 | * for holding all the data. |
| 3138 | */ |
| 3139 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3140 | } dump; |
| 3141 | |
| 3142 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3143 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3144 | /* Should be element of enum motionsensor_type. */ |
| 3145 | uint8_t type; |
| 3146 | |
| 3147 | /* Should be element of enum motionsensor_location. */ |
| 3148 | uint8_t location; |
| 3149 | |
| 3150 | /* Should be element of enum motionsensor_chip. */ |
| 3151 | uint8_t chip; |
| 3152 | } info; |
| 3153 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3154 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 3155 | struct __ec_todo_unpacked { |
| 3156 | /* Should be element of enum motionsensor_type. */ |
| 3157 | uint8_t type; |
| 3158 | |
| 3159 | /* Should be element of enum motionsensor_location. */ |
| 3160 | uint8_t location; |
| 3161 | |
| 3162 | /* Should be element of enum motionsensor_chip. */ |
| 3163 | uint8_t chip; |
| 3164 | |
| 3165 | /* Minimum sensor sampling frequency */ |
| 3166 | uint32_t min_frequency; |
| 3167 | |
| 3168 | /* Maximum sensor sampling frequency */ |
| 3169 | uint32_t max_frequency; |
| 3170 | |
| 3171 | /* Max number of sensor events that could be in fifo */ |
| 3172 | uint32_t fifo_max_event_count; |
| 3173 | } info_3; |
| 3174 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3175 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3176 | struct __ec_align4 { |
| 3177 | /* Should be element of enum motionsensor_type. */ |
| 3178 | uint8_t type; |
| 3179 | |
| 3180 | /* Should be element of enum motionsensor_location. */ |
| 3181 | uint8_t location; |
| 3182 | |
| 3183 | /* Should be element of enum motionsensor_chip. */ |
| 3184 | uint8_t chip; |
| 3185 | |
| 3186 | /* Minimum sensor sampling frequency */ |
| 3187 | uint32_t min_frequency; |
| 3188 | |
| 3189 | /* Maximum sensor sampling frequency */ |
| 3190 | uint32_t max_frequency; |
| 3191 | |
| 3192 | /* Max number of sensor events that could be in fifo */ |
| 3193 | uint32_t fifo_max_event_count; |
| 3194 | |
| 3195 | /* |
| 3196 | * Should be elements of |
| 3197 | * enum motion_sense_cmd_info_flags |
| 3198 | */ |
| 3199 | uint32_t flags; |
| 3200 | } info_4; |
| 3201 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3202 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3203 | struct ec_response_motion_sensor_data data; |
| 3204 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3205 | /* |
| 3206 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3207 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3208 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3209 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3210 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3211 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3212 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3213 | /* Current value of the parameter queried. */ |
| 3214 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3215 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3216 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3217 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3218 | /* |
| 3219 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3220 | * PERFORM_CALIB. |
| 3221 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3222 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3223 | int16_t temp; |
| 3224 | int16_t offset[3]; |
| 3225 | } sensor_offset, perform_calib; |
| 3226 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3227 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3228 | struct __ec_todo_unpacked { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3229 | int16_t temp; |
| 3230 | uint16_t scale[3]; |
| 3231 | } sensor_scale; |
| 3232 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3233 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3234 | |
| 3235 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3236 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3237 | struct ec_response_online_calibration_data online_calib_read; |
| 3238 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3239 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3240 | uint16_t reserved; |
| 3241 | uint32_t enabled; |
| 3242 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3243 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3244 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3245 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3246 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3247 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3248 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3249 | /* |
| 3250 | * Angle between 0 and 360 degree if available, |
| 3251 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3252 | */ |
| 3253 | uint16_t value; |
| 3254 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3255 | |
| 3256 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3257 | struct __ec_todo_unpacked { |
| 3258 | /* |
| 3259 | * Lid angle threshold for switching between tablet and |
| 3260 | * clamshell mode. |
| 3261 | */ |
| 3262 | uint16_t lid_angle; |
| 3263 | |
| 3264 | /* Hysteresis degree. */ |
| 3265 | uint16_t hys_degree; |
| 3266 | } tablet_mode_threshold; |
| 3267 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3268 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3269 | struct __ec_todo_unpacked { |
| 3270 | uint8_t state; |
| 3271 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3272 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3273 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3274 | |
| 3275 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3276 | /* Force lid open command */ |
| 3277 | |
| 3278 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3279 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3280 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3281 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3282 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3283 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3284 | |
| 3285 | /*****************************************************************************/ |
| 3286 | /* Configure the behavior of the power button */ |
| 3287 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3288 | |
| 3289 | enum ec_config_power_button_flags { |
| 3290 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3291 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3292 | }; |
| 3293 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3294 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3295 | /* See enum ec_config_power_button_flags */ |
| 3296 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3297 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3298 | |
| 3299 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3300 | /* USB charging control commands */ |
| 3301 | |
| 3302 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3303 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3304 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3305 | enum usb_charge_mode { |
| 3306 | /* Disable USB port. */ |
| 3307 | USB_CHARGE_MODE_DISABLED, |
| 3308 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3309 | USB_CHARGE_MODE_SDP2, |
| 3310 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3311 | USB_CHARGE_MODE_CDP, |
| 3312 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3313 | USB_CHARGE_MODE_DCP_SHORT, |
| 3314 | /* Enable USB port (for dumb ports). */ |
| 3315 | USB_CHARGE_MODE_ENABLED, |
| 3316 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3317 | USB_CHARGE_MODE_DEFAULT, |
| 3318 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3319 | USB_CHARGE_MODE_COUNT, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3320 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3321 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3322 | enum usb_suspend_charge { |
| 3323 | /* Enable charging in suspend */ |
| 3324 | USB_ALLOW_SUSPEND_CHARGE, |
| 3325 | /* Disable charging in suspend */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3326 | USB_DISALLOW_SUSPEND_CHARGE, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3327 | }; |
| 3328 | |
| 3329 | struct ec_params_usb_charge_set_mode { |
| 3330 | uint8_t usb_port_id; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3331 | uint8_t mode : 7; /* enum usb_charge_mode */ |
| 3332 | uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3333 | } __ec_align1; |
| 3334 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3335 | /*****************************************************************************/ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3336 | /* Tablet mode commands */ |
| 3337 | |
| 3338 | /* Set tablet mode */ |
| 3339 | #define EC_CMD_SET_TABLET_MODE 0x0031 |
| 3340 | |
| 3341 | enum tablet_mode_override { |
| 3342 | TABLET_MODE_DEFAULT, |
| 3343 | TABLET_MODE_FORCE_TABLET, |
| 3344 | TABLET_MODE_FORCE_CLAMSHELL, |
| 3345 | }; |
| 3346 | |
| 3347 | struct ec_params_set_tablet_mode { |
| 3348 | uint8_t tablet_mode; /* enum tablet_mode_override */ |
| 3349 | } __ec_align1; |
| 3350 | |
| 3351 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3352 | /* Persistent storage for host */ |
| 3353 | |
| 3354 | /* Maximum bytes that can be read/written in a single command */ |
| 3355 | #define EC_PSTORE_SIZE_MAX 64 |
| 3356 | |
| 3357 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3358 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3359 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3360 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3361 | /* Persistent storage size, in bytes */ |
| 3362 | uint32_t pstore_size; |
| 3363 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3364 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3365 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3366 | |
| 3367 | /* |
| 3368 | * Read persistent storage |
| 3369 | * |
| 3370 | * Response is params.size bytes of data. |
| 3371 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3372 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3373 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3374 | struct ec_params_pstore_read { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3375 | uint32_t offset; /* Byte offset to read */ |
| 3376 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3377 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3378 | |
| 3379 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3380 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3381 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3382 | struct ec_params_pstore_write { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3383 | uint32_t offset; /* Byte offset to write */ |
| 3384 | uint32_t size; /* Size to write in bytes */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3385 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3386 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3387 | |
| 3388 | /*****************************************************************************/ |
| 3389 | /* Real-time clock */ |
| 3390 | |
| 3391 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3392 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3393 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3394 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3395 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3396 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3397 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3398 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3399 | |
| 3400 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3401 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3402 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3403 | |
| 3404 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3405 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3406 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3407 | |
| 3408 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3409 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3410 | |
| 3411 | /*****************************************************************************/ |
| 3412 | /* Port80 log access */ |
| 3413 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3414 | /* Maximum entries that can be read/written in a single command */ |
| 3415 | #define EC_PORT80_SIZE_MAX 32 |
| 3416 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3417 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3418 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3419 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3420 | |
| 3421 | enum ec_port80_subcmd { |
| 3422 | EC_PORT80_GET_INFO = 0, |
| 3423 | EC_PORT80_READ_BUFFER, |
| 3424 | }; |
| 3425 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3426 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3427 | uint16_t subcmd; |
| 3428 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3429 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3430 | uint32_t offset; |
| 3431 | uint32_t num_entries; |
| 3432 | } read_buffer; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3433 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3434 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3435 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3436 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3437 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3438 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3439 | uint32_t writes; |
| 3440 | uint32_t history_size; |
| 3441 | uint32_t last_boot; |
| 3442 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3443 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3444 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3445 | } data; |
| 3446 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3447 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3448 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3449 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3450 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3451 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3452 | |
| 3453 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3454 | /* Temporary secure storage for host verified boot use */ |
| 3455 | |
| 3456 | /* Number of bytes in a vstore slot */ |
| 3457 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3458 | |
| 3459 | /* Maximum number of vstore slots */ |
| 3460 | #define EC_VSTORE_SLOT_MAX 32 |
| 3461 | |
| 3462 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3463 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3464 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3465 | /* Indicates which slots are locked */ |
| 3466 | uint32_t slot_locked; |
| 3467 | /* Total number of slots available */ |
| 3468 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3469 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3470 | |
| 3471 | /* |
| 3472 | * Read temporary secure storage |
| 3473 | * |
| 3474 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3475 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3476 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3477 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3478 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3479 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3480 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3481 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3482 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3483 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3484 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3485 | |
| 3486 | /* |
| 3487 | * Write temporary secure storage and lock it. |
| 3488 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3489 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3490 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3491 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3492 | uint8_t slot; /* Slot to write to */ |
| 3493 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3494 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3495 | |
| 3496 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3497 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3498 | * reuse the command number, but the data and behavior is incompatible. |
| 3499 | * Version 0 is what originally shipped on Link. |
| 3500 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3501 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3502 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3503 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3504 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3505 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3506 | /* The version 0 structs are opaque. You have to know what they are for |
| 3507 | * the get/set commands to make any sense. |
| 3508 | */ |
| 3509 | |
| 3510 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3511 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3512 | uint8_t sensor_type; |
| 3513 | uint8_t threshold_id; |
| 3514 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3515 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3516 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3517 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3518 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3519 | uint8_t sensor_type; |
| 3520 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3521 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3522 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3523 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3524 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3525 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3526 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3527 | /* The version 1 structs are visible. */ |
| 3528 | enum ec_temp_thresholds { |
| 3529 | EC_TEMP_THRESH_WARN = 0, |
| 3530 | EC_TEMP_THRESH_HIGH, |
| 3531 | EC_TEMP_THRESH_HALT, |
| 3532 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3533 | EC_TEMP_THRESH_COUNT, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3534 | }; |
| 3535 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3536 | /* |
| 3537 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3538 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3539 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3540 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3541 | * hysteresis. |
| 3542 | * For example, |
| 3543 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3544 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3545 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3546 | * temperature <= 299 K. |
| 3547 | * |
| 3548 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3549 | * For example, |
| 3550 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3551 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3552 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3553 | * temperature <= 294 K. |
| 3554 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3555 | * Note that this structure is a sub-structure of |
| 3556 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3557 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3558 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3559 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3560 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3561 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3562 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3563 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3564 | |
| 3565 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3566 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3567 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3568 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3569 | /* This returns a struct ec_thermal_config */ |
| 3570 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3571 | /* |
| 3572 | * Version 1 - set config for one sensor. |
| 3573 | * Use read-modify-write for best results! |
| 3574 | */ |
| 3575 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3576 | uint32_t sensor_num; |
| 3577 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3578 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3579 | /* This returns no data */ |
| 3580 | |
| 3581 | /****************************************************************************/ |
| 3582 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3583 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3584 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3585 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3586 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3587 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3588 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3589 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3590 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3591 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3592 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3593 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3594 | |
| 3595 | /* |
| 3596 | * The original TMP006 calibration only needed four params, but now we need |
| 3597 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3598 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3599 | * and how many params it requires. That way we can change the EC code without |
| 3600 | * needing to update this file. We can also use a different algorithm on each |
| 3601 | * sensor. |
| 3602 | */ |
| 3603 | |
| 3604 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3605 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3606 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3607 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3608 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3609 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3610 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3611 | float s0; |
| 3612 | float b0; |
| 3613 | float b1; |
| 3614 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3615 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3616 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3617 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3618 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3619 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3620 | float s0; |
| 3621 | float b0; |
| 3622 | float b1; |
| 3623 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3624 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3625 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3626 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3627 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3628 | uint8_t algorithm; |
| 3629 | uint8_t num_params; |
| 3630 | uint8_t reserved[2]; |
| 3631 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3632 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3633 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3634 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3635 | uint8_t index; |
| 3636 | uint8_t algorithm; |
| 3637 | uint8_t num_params; |
| 3638 | uint8_t reserved; |
| 3639 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3640 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3641 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3642 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3643 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3644 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3645 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3646 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3647 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3649 | struct ec_response_tmp006_get_raw { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3650 | int32_t t; /* In 1/100 K */ |
| 3651 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3652 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3653 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3654 | /*****************************************************************************/ |
| 3655 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3656 | |
| 3657 | /* |
| 3658 | * Read key state |
| 3659 | * |
| 3660 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3661 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3662 | * |
| 3663 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3664 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3665 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3666 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3667 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3668 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3669 | /* |
| 3670 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3671 | */ |
| 3672 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3673 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3674 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3675 | uint32_t rows; |
| 3676 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3677 | /* Formerly "switches", which was 0. */ |
| 3678 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3679 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3680 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3681 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3682 | uint8_t info_type; |
| 3683 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3684 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3685 | |
| 3686 | enum ec_mkbp_info_type { |
| 3687 | /* |
| 3688 | * Info about the keyboard matrix: number of rows and columns. |
| 3689 | * |
| 3690 | * Returns struct ec_response_mkbp_info. |
| 3691 | */ |
| 3692 | EC_MKBP_INFO_KBD = 0, |
| 3693 | |
| 3694 | /* |
| 3695 | * For buttons and switches, info about which specifically are |
| 3696 | * supported. event_type must be set to one of the values in enum |
| 3697 | * ec_mkbp_event. |
| 3698 | * |
| 3699 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3700 | * bitmask indicating which buttons or switches are present. See the |
| 3701 | * bit inidices below. |
| 3702 | */ |
| 3703 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3704 | |
| 3705 | /* |
| 3706 | * Instantaneous state of buttons and switches. |
| 3707 | * |
| 3708 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3709 | * |
| 3710 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3711 | * indicating the current state of the keyboard matrix. |
| 3712 | * |
| 3713 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3714 | * event state. |
| 3715 | * |
| 3716 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3717 | * state of supported buttons. |
| 3718 | * |
| 3719 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3720 | * state of supported switches. |
| 3721 | */ |
| 3722 | EC_MKBP_INFO_CURRENT = 2, |
| 3723 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3724 | |
| 3725 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3726 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3727 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3728 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3729 | uint8_t col; |
| 3730 | uint8_t row; |
| 3731 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3732 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3733 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3734 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3735 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3736 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3737 | |
| 3738 | /* flags */ |
| 3739 | enum mkbp_config_flags { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3740 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3741 | }; |
| 3742 | |
| 3743 | enum mkbp_config_valid { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3744 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3745 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3746 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3747 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3748 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3749 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3750 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3751 | }; |
| 3752 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3753 | /* |
| 3754 | * Configuration for our key scanning algorithm. |
| 3755 | * |
| 3756 | * Note that this is used as a sub-structure of |
| 3757 | * ec_{params/response}_mkbp_get_config. |
| 3758 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3759 | struct ec_mkbp_config { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3760 | uint32_t valid_mask; /* valid fields */ |
| 3761 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3762 | uint8_t valid_flags; /* which flags are valid */ |
| 3763 | uint16_t scan_period_us; /* period between start of scans */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3764 | /* revert to interrupt mode after no activity for this long */ |
| 3765 | uint32_t poll_timeout_us; |
| 3766 | /* |
| 3767 | * minimum post-scan relax time. Once we finish a scan we check |
| 3768 | * the time until we are due to start the next one. If this time is |
| 3769 | * shorter this field, we use this instead. |
| 3770 | */ |
| 3771 | uint16_t min_post_scan_delay_us; |
| 3772 | /* delay between setting up output and waiting for it to settle */ |
| 3773 | uint16_t output_settle_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3774 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3775 | uint16_t debounce_up_us; /* time for debounce on key up */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3776 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3777 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3778 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3779 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3780 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3781 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3782 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3784 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3785 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3786 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3787 | |
| 3788 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3789 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3790 | |
| 3791 | enum ec_keyscan_seq_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3792 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3793 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3794 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3795 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3796 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3797 | }; |
| 3798 | |
| 3799 | enum ec_collect_flags { |
| 3800 | /* |
| 3801 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3802 | * scans may be skipped. |
| 3803 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3804 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3805 | }; |
| 3806 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3807 | struct ec_collect_item { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3808 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3809 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3810 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3811 | struct ec_params_keyscan_seq_ctrl { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3812 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3813 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3814 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3815 | uint8_t active; /* still active */ |
| 3816 | uint8_t num_items; /* number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3817 | /* Current item being presented */ |
| 3818 | uint8_t cur_item; |
| 3819 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3820 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3821 | /* |
| 3822 | * Absolute time for this scan, measured from the |
| 3823 | * start of the sequence. |
| 3824 | */ |
| 3825 | uint32_t time_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3826 | uint8_t scan[0]; /* keyscan data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3827 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3828 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3829 | uint8_t start_item; /* First item to return */ |
| 3830 | uint8_t num_items; /* Number of items to return */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3831 | } collect; |
| 3832 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3833 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3834 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3835 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3836 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3837 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3838 | uint8_t num_items; /* Number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3839 | /* Data for each item */ |
| 3840 | struct ec_collect_item item[0]; |
| 3841 | } collect; |
| 3842 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3843 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3844 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3845 | /* |
| 3846 | * Get the next pending MKBP event. |
| 3847 | * |
| 3848 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3849 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3850 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3852 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3853 | |
| 3854 | /* |
| 3855 | * We use the most significant bit of the event type to indicate to the host |
| 3856 | * that the EC has more MKBP events available to provide. |
| 3857 | */ |
| 3858 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3859 | |
| 3860 | /* The mask to apply to get the raw event type */ |
| 3861 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3862 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3863 | enum ec_mkbp_event { |
| 3864 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3865 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3866 | |
| 3867 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3868 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3869 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3870 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3871 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3872 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3873 | /* The state of the non-matrixed buttons have changed. */ |
| 3874 | EC_MKBP_EVENT_BUTTON = 3, |
| 3875 | |
| 3876 | /* The state of the switches have changed. */ |
| 3877 | EC_MKBP_EVENT_SWITCH = 4, |
| 3878 | |
| 3879 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3880 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3881 | |
| 3882 | /* |
| 3883 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3884 | * corresponding to the key to be pressed. |
| 3885 | */ |
| 3886 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3887 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3888 | /* |
| 3889 | * New 64-bit host event. |
| 3890 | * The event data is 8 bytes of host event flags. |
| 3891 | */ |
| 3892 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3893 | |
| 3894 | /* Notify the AP that something happened on CEC */ |
| 3895 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3896 | |
| 3897 | /* Send an incoming CEC message to the AP */ |
| 3898 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3899 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3900 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3901 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3902 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3903 | /* New online calibration values are available. */ |
| 3904 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3905 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 3906 | /* Peripheral device charger event */ |
| 3907 | EC_MKBP_EVENT_PCHG = 12, |
| 3908 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3909 | /* Number of MKBP events */ |
| 3910 | EC_MKBP_EVENT_COUNT, |
| 3911 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3912 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3913 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3914 | /* clang-format off */ |
| 3915 | #define EC_MKBP_EVENT_TEXT \ |
| 3916 | { \ |
| 3917 | [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \ |
| 3918 | [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \ |
| 3919 | [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \ |
| 3920 | [EC_MKBP_EVENT_BUTTON] = "BUTTON", \ |
| 3921 | [EC_MKBP_EVENT_SWITCH] = "SWITCH", \ |
| 3922 | [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \ |
| 3923 | [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \ |
| 3924 | [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \ |
| 3925 | [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \ |
| 3926 | [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \ |
| 3927 | [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \ |
| 3928 | [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \ |
| 3929 | [EC_MKBP_EVENT_PCHG] = "PCHG", \ |
| 3930 | } |
| 3931 | /* clang-format on */ |
| 3932 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3933 | union __ec_align_offset1 ec_response_get_next_data { |
| 3934 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3935 | |
| 3936 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3937 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3938 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3939 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3940 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3941 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3942 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3943 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3944 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3945 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3946 | uint32_t buttons; |
| 3947 | |
| 3948 | uint32_t switches; |
| 3949 | |
| 3950 | uint32_t fp_events; |
| 3951 | |
| 3952 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3953 | |
| 3954 | /* CEC events from enum mkbp_cec_event */ |
| 3955 | uint32_t cec_events; |
| 3956 | }; |
| 3957 | |
| 3958 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3959 | uint8_t key_matrix[16]; |
| 3960 | |
| 3961 | /* Unaligned */ |
| 3962 | uint32_t host_event; |
| 3963 | uint64_t host_event64; |
| 3964 | |
| 3965 | struct __ec_todo_unpacked { |
| 3966 | /* For aligning the fifo_info */ |
| 3967 | uint8_t reserved[3]; |
| 3968 | struct ec_response_motion_sense_fifo_info info; |
| 3969 | } sensor_fifo; |
| 3970 | |
| 3971 | uint32_t buttons; |
| 3972 | |
| 3973 | uint32_t switches; |
| 3974 | |
| 3975 | uint32_t fp_events; |
| 3976 | |
| 3977 | uint32_t sysrq; |
| 3978 | |
| 3979 | /* CEC events from enum mkbp_cec_event */ |
| 3980 | uint32_t cec_events; |
| 3981 | |
| 3982 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3983 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3984 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3985 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3986 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3987 | uint8_t event_type; |
| 3988 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3989 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3990 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3991 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3992 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3993 | uint8_t event_type; |
| 3994 | /* Followed by event data if any */ |
| 3995 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3996 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3997 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3998 | /* Bit indices for buttons and switches.*/ |
| 3999 | /* Buttons */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4000 | #define EC_MKBP_POWER_BUTTON 0 |
| 4001 | #define EC_MKBP_VOL_UP 1 |
| 4002 | #define EC_MKBP_VOL_DOWN 2 |
| 4003 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4004 | |
| 4005 | /* Switches */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4006 | #define EC_MKBP_LID_OPEN 0 |
| 4007 | #define EC_MKBP_TABLET_MODE 1 |
| 4008 | #define EC_MKBP_BASE_ATTACHED 2 |
| 4009 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4010 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4011 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4012 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4013 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4014 | struct ec_response_keyboard_factory_test { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4015 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4016 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4017 | |
| 4018 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4019 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF) |
| 4020 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4021 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4022 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \ |
| 4023 | (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4024 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 4025 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4026 | #define EC_MKBP_FP_MATCH_IDX(fpe) \ |
| 4027 | (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
| 4028 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 4029 | #define EC_MKBP_FP_MATCH BIT(28) |
| 4030 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 4031 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 4032 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4033 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4034 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 4035 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 4036 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 4037 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 4038 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4039 | /* Can be used to detect if image was usable for enrollment or not. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4040 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4041 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4042 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 4043 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
| 4044 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
| 4045 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 4046 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 4047 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 4048 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4049 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 4050 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4051 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 4052 | enum ec_mkbp_event_mask_action { |
| 4053 | /* Retrieve the value of a wake mask. */ |
| 4054 | GET_WAKE_MASK = 0, |
| 4055 | |
| 4056 | /* Set the value of a wake mask. */ |
| 4057 | SET_WAKE_MASK, |
| 4058 | }; |
| 4059 | |
| 4060 | enum ec_mkbp_mask_type { |
| 4061 | /* |
| 4062 | * These are host events sent via MKBP. |
| 4063 | * |
| 4064 | * Some examples are: |
| 4065 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 4066 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 4067 | * |
| 4068 | * The only things that should be in this mask are: |
| 4069 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 4070 | */ |
| 4071 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 4072 | |
| 4073 | /* |
| 4074 | * These are MKBP events. Some examples are: |
| 4075 | * |
| 4076 | * EC_MKBP_EVENT_KEY_MATRIX |
| 4077 | * EC_MKBP_EVENT_SWITCH |
| 4078 | * |
| 4079 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 4080 | */ |
| 4081 | EC_MKBP_EVENT_WAKE_MASK, |
| 4082 | }; |
| 4083 | |
| 4084 | struct ec_params_mkbp_event_wake_mask { |
| 4085 | /* One of enum ec_mkbp_event_mask_action */ |
| 4086 | uint8_t action; |
| 4087 | |
| 4088 | /* |
| 4089 | * Which MKBP mask are you interested in acting upon? This is one of |
| 4090 | * ec_mkbp_mask_type. |
| 4091 | */ |
| 4092 | uint8_t mask_type; |
| 4093 | |
| 4094 | /* If setting a new wake mask, this contains the mask to set. */ |
| 4095 | uint32_t new_wake_mask; |
| 4096 | }; |
| 4097 | |
| 4098 | struct ec_response_mkbp_event_wake_mask { |
| 4099 | uint32_t wake_mask; |
| 4100 | }; |
| 4101 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4102 | /*****************************************************************************/ |
| 4103 | /* Temperature sensor commands */ |
| 4104 | |
| 4105 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4106 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4107 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4108 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4109 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4110 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4111 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4112 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4113 | char sensor_name[32]; |
| 4114 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4115 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4116 | |
| 4117 | /*****************************************************************************/ |
| 4118 | |
| 4119 | /* |
| 4120 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 4121 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 4122 | * below. |
| 4123 | */ |
| 4124 | |
| 4125 | /*****************************************************************************/ |
| 4126 | /* Host event commands */ |
| 4127 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4128 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4129 | /* |
| 4130 | * Host event mask params and response structures, shared by all of the host |
| 4131 | * event commands below. |
| 4132 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4133 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4134 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4135 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4136 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4137 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4138 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4139 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4140 | |
| 4141 | /* These all use ec_response_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4142 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 4143 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 4144 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4145 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4146 | |
| 4147 | /* These all use ec_params_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4148 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 4149 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 4150 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4151 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4152 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4153 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4154 | /* |
| 4155 | * Unified host event programming interface - Should be used by newer versions |
| 4156 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4157 | * |
| 4158 | * EC returns: |
| 4159 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 4160 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4161 | */ |
| 4162 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4163 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4164 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 4165 | uint8_t action; |
| 4166 | |
| 4167 | /* |
| 4168 | * Mask type that the host requested the action on - one of |
| 4169 | * enum ec_host_event_mask_type. |
| 4170 | */ |
| 4171 | uint8_t mask_type; |
| 4172 | |
| 4173 | /* Set to 0, ignore on read */ |
| 4174 | uint16_t reserved; |
| 4175 | |
| 4176 | /* Value to be used in case of set operations. */ |
| 4177 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4178 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4179 | |
| 4180 | /* |
| 4181 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 4182 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 4183 | */ |
| 4184 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4185 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4186 | /* Mask value in case of get operation */ |
| 4187 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4188 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4189 | |
| 4190 | enum ec_host_event_action { |
| 4191 | /* |
| 4192 | * params.value is ignored. Value of mask_type populated |
| 4193 | * in response.value |
| 4194 | */ |
| 4195 | EC_HOST_EVENT_GET, |
| 4196 | |
| 4197 | /* Bits in params.value are set */ |
| 4198 | EC_HOST_EVENT_SET, |
| 4199 | |
| 4200 | /* Bits in params.value are cleared */ |
| 4201 | EC_HOST_EVENT_CLEAR, |
| 4202 | }; |
| 4203 | |
| 4204 | enum ec_host_event_mask_type { |
| 4205 | |
| 4206 | /* Main host event copy */ |
| 4207 | EC_HOST_EVENT_MAIN, |
| 4208 | |
| 4209 | /* Copy B of host events */ |
| 4210 | EC_HOST_EVENT_B, |
| 4211 | |
| 4212 | /* SCI Mask */ |
| 4213 | EC_HOST_EVENT_SCI_MASK, |
| 4214 | |
| 4215 | /* SMI Mask */ |
| 4216 | EC_HOST_EVENT_SMI_MASK, |
| 4217 | |
| 4218 | /* Mask of events that should be always reported in hostevents */ |
| 4219 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4220 | |
| 4221 | /* Active wake mask */ |
| 4222 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4223 | |
| 4224 | /* Lazy wake mask for S0ix */ |
| 4225 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4226 | |
| 4227 | /* Lazy wake mask for S3 */ |
| 4228 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4229 | |
| 4230 | /* Lazy wake mask for S5 */ |
| 4231 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4232 | }; |
| 4233 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4234 | #define EC_CMD_HOST_EVENT 0x00A4 |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4235 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4236 | /*****************************************************************************/ |
| 4237 | /* Switch commands */ |
| 4238 | |
| 4239 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4240 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4241 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4242 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4243 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4244 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4245 | |
| 4246 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4247 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4248 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4249 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4250 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4251 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4252 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4253 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4254 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4255 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4256 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4257 | /* Flags to enable now */ |
| 4258 | uint8_t now_flags; |
| 4259 | |
| 4260 | /* Which flags to copy from now_flags */ |
| 4261 | uint8_t now_mask; |
| 4262 | |
| 4263 | /* |
| 4264 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4265 | * transition. (Other flags will be disabled by the S0->S3 |
| 4266 | * transition.) |
| 4267 | */ |
| 4268 | uint8_t suspend_flags; |
| 4269 | |
| 4270 | /* Which flags to copy from suspend_flags */ |
| 4271 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4272 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4273 | |
| 4274 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4275 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4276 | /* Flags to enable now */ |
| 4277 | uint8_t now_flags; |
| 4278 | |
| 4279 | /* Flags to leave enabled in S3 */ |
| 4280 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4281 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4282 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4283 | /*****************************************************************************/ |
| 4284 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4285 | |
| 4286 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4287 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4288 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4289 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4290 | char name[32]; |
| 4291 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4292 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4293 | |
| 4294 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4295 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4296 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4297 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4298 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4299 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4300 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4301 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4302 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4303 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4304 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4305 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4306 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4307 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4308 | uint8_t subcmd; |
| 4309 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4310 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4311 | char name[32]; |
| 4312 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4313 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4314 | uint8_t index; |
| 4315 | } get_info; |
| 4316 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4317 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4318 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4319 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4320 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4321 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4322 | uint8_t val; |
| 4323 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4324 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4325 | uint8_t val; |
| 4326 | char name[32]; |
| 4327 | uint32_t flags; |
| 4328 | } get_info; |
| 4329 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4330 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4331 | |
| 4332 | enum gpio_get_subcmd { |
| 4333 | EC_GPIO_GET_BY_NAME = 0, |
| 4334 | EC_GPIO_GET_COUNT = 1, |
| 4335 | EC_GPIO_GET_INFO = 2, |
| 4336 | }; |
| 4337 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4338 | /*****************************************************************************/ |
| 4339 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4340 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4341 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4342 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4343 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4344 | * |
| 4345 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4346 | */ |
| 4347 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4348 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4349 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4350 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4351 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4352 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4353 | uint8_t read_size; /* Either 8 or 16. */ |
| 4354 | uint8_t port; |
| 4355 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4356 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4357 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4358 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4359 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4360 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4361 | |
| 4362 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4363 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4364 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4365 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4366 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4367 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4368 | uint8_t write_size; /* Either 8 or 16. */ |
| 4369 | uint8_t port; |
| 4370 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4371 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4372 | |
| 4373 | /*****************************************************************************/ |
| 4374 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4375 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4376 | /* Force charge state machine to stop charging the battery or force it to |
| 4377 | * discharge the battery. |
| 4378 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4379 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4380 | #define EC_VER_CHARGE_CONTROL 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4381 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4382 | enum ec_charge_control_mode { |
| 4383 | CHARGE_CONTROL_NORMAL = 0, |
| 4384 | CHARGE_CONTROL_IDLE, |
| 4385 | CHARGE_CONTROL_DISCHARGE, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4386 | /* Add no more entry below. */ |
| 4387 | CHARGE_CONTROL_COUNT, |
| 4388 | }; |
| 4389 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4390 | #define EC_CHARGE_MODE_TEXT \ |
| 4391 | { \ |
| 4392 | [CHARGE_CONTROL_NORMAL] = "NORMAL", \ |
| 4393 | [CHARGE_CONTROL_IDLE] = "IDLE", \ |
| 4394 | [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | enum ec_charge_control_cmd { |
| 4398 | EC_CHARGE_CONTROL_CMD_SET = 0, |
| 4399 | EC_CHARGE_CONTROL_CMD_GET, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4400 | }; |
| 4401 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4402 | struct ec_params_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4403 | uint32_t mode; /* enum charge_control_mode */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4404 | |
| 4405 | /* Below are the fields added in V2. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4406 | uint8_t cmd; /* enum ec_charge_control_cmd. */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4407 | uint8_t reserved; |
| 4408 | /* |
| 4409 | * Lower and upper thresholds for battery sustainer. This struct isn't |
| 4410 | * named to avoid tainting foreign projects' name spaces. |
| 4411 | * |
| 4412 | * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer |
| 4413 | * will be disabled. To disable battery sustainer, set mode=NORMAL, |
| 4414 | * lower=-1, upper=-1. |
| 4415 | */ |
| 4416 | struct { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4417 | int8_t lower; /* Display SoC in percentage. */ |
| 4418 | int8_t upper; /* Display SoC in percentage. */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4419 | } sustain_soc; |
| 4420 | } __ec_align4; |
| 4421 | |
| 4422 | /* Added in v2 */ |
| 4423 | struct ec_response_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4424 | uint32_t mode; /* enum charge_control_mode */ |
| 4425 | struct { /* Battery sustainer thresholds */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4426 | int8_t lower; |
| 4427 | int8_t upper; |
| 4428 | } sustain_soc; |
| 4429 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4430 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4431 | |
| 4432 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4433 | |
| 4434 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4435 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4436 | |
| 4437 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4438 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4439 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4440 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4441 | * end of the previous snapshot. |
| 4442 | * |
| 4443 | * The params are only looked at in version >= 1 of this command. Prior |
| 4444 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4445 | * |
| 4446 | * Response is null-terminated string. Empty string, if there is no more |
| 4447 | * remaining output. |
| 4448 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4449 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4450 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4451 | enum ec_console_read_subcmd { |
| 4452 | CONSOLE_READ_NEXT = 0, |
| 4453 | CONSOLE_READ_RECENT, |
| 4454 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4455 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4456 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4457 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4458 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4459 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4460 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4461 | |
| 4462 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4463 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4464 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4465 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4466 | * EC_RES_SUCCESS if the command was successful. |
| 4467 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4468 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4469 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4470 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4471 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4472 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4473 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4474 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4475 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4476 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4477 | /*****************************************************************************/ |
| 4478 | /* USB port mux control. */ |
| 4479 | |
| 4480 | /* |
| 4481 | * Switch USB mux or return to automatic switching. |
| 4482 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4483 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4484 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4485 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4486 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4487 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4488 | |
| 4489 | /*****************************************************************************/ |
| 4490 | /* LDOs / FETs control. */ |
| 4491 | |
| 4492 | enum ec_ldo_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4493 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4494 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4495 | }; |
| 4496 | |
| 4497 | /* |
| 4498 | * Switch on/off a LDO. |
| 4499 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4500 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4501 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4502 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4503 | uint8_t index; |
| 4504 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4505 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4506 | |
| 4507 | /* |
| 4508 | * Get LDO state. |
| 4509 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4510 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4511 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4512 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4513 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4514 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4515 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4516 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4517 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4518 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4519 | |
| 4520 | /*****************************************************************************/ |
| 4521 | /* Power info. */ |
| 4522 | |
| 4523 | /* |
| 4524 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4525 | * |
| 4526 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4527 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4528 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4529 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4530 | /* |
| 4531 | * v1 of EC_CMD_POWER_INFO |
| 4532 | */ |
| 4533 | enum system_power_source { |
| 4534 | /* |
| 4535 | * Haven't established which power source is used yet, |
| 4536 | * or no presence signals are available |
| 4537 | */ |
| 4538 | POWER_SOURCE_UNKNOWN = 0, |
| 4539 | /* System is running on battery alone */ |
| 4540 | POWER_SOURCE_BATTERY = 1, |
| 4541 | /* System is running on A/C alone */ |
| 4542 | POWER_SOURCE_AC = 2, |
| 4543 | /* System is running on A/C and battery */ |
| 4544 | POWER_SOURCE_AC_BATTERY = 3, |
| 4545 | }; |
| 4546 | |
| 4547 | struct ec_response_power_info_v1 { |
| 4548 | /* enum system_power_source */ |
| 4549 | uint8_t system_power_source; |
| 4550 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4551 | uint8_t battery_soc; |
| 4552 | /* AC Adapter 100% rating, Watts */ |
| 4553 | uint8_t ac_adapter_100pct; |
| 4554 | /* AC Adapter 10ms rating, Watts */ |
| 4555 | uint8_t ac_adapter_10ms; |
| 4556 | /* Battery 1C rating, derated */ |
| 4557 | uint8_t battery_1cd; |
| 4558 | /* Rest of Platform average, Watts */ |
| 4559 | uint8_t rop_avg; |
| 4560 | /* Rest of Platform peak, Watts */ |
| 4561 | uint8_t rop_peak; |
| 4562 | /* Nominal charger efficiency, % */ |
| 4563 | uint8_t nominal_charger_eff; |
| 4564 | /* Rest of Platform VR Average Efficiency, % */ |
| 4565 | uint8_t rop_avg_eff; |
| 4566 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4567 | uint8_t rop_peak_eff; |
| 4568 | /* SoC VR Efficiency at Average level, % */ |
| 4569 | uint8_t soc_avg_eff; |
| 4570 | /* SoC VR Efficiency at Peak level, % */ |
| 4571 | uint8_t soc_peak_eff; |
| 4572 | /* Intel-specific items */ |
| 4573 | struct { |
| 4574 | /* Battery's level of DBPT support: 0, 2 */ |
| 4575 | uint8_t batt_dbpt_support_level; |
| 4576 | /* |
| 4577 | * Maximum peak power from battery (10ms), Watts |
| 4578 | * If DBPT is not supported, this is 0 |
| 4579 | */ |
| 4580 | uint8_t batt_dbpt_max_peak_power; |
| 4581 | /* |
| 4582 | * Sustained peak power from battery, Watts |
| 4583 | * If DBPT is not supported, this is 0 |
| 4584 | */ |
| 4585 | uint8_t batt_dbpt_sus_peak_power; |
| 4586 | } intel; |
| 4587 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4588 | |
| 4589 | /*****************************************************************************/ |
| 4590 | /* I2C passthru command */ |
| 4591 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4592 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4593 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4594 | /* Read data; if not present, message is a write */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4595 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4596 | |
| 4597 | /* Mask for address */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4598 | #define EC_I2C_ADDR_MASK 0x3ff |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4599 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4600 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4601 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4602 | |
| 4603 | /* Any error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4604 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4605 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4606 | struct ec_params_i2c_passthru_msg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4607 | uint16_t addr_flags; /* I2C peripheral address and flags */ |
| 4608 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4609 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4610 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4611 | struct ec_params_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4612 | uint8_t port; /* I2C port number */ |
| 4613 | uint8_t num_msgs; /* Number of messages */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4614 | struct ec_params_i2c_passthru_msg msg[]; |
| 4615 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4616 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4617 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4618 | struct ec_response_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4619 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4620 | uint8_t num_msgs; /* Number of messages processed */ |
| 4621 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4622 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4623 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4624 | /*****************************************************************************/ |
| 4625 | /* Power button hang detect */ |
| 4626 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4627 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4628 | |
| 4629 | /* Reasons to start hang detection timer */ |
| 4630 | /* Power button pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4631 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4632 | |
| 4633 | /* Lid closed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4634 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4635 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4636 | /* Lid opened */ |
| 4637 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4638 | |
| 4639 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4640 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4641 | |
| 4642 | /* Reasons to cancel hang detection */ |
| 4643 | |
| 4644 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4645 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4646 | |
| 4647 | /* Any host command from AP received */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4648 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4649 | |
| 4650 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4651 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4652 | |
| 4653 | /* |
| 4654 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4655 | * timer is started. This provides the AP a way to start the hang timer |
| 4656 | * without reconfiguring any of the other hang detect settings. Note that |
| 4657 | * you must previously have configured the timeouts. |
| 4658 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4659 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4660 | |
| 4661 | /* |
| 4662 | * If this flag is set, all the other fields are ignored (including |
| 4663 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4664 | * without reconfiguring any of the other hang detect settings. |
| 4665 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4666 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4667 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4668 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4669 | /* Flags; see EC_HANG_* */ |
| 4670 | uint32_t flags; |
| 4671 | |
| 4672 | /* Timeout in msec before generating host event, if enabled */ |
| 4673 | uint16_t host_event_timeout_msec; |
| 4674 | |
| 4675 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4676 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4677 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4678 | |
| 4679 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4680 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4681 | |
| 4682 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4683 | * This is the single catch-all host command to exchange data regarding the |
| 4684 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4685 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4686 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4687 | |
| 4688 | /* Subcommands for this host command */ |
| 4689 | enum charge_state_command { |
| 4690 | CHARGE_STATE_CMD_GET_STATE, |
| 4691 | CHARGE_STATE_CMD_GET_PARAM, |
| 4692 | CHARGE_STATE_CMD_SET_PARAM, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4693 | CHARGE_STATE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4694 | }; |
| 4695 | |
| 4696 | /* |
| 4697 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4698 | * params, which are handled by the particular implementations. |
| 4699 | */ |
| 4700 | enum charge_state_params { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4701 | /* charger voltage limit */ |
| 4702 | CS_PARAM_CHG_VOLTAGE, |
| 4703 | |
| 4704 | /* charger current limit */ |
| 4705 | CS_PARAM_CHG_CURRENT, |
| 4706 | |
| 4707 | /* charger input current limit */ |
| 4708 | CS_PARAM_CHG_INPUT_CURRENT, |
| 4709 | |
| 4710 | /* charger-specific status */ |
| 4711 | CS_PARAM_CHG_STATUS, |
| 4712 | |
| 4713 | /* charger-specific options */ |
| 4714 | CS_PARAM_CHG_OPTION, |
| 4715 | |
| 4716 | /* |
| 4717 | * Check if power is limited due to low battery and / or a |
| 4718 | * weak external charger. READ ONLY. |
| 4719 | */ |
| 4720 | CS_PARAM_LIMIT_POWER, |
| 4721 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4722 | /* How many so far? */ |
| 4723 | CS_NUM_BASE_PARAMS, |
| 4724 | |
| 4725 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4726 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4727 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4728 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4729 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4730 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4731 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4732 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4733 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4734 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4735 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4736 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4737 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4738 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4739 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4740 | /* Other custom param ranges go here... */ |
| 4741 | }; |
| 4742 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4743 | struct ec_params_charge_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4744 | uint8_t cmd; /* enum charge_state_command */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4745 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4746 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4747 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4748 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4749 | uint32_t param; /* enum charge_state_param */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4750 | } get_param; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4751 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4752 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4753 | uint32_t param; /* param to set */ |
| 4754 | uint32_t value; /* value to set */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4755 | } set_param; |
| 4756 | } __ec_todo_packed; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4757 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4758 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4759 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4760 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4761 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4762 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4763 | int ac; |
| 4764 | int chg_voltage; |
| 4765 | int chg_current; |
| 4766 | int chg_input_current; |
| 4767 | int batt_state_of_charge; |
| 4768 | } get_state; |
| 4769 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4770 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4771 | uint32_t value; |
| 4772 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4773 | |
| 4774 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4775 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4776 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4777 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4778 | /* |
| 4779 | * Set maximum battery charging current. |
| 4780 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4781 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4782 | #define EC_VER_CHARGE_CURRENT_LIMIT 1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4784 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4785 | uint32_t limit; /* in mA */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 4786 | } __ec_align4; |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4787 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 4788 | struct ec_params_current_limit_v1 { |
| 4789 | uint32_t limit; /* in mA */ |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4790 | /* |
| 4791 | * Battery state of charge is the minimum charge percentage at which |
| 4792 | * the battery charge current limit will apply. |
| 4793 | * When not set, the limit will apply regardless of state of charge. |
| 4794 | */ |
| 4795 | uint8_t battery_soc; /* battery state of charge, 0-100 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4796 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4797 | |
| 4798 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4799 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4800 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4801 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4802 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4803 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4804 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4805 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4806 | 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] | 4807 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4808 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4809 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4810 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4811 | /* |
| 4812 | * Set maximum voltage & current of a dedicated charge port |
| 4813 | */ |
| 4814 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4815 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4816 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4817 | uint16_t current_lim; /* in mA */ |
| 4818 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4819 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4820 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 4821 | /* |
| 4822 | * Get and set charging splashscreen variables |
| 4823 | */ |
| 4824 | #define EC_CMD_CHARGESPLASH 0x00A5 |
| 4825 | |
| 4826 | enum ec_chargesplash_cmd { |
| 4827 | /* Get the current state variables */ |
| 4828 | EC_CHARGESPLASH_GET_STATE = 0, |
| 4829 | |
| 4830 | /* Indicate initialization of the display loop */ |
| 4831 | EC_CHARGESPLASH_DISPLAY_READY, |
| 4832 | |
| 4833 | /* Manually put the EC into the requested state */ |
| 4834 | EC_CHARGESPLASH_REQUEST, |
| 4835 | |
| 4836 | /* Reset all state variables */ |
| 4837 | EC_CHARGESPLASH_RESET, |
| 4838 | |
| 4839 | /* Manually trigger a lockout */ |
| 4840 | EC_CHARGESPLASH_LOCKOUT, |
| 4841 | }; |
| 4842 | |
| 4843 | struct __ec_align1 ec_params_chargesplash { |
| 4844 | /* enum ec_chargesplash_cmd */ |
| 4845 | uint8_t cmd; |
| 4846 | }; |
| 4847 | |
| 4848 | struct __ec_align1 ec_response_chargesplash { |
| 4849 | uint8_t requested; |
| 4850 | uint8_t display_initialized; |
| 4851 | uint8_t locked_out; |
| 4852 | }; |
| 4853 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4854 | /*****************************************************************************/ |
| 4855 | /* Hibernate/Deep Sleep Commands */ |
| 4856 | |
| 4857 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4858 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4859 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4860 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4861 | /* |
| 4862 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4863 | * current settings without changing them. |
| 4864 | */ |
| 4865 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4866 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4867 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4868 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4869 | /* |
| 4870 | * The current time in seconds in which the system has been in the G3 |
| 4871 | * state. This value is reset if the EC transitions out of G3. |
| 4872 | */ |
| 4873 | uint32_t time_g3; |
| 4874 | |
| 4875 | /* |
| 4876 | * The current time remaining in seconds until the EC should hibernate. |
| 4877 | * This value is also reset if the EC transitions out of G3. |
| 4878 | */ |
| 4879 | uint32_t time_remaining; |
| 4880 | |
| 4881 | /* |
| 4882 | * The current time in seconds that the EC should wait in G3 before |
| 4883 | * hibernating. |
| 4884 | */ |
| 4885 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4886 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4887 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4888 | /* Inform the EC when entering a sleep state */ |
| 4889 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4890 | |
| 4891 | enum host_sleep_event { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4892 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4893 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4894 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4895 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4896 | /* S3 suspend with additional enabled wake sources */ |
| 4897 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4898 | }; |
| 4899 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4900 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4901 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4902 | } __ec_align1; |
| 4903 | |
| 4904 | /* |
| 4905 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4906 | * transition failures |
| 4907 | */ |
| 4908 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4909 | |
| 4910 | /* Disable timeout detection for this sleep transition */ |
| 4911 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4912 | |
| 4913 | struct ec_params_host_sleep_event_v1 { |
| 4914 | /* The type of sleep being entered or exited. */ |
| 4915 | uint8_t sleep_event; |
| 4916 | |
| 4917 | /* Padding */ |
| 4918 | uint8_t reserved; |
| 4919 | union { |
| 4920 | /* Parameters that apply for suspend messages. */ |
| 4921 | struct { |
| 4922 | /* |
| 4923 | * The timeout in milliseconds between when this message |
| 4924 | * is received and when the EC will declare sleep |
| 4925 | * transition failure if the sleep signal is not |
| 4926 | * asserted. |
| 4927 | */ |
| 4928 | uint16_t sleep_timeout_ms; |
| 4929 | } suspend_params; |
| 4930 | |
| 4931 | /* No parameters for non-suspend messages. */ |
| 4932 | }; |
| 4933 | } __ec_align2; |
| 4934 | |
| 4935 | /* A timeout occurred when this bit is set */ |
| 4936 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4937 | |
| 4938 | /* |
| 4939 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4940 | * as well as the maximum number of suspend line transitions that will be |
| 4941 | * reported back to the host. |
| 4942 | */ |
| 4943 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4944 | |
| 4945 | struct ec_response_host_sleep_event_v1 { |
| 4946 | union { |
| 4947 | /* Response fields that apply for resume messages. */ |
| 4948 | struct { |
| 4949 | /* |
| 4950 | * The number of sleep power signal transitions that |
| 4951 | * occurred since the suspend message. The high bit |
| 4952 | * indicates a timeout occurred. |
| 4953 | */ |
| 4954 | uint32_t sleep_transitions; |
| 4955 | } resume_response; |
| 4956 | |
| 4957 | /* No response fields for non-resume messages. */ |
| 4958 | }; |
| 4959 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4960 | |
| 4961 | /*****************************************************************************/ |
| 4962 | /* Device events */ |
| 4963 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4964 | |
| 4965 | enum ec_device_event { |
| 4966 | EC_DEVICE_EVENT_TRACKPAD, |
| 4967 | EC_DEVICE_EVENT_DSP, |
| 4968 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 4969 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4970 | }; |
| 4971 | |
| 4972 | enum ec_device_event_param { |
| 4973 | /* Get and clear pending device events */ |
| 4974 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4975 | /* Get device event mask */ |
| 4976 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4977 | /* Set device event mask */ |
| 4978 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4979 | }; |
| 4980 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4981 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4982 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4983 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4984 | uint32_t event_mask; |
| 4985 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4986 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4987 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4988 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4989 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4990 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4991 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4992 | /*****************************************************************************/ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 4993 | /* Get s0ix counter */ |
| 4994 | #define EC_CMD_GET_S0IX_COUNTER 0x00AB |
| 4995 | |
| 4996 | /* Flag use to reset the counter */ |
| 4997 | #define EC_S0IX_COUNTER_RESET 0x1 |
| 4998 | |
| 4999 | struct ec_params_s0ix_cnt { |
| 5000 | /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */ |
| 5001 | uint32_t flags; |
| 5002 | } __ec_align4; |
| 5003 | |
| 5004 | struct ec_response_s0ix_cnt { |
| 5005 | /* Value of the s0ix_counter */ |
| 5006 | uint32_t s0ix_counter; |
| 5007 | } __ec_align4; |
| 5008 | |
| 5009 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5010 | /* Smart battery pass-through */ |
| 5011 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5012 | /* Get / Set 16-bit smart battery registers - OBSOLETE */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5013 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 5014 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5015 | |
| 5016 | /* Get / Set string smart battery parameters |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5017 | * formatted as SMBUS "block". - OBSOLETE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5018 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5019 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5020 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5021 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5022 | /*****************************************************************************/ |
| 5023 | /* Battery vendor parameters |
| 5024 | * |
| 5025 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 5026 | * differ between boards or batteries. On a set operation, the response |
| 5027 | * contains the actual value set, which may be rounded or clipped from the |
| 5028 | * requested value. |
| 5029 | */ |
| 5030 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5031 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5032 | |
| 5033 | enum ec_battery_vendor_param_mode { |
| 5034 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 5035 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 5036 | }; |
| 5037 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5038 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5039 | uint32_t param; |
| 5040 | uint32_t value; |
| 5041 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5042 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5043 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5044 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5045 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5046 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5047 | |
| 5048 | /*****************************************************************************/ |
| 5049 | /* |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5050 | * Smart Battery Firmware Update Command - OBSOLETE |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5051 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5052 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5053 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5054 | /* |
| 5055 | * Entering Verified Boot Mode Command |
| 5056 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 5057 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5058 | * |
| 5059 | * EC no longer needs to know what mode vboot has entered, |
| 5060 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5061 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5062 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5063 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5064 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5065 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5066 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5067 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5068 | #define VBOOT_MODE_NORMAL 0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5069 | #define VBOOT_MODE_DEVELOPER 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5070 | #define VBOOT_MODE_RECOVERY 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5071 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5072 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5073 | /* |
| 5074 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 5075 | * certain addresses (board-specific). |
| 5076 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5077 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5078 | |
| 5079 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5080 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 5081 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 5082 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5083 | }; |
| 5084 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5085 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5086 | uint8_t subcmd; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5087 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5088 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5089 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5090 | struct ec_response_i2c_passthru_protect { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5091 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5092 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5093 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5094 | /*****************************************************************************/ |
| 5095 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5096 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5097 | * |
| 5098 | * These commands are for sending and receiving message via HDMI CEC |
| 5099 | */ |
| 5100 | |
| 5101 | #define MAX_CEC_MSG_LEN 16 |
| 5102 | |
| 5103 | /* CEC message from the AP to be written on the CEC bus */ |
| 5104 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 5105 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5106 | /** |
| 5107 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 5108 | * @msg: message content to write to the CEC bus |
| 5109 | */ |
| 5110 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5111 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5112 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5113 | |
| 5114 | /* Set various CEC parameters */ |
| 5115 | #define EC_CMD_CEC_SET 0x00BA |
| 5116 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5117 | /** |
| 5118 | * struct ec_params_cec_set - CEC parameters set |
| 5119 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5120 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 5121 | * or 1 to enable CEC functionality, in case cmd is |
| 5122 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 5123 | * address between 0 and 15 or 0xff to unregister |
| 5124 | */ |
| 5125 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5126 | uint8_t cmd; /* enum cec_command */ |
| 5127 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5128 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5129 | |
| 5130 | /* Read various CEC parameters */ |
| 5131 | #define EC_CMD_CEC_GET 0x00BB |
| 5132 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5133 | /** |
| 5134 | * struct ec_params_cec_get - CEC parameters get |
| 5135 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5136 | */ |
| 5137 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5138 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5139 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5140 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5141 | /** |
| 5142 | * struct ec_response_cec_get - CEC parameters get response |
| 5143 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 5144 | * disabled or 1 if CEC functionality is enabled, |
| 5145 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 5146 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 5147 | */ |
| 5148 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5149 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5150 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5151 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5152 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5153 | enum cec_command { |
| 5154 | /* CEC reading, writing and events enable */ |
| 5155 | CEC_CMD_ENABLE, |
| 5156 | /* CEC logical address */ |
| 5157 | CEC_CMD_LOGICAL_ADDRESS, |
| 5158 | }; |
| 5159 | |
| 5160 | /* Events from CEC to AP */ |
| 5161 | enum mkbp_cec_event { |
| 5162 | /* Outgoing message was acknowledged by a follower */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5163 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5164 | /* Outgoing message was not acknowledged */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5165 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5166 | }; |
| 5167 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5168 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5169 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5170 | /* Commands for audio codec. */ |
| 5171 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5172 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5173 | enum ec_codec_subcmd { |
| 5174 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 5175 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 5176 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 5177 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5178 | }; |
| 5179 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5180 | enum ec_codec_cap { |
| 5181 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 5182 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 5183 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5184 | }; |
| 5185 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5186 | enum ec_codec_shm_id { |
| 5187 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 5188 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 5189 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5190 | }; |
| 5191 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5192 | enum ec_codec_shm_type { |
| 5193 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 5194 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5195 | }; |
| 5196 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5197 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 5198 | uint8_t shm_id; |
| 5199 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5200 | }; |
| 5201 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5202 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 5203 | uint64_t phys_addr; |
| 5204 | uint32_t len; |
| 5205 | uint8_t shm_id; |
| 5206 | uint8_t reserved[3]; |
| 5207 | }; |
| 5208 | |
| 5209 | struct __ec_align4 ec_param_ec_codec { |
| 5210 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 5211 | uint8_t reserved[3]; |
| 5212 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5213 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5214 | struct ec_param_ec_codec_get_shm_addr get_shm_addr_param; |
| 5215 | struct ec_param_ec_codec_set_shm_addr set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5216 | }; |
| 5217 | }; |
| 5218 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5219 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 5220 | uint32_t capabilities; |
| 5221 | }; |
| 5222 | |
| 5223 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5224 | uint64_t phys_addr; |
| 5225 | uint32_t len; |
| 5226 | uint8_t type; |
| 5227 | uint8_t reserved[3]; |
| 5228 | }; |
| 5229 | |
| 5230 | /*****************************************************************************/ |
| 5231 | |
| 5232 | /* Commands for DMIC on audio codec. */ |
| 5233 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5234 | |
| 5235 | enum ec_codec_dmic_subcmd { |
| 5236 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5237 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5238 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5239 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5240 | }; |
| 5241 | |
| 5242 | enum ec_codec_dmic_channel { |
| 5243 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5244 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5245 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5246 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5247 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5248 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5249 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5250 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5251 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5252 | }; |
| 5253 | |
| 5254 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5255 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5256 | uint8_t gain; |
| 5257 | uint8_t reserved[2]; |
| 5258 | }; |
| 5259 | |
| 5260 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5261 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5262 | uint8_t reserved[3]; |
| 5263 | }; |
| 5264 | |
| 5265 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5266 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5267 | uint8_t reserved[3]; |
| 5268 | |
| 5269 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5270 | struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param; |
| 5271 | struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5272 | }; |
| 5273 | }; |
| 5274 | |
| 5275 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5276 | uint8_t max_gain; |
| 5277 | }; |
| 5278 | |
| 5279 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5280 | uint8_t gain; |
| 5281 | }; |
| 5282 | |
| 5283 | /*****************************************************************************/ |
| 5284 | |
| 5285 | /* Commands for I2S RX on audio codec. */ |
| 5286 | |
| 5287 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5288 | |
| 5289 | enum ec_codec_i2s_rx_subcmd { |
| 5290 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5291 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5292 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5293 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5294 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5295 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5296 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5297 | }; |
| 5298 | |
| 5299 | enum ec_codec_i2s_rx_sample_depth { |
| 5300 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5301 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5302 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5303 | }; |
| 5304 | |
| 5305 | enum ec_codec_i2s_rx_daifmt { |
| 5306 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5307 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5308 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5309 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5310 | }; |
| 5311 | |
| 5312 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5313 | uint8_t depth; |
| 5314 | uint8_t reserved[3]; |
| 5315 | }; |
| 5316 | |
| 5317 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5318 | uint8_t left; |
| 5319 | uint8_t right; |
| 5320 | uint8_t reserved[2]; |
| 5321 | }; |
| 5322 | |
| 5323 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5324 | uint8_t daifmt; |
| 5325 | uint8_t reserved[3]; |
| 5326 | }; |
| 5327 | |
| 5328 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5329 | uint32_t bclk; |
| 5330 | }; |
| 5331 | |
| 5332 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5333 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5334 | uint8_t reserved[3]; |
| 5335 | |
| 5336 | union { |
| 5337 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5338 | set_sample_depth_param; |
| 5339 | struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param; |
| 5340 | struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5341 | }; |
| 5342 | }; |
| 5343 | |
| 5344 | /*****************************************************************************/ |
| 5345 | /* Commands for WoV on audio codec. */ |
| 5346 | |
| 5347 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5348 | |
| 5349 | enum ec_codec_wov_subcmd { |
| 5350 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5351 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5352 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5353 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5354 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5355 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5356 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5357 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5358 | }; |
| 5359 | |
| 5360 | /* |
| 5361 | * @hash is SHA256 of the whole language model. |
| 5362 | * @total_len indicates the length of whole language model. |
| 5363 | * @offset is the cursor from the beginning of the model. |
| 5364 | * @buf is the packet buffer. |
| 5365 | * @len denotes how many bytes in the buf. |
| 5366 | */ |
| 5367 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5368 | uint8_t hash[32]; |
| 5369 | uint32_t total_len; |
| 5370 | uint32_t offset; |
| 5371 | uint8_t buf[128]; |
| 5372 | uint32_t len; |
| 5373 | }; |
| 5374 | |
| 5375 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5376 | uint8_t hash[32]; |
| 5377 | uint32_t total_len; |
| 5378 | }; |
| 5379 | |
| 5380 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5381 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5382 | uint8_t reserved[3]; |
| 5383 | |
| 5384 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5385 | struct ec_param_ec_codec_wov_set_lang set_lang_param; |
| 5386 | struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5387 | }; |
| 5388 | }; |
| 5389 | |
| 5390 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5391 | uint8_t hash[32]; |
| 5392 | }; |
| 5393 | |
| 5394 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5395 | uint8_t buf[128]; |
| 5396 | uint32_t len; |
| 5397 | }; |
| 5398 | |
| 5399 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5400 | uint32_t offset; |
| 5401 | uint32_t len; |
| 5402 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5403 | |
| 5404 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5405 | /* Commands for PoE PSE controller */ |
| 5406 | |
| 5407 | #define EC_CMD_PSE 0x00C0 |
| 5408 | |
| 5409 | enum ec_pse_subcmd { |
| 5410 | EC_PSE_STATUS = 0x0, |
| 5411 | EC_PSE_ENABLE = 0x1, |
| 5412 | EC_PSE_DISABLE = 0x2, |
| 5413 | EC_PSE_SUBCMD_COUNT, |
| 5414 | }; |
| 5415 | |
| 5416 | struct __ec_align1 ec_params_pse { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5417 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5418 | uint8_t port; /* PSE port */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5419 | }; |
| 5420 | |
| 5421 | enum ec_pse_status { |
| 5422 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5423 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5424 | EC_PSE_STATUS_POWERED = 0x2, |
| 5425 | }; |
| 5426 | |
| 5427 | struct __ec_align1 ec_response_pse_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5428 | uint8_t status; /* enum ec_pse_status */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5429 | }; |
| 5430 | |
| 5431 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5432 | /* System commands */ |
| 5433 | |
| 5434 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5435 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5436 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5437 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5438 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5439 | |
| 5440 | /* Command */ |
| 5441 | enum ec_reboot_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5442 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
| 5443 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 5444 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5445 | /* (command 3 was jump to RW-B) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5446 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
| 5447 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 5448 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5449 | /* |
| 5450 | * DEPRECATED: Hibernate EC and clears AP_IDLE flag. |
| 5451 | * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead. |
| 5452 | */ |
| 5453 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5454 | EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */ |
| 5455 | EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5456 | }; |
| 5457 | |
| 5458 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5459 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5460 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5461 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
| 5462 | #define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5463 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5464 | struct ec_params_reboot_ec { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5465 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5466 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5467 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5468 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5469 | /* |
| 5470 | * Get information on last EC panic. |
| 5471 | * |
| 5472 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5473 | * for details. |
| 5474 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5475 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5476 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5477 | /*****************************************************************************/ |
| 5478 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5479 | * Special commands |
| 5480 | * |
| 5481 | * These do not follow the normal rules for commands. See each command for |
| 5482 | * details. |
| 5483 | */ |
| 5484 | |
| 5485 | /* |
| 5486 | * Reboot NOW |
| 5487 | * |
| 5488 | * This command will work even when the EC LPC interface is busy, because the |
| 5489 | * reboot command is processed at interrupt level. Note that when the EC |
| 5490 | * reboots, the host will reboot too, so there is no response to this command. |
| 5491 | * |
| 5492 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5493 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5494 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5495 | |
| 5496 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5497 | * Resend last response (not supported on LPC). |
| 5498 | * |
| 5499 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5500 | * there was no previous command, or the previous command's response was too |
| 5501 | * big to save. |
| 5502 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5503 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5504 | |
| 5505 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5506 | * This header byte on a command indicate version 0. Any header byte less |
| 5507 | * than this means that we are talking to an old EC which doesn't support |
| 5508 | * versioning. In that case, we assume version 0. |
| 5509 | * |
| 5510 | * Header bytes greater than this indicate a later version. For example, |
| 5511 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5512 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5513 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5514 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5515 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5516 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5517 | /* |
| 5518 | * Memory Dump Commands |
| 5519 | * |
| 5520 | * Since the HOSTCMD response size is limited, depending on the |
| 5521 | * protocol, retrieving a memory dump is split into 3 commands. |
| 5522 | * |
| 5523 | * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries, |
| 5524 | * and the total dump size. |
| 5525 | * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given |
| 5526 | * memory dump entry index. |
| 5527 | * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given |
| 5528 | * address. The address and size must be within the bounds of the given |
| 5529 | * memory dump entry index. Each response is limited to the max response size |
| 5530 | * of the host protocol, so this may need to be called repeatedly to retrieve |
| 5531 | * the entire memory dump entry. |
| 5532 | * |
| 5533 | * Memory entries may overlap and may be out of order. |
| 5534 | * The host should check for overlaps to optimize transfer rate. |
| 5535 | */ |
| 5536 | #define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD |
| 5537 | struct ec_response_memory_dump_get_metadata { |
| 5538 | uint16_t memory_dump_entry_count; |
| 5539 | uint32_t memory_dump_total_size; |
| 5540 | } __ec_align4; |
| 5541 | |
| 5542 | #define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE |
| 5543 | struct ec_params_memory_dump_get_entry_info { |
| 5544 | uint16_t memory_dump_entry_index; |
| 5545 | } __ec_align4; |
| 5546 | |
| 5547 | struct ec_response_memory_dump_get_entry_info { |
| 5548 | uint32_t address; |
| 5549 | uint32_t size; |
| 5550 | } __ec_align4; |
| 5551 | |
| 5552 | #define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF |
| 5553 | |
| 5554 | struct ec_params_memory_dump_read_memory { |
| 5555 | uint16_t memory_dump_entry_index; |
| 5556 | uint32_t address; |
| 5557 | uint32_t size; |
| 5558 | } __ec_align4; |
| 5559 | |
| 5560 | /* |
| 5561 | * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into |
| 5562 | * host_cmd_handler_args.response and host_cmd_handler_args.response_size. |
| 5563 | */ |
| 5564 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5565 | /*****************************************************************************/ |
| 5566 | /* |
| 5567 | * PD commands |
| 5568 | * |
| 5569 | * These commands are for PD MCU communication. |
| 5570 | */ |
| 5571 | |
| 5572 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5573 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5574 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5575 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5576 | enum pd_charge_state { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5577 | /* Don't change charge state */ |
| 5578 | PD_CHARGE_NO_CHANGE = 0, |
| 5579 | |
| 5580 | /* No charging allowed */ |
| 5581 | PD_CHARGE_NONE, |
| 5582 | |
| 5583 | /* 5V charging only */ |
| 5584 | PD_CHARGE_5V, |
| 5585 | |
| 5586 | /* Charge at max voltage */ |
| 5587 | PD_CHARGE_MAX, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5588 | }; |
| 5589 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5590 | /* Status of EC being sent to PD */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5591 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5592 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5593 | struct ec_params_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5594 | /* EC status */ |
| 5595 | uint8_t status; |
| 5596 | |
| 5597 | /* battery state of charge */ |
| 5598 | int8_t batt_soc; |
| 5599 | |
| 5600 | /* charging state (from enum pd_charge_state) */ |
| 5601 | uint8_t charge_state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5602 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5603 | |
| 5604 | /* Status of PD being sent back to EC */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5605 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5606 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5607 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5608 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5609 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5610 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5611 | #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ |
| 5612 | #define PD_STATUS_EC_INT_ACTIVE \ |
| 5613 | (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5614 | struct ec_response_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5615 | /* input current limit */ |
| 5616 | uint32_t curr_lim_ma; |
| 5617 | |
| 5618 | /* PD MCU status */ |
| 5619 | uint16_t status; |
| 5620 | |
| 5621 | /* active charging port */ |
| 5622 | int8_t active_charge_port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5623 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5624 | |
| 5625 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5626 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5627 | |
| 5628 | /* PD MCU host event status bits */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5629 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5630 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5631 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5632 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5633 | #define PD_EVENT_TYPEC BIT(4) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5634 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5635 | struct ec_response_host_event_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5636 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5637 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5638 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5639 | /* |
| 5640 | * Set USB type-C port role and muxes |
| 5641 | * |
| 5642 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5643 | * |
| 5644 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5645 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5646 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5647 | |
| 5648 | enum usb_pd_control_role { |
| 5649 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5650 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5651 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5652 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5653 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5654 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5655 | USB_PD_CTRL_ROLE_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5656 | }; |
| 5657 | |
| 5658 | enum usb_pd_control_mux { |
| 5659 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5660 | USB_PD_CTRL_MUX_NONE = 1, |
| 5661 | USB_PD_CTRL_MUX_USB = 2, |
| 5662 | USB_PD_CTRL_MUX_DP = 3, |
| 5663 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5664 | USB_PD_CTRL_MUX_AUTO = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5665 | USB_PD_CTRL_MUX_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5666 | }; |
| 5667 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5668 | enum usb_pd_control_swap { |
| 5669 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5670 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5671 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5672 | USB_PD_CTRL_SWAP_VCONN = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5673 | USB_PD_CTRL_SWAP_COUNT, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5674 | }; |
| 5675 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5676 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5677 | uint8_t port; |
| 5678 | uint8_t role; |
| 5679 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5680 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5681 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5682 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5683 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5684 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5685 | #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] | 5686 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5687 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5688 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5689 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5690 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5691 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5692 | #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5693 | /* Partner unconstrained power */ |
| 5694 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5695 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5696 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5697 | uint8_t enabled; |
| 5698 | uint8_t role; |
| 5699 | uint8_t polarity; |
| 5700 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5701 | } __ec_align1; |
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_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5704 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5705 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5706 | uint8_t polarity; |
| 5707 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5708 | } __ec_align1; |
| 5709 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5710 | /* Possible port partner connections based on CC line states */ |
| 5711 | enum pd_cc_states { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5712 | PD_CC_NONE = 0, /* No port partner attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5713 | |
| 5714 | /* From DFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5715 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
| 5716 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5717 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5718 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5719 | |
| 5720 | /* From UFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5721 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
| 5722 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5723 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5724 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5725 | /* Active/Passive Cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5726 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5727 | /* Optical/Non-optical cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5728 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5729 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5730 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5731 | /* Active Link Uni-Direction */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5732 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5733 | /* Retimer/Redriver cable */ |
| 5734 | #define USB_PD_CTRL_RETIMER_CABLE BIT(4) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5735 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5736 | struct ec_response_usb_pd_control_v2 { |
| 5737 | uint8_t enabled; |
| 5738 | uint8_t role; |
| 5739 | uint8_t polarity; |
| 5740 | char state[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5741 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5742 | uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ |
| 5743 | uint8_t reserved; /* Reserved for future use */ |
| 5744 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
| 5745 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
| 5746 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5747 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5748 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5749 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5750 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5751 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5752 | #define EC_USB_PD_MAX_PORTS 8 |
| 5753 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5754 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5755 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5756 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5757 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5758 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5759 | |
| 5760 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5761 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5762 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5763 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5764 | |
| 5765 | enum usb_chg_type { |
| 5766 | USB_CHG_TYPE_NONE, |
| 5767 | USB_CHG_TYPE_PD, |
| 5768 | USB_CHG_TYPE_C, |
| 5769 | USB_CHG_TYPE_PROPRIETARY, |
| 5770 | USB_CHG_TYPE_BC12_DCP, |
| 5771 | USB_CHG_TYPE_BC12_CDP, |
| 5772 | USB_CHG_TYPE_BC12_SDP, |
| 5773 | USB_CHG_TYPE_OTHER, |
| 5774 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5775 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5776 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5777 | }; |
| 5778 | enum usb_power_roles { |
| 5779 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5780 | USB_PD_PORT_POWER_SOURCE, |
| 5781 | USB_PD_PORT_POWER_SINK, |
| 5782 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5783 | }; |
| 5784 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5785 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5786 | uint16_t voltage_max; |
| 5787 | uint16_t voltage_now; |
| 5788 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5789 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5790 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5791 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5792 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5793 | uint8_t role; |
| 5794 | uint8_t type; |
| 5795 | uint8_t dualrole; |
| 5796 | uint8_t reserved1; |
| 5797 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5798 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5799 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5800 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5801 | /* |
| 5802 | * This command will return the number of USB PD charge port + the number |
| 5803 | * of dedicated port present. |
| 5804 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5805 | */ |
| 5806 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5807 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5808 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5809 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5810 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 5811 | /* |
| 5812 | * This command enable/disable dynamic PDO selection. |
| 5813 | */ |
| 5814 | #define EC_CMD_USB_PD_DPS_CONTROL 0x0106 |
| 5815 | |
| 5816 | struct ec_params_usb_pd_dps_control { |
| 5817 | uint8_t enable; |
| 5818 | } __ec_align1; |
| 5819 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5820 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5821 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5822 | |
| 5823 | enum usb_pd_fw_update_cmds { |
| 5824 | USB_PD_FW_REBOOT, |
| 5825 | USB_PD_FW_FLASH_ERASE, |
| 5826 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5827 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5828 | }; |
| 5829 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5830 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5831 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5832 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5833 | uint8_t port; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5834 | |
| 5835 | /* Size to write in bytes */ |
| 5836 | uint32_t size; |
| 5837 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5838 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5839 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5840 | |
| 5841 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5842 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5843 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5844 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5845 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5846 | uint16_t dev_id; |
| 5847 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5848 | |
| 5849 | /* |
| 5850 | * Reserved for alignment of current_image |
| 5851 | * TODO(rspangler) but it's not aligned! |
| 5852 | * Should have been reserved[2]. |
| 5853 | */ |
| 5854 | uint8_t reserved; |
| 5855 | |
| 5856 | /* One of ec_image */ |
| 5857 | uint32_t current_image; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5858 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5859 | |
| 5860 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5861 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5862 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5863 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5864 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5865 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5866 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5867 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5868 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5869 | struct ec_params_usb_pd_discovery_entry { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5870 | uint16_t vid; /* USB-IF VID */ |
| 5871 | uint16_t pid; /* USB-IF PID */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5872 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5873 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5874 | |
| 5875 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5876 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5877 | |
| 5878 | /* Negative port parameters have special meaning */ |
| 5879 | enum usb_pd_override_ports { |
| 5880 | OVERRIDE_DONT_CHARGE = -2, |
| 5881 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5882 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5883 | }; |
| 5884 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5885 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5886 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5887 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5888 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5889 | /* |
| 5890 | * Read (and delete) one entry of PD event log. |
| 5891 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5892 | * future non-PD logs that use the same internal EC event_log. |
| 5893 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5894 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5895 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5896 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5897 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5898 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5899 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5900 | uint16_t data; /* type-defined data payload */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5901 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5902 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5903 | |
| 5904 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5905 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5906 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5907 | #define PD_LOG_SIZE_MASK 0x1f |
| 5908 | #define PD_LOG_PORT_MASK 0xe0 |
| 5909 | #define PD_LOG_PORT_SHIFT 5 |
| 5910 | #define PD_LOG_PORT_SIZE(port, size) \ |
| 5911 | (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK)) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5912 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5913 | #define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5914 | |
| 5915 | /* PD event log : entry types */ |
| 5916 | /* PD MCU events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5917 | #define PD_EVENT_MCU_BASE 0x00 |
| 5918 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0) |
| 5919 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5920 | /* Reserved for custom board event */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5921 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5922 | /* PD generic accessory events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5923 | #define PD_EVENT_ACC_BASE 0x20 |
| 5924 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0) |
| 5925 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5926 | /* PD power supply events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5927 | #define PD_EVENT_PS_BASE 0x40 |
| 5928 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5929 | /* PD video dongles events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5930 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5931 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0) |
| 5932 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5933 | /* Returned in the "type" field, when there is no entry available */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5934 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5935 | |
| 5936 | /* |
| 5937 | * PD_EVENT_MCU_CHARGE event definition : |
| 5938 | * the payload is "struct usb_chg_measures" |
| 5939 | * the data field contains the port state flags as defined below : |
| 5940 | */ |
| 5941 | /* Port partner is a dual role device */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5942 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5943 | /* Port is the pending override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5944 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5945 | /* Port is the override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5946 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5947 | /* Charger type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5948 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
| 5949 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5950 | /* Power delivery role */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5951 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5952 | |
| 5953 | /* |
| 5954 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5955 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5956 | #define PS_FAULT_OCP 1 |
| 5957 | #define PS_FAULT_FAST_OCP 2 |
| 5958 | #define PS_FAULT_OVP 3 |
| 5959 | #define PS_FAULT_DISCH 4 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5960 | |
| 5961 | /* |
| 5962 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5963 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5964 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5965 | uint8_t major; |
| 5966 | uint8_t minor; |
| 5967 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5968 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5969 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5970 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5971 | uint8_t family[2]; |
| 5972 | uint8_t chipid[2]; |
| 5973 | struct mcdp_version irom; |
| 5974 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5975 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5976 | |
| 5977 | /* struct mcdp_info field decoding */ |
| 5978 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5979 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5980 | |
| 5981 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5982 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5983 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5984 | uint16_t svid_idx; /* SVID index to get */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5985 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5986 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5987 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5988 | #define VDO_MAX_SIZE 7 |
| 5989 | /* Max number of VDM data objects without VDM header */ |
| 5990 | #define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1) |
| 5991 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5992 | struct ec_params_usb_pd_get_mode_response { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5993 | uint16_t svid; /* SVID */ |
| 5994 | uint16_t opos; /* Object Position */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 5995 | uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5996 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5997 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5998 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5999 | |
| 6000 | enum pd_mode_cmd { |
| 6001 | PD_EXIT_MODE = 0, |
| 6002 | PD_ENTER_MODE = 1, |
| 6003 | /* Not a command. Do NOT remove. */ |
| 6004 | PD_MODE_CMD_COUNT, |
| 6005 | }; |
| 6006 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6007 | struct ec_params_usb_pd_set_mode_request { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6008 | uint32_t cmd; /* enum pd_mode_cmd */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6009 | uint16_t svid; /* SVID to set */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6010 | uint8_t opos; /* Object Position */ |
| 6011 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6012 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6013 | |
| 6014 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6015 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6016 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6017 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6018 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 6019 | 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] | 6020 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6021 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6022 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6023 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6024 | |
| 6025 | enum ec_pd_control_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6026 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 6027 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 6028 | PD_RESET, /* Force reset the PD chip */ |
| 6029 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 6030 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6031 | }; |
| 6032 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6033 | struct ec_params_pd_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6034 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6035 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6036 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6037 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6038 | /* Get info about USB-C SS muxes */ |
| 6039 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 6040 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6041 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6042 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6043 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6044 | |
| 6045 | /* Flags representing mux state */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6046 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 6047 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 6048 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 6049 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 6050 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 6051 | #define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */ |
| 6052 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 6053 | #define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */ |
| 6054 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6055 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6056 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6057 | |
| 6058 | /* USB-C Dock connected */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6059 | #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] | 6060 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6061 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6062 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6063 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6064 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6065 | #define EC_CMD_PD_CHIP_INFO 0x011B |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6066 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6067 | struct ec_params_pd_chip_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6068 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6069 | /* |
| 6070 | * Fetch the live chip info or hard-coded + cached chip info |
| 6071 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 6072 | * 1: live chip value for VID/PID/FW Version |
| 6073 | */ |
| 6074 | uint8_t live; |
| 6075 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6076 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6077 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6078 | uint16_t vendor_id; |
| 6079 | uint16_t product_id; |
| 6080 | uint16_t device_id; |
| 6081 | union { |
| 6082 | uint8_t fw_version_string[8]; |
| 6083 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6084 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6085 | } __ec_align2; |
| 6086 | |
| 6087 | struct ec_response_pd_chip_info_v1 { |
| 6088 | uint16_t vendor_id; |
| 6089 | uint16_t product_id; |
| 6090 | uint16_t device_id; |
| 6091 | union { |
| 6092 | uint8_t fw_version_string[8]; |
| 6093 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6094 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6095 | union { |
| 6096 | uint8_t min_req_fw_version_string[8]; |
| 6097 | uint64_t min_req_fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6098 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6099 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6100 | |
| 6101 | /* Run RW signature verification and get status */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6102 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6103 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6104 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6105 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6106 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6107 | |
| 6108 | /* For controlling RWSIG task */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6109 | #define EC_CMD_RWSIG_ACTION 0x011D |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6110 | |
| 6111 | enum rwsig_action { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6112 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 6113 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6114 | }; |
| 6115 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6116 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6117 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6118 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6119 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6120 | /* Run verification on a slot */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6121 | #define EC_CMD_EFS_VERIFY 0x011E |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6122 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6123 | struct ec_params_efs_verify { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6124 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6125 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6126 | |
| 6127 | /* |
| 6128 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 6129 | * type. Integers return a uint32. Strings return a string, using the response |
| 6130 | * size to determine how big it is. |
| 6131 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6132 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6133 | /* |
| 6134 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 6135 | * hardware write-protect enabled. |
| 6136 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6137 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6138 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6139 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6140 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6141 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 6142 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 6143 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6144 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
| 6145 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
| 6146 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
| 6147 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6148 | /* Second Source Factory Cache */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6149 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
| 6150 | CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6151 | CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6152 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6153 | }; |
| 6154 | |
| 6155 | /* |
| 6156 | * Flags to control read operation |
| 6157 | * |
| 6158 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 6159 | * write was successful without reboot. |
| 6160 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6161 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6162 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6163 | struct ec_params_get_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6164 | uint32_t tag; /* enum cbi_data_tag */ |
| 6165 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6166 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6167 | |
| 6168 | /* |
| 6169 | * Flags to control write behavior. |
| 6170 | * |
| 6171 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 6172 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6173 | * 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] | 6174 | * will be initialized to zero first. |
| 6175 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6176 | #define CBI_SET_NO_SYNC BIT(0) |
| 6177 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6178 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6179 | struct ec_params_set_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6180 | uint32_t tag; /* enum cbi_data_tag */ |
| 6181 | uint32_t flag; /* CBI_SET_* */ |
| 6182 | uint32_t size; /* Data size */ |
| 6183 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6184 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6185 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6186 | /* |
| 6187 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 6188 | */ |
| 6189 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 6190 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6191 | /* EC reset causes */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6192 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 6193 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 6194 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 6195 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 6196 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 6197 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 6198 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 6199 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 6200 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 6201 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 6202 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 6203 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 6204 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6205 | /* Some reset flags preserved from previous boot */ |
| 6206 | #define EC_RESET_FLAG_PRESERVED BIT(13) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6207 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 6208 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 6209 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 6210 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6211 | /* AP experienced a watchdog reset */ |
| 6212 | #define EC_RESET_FLAG_AP_WATCHDOG BIT(18) |
| 6213 | /* Do not select RW in EFS. This enables PD in RO for Chromebox. */ |
| 6214 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6215 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 6216 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 6217 | #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] | 6218 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6219 | /* |
| 6220 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 6221 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 6222 | * compatibility: |
| 6223 | * - New entries must be inserted prior to the _COUNT field |
| 6224 | * - If an existing entry is no longer in service, it must be replaced with a |
| 6225 | * RESERVED entry instead. |
| 6226 | * - The semantic meaning of an entry should not change. |
| 6227 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 6228 | */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6229 | enum chipset_shutdown_reason { |
| 6230 | /* |
| 6231 | * Beginning of reset reasons. |
| 6232 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6233 | CHIPSET_RESET_BEGIN = 0, |
| 6234 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 6235 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 6236 | CHIPSET_RESET_BOARD_CUSTOM, |
| 6237 | /* Believe that the AP has hung */ |
| 6238 | CHIPSET_RESET_HANG_REBOOT, |
| 6239 | /* Reset by EC console command */ |
| 6240 | CHIPSET_RESET_CONSOLE_CMD, |
| 6241 | /* Reset by EC host command */ |
| 6242 | CHIPSET_RESET_HOST_CMD, |
| 6243 | /* Keyboard module reset key combination */ |
| 6244 | CHIPSET_RESET_KB_SYSRESET, |
| 6245 | /* Keyboard module warm reboot */ |
| 6246 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 6247 | /* Debug module warm reboot */ |
| 6248 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 6249 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 6250 | CHIPSET_RESET_AP_REQ, |
| 6251 | /* Reset as side-effect of startup sequence */ |
| 6252 | CHIPSET_RESET_INIT, |
| 6253 | /* EC detected an AP watchdog event. */ |
| 6254 | CHIPSET_RESET_AP_WATCHDOG, |
| 6255 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6256 | CHIPSET_RESET_COUNT, /* End of reset reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6257 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6258 | /* |
| 6259 | * Beginning of shutdown reasons. |
| 6260 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6261 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 6262 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 6263 | /* Forcing a shutdown as part of EC initialization */ |
| 6264 | CHIPSET_SHUTDOWN_INIT, |
| 6265 | /* Custom reason on a per-board basis. */ |
| 6266 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 6267 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 6268 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 6269 | /* A power_wait_signal is being asserted */ |
| 6270 | CHIPSET_SHUTDOWN_WAIT, |
| 6271 | /* Critical battery level. */ |
| 6272 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 6273 | /* Because you told me to. */ |
| 6274 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 6275 | /* Forcing a shutdown to effect entry to G3. */ |
| 6276 | CHIPSET_SHUTDOWN_G3, |
| 6277 | /* Force shutdown due to over-temperature. */ |
| 6278 | CHIPSET_SHUTDOWN_THERMAL, |
| 6279 | /* Force a chipset shutdown from the power button through EC */ |
| 6280 | CHIPSET_SHUTDOWN_BUTTON, |
| 6281 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6282 | CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6283 | }; |
| 6284 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6285 | struct ec_response_uptime_info { |
| 6286 | /* |
| 6287 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 6288 | * typically do not restart the EC's time_since_boot epoch. |
| 6289 | * |
| 6290 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 6291 | * sense of time, in both phase and frequency. This timebase is similar |
| 6292 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 6293 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6294 | uint32_t time_since_ec_boot_ms; |
| 6295 | |
| 6296 | /* |
| 6297 | * Number of times the AP was reset by the EC since the last EC boot. |
| 6298 | * Note that the AP may be held in reset by the EC during the initial |
| 6299 | * boot sequence, such that the very first AP boot may count as more |
| 6300 | * than one here. |
| 6301 | */ |
| 6302 | uint32_t ap_resets_since_ec_boot; |
| 6303 | |
| 6304 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6305 | * The set of flags which describe the EC's most recent reset. |
| 6306 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6307 | */ |
| 6308 | uint32_t ec_reset_flags; |
| 6309 | |
| 6310 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6311 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6312 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6313 | uint16_t reset_cause; |
| 6314 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6315 | /* Reserved for protocol growth. */ |
| 6316 | uint16_t reserved; |
| 6317 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6318 | /* |
| 6319 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6320 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6321 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6322 | */ |
| 6323 | uint32_t reset_time_ms; |
| 6324 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6325 | } __ec_align4; |
| 6326 | |
| 6327 | /* |
| 6328 | * Add entropy to the device secret (stored in the rollback region). |
| 6329 | * |
| 6330 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6331 | * flash), so the commands are asynchronous. |
| 6332 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6333 | #define EC_CMD_ADD_ENTROPY 0x0122 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6334 | |
| 6335 | enum add_entropy_action { |
| 6336 | /* Add entropy to the current secret. */ |
| 6337 | ADD_ENTROPY_ASYNC = 0, |
| 6338 | /* |
| 6339 | * Add entropy, and also make sure that the previous secret is erased. |
| 6340 | * (this can be implemented by adding entropy multiple times until |
| 6341 | * all rolback blocks have been overwritten). |
| 6342 | */ |
| 6343 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6344 | /* Read back result from the previous operation. */ |
| 6345 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6346 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6347 | |
| 6348 | struct ec_params_rollback_add_entropy { |
| 6349 | uint8_t action; |
| 6350 | } __ec_align1; |
| 6351 | |
| 6352 | /* |
| 6353 | * Perform a single read of a given ADC channel. |
| 6354 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6355 | #define EC_CMD_ADC_READ 0x0123 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6356 | |
| 6357 | struct ec_params_adc_read { |
| 6358 | uint8_t adc_channel; |
| 6359 | } __ec_align1; |
| 6360 | |
| 6361 | struct ec_response_adc_read { |
| 6362 | int32_t adc_value; |
| 6363 | } __ec_align4; |
| 6364 | |
| 6365 | /* |
| 6366 | * Read back rollback info |
| 6367 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6368 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6369 | |
| 6370 | struct ec_response_rollback_info { |
| 6371 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6372 | int32_t rollback_min_version; |
| 6373 | int32_t rw_rollback_version; |
| 6374 | } __ec_align4; |
| 6375 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6376 | /* Issue AP reset */ |
| 6377 | #define EC_CMD_AP_RESET 0x0125 |
| 6378 | |
| 6379 | /*****************************************************************************/ |
| 6380 | /* Locate peripheral chips |
| 6381 | * |
| 6382 | * Return values: |
| 6383 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6384 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6385 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6386 | */ |
| 6387 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6388 | |
| 6389 | enum ec_chip_type { |
| 6390 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6391 | EC_CHIP_TYPE_TCPC = 1, |
| 6392 | EC_CHIP_TYPE_COUNT, |
| 6393 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6394 | }; |
| 6395 | |
| 6396 | enum ec_bus_type { |
| 6397 | EC_BUS_TYPE_I2C = 0, |
| 6398 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6399 | EC_BUS_TYPE_COUNT, |
| 6400 | EC_BUS_TYPE_MAX = 0xFF, |
| 6401 | }; |
| 6402 | |
| 6403 | struct ec_i2c_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6404 | uint16_t port; /* Physical port for device */ |
| 6405 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6406 | }; |
| 6407 | |
| 6408 | struct ec_params_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6409 | uint8_t type; /* enum ec_chip_type */ |
| 6410 | uint8_t index; /* Specifies one instance of chip type */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6411 | /* Used for type specific parameters in future */ |
| 6412 | union { |
| 6413 | uint16_t reserved; |
| 6414 | }; |
| 6415 | } __ec_align2; |
| 6416 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6417 | struct ec_response_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6418 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6419 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6420 | union { |
| 6421 | struct ec_i2c_info i2c_info; |
| 6422 | }; |
| 6423 | } __ec_align2; |
| 6424 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6425 | /* |
| 6426 | * Reboot AP on G3 |
| 6427 | * |
| 6428 | * This command is used for validation purpose, where the AP needs to be |
| 6429 | * 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] | 6430 | * wake events. |
| 6431 | * - With command version 0: |
| 6432 | * AP reboots immediately from G3 |
| 6433 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6434 | * - With command version 1: |
| 6435 | * AP reboots after the user specified delay |
| 6436 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6437 | */ |
| 6438 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6439 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6440 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6441 | /* configurable delay in seconds in G3 state */ |
| 6442 | uint32_t reboot_ap_at_g3_delay; |
| 6443 | } __ec_align4; |
| 6444 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6445 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6446 | /* Get PD port capabilities |
| 6447 | * |
| 6448 | * Returns the following static *capabilities* of the given port: |
| 6449 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6450 | * future CrOS devices would ever be only a source, so the options are |
| 6451 | * sink or dual. |
| 6452 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6453 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6454 | * or none). |
| 6455 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6456 | * for CrOS devices. |
| 6457 | */ |
| 6458 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6459 | |
| 6460 | enum ec_pd_power_role_caps { |
| 6461 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6462 | EC_PD_POWER_ROLE_SINK = 1, |
| 6463 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6464 | }; |
| 6465 | |
| 6466 | enum ec_pd_try_power_role_caps { |
| 6467 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6468 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6469 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6470 | }; |
| 6471 | |
| 6472 | enum ec_pd_data_role_caps { |
| 6473 | EC_PD_DATA_ROLE_DFP = 0, |
| 6474 | EC_PD_DATA_ROLE_UFP = 1, |
| 6475 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6476 | }; |
| 6477 | |
| 6478 | /* From: power_manager/power_supply_properties.proto */ |
| 6479 | enum ec_pd_port_location { |
| 6480 | /* The location of the port is unknown, or there's only one port. */ |
| 6481 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6482 | |
| 6483 | /* |
| 6484 | * Various positions on the device. The first word describes the side of |
| 6485 | * the device where the port is located while the second clarifies the |
| 6486 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6487 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6488 | * device. |
| 6489 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6490 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6491 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6492 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6493 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6494 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6495 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6496 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6497 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6498 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6499 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6500 | }; |
| 6501 | |
| 6502 | struct ec_params_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6503 | uint8_t port; /* Which port to interrogate */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6504 | } __ec_align1; |
| 6505 | |
| 6506 | struct ec_response_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6507 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6508 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6509 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6510 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6511 | } __ec_align1; |
| 6512 | |
| 6513 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6514 | /* |
| 6515 | * Button press simulation |
| 6516 | * |
| 6517 | * This command is used to simulate a button press. |
| 6518 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6519 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6520 | * |
| 6521 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6522 | */ |
| 6523 | #define EC_CMD_BUTTON 0x0129 |
| 6524 | |
| 6525 | struct ec_params_button { |
| 6526 | /* Button mask aligned to enum keyboard_button_type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6527 | uint32_t btn_mask; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6528 | |
| 6529 | /* Duration in milliseconds button needs to be pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6530 | uint32_t press_ms; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6531 | } __ec_align1; |
| 6532 | |
| 6533 | enum keyboard_button_type { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6534 | KEYBOARD_BUTTON_POWER = 0, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6535 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6536 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6537 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6538 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6539 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6540 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6541 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6542 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6543 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6544 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6545 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6546 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6547 | KEYBOARD_BUTTON_COUNT, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6548 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6549 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6550 | /*****************************************************************************/ |
| 6551 | /* |
| 6552 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6553 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6554 | * Additionally, capability to send function codes for the same keys is |
| 6555 | * optional and acceptable. |
| 6556 | * |
| 6557 | * Note: If the top row can generate both function and action codes by |
| 6558 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6559 | * "function" or "action" codes by default. In both cases, the response |
| 6560 | * for this command will look the same. |
| 6561 | */ |
| 6562 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6563 | |
| 6564 | /* Possible values for the top row keys */ |
| 6565 | enum action_key { |
| 6566 | TK_ABSENT = 0, |
| 6567 | TK_BACK = 1, |
| 6568 | TK_FORWARD = 2, |
| 6569 | TK_REFRESH = 3, |
| 6570 | TK_FULLSCREEN = 4, |
| 6571 | TK_OVERVIEW = 5, |
| 6572 | TK_BRIGHTNESS_DOWN = 6, |
| 6573 | TK_BRIGHTNESS_UP = 7, |
| 6574 | TK_VOL_MUTE = 8, |
| 6575 | TK_VOL_DOWN = 9, |
| 6576 | TK_VOL_UP = 10, |
| 6577 | TK_SNAPSHOT = 11, |
| 6578 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6579 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6580 | TK_KBD_BKLIGHT_UP = 14, |
| 6581 | TK_PLAY_PAUSE = 15, |
| 6582 | TK_NEXT_TRACK = 16, |
| 6583 | TK_PREV_TRACK = 17, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 6584 | TK_KBD_BKLIGHT_TOGGLE = 18, |
| 6585 | TK_MICMUTE = 19, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6586 | TK_MENU = 20, |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6587 | }; |
| 6588 | |
| 6589 | /* |
| 6590 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6591 | * If this needs to change, please create a new version of the command. |
| 6592 | */ |
| 6593 | #define MAX_TOP_ROW_KEYS 15 |
| 6594 | #define MIN_TOP_ROW_KEYS 10 |
| 6595 | |
| 6596 | /* |
| 6597 | * Is the keyboard capable of sending function keys *in addition to* |
| 6598 | * action keys. This is possible for e.g. if the keyboard has a |
| 6599 | * dedicated Fn key. |
| 6600 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6601 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6602 | /* |
| 6603 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6604 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6605 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6606 | /* |
| 6607 | * Whether the keyboard has a screenlock key. |
| 6608 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6609 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6610 | |
| 6611 | struct ec_response_keybd_config { |
| 6612 | /* |
| 6613 | * Number of top row keys, excluding Esc and Screenlock. |
| 6614 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6615 | * (i.e. does not expose any tables to the kernel). |
| 6616 | */ |
| 6617 | uint8_t num_top_row_keys; |
| 6618 | |
| 6619 | /* |
| 6620 | * The action keys in the top row, in order from left to right. |
| 6621 | * The values are filled from enum action_key. Esc and Screenlock |
| 6622 | * keys are not considered part of top row keys. |
| 6623 | */ |
| 6624 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6625 | |
| 6626 | /* Capability flags */ |
| 6627 | uint8_t capabilities; |
| 6628 | |
| 6629 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6630 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6631 | /* |
| 6632 | * Configure smart discharge |
| 6633 | */ |
| 6634 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6635 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6636 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6637 | |
| 6638 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6639 | struct discharge_rate { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6640 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6641 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6642 | }; |
| 6643 | |
| 6644 | struct smart_discharge_zone { |
| 6645 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6646 | int cutoff; |
| 6647 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6648 | int stayup; |
| 6649 | }; |
| 6650 | |
| 6651 | struct ec_params_smart_discharge { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6652 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6653 | /* |
| 6654 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6655 | * zero to disable smart discharging. That is, the system hibernates as |
| 6656 | * soon as the G3 idle timer expires. |
| 6657 | */ |
| 6658 | uint16_t hours_to_zero; |
| 6659 | /* Set both to zero to keep the current rates. */ |
| 6660 | struct discharge_rate drate; |
| 6661 | }; |
| 6662 | |
| 6663 | struct ec_response_smart_discharge { |
| 6664 | uint16_t hours_to_zero; |
| 6665 | struct discharge_rate drate; |
| 6666 | struct smart_discharge_zone dzone; |
| 6667 | }; |
| 6668 | |
| 6669 | /*****************************************************************************/ |
| 6670 | /* Voltage regulator controls */ |
| 6671 | |
| 6672 | /* |
| 6673 | * Get basic info of voltage regulator for given index. |
| 6674 | * |
| 6675 | * Returns the regulator name and supported voltage list in mV. |
| 6676 | */ |
| 6677 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6678 | |
| 6679 | /* Maximum length of regulator name */ |
| 6680 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6681 | |
| 6682 | /* Maximum length of the supported voltage list. */ |
| 6683 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6684 | |
| 6685 | struct ec_params_regulator_get_info { |
| 6686 | uint32_t index; |
| 6687 | } __ec_align4; |
| 6688 | |
| 6689 | struct ec_response_regulator_get_info { |
| 6690 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6691 | uint16_t num_voltages; |
| 6692 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6693 | } __ec_align2; |
| 6694 | |
| 6695 | /* |
| 6696 | * Configure the regulator as enabled / disabled. |
| 6697 | */ |
| 6698 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6699 | |
| 6700 | struct ec_params_regulator_enable { |
| 6701 | uint32_t index; |
| 6702 | uint8_t enable; |
| 6703 | } __ec_align4; |
| 6704 | |
| 6705 | /* |
| 6706 | * Query if the regulator is enabled. |
| 6707 | * |
| 6708 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6709 | */ |
| 6710 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6711 | |
| 6712 | struct ec_params_regulator_is_enabled { |
| 6713 | uint32_t index; |
| 6714 | } __ec_align4; |
| 6715 | |
| 6716 | struct ec_response_regulator_is_enabled { |
| 6717 | uint8_t enabled; |
| 6718 | } __ec_align1; |
| 6719 | |
| 6720 | /* |
| 6721 | * Set voltage for the voltage regulator within the range specified. |
| 6722 | * |
| 6723 | * The driver should select the voltage in range closest to min_mv. |
| 6724 | * |
| 6725 | * Also note that this might be called before the regulator is enabled, and the |
| 6726 | * setting should be in effect after the regulator is enabled. |
| 6727 | */ |
| 6728 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6729 | |
| 6730 | struct ec_params_regulator_set_voltage { |
| 6731 | uint32_t index; |
| 6732 | uint32_t min_mv; |
| 6733 | uint32_t max_mv; |
| 6734 | } __ec_align4; |
| 6735 | |
| 6736 | /* |
| 6737 | * Get the currently configured voltage for the voltage regulator. |
| 6738 | * |
| 6739 | * Note that this might be called before the regulator is enabled, and this |
| 6740 | * should return the configured output voltage if the regulator is enabled. |
| 6741 | */ |
| 6742 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6743 | |
| 6744 | struct ec_params_regulator_get_voltage { |
| 6745 | uint32_t index; |
| 6746 | } __ec_align4; |
| 6747 | |
| 6748 | struct ec_response_regulator_get_voltage { |
| 6749 | uint32_t voltage_mv; |
| 6750 | } __ec_align4; |
| 6751 | |
| 6752 | /* |
| 6753 | * Gather all discovery information for the given port and partner type. |
| 6754 | * |
| 6755 | * Note that if discovery has not yet completed, only the currently completed |
| 6756 | * responses will be filled in. If the discovery data structures are changed |
| 6757 | * in the process of the command running, BUSY will be returned. |
| 6758 | * |
| 6759 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6760 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6761 | * maximum parameter size. |
| 6762 | */ |
| 6763 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6764 | |
| 6765 | enum typec_partner_type { |
| 6766 | TYPEC_PARTNER_SOP = 0, |
| 6767 | TYPEC_PARTNER_SOP_PRIME = 1, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6768 | TYPEC_PARTNER_SOP_PRIME_PRIME = 2, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6769 | }; |
| 6770 | |
| 6771 | struct ec_params_typec_discovery { |
| 6772 | uint8_t port; |
| 6773 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6774 | } __ec_align1; |
| 6775 | |
| 6776 | struct svid_mode_info { |
| 6777 | uint16_t svid; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6778 | uint16_t mode_count; /* Number of modes partner sent */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 6779 | uint32_t mode_vdo[VDO_MAX_OBJECTS]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6780 | }; |
| 6781 | |
| 6782 | struct ec_response_typec_discovery { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6783 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6784 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6785 | uint16_t reserved; |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 6786 | uint32_t discovery_vdo[VDO_MAX_OBJECTS]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6787 | struct svid_mode_info svids[0]; |
| 6788 | } __ec_align1; |
| 6789 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6790 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6791 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6792 | |
| 6793 | enum typec_control_command { |
| 6794 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6795 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6796 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6797 | TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6798 | TYPEC_CONTROL_COMMAND_USB_MUX_SET, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6799 | TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE, |
| 6800 | TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6801 | }; |
| 6802 | |
| 6803 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6804 | enum typec_mode { |
| 6805 | TYPEC_MODE_DP, |
| 6806 | TYPEC_MODE_TBT, |
| 6807 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6808 | }; |
| 6809 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6810 | /* Replies the AP may specify to the TBT EnterMode command as a UFP */ |
| 6811 | enum typec_tbt_ufp_reply { |
| 6812 | TYPEC_TBT_UFP_REPLY_NAK, |
| 6813 | TYPEC_TBT_UFP_REPLY_ACK, |
| 6814 | }; |
| 6815 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6816 | #define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF |
| 6817 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6818 | struct typec_usb_mux_set { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6819 | /* Index of the mux to set in the chain */ |
| 6820 | uint8_t mux_index; |
| 6821 | |
| 6822 | /* USB_PD_MUX_*-encoded USB mux state to set */ |
| 6823 | uint8_t mux_flags; |
| 6824 | } __ec_align1; |
| 6825 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6826 | struct typec_vdm_req { |
| 6827 | /* VDM data, including VDM header */ |
| 6828 | uint32_t vdm_data[VDO_MAX_SIZE]; |
| 6829 | /* Number of 32-bit fields filled in */ |
| 6830 | uint8_t vdm_data_objects; |
| 6831 | /* Partner to address - see enum typec_partner_type */ |
| 6832 | uint8_t partner_type; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6833 | } __ec_align1; |
| 6834 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6835 | struct ec_params_typec_control { |
| 6836 | uint8_t port; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6837 | uint8_t command; /* enum typec_control_command */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6838 | uint16_t reserved; |
| 6839 | |
| 6840 | /* |
| 6841 | * This section will be interpreted based on |command|. Define a |
| 6842 | * placeholder structure to avoid having to increase the size and bump |
| 6843 | * the command version when adding new sub-commands. |
| 6844 | */ |
| 6845 | union { |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6846 | /* Used for CLEAR_EVENTS */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6847 | uint32_t clear_events_mask; |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6848 | /* Used for ENTER_MODE - enum typec_mode */ |
| 6849 | uint8_t mode_to_enter; |
| 6850 | /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */ |
| 6851 | uint8_t tbt_ufp_reply; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6852 | /* Used for USB_MUX_SET */ |
| 6853 | struct typec_usb_mux_set mux_params; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6854 | /* Used for BIST_SHARE_MODE */ |
| 6855 | uint8_t bist_share_mode; |
| 6856 | /* Used for VMD_REQ */ |
| 6857 | struct typec_vdm_req vdm_req_params; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6858 | uint8_t placeholder[128]; |
| 6859 | }; |
| 6860 | } __ec_align1; |
| 6861 | |
| 6862 | /* |
| 6863 | * Gather all status information for a port. |
| 6864 | * |
| 6865 | * Note: this covers many of the return fields from the deprecated |
| 6866 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 6867 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 6868 | * EC_CMD_USB_PD_CONTROL command. |
| 6869 | * |
| 6870 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6871 | */ |
| 6872 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 6873 | |
| 6874 | /* |
| 6875 | * Power role. |
| 6876 | * |
| 6877 | * Note this is also used for PD header creation, and values align to those in |
| 6878 | * the Power Delivery Specification Revision 3.0 (See |
| 6879 | * 6.2.1.1.4 Port Power Role). |
| 6880 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6881 | enum pd_power_role { |
| 6882 | PD_ROLE_SINK = 0, |
| 6883 | PD_ROLE_SOURCE = 1, |
| 6884 | }; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6885 | |
| 6886 | /* |
| 6887 | * Data role. |
| 6888 | * |
| 6889 | * Note this is also used for PD header creation, and the first two values |
| 6890 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 6891 | * 6.2.1.1.6 Port Data Role). |
| 6892 | */ |
| 6893 | enum pd_data_role { |
| 6894 | PD_ROLE_UFP = 0, |
| 6895 | PD_ROLE_DFP = 1, |
| 6896 | PD_ROLE_DISCONNECTED = 2, |
| 6897 | }; |
| 6898 | |
| 6899 | enum pd_vconn_role { |
| 6900 | PD_ROLE_VCONN_OFF = 0, |
| 6901 | PD_ROLE_VCONN_SRC = 1, |
| 6902 | }; |
| 6903 | |
| 6904 | /* |
| 6905 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 6906 | * regardless of whether a debug accessory is connected. |
| 6907 | */ |
| 6908 | enum tcpc_cc_polarity { |
| 6909 | /* |
| 6910 | * _CCx: is used to indicate the polarity while not connected to |
| 6911 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 6912 | * the other will be open. |
| 6913 | */ |
| 6914 | POLARITY_CC1 = 0, |
| 6915 | POLARITY_CC2 = 1, |
| 6916 | |
| 6917 | /* |
| 6918 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 6919 | * SRC Debug Accessory. Assert resistors on both lines. |
| 6920 | */ |
| 6921 | POLARITY_CC1_DTS = 2, |
| 6922 | POLARITY_CC2_DTS = 3, |
| 6923 | |
| 6924 | /* |
| 6925 | * The current TCPC code relies on these specific POLARITY values. |
| 6926 | * Adding in a check to verify if the list grows for any reason |
| 6927 | * that this will give a hint that other places need to be |
| 6928 | * adjusted. |
| 6929 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6930 | POLARITY_COUNT, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6931 | }; |
| 6932 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6933 | #define MODE_DP_PIN_A BIT(0) |
| 6934 | #define MODE_DP_PIN_B BIT(1) |
| 6935 | #define MODE_DP_PIN_C BIT(2) |
| 6936 | #define MODE_DP_PIN_D BIT(3) |
| 6937 | #define MODE_DP_PIN_E BIT(4) |
| 6938 | #define MODE_DP_PIN_F BIT(5) |
| 6939 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6940 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6941 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 6942 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
| 6943 | #define PD_STATUS_EVENT_HARD_RESET BIT(2) |
| 6944 | #define PD_STATUS_EVENT_DISCONNECTED BIT(3) |
| 6945 | #define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4) |
| 6946 | #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6947 | #define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6) |
| 6948 | #define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7) |
| 6949 | #define PD_STATUS_EVENT_VDM_ATTENTION BIT(8) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6950 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6951 | /* |
| 6952 | * Encode and decode for BCD revision response |
| 6953 | * |
| 6954 | * Note: the major revision set is written assuming that the value given is the |
| 6955 | * Specification Revision from the PD header, which currently only maps to PD |
| 6956 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 6957 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6958 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 6959 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 6960 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6961 | |
| 6962 | /* |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6963 | * Encode revision from partner RMDO |
| 6964 | * |
| 6965 | * Unlike the specification revision given in the PD header, specification and |
| 6966 | * version information returned in the revision message data object (RMDO) is |
| 6967 | * not offset. |
| 6968 | */ |
| 6969 | #define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12) |
| 6970 | #define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8) |
| 6971 | #define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4) |
| 6972 | #define PD_STATUS_RMDO_VER_SET_MINOR(r) (r) |
| 6973 | |
| 6974 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6975 | * Decode helpers for Source and Sink Capability PDOs |
| 6976 | * |
| 6977 | * Note: The Power Delivery Specification should be considered the ultimate |
| 6978 | * source of truth on the decoding of these PDOs |
| 6979 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6980 | #define PDO_TYPE_FIXED (0 << 30) |
| 6981 | #define PDO_TYPE_BATTERY (1 << 30) |
| 6982 | #define PDO_TYPE_VARIABLE (2 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6983 | #define PDO_TYPE_AUGMENTED (3 << 30) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6984 | #define PDO_TYPE_MASK (3 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6985 | |
| 6986 | /* |
| 6987 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 6988 | * |
| 6989 | * <31:30> : Fixed Supply |
| 6990 | * <29> : Dual-Role Power |
| 6991 | * <28> : SNK/SRC dependent |
| 6992 | * <27> : Unconstrained Power |
| 6993 | * <26> : USB Communications Capable |
| 6994 | * <25> : Dual-Role Data |
| 6995 | * <24:20> : SNK/SRC dependent |
| 6996 | * <19:10> : Voltage in 50mV Units |
| 6997 | * <9:0> : Maximum Current in 10mA units |
| 6998 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6999 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 7000 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 7001 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 7002 | #define PDO_FIXED_DATA_SWAP BIT(25) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7003 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7004 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7005 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7006 | |
| 7007 | /* |
| 7008 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 7009 | * |
| 7010 | * <31:30> : Battery |
| 7011 | * <29:20> : Maximum Voltage in 50mV units |
| 7012 | * <19:10> : Minimum Voltage in 50mV units |
| 7013 | * <9:0> : Maximum Allowable Power in 250mW units |
| 7014 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7015 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7016 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7017 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7018 | |
| 7019 | /* |
| 7020 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 7021 | * |
| 7022 | * <31:30> : Variable Supply (non-Battery) |
| 7023 | * <29:20> : Maximum Voltage in 50mV units |
| 7024 | * <19:10> : Minimum Voltage in 50mV units |
| 7025 | * <9:0> : Operational Current in 10mA units |
| 7026 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7027 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7028 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7029 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7030 | |
| 7031 | /* |
| 7032 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 7033 | * |
| 7034 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 7035 | * supported as of the cited version. |
| 7036 | * |
| 7037 | * <31:30> : Augmented Power Data Object |
| 7038 | * <29:28> : Programmable Power Supply |
| 7039 | * <27> : PPS Power Limited |
| 7040 | * <26:25> : Reserved |
| 7041 | * <24:17> : Maximum Voltage in 100mV increments |
| 7042 | * <16> : Reserved |
| 7043 | * <15:8> : Minimum Voltage in 100mV increments |
| 7044 | * <7> : Reserved |
| 7045 | * <6:0> : Maximum Current in 50mA increments |
| 7046 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7047 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 7048 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 7049 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7050 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7051 | struct ec_params_typec_status { |
| 7052 | uint8_t port; |
| 7053 | } __ec_align1; |
| 7054 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 7055 | /* |
| 7056 | * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1. |
| 7057 | * If you need to support old ECs who speak only v0, use |
| 7058 | * ec_response_typec_status_v0 instead. They're binary-compatible. |
| 7059 | */ |
| 7060 | struct ec_response_typec_status /* DEPRECATED */ { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7061 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 7062 | uint8_t dev_connected; /* Device connected - bool */ |
| 7063 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 7064 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7065 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7066 | uint8_t power_role; /* enum pd_power_role */ |
| 7067 | uint8_t data_role; /* enum pd_data_role */ |
| 7068 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 7069 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7070 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7071 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 7072 | uint8_t cc_state; /* enum pd_cc_states */ |
| 7073 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 7074 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7075 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7076 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7077 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7078 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7079 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7080 | /* |
| 7081 | * BCD PD revisions for partners |
| 7082 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7083 | * The format has the PD major revision in the upper nibble, and the PD |
| 7084 | * minor revision in the next nibble. The following two nibbles hold the |
| 7085 | * major and minor specification version. If a partner does not support |
| 7086 | * the Revision message, only the major revision will be given. |
| 7087 | * ex. PD Revision 3.2 Version 1.9 would map to 0x3219 |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7088 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7089 | * PD revision/version will be 0 if no PD device is connected. |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7090 | */ |
| 7091 | uint16_t sop_revision; |
| 7092 | uint16_t sop_prime_revision; |
| 7093 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7094 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7095 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7096 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7097 | } __ec_align1; |
| 7098 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame^] | 7099 | struct cros_ec_typec_status { |
| 7100 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 7101 | uint8_t dev_connected; /* Device connected - bool */ |
| 7102 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 7103 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
| 7104 | |
| 7105 | uint8_t power_role; /* enum pd_power_role */ |
| 7106 | uint8_t data_role; /* enum pd_data_role */ |
| 7107 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 7108 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
| 7109 | |
| 7110 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 7111 | uint8_t cc_state; /* enum pd_cc_states */ |
| 7112 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 7113 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
| 7114 | |
| 7115 | char tc_state[32]; /* TC state name */ |
| 7116 | |
| 7117 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
| 7118 | |
| 7119 | /* |
| 7120 | * BCD PD revisions for partners |
| 7121 | * |
| 7122 | * The format has the PD major revision in the upper nibble, and the PD |
| 7123 | * minor revision in the next nibble. The following two nibbles hold the |
| 7124 | * major and minor specification version. If a partner does not support |
| 7125 | * the Revision message, only the major revision will be given. |
| 7126 | * ex. PD Revision 3.2 Version 1.9 would map to 0x3219 |
| 7127 | * |
| 7128 | * PD revision/version will be 0 if no PD device is connected. |
| 7129 | */ |
| 7130 | uint16_t sop_revision; |
| 7131 | uint16_t sop_prime_revision; |
| 7132 | } __ec_align1; |
| 7133 | |
| 7134 | struct ec_response_typec_status_v0 { |
| 7135 | struct cros_ec_typec_status typec_status; |
| 7136 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 7137 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 7138 | } __ec_align1; |
| 7139 | |
| 7140 | struct ec_response_typec_status_v1 { |
| 7141 | struct cros_ec_typec_status typec_status; |
| 7142 | uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */ |
| 7143 | uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */ |
| 7144 | } __ec_align1; |
| 7145 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7146 | /** |
| 7147 | * Get the number of peripheral charge ports |
| 7148 | */ |
| 7149 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 7150 | |
| 7151 | #define EC_PCHG_MAX_PORTS 8 |
| 7152 | |
| 7153 | struct ec_response_pchg_count { |
| 7154 | uint8_t port_count; |
| 7155 | } __ec_align1; |
| 7156 | |
| 7157 | /** |
| 7158 | * Get the status of a peripheral charge port |
| 7159 | */ |
| 7160 | #define EC_CMD_PCHG 0x0135 |
| 7161 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7162 | /* For v1 and v2 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7163 | struct ec_params_pchg { |
| 7164 | uint8_t port; |
| 7165 | } __ec_align1; |
| 7166 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7167 | struct ec_params_pchg_v3 { |
| 7168 | uint8_t port; |
| 7169 | /* Below are new in v3. */ |
| 7170 | uint8_t reserved1; |
| 7171 | uint8_t reserved2; |
| 7172 | uint8_t reserved3; |
| 7173 | /* Errors acked by the host (thus to be cleared) */ |
| 7174 | uint32_t error; |
| 7175 | } __ec_align1; |
| 7176 | |
| 7177 | /* For v1 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7178 | struct ec_response_pchg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7179 | uint32_t error; /* enum pchg_error */ |
| 7180 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7181 | uint8_t battery_percentage; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7182 | uint8_t unused0; |
| 7183 | uint8_t unused1; |
| 7184 | /* Fields added in version 1 */ |
| 7185 | uint32_t fw_version; |
| 7186 | uint32_t dropped_event_count; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7187 | } __ec_align4; |
| 7188 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7189 | /* For v2 and v3 */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7190 | struct ec_response_pchg_v2 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7191 | uint32_t error; /* enum pchg_error */ |
| 7192 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7193 | uint8_t battery_percentage; |
| 7194 | uint8_t unused0; |
| 7195 | uint8_t unused1; |
| 7196 | /* Fields added in version 1 */ |
| 7197 | uint32_t fw_version; |
| 7198 | uint32_t dropped_event_count; |
| 7199 | /* Fields added in version 2 */ |
| 7200 | uint32_t dropped_host_event_count; |
| 7201 | } __ec_align4; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7202 | |
| 7203 | enum pchg_state { |
| 7204 | /* Charger is reset and not initialized. */ |
| 7205 | PCHG_STATE_RESET = 0, |
| 7206 | /* Charger is initialized or disabled. */ |
| 7207 | PCHG_STATE_INITIALIZED, |
| 7208 | /* Charger is enabled and ready to detect a device. */ |
| 7209 | PCHG_STATE_ENABLED, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7210 | /* Device is in proximity. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7211 | PCHG_STATE_DETECTED, |
| 7212 | /* Device is being charged. */ |
| 7213 | PCHG_STATE_CHARGING, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7214 | /* Device is fully charged. It implies DETECTED (& not charging). */ |
| 7215 | PCHG_STATE_FULL, |
| 7216 | /* In download (a.k.a. firmware update) mode */ |
| 7217 | PCHG_STATE_DOWNLOAD, |
| 7218 | /* In download mode. Ready for receiving data. */ |
| 7219 | PCHG_STATE_DOWNLOADING, |
| 7220 | /* Device is ready for data communication. */ |
| 7221 | PCHG_STATE_CONNECTED, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7222 | /* Charger is in Built-In Self Test mode. */ |
| 7223 | PCHG_STATE_BIST, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7224 | /* Put no more entry below */ |
| 7225 | PCHG_STATE_COUNT, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7226 | }; |
| 7227 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7228 | /* clang-format off */ |
| 7229 | #define EC_PCHG_STATE_TEXT \ |
| 7230 | { \ |
| 7231 | [PCHG_STATE_RESET] = "RESET", \ |
| 7232 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 7233 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 7234 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 7235 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
| 7236 | [PCHG_STATE_FULL] = "FULL", \ |
| 7237 | [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ |
| 7238 | [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ |
| 7239 | [PCHG_STATE_CONNECTED] = "CONNECTED", \ |
| 7240 | [PCHG_STATE_BIST] = "BIST", \ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7241 | } |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7242 | /* clang-format on */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7243 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7244 | /** |
| 7245 | * Update firmware of peripheral chip |
| 7246 | */ |
| 7247 | #define EC_CMD_PCHG_UPDATE 0x0136 |
| 7248 | |
| 7249 | /* Port number is encoded in bit[28:31]. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7250 | #define EC_MKBP_PCHG_PORT_SHIFT 28 |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7251 | /* Utility macros for converting MKBP event <-> port number. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7252 | #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) |
| 7253 | #define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7254 | /* Utility macro for extracting event bits. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7255 | #define EC_MKBP_PCHG_EVENT_MASK(e) ((e)&GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0)) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7256 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7257 | #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) |
| 7258 | #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) |
| 7259 | #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) |
| 7260 | #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) |
| 7261 | #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7262 | |
| 7263 | enum ec_pchg_update_cmd { |
| 7264 | /* Reset chip to normal mode. */ |
| 7265 | EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, |
| 7266 | /* Reset and put a chip in update (a.k.a. download) mode. */ |
| 7267 | EC_PCHG_UPDATE_CMD_OPEN, |
| 7268 | /* Write a block of data containing FW image. */ |
| 7269 | EC_PCHG_UPDATE_CMD_WRITE, |
| 7270 | /* Close update session. */ |
| 7271 | EC_PCHG_UPDATE_CMD_CLOSE, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7272 | /* Reset chip (without mode change). */ |
| 7273 | EC_PCHG_UPDATE_CMD_RESET, |
| 7274 | /* Enable pass-through mode. */ |
| 7275 | EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7276 | /* End of commands */ |
| 7277 | EC_PCHG_UPDATE_CMD_COUNT, |
| 7278 | }; |
| 7279 | |
| 7280 | struct ec_params_pchg_update { |
| 7281 | /* PCHG port number */ |
| 7282 | uint8_t port; |
| 7283 | /* enum ec_pchg_update_cmd */ |
| 7284 | uint8_t cmd; |
| 7285 | /* Padding */ |
| 7286 | uint8_t reserved0; |
| 7287 | uint8_t reserved1; |
| 7288 | /* Version of new firmware */ |
| 7289 | uint32_t version; |
| 7290 | /* CRC32 of new firmware */ |
| 7291 | uint32_t crc32; |
| 7292 | /* Address in chip memory where <data> is written to */ |
| 7293 | uint32_t addr; |
| 7294 | /* Size of <data> */ |
| 7295 | uint32_t size; |
| 7296 | /* Partial data of new firmware */ |
| 7297 | uint8_t data[]; |
| 7298 | } __ec_align4; |
| 7299 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7300 | BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT < |
| 7301 | BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8)); |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7302 | |
| 7303 | struct ec_response_pchg_update { |
| 7304 | /* Block size */ |
| 7305 | uint32_t block_size; |
| 7306 | } __ec_align4; |
| 7307 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7308 | #define EC_CMD_DISPLAY_SOC 0x0137 |
| 7309 | |
| 7310 | struct ec_response_display_soc { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7311 | /* Display charge in 10ths of a % (1000=100.0%) */ |
| 7312 | int16_t display_soc; |
| 7313 | /* Full factor in 10ths of a % (1000=100.0%) */ |
| 7314 | int16_t full_factor; |
| 7315 | /* Shutdown SoC in 10ths of a % (1000=100.0%) */ |
| 7316 | int16_t shutdown_soc; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7317 | } __ec_align2; |
| 7318 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7319 | #define EC_CMD_SET_BASE_STATE 0x0138 |
| 7320 | |
| 7321 | struct ec_params_set_base_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7322 | uint8_t cmd; /* enum ec_set_base_state_cmd */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7323 | } __ec_align1; |
| 7324 | |
| 7325 | enum ec_set_base_state_cmd { |
| 7326 | EC_SET_BASE_STATE_DETACH = 0, |
| 7327 | EC_SET_BASE_STATE_ATTACH, |
| 7328 | EC_SET_BASE_STATE_RESET, |
| 7329 | }; |
| 7330 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7331 | #define EC_CMD_I2C_CONTROL 0x0139 |
| 7332 | |
| 7333 | /* Subcommands for I2C control */ |
| 7334 | |
| 7335 | enum ec_i2c_control_command { |
| 7336 | EC_I2C_CONTROL_GET_SPEED, |
| 7337 | EC_I2C_CONTROL_SET_SPEED, |
| 7338 | }; |
| 7339 | |
| 7340 | #define EC_I2C_CONTROL_SPEED_UNKNOWN 0 |
| 7341 | |
| 7342 | struct ec_params_i2c_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7343 | uint8_t port; /* I2C port number */ |
| 7344 | uint8_t cmd; /* enum ec_i2c_control_command */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7345 | union { |
| 7346 | uint16_t speed_khz; |
| 7347 | } cmd_params; |
| 7348 | } __ec_align_size1; |
| 7349 | |
| 7350 | struct ec_response_i2c_control { |
| 7351 | union { |
| 7352 | uint16_t speed_khz; |
| 7353 | } cmd_response; |
| 7354 | } __ec_align_size1; |
| 7355 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7356 | #define EC_CMD_RGBKBD_SET_COLOR 0x013A |
| 7357 | #define EC_CMD_RGBKBD 0x013B |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7358 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7359 | #define EC_RGBKBD_MAX_KEY_COUNT 128 |
| 7360 | #define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF |
| 7361 | #define EC_RGBKBD_MAX_SCALE 0xFF |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7362 | |
| 7363 | enum rgbkbd_state { |
| 7364 | /* RGB keyboard is reset and not initialized. */ |
| 7365 | RGBKBD_STATE_RESET = 0, |
| 7366 | /* RGB keyboard is initialized but not enabled. */ |
| 7367 | RGBKBD_STATE_INITIALIZED, |
| 7368 | /* RGB keyboard is disabled. */ |
| 7369 | RGBKBD_STATE_DISABLED, |
| 7370 | /* RGB keyboard is enabled and ready to receive a command. */ |
| 7371 | RGBKBD_STATE_ENABLED, |
| 7372 | |
| 7373 | /* Put no more entry below */ |
| 7374 | RGBKBD_STATE_COUNT, |
| 7375 | }; |
| 7376 | |
| 7377 | enum ec_rgbkbd_subcmd { |
| 7378 | EC_RGBKBD_SUBCMD_CLEAR = 1, |
| 7379 | EC_RGBKBD_SUBCMD_DEMO = 2, |
| 7380 | EC_RGBKBD_SUBCMD_SET_SCALE = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7381 | EC_RGBKBD_SUBCMD_GET_CONFIG = 4, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7382 | EC_RGBKBD_SUBCMD_COUNT |
| 7383 | }; |
| 7384 | |
| 7385 | enum ec_rgbkbd_demo { |
| 7386 | EC_RGBKBD_DEMO_OFF = 0, |
| 7387 | EC_RGBKBD_DEMO_FLOW = 1, |
| 7388 | EC_RGBKBD_DEMO_DOT = 2, |
| 7389 | EC_RGBKBD_DEMO_COUNT, |
| 7390 | }; |
| 7391 | |
| 7392 | BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255); |
| 7393 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7394 | enum ec_rgbkbd_type { |
| 7395 | EC_RGBKBD_TYPE_UNKNOWN = 0, |
| 7396 | EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */ |
| 7397 | EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */ |
| 7398 | EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */ |
| 7399 | EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */ |
| 7400 | EC_RGBKBD_TYPE_COUNT, |
| 7401 | }; |
| 7402 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7403 | struct ec_rgbkbd_set_scale { |
| 7404 | uint8_t key; |
| 7405 | struct rgb_s scale; |
| 7406 | }; |
| 7407 | |
| 7408 | struct ec_params_rgbkbd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7409 | uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7410 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7411 | struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */ |
| 7412 | uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7413 | struct ec_rgbkbd_set_scale set_scale; |
| 7414 | }; |
| 7415 | } __ec_align1; |
| 7416 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7417 | struct ec_response_rgbkbd { |
| 7418 | /* |
| 7419 | * RGBKBD type supported by the device. |
| 7420 | */ |
| 7421 | |
| 7422 | uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */ |
| 7423 | } __ec_align1; |
| 7424 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7425 | struct ec_params_rgbkbd_set_color { |
| 7426 | /* Specifies the starting key ID whose color is being changed. */ |
| 7427 | uint8_t start_key; |
| 7428 | /* Specifies # of elements in <color>. */ |
| 7429 | uint8_t length; |
| 7430 | /* RGB color data array of length up to MAX_KEY_COUNT. */ |
| 7431 | struct rgb_s color[]; |
| 7432 | } __ec_align1; |
| 7433 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7434 | /* |
| 7435 | * Gather the response to the most recent VDM REQ from the AP, as well |
| 7436 | * as popping the oldest VDM:Attention from the DPM queue |
| 7437 | */ |
| 7438 | #define EC_CMD_TYPEC_VDM_RESPONSE 0x013C |
| 7439 | |
| 7440 | struct ec_params_typec_vdm_response { |
| 7441 | uint8_t port; |
| 7442 | } __ec_align1; |
| 7443 | |
| 7444 | struct ec_response_typec_vdm_response { |
| 7445 | /* Number of 32-bit fields filled in */ |
| 7446 | uint8_t vdm_data_objects; |
| 7447 | /* Partner to address - see enum typec_partner_type */ |
| 7448 | uint8_t partner_type; |
| 7449 | /* enum ec_status describing VDM response */ |
| 7450 | uint16_t vdm_response_err; |
| 7451 | /* VDM data, including VDM header */ |
| 7452 | uint32_t vdm_response[VDO_MAX_SIZE]; |
| 7453 | /* Number of 32-bit Attention fields filled in */ |
| 7454 | uint8_t vdm_attention_objects; |
| 7455 | /* Number of remaining messages to consume */ |
| 7456 | uint8_t vdm_attention_left; |
| 7457 | /* Reserved */ |
| 7458 | uint16_t reserved1; |
| 7459 | /* VDM:Attention contents */ |
| 7460 | uint32_t vdm_attention[2]; |
| 7461 | } __ec_align1; |
| 7462 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 7463 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7464 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7465 | |
| 7466 | /*****************************************************************************/ |
| 7467 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7468 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7469 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7470 | #define EC_CMD_CR51_BASE 0x0300 |
| 7471 | #define EC_CMD_CR51_LAST 0x03FF |
| 7472 | |
| 7473 | /*****************************************************************************/ |
| 7474 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 7475 | |
| 7476 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 7477 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 7478 | |
| 7479 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 7480 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7481 | struct ec_params_fp_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7482 | uint16_t len; /* Number of bytes to write then read */ |
| 7483 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 7484 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7485 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7486 | |
| 7487 | /* Configure the Fingerprint MCU behavior */ |
| 7488 | #define EC_CMD_FP_MODE 0x0402 |
| 7489 | |
| 7490 | /* Put the sensor in its lowest power mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7491 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7492 | /* Wait to see a finger on the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7493 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7494 | /* Poll until the finger has left the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7495 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7496 | /* Capture the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7497 | #define FP_MODE_CAPTURE BIT(3) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7498 | /* Finger enrollment session on-going */ |
| 7499 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 7500 | /* Enroll the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7501 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7502 | /* Try to match the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7503 | #define FP_MODE_MATCH BIT(6) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7504 | /* Reset and re-initialize the sensor. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7505 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 7506 | /* Sensor maintenance for dead pixels. */ |
| 7507 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7508 | /* special value: don't change anything just read back current mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7509 | #define FP_MODE_DONT_CHANGE BIT(31) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7510 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7511 | #define FP_VALID_MODES \ |
| 7512 | (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \ |
| 7513 | FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \ |
| 7514 | FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \ |
| 7515 | FP_MODE_DONT_CHANGE) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7516 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7517 | /* Capture types defined in bits [30..28] */ |
| 7518 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7519 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7520 | /** |
| 7521 | * enum fp_capture_type - Specifies the "mode" when capturing images. |
| 7522 | * |
| 7523 | * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality |
| 7524 | * image (produces 'frame_size' bytes) |
| 7525 | * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x |
| 7526 | * bpp bits) |
| 7527 | * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard) |
| 7528 | * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard) |
| 7529 | * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast |
| 7530 | * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test |
| 7531 | * @FP_CAPTURE_TYPE_MAX: End of enum |
| 7532 | * |
| 7533 | * @note This enum must remain ordered, if you add new values you must ensure |
| 7534 | * that FP_CAPTURE_TYPE_MAX is still the last one. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7535 | */ |
| 7536 | enum fp_capture_type { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7537 | FP_CAPTURE_VENDOR_FORMAT = 0, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7538 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7539 | FP_CAPTURE_PATTERN0 = 2, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7540 | FP_CAPTURE_PATTERN1 = 3, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7541 | FP_CAPTURE_QUALITY_TEST = 4, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7542 | FP_CAPTURE_RESET_TEST = 5, |
| 7543 | FP_CAPTURE_TYPE_MAX, |
| 7544 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7545 | /* Extracts the capture type from the sensor 'mode' word */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7546 | #define FP_CAPTURE_TYPE(mode) \ |
| 7547 | (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7548 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7549 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7550 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7551 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7552 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7553 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7554 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7555 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7556 | |
| 7557 | /* Retrieve Fingerprint sensor information */ |
| 7558 | #define EC_CMD_FP_INFO 0x0403 |
| 7559 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7560 | /* Number of dead pixels detected on the last maintenance */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7561 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7562 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 7563 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7564 | /* No interrupt from the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7565 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7566 | /* SPI communication error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7567 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7568 | /* Invalid sensor Hardware ID */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7569 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7570 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7571 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7572 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7573 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7574 | /* Sensor identification */ |
| 7575 | uint32_t vendor_id; |
| 7576 | uint32_t product_id; |
| 7577 | uint32_t model_id; |
| 7578 | uint32_t version; |
| 7579 | /* Image frame characteristics */ |
| 7580 | uint32_t frame_size; |
| 7581 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7582 | uint16_t width; |
| 7583 | uint16_t height; |
| 7584 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7585 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7586 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7587 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7588 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7589 | /* Sensor identification */ |
| 7590 | uint32_t vendor_id; |
| 7591 | uint32_t product_id; |
| 7592 | uint32_t model_id; |
| 7593 | uint32_t version; |
| 7594 | /* Image frame characteristics */ |
| 7595 | uint32_t frame_size; |
| 7596 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7597 | uint16_t width; |
| 7598 | uint16_t height; |
| 7599 | uint16_t bpp; |
| 7600 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 7601 | /* Template/finger current information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7602 | uint32_t template_size; /* max template size in bytes */ |
| 7603 | uint16_t template_max; /* maximum number of fingers/templates */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7604 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 7605 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7606 | uint32_t template_version; /* version of the template format */ |
| 7607 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7608 | |
| 7609 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7610 | #define EC_CMD_FP_FRAME 0x0404 |
| 7611 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7612 | /* constants defining the 'offset' field which also contains the frame index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7613 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7614 | /* Frame buffer where the captured image is stored */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7615 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7616 | /* First frame buffer holding a template */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7617 | #define FP_FRAME_INDEX_TEMPLATE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7618 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7619 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7620 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7621 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7622 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7623 | |
| 7624 | /* Constants for encryption parameters */ |
| 7625 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 7626 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 7627 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7628 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7629 | #define FP_CONTEXT_TPM_BYTES 32 |
| 7630 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7631 | /* Constants for positive match parameters. */ |
| 7632 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 7633 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7634 | struct ec_fp_template_encryption_metadata { |
| 7635 | /* |
| 7636 | * Version of the structure format (N=3). |
| 7637 | */ |
| 7638 | uint16_t struct_version; |
| 7639 | /* Reserved bytes, set to 0. */ |
| 7640 | uint16_t reserved; |
| 7641 | /* |
| 7642 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 7643 | * a different one is used for every message. |
| 7644 | */ |
| 7645 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7646 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7647 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 7648 | }; |
| 7649 | |
| 7650 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7651 | /* |
| 7652 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 7653 | * in the high nibble, and the real offset within the frame in |
| 7654 | * FP_FRAME_OFFSET_MASK. |
| 7655 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7656 | uint32_t offset; |
| 7657 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7658 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7659 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7660 | /* Load a template into the MCU */ |
| 7661 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 7662 | |
| 7663 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 7664 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 7665 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7666 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7667 | uint32_t offset; |
| 7668 | uint32_t size; |
| 7669 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7670 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7671 | |
| 7672 | /* Clear the current fingerprint user context and set a new one */ |
| 7673 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 7674 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7675 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7676 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7677 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7678 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7679 | enum fp_context_action { |
| 7680 | FP_CONTEXT_ASYNC = 0, |
| 7681 | FP_CONTEXT_GET_RESULT = 1, |
| 7682 | }; |
| 7683 | |
| 7684 | /* Version 1 of the command is "asynchronous". */ |
| 7685 | struct ec_params_fp_context_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7686 | uint8_t action; /**< enum fp_context_action */ |
| 7687 | uint8_t reserved[3]; /**< padding for alignment */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7688 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 7689 | } __ec_align4; |
| 7690 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7691 | #define EC_CMD_FP_STATS 0x0407 |
| 7692 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7693 | #define FPSTATS_CAPTURE_INV BIT(0) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7694 | #define FPSTATS_MATCHING_INV BIT(1) |
| 7695 | |
| 7696 | struct ec_response_fp_stats { |
| 7697 | uint32_t capture_time_us; |
| 7698 | uint32_t matching_time_us; |
| 7699 | uint32_t overall_time_us; |
| 7700 | struct { |
| 7701 | uint32_t lo; |
| 7702 | uint32_t hi; |
| 7703 | } overall_t0; |
| 7704 | uint8_t timestamps_invalid; |
| 7705 | int8_t template_matched; |
| 7706 | } __ec_align2; |
| 7707 | |
| 7708 | #define EC_CMD_FP_SEED 0x0408 |
| 7709 | struct ec_params_fp_seed { |
| 7710 | /* |
| 7711 | * Version of the structure format (N=3). |
| 7712 | */ |
| 7713 | uint16_t struct_version; |
| 7714 | /* Reserved bytes, set to 0. */ |
| 7715 | uint16_t reserved; |
| 7716 | /* Seed from the TPM. */ |
| 7717 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 7718 | } __ec_align4; |
| 7719 | |
| 7720 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 7721 | |
| 7722 | /* FP TPM seed has been set or not */ |
| 7723 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 7724 | |
| 7725 | struct ec_response_fp_encryption_status { |
| 7726 | /* Used bits in encryption engine status */ |
| 7727 | uint32_t valid_flags; |
| 7728 | /* Encryption engine status */ |
| 7729 | uint32_t status; |
| 7730 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7731 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7732 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 7733 | struct ec_params_fp_read_match_secret { |
| 7734 | uint16_t fgr; |
| 7735 | } __ec_align4; |
| 7736 | |
| 7737 | /* The positive match secret has the length of the SHA256 digest. */ |
| 7738 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 7739 | struct ec_response_fp_read_match_secret { |
| 7740 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 7741 | } __ec_align4; |
| 7742 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7743 | /*****************************************************************************/ |
| 7744 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 7745 | |
| 7746 | /* Perform touchpad self test */ |
| 7747 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 7748 | |
| 7749 | /* Get number of frame types, and the size of each type */ |
| 7750 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 7751 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7752 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7753 | uint32_t n_frames; |
| 7754 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7755 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7756 | |
| 7757 | /* Create a snapshot of current frame readings */ |
| 7758 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 7759 | |
| 7760 | /* Read the frame */ |
| 7761 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 7762 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7763 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7764 | uint32_t frame_index; |
| 7765 | uint32_t offset; |
| 7766 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7767 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7768 | |
| 7769 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7770 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 7771 | |
| 7772 | #define EC_COMM_TEXT_MAX 8 |
| 7773 | |
| 7774 | /* |
| 7775 | * Get battery static information, i.e. information that never changes, or |
| 7776 | * very infrequently. |
| 7777 | */ |
| 7778 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 7779 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7780 | /** |
| 7781 | * struct ec_params_battery_static_info - Battery static info parameters |
| 7782 | * @index: Battery index. |
| 7783 | */ |
| 7784 | struct ec_params_battery_static_info { |
| 7785 | uint8_t index; |
| 7786 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7787 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7788 | /** |
| 7789 | * struct ec_response_battery_static_info - Battery static info response |
| 7790 | * @design_capacity: Battery Design Capacity (mAh) |
| 7791 | * @design_voltage: Battery Design Voltage (mV) |
| 7792 | * @manufacturer: Battery Manufacturer String |
| 7793 | * @model: Battery Model Number String |
| 7794 | * @serial: Battery Serial Number String |
| 7795 | * @type: Battery Type String |
| 7796 | * @cycle_count: Battery Cycle Count |
| 7797 | */ |
| 7798 | struct ec_response_battery_static_info { |
| 7799 | uint16_t design_capacity; |
| 7800 | uint16_t design_voltage; |
| 7801 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 7802 | char model[EC_COMM_TEXT_MAX]; |
| 7803 | char serial[EC_COMM_TEXT_MAX]; |
| 7804 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7805 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7806 | uint32_t cycle_count; |
| 7807 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7808 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7809 | /** |
| 7810 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 7811 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 7812 | * strings. |
| 7813 | * @design_capacity: battery design capacity (in mAh) |
| 7814 | * @design_voltage: battery design voltage (in mV) |
| 7815 | * @cycle_count: battery cycle count |
| 7816 | * @manufacturer_ext: battery manufacturer string |
| 7817 | * @model_ext: battery model string |
| 7818 | * @serial_ext: battery serial number string |
| 7819 | * @type_ext: battery type string |
| 7820 | */ |
| 7821 | struct ec_response_battery_static_info_v1 { |
| 7822 | uint16_t design_capacity; |
| 7823 | uint16_t design_voltage; |
| 7824 | uint32_t cycle_count; |
| 7825 | char manufacturer_ext[12]; |
| 7826 | char model_ext[12]; |
| 7827 | char serial_ext[12]; |
| 7828 | char type_ext[12]; |
| 7829 | } __ec_align4; |
| 7830 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7831 | /** |
| 7832 | * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info |
| 7833 | * |
| 7834 | * Equivalent to struct ec_response_battery_static_info, but with strings |
| 7835 | * further lengthened (relative to v1) to accommodate the maximum string length |
| 7836 | * permitted by the Smart Battery Data Specification revision 1.1 and fields |
| 7837 | * renamed to better match that specification. |
| 7838 | * |
| 7839 | * @design_capacity: battery design capacity (in mAh) |
| 7840 | * @design_voltage: battery design voltage (in mV) |
| 7841 | * @cycle_count: battery cycle count |
| 7842 | * @manufacturer: battery manufacturer string |
| 7843 | * @device_name: battery model string |
| 7844 | * @serial: battery serial number string |
| 7845 | * @chemistry: battery type string |
| 7846 | */ |
| 7847 | struct ec_response_battery_static_info_v2 { |
| 7848 | uint16_t design_capacity; |
| 7849 | uint16_t design_voltage; |
| 7850 | uint32_t cycle_count; |
| 7851 | char manufacturer[32]; |
| 7852 | char device_name[32]; |
| 7853 | char serial[32]; |
| 7854 | char chemistry[32]; |
| 7855 | } __ec_align4; |
| 7856 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7857 | /* |
| 7858 | * Get battery dynamic information, i.e. information that is likely to change |
| 7859 | * every time it is read. |
| 7860 | */ |
| 7861 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 7862 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7863 | /** |
| 7864 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 7865 | * @index: Battery index. |
| 7866 | */ |
| 7867 | struct ec_params_battery_dynamic_info { |
| 7868 | uint8_t index; |
| 7869 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7870 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7871 | /** |
| 7872 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 7873 | * @actual_voltage: Battery voltage (mV) |
| 7874 | * @actual_current: Battery current (mA); negative=discharging |
| 7875 | * @remaining_capacity: Remaining capacity (mAh) |
| 7876 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 7877 | * @flags: Flags, see EC_BATT_FLAG_* |
| 7878 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 7879 | * @desired_current: Charging current desired by battery (mA) |
| 7880 | */ |
| 7881 | struct ec_response_battery_dynamic_info { |
| 7882 | int16_t actual_voltage; |
| 7883 | int16_t actual_current; |
| 7884 | int16_t remaining_capacity; |
| 7885 | int16_t full_capacity; |
| 7886 | int16_t flags; |
| 7887 | int16_t desired_voltage; |
| 7888 | int16_t desired_current; |
| 7889 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7890 | |
| 7891 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7892 | * Control charger chip. Used to control charger chip on the peripheral. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7893 | */ |
| 7894 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 7895 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7896 | /** |
| 7897 | * struct ec_params_charger_control - Charger control parameters |
| 7898 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 7899 | * max_current and (possibly) charge battery, negative to request current |
| 7900 | * from base (OTG). |
| 7901 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 7902 | * >= 0. |
| 7903 | * @allow_charging: Allow base battery charging (only makes sense if |
| 7904 | * max_current > 0). |
| 7905 | */ |
| 7906 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7907 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7908 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7909 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7910 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7911 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7912 | /* Get ACK from the USB-C SS muxes */ |
| 7913 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 7914 | |
| 7915 | struct ec_params_usb_pd_mux_ack { |
| 7916 | uint8_t port; /* USB-C port number */ |
| 7917 | } __ec_align1; |
| 7918 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7919 | /* Get boot time */ |
| 7920 | #define EC_CMD_GET_BOOT_TIME 0x0604 |
| 7921 | |
| 7922 | enum boot_time_param { |
| 7923 | ARAIL = 0, |
| 7924 | RSMRST, |
| 7925 | ESPIRST, |
| 7926 | PLTRST_LOW, |
| 7927 | PLTRST_HIGH, |
| 7928 | EC_CUR_TIME, |
| 7929 | RESET_CNT, |
| 7930 | }; |
| 7931 | |
| 7932 | struct ec_response_get_boot_time { |
| 7933 | uint64_t timestamp[RESET_CNT]; |
| 7934 | uint16_t cnt; |
| 7935 | } __ec_align4; |
| 7936 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7937 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7938 | /* |
| 7939 | * Reserve a range of host commands for board-specific, experimental, or |
| 7940 | * special purpose features. These can be (re)used without updating this file. |
| 7941 | * |
| 7942 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 7943 | * their EC commands for easier development, testing, debugging, and support. |
| 7944 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7945 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 7946 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 7947 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7948 | * In your experimental code, you may want to do something like this: |
| 7949 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7950 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 7951 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 7952 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 7953 | * |
| 7954 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 7955 | * EC_VER_MASK(0); |
| 7956 | * |
| 7957 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 7958 | * EC_VER_MASK(0); |
| 7959 | * |
| 7960 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 7961 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7962 | */ |
| 7963 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 7964 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 7965 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7966 | /* |
| 7967 | * Given the private host command offset, calculate the true private host |
| 7968 | * command value. |
| 7969 | */ |
| 7970 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 7971 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 7972 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7973 | /*****************************************************************************/ |
| 7974 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 7975 | * Passthru commands |
| 7976 | * |
| 7977 | * Some platforms have sub-processors chained to each other. For example. |
| 7978 | * |
| 7979 | * AP <--> EC <--> PD MCU |
| 7980 | * |
| 7981 | * The top 2 bits of the command number are used to indicate which device the |
| 7982 | * command is intended for. Device 0 is always the device receiving the |
| 7983 | * command; other device mapping is board-specific. |
| 7984 | * |
| 7985 | * When a device receives a command to be passed to a sub-processor, it passes |
| 7986 | * it on with the device number set back to 0. This allows the sub-processor |
| 7987 | * to remain blissfully unaware of whether the command originated on the next |
| 7988 | * device up the chain, or was passed through from the AP. |
| 7989 | * |
| 7990 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 7991 | * AP sends command 0x4002 to the EC |
| 7992 | * EC sends command 0x0002 to the PD MCU |
| 7993 | * EC forwards PD MCU response back to the AP |
| 7994 | */ |
| 7995 | |
| 7996 | /* Offset and max command number for sub-device n */ |
| 7997 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 7998 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 7999 | |
| 8000 | /*****************************************************************************/ |
| 8001 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 8002 | * Deprecated constants. These constants have been renamed for clarity. The |
| 8003 | * meaning and size has not changed. Programs that use the old names should |
| 8004 | * switch to the new names soon, as the old names may not be carried forward |
| 8005 | * forever. |
| 8006 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8007 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 8008 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 8009 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 8010 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8011 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8012 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8013 | #ifdef __cplusplus |
| 8014 | } |
| 8015 | #endif |
| 8016 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8017 | #endif /* __CROS_EC_EC_COMMANDS_H */ |